/* $Header$ * * This generates a master /etc/passwd containing all active (status != 0) * accounts. * * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology. * For copying and distribution information, please see the file * . */ #include #include #include #include #include #include EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "passwd.gen"; char *db = "moira/moira"; main(argc, argv) int argc; char **argv; { FILE *out = stdout; char *outf = NULL, outft[64]; struct stat sb; int flag; EXEC SQL BEGIN DECLARE SECTION; char login[9], shell[33], fullname[33], oa[17], op[13], hp[17]; char nickname[17]; int uid; EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { if (ModDiff (&flag, "users", sb.st_mtime)) exit(MR_DATE); if (flag < 0) { fprintf(stderr, "File %s does not need to be rebuilt.\n", argv[1]); exit(MR_NO_CHANGE); } } outf = argv[1]; sprintf(outft, "%s~", outf); if ((out = fopen(outft, "w")) == NULL) { fprintf(stderr, "unable to open %s for output\n", outf); exit(MR_OCONFIG); } } else if (argc != 1) { fprintf(stderr, "usage: %s [outfile]\n", argv[0]); exit(MR_ARGS); } else { outf = NULL; } EXEC SQL WHENEVER SQLERROR GOTO sqlerr; EXEC SQL DECLARE x CURSOR FOR SELECT login, unix_uid, shell, fullname, office_addr, nickname, office_phone, home_phone FROM users WHERE status = 1; EXEC SQL OPEN x; while (1) { EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname, :op, :hp; if (sqlca.sqlcode != 0) break; strtrim(login); strtrim(fullname); strtrim(nickname); strtrim(oa); strtrim(op); strtrim(hp); strtrim(shell); fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n", login, uid, fullname, nickname, oa, op, hp, login, shell); } EXEC SQL CLOSE x; EXEC SQL COMMIT; if (fclose(out)) { perror("close failed"); exit(MR_CCONFIG); } if (outf) fix_file(outf); exit(MR_SUCCESS); sqlerr: db_error(sqlca.sqlcode); exit(MR_DBMS_ERR); }