]>
Commit | Line | Data |
---|---|---|
469f80df | 1 | /* $Header$ |
2 | */ | |
3 | ||
4 | #include <stdio.h> | |
5 | #include <strings.h> | |
6 | #include <ctype.h> | |
7 | #include <sys/time.h> | |
932028de | 8 | #include <moira.h> |
9 | #include <moira_site.h> | |
469f80df | 10 | |
11 | ||
12 | ##define WHO 11859 /* root */ | |
13 | ##define PROG "emp-tape" | |
14 | ||
397e9044 | 15 | #define MAX_ID_VALUE 31999 |
469f80df | 16 | #define MIN_ID_VALUE 101 |
17 | ||
18 | /* File format is: | |
19 | ||
20 | 0-8 id number | |
21 | 9-38 name | |
22 | 39-62 office address | |
23 | 63-74 phone1 | |
24 | 75-86 phone2 | |
25 | 87-106 dept | |
26 | 107-156 title | |
27 | 157-186 username | |
28 | 187-241 host | |
29 | ||
30 | */ | |
31 | ||
32 | #define LOC_ID 0 | |
33 | #define LOC_NAME 9 | |
34 | #define LOC_OFFICE 39 | |
35 | #define LOC_PHONE 63 | |
36 | #define LOC_PHONE2 75 | |
37 | #define LOC_DEPT 87 | |
38 | #define LOC_TITLE 107 | |
39 | #define LOC_USERNAME 157 | |
40 | #define LOC_HOST 187 | |
41 | ||
42 | #define LEN_ID 9 | |
a6e9fead | 43 | #define LEN_NAME 30 |
44 | #define LEN_OFFICE 24 | |
469f80df | 45 | #define LEN_PHONE 12 |
46 | #define LEN_PHONE2 12 | |
a6e9fead | 47 | #define LEN_DEPT 20 |
48 | #define LEN_TITLE 50 | |
49 | #define LEN_USERNAME 30 | |
469f80df | 50 | #define LEN_HOST 55 |
51 | ||
52 | ||
53 | struct entry { | |
a6e9fead | 54 | char *name; |
469f80df | 55 | char *last; |
56 | char *first; | |
57 | char *middle; | |
58 | char *title; | |
59 | char *class; | |
60 | char *id; | |
61 | char *eid; | |
62 | char *dept; | |
63 | char *address; | |
64 | char *phone; | |
a6e9fead | 65 | char *phone2; |
469f80df | 66 | char *email; |
67 | }; | |
68 | ||
69 | ||
70 | char *whoami; | |
71 | int newfinger = 0; | |
72 | ||
73 | ||
74 | main(argc, argv) | |
75 | int argc; | |
76 | char **argv; | |
77 | ##{ | |
78 | FILE *in; | |
79 | struct entry *e, *get_next_entry(); | |
80 | int i, wait = 0; | |
81 | char buf[BUFSIZ], *file = NULL; | |
82 | ||
83 | whoami = rindex(argv[0], '/'); | |
84 | if (whoami) | |
85 | whoami++; | |
86 | else | |
87 | whoami = argv[0]; | |
88 | ||
89 | for (i = 1; i < argc; i++) { | |
90 | if (!strcmp(argv[i], "-w")) | |
91 | wait++; | |
92 | else if (!strcmp(argv[i], "-D")) | |
93 | setenv("ING_SET", "set printqry"); | |
94 | else if (!strcmp(argv[i], "-n")) | |
95 | newfinger++; | |
96 | else if (file != NULL) | |
325821e4 | 97 | fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); |
469f80df | 98 | else |
99 | file = argv[i]; | |
100 | } | |
101 | ||
102 | in = fopen(file, "r"); | |
103 | if (in == NULL) { | |
104 | fprintf(stderr, "Unable to open %s for input\n", file); | |
105 | exit(1); | |
106 | } | |
107 | ||
325821e4 | 108 | setlinebuf(stdout); |
109 | setlinebuf(stderr); | |
110 | ||
469f80df | 111 | ## ingres sms |
112 | ## range of u is users | |
113 | ||
114 | while (e = get_next_entry(in)) { | |
115 | process_entry(e); | |
116 | if (wait) { | |
117 | printf("Next"); | |
118 | fflush(stdout); | |
119 | gets(buf); | |
120 | } | |
121 | } | |
122 | ||
123 | ## exit | |
124 | exit(0); | |
125 | ##} | |
126 | ||
127 | ||
128 | char *substr(buf, key) | |
129 | char *buf; | |
130 | char *key; | |
131 | { | |
132 | int l; | |
133 | ||
134 | for (l = strlen(key); *buf; buf++) | |
135 | if (!strncmp(buf, key, l)) | |
136 | return(buf); | |
137 | return(NULL); | |
138 | } | |
139 | ||
140 | ||
141 | struct entry *get_next_entry(in) | |
142 | FILE *in; | |
143 | { | |
144 | static struct entry e; | |
a6e9fead | 145 | static char buf[BUFSIZ], mid[16], eid[16], email[256]; |
146 | static char name[LEN_NAME+1], sname[LEN_NAME+1], id[LEN_ID+1]; | |
147 | static char office[LEN_OFFICE+1], phone[LEN_PHONE+1], phone2[LEN_PHONE2+1]; | |
148 | static char dept[LEN_DEPT+1], title[LEN_TITLE+1], username[LEN_USERNAME+1]; | |
149 | static char host[LEN_HOST+1]; | |
039f9637 | 150 | int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v; |
469f80df | 151 | char *p; |
152 | ||
4763be9c | 153 | if (fgets(buf, sizeof(buf), in) == NULL) |
154 | return((struct entry *)NULL); | |
a6e9fead | 155 | |
156 | strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0; | |
157 | strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0; | |
158 | strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE); office[LEN_OFFICE] = 0; | |
159 | strncpy(phone, &buf[LOC_PHONE], LEN_PHONE); phone[LEN_PHONE] = 0; | |
160 | strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2); phone2[LEN_PHONE2] = 0; | |
161 | strncpy(dept, &buf[LOC_DEPT], LEN_DEPT); dept[LEN_DEPT] = 0; | |
162 | strncpy(title, &buf[LOC_TITLE], LEN_TITLE); title[LEN_TITLE] = 0; | |
163 | strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME); username[LEN_USERNAME] = 0; | |
164 | strncpy(host, &buf[LOC_HOST], LEN_HOST); host[LEN_HOST] = 0; | |
165 | ||
166 | strcpy(sname, name); | |
167 | e.name = strtrim(sname); | |
168 | p = index(name, ','); | |
469f80df | 169 | if (p) |
170 | *p = 0; | |
a6e9fead | 171 | e.last = strtrim(name); |
469f80df | 172 | if (p) { |
a6e9fead | 173 | p++; |
174 | while (isspace(*p)) | |
175 | p++; | |
176 | e.first = p; | |
469f80df | 177 | if (p = index(e.first, ' ')) { |
178 | *p = 0; | |
a6e9fead | 179 | e.first = strtrim(e.first); |
469f80df | 180 | e.middle = strtrim(p + 1); |
a6e9fead | 181 | } else { |
182 | e.first = strtrim(e.first); | |
183 | e.middle = ""; | |
184 | } | |
185 | } else { | |
186 | e.first = ""; | |
187 | e.middle = ""; | |
188 | } | |
039f9637 | 189 | ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0; |
469f80df | 190 | LookForSt(e.last); |
191 | LookForO(e.last); | |
039f9637 | 192 | LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, |
193 | &ends_ii, &ends_v); | |
194 | LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, | |
195 | &ends_ii, &ends_v); | |
469f80df | 196 | FixCase(e.last); |
197 | FixCase(e.first); | |
198 | FixCase(e.middle); | |
199 | ||
a6e9fead | 200 | e.id = id; |
469f80df | 201 | e.eid = eid; |
202 | EncryptID(e.eid, e.id, e.first, e.last); | |
203 | ||
a6e9fead | 204 | e.address = strtrim(office); |
205 | e.phone = strtrim(phone); | |
206 | e.phone2 = strtrim(phone2); | |
207 | e.dept = strtrim(dept); | |
208 | e.title = strtrim(title); | |
469f80df | 209 | |
210 | e.class = "MITS"; | |
211 | if (!strcmp(e.dept, "PROJECT ATHENA")) | |
212 | e.class = "STAFF"; | |
e1695a1c | 213 | else if (substr(e.title, "PROF") || substr(e.title, "LECTURE")) |
469f80df | 214 | e.class = "FACULTY"; |
215 | else if (!strcmp(e.title, "VISITING SCIENTIST")) | |
216 | e.class = "VSCIENTI"; | |
217 | ||
a6e9fead | 218 | strcpy(email, strtrim(username)); |
219 | if (host[0] == '@') | |
220 | strncat(email, strtrim(host)); | |
221 | e.email = email; | |
469f80df | 222 | |
223 | return(&e); | |
224 | } | |
225 | ||
226 | ||
227 | process_entry(e) | |
228 | struct entry *e; | |
229 | ##{ | |
230 | int changed, nochange; | |
231 | char buf[BUFSIZ], *from, *to; | |
325821e4 | 232 | ## char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle; |
233 | ## char *raddr, *rhphone, *rophone; | |
a6e9fead | 234 | ## char class[9], oaddr[25], ophone[17], dept[128]; |
235 | ## int id, status; | |
469f80df | 236 | |
237 | first = e->first; | |
9e4455c2 | 238 | if (strlen(first) > 16) |
239 | first[16] = 0; | |
469f80df | 240 | last = e->last; |
9e4455c2 | 241 | if (strlen(last) > 16) |
242 | last[16] = 0; | |
469f80df | 243 | eid = e->eid; |
325821e4 | 244 | sid = e->id; |
469f80df | 245 | id = 0; |
325821e4 | 246 | |
247 | /* Get user info */ | |
469f80df | 248 | ## repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr, |
a6e9fead | 249 | ## ophone = u.office_phone, dept = u.mit_dept, status = u.#status) |
325821e4 | 250 | ## where u.#last = @last and u.#first = @first and u.mit_id = @sid |
469f80df | 251 | if (id == 0) { |
325821e4 | 252 | ## repeat retrieve (id = u.users_id, class = u.mit_year, |
253 | ## oaddr = u.office_addr, ophone = u.office_phone, | |
254 | ## dept = u.mit_dept, status = u.#status) | |
255 | ## where u.#last = @last and u.#first = @first and u.mit_id = @eid | |
256 | if (id == 0) { | |
257 | newuser(e); | |
258 | return; | |
259 | } | |
469f80df | 260 | } |
325821e4 | 261 | |
e1695a1c | 262 | if (strcmp(e->class, strtrim(class)) && |
263 | strcmp(class, "STAFF") && strcmp(class, "SIPB")) { | |
469f80df | 264 | com_err(whoami, 0, "updating class for %s %s from %s to %s", |
265 | first, last, class, e->class); | |
a6e9fead | 266 | if (status == US_NOT_ALLOWED && !strcmp(e->class, "FACULTY")) |
267 | status = US_NO_LOGIN_YET; | |
268 | if (status == US_ENROLL_NOT_ALLOWED && !strcmp(e->class, "FACULTY")) | |
269 | status = US_ENROLLED; | |
469f80df | 270 | strcpy(class, e->class); |
325821e4 | 271 | ## repeat replace u (mit_year = @class, #status = @status, |
469f80df | 272 | ## modtime = "now", modby = WHO, modwith = PROG) |
4763be9c | 273 | ## where u.users_id = @id |
469f80df | 274 | } |
325821e4 | 275 | |
469f80df | 276 | changed = nochange = 0; |
277 | strcpy(buf, e->address); | |
278 | while (to = index(buf, ',')) | |
279 | *to = ';'; | |
280 | while (to = index(buf, ':')) | |
281 | *to = ';'; | |
282 | if (newfinger) { | |
a6e9fead | 283 | if (oaddr[0] == ' ' && buf[0]) { |
469f80df | 284 | strncpy(oaddr, buf, 16); |
285 | oaddr[16] = 0; | |
286 | changed++; | |
6eb764c5 | 287 | } else if (strncmp(strtrim(oaddr), buf, 15)) |
469f80df | 288 | nochange++; |
289 | } else { | |
290 | if (strncmp(strtrim(oaddr), buf, 15)) | |
291 | changed++; | |
292 | strncpy(oaddr, buf, 16); | |
293 | oaddr[16] = 0; | |
294 | } | |
295 | from = e->phone; | |
296 | to = buf; | |
297 | while (*from) { | |
298 | if (isdigit(*from)) | |
299 | *to++ = *from; | |
300 | from++; | |
301 | } | |
302 | *to = 0; | |
303 | if (newfinger) { | |
304 | if (ophone[0] == ' ') { | |
305 | strncpy(ophone, buf, 16); | |
306 | ophone[16] = 0; | |
6eb764c5 | 307 | } else if (strncmp(strtrim(ophone), buf, 11)) |
469f80df | 308 | nochange++; |
309 | } else { | |
310 | if (strncmp(strtrim(ophone), buf, 11)) | |
311 | changed++; | |
312 | strncpy(ophone, buf, 16); | |
313 | ophone[16] = 0; | |
314 | } | |
315 | FixCase(e->dept); | |
a6e9fead | 316 | FixCase(e->title); |
469f80df | 317 | if (newfinger) { |
318 | if (dept[0] == ' ') { | |
319 | strncpy(dept, e->dept, 12); | |
320 | dept[12] = 0; | |
6eb764c5 | 321 | } else if (strncmp(strtrim(dept), e->dept, 11)) |
469f80df | 322 | nochange++; |
323 | } else { | |
324 | if (strncmp(strtrim(dept), e->dept, 11)) | |
325 | changed++; | |
326 | strncpy(dept, e->dept, 12); | |
327 | dept[12] = 0; | |
328 | } | |
325821e4 | 329 | sid = e->id; |
330 | name = e->name; | |
331 | rdept = e->dept; | |
332 | rtitle = e->title; | |
333 | raddr = e->address; | |
334 | rhphone = e->phone; | |
335 | rophone = e->phone2; | |
469f80df | 336 | if (changed) { |
337 | com_err(whoami, 0, "updating finger for %s %s", first, last); | |
325821e4 | 338 | ## repeat replace u (office_addr = @oaddr, |
469f80df | 339 | ## office_phone = @ophone, #mit_dept = @dept, |
325821e4 | 340 | ## fmodtime = "now", fmodby = WHO, fmodwith = PROG, |
341 | ## xname = @name, xdept = @rdept, xtitle = @rtitle, | |
342 | ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone, | |
343 | ## xmodtime = date("now"), mit_id = @sid) | |
344 | ## where u.users_id = @id | |
345 | } else { | |
346 | ## repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle, | |
347 | ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone, | |
348 | ## xmodtime = date("now"), mit_id = @sid) | |
469f80df | 349 | ## where u.users_id = @id |
a6e9fead | 350 | } |
469f80df | 351 | ##} |
352 | ||
353 | ||
354 | newuser(e) | |
355 | struct entry *e; | |
356 | ##{ | |
357 | char *from, *to; | |
358 | ## int id, uid, st; | |
325821e4 | 359 | ## char *last, *first, *class, *middle, login[9], *sid, fullname[65]; |
360 | ## char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17]; | |
361 | ## char *rdept, *rhphone, *rophone; | |
469f80df | 362 | |
363 | strncpy(oaddr, e->address, 16); | |
a6e9fead | 364 | oaddr[16] = 0; |
469f80df | 365 | while (to = index(oaddr, ',')) |
366 | *to = ';'; | |
367 | while (to = index(oaddr, ':')) | |
368 | *to = ';'; | |
369 | from = e->phone; | |
370 | to = ophone; | |
371 | while (*from) { | |
372 | if (isdigit(*from)) | |
373 | *to++ = *from; | |
374 | from++; | |
375 | } | |
376 | *to = 0; | |
a6e9fead | 377 | FixCase(e->dept); |
469f80df | 378 | strncpy(dept, e->dept, 12); |
a6e9fead | 379 | dept[12] = 0; |
469f80df | 380 | |
27736587 | 381 | id = set_next_object_id("users_id", 0); |
382 | uid = set_next_object_id("uid", 1); | |
469f80df | 383 | sprintf(login, "#%d", uid); |
384 | last = e->last; | |
385 | first = e->first; | |
386 | middle = e->middle; | |
469f80df | 387 | class = e->class; |
388 | if (*middle) | |
389 | sprintf(fullname, "%s %s %s", first, middle, last); | |
390 | else | |
391 | sprintf(fullname, "%s %s", first, last); | |
392 | st = US_NOT_ALLOWED; | |
e1695a1c | 393 | if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF")) |
469f80df | 394 | st = US_NO_LOGIN_YET; |
325821e4 | 395 | |
396 | sid = e->id; | |
397 | name = e->name; | |
398 | rdept = e->dept; | |
399 | title = e->title; | |
400 | rhphone = e->phone; | |
401 | rophone = e->phone2; | |
402 | ||
403 | ||
469f80df | 404 | ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh", |
405 | ## #last = last, #first = first, #middle = middle, status = st, | |
325821e4 | 406 | ## #mit_id = sid, #mit_year = class, |
469f80df | 407 | ## modtime = "now", modby = WHO, modwith = PROG, |
408 | ## #fullname = fullname, office_addr = oaddr, | |
409 | ## office_phone = ophone, #mit_dept = dept, | |
410 | ## fmodtime = "now", fmodby = WHO, fmodwith = PROG, | |
325821e4 | 411 | ## potype = "NONE", |
412 | ## xname = name, xdept = rdept, xtitle = title, | |
413 | ## xaddress = oaddr, xphone1 = rhphone, xphone2 = rophone, | |
414 | ## xmodtime = date("now")) | |
a6e9fead | 415 | |
469f80df | 416 | ##} |
417 | ||
418 | ||
27736587 | 419 | set_next_object_id(object, limit) |
469f80df | 420 | char *object; |
27736587 | 421 | int limit; |
469f80df | 422 | ##{ |
423 | ## char *name; | |
424 | ## int rowcount, exists, value; | |
425 | ||
426 | name = object; | |
427 | ## begin transaction | |
428 | ## repeat retrieve (value = values.#value) where values.#name = @name | |
429 | ## inquire_equel(rowcount = "rowcount") | |
430 | if (rowcount != 1) { | |
431 | ## abort | |
432 | return(0); | |
433 | } | |
434 | ||
435 | ## retrieve (exists = any(users.name where users.name = value)) | |
436 | ## inquire_equel(rowcount = "rowcount") | |
437 | if (rowcount != 1) { | |
438 | ## abort | |
439 | return(0); | |
440 | } | |
441 | while (exists) { | |
442 | value++; | |
27736587 | 443 | if (limit && value > MAX_ID_VALUE) |
469f80df | 444 | value = MIN_ID_VALUE; |
445 | ## retrieve (exists = any(users.name where users.name = value)) | |
446 | } | |
447 | ||
448 | ## repeat replace values (#value = @value) where values.#name = @name | |
449 | ## end transaction | |
450 | return(value); | |
451 | ##} |