]>
Commit | Line | Data |
---|---|---|
f59a4f24 | 1 | /* $Header$ |
2 | * | |
3 | * This generates the input file for the mkdirdb program for the MIT.EDU | |
4 | * mailhub. | |
5 | * | |
6 | * (c) Copyright 1989 by the Massachusetts Institute of Technology. | |
7 | * For copying and distribution information, please see the file | |
8 | * <mit-copyright.h>. | |
9 | */ | |
10 | ||
11 | ||
12 | #include <mit-copyright.h> | |
13 | #include <stdio.h> | |
14 | #include <string.h> | |
15 | #include <sms.h> | |
16 | #include <sms_app.h> | |
17 | #include <sys/types.h> | |
18 | #include <sys/stat.h> | |
19 | #include <sys/time.h> | |
20 | ||
21 | ||
22 | extern int errno; | |
23 | char *whoami = "finger.gen"; | |
24 | char *ingres_date_and_time(); | |
25 | ||
26 | ||
27 | main(argc, argv) | |
28 | int argc; | |
29 | char **argv; | |
30 | { | |
31 | long tm = time(NULL); | |
32 | FILE *out= stdout; | |
33 | char filename[64], *targetfile; | |
34 | struct stat sb; | |
35 | ## int flag1; | |
36 | ## char *filetime; | |
37 | int ingerr(); | |
38 | ||
39 | IIseterr(ingerr); | |
40 | initialize_sms_error_table(); | |
41 | ## ingres sms | |
42 | ## set lockmode session where level = table | |
43 | ||
44 | if (argc == 2) { | |
45 | if (stat(argv[1], &sb) == 0) { | |
46 | filetime = ingres_date_and_time(sb.st_mtime); | |
47 | ## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime))) | |
48 | ## where tblstats.table = "users" | |
49 | if (flag1 < 0) { | |
50 | fprintf(stderr, "File %s does not need to be rebuilt.\n", | |
51 | argv[1]); | |
52 | exit(SMS_NO_CHANGE); | |
53 | } | |
54 | } | |
55 | targetfile = argv[1]; | |
56 | sprintf(filename, "%s~", targetfile); | |
57 | if ((out = fopen(filename, "w")) == NULL) { | |
58 | fprintf(stderr, "unable to open %s for output\n", filename); | |
59 | exit(SMS_OCONFIG); | |
60 | } | |
61 | } else if (argc != 1) { | |
62 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
63 | exit(SMS_ARGS); | |
64 | } | |
65 | ||
66 | ## begin transaction | |
67 | get_info(out); | |
68 | ## end transaction | |
69 | ## exit | |
70 | ||
71 | if (fclose(out)) { | |
72 | perror("close failed"); | |
73 | exit(SMS_CCONFIG); | |
74 | } | |
75 | ||
76 | if (argc == 2) | |
77 | fix_file(targetfile); | |
78 | exit(SMS_SUCCESS); | |
79 | } | |
80 | ||
81 | ||
82 | /* | |
83 | * ingerr: (supposedly) called when Ingres indicates an error. | |
84 | * I have not yet been able to get this to work to intercept a | |
85 | * database open error. | |
86 | */ | |
87 | #define INGRES_DEADLOCK 4700 | |
88 | ||
89 | static int ingerr(num) | |
90 | int *num; | |
91 | { | |
92 | char buf[256]; | |
93 | int ingres_errno; | |
94 | ||
95 | switch (*num) { | |
96 | case INGRES_DEADLOCK: | |
97 | ingres_errno = SMS_DEADLOCK; | |
98 | break; | |
99 | default: | |
100 | ingres_errno = SMS_INGRES_ERR; | |
101 | } | |
102 | com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num); | |
103 | critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num); | |
104 | exit(ingres_errno); | |
105 | } | |
106 | ||
107 | ||
108 | get_info(out) | |
109 | FILE *out; | |
110 | ##{ | |
111 | ## int id, pid, bid, mid; | |
112 | ## char name[129], type[9], buf[257], fname[17], mname[17], lname[17]; | |
113 | ## char year[9], dept[13], oaddr[17], ophone[13], haddr[81], hphone[17]; | |
114 | char stuemp, *mhost, *uname, *pob; | |
115 | struct hash *strings; | |
116 | ||
117 | /* get locks */ | |
118 | ## retrieve (buf = users.modtime) where users.users_id = 0 | |
119 | ||
120 | strings = create_hash(2000); | |
121 | ## retrieve (id = strings.string_id, name = strings.string) { | |
122 | hash_store(strings, id, strsave(strtrim(name))); | |
123 | ## } | |
124 | ||
125 | ||
126 | ## range of u is users | |
127 | ## retrieve (id = u.users_id, name = u.login, | |
128 | ## fname = u.first, mname = u.middle, lname = u.last, | |
129 | ## year = u.mit_year, dept = u.mit_dept, | |
130 | ## oaddr = u.office_addr, ophone = u.office_phone, | |
131 | ## haddr = u.home_addr, hphone = u.home_phone, | |
132 | ## type = u.potype, bid = u.box_id) | |
133 | ## where u.status != 3 { | |
134 | ||
135 | if (id == 0) | |
136 | continue; | |
137 | ||
138 | strtrim(year); | |
139 | if (atoi(year) || !strcmp(year, "G")) | |
140 | stuemp = 'S'; | |
141 | else if (!strcmp(year, "FACULTY") || !strcmp(year, "MITS") || | |
142 | !strcmp(year, "STAFF")) | |
143 | stuemp = 'E'; | |
144 | else if (!strcmp(year, "PROJECT") || !strcmp(year, "SYSTEM")) | |
145 | continue; | |
146 | else | |
147 | stuemp = '?'; | |
148 | ||
149 | if (type[0] == 'S' & (pob = hash_lookup(strings, bid)) != NULL) { | |
150 | uname = pob; | |
151 | mhost = index(pob, '@'); | |
152 | if (mhost) | |
153 | *mhost++ = 0; | |
154 | else | |
155 | mhost = &uname[strlen(uname) + 1]; | |
156 | } else if (type[0] == 'N') { | |
157 | mhost = ""; | |
158 | uname = ""; | |
159 | } else { | |
160 | mhost = "ATHENA.MIT.EDU"; | |
161 | uname = strtrim(name); | |
162 | } | |
163 | ||
164 | fprintf(out, "%c:%s:%s:%s:%s:", | |
165 | stuemp, "", strtrim(lname), strtrim(fname), strtrim(mname)); | |
166 | fprintf(out, "%s:%s:%s:%s:%s:%s:%s:%s:", | |
167 | strtrim(oaddr), "", strtrim(ophone), "", | |
168 | "", "", uname, mhost); | |
169 | fprintf(out, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%d\n", | |
170 | strtrim(haddr), "", "", "", strtrim(hphone), | |
171 | "", "", "", "", year, "", id); | |
172 | ## } | |
173 | ##} |