9 #include <moira_site.h>
12 ##define WHO 11859 /* root */
13 ##define PROG "stu-tape"
15 #define MAX_ID_VALUE 31999
16 #define MIN_ID_VALUE 101
38 #define LOC_ADDRESS 80
39 #define LOC_DORM_ROOM 110
42 #define LOC_DPHONE 155
43 #define LOC_MPHONE 243
49 #define LEN_ADDRESS 30
50 #define LEN_DORM_ROOM 15
85 struct entry *e, *get_next_entry();
87 char buf[BUFSIZ], *file = NULL;
89 whoami = rindex(argv[0], '/');
95 for (i = 1; i < argc; i++) {
96 if (!strcmp(argv[i], "-w"))
98 else if (!strcmp(argv[i], "-D"))
99 setenv("ING_SET", "set printqry");
100 else if (!strcmp(argv[i], "-n"))
102 else if (file != NULL)
103 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
108 in = fopen(file, "r");
110 fprintf(stderr, "Unable to open %s for input\n", file);
118 ## range of u is users
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 ## 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];
245 if (strlen(first) > 16)
248 if (strlen(last) > 16)
256 ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr,
257 ## hphone = u.home_phone, ophone = u.office_phone,
258 ## status = u.#status, dept = u.mit_dept)
259 ## where u.#last = @last and u.#first = @first and u.mit_id = @sid
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
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.
276 if (strcmp(e->class, strtrim(class)) &&
277 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
278 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
279 first, last, class, e->class);
280 if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
281 if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
282 strcpy(class, e->class);
283 ## repeat replace u (mit_year = @class, #status = @status,
284 ## modtime = "now", modby = WHO, modwith = PROG)
285 ## where u.users_id = @id
288 /* Deal with updating the finger info if necessary */
290 changed = nochange = 0;
291 strcpy(buf, e->address);
294 strcat(buf, e->dorm);
298 strcat(buf, e->city);
303 strcat(buf, e->state);
305 while (to = index(buf, ','))
307 while (to = index(buf, ':'))
310 if (haddr[0] == ' ') {
311 strncpy(haddr, buf, 80);
314 } else if (strncmp(strtrim(haddr), buf, 80))
317 if (strncmp(strtrim(haddr), buf, 80))
319 strncpy(haddr, buf, 80);
331 if (hphone[0] == ' ') {
332 strncpy(hphone, buf, 16);
334 } else if (strncmp(strtrim(hphone), buf, 16))
337 if (strncmp(strtrim(hphone), buf, 16))
339 strncpy(hphone, buf, 16);
351 if (ophone[0] == ' ') {
352 strncpy(ophone, buf, 12);
354 } else if (strncmp(strtrim(ophone), buf, 12))
357 if (strncmp(strtrim(ophone), buf, 12))
359 strncpy(ophone, buf, 12);
362 e->course = e->course;
364 if (dept[0] == ' ') {
365 strncpy(dept, e->course, 12);
367 } else if (strncmp(strtrim(dept), e->course, 11))
370 if (strncmp(strtrim(dept), e->course, 11))
372 strncpy(dept, e->course, 12);
381 strcpy(raddr, e->address);
384 strcat(raddr, e->dorm);
388 strcat(raddr, e->city);
393 strcat(raddr, e->state);
396 com_err(whoami, 0, "updating finger for %s %s", first, last);
397 ## repeat replace u (home_addr = @haddr, home_phone = @hphone,
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
405 ## repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle,
406 ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
407 ## xmodtime = date("now"), mit_id = @sid)
408 ## where u.users_id = @id
416 char buf[512], *from, *to;
418 ## char *last, *first, *class, *middle, login[9], *sid, fullname[65];
419 ## char haddr[81], hphone[17], ophone[13], dept[24], *title;
422 strcpy(buf, e->address);
425 strcat(buf, e->dorm);
429 strcat(buf, e->city);
433 strcat(buf, e->state);
435 strncpy(haddr, buf, 80);
444 strncpy(hphone, buf, 16);
453 strncpy(ophone, buf, 12);
454 strncpy(dept, e->course, 12);
456 id = set_next_object_id("users_id", 0);
457 uid = set_next_object_id("uid", 1);
458 sprintf(login, "#%d", uid);
466 sprintf(fullname, "%s %s %s", first, middle, last);
468 sprintf(fullname, "%s %s", first, last);
470 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
471 ## #last = last, #first = first, #middle = middle, status = 0,
472 ## #mit_id = sid, #mit_year = class,
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,
478 ## xname = fullname, xdept = dept, xtitle = title,
479 ## xaddress = haddr, xphone1 = hphone, xphone2 = ophone,
480 ## xmodtime = date("now"))
482 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
486 set_next_object_id(object, limit)
491 ## int rowcount, exists, value;
495 ## repeat retrieve (value = values.#value) where values.#name = @name
496 ## inquire_equel(rowcount = "rowcount")
502 ## retrieve (exists = any(users.name where users.name = value))
503 ## inquire_equel(rowcount = "rowcount")
510 if (limit && value > MAX_ID_VALUE)
511 value = MIN_ID_VALUE;
512 ## retrieve (exists = any(users.name where users.name = value))
515 ## repeat replace values (#value = @value) where values.#name = @name