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";
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;
38 EXEC SQL CONNECT moira;
41 EXEC SQL DATABASE moira;
45 if (stat(argv[1], &sb) == 0) {
46 if (ModDiff (&flag, "users", sb.st_mtime))
49 fprintf(stderr, "File %s does not need to be rebuilt.\n",
55 sprintf(outft, "%s~", outf);
56 if ((out = fopen(outft, "w")) == NULL) {
57 fprintf(stderr, "unable to open %s for output\n", outf);
60 } else if (argc != 1) {
61 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
67 /* The following is declarative, not executed,
68 * and so is dependent on where it is in the file,
69 * not in the order of execution of statements.
71 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
73 EXEC SQL DECLARE x CURSOR FOR SELECT
74 login, uid, shell, fullname, office_addr, nickname,
75 office_phone, home_phone
76 FROM users WHERE status = 1;
79 EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname,
81 if (sqlca.sqlcode != 0) break;
89 fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n",
90 login, uid, fullname, nickname, oa, op, hp, login, shell);
98 EXEC SQL CLOSE DATABASE;
102 perror("close failed");
110 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
111 critical_alert("DCM", "Passwd build encountered INGRES ERROR %d",