9 #include <moira_site.h>
10 EXEC SQL INCLUDE sqlca;
13 #define WHO 11859 /* root */
14 #define PROG "emp-tape"
16 #define MAX_ID_VALUE 31999
17 #define MIN_ID_VALUE 101
40 #define LOC_USERNAME 157
50 #define LEN_USERNAME 30
80 struct entry *e, *get_next_entry();
82 char buf[BUFSIZ], *file = NULL;
84 whoami = rindex(argv[0], '/');
90 for (i = 1; i < argc; i++) {
91 if (!strcmp(argv[i], "-w"))
93 else if (!strcmp(argv[i], "-D"))
94 setenv("ING_SET", "set printqry");
95 else if (!strcmp(argv[i], "-n"))
97 else if (file != NULL)
98 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
103 in = fopen(file, "r");
105 fprintf(stderr, "Unable to open %s for input\n", file);
112 EXEC SQL CONNECT moira;
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 EXEC SQL BEGIN DECLARE SECTION;
233 char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
234 char *raddr, *rhphone, *rophone;
235 char class[9], oaddr[25], ophone[17], dept[128];
237 EXEC SQL END DECLARE SECTION;
240 if (strlen(first) > 16)
243 if (strlen(last) > 16)
250 EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
251 INTO :id, :class, :oaddr, :ophone, :dept, :status
253 WHERE last = :last and first = :first and clearid = :sid;
255 EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
256 INTO :id, :class, :oaddr, :ophone, :dept, :status
258 WHERE last = :last and first = :first and clearid = :eid;
265 if (strcmp(e->class, strtrim(class)) &&
266 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
267 com_err(whoami, 0, "updating class for %s %s from %s to %s",
268 first, last, class, e->class);
269 if (status == US_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
270 status = US_NO_LOGIN_YET;
271 if (status == US_ENROLL_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
272 status = US_ENROLLED;
273 strcpy(class, e->class);
274 EXEC SQL UPDATE users
275 SET type = :class, status = :status, modtime = 'now',
276 modby = WHO, modwith = PROG
277 WHERE users_id = :id;
280 changed = nochange = 0;
281 strcpy(buf, e->address);
282 while (to = index(buf, ','))
284 while (to = index(buf, ':'))
287 if (oaddr[0] == ' ' && buf[0]) {
288 strncpy(oaddr, buf, 16);
291 } else if (strncmp(strtrim(oaddr), buf, 15))
294 if (strncmp(strtrim(oaddr), buf, 15))
296 strncpy(oaddr, buf, 16);
308 if (ophone[0] == ' ') {
309 strncpy(ophone, buf, 16);
311 } else if (strncmp(strtrim(ophone), buf, 11))
314 if (strncmp(strtrim(ophone), buf, 11))
316 strncpy(ophone, buf, 16);
322 if (dept[0] == ' ') {
323 strncpy(dept, e->dept, 12);
325 } else if (strncmp(strtrim(dept), e->dept, 11))
328 if (strncmp(strtrim(dept), e->dept, 11))
330 strncpy(dept, e->dept, 12);
341 com_err(whoami, 0, "updating finger for %s %s", first, last);
342 EXEC SQL REPEATED UPDATE users
343 SET office_addr = :oaddr, office_phone = :ophone, mit_dept = :dept,
344 fmodtime = 'now', fmodby = WHO, fmodwith = PROG,
345 xname = :name, xdept = :rdept, xtitle = :rtitle,
346 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
347 xmodtime = 'now', mit_id = :sid
348 WHERE users_id = :id;
350 EXEC SQL REPEATED UPDATE users
351 SET xname = :name, xdept = :rdept, xtitle = :rtitle,
352 xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
353 xmodtime = 'now', mit_id = :sid
354 WHERE users_id = :id;
363 EXEC SQL BEGIN DECLARE SECTION;
364 int id, uid, st, who;
365 char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
366 char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17];
367 char *rdept, *rhphone, *rophone;
368 EXEC SQL END DECLARE SECTION;
372 strncpy(oaddr, e->address, 16);
374 while (to = index(oaddr, ','))
376 while (to = index(oaddr, ':'))
387 strncpy(dept, e->dept, 12);
390 id = set_next_object_id("users_id", 0);
391 uid = set_next_object_id("uid", 1);
392 sprintf(login, "#%d", uid);
398 sprintf(fullname, "%s %s %s", first, middle, last);
400 sprintf(fullname, "%s %s", first, last);
402 if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
403 st = US_NO_LOGIN_YET;
412 EXEC SQL INSERT INTO users
413 (login, users_id, uid, shell, last, first, middle, status,
414 clearid, type, modtime, modby, modwith, fullname, office_addr,
415 office_phone, department, fmodtime, fmodby, fmodwith,
416 potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
417 VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, :st,
418 :sid, :class, 'now', :who, :prog, :fullname, :oaddr, :ophone,
419 :dept, 'now', :who, :prog, 'NONE', :name, :rdept,
420 :title, :oaddr, :rhphone, :rophone, 'now');
424 set_next_object_id(object, limit)
428 EXEC SQL BEGIN DECLARE SECTION;
430 int rowcount, flag, value;
431 EXEC SQL END DECLARE SECTION;
434 EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :name;
435 if (sqlca.sqlerrd[2] != 1) {
437 com_err(whoami, MR_INTERNAL, "values table inconsistancy");
442 EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
443 if (sqlca.sqlerrd[2] == 0)
447 if (limit && value > MAX_ID_VALUE)
448 value = MIN_ID_VALUE;
450 EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
451 if (sqlca.sqlerrd[2] == 0)
456 if (limit && value > MAX_ID_VALUE)
457 value = MIN_ID_VALUE;
458 EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = :name;