3 * This generates a master /etc/passwd containing all active (status != 0)
6 * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
14 #include <sys/types.h>
17 EXEC SQL INCLUDE sqlca;
20 char *whoami = "passwd.gen";
21 char *db = "moira/moira";
28 char *outf = NULL, outft[64];
31 EXEC SQL BEGIN DECLARE SECTION;
32 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
35 EXEC SQL END DECLARE SECTION;
40 if (stat(argv[1], &sb) == 0) {
41 if (ModDiff (&flag, "users", sb.st_mtime))
44 fprintf(stderr, "File %s does not need to be rebuilt.\n",
50 sprintf(outft, "%s~", outf);
51 if ((out = fopen(outft, "w")) == NULL) {
52 fprintf(stderr, "unable to open %s for output\n", outf);
55 } else if (argc != 1) {
56 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
62 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
64 EXEC SQL DECLARE x CURSOR FOR SELECT
65 login, unix_uid, shell, fullname, office_addr, nickname,
66 office_phone, home_phone
67 FROM users WHERE status = 1;
70 EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname,
72 if (sqlca.sqlcode != 0) break;
80 fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n",
81 login, uid, fullname, nickname, oa, op, hp, login, shell);
89 perror("close failed");
97 db_error(sqlca.sqlcode);