]> andersk Git - moira.git/blob - regtape/students.pc
Code style cleanup. (No functional changes)
[moira.git] / regtape / students.pc
1 /* $Header$
2  */
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <sys/time.h>
8 #include <moira.h>
9 #include <moira_site.h>
10 EXEC SQL INCLUDE sqlca;
11
12
13 #define WHO 11859               /* root */
14 #define PROG "stu-tape"
15
16 #define MAX_ID_VALUE    31999
17 #define MIN_ID_VALUE    101
18
19 /* File format is:
20
21 0-29    name
22 30-38   id number
23 50-54   school code
24 55-79   year
25 80-109  address
26 110-124 room
27 125-144 city
28 145-158 state
29 159-168 dorm phone
30 169-212 home address
31 213-232 home city
32 243-251 mit phone (?)
33 */
34
35 #define LOC_NAME 0
36 #define LOC_ID 30
37 #define LOC_COURSE 50
38 #define LOC_YEAR 55
39 #define LOC_ADDRESS 80
40 #define LOC_DORM_ROOM 110
41 #define LOC_CITY 125
42 #define LOC_STATE 145
43 #define LOC_DPHONE 155
44 #define LOC_MPHONE 243
45
46 #define LEN_NAME 30
47 #define LEN_ID 9
48 #define LEN_COURSE 5
49 #define LEN_YEAR 25
50 #define LEN_ADDRESS 30
51 #define LEN_DORM_ROOM 15
52 #define LEN_CITY 20
53 #define LEN_STATE 10
54 #define LEN_DPHONE 12
55 #define LEN_MPHONE 12
56
57 struct entry {
58   char *name;
59   char *last;
60   char *first;
61   char *middle;
62   char *title;
63   char *id;
64   char *eid;
65   char *course;
66   char *year;
67   char *address;
68   char *dorm;
69   char *city;
70   char *state;
71   char *dphone;
72   char *mphone;
73   char *class;
74 };
75
76
77 char *whoami;
78 int newfinger = 0;
79
80 #define SQL_DUPLICATE -2112
81 #define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403)
82
83 int main(int argc, char **argv)
84 {
85   FILE *in;
86   struct entry *e, *get_next_entry();
87   int i, wait = 0;
88   char buf[BUFSIZ], *file = NULL;
89   EXEC SQL BEGIN DECLARE SECTION;
90   char *db = "moira";
91   EXEC SQL END DECLARE SECTION;
92
93   whoami = strrchr(argv[0], '/');
94   if (whoami)
95     whoami++;
96   else
97     whoami = argv[0];
98
99   setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
100   setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
101
102   for (i = 1; i < argc; i++)
103     {
104       if (!strcmp(argv[i], "-w"))
105         wait++;
106       else if (!strcmp(argv[i], "-D"))
107         setenv("ING_SET", "set printqry");
108       else if (!strcmp(argv[i], "-n"))
109         newfinger++;
110       else if (file)
111         fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
112       else
113         file = argv[i];
114     }
115
116   in = fopen(file, "r");
117   if (!in)
118     {
119       fprintf(stderr, "Unable to open %s for input\n", file);
120       exit(1);
121     }
122
123   initialize_sms_error_table();
124
125   EXEC SQL CONNECT :db IDENTIFIED BY :db;
126   if (sqlca.sqlcode)
127     {
128       dbmserr("connecting", sqlca.sqlcode);
129       exit(1);
130     }
131
132   while ((e = get_next_entry(in)))
133     {
134     again:
135       process_entry(e);
136       EXEC SQL COMMIT WORK;
137       if (sqlca.sqlcode)
138         {
139           dbmserr("committing work", sqlca.sqlcode);
140           exit(1);
141         }
142       if (wait)
143         {
144           printf("Next");
145           fflush(stdout);
146           gets(buf);
147         }
148     }
149
150   exit(0);
151 }
152
153
154 struct entry *get_next_entry(FILE *in)
155 {
156   static struct entry e;
157   static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
158   static char name[LEN_NAME + 1], id[LEN_ID + 1], course[LEN_COURSE + 1];
159   static char year[LEN_YEAR + 1], address[LEN_ADDRESS + 1];
160   static char dorm_room[LEN_DORM_ROOM + 1], city[LEN_CITY + 1];
161   static char state[LEN_STATE + 1], dphone[LEN_DPHONE + 1];
162   static char mphone[LEN_MPHONE + 1], sname[LEN_NAME + 1], title[128];
163   static int nyear = 0;
164   int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v;
165   char *p;
166
167   if (nyear == 0)
168     {
169       struct tm *tm;
170       struct timeval tv;
171
172       gettimeofday(&tv, NULL);
173       tm = localtime(&tv.tv_sec);
174       nyear = tm->tm_year;
175       if (tm->tm_mon > 5)
176         nyear++;
177     }
178
179   if (!fgets(buf, sizeof(buf), in))
180     return NULL;
181
182   strncpy(name, &buf[LOC_NAME], LEN_NAME);
183   name[LEN_NAME] = '\0';
184   strncpy(id, &buf[LOC_ID], LEN_ID);
185   id[LEN_ID] = '\0';
186   strncpy(course, &buf[LOC_COURSE], LEN_COURSE);
187   course[LEN_COURSE] = '\0';
188   strncpy(year, &buf[LOC_YEAR], LEN_YEAR);
189   year[LEN_YEAR] = '\0';
190   strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS);
191   address[LEN_ADDRESS] = '\0';
192   strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM);
193   dorm_room[LEN_DORM_ROOM] = '\0';
194   strncpy(city, &buf[LOC_CITY], LEN_CITY);
195   city[LEN_CITY] = '\0';
196   strncpy(state, &buf[LOC_STATE], LEN_STATE);
197   state[LEN_STATE] = '\0';
198   strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE);
199   dphone[LEN_DPHONE] = '\0';
200   strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE);
201   mphone[LEN_MPHONE] = '\0';
202
203   strcpy(sname, name);
204   e.name = strtrim(sname);
205   p = strchr(name, ',');
206   if (p)
207     *p = '\0';
208   e.last = strtrim(name);
209   if (p)
210     {
211       p++;
212       while (isspace(*p))
213         p++;
214       e.first = p;
215       if (p = strchr(e.first, ' '))
216         {
217           *p = '\0';
218           e.first = strtrim(e.first);
219           e.middle = strtrim(p + 1);
220         }
221       else
222         {
223           e.first = strtrim(e.first);
224           e.middle = "";
225         }
226     }
227   else
228     {
229       e.first = "";
230       e.middle = "";
231     }
232   ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0;
233   LookForSt(e.last);
234   LookForO(e.last);
235   LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
236                   &ends_ii, &ends_v);
237   LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
238                   &ends_ii, &ends_v);
239   FixCase(e.last);
240   FixCase(e.first);
241   FixCase(e.middle);
242
243   e.id = id;
244   e.id[LEN_ID] = '\0';
245   e.eid = eid;
246   EncryptID(e.eid, e.id, e.first, e.last);
247
248   e.year = strtrim(year);
249   e.title = title;
250   if (e.year[0] == 'G')
251     {
252       e.class = "G";
253       sprintf(title, "Grad Student");
254     }
255   else
256     {
257       e.class = classbuf;
258       sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900);
259       sprintf(title, "Undergrad (class of %s)", classbuf);
260     }
261
262   e.course = strtrim(course);
263   e.address = strtrim(address);
264   e.dorm = strtrim(dorm_room);
265   e.city = strtrim(city);
266   e.state = strtrim(state);
267   e.dphone = strtrim(dphone);
268   e.mphone = strtrim(mphone);
269   return &e;
270 }
271
272
273 process_entry(struct entry *e)
274 {
275   int changed, nochange, encrypted;
276   char buf[BUFSIZ], *from, *to;
277   EXEC SQL BEGIN DECLARE SECTION;
278   char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept;
279   char *rtitle, *rophone, *rhphone, *prog;
280   char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128];
281   char dfirst[17], dlast[17], dmiddle[17];
282   int id, status, who;
283   EXEC SQL END DECLARE SECTION;
284
285   who = WHO;
286   prog = PROG;
287   first = e->first;
288   if (strlen(first) > 16)
289     first[16] = '\0';
290   last = e->last;
291   if (strlen(last) > 16)
292     last[16] = '\0';
293   middle = e->middle;
294   eid = e->eid;
295   sid = e->id;
296   id = 0;
297   encrypted = 0;
298
299   /* Get user info */
300   EXEC SQL SELECT users_id, first, last, middle, type, home_addr, home_phone,
301     office_phone, status, department
302     INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone,
303     :ophone, :status, :dept
304     FROM users
305     WHERE clearid = :sid;
306   if (sqlfail())
307     {
308       if (sqlca.sqlcode == SQL_DUPLICATE)
309         {
310           com_err(whoami, 0, "duplicate ID number %s on user %s %s",
311                   sid, first, last);
312           return;
313         }
314       else
315         sqlexit();
316     }
317   if (id == 0)
318     {
319       EXEC SQL SELECT users_id, first, last, middle, type, home_addr,
320         home_phone, office_phone, status, department
321         INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr,
322         :hphone, :ophone, :status, :dept
323         FROM users
324         WHERE last = :last and first = :first and clearid = :eid;
325       if (sqlfail())
326         sqlexit();
327       encrypted++;
328       if (id == 0)
329         {
330           newuser(e);
331           return;
332         }
333     }
334
335   /* See if class changed: if it's different, and the value in the database
336    * is not STAFF or SIPBMEM, and the value from the tape is actually
337    * meaningful, then update the database.  Since they were on the
338    * students tape, make the account usable.
339    */
340   if (strcmp(e->class, strtrim(class)) &&
341       strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") &&
342       e->year[0])
343     {
344       com_err(whoami, 0, "updating class for user %s %s from %s to %s",
345               first, last, class, e->class);
346       if (status == US_NOT_ALLOWED)
347         status = US_NO_LOGIN_YET;
348       if (status == US_ENROLL_NOT_ALLOWED)
349         status = US_ENROLLED;
350       strcpy(class, e->class);
351       EXEC SQL UPDATE users
352         SET type = NVL(:class, CHR(0)), status = :status, modtime = SYSDATE,
353         modby = :who, modwith = :prog
354         WHERE users_id = :id;
355       if (sqlca.sqlcode)
356         {
357           dbmserr("updating class", sqlca.sqlcode);
358           exit(1);
359         }
360     }
361
362   /* Update name if necessary */
363   if (strcmp(first, strtrim(dfirst)) ||
364       strcmp(last, strtrim(dlast)) ||
365       strcmp(middle, strtrim(dmiddle)))
366     {
367       com_err(whoami, 0, "updating real name for %s %s", first, last);
368       EXEC SQL UPDATE users
369         SET first = NVL(:first, CHR(0)), last = NVL(:last, CHR(0)),
370         middle = NVL(:middle, CHR(0)), modby = :who, modwith = :prog,
371         modtime = SYSDATE
372         WHERE users_id = :id;
373       if (sqlca.sqlcode != 0)
374         {
375           dbmserr("updating name", sqlca.sqlcode);
376           exit(1);
377         }
378     }
379
380   /* Deal with updating the finger info if necessary */
381   changed = nochange = 0;
382   if (encrypted)
383     changed++;
384   strcpy(buf, e->address);
385   if (*e->dorm)
386     {
387       strcat(buf, " ");
388       strcat(buf, e->dorm);
389     }
390   if (*e->city)
391     {
392       strcat(buf, " ");
393       strcat(buf, e->city);
394     }
395   FixCase(buf);
396   if (*e->state)
397     {
398       strcat(buf, " ");
399       strcat(buf, e->state);
400     }
401   while ((to = strchr(buf, ',')))
402     *to = ';';
403   while ((to = strchr(buf, ':')))
404     *to = ';';
405   if (newfinger)
406     {
407       if (haddr[0] == ' ')
408         {
409           strncpy(haddr, buf, 80);
410           haddr[80] = '\0';
411           changed++;
412         }
413       else if (strncmp(strtrim(haddr), buf, 80))
414         nochange++;
415     }
416   else
417     {
418       if (strncmp(strtrim(haddr), buf, 80))
419         changed++;
420       strncpy(haddr, buf, 80);
421       haddr[80] = '\0';
422     }
423   from = e->dphone;
424   to = buf;
425   while (*from)
426     {
427       if (isdigit(*from))
428         *to++ = *from;
429       from++;
430     }
431   *to = '\0';
432   if (newfinger)
433     {
434       if (hphone[0] == ' ')
435         {
436           strncpy(hphone, buf, 16);
437           hphone[16] = '\0';
438         }
439       else if (strncmp(strtrim(hphone), buf, 16))
440         nochange++;
441     }
442   else
443     {
444       if (strncmp(strtrim(hphone), buf, 16))
445         changed++;
446       strncpy(hphone, buf, 16);
447       hphone[16] = '\0';
448     }
449   from = e->mphone;
450   to = buf;
451   while (*from)
452     {
453       if (isdigit(*from))
454         *to++ = *from;
455       from++;
456     }
457   *to = '\0';
458   if (newfinger)
459     {
460       if (ophone[0] == ' ')
461         {
462           strncpy(ophone, buf, 12);
463           ophone[12] = '\0';
464         }
465       else if (strncmp(strtrim(ophone), buf, 12))
466         nochange++;
467     }
468   else
469     {
470       if (strncmp(strtrim(ophone), buf, 12))
471         changed++;
472       strncpy(ophone, buf, 12);
473       ophone[12] = '\0';
474     }
475   e->course = e->course;
476   if (newfinger)
477     {
478       if (dept[0] == ' ')
479         {
480           strncpy(dept, e->course, 12);
481           dept[12] = '\0';
482         }
483       else if (strncmp(strtrim(dept), e->course, 11))
484         nochange++;
485     }
486   else
487     {
488       if (strncmp(strtrim(dept), e->course, 11))
489         changed++;
490       strncpy(dept, e->course, 12);
491       dept[12] = '\0';
492     }
493   sid = e->id;
494   name = e->name;
495   rdept = e->course;
496   rtitle = e->title;
497   rophone = e->mphone;
498   rhphone = e->dphone;
499   strcpy(raddr, e->address);
500   if (*e->dorm)
501     {
502       strcat(raddr, " ");
503       strcat(raddr, e->dorm);
504     }
505   strcat(raddr, "|");
506   if (*e->city)
507     {
508       strcat(raddr, e->city);
509       FixCase(raddr);
510       if (*e->state)
511         {
512           strcat(raddr, " ");
513           if (isupper(e->state[0]) && isupper(e->state[1]) &&
514               isdigit(e->state[2]) && isdigit(e->state[3]) &&
515               isdigit(e->state[4]) && isdigit(e->state[5]) &&
516               isdigit(e->state[6]))
517             {
518               sprintf(buf, "%c%c  %s", e->state[0], e->state[1],
519                       &(e->state[2]));
520               strcat(raddr, buf);
521             }
522           else
523             strcat(raddr, e->state);
524         }
525     }
526   else
527     {
528       FixCase(raddr);
529       strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
530     }
531   if (changed)
532     {
533       com_err(whoami, 0, "updating finger for %s %s", first, last);
534       EXEC SQL UPDATE users
535         SET home_addr = NVL(:haddr, CHR(0)), home_phone = NVL(:hphone, CHR(0)),
536         office_phone = NVL(:ophone, CHR(0)), department = NVL(:dept, CHR(0)),
537         fmodtime = SYSDATE, fmodby = :who, fmodwith = :prog,
538         xname = NVL(:name, CHR(0)), xdept = NVL(:rdept, CHR(0)),
539         xtitle = NVL(:rtitle, CHR(0)), xaddress = NVL(:raddr, CHR(0)),
540         xphone1 = NVL(:rhphone, CHR(0)), xphone2 = NVL(:rophone, CHR(0)),
541         xmodtime = SYSDATE, clearid = NVL(:sid, CHR(0))
542         WHERE users_id = :id;
543       if (sqlca.sqlcode)
544         {
545           dbmserr(NULL, sqlca.sqlcode);
546           exit(1);
547         }
548     }
549   else
550     {
551       EXEC SQL UPDATE users
552         SET xname = NVL(:name, CHR(0)), xdept = NVL(:rdept, CHR(0)),
553         xtitle = NVL(:rtitle, CHR(0)), xaddress = NVL(:raddr, CHR(0)),
554         xphone1 = NVL(:rhphone, CHR(0)), xphone2 = NVL(:rophone, CHR(0)),
555         xmodtime = SYSDATE, clearid = NVL(:sid, CHR(0))
556         WHERE users_id = :id;
557       if (sqlca.sqlcode)
558         {
559           dbmserr(NULL, sqlca.sqlcode);
560           exit(1);
561         }
562     }
563 }
564
565
566 newuser(struct entry *e)
567 {
568   char buf[512], *from, *to;
569   EXEC SQL BEGIN DECLARE SECTION;
570   int id, uid, who;
571   char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
572   char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name;
573   EXEC SQL END DECLARE SECTION;
574
575   who = WHO;
576   prog = PROG;
577   strcpy(buf, e->address);
578   if (*e->dorm)
579     {
580       strcat(buf, " ");
581       strcat(buf, e->dorm);
582     }
583   if (*e->city)
584     {
585       strcat(buf, " ");
586       strcat(buf, e->city);
587     }
588   if (*e->state)
589     {
590       strcat(buf, " ");
591       strcat(buf, e->state);
592     }
593   strncpy(haddr, buf, 80);
594   from = e->dphone;
595   to = buf;
596   while (*from)
597     {
598       if (isdigit(*from))
599         *to++ = *from;
600       from++;
601     }
602   *to = '\0';
603   strncpy(hphone, buf, 16);
604   from = e->mphone;
605   to = buf;
606   while (*from)
607     {
608       if (isdigit(*from))
609         *to++ = *from;
610       from++;
611     }
612   *to = '\0';
613   strncpy(ophone, buf, 12);
614   strncpy(dept, e->course, 12);
615
616   id = set_next_users_id(0);
617   uid = set_next_uid(1);
618   sprintf(login, "#%d", uid);
619   last = e->last;
620   first = e->first;
621   middle = e->middle;
622   sid = e->id;
623   class = e->class;
624   title = e->title;
625   if (*middle)
626     sprintf(fullname, "%s %s %s", first, middle, last);
627   else
628     sprintf(fullname, "%s %s", first, last);
629   name = e->name;
630   strcpy(raddr, e->address);
631   if (*e->dorm)
632     {
633       strcat(raddr, " ");
634       strcat(raddr, e->dorm);
635     }
636   strcat(raddr, "|");
637   if (*e->city)
638     {
639       strcat(raddr, e->city);
640       FixCase(raddr);
641       if (*e->state)
642         {
643           strcat(raddr, " ");
644           if (isupper(e->state[0]) && isupper(e->state[1]) &&
645               isdigit(e->state[2]) && isdigit(e->state[3]) &&
646               isdigit(e->state[4]) && isdigit(e->state[5]) &&
647               isdigit(e->state[6]))
648             {
649               sprintf(buf, "%c%c  %s", e->state[0], e->state[1],
650                       &(e->state[2]));
651               strcat(raddr, buf);
652             }
653           else
654             strcat(raddr, e->state);
655         }
656     }
657   else
658     {
659       FixCase(raddr);
660       strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
661     }
662   EXEC SQL INSERT INTO users
663     (login, users_id, unix_uid, shell, last, first, middle, status,
664      clearid, type, modtime, modby, modwith, fullname, home_addr,
665      home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
666      potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
667     VALUES (:login, :id, :uid, '/bin/athena/tcsh', NVL(:last, CHR(0)),
668             NVL(:first, CHR(0)), NVL(:middle, CHR(0)), 0, NVL(:sid, CHR(0)),
669             NVL(:class, CHR(0)), SYSDATE, :who, :prog, NVL(:fullname, CHR(0)),
670             NVL(:haddr, CHR(0)), NVL(:hphone, CHR(0)), NVL(:ophone, CHR(0)),
671             NVL(:dept, CHR(0)), SYSDATE, :who, :prog, 'NONE',
672             NVL(:name, CHR(0)), NVL(:dept, CHR(0)), NVL(:title, CHR(0)),
673             NVL(:raddr, CHR(0)), NVL(:hphone, CHR(0)), NVL(:ophone, CHR(0)),
674             SYSDATE);
675   if (sqlca.sqlcode)
676     {
677       dbmserr("adding user", sqlca.sqlcode);
678       exit(1);
679     }
680   else
681     com_err(whoami, 0, "adding user %s %s", e->first, e->last);
682 }
683
684
685 int set_next_users_id(int limit)
686 {
687   EXEC SQL BEGIN DECLARE SECTION;
688   int rowcount, flag, value, retval;
689   EXEC SQL END DECLARE SECTION;
690
691   EXEC SQL SELECT value INTO :value FROM numvalues
692     WHERE name = 'users_id';
693   if (sqlfail())
694     sqlexit();
695   if (sqlca.sqlerrd[2] != 1)
696     {
697       EXEC SQL ROLLBACK;
698       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
699       exit(1);
700     }
701
702   flag = 0;
703   EXEC SQL SELECT users_id INTO :flag FROM users
704     WHERE users_id = :value;
705   if (sqlfail())
706     sqlexit();
707   if (sqlca.sqlerrd[2] == 0)
708     flag = 0;
709   while (flag)
710     {
711       value++;
712       if (limit && value > MAX_ID_VALUE)
713         value = MIN_ID_VALUE;
714       flag = 0;
715       EXEC SQL SELECT users_id INTO :flag FROM users
716         WHERE users_id = :value;
717       if (sqlfail())
718         sqlexit();
719       if (sqlca.sqlerrd[2] == 0)
720         flag = 0;
721     }
722
723   retval = value++;
724   if (limit && value > MAX_ID_VALUE)
725     value = MIN_ID_VALUE;
726   EXEC SQL UPDATE numvalues SET value = :value
727     WHERE name = 'users_id';
728   if (sqlca.sqlcode)
729     {
730       dbmserr("updating numvalues", sqlca.sqlcode);
731       exit(1);
732     }
733   return retval;
734 }
735
736 int set_next_uid(int limit)
737 {
738   EXEC SQL BEGIN DECLARE SECTION;
739   int rowcount, flag, value, retval;
740   EXEC SQL END DECLARE SECTION;
741
742   EXEC SQL SELECT value INTO :value FROM numvalues
743     WHERE name = 'unix_uid';
744   if (sqlfail())
745     sqlexit();
746   if (sqlca.sqlerrd[2] != 1)
747     {
748       EXEC SQL ROLLBACK;
749       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
750       exit(1);
751     }
752
753   flag = 0;
754   EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
755   if (sqlfail())
756     sqlexit();
757   if (sqlca.sqlerrd[2] == 0)
758     flag = 0;
759   while (flag)
760     {
761       value++;
762       if (limit && value > MAX_ID_VALUE)
763         value = MIN_ID_VALUE;
764       flag = 0;
765       EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
766       if (sqlfail())
767         sqlexit();
768       if (sqlca.sqlerrd[2] == 0)
769         flag = 0;
770     }
771
772   retval = value++;
773   if (limit && value > MAX_ID_VALUE)
774     value = MIN_ID_VALUE;
775   EXEC SQL UPDATE numvalues SET value = :value WHERE name = 'unix_uid';
776   if (sqlca.sqlcode)
777     {
778       dbmserr("updating numvalues", sqlca.sqlcode);
779       exit(1);
780     }
781   return retval;
782 }
783
784
785 sqlexit(void)
786 {
787   dbmserr(NULL, sqlca.sqlcode);
788   EXEC SQL ROLLBACK WORK;
789   exit(1);
790 }
791
792 dbmserr(char *where, int what)
793 {
794   char err_msg[256];
795   int bufsize = 256, msglength = 0;
796
797   sqlglm(err_msg, &bufsize, &msglength);
798   err_msg[msglength] = '\0';
799
800   if (where)
801     com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where);
802   else
803     com_err(whoami, 0, "DBMS error %s", err_msg);
804 }
This page took 0.099961 seconds and 5 git commands to generate.