--- /dev/null
+/* $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
+ * <mit-copyright.h>.
+ */
+
+#include <mit-copyright.h>
+#include <stdio.h>
+#include <moira.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+EXEC SQL INCLUDE sqlca;
+
+extern int errno;
+char *whoami = "directory.gen";
+char *db = "moira/moira";
+
+int main(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], last_name[17], first_name[17], middle_name[16];
+ char office_address[17], office_phone[13];
+ char home_address[82], home_phone[17];
+ char id[17], type[9];
+ 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")))
+ {
+ 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, last, first, middle, office_addr, office_phone,
+ home_addr, home_phone, clearid, type
+ FROM users WHERE status = 1 AND type != 'SYSTEM' AND type != 'STAFF'
+ AND type NOT LIKE 'GUES%';
+ EXEC SQL OPEN x;
+ while (1)
+ {
+ EXEC SQL FETCH x INTO :login, :last_name, :first_name, :middle_name,
+ :office_address, :office_phone, :home_address, :home_phone,
+ :id, :type;
+ if (sqlca.sqlcode)
+ break;
+ strtrim(login);
+ strtrim(last_name);
+ strtrim(first_name);
+ strtrim(middle_name);
+ strtrim(office_address);
+ strtrim(office_phone);
+ strtrim(home_address);
+ strtrim(home_phone);
+ strtrim(id);
+ strtrim(type);
+#ifdef notdef
+ if(isdigit(*id))
+ fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
+ "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:"
+ "Unlisted Account\n", id, last_name, login, last_name,
+ first_name, middle_name, last_name, first_name,
+ middle_name, login, login, office_phone, office_address,
+ home_phone, home_address);
+#else
+ if(isdigit(*id))
+ fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
+ "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:%s\n",
+ id, last_name, login, last_name, first_name, middle_name,
+ last_name, first_name, middle_name, login, login,
+ "", "", "", "", strcmp(type, "G") == 0 ? "G" :
+ !strncmp(type, "19", 2) ? "Undergraduate" :
+ !strncmp(type, "20", 2) ? "Undergraduate" : "MIT Affiliate");
+#endif
+ }
+ 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);
+}