9 #include <moira_site.h>
12 ##define WHO 11859 /* root */
13 ##define PROG "emp-tape"
15 #define MAX_ID_VALUE 31999
16 #define MIN_ID_VALUE 101
39 #define LOC_USERNAME 157
49 #define LEN_USERNAME 30
79 struct entry *e, *get_next_entry();
81 char buf[BUFSIZ], *file = NULL;
83 whoami = rindex(argv[0], '/');
89 for (i = 1; i < argc; i++) {
90 if (!strcmp(argv[i], "-w"))
92 else if (!strcmp(argv[i], "-D"))
93 setenv("ING_SET", "set printqry");
94 else if (!strcmp(argv[i], "-n"))
96 else if (file != NULL)
97 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
102 in = fopen(file, "r");
104 fprintf(stderr, "Unable to open %s for input\n", file);
112 ## range of u is users
114 while (e = get_next_entry(in)) {
128 char *substr(buf, key)
134 for (l = strlen(key); *buf; buf++)
135 if (!strncmp(buf, key, l))
141 struct entry *get_next_entry(in)
144 static struct entry e;
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];
150 int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
153 if (fgets(buf, sizeof(buf), in) == NULL)
154 return((struct entry *)NULL);
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;
167 e.name = strtrim(sname);
168 p = index(name, ',');
171 e.last = strtrim(name);
177 if (p = index(e.first, ' ')) {
179 e.first = strtrim(e.first);
180 e.middle = strtrim(p + 1);
182 e.first = strtrim(e.first);
189 ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
192 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
194 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
202 EncryptID(e.eid, e.id, e.first, e.last);
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);
211 if (!strcmp(e.dept, "PROJECT ATHENA"))
213 else if (substr(e.title, "PROF") || substr(e.title, "LECTURE"))
215 else if (!strcmp(e.title, "VISITING SCIENTIST"))
216 e.class = "VSCIENTI";
218 strcpy(email, strtrim(username));
220 strncat(email, strtrim(host));
230 int changed, nochange;
231 char buf[BUFSIZ], *from, *to;
232 ## char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
233 ## char *raddr, *rhphone, *rophone;
234 ## char class[9], oaddr[25], ophone[17], dept[128];
238 if (strlen(first) > 16)
241 if (strlen(last) > 16)
248 ## repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
249 ## ophone = u.office_phone, dept = u.mit_dept, status = u.#status)
250 ## where u.#last = @last and u.#first = @first and u.mit_id = @sid
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
262 if (strcmp(e->class, strtrim(class)) &&
263 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
264 com_err(whoami, 0, "updating class for %s %s from %s to %s",
265 first, last, class, e->class);
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;
270 strcpy(class, e->class);
271 ## repeat replace u (mit_year = @class, #status = @status,
272 ## modtime = "now", modby = WHO, modwith = PROG)
273 ## where u.users_id = @id
276 changed = nochange = 0;
277 strcpy(buf, e->address);
278 while (to = index(buf, ','))
280 while (to = index(buf, ':'))
283 if (oaddr[0] == ' ' && buf[0]) {
284 strncpy(oaddr, buf, 16);
287 } else if (strncmp(strtrim(oaddr), buf, 15))
290 if (strncmp(strtrim(oaddr), buf, 15))
292 strncpy(oaddr, buf, 16);
304 if (ophone[0] == ' ') {
305 strncpy(ophone, buf, 16);
307 } else if (strncmp(strtrim(ophone), buf, 11))
310 if (strncmp(strtrim(ophone), buf, 11))
312 strncpy(ophone, buf, 16);
318 if (dept[0] == ' ') {
319 strncpy(dept, e->dept, 12);
321 } else if (strncmp(strtrim(dept), e->dept, 11))
324 if (strncmp(strtrim(dept), e->dept, 11))
326 strncpy(dept, e->dept, 12);
337 com_err(whoami, 0, "updating finger for %s %s", first, last);
338 ## repeat replace u (office_addr = @oaddr,
339 ## office_phone = @ophone, #mit_dept = @dept,
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
346 ## repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle,
347 ## xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
348 ## xmodtime = date("now"), mit_id = @sid)
349 ## where u.users_id = @id
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;
363 strncpy(oaddr, e->address, 16);
365 while (to = index(oaddr, ','))
367 while (to = index(oaddr, ':'))
378 strncpy(dept, e->dept, 12);
381 id = set_next_object_id("users_id", 0);
382 uid = set_next_object_id("uid", 1);
383 sprintf(login, "#%d", uid);
389 sprintf(fullname, "%s %s %s", first, middle, last);
391 sprintf(fullname, "%s %s", first, last);
393 if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
394 st = US_NO_LOGIN_YET;
404 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
405 ## #last = last, #first = first, #middle = middle, status = st,
406 ## #mit_id = sid, #mit_year = class,
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,
412 ## xname = name, xdept = rdept, xtitle = title,
413 ## xaddress = oaddr, xphone1 = rhphone, xphone2 = rophone,
414 ## xmodtime = date("now"))
419 set_next_object_id(object, limit)
424 ## int rowcount, exists, value;
428 ## repeat retrieve (value = values.#value) where values.#name = @name
429 ## inquire_equel(rowcount = "rowcount")
435 ## retrieve (exists = any(users.name where users.name = value))
436 ## inquire_equel(rowcount = "rowcount")
443 if (limit && value > MAX_ID_VALUE)
444 value = MIN_ID_VALUE;
445 ## retrieve (exists = any(users.name where users.name = value))
448 ## repeat replace values (#value = @value) where values.#name = @name