9 #include <moira_site.h>
10 EXEC SQL INCLUDE sqlca;
13 #define WHO 11859 /* root */
14 #define PROG "stu-tape"
16 #define MAX_ID_VALUE 31999
17 #define MIN_ID_VALUE 101
39 #define LOC_ADDRESS 80
40 #define LOC_DORM_ROOM 110
43 #define LOC_DPHONE 155
44 #define LOC_MPHONE 243
50 #define LEN_ADDRESS 30
51 #define LEN_DORM_ROOM 15
86 struct entry *e, *get_next_entry();
88 char buf[BUFSIZ], *file = NULL;
90 whoami = rindex(argv[0], '/');
96 for (i = 1; i < argc; i++) {
97 if (!strcmp(argv[i], "-w"))
99 else if (!strcmp(argv[i], "-D"))
100 setenv("ING_SET", "set printqry");
101 else if (!strcmp(argv[i], "-n"))
103 else if (file != NULL)
104 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
109 in = fopen(file, "r");
111 fprintf(stderr, "Unable to open %s for input\n", file);
118 EXEC SQL CONNECT moira;
120 while (e = get_next_entry(in)) {
134 struct entry *get_next_entry(in)
137 static struct entry e;
138 static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
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;
145 int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v;
152 gettimeofday(&tv, NULL);
153 tm = localtime(&tv.tv_sec);
159 if (fgets(buf, sizeof(buf), in) == NULL)
160 return((struct entry *)NULL);
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;
174 e.name = strtrim(sname);
175 p = index(name, ',');
178 e.last = strtrim(name);
184 if (p = index(e.first, ' ')) {
186 e.first = strtrim(e.first);
187 e.middle = strtrim(p + 1);
189 e.first = strtrim(e.first);
196 ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0;
199 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
201 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
210 EncryptID(e.eid, e.id, e.first, e.last);
212 e.year = strtrim(year);
214 if (e.year[0] == 'G') {
216 sprintf(title, "Grad Student");
219 sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900);
220 sprintf(title, "Undergrad (class of %s)", classbuf);
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);
237 int changed, nochange, encrypted;
238 char buf[BUFSIZ], *from, *to;
239 EXEC SQL BEGIN DECLARE SECTION;
240 char *first, *last, *eid, *title, *sid, *name, *rname, *rdept, *rtitle;
241 char *rophone, *rhphone;
242 char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128];
244 EXEC SQL END DECLARE SECTION;
247 if (strlen(first) > 16)
250 if (strlen(last) > 16)
258 EXEC SQL SELECT users_id, type, home_addr, home_phone, office_phone, status, department
259 INTO :id, :class, :haddr, :hphone, :ophone, :status, :dept
261 WHERE last = :last and first = :first and clearid = :sid;
263 EXEC SQL SELECT users_id, type, home_addr, home_phone, office_phone, status, department
264 INTO :id, :class, :haddr, :hphone, :ophone, :status, :dept
266 WHERE last = :last and first = :first and clearid = :eid;
274 /* See if class changed: if it's different, and the value in the database
275 * is not STAFF or SIPB, then update the database. Since they were on the
276 * students tape, make the account usable.
278 if (strcmp(e->class, strtrim(class)) &&
279 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
280 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
281 first, last, class, e->class);
282 if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
283 if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
284 strcpy(class, e->class);
285 EXEC SQL UPDATE users
286 SET type = :class, status = :status, modtime = 'now',
287 modby = WHO, modwith = PROG
288 WHERE users_id = :id;
291 /* Deal with updating the finger info if necessary */
293 changed = nochange = 0;
294 strcpy(buf, e->address);
297 strcat(buf, e->dorm);
301 strcat(buf, e->city);
306 strcat(buf, e->state);
308 while (to = index(buf, ','))
310 while (to = index(buf, ':'))
313 if (haddr[0] == ' ') {
314 strncpy(haddr, buf, 80);
317 } else if (strncmp(strtrim(haddr), buf, 80))
320 if (strncmp(strtrim(haddr), buf, 80))
322 strncpy(haddr, buf, 80);
334 if (hphone[0] == ' ') {
335 strncpy(hphone, buf, 16);
337 } else if (strncmp(strtrim(hphone), buf, 16))
340 if (strncmp(strtrim(hphone), buf, 16))
342 strncpy(hphone, buf, 16);
354 if (ophone[0] == ' ') {
355 strncpy(ophone, buf, 12);
357 } else if (strncmp(strtrim(ophone), buf, 12))
360 if (strncmp(strtrim(ophone), buf, 12))
362 strncpy(ophone, buf, 12);
365 e->course = e->course;
367 if (dept[0] == ' ') {
368 strncpy(dept, e->course, 12);
370 } else if (strncmp(strtrim(dept), e->course, 11))
373 if (strncmp(strtrim(dept), e->course, 11))
375 strncpy(dept, e->course, 12);
384 strcpy(raddr, e->address);
387 strcat(raddr, e->dorm);
391 strcat(raddr, e->city);
395 if (isupper(e->state[0]) && isupper(e->state[1]) &&
396 isdigit(e->state[2]) && isdigit(e->state[3]) &&
397 isdigit(e->state[4]) && isdigit(e->state[5]) &&
398 isdigit(e->state[6])) {
399 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
403 strcat(raddr, e->state);
407 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
410 com_err(whoami, 0, "updating finger for %s %s", first, last);
411 EXEC SQL REPEATED UPDATE users
412 SET home_addr = :haddr, home_phone = :hphone,
413 office_phone = :ophone, department = :dept,
414 fmodtime = 'now', fmodby = WHO, fmodwith = PROG,
415 xname = :name, xdept = :rdept, xtitle = :rtitle,
416 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
417 xmodtime = date('now'), clearid = :sid
418 WHERE users_id = :id;
420 EXEC SQL REPEATED UPDATE users
421 SET xname = :name, xdept = :rdept, xtitle = :rtitle,
422 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
423 xmodtime = date('now'), clearid = :sid
424 WHERE users_id = :id;
432 char buf[512], *from, *to;
433 EXEC SQL BEGIN DECLARE SECTION;
435 char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
436 char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name;
437 EXEC SQL END DECLARE SECTION;
441 strcpy(buf, e->address);
444 strcat(buf, e->dorm);
448 strcat(buf, e->city);
452 strcat(buf, e->state);
454 strncpy(haddr, buf, 80);
463 strncpy(hphone, buf, 16);
472 strncpy(ophone, buf, 12);
473 strncpy(dept, e->course, 12);
475 id = set_next_object_id("users_id", 0);
476 uid = set_next_object_id("uid", 1);
477 sprintf(login, "#%d", uid);
485 sprintf(fullname, "%s %s %s", first, middle, last);
487 sprintf(fullname, "%s %s", first, last);
489 strcpy(raddr, e->address);
492 strcat(raddr, e->dorm);
496 strcat(raddr, e->city);
500 if (isupper(e->state[0]) && isupper(e->state[1]) &&
501 isdigit(e->state[2]) && isdigit(e->state[3]) &&
502 isdigit(e->state[4]) && isdigit(e->state[5]) &&
503 isdigit(e->state[6])) {
504 sprintf(buf, "%c%c %s", e->state[0],e->state[1],
508 strcat(raddr, e->state);
512 strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
514 EXEC SQL INSERT INTO users
515 (login, users_id, uid, shell, last, first, middle, status,
516 clearid, type, modtime, modby, modwith, fullname, home_addr,
517 home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
518 potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
519 VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, 0,
520 :sid, :class, 'now', :who, :prog, :fullname, :haddr, :hphone,
521 :ophone, :dept, 'now', :who, :prog, 'NONE', :name, :dept,
522 :title, :raddr, :hphone, :ophone, date('now'));
523 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
527 set_next_object_id(object, limit)
531 EXEC SQL BEGIN DECLARE SECTION;
533 int rowcount, flag, value;
534 EXEC SQL END DECLARE SECTION;
537 EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :name;
538 if (sqlca.sqlerrd[2] != 1) {
540 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
545 EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
546 if (sqlca.sqlerrd[2] == 0)
550 if (limit && value > MAX_ID_VALUE)
551 value = MIN_ID_VALUE;
553 EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
554 if (sqlca.sqlerrd[2] == 0)
559 if (limit && value > MAX_ID_VALUE)
560 value = MIN_ID_VALUE;
561 EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = :name;