9 #include <moira_site.h>
12 ##define WHO 11859 /* root */
13 ##define PROG "emp-tape"
15 #define MAX_ID_VALUE 32766
16 #define MIN_ID_VALUE 101
39 #define LOC_USERNAME 157
49 #define LEN_USERNAME 29
77 struct entry *e, *get_next_entry();
79 char buf[BUFSIZ], *file = NULL;
81 whoami = rindex(argv[0], '/');
87 for (i = 1; i < argc; i++) {
88 if (!strcmp(argv[i], "-w"))
90 else if (!strcmp(argv[i], "-D"))
91 setenv("ING_SET", "set printqry");
92 else if (!strcmp(argv[i], "-n"))
94 else if (file != NULL)
95 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
100 in = fopen(file, "r");
102 fprintf(stderr, "Unable to open %s for input\n", file);
107 ## range of u is users
109 while (e = get_next_entry(in)) {
123 char *substr(buf, key)
129 for (l = strlen(key); *buf; buf++)
130 if (!strncmp(buf, key, l))
136 struct entry *get_next_entry(in)
139 static struct entry e;
140 static char buf[BUFSIZ], mid[16], eid[16], email[256], phone[13];
141 int ends_sr, ends_jr, ends_iii, ends_iv;
144 if (fgets(buf, sizeof(buf), in) == NULL)
145 return((struct entry *)NULL);
146 buf[LOC_NAME + LEN_NAME] = 0;
147 p = index(&buf[LOC_NAME], ',');
150 e.last = strtrim(&buf[LOC_NAME]);
153 if (p = index(e.first, ' ')) {
155 e.middle = strtrim(p + 1);
160 e.first = strtrim(e.first);
161 ends_sr = ends_jr = ends_iii = ends_iv = 0;
164 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
165 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
170 strncpy(mid, buf, LEN_ID);
173 EncryptID(e.eid, e.id, e.first, e.last);
175 e.address = &buf[LOC_OFFICE];
176 e.address[LEN_OFFICE] = 0;
177 e.address = strtrim(e.address);
179 strncpy(phone, &buf[LOC_PHONE], LEN_PHONE);
180 e.phone = strtrim(e.phone);
181 e.dept = &buf[LOC_DEPT];
182 e.dept[LEN_DEPT] = 0;
183 e.dept = strtrim(e.dept);
184 e.title = &buf[LOC_TITLE];
185 e.title[LEN_TITLE] = 0;
186 e.title = strtrim(e.title);
189 if (!strcmp(e.dept, "PROJECT ATHENA"))
191 else if (substr(e.title, "PROF") || substr(e.title, "LECTURE"))
193 else if (!strcmp(e.title, "VISITING SCIENTIST"))
194 e.class = "VSCIENTI";
196 strncpy(email, &buf[LOC_USERNAME], LEN_USERNAME);
198 if (buf[LOC_HOST] == '@')
199 strncat(email, &buf[LOC_HOST], LEN_HOST);
200 e.email = strtrim(email);
209 int changed, nochange;
210 char buf[BUFSIZ], *from, *to;
211 ## char *first, *last, *eid;
212 ## char class[9], oaddr[17], ophone[17], dept[17];
216 if (strlen(first) > 16)
219 if (strlen(last) > 16)
223 ## repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
224 ## ophone = u.office_phone, dept = u.mit_dept)
225 ## where u.#last = @last and u.#first = @first and u.mit_id = @eid
230 if (strcmp(e->class, strtrim(class)) &&
231 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
232 com_err(whoami, 0, "updating class for %s %s from %s to %s",
233 first, last, class, e->class);
234 strcpy(class, e->class);
235 ## repeat replace u (mit_year = @class,
236 ## modtime = "now", modby = WHO, modwith = PROG)
237 ## where u.users_id = @id
239 changed = nochange = 0;
240 strcpy(buf, e->address);
241 while (to = index(buf, ','))
243 while (to = index(buf, ':'))
246 if (oaddr[0] == ' ') {
247 strncpy(oaddr, buf, 16);
250 } else if (strncmp(strtrim(oaddr), buf, 15))
253 if (strncmp(strtrim(oaddr), buf, 15))
255 strncpy(oaddr, buf, 16);
267 if (ophone[0] == ' ') {
268 strncpy(ophone, buf, 16);
270 } else if (strncmp(strtrim(ophone), buf, 11))
273 if (strncmp(strtrim(ophone), buf, 11))
275 strncpy(ophone, buf, 16);
280 if (dept[0] == ' ') {
281 strncpy(dept, e->dept, 12);
283 } else if (strncmp(strtrim(dept), e->dept, 11))
286 if (strncmp(strtrim(dept), e->dept, 11))
288 strncpy(dept, e->dept, 12);
292 com_err(whoami, 0, "updating finger for %s %s", first, last);
293 ## repeat replace u (office_addr = @oaddr,
294 ## office_phone = @ophone, #mit_dept = @dept,
295 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG)
296 ## where u.users_id = @id
298 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
307 ## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
308 ## char oaddr[81], ophone[13], dept[13];
311 strncpy(oaddr, e->address, 16);
312 while (to = index(oaddr, ','))
314 while (to = index(oaddr, ':'))
324 strncpy(dept, e->dept, 12);
326 id = set_next_object_id("users_id");
327 uid = set_next_object_id("uid");
328 sprintf(login, "#%d", uid);
335 sprintf(fullname, "%s %s %s", first, middle, last);
337 sprintf(fullname, "%s %s", first, last);
339 if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
340 st = US_NO_LOGIN_YET;
342 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
343 ## #last = last, #first = first, #middle = middle, status = st,
344 ## #mit_id = eid, #mit_year = class,
345 ## modtime = "now", modby = WHO, modwith = PROG,
346 ## #fullname = fullname, office_addr = oaddr,
347 ## office_phone = ophone, #mit_dept = dept,
348 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG,
350 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
354 set_next_object_id(object)
358 ## int rowcount, exists, value;
362 ## repeat retrieve (value = values.#value) where values.#name = @name
363 ## inquire_equel(rowcount = "rowcount")
369 ## retrieve (exists = any(users.name where users.name = value))
370 ## inquire_equel(rowcount = "rowcount")
377 if (value > MAX_ID_VALUE)
378 value = MIN_ID_VALUE;
379 ## retrieve (exists = any(users.name where users.name = value))
382 ## repeat replace values (#value = @value) where values.#name = @name