3 * This generates a master /etc/passwd containing all active (status != 0)
6 * Copyright (C) 1998 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
21 EXEC SQL INCLUDE sqlca;
25 char *whoami = "directory.gen";
26 char *db = "moira/moira";
28 int main(int argc, char **argv)
31 char *outf = NULL, outft[MAXPATHLEN];
32 EXEC SQL BEGIN DECLARE SECTION;
33 char login[USERS_LOGIN_SIZE], last_name[USERS_LAST_SIZE];
34 char first_name[USERS_FIRST_SIZE], middle_name[USERS_MIDDLE_SIZE];
35 char office_address[USERS_OFFICE_ADDR_SIZE];
36 char office_phone[USERS_OFFICE_PHONE_SIZE];
37 char home_address[USERS_HOME_ADDR_SIZE], home_phone[USERS_HOME_PHONE_SIZE];
38 char id[USERS_CLEARID_SIZE], type[USERS_TYPE_SIZE];
39 EXEC SQL END DECLARE SECTION;
46 sprintf(outft, "%s~", outf);
47 if (!(out = fopen(outft, "w")))
49 fprintf(stderr, "unable to open %s for output\n", outf);
55 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
61 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
63 EXEC SQL DECLARE x CURSOR FOR SELECT
64 login, last, first, middle, office_addr, office_phone,
65 home_addr, home_phone, clearid, type
66 FROM users WHERE status = 1 AND type != 'SYSTEM' AND type != 'STAFF'
67 AND type NOT LIKE 'GUES%';
71 EXEC SQL FETCH x INTO :login, :last_name, :first_name, :middle_name,
72 :office_address, :office_phone, :home_address, :home_phone,
80 strtrim(office_address);
81 strtrim(office_phone);
82 strtrim(home_address);
88 fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
89 "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:"
90 "Unlisted Account\n", id, last_name, login, last_name,
91 first_name, middle_name, last_name, first_name,
92 middle_name, login, login, office_phone, office_address,
93 home_phone, home_address);
96 fprintf(out, "%s^4:p\t24:%s %s\t7:%s, %s %s\t3:%s, %s "
97 "%s\t5:%s\t2:%s@mit.edu\t1:%s\t0:%s\t14:%s\t15:%s\t10:%s\n",
98 id, last_name, login, last_name, first_name, middle_name,
99 last_name, first_name, middle_name, login, login,
100 "", "", "", "", strcmp(type, "G") == 0 ? "G" :
101 !strncmp(type, "19", 2) ? "Undergraduate" :
102 !strncmp(type, "20", 2) ? "Undergraduate" : "MIT Affiliate");
111 perror("close failed");
119 db_error(sqlca.sqlcode);