#
# Imakefile for moira regtape programs.
-SRCS= students.c employee.c sign.c rafnu.c
-CODE= students.dc employee.dc sign.dc rafnu.c
+SRCS= students.c employee.c sign.c verify.c vote.c rafnu.c
+CODE= students.dc employee.dc sign.dc verify.dc vote.dc rafnu.c
SRCDIR = $(SRCTOP)/regtape
-DEFINES = -I/mit/gdss/include
+DEFINES = $(GDSSINC)
sqlrule()
program(students, students.o rafnu.o,,$(CLIBS) $(SQL_LIB), $(PROGDIR))
program(employee, employee.o rafnu.o,,$(CLIBS) $(SQL_LIB), $(PROGDIR))
-/* program(verify, verify.o rafnu.o,,/mit/gdss/`machtype`/libgdss.a $(CLIBS) $(SQL_LIB), $(PROGDIR)) */
-program(sign, sign.o rafnu.o,,/mit/gdss/`machtype`/libgdss.a $(CLIBS) $(SQL_LIB), $(PROGDIR))
-/* program(vote, vote.o rafnu.o,,$(CLIBS) $(SQL_LIB), $(PROGDIR)) */
+program(verify, verify.o rafnu.o,,$(LIBGDSS) $(CLIBS) $(SQL_LIB), $(PROGDIR))
+program(sign, sign.o rafnu.o,,$(LIBGDSS) $(CLIBS) $(SQL_LIB), $(PROGDIR))
+program(vote, vote.o rafnu.o,,$(CLIBS) $(SQL_LIB), $(PROGDIR))
sqlfile(students)
sqlfile(employee)
*/
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <moira.h>
char *whoami;
int newfinger = 0;
-#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 100)
-#define SQL_DUPLICATE -40100
-#define SQL_DEADLOCK -49900
+#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403)
+#define SQL_DUPLICATE 1422
main(argc, argv)
struct entry *e, *get_next_entry();
int i, wait = 0;
char buf[BUFSIZ], *file = NULL;
+EXEC SQL BEGIN DECLARE SECTION;
+ char *db="moira";
+EXEC SQL END DECLARE SECTION;
- whoami = rindex(argv[0], '/');
+ whoami = strrchr(argv[0], '/');
if (whoami)
whoami++;
else
whoami = argv[0];
+ setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-w"))
wait++;
exit(1);
}
- setlinebuf(stdout);
- setlinebuf(stderr);
initialize_sms_error_table();
- EXEC SQL CONNECT moira;
+ EXEC SQL CONNECT :db IDENTIFIED BY :db;
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d opening database", sqlca.sqlcode);
+ dbmserr("opening database", sqlca.sqlcode);
exit(1);
}
process_entry(e);
EXEC SQL COMMIT WORK;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "commiting work");
- goto again;
- } else {
- com_err(whoami, 0, "ingres error %d committing work", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("committing work", sqlca.sqlcode);
+ exit(1);
}
if (wait) {
printf("Next");
strcpy(sname, name);
e.name = strtrim(sname);
- p = index(name, ',');
+ p = strchr(name, ',');
if (p)
*p = 0;
e.last = strtrim(name);
while (isspace(*p))
p++;
e.first = p;
- if (p = index(e.first, ' ')) {
+ if (p = strchr(e.first, ' ')) {
*p = 0;
e.first = strtrim(e.first);
e.middle = strtrim(p + 1);
if (sqlca.sqlcode == SQL_DUPLICATE) {
com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
return;
- } else if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
} else
sqlexit();
}
INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr, :ophone, :dept, :status
FROM users
WHERE last = :last and first = :first and clearid = :eid;
- if (sqlfail()) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else if (sqlca.sqlcode != SQL_DUPLICATE)
+ if (sqlfail() && sqlca.sqlcode != SQL_DUPLICATE) {
sqlexit();
}
encrypted++;
status = US_ENROLLED;
strcpy(class, e->class);
EXEC SQL UPDATE users
- SET type = :class, status = :status, modtime = 'now',
+ SET type = NVL(:class,CHR(0)), status = :status, modtime = SYSDATE,
modby = :who, modwith = :prog
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating user");
- return;
- } else {
- com_err(whoami, 0, "ingres error %d updating user", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("updating user", sqlca.sqlcode);
+ exit(1);
}
}
strcmp(middle, strtrim(dmiddle))) {
com_err(whoami, 0, "updating real name for %s %s", first, last);
EXEC SQL UPDATE users
- SET first = :first, last = :last, middle = :middle,
- modby = :who, modwith = :prog, modtime = 'now'
+ SET first = NVL(:first,CHR(0)), last = NVL(:last,CHR(0)),
+ middle = NVL(:middle,CHR(0)), modby = :who, modwith = :prog,
+ modtime = SYSDATE
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating name");
- return;
- } else {
- com_err(whoami, 0, "ingres error %d updating name", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("updating name", sqlca.sqlcode);
+ exit(1);
}
}
changed = nochange = 0;
if (encrypted) changed++;
strcpy(buf, e->address);
- while (to = index(buf, ','))
+ while (to = strchr(buf, ','))
*to = ';';
- while (to = index(buf, ':'))
+ while (to = strchr(buf, ':'))
*to = ';';
if (newfinger) {
if (oaddr[0] == ' ' && buf[0]) {
rophone = e->phone2;
if (changed) {
com_err(whoami, 0, "updating finger for %s %s", first, last);
- EXEC SQL REPEATED UPDATE users
- SET office_addr = :oaddr, office_phone = :ophone, department = :dept,
- fmodtime = 'now', fmodby = :who, fmodwith = :prog,
- xname = :name, xdept = :rdept, xtitle = :rtitle,
- xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
- xmodtime = 'now', clearid = :sid
+ EXEC SQL UPDATE users
+ SET office_addr = NVL(:oaddr,CHR(0)),
+ office_phone = NVL(:ophone,CHR(0)), department = NVL(:dept,CHR(0)),
+ fmodtime = SYSDATE, fmodby = :who, fmodwith = :prog,
+ xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
+ xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
+ xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
+ xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr(NULL, sqlca.sqlcode);
+ exit(1);
}
} else {
- EXEC SQL REPEATED UPDATE users
- SET xname = :name, xdept = :rdept, xtitle = :rtitle,
- xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
- xmodtime = 'now', clearid = :sid
+ EXEC SQL UPDATE users
+ SET xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
+ xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
+ xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
+ xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr(NULL, sqlca.sqlcode);
+ exit(1);
}
}
}
prog = PROG;
strncpy(oaddr, e->address, 16);
oaddr[16] = 0;
- while (to = index(oaddr, ','))
+ while (to = strchr(oaddr, ','))
*to = ';';
- while (to = index(oaddr, ':'))
+ while (to = strchr(oaddr, ':'))
*to = ';';
from = e->phone;
to = ophone;
rhphone = e->phone;
rophone = e->phone2;
- EXEC SQL REPEATED INSERT INTO users
- (login, users_id, uid, shell, last, first, middle, status,
+ EXEC SQL INSERT INTO users
+ (login, users_id, unix_uid, shell, last, first, middle, status,
clearid, type, modtime, modby, modwith, fullname, office_addr,
office_phone, department, fmodtime, fmodby, fmodwith,
potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
- VALUES (:login, :id, :uid, '/bin/athena/tcsh', :last, :first,
- :middle, :st, :sid, :class, 'now', :who, :prog,
- :fullname, :oaddr, :ophone, :dept, 'now', :who, :prog,
- 'NONE', :name, :rdept, :title, :oaddr, :rhphone,
- :rophone, 'now');
+ VALUES (:login, :id, :uid, '/bin/athena/tcsh',
+ NVL(:last,CHR(0)), NVL(:first,CHR(0)), NVL(:middle,CHR(0)),
+ :st, NVL(:sid,CHR(0)), NVL(:class,CHR(0)), SYSDATE, :who, :prog,
+ NVL(:fullname,CHR(0)), NVL(:oaddr,CHR(0)), NVL(:ophone,CHR(0)),
+ NVL(:dept,CHR(0)), SYSDATE, :who, :prog, 'NONE',
+ NVL(:name,CHR(0)), NVL(:rdept,CHR(0)), NVL(:title,CHR(0)),
+ NVL(:oaddr,CHR(0)), NVL(:rhphone,CHR(0)), NVL(:rophone,CHR(0)),
+ SYSDATE);
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "adding user");
- } else {
- com_err(whoami, 0, "ingres error %d adding user", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("adding user", sqlca.sqlcode);
+ exit(1);
} else
com_err(whoami, 0, "adding user %s %s", e->first, e->last);
}
int rowcount, flag, value, retval;
EXEC SQL END DECLARE SECTION;
- EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
+ EXEC SQL SELECT value INTO :value FROM numvalues
WHERE name = 'users_id';
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] != 1) {
}
flag = 0;
- EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
+ EXEC SQL SELECT users_id INTO :flag FROM users
WHERE users_id = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
flag = 0;
- EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
+ EXEC SQL SELECT users_id INTO :flag FROM users
WHERE users_id = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
retval = value++;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
- EXEC SQL REPEATED UPDATE numvalues SET value = :value
+ EXEC SQL UPDATE numvalues SET value = :value
WHERE name = 'users_id';
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d assigning ID", sqlca.sqlcode);
+ dbmserr("assigning ID", sqlca.sqlcode);
exit(1);
}
return(retval);
int rowcount, flag, value, retval;
EXEC SQL END DECLARE SECTION;
- EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
- WHERE name = 'uid';
+ EXEC SQL SELECT value INTO :value FROM numvalues
+ WHERE name = 'unix_uid';
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] != 1) {
EXEC SQL ROLLBACK;
}
flag = 0;
- EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
+ EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
flag = 0;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
flag = 0;
- EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
+ EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
flag = 0;
retval = value++;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
- EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = 'uid';
+ EXEC SQL UPDATE numvalues SET value = :value WHERE name = 'unix_uid';
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d assigning ID", sqlca.sqlcode);
+ dbmserr("assigning ID", sqlca.sqlcode);
exit(1);
}
return(retval);
sqlexit()
{
- if (sqlca.sqlcode == SQL_DEADLOCK)
- com_err(whoami, MR_DEADLOCK, "unrecoverable ingres error %d",
- sqlca.sqlcode);
- else
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr(NULL, sqlca.sqlcode);
EXEC SQL ROLLBACK WORK;
exit(1);
}
+
+dbmserr(char *where, int what)
+{
+ char err_msg[256];
+ int bufsize=256, msglength=0;
+
+ sqlglm(err_msg, &bufsize, &msglength);
+ err_msg[msglength]=0;
+
+ if(where)
+ com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where);
+ else
+ com_err(whoami, 0, "DBMS error %s", err_msg);
+}
+++ /dev/null
-/* $Header$ */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <moira.h>
-
-struct user {
- int users_id;
- char first[33];
- char last[33];
- int status;
-};
-
-extern int errno;
-int debug;
-char *program;
-
-
-main(argc, argv)
-int argc;
-char **argv;
-{
- char buf[1024], first[33], last[33];
- int i;
- char *inputfile;
- FILE *in;
- struct user *u;
- struct user users[32];
- struct user *get_user();
-
- program = argv[0];
-
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-d"))
- debug++;
- else if (!strcmp(argv[i], "-D"))
- setenv("ING_SET", "set printqry");
- else if (argv[i][0] == '-')
- usage(argv);
- else if (inputfile != NULL)
- usage(argv);
- else inputfile = argv[i];
- }
-
- if (inputfile) {
- in = fopen(inputfile, "r");
- if (in == NULL) {
- com_err(program, errno, "opening file \"%s\" for input", inputfile);
- exit(1);
- }
- } else
- in = stdin;
-
-## ingres sms
-
- i = 0;
- while (!feof(in)) {
- fgets(buf, sizeof(buf), in);
- u = get_user(buf);
- if (!u) continue;
- if (strcmp(u->last, users[0].last) ||
- strcmp(u->first, users[0].first)) {
- /* We've got a matching group! */
- process_users(users, i);
- bcopy(u, &(users[0]), sizeof(*u));
- i = 1;
- } else {
- bcopy(u, &(users[i]), sizeof(*u));
- i++;
- }
- }
-}
-
-usage(argv)
-char **argv;
-{
- fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]);
- exit(1);
-}
-
-struct user *get_user(buf)
-char *buf;
-{
- static struct user u;
-
- if (sscanf(buf, "| %d|%s |%s | %d|", &u.users_id, u.first,
- u.last, &u.status) != 4) {
- com_err(program, 0, " parsing input line %s", buf);
- return(NULL);
- }
- return(&u);
-}
-
-
-process_users(users, count)
-struct user users[];
-int count;
-##{
- char buf[256];
- int i;
-## char login[9], id[17], class[9], modtime[26], modwith[9], xmodtime[26];
-## char login2[9], id2[17], class2[9], modtime2[26],modwith2[9],xmodtime2[26];
-## char login3[9], id3[17], class3[9], modtime3[26],modwith3[9],xmodtime3[26];
-## int users_id, users_id2, users_id3, status, status2, status3, rowcount;
-
- printf("\nGot %d users named %s %s\n", count, users[0].first, users[0].last);
- if (count < 2) return;
-
- users_id = users[0].users_id;
-## range of u is users
-## retrieve (login = u.#login, id = u.mit_id, class = u.mit_year,
-## modtime = u.#modtime, modwith = u.#modwith,
-## xmodtime = u.#xmodtime, status = u.#status)
-## where u.#users_id = users_id
-
- users_id2 = users[1].users_id;
-## retrieve (login2 = u.#login, id2 = u.mit_id, class2 = u.mit_year,
-## modtime2 = u.#modtime, modwith2 = u.#modwith,
-## xmodtime2 = u.#xmodtime, status2 = u.#status)
-## where u.#users_id = users_id2
-
- modtime[20] = modtime2[20] = xmodtime[20] = xmodtime2[20] = 0;
-
- printf("A: %s %5d %d\t\t\tB: %s %5d %d\n", login, users_id, status,
- login2, users_id2, status2);
- printf(" %s %s\t\t %s %s\n", class, id, class2, id2);
- printf(" %s %s\t %s %s\n", modtime, modwith, modtime2, modwith2);
- printf(" %s\t\t\t %s\n", xmodtime, xmodtime2);
-
- if (count > 2) {
- for (i = 2; i < count; i++) {
- users_id3 = users[i].users_id;
-## retrieve (login3 = u.#login, id3 = u.mit_id, class3 = u.mit_year,
-## modtime3 = u.#modtime, modwith3 = u.#modwith,
-## xmodtime3 = u.#xmodtime, status3 = u.#status)
-## where u.#users_id = users_id3
- modtime3[20] = xmodtime3[20] = 0;
- printf("\n%c: %s %5d %d\n", 'A' + i,
- login3, users_id3, status3);
- printf(" %s %s\n", class3, id3);
- printf(" %s %s\n", modtime3, modwith3);
- printf(" %s\n", xmodtime3);
- }
- }
-
- if (count == 2) {
- if (status == 3 || status2 == 3) return;
- if ((status == 0 || status == 4) &&
- !isdigit(id[0]) && !isdigit(xmodtime[0])) {
- printf("DELETING %s\n", login);
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s marked for deletion.\n", login);
- return;
- }
- if ((status2 == 0 || status2 == 4) &&
- !isdigit(id2[0]) && !isdigit(xmodtime2[0])) {
- printf("DELETING %s\n", login2);
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id2
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s marked for deletion.\n", login2);
- return;
- }
- }
-
- printf("\n0,sp: Do nothing\n1: Delete B\n2: Delete A\n");
- printf("3: A<-B's ID; Delete B\n4: B<-A's ID; Delete A\n");
- if (count > 2)
- printf("5: Delete C\n");
- if (count > 3)
- printf("6: Delete D\n");
- printf("?");fflush(stdout);
- gets(buf);
- switch (buf[0]) {
- case '1':
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id2
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s marked for deletion.\n", login2);
- break;
- case '2':
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s marked for deletion.\n", login);
- break;
- case '3':
-## replace u (#mit_id = id2, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id2
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s updated, %s marked for deletion.\n", login, login2);
- break;
- case '4':
-## replace u (#mit_id = id, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id2
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %s updated, %s marked for deletion.\n", login2, login);
- break;
- case '5':
- users_id = users[2].users_id;
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %d marked for deletion.\n", users[2].users_id);
- break;
- case '6':
- users_id = users[3].users_id;
-## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
-## modby=8873) where u.#users_id = users_id
-## inquire_equel(rowcount = "rowcount")
- if (rowcount != 1)
- printf("Failed!\007\007\007\n");
- else
- printf("User %d marked for deletion.\n", users[3].users_id);
- break;
- case 'q':
- exit(0);
- default:
- printf("Leaving unchanged\n");
- }
-##}
*/
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <moira.h>
SigInfo si;
int found, status, i, wait;
EXEC SQL BEGIN DECLARE SECTION;
- char login[10], mid[32], rawsig[256];
+ char login[10], mid[32], rawsig[256], *db="moira";
int id, timestamp, sms;
EXEC SQL END DECLARE SECTION;
com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt");
}
- EXEC SQL CONNECT moira;
+ EXEC SQL CONNECT :db IDENTIFIED BY :db;
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
exit(1);
}
SELECT users_id, login, clearid
FROM users WHERE signature = '';
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
exit(1);
}
EXEC SQL OPEN c;
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
exit(1);
}
while (1) {
si.rawsig = (unsigned char *) &rawsig[0];
while (sq_get_data(sq, &data)) {
- p = index(data, ':');
+ p = strchr(data, ':');
if (!p) {
com_err(program, 0, " malformatted data");
continue;
}
timestamp = si.timestamp;
- EXEC SQL REPEATED UPDATE users
+ EXEC SQL UPDATE users
SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
exit(1);
}
EXEC SQL COMMIT WORK;
*/
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <moira.h>
char *whoami;
int newfinger = 0;
-#define SQL_DUPLICATE -40100
-#define SQL_DEADLOCK -49900
-#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 100)
+#define SQL_DUPLICATE 1422
+#define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403)
main(argc, argv)
int argc;
struct entry *e, *get_next_entry();
int i, wait = 0;
char buf[BUFSIZ], *file = NULL;
+EXEC SQL BEGIN DECLARE SECTION;
+ char *db="moira";
+EXEC SQL END DECLARE SECTION;
- whoami = rindex(argv[0], '/');
+ whoami = strrchr(argv[0], '/');
if (whoami)
whoami++;
else
whoami = argv[0];
+ setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-w"))
wait++;
exit(1);
}
- setlinebuf(stdout);
- setlinebuf(stderr);
initialize_sms_error_table();
- EXEC SQL CONNECT moira;
+ EXEC SQL CONNECT :db IDENTIFIED BY :db;
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr("connecting", sqlca.sqlcode);
exit(1);
}
process_entry(e);
EXEC SQL COMMIT WORK;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "commiting work");
- goto again;
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("committing work", sqlca.sqlcode);
+ exit(1);
}
if (wait) {
printf("Next");
strcpy(sname, name);
e.name = strtrim(sname);
- p = index(name, ',');
+ p = strchr(name, ',');
if (p)
*p = 0;
e.last = strtrim(name);
while (isspace(*p))
p++;
e.first = p;
- if (p = index(e.first, ' ')) {
+ if (p = strchr(e.first, ' ')) {
*p = 0;
e.first = strtrim(e.first);
e.middle = strtrim(p + 1);
encrypted = 0;
/* Get user info */
- EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
+ EXEC SQL SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
FROM users
WHERE clearid = :sid;
if (sqlca.sqlcode == SQL_DUPLICATE) {
com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
return;
- } else if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
} else
sqlexit();
}
if (id == 0) {
- EXEC SQL REPEATED SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
+ EXEC SQL SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
FROM users
WHERE last = :last and first = :first and clearid = :eid;
- if (sqlfail()) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "looking up user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else if (sqlca.sqlcode != SQL_DUPLICATE)
- sqlexit();
- }
+ if (sqlfail()) sqlexit();
encrypted++;
if (id == 0) {
newuser(e);
if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
strcpy(class, e->class);
- EXEC SQL REPEATED UPDATE users
- SET type = :class, status = :status, modtime = 'now',
+ EXEC SQL UPDATE users
+ SET type = NVL(:class,CHR(0)), status = :status, modtime = SYSDATE,
modby = :who, modwith = :prog
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr("updating class", sqlca.sqlcode);
exit(1);
}
}
strcmp(middle, strtrim(dmiddle))) {
com_err(whoami, 0, "updating real name for %s %s", first, last);
EXEC SQL UPDATE users
- SET first = :first, last = :last, middle = :middle,
- modby = :who, modwith = :prog, modtime = 'now'
+ SET first = NVL(:first,CHR(0)), last = NVL(:last,CHR(0)),
+ middle = NVL(:middle,CHR(0)), modby = :who, modwith = :prog,
+ modtime = SYSDATE
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr("updating name", sqlca.sqlcode);
exit(1);
}
}
strcat(buf, " ");
strcat(buf, e->state);
}
- while (to = index(buf, ','))
+ while (to = strchr(buf, ','))
*to = ';';
- while (to = index(buf, ':'))
+ while (to = strchr(buf, ':'))
*to = ';';
if (newfinger) {
if (haddr[0] == ' ') {
}
if (changed) {
com_err(whoami, 0, "updating finger for %s %s", first, last);
- EXEC SQL REPEATED UPDATE users
- SET home_addr = :haddr, home_phone = :hphone,
- office_phone = :ophone, department = :dept,
- fmodtime = 'now', fmodby = :who, fmodwith = :prog,
- xname = :name, xdept = :rdept, xtitle = :rtitle,
- xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
- xmodtime = date('now'), clearid = :sid
+ EXEC SQL UPDATE users
+ SET home_addr = NVL(:haddr,CHR(0)), home_phone = NVL(:hphone,CHR(0)),
+ office_phone = NVL(:ophone,CHR(0)), department = NVL(:dept,CHR(0)),
+ fmodtime = SYSDATE, fmodby = :who, fmodwith = :prog,
+ xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
+ xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
+ xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
+ xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr(NULL, sqlca.sqlcode);
+ exit(1);
}
} else {
- EXEC SQL REPEATED UPDATE users
- SET xname = :name, xdept = :rdept, xtitle = :rtitle,
- xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
- xmodtime = date('now'), clearid = :sid
+ EXEC SQL UPDATE users
+ SET xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
+ xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
+ xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
+ xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
WHERE users_id = :id;
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "updating user %s", sid);
- EXEC SQL ROLLBACK;
- return process_entry(e);
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr(NULL, sqlca.sqlcode);
+ exit(1);
}
}
}
FixCase(raddr);
strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
}
- EXEC SQL REPEATED INSERT INTO users
- (login, users_id, uid, shell, last, first, middle, status,
+ EXEC SQL INSERT INTO users
+ (login, users_id, unix_uid, shell, last, first, middle, status,
clearid, type, modtime, modby, modwith, fullname, home_addr,
home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
- VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, 0,
- :sid, :class, 'now', :who, :prog, :fullname, :haddr, :hphone,
- :ophone, :dept, 'now', :who, :prog, 'NONE', :name, :dept,
- :title, :raddr, :hphone, :ophone, date('now'));
+ VALUES (:login, :id, :uid, '/bin/athena/tcsh', NVL(:last,CHR(0)),
+ NVL(:first,CHR(0)), NVL(:middle,CHR(0)), 0, NVL(:sid,CHR(0)),
+ NVL(:class,CHR(0)), SYSDATE, :who, :prog, NVL(:fullname,CHR(0)),
+ NVL(:haddr,CHR(0)), NVL(:hphone,CHR(0)), NVL(:ophone,CHR(0)),
+ NVL(:dept,CHR(0)), SYSDATE, :who, :prog, 'NONE',
+ NVL(:name,CHR(0)), NVL(:dept,CHR(0)), NVL(:title,CHR(0)),
+ NVL(:raddr,CHR(0)), NVL(:hphone,CHR(0)), NVL(:ophone,CHR(0)),
+ SYSDATE);
if (sqlca.sqlcode != 0) {
- if (sqlca.sqlcode == SQL_DEADLOCK) {
- com_err(whoami, MR_DEADLOCK, "adding user %s", sid);
- EXEC SQL ROLLBACK;
- return newuser(e);
- } else {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
- exit(1);
- }
+ dbmserr("adding user", sqlca.sqlcode);
+ exit(1);
} else
com_err(whoami, 0, "adding user %s %s", e->first, e->last);
}
int rowcount, flag, value, retval;
EXEC SQL END DECLARE SECTION;
- EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
+ EXEC SQL SELECT value INTO :value FROM numvalues
WHERE name = 'users_id';
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] != 1) {
}
flag = 0;
- EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
+ EXEC SQL SELECT users_id INTO :flag FROM users
WHERE users_id = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
flag = 0;
- EXEC SQL REPEATED SELECT users_id INTO :flag FROM users
+ EXEC SQL SELECT users_id INTO :flag FROM users
WHERE users_id = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
retval = value++;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
- EXEC SQL REPEATED UPDATE numvalues SET value = :value
+ EXEC SQL UPDATE numvalues SET value = :value
WHERE name = 'users_id';
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr("updating numvalues", sqlca.sqlcode);
exit(1);
}
return(retval);
int rowcount, flag, value, retval;
EXEC SQL END DECLARE SECTION;
- EXEC SQL REPEATED SELECT value INTO :value FROM numvalues
- WHERE name = 'uid';
+ EXEC SQL SELECT value INTO :value FROM numvalues
+ WHERE name = 'unix_uid';
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] != 1) {
EXEC SQL ROLLBACK;
}
flag = 0;
- EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
+ EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
flag = 0;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
flag = 0;
- EXEC SQL REPEATED SELECT uid INTO :flag FROM users WHERE uid = :value;
+ EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
if (sqlfail()) sqlexit();
if (sqlca.sqlerrd[2] == 0)
flag = 0;
retval = value++;
if (limit && value > MAX_ID_VALUE)
value = MIN_ID_VALUE;
- EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = 'uid';
+ EXEC SQL UPDATE numvalues SET value = :value WHERE name = 'unix_uid';
if (sqlca.sqlcode != 0) {
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr("updating numvalues", sqlca.sqlcode);
exit(1);
}
return(retval);
sqlexit()
{
- if (sqlca.sqlcode == SQL_DEADLOCK)
- com_err(whoami, MR_DEADLOCK, "unrecoverable ingres error %d",
- sqlca.sqlcode);
- else
- com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
+ dbmserr(NULL, sqlca.sqlcode);
EXEC SQL ROLLBACK WORK;
exit(1);
}
+
+dbmserr(char *where, int what)
+{
+ char err_msg[256];
+ int bufsize=256, msglength=0;
+
+ sqlglm(err_msg, &bufsize, &msglength);
+ err_msg[msglength]=0;
+
+ if(where)
+ com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where);
+ else
+ com_err(whoami, 0, "DBMS error %s", err_msg);
+}
*/
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <moira.h>
int argc;
char **argv;
{
- char buf[BUFSIZ], *usercheck[100], sigbuf[256], *data;
+ char buf[BUFSIZ], *usercheck[100], sigbuf[256], *data, *db="moira";
SigInfo si;
struct save_queue *sq;
int status, i, wait, check, debug, fix;
EXEC SQL BEGIN DECLARE SECTION;
char login[10], mid[32], rawsig[256], who[257];
+ EXEC SQL VAR rawsig IS STRING(256);
int id, timestamp, sms;
EXEC SQL END DECLARE SECTION;
else usercheck[check++] = argv[i];
}
- EXEC SQL CONNECT moira;
+ EXEC SQL CONNECT :db IDENTIFIED BY :db;
if (fix) {
/* Set the name of our kerberos ticket file */
EXEC SQL DECLARE c CURSOR FOR
SELECT login, clearid, signature, string, sigdate
FROM users, strings
- WHERE signature != '' and sigwho = string_id;
+ WHERE signature != CHR(0) and sigwho = string_id;
EXEC SQL OPEN c;
while (1) {
EXEC SQL FETCH c INTO :login, :mid, :rawsig, :who, :timestamp;
if (fix) {
while (sq_get_data(sq, &data)) {
strncpy(login, data, 8);
- if (index(login, ':'))
- *index(login, ':') = 0;
+ if (strchr(login, ':'))
+ *strchr(login, ':') = 0;
again:
com_err(program, 0, "fixing sig for %s", login);
status = GDSS_Sign(data, strlen(data), sigbuf, &si);
}
timestamp = si.timestamp;
- EXEC SQL REPEATED UPDATE users
+ EXEC SQL UPDATE users
SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp
WHERE login = :login;
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
dest_tkt();
exit(1);
}
EXEC SQL DECLARE s CURSOR FOR
SELECT clearid, signature, string, sigdate
FROM users, strings
- WHERE signature != '' and sigwho = string_id and login = :login;
+ WHERE sigwho = string_id and login = :login;
EXEC SQL OPEN s;
while (1) {
EXEC SQL FETCH s INTO :mid, :rawsig, :who, :timestamp;
}
timestamp = si.timestamp;
- EXEC SQL REPEATED UPDATE users
+ EXEC SQL UPDATE users
SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp
WHERE login = :login;
if (sqlca.sqlcode != 0) {
- com_err(program, 0, "ingres error %d", sqlca.sqlcode);
+ com_err(program, 0, "dbms error %d", sqlca.sqlcode);
dest_tkt();
exit(1);
}
*/
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <moira.h>
FILE *in;
struct entry *e, *get_next_entry();
int i, wait = 0;
- char buf[BUFSIZ], *file = NULL, *p, *p1;
+ char buf[BUFSIZ], *file = NULL, *p, *p1, *db="moira";
debug = 0;
- whoami = rindex(argv[0], '/');
+ whoami = strrchr(argv[0], '/');
if (whoami)
whoami++;
else
whoami = argv[0];
+ setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-w"))
wait++;
exit(1);
}
- setlinebuf(stdout);
- setlinebuf(stderr);
-
- EXEC SQL CONNECT moira;
+ EXEC SQL CONNECT :db IDENTIFIED BY :db;
if (sqlca.sqlcode != 0) {
com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
exit(1);
{
EXEC SQL BEGIN DECLARE SECTION;
char *id, *login;
+ EXEC SQL VAR login is STRING(9);
EXEC SQL END DECLARE SECTION;
id = e->id;
login = e->login;
- EXEC SQL REPEATED SELECT login INTO :login FROM users
- WHERE clearid = :id;
+ EXEC SQL SELECT login INTO :login FROM users WHERE clearid = :id;
if (sqlca.sqlcode != 0) {
fprintf(stderr, "Error %d on %s\n", sqlca.sqlcode, e->line);
return(-1);