From: danw Date: Mon, 20 Jan 1997 18:22:47 +0000 (+0000) Subject: Oracle and Solaris/POSIX changes X-Git-Tag: MOIRA4_INITIAL~4 X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/9c04b191b56a0e1ea6bd408e228034e35b7783c4 Oracle and Solaris/POSIX changes Removed unused files. Source tree should only have Imakefiles, not Makefiles --- diff --git a/gen/Imakefile b/gen/Imakefile index ea40b5e7..ddb7c10f 100644 --- a/gen/Imakefile +++ b/gen/Imakefile @@ -10,67 +10,50 @@ SRCDIR = $(SRCTOP)/gen #ifdef GDSS -SRCS = util.c moddiff.c ca.c passwd.c zephyr.c aliases.c hesiod.c \ - nfs.c mailhub.c mitdir.c prlogger.c stats.c sis.c pobox.c \ - letter.c hosts.c report.c networks.c -OBJS = util.o moddiff.o ca.o passwd.o zephyr.o aliases.o hesiod.o \ - nfs.o mailhub.o mitdir.o prlogger.o stats.o sis.o pobox.o \ - letter.o hosts.o report.o networks.o -CODE = util.c moddiff.dc ca.dc passwd.dc zephyr.dc aliases.dc hesiod.dc \ - nfs.dc mailhub.dc mitdir.dc prlogger.dc stats.dc sis.dc pobox.dc \ - letter.dc hosts.dc report.dc networks.dc +SRCS = util.c moddiff.c passwd.c hesiod.c \ + nfs.c mailhub.c sis.c pobox.c \ + hosts.c networks.c +OBJS = util.o moddiff.o passwd.o hesiod.o \ + nfs.o mailhub.o sis.o pobox.o \ + hosts.o networks.o +CODE = util.c moddiff.dc passwd.dc hesiod.dc \ + nfs.dc mailhub.dc sis.dc pobox.dc \ + hosts.dc networks.dc LIBS = -L/usr/athena/lib ../lib/libmoira.a -lcom_err -lzephyr \ - ../server/libmrglue.a /mit/gdss/`machtype`/libgdss.a \ - -lkrb -ldes -lhesiod ${SQL_LIB} -DEFINES = -I/mit/gdss/include + ../server/libmrglue.a $(LIBGDSS) -lkrb -ldes -lhesiod ${SQL_LIB} +DEFINES = $(GDSSINC) #else /* GDSS */ -SRCS = util.c moddiff.c ca.c passwd.c zephyr.c aliases.c hesiod.c \ - nfs.c mailhub.c mitdir.c prlogger.c stats.c pobox.c \ - letter.c hosts.c report.c networks.c -OBJS = util.o moddiff.o ca.o passwd.o zephyr.o aliases.o hesiod.o \ - nfs.o mailhub.o mitdir.o prlogger.o stats.o pobox.o \ - letter.o hosts.o report.o networks.o -CODE = util.c moddiff.dc ca.dc passwd.dc zephyr.dc aliases.dc hesiod.dc \ - nfs.dc mailhub.dc mitdir.dc prlogger.dc stats.dc pobox.dc \ - letter.dc hosts.dc report.dc networks.dc +SRCS = util.c moddiff.c passwd.c hesiod.c \ + nfs.c mailhub.c pobox.c \ + hosts.c networks.c +OBJS = util.o moddiff.o passwd.o hesiod.o \ + nfs.o mailhub.o pobox.o \ + hosts.o networks.o +CODE = util.c moddiff.dc passwd.dc hesiod.dc \ + nfs.dc mailhub.dc pobox.dc \ + hosts.dc networks.dc LIBS = -L/usr/athena/lib ../lib/libmoira.a -lcom_err -lzephyr \ ../server/libmrglue.a -lkrb -ldes -lhesiod ${SQL_LIB} DEFINES = #endif /* GDSS */ sqlrule() -program(ca.gen, ca.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(moddiff) -sqlfile(ca) program(passwd.gen, passwd.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) +sqlfile(moddiff) sqlfile(passwd) -program(zephyr.gen, zephyr.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(zephyr) -program(aliases.gen, aliases.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(aliases) program(hesiod.gen, hesiod.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(hesiod) program(nfs.gen, nfs.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(nfs) program(mailhub.gen, mailhub.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(mailhub) -program(mitdir.gen, mitdir.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(mitdir) -program(prlogger.gen, prlogger.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(prlogger) -program(stats.gen, stats.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(stats) #ifdef GDSS program(sis.gen, sis.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(sis) #endif program(pobox.gen, pobox.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(pobox) -program(letter.gen, letter.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(letter) program(hosts.gen, hosts.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(hosts) -program(report.gen, report.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) -sqlfile(report); program(networks.gen, networks.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(networks) diff --git a/gen/aliases.dc b/gen/aliases.dc deleted file mode 100644 index a65cff59..00000000 --- a/gen/aliases.dc +++ /dev/null @@ -1,459 +0,0 @@ -/* $Header$ - * - * This generates the /usr/lib/aliases mail aliases file for the mailhub. - * The aliases file will contain: - * user pobox entries - * maillist expansions - * sublists of maillists - * - * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - - -#define ML_WID 72 -#define AL_MAX_WID 592 - -char *divide = "########################################################################"; -extern int errno; -char *whoami = "aliases.gen"; -FILE *out; - -main(argc, argv) -int argc; -char **argv; -{ - long tm = time(NULL); - char filename[64], *targetfile; - struct stat sb; - int flag1, flag2, flag3; - - out = stdout; - initialize_sms_error_table(); -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - - if (ModDiff (&flag1, "list", sb.st_mtime) || - ModDiff (&flag2, "imembers", sb.st_mtime) || - ModDiff (&flag3, "users", sb.st_mtime)) exit (MR_DATE); - - if (flag1 < 0 && flag2 < 0 && flag3 < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - targetfile = argv[1]; - sprintf(filename, "%s~", targetfile); - if ((out = fopen(filename, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", filename); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } - - fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm)); - fprintf(out, "# This file is automatically generated, do not edit it directly.\n%s\n\n", divide); - - get_info(); -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endif -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql - - fprintf(stderr, "Dumping information\n"); - do_mlists(out); - do_poboxes(out); - - fprintf(out, "\n%s\n# End of aliases file\n%s\n", divide, divide); - - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - - if (argc == 2) - fix_file(targetfile); - exit(MR_SUCCESS); -} - - -struct hash *users, *machines, *strings, *lists; -struct user { - char login[9]; - char *pobox; -}; -struct member { - struct member *next; - char *name; - int list_id; -}; -struct list { - char *name; - char maillist; - char acl_t; - char *description; - int acl_id; - struct member *m; -}; - - -get_info() -{ - EXEC SQL BEGIN DECLARE SECTION; - int id, maillistp, acl, pid, bid, mid; - char name[129], type[9], buf[257]; - EXEC SQL END DECLARE SECTION; - char *s; - register struct user *u; - register struct list *l; - register struct member *m; - register struct list *memberlist; - - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - /* get locks */ - EXEC SQL SELECT modtime INTO :buf FROM list WHERE LIST_ID = 0; - EXEC SQL SELECT modtime INTO :buf FROM users WHERE USERS_ID = 0; - - fprintf(stderr, "Loading machines\n"); - machines = create_hash(1000); - - EXEC SQL DECLARE m_cursor CURSOR FOR - SELECT mach_id, name - FROM machine - ORDER BY mach_id; - EXEC SQL OPEN m_cursor; - while (1) { - EXEC SQL FETCH m_cursor INTO :id, :name; - if (sqlca.sqlcode != 0) break; - if (s = index(name, '.')) - *s = 0; -#ifdef ATHENA - strcat(name, ".LOCAL"); -#endif - hash_store(machines, id, strsave(name)); - } - EXEC SQL CLOSE m_cursor; - - - fprintf(stderr, "Loading strings\n"); - strings = create_hash(11001); - - EXEC SQL DECLARE s_cursor CURSOR FOR - SELECT string_id, trim(string) - FROM strings - ORDER BY string_id; - EXEC SQL OPEN s_cursor; - while (1) { - EXEC SQL FETCH s_cursor INTO :id, :name; - if (sqlca.sqlcode != 0) break; - hash_store(strings, id, strsave(name)); - } - EXEC SQL CLOSE s_cursor; - - fprintf(stderr, "Loading users\n"); - users = create_hash(12001); - - EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT users_id, login, potype, pop_id, box_id - FROM users WHERE status = 1 OR status = 5 OR status = 6 - ORDER BY users_id; - EXEC SQL OPEN u_cursor; - while (1) { - EXEC SQL FETCH u_cursor INTO :id, :name, :type, :pid, :bid; - if (sqlca.sqlcode != 0) break; - u = (struct user *) malloc(sizeof(struct user)); - strcpy(u->login, strtrim(name)); - if (type[0] == 'P') { - if (s = hash_lookup(machines, pid)) { - sprintf(buf, "%s@%s", name, s); - u->pobox = strsave(buf); - } else { - u->pobox = (char *) NULL; - fprintf(stderr, "User %s's pobox is on a missing machine!\n", - u->login); - } - } else if (type[0] == 'S') { - if ((u->pobox = hash_lookup(strings, bid)) == NULL) { - u->pobox = (char *) NULL; - fprintf(stderr, "User %s's pobox string is missing!\n", - u->login); - } - } else - u->pobox = (char *) NULL; - hash_store(users, id, u); - } - EXEC SQL CLOSE u_cursor; - EXEC SQL COMMIT; - - fprintf(stderr, "Loading lists\n"); - lists = create_hash(15001); - - EXEC SQL DECLARE l_cursor CURSOR FOR - SELECT list_id, name, maillist, description, acl_type, acl_id - FROM list WHERE active != 0 - ORDER BY list_id; - EXEC SQL OPEN l_cursor; - while (1) { - EXEC SQL FETCH l_cursor INTO :id, :name, :maillistp, - :buf, :type, :acl; - if (sqlca.sqlcode != 0) break; - l = (struct list *) malloc(sizeof(struct list)); - l->name = strsave(strtrim(name)); - l->maillist = maillistp; - l->description = strsave(strtrim(buf)); - l->acl_t = type[0]; - l->acl_id = acl; - l->m = (struct member *) NULL; - hash_store(lists, id, l); - } - EXEC SQL CLOSE l_cursor; - EXEC SQL COMMIT; - - fprintf(stderr, "Loading members\n"); - - EXEC SQL DECLARE mem_cursor CURSOR FOR - SELECT list_id, member_type, member_id - FROM imembers WHERE direct = 1 - ORDER BY list_id; - EXEC SQL OPEN mem_cursor; - while (1) { - EXEC SQL FETCH mem_cursor INTO :id, :type, :mid; - if (sqlca.sqlcode != 0) break; - if (l = (struct list *) hash_lookup(lists, id)) { - m = (struct member *) malloc(sizeof(struct member)); - if (type[0] == 'U' && - (u = (struct user *) hash_lookup(users, mid))) { - m->list_id = 0; - m->name = u->login; - m->next = l->m; - l->m = m; - } else if (type[0] == 'L' && - (memberlist = (struct list *) hash_lookup(lists, mid))) { - m->list_id = mid; - m->name = memberlist->name; - m->next = l->m; - l->m = m; - } else if (type[0] == 'S' && - (s = hash_lookup(strings, mid))) { - m->list_id = 0; - m->name = s; - m->next = l->m; - l->m = m; - } - } - } - EXEC SQL CLOSE mem_cursor; - return; - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Alias build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -save_mlist(id, l, force) -int id; -register struct list *l; -int force; -{ - register struct member *m; - struct list *l1; - - if (l->maillist == 2 || - (l->maillist == 0 && !force)) - return; - - if (l->m && l->m->next == NULL && - !strcasecmp(l->name, l->m->name)) { - l->maillist = 0; - return; - } - l->maillist = 2; - output_mlist(id, l); - - if (l->acl_t == 'L' && (l1 = (struct list *)hash_lookup(lists, l->acl_id))) - save_mlist(0, l1, 1); - - for (m = l->m; m; m = m->next) { - if (m->list_id && (l1 = (struct list *)hash_lookup(lists, m->list_id))) - save_mlist(0, l1, 1); - } -} - - -int lwid, bol, awid; - -output_mlist(id, l) -int id; -register struct list *l; -{ - struct list *l1; - register struct member *m; - struct user *u; - - put_fill(out, l->description); - if (l->acl_t == 'L') { - if (l1 = (struct list *) hash_lookup(lists, l->acl_id)) - fprintf(out, "owner-%s: %s\n", l->name, l1->name); - } else if (l->acl_t == 'U') { - if (u = (struct user *) hash_lookup(users, l->acl_id)) - fprintf(out, "owner-%s: %s\n", l->name, u->login); - } - - fprintf(out, "%s: ", l->name); - lwid = strlen(l->name) + 2; - bol = 1; - for (m = l->m; m; m = m->next) - do_member(out, m->name); - if (l->m == (struct member *)NULL) - fprintf(out, "/dev/null"); - fprintf(out, "\n\n"); -} - - -/* Extract mailing lists. Make a list of all mailinglists, then - * process them, adding any sub-lists or acl lists to the list of lists - * to be processed. If further sublists are encountered, repeat... - */ - -do_mlists(out) -FILE *out; -{ - fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide); - hash_step(lists, save_mlist, 0); -} - - -/* print out strings separated by commas, doing line breaks as appropriate */ - -do_member(out, s) -FILE *out; -register char *s; -{ - register wwid; - static int cont = 1; - - wwid = strlen(s); - - if (!bol && awid + wwid + 2 > AL_MAX_WID) { - fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont); - cont++; - awid = lwid = 17 + wwid; - fputs(s, out); - return; - } - - if (bol) { - lwid += wwid; - awid = lwid; - fputs(s, out); - bol = 0; - return; - } - if (lwid + wwid + 2 > ML_WID) { - fprintf(out, ",\n\t%s", s); - awid += lwid + wwid + 2; - lwid = wwid + 8; - return; - } - lwid += wwid + 2; - fprintf(out, ", %s", s); -} - -do_pobox(id, u, out) -int id; -register struct user *u; -FILE *out; -{ - if (u->pobox) - fprintf(out, "%s: %s\n", u->login, u->pobox); -} - - -/* Do user poboxes. Just step through the users table, and print any - * we extracted earlier. - */ - -do_poboxes(out) -FILE *out; -{ - fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide); - - hash_step(users, do_pobox, out); -} - - -put_fill(aliases, string) -FILE *aliases; -register char *string; -{ - register char *c; - register int lwid; - register int wwid; - - if (*string == 0) return; - fputs("# ", aliases); - lwid = 3; - - while (1) { - while (*string && *string == ' ') string++; - c = (char *)index(string, ' '); - if (c == 0) { - wwid = strlen(string); - } else { - wwid = c - string; - *c = 0; - } - - if ((lwid + wwid) > ML_WID) { - fputs("\n# ", aliases); - lwid = 3; - fputs(string, aliases); - } else { - fputs(string, aliases); - } - - if (c == (char *)0) break; - /* add a space after the word */ - (void) fputc(' ', aliases); - wwid++; - lwid += wwid; - string += wwid; - /* add another if after a period */ - if (*--c == '.') { - (void) fputc(' ', aliases); - lwid++; - } - } - - (void) fputc('\n', aliases); -} diff --git a/gen/aliases.sh b/gen/aliases.sh deleted file mode 100644 index 3b3dd59b..00000000 --- a/gen/aliases.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -PATH=/bin:/usr/ucb:/usr/bin - -MR_MKCRED=47836474 - -cat /usr/lib/local-aliases >> /usr/lib/aliases.new -diff /usr/lib/aliases /usr/lib/aliases.new > /tmp/aliasdiff -cp /dev/null /usr/lib/aliases.new.dir -cp /dev/null /usr/lib/aliases.new.pag -/usr/lib/sendmail -bi -oA/usr/lib/aliases.new -if [ $? != 0 ]; then - exit $MR_MKCRED - fi -kill `ps ax | grep "accepting connections" | grep -v grep | awk '{print $1}'` -mv /usr/lib/aliases /usr/lib/aliases.old -mv /usr/lib/aliases.dir /usr/lib/aliases.old.dir -mv /usr/lib/aliases.pag /usr/lib/aliases.old.pag -mv /usr/lib/aliases.new /usr/lib/aliases -mv /usr/lib/aliases.new.dir /usr/lib/aliases.dir -mv /usr/lib/aliases.new.pag /usr/lib/aliases.pag -/usr/lib/sendmail -bd -q30m - -rm -f $0 -exit 0 - -# $Header$ diff --git a/gen/ca.dc b/gen/ca.dc deleted file mode 100644 index 5ff09983..00000000 --- a/gen/ca.dc +++ /dev/null @@ -1,181 +0,0 @@ -/* $Header$ - * - * This generates a list of users and their home directories for the - * Centra America daemon. - * - * (c) Copyright 1991 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -extern int errno; -char *whoami = "ca.gen"; - -struct prec { - int phys_id; - char mach[64]; - char dir[128]; -}; - - -main(argc, argv) -int argc; -char **argv; -{ - FILE *out = stdout; - char *outf = NULL, outft[64], *p, last[256]; - struct stat sb; - struct save_queue *sq; - struct prec *prec; - int flag1, flag2, first, cnt; - EXEC SQL BEGIN DECLARE SECTION; - char login[257], name[257], dir[257]; - int id; - EXEC SQL END DECLARE SECTION; - - initialize_sms_error_table (); - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag1, "users", sb.st_mtime) == 0 && - ModDiff (&flag2, "filesys", sb.st_mtime) == 0 && - flag1 < 0 && flag2 < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - outf = argv[1]; - sprintf(outft, "%s~", outf); - if ((out = fopen(outft, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } else { - outf = NULL; - } - - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - sq = sq_create(); - - cnt = 0; - EXEC SQL DECLARE y CURSOR FOR - SELECT p.nfsphys_id, p.dir, m.name - FROM nfsphys p, machine m - WHERE m.mach_id = p.mach_id - ORDER BY p.nfsphys_id; - EXEC SQL OPEN y; - while (1) { - EXEC SQL FETCH y INTO :id, :dir, :name; - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - strtrim(dir); - strtrim(name); - prec = (struct prec *) malloc(sizeof(struct prec)); - prec->phys_id = id; - strcpy(prec->mach, strtrim(name)); - strcpy(prec->dir, strtrim(dir)); - sq_save_data(sq, prec); - cnt++; - } - EXEC SQL CLOSE y; - fprintf(stderr, "Loaded %d NFS partitions\n", cnt); - - while (sq_get_data(sq, &prec)) { - id = prec->phys_id; -#ifdef DEBUG - printf("got ID %d\n", id); - printf("mach %s dir %s\n", prec->mach, prec->dir); -#endif - EXEC SQL DECLARE x CURSOR FOR - SELECT u.login, u.fullname - FROM users u, filesys f - WHERE f.label = u.login and u.status = 1 and f.phys_id = :id - ORDER BY u.login; - EXEC SQL OPEN x; - first = 1; - while (1) { - EXEC SQL FETCH x INTO :login, :name; - if (sqlca.sqlcode != 0) break; - if (first) { - first = 0; - fprintf(out, "*%s:%s\n", prec->mach, prec->dir); - } - strtrim(login); - strtrim(name); - fprintf(out, "%s,%s\n", login, name); - } - EXEC SQL CLOSE x; - } - fprintf(stderr, "Processed NFS partitions\n"); - - cnt = 0; - EXEC SQL DECLARE z CURSOR FOR - SELECT DISTINCT u.login, u.fullname, f.name - FROM users u, filesys f - WHERE f.label = u.login and u.status = 1 and f.type = 'AFS' - ORDER BY u.login; - EXEC SQL OPEN z; - while (1) { - EXEC SQL FETCH z INTO :login, :name, :dir; - if (sqlca.sqlcode != 0) break; - p = rindex(dir, '/'); - if (p) *p = 0; - if (strcmp(last, dir)) { - strcpy(last, dir); - fprintf(out, "*%s:%s\n", "AFS", dir); - } - strtrim(login); - strtrim(name); - fprintf(out, "%s,%s\n", login, name); - cnt++; - } - EXEC SQL CLOSE z; - fprintf(stderr, "Processed %d AFS users\n", cnt); - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); - - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Central America build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} diff --git a/gen/hesiod.dc b/gen/hesiod.dc index c41149cd..53440490 100644 --- a/gen/hesiod.dc +++ b/gen/hesiod.dc @@ -17,13 +17,19 @@ #include #include #include +#include EXEC SQL INCLUDE sqlca; -#ifdef ATHENA +#ifndef HTYPE #define HTYPE "UNSPECA" -#else -#define HTYPE "TXT" +#endif +#ifndef HCLASS +#define HCLASS "HS" +#endif + +#ifndef HESIOD_SUBDIR +#define HESIOD_SUBDIR "hesiod" #endif /* max number of bytes of a data record that can be returned in a hesiod @@ -37,6 +43,7 @@ char hesiod_dir[64]; struct hash *machines = NULL; struct hash *users = NULL; char *whoami = "hesiod.gen"; +char *db = "moira/moira"; struct grp { struct grp *next; @@ -65,15 +72,9 @@ char **argv; } initialize_sms_error_table (); - sprintf(hesiod_dir, "%s/hesiod", DCM_DIR); + sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR); -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; changed = do_passwd(); changed += do_filsys(); @@ -84,13 +85,6 @@ char **argv; changed += do_service(); changed += do_groups(); -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - if (!changed) { fprintf(stderr, "No files updated.\n"); if (argc == 2 && stat(argv[1], &sb) == 0) @@ -122,7 +116,7 @@ get_mach() EXEC SQL DECLARE m_cursor CURSOR FOR SELECT name, mach_id FROM machine - WHERE status = 1 + WHERE status = 1 and mach_id != 0 ORDER BY mach_id; EXEC SQL OPEN m_cursor; while (1) { @@ -132,12 +126,7 @@ get_mach() } if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode); EXEC SQL CLOSE m_cursor; -#ifsql INGRES EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql } @@ -195,7 +184,7 @@ do_passwd() users = create_hash(12001); EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT login, uid, shell, fullname, nickname, office_addr, + SELECT login, unix_uid, shell, fullname, nickname, office_addr, office_phone, home_phone, users_id, pop_id, potype, status FROM users WHERE status = 1 or status = 5 or status = 6 @@ -217,24 +206,20 @@ do_passwd() u->lists = NULL; hash_store(users, id, u); if (status == 1) { - fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n", - login, HTYPE, login, uid, fullname, nn, oa, op, hp, - login, shell); - fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login); + fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n", + login, HCLASS, HTYPE, login, uid, fullname, nn, oa, + op, hp, login, shell); + fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, + login); } if (pid != 0 && (mach = hash_lookup(machines, pid))) { - fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n", - login, HTYPE, mach, login); + fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n", + login, HCLASS, HTYPE, mach, login); } } if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode); EXEC SQL CLOSE u_cursor; -#ifsql INGRES EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(pout) || fclose(uout) || fclose(bout)) { fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n"); @@ -308,10 +293,6 @@ do_groups() */ EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - /* get lock records */ - EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0; - EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0; - EXEC SQL DECLARE l_cursor CURSOR FOR SELECT name, gid, list_id FROM list @@ -324,9 +305,9 @@ do_groups() strtrim(name); sprintf(buf, "%s:%d", name, gid); hash_store(groups, lid, strsave(buf)); - fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name); - fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n", - name, HTYPE, name, gid); + fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name); + fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n", + name, HCLASS, HTYPE, name, gid); } EXEC SQL CLOSE l_cursor; @@ -371,19 +352,15 @@ do_groups() } } EXEC SQL CLOSE i_cursor; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql for (p = &(users->data[users->size - 1]); p >= users->data; p--) { for (b = *p; b; b = b->next) { if ((g = ((struct user *)b->data)->lists) == NULL) continue; - fprintf(lout, "%s.grplist\tHS %s \"", - ((struct user *)b->data)->name, HTYPE); + fprintf(lout, "%s.grplist\t%s %s \"", + ((struct user *)b->data)->name, HCLASS, HTYPE); len = 0; for (; g; g = g->next) { if (len + strlen(g->lid) + 1 < MAXHESSIZE) { @@ -428,7 +405,6 @@ do_filsys() char comments[65]; int flag1, flag2, flag3, flag4, id, fid; EXEC SQL END DECLARE SECTION; - char *index(); sprintf(outf, "%s/filsys.db", hesiod_dir); @@ -459,7 +435,7 @@ do_filsys() sq2 = sq_create(); EXEC SQL DECLARE f_cursor CURSOR FOR - SELECT label, type, name, mach_id, access, mount, comments, filsys_id + SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id FROM filesys ORDER BY filsys_id; EXEC SQL OPEN f_cursor; @@ -470,17 +446,17 @@ do_filsys() strtrim(type); if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) { if (mach = hash_lookup(machines, id)) { - fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n", - strtrim(name), HTYPE, type, strtrim(loc), mach, - strtrim(access), strtrim(mount)); + fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n", + strtrim(name), HCLASS, HTYPE, type, strtrim(loc), + mach, strtrim(access), strtrim(mount)); } } else if (!strcmp(type, "AFS")) { - fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n", - strtrim(name), HTYPE, strtrim(loc), strtrim(access), - strtrim(mount)); + fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n", + strtrim(name), HCLASS, HTYPE, strtrim(loc), + strtrim(access), strtrim(mount)); } else if (!strcmp(type, "ERR")) { - fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n", - strtrim(name), HTYPE, strtrim(comments)); + fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n", + strtrim(name), HCLASS, HTYPE, strtrim(comments)); } else if (!strcmp(type, "FSGROUP")) { sprintf(trans, "%s:%d", strtrim(name), fid); sq_save_data(sq, strsave(trans)); @@ -492,34 +468,34 @@ do_filsys() EXEC SQL CLOSE f_cursor; while (sq_get_data(sq, &group)) { - fid = atoi(index(group, ':')+1); - *index(group, ':') = 0; + fid = atoi(strchr(group, ':')+1); + *strchr(group, ':') = 0; EXEC SQL DECLARE f_cursor2 CURSOR FOR - SELECT DISTINCT f.type, f.name, f.mach_id, f.access, f.mount, + SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount, f.comments, f.label, g.key FROM filesys f, fsgroup g WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid ORDER BY key, label; EXEC SQL OPEN f_cursor2; - for (flag1=1;;flag1++) { + for (flag1=1;;flag1++) { EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount, :comments, :name, :trans; if (sqlca.sqlcode != 0) break; strtrim(type); if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) { if (mach = hash_lookup(machines, id)) { - fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s %d\"\n", - group, HTYPE, type, strtrim(loc), mach, + fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n", + group, HCLASS, HTYPE, type, strtrim(loc), mach, strtrim(access), strtrim(mount), flag1); } } else if (!strcmp(type, "AFS")) { - fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s %d\"\n", - group, HTYPE, strtrim(loc), strtrim(access), + fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n", + group, HCLASS, HTYPE, strtrim(loc), strtrim(access), strtrim(mount), flag1); } else if (!strcmp(type, "ERR")) { - fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n", - group, HTYPE, strtrim(comments)); + fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n", + group, HCLASS, HTYPE, strtrim(comments)); } } EXEC SQL CLOSE f_cursor2; @@ -528,9 +504,9 @@ do_filsys() sq_destroy(sq); while (sq_get_data(sq2, &group)) { - fid = atoi(index(group, ':') + 1); - *index(group, ':') = 0; - fprintf(out, "%s.filsys\tHS %s \"MUL", group, HTYPE); + fid = atoi(strchr(group, ':') + 1); + *strchr(group, ':') = 0; + fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE); EXEC SQL DECLARE f_cursor3 CURSOR FOR SELECT DISTINCT f.label, g.key FROM filesys f, fsgroup g @@ -556,16 +532,12 @@ do_filsys() while (1) { EXEC SQL FETCH a_cursor INTO :name, :trans; if (sqlca.sqlcode != 0) break; - fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", - strtrim(name), strtrim(trans)); + fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n", + strtrim(name), HCLASS, strtrim(trans)); } EXEC SQL CLOSE a_cursor; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of filsys.db\n"); @@ -594,8 +566,8 @@ typedef long set_mask; #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS))) #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS))) #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask))) -#define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask)) -#define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask))) +#define SET_ZERO(p) memset((char *)(p), 0, setsize * sizeof(set_mask)) +#define SET_CMP(p1, p2) (memcmp((p1), (p2), setsize * sizeof(set_mask))) int nbitsset(set) set_mask *set; @@ -626,7 +598,7 @@ do_cluster() if (stat(outf, &sb) == 0) { ftime = sb.st_mtime; - if (ModDiff (&flag1, "cluster", ftime) + if (ModDiff (&flag1, "clusters", ftime) || ModDiff (&flag2, "machine", ftime) || ModDiff (&flag3, "mcmap", ftime) || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE); @@ -646,14 +618,14 @@ do_cluster() fprintf(stderr, "Building cluster.db\n"); get_mach(); - EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM cluster; + EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters; maxclu++; setsize = howmany(maxclu, NSETBITS); EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine; maxmach++; machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **)); - bzero(machs, (maxmach + 1) * sizeof(int)); + memset(machs, 0, (maxmach + 1) * sizeof(int)); EXEC SQL DECLARE p_cursor CURSOR FOR SELECT mach_id, clu_id @@ -690,8 +662,8 @@ do_cluster() strtrim(label2); strtrim(data); fprintf(out, - "mrinternal-%d.cluster\tHS %s \"%s %s\"\n", - mid, HTYPE, label2, data); + "mrinternal-%d.cluster\t%s %s \"%s %s\"\n", + mid, HCLASS, HTYPE, label2, data); } EXEC SQL CLOSE d_cursor; } @@ -701,7 +673,7 @@ do_cluster() for (cid = 1; cid < maxclu; cid++) if (SET_ISSET(cid, ms)) break; - EXEC SQL SELECT name INTO :name FROM cluster WHERE clu_id = :cid; + EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid; strtrim(name); } @@ -710,11 +682,11 @@ do_cluster() *p++ = *mach; *p = 0; if (oneclu) - fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n", - machbuf, name); + fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", + machbuf, HCLASS, name); else - fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n", - machbuf, mid); + fprintf(out, "%s.cluster\t%s CNAME mrinternal-%d.cluster\n", + machbuf, HCLASS, mid); } for (id = mid + 1; id < maxmach; id++) { if ((ps = machs[id]) && !SET_CMP(ms, ps)) { @@ -725,12 +697,12 @@ do_cluster() *p++ = *mach; *p = 0; if (oneclu) - fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n", - machbuf, name); + fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", + machbuf, HCLASS, name); else fprintf(out, - "%s.cluster\tHS CNAME mrinternal-%d.cluster\n", - machbuf, mid); + "%s.cluster\t%s CNAME mrinternal-%d.cluster\n", + machbuf, HCLASS, mid); } } } @@ -740,7 +712,7 @@ do_cluster() EXEC SQL DECLARE d_cursor2 CURSOR FOR SELECT c.name, d.serv_label, d.serv_cluster - FROM svc d, cluster c + FROM svc d, clusters c WHERE c.clu_id = d.clu_id; EXEC SQL OPEN d_cursor2; while (1) { @@ -749,16 +721,11 @@ do_cluster() strtrim(name); strtrim(label2); strtrim(data); - fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n", - name, HTYPE, label2, data); + fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n", + name, HCLASS, HTYPE, label2, data); } free(machs); -#ifsql INGRES EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of cluster.db\n"); @@ -813,23 +780,21 @@ do_printcap() while (1) { EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq; if (sqlca.sqlcode != 0) break; + if (!hash_lookup(machines, rm)) continue; strtrim(name); strtrim(rp); strtrim(sd); - fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d", - name, HTYPE, name, rp, hash_lookup(machines, rm), sd, ka, pc); + fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d", + name, HCLASS, HTYPE, name, rp, hash_lookup(machines, rm), + sd, ka, pc); if (rq && hash_lookup(machines, rq)) fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq)); else fputs("\"\n", out); } EXEC SQL CLOSE p_cursor2; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of pcap.db\n"); @@ -851,7 +816,7 @@ do_palladium() time_t ftime; EXEC SQL BEGIN DECLARE SECTION; char name[33], trans[129]; - int flag, flag1, ident, rm; + int flag, flag1, identifier, rm; EXEC SQL END DECLARE SECTION; sprintf(outf, "%s/palladium.db", hesiod_dir); @@ -877,16 +842,18 @@ do_palladium() get_mach(); EXEC SQL DECLARE p_cursor3 CURSOR FOR - SELECT name, ident, mach_id + SELECT name, identifier, mach_id FROM palladium; EXEC SQL OPEN p_cursor3; while (1) { - EXEC SQL FETCH p_cursor3 INTO :name, :ident, :rm; + EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm; if (sqlca.sqlcode != 0) break; + if (!hash_lookup(machines, rm)) break; strtrim(name); fprintf(out, - "%s.palladium\tHS %s \"%s %d %s interface directory\"\n", - name, HTYPE, hash_lookup(machines, rm), ident, name); + "%s.palladium\t%s %s \"%s %d %s interface directory\"\n", + name, HCLASS, HTYPE, hash_lookup(machines, rm), identifier, + name); } EXEC SQL CLOSE p_cursor3; @@ -900,15 +867,12 @@ do_palladium() if (sqlca.sqlcode != 0) break; strtrim(name); strtrim(trans); - fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans); + fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE, + trans); } EXEC SQL CLOSE a_cursor2; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of palladium.db\n"); @@ -965,15 +929,11 @@ do_sloc() if (sqlca.sqlcode != 0) break; strtrim(service); if (mach = hash_lookup(machines, id)) - fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach); + fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach); } EXEC SQL CLOSE s_cursor; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of sloc.db\n"); @@ -1028,8 +988,8 @@ do_service() lowercase(protocol); /* Convert protocol to lowercase */ strtrim(service); strtrim(protocol); - fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n", - service, HTYPE, service, protocol, port); + fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n", + service, HCLASS, HTYPE, service, protocol, port); } EXEC SQL CLOSE s_cursor2; @@ -1043,15 +1003,12 @@ do_service() if (sqlca.sqlcode != 0) break; strtrim(service); strtrim(altserv); - fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv); + fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS, + altserv); } EXEC SQL CLOSE a_cursor3; -#ifsql INGRES + EXEC SQL COMMIT; -#endsql -#ifsql INFORMIX - EXEC SQL COMMIT WORK; -#endsql if (fclose(out)) { fprintf(stderr, "Unsuccessful close of service.db\n"); diff --git a/gen/hosts.dc b/gen/hosts.dc index 8119f6e3..742c7f6a 100644 --- a/gen/hosts.dc +++ b/gen/hosts.dc @@ -17,7 +17,7 @@ EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "hosts.gen"; - +char *db = "moira/moira"; main(argc, argv) int argc; @@ -34,13 +34,7 @@ char **argv; char name[65], vendor[33], model[33], os[33], addr[17]; EXEC SQL END DECLARE SECTION; -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -135,12 +129,8 @@ char **argv; } EXEC SQL CLOSE x; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + + EXEC SQL COMMIT; fprintf(out, "; End of automatically generated host table\n"); if (fclose(out)) { @@ -152,12 +142,6 @@ char **argv; exit(MR_SUCCESS); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Hosts build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/informix.awk b/gen/informix.awk deleted file mode 100644 index ee2c6124..00000000 --- a/gen/informix.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN {state = 0} -$1=="#ifsql"&&$2=="INFORMIX" {state = 0; printf("\n"); next} -$1=="#ifsql" {state = 1; printf("\n"); next} -$1=="#elsesql" {state = 1-state; printf("\n"); next} -$1=="#endsql" {state = 0; printf("\n"); next} -state==1 {printf("\n"); next} -state==0 diff --git a/gen/ingres.awk b/gen/ingres.awk deleted file mode 100644 index 9426e283..00000000 --- a/gen/ingres.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN {state = 0} -$1=="#ifsql"&&$2=="INGRES" {state = 0; printf("\n"); next} -$1=="#ifsql" {state = 1; printf("\n"); next} -$1=="#elsesql" {state = 1-state; printf("\n"); next} -$1=="#endsql" {state = 0; printf("\n"); next} -state==1 {printf("\n"); next} -state==0 diff --git a/gen/letter.dc b/gen/letter.dc deleted file mode 100644 index 1ab107fd..00000000 --- a/gen/letter.dc +++ /dev/null @@ -1,245 +0,0 @@ -/* $Header$ - * - * This generates confirmation letters to people who recently set - * their secure instance passwords. - * - * (c) Copyright 1992 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -#define LETTER "letter.template" - -extern int errno; -char *whoami = "letter.gen"; - - -main(argc, argv) -int argc; -char **argv; -{ - FILE *out = stdout; - char *outf = NULL, outft[64]; - struct stat sb; - int flag; - struct timeval tv; - EXEC SQL BEGIN DECLARE SECTION; - char login[10], first[17], last[17], fullname[34], addr[84]; - int lastrun, when; - EXEC SQL END DECLARE SECTION; - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag, "users", sb.st_mtime)) - exit(MR_DATE); - if (flag < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - outf = argv[1]; - sprintf(outft, "%s~", outf); - if ((out = fopen(outft, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } else { - outf = NULL; - } - - init_letter(); - - /* The following is declarative, not executed, - * and so is dependent on where it is in the file, - * not in the order of execution of statements. - */ - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - EXEC SQL SELECT secure INTO :lastrun FROM users WHERE users_id = 0; - - gettimeofday(&tv, NULL); - - EXEC SQL DECLARE x CURSOR FOR SELECT - login, first, last, xaddress, secure - FROM users WHERE secure > :lastrun; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :login, :first, :last, :addr, :when; - if (sqlca.sqlcode != 0) break; - strtrim(login); - strtrim(first); - strtrim(last); - sprintf(fullname, "%s %s", first, last); - print_letter(out, login, fullname, strtrim(addr), when); - } - - EXEC SQL CLOSE x; - - lastrun = tv.tv_sec; - EXEC SQL UPDATE users SET secure = :lastrun WHERE users_id = 0; - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - if (outf) - fix_file(outf); - - exit(MR_SUCCESS); - - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Letter build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -char *letter_text; - - -/* Read the template into a buffer */ - -init_letter() -{ - int fd; - char filename[256]; - struct stat stbuf; - - sprintf(filename, "%s/%s", DCM_DIR, LETTER); - if ((fd = open(filename, O_RDONLY, 0)) < 0) { - com_err(whoami, MR_OCONFIG, " opening letter template %s", filename); - exit(MR_OCONFIG); - } - if (fstat(fd, &stbuf)) { - com_err(whoami, MR_OCONFIG, " stating letter template %s", filename); - exit(MR_OCONFIG); - } - if ((letter_text = (char *)malloc(stbuf.st_size + 1)) == NULL) { - com_err(whoami, MR_NO_MEM, " reading letter template"); - exit(MR_NO_MEM); - } - if (read(fd, letter_text, stbuf.st_size) < stbuf.st_size) { - com_err(whoami, MR_OCONFIG, " unable to read all of letter"); - exit(MR_OCONFIG); - } - letter_text[stbuf.st_size] = 0; - close(fd); -} - - -/* Print out a copy of the letter */ - -print_letter(out, login, fullname, addr, when) -FILE *out; -char *login, *fullname, *addr; -int when; -{ - register char *p; - char buf[256], *a1, *a2, *d; - char *rindex(), *index(); - - /* split address into two lines. - * First determine if postal or interdepartmental address. - * Postal addreses end in state & zip code, as in "MA02139" - * Anything else, assume interdepartmental. - */ - strcpy(buf, addr); - a1 = buf; - if (a2 = index(buf, '|')) { - *a2++ = 0; - } else { - a2 = rindex(buf, ' '); /* before state & zip */ - if (a2 && isupper(a2[1]) && isupper(a2[2]) && - isdigit(a2[3]) && isdigit(a2[4]) && isdigit(a2[5]) && - isdigit(a2[6]) && isdigit(a2[7])) { - /* Must be postal address. */ - /* missing space between state & zip, fix */ - for (p = a2; *p; p++); /* find end of string */ - for (p--; isdigit(*p); p--) - p[2] = p[1]; - p[2] = p[1]; - p[1] = ' '; - /* Backup to previous space, start of state */ - for (; *a2 != ' '; a2--); - /* Backup to previous space, start of city */ - for (a2--; *a2 != ' '; a2--); - /* terminate first line, leave a2 pointing at second */ - *a2++ = 0; - } else { - /* Must be interdepartmental */ - a2 = "MIT INTERDEPARTMENTAL MAIL"; - } - } - - d = ctime(&when); - d[strlen(d)-1] = 0; - - for (p = letter_text; *p; p++) { - if (*p == '%') { - p++; - switch (*p) { - case 'l': - fputs(login, out); - break; - case 'n': - fputs(fullname, out); - break; - case 'A': - fputs(addr, out); - break; - case 'a': - p++; - switch (*p) { - case '1': - fputs(a1, out); - break; - case '2': - fputs(a2, out); - break; - default: - fputs(addr, out); - } - break; - case 'd': - fputs(d, out); - break; - default: - putc('%', out); - putc(*p, out); - } - } else - putc(*p, out); - } - fflush(out); -} diff --git a/gen/letter.sh b/gen/letter.sh deleted file mode 100644 index ca669ca7..00000000 --- a/gen/letter.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/moira/bin/perl -# $Header$ -# This script prints the letters confirming registration for the extra -# kerberos principal. - -# The algorithm consists of first checking to see that the previous -# day's job printed. If so, the cached copy is deleted. Otherwise, -# today's is appended to yesterday's and we continue working with that. - -$printer = "nil"; -$newfile = "/tmp/letter.out"; -$savefile = "/u1/letter.save"; -$holdfile = "/u1/letter.hold"; -$logfile = "/u1/letter.log"; - -open(LOG, ">>" . $logfile); - -print LOG "\nRunning " . `date`; - -$printed =`/usr/athena/bin/lpquota -l | tail -2`; -@printed = split(/\s+/, $printed); - -print LOG "\nlast printed " . $printed; - -$filed = `ls -l $savefile`; -@filed = split(/\s+/, $filed); - -print LOG "\nfile touched " . $filed; - -if ($printed[1] eq $filed[4] && $printed[2] eq $filed[5]) { - system("mv $newfile $savefile"); - print LOG "\nall OK"; -} else { - if ( -s $savefile) { - if ( ! -f $holdfile) { - open(MAIL, "|/bin/mail dbadmin thorne"); - print MAIL "To: dbadmin, thorne\n"; - print MAIL "Subject: reg_extra printing error\n"; - print MAIL "Reg_extra letters failed to print yesterday\n"; - print MAIL $filed; - print MAIL $printed; - close(MAIL); - print LOG "\nmail sent"; - } - system("cat $newfile >> $savefile"); - } else { - system("mv $newfile $savefile"); - } -} - -unlink($holdfile); - -print LOG "\nprinting..."; - -open(OUT, "/usr/ucb/lpr -P$printer -h $savefile|"); -$msg = ; -close(OUT); - -print LOG "done\n"; - -if ($msg eq "Printer queue is disabled.\n") { - open(FOO, $holdfile); - close(FOO); - print LOG "got expected queue down error\n"; -} - -exit 0; diff --git a/gen/letter.template b/gen/letter.template deleted file mode 100644 index d17a1497..00000000 --- a/gen/letter.template +++ /dev/null @@ -1,39 +0,0 @@ -%! -%%Page: 1 1 -% Turn on double-sided printing for HP4mx printers -%%BeginFeature *Duplex True -<< /Duplex true >> setpagedevice -%%EndFeature - -/Times-Roman findfont 10 scalefont setfont -92 708 moveto(Athena User Accounts)show -92 696 moveto(MIT Room 11-124G)show -92 684 moveto(77 Massachusetts Ave)show -92 672 moveto(Cambridge, MA 02139)show -/Times-Roman findfont 12 scalefont setfont -155 610 moveto(%n)show -155 596 moveto(%a1)show -155 582 moveto(%a2)show - -showpage - -%%Page: 2 2 - -/Times-Roman findfont 12 scalefont setfont -92 678 moveto(From: Information Systems)show -124 666 moveto(Athena User Accounts)show -92 637 moveto(To: %n)show -375 637 moveto(%d)show -120 580 moveto(This letter is to con\256rm that `%l' registered for a second Athena password)show -92 568 moveto(using the reg_extra program.)show -120 538 moveto(If you did not do this, then there is reason to believe your account has been)show -92 526 moveto(compromised, so contact Athena User Accounts immediately by calling x3-1325,)show -92 514 moveto(sending mail to , or stopping by 11-124H between the hours of)show -92 502 moveto(2 to 5.)show -120 468 moveto(The password will not take effect for two weeks from the date above. Remember,)show -92 456 moveto(the second Athena password \(``extra'' instance\) will allow access to your grades and,)show -92 444 moveto(potentially, other sensitive information. It is important that you keep all passwords)show -92 432 moveto(private, since they will be used to give you access to more and more critical functions.)show -120 398 moveto(If you have any question please contact Athena User Accounts.)show - -showpage diff --git a/gen/mailhub.dc b/gen/mailhub.dc index 86987d24..83651a87 100644 --- a/gen/mailhub.dc +++ b/gen/mailhub.dc @@ -22,6 +22,7 @@ EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "mailhub.gen"; +char *db = "moira/moira"; char *perm_malloc(); char *pstrsave(); char *divide = "##############################################################"; @@ -46,13 +47,7 @@ char **argv; int flag; EXEC SQL END DECLARE SECTION; -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -80,12 +75,7 @@ char **argv; get_info(); -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + EXEC SQL COMMIT; fprintf(stderr, "Sorting Info\n"); sort_info(); @@ -131,8 +121,8 @@ struct list { struct names { char *name; struct names *next; - int keep:1; - int id:31; + int keep; + int id; }; @@ -153,11 +143,6 @@ get_info() */ EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - /* Get Locks */ - - EXEC SQL SELECT modtime INTO :buf FROM users WHERE users_id = 0; - EXEC SQL SELECT modtime INTO :buf FROM list WHERE list_id = 0; - cnt = 0; machines = create_hash(1000); @@ -170,7 +155,7 @@ get_info() while (1) { EXEC SQL FETCH m_cursor INTO :id, :name; if (sqlca.sqlcode != 0) break; - if (s = index(name, '.')) + if (s = strchr(name, '.')) *s = 0; else strtrim(name); @@ -191,14 +176,14 @@ get_info() strings = create_hash(11001); EXEC SQL DECLARE s_cursor CURSOR FOR - SELECT string_id, trim(string) + SELECT string_id, string FROM strings ORDER BY string_id; EXEC SQL OPEN s_cursor; while (1) { EXEC SQL FETCH s_cursor INTO :id, :name; if (sqlca.sqlcode != 0) break; - if (hash_store(strings, id, pstrsave(name)) < 0) { + if (hash_store(strings, id, pstrsave(strtrim(name))) < 0) { fprintf(stderr, "Out of memory!\n"); exit(MR_NO_MEM); } @@ -244,7 +229,6 @@ get_info() cnt++; } EXEC SQL CLOSE u_cursor; - EXEC SQL COMMIT; fprintf(stderr, "Loaded %d users\n", cnt); cnt = 0; @@ -273,7 +257,6 @@ get_info() cnt++; } EXEC SQL CLOSE l_cursor; - EXEC SQL COMMIT; fprintf(stderr, "Loaded %d lists\n", cnt); cnt = 0; @@ -313,12 +296,12 @@ get_info() } EXEC SQL CLOSE m_cursor2; fprintf(stderr, "Loaded %d members\n", cnt); + + EXEC SQL COMMIT; return; sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Mailhub build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } @@ -576,9 +559,9 @@ register char *s; wwid = strlen(s); if (!bol && awid + wwid + 2 > AL_MAX_WID) { - sprintf(str, "%c%c%c%c%c%c", random() % 26 + 97, random() % 26 + 97, - random() % 26 + 97, random() % 26 + 97, - random() % 26 + 97, random() % 26 + 97); + sprintf(str, "%c%c%c%c%c%c", rand() % 26 + 97, rand() % 26 + 97, + rand() % 26 + 97, rand() % 26 + 97, + rand() % 26 + 97, rand() % 26 + 97); str[6] = '\0'; fprintf(out, ",\n\tcont%d-%s\ncont%d-%s: ", cont, str, cont, str); cont++; @@ -619,7 +602,7 @@ register char *string; while (1) { while (*string && *string == ' ') string++; - c = (char *)index(string, ' '); + c = (char *)strchr(string, ' '); if (c == 0) { wwid = strlen(string); } else { @@ -700,7 +683,7 @@ pstrsave(s) } len = strlen(s) + 1; p = perm_malloc((u_int)len); - if (p) bcopy(s, p, len); + if (p) memcpy(p, s, len); return p; } @@ -722,7 +705,7 @@ int size; free(h); return((struct hash *) NULL); } - bzero(h->data, size * sizeof(char *)); + memset(h->data, 0, size * sizeof(char *)); return(h); } diff --git a/gen/mitdir.dc b/gen/mitdir.dc deleted file mode 100644 index f393d182..00000000 --- a/gen/mitdir.dc +++ /dev/null @@ -1,200 +0,0 @@ -/* $Header$ - * - * This generates the input file for the mkdirdb program for the MIT.EDU - * mailhub. - * - * (c) Copyright 1989, 1990 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - - -extern int errno; -char *whoami = "mitdir.gen"; - - -main(argc, argv) -int argc; -char **argv; -{ - long tm = time(NULL); - FILE *out= stdout; - char filename[64], *targetfile; - struct stat sb; - EXEC SQL BEGIN DECLARE SECTION; - int flag1; - EXEC SQL END DECLARE SECTION; - int ingerr(); - - initialize_sms_error_table(); - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag1, "users", sb.st_mtime)) - exit(MR_DATE); - if (flag1 < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - targetfile = argv[1]; - sprintf(filename, "%s~", targetfile); - if ((out = fopen(filename, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", filename); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } - - get_info(out); - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - - if (argc == 2) - fix_file(targetfile); - exit(MR_SUCCESS); -} - - -get_info(out) -FILE *out; -{ - int mitroom, mitphone; - char stuemp, *mhost, *uname, *pob, *tmp; - struct hash *strings; - EXEC SQL BEGIN DECLARE SECTION; - int id, pid, bid, mid; - char name[129], type[9], buf[257], fname[17], mname[17], lname[17]; - char year[9], dept[13], oaddr[17], ophone[13], haddr[81], hphone[17]; - char affil[5]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - /* get locks */ - EXEC SQL SELECT modtime INTO :buf FROM users WHERE users_id = 0; - - strings = create_hash(2000); - EXEC SQL DECLARE s_lock CURSOR FOR - SELECT string_id, string - FROM strings; - EXEC SQL OPEN s_lock; - while (1) { - EXEC SQL FETCH s_lock INTO :id, :name; - if (sqlca.sqlcode != 0) break; - hash_store(strings, id, strsave(strtrim(name))); - } - EXEC SQL CLOSE s_lock; - - EXEC SQL DECLARE u_cursor1 CURSOR FOR - SELECT users_id, login, first, middle, last, - mit_year, mit_dept, office_addr, office_phone, - home_addr, home_phone, potype, box_id - FROM users - WHERE status != 3; - EXEC SQL OPEN u_cursor1; - while (1) { - EXEC SQL FETCH u_cursor1 INTO :id, :name, :fname, :mname, :lname, - :year, :dept, :oaddr, :ophone, :haddr, :hphone, :type, :bid; - if (sqlca.sqlcode != 0) break; - - if (id == 0) - continue; - - strtrim(year); - if (atoi(year) || !strcmp(year, "G")) - stuemp = 'S'; - else if (!strcmp(year, "FACULTY") || !strcmp(year, "MITS") || - !strcmp(year, "STAFF")) - stuemp = 'E'; - else if (!strcmp(year, "PROJECT") || !strcmp(year, "SYSTEM")) - continue; - else - stuemp = '?'; - - if (type[0] == 'S' & (pob = hash_lookup(strings, bid)) != NULL) { - uname = pob; - mhost = index(pob, '@'); - if (mhost) - *mhost++ = 0; - else - mhost = &uname[strlen(uname) + 1]; - } else if (type[0] == 'N') { - mhost = ""; - uname = ""; - } else { - mhost = "ATHENA.MIT.EDU"; - uname = strtrim(name); - } - - strtrim(oaddr); - if (oaddr[0] != ' ') { - tmp = &oaddr[strlen(oaddr) - 1]; - if (*tmp == 'm' || *tmp == 'M') { - *tmp = 0; - } - } - - if (tmp = index(ophone, '-')) { - bcopy(tmp+1, tmp, strlen(tmp)-1); - } - if (tmp = index(hphone, '-')) { - bcopy(tmp+1, tmp, strlen(tmp)-1); - } - - fprintf(out, "%c:%s, %s %s:", - stuemp, strtrim(lname), strtrim(fname), strtrim(mname)); - fprintf(out, "%s:%s:%s:%s::", lname, fname, mname, oaddr); - if (ophone[0] != ' ') - fprintf(out, "%010d:::%s:%s:%s:", - atoi(ophone), strtrim(dept), uname, mhost); - else - fprintf(out, ":::%s:%s:%s:", - strtrim(dept), uname, mhost); - if (hphone[0] != ' ') - fprintf(out, "%s:::::%010d::::%s::0\n", - strtrim(haddr), atoi(hphone), year); - else - fprintf(out, "%s:::::::::%s::0\n", - strtrim(haddr), year); - } - EXEC SQL CLOSE u_cursor1; - return; - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Mitdir build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} diff --git a/gen/moddiff.dc b/gen/moddiff.dc index 8ab2f463..f96122a4 100644 --- a/gen/moddiff.dc +++ b/gen/moddiff.dc @@ -38,12 +38,9 @@ time_t ModTime; *flag = 0; tbl_name = tbl; - EXEC SQL SELECT modtime INTO :filetime FROM tblstats + EXEC SQL SELECT TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS') INTO :filetime FROM tblstats WHERE table_name = :tbl_name; if (sqlca.sqlcode != 0) { - if (sqlca.sqlcode == -37000 || - sqlca.sqlcode == 17700) - exit(MR_DEADLOCK); fprintf(stderr, "Moddiff Query failed: %d\n", sqlca.sqlcode); return(MR_DATE); } diff --git a/gen/networks.dc b/gen/networks.dc index 697fc481..655e1797 100644 --- a/gen/networks.dc +++ b/gen/networks.dc @@ -13,12 +13,13 @@ #include #include #include +#include EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "network.gen"; - +char *db = "moira/moira"; main(argc, argv) int argc; @@ -28,19 +29,14 @@ char **argv; char *outf = NULL, outft[64], *p, buf[256]; struct stat sb; struct timeval now; + struct in_addr addr; int flag1, i; EXEC SQL BEGIN DECLARE SECTION; - int id, addr; + int id, saddr; char name[65], description[65]; EXEC SQL END DECLARE SECTION; -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -81,21 +77,19 @@ char **argv; FROM subnet ORDER BY saddr; EXEC SQL OPEN x; while (1) { - EXEC SQL FETCH x INTO :name, :id, :addr, :description; + EXEC SQL FETCH x INTO :name, :id, :saddr, :description; if (sqlca.sqlcode != 0) break; if (id == 0) continue; if (*strtrim(name) == 0) continue; - fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name, inet_ntoa(htonl(addr)), - description); + addr.s_addr=htonl(saddr); + fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name, + inet_ntoa(addr), + strtrim(description)); } EXEC SQL CLOSE x; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + + EXEC SQL COMMIT; fprintf(out, "; End of automatically generated network table\n"); if (fclose(out)) { @@ -107,12 +101,6 @@ char **argv; exit(MR_SUCCESS); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Networks build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/nfs.dc b/gen/nfs.dc index 36683030..f013e1a3 100644 --- a/gen/nfs.dc +++ b/gen/nfs.dc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,7 @@ EXEC SQL INCLUDE sqlca; #define min(x,y) ((x) < (y) ? (x) : (y)) char *whoami = "nfs.gen"; +char *db = "moira/moira"; char *malloc(), *strsave(); char nfs_dir[64]; struct hash *users, *groups; @@ -41,22 +43,11 @@ char **argv; initialize_sms_error_table(); sprintf(nfs_dir, "%s/nfs", DCM_DIR); -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; changed = do_nfs(); -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + EXEC SQL COMMIT; if (!changed) { fprintf(stderr, "No files updated.\n"); @@ -93,6 +84,7 @@ int do_nfs() * not in the order of execution of statements. */ EXEC SQL WHENEVER SQLERROR GOTO sqlerr; + EXEC SQL DECLARE s_cursor CURSOR FOR SELECT m.name, s.value3 FROM machine m, serverhosts s @@ -111,15 +103,14 @@ int do_nfs() changed += do_machs(machs); return(changed); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "NFS build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } /* Make all of the credentials lists that will be needed. Returns 0 if - * no files were actually changed */ + * no files were actually changed + */ int do_lists(lists) struct save_queue *lists; @@ -146,9 +137,6 @@ struct save_queue *lists; } */ - /* get locks */ - EXEC SQL SELECT modtime INTO :lname FROM list WHERE list_id = 0; - EXEC SQL SELECT modtime INTO :lname FROM users WHERE users_id = 0; /* build the list of everyone, and store it in a file whose name * corresponds to the empty list. @@ -192,10 +180,8 @@ struct save_queue *lists; */ return(1); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "NFS build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } @@ -254,7 +240,7 @@ do_everyone() /* now do grplists */ users = create_hash(10000); EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT users_id, login, uid + SELECT users_id, login, unix_uid FROM users WHERE status = 1 ORDER BY users_id; @@ -304,10 +290,8 @@ do_everyone() free(groups); return(1); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "NFS build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } @@ -322,17 +306,13 @@ struct save_queue *machs; char *machname, listname[33], dev[33], dir[81], fstype[9]; int uid, quota, id, gid, flag1, flag2, flag3, flag4; EXEC SQL END DECLARE SECTION; - char file[64], f1[64], f2[64], *cp, *index(); + char file[64], f1[64], f2[64], *cp; int prevuid, quotasum, olddev, oldmach; FILE *fd; struct hash *machines; fprintf(stderr, "Building machine files\n"); - /* acquire locks on machines & filesystems */ - EXEC SQL SELECT modtime INTO :listname FROM users WHERE users_id = 0; - EXEC SQL SELECT modtime INTO :listname FROM machine WHERE mach_id = 0; - EXEC SQL SELECT modtime INTO :listname FROM filesys WHERE filsys_id = 0; machines = create_hash(100); while (sq_get_data(machs, &machname)) { @@ -375,7 +355,7 @@ struct save_queue *machs; fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = index(dev, '/')) *cp = '@'; + while (cp = strchr(dev, '/')) *cp = '@'; sprintf(file, "%s/%s.%s.quotas", nfs_dir, hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); @@ -388,7 +368,7 @@ struct save_queue *machs; } if (uid != prevuid) { if ((cp = hash_lookup(users, prevuid)) && - (cp = index(cp, ':'))) + (cp = strchr(cp, ':'))) prevuid = atoi(cp+1); if (quotasum) fprintf(fd, "%d %d\n", prevuid, quotasum); @@ -400,7 +380,7 @@ struct save_queue *machs; } EXEC SQL CLOSE q_cursor; if ((cp = hash_lookup(users, prevuid)) && - (cp = index(cp, ':'))) + (cp = strchr(cp, ':'))) prevuid = atoi(cp+1); if (quotasum) fprintf(fd, "%d %d\n", prevuid, quotasum); @@ -432,7 +412,7 @@ struct save_queue *machs; fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = index(dev, '/')) *cp = '@'; + while (cp = strchr(dev, '/')) *cp = '@'; sprintf(file, "%s/%s.%s.quotas", nfs_dir, hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); @@ -468,7 +448,7 @@ struct save_queue *machs; fd = stdin; EXEC SQL DECLARE q_cursor3 CURSOR FOR - SELECT DISTINCT f.name, f.lockertype, u.uid, l.gid, f.phys_id, + SELECT DISTINCT f.name, f.lockertype, u.unix_uid, l.gid, f.phys_id, f.mach_id, n.device FROM users u, list l, nfsphys n, filesys f WHERE u.users_id = f.owner AND @@ -482,12 +462,13 @@ struct save_queue *machs; EXEC SQL FETCH q_cursor3 INTO :dir, :fstype, :uid, :gid, :flag1, :flag2, :dev; if (sqlca.sqlcode != 0) break; - if (flag1 != olddev || flag2 != oldmach) { + if ((flag1 != olddev || flag2 != oldmach) && + hash_lookup(machines, flag2)) { if (fd != stdin) fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = index(dev, '/')) *cp = '@'; + while (cp = strchr(dev, '/')) *cp = '@'; sprintf(file, "%s/%s.%s.dirs", nfs_dir, hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); @@ -505,8 +486,6 @@ struct save_queue *machs; } return(1); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "NFS build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/passwd.dc b/gen/passwd.dc index 3c4bbad8..d80d7aab 100644 --- a/gen/passwd.dc +++ b/gen/passwd.dc @@ -18,7 +18,7 @@ EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "passwd.gen"; - +char *db = "moira/moira"; main(argc, argv) int argc; @@ -34,13 +34,7 @@ char **argv; int uid; EXEC SQL END DECLARE SECTION; -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -68,7 +62,7 @@ char **argv; EXEC SQL WHENEVER SQLERROR GOTO sqlerr; EXEC SQL DECLARE x CURSOR FOR SELECT - login, uid, shell, fullname, office_addr, nickname, + login, unix_uid, shell, fullname, office_addr, nickname, office_phone, home_phone FROM users WHERE status = 1; EXEC SQL OPEN x; @@ -88,12 +82,8 @@ char **argv; } EXEC SQL CLOSE x; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + + EXEC SQL COMMIT; if (fclose(out)) { perror("close failed"); @@ -104,8 +94,6 @@ char **argv; exit(MR_SUCCESS); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Passwd build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/pobox.dc b/gen/pobox.dc index bba1e2ec..9dc367bc 100644 --- a/gen/pobox.dc +++ b/gen/pobox.dc @@ -14,12 +14,11 @@ #include #include #include -#include EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "pobox.gen"; - +char *db = "moira/moira"; main(argc, argv) int argc; @@ -33,13 +32,7 @@ char **argv; char login[9], id[18], string[257]; EXEC SQL END DECLARE SECTION; -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -109,12 +102,7 @@ char **argv; EXEC SQL CLOSE y; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + EXEC SQL COMMIT; if (fclose(out)) { perror("close failed"); @@ -125,12 +113,6 @@ char **argv; exit(MR_SUCCESS); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Pobox build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/prlogger.dc b/gen/prlogger.dc deleted file mode 100644 index 9bed6406..00000000 --- a/gen/prlogger.dc +++ /dev/null @@ -1,109 +0,0 @@ -/* $Header$ - * - * This generates a list of active users for the prlogger - * - * (c) Copyright 1990 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -extern int errno; -char *whoami = "prlogger.gen"; - - -main(argc, argv) -int argc; -char **argv; -{ - FILE *out = stdout; - char *outf = NULL, outft[64]; - struct stat sb; - int flag, ret; - EXEC SQL BEGIN DECLARE SECTION; - char login[9], class[9]; - EXEC SQL END DECLARE SECTION; - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag, "users", sb.st_mtime)) { - if (sqlca.sqlcode == -37000 || - sqlca.sqlcode == -49900) - exit(MR_DEADLOCK); - else - exit(MR_DATE); - } - if (flag < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - outf = argv[1]; - sprintf(outft, "%s~", outf); - if ((out = fopen(outft, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } else { - outf = NULL; - } - - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - EXEC SQL DECLARE x CURSOR FOR - SELECT login, type FROM users WHERE status = 1; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :login, :class; - if (sqlca.sqlcode != 0) break; - strtrim(login); - strtrim(class); - fprintf(out, "%s %s\n", login, class); - } - EXEC SQL CLOSE x; - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); - - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "PrLogger build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} diff --git a/gen/prlogger.sh b/gen/prlogger.sh deleted file mode 100644 index ef11f987..00000000 --- a/gen/prlogger.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -PATH=/bin:/usr/ucb:/usr/bin - -MR_TARERR=47836476 -MR_MISSINGFILE=47836473 - -INFILE=/tmp/prlogger.out -OUTFILE=/usr/spool/quota/users/prlogger - -if [ ! -r $INFILE ]; then - exit $MR_MISSINGFILE - fi - -mv $INFILE $OUTFILE -if [ $? != 0 ]; then - exit $MR_TARERR - fi - -/usr/spool/quota/users/moira_update & - -rm -f $0 $INFILE -exit 0 - -# $Header$ diff --git a/gen/report.dc b/gen/report.dc deleted file mode 100644 index d9cded24..00000000 --- a/gen/report.dc +++ /dev/null @@ -1,286 +0,0 @@ -/* $Header$ - * - * This generates some useful reports. - * - * (c) Copyright 1993 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -extern int errno; -char *whoami = "report.gen"; -FILE *out = stdout; - -struct user { - char name[9]; - int uid; - int status; -}; -struct hash *users = NULL; -struct hash *kmaps = NULL; - -main(argc, argv) -int argc; -char **argv; -{ - char *outf = NULL, outft[64], *p, buf[256]; - struct stat sb; - struct timeval now; - int flag1, flag2, i; - struct hash *aliases = NULL; - struct hash *nets = NULL; - struct user *u; - - EXEC SQL BEGIN DECLARE SECTION; - int id, sid, status, uid, ustatus, owner, creator, modby; - char login[9]; - char name[65], vendor[33], model[33], os[33], addr[17]; - char location[17], owner_type[16]; - char schange[25], modtime[25], modwith[33], created[25]; - EXEC SQL END DECLARE SECTION; - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) - { - if (stat(argv[1], &sb) == 0) - { - if (ModDiff(&flag1, "machine", sb.st_mtime) || - ModDiff(&flag2, "subnet", sb.st_mtime)) - exit(MR_DATE); - if (flag1 < 0 && flag2 < 0) - { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - outf = argv[1]; - sprintf(outft, "%s~", outf); - if ((out = fopen(outft, "w")) == NULL) - { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } else if (argc != 1) - { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } else - { - outf = NULL; - } - - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - users = create_hash(12001); - - /* - * suck in user table - */ - - EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0; - - EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT login, uid, users_id, status - FROM users; - EXEC SQL OPEN u_cursor; - - while (1) - { - EXEC SQL FETCH u_cursor INTO :login, :uid, :id, :ustatus; - if (sqlca.sqlcode != 0) break; - strtrim(login); - u = (struct user *) malloc(sizeof(struct user)); - strcpy(u->name, login); - u->uid = uid; - u->status = ustatus; - hash_store(users, id, u); - } - - EXEC SQL CLOSE u_cursor; - - /* - * suck in host alias table - */ - - EXEC SQL SELECT modtime INTO :name FROM machine WHERE mach_id = 0; - - gettimeofday(&now, NULL); - - fprintf(out, "# Moira host table dump generated at %s\n", - ctime(&now.tv_sec)); - - EXEC SQL DECLARE y CURSOR FOR SELECT - mach_id, name FROM hostalias; - EXEC SQL OPEN y; - - aliases = create_hash(1001); - while (1) - { - EXEC SQL FETCH y INTO :id, :name; - - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - if (p = hash_lookup(aliases, id)) - { - sprintf(buf, "%s,%s", p, name); - hash_update(aliases, id, strsave(buf)); - free(p); - } else - hash_store(aliases, id, strsave(name)); - } - - EXEC SQL CLOSE y; - - - /* - * suck in network table - */ - - EXEC SQL SELECT modtime INTO :name FROM subnet WHERE snet_id = 0; - - EXEC SQL DECLARE n_cursor CURSOR FOR SELECT - snet_id, name FROM subnet; - EXEC SQL OPEN n_cursor; - - nets = create_hash(301); - while (1) - { - EXEC SQL FETCH n_cursor INTO :id, :name; - - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - hash_store(nets, id, strsave(name)); - } - - EXEC SQL CLOSE n_cursor; - - /* - * dump machine table - */ - - - EXEC SQL DECLARE x CURSOR FOR SELECT - name, mach_id, status, statuschange, vendor, model, os, address, location, snet_id, owner_type, owner_id, modby, modtime, modwith, created, creator - FROM machine; - EXEC SQL OPEN x; - - while (1) - { - EXEC SQL FETCH x INTO :name, :id, :status, :schange, :vendor, :model, :os, :addr, :location, :sid, :owner_type, :owner, :modby, :modtime, :modwith, :created, :creator; - - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - - if (p = hash_lookup(aliases, id)) - sprintf(buf, "%s,%s", name, p); - else - strcpy(buf, name); - - fprintf(out, "HOST|%s|", buf); - if(p = hash_lookup(nets, sid)) - fprintf(out, "%s|", strtrim(p)); - else - if(sid == 0) - fprintf(out, "NONE|"); - else - fprintf(out, "%d|", sid); - - fprintf(out, "%s|%s|", strtrim(addr), - status == 3 ? "deleted" : - status == 2 ? "none" : status == 1 ? "active" : status == 0 ? - "reserved" : "unknown"); - - fprintf(out, "%s|", strtrim(schange)); - fprintf(out, "%s|", strtrim(location)); - fprintf(out, "%s|", strtrim(vendor)); - fprintf(out, "%s|", strtrim(model)); - fprintf(out, "%s|", strtrim(os)); - - print_user(strtrim(owner_type), owner); - print_user("STRING", creator); - fprintf(out, "%s|", strtrim(created)); - print_user("STRING", modby < 0 ? -modby : modby); - - fprintf(out, "%s|", strtrim(modtime)); - fprintf(out, "%s|", strtrim(modwith)); - fprintf(out, "\n"); - } - - EXEC SQL CLOSE x; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - fprintf(out, "# End of Report\n"); - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); - - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Report build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -print_user(type, user) - char *type; - unsigned int user; -{ - struct user *u; - char *c; - EXEC SQL BEGIN DECLARE SECTION; - int id; - char name[128]; - EXEC SQL END DECLARE SECTION; - - if(strcmp(type, "USER") == 0) - { - if(u = (struct user *) hash_lookup(users, user)) - fprintf(out, "USER %s|", u->name); - else - fprintf(out, "USER %d|", user); - } - else - if(id == 0) - fprintf(out, "smsuser|"); - else - { - id = user; - EXEC SQL SELECT string INTO :name FROM strings WHERE string_id = :id; - if (sqlca.sqlcode == 0) - fprintf(out, "%s|", strtrim(name)); - else - fprintf(out, "UNKNOWN|"); - } - sqlerr: - return; -} diff --git a/gen/sis.dc b/gen/sis.dc index e2c4b98a..e7b0b6e6 100644 --- a/gen/sis.dc +++ b/gen/sis.dc @@ -21,11 +21,12 @@ #include #include #include +#include EXEC SQL INCLUDE sqlca; extern int errno; char *whoami = "sis.gen"; - +char *db = "moira/moira"; main(argc, argv) int argc; @@ -39,6 +40,7 @@ char **argv; struct timeval now; EXEC SQL BEGIN DECLARE SECTION; char login[9], sig[257], id[17], kname[257]; + EXEC SQL VAR sig IS STRING(257); int timestamp; struct { char login[12]; char id[12]; @@ -48,13 +50,7 @@ char **argv; initialize_sms_error_table (); -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql + EXEC SQL CONNECT :db; if (argc == 2) { if (stat(argv[1], &sb) == 0) { @@ -98,6 +94,7 @@ char **argv; strtrim(login); strtrim(id); strtrim(kname); + memset(&outrec, 0, sizeof(outrec)); strcpy(outrec.login, login); strcpy(outrec.id, id); si.timestamp = timestamp; @@ -109,12 +106,7 @@ char **argv; } EXEC SQL CLOSE x; -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql + EXEC SQL COMMIT; if (close(out)) { perror("close failed"); @@ -125,12 +117,6 @@ char **argv; exit(MR_SUCCESS); sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "SIS build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/stats.dc b/gen/stats.dc deleted file mode 100644 index 0933aba1..00000000 --- a/gen/stats.dc +++ /dev/null @@ -1,127 +0,0 @@ -/* $Header$ - * - * This generates a list of how many lockers are on each NFS server - * for statistics gathering purposes. - * - * (c) Copyright 1991 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -extern int errno; -char *whoami = "stats.gen"; - - -main(argc, argv) -int argc; -char **argv; -{ - FILE *out = stdout; - char *outf = NULL, outft[64]; - struct stat sb; - int flag1, flag2, flag3; - struct hash *machines; - EXEC SQL BEGIN DECLARE SECTION; - char name[257]; - int n, id; - EXEC SQL END DECLARE SECTION; - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag1, "machine", sb.st_mtime) == 0 && - ModDiff (&flag2, "filesys", sb.st_mtime) == 0 && - ModDiff (&flag3, "nfsphys", sb.st_mtime) == 0 && - flag1 < 0 && flag2 < 0 && flag3 < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); - } - } - outf = argv[1]; - sprintf(outft, "%s~", outf); - if ((out = fopen(outft, "w")) == NULL) { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } else if (argc != 1) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } else { - outf = NULL; - } - - /* The following is declarative, not executed, - * and so is dependent on where it is in the file, - * not in the order of execution of statements. - */ - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - machines = create_hash(1000); - - EXEC SQL DECLARE m CURSOR FOR - SELECT mach_id, name - FROM machine; - EXEC SQL OPEN m; - while (1) { - EXEC SQL FETCH m INTO :id, :name; - if (sqlca.sqlcode != 0) break; - hash_store(machines, id, strsave(name)); - } - EXEC SQL CLOSE m; - - EXEC SQL DECLARE x CURSOR FOR - SELECT DISTINCT f.mach_id, count(f.filsys_id) - FROM filesys f - WHERE f.type='NFS' - GROUP BY f.mach_id; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :id, :n; - if (sqlca.sqlcode != 0) break; - fprintf(out, "%-32s %d\n", hash_lookup(machines, id), n); - } - EXEC SQL CLOSE x; - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); - } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); - - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); -#ifsql INGRES - if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000) - exit(MR_DEADLOCK); -#endsql - critical_alert("DCM", "Central America build encountered INGRES ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} diff --git a/gen/util.c b/gen/util.c index 8bbe2390..b3d1aa70 100644 --- a/gen/util.c +++ b/gen/util.c @@ -14,6 +14,7 @@ #include #include +extern void sqlglm(char buf[], int *, int *); fix_file(targetfile) char *targetfile; @@ -65,11 +66,14 @@ db_error(code) int code; { extern char *whoami; + char buf[256]; + int bufsize=256, len=0; - com_err(whoami, MR_INGRES_ERR, " code %d\n", code); - if (code == -49900 || code == -37000 || code == 17700) - exit(MR_DEADLOCK); - critical_alert("DCM", "%s build encountered DATABASE ERROR %d", - whoami, code); - exit(MR_INGRES_ERR); + com_err(whoami, MR_DBMS_ERR, " code %d\n", code); + sqlglm(buf, &bufsize, &len); + buf[len]=0; + com_err(whoami, 0, "SQL error text = %s", buf); + critical_alert("DCM", "%s build encountered DATABASE ERROR %d\n%s", + whoami, code, buf); + exit(MR_DBMS_ERR); } diff --git a/gen/zephyr.dc b/gen/zephyr.dc deleted file mode 100644 index e6fca3ee..00000000 --- a/gen/zephyr.dc +++ /dev/null @@ -1,370 +0,0 @@ -/* $Header$ - * - * This generates zephyr acl files - * - * (c) Copyright 1990 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include -#include -#include -#include -#include -EXEC SQL INCLUDE sqlca; - -extern int errno; -char *whoami = "zephyr.gen"; - -char zephyr_dir[BUFSIZ]; - - -main(argc, argv) -int argc; -char **argv; -{ - struct stat sb; - int changed; - char cmd[256]; - - if (argc > 2) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } - - sprintf(zephyr_dir, "%s/zephyr", DCM_DIR); - -#ifsql INGRES - EXEC SQL CONNECT moira; - EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; -#endsql -#ifsql INFORMIX - EXEC SQL DATABASE moira; -#endsql - - changed = do_classes(); - -#ifsql INGRES - EXEC SQL DISCONNECT; -#endsql -#ifsql INFORMIX - EXEC SQL CLOSE DATABASE; -#endsql - - if (!changed) { - fprintf(stderr, "No files updated.\n"); - if (argc == 2 && stat(argv[1], &sb) == 0) - exit(MR_NO_CHANGE); - } - - if (argc == 2) { - fprintf(stderr, "Building tar file.\n"); - sprintf(cmd, "cd %s; tar cf %s .", zephyr_dir, argv[1]); - if (system(cmd)) - exit(MR_TAR_FAIL); - } - - exit(MR_SUCCESS); -} - - -struct zclass { - char class[17]; - char xtype[9]; - char stype[9]; - char wtype[9]; - char utype[9]; - int xid; - int sid; - int wid; - int uid; - struct zclass *next; -}; - - -int do_classes() -{ - FILE *out; - char outclass[256], buf[256]; - struct zclass *top, *next, *zc; - struct stat sb; - int flag1, flag2; - EXEC SQL BEGIN DECLARE SECTION; - char zclass[17], zxtype[9], zstype[9], zwtype[9], zutype[9]; - int zxid, zsid, zwid, zuid; - EXEC SQL END DECLARE SECTION; - - sprintf(outclass, "%s/class-registry.acl", zephyr_dir); - if (stat(outclass, &sb) == 0) { - if (ModDiff(&flag1, "zephyr", sb.st_mtime) || - ModDiff(&flag2, "imembers", sb.st_mtime)) - exit(MR_DATE); - if (flag1 < 0 && flag2 < 0) { - fprintf(stderr, "Zephyr files do not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(buf, "%s~", outclass); - out = fopen(buf, "w"); - if (out == NULL) { - perror("opening class-registry.acl"); - exit(MR_OCONFIG); - } - top = (struct zclass *)malloc(sizeof(struct zclass)); - next = top; - - /* The following is declarative, not executed, - * and so is dependent on where it is in the file, - * not in the order of execution of statements. - */ - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - EXEC SQL DECLARE classes CURSOR FOR SELECT class, xmt_type, xmt_id, - sub_type, sub_id, iws_type, iws_id, iui_type, iui_id - FROM zephyr; - EXEC SQL OPEN classes; - while (1) { - EXEC SQL FETCH classes INTO - :zclass, :zxtype, :zxid, :zstype, :zsid, - :zwtype, :zwid, :zutype, :zuid; - if (sqlca.sqlcode != 0) break; - zc = (struct zclass *)malloc(sizeof(struct zclass)); - next->next = zc; - next = zc; - strcpy(zc->class, zclass); - strcpy(zc->xtype, zxtype); - strcpy(zc->stype, zstype); - strcpy(zc->wtype, zwtype); - strcpy(zc->utype, zutype); - zc->xid = zxid; - zc->sid = zsid; - zc->wid = zwid; - zc->uid = zuid; - } - if (sqlca.sqlcode != 100) { - fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); - exit(MR_INGRES_ERR); - } - EXEC SQL CLOSE classes; - for (zc = top->next; zc; zc = zc->next) { - fprintf(out, "%s:\n", strtrim(zc->class)); - fprintf(stderr, "Working on %s\n", zc->class); - if (!strcasecmp(strtrim(zc->xtype), "LIST")) { - getlist(zc->xid, zc->class, "xmt"); - } else if (!strcasecmp(zc->xtype, "KERBEROS")) { - getstring(zc->xid, zc->class, "xmt"); - } else if (!strcasecmp(zc->xtype, "USER")) { - getuser(zc->xid, zc->class, "xmt"); - } else if (!strcasecmp(zc->xtype, "NONE")) { - getnone(zc->class, "xmt"); - } - if (!strcasecmp(strtrim(zc->stype), "LIST")) { - getlist(zc->sid, zc->class, "sub"); - } else if (!strcasecmp(zc->stype, "KERBEROS")) { - getstring(zc->sid, zc->class, "sub"); - } else if (!strcasecmp(zc->stype, "USER")) { - getuser(zc->sid, zc->class, "sub"); - } else if (!strcasecmp(zc->stype, "NONE")) { - getnone(zc->class, "sub"); - } - if (!strcasecmp(strtrim(zc->wtype), "LIST")) { - getlist(zc->wid, zc->class, "iws"); - } else if (!strcasecmp(zc->wtype, "KERBEROS")) { - getstring(zc->wid, zc->class, "iws"); - } else if (!strcasecmp(zc->wtype, "USER")) { - getuser(zc->wid, zc->class, "iws"); - } else if (!strcasecmp(zc->wtype, "NONE")) { - getnone(zc->class, "iws"); - } - if (!strcasecmp(strtrim(zc->utype), "LIST")) { - getlist(zc->uid, zc->class, "iui"); - } else if (!strcasecmp(zc->utype, "KERBEROS")) { - getstring(zc->uid, zc->class, "iui"); - } else if (!strcasecmp(zc->utype, "USER")) { - getuser(zc->uid, zc->class, "iui"); - } else if (!strcasecmp(zc->utype, "NONE")) { - getnone(zc->class, "iui"); - } - } - fclose(out); - fix_file(outclass); - return(1); - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -getlist(list_id, zclass, atype) -int list_id; -char *zclass; -char *atype; -{ - char ofile[256], buf[256]; - FILE *out; - EXEC SQL BEGIN DECLARE SECTION; - char str[257]; - int zid; - EXEC SQL END DECLARE SECTION; - - zid = list_id; - sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); - fprintf(buf, "%s~", ofile); - out = fopen(buf, "w"); - if (out == NULL) { - perror("opening acl file"); - exit(MR_OCONFIG); - } - - EXEC SQL DECLARE umember CURSOR FOR SELECT users.login - FROM users, imembers - WHERE imembers.list_id = :zid and imembers.member_type='USER' and - imembers.member_id=users.users_id; - EXEC SQL OPEN umember; - while (1) { - EXEC SQL FETCH umember INTO :str; - if (sqlca.sqlcode != 0) break; - fprintf(out, "%s\n", strtrim(str)); - } - if (sqlca.sqlcode != 100) { - fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); - exit(MR_INGRES_ERR); - } - EXEC SQL CLOSE umember; - - EXEC SQL DECLARE smember CURSOR FOR SELECT strings.string - FROM strings, imembers - WHERE imembers.list_id = :zid and imembers.member_id=strings.string_id - and (imembers.member_type='STRING' or imembers.member_type='KERBEROS'); - EXEC SQL OPEN smember; - while (1) { - EXEC SQL FETCH smember INTO :str; - if (sqlca.sqlcode != 0) break; - fprintf(out, "%s\n", strtrim(str)); - } - if (sqlca.sqlcode != 100) { - fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); - exit(MR_INGRES_ERR); - } - EXEC SQL CLOSE smember; - if (fclose(out)) { - perror("closing acl file"); - exit(MR_CCONFIG); - } - fix_file(ofile); - return; - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - -getstring(string_id, zclass, atype) -int string_id; -char *zclass; -char *atype; -{ - char ofile[256], buf[256]; - FILE *out; - EXEC SQL BEGIN DECLARE SECTION; - char str[257]; - int zid; - EXEC SQL END DECLARE SECTION; - - zid = string_id; - sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); - fprintf(buf, "%s~", ofile); - out = fopen(buf, "w"); - if (out == NULL) { - perror("opening acl file"); - exit(MR_OCONFIG); - } - - EXEC SQL SELECT string INTO :str FROM strings WHERE string_id = :zid; - if (sqlca.sqlcode != 0) { - if (sqlca.sqlcode == 100) { - fprintf(stderr, "String %d not found for class %s type %s\n", - zid, zclass, atype); - } else { - fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); - exit(MR_INGRES_ERR); - } - } - if (!strcmp(strtrim(str), "WILDCARD")) { - strcpy(str, "*.*@*"); - } - fprintf(out, "%s\n", str); - if (fclose(out)) { - perror("closing acl file"); - exit(MR_CCONFIG); - } - fix_file(ofile); - return; - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -getuser(user_id, zclass, atype) -int user_id; -char *zclass; -char *atype; -{ - char ofile[256], buf[256]; - FILE *out; - EXEC SQL BEGIN DECLARE SECTION; - char login[9]; - int zid; - EXEC SQL END DECLARE SECTION; - - zid = user_id; - sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); - fprintf(buf, "%s~", ofile); - out = fopen(buf, "w"); - if (out == NULL) { - perror("opening acl file"); - exit(MR_OCONFIG); - } - - EXEC SQL SELECT login INTO :login FROM users WHERE users_id = :zid; - if (sqlca.sqlcode != 0) { - if (sqlca.sqlcode == 100) { - fprintf(stderr, "User %d not found\n", zid); - } else { - fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); - exit(MR_INGRES_ERR); - } - } - fprintf(out, "%s\n", strtrim(login)); - if (fclose(out)) { - perror("closing acl file"); - exit(MR_CCONFIG); - } - fix_file(ofile); - return; - sqlerr: - com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); - critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", - sqlca.sqlcode); - exit(MR_INGRES_ERR); -} - - -getnone(zclass, atype) -char *zclass; -char *atype; -{ - char ofile[256]; - - sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); - unlink(ofile); -}