]>
Commit | Line | Data |
---|---|---|
093c49c9 | 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> | |
093c49c9 | 10 | |
11 | ||
5e2b5b5f | 12 | ##define WHO 11859 /* root */ |
13 | ##define PROG "stu-tape" | |
14 | ||
397e9044 | 15 | #define MAX_ID_VALUE 31999 |
5e2b5b5f | 16 | #define MIN_ID_VALUE 101 |
17 | ||
093c49c9 | 18 | /* File format is: |
19 | ||
20 | 0-29 name | |
21 | 30-38 id number | |
22 | 50-54 school code | |
23 | 55-79 year | |
24 | 80-109 address | |
25 | 110-124 room | |
26 | 125-144 city | |
27 | 145-158 state | |
28 | 159-168 dorm phone | |
29 | 169-212 home address | |
30 | 213-232 home city | |
31 | 243-251 mit phone (?) | |
32 | */ | |
33 | ||
34 | #define LOC_NAME 0 | |
35 | #define LOC_ID 30 | |
36 | #define LOC_COURSE 50 | |
37 | #define LOC_YEAR 55 | |
38 | #define LOC_ADDRESS 80 | |
39 | #define LOC_DORM_ROOM 110 | |
40 | #define LOC_CITY 125 | |
41 | #define LOC_STATE 145 | |
c48e3c93 | 42 | #define LOC_DPHONE 155 |
e3c8ca24 | 43 | #define LOC_MPHONE 243 |
093c49c9 | 44 | |
e3c8ca24 | 45 | #define LEN_NAME 30 |
093c49c9 | 46 | #define LEN_ID 9 |
e3c8ca24 | 47 | #define LEN_COURSE 5 |
48 | #define LEN_YEAR 25 | |
49 | #define LEN_ADDRESS 30 | |
50 | #define LEN_DORM_ROOM 15 | |
51 | #define LEN_CITY 20 | |
c48e3c93 | 52 | #define LEN_STATE 10 |
53 | #define LEN_DPHONE 12 | |
54 | #define LEN_MPHONE 12 | |
093c49c9 | 55 | |
56 | struct entry { | |
e3c8ca24 | 57 | char *name; |
093c49c9 | 58 | char *last; |
59 | char *first; | |
60 | char *middle; | |
61 | char *title; | |
62 | char *id; | |
63 | char *eid; | |
64 | char *course; | |
65 | char *year; | |
66 | char *address; | |
67 | char *dorm; | |
68 | char *city; | |
69 | char *state; | |
70 | char *dphone; | |
71 | char *mphone; | |
72 | char *class; | |
093c49c9 | 73 | }; |
74 | ||
75 | ||
76 | char *whoami; | |
a97bc039 | 77 | int newfinger = 0; |
093c49c9 | 78 | |
79 | ||
80 | main(argc, argv) | |
81 | int argc; | |
82 | char **argv; | |
5e2b5b5f | 83 | ##{ |
093c49c9 | 84 | FILE *in; |
85 | struct entry *e, *get_next_entry(); | |
a97bc039 | 86 | int i, wait = 0; |
87 | char buf[BUFSIZ], *file = NULL; | |
093c49c9 | 88 | |
89 | whoami = rindex(argv[0], '/'); | |
90 | if (whoami) | |
91 | whoami++; | |
92 | else | |
93 | whoami = argv[0]; | |
94 | ||
a97bc039 | 95 | for (i = 1; i < argc; i++) { |
96 | if (!strcmp(argv[i], "-w")) | |
97 | wait++; | |
98 | else if (!strcmp(argv[i], "-D")) | |
99 | setenv("ING_SET", "set printqry"); | |
100 | else if (!strcmp(argv[i], "-n")) | |
101 | newfinger++; | |
102 | else if (file != NULL) | |
dcd4e696 | 103 | fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); |
a97bc039 | 104 | else |
105 | file = argv[i]; | |
106 | } | |
093c49c9 | 107 | |
a97bc039 | 108 | in = fopen(file, "r"); |
093c49c9 | 109 | if (in == NULL) { |
a97bc039 | 110 | fprintf(stderr, "Unable to open %s for input\n", file); |
093c49c9 | 111 | exit(1); |
112 | } | |
113 | ||
dcd4e696 | 114 | setlinebuf(stdout); |
115 | setlinebuf(stderr); | |
116 | ||
5e2b5b5f | 117 | ## ingres sms |
118 | ## range of u is users | |
119 | ||
093c49c9 | 120 | while (e = get_next_entry(in)) { |
121 | process_entry(e); | |
122 | if (wait) { | |
123 | printf("Next"); | |
124 | fflush(stdout); | |
125 | gets(buf); | |
126 | } | |
127 | } | |
128 | ||
5e2b5b5f | 129 | ## exit |
093c49c9 | 130 | exit(0); |
5e2b5b5f | 131 | ##} |
093c49c9 | 132 | |
133 | ||
134 | struct entry *get_next_entry(in) | |
135 | FILE *in; | |
136 | { | |
137 | static struct entry e; | |
138 | static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12]; | |
e3c8ca24 | 139 | static char name[LEN_NAME+1], id[LEN_ID+1], course[LEN_COURSE+1]; |
140 | static char year[LEN_YEAR+1], address[LEN_ADDRESS+1]; | |
141 | static char dorm_room[LEN_DORM_ROOM+1], city[LEN_CITY+1]; | |
142 | static char state[LEN_STATE+1], dphone[LEN_DPHONE+1], mphone[LEN_MPHONE+1]; | |
143 | static char sname[LEN_NAME+1], title[128]; | |
144 | static int nyear = 0; | |
039f9637 | 145 | int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v; |
093c49c9 | 146 | char *p; |
147 | ||
e3c8ca24 | 148 | if (nyear == 0) { |
093c49c9 | 149 | struct tm *tm; |
150 | struct timeval tv; | |
151 | ||
152 | gettimeofday(&tv, NULL); | |
153 | tm = localtime(&tv.tv_sec); | |
e3c8ca24 | 154 | nyear = tm->tm_year; |
093c49c9 | 155 | if (tm->tm_mon > 5) |
e3c8ca24 | 156 | nyear++; |
093c49c9 | 157 | } |
158 | ||
22a6d0dc | 159 | if (fgets(buf, sizeof(buf), in) == NULL) |
160 | return((struct entry *)NULL); | |
e3c8ca24 | 161 | |
162 | strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0; | |
163 | strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0; | |
164 | strncpy(course, &buf[LOC_COURSE], LEN_COURSE); course[LEN_COURSE] = 0; | |
165 | strncpy(year, &buf[LOC_YEAR], LEN_YEAR); year[LEN_YEAR] = 0; | |
166 | strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); address[LEN_ADDRESS] = 0; | |
167 | strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); dorm_room[LEN_DORM_ROOM] = 0; | |
168 | strncpy(city, &buf[LOC_CITY], LEN_CITY); city[LEN_CITY] = 0; | |
169 | strncpy(state, &buf[LOC_STATE], LEN_STATE); state[LEN_STATE] = 0; | |
170 | strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); dphone[LEN_DPHONE] = 0; | |
171 | strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); mphone[LEN_MPHONE] = 0; | |
172 | ||
173 | strcpy(sname, name); | |
174 | e.name = strtrim(sname); | |
175 | p = index(name, ','); | |
093c49c9 | 176 | if (p) |
177 | *p = 0; | |
e3c8ca24 | 178 | e.last = strtrim(name); |
093c49c9 | 179 | if (p) { |
e3c8ca24 | 180 | p++; |
181 | while (isspace(*p)) | |
182 | p++; | |
183 | e.first = p; | |
093c49c9 | 184 | if (p = index(e.first, ' ')) { |
185 | *p = 0; | |
e3c8ca24 | 186 | e.first = strtrim(e.first); |
093c49c9 | 187 | e.middle = strtrim(p + 1); |
6d6c60e6 | 188 | } else { |
189 | e.first = strtrim(e.first); | |
190 | e.middle = ""; | |
191 | } | |
e3c8ca24 | 192 | } else { |
193 | e.first = ""; | |
194 | e.middle = ""; | |
195 | } | |
039f9637 | 196 | ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0; |
093c49c9 | 197 | LookForSt(e.last); |
198 | LookForO(e.last); | |
039f9637 | 199 | LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, |
200 | &ends_ii, &ends_v); | |
201 | LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, | |
202 | &ends_ii, &ends_v); | |
093c49c9 | 203 | FixCase(e.last); |
204 | FixCase(e.first); | |
205 | FixCase(e.middle); | |
093c49c9 | 206 | |
e3c8ca24 | 207 | e.id = id; |
093c49c9 | 208 | e.id[LEN_ID] = 0; |
209 | e.eid = eid; | |
210 | EncryptID(e.eid, e.id, e.first, e.last); | |
211 | ||
e3c8ca24 | 212 | e.year = strtrim(year); |
213 | e.title = title; | |
214 | if (e.year[0] == 'G') { | |
215 | e.class = "G"; | |
216 | sprintf(title, "Grad Student"); | |
217 | } else { | |
093c49c9 | 218 | e.class = classbuf; |
e3c8ca24 | 219 | sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900); |
220 | sprintf(title, "Undergrad (class of %s)", classbuf); | |
093c49c9 | 221 | } |
e3c8ca24 | 222 | |
223 | e.course = strtrim(course); | |
224 | e.address = strtrim(address); | |
225 | e.dorm = strtrim(dorm_room); | |
226 | e.city = strtrim(city); | |
227 | e.state = strtrim(state); | |
228 | e.dphone = strtrim(dphone); | |
229 | e.mphone = strtrim(mphone); | |
093c49c9 | 230 | return(&e); |
231 | } | |
232 | ||
233 | ||
093c49c9 | 234 | process_entry(e) |
235 | struct entry *e; | |
5e2b5b5f | 236 | ##{ |
c48e3c93 | 237 | int changed, nochange, encrypted; |
5e2b5b5f | 238 | char buf[BUFSIZ], *from, *to; |
c48e3c93 | 239 | ## char *first, *last, *eid, *title, *sid, *name, *rname, *rdept, *rtitle; |
240 | ## char *rophone, *rhphone; | |
241 | ## char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128]; | |
e3c8ca24 | 242 | ## int id, status; |
5e2b5b5f | 243 | |
244 | first = e->first; | |
9e4455c2 | 245 | if (strlen(first) > 16) |
246 | first[16] = 0; | |
5e2b5b5f | 247 | last = e->last; |
9e4455c2 | 248 | if (strlen(last) > 16) |
249 | last[16] = 0; | |
5e2b5b5f | 250 | eid = e->eid; |
c48e3c93 | 251 | sid = e->id; |
5e2b5b5f | 252 | id = 0; |
c48e3c93 | 253 | encrypted = 0; |
254 | ||
255 | /* Get user info */ | |
5e2b5b5f | 256 | ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr, |
257 | ## hphone = u.home_phone, ophone = u.office_phone, | |
e3c8ca24 | 258 | ## status = u.#status, dept = u.mit_dept) |
c48e3c93 | 259 | ## where u.#last = @last and u.#first = @first and u.mit_id = @sid |
5e2b5b5f | 260 | if (id == 0) { |
c48e3c93 | 261 | ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr, |
262 | ## hphone = u.home_phone, ophone = u.office_phone, | |
263 | ## status = u.#status, dept = u.mit_dept) | |
264 | ## where u.#last = @last and u.#first = @first and u.mit_id = @eid | |
265 | encrypted++; | |
266 | if (id == 0) { | |
267 | newuser(e); | |
268 | return; | |
269 | } | |
093c49c9 | 270 | } |
c48e3c93 | 271 | |
272 | /* See if class changed: if it's different, and the value in the database | |
273 | * is not STAFF or SIPB, then update the database. Since they were on the | |
274 | * students tape, make the account usable. | |
275 | */ | |
a262e022 | 276 | if (strcmp(e->class, strtrim(class)) && |
277 | strcmp(class, "STAFF") && strcmp(class, "SIPB")) { | |
a97bc039 | 278 | com_err(whoami, 0, "updating class for user %s %s from %s to %s", |
279 | first, last, class, e->class); | |
e3c8ca24 | 280 | if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET; |
281 | if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED; | |
5e2b5b5f | 282 | strcpy(class, e->class); |
c48e3c93 | 283 | ## repeat replace u (mit_year = @class, #status = @status, |
5e2b5b5f | 284 | ## modtime = "now", modby = WHO, modwith = PROG) |
fac211e8 | 285 | ## where u.users_id = @id |
093c49c9 | 286 | } |
c48e3c93 | 287 | |
288 | /* Deal with updating the finger info if necessary */ | |
289 | ||
a97bc039 | 290 | changed = nochange = 0; |
e3c8ca24 | 291 | strcpy(buf, e->address); |
093c49c9 | 292 | if (*e->dorm) { |
293 | strcat(buf, " "); | |
5e2b5b5f | 294 | strcat(buf, e->dorm); |
093c49c9 | 295 | } |
296 | if (*e->city) { | |
297 | strcat(buf, " "); | |
5e2b5b5f | 298 | strcat(buf, e->city); |
093c49c9 | 299 | } |
5e2b5b5f | 300 | FixCase(buf); |
093c49c9 | 301 | if (*e->state) { |
302 | strcat(buf, " "); | |
5e2b5b5f | 303 | strcat(buf, e->state); |
093c49c9 | 304 | } |
5e2b5b5f | 305 | while (to = index(buf, ',')) |
306 | *to = ';'; | |
307 | while (to = index(buf, ':')) | |
308 | *to = ';'; | |
a97bc039 | 309 | if (newfinger) { |
310 | if (haddr[0] == ' ') { | |
311 | strncpy(haddr, buf, 80); | |
312 | haddr[80] = 0; | |
313 | changed++; | |
314 | } else if (strncmp(strtrim(haddr), buf, 80)) | |
315 | nochange++; | |
316 | } else { | |
317 | if (strncmp(strtrim(haddr), buf, 80)) | |
318 | changed++; | |
5e2b5b5f | 319 | strncpy(haddr, buf, 80); |
a97bc039 | 320 | haddr[80] = 0; |
093c49c9 | 321 | } |
322 | from = e->dphone; | |
323 | to = buf; | |
324 | while (*from) { | |
325 | if (isdigit(*from)) | |
326 | *to++ = *from; | |
327 | from++; | |
328 | } | |
329 | *to = 0; | |
a97bc039 | 330 | if (newfinger) { |
331 | if (hphone[0] == ' ') { | |
332 | strncpy(hphone, buf, 16); | |
333 | hphone[16] = 0; | |
334 | } else if (strncmp(strtrim(hphone), buf, 16)) | |
335 | nochange++; | |
336 | } else { | |
337 | if (strncmp(strtrim(hphone), buf, 16)) | |
338 | changed++; | |
5e2b5b5f | 339 | strncpy(hphone, buf, 16); |
a97bc039 | 340 | hphone[16] = 0; |
093c49c9 | 341 | } |
342 | from = e->mphone; | |
343 | to = buf; | |
344 | while (*from) { | |
345 | if (isdigit(*from)) | |
346 | *to++ = *from; | |
347 | from++; | |
348 | } | |
349 | *to = 0; | |
a97bc039 | 350 | if (newfinger) { |
351 | if (ophone[0] == ' ') { | |
352 | strncpy(ophone, buf, 12); | |
353 | ophone[12] = 0; | |
354 | } else if (strncmp(strtrim(ophone), buf, 12)) | |
355 | nochange++; | |
356 | } else { | |
357 | if (strncmp(strtrim(ophone), buf, 12)) | |
358 | changed++; | |
5e2b5b5f | 359 | strncpy(ophone, buf, 12); |
a97bc039 | 360 | ophone[12] = 0; |
093c49c9 | 361 | } |
e3c8ca24 | 362 | e->course = e->course; |
a97bc039 | 363 | if (newfinger) { |
364 | if (dept[0] == ' ') { | |
365 | strncpy(dept, e->course, 12); | |
366 | dept[12] = 0; | |
367 | } else if (strncmp(strtrim(dept), e->course, 11)) | |
368 | nochange++; | |
369 | } else { | |
370 | if (strncmp(strtrim(dept), e->course, 11)) | |
371 | changed++; | |
5e2b5b5f | 372 | strncpy(dept, e->course, 12); |
a97bc039 | 373 | dept[12] = 0; |
093c49c9 | 374 | } |
c48e3c93 | 375 | sid = e->id; |
376 | name = e->name; | |
377 | rdept = e->course; | |
378 | rtitle = e->title; | |
379 | rophone = e->mphone; | |
380 | rhphone = e->dphone; | |
381 | strcpy(raddr, e->address); | |
382 | if (*e->dorm) { | |
383 | strcat(raddr, " "); | |
384 | strcat(raddr, e->dorm); | |
385 | } | |
386 | if (*e->city) { | |
387 | strcat(raddr, " "); | |
388 | strcat(raddr, e->city); | |
389 | } | |
390 | FixCase(raddr); | |
391 | if (*e->state) { | |
392 | strcat(raddr, " "); | |
393 | strcat(raddr, e->state); | |
394 | } | |
093c49c9 | 395 | if (changed) { |
5e2b5b5f | 396 | com_err(whoami, 0, "updating finger for %s %s", first, last); |
397 | ## repeat replace u (home_addr = @haddr, home_phone = @hphone, | |
c48e3c93 | 398 | ## office_phone = @ophone, #mit_dept = @dept, |
399 | ## fmodtime = "now", fmodby = WHO, fmodwith = PROG, | |
400 | ## xname = @name, xdept = @rdept, xtitle = @rtitle, | |
401 | ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone, | |
402 | ## xmodtime = date("now"), mit_id = @sid) | |
403 | ## where u.users_id = @id | |
404 | } else { | |
405 | ## repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle, | |
406 | ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone, | |
407 | ## xmodtime = date("now"), mit_id = @sid) | |
5e2b5b5f | 408 | ## where u.users_id = @id |
e3c8ca24 | 409 | } |
5e2b5b5f | 410 | ##} |
093c49c9 | 411 | |
5e2b5b5f | 412 | |
413 | newuser(e) | |
093c49c9 | 414 | struct entry *e; |
5e2b5b5f | 415 | ##{ |
416 | char buf[512], *from, *to; | |
417 | ## int id, uid; | |
c48e3c93 | 418 | ## char *last, *first, *class, *middle, login[9], *sid, fullname[65]; |
419 | ## char haddr[81], hphone[17], ophone[13], dept[24], *title; | |
5e2b5b5f | 420 | |
421 | ||
e3c8ca24 | 422 | strcpy(buf, e->address); |
5e2b5b5f | 423 | if (*e->dorm) { |
424 | strcat(buf, " "); | |
e3c8ca24 | 425 | strcat(buf, e->dorm); |
5e2b5b5f | 426 | } |
427 | if (*e->city) { | |
428 | strcat(buf, " "); | |
e3c8ca24 | 429 | strcat(buf, e->city); |
5e2b5b5f | 430 | } |
431 | if (*e->state) { | |
432 | strcat(buf, " "); | |
e3c8ca24 | 433 | strcat(buf, e->state); |
5e2b5b5f | 434 | } |
435 | strncpy(haddr, buf, 80); | |
436 | from = e->dphone; | |
437 | to = buf; | |
438 | while (*from) { | |
439 | if (isdigit(*from)) | |
440 | *to++ = *from; | |
441 | from++; | |
442 | } | |
443 | *to = 0; | |
444 | strncpy(hphone, buf, 16); | |
445 | from = e->mphone; | |
446 | to = buf; | |
447 | while (*from) { | |
448 | if (isdigit(*from)) | |
449 | *to++ = *from; | |
450 | from++; | |
451 | } | |
452 | *to = 0; | |
453 | strncpy(ophone, buf, 12); | |
5e2b5b5f | 454 | strncpy(dept, e->course, 12); |
5e2b5b5f | 455 | |
27736587 | 456 | id = set_next_object_id("users_id", 0); |
457 | uid = set_next_object_id("uid", 1); | |
5e2b5b5f | 458 | sprintf(login, "#%d", uid); |
459 | last = e->last; | |
460 | first = e->first; | |
461 | middle = e->middle; | |
c48e3c93 | 462 | sid = e->id; |
5e2b5b5f | 463 | class = e->class; |
c48e3c93 | 464 | title = e->title; |
5e2b5b5f | 465 | if (*middle) |
466 | sprintf(fullname, "%s %s %s", first, middle, last); | |
467 | else | |
468 | sprintf(fullname, "%s %s", first, last); | |
469 | ||
470 | ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh", | |
471 | ## #last = last, #first = first, #middle = middle, status = 0, | |
c48e3c93 | 472 | ## #mit_id = sid, #mit_year = class, |
5e2b5b5f | 473 | ## modtime = "now", modby = WHO, modwith = PROG, |
474 | ## #fullname = fullname, home_addr = haddr, home_phone = hphone, | |
475 | ## office_phone = ophone, #mit_dept = dept, | |
476 | ## fmodtime = "now", fmodby = WHO, fmodwith = PROG, | |
c48e3c93 | 477 | ## potype = "NONE", |
478 | ## xname = fullname, xdept = dept, xtitle = title, | |
479 | ## xaddress = haddr, xphone1 = hphone, xphone2 = ophone, | |
480 | ## xmodtime = date("now")) | |
e3c8ca24 | 481 | |
093c49c9 | 482 | com_err(whoami, 0, "adding user %s %s", e->first, e->last); |
5e2b5b5f | 483 | ##} |
484 | ||
485 | ||
27736587 | 486 | set_next_object_id(object, limit) |
5e2b5b5f | 487 | char *object; |
27736587 | 488 | int limit; |
5e2b5b5f | 489 | ##{ |
490 | ## char *name; | |
491 | ## int rowcount, exists, value; | |
492 | ||
493 | name = object; | |
494 | ## begin transaction | |
495 | ## repeat retrieve (value = values.#value) where values.#name = @name | |
496 | ## inquire_equel(rowcount = "rowcount") | |
497 | if (rowcount != 1) { | |
498 | ## abort | |
499 | return(0); | |
093c49c9 | 500 | } |
5e2b5b5f | 501 | |
502 | ## retrieve (exists = any(users.name where users.name = value)) | |
503 | ## inquire_equel(rowcount = "rowcount") | |
504 | if (rowcount != 1) { | |
505 | ## abort | |
506 | return(0); | |
507 | } | |
508 | while (exists) { | |
509 | value++; | |
27736587 | 510 | if (limit && value > MAX_ID_VALUE) |
5e2b5b5f | 511 | value = MIN_ID_VALUE; |
512 | ## retrieve (exists = any(users.name where users.name = value)) | |
513 | } | |
514 | ||
515 | ## repeat replace values (#value = @value) where values.#name = @name | |
516 | ## end transaction | |
517 | return(value); | |
518 | ##} | |
519 | ||
520 |