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 = "directory.gen";
21 char *db = "moira/moira";
23 int main(int argc, char **argv)
26 char *outf = NULL, outft[64];
29 EXEC SQL BEGIN DECLARE SECTION;
30 char login[9], last_name[17], first_name[17], middle_name[16];
31 char office_address[17], office_phone[13];
32 char home_address[82], home_phone[17];
34 EXEC SQL END DECLARE SECTION;
40 if (stat(argv[1], &sb) == 0)
42 if (ModDiff (&flag, "users", sb.st_mtime))
46 fprintf(stderr, "File %s does not need to be rebuilt.\n",
52 sprintf(outft, "%s~", outf);
53 if (!(out = fopen(outft, "w")))
55 fprintf(stderr, "unable to open %s for output\n", outf);
61 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
67 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
69 EXEC SQL DECLARE x CURSOR FOR SELECT
70 login, last, first, middle, office_addr, office_phone,
71 home_addr, home_phone, clearid, type
72 FROM users WHERE status = 1 AND type != 'SYSTEM' AND type != 'STAFF'
73 AND type NOT LIKE 'GUES%';
77 EXEC SQL FETCH x INTO :login, :last_name, :first_name, :middle_name,
78 :office_address, :office_phone, :home_address, :home_phone,
86 strtrim(office_address);
87 strtrim(office_phone);
88 strtrim(home_address);
94 fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
95 "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:"
96 "Unlisted Account\n", id, last_name, login, last_name,
97 first_name, middle_name, last_name, first_name,
98 middle_name, login, login, office_phone, office_address,
99 home_phone, home_address);
102 fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
103 "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:%s\n",
104 id, last_name, login, last_name, first_name, middle_name,
105 last_name, first_name, middle_name, login, login,
106 "", "", "", "", strcmp(type, "G") == 0 ? "G" :
107 !strncmp(type, "19", 2) ? "Undergraduate" :
108 !strncmp(type, "20", 2) ? "Undergraduate" : "MIT Affiliate");
117 perror("close failed");
125 db_error(sqlca.sqlcode);