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 while (*(e.first) && isspace(*(e.first)))
155 if (p = index(e.first, ' ')) {
157 e.middle = strtrim(p + 1);
162 e.first = strtrim(e.first);
163 ends_sr = ends_jr = ends_iii = ends_iv = 0;
166 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
167 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
172 strncpy(mid, buf, LEN_ID);
175 EncryptID(e.eid, e.id, e.first, e.last);
177 e.address = &buf[LOC_OFFICE];
178 e.address[LEN_OFFICE] = 0;
179 e.address = strtrim(e.address);
181 strncpy(phone, &buf[LOC_PHONE], LEN_PHONE);
182 e.phone = strtrim(e.phone);
183 e.dept = &buf[LOC_DEPT];
184 e.dept[LEN_DEPT] = 0;
185 e.dept = strtrim(e.dept);
186 e.title = &buf[LOC_TITLE];
187 e.title[LEN_TITLE] = 0;
188 e.title = strtrim(e.title);
191 if (!strcmp(e.dept, "PROJECT ATHENA"))
193 else if (substr(e.title, "PROF") || substr(e.title, "LECTURE"))
195 else if (!strcmp(e.title, "VISITING SCIENTIST"))
196 e.class = "VSCIENTI";
198 strncpy(email, &buf[LOC_USERNAME], LEN_USERNAME);
200 if (buf[LOC_HOST] == '@')
201 strncat(email, &buf[LOC_HOST], LEN_HOST);
202 e.email = strtrim(email);
211 int changed, nochange;
212 char buf[BUFSIZ], *from, *to;
213 ## char *first, *last, *eid;
214 ## char class[9], oaddr[17], ophone[17], dept[17];
218 if (strlen(first) > 16)
221 if (strlen(last) > 16)
225 ## repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
226 ## ophone = u.office_phone, dept = u.mit_dept)
227 ## where u.#last = @last and u.#first = @first and u.mit_id = @eid
232 if (strcmp(e->class, strtrim(class)) &&
233 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
234 com_err(whoami, 0, "updating class for %s %s from %s to %s",
235 first, last, class, e->class);
236 strcpy(class, e->class);
237 ## repeat replace u (mit_year = @class,
238 ## modtime = "now", modby = WHO, modwith = PROG)
239 ## where u.users_id = @id
241 changed = nochange = 0;
242 strcpy(buf, e->address);
243 while (to = index(buf, ','))
245 while (to = index(buf, ':'))
248 if (oaddr[0] == ' ') {
249 strncpy(oaddr, buf, 16);
252 } else if (strncmp(strtrim(oaddr), buf, 15))
255 if (strncmp(strtrim(oaddr), buf, 15))
257 strncpy(oaddr, buf, 16);
269 if (ophone[0] == ' ') {
270 strncpy(ophone, buf, 16);
272 } else if (strncmp(strtrim(ophone), buf, 11))
275 if (strncmp(strtrim(ophone), buf, 11))
277 strncpy(ophone, buf, 16);
282 if (dept[0] == ' ') {
283 strncpy(dept, e->dept, 12);
285 } else if (strncmp(strtrim(dept), e->dept, 11))
288 if (strncmp(strtrim(dept), e->dept, 11))
290 strncpy(dept, e->dept, 12);
294 com_err(whoami, 0, "updating finger for %s %s", first, last);
295 ## repeat replace u (office_addr = @oaddr,
296 ## office_phone = @ophone, #mit_dept = @dept,
297 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG)
298 ## where u.users_id = @id
300 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
309 ## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
310 ## char oaddr[81], ophone[13], dept[13];
313 strncpy(oaddr, e->address, 16);
314 while (to = index(oaddr, ','))
316 while (to = index(oaddr, ':'))
326 strncpy(dept, e->dept, 12);
328 id = set_next_object_id("users_id");
329 uid = set_next_object_id("uid");
330 sprintf(login, "#%d", uid);
337 sprintf(fullname, "%s %s %s", first, middle, last);
339 sprintf(fullname, "%s %s", first, last);
341 if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
342 st = US_NO_LOGIN_YET;
344 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
345 ## #last = last, #first = first, #middle = middle, status = st,
346 ## #mit_id = eid, #mit_year = class,
347 ## modtime = "now", modby = WHO, modwith = PROG,
348 ## #fullname = fullname, office_addr = oaddr,
349 ## office_phone = ophone, #mit_dept = dept,
350 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG,
352 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
356 set_next_object_id(object)
360 ## int rowcount, exists, value;
364 ## repeat retrieve (value = values.#value) where values.#name = @name
365 ## inquire_equel(rowcount = "rowcount")
371 ## retrieve (exists = any(users.name where users.name = value))
372 ## inquire_equel(rowcount = "rowcount")
379 if (value > MAX_ID_VALUE)
380 value = MIN_ID_VALUE;
381 ## retrieve (exists = any(users.name where users.name = value))
384 ## repeat replace values (#value = @value) where values.#name = @name