From 5eaef52092da48d922a6b37cf48bb7c5104d0841 Mon Sep 17 00:00:00 2001 From: danw Date: Mon, 5 Jan 1998 19:51:32 +0000 Subject: [PATCH] Code style cleanup. (No functional changes) --- backup/db2bkup.awk | 57 +- backup/db2rest.awk | 70 +- backup/dump_db.h | 3 +- backup/dump_db.pc | 182 ++- backup/dumprest.pc | 27 +- backup/rest_db.pc | 327 ++-- clients/addusr/addusr.c | 544 ++++--- clients/blanche/blanche.c | 1541 +++++++++--------- clients/mailmaint/mailmaint.c | 1363 ++++++++-------- clients/moira/TODO | 2 +- clients/moira/attach.c | 1481 +++++++++-------- clients/moira/cluster.c | 2313 +++++++++++++-------------- clients/moira/dcmmaint.c | 758 +++++---- clients/moira/defs.h | 16 +- clients/moira/delete.c | 939 +++++------ clients/moira/f_defs.h | 32 +- clients/moira/globals.c | 8 +- clients/moira/globals.h | 8 +- clients/moira/lists.c | 1131 +++++++------ clients/moira/main.c | 252 ++- clients/moira/menu.c | 1071 ++++++------- clients/moira/menu.h | 30 +- clients/moira/menus.c | 645 ++++---- clients/moira/misc.c | 178 +-- clients/moira/namespace.c | 386 +++-- clients/moira/nfs.c | 512 +++--- clients/moira/pobox.c | 331 ++-- clients/moira/printer.c | 689 ++++---- clients/moira/quota.c | 426 +++-- clients/moira/user.c | 1423 ++++++++--------- clients/moira/utils.c | 961 ++++++----- clients/moira/zephyr.c | 443 +++--- clients/mrcheck/mrcheck.c | 322 ++-- clients/mrtest/mrtest.c | 628 ++++---- clients/passwd/chfn.c | 463 +++--- clients/passwd/chpobox.c | 479 +++--- clients/passwd/chsh.c | 340 ++-- clients/userreg/disable.c | 392 ++--- clients/userreg/display.c | 452 +++--- clients/userreg/reg_stubs.c | 603 ++++--- clients/userreg/register | 2 +- clients/userreg/userreg.c | 1397 ++++++++-------- clients/userreg/userreg.h | 18 +- dbck/dbck.h | 54 +- dbck/dbck.pc | 271 ++-- dbck/fix.pc | 321 ++-- dbck/nhash.c | 200 ++- dbck/phase1.pc | 1231 +++++++------- dbck/phase2.pc | 2822 +++++++++++++++++---------------- dbck/phase3.pc | 75 +- dbck/phase4.pc | 356 +++-- dcm/dcm.pc | 607 +++---- dcm/startdcm.c | 218 +-- gen/Imakefile | 6 +- gen/hesiod.pc | 1873 ++++++++++++---------- gen/hesiod.sh | 4 +- gen/hosts.pc | 226 +-- gen/install_dirs | 12 +- gen/install_quotas | 6 +- gen/mailhub.pc | 1205 +++++++------- gen/moddiff.pc | 330 ++-- gen/network.pc | 144 +- gen/nfs.pc | 819 +++++----- gen/nfs.sh | 2 +- gen/passwd.pc | 129 +- gen/pobox.pc | 166 +- gen/setquota.c | 234 ++- gen/util.c | 97 +- gen/warehouse.pc | 247 +-- gen/zero_quotas | 8 +- include/moira_site.h | 12 +- incremental/afs.c | 1046 ++++++------ incremental/afs_create.pl | 2 +- incremental/afs_nightly.pl | 8 +- incremental/afs_rename.pl | 2 +- incremental/ksrvtgt.c | 105 +- lib/critical.c | 82 +- lib/fixhost.c | 94 +- lib/fixname.c | 178 +-- lib/gdss_convert.c | 9 +- lib/hash.c | 181 +-- lib/idno.c | 30 +- lib/kname_unparse.c | 114 +- lib/krb_et.et | 2 +- lib/mr_access.c | 59 +- lib/mr_auth.c | 86 +- lib/mr_call.c | 53 +- lib/mr_connect.c | 150 +- lib/mr_et.et | 2 +- lib/mr_init.c | 19 +- lib/mr_ops.c | 182 ++- lib/mr_param.c | 372 +++-- lib/mr_private.h | 2 +- lib/mr_query.c | 105 +- lib/nfsparttype.c | 127 +- lib/sq.c | 185 ++- lib/strs.c | 146 +- lib/ureg_err.et | 2 +- reg_svr/reg_svr.c | 1594 +++++++++---------- reg_svr/reg_svr.h | 36 +- reg_svr/requests.c | 466 +++--- reg_svr/startreg.c | 218 +-- regtape/employee.pc | 942 ++++++----- regtape/personel.input | 20 +- regtape/rafnu.c | 101 +- regtape/registrar.input | 20 +- regtape/sign.pc | 242 +-- regtape/students.pc | 1219 +++++++------- regtape/verify.pc | 425 ++--- regtape/vote.pc | 171 +- server/cache.pc | 506 +++--- server/increment.pc | 707 ++++----- server/mr_glue.c | 275 ++-- server/mr_main.c | 832 +++++----- server/mr_sauth.c | 180 ++- server/mr_scall.c | 611 ++++--- server/mr_server.h | 40 +- server/mr_shutdown.c | 19 +- server/mr_srvdata.c | 4 +- server/mr_util.c | 197 +-- server/qaccess.pc | 532 +++---- server/qfollow.pc | 1813 +++++++++++---------- server/qrtn.h | 4 +- server/qrtn.pc | 1376 ++++++++-------- server/qsetup.pc | 1640 +++++++++---------- server/qsubs.c | 199 +-- server/qsupport.pc | 2094 ++++++++++++------------ server/queries2.c | 371 +++-- server/query.h | 72 +- server/qvalidate.pc | 942 +++++------ server/startmoira.c | 235 +-- update/auth_002.c | 179 ++- update/checksum.c | 23 +- update/client.c | 199 ++- update/config.c | 139 +- update/exec_002.c | 176 +- update/get_file.c | 301 ++-- update/hostname.c | 34 +- update/log.c | 92 +- update/send_file.c | 244 ++- update/smskey.c | 51 +- update/ticket.c | 105 +- update/update_server.c | 306 ++-- update/update_test.c | 166 +- update/xfer_002.c | 85 +- update/xfer_003.c | 85 +- 146 files changed, 29439 insertions(+), 29112 deletions(-) diff --git a/backup/db2bkup.awk b/backup/db2bkup.awk index f435372d..16ada418 100644 --- a/backup/db2bkup.awk +++ b/backup/db2bkup.awk @@ -6,7 +6,7 @@ # This is not guaranteed to work for all data types; it may # need to be extended. -BEGIN { +BEGIN { print "/* This file automatically generated */"; print "/* Do not edit */\n"; print "#include "; @@ -18,15 +18,15 @@ BEGIN { print "/* This file automatically generated */" > "bkup1.pc"; print "/* Do not edit */\n" >> "bkup1.pc"; print "#include " >> "bkup1.pc"; - print "FILE *open_file();" >> "bkup1.pc"; - print "do_backups(prefix)\n\tchar *prefix;\n{" >> "bkup1.pc"; + print "FILE *open_file(char *prefix, char *suffix);\n" >> "bkup1.pc"; + print "int do_backups(char *prefix)\n{" >> "bkup1.pc"; } $1=="#" { next; } -/^create/ { - printf "dump_%s(f)\nFILE *f;\n{\n\tEXEC SQL BEGIN DECLARE SECTION;\n", $3; - printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.pc"; +/^create/ { + printf "int dump_%s(FILE *f)\n{\n EXEC SQL BEGIN DECLARE SECTION;\n", $3; + printf " dump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.pc"; tablename = $3; rangename = substr(tablename, 1, 1); @@ -35,65 +35,64 @@ $1=="#" { next; } } NF>=2 { - vname[count] = $1; - printf "/* %s */\n", $0; + vname[count] = $1; + printf " /* %s */\n", $0; if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { - printf "\tint\tt_%s;\n", vname[count]; + printf " int\tt_%s;\n", vname[count]; vtype[count]="int"; } else if ($2 ~ /CHAR\([0-9]*\)/) { t = split($2, temp, "("); if (t != 2) printf "Can't parse %s\n", $2; t = split(temp[2], temp2, ")"); if (t != 2) printf "Can't parse %s\n", temp[2]; - printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; + printf " char\tt_%s[%d];\n", vname[count], temp2[1]+1; if ($1 == "signature") { vtype[count]="bin"; - printf "\tEXEC SQL VAR t_signature IS STRING(%d);\n", temp2[1]+1; + printf " EXEC SQL VAR t_signature IS STRING(%d);\n", temp2[1]+1; } else { vtype[count]="str"; } vsize[count] = temp2[1]+1; } else if ($2 ~ /DATE/) { - printf "\tchar\tt_%s[26];\n", vname[count]; + printf " char\tt_%s[26];\n", vname[count]; vtype[count]="date"; } else printf "Unknown data type %s\n", $2; count++; } -/^\);$/ { - printf "\tEXEC SQL END DECLARE SECTION;\n"; - printf "\tEXEC SQL DECLARE c_%s CURSOR FOR\n", tablename; - printf "\t\tSELECT\n"; +/^\);$/ { + printf " EXEC SQL END DECLARE SECTION;\n\n"; + printf " EXEC SQL DECLARE c_%s CURSOR FOR SELECT\n", tablename; for (i = 0; i < count; i++) { if (i != 0) { print ","; } if(vtype[i] ~ /date/) { - printf "\t\t\tTO_CHAR(%s, 'DD-mon-YYYY HH24:MI:SS')", vname[i]; - } else printf "\t\t\t%s", vname[i]; + printf " TO_CHAR(%s, 'DD-mon-YYYY HH24:MI:SS')", vname[i]; + } else printf " %s", vname[i]; } printf " FROM %s;\n", tablename; - printf "\tEXEC SQL OPEN c_%s;\n", tablename; - printf "\twhile(1) {\n\t\tEXEC SQL FETCH c_%s INTO\n", tablename; + printf " EXEC SQL OPEN c_%s;\n", tablename; + printf " while (1)\n {\n EXEC SQL FETCH c_%s INTO\n", tablename; for (i = 0; i < count; i++) { if (i != 0) printf ",\n"; - printf "\t\t\t:t_%s", vname[i]; + printf " :t_%s", vname[i]; } printf ";\n"; - printf "\t\tif(sqlca.sqlcode != 0) break;\n"; + printf " if (sqlca.sqlcode != 0)\n break;\n"; for (i = 0; i < count; i++) { - if (i != 0) print "\t\tdump_sep(f);"; + if (i != 0) print " dump_sep(f);"; if (vtype[i] ~ /str/ || vtype[i] ~ /date/) { - printf "\t\tdump_str(f, strtrim(t_%s));\n", vname[i]; + printf " dump_str(f, strtrim(t_%s));\n", vname[i]; } else { - printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]; + printf " dump_%s(f, t_%s);\n", vtype[i], vname[i]; } } - printf "\t\tdump_nl(f);\n"; - printf "\t}\n"; - printf "\tEXEC SQL CLOSE c_%s;\n", tablename; - printf "\tsafe_close(f);\n"; + printf " dump_nl(f);\n"; + printf " }\n"; + printf " EXEC SQL CLOSE c_%s;\n", tablename; + printf " safe_close(f);\n"; printf "}\n\n"; } diff --git a/backup/db2rest.awk b/backup/db2rest.awk index a5b73ca1..269cad43 100644 --- a/backup/db2rest.awk +++ b/backup/db2rest.awk @@ -12,21 +12,21 @@ BEGIN { print "#include "; print "EXEC SQL INCLUDE sqlca;"; print "EXEC SQL WHENEVER SQLERROR DO dbmserr();"; - print "void parse_nl(), parse_str(FILE *, char *, int), parse_sep();\n"; + print "void parse_nl(FILE *), parse_str(FILE *, char *, int), parse_sep(FILE *);\n"; print "/* This file automatically generated */" > "rest1.pc"; print "/* Do not edit */\n" >> "rest1.pc"; print "#include " >> "rest1.pc"; - print "FILE *open_file();" >> "rest1.pc"; - print "do_restores(prefix)\n\tchar *prefix;\n{" >> "rest1.pc"; + print "FILE *open_file(char *prefix, char *suffix);\n" >> "rest1.pc"; + print "int do_restores(char *prefix)\n{" >> "rest1.pc"; } $1=="#" { next; } /^create/ { - printf "restore_%s(f)\nFILE *f;\n", $3; - print "{\n\tEXEC SQL BEGIN DECLARE SECTION;"; - printf "\trestore_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "rest1.pc"; + printf "int restore_%s(FILE *f)\n", $3; + print "{\n EXEC SQL BEGIN DECLARE SECTION;"; + printf " restore_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "rest1.pc"; tablename = $3; rangename = substr(tablename, 1, 1); @@ -35,71 +35,71 @@ $1=="#" { next; } } NF >= 2 { - vname[count] = $1; - printf "/* %s */\n", $0; + vname[count] = $1; + printf " /* %s */\n", $0; if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { - printf "\tint\tt_%s;\n", vname[count]; + printf " int\tt_%s;\n", vname[count]; vtype[count]="int"; } else if ($2 ~ /CHAR\([0-9]*\)/) { t = split($2, temp, "("); if (t != 2) printf "Can't parse %s\n", $2; t = split(temp[2], temp2, ")"); if (t != 2) printf "Can't parse %s\n", temp[2]; - printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; + printf " char\tt_%s[%d];\n", vname[count], temp2[1]+1; if ($1 == "signature") { vtype[count]="bin"; - printf "\tEXEC SQL VAR t_signature IS STRING(%d);\n", temp2[1]+1; + printf " EXEC SQL VAR t_signature IS STRING(%d);\n", temp2[1]+1; } else vtype[count]="str"; vsize[count] = temp2[1]+1; } else if ($2 ~ /DATE/) { - printf "\tchar\tt_%s[26];\n", vname[count]; + printf " char\tt_%s[26];\n", vname[count]; vtype[count]="date"; } else printf "Unknown data type %s\n", $2; count++; } -/^\);$/ { - printf "\tEXEC SQL END DECLARE SECTION;\n\tint count=0;\n"; +/^\);$/ { + printf " EXEC SQL END DECLARE SECTION;\n\n int count = 0;\n"; - print "\twhile(!feof(f)) {"; - print "\t\tif(!(++count%100)) {\n\t\t\tEXEC SQL COMMIT;\n\t\t}\n"; + print " while (!feof(f))\n {"; + print " if (!(++count % 100))\n EXEC SQL COMMIT;\n"; for (i = 0; i < count; i++) { - if (i != 0) print "\t\tparse_sep(f);"; + if (i != 0) print " parse_sep(f);"; if (vtype[i] ~ /int/) { - printf("\t\tt_%s = parse_int(f);\n", vname[i]); + printf(" t_%s = parse_int(f);\n", vname[i]); } else if (vtype[i] ~ /date/) { - printf "\t\tparse_str(f, t_%s, 26);\n", vname[i]; + printf " parse_str(f, t_%s, 26);\n", vname[i]; } else { - printf "\t\tparse_str(f, t_%s, %d);\n", vname[i], vsize[i]; + printf " parse_str(f, t_%s, %d);\n", vname[i], vsize[i]; } - if (i == 0) print "\t\tif (feof(f)) break;"; + if (i == 0) print " if (feof(f))\n break;"; } - printf "\t\tparse_nl(f);\n" + printf " parse_nl(f);\n" - printf "\t\tEXEC SQL INSERT INTO %s (\n", tablename; + printf " EXEC SQL INSERT INTO %s (\n", tablename; for (i = 0; i < count; i++) { if (i != 0) printf ",\n"; - printf "\t\t\t%s", vname[i]; + printf " %s", vname[i]; } - printf ")\n\t\tVALUES (\n"; + printf ")\n VALUES (\n"; for (i = 0; i < count; i++) { if (i != 0) printf ",\n"; if (vtype[i] ~ /date/) { - printf "\t\t\tTO_DATE(NVL(:t_%s,TO_CHAR(SYSDATE, 'DD_mon-YYYY HH24:MI:SS')), 'DD-mon-YYYY HH24:MI:SS')", vname[i]; + printf " TO_DATE(NVL(:t_%s,TO_CHAR(SYSDATE, 'DD_mon-YYYY HH24:MI:SS')), 'DD-mon-YYYY HH24:MI:SS')", vname[i]; } else if(vtype[i] ~ /int/) { - printf "\t\t\t:t_%s", vname[i]; + printf " :t_%s", vname[i]; } else { - printf "\t\t\tNVL(:t_%s,CHR(0))", vname[i]; + printf " NVL(:t_%s,CHR(0))", vname[i]; } } - printf ");\n\t\tif (sqlca.sqlcode != 0) {\n"; - printf "\t\t\tsqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0;\n"; - printf "\t\t\tprintf(\"%%s\\n\", sqlca.sqlerrm.sqlerrmc);\n"; - printf "\t\t\tcom_err(\"restore\", 0, \"insert failed\");\n"; - printf "\t\t\texit(2);\n\t\t}\n\t}\n"; - printf "\t(void) fclose(f);\n"; - printf "\tEXEC SQL COMMIT;\n"; + printf ");\n if (sqlca.sqlcode != 0)\n {\n"; + printf " sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = 0;\n"; + printf " printf(\"%%s\\n\", sqlca.sqlerrm.sqlerrmc);\n"; + printf " com_err(\"restore\", 0, \"insert failed\");\n"; + printf " exit(2);\n }\n }\n"; + printf " fclose(f);\n"; + printf " EXEC SQL COMMIT;\n"; printf "}\n\n"; } diff --git a/backup/dump_db.h b/backup/dump_db.h index 945850ec..c68ed880 100644 --- a/backup/dump_db.h +++ b/backup/dump_db.h @@ -1,7 +1,6 @@ /* $Header$ */ -#define SEP_CHAR ('|') +#define SEP_CHAR ('|') #define dump_nl(f) { if (putc('\n', f) < 0) wpunt(); } #define dump_sep(f) { if (putc(SEP_CHAR, f) < 0) wpunt(); } - diff --git a/backup/dump_db.pc b/backup/dump_db.pc index 4148e926..2a6231e5 100644 --- a/backup/dump_db.pc +++ b/backup/dump_db.pc @@ -9,7 +9,7 @@ * * This program dumps the SMS database to a series of output files * which can be later read back into SMS in the event of a crash. - * + * */ #ifndef lint @@ -33,125 +33,131 @@ EXEC SQL INCLUDE sqlca; FILE *open_file(); EXEC SQL BEGIN DECLARE SECTION; -char *db="moira"; +char *db = "moira"; EXEC SQL END DECLARE SECTION; -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - char *prefix; - register int i; - - if (argc != 2) { - fprintf(stderr, "Usage: %s prefix\n", argv[0]); - exit(1); + char *prefix; + register int i; + + if (argc != 2) + { + fprintf(stderr, "Usage: %s prefix\n", argv[0]); + exit(1); } - prefix = argv[1]; + prefix = argv[1]; - EXEC SQL CONNECT :db IDENTIFIED BY :db; + EXEC SQL CONNECT :db IDENTIFIED BY :db; - do_backups(prefix); + do_backups(prefix); - EXEC SQL COMMIT; - exit(0); + EXEC SQL COMMIT; + exit(0); } -dump_int(f, n) - FILE *f; - int n; +int dump_int(FILE *f, int n) { - char buf[1024]; - (void) sprintf(buf, "%d", n); - dump_str(f, buf); + char buf[1024]; + sprintf(buf, "%d", n); + dump_str(f, buf); } -wpunt() +int wpunt(void) { - punt("can't write backup file"); + punt("can't write backup file"); } -dump_str(f, str) - register FILE *f; - register char *str; +int dump_str(register FILE *f, register char *str) { - register char *ibp; - register int c; /* PCC doesn't put chars in registers.. */ - register int t; - - for (ibp = str; c = (unsigned char) *ibp; ibp++) { - if(c<32 || c>126 || c==SEP_CHAR || c=='\\') { - if (putc1('\\', f) < 0) wpunt(); - t = ((c>>6)&7) + '0'; - if (putc1(t,f) < 0) wpunt(); - t = ((c>>3)&7) + '0'; - if (putc1(t,f) < 0) wpunt(); - t = (c&7) + '0'; - if (putc1(t,f) < 0) wpunt(); - } else { - if (putc1(c, f) < 0) wpunt(); + register char *ibp; + register int c; /* PCC doesn't put chars in registers.. */ + register int t; + + for (ibp = str; c = (unsigned char) *ibp; ibp++) + { + if (c < 32 || c > 126 || c == SEP_CHAR || c == '\\') + { + if (putc1('\\', f) < 0) + wpunt(); + t = ((c >> 6) & 7) + '0'; + if (putc1(t, f) < 0) + wpunt(); + t = ((c >> 3) & 7) + '0'; + if (putc1(t, f) < 0) + wpunt(); + t = (c & 7) + '0'; + if (putc1(t, f) < 0) + wpunt(); + } + else + { + if (putc1(c, f) < 0) + wpunt(); } } } -safe_close(stream) - FILE *stream; +int safe_close(FILE *stream) { - if (fflush(stream) == EOF) - punt("Unable to fflush"); - if (fsync(fileno(stream)) != 0) - punt("Unable to fsync"); - (void) fclose(stream); -} - -FILE *open_file(prefix, suffix) - char *prefix, *suffix; + if (fflush(stream) == EOF) + punt("Unable to fflush"); + if (fsync(fileno(stream)) != 0) + punt("Unable to fsync"); + fclose(stream); +} + +FILE *open_file(char *prefix, char *suffix) { - char name[BUFSIZ]; - int fd; - FILE *f; - - (void) strcpy(name, prefix); - (void) strcat(name, suffix); - - fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644); - if (fd < 0) { - punt(name); - } - f = fdopen(fd, "w"); - if (f == NULL) { - fprintf(stderr, "fdopen of "); - punt(name); + char name[BUFSIZ]; + int fd; + FILE *f; + + strcpy(name, prefix); + strcat(name, suffix); + + fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644); + if (fd < 0) + punt(name); + f = fdopen(fd, "w"); + if (!f) + { + fprintf(stderr, "fdopen of "); + punt(name); } - fprintf(stderr, "Working on %s\n", name); - return(f); + fprintf(stderr, "Working on %s\n", name); + return f; } /* * Trim whitespace off both ends of a string. */ -char *strtrim(save) - register char *save; +char *strtrim(register char *save) { - register char *t, *s; - - s = save; - while (isspace(*s)) s++; - /* skip to end of string */ - if (*s == '\0') { - *save = '\0'; - return(save); + register char *t, *s; + + s = save; + while (isspace(*s)) + s++; + /* skip to end of string */ + if (*s == '\0') + { + *save = '\0'; + return save; } - for (t = s; *t; t++) continue; - while (t > s) { - --t; - if (!isspace(*t)) { - t++; - break; + for (t = s; *t; t++) + continue; + while (t > s) + { + --t; + if (!isspace(*t)) + { + t++; + break; } } - *t = '\0'; - return s; + *t = '\0'; + return s; } diff --git a/backup/dumprest.pc b/backup/dumprest.pc index 501b38b8..dd224f02 100644 --- a/backup/dumprest.pc +++ b/backup/dumprest.pc @@ -16,22 +16,21 @@ static char *rcsid_dumprest_qc = "$Header$"; #include #include -punt(msg) - char *msg; +int punt(char *msg) { - perror(msg); - exit(1); + perror(msg); + exit(1); } -dbmserr(void) +int dbmserr(void) { - EXEC SQL BEGIN DECLARE SECTION; - char err_msg[256]; - EXEC SQL END DECLARE SECTION; - int bufsize=256, msglength=0; - - sqlglm(err_msg, &bufsize, &msglength); - err_msg[msglength]=0; - fprintf(stderr, "Fatal SQL error:\n%s", err_msg); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + char err_msg[256]; + EXEC SQL END DECLARE SECTION; + int bufsize = 256, msglength = 0; + + sqlglm(err_msg, &bufsize, &msglength); + err_msg[msglength] = '\0'; + fprintf(stderr, "Fatal SQL error:\n%s", err_msg); + exit(1); } diff --git a/backup/rest_db.pc b/backup/rest_db.pc index 4c268ea9..1d26fb50 100644 --- a/backup/rest_db.pc +++ b/backup/rest_db.pc @@ -6,7 +6,7 @@ * (c) Copyright 1988 by the Massachusetts Institute of Technology. * For copying and distribution information, please see the file * . - * + * */ #ifndef lint @@ -22,195 +22,214 @@ EXEC SQL INCLUDE sqlca; #include "dump_db.h" -/*ARGSUSED*/ -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - char buf[BUFSIZ]; - char *prefix; - EXEC SQL BEGIN DECLARE SECTION; - char *db; - EXEC SQL END DECLARE SECTION; - - if (argc != 2) { - fprintf(stderr, "Usage: %s database\n", argv[0]); - exit(1); + char buf[BUFSIZ]; + char *prefix; + EXEC SQL BEGIN DECLARE SECTION; + char *db; + EXEC SQL END DECLARE SECTION; + + if (argc != 2) + { + fprintf(stderr, "Usage: %s database\n", argv[0]); + exit(1); } - db = argv[1]; + db = argv[1]; - if (!yes_or_no("Do you *REALLY* want to wipe the moira database?")) { - printf("I didn't think so\n"); - exit(1); - } - sprintf(buf, "Have you initialized an empty database named %s?", db); - if (!yes_or_no(buf)) { - printf("You should have\n"); - exit(1); + if (!yes_or_no("Do you *REALLY* want to wipe the moira database?")) + { + printf("I didn't think so\n"); + exit(1); } - - printf("Opening database: "); - (void) fflush(stdout); - EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (sqlca.sqlcode != 0) { - com_err(argv[0], 0, "Ingres database open failed"); - exit(1); + sprintf(buf, "Have you initialized an empty database named %s?", db); + if (!yes_or_no(buf)) + { + printf("You should have\n"); + exit(1); } - printf(" done\n"); - printf("Prefix of backup to restore: "); - (void) fflush(stdout); - if (gets(buf) == NULL) { - return 1; + printf("Opening database: "); + fflush(stdout); + EXEC SQL CONNECT :db IDENTIFIED BY :db; + if (sqlca.sqlcode != 0) + { + com_err(argv[0], 0, "Ingres database open failed"); + exit(1); } - prefix = buf; - - if (!yes_or_no("Are you SURE?")) { - printf("I didn't think so\n"); - exit(1); + printf(" done\n"); + + printf("Prefix of backup to restore: "); + fflush(stdout); + if (!gets(buf)) + return 1; + prefix = buf; + + if (!yes_or_no("Are you SURE?")) + { + printf("I didn't think so\n"); + exit(1); } - do_restores(prefix); - printf("Restore complete\n"); - EXEC SQL COMMIT; - exit(0); - /*NOTREACHED*/ + do_restores(prefix); + printf("Restore complete\n"); + EXEC SQL COMMIT; + exit(0); + /*NOTREACHED*/ } -yes_or_no(prompt) - char *prompt; +int yes_or_no(char *prompt) { - char buf[BUFSIZ]; - int ret; - - int tt = open("/dev/tty", O_RDWR, 0); - FILE *o, *i; - - register char *cp; - - if (tt < 0) return 0; - - (void) fflush(stdout); - (void) fflush(stderr); - o = fdopen(dup(tt), "w"); - i = fdopen(dup(tt), "r"); - (void) close(tt); - - for (;;) { - fprintf(o, "%s (yes or no): ", prompt); - (void) fflush(o); - if (fgets(buf, BUFSIZ, i) == NULL) goto err; - for (cp = buf; *cp; cp++) { - if (isupper(*cp)) *cp=tolower(*cp); + char buf[BUFSIZ]; + int ret; + + int tt = open("/dev/tty", O_RDWR, 0); + FILE *o, *i; + + register char *cp; + + if (tt < 0) + return 0; + + fflush(stdout); + fflush(stderr); + o = fdopen(dup(tt), "w"); + i = fdopen(dup(tt), "r"); + close(tt); + + for (;;) + { + fprintf(o, "%s (yes or no): ", prompt); + fflush(o); + if (!fgets(buf, BUFSIZ, i)) + goto err; + for (cp = buf; *cp; cp++) + { + if (isupper(*cp)) + *cp = tolower(*cp); } - if (strcmp(buf, "yes\n") == 0) { - ret = 1; goto out; + if (!strcmp(buf, "yes\n")) + { + ret = 1; + goto out; } - if (strcmp(buf, "no\n") == 0) { - ret = 0; goto out; + if (!strcmp(buf, "no\n")) + { + ret = 0; + goto out; } } err: - ret = 0; + ret = 0; out: - (void) fclose(o); - (void) fclose(i); - return ret; + fclose(o); + fclose(i); + return ret; } -int parse_int(f) - register FILE *f; +int parse_int(register FILE *f) { - register int c; - register int val = 0; - register int sign = 1; - while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') { - if (c == '-') sign = -1; - else if (isdigit(c)) { - val *= 10; - val += (c - '0'); - } else (void) fprintf(stderr,"non-digit in numeric field\n"); + register int c; + register int val = 0; + register int sign = 1; + while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') + { + if (c == '-') + sign = -1; + else if (isdigit(c)) + { + val *= 10; + val += (c - '0'); + } else + fprintf(stderr, "non-digit in numeric field\n"); } - (void) ungetc(c, f); - return(val * sign); + ungetc(c, f); + return val * sign; } -void parse_str(f, buf, maxlen) - register FILE *f; - register char *buf; - register int maxlen; +void parse_str(register FILE *f, register char *buf, register int maxlen) { - register int c, len=0; - - while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len < maxlen) { - if (c == '\\') { - c = getc(f); - if (isdigit(c)) { - /* Expect three-digit octal number.. */ - register int c1, c2; - c1 = getc(f); - c2 = getc(f); - if (!isdigit(c1) || !isdigit(c2)) - punt("Broken \\###"); - /* Convert to ASCII code: */ - *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0'); - len++; - } else if (c == '\\' || c == SEP_CHAR) { - *buf++ = c; - len++; - } else punt ("Broken '\\'"); - } else { - *buf++ = c; - len++; + register int c, len = 0; + + while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len < maxlen) + { + if (c == '\\') + { + c = getc(f); + if (isdigit(c)) + { + /* Expect three-digit octal number.. */ + register int c1, c2; + c1 = getc(f); + c2 = getc(f); + if (!isdigit(c1) || !isdigit(c2)) + punt("Broken \\###"); + /* Convert to ASCII code: */ + *buf++ = ((c - '0') << 6) + ((c1 - '0') << 3) + c2 - '0'; + len++; + } + else if (c == '\\' || c == SEP_CHAR) + { + *buf++ = c; + len++; + } + else + punt ("Broken '\\'"); + } + else + { + *buf++ = c; + len++; } } - *buf='\0'; - if (c == EOF) - return; - - if (c != EOF && c != SEP_CHAR && c != '\n') { - fprintf(stderr, "Field too wide, truncated\n"); - while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n'); - (void) ungetc(c, f); - } else { - (void) ungetc(c, f); + *buf = '\0'; + if (c == EOF) + return; + + if (c != EOF && c != SEP_CHAR && c != '\n') + { + fprintf(stderr, "Field too wide, truncated\n"); + while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n') + ; + ungetc(c, f); } + else + ungetc(c, f); } - -void parse_sep(f) - FILE *f; + +void parse_sep(FILE *f) { - if (getc(f) != SEP_CHAR) punt("Expected Separator"); + if (getc(f) != SEP_CHAR) + punt("Expected Separator"); } -void parse_nl(f) - FILE *f; +void parse_nl(FILE *f) { - if (getc(f) != '\n') punt("Expected newline"); + if (getc(f) != '\n') + punt("Expected newline"); } -FILE *open_file(prefix, suffix) - char *prefix, *suffix; +FILE *open_file(char *prefix, char *suffix) { - char name[BUFSIZ]; - int fd; - FILE *f; - - EXEC SQL COMMIT WORK; - - (void) strcpy(name, prefix); - (void) strcat(name, suffix); - - fd = open(name, O_RDONLY, 0); - if (fd < 0) { - punt(name); - } - f = fdopen(fd, "r"); - if (f == NULL) { - fprintf(stderr, "fdopen of "); - punt(name); + char name[BUFSIZ]; + int fd; + FILE *f; + + EXEC SQL COMMIT WORK; + + strcpy(name, prefix); + strcat(name, suffix); + + fd = open(name, O_RDONLY, 0); + if (fd < 0) + punt(name); + f = fdopen(fd, "r"); + if (!f) + { + fprintf(stderr, "fdopen of "); + punt(name); } - fprintf(stderr, "Working on %s\n", name); - return(f); + fprintf(stderr, "Working on %s\n", name); + return f; } diff --git a/clients/addusr/addusr.c b/clients/addusr/addusr.c index 0a77fb78..8d5bbac3 100644 --- a/clients/addusr/addusr.c +++ b/clients/addusr/addusr.c @@ -35,7 +35,7 @@ char *class, *comment, *status_str, *shell, *filename; int reg_only, reg, verbose, nodupcheck; /* argument parsing macro */ -#define argis(a,b) ((strcmp(*arg+1, a) == 0) || (strcmp(*arg+1, b) == 0)) +#define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b)) char *whoami; int duplicate, errors; @@ -45,301 +45,363 @@ extern int errno; int usercheck(), scream(); -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - int status, lineno; - char **arg = argv, *qargv[U_END]; - char *motd, *p, *first, *middle, *last, *id, *login, *passwd, *server; - char buf[BUFSIZ], idbuf[32]; - FILE *input; + int status, lineno; + char **arg = argv, *qargv[U_END]; + char *motd, *p, *first, *middle, *last, *id, *login, *passwd, *server; + char buf[BUFSIZ], idbuf[32]; + FILE *input; - /* clear all flags & lists */ - reg_only = reg = verbose = lineno = nodupcheck = errors = 0; - server = NULL; - filename = "-"; - shell = DEFAULT_SHELL; - class = "TEMP"; - comment = ""; - status_str = "0"; + /* clear all flags & lists */ + reg_only = reg = verbose = lineno = nodupcheck = errors = 0; + server = NULL; + filename = "-"; + shell = DEFAULT_SHELL; + class = "TEMP"; + comment = ""; + status_str = "0"; - whoami = argv[0]; + whoami = argv[0]; - /* parse args */ - while (++arg - argv < argc) { - if (**arg == '-') + /* parse args */ + while (++arg - argv < argc) + { + if (**arg == '-') { - if (argis("c", "class")) - if (arg - argv < argc - 1) { - ++arg; - class = *arg; - } else - usage(argv); - else if (argis("C", "comment")) - if (arg - argv < argc - 1) { - ++arg; - comment = *arg; - } else - usage(argv); - else if (argis("s", "status")) - if (arg - argv < argc - 1) { - ++arg; - status_str = *arg; - } else - usage(argv); - else if (argis("h", "shell")) - if (arg - argv < argc - 1) { - ++arg; - shell = *arg; - } else - usage(argv); - else if (argis("r", "reg_only")) - reg_only++; - else if (argis("R", "register")) - reg++; - else if (argis("f", "file")) - if (arg - argv < argc - 1) { - ++arg; - filename = *arg; - } else - usage(argv); - else if (argis("v","verbose")) - verbose++; - else if (argis("d","nodupcheck")) - nodupcheck++; - else if (argis("S","server") || argis("db","database")) - if (arg - argv < argc - 1) { - ++arg; - server = *arg; - } else - usage(argv); - else + if (argis("c", "class")) + { + if (arg - argv < argc - 1) + { + ++arg; + class = *arg; + } + else + usage(argv); + } + else if (argis("C", "comment")) + { + if (arg - argv < argc - 1) + { + ++arg; + comment = *arg; + } + else + usage(argv); + } + else if (argis("s", "status")) + { + if (arg - argv < argc - 1) + { + ++arg; + status_str = *arg; + } + else + usage(argv); + } + else if (argis("h", "shell")) + { + if (arg - argv < argc - 1) + { + ++arg; + shell = *arg; + } + else + usage(argv); + } + else if (argis("r", "reg_only")) + reg_only++; + else if (argis("R", "register")) + reg++; + else if (argis("f", "file")) + { + if (arg - argv < argc - 1) + { + ++arg; + filename = *arg; + } + else + usage(argv); + } + else if (argis("v", "verbose")) + verbose++; + else if (argis("d", "nodupcheck")) + nodupcheck++; + else if (argis("S", "server") || argis("db", "database")) + { + if (arg - argv < argc - 1) + { + ++arg; + server = *arg; + } + else usage(argv); - } else - usage(argv); + } + else + usage(argv); + } + else + usage(argv); } - if (!strcmp(filename, "-")) - input = stdin; - else { - input = fopen(filename, "r"); - if (input == NULL) { - com_err(whoami, errno, "opening input file %s", filename); - exit(2); + if (!strcmp(filename, "-")) + input = stdin; + else + { + input = fopen(filename, "r"); + if (!input) + { + com_err(whoami, errno, "opening input file %s", filename); + exit(2); } } - if (!reg_only) { - /* fire up Moira */ - if (status = mr_connect(server)) { - com_err(whoami, status, "unable to connect to the Moira server"); - exit(2); + if (!reg_only) + { + /* fire up Moira */ + if ((status = mr_connect(server))) + { + com_err(whoami, status, "unable to connect to the Moira server"); + exit(2); } - if ( status = mr_motd(&motd) ) { - com_err(whoami, status, "unable to check server status"); - exit(2); + if ((status = mr_motd(&motd))) + { + com_err(whoami, status, "unable to check server status"); + exit(2); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(2); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(2); } - if (status = mr_auth("addusr")) { - if (status == MR_USER_AUTH) - com_err(whoami, status, ""); - else { - com_err(whoami, status, "unable to authenticate to Moira"); - exit(2); + if ((status = mr_auth("addusr"))) + { + if (status == MR_USER_AUTH) + com_err(whoami, status, ""); + else + { + com_err(whoami, status, "unable to authenticate to Moira"); + exit(2); } } } - if (reg || reg_only) - ureg_init(); + if (reg || reg_only) + ureg_init(); - qargv[U_NAME] = UNIQUE_LOGIN; - qargv[U_UID] = UNIQUE_UID; - qargv[U_SHELL] = shell; - qargv[U_STATE] = status_str; - qargv[U_CLASS] = class; - qargv[U_COMMENT] = comment; - qargv[U_SIGNATURE] = ""; - qargv[U_SECURE] = "0"; - while (fgets(buf, BUFSIZ, input)) { - /* throw away terminating newline */ - p = &buf[strlen(buf) - 1]; - if (*p == '\n') - *p = 0; - lineno++; - if (strlen(buf) == 0) + qargv[U_NAME] = UNIQUE_LOGIN; + qargv[U_UID] = UNIQUE_UID; + qargv[U_SHELL] = shell; + qargv[U_STATE] = status_str; + qargv[U_CLASS] = class; + qargv[U_COMMENT] = comment; + qargv[U_SIGNATURE] = ""; + qargv[U_SECURE] = "0"; + while (fgets(buf, BUFSIZ, input)) + { + /* throw away terminating newline */ + p = &buf[strlen(buf) - 1]; + if (*p == '\n') + *p = '\0'; + lineno++; + if (strlen(buf) == 0) + continue; + /* Last name is first thing on line */ + last = buf; + /* First name follows a comma */ + p = strchr(last, ','); + if (!p) + { + com_err(whoami, MR_BAD_CHAR, "Missing comma on line %d", lineno); + errors++; continue; - /* Last name is first thing on line */ - last = buf; - /* First name follows a comma */ - p = strchr(last, ','); - if (!p) { - com_err(whoami, MR_BAD_CHAR, "Missing comma on line %d", lineno); - errors++; - continue; } - *p++ = 0; - first = p; - while (*p) p++; /* find end-of-line */ - if (reg_only || reg) { - while (!isspace(*p)) p--; - if (p <= first) { - com_err(whoami, 0, "Missing password on line %d", lineno); - errors++; - continue; - } - passwd = strtrim(&p[1]); - *p-- = 0; - /* previous field is login name */ - while (isspace(*p)) p--; - while (!isspace(*p)) p--; - if (p <= first) { - com_err(whoami, 0, "Missing login on line %d", lineno); - errors++; - continue; + *p++ = '\0'; + first = p; + while (*p) /* find end-of-line */ + p++; + if (reg_only || reg) + { + while (!isspace(*p)) + p--; + if (p <= first) + { + com_err(whoami, 0, "Missing password on line %d", lineno); + errors++; + continue; } - login = strtrim(&p[1]); - *p-- = 0; - } else { - /* ID is last thing on line */ + passwd = strtrim(&p[1]); + *p-- = '\0'; + /* previous field is login name */ + while (isspace(*p)) + p--; + while (!isspace(*p)) p--; + if (p <= first) + { + com_err(whoami, 0, "Missing login on line %d", lineno); + errors++; + continue; + } + login = strtrim(&p[1]); + *p-- = '\0'; } - while (isspace(*p)) p--; - while (!isspace(*p)) p--; - if (p <= first) { - com_err(whoami, 0, "Missing ID on line %d", lineno); - errors++; - continue; + else + { + /* ID is last thing on line */ + p--; } - id = &p[1]; - *p-- = 0; - /* If something between first name & ID, it's middle name */ - while (isspace(*p)) p--; - while (!isspace(*p)) p--; - if (p <= first) - middle = ""; - else { - middle = &p[1]; - *p = 0; + while (isspace(*p)) + p--; + while (!isspace(*p)) + p--; + if (p <= first) + { + com_err(whoami, 0, "Missing ID on line %d", lineno); + errors++; + continue; } - qargv[U_FIRST] = strtrim(first); - qargv[U_MIDDLE] = strtrim(middle); - qargv[U_LAST] = strtrim(last); - qargv[U_MITID] = strtrim(id); - FixCase(qargv[U_FIRST]); - FixCase(qargv[U_MIDDLE]); - FixCase(qargv[U_LAST]); - RemoveHyphens(qargv[U_MITID]); - if (!reg_only) { - if (!nodupcheck) { - char *dargv[2]; + id = &p[1]; + *p-- = '\0'; + /* If something between first name & ID, it's middle name */ + while (isspace(*p)) + p--; + while (!isspace(*p)) + p--; + if (p <= first) + middle = ""; + else + { + middle = &p[1]; + *p = '\0'; + } + qargv[U_FIRST] = strtrim(first); + qargv[U_MIDDLE] = strtrim(middle); + qargv[U_LAST] = strtrim(last); + qargv[U_MITID] = strtrim(id); + FixCase(qargv[U_FIRST]); + FixCase(qargv[U_MIDDLE]); + FixCase(qargv[U_LAST]); + RemoveHyphens(qargv[U_MITID]); + if (!reg_only) + { + if (!nodupcheck) + { + char *dargv[2]; - dargv[0] = qargv[U_FIRST]; - dargv[1] = qargv[U_LAST]; - duplicate = 0; - status = mr_query("get_user_account_by_name", 2, dargv, - usercheck, (char *) qargv); - if (status && status != MR_NO_MATCH) { - com_err(whoami, status, - "checking to see if user %s %s already exists", - qargv[0], qargv[1]); - com_err(whoami, 0, "NOT ADDING USER"); - errors++; - continue; + dargv[0] = qargv[U_FIRST]; + dargv[1] = qargv[U_LAST]; + duplicate = 0; + status = mr_query("get_user_account_by_name", 2, dargv, + usercheck, (char *) qargv); + if (status && status != MR_NO_MATCH) + { + com_err(whoami, status, + "checking to see if user %s %s already exists", + qargv[0], qargv[1]); + com_err(whoami, 0, "NOT ADDING USER"); + errors++; + continue; + } + if (duplicate > 0) + { + com_err(whoami, MR_EXISTS, "user %s %s already exists", + qargv[0], qargv[1]); + com_err(whoami, 0, "NOT ADDING USER"); + errors++; + continue; } - if (duplicate > 0) { - com_err(whoami, MR_EXISTS, "user %s %s already exists", - qargv[0], qargv[1]); - com_err(whoami, 0, "NOT ADDING USER"); - errors++; - continue; - } else if (duplicate < 0) { - com_err(whoami, MR_EXISTS, - "user %s %s already exists with different ID number", - qargv[U_FIRST], qargv[U_LAST]); - com_err(whoami, 0, "ADDING user anyway"); + else if (duplicate < 0) + { + com_err(whoami, MR_EXISTS, + "user %s %s already exists with different ID number", + qargv[U_FIRST], qargv[U_LAST]); + com_err(whoami, 0, "ADDING user anyway"); } } - status = mr_query("add_user_account", U_SECURE + 1, qargv, - scream, NULL); - if (status) { - com_err(whoami, status, "adding user %s %s", first, last); - errors++; - } else if (verbose) + status = mr_query("add_user_account", U_SECURE + 1, qargv, + scream, NULL); + if (status) + { + com_err(whoami, status, "adding user %s %s", first, last); + errors++; + } + else if (verbose) + { printf("Added user %s %s %s (%s)\n", qargv[U_FIRST], qargv[U_MIDDLE], qargv[U_LAST], qargv[U_MITID]); + } } - if (reg || reg_only) { - EncryptID(idbuf, qargv[U_MITID], qargv[U_FIRST], qargv[U_LAST]); - status = grab_login(qargv[U_FIRST], qargv[U_LAST], - qargv[U_MITID], idbuf, login); - if (status) { - com_err(whoami, status, "while registering (login) %s %s", - qargv[U_FIRST], qargv[U_LAST]); - errors++; - continue; - } else if (verbose) + if (reg || reg_only) + { + EncryptID(idbuf, qargv[U_MITID], qargv[U_FIRST], qargv[U_LAST]); + status = grab_login(qargv[U_FIRST], qargv[U_LAST], + qargv[U_MITID], idbuf, login); + if (status) + { + com_err(whoami, status, "while registering (login) %s %s", + qargv[U_FIRST], qargv[U_LAST]); + errors++; + continue; + } + else if (verbose) + { printf("Registered user %s %s as %s\n", qargv[U_FIRST], qargv[U_LAST], login); - status = set_password(qargv[U_FIRST], qargv[U_LAST], - qargv[U_MITID], idbuf, passwd); - if (status) { - com_err(whoami, status, "While registering (passwd) %s %s", - qargv[U_FIRST], qargv[U_LAST]); - errors++; - continue; + } + status = set_password(qargv[U_FIRST], qargv[U_LAST], + qargv[U_MITID], idbuf, passwd); + if (status) + { + com_err(whoami, status, "While registering (passwd) %s %s", + qargv[U_FIRST], qargv[U_LAST]); + errors++; + continue; } else if (verbose) printf("Set password for user %s\n", login); } } - exit(errors); + exit(errors); } -usage(argv) -char **argv; +usage(char **argv) { - fprintf(stderr, "Usage: %s [options]\n",argv[0]); - fprintf(stderr, "Options are\n"); - fprintf(stderr, " -f | -file filename (default STDIN)\n"); - fprintf(stderr, " -c | -class class (default TEMP)\n"); - fprintf(stderr, " -C | -comment \"comment\" (default \"\")\n"); - fprintf(stderr, " -s | -status status (default 0)\n"); - fprintf(stderr, " -h | -shell shell (default %s)\n", DEFAULT_SHELL); - fprintf(stderr, " -r | -reg_only\n"); - fprintf(stderr, " -R | -register (and add to database)\n"); - fprintf(stderr, " -v | -verbose\n"); - fprintf(stderr, " -d | -nodupcheck (don't check for duplicates)\n"); - fprintf(stderr, " -db | -database host:port\n"); - exit(1); + fprintf(stderr, "Usage: %s [options]\n", argv[0]); + fprintf(stderr, "Options are\n"); + fprintf(stderr, " -f | -file filename (default STDIN)\n"); + fprintf(stderr, " -c | -class class (default TEMP)\n"); + fprintf(stderr, " -C | -comment \"comment\" (default \"\")\n"); + fprintf(stderr, " -s | -status status (default 0)\n"); + fprintf(stderr, " -h | -shell shell (default %s)\n", DEFAULT_SHELL); + fprintf(stderr, " -r | -reg_only\n"); + fprintf(stderr, " -R | -register (and add to database)\n"); + fprintf(stderr, " -v | -verbose\n"); + fprintf(stderr, " -d | -nodupcheck (don't check for duplicates)\n"); + fprintf(stderr, " -db | -database host:port\n"); + exit(1); } /* Called only if a query returns a value that we weren't expecting */ -scream() +scream(void) { - fprintf(stderr, "Programmer botch\n"); - exit(3); + fprintf(stderr, "Programmer botch\n"); + exit(3); } /* query callback routine to check for duplicate users */ -usercheck(argc, argv, qargv) -int argc; -char **argv; -char **qargv; +usercheck(int argc, char **argv, char **qargv) { - if (!strcmp(argv[U_MITID], qargv[U_MITID])) - duplicate++; - else - duplicate--; + if (!strcmp(argv[U_MITID], qargv[U_MITID])) + duplicate++; + else + duplicate--; } diff --git a/clients/blanche/blanche.c b/clients/blanche/blanche.c index 0d0a6906..b2428450 100644 --- a/clients/blanche/blanche.c +++ b/clients/blanche/blanche.c @@ -29,8 +29,8 @@ static char blanche_rcsid[] = "$Header$"; struct member { - int type; - char *name; + int type; + char *name; }; /* It is important to membercmp that M_USER < M_LIST < M_STRING */ @@ -41,7 +41,7 @@ struct member { #define M_KERBEROS 4 /* argument parsing macro */ -#define argis(a,b) ((strcmp(*arg+1, a) == 0) || (strcmp(*arg+1, b) == 0)) +#define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b)) /* flags from command line */ int infoflg, verbose, syncflg, memberflg, recursflg, noauth; @@ -55,446 +55,546 @@ struct save_queue *addlist, *dellist, *memberlist, *synclist; char *listname, *whoami; -#ifndef POSIX -extern int errno; -#endif - int show_list_info(), show_list_count(), get_list_members(), scream(); int show_list_members(), membercmp(), save_list_info(); struct member *parse_member(); - - -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - int status, success; - char **arg = argv; - char *membervec[3], *motd; - struct member *memberstruct; - char *server = NULL, *p; - - /* clear all flags & lists */ - infoflg = verbose = syncflg = memberflg = recursflg = 0; - noauth = showusers = showstrings = showkerberos = showlists = 0; - createflag = setinfo = 0; - active = public = hidden = maillist = grouplist = -1; - listname = newname = desc = NULL; - owner = NULL; - addlist = sq_create(); - dellist = sq_create(); - memberlist = sq_create(); - synclist = sq_create(); - whoami = argv[0]; - - success = 1; - - /* parse args, building addlist, dellist, & synclist */ - while (++arg - argv < argc) { - if (**arg == '-') + int status, success; + char **arg = argv; + char *membervec[3], *motd; + struct member *memberstruct; + char *server = NULL, *p; + + /* clear all flags & lists */ + infoflg = verbose = syncflg = memberflg = recursflg = 0; + noauth = showusers = showstrings = showkerberos = showlists = 0; + createflag = setinfo = 0; + active = public = hidden = maillist = grouplist = -1; + listname = newname = desc = NULL; + owner = NULL; + addlist = sq_create(); + dellist = sq_create(); + memberlist = sq_create(); + synclist = sq_create(); + whoami = argv[0]; + + success = 1; + + /* parse args, building addlist, dellist, & synclist */ + while (++arg - argv < argc) + { + if (**arg == '-') { - if (argis("m", "members")) - memberflg++; - else if (argis("u", "users")) - showusers++; - else if (argis("s", "strings")) - showstrings++; - else if (argis("l", "lists")) - showlists++; - else if (argis("k", "kerberos")) - showkerberos++; - else if (argis("i","info")) - infoflg++; - else if (argis("n","noauth")) - noauth++; - else if (argis("v","verbose")) - verbose++; - else if (argis("r","recursive")) - recursflg++; - else if (argis("S","server") || argis("db","database")) - if (arg - argv < argc - 1) { - ++arg; - server = *arg; - } else - usage(argv); - else if (argis("a","add")) - if (arg - argv < argc - 1) { - ++arg; - if (memberstruct = parse_member(*arg)) - sq_save_data(addlist, memberstruct); - } else - usage(argv); - else if (argis("al","addlist")) - if (arg - argv < argc - 1) { - ++arg; - get_members_from_file(*arg, addlist); - } else - usage(argv); - else if (argis("d","delete")) - if (arg - argv < argc - 1) { - ++arg; - if (memberstruct = parse_member(*arg)) - sq_save_data(dellist, memberstruct); - } else - usage(argv); - else if (argis("dl","deletelist")) - if (arg - argv < argc - 1) { - ++arg; - get_members_from_file(*arg, dellist); - } else - usage(argv); - else if (argis("f","file")) - if (arg - argv < argc - 1) { - syncflg++; - ++arg; - get_members_from_file(*arg, synclist); - } else - usage(argv); - else if (argis("C", "create")) - createflag++; - else if (argis("P", "public")) { - setinfo++; - public = 1; - } else if (argis("NP", "private")) { - setinfo++; - public = 0; - } else if (argis("A", "active")) { - setinfo++; - active = 1; - } else if (argis("I", "inactive")) { - setinfo++; - active = 0; - } else if (argis("V", "visible")) { - setinfo++; - hidden = 0; - } else if (argis("H", "hidden")) { - setinfo++; - hidden = 1; - } else if (argis("M", "mail")) { - setinfo++; - maillist = 1; - } else if (argis("NM", "notmail")) { - setinfo++; - maillist = 0; - } else if (argis("G", "group")) { - setinfo++; - grouplist = 1; - } else if (argis("NG", "notgroup")) { - setinfo++; - grouplist = 0; - } else if (argis("D", "desc")) - if (arg - argv < argc - 1) { - setinfo++; - ++arg; - desc = *arg; - } else - usage(argv); - else if (argis("O", "owner")) - if (arg - argv < argc - 1) { - setinfo++; - ++arg; - owner = parse_member(*arg); - } else - usage(argv); - else if (argis("R", "rename")) - if (arg - argv < argc - 1) { - setinfo++; - ++arg; - newname = *arg; - } else - usage(argv); - - else + if (argis("m", "members")) + memberflg++; + else if (argis("u", "users")) + showusers++; + else if (argis("s", "strings")) + showstrings++; + else if (argis("l", "lists")) + showlists++; + else if (argis("k", "kerberos")) + showkerberos++; + else if (argis("i", "info")) + infoflg++; + else if (argis("n", "noauth")) + noauth++; + else if (argis("v", "verbose")) + verbose++; + else if (argis("r", "recursive")) + recursflg++; + else if (argis("S", "server") || argis("db", "database")) + { + if (arg - argv < argc - 1) + { + ++arg; + server = *arg; + } + else + usage(argv); + } + else if (argis("a", "add")) + { + if (arg - argv < argc - 1) + { + ++arg; + if ((memberstruct = parse_member(*arg))) + sq_save_data(addlist, memberstruct); + } + else + usage(argv); + } + else if (argis("al", "addlist")) + { + if (arg - argv < argc - 1) + { + ++arg; + get_members_from_file(*arg, addlist); + } + else + usage(argv); + } + else if (argis("d", "delete")) + { + if (arg - argv < argc - 1) + { + ++arg; + if ((memberstruct = parse_member(*arg))) + sq_save_data(dellist, memberstruct); + } + else + usage(argv); + } + else if (argis("dl", "deletelist")) + { + if (arg - argv < argc - 1) + { + ++arg; + get_members_from_file(*arg, dellist); + } + else + usage(argv); + } + else if (argis("f", "file")) + { + if (arg - argv < argc - 1) + { + syncflg++; + ++arg; + get_members_from_file(*arg, synclist); + } + else + usage(argv); + } + else if (argis("C", "create")) + createflag++; + else if (argis("P", "public")) + { + setinfo++; + public = 1; + } + else if (argis("NP", "private")) + { + setinfo++; + public = 0; + } + else if (argis("A", "active")) + { + setinfo++; + active = 1; + } + else if (argis("I", "inactive")) + { + setinfo++; + active = 0; + } + else if (argis("V", "visible")) + { + setinfo++; + hidden = 0; + } + else if (argis("H", "hidden")) + { + setinfo++; + hidden = 1; + } + else if (argis("M", "mail")) + { + setinfo++; + maillist = 1; + } + else if (argis("NM", "notmail")) + { + setinfo++; + maillist = 0; + } + else if (argis("G", "group")) + { + setinfo++; + grouplist = 1; + } + else if (argis("NG", "notgroup")) + { + setinfo++; + grouplist = 0; + } + else if (argis("D", "desc")) + { + if (arg - argv < argc - 1) + { + setinfo++; + ++arg; + desc = *arg; + } + else + usage(argv); + } + else if (argis("O", "owner")) + { + if (arg - argv < argc - 1) + { + setinfo++; + ++arg; + owner = parse_member(*arg); + } + else + usage(argv); + } + else if (argis("R", "rename")) + { + if (arg - argv < argc - 1) + { + setinfo++; + ++arg; + newname = *arg; + } + else usage(argv); + } + else + usage(argv); } - else if (listname == NULL) - listname = *arg; - else - usage(argv); + else if (listname == NULL) + listname = *arg; + else + usage(argv); } - if (listname == NULL) - usage(argv); - - /* if no other options specified, turn on list members flag */ - if (!(infoflg || syncflg || createflag || setinfo || - addlist->q_next != addlist || dellist->q_next != dellist)) - memberflg++; - - /* If none of {users,strings,lists,kerberos} specified, turn them all on */ - if (!(showusers || showstrings || showlists || showkerberos)) - showusers = showstrings = showlists = showkerberos = 1; - - /* fire up Moira */ - if (status = mr_connect(server)) { - com_err(whoami, status, "unable to connect to the Moira server"); - exit(2); + if (listname == NULL) + usage(argv); + + /* if no other options specified, turn on list members flag */ + if (!(infoflg || syncflg || createflag || setinfo || + addlist->q_next != addlist || dellist->q_next != dellist)) + memberflg++; + + /* If none of {users,strings,lists,kerberos} specified, turn them all on */ + if (!(showusers || showstrings || showlists || showkerberos)) + showusers = showstrings = showlists = showkerberos = 1; + + /* fire up Moira */ + if ((status = mr_connect(server))) + { + com_err(whoami, status, "unable to connect to the Moira server"); + exit(2); } - if ( status = mr_motd(&motd) ) { - com_err(whoami, status, "unable to check server status"); - exit(2); + if ((status = mr_motd(&motd))) + { + com_err(whoami, status, "unable to check server status"); + exit(2); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(2); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(2); } - if (!noauth && (status = mr_auth("blanche"))) { - if (status == MR_USER_AUTH) - com_err(whoami, status, ""); - else { - com_err(whoami, status, "unable to authenticate to Moira"); - com_err(whoami, 0, - " Try the -noauth flag if you don't need authentication"); - exit(2); + if (!noauth && (status = mr_auth("blanche"))) + { + if (status == MR_USER_AUTH) + com_err(whoami, status, ""); + else + { + com_err(whoami, status, "unable to authenticate to Moira"); + com_err(whoami, 0, + " Try the -noauth flag if you don't need authentication"); + exit(2); } } - /* create if needed */ - if (createflag) { - char *argv[10]; - - argv[0] = listname; - argv[1] = (active == 0) ? "0" : "1"; - argv[2] = (public == 1) ? "1" : "0"; - argv[3] = (hidden == 1) ? "1" : "0"; - argv[4] = (maillist == 0) ? "0" : "1"; - argv[5] = (grouplist == 1) ? "1" : "0"; - argv[6] = UNIQUE_GID; - argv[9] = desc ? desc : "none"; - - if (owner) { - argv[8] = owner->name; - switch (owner->type) { - case M_ANY: - case M_USER: - argv[7] = "USER"; - status = mr_query("add_list", 10, argv, scream, NULL); - if (owner->type != M_ANY || status != MR_USER) - break; - - case M_LIST: - argv[7] = "LIST"; - status = mr_query("add_list", 10, argv, scream, NULL); - break; - - case M_KERBEROS: - argv[7] = "KERBEROS"; - status = mr_query("add_list", 10, argv, scream, NULL); - break; - } - } else { - argv[7] = "USER"; - argv[8] = getenv("USER"); - - status = mr_query("add_list", 10, argv, scream, NULL); - } - - if (status) { - com_err(whoami, status, "while creating list."); - exit(1); + /* create if needed */ + if (createflag) + { + char *argv[10]; + + argv[0] = listname; + argv[1] = (active == 0) ? "0" : "1"; + argv[2] = (public == 1) ? "1" : "0"; + argv[3] = (hidden == 1) ? "1" : "0"; + argv[4] = (maillist == 0) ? "0" : "1"; + argv[5] = (grouplist == 1) ? "1" : "0"; + argv[6] = UNIQUE_GID; + argv[9] = desc ? desc : "none"; + + if (owner) + { + argv[8] = owner->name; + switch (owner->type) + { + case M_ANY: + case M_USER: + argv[7] = "USER"; + status = mr_query("add_list", 10, argv, scream, NULL); + if (owner->type != M_ANY || status != MR_USER) + break; + + case M_LIST: + argv[7] = "LIST"; + status = mr_query("add_list", 10, argv, scream, NULL); + break; + + case M_KERBEROS: + argv[7] = "KERBEROS"; + status = mr_query("add_list", 10, argv, scream, NULL); + break; + } } - } else if (setinfo) { - char *argv[11]; - - status = mr_query("get_list_info", 1, &listname, - save_list_info, (char *)argv); - if (status) { - com_err(whoami, status, "while getting list information"); - exit(1); + else + { + argv[7] = "USER"; + argv[8] = getenv("USER"); + + status = mr_query("add_list", 10, argv, scream, NULL); } - argv[0] = listname; - if (newname) argv[1] = newname; - if (active != -1) argv[2] = active ? "1" : "0"; - if (public != -1) argv[3] = public ? "1" : "0"; - if (hidden != -1) argv[4] = hidden ? "1" : "0"; - if (maillist != -1) argv[5] = maillist ? "1" : "0"; - if (grouplist != -1) argv[6] = grouplist ? "1" : "0"; - if (desc) argv[10] = desc; - - if (owner) { - argv[9] = owner->name; - switch (owner->type) { - case M_ANY: - case M_USER: - argv[8] = "USER"; - status = mr_query("update_list", 11, argv, scream, NULL); - if (owner->type != M_ANY || status != MR_USER) - break; - - case M_LIST: - argv[8] = "LIST"; - status = mr_query("update_list", 11, argv, scream, NULL); - break; - - case M_KERBEROS: - argv[8] = "KERBEROS"; - status = mr_query("update_list", 11, argv, scream, NULL); - break; - } - } else status = mr_query("update_list", 11, argv, scream, NULL); - - if (status) - com_err(whoami, status, "while updating list."); - else if (newname) listname = newname; + if (status) + { + com_err(whoami, status, "while creating list."); + exit(1); + } } + else if (setinfo) + { + char *argv[11]; - /* display list info if requested to */ - if (infoflg) { - status = mr_query("get_list_info", 1, &listname, show_list_info,NULL); - if (status) + status = mr_query("get_list_info", 1, &listname, + save_list_info, (char *)argv); + if (status) + { com_err(whoami, status, "while getting list information"); - if (verbose && !memberflg) { - status = mr_query("count_members_of_list", 1, &listname, - show_list_count, NULL); - if (status) - com_err(whoami, status, "while getting list count"); + exit(1); } + + argv[0] = listname; + if (newname) + argv[1] = newname; + if (active != -1) + argv[2] = active ? "1" : "0"; + if (public != -1) + argv[3] = public ? "1" : "0"; + if (hidden != -1) + argv[4] = hidden ? "1" : "0"; + if (maillist != -1) + argv[5] = maillist ? "1" : "0"; + if (grouplist != -1) + argv[6] = grouplist ? "1" : "0"; + if (desc) + argv[10] = desc; + + if (owner) + { + argv[9] = owner->name; + switch (owner->type) + { + case M_ANY: + case M_USER: + argv[8] = "USER"; + status = mr_query("update_list", 11, argv, scream, NULL); + if (owner->type != M_ANY || status != MR_USER) + break; + + case M_LIST: + argv[8] = "LIST"; + status = mr_query("update_list", 11, argv, scream, NULL); + break; + + case M_KERBEROS: + argv[8] = "KERBEROS"; + status = mr_query("update_list", 11, argv, scream, NULL); + break; + } + } + else + status = mr_query("update_list", 11, argv, scream, NULL); + + if (status) + com_err(whoami, status, "while updating list."); + else if (newname) + listname = newname; } - /* if we're synchronizing to a file, we need to: - * get the current members of the list - * for each member of the sync file - * if they are on the list, remove them from the in-memory copy - * if they're not on the list, add them to add-list - * if anyone is left on the in-memory copy, put them on the delete-list - * lastly, reset memberlist so we can use it again later - */ - if (syncflg) { - status = mr_query("get_members_of_list", 1, &listname, - get_list_members, (char *)memberlist); - if (status) { - com_err(whoami, status, "getting members of list %s", listname); - exit (2); + /* display list info if requested to */ + if (infoflg) + { + status = mr_query("get_list_info", 1, &listname, show_list_info, NULL); + if (status) + com_err(whoami, status, "while getting list information"); + if (verbose && !memberflg) + { + status = mr_query("count_members_of_list", 1, &listname, + show_list_count, NULL); + if (status) + com_err(whoami, status, "while getting list count"); } - while (sq_get_data(synclist, &memberstruct)) { - struct save_queue *q; - int removed = 0; - - for (q = memberlist->q_next; q != memberlist; q = q->q_next) { - if (membercmp(q->q_data, memberstruct) == 0) { - q->q_prev->q_next = q->q_next; - q->q_next->q_prev = q->q_prev; - removed++; - break; + } + + /* if we're synchronizing to a file, we need to: + * get the current members of the list + * for each member of the sync file + * if they are on the list, remove them from the in-memory copy + * if they're not on the list, add them to add-list + * if anyone is left on the in-memory copy, put them on the delete-list + * lastly, reset memberlist so we can use it again later + */ + if (syncflg) + { + status = mr_query("get_members_of_list", 1, &listname, + get_list_members, (char *)memberlist); + if (status) + { + com_err(whoami, status, "getting members of list %s", listname); + exit(2); + } + while (sq_get_data(synclist, &memberstruct)) + { + struct save_queue *q; + int removed = 0; + + for (q = memberlist->q_next; q != memberlist; q = q->q_next) + { + if (membercmp(q->q_data, memberstruct) == 0) + { + q->q_prev->q_next = q->q_next; + q->q_next->q_prev = q->q_prev; + removed++; + break; } } - if (!removed) - sq_save_data(addlist, memberstruct); + if (!removed) + sq_save_data(addlist, memberstruct); } - while (sq_get_data(memberlist, &memberstruct)) - sq_save_data(dellist, memberstruct); - sq_destroy(memberlist); - memberlist = sq_create(); + while (sq_get_data(memberlist, &memberstruct)) + sq_save_data(dellist, memberstruct); + sq_destroy(memberlist); + memberlist = sq_create(); } - /* Process the add list */ - while (sq_get_data(addlist, &memberstruct)) { - /* canonicalize string if necessary */ - if (memberstruct->type == M_STRING && - (p = strchr(memberstruct->name, '@'))) { - char *host = canonicalize_hostname(strsave(++p)); - static char **mailhubs = NULL; - char *argv[4]; - int i, collect(); - - if (!mailhubs) { - argv[0] = "mailhub"; - argv[1] = "TYPE"; - argv[2] = "*"; - mailhubs = (char **)malloc(sizeof(char *)); - mailhubs[0] = NULL; - status = mr_query("get_alias", 3, argv, collect, - (char *)&mailhubs); - if (status != MR_SUCCESS && status != MR_NO_MATCH) { - com_err(whoami, status, - " while reading list of MAILHUB servers"); - mailhubs[0] = NULL; + /* Process the add list */ + while (sq_get_data(addlist, &memberstruct)) + { + /* canonicalize string if necessary */ + if (memberstruct->type == M_STRING && + (p = strchr(memberstruct->name, '@'))) + { + char *host = canonicalize_hostname(strsave(++p)); + static char **mailhubs = NULL; + char *argv[4]; + int i, collect(); + + if (!mailhubs) + { + argv[0] = "mailhub"; + argv[1] = "TYPE"; + argv[2] = "*"; + mailhubs = malloc(sizeof(char *)); + mailhubs[0] = NULL; + status = mr_query("get_alias", 3, argv, collect, + (char *)&mailhubs); + if (status != MR_SUCCESS && status != MR_NO_MATCH) + { + com_err(whoami, status, + " while reading list of MAILHUB servers"); + mailhubs[0] = NULL; } } - for (i = 0; p = mailhubs[i]; i++) { - if (!strcasecmp(p, host)) { - host = strsave(memberstruct->name); - *(strchr(memberstruct->name, '@')) = 0; - memberstruct->type = M_ANY; - fprintf(stderr, "Warning: \"STRING:%s\" converted to \"%s\" because it is a local name.\n", - host, memberstruct->name); - break; + for (i = 0; (p = mailhubs[i]); i++) + { + if (!strcasecmp(p, host)) + { + host = strsave(memberstruct->name); + *(strchr(memberstruct->name, '@')) = 0; + memberstruct->type = M_ANY; + fprintf(stderr, "Warning: \"STRING:%s\" converted to " + "\"%s\" because it is a local name.\n", + host, memberstruct->name); + break; } } - free(host); + free(host); } - /* now continue adding member */ - membervec[0] = listname; - membervec[2] = memberstruct->name; - if (verbose) { - printf("Adding member "); - show_list_member(memberstruct); + /* now continue adding member */ + membervec[0] = listname; + membervec[2] = memberstruct->name; + if (verbose) + { + printf("Adding member "); + show_list_member(memberstruct); } - switch (memberstruct->type) { + switch (memberstruct->type) + { case M_ANY: case M_USER: - membervec[1] = "USER"; - status = mr_query("add_member_to_list", 3, membervec, scream, NULL); - if (status == MR_SUCCESS) + membervec[1] = "USER"; + status = mr_query("add_member_to_list", 3, membervec, scream, NULL); + if (status == MR_SUCCESS) + break; + else if (status != MR_USER || memberstruct->type != M_ANY) + { + com_err(whoami, status, "while adding member %s to %s", + memberstruct->name, listname); + success = 0; break; - else if (status != MR_USER || memberstruct->type != M_ANY) { - com_err(whoami, status, "while adding member %s to %s", - memberstruct->name, listname); - success = 0; - break; } case M_LIST: - membervec[1] = "LIST"; - status = mr_query("add_member_to_list", 3, membervec, - scream, NULL); - if (status == MR_SUCCESS) { - if (!strcmp(membervec[0], getenv("USER"))) { - fprintf(stderr, "\nWARNING: \"LIST:%s\" was just added to list \"%s\".\n", - membervec[2], membervec[0]); - fprintf(stderr, "If you meant to add yourself to the list \"%s\", type:\n", membervec[2]); - fprintf(stderr, "\tblanche %s -d %s\t(to undo this)\n", - membervec[0], membervec[2]); - fprintf(stderr, "\tblanche %s -a %s\t(to add yourself to that list)\n", - membervec[2], membervec[0]); + membervec[1] = "LIST"; + status = mr_query("add_member_to_list", 3, membervec, + scream, NULL); + if (status == MR_SUCCESS) + { + if (!strcmp(membervec[0], getenv("USER"))) + { + fprintf(stderr, "\nWARNING: \"LIST:%s\" was just added " + "to list \"%s\".\n", membervec[2], membervec[0]); + fprintf(stderr, "If you meant to add yourself to the list " + "\"%s\", type:\n", membervec[2]); + fprintf(stderr, "\tblanche %s -d %s\t(to undo this)\n", + membervec[0], membervec[2]); + fprintf(stderr, "\tblanche %s -a %s\t(to add yourself to " + "that list)\n", membervec[2], membervec[0]); } - break; - } else if (status != MR_LIST || memberstruct->type != M_ANY) { - com_err(whoami, status, "while adding member %s to %s", - memberstruct->name, listname); - success = 0; - break; + break; + } + else if (status != MR_LIST || memberstruct->type != M_ANY) + { + com_err(whoami, status, "while adding member %s to %s", + memberstruct->name, listname); + success = 0; + break; } case M_STRING: - if (memberstruct->type == M_ANY && - !strchr(memberstruct->name, '@') && - !strchr(memberstruct->name, '!') && - !strchr(memberstruct->name, '%')) { - /* if user is trying to add something which isn't a - remote string, or a list, or a user, and didn't - explicitly specify `STRING:', it's probably a typo */ - com_err(whoami, MR_NO_MATCH, "while adding member %s to %s", - memberstruct->name, listname); - success = 0; - break; + if (memberstruct->type == M_ANY && + !strchr(memberstruct->name, '@') && + !strchr(memberstruct->name, '!') && + !strchr(memberstruct->name, '%')) + { + /* if user is trying to add something which isn't a + remote string, or a list, or a user, and didn't + explicitly specify `STRING:', it's probably a typo */ + com_err(whoami, MR_NO_MATCH, "while adding member %s to %s", + memberstruct->name, listname); + success = 0; + break; } - - membervec[1] = "STRING"; - status = mr_query("add_member_to_list", 3, membervec, - scream, NULL); - if (status != MR_SUCCESS) { + + membervec[1] = "STRING"; + status = mr_query("add_member_to_list", 3, membervec, + scream, NULL); + if (status != MR_SUCCESS) + { com_err(whoami, status, "while adding member %s to %s", memberstruct->name, listname); success = 0; } - break; + break; case M_KERBEROS: - membervec[1] = "KERBEROS"; - status = mr_query("add_member_to_list", 3, membervec, - scream, NULL); - if (status != MR_SUCCESS) { + membervec[1] = "KERBEROS"; + status = mr_query("add_member_to_list", 3, membervec, + scream, NULL); + if (status != MR_SUCCESS) + { com_err(whoami, status, "while adding member %s to %s", memberstruct->name, listname); success = 0; @@ -502,81 +602,93 @@ char **argv; } } - /* Process the delete list */ - while (sq_get_data(dellist, &memberstruct)) { - membervec[0] = listname; - membervec[2] = memberstruct->name; - if (verbose) { - printf("Deleting member "); - show_list_member(memberstruct); + /* Process the delete list */ + while (sq_get_data(dellist, &memberstruct)) + { + membervec[0] = listname; + membervec[2] = memberstruct->name; + if (verbose) + { + printf("Deleting member "); + show_list_member(memberstruct); } - switch (memberstruct->type) { + switch (memberstruct->type) + { case M_ANY: case M_USER: - membervec[1] = "USER"; - status = mr_query("delete_member_from_list", 3, membervec, - scream, NULL); - if (status == MR_SUCCESS) + membervec[1] = "USER"; + status = mr_query("delete_member_from_list", 3, membervec, + scream, NULL); + if (status == MR_SUCCESS) + break; + else if ((status != MR_USER && status != MR_NO_MATCH) || + memberstruct->type != M_ANY) + { + com_err(whoami, status, "while deleting member %s from %s", + memberstruct->name, listname); + success = 0; break; - else if ((status != MR_USER && status != MR_NO_MATCH) || - memberstruct->type != M_ANY) { - com_err(whoami, status, "while deleting member %s from %s", - memberstruct->name, listname); - success = 0; - break; } case M_LIST: - membervec[1] = "LIST"; - status = mr_query("delete_member_from_list", 3, membervec, - scream, NULL); - if (status == MR_SUCCESS) - break; - else if ((status != MR_LIST && status != MR_NO_MATCH) || - memberstruct->type != M_ANY) { - if (status == MR_PERM && memberstruct->type == M_ANY && - !strcmp(membervec[2], getenv("USER"))) { - /* M_ANY means we've fallen through from the user - * case. The user is trying to remove himself from - * a list, but we got MR_USER or MR_NO_MATCH above, - * meaning he's not really on it, and we got MR_PERM - * when trying to remove LIST:$USER because he's not - * on the acl. That error is useless, so return - * MR_NO_MATCH instead. However, this will generate the - * wrong error if the user was trying to remove the list - * with his username from a list he doesn't administrate - * without explicitly specifying "list:". - */ + membervec[1] = "LIST"; + status = mr_query("delete_member_from_list", 3, membervec, + scream, NULL); + if (status == MR_SUCCESS) + break; + else if ((status != MR_LIST && status != MR_NO_MATCH) || + memberstruct->type != M_ANY) + { + if (status == MR_PERM && memberstruct->type == M_ANY && + !strcmp(membervec[2], getenv("USER"))) + { + /* M_ANY means we've fallen through from the user + * case. The user is trying to remove himself from + * a list, but we got MR_USER or MR_NO_MATCH above, + * meaning he's not really on it, and we got MR_PERM + * when trying to remove LIST:$USER because he's not + * on the acl. That error is useless, so return + * MR_NO_MATCH instead. However, this will generate the + * wrong error if the user was trying to remove the list + * with his username from a list he doesn't administrate + * without explicitly specifying "list:". + */ status = MR_NO_MATCH; } - com_err(whoami, status, "while deleting member %s from %s", - memberstruct->name, listname); - success = 0; - break; + com_err(whoami, status, "while deleting member %s from %s", + memberstruct->name, listname); + success = 0; + break; } case M_STRING: - membervec[1] = "STRING"; - status = mr_query("delete_member_from_list", 3, membervec, - scream, NULL); - if (status == MR_STRING && memberstruct->type == M_ANY) { + membervec[1] = "STRING"; + status = mr_query("delete_member_from_list", 3, membervec, + scream, NULL); + if (status == MR_STRING && memberstruct->type == M_ANY) + { com_err(whoami, 0, " Unable to find member %s to delete from %s", memberstruct->name, listname); success = 0; - if (!strcmp(membervec[0], getenv("USER"))) { - fprintf(stderr, "(If you were trying to remove yourself from the list \"%s\",\n", membervec[2]); - fprintf(stderr, "the correct command is \"blanche %s -d %s\".)\n", - membervec[2], membervec[0]); - } - } else if (status != MR_SUCCESS) { + if (!strcmp(membervec[0], getenv("USER"))) + { + fprintf(stderr, "(If you were trying to remove yourself " + "from the list \"%s\",\n", membervec[2]); + fprintf(stderr, "the correct command is \"blanche %s -d " + "%s\".)\n", membervec[2], membervec[0]); + } + } + else if (status != MR_SUCCESS) + { com_err(whoami, status, "while deleting member %s from %s", memberstruct->name, listname); success = 0; } - break; + break; case M_KERBEROS: - membervec[1] = "KERBEROS"; - status = mr_query("delete_member_from_list", 3, membervec, - scream, NULL); - if (status != MR_SUCCESS) { + membervec[1] = "KERBEROS"; + status = mr_query("delete_member_from_list", 3, membervec, + scream, NULL); + if (status != MR_SUCCESS) + { com_err(whoami, status, "while deleting member %s from %s", memberstruct->name, listname); success = 0; @@ -584,284 +696,278 @@ char **argv; } } - /* Display the members of the list now, if requested */ - if (memberflg) { - if (recursflg) - recursive_display_list_members(); - else { - status = mr_query("get_members_of_list", 1, &listname, - get_list_members, (char *)memberlist); - if (status) - com_err(whoami, status, "while getting members of list %s", - listname); - while (sq_get_data(memberlist, &memberstruct)) - show_list_member(memberstruct); + /* Display the members of the list now, if requested */ + if (memberflg) + { + if (recursflg) + recursive_display_list_members(); + else + { + status = mr_query("get_members_of_list", 1, &listname, + get_list_members, (char *)memberlist); + if (status) + com_err(whoami, status, "while getting members of list %s", + listname); + while (sq_get_data(memberlist, &memberstruct)) + show_list_member(memberstruct); } } - /* We're done! */ - mr_disconnect(); - exit(success?0:1); + /* We're done! */ + mr_disconnect(); + exit(success ? 0 : 1); } -usage(argv) -char **argv; +usage(char **argv) { - fprintf(stderr, "Usage: %s listname [options]\n",argv[0]); - fprintf(stderr, "Options are\n"); - fprintf(stderr, " %-39s%-39s\n", "-v | -verbose", - "-C | -create"); - fprintf(stderr, " %-39s%-39s\n", "-m | -members", - "-R | -rename newname"); - fprintf(stderr, " %-39s%-39s\n", "-u | -users", - "-P | -public"); - fprintf(stderr, " %-39s%-39s\n", "-l | -lists", - "-NP | -private"); - fprintf(stderr, " %-39s%-39s\n", "-s | -strings", - "-A | -active"); - fprintf(stderr, " %-39s%-39s\n", "-k | -kerberos", - "-I | -inactive"); - fprintf(stderr, " %-39s%-39s\n", "-i | -info", - "-V | -visible"); - fprintf(stderr, " %-39s%-39s\n", "-r | -recursive", - "-H | -hidden"); - fprintf(stderr, " %-39s%-39s\n", "-a | -add member", - "-M | -mail"); - fprintf(stderr, " %-39s%-39s\n", "-d | -delete member", - "-NM | -notmail"); - fprintf(stderr, " %-39s%-39s\n", "-al | -addlist filename", - "-G | -group"); - fprintf(stderr, " %-39s%-39s\n", "-dl | -deletelist filename", - "-NG | -notgroup"); - fprintf(stderr, " %-39s%-39s\n", "-f | -file filename", - "-D | -desc description"); - fprintf(stderr, " %-39s%-39s\n", "-n | -noauth", - "-O | -owner owner"); - fprintf(stderr, " %-39s%-39s\n", "-db | -database host[:port]", - ""); - exit(1); + fprintf(stderr, "Usage: %s listname [options]\n", argv[0]); + fprintf(stderr, "Options are\n"); + fprintf(stderr, " %-39s%-39s\n", "-v | -verbose", + "-C | -create"); + fprintf(stderr, " %-39s%-39s\n", "-m | -members", + "-R | -rename newname"); + fprintf(stderr, " %-39s%-39s\n", "-u | -users", + "-P | -public"); + fprintf(stderr, " %-39s%-39s\n", "-l | -lists", + "-NP | -private"); + fprintf(stderr, " %-39s%-39s\n", "-s | -strings", + "-A | -active"); + fprintf(stderr, " %-39s%-39s\n", "-k | -kerberos", + "-I | -inactive"); + fprintf(stderr, " %-39s%-39s\n", "-i | -info", + "-V | -visible"); + fprintf(stderr, " %-39s%-39s\n", "-r | -recursive", + "-H | -hidden"); + fprintf(stderr, " %-39s%-39s\n", "-a | -add member", + "-M | -mail"); + fprintf(stderr, " %-39s%-39s\n", "-d | -delete member", + "-NM | -notmail"); + fprintf(stderr, " %-39s%-39s\n", "-al | -addlist filename", + "-G | -group"); + fprintf(stderr, " %-39s%-39s\n", "-dl | -deletelist filename", + "-NG | -notgroup"); + fprintf(stderr, " %-39s%-39s\n", "-f | -file filename", + "-D | -desc description"); + fprintf(stderr, " %-39s%-39s\n", "-n | -noauth", + "-O | -owner owner"); + fprintf(stderr, " %-39s%-39s\n", "-db | -database host[:port]", + ""); + exit(1); } /* Display the members stored in the queue */ -show_list_member(memberstruct) -struct member *memberstruct; +show_list_member(struct member *memberstruct) { - char *s = ""; + char *s = ""; - switch (memberstruct->type) { + switch (memberstruct->type) + { case M_USER: - if (!showusers) - return; - s = "USER"; - break; + if (!showusers) + return; + s = "USER"; + break; case M_LIST: - if (!showlists) - return; - s = "LIST"; - break; + if (!showlists) + return; + s = "LIST"; + break; case M_STRING: - if (!showstrings) - return; - s = "STRING"; - break; + if (!showstrings) + return; + s = "STRING"; + break; case M_KERBEROS: - if (!showkerberos) - return; - s = "KERBEROS"; - break; - case M_ANY: - printf("%s\n", memberstruct->name); + if (!showkerberos) return; + s = "KERBEROS"; + break; + case M_ANY: + printf("%s\n", memberstruct->name); + return; } - if (verbose) - printf("%s:%s\n", s, memberstruct->name); - else { - if (memberstruct->type == M_LIST) - printf("LIST:%s\n", memberstruct->name); - else if (memberstruct->type == M_KERBEROS) - printf("KERBEROS:%s\n", memberstruct->name); - else if (memberstruct->type == M_STRING && - !strchr(memberstruct->name, '@')) - printf("STRING:%s\n", memberstruct->name); - else - printf("%s\n", memberstruct->name); + if (verbose) + printf("%s:%s\n", s, memberstruct->name); + else + { + if (memberstruct->type == M_LIST) + printf("LIST:%s\n", memberstruct->name); + else if (memberstruct->type == M_KERBEROS) + printf("KERBEROS:%s\n", memberstruct->name); + else if (memberstruct->type == M_STRING && + !strchr(memberstruct->name, '@')) + printf("STRING:%s\n", memberstruct->name); + else + printf("%s\n", memberstruct->name); } } /* Show the retrieved information about a list */ -show_list_info(argc, argv, hint) -int argc; -char **argv; -int hint; +int show_list_info(int argc, char **argv, int hint) { - printf("List: %s\n", argv[0]); - printf("Description: %s\n", argv[9]); - printf("Flags: %s, %s, and %s\n", - atoi(argv[1]) ? "active" : "inactive", - atoi(argv[2]) ? "public" : "private", - atoi(argv[3]) ? "hidden" : "visible"); - printf("%s is %sa maillist and is %sa group", argv[0], - atoi(argv[4]) ? "" : "not ", - atoi(argv[5]) ? "" : "not "); - if (atoi(argv[5])) - printf(" with GID %d\n", atoi(argv[6])); - else - printf("\n"); - printf("Owner: %s %s\n", argv[7], argv[8]); - printf("Last modified by %s with %s on %s\n", argv[11], argv[12], argv[10]); - return(MR_CONT); + printf("List: %s\n", argv[0]); + printf("Description: %s\n", argv[9]); + printf("Flags: %s, %s, and %s\n", + atoi(argv[1]) ? "active" : "inactive", + atoi(argv[2]) ? "public" : "private", + atoi(argv[3]) ? "hidden" : "visible"); + printf("%s is %sa maillist and is %sa group", argv[0], + atoi(argv[4]) ? "" : "not ", + atoi(argv[5]) ? "" : "not "); + if (atoi(argv[5])) + printf(" with GID %d\n", atoi(argv[6])); + else + printf("\n"); + printf("Owner: %s %s\n", argv[7], argv[8]); + printf("Last modified by %s with %s on %s\n", argv[11], argv[12], argv[10]); + return MR_CONT; } /* Copy retrieved information about a list into a new argv */ -save_list_info(argc, argv, hint) -int argc; -char **argv; -int hint; +int save_list_info(int argc, char **argv, int hint) { - char **nargv = (char **)hint; - - for(argc = 0; argc < 10; argc++) - nargv[argc+1] = strdup(argv[argc]); - return MR_CONT; + char **nargv = (char **)hint; + + for (argc = 0; argc < 10; argc++) + nargv[argc + 1] = strdup(argv[argc]); + return MR_CONT; } /* Show the retrieve list member count */ -show_list_count(argc, argv, hint) -int argc; -char **argv; -int hint; +show_list_count(int argc, char **argv, int hint) { - printf("Members: %s\n", argv[0]); + printf("Members: %s\n", argv[0]); } /* Recursively find all of the members of listname, and then display them */ -recursive_display_list_members() +recursive_display_list_members(void) { - int status, count, savecount; - struct save_queue *lists, *members; - struct member *m, *m1, *data; - - lists = sq_create(); - members = sq_create(); - m = (struct member *) malloc(sizeof(struct member)); - m->type = M_LIST; - m->name = listname; - sq_save_data(lists, m); - - while (sq_get_data(lists, &m)) { - sq_destroy(memberlist); - memberlist = sq_create(); - status = mr_query("get_members_of_list", 1, &(m->name), - get_list_members, (char *)memberlist); - if (status) - com_err(whoami, status, "while getting members of list %s", m->name); - while (sq_get_data(memberlist, &m1)) { - if (m1->type == M_LIST) - unique_add_member(lists, m1); - else - unique_add_member(members, m1); + int status, count, savecount; + struct save_queue *lists, *members; + struct member *m, *m1, *data; + + lists = sq_create(); + members = sq_create(); + m = malloc(sizeof(struct member)); + m->type = M_LIST; + m->name = listname; + sq_save_data(lists, m); + + while (sq_get_data(lists, &m)) + { + sq_destroy(memberlist); + memberlist = sq_create(); + status = mr_query("get_members_of_list", 1, &(m->name), + get_list_members, (char *)memberlist); + if (status) + com_err(whoami, status, "while getting members of list %s", m->name); + while (sq_get_data(memberlist, &m1)) + { + if (m1->type == M_LIST) + unique_add_member(lists, m1); + else + unique_add_member(members, m1); } } - savecount = count = sq_count_elts(members); - data = (struct member *) malloc(count * sizeof(struct member)); - count = 0; - while (sq_get_data(members, &m)) - memcpy(&data[count++], m, sizeof(struct member)); - qsort(data, count, sizeof(struct member), membercmp); - for (count = 0; count < savecount; count++) { - show_list_member(&data[count]); - } + savecount = count = sq_count_elts(members); + data = malloc(count * sizeof(struct member)); + count = 0; + while (sq_get_data(members, &m)) + memcpy(&data[count++], m, sizeof(struct member)); + qsort(data, count, sizeof(struct member), membercmp); + for (count = 0; count < savecount; count++) + show_list_member(&data[count]); } /* add a struct member to a queue if that member isn't already there. */ -unique_add_member(q, m) -struct save_queue *q; -struct member *m; +unique_add_member(struct save_queue *q, struct member *m) { - struct save_queue *qp; + struct save_queue *qp; - for (qp = q->q_next; qp != q; qp = qp->q_next) { - if (!membercmp(qp->q_data, m)) - return; + for (qp = q->q_next; qp != q; qp = qp->q_next) + { + if (!membercmp(qp->q_data, m)) + return; } - sq_save_data(q, m); + sq_save_data(q, m); } /* Collect the retrieved members of the list */ -get_list_members(argc, argv, q) -int argc; -char **argv; -struct save_queue *q; +int get_list_members(int argc, char **argv, struct save_queue *q) { - struct member *m; + struct member *m; - m = (struct member *) malloc(sizeof(struct member)); - switch (argv[0][0]) { + m = malloc(sizeof(struct member)); + switch (argv[0][0]) + { case 'U': - m->type = M_USER; - break; + m->type = M_USER; + break; case 'L': - m->type = M_LIST; - break; + m->type = M_LIST; + break; case 'S': - m->type = M_STRING; - break; + m->type = M_STRING; + break; case 'K': - m->type = M_KERBEROS; - break; + m->type = M_KERBEROS; + break; } - m->name = strsave(argv[1]); - sq_save_data(q, m); - return(MR_CONT); + m->name = strsave(argv[1]); + sq_save_data(q, m); + return MR_CONT; } /* Called only if a query returns a value that we weren't expecting */ -scream() +scream(void) { - fprintf(stderr, "Programmer botch\n"); - exit(3); + fprintf(stderr, "Programmer botch\n"); + exit(3); } /* Open file, parse members from file, and put them on the specified queue */ -get_members_from_file(filename, queue) -char *filename; -struct save_queue *queue; +get_members_from_file(char *filename, struct save_queue *queue) { - FILE *in; - char buf[BUFSIZ]; - struct member *memberstruct; - - if (!strcmp(filename, "-")) - in = stdin; - else { - in = fopen(filename, "r"); - if (!in) { - com_err(whoami, errno, "while opening %s for input", filename); - exit(2); + FILE *in; + char buf[BUFSIZ]; + struct member *memberstruct; + + if (!strcmp(filename, "-")) + in = stdin; + else + { + in = fopen(filename, "r"); + if (!in) + { + com_err(whoami, errno, "while opening %s for input", filename); + exit(2); } } - while (fgets(buf, BUFSIZ, in)) - if (memberstruct = parse_member(buf)) + while (fgets(buf, BUFSIZ, in)) + { + if ((memberstruct = parse_member(buf))) sq_save_data(queue, memberstruct); - if (!feof(in)) { + } + if (!feof(in)) + { com_err(whoami, errno, "while reading from %s", filename); exit(2); } @@ -870,18 +976,16 @@ struct save_queue *queue; /* Collect the possible expansions of the alias MAILHUB */ -int collect(argc, argv, list) -int argc; -char **argv; -char ***list; +int collect(int argc, char **argv, char ***list) { - int i; - - for (i = 0; (*list)[i]; i++); - *list = (char **)realloc(*list, (i + 2) * sizeof(char *)); - (*list)[i] = strsave(argv[2]); - (*list)[i+1] = NULL; - return(MR_CONT); + int i; + + for (i = 0; (*list)[i]; i++) + ; + *list = realloc(*list, (i + 2) * sizeof(char *)); + (*list)[i] = strsave(argv[2]); + (*list)[i + 1] = NULL; + return MR_CONT; } @@ -889,81 +993,84 @@ char ***list; * is not found. ';' is a comment character. */ -struct member *parse_member(s) -register char *s; +struct member *parse_member(register char *s) { - register struct member *m; - char *p, *lastchar; - - while (*s && isspace(*s)) - s++; - lastchar = p = s; - while (*p && *p != '\n' && *p != ';') + register struct member *m; + char *p, *lastchar; + + while (*s && isspace(*s)) + s++; + lastchar = p = s; + while (*p && *p != '\n' && *p != ';') + { if (isprint(*p) && !isspace(*p)) lastchar = p++; else p++; - lastchar++; - *lastchar = 0; - if (p == s || strlen(s) == 0) - return(NULL); - - if ((m = (struct member *) malloc(sizeof(struct member))) == NULL) - return(NULL); - - if (p = strchr(s, ':')) { - *p = 0; - m->name = ++p; - if (!strcasecmp("user", s)) - m->type = M_USER; - else if (!strcasecmp("list", s)) - m->type = M_LIST; - else if (!strcasecmp("string", s)) - m->type = M_STRING; - else if (!strcasecmp("kerberos", s)) - m->type = M_KERBEROS; - else { - m->type = M_ANY; - *(--p) = ':'; - m->name = s; + } + lastchar++; + *lastchar = '\0'; + if (p == s || strlen(s) == 0) + return NULL; + + if (!(m = malloc(sizeof(struct member)))) + return NULL; + + if ((p = strchr(s, ':'))) + { + *p = '\0'; + m->name = ++p; + if (!strcasecmp("user", s)) + m->type = M_USER; + else if (!strcasecmp("list", s)) + m->type = M_LIST; + else if (!strcasecmp("string", s)) + m->type = M_STRING; + else if (!strcasecmp("kerberos", s)) + m->type = M_KERBEROS; + else + { + m->type = M_ANY; + *(--p) = ':'; + m->name = s; } - m->name = strsave(m->name); - } else { - m->name = strsave(s); - m->type = M_ANY; + m->name = strsave(m->name); + } + else + { + m->name = strsave(s); + m->type = M_ANY; } - return(m); + return m; } - /* - * This routine two compares members by the following rules: - * 1. A USER is less than a LIST - * 2. A LIST is less than a STRING - * 3. If two members are of the same type, the one alphabetically first - * is less than the other - * It returs < 0 if the first member is less, 0 if they are identical, and - * > 0 if the second member is less (the first member is greater). - */ +/* + * This routine two compares members by the following rules: + * 1. A USER is less than a LIST + * 2. A LIST is less than a STRING + * 3. If two members are of the same type, the one alphabetically first + * is less than the other + * It returs < 0 if the first member is less, 0 if they are identical, and + * > 0 if the second member is less (the first member is greater). + */ -int membercmp(m1, m2) - struct member *m1, *m2; +int membercmp(struct member *m1, struct member *m2) { - if (m1->type == M_ANY || m2->type == M_ANY || (m1->type == m2->type)) - return(strcmp(m1->name, m2->name)); - else - return(m1->type - m2->type); + if (m1->type == M_ANY || m2->type == M_ANY || (m1->type == m2->type)) + return strcmp(m1->name, m2->name); + else + return m1->type - m2->type; } -sq_count_elts(q) -struct save_queue *q; +int sq_count_elts(struct save_queue *q) { - char *foo; - int count; + char *foo; + int count; - count = 0; - while (sq_get_data(q, &foo)) - count++; - return(count); + count = 0; + while (sq_get_data(q, &foo)) + count++; + return count; } diff --git a/clients/mailmaint/mailmaint.c b/clients/mailmaint/mailmaint.c index 4c6aa099..51d2f98e 100644 --- a/clients/mailmaint/mailmaint.c +++ b/clients/mailmaint/mailmaint.c @@ -12,9 +12,7 @@ static char rcsid_mailmaint_c[] = "$Header$"; #endif /***********************************************************************/ -/* mailmaint.c - pjlevine - 20 August 1987 - -*/ +/* mailmaint.c - pjlevine - 20 August 1987 */ /***********************************************************************/ #include #include @@ -22,11 +20,8 @@ static char rcsid_mailmaint_c[] = "$Header$"; #include #include #include -#ifdef __STDC__ #include -#else -#include -#endif +#include #include #include #include @@ -39,33 +34,27 @@ static char rcsid_mailmaint_c[] = "$Header$"; #define DISPROW 15 #define LISTMAX 50 #define LISTSIZE 32 -#define CTL(ch) ((ch) & 037) -#define MAX(A,B) ((A) > (B) ? (A) : (B)) +#define CTL(ch) ((ch) & 037) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) char *whoami; /* should not be static, for logging package */ static int status; static int scream(); -extern char *strsave(); -#ifdef __STDC__ void menu_err_hook(const char *who, long code, const char *fmt, va_list args); -#else -void menu_err_hook(); -#define const -#endif typedef struct list_info { - int active; - int public; - int hidden; - int maillist; - int group; - char *acl_type; - char *acl_name; - char *desc; - char *modtime; - char *modby; - char *modwith; -} List_info; + int active; + int public; + int hidden; + int maillist; + int group; + char *acl_type; + char *acl_name; + char *desc; + char *modtime; + char *modby; + char *modwith; +} List_info; static char *ascbuff = {"0123456789"}; static int print_2(), print_1(); @@ -73,19 +62,11 @@ static List_info *current_li = (List_info *) NULL; static int get_list_info(); static int fetch_list_info(); -char *malloc(); -char *getlogin(); -extern char *strsave(); -char *getenv(); -char *calloc(); - -uid_t getuid(); - typedef struct _menu { - int num_items; - char *title; - char **items; -} MENU; + int num_items; + char *title; + char **items; +} MENU; MENU *main_menu, *help_menu; @@ -97,861 +78,842 @@ char *username; /* This crock is because the original code was very broken and this makes * it work. Someday, we should abandon the code or fix it right. */ -#define mvcur(oy,ox,ny,nx) move(ny,nx) +#define mvcur(oy, ox, ny, nx) move(ny, nx) /****************************************************/ -/*ARGSUSED*/ -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { -#ifdef __STDC__ - void (*old_hook)(const char *, long, const char *, va_list); -#else - void (*old_hook)(); -#endif - int use_menu = 1; - char buf[BUFSIZ], *motd; - - if ((whoami = strrchr(argv[0], '/')) == NULL) - whoami = argv[0]; - else - whoami++; - if ((current_li = (List_info *) malloc(sizeof(List_info))) - == (List_info *) NULL) { - (void) sprintf(buf, ": allocating list info"); - goto punt; + void (*old_hook)(const char *, long, const char *, va_list); + int use_menu = 1; + char buf[BUFSIZ], *motd; + + if ((whoami = strrchr(argv[0], '/')) == NULL) + whoami = argv[0]; + else + whoami++; + if (!(current_li = malloc(sizeof(List_info)))) + { + sprintf(buf, ": allocating list info"); + goto punt; } - else { - current_li->acl_type = (char *) NULL; - current_li->acl_name = (char *) NULL; - current_li->desc = (char *) NULL; - current_li->modtime = (char *) NULL; - current_li->modby = (char *) NULL; - current_li->modwith = (char *) NULL; + else + { + current_li->acl_type = NULL; + current_li->acl_name = NULL; + current_li->desc = NULL; + current_li->modtime = NULL; + current_li->modby = NULL; + current_li->modwith = NULL; } - if ((username = getlogin()) == NULL) { - struct passwd *getpwuid(); + if (!(username = getlogin())) + { + struct passwd *getpwuid(); - username = getpwuid((int) getuid())->pw_name; + username = getpwuid(getuid())->pw_name; } - username = (username && strlen(username)) ? strsave(username) : ""; + username = (username && strlen(username)) ? strsave(username) : ""; - printf("Connecting to database for %s...please hold on.\n", username); + printf("Connecting to database for %s...please hold on.\n", username); - status = mr_connect(NULL); - if (status) { - (void) sprintf(buf, "\nConnection to Moira server failed"); - goto punt; + status = mr_connect(NULL); + if (status) + { + sprintf(buf, "\nConnection to Moira server failed"); + goto punt; } - status = mr_motd(&motd); - if (status) { - com_err(whoami, status, " unable to check server status"); - mr_disconnect(); - exit(2); + status = mr_motd(&motd); + if (status) + { + com_err(whoami, status, " unable to check server status"); + mr_disconnect(); + exit(2); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(2); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(2); } - status = mr_auth("mailmaint"); - if (status) { - (void) sprintf(buf, "\nAuthorization failed.\n"); - goto punt; + status = mr_auth("mailmaint"); + if (status) + { + sprintf(buf, "\nAuthorization failed.\n"); + goto punt; } - if (use_menu) { - (void) initscr(); - if ((LINES < 24) || (COLS < 60)) { - display_buff("Display window too small.\n\n"); - (void) sprintf(buf, "Current window parameters are (%d \ -lines, %d columns)\n", LINES, COLS); - display_buff(buf); - display_buff("Please resize your window\n"); - display_buff("to at least 24 lines and 60 columns.\n"); - exit(0); + if (use_menu) + { + initscr(); + if ((LINES < 24) || (COLS < 60)) + { + display_buff("Display window too small.\n\n"); + sprintf(buf, + "Current window parameters are (%d lines, %d columns)\n", + LINES, COLS); + display_buff(buf); + display_buff("Please resize your window\n"); + display_buff("to at least 24 lines and 60 columns.\n"); + exit(0); } - raw(); - noecho(); - old_hook = set_com_err_hook(menu_err_hook); - position[0] = oldpos[0] = 1; - level = 0; - pack_main_menu(); - pack_help_menu(); - display_menu(main_menu); - get_main_input(); - cls(); - endwin(); - set_com_err_hook(old_hook); + raw(); + noecho(); + old_hook = set_com_err_hook(menu_err_hook); + position[0] = oldpos[0] = 1; + level = 0; + pack_main_menu(); + pack_help_menu(); + display_menu(main_menu); + get_main_input(); + cls(); + endwin(); + set_com_err_hook(old_hook); } - exit(0); + exit(0); punt: - com_err(whoami, status, buf); - exit(1); + com_err(whoami, status, buf); + exit(1); } /****************************************************/ -get_main_input() +int get_main_input(void) { - int c; - int retflg; - - while (1) { - oldpos[level] = position[level]; - retflg = 0; - currow = DISPROW + 2; - page = 1; - toggle = num_members = moreflg = 0; - c = getchar() & 0x7f; /* mask parity bit */ - if (c == '\r' || c == '\n') { - if (position[level] == 7) - c = 'q'; - else - c = ascbuff[position[level]]; - retflg = 1; + int c; + int retflg; + + while (1) + { + oldpos[level] = position[level]; + retflg = 0; + currow = DISPROW + 2; + page = 1; + toggle = num_members = moreflg = 0; + c = getchar() & 0x7f; /* mask parity bit */ + if (c == '\r' || c == '\n') + { + if (position[level] == 7) + c = 'q'; + else + c = ascbuff[position[level]]; + retflg = 1; } - switch (c) { + switch (c) + { case 'L' & 037: /* clear screen */ - display_menu(main_menu); - break; + display_menu(main_menu); + break; case 'q': case 'Q': /* quit */ - position[level] = 7; - highlight(main_menu); - if (retflg) { - cls(); - return; + position[level] = 7; + highlight(main_menu); + if (retflg) + { + cls(); + return; } - break; + break; case '1': /* show all lists */ - position[level] = 1; - if (retflg) { - show_all(); - } - break; + position[level] = 1; + if (retflg) + show_all(); + break; case '2': /* get all members of a list */ - position[level] = 2; - if (retflg) { - (void) list_members(); - } - break; + position[level] = 2; + if (retflg) + list_members(); + break; case '3': /* display list which user is a recipient */ - position[level] = 3; - if (retflg) { - list_by_member(); - } - break; + position[level] = 3; + if (retflg) + list_by_member(); + break; case '4': /* show description */ - position[level] = 4; - if (retflg) { - show_list_info(); - } - break; + position[level] = 4; + if (retflg) + show_list_info(); + break; case '5': /* add to list */ - position[level] = 5; - if (retflg) { - add_member(); - } - break; + position[level] = 5; + if (retflg) + add_member(); + break; case '6': /* delete */ - position[level] = 6; - if (retflg) { - delete_member(); - } - break; - case 27: /* up arrow */ - c = getchar() & 0x7f; - if (c == 91) { - c = getchar() & 0x7f; - if (c == 65) { - position[level]--; - if (!position[level]) - position[level] = 7; + position[level] = 6; + if (retflg) + delete_member(); + break; + case 27: /* escape */ + c = getchar() & 0x7f; + if (c == 91) + { + c = getchar() & 0x7f; + if (c == 65) /* up arrow */ + { + position[level]--; + if (!position[level]) + position[level] = 7; } - else { - if (c == 66) { - position[level]++; - if (position[level] > 7) - position[level] = 1; + else + { + if (c == 66) /* down arrow */ + { + position[level]++; + if (position[level] > 7) + position[level] = 1; } } } - break; + break; default: - printf("%c", 7); - break; + printf("%c", 7); + break; } - highlight(main_menu); + highlight(main_menu); } } /****************************************************/ -show_list_info() +int show_list_info(void) { - char *buf; - - show_text(DISPROW, STARTCOL, "Show information about a list.\n"); - buf = calloc((unsigned)1024, 1); - if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { - display_buff("\n"); - if (fetch_list_info(buf, current_li) == 0) { - (void) sprintf(buf, "Description: %s\n", current_li->desc); - if (strlen(buf) > 60) - (void) display_buff(buf); - else - show_text(currow, STARTCOL, buf); - currow++; - (void) sprintf(buf, "List Administrator: %s %s", - current_li->acl_type, current_li->acl_name); - show_text(currow, STARTCOL, buf); - currow++; - (void) sprintf(buf, "Modified on %s by user %s with %s", - current_li->modtime, current_li->modby, - current_li->modwith); + char *buf; + + show_text(DISPROW, STARTCOL, "Show information about a list.\n"); + buf = calloc(1024, 1); + if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) + { + display_buff("\n"); + if (fetch_list_info(buf, current_li) == 0) + { + sprintf(buf, "Description: %s\n", current_li->desc); + if (strlen(buf) > 60) + display_buff(buf); + else show_text(currow, STARTCOL, buf); - currow++; + currow++; + sprintf(buf, "List Administrator: %s %s", + current_li->acl_type, current_li->acl_name); + show_text(currow, STARTCOL, buf); + currow++; + sprintf(buf, "Modified on %s by user %s with %s", + current_li->modtime, current_li->modby, + current_li->modwith); + show_text(currow, STARTCOL, buf); + currow++; } - else { - show_text(currow, STARTCOL, "mailmaint: No such list found."); - currow++; + else + { + show_text(currow, STARTCOL, "mailmaint: No such list found."); + currow++; } - show_text(currow, STARTCOL, "Press any Key to continue..."); - (void) getchar(); + show_text(currow, STARTCOL, "Press any Key to continue..."); + getchar(); } - clrwin(DISPROW); + clrwin(DISPROW); } /****************************************************/ -display_buff(buf) - char *buf; +int display_buff(char *buf) { - int i, cnt; - char *printbuf; - int maxcol; - - maxcol = COLS; - -/* I don't understand the point of this limitation. -jweiss 3/25/94 - if (maxcol >= 80) - maxcol = 80; -*/ - cnt = 0; - printbuf = calloc((unsigned)maxcol, 1); - for (i = 0; i <= strlen(buf); i++) { - printbuf[cnt] = buf[i]; - cnt++; - if (cnt >= maxcol) { - (void) start_display_buff(printbuf); - cnt = 0; - free(printbuf); - printbuf = calloc((unsigned)maxcol, 1); + int i, cnt; + char *printbuf; + int maxcol; + + maxcol = COLS; + + cnt = 0; + printbuf = calloc(maxcol, 1); + for (i = 0; i <= strlen(buf); i++) + { + printbuf[cnt] = buf[i]; + cnt++; + if (cnt >= maxcol) + { + start_display_buff(printbuf); + cnt = 0; + free(printbuf); + printbuf = calloc(maxcol, 1); } } - if (strlen(buf) % maxcol != 0) { - (void) start_display_buff(printbuf); - free(printbuf); + if (strlen(buf) % maxcol != 0) + { + start_display_buff(printbuf); + free(printbuf); } - return (0); + return 0; } /****************************************************/ -start_display_buff(buff) - char *buff; +int start_display_buff(char *buff) { - char buffer[5]; - - num_members++; - if (moreflg) - return (0); - if (currow >= LINES - 2) { - page++; - currow++; - mvcur(0, 0, currow, STARTCOL); - refresh(); - if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { - erase_line(currow, STARTCOL); - show_text(currow, STARTCOL, "Flushing query..."); - moreflg = 1; - return (0); + char buffer[5]; + + num_members++; + if (moreflg) + return 0; + if (currow >= LINES - 2) + { + page++; + currow++; + mvcur(0, 0, currow, STARTCOL); + refresh(); + if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) + { + erase_line(currow, STARTCOL); + show_text(currow, STARTCOL, "Flushing query..."); + moreflg = 1; + return 0; } - clrwin(DISPROW + 2); - currow = DISPROW + 2; - show_text(currow, STARTCOL, "continued"); - currow++; + clrwin(DISPROW + 2); + currow = DISPROW + 2; + show_text(currow, STARTCOL, "continued"); + currow++; } - show_text(currow, STARTCOL, buff); - currow++; - return (0); + show_text(currow, STARTCOL, buff); + currow++; + return 0; } /****************************************************/ -add_member() +int add_member(void) { - char *argv[3]; - char *buf; - - show_text(DISPROW, STARTCOL, "Add yourself to a list\n"); - buf = calloc(LISTMAX, 1); - if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { - display_buff("\n"); - argv[0] = strsave(buf); - argv[1] = strsave("user"); - argv[2] = strsave(username); - if (status = mr_query("add_member_to_list", 3, argv, - scream, (char *) NULL)) { - display_buff("\n"); - com_err(whoami, status, " found.\n"); + char *argv[3]; + char *buf; + + show_text(DISPROW, STARTCOL, "Add yourself to a list\n"); + buf = calloc(LISTMAX, 1); + if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) + { + display_buff("\n"); + argv[0] = strsave(buf); + argv[1] = strsave("user"); + argv[2] = strsave(username); + if ((status = mr_query("add_member_to_list", 3, argv, scream, NULL))) + { + display_buff("\n"); + com_err(whoami, status, " found.\n"); } - else { - (void) sprintf(buf, "User %s added to list\n", username); - show_text(DISPROW + 3, STARTCOL, buf); + else + { + sprintf(buf, "User %s added to list\n", username); + show_text(DISPROW + 3, STARTCOL, buf); } - currow = DISPROW + 4; - show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); - (void) getchar(); + currow = DISPROW + 4; + show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); + getchar(); } - clrwin(DISPROW); + clrwin(DISPROW); } /****************************************************/ -delete_member() +int delete_member(void) { - char *argv[3]; - char *buf; - - show_text(DISPROW, STARTCOL, "Remove yourself from a list\n"); - buf = calloc(LISTMAX, 1); - if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { - display_buff("\n"); - argv[0] = strsave(buf); - argv[1] = strsave("user"); - argv[2] = strsave(username); - if (status = mr_query("delete_member_from_list", 3, argv, - scream, (char *) NULL)) { - display_buff("\n"); - com_err(whoami, status, " found.\n"); + char *argv[3]; + char *buf; + + show_text(DISPROW, STARTCOL, "Remove yourself from a list\n"); + buf = calloc(LISTMAX, 1); + if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) + { + display_buff("\n"); + argv[0] = strsave(buf); + argv[1] = strsave("user"); + argv[2] = strsave(username); + if ((status = mr_query("delete_member_from_list", 3, argv, scream, NULL))) + { + display_buff("\n"); + com_err(whoami, status, " found.\n"); } - else { - (void) sprintf(buf, "User %s deleted from list\n", username); - show_text(DISPROW + 3, STARTCOL, buf); + else + { + sprintf(buf, "User %s deleted from list\n", username); + show_text(DISPROW + 3, STARTCOL, buf); } - currow = DISPROW + 4; - show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); - (void) getchar(); + currow = DISPROW + 4; + show_text(DISPROW + 4, STARTCOL, "Press any Key to continue..."); + getchar(); } - clrwin(DISPROW); + clrwin(DISPROW); } /****************************************************/ -list_by_member() +int list_by_member(void) { - char *nargv[3]; - char *buf; - - nargv[1] = strsave("ruser"); - nargv[2] = strsave(username); - buf = calloc(BUFSIZ, 1); - (void) sprintf(buf, "%s is on the following lists:\n", username); - show_text(DISPROW, STARTCOL, buf); - mvcur(0, 0, currow, STARTCOL); - refresh(); - if (status = mr_query("get_lists_of_member", 2, nargv + 1, - print_1, (char *) NULL)) { - display_buff("\n"); - com_err(whoami, status, " in get_lists_of_member"); + char *nargv[3]; + char *buf; + + nargv[1] = strsave("ruser"); + nargv[2] = strsave(username); + buf = calloc(BUFSIZ, 1); + sprintf(buf, "%s is on the following lists:\n", username); + show_text(DISPROW, STARTCOL, buf); + mvcur(0, 0, currow, STARTCOL); + refresh(); + if ((status = mr_query("get_lists_of_member", 2, nargv + 1, print_1, NULL))) + { + display_buff("\n"); + com_err(whoami, status, " in get_lists_of_member"); } - currow++; - show_text(currow, STARTCOL, "Press any Key to continue..."); - (void) getchar(); - clrwin(DISPROW); - return; + currow++; + show_text(currow, STARTCOL, "Press any Key to continue..."); + getchar(); + clrwin(DISPROW); + return; } /****************************************************/ -show_all() +int show_all(void) { - char c; - - show_text(DISPROW, STARTCOL, "This function may take a \ -while... proceed? [n] "); - c = getchar() & 0x7f; - if (c == 'y' || c == 'Y') { - move(DISPROW + 1, STARTCOL); - addstr("Processing query...please hold"); - refresh(); - (void) list_all_groups(); + char c; + + show_text(DISPROW, STARTCOL, "This function may take a while... proceed? [n] "); + c = getchar() & 0x7f; + if (c == 'y' || c == 'Y') + { + move(DISPROW + 1, STARTCOL); + addstr("Processing query...please hold"); + refresh(); + list_all_groups(); } - else - erase_line(DISPROW, STARTCOL); - return; - + else + erase_line(DISPROW, STARTCOL); + return; } /****************************************************/ -/*ARGSUSED*/ -static int -print_1(argc, argv, callback) - int argc; - char *argv[], *callback; +static int print_1(int argc, char *argv[], char *callback) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - /* no newline 'cause display_buff adds one */ - (void) sprintf(buf, "%s\n", argv[0]); - (void) start_display(buf); + /* no newline 'cause display_buff adds one */ + sprintf(buf, "%s\n", argv[0]); + start_display(buf); - return (0); + return 0; } /****************************************************/ -/*ARGSUSED*/ -static int -print_all(argc, argv, callback) - int argc; - char *argv[], *callback; +static int print_all(int argc, char *argv[], char *callback) { - char buf[BUFSIZ]; - - if (moreflg) - return (0); - if (first_time) { - erase_line(DISPROW + 1, STARTCOL); - show_text(DISPROW + 1, STARTCOL, "All mailing lists:"); - first_time = 0; + char buf[BUFSIZ]; + + if (moreflg) + return 0; + if (first_time) + { + erase_line(DISPROW + 1, STARTCOL); + show_text(DISPROW + 1, STARTCOL, "All mailing lists:"); + first_time = 0; } - (void) sprintf(buf, "%s\n", argv[0]); - (void) start_display(buf); + sprintf(buf, "%s\n", argv[0]); + start_display(buf); - return (0); + return 0; } /****************************************************/ -list_all_groups() +int list_all_groups(void) { - char *argv[5]; - argv[0] = argv[1] = argv[3] = "true"; - argv[4] = "dontcare"; - argv[2] = "false"; - first_time = 1; - if (status = mr_query("qualified_get_lists", 5, argv, - print_all, (char *) NULL)) { - display_buff("\n"); - com_err(whoami, status, " in list_all_groups\n"); + char *argv[5]; + argv[0] = argv[1] = argv[3] = "true"; + argv[4] = "dontcare"; + argv[2] = "false"; + first_time = 1; + if ((status = mr_query("qualified_get_lists", 5, argv, print_all, NULL))) + { + display_buff("\n"); + com_err(whoami, status, " in list_all_groups\n"); } - end_display(); + end_display(); - return (0); + return 0; } /****************************************************/ -list_members() +int list_members(void) { - char *argv[1]; - char *buf; - char buffer[80]; - - found_some = 0; - move(DISPROW, STARTCOL); - mvcur(0, 0, DISPROW, STARTCOL); - refresh(); - buf = calloc(LISTMAX, 1); - if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) { - (void) sprintf(buffer, "The members of list '%s' are:", buf); - show_text(DISPROW + 1, STARTCOL, buffer); - argv[0] = buf; - if (status = mr_query("get_members_of_list", 1, argv, - print_2, (char *) NULL)) { - display_buff("\n"); - com_err(whoami, status, " found.\n"); - currow++; + char *argv[1]; + char *buf; + char buffer[80]; + + found_some = 0; + move(DISPROW, STARTCOL); + mvcur(0, 0, DISPROW, STARTCOL); + refresh(); + buf = calloc(LISTMAX, 1); + if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) + { + sprintf(buffer, "The members of list '%s' are:", buf); + show_text(DISPROW + 1, STARTCOL, buffer); + argv[0] = buf; + if ((status = mr_query("get_members_of_list", 1, argv, print_2, NULL))) + { + display_buff("\n"); + com_err(whoami, status, " found.\n"); + currow++; } - if (!found_some) { - show_text(currow, STARTCOL, "List is empty (no members)."); - currow++; - show_text(currow, STARTCOL, "Press any key to continue..."); - getchar(); - clrwin(DISPROW); - return; + if (!found_some) + { + show_text(currow, STARTCOL, "List is empty (no members)."); + currow++; + show_text(currow, STARTCOL, "Press any key to continue..."); + getchar(); + clrwin(DISPROW); + return; } - end_display(); - return(0); + end_display(); + return 0; } - clrwin(DISPROW); - return (0); + clrwin(DISPROW); + return 0; } /****************************************************/ -/*ARGSUSED*/ -static int -print_2(argc, argv, callback) - int argc; - char *argv[], *callback; +static int print_2(int argc, char *argv[], char *callback) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - found_some = 1; - (void) sprintf(buf, "%s %s", argv[0], argv[1]); - (void) start_display(buf); + found_some = 1; + sprintf(buf, "%s %s", argv[0], argv[1]); + start_display(buf); - return (0); + return 0; } /****************************************************/ -start_display(buff) - char *buff; +int start_display(char *buff) { - char *buffer; - int secondcol; /* where to start the second column of text */ - - secondcol = (COLS / 2); /* 1/2 was accross the screen */ - num_members++; - if (moreflg) - return(0); - buffer = calloc(50, 1); - if (currow >= LINES - 2) { - page++; - mvcur(0, 0, currow, STARTCOL); - refresh(); - if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { - erase_line(currow, STARTCOL); - show_text(currow, STARTCOL, "Flushing query..."); - moreflg = 1; - return (0); + char *buffer; + int secondcol; /* where to start the second column of text */ + + secondcol = (COLS / 2); /* 1/2 was accross the screen */ + num_members++; + if (moreflg) + return 0; + buffer = calloc(50, 1); + if (currow >= LINES - 2) + { + page++; + mvcur(0, 0, currow, STARTCOL); + refresh(); + if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) + { + erase_line(currow, STARTCOL); + show_text(currow, STARTCOL, "Flushing query..."); + moreflg = 1; + return 0; } - clrwin(DISPROW + 2); - currow = DISPROW + 2; - (void) sprintf(buffer, "Continued (Page %d)", page); - show_text(currow, STARTCOL, buffer); - currow++; - toggle = 0; + clrwin(DISPROW + 2); + currow = DISPROW + 2; + sprintf(buffer, "Continued (Page %d)", page); + show_text(currow, STARTCOL, buffer); + currow++; + toggle = 0; } - if (!toggle) - show_text(currow, STARTCOL, buff); - else { - erase_line(currow, secondcol-1); /* in case the 1st col is too long */ - show_text(currow, secondcol, buff); - currow++; + if (!toggle) + show_text(currow, STARTCOL, buff); + else + { + erase_line(currow, secondcol - 1); /* in case the 1st col is too long */ + show_text(currow, secondcol, buff); + currow++; } - toggle = !toggle; - return(0); + toggle = !toggle; + return 0; } /****************************************************/ -end_display() +int end_display(void) { - char *buffer; + char *buffer; - if (moreflg) { - clrwin(DISPROW); - return; + if (moreflg) + { + clrwin(DISPROW); + return; } - buffer = calloc(50, 1); - currow++; - (void) sprintf(buffer, "End of List. %d Total Members\n", num_members - 1); - show_text(currow, STARTCOL, buffer); - currow++; - show_text(currow, STARTCOL, "Press any key to continue..."); - (void) getchar(); - clrwin(DISPROW); - + buffer = calloc(50, 1); + currow++; + sprintf(buffer, "End of List. %d Total Members\n", num_members - 1); + show_text(currow, STARTCOL, buffer); + currow++; + show_text(currow, STARTCOL, "Press any key to continue..."); + getchar(); + clrwin(DISPROW); } /****************************************************/ -display_menu(menu) - MENU *menu; +int display_menu(MENU *menu) { - int i; - - cls(); - title(menu->title); - mvcur(0, 0, STARTROW, STARTCOL); - refresh(); - for (i = 0; i <= menu->num_items - 1; i++) { - move(STARTROW + i, STARTCOL); - standend(); - addstr(menu->items[i]); - refresh(); + int i; + + cls(); + title(menu->title); + mvcur(0, 0, STARTROW, STARTCOL); + refresh(); + for (i = 0; i <= menu->num_items - 1; i++) + { + move(STARTROW + i, STARTCOL); + standend(); + addstr(menu->items[i]); + refresh(); + } + center_text(STARTROW + menu->num_items + 2, + "Enter a number, , or ."); + if (!level) + { + center_text(STARTROW + menu->num_items + 3, + "Press 'q' to exit, to confirm choice."); + } + else + { + center_text(STARTROW + menu->num_items + 3, + "Press 'q' to exit, 'r' for main menu, " + " to confirm choice."); } - center_text(STARTROW + menu->num_items + 2, - "Enter a number, , or ."); - if (!level) - center_text(STARTROW + menu->num_items + 3, - "Press 'q' to exit, to confirm choice."); - else - center_text(STARTROW + menu->num_items + 3, - "Press 'q' to exit, 'r' for main menu, to confirm choice."); - - if (!level) - highlight(main_menu); + + if (!level) + highlight(main_menu); } /****************************************************/ -pack_main_menu() +int pack_main_menu(void) { - char *buf; - - main_menu = (MENU *) malloc((unsigned) sizeof(MENU)); - main_menu->num_items = 7; - main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items); - - buf = calloc(50, 1); - (void) sprintf(buf, "Mail List Program for %s", username); - main_menu->title = strsave(buf); - main_menu->items[0] = strsave("1. Show all public mailing lists."); - main_menu->items[1] = strsave("2. Get all members of a mailing list."); - main_menu->items[2] = strsave("3. Display lists of which you are a member."); - main_menu->items[3] = strsave("4. Show description of list."); - main_menu->items[4] = strsave("5. Add yourself to a mailing list."); - main_menu->items[5] = strsave("6. Delete yourself from a mailing list."); - main_menu->items[6] = strsave("q. Quit."); + char *buf; + + main_menu = malloc(sizeof(MENU)); + main_menu->num_items = 7; + main_menu->items = malloc(sizeof(char *) * main_menu->num_items); + + buf = calloc(50, 1); + sprintf(buf, "Mail List Program for %s", username); + main_menu->title = strsave(buf); + main_menu->items[0] = strsave("1. Show all public mailing lists."); + main_menu->items[1] = strsave("2. Get all members of a mailing list."); + main_menu->items[2] = strsave("3. Display lists of which you are a member."); + main_menu->items[3] = strsave("4. Show description of list."); + main_menu->items[4] = strsave("5. Add yourself to a mailing list."); + main_menu->items[5] = strsave("6. Delete yourself from a mailing list."); + main_menu->items[6] = strsave("q. Quit."); } /****************************************************/ -pack_help_menu() +int pack_help_menu(void) { - help_menu = (MENU *) malloc((unsigned) sizeof(MENU)); - help_menu->num_items = 5; - help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items); - - help_menu->title = strsave("mailmaint is designed as a basic mail list administration program."); - help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like"); - help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the"); - help_menu->items[2] = strsave("program listmaint."); - help_menu->items[3] = strsave(" "); - help_menu->items[4] = strsave("Press any key to continue."); + help_menu = malloc(sizeof(MENU)); + help_menu->num_items = 5; + help_menu->items = malloc(sizeof(char *) * help_menu->num_items); + + help_menu->title = strsave("mailmaint is designed as a basic mail list administration program."); + help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like"); + help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the"); + help_menu->items[2] = strsave("program listmaint."); + help_menu->items[3] = strsave(" "); + help_menu->items[4] = strsave("Press any key to continue."); } /****************************************************/ -highlight(menu) - MENU *menu; +int highlight(MENU *menu) { - - - if (oldpos[level] != position[level]) { - move(STARTROW + oldpos[level] - 1, STARTCOL); - standend(); - addstr(menu->items[oldpos[level] - 1]); - refresh(); + if (oldpos[level] != position[level]) + { + move(STARTROW + oldpos[level] - 1, STARTCOL); + standend(); + addstr(menu->items[oldpos[level] - 1]); + refresh(); } - move(STARTROW + position[level] - 1, STARTCOL); - standout(); - addstr(menu->items[position[level] - 1]); - refresh(); - standend(); - refresh(); + move(STARTROW + position[level] - 1, STARTCOL); + standout(); + addstr(menu->items[position[level] - 1]); + refresh(); + standend(); + refresh(); } /****************************************************/ -title(buff) - char *buff; +int title(char *buff) { - move(0, MAX(0, (COLS - strlen(buff)) >> 1)); - standout(); - addstr(buff); - refresh(); - standend(); + move(0, MAX(0, (COLS - strlen(buff)) >> 1)); + standout(); + addstr(buff); + refresh(); + standend(); } /****************************************************/ -center_text(row, buff) - int row; - char *buff; +int center_text(int row, char *buff) { - move(row, MAX(0, (COLS - strlen(buff)) >> 1)); - addstr(buff); - refresh(); + move(row, MAX(0, (COLS - strlen(buff)) >> 1)); + addstr(buff); + refresh(); } /****************************************************/ -show_text(row, col, buff) - int row, col; - char *buff; +int show_text(int row, int col, char *buff) { - mvcur(0, 0, row, col); - addstr(buff); - refresh(); + mvcur(0, 0, row, col); + addstr(buff); + refresh(); } /****************************************************/ -erase_line(row, col) - int row, col; +int erase_line(int row, int col) { - char *buff; - int i; - - buff = calloc((unsigned)COLS, 1); - for (i = 0; i <= COLS - 2; i++) - buff[i] = ' '; - buff[i] = 0; /* just to be sure ! */ - move(row, col); - mvcur(0, 0, row, col); - addstr(buff); - refresh(); - free(buff); /* close mem. leak */ + char *buff; + int i; + + buff = calloc(COLS, 1); + for (i = 0; i <= COLS - 2; i++) + buff[i] = ' '; + buff[i] = 0; /* just to be sure ! */ + move(row, col); + mvcur(0, 0, row, col); + addstr(buff); + refresh(); + free(buff); /* close mem. leak */ } /****************************************************/ -cls() +int cls(void) { - clear(); - refresh(); + clear(); + refresh(); } /****************************************************/ -clrwin(erase_row) - int erase_row; +int clrwin(int erase_row) { - int i; - char *buff; - int maxcol; - - maxcol = COLS; -/* I don't understand the point of this limitation. -jweiss 3/25/94 - and I believe it was preventing the window from being cleared properly. - if (maxcol > 80) - maxcol = 80; */ /* limit width */ - - buff = calloc((unsigned)maxcol + 1, 1); - for (i = 0; i <= maxcol - 1; i++) - buff[i] = ' '; - buff[i] = 0; /* just to be sure ! */ - mvcur(0, 0, erase_row, STARTCOL); - refresh(); - for (i = erase_row; i <= currow - 1; i++) { - addstr(buff); - } + int i; + char *buff; + int maxcol; + + maxcol = COLS; + + buff = calloc(maxcol + 1, 1); + for (i = 0; i <= maxcol - 1; i++) + buff[i] = ' '; + buff[i] = 0; /* just to be sure ! */ + mvcur(0, 0, erase_row, STARTCOL); + refresh(); + for (i = erase_row; i <= currow - 1; i++) addstr(buff); - mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL); - refresh(); - free (buff); /* fix mem. leak */ + addstr(buff); + mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL); + refresh(); + free(buff); } /****************************************************/ - -static int -scream() +static int scream(void) { - com_err(whoami, status, "\nA Moira update returned a value -- programmer \ -botch\n"); - mr_disconnect(); - exit(1); - return(0); /* to keep compiler happy */ + com_err(whoami, status, + "\nA Moira update returned a value -- programmer botch\n"); + mr_disconnect(); + exit(1); + return 0; /* to keep compiler happy */ } /****************************************************/ -/*ARGSUSED*/ -static int -fetch_list_info(list, li) - char *list; - List_info *li; +static int fetch_list_info(char *list, List_info *li) { - char *argv[1]; + char *argv[1]; - argv[0] = list; - return mr_query("get_list_info", 1, argv, get_list_info, (char *) NULL); + argv[0] = list; + return mr_query("get_list_info", 1, argv, get_list_info, NULL); } -/* ARGSUSED */ -static int -get_list_info(argc, argv) - int argc; - char **argv; +static int get_list_info(int argc, char **argv) { - - if (current_li->acl_type) - free(current_li->acl_type); - current_li->acl_type = strsave(argv[7]); - if (current_li->acl_name) - free(current_li->acl_name); - current_li->acl_name = strsave(argv[8]); - if (current_li->desc) - free(current_li->desc); - current_li->desc = strsave(argv[9]); - if (current_li->modtime) - free(current_li->modtime); - current_li->modtime = strsave(argv[10]); - if (current_li->modby) - free(current_li->modby); - current_li->modby = strsave(argv[11]); - if (current_li->modwith) - free(current_li->modwith); - current_li->modwith = strsave(argv[12]); - return (0); + if (current_li->acl_type) + free(current_li->acl_type); + current_li->acl_type = strsave(argv[7]); + if (current_li->acl_name) + free(current_li->acl_name); + current_li->acl_name = strsave(argv[8]); + if (current_li->desc) + free(current_li->desc); + current_li->desc = strsave(argv[9]); + if (current_li->modtime) + free(current_li->modtime); + current_li->modtime = strsave(argv[10]); + if (current_li->modby) + free(current_li->modby); + current_li->modby = strsave(argv[11]); + if (current_li->modwith) + free(current_li->modwith); + current_li->modwith = strsave(argv[12]); + return 0; } - - /****************************************************/ /* Prompt the user for input */ -int -Prompt(prompt, buf, buflen, crok) - char *prompt; - char *buf; - int buflen; - int crok; +int Prompt(char *prompt, char *buf, int buflen, int crok) { - int c; - char *p; - - addstr(prompt); - refresh(); - for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) { - refresh(); - c = getchar() & 0x7f; - switch (c) { + int c; + char *p; + + addstr(prompt); + refresh(); + for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) + { + refresh(); + c = getchar() & 0x7f; + switch (c) + { case CTL('C'): - return 0; + return 0; case CTL('Z'): - return 0; + return 0; case CTL('L'): - cls(); - display_menu(main_menu); - return (0); + cls(); + display_menu(main_menu); + return 0; case '\n': case '\r': - if (crok) - display_buff("\n"); - *p = '\0'; - if (strlen(buf) < 1)/* only \n or \r in buff */ - return (-1); - else - return (1); + if (crok) + display_buff("\n"); + *p = '\0'; + if (strlen(buf) < 1) /* only \n or \r in buff */ + return -1; + else + return 1; case '\b': case '\177': - if (p > buf) { - p--; - printf("\b \b"); + if (p > buf) + { + p--; + printf("\b \b"); } - break; + break; case CTL('U'): case CTL('G'): case CTL('['): - while (p-- > buf) - printf("\b \b"); - p = buf; - break; + while (p-- > buf) + printf("\b \b"); + p = buf; + break; default: - if (abs(strlen(p) - strlen(buf)) >= buflen) { - printf("%c", 7); - break; + if (abs(strlen(p) - strlen(buf)) >= buflen) + { + printf("%c", 7); + break; } - if (isprint(c)) { - (void) addch(c); - *p++ = c; + if (isprint(c)) + { + addch(c); + *p++ = c; } - else - (void) putchar(CTL('G')); - break; + else + putchar(CTL('G')); + break; } } - return(0); + return 0; } @@ -960,24 +922,21 @@ Prompt(prompt, buf, buflen, crok) * curses instead of around it. */ -void -menu_err_hook(who, code, fmt, args) - const char *who; - long code; - const char *fmt; - va_list args; +void menu_err_hook(const char *who, long code, const char *fmt, va_list args) { - char buf[BUFSIZ], *cp; - - (void) strcpy(buf, who); - for (cp = buf; *cp; cp++); - *cp++ = ':'; - *cp++ = ' '; - if (code) { - (void) strcpy(cp, error_message(code)); - while (*cp) - cp++; + char buf[BUFSIZ], *cp; + + strcpy(buf, who); + for (cp = buf; *cp; cp++) + ; + *cp++ = ':'; + *cp++ = ' '; + if (code) + { + strcpy(cp, error_message(code)); + while (*cp) + cp++; } - vsprintf(cp, fmt, args); - display_buff(buf); + vsprintf(cp, fmt, args); + display_buff(buf); } diff --git a/clients/moira/TODO b/clients/moira/TODO index 9d702c13..e7942acd 100644 --- a/clients/moira/TODO +++ b/clients/moira/TODO @@ -11,7 +11,7 @@ Minor Changes ------------- - Add Kerberos code to register user. - + Major Fixes and Additions ------------------------- diff --git a/clients/moira/attach.c b/clients/moira/attach.c index c3ed591f..d1a7e2e1 100644 --- a/clients/moira/attach.c +++ b/clients/moira/attach.c @@ -4,10 +4,10 @@ /* This is the file attach.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. - * It Contains: Functions for maintaining data used by Hesiod - * to map courses/projects/users to their file systems, - * and maintain filesys info. - * + * It Contains: Functions for maintaining data used by Hesiod + * to map courses/projects/users to their file systems, + * and maintain filesys info. + * * Created: 5/4/88 * By: Chris D. Peterson * @@ -17,7 +17,7 @@ * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -43,7 +43,6 @@ #define ALIAS 3 #define NO_MACHINE ("[NONE]") -#define NO_MACHINE_BAD ("[NONE]") #define DEFAULT_TYPE ("AFS") #define DEFAULT_MACHINE DEFAULT_NONE @@ -58,31 +57,28 @@ /* Function Name: SetDefaults * Description: sets the default values for filesystem additions. - * Arguments: info - an array of char pointers to recieve defaults. + * Arguments: info - an array of char pointers to recieve defaults. * Returns: char ** (this array, now filled). */ -static char ** -SetDefaults(info, name) -char ** info; -char * name; +static char **SetDefaults(char **info, char *name) { - char buf[BUFSIZ]; - - info[FS_NAME] = Strsave(name); - info[FS_TYPE] = Strsave(DEFAULT_TYPE); - info[FS_MACHINE] = Strsave(DEFAULT_MACHINE); - info[FS_PACK] = Strsave(DEFAULT_PACK); - sprintf(buf, "/mit/%s", name); - info[FS_M_POINT] = Strsave(buf); - info[FS_ACCESS] = Strsave(DEFAULT_ACCESS); - info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS); - info[FS_OWNER] = Strsave(DEFAULT_OWNER); - info[FS_OWNERS] = Strsave(DEFAULT_OWNERS); - info[FS_CREATE] = Strsave(DEFAULT_CREATE); - info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE); - info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL; - return(info); + char buf[BUFSIZ]; + + info[FS_NAME] = Strsave(name); + info[FS_TYPE] = Strsave(DEFAULT_TYPE); + info[FS_MACHINE] = Strsave(DEFAULT_MACHINE); + info[FS_PACK] = Strsave(DEFAULT_PACK); + sprintf(buf, "/mit/%s", name); + info[FS_M_POINT] = Strsave(buf); + info[FS_ACCESS] = Strsave(DEFAULT_ACCESS); + info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS); + info[FS_OWNER] = Strsave(DEFAULT_OWNER); + info[FS_OWNERS] = Strsave(DEFAULT_OWNERS); + info[FS_CREATE] = Strsave(DEFAULT_CREATE); + info[FS_L_TYPE] = Strsave(DEFAULT_L_TYPE); + info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL; + return info; } /* Function Name: GetFSInfo @@ -92,49 +88,51 @@ char * name; * Returns: a pointer to the first element in the queue. */ -static struct qelem * -GetFSInfo(type, name) -int type; -char *name; +static struct qelem *GetFSInfo(int type, char *name) { - int stat; - struct qelem * elem = NULL; - char * args[5]; + int stat; + struct qelem *elem = NULL; + char *args[5]; - switch (type) { + switch (type) + { case LABEL: - if ( (stat = do_mr_query("get_filesys_by_label", 1, &name, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetFSInfo"); - return(NULL); + if ((stat = do_mr_query("get_filesys_by_label", 1, &name, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetFSInfo"); + return NULL; } - break; + break; case MACHINE: - if ( (stat = do_mr_query("get_filesys_by_machine", 1, &name, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetFSInfo"); - return(NULL); + if ((stat = do_mr_query("get_filesys_by_machine", 1, &name, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetFSInfo"); + return NULL; } - break; + break; case GROUP: - if ( (stat = do_mr_query("get_filesys_by_group", 1, &name, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetFSInfo"); - return(NULL); + if ((stat = do_mr_query("get_filesys_by_group", 1, &name, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetFSInfo"); + return NULL; } - break; + break; case ALIAS: - args[ALIAS_NAME] = name; - args[ALIAS_TYPE] = FS_ALIAS_TYPE; - args[ALIAS_TRANS] = "*"; - if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo, - (char *) &elem)) != 0) { - com_err(program_name, stat, " in get_alias."); - return(NULL); + args[ALIAS_NAME] = name; + args[ALIAS_TYPE] = FS_ALIAS_TYPE; + args[ALIAS_TRANS] = "*"; + if ((stat = do_mr_query("get_alias", 3, args, StoreInfo, + (char *) &elem))) + { + com_err(program_name, stat, " in get_alias."); + return NULL; } } - return(QueueTop(elem)); + return QueueTop(elem); } /* Function Name: PrintFSAlias @@ -143,29 +141,26 @@ char *name; * Returns: the name of the filesys - used be QueryLoop(). */ -static char * -PrintFSAlias(info) -char ** info; +static char *PrintFSAlias(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME], - info[ALIAS_TRANS]); - Put_message(buf); - return(info[ALIAS_NAME]); + sprintf(buf, "Alias: %-25s Filesystem: %s", info[ALIAS_NAME], + info[ALIAS_TRANS]); + Put_message(buf); + return info[ALIAS_NAME]; } static int fsgCount = 1; -static char * -PrintFSGMembers(info) -char ** info; +static char *PrintFSGMembers(char **info) { - char print_buf[BUFSIZ]; + char print_buf[BUFSIZ]; - sprintf(print_buf, " %d. Filesystem: %-32s (sort key: %s)", fsgCount++, info[0], info[1]); - Put_message(print_buf); - return(info[0]); + sprintf(print_buf, " %d. Filesystem: %-32s (sort key: %s)", + fsgCount++, info[0], info[1]); + Put_message(print_buf); + return info[0]; } @@ -175,96 +170,96 @@ char ** info; * Returns: none. */ -static char * -PrintFSInfo(info) -char ** info; +static char *PrintFSInfo(char **info) { - char print_buf[BUFSIZ]; - - FORMFEED; - - if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL")) { - int stat; - struct qelem *elem = NULL; - - if (!strcmp(info[FS_TYPE], "MUL")) - sprintf(print_buf,"%20s Multiple Filesystem: %s", " ", info[FS_NAME]); - else - sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]); - Put_message(print_buf); - - sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]); - Put_message(print_buf); - sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], - info[FS_MODWITH]); - Put_message(print_buf); - Put_message("Containing the filesystems (in order):"); - if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME], - StoreInfo, (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) - Put_message(" [no members]"); - else - com_err(program_name, stat, " in PrintFSInfo"); - } else { - fsgCount = 1; - Loop(QueueTop(elem), (void *) PrintFSGMembers); - FreeQueue(elem); + char print_buf[BUFSIZ]; + + FORMFEED; + + if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL")) + { + int stat; + struct qelem *elem = NULL; + + if (!strcmp(info[FS_TYPE], "MUL")) + sprintf(print_buf, "%20s Multiple Filesystem: %s", " ", info[FS_NAME]); + else + sprintf(print_buf, "%20s Filesystem Group: %s", " ", info[FS_NAME]); + Put_message(print_buf); + + sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]); + Put_message(print_buf); + sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], + info[FS_MODWITH]); + Put_message(print_buf); + Put_message("Containing the filesystems (in order):"); + if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME], + StoreInfo, (char *)&elem))) + { + if (stat == MR_NO_MATCH) + Put_message(" [no members]"); + else + com_err(program_name, stat, " in PrintFSInfo"); + } + else + { + fsgCount = 1; + Loop(QueueTop(elem), PrintFSGMembers); + FreeQueue(elem); } - } else { - sprintf(print_buf,"%20s Filesystem: %s", " ", info[FS_NAME]); - Put_message(print_buf); - sprintf(print_buf,"Type: %-40s Machine: %-15s", - info[FS_TYPE], info[FS_MACHINE]); - Put_message(print_buf); - sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ", - info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]); - Put_message(print_buf); - sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]); - Put_message(print_buf); - sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s", - info[FS_OWNER], info[FS_OWNERS]); - Put_message(print_buf); - sprintf(print_buf, "Update Fileserver: %-27s Locker Type: %s", - atoi(info[FS_CREATE]) ? "ON" : "OFF", - info[FS_L_TYPE]); - Put_message(print_buf); - sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], - info[FS_MODWITH]); - Put_message(print_buf); } - return(info[FS_NAME]); + else + { + sprintf(print_buf, "%20s Filesystem: %s", " ", info[FS_NAME]); + Put_message(print_buf); + sprintf(print_buf, "Type: %-40s Machine: %-15s", + info[FS_TYPE], info[FS_MACHINE]); + Put_message(print_buf); + sprintf(print_buf, "Default Access: %-2s Packname: %-17s Mountpoint %s ", + info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]); + Put_message(print_buf); + sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]); + Put_message(print_buf); + sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s", + info[FS_OWNER], info[FS_OWNERS]); + Put_message(print_buf); + sprintf(print_buf, "Update Fileserver: %-27s Locker Type: %s", + atoi(info[FS_CREATE]) ? "ON" : "OFF", info[FS_L_TYPE]); + Put_message(print_buf); + sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], + info[FS_MODWITH]); + Put_message(print_buf); + } + return info[FS_NAME]; } -char *canonicalize_cell(c) -char *c; +char *canonicalize_cell(char *c) { - struct stat stbuf; - char path[512]; - int count; - - sprintf(path, "/afs/%s", c); - if (lstat(path, &stbuf) || !stbuf.st_mode&S_IFLNK) - return(c); - count = readlink(path, path, sizeof(path)); - if (count < 1) return(c); - path[count] = 0; - free(c); - return(strsave(path)); + struct stat stbuf; + char path[512]; + int count; + + sprintf(path, "/afs/%s", c); + if (lstat(path, &stbuf) || !stbuf.st_mode & S_IFLNK) + return c; + count = readlink(path, path, sizeof(path)); + if (count < 1) + return c; + path[count] = 0; + free(c); + return strsave(path); } -int GetAliasValue(argc, argv, retval) -int argc; -char **argv; -char **retval; +int GetAliasValue(int argc, char **argv, char **retval) { - *retval = strsave(argv[2]); - return(MR_CONT); + *retval = strsave(argv[2]); + return MR_CONT; } /* Function Name: AskFSInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. @@ -272,152 +267,178 @@ char **retval; * Returns: none. */ -static char ** -AskFSInfo(info, name) -char ** info; -Bool name; +static char **AskFSInfo(char **info, Bool name) { - char temp_buf[BUFSIZ], *newname, access_type[32]; - int fsgroup = 0, newdefaults = 0; - - Put_message(""); - sprintf(temp_buf, "Changing Attributes of filesystem %s.", - info[FS_NAME]); - Put_message(temp_buf); - Put_message(""); - - if (name) { - newname = Strsave(info[FS_NAME]); - if (GetValueFromUser("The new name for this filesystem", - &newname) == SUB_ERROR) - return(NULL); + char temp_buf[BUFSIZ], *newname, access_type[32]; + int fsgroup = 0, newdefaults = 0; + + Put_message(""); + sprintf(temp_buf, "Changing Attributes of filesystem %s.", info[FS_NAME]); + Put_message(temp_buf); + Put_message(""); + + if (name) + { + newname = Strsave(info[FS_NAME]); + if (GetValueFromUser("The new name for this filesystem", + &newname) == SUB_ERROR) + return NULL; } - strcpy(temp_buf, info[FS_TYPE]); - if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) == - SUB_ERROR) - return(NULL); - if (!strcasecmp(info[FS_TYPE], "FSGROUP") || - !strcasecmp(info[FS_TYPE], "MUL")) - fsgroup++; - if (strcasecmp(info[FS_TYPE], temp_buf)) - newdefaults++; - if (fsgroup) { - free(info[FS_MACHINE]); - info[FS_MACHINE] = Strsave(NO_MACHINE); - } else { - if (!strcasecmp(info[FS_TYPE], "AFS")) { - if (!name || newdefaults) { - free(info[FS_MACHINE]); - info[FS_MACHINE] = strsave(DEFAULT_CELL); + strcpy(temp_buf, info[FS_TYPE]); + if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) == + SUB_ERROR) + return NULL; + if (!strcasecmp(info[FS_TYPE], "FSGROUP") || + !strcasecmp(info[FS_TYPE], "MUL")) + fsgroup++; + if (strcasecmp(info[FS_TYPE], temp_buf)) + newdefaults++; + if (fsgroup) + { + free(info[FS_MACHINE]); + info[FS_MACHINE] = Strsave(NO_MACHINE); + } + else + { + if (!strcasecmp(info[FS_TYPE], "AFS")) + { + if (!name || newdefaults) + { + free(info[FS_MACHINE]); + info[FS_MACHINE] = strsave(DEFAULT_CELL); } - if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) == + if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) == SUB_ERROR) - return(NULL); - info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]); - } else { - if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) == - SUB_ERROR) - return(NULL); - info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]); + return NULL; + info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]); + } + else + { + if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) == + SUB_ERROR) + return NULL; + info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]); } } - if (!fsgroup) { - if (!strcasecmp(info[FS_TYPE], "AFS")) { - char *path, *args[3], *p; - int status, depth, i; - if (GetTypeFromUser("Filesystem's lockertype", "lockertype", - &info[FS_L_TYPE]) == SUB_ERROR) - return(NULL); - if (!name || newdefaults) { - free(info[FS_PACK]); - lowercase(info[FS_MACHINE]); - sprintf(temp_buf, "%s:%s", info[FS_MACHINE], info[FS_L_TYPE]); - args[0] = temp_buf; - args[1] = "AFSPATH"; - args[2] = "*"; - path = "???"; - status = do_mr_query("get_alias", 3, args, - GetAliasValue, &path); - if (status == MR_SUCCESS) { - p = strchr(path, ':'); - if (p) { - *p = 0; - depth = atoi(++p); - } else - depth = 0; - sprintf(temp_buf, "/afs/%s/%s", info[FS_MACHINE], path); - if (depth >= 0) { - for (p=info[FS_NAME]; *p&&(p-info[FS_NAME])= 0) + { + for (p = info[FS_NAME]; + *p && (p - info[FS_NAME]) < depth; p++) + { + if (islower(*p)) + { + strcat(temp_buf, "/x"); + temp_buf[strlen(temp_buf) - 1] = *p; + } + else + { + sprintf(temp_buf, "/afs/%s/%s/other", + info[FS_MACHINE], path); + break; } } - } else if (depth == -1) { - if (isdigit(info[FS_NAME][0])) { - strcat(temp_buf, "/"); - depth = strlen(temp_buf); - for (p = info[FS_NAME]; *p && isdigit(*p); p++) { - temp_buf[depth++] = *p; - temp_buf[depth] = 0; + } + else if (depth == -1) + { + if (isdigit(info[FS_NAME][0])) + { + strcat(temp_buf, "/"); + depth = strlen(temp_buf); + for (p = info[FS_NAME]; *p && isdigit(*p); p++) + { + temp_buf[depth++] = *p; + temp_buf[depth] = 0; } - } else - strcat(temp_buf, "/other"); - } else { + } + else + strcat(temp_buf, "/other"); + } + else + { /* no default */ } - strcat(temp_buf, "/"); - strcat(temp_buf, info[FS_NAME]); - free(path); - } else { - sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE], - lowercase(info[FS_L_TYPE]), info[FS_NAME]); + strcat(temp_buf, "/"); + strcat(temp_buf, info[FS_NAME]); + free(path); } - info[FS_PACK] = strsave(temp_buf); + else + { + sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE], + lowercase(info[FS_L_TYPE]), info[FS_NAME]); + } + info[FS_PACK] = strsave(temp_buf); } } - if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]) == - SUB_ERROR) - return(NULL); - sprintf(access_type, "fs_access_%s", info[FS_TYPE]); - if (GetTypeFromUser("Filesystem's Default Access", access_type, - &info[FS_ACCESS]) == SUB_ERROR) - return(NULL); + if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]) == + SUB_ERROR) + return NULL; + sprintf(access_type, "fs_access_%s", info[FS_TYPE]); + if (GetTypeFromUser("Filesystem's Default Access", access_type, + &info[FS_ACCESS]) == SUB_ERROR) + return NULL; } - if (GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]) - == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]) == - SUB_ERROR) - return(NULL); - if (!fsgroup) - if (GetYesNoValueFromUser("Propagate changes to fileserver", - &info[FS_CREATE]) == SUB_ERROR) - return(NULL); - if (strcasecmp(info[FS_TYPE], "AFS")) { - if (GetTypeFromUser("Filesystem's lockertype", "lockertype", - &info[FS_L_TYPE]) == SUB_ERROR) - return(NULL); + if (GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]) + == SUB_ERROR) + return NULL; + if (GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]) == + SUB_ERROR) + return NULL; + if (!fsgroup) + if (GetYesNoValueFromUser("Propagate changes to fileserver", + &info[FS_CREATE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[FS_TYPE], "AFS")) + { + if (GetTypeFromUser("Filesystem's lockertype", "lockertype", + &info[FS_L_TYPE]) == SUB_ERROR) + return NULL; } - FreeAndClear(&info[FS_MODTIME], TRUE); - FreeAndClear(&info[FS_MODBY], TRUE); - FreeAndClear(&info[FS_MODWITH], TRUE); + FreeAndClear(&info[FS_MODTIME], TRUE); + FreeAndClear(&info[FS_MODBY], TRUE); + FreeAndClear(&info[FS_MODWITH], TRUE); - if (name) /* slide the newname into the #2 slot. */ - SlipInNewName(info, newname); + if (name) /* slide the newname into the #2 slot. */ + SlipInNewName(info, newname); - return(info); + return info; } @@ -429,18 +450,14 @@ Bool name; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -GetFS(argc, argv) -int argc; -char **argv; +int GetFS(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetFSInfo(LABEL, argv[1]); /* get info. */ - Loop(top, (void *) PrintFSInfo); - FreeQueue(top); /* clean the queue. */ - return (DM_NORMAL); + top = GetFSInfo(LABEL, argv[1]); /* get info. */ + Loop(top, PrintFSInfo); + FreeQueue(top); /* clean the queue. */ + return DM_NORMAL; } /* Function Name: GetFSM @@ -449,52 +466,46 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -GetFSM(argc, argv) -int argc; -char **argv; +int GetFSM(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - argv[1] = canonicalize_hostname(strsave(argv[1])); - top = GetFSInfo(MACHINE, argv[1]); /* get info. */ - Loop(top, (void *) PrintFSInfo); - FreeQueue(top); /* clean the queue. */ - return (DM_NORMAL); + argv[1] = canonicalize_hostname(strsave(argv[1])); + top = GetFSInfo(MACHINE, argv[1]); /* get info. */ + Loop(top, PrintFSInfo); + FreeQueue(top); /* clean the queue. */ + return DM_NORMAL; } /* Function Name: RealDeleteFS * Description: Does the real deletion work. * Arguments: info - array of char *'s containing all useful info. - * one_item - a Boolean that is true if only one item + * one_item - a Boolean that is true if only one item * in queue that dumped us here. * Returns: none. */ -void -RealDeleteFS(info, one_item) -char ** info; -Bool one_item; +void RealDeleteFS(char **info, Bool one_item) { - int stat; - char temp_buf[BUFSIZ]; - -/* - * Deletetions are performed if the user hits 'y' on a list of multiple - * filesystem, or if the user confirms on a unique alias. - */ - sprintf(temp_buf, "Are you sure that you want to delete filesystem %s", - info[FS_NAME]); - if(!one_item || Confirm(temp_buf)) { - if ( (stat = do_mr_query("delete_filesys", 1, - &info[FS_NAME], Scream, NULL)) != 0) - com_err(program_name, stat, " filesystem not deleted."); - else - Put_message("Filesystem deleted."); + int stat; + char temp_buf[BUFSIZ]; + + /* + * Deletions are performed if the user hits 'y' on a list of multiple + * filesystem, or if the user confirms on a unique alias. + */ + sprintf(temp_buf, "Are you sure that you want to delete filesystem %s", + info[FS_NAME]); + if (!one_item || Confirm(temp_buf)) + { + if ((stat = do_mr_query("delete_filesys", 1, + &info[FS_NAME], Scream, NULL))) + com_err(program_name, stat, " filesystem not deleted."); + else + Put_message("Filesystem deleted."); } - else - Put_message("Filesystem not deleted."); + else + Put_message("Filesystem not deleted."); } /* Function Name: DeleteFS @@ -503,63 +514,56 @@ Bool one_item; * Returns: none. */ -/* ARGSUSED */ - -int -DeleteFS(argc, argv) -int argc; -char **argv; +int DeleteFS(int argc, char **argv) { - struct qelem *elem = GetFSInfo(LABEL, argv[1]); - QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem"); + struct qelem *elem = GetFSInfo(LABEL, argv[1]); + QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem"); - FreeQueue(elem); - return (DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: RealChangeFS * Description: performs the actual change to the filesys. - * Arguments: info - the information + * Arguments: info - the information * junk - an unused boolean. * Returns: none. */ -/* ARGSUSED. */ -static void -RealChangeFS(info, junk) -char ** info; -Bool junk; +static void RealChangeFS(char **info, Bool junk) { - int stat; - char ** args; - extern Menu nfsphys_menu; - - args = AskFSInfo(info, TRUE); - if (args == NULL) { - Put_message("Aborted."); - return; + int stat; + char **args; + extern Menu nfsphys_menu; + + args = AskFSInfo(info, TRUE); + if (!args) + { + Put_message("Aborted."); + return; } - stat = do_mr_query("update_filesys", CountArgs(args), args, - NullFunc, NULL); - switch (stat) { + stat = do_mr_query("update_filesys", CountArgs(args), args, NullFunc, NULL); + switch (stat) + { case MR_NFS: - Put_message("That NFS filesystem is not exported."); - if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) { - Do_menu(&nfsphys_menu, 0, NULL); - if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE) - == TRUE) { - if (stat = do_mr_query("update_filesys", CountArgs(args), args, - NullFunc, NULL)) - com_err(program_name, stat, " filesystem not updated"); - else - Put_message("filesystem sucessfully updated."); + Put_message("That NFS filesystem is not exported."); + if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) + { + Do_menu(&nfsphys_menu, 0, NULL); + if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE) == TRUE) + { + if ((stat = do_mr_query("update_filesys", CountArgs(args), args, + NullFunc, NULL))) + com_err(program_name, stat, " filesystem not updated"); + else + Put_message("filesystem sucessfully updated."); } } - break; + break; case MR_SUCCESS: - break; + break; default: - com_err(program_name, stat, " in UpdateFS"); + com_err(program_name, stat, " in UpdateFS"); } } @@ -569,17 +573,13 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ChangeFS(argc, argv) -char **argv; -int argc; +int ChangeFS(int argc, char **argv) { - struct qelem *elem = GetFSInfo(LABEL, argv[1]); - QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem"); + struct qelem *elem = GetFSInfo(LABEL, argv[1]); + QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem"); - FreeQueue(elem); - return (DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: AddFS @@ -588,152 +588,157 @@ int argc; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddFS(argc, argv) -char **argv; -int argc; +int AddFS(int argc, char **argv) { - char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ]; - int stat; - extern Menu nfsphys_menu; - - if ( !ValidName(argv[1]) ) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_filesys_by_label", 1, argv + 1, - NullFunc, NULL)) == 0) { - Put_message ("A Filesystem by that name already exists."); - return(DM_NORMAL); - } else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in AddFS"); - return(DM_NORMAL); - } - - if ((args = AskFSInfo(SetDefaults(info, argv[1]), FALSE )) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ]; + int stat; + extern Menu nfsphys_menu; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if (!(stat = do_mr_query("get_filesys_by_label", 1, argv + 1, + NullFunc, NULL))) + { + Put_message ("A Filesystem by that name already exists."); + return DM_NORMAL; + } + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in AddFS"); + return DM_NORMAL; + } + + if (!(args = AskFSInfo(SetDefaults(info, argv[1]), FALSE))) + { + Put_message("Aborted."); + return DM_NORMAL; } - stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL); - switch (stat) { + stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL); + switch (stat) + { case MR_NFS: - Put_message("That NFS filesystem is not exported."); - if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) { - Do_menu(&nfsphys_menu, 0, NULL); - if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE) - == TRUE) { - if (stat = do_mr_query("add_filesys", CountArgs(args), args, - NullFunc, NULL)) - com_err(program_name, stat, " in AddFS"); - else - Put_message("Created."); - } + Put_message("That NFS filesystem is not exported."); + if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) + { + Do_menu(&nfsphys_menu, 0, NULL); + if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE) + == TRUE) { + if ((stat = do_mr_query("add_filesys", CountArgs(args), args, + NullFunc, NULL))) + com_err(program_name, stat, " in AddFS"); + else + Put_message("Created."); + } } - break; + break; case MR_SUCCESS: - break; + break; default: - com_err(program_name, stat, " in AddFS"); + com_err(program_name, stat, " in AddFS"); } - if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) { - static char *val[] = {"def_quota", NULL}; - static char *def_quota = NULL; - char *argv[Q_QUOTA + 1]; - struct qelem *top = NULL; - - if (def_quota == NULL) { - stat = do_mr_query("get_value", CountArgs(val), val, - StoreInfo, (char *) &top); - if (stat != MR_SUCCESS) { - com_err(program_name, stat, " getting default quota"); - } else { - top = QueueTop(top); - def_quota = Strsave(((char **)top->q_data)[0]); - FreeQueue(top); + if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) + { + static char *val[] = {"def_quota", NULL}; + static char *def_quota = NULL; + char *argv[Q_QUOTA + 1]; + struct qelem *top = NULL; + + if (!def_quota) + { + stat = do_mr_query("get_value", CountArgs(val), val, + StoreInfo, (char *) &top); + if (stat != MR_SUCCESS) + com_err(program_name, stat, " getting default quota"); + else + { + top = QueueTop(top); + def_quota = Strsave(((char **)top->q_data)[0]); + FreeQueue(top); } } - if (def_quota != NULL) { - sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)", - info[FS_NAME], def_quota, info[FS_NAME]); - if (YesNoQuestion(buf, 1) == TRUE) { - argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME]; - if (!strcmp(info[FS_TYPE], "NFS")) - argv[Q_TYPE] = "USER"; - else - argv[Q_TYPE] = "ANY"; - argv[Q_QUOTA] = def_quota; - if ((stat = do_mr_query("add_quota", Q_QUOTA+1, argv, Scream, - (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, stat, " while adding quota"); - } + if (def_quota) + { + sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)", + info[FS_NAME], def_quota, info[FS_NAME]); + if (YesNoQuestion(buf, 1) == TRUE) + { + argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME]; + if (!strcmp(info[FS_TYPE], "NFS")) + argv[Q_TYPE] = "USER"; + else + argv[Q_TYPE] = "ANY"; + argv[Q_QUOTA] = def_quota; + if ((stat = do_mr_query("add_quota", Q_QUOTA + 1, argv, Scream, + NULL))) + com_err(program_name, stat, " while adding quota"); } } - } else if (stat == MR_SUCCESS) { - if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1) - == TRUE) { - parsed_argc = 1; - parsed_argv[0] = info[FS_NAME]; - AddQuota(); + } + else if (stat == MR_SUCCESS) + { + if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1) == TRUE) + { + parsed_argc = 1; + parsed_argv[0] = info[FS_NAME]; + AddQuota(); } } - FreeInfo(info); - return (DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } /* Function Name: SortAfter - * Description: choose a sortkey to cause an item to be added after + * Description: choose a sortkey to cause an item to be added after * the count element in the queue * Arguments: queue of filesys names & sortkeys, queue count pointer * Returns: sort key to use. */ -/* ARGSUSED */ -char * -SortAfter(elem, count) -struct qelem *elem; -int count; +char *SortAfter(struct qelem *elem, int count) { - char *prev, *next, prevnext, *key, keybuf[9]; - - /* first find the two keys we need to insert between */ - prev = "A"; - for (; count > 0; count--) { - prev = ((char **)elem->q_data)[1]; - if (elem->q_forw) - elem = elem->q_forw; - else - break; - } - if (count > 0) - next = "Z"; - else - next = ((char **)elem->q_data)[1]; - - /* now copy the matching characters */ - for (key = keybuf; *prev && *prev == *next; next++) { - *key++ = *prev++; + char *prev, *next, prevnext, *key, keybuf[9]; + + /* first find the two keys we need to insert between */ + prev = "A"; + for (; count > 0; count--) + { + prev = ((char **)elem->q_data)[1]; + if (elem->q_forw) + elem = elem->q_forw; + else + break; } - - /* and set the last character */ - if (*prev == 0) - *prev = prevnext = 'A'; - else - prevnext = prev[1]; - if (prevnext == 0) - prevnext = 'A'; - if (*next == 0) - *next = 'Z'; - if (*next - *prev > 1) { - *key++ = (*next + *prev)/2; - } else { - *key++ = *prev; - *key++ = (prevnext + 'Z')/2; + if (count > 0) + next = "Z"; + else + next = ((char **)elem->q_data)[1]; + + /* now copy the matching characters */ + for (key = keybuf; *prev && *prev == *next; next++) + *key++ = *prev++; + + /* and set the last character */ + if (*prev == 0) + *prev = prevnext = 'A'; + else + prevnext = prev[1]; + if (prevnext == 0) + prevnext = 'A'; + if (*next == 0) + *next = 'Z'; + if (*next - *prev > 1) + *key++ = (*next + *prev) / 2; + else + { + *key++ = *prev; + *key++ = (prevnext + 'Z') / 2; } - *key = 0; - return(Strsave(keybuf)); + *key = 0; + return Strsave(keybuf); } /* Function Name: AddFSToGroup @@ -742,51 +747,53 @@ int count; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddFSToGroup(argc, argv) -char **argv; -int argc; +int AddFSToGroup(int argc, char **argv) { - int stat, count; - struct qelem *elem = NULL; - char buf[BUFSIZ], *args[5], *bufp; - - if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo, - (char *)&elem)) != 0) { - if (stat != MR_NO_MATCH) - com_err(program_name, stat, " in AddFSToGroup"); + int stat, count; + struct qelem *elem = NULL; + char buf[BUFSIZ], *args[5], *bufp; + + if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo, + (char *)&elem))) + { + if (stat != MR_NO_MATCH) + com_err(program_name, stat, " in AddFSToGroup"); } - if (elem == NULL) { - args[0] = argv[1]; - args[1] = argv[2]; - args[2] = "M"; - stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); - if (stat) - com_err(program_name, stat, " in AddFSToGroup"); - return(DM_NORMAL); + if (elem == NULL) + { + args[0] = argv[1]; + args[1] = argv[2]; + args[2] = "M"; + stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); + if (stat) + com_err(program_name, stat, " in AddFSToGroup"); + return DM_NORMAL; } - elem = QueueTop(elem); - fsgCount = 1; - Loop(elem, (void *) PrintFSGMembers); - sprintf(buf, "%d", QueueCount(elem)); - bufp = Strsave(buf); - if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR) - return(DM_NORMAL); - count = atoi(bufp); - free(bufp); - args[2] = SortAfter(elem, count); - - FreeQueue(QueueTop(elem)); - args[0] = argv[1]; - args[1] = argv[2]; - stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); - if (stat == MR_EXISTS) { - Put_message("That filesystem is already a member of the group."); - Put_message("Use the order command if you want to change the sorting order."); - } else if (stat) - com_err(program_name, stat, " in AddFSToGroup"); - return(DM_NORMAL); + elem = QueueTop(elem); + fsgCount = 1; + Loop(elem, PrintFSGMembers); + sprintf(buf, "%d", QueueCount(elem)); + bufp = Strsave(buf); + if (GetValueFromUser("Enter number of filesystem it should follow " + "(0 to make it first):", &bufp) == SUB_ERROR) + return DM_NORMAL; + count = atoi(bufp); + free(bufp); + args[2] = SortAfter(elem, count); + + FreeQueue(QueueTop(elem)); + args[0] = argv[1]; + args[1] = argv[2]; + stat = do_mr_query("add_filesys_to_fsgroup", 3, args, Scream, NULL); + if (stat == MR_EXISTS) + { + Put_message("That filesystem is already a member of the group."); + Put_message("Use the order command if you want to change the " + "sorting order."); + } + else if (stat) + com_err(program_name, stat, " in AddFSToGroup"); + return DM_NORMAL; } @@ -796,23 +803,18 @@ int argc; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -RemoveFSFromGroup(argc, argv) -char **argv; -int argc; +int RemoveFSFromGroup(int argc, char **argv) { - int stat; - char buf[BUFSIZ]; - - sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]); - if (!Confirm(buf)) - return(DM_NORMAL); - if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv+1, - Scream, NULL)) != 0) { - com_err(program_name, stat, ", not removed."); - } - return(DM_NORMAL); + int stat; + char buf[BUFSIZ]; + + sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]); + if (!Confirm(buf)) + return DM_NORMAL; + if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv + 1, + Scream, NULL))) + com_err(program_name, stat, ", not removed."); + return DM_NORMAL; } /* Function Name: ChangeFSGroupOrder @@ -821,87 +823,97 @@ int argc; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ChangeFSGroupOrder(argc, argv) -char **argv; -int argc; +int ChangeFSGroupOrder(int argc, char **argv) { - int stat, src, dst, i; - struct qelem *elem = NULL, *top, *tmpelem; - char buf[BUFSIZ], *bufp, *args[3]; - - if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo, - (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) { - sprintf(buf, - "Ether %s is not a filesystem group or it has no members", - argv[1]); - Put_message(buf); - } else - com_err(program_name, stat, " in ChangeFSGroupOrder"); - return(DM_NORMAL); + int stat, src, dst, i; + struct qelem *elem = NULL, *top, *tmpelem; + char buf[BUFSIZ], *bufp, *args[3]; + + if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo, + (char *)&elem))) + { + if (stat == MR_NO_MATCH) + { + sprintf(buf, + "Ether %s is not a filesystem group or it has no members", + argv[1]); + Put_message(buf); + } + else + com_err(program_name, stat, " in ChangeFSGroupOrder"); + return DM_NORMAL; } - top = QueueTop(elem); - fsgCount = 1; - Loop(top, (void *) PrintFSGMembers); - while (1) { - bufp = Strsave("1"); - if (GetValueFromUser("Enter number of the filesystem to move:", - &bufp) == SUB_ERROR) - return(DM_NORMAL); - src = atoi(bufp); - free(bufp); - if (src < 0) { - Put_message("You must enter a positive number (or 0 to abort)."); - continue; - } else if (src == 0) { - Put_message("Aborted."); - return(DM_NORMAL); + top = QueueTop(elem); + fsgCount = 1; + Loop(top, PrintFSGMembers); + while (1) + { + bufp = Strsave("1"); + if (GetValueFromUser("Enter number of the filesystem to move:", + &bufp) == SUB_ERROR) + return DM_NORMAL; + src = atoi(bufp); + free(bufp); + if (src < 0) + { + Put_message("You must enter a positive number (or 0 to abort)."); + continue; } - for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw); - if (i > 0) { - Put_message("You entered a number that is too high"); - continue; + else if (src == 0) + { + Put_message("Aborted."); + return DM_NORMAL; } - break; + for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw) + ; + if (i > 0) + { + Put_message("You entered a number that is too high"); + continue; + } + break; } - while (1) { - bufp = Strsave("0"); - if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR) - return(DM_NORMAL); - dst = atoi(bufp); - free(bufp); - if (src == dst || src == dst + 1) { - Put_message("That has no effect on the sorting order!"); - return(DM_NORMAL); + while (1) + { + bufp = Strsave("0"); + if (GetValueFromUser("Enter number of filesystem it should follow " + "(0 to make it first):", &bufp) == SUB_ERROR) + return DM_NORMAL; + dst = atoi(bufp); + free(bufp); + if (src == dst || src == dst + 1) + { + Put_message("That has no effect on the sorting order!"); + return DM_NORMAL; } - if (dst < 0) { - Put_message("You must enter a non-negative number."); - continue; + if (dst < 0) + { + Put_message("You must enter a non-negative number."); + continue; } - for (tmpelem = top, i = dst; - i-- > 1 && tmpelem->q_forw; - tmpelem = tmpelem->q_forw); - if (i > 0) { - Put_message("You entered a number that is too high"); - continue; + for (tmpelem = top, i = dst; i-- > 1 && tmpelem->q_forw; + tmpelem = tmpelem->q_forw) + ; + if (i > 0) + { + Put_message("You entered a number that is too high"); + continue; } - break; + break; } - args[2] = SortAfter(top, dst); - args[0] = argv[1]; - args[1] = ((char **)elem->q_data)[0]; - if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args, - Scream, NULL)) != 0) { - com_err(program_name, stat, " in ChangeFSGroupOrder"); - return(DM_NORMAL); - } - if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args, - Scream, NULL)) != 0) { - com_err(program_name, stat, " in ChangeFSGroupOrder"); + args[2] = SortAfter(top, dst); + args[0] = argv[1]; + args[1] = ((char **)elem->q_data)[0]; + if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args, + Scream, NULL))) + { + com_err(program_name, stat, " in ChangeFSGroupOrder"); + return DM_NORMAL; } - return(DM_NORMAL); + if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args, + Scream, NULL))) + com_err(program_name, stat, " in ChangeFSGroupOrder"); + return DM_NORMAL; } @@ -915,19 +927,15 @@ int argc; * this will work correctly. */ -/* ARGSUSED */ -int -GetFSAlias(argc, argv) -int argc; -char **argv; +int GetFSAlias(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetFSInfo(ALIAS, argv[1]); - Put_message(" "); /* blank line. */ - Loop(top, (void *) PrintFSAlias); - FreeQueue(top); - return(DM_NORMAL); + top = GetFSInfo(ALIAS, argv[1]); + Put_message(" "); /* blank line. */ + Loop(top, (void *) PrintFSAlias); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: CreateFSAlias @@ -935,96 +943,93 @@ char **argv; * Arguments: argc, argv - name of alias in argv[1]. * Returns: DM_NORMAL. * NOTES: This requires (name, type, transl) I get {name, translation} - * from the user. I provide type, which is well-known. + * from the user. I provide type, which is well-known. */ -/* ARGSUSED */ -int -CreateFSAlias(argc, argv) -int argc; -char **argv; +int CreateFSAlias(int argc, char **argv) { - register int stat; - struct qelem *elem, *top; - char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info; - - elem = NULL; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[ALIAS_NAME] = Strsave(argv[1]); - args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE); - args[ALIAS_TRANS] = Strsave("*"); - -/* - * Check to see if this alias already exists in the database, if so then - * print out values, free memory used and then exit. - */ - - if ( (stat = do_mr_query("get_alias", 3, args, StoreInfo, - (char *)&elem)) == 0) { - top = elem = QueueTop(elem); - while (elem != NULL) { - info = (char **) elem->q_data; - sprintf(buf,"The alias: %s currently describes the filesystem %s", - info[ALIAS_NAME], info[ALIAS_TRANS]); - Put_message(buf); - elem = elem->q_forw; + register int stat; + struct qelem *elem, *top; + char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info; + + elem = NULL; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + args[ALIAS_NAME] = Strsave(argv[1]); + args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE); + args[ALIAS_TRANS] = Strsave("*"); + + /* + * Check to see if this alias already exists in the database, if so then + * print out values, free memory used and then exit. + */ + + if (!(stat = do_mr_query("get_alias", 3, args, StoreInfo, + (char *)&elem))) + { + top = elem = QueueTop(elem); + while (elem) + { + info = (char **) elem->q_data; + sprintf(buf, "The alias: %s currently describes the filesystem %s", + info[ALIAS_NAME], info[ALIAS_TRANS]); + Put_message(buf); + elem = elem->q_forw; } - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } - else if ( stat != MR_NO_MATCH) { - com_err(program_name, stat, " in CreateFSAlias."); - return(DM_NORMAL); + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in CreateFSAlias."); + return DM_NORMAL; } - args[ALIAS_TRANS]= Strsave(""); - args[ALIAS_END] = NULL; - if (GetValueFromUser("Which filesystem will this alias point to?", - &args[ALIAS_TRANS]) == SUB_ERROR) - return(DM_NORMAL); + args[ALIAS_TRANS] = Strsave(""); + args[ALIAS_END] = NULL; + if (GetValueFromUser("Which filesystem will this alias point to?", + &args[ALIAS_TRANS]) == SUB_ERROR) + return DM_NORMAL; - if ( (stat = do_mr_query("add_alias", 3, args, NullFunc, NULL)) != 0) - com_err(program_name, stat, " in CreateFSAlias."); + if ((stat = do_mr_query("add_alias", 3, args, NullFunc, NULL))) + com_err(program_name, stat, " in CreateFSAlias."); - FreeInfo(args); - return (DM_NORMAL); + FreeInfo(args); + return DM_NORMAL; } - + /* Function Name: RealDeleteFSAlias * Description: Does the real deletion work. * Arguments: info - array of char *'s containing all useful info. - * one_item - a Boolean that is true if only one item + * one_item - a Boolean that is true if only one item * in queue that dumped us here. * Returns: none. */ -void -RealDeleteFSAlias(info, one_item) -char ** info; -Bool one_item; +void RealDeleteFSAlias(char **info, Bool one_item) { - int stat; - char temp_buf[BUFSIZ]; - -/* - * Deletetions are performed if the user hits 'y' on a list of multiple - * filesystem, or if the user confirms on a unique alias. - */ - sprintf(temp_buf, - "Are you sure that you want to delete the filesystem alias %s", - info[ALIAS_NAME]); - if(!one_item || Confirm(temp_buf)) { - if ( (stat = do_mr_query("delete_alias", CountArgs(info), - info, Scream, NULL)) != 0 ) - com_err(program_name, stat, " filesystem alias not deleted."); - else - Put_message("Filesystem alias deleted."); + int stat; + char temp_buf[BUFSIZ]; + + /* + * Deletions are performed if the user hits 'y' on a list of multiple + * filesystem, or if the user confirms on a unique alias. + */ + sprintf(temp_buf, + "Are you sure that you want to delete the filesystem alias %s", + info[ALIAS_NAME]); + if (!one_item || Confirm(temp_buf)) + { + if ((stat = do_mr_query("delete_alias", CountArgs(info), + info, Scream, NULL))) + com_err(program_name, stat, " filesystem alias not deleted."); + else + Put_message("Filesystem alias deleted."); } - else - Put_message("Filesystem alias not deleted."); + else + Put_message("Filesystem alias not deleted."); } /* Function Name: DeleteFSAlias @@ -1032,20 +1037,16 @@ Bool one_item; * Arguments: argc, argv - name of alias in argv[1]. * Returns: DM_NORMAL. * NOTES: This requires (name, type, transl) I get {name, translation} - * from the user. I provide type, which is well-known. + * from the user. I provide type, which is well-known. */ -/* ARGSUSED */ -int -DeleteFSAlias(argc, argv) -int argc; -char **argv; +int DeleteFSAlias(int argc, char **argv) { - struct qelem *elem = GetFSInfo(ALIAS, argv[1]); - QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias, - "Delete the Filesystem Alias"); - FreeQueue(elem); - return (DM_NORMAL); + struct qelem *elem = GetFSInfo(ALIAS, argv[1]); + QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias, + "Delete the Filesystem Alias"); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: AttachHelp @@ -1054,24 +1055,23 @@ char **argv; * Returns: DM_NORMAL. */ -int -AttachHelp() +int AttachHelp(void) { - static char *message[] = { - "These are the options:", - "", - "get - get information about a filesystem.", - "add - add a new filesystem to the data base.", - "update - update the information in the database on a filesystem.", - "delete - delete a filesystem from the database.", - "check - check information about association of a name and a filesys.", - "alias - associate a name with a filesystem.", - "unalias - disassociate a name with a filesystem.", - "verbose - toggle the request for delete confirmation.", - NULL, - }; - - return(PrintHelp(message)); + static char *message[] = { + "These are the options:", + "", + "get - get information about a filesystem.", + "add - add a new filesystem to the data base.", + "update - update the information in the database on a filesystem.", + "delete - delete a filesystem from the database.", + "check - check information about association of a name and a filesys.", + "alias - associate a name with a filesystem.", + "unalias - disassociate a name with a filesystem.", + "verbose - toggle the request for delete confirmation.", + NULL, + }; + + return PrintHelp(message); } /* Function Name: FSGroupHelp @@ -1080,21 +1080,20 @@ AttachHelp() * Returns: DM_NORMAL. */ -int -FSGroupHelp() +int FSGroupHelp(void) { - static char *message[] = { - "A filesystem group is a named sorted list of filesystems.", - "", - "To create, modify, or delete a group itself, use the menu above", - " this one, and manipulate a filesystem of type FSGROUP.", - "Options here are:", - " get - get info about a group and show its members", - " add - add a new member to a group.", - " remove - remove a member from a group.", - " order - change the sorting order of a group.", - NULL - }; - - return(PrintHelp(message)); + static char *message[] = { + "A filesystem group is a named sorted list of filesystems.", + "", + "To create, modify, or delete a group itself, use the menu above", + " this one, and manipulate a filesystem of type FSGROUP.", + "Options here are:", + " get - get info about a group and show its members", + " add - add a new member to a group.", + " remove - remove a member from a group.", + " order - change the sorting order of a group.", + NULL + }; + + return PrintHelp(message); } diff --git a/clients/moira/cluster.c b/clients/moira/cluster.c index 72f796e5..9e1132d6 100644 --- a/clients/moira/cluster.c +++ b/clients/moira/cluster.c @@ -4,18 +4,18 @@ /* This is the file cluster.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. - * It Contains: - * + * It Contains: + * * Created: 4/22/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -30,9 +30,7 @@ #include #include #include -#ifdef POSIX #include -#endif #include #include @@ -59,21 +57,23 @@ #define S_DEFAULT_LOW "18.0.0.20" #define S_DEFAULT_HIGH "18.0.2.249" -static char *states[] = { "Reserved (0)", - "Active (1)", - "None (2)", - "Deleted (3)" }; - -static char *MacState(state) -int state; +static char *states[] = { + "Reserved (0)", + "Active (1)", + "None (2)", + "Deleted (3)" +}; + +static char *MacState(int state) { - static char buf[BUFSIZ]; + static char buf[BUFSIZ]; - if (state < 0 || state > 3) { - sprintf(buf, "Unknown (%d)", state); - return(buf); + if (state < 0 || state > 3) + { + sprintf(buf, "Unknown (%d)", state); + return buf; } - return(states[state]); + return states[state]; } @@ -87,26 +87,24 @@ int state; * Returns: info - the array. */ -static char ** -SetMachineDefaults(info, name) -char ** info, *name; +static char **SetMachineDefaults(char **info, char *name) { - info[M_NAME] = Strsave(name); - info[M_VENDOR] = Strsave(M_DEFAULT_TYPE); - info[M_MODEL] = Strsave(M_DEFAULT_TYPE); - info[M_OS] = Strsave(M_DEFAULT_TYPE); - info[M_LOC] = Strsave(M_DEFAULT_TYPE); - info[M_CONTACT] = Strsave(M_DEFAULT_TYPE); - info[M_USE] = Strsave("0"); - info[M_STAT] = Strsave("1"); - info[M_SUBNET] = Strsave("NONE"); - info[M_ADDR] = Strsave("unique"); - info[M_OWNER_TYPE] = Strsave("NONE"); - info[M_OWNER_NAME] = Strsave("NONE"); - info[M_ACOMMENT] = Strsave(""); - info[M_OCOMMENT] = Strsave(""); - info[15] = info[16] = NULL; - return(info); + info[M_NAME] = Strsave(name); + info[M_VENDOR] = Strsave(M_DEFAULT_TYPE); + info[M_MODEL] = Strsave(M_DEFAULT_TYPE); + info[M_OS] = Strsave(M_DEFAULT_TYPE); + info[M_LOC] = Strsave(M_DEFAULT_TYPE); + info[M_CONTACT] = Strsave(M_DEFAULT_TYPE); + info[M_USE] = Strsave("0"); + info[M_STAT] = Strsave("1"); + info[M_SUBNET] = Strsave("NONE"); + info[M_ADDR] = Strsave("unique"); + info[M_OWNER_TYPE] = Strsave("NONE"); + info[M_OWNER_NAME] = Strsave("NONE"); + info[M_ACOMMENT] = Strsave(""); + info[M_OCOMMENT] = Strsave(""); + info[15] = info[16] = NULL; + return info; } /* Function Name: SetClusterDefaults @@ -116,15 +114,13 @@ char ** info, *name; * Returns: info - the array. */ -static char ** -SetClusterDefaults(info, name) -char ** info, *name; +static char **SetClusterDefaults(char **info, char *name) { - info[C_NAME] = Strsave(name); - info[C_DESCRIPT] = Strsave(C_DEFAULT_DESCRIPT); - info[C_LOCATION] = Strsave(C_DEFAULT_LOCATION); - info[C_MODBY] = info[C_MODTIME] = info[C_MODWITH] = info[C_END] = NULL; - return(info); + info[C_NAME] = Strsave(name); + info[C_DESCRIPT] = Strsave(C_DEFAULT_DESCRIPT); + info[C_LOCATION] = Strsave(C_DEFAULT_LOCATION); + info[C_MODBY] = info[C_MODTIME] = info[C_MODWITH] = info[C_END] = NULL; + return info; } /* Function Name: SetSubnetDefaults @@ -134,105 +130,102 @@ char ** info, *name; * Returns: info - the array. */ -static char ** -SetSubnetDefaults(info, name) -char ** info, *name; +static char **SetSubnetDefaults(char **info, char *name) { - char buf[256]; - - info[C_NAME] = Strsave(name); - info[SN_DESC] = Strsave(""); - sprintf(buf, "%ld", ntohl(inet_addr("18.255.0.0"))); - info[SN_ADDRESS] = Strsave(buf); - sprintf(buf, "%ld", ntohl(inet_addr("255.255.0.0"))); - info[SN_MASK] = Strsave(buf); - sprintf(buf, "%ld", ntohl(inet_addr(S_DEFAULT_LOW))); - info[SN_LOW] = Strsave(buf); - sprintf(buf, "%ld", ntohl(inet_addr(S_DEFAULT_HIGH))); - info[SN_HIGH] = Strsave(buf); - info[SN_PREFIX] = Strsave(""); - info[SN_ACE_TYPE] = Strsave("LIST"); - info[SN_ACE_NAME] = Strsave("network"); - info[SN_MODBY] = info[SN_MODTIME] = info[SN_MODWITH] = info[SN_END] = NULL; - return(info); + char buf[256]; + + info[C_NAME] = Strsave(name); + info[SN_DESC] = Strsave(""); + sprintf(buf, "%ld", ntohl(inet_addr("18.255.0.0"))); + info[SN_ADDRESS] = Strsave(buf); + sprintf(buf, "%ld", ntohl(inet_addr("255.255.0.0"))); + info[SN_MASK] = Strsave(buf); + sprintf(buf, "%ld", ntohl(inet_addr(S_DEFAULT_LOW))); + info[SN_LOW] = Strsave(buf); + sprintf(buf, "%ld", ntohl(inet_addr(S_DEFAULT_HIGH))); + info[SN_HIGH] = Strsave(buf); + info[SN_PREFIX] = Strsave(""); + info[SN_ACE_TYPE] = Strsave("LIST"); + info[SN_ACE_NAME] = Strsave("network"); + info[SN_MODBY] = info[SN_MODTIME] = info[SN_MODWITH] = info[SN_END] = NULL; + return info; } /* -------------------- General Functions -------------------- */ static char aliasbuf[256]; -static char * -PrintAliases(info) -char **info; +static char *PrintAliases(char **info) { - if (strlen(aliasbuf) == 0) - sprintf(aliasbuf, "Aliases: %s", info[0]); - else { - strcat(aliasbuf, ", "); - strcat(aliasbuf, info[0]); + if (strlen(aliasbuf) == 0) + sprintf(aliasbuf, "Aliases: %s", info[0]); + else + { + strcat(aliasbuf, ", "); + strcat(aliasbuf, info[0]); } } /* Function Name: PrintMachInfo - * Description: This function Prints out the Machine info in + * Description: This function Prints out the Machine info in * a coherent form. * Arguments: info - array of information about a machine. * Returns: The name of the Machine */ -static char * -PrintMachInfo(info) -char ** info; +static char *PrintMachInfo(char **info) { - char buf[BUFSIZ], tbuf[256]; - char *args[3]; - struct qelem *elem = NULL; - int stat; - - Put_message(""); - sprintf(buf, "Machine: %s", info[M_NAME]); - Put_message(buf); - args[0] = "*"; - args[1] = info[M_NAME]; - if ((stat = do_mr_query("get_hostalias", 2, args, StoreInfo, (char *)&elem)) - != 0) { - if (stat != MR_NO_MATCH) - com_err(program_name, stat, " looking up aliases"); - } else { - aliasbuf[0] = 0; - Loop(QueueTop(elem), (void *) PrintAliases); - FreeQueue(elem); - Put_message(aliasbuf); + char buf[BUFSIZ], tbuf[256]; + char *args[3]; + struct qelem *elem = NULL; + int stat; + + Put_message(""); + sprintf(buf, "Machine: %s", info[M_NAME]); + Put_message(buf); + args[0] = "*"; + args[1] = info[M_NAME]; + if ((stat = do_mr_query("get_hostalias", 2, args, StoreInfo, (char *)&elem))) + { + if (stat != MR_NO_MATCH) + com_err(program_name, stat, " looking up aliases"); + } + else + { + aliasbuf[0] = 0; + Loop(QueueTop(elem), (void *) PrintAliases); + FreeQueue(elem); + Put_message(aliasbuf); } - sprintf(tbuf, "%s %s", info[M_OWNER_TYPE], - strcmp(info[M_OWNER_TYPE], "NONE") ? info[M_OWNER_NAME] : ""); - sprintf(buf, "Address: %-16s Network: %-16s", - info[M_ADDR], info[M_SUBNET]); - Put_message(buf); - sprintf(buf, "Owner: %-16s Use data: %s", tbuf, info[M_INUSE]); - Put_message(buf); - sprintf(buf, "Status: %-16s Changed: %s", - MacState(atoi(info[M_STAT])), info[M_STAT_CHNG]); - Put_message(buf); - Put_message(""); - - sprintf(buf, "Vendor: %-16s Model: %-20s OS: %s", - info[M_VENDOR], info[M_MODEL], info[M_OS]); - Put_message(buf); - sprintf(buf, "Location: %-16s Contact: %-20s Opt: %s", - info[M_LOC], info[M_CONTACT], info[M_USE]); - Put_message(buf); - sprintf(buf, "\nAdm cmt: %s", info[M_ACOMMENT]); - Put_message(buf); - sprintf(buf, "Op cmt: %s", info[M_OCOMMENT]); - Put_message(buf); - Put_message(""); - sprintf(buf, "Created by %s on %s", info[M_CREATOR], info[M_CREATED]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[M_MODBY], info[M_MODTIME], info[M_MODWITH]); - Put_message(buf); - return(info[M_NAME]); + sprintf(tbuf, "%s %s", info[M_OWNER_TYPE], + strcmp(info[M_OWNER_TYPE], "NONE") ? info[M_OWNER_NAME] : ""); + sprintf(buf, "Address: %-16s Network: %-16s", + info[M_ADDR], info[M_SUBNET]); + Put_message(buf); + sprintf(buf, "Owner: %-16s Use data: %s", tbuf, info[M_INUSE]); + Put_message(buf); + sprintf(buf, "Status: %-16s Changed: %s", + MacState(atoi(info[M_STAT])), info[M_STAT_CHNG]); + Put_message(buf); + Put_message(""); + + sprintf(buf, "Vendor: %-16s Model: %-20s OS: %s", + info[M_VENDOR], info[M_MODEL], info[M_OS]); + Put_message(buf); + sprintf(buf, "Location: %-16s Contact: %-20s Opt: %s", + info[M_LOC], info[M_CONTACT], info[M_USE]); + Put_message(buf); + sprintf(buf, "\nAdm cmt: %s", info[M_ACOMMENT]); + Put_message(buf); + sprintf(buf, "Op cmt: %s", info[M_OCOMMENT]); + Put_message(buf); + Put_message(""); + sprintf(buf, "Created by %s on %s", info[M_CREATOR], info[M_CREATED]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[M_MODBY], info[M_MODTIME], info[M_MODWITH]); + Put_message(buf); + return info[M_NAME]; } /* Function Name: PrintCname @@ -241,40 +234,36 @@ char ** info; * Returns: The name of the alias. */ -static char * -PrintCname(info) -char ** info; +static char *PrintCname(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf, "Alias: %-32s Canonical Name: %s", info[0], info[1]); - Put_message(buf); - return(info[0]); + sprintf(buf, "Alias: %-32s Canonical Name: %s", info[0], info[1]); + Put_message(buf); + return info[0]; } /* Function Name: PrintClusterInfo - * Description: This function Prints out the cluster info + * Description: This function Prints out the cluster info * in a coherent form. * Arguments: info - array of information about a cluster. * Returns: The name of the cluster. */ -static char * -PrintClusterInfo(info) -char ** info; +static char *PrintClusterInfo(char **info) { - char buf[BUFSIZ]; - - Put_message(""); - sprintf(buf, "Cluster: %s", info[C_NAME]); - Put_message(buf); - sprintf(buf, "Description: %s", info[C_DESCRIPT]); - Put_message(buf); - sprintf(buf, "Location: %s", info[C_LOCATION]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[C_MODBY], info[C_MODTIME], info[C_MODWITH]); - Put_message(buf); - return(info[C_NAME]); + char buf[BUFSIZ]; + + Put_message(""); + sprintf(buf, "Cluster: %s", info[C_NAME]); + Put_message(buf); + sprintf(buf, "Description: %s", info[C_DESCRIPT]); + Put_message(buf); + sprintf(buf, "Location: %s", info[C_LOCATION]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[C_MODBY], info[C_MODTIME], info[C_MODWITH]); + Put_message(buf); + return info[C_NAME]; } /* Function Name: PrintClusterData @@ -283,17 +272,15 @@ char ** info; * Returns: The name of the cluster. */ -static char * -PrintClusterData(info) -char ** info; +static char *PrintClusterData(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - Put_message(""); - sprintf(buf, "Cluster: %-20s Label: %-15s Data: %s", - info[CD_NAME], info[CD_LABEL], info[CD_DATA]); - Put_message(buf); - return(info[CD_NAME]); + Put_message(""); + sprintf(buf, "Cluster: %-20s Label: %-15s Data: %s", + info[CD_NAME], info[CD_LABEL], info[CD_DATA]); + Put_message(buf); + return info[CD_NAME]; } /* Function Name: PrintMCMap @@ -302,58 +289,54 @@ char ** info; * Returns: none */ -static char * -PrintMCMap(info) -char ** info; +static char *PrintMCMap(char **info) { - char buf[BUFSIZ]; - sprintf(buf, "Cluster: %-30s Machine: %-20s", - info[MAP_CLUSTER], info[MAP_MACHINE]); - Put_message(buf); - return(""); /* Used by QueryLoop(). */ + char buf[BUFSIZ]; + sprintf(buf, "Cluster: %-30s Machine: %-20s", + info[MAP_CLUSTER], info[MAP_MACHINE]); + Put_message(buf); + return ""; /* Used by QueryLoop(). */ } /* Function Name: PrintSubnetInfo - * Description: This function Prints out the subnet info + * Description: This function Prints out the subnet info * in a coherent form. * Arguments: info - array of information about a subnet. * Returns: The name of the subnet. */ -static char * -PrintSubnetInfo(info) -char ** info; +static char *PrintSubnetInfo(char **info) { - char buf[BUFSIZ]; - struct in_addr addr, mask, low, high; - - Put_message(""); - sprintf(buf, " Network: %s", info[SN_NAME]); - Put_message(buf); - sprintf(buf, " Description: %s", info[SN_DESC]); - Put_message(buf); - addr.s_addr = htonl(atoi(info[SN_ADDRESS])); - mask.s_addr = htonl(atoi(info[SN_MASK])); - low.s_addr = htonl(atoi(info[SN_LOW])); - high.s_addr = htonl(atoi(info[SN_HIGH])); - /* screwy sequence is here because inet_ntoa returns a pointer to - a static buf. If it were all one sprintf, the last value would - appear 4 times. */ - sprintf(buf, " Address: %s Mask: ", inet_ntoa(addr)); - strcat(buf, inet_ntoa(mask)); - strcat(buf, "\n High: "); - strcat(buf, inet_ntoa(high)); - strcat(buf, " Low: "); - strcat(buf, inet_ntoa(low)); - Put_message(buf); - sprintf(buf, "Hostname prefix: %s", info[SN_PREFIX]); - Put_message(buf); - sprintf(buf, " Owner: %s %s\n", info[SN_ACE_TYPE], - strcmp(info[SN_ACE_TYPE],"NONE") ? info[SN_ACE_NAME] : ""); - Put_message(buf); - sprintf(buf,MOD_FORMAT,info[SN_MODBY],info[SN_MODTIME],info[SN_MODWITH]); - Put_message(buf); - return(info[SN_NAME]); + char buf[BUFSIZ]; + struct in_addr addr, mask, low, high; + + Put_message(""); + sprintf(buf, " Network: %s", info[SN_NAME]); + Put_message(buf); + sprintf(buf, " Description: %s", info[SN_DESC]); + Put_message(buf); + addr.s_addr = htonl(atoi(info[SN_ADDRESS])); + mask.s_addr = htonl(atoi(info[SN_MASK])); + low.s_addr = htonl(atoi(info[SN_LOW])); + high.s_addr = htonl(atoi(info[SN_HIGH])); + /* screwy sequence is here because inet_ntoa returns a pointer to + a static buf. If it were all one sprintf, the last value would + appear 4 times. */ + sprintf(buf, " Address: %s Mask: ", inet_ntoa(addr)); + strcat(buf, inet_ntoa(mask)); + strcat(buf, "\n High: "); + strcat(buf, inet_ntoa(high)); + strcat(buf, " Low: "); + strcat(buf, inet_ntoa(low)); + Put_message(buf); + sprintf(buf, "Hostname prefix: %s", info[SN_PREFIX]); + Put_message(buf); + sprintf(buf, " Owner: %s %s\n", info[SN_ACE_TYPE], + strcmp(info[SN_ACE_TYPE], "NONE") ? info[SN_ACE_NAME] : ""); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[SN_MODBY], info[SN_MODTIME], info[SN_MODWITH]); + Put_message(buf); + return info[SN_NAME]; } /* Function Name: GetMCInfo. @@ -364,82 +347,89 @@ char ** info; * Returns: the top element of a queue containing the data or NULL. */ -struct qelem * -GetMCInfo(type, name1, name2) -int type; -char * name1, *name2; +struct qelem *GetMCInfo(int type, char *name1, char *name2) { + int stat; + struct qelem *elem = NULL; + char *args[5]; - int stat; - struct qelem * elem = NULL; - char * args[5]; - - switch (type) { + switch (type) + { case MACHINE: - args[0] = name1; - args[1] = args[2] = args[3] = "*"; - if ( (stat = do_mr_query("get_host", 4, args, - StoreInfo, (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) { - char buf[128]; - sprintf(buf, "Machine '%s' is not in the database.", name1); - Put_message(buf); - } else - com_err(program_name, stat, " in get_machine."); - return(NULL); + args[0] = name1; + args[1] = args[2] = args[3] = "*"; + if ((stat = do_mr_query("get_host", 4, args, + StoreInfo, (char *)&elem))) + { + if (stat == MR_NO_MATCH) + { + char buf[128]; + sprintf(buf, "Machine '%s' is not in the database.", name1); + Put_message(buf); + } + else + com_err(program_name, stat, " in get_machine."); + return NULL; } - break; + break; case CNAME: - args[0] = name1; - args[1] = name2; - if ( (stat = do_mr_query("get_hostalias", 2, args, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in get_hostalias."); - return(NULL); + args[0] = name1; + args[1] = name2; + if ((stat = do_mr_query("get_hostalias", 2, args, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in get_hostalias."); + return NULL; } - break; + break; case SUBNET: - if ( (stat = do_mr_query("get_subnet", 1, &name1, - StoreInfo, (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) { - char buf[128]; - sprintf(buf, "Network '%s' is not in the database.", name1); - Put_message(buf); - } else - com_err(program_name, stat, " in get_subnet."); - return(NULL); + if ((stat = do_mr_query("get_subnet", 1, &name1, + StoreInfo, (char *)&elem))) + { + if (stat == MR_NO_MATCH) + { + char buf[128]; + sprintf(buf, "Network '%s' is not in the database.", name1); + Put_message(buf); + } + else + com_err(program_name, stat, " in get_subnet."); + return NULL; } - break; + break; case CLUSTER: - if ( (stat = do_mr_query("get_cluster", 1, &name1, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in get_cluster."); - return(NULL); + if ((stat = do_mr_query("get_cluster", 1, &name1, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in get_cluster."); + return NULL; } - break; + break; case MAP: - args[MAP_MACHINE] = name1; - args[MAP_CLUSTER] = name2; - if ( (stat = do_mr_query("get_machine_to_cluster_map", 2, args, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in get_machine_to_cluster_map."); - return(NULL); + args[MAP_MACHINE] = name1; + args[MAP_CLUSTER] = name2; + if ((stat = do_mr_query("get_machine_to_cluster_map", 2, args, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in get_machine_to_cluster_map."); + return NULL; } - break; + break; case DATA: - args[CD_NAME] = name1; - args[CD_LABEL] = name2; - if ( (stat = do_mr_query("get_cluster_data", 2, args, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in get_cluster_data."); - return(NULL); + args[CD_NAME] = name1; + args[CD_LABEL] = name2; + if ((stat = do_mr_query("get_cluster_data", 2, args, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in get_cluster_data."); + return NULL; } } - return(QueueTop(elem)); + return QueueTop(elem); } /* Function Name: AskMCDInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the information to ask about * type - type of information - MACHINE @@ -449,219 +439,226 @@ char * name1, *name2; * Returns: none. */ -char ** -AskMCDInfo(info, type, name) -char ** info; -int type; -Bool name; +char **AskMCDInfo(char **info, int type, Bool name) { - char temp_buf[BUFSIZ], *newname, *oldnewname; + char temp_buf[BUFSIZ], *newname, *oldnewname; - switch (type) { + switch (type) + { case MACHINE: - sprintf(temp_buf, "\nSetting the information for the Machine %s...", - info[M_NAME]); - break; + sprintf(temp_buf, "\nSetting the information for the Machine %s...", + info[M_NAME]); + break; case SUBNET: - sprintf(temp_buf, "Setting the information for the Network %s...", - info[SN_NAME]); - break; + sprintf(temp_buf, "Setting the information for the Network %s...", + info[SN_NAME]); + break; case CLUSTER: - sprintf(temp_buf, "Setting the information for the Cluster %s...", - info[C_NAME]); - break; + sprintf(temp_buf, "Setting the information for the Cluster %s...", + info[C_NAME]); + break; case DATA: - sprintf(temp_buf, "Setting the Data for the Cluster %s...", - info[CD_NAME]); - break; + sprintf(temp_buf, "Setting the Data for the Cluster %s...", + info[CD_NAME]); + break; } - Put_message(temp_buf); + Put_message(temp_buf); - if (name) { - switch (type) { + if (name) + { + switch (type) + { case MACHINE: - newname = Strsave(info[M_NAME]); - if (GetValueFromUser("The new name for this machine? ", &newname) == - SUB_ERROR) - return(NULL); - oldnewname = Strsave(newname); - newname = canonicalize_hostname(newname); - if (strcasecmp(newname, oldnewname) && *oldnewname != '"') { - sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'\n", - oldnewname, newname); - Put_message(temp_buf); + newname = Strsave(info[M_NAME]); + if (GetValueFromUser("The new name for this machine? ", &newname) == + SUB_ERROR) + return NULL; + oldnewname = Strsave(newname); + newname = canonicalize_hostname(newname); + if (strcasecmp(newname, oldnewname) && *oldnewname != '"') + { + sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'\n", + oldnewname, newname); + Put_message(temp_buf); } - free(oldnewname); - break; + free(oldnewname); + break; case SUBNET: - newname = Strsave(info[SN_NAME]); - if (GetValueFromUser("The new name for this network? ", - &newname) == SUB_ERROR) - return(NULL); - break; + newname = Strsave(info[SN_NAME]); + if (GetValueFromUser("The new name for this network? ", &newname) == + SUB_ERROR) + return NULL; + break; case CLUSTER: - newname = Strsave(info[C_NAME]); - if (GetValueFromUser("The new name for this cluster? ", - &newname) == SUB_ERROR) - return(NULL); - break; + newname = Strsave(info[C_NAME]); + if (GetValueFromUser("The new name for this cluster? ", &newname) == + SUB_ERROR) + return NULL; + break; default: - Put_message("Unknown type in AskMCDInfo, programmer botch"); - return(NULL); + Put_message("Unknown type in AskMCDInfo, programmer botch"); + return NULL; } } - switch(type) { + switch (type) + { case MACHINE: - if (GetValueFromUser("Machine's vendor", &info[M_VENDOR]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Machine's model", &info[M_MODEL]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Machine's operating system", &info[M_OS]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Machine's location", &info[M_LOC]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Machine's contact", &info[M_CONTACT]) == - SUB_ERROR) - return(NULL); -#ifdef notdef - if (GetValueFromUser("Machine's use code", &info[M_USE]) == SUB_ERROR) - return(NULL); -#endif - while (1) { - int i; - if (GetValueFromUser("Machine's status (? for help)", + if (GetValueFromUser("Machine's vendor", &info[M_VENDOR]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Machine's model", &info[M_MODEL]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Machine's operating system", &info[M_OS]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Machine's location", &info[M_LOC]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Machine's contact", &info[M_CONTACT]) == + SUB_ERROR) + return NULL; + while (1) + { + int i; + if (GetValueFromUser("Machine's status (? for help)", &info[M_STAT]) == SUB_ERROR) - return(NULL); - if (isdigit(info[M_STAT][0])) break; - Put_message("Valid status numbers:"); - for (i = 0; i < 4; i++) Put_message(states[i]); + return NULL; + if (isdigit(info[M_STAT][0])) + break; + Put_message("Valid status numbers:"); + for (i = 0; i < 4; i++) + Put_message(states[i]); + } + + /* there appears to be some argument mismatch between the client + * and the server.. so here is this argument shuffler. + * I have since modified this to always shuffle the arguments.. + * not just do so when performing a modify all fields request. + * The SetMachinedefaults() has been changed to reflect this. + * pray for us and may we attain enlightenment through structures. + */ + + if (name) + { + /* info did not come from SetMachineDefaults(), which does not + * initialize entry 8 (M_STAT_CHNG), therefore we can + * free it. + */ + /* This is an update of an existing machine and the structure + * was filled in thru a query to the db which does fill in this + * field. + */ + free(info[8]); } - - /* there appears to be some argument mismatch between the client - * and the server.. so here is this argument shuffler. - * I have since modified this to always shuffle the arguments.. - * not just do so when performing a modify all fields request. - * The SetMachinedefaults() has been changed to reflect this. - * pray for us and may we attain enlightenment through structures. - */ - - - if(name) { - /* info did not come from SetMachineDefaults(), which does not - * initialize entry 8 (M_STAT_CHNG), therefore we can - * free it. - */ - /* This is an update of an existing machine and the structure - * was filled in thru a query to the db which does fill in this - * field. - */ - free(info[8]); + + info[8] = info[M_SUBNET]; + info[9] = info[M_ADDR]; + info[10] = info[M_OWNER_TYPE]; + info[11] = info[M_OWNER_NAME]; + info[12] = info[M_ACOMMENT]; + info[13] = info[M_OCOMMENT]; + + if (name) + { + if (GetValueFromUser("Machine's network (or 'none')", &info[8]) + == SUB_ERROR) + return NULL; } - - info[8] = info[M_SUBNET]; - info[9] = info[M_ADDR]; - info[10] = info[M_OWNER_TYPE]; - info[11] = info[M_OWNER_NAME]; - info[12] = info[M_ACOMMENT]; - info[13] = info[M_OCOMMENT]; - - if(name) - if (GetValueFromUser("Machine's network (or 'none')", &info[8]) - == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Machine's address (or 'unassigned' or 'unique')", - &info[9]) == SUB_ERROR) - return(NULL); - if (GetTypeFromUser("Machine's owner type", "ace_type", &info[10]) == - SUB_ERROR) - return(NULL); - if (strcmp(info[10], "NONE") && - GetValueFromUser("Owner's Name", &info[11]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Administrative comment", &info[12]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Operational comment", &info[13]) == SUB_ERROR) - return(NULL); - info[14] = NULL; - FreeAndClear(&info[15], TRUE); - FreeAndClear(&info[16], TRUE); - break; + if (GetValueFromUser("Machine's address (or 'unassigned' or 'unique')", + &info[9]) == SUB_ERROR) + return NULL; + if (GetTypeFromUser("Machine's owner type", "ace_type", &info[10]) == + SUB_ERROR) + return NULL; + if (strcmp(info[10], "NONE") && + GetValueFromUser("Owner's Name", &info[11]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Administrative comment", &info[12]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Operational comment", &info[13]) == SUB_ERROR) + return NULL; + info[14] = NULL; + FreeAndClear(&info[15], TRUE); + FreeAndClear(&info[16], TRUE); + break; case SUBNET: - if (GetValueFromUser("Network description", &info[SN_DESC]) == SUB_ERROR) - return(NULL); - if (GetAddressFromUser("Network address", &info[SN_ADDRESS]) == SUB_ERROR) - return(NULL); - if (GetAddressFromUser("Network mask", &info[SN_MASK]) == SUB_ERROR) - return(NULL); - if (atoi(info[SN_LOW]) == ntohl(inet_addr(S_DEFAULT_LOW))) { - struct in_addr low; - unsigned long mask, addr; - - addr = atoi(info[SN_ADDRESS]); - mask = atoi(info[SN_MASK]); - low.s_addr = atoi(info[SN_LOW]); - low.s_addr = (low.s_addr & ~mask) | (addr & mask); - free(info[SN_LOW]); - sprintf(temp_buf, "%d", low.s_addr); - info[SN_LOW] = strsave(temp_buf); + if (GetValueFromUser("Network description", &info[SN_DESC]) == SUB_ERROR) + return NULL; + if (GetAddressFromUser("Network address", &info[SN_ADDRESS]) == SUB_ERROR) + return NULL; + if (GetAddressFromUser("Network mask", &info[SN_MASK]) == SUB_ERROR) + return NULL; + if (atoi(info[SN_LOW]) == ntohl(inet_addr(S_DEFAULT_LOW))) + { + struct in_addr low; + unsigned long mask, addr; + + addr = atoi(info[SN_ADDRESS]); + mask = atoi(info[SN_MASK]); + low.s_addr = atoi(info[SN_LOW]); + low.s_addr = (low.s_addr & ~mask) | (addr & mask); + free(info[SN_LOW]); + sprintf(temp_buf, "%d", low.s_addr); + info[SN_LOW] = strsave(temp_buf); } - if (GetAddressFromUser("Lowest assignable address", &info[SN_LOW]) == SUB_ERROR) - return(NULL); - if (atoi(info[SN_HIGH]) == ntohl(inet_addr(S_DEFAULT_HIGH))) { - struct in_addr high; - unsigned long mask, addr; - - addr = atoi(info[SN_ADDRESS]); - mask = atoi(info[SN_MASK]); - high.s_addr = atoi(info[SN_HIGH]); - high.s_addr = (high.s_addr & ~mask) | (addr & mask); - free(info[SN_HIGH]); - sprintf(temp_buf, "%d", high.s_addr); - info[SN_HIGH] = strsave(temp_buf); + if (GetAddressFromUser("Lowest assignable address", &info[SN_LOW]) == + SUB_ERROR) + return NULL; + if (atoi(info[SN_HIGH]) == ntohl(inet_addr(S_DEFAULT_HIGH))) + { + struct in_addr high; + unsigned long mask, addr; + + addr = atoi(info[SN_ADDRESS]); + mask = atoi(info[SN_MASK]); + high.s_addr = atoi(info[SN_HIGH]); + high.s_addr = (high.s_addr & ~mask) | (addr & mask); + free(info[SN_HIGH]); + sprintf(temp_buf, "%d", high.s_addr); + info[SN_HIGH] = strsave(temp_buf); } - if (GetAddressFromUser("Highest assignable address", &info[SN_HIGH]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Hostname prefix", &info[SN_PREFIX]) == SUB_ERROR) - return(NULL); - if (GetTypeFromUser("Owner type", "ace_type", &info[SN_ACE_TYPE]) == SUB_ERROR) - return(NULL); - if (strcmp(info[SN_ACE_TYPE], "NONE") && - GetValueFromUser("Owner name", &info[SN_ACE_NAME]) == SUB_ERROR) - return(NULL); - FreeAndClear(&info[SN_MODTIME], TRUE); - FreeAndClear(&info[SN_MODBY], TRUE); - FreeAndClear(&info[SN_MODWITH], TRUE); - break; + if (GetAddressFromUser("Highest assignable address", &info[SN_HIGH]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Hostname prefix", &info[SN_PREFIX]) == SUB_ERROR) + return NULL; + if (GetTypeFromUser("Owner type", "ace_type", &info[SN_ACE_TYPE]) == + SUB_ERROR) + return NULL; + if (strcmp(info[SN_ACE_TYPE], "NONE") && + GetValueFromUser("Owner name", &info[SN_ACE_NAME]) == SUB_ERROR) + return NULL; + FreeAndClear(&info[SN_MODTIME], TRUE); + FreeAndClear(&info[SN_MODBY], TRUE); + FreeAndClear(&info[SN_MODWITH], TRUE); + break; case CLUSTER: - if (GetValueFromUser("Cluster's Description:", &info[C_DESCRIPT]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Cluster's Location:", &info[C_LOCATION]) == - SUB_ERROR) - return(NULL); - FreeAndClear(&info[C_MODTIME], TRUE); - FreeAndClear(&info[C_MODBY], TRUE); - FreeAndClear(&info[C_MODWITH], TRUE); - break; + if (GetValueFromUser("Cluster's Description:", &info[C_DESCRIPT]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Cluster's Location:", &info[C_LOCATION]) == + SUB_ERROR) + return NULL; + FreeAndClear(&info[C_MODTIME], TRUE); + FreeAndClear(&info[C_MODBY], TRUE); + FreeAndClear(&info[C_MODWITH], TRUE); + break; case DATA: - if (GetValueFromUser("Label defining this data?", &info[CD_LABEL]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("The data itself ? ", &info[CD_DATA]) == SUB_ERROR) - return(NULL); - break; + if (GetValueFromUser("Label defining this data?", &info[CD_LABEL]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("The data itself ? ", &info[CD_DATA]) == SUB_ERROR) + return NULL; + break; } -/* - * Slide the newname into the #2 slot, this screws up all future references - * to this list. - */ - if (name) - SlipInNewName(info, newname); + /* + * Slide the newname into the #2 slot, this screws up all future references + * to this list. + */ + if (name) + SlipInNewName(info, newname); - return(info); + return info; } /* ----------- Machine Menu ----------- */ @@ -672,26 +669,22 @@ Bool name; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowMachineInfo(argc, argv) -int argc; -char **argv; +int ShowMachineInfo(int argc, char **argv) { - struct qelem *top; - char *tmpname; - - tmpname = canonicalize_hostname(strsave(argv[1])); - top = GetMCInfo(MACHINE, tmpname, (char *) NULL); - Loop(top, ( (void *) PrintMachInfo) ); - FreeQueue(top); - return(DM_NORMAL); + struct qelem *top; + char *tmpname; + + tmpname = canonicalize_hostname(strsave(argv[1])); + top = GetMCInfo(MACHINE, tmpname, NULL); + Loop(top, ((void *) PrintMachInfo)); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: ShowMachineQuery * Description: This function shows the information about a machine. * or group of machines, which may be selected through a - * number of criteria. + * number of criteria. * Arguments: argc, argv - the name of the machine in argv[1], * the address of the machine in argv[2], * the location of the machine in argv[3], @@ -700,51 +693,49 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowMachineQuery(argc, argv) -int argc; -char **argv; +int ShowMachineQuery(int argc, char **argv) { - int stat; - struct qelem *top, *elem = NULL; - char *args[5]; - - if (!strcmp(argv[1], "") && !strcmp(argv[2], "") && - !strcmp(argv[3], "") && !strcmp(argv[4], "")) { - Put_message("You must specify at least one parameter of the query."); - return(DM_NORMAL); + int stat; + struct qelem *top, *elem = NULL; + char *args[5]; + + if (!strcmp(argv[1], "") && !strcmp(argv[2], "") && + !strcmp(argv[3], "") && !strcmp(argv[4], "")) + { + Put_message("You must specify at least one parameter of the query."); + return DM_NORMAL; } - if (*argv[1]) - args[0] = canonicalize_hostname(strsave(argv[1])); - else - args[0] = "*"; - if (*argv[2]) - args[1] = argv[2]; - else - args[1] = "*"; - if (*argv[3]) - args[2] = argv[3]; - else - args[2] = "*"; - if (*argv[4]) - args[3] = argv[4]; - else - args[3] = "*"; - - if ((stat = do_mr_query("get_host", 4, args, StoreInfo, - (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) - Put_message("No machine(s) found matching query in the database."); - else - com_err(program_name, stat, " in get_machine."); - return(DM_NORMAL); + if (*argv[1]) + args[0] = canonicalize_hostname(strsave(argv[1])); + else + args[0] = "*"; + if (*argv[2]) + args[1] = argv[2]; + else + args[1] = "*"; + if (*argv[3]) + args[2] = argv[3]; + else + args[2] = "*"; + if (*argv[4]) + args[3] = argv[4]; + else + args[3] = "*"; + + if ((stat = do_mr_query("get_host", 4, args, StoreInfo, + (char *)&elem))) + { + if (stat == MR_NO_MATCH) + Put_message("No machine(s) found matching query in the database."); + else + com_err(program_name, stat, " in get_machine."); + return DM_NORMAL; } - top = QueueTop(elem); - Loop(top, ( (void *) PrintMachInfo) ); - FreeQueue(top); - return(DM_NORMAL); + top = QueueTop(elem); + Loop(top, ((void *) PrintMachInfo)); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: AddMachine @@ -753,78 +744,79 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddMachine(argc, argv) -int argc; -char **argv; +int AddMachine(int argc, char **argv) { - char **args, *info[MAX_ARGS_SIZE], *name, buf[256], *xargs[5]; - char **rinfo; - struct qelem * elem = NULL; - int stat; - - if (!ValidName(argv[1])) /* Checks for wildcards. */ - return(DM_NORMAL); - - /* - * get the network record - */ - - if (strcasecmp(argv[1], "none") && - (stat = do_mr_query("get_subnet", 1, &argv[1], - StoreInfo, (char *)&elem)) != 0) { - if (stat == MR_NO_MATCH) { - char buf[128]; - sprintf(buf, "Network '%s' is not in the database.", argv[1]); - Put_message(buf); + char **args, *info[MAX_ARGS_SIZE], *name, buf[256], *xargs[5]; + char **rinfo; + struct qelem *elem = NULL; + int stat; + + if (!ValidName(argv[1])) /* Checks for wildcards. */ + return DM_NORMAL; + + /* + * get the network record + */ + + if (strcasecmp(argv[1], "none") && + (stat = do_mr_query("get_subnet", 1, &argv[1], + StoreInfo, (char *)&elem))) + { + if (stat == MR_NO_MATCH) + { + char buf[128]; + sprintf(buf, "Network '%s' is not in the database.", argv[1]); + Put_message(buf); } else - com_err(program_name, stat, " in get_subnet."); - return(DM_NORMAL); - } - -/* - * Check to see if this machine already exists. - */ + com_err(program_name, stat, " in get_subnet."); + return DM_NORMAL; + } - name = strsave(""); /* want to put prefix here */ - if (GetValueFromUser("Machine name", &name) == SUB_ERROR) - return(0); + /* + * Check to see if this machine already exists. + */ - name = canonicalize_hostname(strsave(name)); + name = strsave(""); /* want to put prefix here */ + if (GetValueFromUser("Machine name", &name) == SUB_ERROR) + return 0; - xargs[0] = name; - xargs[1] = xargs[2] = xargs[3] = "*"; - if ( (stat = do_mr_query("get_host", 4, xargs, NullFunc, NULL)) == 0) { - sprintf(buf, "The machine '%s' already exists.", name); - Put_message(buf); - free(name); - return(DM_NORMAL); + name = canonicalize_hostname(strsave(name)); + + xargs[0] = name; + xargs[1] = xargs[2] = xargs[3] = "*"; + if (!(stat = do_mr_query("get_host", 4, xargs, NullFunc, NULL))) + { + sprintf(buf, "The machine '%s' already exists.", name); + Put_message(buf); + free(name); + return DM_NORMAL; } - else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, - " while checking machine '%s' in AddMachine.", name); - free(name); - return(DM_NORMAL); + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, + " while checking machine '%s' in AddMachine.", name); + free(name); + return DM_NORMAL; } - rinfo = SetMachineDefaults(info, name); - rinfo[M_SUBNET] = strsave(argv[1]); - if ((args = AskMCDInfo(rinfo, MACHINE, FALSE)) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + rinfo = SetMachineDefaults(info, name); + rinfo[M_SUBNET] = strsave(argv[1]); + if (!(args = AskMCDInfo(rinfo, MACHINE, FALSE))) + { + Put_message("Aborted."); + return DM_NORMAL; } -/* - * Actually create the new Machine. - */ - - if ( (stat = do_mr_query("add_host", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in AddMachine."); - - FreeInfo(info); - free(name); - return(DM_NORMAL); + /* + * Actually create the new Machine. + */ + + if ((stat = do_mr_query("add_host", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in AddMachine."); + + FreeInfo(info); + free(name); + return DM_NORMAL; } /* Function Name: RealUpdateMachine @@ -834,23 +826,20 @@ char **argv; * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateMachine(info, junk) -char ** info; -Bool junk; +static void RealUpdateMachine(char **info, Bool junk) { - register int stat; - char ** args = AskMCDInfo(info, MACHINE, TRUE); - if (args == NULL) { - Put_message("Aborted."); - return; + register int stat; + char **args = AskMCDInfo(info, MACHINE, TRUE); + if (!args) + { + Put_message("Aborted."); + return; } - if ( (stat = do_mr_query("update_host", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in UpdateMachine."); - else - Put_message("Machine successfully updated."); + if ((stat = do_mr_query("update_host", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in UpdateMachine."); + else + Put_message("Machine successfully updated."); } /* Function Name: UpdateMachine @@ -859,22 +848,18 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -UpdateMachine(argc, argv) -int argc; -char **argv; +int UpdateMachine(int argc, char **argv) { - struct qelem *top; - char *tmpname; + struct qelem *top; + char *tmpname; - tmpname = canonicalize_hostname(strsave(argv[1])); - top = GetMCInfo( MACHINE, tmpname, (char *) NULL); - QueryLoop(top, NullPrint, RealUpdateMachine, "Update the machine"); + tmpname = canonicalize_hostname(strsave(argv[1])); + top = GetMCInfo(MACHINE, tmpname, NULL); + QueryLoop(top, NullPrint, RealUpdateMachine, "Update the machine"); - FreeQueue(top); - free(tmpname); - return(DM_NORMAL); + FreeQueue(top); + free(tmpname); + return DM_NORMAL; } /* Function Name: CheckAndRemoveFromCluster @@ -885,62 +870,65 @@ char **argv; * Returns: MR_ERROR if machine left in a cluster, or mr_error. */ -int -CheckAndRemoveFromCluster(name, ask_user) -char * name; -Bool ask_user; +int CheckAndRemoveFromCluster(char *name, Bool ask_user) { - register int stat, ret_value; - Bool delete_it; - char *args[10], temp_buf[BUFSIZ], *ptr; - struct qelem *top, *elem = NULL; - - ret_value = SUB_NORMAL; /* initialize ret_value. */ - args[0] = name; - args[1] = "*"; - stat = do_mr_query("get_machine_to_cluster_map", 2, args, - StoreInfo, (char *)&elem); - if (stat && stat != MR_NO_MATCH) { - com_err(program_name, stat, " in get_machine_to_cluster_map."); - return(DM_NORMAL); + register int stat, ret_value; + Bool delete_it; + char *args[10], temp_buf[BUFSIZ], *ptr; + struct qelem *top, *elem = NULL; + + ret_value = SUB_NORMAL; /* initialize ret_value. */ + args[0] = name; + args[1] = "*"; + stat = do_mr_query("get_machine_to_cluster_map", 2, args, + StoreInfo, (char *)&elem); + if (stat && stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in get_machine_to_cluster_map."); + return DM_NORMAL; } - if (stat == MR_SUCCESS) { - elem = top = QueueTop(elem); - if (ask_user) { - sprintf(temp_buf, "%s is assigned to the following clusters.", - name); - Put_message(temp_buf); - Loop(top, (void *) PrintMCMap); - ptr = "Remove this machine from ** ALL ** these clusters?"; - if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */ - delete_it = TRUE; - else { - Put_message("Aborting..."); - FreeQueue(top); - return(SUB_ERROR); + if (stat == MR_SUCCESS) + { + elem = top = QueueTop(elem); + if (ask_user) + { + sprintf(temp_buf, "%s is assigned to the following clusters.", name); + Put_message(temp_buf); + Loop(top, (void *) PrintMCMap); + ptr = "Remove this machine from ** ALL ** these clusters?"; + if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */ + delete_it = TRUE; + else + { + Put_message("Aborting..."); + FreeQueue(top); + return SUB_ERROR; } } - else - delete_it = TRUE; - - if (delete_it) { - while (elem != NULL) { - char **info = (char **) elem->q_data; - if ( (stat = do_mr_query( "delete_machine_from_cluster", - 2, info, Scream, NULL)) != 0) { - ret_value = SUB_ERROR; - com_err(program_name, stat, - " in delete_machine_from_cluster."); - sprintf(temp_buf, - "Machine %s ** NOT ** removed from cluster %s.", - info[MAP_MACHINE], info[MAP_CLUSTER]); - Put_message(temp_buf); + else + delete_it = TRUE; + + if (delete_it) + { + while (elem) + { + char **info = (char **) elem->q_data; + if ((stat = do_mr_query("delete_machine_from_cluster", + 2, info, Scream, NULL))) + { + ret_value = SUB_ERROR; + com_err(program_name, stat, + " in delete_machine_from_cluster."); + sprintf(temp_buf, + "Machine %s ** NOT ** removed from cluster %s.", + info[MAP_MACHINE], info[MAP_CLUSTER]); + Put_message(temp_buf); } - elem = elem->q_forw; + elem = elem->q_forw; } } } - return(ret_value); + return ret_value; } /* Function Name: RealDeleteMachine @@ -951,28 +939,29 @@ Bool ask_user; * Returns: none. */ -static void -RealDeleteMachine(info, one_machine) -char ** info; -Bool one_machine; +static void RealDeleteMachine(char **info, Bool one_machine) { - register int stat; - char temp_buf[BUFSIZ]; - - sprintf(temp_buf, "Are you sure you want to delete the machine %s (y/n)? ", - info[M_NAME]); - if(!one_machine || Confirm(temp_buf)) { - if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR) { - if ( (stat = do_mr_query("delete_host", 1, - &info[M_NAME], Scream, NULL)) != 0) { - com_err(program_name, stat, " in DeleteMachine."); - sprintf(temp_buf, "%s ** NOT ** deleted.", - info[M_NAME]); - Put_message(temp_buf); + register int stat; + char temp_buf[BUFSIZ]; + + sprintf(temp_buf, "Are you sure you want to delete the machine %s (y/n)? ", + info[M_NAME]); + if (!one_machine || Confirm(temp_buf)) + { + if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR) + { + if ((stat = do_mr_query("delete_host", 1, + &info[M_NAME], Scream, NULL))) + { + com_err(program_name, stat, " in DeleteMachine."); + sprintf(temp_buf, "%s ** NOT ** deleted.", + info[M_NAME]); + Put_message(temp_buf); } - else { - sprintf(temp_buf, "%s successfully Deleted.", info[M_NAME]); - Put_message(temp_buf); + else + { + sprintf(temp_buf, "%s successfully Deleted.", info[M_NAME]); + Put_message(temp_buf); } } } @@ -986,49 +975,43 @@ Bool one_machine; /* Perhaps we should remove the cluster if it has no machine now. */ -/* ARGSUSED */ -int -DeleteMachine(argc, argv) -int argc; -char **argv; +int DeleteMachine(int argc, char **argv) { - struct qelem *top; - char *tmpname; - - tmpname = canonicalize_hostname(strsave(argv[1])); - top = GetMCInfo(MACHINE, tmpname, (char *) NULL); - QueryLoop(top, PrintMachInfo, RealDeleteMachine, "Delete the machine"); - FreeQueue(top); - free(tmpname); - return(DM_NORMAL); + struct qelem *top; + char *tmpname; + + tmpname = canonicalize_hostname(strsave(argv[1])); + top = GetMCInfo(MACHINE, tmpname, (char *) NULL); + QueryLoop(top, PrintMachInfo, RealDeleteMachine, "Delete the machine"); + FreeQueue(top); + free(tmpname); + return DM_NORMAL; } -char *partial_canonicalize_hostname(s) -char *s; +char *partial_canonicalize_hostname(char *s) { - char buf[256], *cp; - static char *def_domain = NULL; - struct hostent *hp; -#ifdef POSIX - struct utsname name; -#endif - - if (!def_domain) { - (void) uname(&name); - hp = gethostbyname(name.nodename); - cp = (char *) strchr(hp->h_name, '.'); - if (cp) - def_domain = strsave(++cp); - else - def_domain = ""; + char buf[256], *cp; + static char *def_domain = NULL; + struct hostent *hp; + struct utsname name; + + if (!def_domain) + { + uname(&name); + hp = gethostbyname(name.nodename); + cp = strchr(hp->h_name, '.'); + if (cp) + def_domain = strsave(++cp); + else + def_domain = ""; } - if (strchr(s, '.') || strchr(s, '*')) - return(s); - sprintf(buf, "%s.%s", s, def_domain); - free(s); - return(strsave(buf)); + if (strchr(s, '.') || strchr(s, '*')) + return s; + sprintf(buf, "%s.%s", s, def_domain); + free(s); + return strsave(buf); } @@ -1038,70 +1021,60 @@ char *s; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowCname(argc, argv) -int argc; -char **argv; +int ShowCname(int argc, char **argv) { - struct qelem *top; - char *tmpalias, *tmpname; - - tmpalias = partial_canonicalize_hostname(strsave(argv[1])); - tmpname = canonicalize_hostname(strsave(argv[2])); - top = GetMCInfo(CNAME, tmpalias, tmpname); - Put_message(""); /* blank line on screen */ - Loop(top, ( (void *) PrintCname) ); - FreeQueue(top); - return(DM_NORMAL); + struct qelem *top; + char *tmpalias, *tmpname; + + tmpalias = partial_canonicalize_hostname(strsave(argv[1])); + tmpname = canonicalize_hostname(strsave(argv[2])); + top = GetMCInfo(CNAME, tmpalias, tmpname); + Put_message(""); /* blank line on screen */ + Loop(top, ((void *) PrintCname)); + FreeQueue(top); + return DM_NORMAL; } -/* ARGSUSED */ -int -AddCname(argc, argv) -int argc; -char ** argv; +int AddCname(int argc, char **argv) { - int stat; - char *args[10]; - - args[0] = partial_canonicalize_hostname(strsave(argv[1])); - args[1] = canonicalize_hostname(strsave(argv[2])); - stat = do_mr_query("add_hostalias", 2, args, Scream, NULL); - switch (stat) { + int stat; + char *args[10]; + + args[0] = partial_canonicalize_hostname(strsave(argv[1])); + args[1] = canonicalize_hostname(strsave(argv[2])); + stat = do_mr_query("add_hostalias", 2, args, Scream, NULL); + switch (stat) + { case MR_SUCCESS: - break; + break; case MR_EXISTS: - Put_message("That alias name is already in use."); - break; + Put_message("That alias name is already in use."); + break; case MR_PERM: - Put_message("Permission denied. (Regular users can only add two aliases to a host."); - break; + Put_message("Permission denied. " + "(Regular users can only add two aliases to a host."); + break; default: - com_err(program_name, stat, " in add_hostalias"); + com_err(program_name, stat, " in add_hostalias"); } - return(DM_NORMAL); + return DM_NORMAL; } -/* ARGSUSED */ -int -DeleteCname(argc, argv) -int argc; -char ** argv; +int DeleteCname(int argc, char **argv) { - int stat; - char *machine, *cluster, temp_buf[BUFSIZ], *args[10]; - Bool add_it, one_machine, one_cluster; - struct qelem * melem, *mtop, *celem, *ctop; - - args[0] = partial_canonicalize_hostname(strsave(argv[1])); - args[1] = canonicalize_hostname(strsave(argv[2])); - stat = do_mr_query("delete_hostalias", 2, args, Scream, NULL); - if (stat) - com_err(program_name, stat, " in delete_hostalias"); - return(DM_NORMAL); + int stat; + char *machine, *cluster, temp_buf[BUFSIZ], *args[10]; + Bool add_it, one_machine, one_cluster; + struct qelem *melem, *mtop, *celem, *ctop; + + args[0] = partial_canonicalize_hostname(strsave(argv[1])); + args[1] = canonicalize_hostname(strsave(argv[2])); + stat = do_mr_query("delete_hostalias", 2, args, Scream, NULL); + if (stat) + com_err(program_name, stat, " in delete_hostalias"); + return DM_NORMAL; } @@ -1112,87 +1085,90 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddMachineToCluster(argc, argv) -int argc; -char ** argv; +int AddMachineToCluster(int argc, char **argv) { - int stat; - char *machine, *cluster, temp_buf[BUFSIZ], *args[10]; - Bool add_it, one_machine, one_cluster; - struct qelem * melem, *mtop, *celem, *ctop; - - machine = canonicalize_hostname(strsave(argv[1])); - if (strcasecmp(machine, argv[1]) && *argv[1] != '"') { - sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.", - argv[1], machine); - Put_message(temp_buf); + int stat; + char *machine, *cluster, temp_buf[BUFSIZ], *args[10]; + Bool add_it, one_machine, one_cluster; + struct qelem *melem, *mtop, *celem, *ctop; + + machine = canonicalize_hostname(strsave(argv[1])); + if (strcasecmp(machine, argv[1]) && *argv[1] != '"') + { + sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.", + argv[1], machine); + Put_message(temp_buf); } - cluster = argv[2]; - - celem = ctop = GetMCInfo(CLUSTER, cluster, (char *) NULL); - melem = mtop = GetMCInfo(MACHINE, machine, (char *) NULL); - free(machine); - - one_machine = (QueueCount(mtop) == 1); - one_cluster = (QueueCount(ctop) == 1); - - /* No good way to use QueryLoop() here, sigh */ - - while (melem != NULL) { - char ** minfo = (char **) melem->q_data; - while (celem != NULL) { - char ** cinfo = (char **) celem->q_data; - if (one_machine && one_cluster) - add_it = TRUE; - else { - sprintf(temp_buf,"Add machine %s to cluster %s (y/n/q) ?", - minfo[M_NAME], cinfo[C_NAME]); - switch (YesNoQuitQuestion(temp_buf, FALSE)) { + cluster = argv[2]; + + celem = ctop = GetMCInfo(CLUSTER, cluster, NULL); + melem = mtop = GetMCInfo(MACHINE, machine, NULL); + free(machine); + + one_machine = (QueueCount(mtop) == 1); + one_cluster = (QueueCount(ctop) == 1); + + /* No good way to use QueryLoop() here, sigh */ + + while (melem) + { + char **minfo = (char **) melem->q_data; + while (celem) + { + char **cinfo = (char **) celem->q_data; + if (one_machine && one_cluster) + add_it = TRUE; + else + { + sprintf(temp_buf, "Add machine %s to cluster %s (y/n/q) ?", + minfo[M_NAME], cinfo[C_NAME]); + switch (YesNoQuitQuestion(temp_buf, FALSE)) + { case TRUE: - add_it = TRUE; - break; + add_it = TRUE; + break; case FALSE: - add_it = FALSE; - break; + add_it = FALSE; + break; default: - Put_message("Aborting..."); - FreeQueue(ctop); - FreeQueue(mtop); - return(DM_NORMAL); + Put_message("Aborting..."); + FreeQueue(ctop); + FreeQueue(mtop); + return DM_NORMAL; } } - if (add_it) { - args[0] = minfo[M_NAME]; - args[1] = cinfo[C_NAME]; - stat = do_mr_query("add_machine_to_cluster", 2, args, - Scream, NULL); - switch (stat) { + if (add_it) + { + args[0] = minfo[M_NAME]; + args[1] = cinfo[C_NAME]; + stat = do_mr_query("add_machine_to_cluster", 2, args, + Scream, NULL); + switch (stat) + { case MR_SUCCESS: - break; + break; case MR_EXISTS: - sprintf(temp_buf, "%s is already in cluster %s", - minfo[M_NAME], cinfo[C_NAME]); - Put_message(temp_buf); - break; + sprintf(temp_buf, "%s is already in cluster %s", + minfo[M_NAME], cinfo[C_NAME]); + Put_message(temp_buf); + break; default: - com_err(program_name, stat, " in AddMachineToCluster."); - break; + com_err(program_name, stat, " in AddMachineToCluster."); + break; } } - celem = celem->q_forw; + celem = celem->q_forw; } - celem = ctop; /* reset cluster element. */ - melem = melem->q_forw; + celem = ctop; /* reset cluster element. */ + melem = melem->q_forw; } - FreeQueue(ctop); - FreeQueue(mtop); - return(DM_NORMAL); + FreeQueue(ctop); + FreeQueue(mtop); + return DM_NORMAL; } /* Function Name: RealRemoveMachineFromCluster - * Description: This function actually removes the machine from its + * Description: This function actually removes the machine from its * cluster. * Arguments: info - all information nescessary to perform the removal. * one_map - True if there is only one case, and we should @@ -1200,28 +1176,27 @@ char ** argv; * Returns: none. */ -static void -RealRemoveMachineFromCluster(info, one_map) -char ** info; -Bool one_map; +static void RealRemoveMachineFromCluster(char **info, Bool one_map) { - char temp_buf[BUFSIZ]; - register int stat; - - sprintf(temp_buf, "Remove %s from the cluster %s", - info[MAP_MACHINE], info[MAP_CLUSTER]); - if (!one_map || Confirm(temp_buf)) { - if ( (stat = do_mr_query("delete_machine_from_cluster", 2, - info, Scream, NULL)) != 0 ) - com_err(program_name, stat, " in delete_machine_from_cluster"); - else { - sprintf(temp_buf, "%s has been removed from the cluster %s.", - info[MAP_MACHINE], info[MAP_CLUSTER]); - Put_message(temp_buf); + char temp_buf[BUFSIZ]; + register int stat; + + sprintf(temp_buf, "Remove %s from the cluster %s", + info[MAP_MACHINE], info[MAP_CLUSTER]); + if (!one_map || Confirm(temp_buf)) + { + if ((stat = do_mr_query("delete_machine_from_cluster", 2, + info, Scream, NULL))) + com_err(program_name, stat, " in delete_machine_from_cluster"); + else + { + sprintf(temp_buf, "%s has been removed from the cluster %s.", + info[MAP_MACHINE], info[MAP_CLUSTER]); + Put_message(temp_buf); } } - else - Put_message("Machine not removed."); + else + Put_message("Machine not removed."); } /* Function Name: RemoveMachineFromCluster @@ -1231,44 +1206,42 @@ Bool one_map; * Returns: none. */ -/* ARGSUSED */ -int -RemoveMachineFromCluster(argc, argv) -int argc; -char ** argv; +int RemoveMachineFromCluster(int argc, char **argv) { - struct qelem *elem = NULL; - char buf[BUFSIZ], * args[10]; - register int stat; - - args[MAP_MACHINE] = canonicalize_hostname(strsave(argv[1])); - if (strcasecmp(args[MAP_MACHINE], argv[1]) && *argv[1] != '"') { - sprintf(buf, "Warning: '%s' canonicalized to '%s'.", - argv[1], args[MAP_MACHINE]); - Put_message(buf); + struct qelem *elem = NULL; + char buf[BUFSIZ], * args[10]; + register int stat; + + args[MAP_MACHINE] = canonicalize_hostname(strsave(argv[1])); + if (strcasecmp(args[MAP_MACHINE], argv[1]) && *argv[1] != '"') + { + sprintf(buf, "Warning: '%s' canonicalized to '%s'.", + argv[1], args[MAP_MACHINE]); + Put_message(buf); } - args[MAP_CLUSTER] = argv[2]; - args[MAP_END] = NULL; - - stat = do_mr_query("get_machine_to_cluster_map", CountArgs(args), args, - StoreInfo, (char *)&elem); - if (stat == MR_NO_MATCH) { - sprintf(buf, "The machine %s is not is the cluster %s.", - args[MAP_MACHINE], args[MAP_CLUSTER]); - Put_message(buf); - free(args[MAP_MACHINE]); - return(DM_NORMAL); + args[MAP_CLUSTER] = argv[2]; + args[MAP_END] = NULL; + + stat = do_mr_query("get_machine_to_cluster_map", CountArgs(args), args, + StoreInfo, (char *)&elem); + if (stat == MR_NO_MATCH) + { + sprintf(buf, "The machine %s is not is the cluster %s.", + args[MAP_MACHINE], args[MAP_CLUSTER]); + Put_message(buf); + free(args[MAP_MACHINE]); + return DM_NORMAL; } - if (stat != MR_SUCCESS) - com_err(program_name, stat, " in delete_machine_from_cluster"); + if (stat != MR_SUCCESS) + com_err(program_name, stat, " in delete_machine_from_cluster"); - elem = QueueTop(elem); - QueryLoop(elem, PrintMCMap, RealRemoveMachineFromCluster, - "Remove this machine from this cluster"); + elem = QueueTop(elem); + QueryLoop(elem, PrintMCMap, RealRemoveMachineFromCluster, + "Remove this machine from this cluster"); - FreeQueue(elem); - free(args[MAP_MACHINE]); - return(DM_NORMAL); + FreeQueue(elem); + free(args[MAP_MACHINE]); + return DM_NORMAL; } /* ---------- Subnet Menu -------- */ @@ -1279,18 +1252,14 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowSubnetInfo(argc, argv) -int argc; -char ** argv; +int ShowSubnetInfo(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetMCInfo(SUBNET, argv[1], (char *) NULL); - Loop(top, (void *) PrintSubnetInfo); - FreeQueue(top); - return(DM_NORMAL); + top = GetMCInfo(SUBNET, argv[1], (char *) NULL); + Loop(top, (void *) PrintSubnetInfo); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: AddSubnet @@ -1299,45 +1268,44 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddSubnet(argc, argv) -int argc; -char ** argv; +int AddSubnet(int argc, char **argv) { - char **args, *info[MAX_ARGS_SIZE], *name = argv[1]; - int stat; -/* - * Check to see if this subnet already exists. - */ - if (!ValidName(name)) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_subnet", 1, &name, - NullFunc, NULL)) == MR_SUCCESS) { - Put_message("This subnet already exists."); - return(DM_NORMAL); + char **args, *info[MAX_ARGS_SIZE], *name = argv[1]; + int stat; + + /* + * Check to see if this subnet already exists. + */ + if (!ValidName(name)) + return DM_NORMAL; + + if ((stat = do_mr_query("get_subnet", 1, &name, + NullFunc, NULL)) == MR_SUCCESS) + { + Put_message("This subnet already exists."); + return DM_NORMAL; } - else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in AddSubnet."); - return(DM_NORMAL); + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in AddSubnet."); + return DM_NORMAL; } - if ((args = AskMCDInfo(SetSubnetDefaults(info, name), SUBNET, FALSE)) == - NULL) { - Put_message("Aborted."); - FreeInfo(info); - return(DM_NORMAL); + if (!(args = AskMCDInfo(SetSubnetDefaults(info, name), SUBNET, FALSE))) + { + Put_message("Aborted."); + FreeInfo(info); + return DM_NORMAL; } -/* - * Actually create the new Subnet. - */ - if ( (stat = do_mr_query("add_subnet", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in AddSubnet."); + /* + * Actually create the new Subnet. + */ + if ((stat = do_mr_query("add_subnet", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in AddSubnet."); - FreeInfo(info); - return(DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } /* Function Name: RealUpdateSubnet @@ -1347,23 +1315,20 @@ char ** argv; * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateSubnet(info, junk) -char ** info; -Bool junk; +static void RealUpdateSubnet(char **info, Bool junk) { - register int stat; - char ** args = AskMCDInfo(info, SUBNET, TRUE); - if (args == NULL) { - Put_message("Aborted."); - return; + register int stat; + char **args = AskMCDInfo(info, SUBNET, TRUE); + if (!args) + { + Put_message("Aborted."); + return; } - if ( (stat = do_mr_query("update_subnet", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in UpdateSubnet."); - else - Put_message("Subnet successfully updated."); + if ((stat = do_mr_query("update_subnet", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in UpdateSubnet."); + else + Put_message("Subnet successfully updated."); } /* Function Name: UpdateSubnet @@ -1372,18 +1337,14 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -UpdateSubnet(argc, argv) -int argc; -char ** argv; +int UpdateSubnet(int argc, char **argv) { - struct qelem *top; - top = GetMCInfo( SUBNET, argv[1], (char *) NULL ); - QueryLoop(top, NullPrint, RealUpdateSubnet, "Update the subnet"); + struct qelem *top; + top = GetMCInfo(SUBNET, argv[1], NULL); + QueryLoop(top, NullPrint, RealUpdateSubnet, "Update the subnet"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: RealDeleteSubnet @@ -1394,29 +1355,28 @@ char ** argv; * Returns: none. */ -static void -RealDeleteSubnet(info, one_subnet) -char ** info; -Bool one_subnet; +static void RealDeleteSubnet(char **info, Bool one_subnet) { - register int stat; - char temp_buf[BUFSIZ]; - - sprintf(temp_buf, - "Are you sure the you want to delete the subnet %s (y/n) ?", - info[C_NAME]); - if (!one_subnet || Confirm(temp_buf)) { - if ( (stat = do_mr_query("delete_subnet", 1, - &info[C_NAME], Scream, NULL)) != 0) { - com_err(program_name, stat, " in delete_subnet."); - sprintf(temp_buf, "Subnet %s ** NOT ** deleted.", - info[C_NAME]); - Put_message(temp_buf); + register int stat; + char temp_buf[BUFSIZ]; + + sprintf(temp_buf, + "Are you sure the you want to delete the subnet %s (y/n) ?", + info[C_NAME]); + if (!one_subnet || Confirm(temp_buf)) + { + if ((stat = do_mr_query("delete_subnet", 1, + &info[C_NAME], Scream, NULL))) + { + com_err(program_name, stat, " in delete_subnet."); + sprintf(temp_buf, "Subnet %s ** NOT ** deleted.", info[C_NAME]); + Put_message(temp_buf); } - else { - sprintf(temp_buf, "subnet %s successfully deleted.", - info[C_NAME]); - Put_message(temp_buf); + else + { + sprintf(temp_buf, "subnet %s successfully deleted.", + info[C_NAME]); + Put_message(temp_buf); } } } @@ -1427,21 +1387,17 @@ Bool one_subnet; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeleteSubnet(argc, argv) -int argc; -char ** argv; +int DeleteSubnet(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetMCInfo( SUBNET, argv[1], (char *) NULL ); - QueryLoop(top, PrintSubnetInfo, RealDeleteSubnet, "Delete the subnet"); + top = GetMCInfo(SUBNET, argv[1], NULL); + QueryLoop(top, PrintSubnetInfo, RealDeleteSubnet, "Delete the subnet"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } - + /* ---------- Cluster Menu -------- */ /* Function Name: ShowClusterInfo @@ -1450,18 +1406,14 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowClusterInfo(argc, argv) -int argc; -char ** argv; +int ShowClusterInfo(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetMCInfo(CLUSTER, argv[1], (char *) NULL); - Loop(top, (void *) PrintClusterInfo); - FreeQueue(top); - return(DM_NORMAL); + top = GetMCInfo(CLUSTER, argv[1], NULL); + Loop(top, (void *) PrintClusterInfo); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: AddCluster @@ -1470,45 +1422,44 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddCluster(argc, argv) -int argc; -char ** argv; +int AddCluster(int argc, char **argv) { - char **args, *info[MAX_ARGS_SIZE], *name = argv[1]; - int stat; -/* - * Check to see if this cluster already exists. - */ - if (!ValidName(name)) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_cluster", 1, &name, - NullFunc, NULL)) == MR_SUCCESS) { - Put_message("This cluster already exists."); - return(DM_NORMAL); + char **args, *info[MAX_ARGS_SIZE], *name = argv[1]; + int stat; + + /* + * Check to see if this cluster already exists. + */ + if (!ValidName(name)) + return DM_NORMAL; + + if ((stat = do_mr_query("get_cluster", 1, &name, + NullFunc, NULL)) == MR_SUCCESS) + { + Put_message("This cluster already exists."); + return DM_NORMAL; } - else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in AddCluster."); - return(DM_NORMAL); + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in AddCluster."); + return DM_NORMAL; } - if ((args = AskMCDInfo(SetClusterDefaults(info, name), CLUSTER, FALSE)) == - NULL) { - Put_message("Aborted."); - FreeInfo(info); - return(DM_NORMAL); + if (!(args = AskMCDInfo(SetClusterDefaults(info, name), CLUSTER, FALSE))) + { + Put_message("Aborted."); + FreeInfo(info); + return DM_NORMAL; } -/* - * Actually create the new Cluster. - */ - if ( (stat = do_mr_query("add_cluster", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in AddCluster."); + /* + * Actually create the new Cluster. + */ + if ((stat = do_mr_query("add_cluster", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in AddCluster."); - FreeInfo(info); - return(DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } /* Function Name: RealUpdateCluster @@ -1518,23 +1469,21 @@ char ** argv; * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateCluster(info, junk) -char ** info; -Bool junk; +static void RealUpdateCluster(char **info, Bool junk) { - register int stat; - char ** args = AskMCDInfo(info, CLUSTER, TRUE); - if (args == NULL) { - Put_message("Aborted."); - return; + register int stat; + char **args = AskMCDInfo(info, CLUSTER, TRUE); + + if (!args) + { + Put_message("Aborted."); + return; } - if ( (stat = do_mr_query("update_cluster", CountArgs(args), - args, Scream, NULL)) != 0) - com_err(program_name, stat, " in UpdateCluster."); - else - Put_message("Cluster successfully updated."); + if ((stat = do_mr_query("update_cluster", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, stat, " in UpdateCluster."); + else + Put_message("Cluster successfully updated."); } /* Function Name: UpdateCluster @@ -1543,18 +1492,14 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -UpdateCluster(argc, argv) -int argc; -char ** argv; +int UpdateCluster(int argc, char **argv) { - struct qelem *top; - top = GetMCInfo( CLUSTER, argv[1], (char *) NULL ); - QueryLoop(top, NullPrint, RealUpdateCluster, "Update the cluster"); + struct qelem *top; + top = GetMCInfo(CLUSTER, argv[1], NULL); + QueryLoop(top, NullPrint, RealUpdateCluster, "Update the cluster"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: CheckAndRemoveMachine @@ -1566,69 +1511,73 @@ char ** argv; * Returns: SUB_ERROR if all machines not removed. */ -int -CheckAndRemoveMachines(name, ask_first) -char * name; -Bool ask_first; +int CheckAndRemoveMachines(char *name, Bool ask_first) { - register int stat, ret_value; - Bool delete_it; - char *args[10], temp_buf[BUFSIZ], *ptr; - struct qelem *top, *elem = NULL; - - ret_value = SUB_NORMAL; - args[MAP_MACHINE] = "*"; - args[MAP_CLUSTER] = name; - stat = do_mr_query("get_machine_to_cluster_map", 2, args, - StoreInfo, (char *)&elem); - if (stat && stat != MR_NO_MATCH) { - com_err(program_name, stat, " in get_machine_to_cluster_map."); - return(DM_NORMAL); + register int stat, ret_value; + Bool delete_it; + char *args[10], temp_buf[BUFSIZ], *ptr; + struct qelem *top, *elem = NULL; + + ret_value = SUB_NORMAL; + args[MAP_MACHINE] = "*"; + args[MAP_CLUSTER] = name; + stat = do_mr_query("get_machine_to_cluster_map", 2, args, + StoreInfo, (char *)&elem); + if (stat && stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in get_machine_to_cluster_map."); + return DM_NORMAL; } - if (stat == 0) { - elem = top = QueueTop(elem); - if (ask_first) { - sprintf(temp_buf, - "The cluster %s has the following machines in it:", - name); - Put_message(temp_buf); - while (elem != NULL) { - char **info = (char **) elem->q_data; - Print(1, &info[MAP_MACHINE], (char *) NULL); - elem = elem->q_forw; + if (stat == MR_SUCCESS) + { + elem = top = QueueTop(elem); + if (ask_first) + { + sprintf(temp_buf, "The cluster %s has the following machines in it:", + name); + Put_message(temp_buf); + while (elem) + { + char **info = (char **) elem->q_data; + Print(1, &info[MAP_MACHINE], (char *) NULL); + elem = elem->q_forw; } - ptr = "Remove ** ALL ** these machines from this cluster?"; - - if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */ - delete_it = TRUE; - else { - Put_message("Aborting..."); - FreeQueue(top); - return(SUB_ERROR); + ptr = "Remove ** ALL ** these machines from this cluster?"; + + if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */ + delete_it = TRUE; + else + { + Put_message("Aborting..."); + FreeQueue(top); + return SUB_ERROR; } } - else - delete_it = TRUE; - - if (delete_it) { - elem = top; - while (elem != 0) { - char **info = (char **) elem->q_data; - if ( (stat = do_mr_query("delete_machine_from_cluster", - 2, info, Scream, NULL)) != 0) { - ret_value = SUB_ERROR; - com_err(program_name, stat, - " in delete_machine_from_cluster."); - sprintf(temp_buf, - "Machine %s ** NOT ** removed from cluster %s.", - info[MAP_MACHINE], info[MAP_CLUSTER]); - Put_message(temp_buf); + else + delete_it = TRUE; + + if (delete_it) + { + elem = top; + while (elem) + { + char **info = (char **) elem->q_data; + if ((stat = do_mr_query("delete_machine_from_cluster", + 2, info, Scream, NULL))) + { + ret_value = SUB_ERROR; + com_err(program_name, stat, + " in delete_machine_from_cluster."); + sprintf(temp_buf, + "Machine %s ** NOT ** removed from cluster %s.", + info[MAP_MACHINE], info[MAP_CLUSTER]); + Put_message(temp_buf); } - elem = elem->q_forw; + elem = elem->q_forw; } } } - return(ret_value); + return ret_value; } /* Function Name: RealDeleteCluster @@ -1639,30 +1588,30 @@ Bool ask_first; * Returns: none. */ -static void -RealDeleteCluster(info, one_cluster) -char ** info; -Bool one_cluster; +static void RealDeleteCluster(char **info, Bool one_cluster) { - register int stat; - char temp_buf[BUFSIZ]; - - sprintf(temp_buf, - "Are you sure the you want to delete the cluster %s (y/n) ?", - info[C_NAME]); - if (!one_cluster || Confirm(temp_buf)) { - if (CheckAndRemoveMachines(info[C_NAME], TRUE) != SUB_ERROR) { - if ( (stat = do_mr_query("delete_cluster", 1, - &info[C_NAME], Scream, NULL)) != 0) { - com_err(program_name, stat, " in delete_cluster."); - sprintf(temp_buf, "Cluster %s ** NOT ** deleted.", - info[C_NAME]); - Put_message(temp_buf); + register int stat; + char temp_buf[BUFSIZ]; + + sprintf(temp_buf, + "Are you sure the you want to delete the cluster %s (y/n) ?", + info[C_NAME]); + if (!one_cluster || Confirm(temp_buf)) + { + if (CheckAndRemoveMachines(info[C_NAME], TRUE) != SUB_ERROR) + { + if ((stat = do_mr_query("delete_cluster", 1, + &info[C_NAME], Scream, NULL))) + { + com_err(program_name, stat, " in delete_cluster."); + sprintf(temp_buf, "Cluster %s ** NOT ** deleted.", info[C_NAME]); + Put_message(temp_buf); } - else { - sprintf(temp_buf, "cluster %s successfully deleted.", - info[C_NAME]); - Put_message(temp_buf); + else + { + sprintf(temp_buf, "cluster %s successfully deleted.", + info[C_NAME]); + Put_message(temp_buf); } } } @@ -1674,21 +1623,17 @@ Bool one_cluster; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeleteCluster(argc, argv) -int argc; -char ** argv; +int DeleteCluster(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetMCInfo( CLUSTER, argv[1], (char *) NULL ); - QueryLoop(top, PrintClusterInfo, RealDeleteCluster, "Delete the cluster"); + top = GetMCInfo(CLUSTER, argv[1], NULL); + QueryLoop(top, PrintClusterInfo, RealDeleteCluster, "Delete the cluster"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } - + /* ----------- Cluster Data Menu -------------- */ /* Function Name: ShowClusterData @@ -1698,23 +1643,20 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowClusterData(argc, argv) -int argc; -char ** argv; -{ - struct qelem *elem, *top; - char **info; - - top = elem = GetMCInfo(DATA, argv[1], argv[2]); - while (elem != NULL) { - info = (char **) elem->q_data; - PrintClusterData(info); - elem = elem->q_forw; +int ShowClusterData(int argc, char **argv) +{ + struct qelem *elem, *top; + char **info; + + top = elem = GetMCInfo(DATA, argv[1], argv[2]); + while (elem) + { + info = (char **) elem->q_data; + PrintClusterData(info); + elem = elem->q_forw; } - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: AddClusterData @@ -1725,18 +1667,14 @@ char ** argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddClusterData(argc, argv) -int argc; -char ** argv; -{ - int stat; - - if( (stat = do_mr_query("add_cluster_data", 3, argv + 1, - Scream, (char *) NULL)) != 0) - com_err(program_name, stat, " in AddClusterData."); - return(DM_NORMAL); +int AddClusterData(int argc, char **argv) +{ + int stat; + + if ((stat = do_mr_query("add_cluster_data", 3, argv + 1, + Scream, (char *) NULL))) + com_err(program_name, stat, " in AddClusterData."); + return DM_NORMAL; } /* Function Name: RealRemoveClusterData @@ -1748,25 +1686,24 @@ char ** argv; * Returns: none. */ -static void -RealRemoveClusterData(info, one_item) -char ** info; -Bool one_item; +static void RealRemoveClusterData(char **info, Bool one_item) { - register int stat; - char * temp_ptr; - - Put_message(" "); - temp_ptr = "Are you sure that you want to remove this cluster data (y/n) ?"; - PrintClusterData(info); - if (!one_item || Confirm(temp_ptr)) { - if( (stat = do_mr_query("delete_cluster_data", 3, info, - Scream, (char *) NULL)) != 0) { - com_err(program_name, stat, " in DeleteClusterData."); - Put_message("Data not removed."); + register int stat; + char *temp_ptr; + + Put_message(" "); + temp_ptr = "Are you sure that you want to remove this cluster data (y/n) ?"; + PrintClusterData(info); + if (!one_item || Confirm(temp_ptr)) + { + if ((stat = do_mr_query("delete_cluster_data", 3, info, + Scream, (char *) NULL))) + { + com_err(program_name, stat, " in DeleteClusterData."); + Put_message("Data not removed."); } - else - Put_message("Removal successful."); + else + Put_message("Removal successful."); } } @@ -1778,20 +1715,16 @@ Bool one_item; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -RemoveClusterData(argc, argv) -int argc; -char ** argv; +int RemoveClusterData(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetMCInfo(DATA, argv[1], argv[2]); - QueryLoop(top, PrintClusterData, RealRemoveClusterData, - "Remove data from cluster"); + top = GetMCInfo(DATA, argv[1], argv[2]); + QueryLoop(top, PrintClusterData, RealRemoveClusterData, + "Remove data from cluster"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: MachineToClusterMap @@ -1801,31 +1734,29 @@ char ** argv; * Returns: none. */ -/* ARGSUSED */ -int -MachineToClusterMap(argc,argv) -int argc; -char **argv; +int MachineToClusterMap(int argc, char **argv) { - struct qelem *elem, *top; - char *tmpname, temp_buf[256]; - - tmpname = canonicalize_hostname(strsave(argv[1])); - if (strcasecmp(tmpname, argv[1]) && *argv[1] != '"') { - sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.", - argv[1], tmpname); - Put_message(temp_buf); + struct qelem *elem, *top; + char *tmpname, temp_buf[256]; + + tmpname = canonicalize_hostname(strsave(argv[1])); + if (strcasecmp(tmpname, argv[1]) && *argv[1] != '"') + { + sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.", + argv[1], tmpname); + Put_message(temp_buf); } - top = elem = GetMCInfo(MAP, tmpname, argv[2]); - - Put_message(""); /* blank line on screen */ - while (elem != NULL) { - char ** info = (char **) elem->q_data; - PrintMCMap(info); - elem = elem->q_forw; + top = elem = GetMCInfo(MAP, tmpname, argv[2]); + + Put_message(""); /* blank line on screen */ + while (elem) + { + char **info = (char **) elem->q_data; + PrintMCMap(info); + elem = elem->q_forw; } - FreeQueue(top); - free(tmpname); - return(DM_NORMAL); + FreeQueue(top); + free(tmpname); + return DM_NORMAL; } diff --git a/clients/moira/dcmmaint.c b/clients/moira/dcmmaint.c index 35c81e9e..103147af 100644 --- a/clients/moira/dcmmaint.c +++ b/clients/moira/dcmmaint.c @@ -24,527 +24,479 @@ char *atot(); #define DCM_ENABLE_FLAG 0 -genable(argc, argv, info) -int argc; -char **argv; -char **info; +int genable(int argc, char **argv, char **info) { - info[1] = strsave(argv[0]); - return(MR_CONT); + info[1] = strsave(argv[0]); + return MR_CONT; } -EnableDcm(argc, argv) -int argc; -char **argv; +int EnableDcm(int argc, char **argv) { - int status; - char *info[3]; - - info[0] = "dcm_enable"; - if (status = do_mr_query("get_value", 1, info, genable, info)) - com_err(whoami, status, " while getting value of dcm_enable"); - if (GetValueFromUser("Enable value", &info[1]) == SUB_ERROR) - return(DM_NORMAL); - if (status = do_mr_query("update_value", 2, info, Scream, NULL)) - com_err(whoami, status, " while updating value of dcm_enable"); - FreeAndClear(&info[0], FALSE); - FreeAndClear(&info[1], TRUE); - return(DM_NORMAL); + int status; + char *info[3]; + + info[0] = "dcm_enable"; + if ((status = do_mr_query("get_value", 1, info, genable, info))) + com_err(whoami, status, " while getting value of dcm_enable"); + if (GetValueFromUser("Enable value", &info[1]) == SUB_ERROR) + return DM_NORMAL; + if ((status = do_mr_query("update_value", 2, info, Scream, NULL))) + com_err(whoami, status, " while updating value of dcm_enable"); + FreeAndClear(&info[0], FALSE); + FreeAndClear(&info[1], TRUE); + return DM_NORMAL; } -int shserv(argc, argv) -int argc; -char **argv; +int shserv(int argc, char **argv) { - char tmp[64], *dfgen; - - Put_message("Name Type Owner Modified"); - sprintf(tmp, "%s:%s", argv[SVC_ACE_TYPE], argv[SVC_ACE_NAME]); - sprintf(buf, "%-10s %-8s %-11s by %s on %s with %s", argv[SVC_SERVICE], - argv[SVC_TYPE], tmp, argv[SVC_MODBY], argv[SVC_MODTIME], - argv[SVC_MODWITH]); - Put_message(buf); - sprintf(buf, " Interval %s, Target:%s, Script:%s", - unparse_interval(atoi(argv[SVC_INTERVAL])), argv[SVC_TARGET], - argv[SVC_SCRIPT]); - Put_message(buf); - if (atoi(argv[SVC_HARDERROR])) - sprintf(tmp, "Error %d: %s", atoi(argv[SVC_HARDERROR]), argv[SVC_ERRMSG]); - else - strcpy(tmp, "No error"); - dfgen = strsave(atot(argv[SVC_DFGEN])); - sprintf(buf, " Generated %s; Last Checked %s", dfgen, - atot(argv[SVC_DFCHECK])); - free(dfgen); - Put_message(buf); - sprintf(buf, " %s/%s/%s", atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", - atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", tmp); - Put_message(buf); - Put_message(""); - return(MR_CONT); + char tmp[64], *dfgen; + + Put_message("Name Type Owner Modified"); + sprintf(tmp, "%s:%s", argv[SVC_ACE_TYPE], argv[SVC_ACE_NAME]); + sprintf(buf, "%-10s %-8s %-11s by %s on %s with %s", argv[SVC_SERVICE], + argv[SVC_TYPE], tmp, argv[SVC_MODBY], argv[SVC_MODTIME], + argv[SVC_MODWITH]); + Put_message(buf); + sprintf(buf, " Interval %s, Target:%s, Script:%s", + unparse_interval(atoi(argv[SVC_INTERVAL])), argv[SVC_TARGET], + argv[SVC_SCRIPT]); + Put_message(buf); + if (atoi(argv[SVC_HARDERROR])) + sprintf(tmp, "Error %d: %s", atoi(argv[SVC_HARDERROR]), argv[SVC_ERRMSG]); + else + strcpy(tmp, "No error"); + dfgen = strsave(atot(argv[SVC_DFGEN])); + sprintf(buf, " Generated %s; Last Checked %s", dfgen, + atot(argv[SVC_DFCHECK])); + free(dfgen); + Put_message(buf); + sprintf(buf, " %s/%s/%s", atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", + atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", tmp); + Put_message(buf); + Put_message(""); + return MR_CONT; } -showserv(argc, argv) -int argc; -char **argv; +int showserv(int argc, char **argv) { - char *qargv[1]; - int status; - - qargv[0] = argv[1]; - if (status = do_mr_query("get_server_info", 1, qargv, shserv, NULL)) - com_err(whoami, status, " while getting server info"); - return(DM_NORMAL); + char *qargv[1]; + int status; + + qargv[0] = argv[1]; + if ((status = do_mr_query("get_server_info", 1, qargv, shserv, NULL))) + com_err(whoami, status, " while getting server info"); + return DM_NORMAL; } -char *unparse_interval(i) -int i; +char *unparse_interval(int i) { - static char uibuf[10]; + static char uibuf[10]; - sprintf(uibuf, "%02d:%02d:00", i / 60, i % 60); - return(uibuf); + sprintf(uibuf, "%02d:%02d:00", i / 60, i % 60); + return uibuf; } -addserv(argc, argv) -int argc; -char **argv; +int addserv(int argc, char **argv) { - int status; - char *info[SC_END+1], **askserv(); - - initserv(argv[1], info); - if (askserv(info) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + int status; + char *info[SC_END + 1], **askserv(); + + initserv(argv[1], info); + if (!askserv(info)) + { + Put_message("Aborted."); + return DM_NORMAL; } - if (status = do_mr_query("add_server_info", SC_END, info, Scream, NULL)) - com_err(whoami, status, " while updating server info"); - FreeInfo(info); - return(DM_NORMAL); + if ((status = do_mr_query("add_server_info", SC_END, info, Scream, NULL))) + com_err(whoami, status, " while updating server info"); + FreeInfo(info); + return DM_NORMAL; } -char **askserv(info) -char **info; +char **askserv(char **info) { - if (GetValueFromUser("Interval", &info[SC_INTERVAL]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Target", &info[SC_TARGET]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Script", &info[SC_SCRIPT]) == SUB_ERROR) - return(NULL); - if (GetTypeFromUser("Service type", "service", &info[SC_TYPE]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Enable", &info[SC_ENABLE]) == SUB_ERROR) - return(NULL); - if (GetTypeFromUser("ACE type", "ace_type", &info[SC_ACE_TYPE]) == - SUB_ERROR) - return(NULL); - if (strcasecmp("none", info[SC_ACE_TYPE])) + if (GetValueFromUser("Interval", &info[SC_INTERVAL]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Target", &info[SC_TARGET]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Script", &info[SC_SCRIPT]) == SUB_ERROR) + return NULL; + if (GetTypeFromUser("Service type", "service", &info[SC_TYPE]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Enable", &info[SC_ENABLE]) == SUB_ERROR) + return NULL; + if (GetTypeFromUser("ACE type", "ace_type", &info[SC_ACE_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp("none", info[SC_ACE_TYPE])) + { if (GetValueFromUser("Ace name", &info[SC_ACE_NAME]) == SUB_ERROR) - return(NULL); - return(info); + return NULL; + } + return info; } -gserv(argc, argv, cargv) -int argc; -char **argv; -char **cargv; +int gserv(int argc, char **argv, char **cargv) { - cargv[SC_SERVICE] = strsave(argv[SVC_SERVICE]); - cargv[SC_INTERVAL] = strsave(argv[SVC_INTERVAL]); - cargv[SC_TARGET] = strsave(argv[SVC_TARGET]); - cargv[SC_SCRIPT] = strsave(argv[SVC_SCRIPT]); - cargv[SC_TYPE] = strsave(argv[SVC_TYPE]); - cargv[SC_ENABLE] = strsave(argv[SVC_ENABLE]); - cargv[SC_ACE_TYPE] = strsave(argv[SVC_ACE_TYPE]); - cargv[SC_ACE_NAME] = strsave(argv[SVC_ACE_NAME]); - cargv[SC_END] = NULL; - return(MR_CONT); + cargv[SC_SERVICE] = strsave(argv[SVC_SERVICE]); + cargv[SC_INTERVAL] = strsave(argv[SVC_INTERVAL]); + cargv[SC_TARGET] = strsave(argv[SVC_TARGET]); + cargv[SC_SCRIPT] = strsave(argv[SVC_SCRIPT]); + cargv[SC_TYPE] = strsave(argv[SVC_TYPE]); + cargv[SC_ENABLE] = strsave(argv[SVC_ENABLE]); + cargv[SC_ACE_TYPE] = strsave(argv[SVC_ACE_TYPE]); + cargv[SC_ACE_NAME] = strsave(argv[SVC_ACE_NAME]); + cargv[SC_END] = NULL; + return MR_CONT; } -initserv(name, argv) -char *name; -char **argv; +int initserv(char *name, char **argv) { - char tmp[BUFSIZ]; - - argv[SC_SERVICE] = strsave(name); - argv[SC_INTERVAL] = strsave("1440"); - sprintf(tmp, "/tmp/%s.out", name); - argv[SC_TARGET] = strsave(tmp); - sprintf(tmp, "%s/%s.sh", BIN_DIR, name); - argv[SC_SCRIPT] = strsave(tmp); - argv[SC_TYPE] = strsave("UNIQUE"); - argv[SC_ENABLE] = strsave("1"); - argv[SC_ACE_TYPE] = strsave("LIST"); - argv[SC_ACE_NAME] = strsave("dbadmin"); - argv[SC_END] = NULL; + char tmp[BUFSIZ]; + + argv[SC_SERVICE] = strsave(name); + argv[SC_INTERVAL] = strsave("1440"); + sprintf(tmp, "/tmp/%s.out", name); + argv[SC_TARGET] = strsave(tmp); + sprintf(tmp, "%s/%s.sh", BIN_DIR, name); + argv[SC_SCRIPT] = strsave(tmp); + argv[SC_TYPE] = strsave("UNIQUE"); + argv[SC_ENABLE] = strsave("1"); + argv[SC_ACE_TYPE] = strsave("LIST"); + argv[SC_ACE_NAME] = strsave("dbadmin"); + argv[SC_END] = NULL; } -updateserv(argc, argv) -int argc; -char **argv; +int updateserv(int argc, char **argv) { - char *qargv[SC_END+1]; - int status; - - qargv[0] = (char *)argv[1]; - if (status = do_mr_query("get_server_info", 1, - qargv, gserv, (char *)qargv)) { - com_err(whoami, status, " while getting server info"); - return(DM_NORMAL); + char *qargv[SC_END + 1]; + int status; + + qargv[0] = (char *)argv[1]; + if ((status = do_mr_query("get_server_info", 1, + qargv, gserv, (char *)qargv))) + { + com_err(whoami, status, " while getting server info"); + return DM_NORMAL; } - if (askserv(qargv) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + if (!askserv(qargv)) + { + Put_message("Aborted."); + return DM_NORMAL; } - if (status = do_mr_query("update_server_info", SC_END, qargv, Scream, NULL)) - com_err(whoami, status, " while updating server info"); - return(DM_NORMAL); + if ((status = do_mr_query("update_server_info", SC_END, qargv, Scream, NULL))) + com_err(whoami, status, " while updating server info"); + return DM_NORMAL; } -int shhost(argc, argv) -int argc; -char **argv; +int shhost(int argc, char **argv) { - char tmp[64], *ltt; - - sprintf(buf, "%s:%s mod by %s on %s with %s", argv[SH_MACHINE], - argv[SH_SERVICE], argv[SH_MODBY], argv[SH_MODTIME], - argv[SH_MODWITH]); - Put_message(buf); - if (atoi(argv[SH_HOSTERROR])) - sprintf(tmp, "Error %d: %s", atoi(argv[SH_HOSTERROR]), argv[SH_ERRMSG]); - else - strcpy(tmp, "No error"); - sprintf(buf, " %s/%s/%s/%s/%s", - atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", - atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", - atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", - atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", tmp); - Put_message(buf); - Put_message(" Last Try Last Success Value1 Value2 Value3"); - ltt = strsave(atot(argv[SH_LASTTRY])); - sprintf(buf, " %-20s %-20s %-9d %-9d %s", ltt, atot(argv[SH_LASTSUCCESS]), - atoi(argv[SH_VALUE1]), atoi(argv[SH_VALUE2]), argv[SH_VALUE3]); - free(ltt); - Put_message(buf); - Put_message(""); - return(MR_CONT); + char tmp[64], *ltt; + + sprintf(buf, "%s:%s mod by %s on %s with %s", argv[SH_MACHINE], + argv[SH_SERVICE], argv[SH_MODBY], argv[SH_MODTIME], + argv[SH_MODWITH]); + Put_message(buf); + if (atoi(argv[SH_HOSTERROR])) + sprintf(tmp, "Error %d: %s", atoi(argv[SH_HOSTERROR]), argv[SH_ERRMSG]); + else + strcpy(tmp, "No error"); + sprintf(buf, " %s/%s/%s/%s/%s", + atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", + atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", + atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", + atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", tmp); + Put_message(buf); + Put_message(" Last Try Last Success Value1 Value2 Value3"); + ltt = strsave(atot(argv[SH_LASTTRY])); + sprintf(buf, " %-20s %-20s %-9d %-9d %s", ltt, atot(argv[SH_LASTSUCCESS]), + atoi(argv[SH_VALUE1]), atoi(argv[SH_VALUE2]), argv[SH_VALUE3]); + free(ltt); + Put_message(buf); + Put_message(""); + return MR_CONT; } -showhost(argc, argv) -int argc; -char **argv; +int showhost(int argc, char **argv) { - char *qargv[2]; - int status; - - qargv[SHI_SERVICE] = argv[1]; - qargv[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); - if (status = do_mr_query("get_server_host_info", 2, qargv, shhost, NULL)) - com_err(whoami, status, " getting server/host info"); - return(DM_NORMAL); + char *qargv[2]; + int status; + + qargv[SHI_SERVICE] = argv[1]; + qargv[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); + if ((status = do_mr_query("get_server_host_info", 2, qargv, shhost, NULL))) + com_err(whoami, status, " getting server/host info"); + return DM_NORMAL; } -resetsrverr(argc, argv) -int argc; -char **argv; +int resetsrverr(int argc, char **argv) { - int status; - if (status = do_mr_query("reset_server_error", 1, &argv[1], Scream, NULL)) - com_err(whoami, status, " while resetting server error"); - return(DM_NORMAL); + int status; + if ((status = do_mr_query("reset_server_error", 1, &argv[1], Scream, NULL))) + com_err(whoami, status, " while resetting server error"); + return DM_NORMAL; } -resetsrvc(argc, argv) -int argc; -char **argv; +int resetsrvc(int argc, char **argv) { - int status; - char *qargv[6], buf[BUFSIZ]; - - sprintf(buf, "Reset state for service %s (Y/N)", argv[1]); - if (!Confirm(buf)) - return(DM_NORMAL); - qargv[0] = argv[1]; - qargv[1] = "0"; - qargv[2] = "0"; - qargv[3] = "0"; - qargv[4] = "0"; - qargv[5] = ""; - if (status = do_mr_query("set_server_internal_flags", 6, qargv, - Scream, NULL)) - com_err(whoami, status, " while resetting server error"); - return(DM_NORMAL); + int status; + char *qargv[6], buf[BUFSIZ]; + + sprintf(buf, "Reset state for service %s (Y/N)", argv[1]); + if (!Confirm(buf)) + return DM_NORMAL; + qargv[0] = argv[1]; + qargv[1] = "0"; + qargv[2] = "0"; + qargv[3] = "0"; + qargv[4] = "0"; + qargv[5] = ""; + if ((status = do_mr_query("set_server_internal_flags", 6, qargv, + Scream, NULL))) + com_err(whoami, status, " while resetting server error"); + return DM_NORMAL; } -resethosterr(argc, argv) -int argc; -char **argv; +int resethosterr(int argc, char **argv) { - int status; + int status; - argv[2] = canonicalize_hostname(strsave(argv[2])); - if (status = do_mr_query("reset_server_host_error", 2, &argv[1], - Scream, NULL)) - com_err(whoami, status, " while resetting server/host error"); - return(DM_NORMAL); + argv[2] = canonicalize_hostname(strsave(argv[2])); + if ((status = do_mr_query("reset_server_host_error", 2, &argv[1], + Scream, NULL))) + com_err(whoami, status, " while resetting server/host error"); + return DM_NORMAL; } -resethost(argc, argv) -int argc; -char **argv; +int resethost(int argc, char **argv) { - int status; - char *qargv[9], buf[BUFSIZ]; - - sprintf(buf, "Reset state for service %s on host %s (Y/N)", argv[1], - canonicalize_hostname(strsave(argv[2]))); - if (!Confirm(buf)) - return(DM_NORMAL); - qargv[0] = argv[1]; - qargv[1] = canonicalize_hostname(strsave(argv[2])); - qargv[2] = "0"; - qargv[3] = "0"; - qargv[4] = "0"; - qargv[5] = "0"; - qargv[6] = ""; - qargv[7] = "0"; - qargv[8] = "0"; - if (status = do_mr_query("set_server_host_internal", 9, qargv, - Scream, NULL)) - com_err(whoami, status, " while resetting server/host error"); - return(DM_NORMAL); + int status; + char *qargv[9], buf[BUFSIZ]; + + sprintf(buf, "Reset state for service %s on host %s (Y/N)", argv[1], + canonicalize_hostname(strsave(argv[2]))); + if (!Confirm(buf)) + return DM_NORMAL; + qargv[0] = argv[1]; + qargv[1] = canonicalize_hostname(strsave(argv[2])); + qargv[2] = "0"; + qargv[3] = "0"; + qargv[4] = "0"; + qargv[5] = "0"; + qargv[6] = ""; + qargv[7] = "0"; + qargv[8] = "0"; + if ((status = do_mr_query("set_server_host_internal", 9, qargv, + Scream, NULL))) + com_err(whoami, status, " while resetting server/host error"); + return DM_NORMAL; } -sethostor(argc, argv) -int argc; -char **argv; +int sethostor(int argc, char **argv) { - int status; + int status; - argv[2] = canonicalize_hostname(strsave(argv[2])); - if (status = do_mr_query("set_server_host_override", 2, &argv[1], - Scream, NULL)) - com_err(whoami, status, " while setting server/host override"); - return(DM_NORMAL); + argv[2] = canonicalize_hostname(strsave(argv[2])); + if ((status = do_mr_query("set_server_host_override", 2, &argv[1], + Scream, NULL))) + com_err(whoami, status, " while setting server/host override"); + return DM_NORMAL; } -ghost(argc, argv, cargv) -int argc; -char **argv; -char **cargv; +int ghost(int argc, char **argv, char **cargv) { - cargv[SHI_SERVICE] = strsave(argv[SH_SERVICE]); - cargv[SHI_MACHINE] = strsave(argv[SH_MACHINE]); - cargv[SHI_ENABLE] = strsave(argv[SH_ENABLE]); - cargv[SHI_VALUE1] = strsave(argv[SH_VALUE1]); - cargv[SHI_VALUE2] = strsave(argv[SH_VALUE2]); - cargv[SHI_VALUE3] = strsave(argv[SH_VALUE3]); - cargv[SHI_END] = NULL; - return(MR_CONT); + cargv[SHI_SERVICE] = strsave(argv[SH_SERVICE]); + cargv[SHI_MACHINE] = strsave(argv[SH_MACHINE]); + cargv[SHI_ENABLE] = strsave(argv[SH_ENABLE]); + cargv[SHI_VALUE1] = strsave(argv[SH_VALUE1]); + cargv[SHI_VALUE2] = strsave(argv[SH_VALUE2]); + cargv[SHI_VALUE3] = strsave(argv[SH_VALUE3]); + cargv[SHI_END] = NULL; + return MR_CONT; } -inithost(info) -char **info; +int inithost(char **info) { - info[SHI_MACHINE] = canonicalize_hostname(strsave(info[SH_MACHINE])); - info[SHI_ENABLE] = strsave("1"); - info[SHI_VALUE1] = strsave("0"); - info[SHI_VALUE2] = strsave("0"); - info[SHI_VALUE3] = strsave(""); - info[SHI_END] = NULL; + info[SHI_MACHINE] = canonicalize_hostname(strsave(info[SH_MACHINE])); + info[SHI_ENABLE] = strsave("1"); + info[SHI_VALUE1] = strsave("0"); + info[SHI_VALUE2] = strsave("0"); + info[SHI_VALUE3] = strsave(""); + info[SHI_END] = NULL; } -char **askhost(info) -char **info; +char **askhost(char **info) { - if (GetValueFromUser("Enable", &info[SHI_ENABLE]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Value 1", &info[SHI_VALUE1]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Value 2", &info[SHI_VALUE2]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Value 3", &info[SHI_VALUE3]) == SUB_ERROR) - return(NULL); - return(info); + if (GetValueFromUser("Enable", &info[SHI_ENABLE]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Value 1", &info[SHI_VALUE1]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Value 2", &info[SHI_VALUE2]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Value 3", &info[SHI_VALUE3]) == SUB_ERROR) + return NULL; + return info; } -updatehost(argc, argv) -int argc; -char **argv; +int updatehost(int argc, char **argv) { - char *info[SHI_END+1]; - int status; - - info[SHI_SERVICE] = strsave(argv[1]); - info[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); - if (status = do_mr_query("get_server_host_info", 2, info, ghost, - (char *)info)) { - com_err(whoami, status, " while getting server/host info"); - return(DM_NORMAL); + char *info[SHI_END + 1]; + int status; + + info[SHI_SERVICE] = strsave(argv[1]); + info[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); + if ((status = do_mr_query("get_server_host_info", 2, info, ghost, + (char *)info))) + { + com_err(whoami, status, " while getting server/host info"); + return DM_NORMAL; } - if (askhost(info) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + if (!askhost(info)) + { + Put_message("Aborted."); + return DM_NORMAL; } - if (status = do_mr_query("update_server_host_info", SHI_END, info, - Scream, NULL)) - com_err(whoami, status, " while updating server/host info"); - FreeInfo(info); - return(DM_NORMAL); + if ((status = do_mr_query("update_server_host_info", SHI_END, info, + Scream, NULL))) + com_err(whoami, status, " while updating server/host info"); + FreeInfo(info); + return DM_NORMAL; } -addhost(argc, argv) -int argc; -char **argv; +int addhost(int argc, char **argv) { - char *info[SHI_END+1]; - int status; - - info[SHI_SERVICE] = strsave(argv[1]); - info[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); - inithost(info); - if (askhost(info) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + char *info[SHI_END + 1]; + int status; + + info[SHI_SERVICE] = strsave(argv[1]); + info[SHI_MACHINE] = canonicalize_hostname(strsave(argv[2])); + inithost(info); + if (!askhost(info)) + { + Put_message("Aborted."); + return DM_NORMAL; } - if (status = do_mr_query("add_server_host_info", SHI_END, info, - Scream, NULL)) - com_err(whoami, status, " while adding server/host info"); - FreeInfo(info); - return(DM_NORMAL); + if ((status = do_mr_query("add_server_host_info", SHI_END, info, + Scream, NULL))) + com_err(whoami, status, " while adding server/host info"); + FreeInfo(info); + return DM_NORMAL; } -delserv(argc, argv) -int argc; -char **argv; +int delserv(int argc, char **argv) { - int status; + int status; - if (status = do_mr_query("delete_server_info", 1, &argv[1], Scream, NULL)) - com_err(whoami, status, " while deleting server info"); - return(DM_NORMAL); + if ((status = do_mr_query("delete_server_info", 1, &argv[1], Scream, NULL))) + com_err(whoami, status, " while deleting server info"); + return DM_NORMAL; } -delhost(argc, argv) -int argc; -char **argv; +int delhost(int argc, char **argv) { - int status; + int status; - argv[2] = canonicalize_hostname(strsave(argv[2])); - if (status = do_mr_query("delete_server_host_info", 2, &argv[1], - Scream, NULL)) - com_err(whoami, status, " while deleting server/host info"); - return(DM_NORMAL); + argv[2] = canonicalize_hostname(strsave(argv[2])); + if ((status = do_mr_query("delete_server_host_info", 2, &argv[1], + Scream, NULL))) + com_err(whoami, status, " while deleting server/host info"); + return DM_NORMAL; } -pserv(argc, argv, count) -int argc; -char **argv; -int *count; +int pserv(int argc, char **argv, int *count) { - sprintf(buf, "Service %s", argv[0]); - Put_message(buf); - (*count)++; - return(MR_CONT); + sprintf(buf, "Service %s", argv[0]); + Put_message(buf); + (*count)++; + return MR_CONT; } -phost(argc, argv, count) -int argc; -char **argv; -int *count; +int phost(int argc, char **argv, int *count) { - sprintf(buf, "Host %s:%s", argv[0], argv[1]); - Put_message(buf); - (*count)++; - return(MR_CONT); + sprintf(buf, "Host %s:%s", argv[0], argv[1]); + Put_message(buf); + (*count)++; + return MR_CONT; } -InProgress() +int InProgress(void) { - char *argv[6]; - int status, count = 0; - - argv[0] = argv[2] = "DONTCARE"; - argv[1] = "TRUE"; - if ((status = do_mr_query("qualified_get_server", 3, argv, pserv, - (char *)&count)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting servers"); - argv[0] = "*"; - argv[1] = argv[2] = argv[3] = argv[5] = "DONTCARE"; - argv[4] = "TRUE"; - if ((status = do_mr_query("qualified_get_server_host",6,argv,phost, - (char *)&count)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting server/hosts"); - if (!count) - strcpy(buf, "Nothing is in progress at this time"); - else - sprintf(buf, "%d update%s in progress at this time", count, - count == 1 ? "" : "s"); - Put_message(buf); - return(DM_NORMAL); + char *argv[6]; + int status, count = 0; + + argv[0] = argv[2] = "DONTCARE"; + argv[1] = "TRUE"; + if ((status = do_mr_query("qualified_get_server", 3, argv, pserv, + (char *)&count)) && status != MR_NO_MATCH) + com_err(whoami, status, " while getting servers"); + argv[0] = "*"; + argv[1] = argv[2] = argv[3] = argv[5] = "DONTCARE"; + argv[4] = "TRUE"; + if ((status = do_mr_query("qualified_get_server_host", 6, argv, phost, + (char *)&count)) && status != MR_NO_MATCH) + com_err(whoami, status, " while getting server/hosts"); + if (!count) + strcpy(buf, "Nothing is in progress at this time"); + else + sprintf(buf, "%d update%s in progress at this time", count, + count == 1 ? "" : "s"); + Put_message(buf); + return DM_NORMAL; } -DcmFailed() +int DcmFailed(void) { - char *argv[6]; - int status, count = 0; - - argv[0] = argv[1] = "DONTCARE"; - argv[2] = "TRUE"; - if ((status = do_mr_query("qualified_get_server", 3, argv, pserv, - (char *)&count)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting servers"); - argv[0] = "*"; - argv[1] = argv[2] = argv[3] = argv[4] = "DONTCARE"; - argv[5] = "TRUE"; - if ((status = do_mr_query("qualified_get_server_host",6,argv,phost, - (char *)&count)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting server/hosts"); - if (!count) - strcpy(buf, "Nothing has failed at this time"); - else - sprintf(buf, "%d thing%s ha%s failed at this time", count, - count == 1 ? "" : "s", count == 1 ? "s" : "ve"); - Put_message(buf); - return(DM_NORMAL); + char *argv[6]; + int status, count = 0; + + argv[0] = argv[1] = "DONTCARE"; + argv[2] = "TRUE"; + if ((status = do_mr_query("qualified_get_server", 3, argv, pserv, + (char *)&count)) && status != MR_NO_MATCH) + com_err(whoami, status, " while getting servers"); + argv[0] = "*"; + argv[1] = argv[2] = argv[3] = argv[4] = "DONTCARE"; + argv[5] = "TRUE"; + if ((status = do_mr_query("qualified_get_server_host", 6, argv, phost, + (char *)&count)) && status != MR_NO_MATCH) + com_err(whoami, status, " while getting server/hosts"); + if (!count) + strcpy(buf, "Nothing has failed at this time"); + else + sprintf(buf, "%d thing%s ha%s failed at this time", count, + count == 1 ? "" : "s", count == 1 ? "s" : "ve"); + Put_message(buf); + return DM_NORMAL; } -Dcm() +int Dcm(void) { - int status; - if (Confirm("Are you sure you want to start a DCM now")) - if (status = mr_do_update()) + int status; + if (Confirm("Are you sure you want to start a DCM now")) + { + if ((status = mr_do_update())) com_err(whoami, status, " while triggering update"); - return(DM_NORMAL); + } + return DM_NORMAL; } diff --git a/clients/moira/defs.h b/clients/moira/defs.h index f55f2a63..3574482e 100644 --- a/clients/moira/defs.h +++ b/clients/moira/defs.h @@ -1,17 +1,17 @@ /* This is the file defs.h for the SMS Client, which allows a nieve * user to quickly and easily maintain most parts of the SMS database. * It Contains: useful definitions. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -46,8 +46,8 @@ #define MAX_ARGS_SIZE 100 typedef void (*FVoid)(); /* function pointer typedef. */ -typedef char * (*FCharStar)(); /* function pointer typedef. */ -typedef int (*FInt)(); /* function pointer typedef. */ +typedef char *(*FCharStar)(); /* function pointer typedef. */ +typedef int (*FInt)(); /* function pointer typedef. */ typedef int Bool; @@ -62,9 +62,9 @@ typedef int Bool; /* for use with insqueue and remque. */ struct qelem { - struct qelem *q_forw; - struct qelem *q_back; - char * q_data; + struct qelem *q_forw; + struct qelem *q_back; + char *q_data; }; #endif /* _defs_header_ */ /* Do Not Add Anything After This Line */ diff --git a/clients/moira/delete.c b/clients/moira/delete.c index b8085920..a06f2b1f 100644 --- a/clients/moira/delete.c +++ b/clients/moira/delete.c @@ -5,17 +5,17 @@ /* This is the file delete.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: functions for deleting users and lists. - * + * * Created: 5/18/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -38,44 +38,44 @@ * Returns: none. */ -int -CheckListForDeletion(name, verbose) -char * name; -Bool verbose; +int CheckListForDeletion(char *name, Bool verbose) { - struct qelem *elem = NULL; - int status; - char *args[2], buf[BUFSIZ], **info; - - if ( (status = do_mr_query("count_members_of_list", 1, &name, StoreInfo, - (char *) &elem)) != 0) { - com_err(program_name, status, - " in DeleteList (count_members_of_list)."); - return(SUB_NORMAL); + struct qelem *elem = NULL; + int status; + char *args[2], buf[BUFSIZ], **info; + + if ((status = do_mr_query("count_members_of_list", 1, &name, StoreInfo, + (char *) &elem))) + { + com_err(program_name, status, " in DeleteList (count_members_of_list)."); + return SUB_NORMAL; } - info = (char **) elem->q_data; - if ( strcmp(info[NAME],"0") == 0) { - if (verbose) { - sprintf(buf, "Delete the empty list %s? ", name); - switch (YesNoQuestion(buf, FALSE)) { + info = (char **) elem->q_data; + if (!strcmp(info[NAME], "0")) + { + if (verbose) + { + sprintf(buf, "Delete the empty list %s? ", name); + switch (YesNoQuestion(buf, FALSE)) + { case TRUE: - break; + break; case FALSE: - Put_message("Not deleting this list."); - FreeQueue(elem); - return(SUB_NORMAL); + Put_message("Not deleting this list."); + FreeQueue(elem); + return SUB_NORMAL; default: - Put_message("Aborting Deletion!"); - FreeQueue(elem); - return(SUB_ERROR); + Put_message("Aborting Deletion!"); + FreeQueue(elem); + return SUB_ERROR; } } - args[0] = "foo"; /* not used. */ - args[1] = name; - DeleteList(2, args); + args[0] = "foo"; /* not used. */ + args[1] = name; + DeleteList(2, args); } - FreeQueue(elem); - return(SUB_NORMAL); + FreeQueue(elem); + return SUB_NORMAL; } /* Function Name: CheckAce @@ -86,41 +86,39 @@ Bool verbose; * Returns: none. */ -void -CheckAce(type, name, verbose) -char * type, *name; -Bool verbose; +void CheckAce(char *type, char *name, Bool verbose) { - char *args[2], buf[BUFSIZ]; - int status; - - if ( strcmp(type, "LIST") != 0 ) - return; /* If the ace is not a list the ignore it. */ - - args[0] = type; - args[1] = name; - status = do_mr_query("get_ace_use", 2, args, NullFunc, (char *) NULL); - if (status != MR_NO_MATCH) - return; /* If this query fails the ace will + char *args[2], buf[BUFSIZ]; + int status; + + if (strcmp(type, "LIST")) + return; /* If the ace is not a list the ignore it. */ + + args[0] = type; + args[1] = name; + status = do_mr_query("get_ace_use", 2, args, NullFunc, NULL); + if (status != MR_NO_MATCH) + return; /* If this query fails the ace will not be deleted even if it is empty. */ - if (verbose) { - sprintf(buf, "Delete the unused Access Control Entity (ACE) %s? ", - name); - if ( YesNoQuestion(buf, FALSE) != TRUE) { - Put_message("Aborting Deletion!"); - return; + if (verbose) + { + sprintf(buf, "Delete the unused Access Control Entity (ACE) %s? ", name); + if (YesNoQuestion(buf, FALSE) != TRUE) + { + Put_message("Aborting Deletion!"); + return; } } -/* - * Delete the ACE. - * - * NOTE: Delete list expects only the name of the list to delete in argv[1]. - * since, 'args' already satisfies this, there is no need to create - * a special argument list. - */ - DeleteList(2, args); + /* + * Delete the ACE. + * + * NOTE: Delete list expects only the name of the list to delete in argv[1]. + * since, 'args' already satisfies this, there is no need to create + * a special argument list. + */ + DeleteList(2, args); } - + /* Function Name: CheckIfAce * Description: Checks to see if this is an ace of another data object. @@ -129,56 +127,56 @@ Bool verbose; * succeed. */ -int -CheckIfAce(name, type, verbose) -char * name, * type; -Bool verbose; +int CheckIfAce(char *name, char *type, Bool verbose) { - char * args[2], buf[BUFSIZ], **info; - struct qelem *local, *elem; - int status; - elem = NULL; - - args[0] = type; - args[1] = name; - switch (status = do_mr_query("get_ace_use", 2, args, - StoreInfo, (char *) &elem)) { + char *args[2], buf[BUFSIZ], **info; + struct qelem *local, *elem; + int status; + elem = NULL; + + args[0] = type; + args[1] = name; + switch ((status = do_mr_query("get_ace_use", 2, args, + StoreInfo, (char *) &elem))) + { case MR_NO_MATCH: - return(DM_NORMAL); + return DM_NORMAL; case MR_SUCCESS: - local = elem = QueueTop(elem); - info = (char **) local->q_data; - if (QueueCount(elem) == 1 && - !strcmp(info[0], "LIST") && - !strcmp(info[1], name)) { - FreeQueue(elem); - return(DM_NORMAL); + local = elem = QueueTop(elem); + info = (char **) local->q_data; + if (QueueCount(elem) == 1 && + !strcmp(info[0], "LIST") && + !strcmp(info[1], name)) + { + FreeQueue(elem); + return DM_NORMAL; } - if (verbose) { - sprintf(buf, "%s %s %s", type, name, - "is the ACE for the following data objects:"); - Put_message(buf); - Put_message(""); - for (; local != NULL; local = local->q_forw) { - info = (char **) local->q_data; - if (!strcmp(info[0], "LIST") && - !strcmp(info[1], name)) - continue; - Print(CountArgs(info), info, NULL); + if (verbose) + { + sprintf(buf, "%s %s %s", type, name, + "is the ACE for the following data objects:"); + Put_message(buf); + Put_message(""); + for (; local != NULL; local = local->q_forw) + { + info = (char **) local->q_data; + if (!strcmp(info[0], "LIST") && + !strcmp(info[1], name)) + continue; + Print(CountArgs(info), info, NULL); } - Put_message(""); - Put_message( - "The ACE for each of these items must be changed before"); - sprintf(buf,"the %s %s can be deleted.\n", type, name); - Put_message(buf); + Put_message(""); + Put_message("The ACE for each of these items must be changed before"); + sprintf(buf, "the %s %s can be deleted.\n", type, name); + Put_message(buf); } - break; + break; default: - com_err(program_name, status, " in CheckIfAce (get_ace_use)."); - return(SUB_ERROR); + com_err(program_name, status, " in CheckIfAce (get_ace_use)."); + return SUB_ERROR; } - FreeQueue(elem); - return(SUB_ERROR); + FreeQueue(elem); + return SUB_ERROR; } /* Function Name: RemoveItemFromLists @@ -190,83 +188,86 @@ Bool verbose; * Returns: SUB_ERROR if there is an error. */ -int -RemoveItemFromLists(name, type, elem, verbose) -char * name, *type; -struct qelem ** elem; -int verbose; +int RemoveItemFromLists(char *name, char *type, struct qelem **elem, + int verbose) { - struct qelem *local; - char *args[10], temp_buf[BUFSIZ]; - int lists; - register int status; - - args[0] = type; - args[1] = name; - *elem = NULL; - -/* - * Get all list of which this item is a member, and store them in a queue. - */ + struct qelem *local; + char *args[10], temp_buf[BUFSIZ]; + int lists; + register int status; - status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, - (char *) elem); + args[0] = type; + args[1] = name; + *elem = NULL; - if (status == MR_NO_MATCH) - return(SUB_NORMAL); + /* + * Get all list of which this item is a member, and store them in a queue. + */ - if (status != MR_SUCCESS) { - com_err(program_name, status, " in DeleteList (get_lists_of_member)."); - return(SUB_ERROR); - } + status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, + (char *) elem); -/* - * If verbose mode, ask user of we should remove our list from - * all these lists. - */ + if (status == MR_NO_MATCH) + return SUB_NORMAL; + + if (status != MR_SUCCESS) + { + com_err(program_name, status, " in DeleteList (get_lists_of_member)."); + return SUB_ERROR; + } - local = *elem = QueueTop(*elem); - lists = QueueCount(*elem); - if (lists == 0) - return(SUB_NORMAL); - if (verbose) { - sprintf(temp_buf, "%s %s is a member of %d other list%s.\n", type, - name, lists, ((lists == 1) ? "" : "s") ); - Put_message(temp_buf); - while (local != NULL) { - char ** info = (char **) local->q_data; - Print( 1, &info[GLOM_NAME], (char *) NULL); + /* + * If verbose mode, ask user of we should remove our list from + * all these lists. + */ + + local = *elem = QueueTop(*elem); + lists = QueueCount(*elem); + if (lists == 0) + return SUB_NORMAL; + if (verbose) + { + sprintf(temp_buf, "%s %s is a member of %d other list%s.\n", type, + name, lists, ((lists == 1) ? "" : "s")); + Put_message(temp_buf); + while (local) + { + char **info = (char **) local->q_data; + Print(1, &info[GLOM_NAME], (char *) NULL); local = local->q_forw; } Put_message(" "); /* Blank Line. */ - sprintf(temp_buf,"Remove %s %s from these lists? ", type, name); - if (YesNoQuestion(temp_buf, FALSE) != TRUE) { + sprintf(temp_buf, "Remove %s %s from these lists? ", type, name); + if (YesNoQuestion(temp_buf, FALSE) != TRUE) + { Put_message("Aborting..."); FreeQueue(*elem); *elem = NULL; - return(SUB_ERROR); - } + return SUB_ERROR; + } } -/* - * Remove this list from all lists that it is a member of. - */ - - local = *elem; - args[DM_MEMBER] = name; - args[DM_TYPE] = type; - while (local != NULL) { - char ** info = (char **) local->q_data; - args[DM_LIST] = info[GLOM_NAME]; - if ( (status = do_mr_query("delete_member_from_list", - 3, args, Scream, NULL)) != 0) { - com_err(program_name, status, " in delete_member\nAborting\n"); - FreeQueue(*elem); - return(SUB_ERROR); + /* + * Remove this list from all lists that it is a member of. + */ + + local = *elem; + args[DM_MEMBER] = name; + args[DM_TYPE] = type; + while (local) + { + char **info = (char **) local->q_data; + args[DM_LIST] = info[GLOM_NAME]; + if ((status = do_mr_query("delete_member_from_list", + 3, args, Scream, NULL))) + { + com_err(program_name, status, " in delete_member\nAborting\n"); + FreeQueue(*elem); + return SUB_ERROR; } - local = local->q_forw; + local = local->q_forw; } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: RemoveMembersOfList @@ -276,70 +277,73 @@ int verbose; * Returns: SUB_ERROR - if we could not delete, or the user abouted. */ -int -RemoveMembersOfList(name, verbose) -char * name; -Bool verbose; +int RemoveMembersOfList(char *name, Bool verbose) { - char buf[BUFSIZ], *args[10]; - struct qelem *local, *elem = NULL; - int status, members; -/* - * Get the members of this list. - */ - status = do_mr_query("get_members_of_list", 1, &name, StoreInfo, - (char *) &elem); - if (status == MR_NO_MATCH) - return(SUB_NORMAL); - - if (status != 0) { - com_err(program_name, status, " in DeleteList (get_members_of_list)."); - return(SUB_ERROR); + char buf[BUFSIZ], *args[10]; + struct qelem *local, *elem = NULL; + int status, members; + /* + * Get the members of this list. + */ + status = do_mr_query("get_members_of_list", 1, &name, StoreInfo, + (char *) &elem); + if (status == MR_NO_MATCH) + return SUB_NORMAL; + + if (status) + { + com_err(program_name, status, " in DeleteList (get_members_of_list)."); + return SUB_ERROR; } -/* - * If verbose mode, then ask the user if we should delete. - */ - local = elem = QueueTop(elem); - if ( (members = QueueCount(elem)) == 0) - return(SUB_NORMAL); - if (verbose) { - sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem), - ((members == 1) ? "" : "s") ); - Put_message(buf); - Put_message(" "); /* Blank Line. */ - while (local != NULL) { - char ** info = (char **) local->q_data; - Print( CountArgs(info), info, NULL); - local = local->q_forw; + /* + * If verbose mode, then ask the user if we should delete. + */ + local = elem = QueueTop(elem); + if (!(members = QueueCount(elem))) + return SUB_NORMAL; + if (verbose) + { + sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem), + ((members == 1) ? "" : "s")); + Put_message(buf); + Put_message(" "); /* Blank Line. */ + while (local) + { + char **info = (char **) local->q_data; + Print(CountArgs(info), info, NULL); + local = local->q_forw; } - Put_message(" "); /* Blank Line. */ - sprintf(buf, "Remove th%s member%s from list %s? ", - ((members == 1) ? "is" : "ese"), - ((members == 1) ? "" : "s"), name ); - if ( YesNoQuestion(buf, FALSE) != TRUE) { - Put_message("Aborting..."); - FreeQueue(elem); - return(SUB_ERROR); + Put_message(" "); /* Blank Line. */ + sprintf(buf, "Remove th%s member%s from list %s? ", + ((members == 1) ? "is" : "ese"), + ((members == 1) ? "" : "s"), name); + if (YesNoQuestion(buf, FALSE) != TRUE) + { + Put_message("Aborting..."); + FreeQueue(elem); + return SUB_ERROR; } } -/* - * Perform The Removal. - */ - local = elem; - args[0] = name; - while (local != NULL) { - char ** info = (char **) local->q_data; - args[1] = info[0]; - args[2] = info[1]; - if ( (status = do_mr_query("delete_member_from_list", - 3, args, Scream, NULL)) != 0) { - com_err(program_name, status, " in delete_member\nAborting\n"); - FreeQueue(elem); - return(SUB_ERROR); + /* + * Perform The Removal. + */ + local = elem; + args[0] = name; + while (local) + { + char **info = (char **) local->q_data; + args[1] = info[0]; + args[2] = info[1]; + if ((status = do_mr_query("delete_member_from_list", + 3, args, Scream, NULL))) + { + com_err(program_name, status, " in delete_member\nAborting\n"); + FreeQueue(elem); + return SUB_ERROR; } - local = local->q_forw; + local = local->q_forw; } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: DeleteUserGroup @@ -351,38 +355,40 @@ Bool verbose; * Returns: MR_ERROR if there is an error. */ -int -DeleteUserGroup(name, verbose) -char * name; -Bool verbose; +int DeleteUserGroup(char *name, Bool verbose) { - int status, ans; - char buf[BUFSIZ], *args[10]; - - status = do_mr_query("get_list_info", 1, &name, NullFunc, (char *) NULL); - if (status == 0) { - if (verbose) { - sprintf(buf, "There is also a list named %s, delete it?", name); - ans = YesNoQuestion(buf, FALSE); - if (ans == FALSE) { - Put_message("Leaving group alone."); - return(SUB_NORMAL); + int status, ans; + char buf[BUFSIZ], *args[10]; + + status = do_mr_query("get_list_info", 1, &name, NullFunc, (char *) NULL); + if (!status) + { + if (verbose) + { + sprintf(buf, "There is also a list named %s, delete it?", name); + ans = YesNoQuestion(buf, FALSE); + if (ans == FALSE) + { + Put_message("Leaving group alone."); + return SUB_NORMAL; } - if (ans < 0) { - Put_message("Aborting...\n"); - return(SUB_ERROR); + if (ans < 0) + { + Put_message("Aborting...\n"); + return SUB_ERROR; } } - /* ans == TRUE || ~verbose */ - args[0] = "foo"; /* not used. */ - args[1] = name; - DeleteList(2, args); + /* ans == TRUE || ~verbose */ + args[0] = "foo"; /* not used. */ + args[1] = name; + DeleteList(2, args); } - else if (status != MR_NO_MATCH) { - com_err(program_name, status, " Aborting Delete User."); - return(SUB_ERROR); + else if (status != MR_NO_MATCH) + { + com_err(program_name, status, " Aborting Delete User."); + return SUB_ERROR; } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: DeleteHomeFilesys @@ -392,45 +398,46 @@ Bool verbose; * Returns: SUB_NORMAL if home filesystem deleted, or nonexistant. */ -int -DeleteHomeFilesys(name, verbose) -char * name; -Bool verbose; +int DeleteHomeFilesys(char *name, Bool verbose) { - int status; - char buf[BUFSIZ]; - - switch (status = do_mr_query("get_filesys_by_label", 1, &name, NullFunc, - (char *) NULL)) { + int status; + char buf[BUFSIZ]; + + switch ((status = do_mr_query("get_filesys_by_label", 1, &name, NullFunc, + NULL))) + { case MR_NO_MATCH: - break; + break; case MR_SUCCESS: - if (verbose) { - sprintf(buf, "Delete the filesystem named %s (y/n)?", name); - switch (YesNoQuestion(buf, FALSE)) { + if (verbose) + { + sprintf(buf, "Delete the filesystem named %s (y/n)?", name); + switch (YesNoQuestion(buf, FALSE)) + { case FALSE: - Put_message("Filesystem Not Deleted, continuing...\n"); - return(SUB_NORMAL); + Put_message("Filesystem Not Deleted, continuing...\n"); + return SUB_NORMAL; case TRUE: - break; + break; default: - Put_message("Filesystem Not Deleted, aborting...\n\n"); - return(SUB_ERROR); + Put_message("Filesystem Not Deleted, aborting...\n\n"); + return SUB_ERROR; } } - if ( (status = do_mr_query("delete_filesys", 1, &name, Scream, - (char *) NULL) ) != MR_SUCCESS) { - com_err(program_name, status, " in delete_filesys."); - return(SUB_ERROR); + if ((status = do_mr_query("delete_filesys", 1, &name, Scream, + NULL)) != MR_SUCCESS) + { + com_err(program_name, status, " in delete_filesys."); + return SUB_ERROR; } - else - Put_message("Filesystem Successfully Deleted."); - break; + else + Put_message("Filesystem Successfully Deleted."); + break; default: - com_err(program_name, status, " in get_filesystem_by_label)."); - return(SUB_ERROR); + com_err(program_name, status, " in get_filesystem_by_label)."); + return SUB_ERROR; } - return(SUB_NORMAL); + return SUB_NORMAL; } #ifndef ATHENA @@ -440,21 +447,20 @@ Bool verbose; * Returns: SUB_ERROR if the deletion failed. */ -static int -RealDeleteUser(name) -char * name; +static int RealDeleteUser(char *name) { - char buf[BUFSIZ]; - int status; - - if ( (status = do_mr_query("delete_user", 1, &name, Scream, - (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, status, ": user not deleted"); - return(SUB_ERROR); + char buf[BUFSIZ]; + int status; + + if ((status = do_mr_query("delete_user", 1, &name, Scream, + NULL)) != MR_SUCCESS) + { + com_err(program_name, status, ": user not deleted"); + return SUB_ERROR; } - (void) sprintf(buf, "User %s deleted.", name); - Put_message(buf); - return(SUB_NORMAL); + sprintf(buf, "User %s deleted.", name); + Put_message(buf); + return SUB_NORMAL; } #endif @@ -464,22 +470,21 @@ char * name; * Returns: SUB_ERROR if the deletion failed. */ -static int -RealDeleteList(name) -char * name; +static int RealDeleteList(char *name) { - char buf[BUFSIZ]; - int status; - - if ( (status = do_mr_query("delete_list", 1, &name, Scream, - (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, status, ": list not deleted"); - return(SUB_ERROR); + char buf[BUFSIZ]; + int status; + + if ((status = do_mr_query("delete_list", 1, &name, Scream, + NULL)) != MR_SUCCESS) + { + com_err(program_name, status, ": list not deleted"); + return SUB_ERROR; } - (void) sprintf(buf, "List %s deleted.", name); - Put_message(buf); - Put_message(""); - return(SUB_NORMAL); + sprintf(buf, "List %s deleted.", name); + Put_message(buf); + Put_message(""); + return SUB_NORMAL; } /* Function Name: AttemptToDeleteList @@ -494,76 +499,75 @@ char * name; * one way or the other. */ -void -AttemptToDeleteList(list_info, ask_first) -char ** list_info; -Bool ask_first; +void AttemptToDeleteList(char **list_info, Bool ask_first) { - int status; - struct qelem *local, *member_of; - char *name = list_info[L_NAME]; - member_of = NULL; - - /* - * Attempt delete. - will only work if: - * 1) This list has no members. - * 2) This list in a member of no other lists. - * 3) This list is not an ace of another object. - */ - - switch (status = do_mr_query("delete_list", 1, &name, - Scream, (char *) NULL)) { + int status; + struct qelem *local, *member_of; + char *name = list_info[L_NAME]; + member_of = NULL; + + /* + * Attempt delete. - will only work if: + * 1) This list has no members. + * 2) This list in a member of no other lists. + * 3) This list is not an ace of another object. + */ + + switch ((status = do_mr_query("delete_list", 1, &name, Scream, NULL))) + { case MR_SUCCESS: - Put_message("List Sucessfully Deleted."); - CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); - break; + Put_message("List Sucessfully Deleted."); + CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); + break; case MR_IN_USE: - /* - * This list is in use. Try to find out why, - * and for the cases where we have a good idea of - * what to do we will query and then do it. - */ - - if ((CheckIfAce(name, "list", ask_first) != SUB_NORMAL) || - (RemoveItemFromLists(name, "list", - &member_of, ask_first) != SUB_NORMAL)) - break; - /* - * If the list is it's own ACL, then make the person performing - * the delete the owner before removing this person from the list - */ - if (!strcmp(list_info[L_ACE_TYPE], "LIST") && - !strcmp(list_info[L_ACE_NAME], list_info[L_NAME])) { - free(list_info[L_ACE_TYPE]); - free(list_info[L_ACE_NAME]); - list_info[L_ACE_TYPE] = Strsave("USER"); - list_info[L_ACE_NAME] = Strsave(user); - SlipInNewName(list_info, Strsave(list_info[L_NAME])); - if ((status = do_mr_query("update_list", CountArgs(list_info)-3, - list_info, Scream, (char *) NULL)) - != MR_SUCCESS) { - com_err(program_name, status, " while updating list owner"); - Put_message("List may be only partly deleted."); - } + /* + * This list is in use. Try to find out why, + * and for the cases where we have a good idea of + * what to do we will query and then do it. + */ + + if ((CheckIfAce(name, "list", ask_first) != SUB_NORMAL) || + (RemoveItemFromLists(name, "list", + &member_of, ask_first) != SUB_NORMAL)) + break; + /* + * If the list is it's own ACL, then make the person performing + * the delete the owner before removing this person from the list + */ + if (!strcmp(list_info[L_ACE_TYPE], "LIST") && + !strcmp(list_info[L_ACE_NAME], list_info[L_NAME])) + { + free(list_info[L_ACE_TYPE]); + free(list_info[L_ACE_NAME]); + list_info[L_ACE_TYPE] = Strsave("USER"); + list_info[L_ACE_NAME] = Strsave(user); + SlipInNewName(list_info, Strsave(list_info[L_NAME])); + if ((status = do_mr_query("update_list", CountArgs(list_info) - 3, + list_info, Scream, NULL)) != MR_SUCCESS) + { + com_err(program_name, status, " while updating list owner"); + Put_message("List may be only partly deleted."); + } } - if ((RemoveMembersOfList(name, ask_first) == SUB_NORMAL) && - (RealDeleteList(name) == SUB_NORMAL) ) + if ((RemoveMembersOfList(name, ask_first) == SUB_NORMAL) && + (RealDeleteList(name) == SUB_NORMAL)) { /* if... */ - CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); - - local = QueueTop(member_of); - while (local != NULL) { - char ** info = (char **) local->q_data; - if (CheckListForDeletion(info[LM_LIST], ask_first) == SUB_ERROR) - break; - local = local->q_forw; + CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); + + local = QueueTop(member_of); + while (local) + { + char **info = (char **) local->q_data; + if (CheckListForDeletion(info[LM_LIST], ask_first) == SUB_ERROR) + break; + local = local->q_forw; } - FreeQueue(member_of); + FreeQueue(member_of); } - break; + break; default: - com_err(program_name, status, " in DeleteList (delete_list)."); - break; + com_err(program_name, status, " in DeleteList (delete_list)."); + break; } } @@ -573,62 +577,66 @@ Bool ask_first; * Returns: DM Status Code. */ -/* ARGSUSED */ -int -DeleteList(argc, argv) -int argc; -char *argv[]; +int DeleteList(int argc, char *argv[]) { - char buf[BUFSIZ]; - struct qelem *top, *list; - register int status; - Bool one_list; - - list = NULL; - - switch(status = do_mr_query("get_list_info", 1, argv + 1, - StoreInfo, (char *) &list)){ + char buf[BUFSIZ]; + struct qelem *top, *list; + register int status; + Bool one_list; + + list = NULL; + + switch ((status = do_mr_query("get_list_info", 1, argv + 1, + StoreInfo, (char *) &list))) + { case MR_SUCCESS: - break; -/* case MR_NO_WILDCARD: - Put_message("Wildcards are not accepted here."); - return(DM_NORMAL); -*/ case MR_NO_MATCH: + break; +#if 0 + case MR_NO_WILDCARD: + Put_message("Wildcards are not accepted here."); + return DM_NORMAL; +#endif + case MR_NO_MATCH: case MR_LIST: - Put_message("There is no list that matches that name."); - return(DM_NORMAL); + Put_message("There is no list that matches that name."); + return DM_NORMAL; default: - com_err(program_name, status, " in DeleteList (get_list_info)."); - return(DM_NORMAL); + com_err(program_name, status, " in DeleteList (get_list_info)."); + return DM_NORMAL; } - - top = list = QueueTop(list); - one_list = (QueueCount(list) == 1); - while (list != NULL) { - char ** info = (char**) list->q_data; - if (one_list) { - sprintf( buf, "Are you sure that you want to delete the list %s", - info[L_NAME]); - if ( Confirm(buf) ) AttemptToDeleteList(info, TRUE); + + top = list = QueueTop(list); + one_list = (QueueCount(list) == 1); + while (list) + { + char **info = (char **) list->q_data; + if (one_list) + { + sprintf(buf, "Are you sure that you want to delete the list %s", + info[L_NAME]); + if (Confirm(buf)) + AttemptToDeleteList(info, TRUE); } - else { - sprintf(buf, "Delete the list %s", info[L_NAME]); - switch( YesNoQuestion( buf, FALSE ) ) { + else + { + sprintf(buf, "Delete the list %s", info[L_NAME]); + switch (YesNoQuestion(buf, FALSE)) + { case TRUE: - AttemptToDeleteList(info, TRUE); - break; + AttemptToDeleteList(info, TRUE); + break; case FALSE: - break; + break; default: - Put_message ("Aborting..."); - FreeQueue(top); - return(DM_QUIT); + Put_message("Aborting..."); + FreeQueue(top); + return DM_QUIT; } } - list = list->q_forw; + list = list->q_forw; } - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: DeleteUser @@ -637,78 +645,77 @@ char *argv[]; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeleteUser(argc, argv) -int argc; -char ** argv; +int DeleteUser(int argc, char **argv) { - int status; - char buf[BUFSIZ]; - char * name = argv[1]; /* name of the user we are deleting. */ + int status; + char buf[BUFSIZ]; + char *name = argv[1]; /* name of the user we are deleting. */ #ifndef ATHENA - struct qelem *local, *member_of = NULL; + struct qelem *local, *member_of = NULL; #endif - if (!ValidName(name)) - return(DM_NORMAL); + if (!ValidName(name)) + return DM_NORMAL; - if (!Confirm("Are you sure that you want to delete this user?")) - return(DM_NORMAL); + if (!Confirm("Are you sure that you want to delete this user?")) + return DM_NORMAL; - status = do_mr_query("delete_user", 1, &name, Scream, (char *) NULL); - if (status != MR_IN_USE && status != 0) { - com_err(program_name, status, ": user not deleted"); - return(DM_NORMAL); + status = do_mr_query("delete_user", 1, &name, Scream, NULL); + if (status != MR_IN_USE && status != 0) + { + com_err(program_name, status, ": user not deleted"); + return DM_NORMAL; } - if (status == 0) { - sprintf(buf,"User %s deleted.", name); - Put_message(buf); + if (status == 0) + { + sprintf(buf, "User %s deleted.", name); + Put_message(buf); #ifdef ATHENA - /* delete this return if the policy decision below is reversed */ - return(DM_NORMAL); + /* delete this return if the policy decision below is reversed */ + return DM_NORMAL; #endif } #ifdef ATHENA -/* Design decision not to allow registered users to be deleted. - */ - Put_message("Sorry, registered users cannot be deleted from the database."); - Put_message("Deactivate the user now, and the system manager will expunge later."); + /* Design decision not to allow registered users to be deleted. + */ + Put_message("Sorry, registered users cannot be deleted from the database."); + Put_message("Deactivate the user now, and the system manager will expunge later."); #else - else if (status == MR_IN_USE) { - -/* - * Check: - * 1) Query - Delete home filesytem. - * 2) Query - Delete user Group. - * 2) Is the user an ACE of any object in the database? - * 3) Query - Remove user from all list of which he is a member. - * - * If all these have been accomplished, then attempt to delete the user again. - */ - if ( (DeleteHomeFilesys(name, TRUE) == SUB_ERROR) || - (DeleteUserGroup(name, TRUE) == SUB_ERROR) || - (CheckIfAce(name, "user", TRUE) == SUB_ERROR) || - (RemoveItemFromLists(name, "user", - &member_of, TRUE) == SUB_ERROR) || - (RealDeleteUser(name) == SUB_ERROR) ) { - return(DM_NORMAL); - } + else if (status == MR_IN_USE) + { + + /* + * Check: + * 1) Query - Delete home filesytem. + * 2) Query - Delete user Group. + * 2) Is the user an ACE of any object in the database? + * 3) Query - Remove user from all list of which he is a member. + * + * If all these have been accomplished, then attempt to delete + * the user again. + */ + if ((DeleteHomeFilesys(name, TRUE) == SUB_ERROR) || + (DeleteUserGroup(name, TRUE) == SUB_ERROR) || + (CheckIfAce(name, "user", TRUE) == SUB_ERROR) || + (RemoveItemFromLists(name, "user", &member_of, TRUE) == SUB_ERROR) || + (RealDeleteUser(name) == SUB_ERROR)) + return DM_NORMAL; } -/* - * Query - Delete all empty lists created by removing this user from them. - */ + /* + * Query - Delete all empty lists created by removing this user from them. + */ - local = member_of; - while (local != NULL) { - char ** info = (char **) local->q_data; - if (CheckListForDeletion(info[0], TRUE) == SUB_ERROR) - break; - local = local->q_forw; + local = member_of; + while (local) + { + char **info = (char **) local->q_data; + if (CheckListForDeletion(info[0], TRUE) == SUB_ERROR) + break; + local = local->q_forw; } - FreeQueue(member_of); /* Free memory and return. */ + FreeQueue(member_of); /* Free memory and return. */ #endif - return(DM_NORMAL); + return DM_NORMAL; } diff --git a/clients/moira/f_defs.h b/clients/moira/f_defs.h index 886e6766..f9edf4fc 100644 --- a/clients/moira/f_defs.h +++ b/clients/moira/f_defs.h @@ -1,17 +1,17 @@ -/* This is the file f_defs.h for the SMS Client, which allows a nieve +/* This is the file f_defs.h for the SMS Client, which allows a * user to quickly and easily maintain most parts of the SMS database. * It Contains: useful definitions. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -20,10 +20,6 @@ #ifndef _f_defs_ #define _f_defs_ -/* general Library functions. */ - -char * malloc(); - /* attach.c */ int GetFS(); /* Get information about named filsys. */ @@ -61,7 +57,7 @@ int DeleteCluster(); /* removes a cluste from the database. */ int ShowClusterInfo(); /* show information about a cluster. */ int MachinesInCluster(); /* list all machines in a give cluster. */ -int AddCluster(); +int AddCluster(); int UpdateCluster(); /* add, update, and delete clusters. */ int DeleteCluster(); @@ -87,7 +83,7 @@ int DeleteList(), DeleteUser(); int ListByMember(); /* list all list to which a member belongs. */ int ListByAdministrator(); /* list all list to which a given member can administer. */ -int ListAllGroups(); +int ListAllGroups(); int ListAllPublicMailLists(); /* List misc. types of lists. */ int ListAllMailLists(); @@ -99,10 +95,10 @@ int ListStringMembers(); int ShowListInfo(); /* show info about a list. */ int UpdateList(); /* change info about a list. */ -int InterRemoveItemFromLists(); /* Interactivly remove an item from all lists*/ +int InterRemoveItemFromLists(); /* Interactivly remove item from all lists */ int ListmaintMemberMenuEntry(); /* entry and exit functions for member menu. */ -int ListmaintMemberMenuExit(); +int ListmaintMemberMenuExit(); int ListHelp(); /* help function for lists. */ /* nfs.c */ @@ -173,8 +169,8 @@ int TableStats(), ShowClients(), ShowValue(), ShowAlias(); /* utils.c */ -/* - * For descriptions of all of these functions see the +/* + * For descriptions of all of these functions see the * internals documentation. */ @@ -185,16 +181,16 @@ void FreeQueue(); /* Frees an entire queue. */ void FreeAndClear(); /* Frees a single pointer. */ void Loop(); /* Performs an operation on every item in a queue. */ -void QueryLoop(); /* Queries the user before performing +void QueryLoop(); /* Queries the user before performing an operation on every item in a queue. */ void RemoveHyphens(); /* Removes the hyphens from a string. */ void SlipInNewName(); /* Slips a new name into an argument list in the correct place. */ -int CountArgs(); /* Counts the strings in a NULL terminated +int CountArgs(); /* Counts the strings in a NULL terminated array. */ int GetValueFromUser(); /* Updates value by asking the user. */ -int GetYesNoValueFromUser(); /* Updates a yes/no value by asking the user.*/ +int GetYesNoValueFromUser(); /* Updates yes/no value by asking the user. */ int GetFSTypes(); /* Gets Filesystem types from a user. */ int NullFunc(); /* NULL return function. */ int Print(); /* Prints out array of strings. */ @@ -208,7 +204,7 @@ char *CanonicalizeHostname(); /* this is what it does. */ char *NullPrint(); /* Prints nothing, returns argv[0]. */ char *Strsave(); /* allocated space for a copy of the string. */ char *atot(); /* convert unix time to date string */ -struct qelem * QueueTop(); /* Finds the top of a queue. */ +struct qelem *QueueTop(); /* Finds the top of a queue. */ Bool Confirm(); /* Confirms a delete operation, with user. */ Bool YesNoQuestion(); /* Asks a user a yes no type question. */ Bool YesNoQuitQuestion(); /* Asks a user a yes - no - quit question. */ diff --git a/clients/moira/globals.c b/clients/moira/globals.c index e901156f..b3583ee0 100644 --- a/clients/moira/globals.c +++ b/clients/moira/globals.c @@ -5,17 +5,17 @@ /* This is the file globals.c for the Moira Client, which allows a nieve * user to quickly and easily maintain most parts of the Moira database. * It Contains: globals variable definitions. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -23,7 +23,7 @@ #include "defs.h" Bool verbose; /* TRUE if verbose mode is active (default). */ -Bool found_some; /* used by lists.c for determining if there +Bool found_some; /* used by lists.c for determining if there are any members of a given type. */ char *user; /* The name of the user executing this program. */ diff --git a/clients/moira/globals.h b/clients/moira/globals.h index 4d4cb24f..bc259724 100644 --- a/clients/moira/globals.h +++ b/clients/moira/globals.h @@ -1,17 +1,17 @@ /* This is the file globals.h for the SMS Client, which allows a nieve * user to quickly and easily maintain most parts of the SMS database. * It Contains: globals variable definitions. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -22,7 +22,7 @@ #define _sms_client_globals_ extern Bool verbose; /* TRUE if verbose mode is active (default). */ -extern Bool found_some; /* used by lists.c for determining if there +extern Bool found_some; /* used by lists.c for determining if there are any members of a given type. */ extern char *user; /* The name of the user executing this program. */ diff --git a/clients/moira/lists.c b/clients/moira/lists.c index 7a7e6c4d..1bd5f7f8 100644 --- a/clients/moira/lists.c +++ b/clients/moira/lists.c @@ -5,17 +5,17 @@ /* This is the file lists.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: All list manipulation functions, except delete. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -55,15 +55,12 @@ static char current_list[BUFSIZ]; * Returns: none. */ -static void -PrintListAce(info) -char ** info; +static void PrintListAce(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf, "Item: %-20s Name: %s", info[ACE_TYPE], - info[ACE_NAME]); - Put_message(buf); + sprintf(buf, "Item: %-20s Name: %s", info[ACE_TYPE], info[ACE_NAME]); + Put_message(buf); } /* Function Name: PrintListInfo @@ -72,44 +69,44 @@ char ** info; * Returns: none. */ -static void -PrintListInfo(info) -char ** info; +static void PrintListInfo(char **info) { - char buf[BUFSIZ]; - - Put_message(" "); - (void) sprintf(buf, "%20sList: %s", "", info[L_NAME]); - (void) Put_message(buf); - (void) sprintf(buf, "Description: %s", info[L_DESC]); - (void) Put_message(buf); - if ( atoi(info[L_MAILLIST])) - Put_message("This list is a mailing list."); - else - Put_message("This list is NOT a mailing list."); - if ( atoi(info[L_GROUP]) ) { - (void) sprintf(buf,"This list is a Group and its ID number is %s", - info[L_GID]); - Put_message(buf); + char buf[BUFSIZ]; + + Put_message(" "); + sprintf(buf, "%20sList: %s", "", info[L_NAME]); + Put_message(buf); + sprintf(buf, "Description: %s", info[L_DESC]); + Put_message(buf); + if (atoi(info[L_MAILLIST])) + Put_message("This list is a mailing list."); + else + Put_message("This list is NOT a mailing list."); + if (atoi(info[L_GROUP])) + { + sprintf(buf, "This list is a Group and its ID number is %s", + info[L_GID]); + Put_message(buf); } - else - Put_message("This list is NOT a Group."); - - if (strcmp(info[L_ACE_TYPE],"NONE") == 0) - Put_message("This list has no Administrator, how strange?!"); - else { - sprintf(buf, "The Administrator of this list is the %s: %s", - info[L_ACE_TYPE], info[L_ACE_NAME]); - Put_message(buf); + else + Put_message("This list is NOT a Group."); + + if (!strcmp(info[L_ACE_TYPE], "NONE")) + Put_message("This list has no Administrator, how strange?!"); + else + { + sprintf(buf, "The Administrator of this list is the %s: %s", + info[L_ACE_TYPE], info[L_ACE_NAME]); + Put_message(buf); } - (void) sprintf(buf, "This list is: %s, %s, and %s", - atoi(info[L_ACTIVE]) ? "active" : "inactive", - atoi(info[L_PUBLIC]) ? "public" : "private", - atoi(info[L_HIDDEN]) ? "hidden" : "visible"); - (void) Put_message(buf); - sprintf(buf, MOD_FORMAT, info[L_MODBY], info[L_MODTIME], info[L_MODWITH]); - (void) Put_message(buf); + sprintf(buf, "This list is: %s, %s, and %s", + atoi(info[L_ACTIVE]) ? "active" : "inactive", + atoi(info[L_PUBLIC]) ? "public" : "private", + atoi(info[L_HIDDEN]) ? "hidden" : "visible"); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[L_MODBY], info[L_MODTIME], info[L_MODWITH]); + Put_message(buf); } /* Function Name: GetListInfo @@ -119,57 +116,58 @@ char ** info; * Returns: the first element in the queue. */ -/* ARGSUSED */ -struct qelem * -GetListInfo(type, name1, name2) -int type; -char * name1, *name2; +struct qelem *GetListInfo(int type, char *name1, char *name2) { - char *args[2]; - struct qelem * elem = NULL; - register int status; + char *args[2]; + struct qelem *elem = NULL; + register int status; - switch(type) { + switch (type) + { case LIST: - args[0] = name1; - if ( (status = do_mr_query("get_list_info", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, " in get_list_info"); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_list_info", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in get_list_info"); + return NULL; } - break; + break; case MEMBERS: - args[0] = name1; - if ( (status = do_mr_query("get_members_of_list", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, " in get_members_of_list"); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_members_of_list", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in get_members_of_list"); + return NULL; } - break; + break; case GLOM: - args[0] = name1; - args[1] = name2; - if ( (status = do_mr_query("get_lists_of_member", 2, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, " in get_list_of_members"); - return (NULL); + args[0] = name1; + args[1] = name2; + if ((status = do_mr_query("get_lists_of_member", 2, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in get_list_of_members"); + return NULL; } - break; + break; case ACE_USE: - args[0] = name1; - args[1] = name2; - if ( (status = do_mr_query("get_ace_use", 2, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, " in get_ace_use"); - return (NULL); + args[0] = name1; + args[1] = name2; + if ((status = do_mr_query("get_ace_use", 2, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in get_ace_use"); + return NULL; } - break; + break; } - return( QueueTop(elem) ); -} + return QueueTop(elem); +} /* Function Name: AskListInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. @@ -177,71 +175,73 @@ char * name1, *name2; * Returns: SUB_ERROR or SUB_NORMAL. */ -char ** -AskListInfo(info, name) -char ** info; -Bool name; +char **AskListInfo(char **info, Bool name) { - char temp_buf[BUFSIZ], *newname; - - Put_message(" "); - sprintf(temp_buf,"Setting information of list %s.",info[L_NAME]); - Put_message(temp_buf); - Put_message(" "); - - if (name) { - while (1) { - newname = Strsave(info[L_NAME]); - if (GetValueFromUser("The new name for this list", &newname) == - SUB_ERROR) - return(NULL); - if (ValidName(newname)) - break; + char temp_buf[BUFSIZ], *newname; + + Put_message(" "); + sprintf(temp_buf, "Setting information of list %s.", info[L_NAME]); + Put_message(temp_buf); + Put_message(" "); + + if (name) + { + while (1) + { + newname = Strsave(info[L_NAME]); + if (GetValueFromUser("The new name for this list", &newname) == + SUB_ERROR) + return NULL; + if (ValidName(newname)) + break; } } - if (GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]) == - SUB_ERROR) - return(NULL); - if (GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]) == - SUB_ERROR) - return(NULL); - if (GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]) == - SUB_ERROR) - return(NULL); - if (GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]) == - SUB_ERROR) - return(NULL); - if (GetYesNoValueFromUser("Is this a group", &info[L_GROUP]) == SUB_ERROR) - return(NULL); - if (atoi(info[L_GROUP])) + if (GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]) == + SUB_ERROR) + return NULL; + if (GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]) == + SUB_ERROR) + return NULL; + if (GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]) == + SUB_ERROR) + return NULL; + if (GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]) == + SUB_ERROR) + return NULL; + if (GetYesNoValueFromUser("Is this a group", &info[L_GROUP]) == SUB_ERROR) + return NULL; + if (atoi(info[L_GROUP])) + { if (GetValueFromUser("What is the GID for this group.", &info[L_GID]) == SUB_ERROR) - return(NULL); - - if (GetTypeFromUser("What Type of Administrator", "ace_type", - &info[L_ACE_TYPE]) == SUB_ERROR) - return(NULL); - if ((strcasecmp(info[L_ACE_TYPE], "NONE") != 0) && - (strcasecmp(info[L_ACE_TYPE], "none") != 0)) { - sprintf(temp_buf, "Which %s will be the administrator of this list: ", - info[L_ACE_TYPE]); - if (GetValueFromUser(temp_buf, &info[L_ACE_NAME]) == SUB_ERROR) - return(NULL); + return NULL; } - if (GetValueFromUser("Description: ", &info[L_DESC]) == SUB_ERROR) - return(NULL); - - FreeAndClear(&info[L_MODTIME], TRUE); - FreeAndClear(&info[L_MODBY], TRUE); - FreeAndClear(&info[L_MODWITH], TRUE); -/* - * Slide the newname into the #2 slot, this screws up all future references - * to this list. - */ - if (name) /* slide the newname into the #2 slot. */ - SlipInNewName(info, newname); - return(info); + if (GetTypeFromUser("What Type of Administrator", "ace_type", + &info[L_ACE_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[L_ACE_TYPE], "NONE") && + strcasecmp(info[L_ACE_TYPE], "none")) + { + sprintf(temp_buf, "Which %s will be the administrator of this list: ", + info[L_ACE_TYPE]); + if (GetValueFromUser(temp_buf, &info[L_ACE_NAME]) == SUB_ERROR) + return NULL; + } + if (GetValueFromUser("Description: ", &info[L_DESC]) == SUB_ERROR) + return NULL; + + FreeAndClear(&info[L_MODTIME], TRUE); + FreeAndClear(&info[L_MODBY], TRUE); + FreeAndClear(&info[L_MODWITH], TRUE); + /* + * Slide the newname into the #2 slot, this screws up all future references + * to this list. + */ + if (name) /* slide the newname into the #2 slot. */ + SlipInNewName(info, newname); + + return info; } /* -------------- List functions. -------------- */ @@ -252,22 +252,19 @@ Bool name; * Returns: DM status code. */ -/* ARGSUSED */ -int -ShowListInfo(argc, argv) -int argc; -char **argv; +int ShowListInfo(int argc, char **argv) { - struct qelem *top, *list; + struct qelem *top, *list; - top = list = GetListInfo(LIST, argv[1], (char *) NULL); - while (list != NULL) { - PrintListInfo( (char **) list->q_data); - list = list->q_forw; + top = list = GetListInfo(LIST, argv[1], NULL); + while (list) + { + PrintListInfo((char **) list->q_data); + list = list->q_forw; } - - FreeQueue(top); - return(DM_NORMAL); + + FreeQueue(top); + return DM_NORMAL; } /* Function Name: RealUpdateList @@ -276,50 +273,50 @@ char **argv; * junk - an UNUSED boolean. * Returns: none. */ - -/* ARGSUSED */ -static void -RealUpdateList(info, junk) -char ** info; -Bool junk; + +static void RealUpdateList(char **info, Bool junk) { - register int stat; - char ** args; - struct qelem *elem = NULL; - - if ((args = AskListInfo(info, TRUE)) == NULL) { - Put_message("Aborted."); - return; + register int stat; + char **args; + struct qelem *elem = NULL; + + if (!(args = AskListInfo(info, TRUE))) + { + Put_message("Aborted."); + return; } - /* - * If the new list name is less than 8 characters, make sure it doesn't - * collide with a username. - */ - if ((strlen(args[2]) <= 8) && - do_mr_query("get_user_account_by_login", 1, args + 1, - StoreInfo, (char *) &elem) != MR_NO_MATCH) { - char buf[256]; - - sprintf(buf, "\nA user by the name `%s' already exists in the database.", - args[1]); - Put_message(buf); - Loop(QueueTop(elem), FreeInfo); - FreeQueue(elem); - if (YesNoQuestion("Do you still want to rename this list to that name", - FALSE) != TRUE) { - Put_message("List ** NOT ** Updated."); - return; - } + /* + * If the new list name is less than 8 characters, make sure it doesn't + * collide with a username. + */ + if ((strlen(args[2]) <= 8) && + do_mr_query("get_user_account_by_login", 1, args + 1, + StoreInfo, (char *) &elem) != MR_NO_MATCH) + { + char buf[256]; + + sprintf(buf, "\nA user by the name `%s' already exists in the database.", + args[1]); + Put_message(buf); + Loop(QueueTop(elem), FreeInfo); + FreeQueue(elem); + if (YesNoQuestion("Do you still want to rename this list to that name", + FALSE) != TRUE) + { + Put_message("List ** NOT ** Updated."); + return; + } } - - if ( (stat = do_mr_query("update_list", CountArgs(args), args, - Scream, (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, stat, " in UpdateList."); - Put_message("List ** NOT ** Updated."); + + if ((stat = do_mr_query("update_list", CountArgs(args), args, + Scream, (char *) NULL)) != MR_SUCCESS) + { + com_err(program_name, stat, " in UpdateList."); + Put_message("List ** NOT ** Updated."); } - else - Put_message("List successfully updated."); + else + Put_message("List successfully updated."); } /* Function Name: UpdateList @@ -328,19 +325,15 @@ Bool junk; * Returns: DM Status code. */ -/* ARGSUSED */ -int -UpdateList(argc, argv) -int argc; -char **argv; +int UpdateList(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetListInfo(LIST, argv[1], (char *) NULL); - QueryLoop(top, NullPrint, RealUpdateList, "Update the list"); + top = GetListInfo(LIST, argv[1], (char *) NULL); + QueryLoop(top, NullPrint, RealUpdateList, "Update the list"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: SetDefaults @@ -350,86 +343,81 @@ char **argv; * Returns: defaults - the default information. */ -static char ** -SetDefaults(info, name) -char ** info; -char * name; +static char **SetDefaults(char **info, char *name) { - info[L_NAME] = Strsave(name); - info[L_ACTIVE] = Strsave(DEFAULT_ACTIVE); - info[L_PUBLIC] = Strsave(DEFAULT_PUBLIC); - info[L_HIDDEN] = Strsave(DEFAULT_HIDDEN); - info[L_MAILLIST] = Strsave(DEFAULT_MAILLIST); - info[L_GROUP] = Strsave(DEFAULT_GROUP); - info[L_GID] = Strsave(DEFAULT_GID); - info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE); - info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME); - info[L_DESC] = Strsave(DEFAULT_DESCRIPTION); - info[L_MODTIME] = info[L_MODBY] = info[L_MODWITH] = info[L_END] = NULL; - return(info); + info[L_NAME] = Strsave(name); + info[L_ACTIVE] = Strsave(DEFAULT_ACTIVE); + info[L_PUBLIC] = Strsave(DEFAULT_PUBLIC); + info[L_HIDDEN] = Strsave(DEFAULT_HIDDEN); + info[L_MAILLIST] = Strsave(DEFAULT_MAILLIST); + info[L_GROUP] = Strsave(DEFAULT_GROUP); + info[L_GID] = Strsave(DEFAULT_GID); + info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE); + info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME); + info[L_DESC] = Strsave(DEFAULT_DESCRIPTION); + info[L_MODTIME] = info[L_MODBY] = info[L_MODWITH] = info[L_END] = NULL; + return info; } /* Function Name: AddList - * Description: + * Description: * Arguments: argc, argv - name of list in argv[1]. * Returns: SUB_ERROR if list not created. */ -/* ARGSUSED */ -int -AddList(argc, argv) -int argc; -char **argv; +int AddList(int argc, char **argv) { - static char *info[MAX_ARGS_SIZE], **add_args; - int status, ret_code = SUB_NORMAL; - struct qelem *elem = NULL; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - status = do_mr_query("get_list_info", 1, argv + 1, NullFunc, - (char *) NULL); - if (status != MR_NO_MATCH) { - if (status == MR_SUCCESS) - Put_message("This list already exists."); - else - com_err(program_name, status, " in AddList."); - return(SUB_ERROR); + static char *info[MAX_ARGS_SIZE], **add_args; + int status, ret_code = SUB_NORMAL; + struct qelem *elem = NULL; + + if (!ValidName(argv[1])) + return DM_NORMAL; + status = do_mr_query("get_list_info", 1, argv + 1, NullFunc, NULL); + if (status != MR_NO_MATCH) + { + if (status == MR_SUCCESS) + Put_message("This list already exists."); + else + com_err(program_name, status, " in AddList."); + return SUB_ERROR; } - /* - * If the listname is less than 8 characters, make sure it doesn't - * collide with a username. - */ - if ((strlen(argv[1]) <= 8) && - do_mr_query("get_user_account_by_login", 1, argv + 1, - StoreInfo, (char *) &elem) != MR_NO_MATCH) { - char buf[256]; - - sprintf(buf, "\nA user by the name `%s' already exists in the database.", - argv[1]); - Put_message(buf); - Loop(QueueTop(elem), FreeInfo); - FreeQueue(elem); - if (YesNoQuestion("Crate a list with the same name", - FALSE) != TRUE) - return(SUB_ERROR); + /* + * If the listname is less than 8 characters, make sure it doesn't + * collide with a username. + */ + if ((strlen(argv[1]) <= 8) && + do_mr_query("get_user_account_by_login", 1, argv + 1, + StoreInfo, (char *) &elem) != MR_NO_MATCH) + { + char buf[256]; + + sprintf(buf, "\nA user by the name `%s' already exists in the database.", + argv[1]); + Put_message(buf); + Loop(QueueTop(elem), FreeInfo); + FreeQueue(elem); + if (YesNoQuestion("Crate a list with the same name", FALSE) != TRUE) + return SUB_ERROR; } - - if ((add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE)) == NULL) { - Put_message("Aborted."); - return(SUB_ERROR); + + if (!(add_args = AskListInfo(SetDefaults(info, argv[1]), FALSE))) + { + Put_message("Aborted."); + return SUB_ERROR; } - if ( (status = do_mr_query("add_list", CountArgs(add_args), add_args, - Scream, (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, status, " in AddList."); - Put_message("List Not Created."); - ret_code = SUB_ERROR; + if ((status = do_mr_query("add_list", CountArgs(add_args), add_args, + Scream, (char *) NULL)) != MR_SUCCESS) + { + com_err(program_name, status, " in AddList."); + Put_message("List Not Created."); + ret_code = SUB_ERROR; } - FreeInfo(info); - return(ret_code); + FreeInfo(info); + return ret_code; } /* Function Name: Instructions @@ -438,25 +426,24 @@ char **argv; * Returns: DM Status Code. */ -int -ListHelp() +int ListHelp(void) { - static char * message[] = { - "Listmaint handles the creation, deletion, and updating of lists.", - "A list can be a mailing list, a group list, or both.", - "The concept behind lists is that a list has an owner", - "- administrator - and members.", - "The administrator of a list may be another list.", - "The members of a list can be users (login names), other lists,", - "or address strings.", - "You can use certain keys to do the following:", - " Refresh the screen - Type ctrl-L.", - " Escape from a function - Type ctrl-C.", - " Suspend the program (temporarily) - Type ctrl-Z.", - NULL, - }; - - return(PrintHelp(message)); + static char *message[] = { + "Listmaint handles the creation, deletion, and updating of lists.", + "A list can be a mailing list, a group list, or both.", + "The concept behind lists is that a list has an owner", + "- administrator - and members.", + "The administrator of a list may be another list.", + "The members of a list can be users (login names), other lists,", + "or address strings.", + "You can use certain keys to do the following:", + " Refresh the screen - Type ctrl-L.", + " Escape from a function - Type ctrl-C.", + " Suspend the program (temporarily) - Type ctrl-Z.", + NULL, + }; + + return PrintHelp(message); } /*-*-* LISTMAINT UPDATE MENU *-*-*/ @@ -468,66 +455,60 @@ ListHelp() * Returns: none. */ -/* ARGSUSED */ -int -ListmaintMemberMenuEntry(m, argc, argv) -Menu *m; -int argc; -char **argv; +int ListmaintMemberMenuEntry(Menu *m, int argc, char **argv) { - char temp_buf[BUFSIZ]; - char *list_name = argv[1]; - register int stat; - - if (!ValidName(list_name)) - return(DM_QUIT); - - if (*argv[0] == 'a') { /* add_list */ - if (AddList(argc, argv) == SUB_ERROR) - return(DM_QUIT); - (void) sprintf(temp_buf, "List '%s' created. Do you want to %s", - list_name, "change its membership (y/n)? "); - if (YesNoQuestion(temp_buf, TRUE) != TRUE ) - return(DM_QUIT); + char temp_buf[BUFSIZ]; + char *list_name = argv[1]; + register int stat; + + if (!ValidName(list_name)) + return DM_QUIT; + + if (*argv[0] == 'a') + { /* add_list */ + if (AddList(argc, argv) == SUB_ERROR) + return DM_QUIT; + sprintf(temp_buf, "List '%s' created. Do you want to %s", list_name, + "change its membership (y/n)? "); + if (YesNoQuestion(temp_buf, TRUE) != TRUE) + return DM_QUIT; } - else - /* All we want to know is if it exists. */ - switch( (stat = do_mr_query("count_members_of_list", 1, argv + 1, - NullFunc, (char *) NULL))) { - case MR_SUCCESS: - break; - case MR_LIST: - Put_message("This list does not exist."); - return(DM_QUIT); - case MR_PERM: - Put_message("You are not allowed to view this list."); - break; - default: - com_err(program_name, stat, " in get_list_info"); - return(DM_QUIT); - } - - (void) sprintf(temp_buf, - "Change/Display membership of '%s'", list_name); - m->m_title = Strsave(temp_buf); - strcpy(current_list, list_name); - return(DM_NORMAL); + else + /* All we want to know is if it exists. */ + switch ((stat = do_mr_query("count_members_of_list", 1, argv + 1, + NullFunc, NULL))) + { + case MR_SUCCESS: + break; + case MR_LIST: + Put_message("This list does not exist."); + return DM_QUIT; + case MR_PERM: + Put_message("You are not allowed to view this list."); + break; + default: + com_err(program_name, stat, " in get_list_info"); + return DM_QUIT; + } + + sprintf(temp_buf, "Change/Display membership of '%s'", list_name); + m->m_title = Strsave(temp_buf); + strcpy(current_list, list_name); + return DM_NORMAL; } /* Function Name: ListmaintMemberMenuExit * Description: This is the function called when the member menu is * exited, it frees the memory that is storing the name. * Arguments: m - the menu - * Returns: DM_NORMAL + * Returns: DM_NORMAL */ -int -ListmaintMemberMenuExit(m) -Menu *m; +int ListmaintMemberMenuExit(Menu *m) { - free(m->m_title); - strcpy(current_list, ""); - return(DM_NORMAL); + free(m->m_title); + strcpy(current_list, ""); + return DM_NORMAL; } /* Function Name: ListMembersByType @@ -537,44 +518,44 @@ Menu *m; * NOTE: if type is NULL, all lists members are listed. */ -int -ListMembersByType(type) -char * type; +int ListMembersByType(char *type) { - char temp_buf[BUFSIZ]; - register int status; - char * args[10]; - - args[0] = current_list; - args[1] = NULL; - - found_some = FALSE; - if ( (status = do_mr_query("get_members_of_list", CountArgs(args), args, - PrintByType, type)) != 0) { - com_err(program_name, status, " in ListMembersByType"); - return(DM_NORMAL); + char temp_buf[BUFSIZ]; + register int status; + char *args[10]; + + args[0] = current_list; + args[1] = NULL; + + found_some = FALSE; + if ((status = do_mr_query("get_members_of_list", CountArgs(args), args, + PrintByType, type))) + { + com_err(program_name, status, " in ListMembersByType"); + return DM_NORMAL; } - if (!found_some) { - if (type == NULL) - Put_message("List is empty (no members)."); - else { - sprintf(temp_buf,"No %s Members",type); - Put_message(temp_buf); + if (!found_some) + { + if (!type) + Put_message("List is empty (no members)."); + else + { + sprintf(temp_buf, "No %s Members", type); + Put_message(temp_buf); } } } /* Function Name: ListAllMembers * Description: lists all members of the current list. - * Arguments: + * Arguments: * Returns: DM_NORMAL */ -int -ListAllMembers() +int ListAllMembers(void) { - ListMembersByType(NULL); - return (DM_NORMAL); + ListMembersByType(NULL); + return DM_NORMAL; } /* Function Name: ListUserMembers @@ -583,10 +564,10 @@ ListAllMembers() * Returns: DM_NORMAL. */ -ListUserMembers() +int ListUserMembers(void) { - ListMembersByType("USER"); - return(DM_NORMAL); + ListMembersByType("USER"); + return DM_NORMAL; } /* Function Name: ListListMembers @@ -595,10 +576,10 @@ ListUserMembers() * Returns: DM_NORMAL. */ -ListListMembers() +int ListListMembers(void) { - ListMembersByType("LIST"); - return(DM_NORMAL); + ListMembersByType("LIST"); + return DM_NORMAL; } /* Function Name: ListStringMembers @@ -607,10 +588,10 @@ ListListMembers() * Returns: DM_NORMAL. */ -ListStringMembers() +int ListStringMembers(void) { - ListMembersByType("STRING"); - return(DM_NORMAL); + ListMembersByType("STRING"); + return DM_NORMAL; } /* Function Name: GetMemberInfo @@ -623,31 +604,30 @@ ListStringMembers() * Returns: SUB_ERROR or SUB_NORMAL. */ -int -GetMemberInfo(action, ret_argv) -char *action, **ret_argv; +int GetMemberInfo(char *action, char **ret_argv) { - char temp_buf[BUFSIZ]; - - ret_argv[LM_LIST] = Strsave(current_list); - - ret_argv[LM_TYPE] = Strsave("user"); - if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) == - SUB_ERROR) - return(SUB_ERROR); - - sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action); - ret_argv[LM_MEMBER] = Strsave(user); - if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR) - return(SUB_ERROR); - ret_argv[LM_END] = NULL; /* NULL terminate this list. */ - - if (strcasecmp(ret_argv[LM_TYPE], "string") && - !ValidName( ret_argv[LM_MEMBER] ) ) { - FreeInfo(ret_argv); - return(SUB_ERROR); + char temp_buf[BUFSIZ]; + + ret_argv[LM_LIST] = Strsave(current_list); + + ret_argv[LM_TYPE] = Strsave("user"); + if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) == + SUB_ERROR) + return SUB_ERROR; + + sprintf(temp_buf, "Name of %s to %s", ret_argv[LM_TYPE], action); + ret_argv[LM_MEMBER] = Strsave(user); + if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR) + return SUB_ERROR; + ret_argv[LM_END] = NULL; /* NULL terminate this list. */ + + if (strcasecmp(ret_argv[LM_TYPE], "string") && + !ValidName(ret_argv[LM_MEMBER])) + { + FreeInfo(ret_argv); + return SUB_ERROR; } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: AddMember @@ -656,53 +636,62 @@ char *action, **ret_argv; * Returns: DM_NORMAL. */ -int -AddMember() +int AddMember(void) { - char *args[10], temp_buf[BUFSIZ], *p; - register int status; - struct qelem *mailhubs, *elem, *GetTypeValues(); - - if ( GetMemberInfo("add", args) == SUB_ERROR ) - return(DM_NORMAL); - - if (!strcmp(args[LM_TYPE], "STRING")) { - if (p = strchr(args[LM_MEMBER], '@')) { - char *host = canonicalize_hostname(strsave(++p)); - mailhubs = GetTypeValues("mailhub"); - for (elem = mailhubs; elem; elem = elem->q_forw) { - if (!strcasecmp(host, elem->q_data)) { - free(host); - host = strsave(args[LM_MEMBER]); - *(--p) = 0; - sprintf(temp_buf, "String \"%s\" should be USER or LIST \"%s\" because it is a local name.", - host, args[LM_MEMBER]); - Put_message(temp_buf); - free(args[LM_TYPE]); - free(host); - return(DM_NORMAL); + char *args[10], temp_buf[BUFSIZ], *p; + register int status; + struct qelem *mailhubs, *elem, *GetTypeValues(); + + if (GetMemberInfo("add", args) == SUB_ERROR) + return DM_NORMAL; + + if (!strcmp(args[LM_TYPE], "STRING")) + { + if ((p = strchr(args[LM_MEMBER], '@'))) + { + char *host = canonicalize_hostname(strsave(++p)); + mailhubs = GetTypeValues("mailhub"); + for (elem = mailhubs; elem; elem = elem->q_forw) + { + if (!strcasecmp(host, elem->q_data)) + { + free(host); + host = strsave(args[LM_MEMBER]); + *(--p) = 0; + sprintf(temp_buf, "String \"%s\" should be USER or LIST " + "\"%s\" because it is a local name.", host, + args[LM_MEMBER]); + Put_message(temp_buf); + free(args[LM_TYPE]); + free(host); + return DM_NORMAL; } } - free(host); - } else if (!strchr(args[LM_MEMBER], '!')) { - Put_message("Member which is not a foreign mail address should not be type STRING."); - return(DM_NORMAL); + free(host); + } + else if (!strchr(args[LM_MEMBER], '!')) + { + Put_message("Member which is not a foreign mail address " + "should not be type STRING."); + return DM_NORMAL; } } - if ( (status = do_mr_query("add_member_to_list", CountArgs(args), args, - Scream, NULL)) != MR_SUCCESS) { - if (status == MR_EXISTS) { - sprintf(temp_buf, "The %s %s is already a member of LIST %s.", - args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]); - Put_message(temp_buf); + if ((status = do_mr_query("add_member_to_list", CountArgs(args), args, + Scream, NULL)) != MR_SUCCESS) + { + if (status == MR_EXISTS) + { + sprintf(temp_buf, "The %s %s is already a member of LIST %s.", + args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]); + Put_message(temp_buf); } - else - com_err(program_name, status, " in AddMember"); + else + com_err(program_name, status, " in AddMember"); } - FreeInfo(args); - return(DM_NORMAL); + FreeInfo(args); + return DM_NORMAL; } /* Function Name: DeleteMember @@ -711,27 +700,27 @@ AddMember() * Returns: DM_NORMAL */ -int -DeleteMember() +int DeleteMember(void) { - char *args[10]; - register int status; - - if( GetMemberInfo("delete", args) == SUB_ERROR ) - return(DM_NORMAL); - - if (Confirm("Are you sure you want to delete this member?") ) { - if (status = do_mr_query("delete_member_from_list", CountArgs(args), - args, Scream, NULL)) - com_err(program_name, status, " in DeleteMember"); - else - Put_message("Deletion Completed."); + char *args[10]; + register int status; + + if (GetMemberInfo("delete", args) == SUB_ERROR) + return DM_NORMAL; + + if (Confirm("Are you sure you want to delete this member?")) + { + if ((status = do_mr_query("delete_member_from_list", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, status, " in DeleteMember"); + else + Put_message("Deletion Completed."); } - else - Put_message("Deletion has been Aborted."); + else + Put_message("Deletion has been Aborted."); - FreeInfo(args); - return(DM_NORMAL); + FreeInfo(args); + return DM_NORMAL; } /* Function Name: InterRemoveItemFromLists @@ -743,54 +732,57 @@ DeleteMember() * enough information in it to delete the member from the list. */ -int -InterRemoveItemFromLists() +int InterRemoveItemFromLists(void) { - register int status; - char *type, *name, *args[10], buf[BUFSIZ]; - struct qelem *top, *elem; - - type = strsave("USER"); - if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) - return(DM_NORMAL); - - sprintf(buf, "Name of %s", type); - name = strsave(user); - if (GetValueFromUser(buf, &name) == SUB_ERROR) - return(DM_NORMAL); - - if (!ValidName(name)) - return(DM_NORMAL); - - top = elem = GetListInfo(GLOM, type, name); - - while(elem != NULL) { - char line[BUFSIZ]; - char ** info = (char **) elem->q_data; - sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type, - name, info[GLOM_NAME]); - switch (YesNoQuitQuestion(line, FALSE)) { + register int status; + char *type, *name, *args[10], buf[BUFSIZ]; + struct qelem *top, *elem; + + type = strsave("USER"); + if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) + return DM_NORMAL; + + sprintf(buf, "Name of %s", type); + name = strsave(user); + if (GetValueFromUser(buf, &name) == SUB_ERROR) + return DM_NORMAL; + + if (!ValidName(name)) + return DM_NORMAL; + + top = elem = GetListInfo(GLOM, type, name); + + while (elem) + { + char line[BUFSIZ]; + char **info = (char **) elem->q_data; + sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type, + name, info[GLOM_NAME]); + switch (YesNoQuitQuestion(line, FALSE)) + { case TRUE: - Put_message("deleting..."); - args[DM_LIST] = info[GLOM_NAME]; - args[DM_TYPE] = type; - args[DM_MEMBER] = name; - if ( (status = do_mr_query("delete_member_from_list", 3, args, - Scream, (char *) NULL)) != 0) - /* should probabally check to delete list. */ - com_err(program_name, status, " in delete_member"); - break; + Put_message("deleting..."); + args[DM_LIST] = info[GLOM_NAME]; + args[DM_TYPE] = type; + args[DM_MEMBER] = name; + if ((status = do_mr_query("delete_member_from_list", 3, args, + Scream, (char *) NULL))) + { + /* should probabally check to delete list. */ + com_err(program_name, status, " in delete_member"); + } + break; case FALSE: - break; + break; default: - Put_message("Aborting..."); - FreeQueue(top); - return(DM_NORMAL); + Put_message("Aborting..."); + FreeQueue(top); + return DM_NORMAL; } - elem = elem->q_forw; + elem = elem->q_forw; } - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /*-*-* LIST MENU *-*-*/ @@ -801,44 +793,45 @@ InterRemoveItemFromLists() * Returns: DM_NORMAL. */ -int -ListByMember() +int ListByMember(void) { - char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info; - Bool maillist, group; - struct qelem *top, *elem; - - type = strsave("USER"); - if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) - return(DM_NORMAL); - - sprintf(buf, "Name of %s", type); - name = strsave(user); - if (GetValueFromUser(buf, &name) == SUB_ERROR) - return(DM_NORMAL); - - /* What we really want is a recursive search */ - sprintf(temp_buf, "R%s", type); - free(type); type = Strsave(temp_buf); - - if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?", - TRUE)) == -1) - return(DM_NORMAL); - if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?", - TRUE)) == -1) - return(DM_NORMAL); - - elem = top = GetListInfo(GLOM, type, name); - - while (elem != NULL) { - info = (char**) elem->q_data; - if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) || - (group == TRUE && !strcmp(info[GLOM_GROUP], "1"))) - Put_message(info[GLOM_NAME]); - elem = elem->q_forw; + char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info; + Bool maillist, group; + struct qelem *top, *elem; + + type = strsave("USER"); + if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) + return DM_NORMAL; + + sprintf(buf, "Name of %s", type); + name = strsave(user); + if (GetValueFromUser(buf, &name) == SUB_ERROR) + return DM_NORMAL; + + /* What we really want is a recursive search */ + sprintf(temp_buf, "R%s", type); + free(type); + type = Strsave(temp_buf); + + if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?", + TRUE)) == -1) + return DM_NORMAL; + if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?", + TRUE)) == -1) + return DM_NORMAL; + + elem = top = GetListInfo(GLOM, type, name); + + while (elem) + { + info = (char **) elem->q_data; + if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) || + (group == TRUE && !strcmp(info[GLOM_GROUP], "1"))) + Put_message(info[GLOM_NAME]); + elem = elem->q_forw; } - FreeQueue(top); - return (DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: ListByAdministrator @@ -848,38 +841,38 @@ ListByMember() * Returns: DM_NORMAL. */ -int -ListByAdministrator() +int ListByAdministrator(void) { - char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name; - struct qelem *top; - - type = strsave("USER"); - if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) - return(DM_NORMAL); - - sprintf(buf, "Name of %s", type); - name = strsave(user); - if (GetValueFromUser(buf, &name) == SUB_ERROR) - return(DM_NORMAL); - - switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE)) { + char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name; + struct qelem *top; + + type = strsave("USER"); + if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) + return DM_NORMAL; + + sprintf(buf, "Name of %s", type); + name = strsave(user); + if (GetValueFromUser(buf, &name) == SUB_ERROR) + return DM_NORMAL; + + switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE)) + { case TRUE: - sprintf(temp_buf, "R%s", type); /* "USER" to "RUSER" etc. */ - free(type); - type = Strsave(temp_buf); - break; + sprintf(temp_buf, "R%s", type); /* "USER" to "RUSER" etc. */ + free(type); + type = Strsave(temp_buf); + break; case FALSE: - break; + break; default: - return(DM_NORMAL); + return DM_NORMAL; } - - top = GetListInfo(ACE_USE, type, name); - Loop(top, PrintListAce); - FreeQueue(top); - return (DM_NORMAL); + top = GetListInfo(ACE_USE, type, name); + Loop(top, PrintListAce); + + FreeQueue(top); + return DM_NORMAL; } /* Function Name: ListAllPublicMailLists @@ -888,22 +881,24 @@ ListByAdministrator() * Returns: DM_NORMAL. */ -ListAllPublicMailLists() +int ListAllPublicMailLists(void) { - register int status; - static char * args[] = { - "TRUE", /* active */ - "TRUE", /* public */ - "FALSE", /* hidden */ - "TRUE", /* maillist */ - "DONTCARE", /* group. */ - }; - - if (YesNoQuestion("This query will take a while. Do you wish to continue?", - TRUE) == TRUE ) - if (status = do_mr_query("qualified_get_lists", 5, args, - Print, (char *) NULL) != 0) - com_err(program_name, status, " in ListAllGroups"); - - return (DM_NORMAL); + register int status; + static char *args[] = { + "TRUE", /* active */ + "TRUE", /* public */ + "FALSE", /* hidden */ + "TRUE", /* maillist */ + "DONTCARE", /* group. */ + }; + + if (YesNoQuestion("This query will take a while. Do you wish to continue?", + TRUE) == TRUE) + { + if (status = do_mr_query("qualified_get_lists", 5, args, + Print, NULL) != MR_SUCCESS) + com_err(program_name, status, " in ListAllGroups"); + } + + return DM_NORMAL; } diff --git a/clients/moira/main.c b/clients/moira/main.c index 7295830e..afa7d07c 100644 --- a/clients/moira/main.c +++ b/clients/moira/main.c @@ -5,17 +5,17 @@ /* This is the file main.c for the Moira Client, which allows a nieve * user to quickly and easily maintain most parts of the Moira database. * It Contains: The main driver for the Moira Client. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -33,26 +33,20 @@ #include "f_defs.h" #include "globals.h" -char * whoami; /* used by menu.c ugh!!! */ -char * moira_server; +char *whoami; /* used by menu.c ugh!!! */ +char *moira_server; int interrupt = 0; extern Menu moira_top_menu, list_menu, user_menu, dcm_menu; -#ifndef DEBUG static void Signal_Handler(), CatchInterrupt(); -#endif static void ErrorExit(), Usage(); char *getlogin(); uid_t getuid(); struct passwd *getpwuid(); -#ifdef _AIX -Bool use_menu = FALSE; /* whether or not we are using a menu. */ -#else Bool use_menu = TRUE; /* whether or not we are using a menu. */ -#endif /* Function Name: main * Description: The main driver for the Moira Client. @@ -60,67 +54,73 @@ Bool use_menu = TRUE; /* whether or not we are using a menu. */ * Returns: doesn't return. */ -void -main(argc, argv) - int argc; - char ** argv; +void main(int argc, char **argv) { - int status; - Menu *menu; - char *motd, **arg; -#ifdef POSIX - struct sigaction act; -#endif - - if ((user = getlogin()) == NULL) - user = getpwuid((int) getuid())->pw_name; - user = (user && strlen(user)) ? Strsave(user) : ""; - - if ((program_name = strrchr(argv[0], '/')) == NULL) - program_name = argv[0]; - else - program_name++; - program_name = Strsave(program_name); - whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ - - verbose = TRUE; - arg = argv; - moira_server = NULL; - - while (++arg - argv < argc) { - if (**arg == '-') { - if (!strcmp(*arg, "-nomenu")) - use_menu = FALSE; - else if (!strcmp(*arg, "-menu")) - use_menu = TRUE; - else if (!strcmp(*arg, "-db")) - if (arg - argv < argc - 1) { + int status; + Menu *menu; + char *motd, **arg; + struct sigaction act; + + if (!(user = getlogin())) + user = getpwuid(getuid())->pw_name; + user = (user && strlen(user)) ? Strsave(user) : ""; + + if (!(program_name = strrchr(argv[0], '/'))) + program_name = argv[0]; + else + program_name++; + program_name = Strsave(program_name); + whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ + + verbose = TRUE; + arg = argv; + moira_server = NULL; + + while (++arg - argv < argc) + { + if (**arg == '-') + { + if (!strcmp(*arg, "-nomenu")) + use_menu = FALSE; + else if (!strcmp(*arg, "-menu")) + use_menu = TRUE; + else if (!strcmp(*arg, "-db")) + { + if (arg - argv < argc - 1) + { ++arg; moira_server = *arg; - } else - Usage(argv); - else - Usage(argv); + } else + Usage(argv); + } + else + Usage(argv); } } - if ( status = mr_connect(moira_server) ) - ErrorExit("\nConnection to Moira server failed", status); - - if ( status = mr_motd(&motd) ) - ErrorExit("\nUnable to check server status", status); - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(1); + if ((status = mr_connect(moira_server))) + ErrorExit("\nConnection to Moira server failed", status); + + if ((status = mr_motd(&motd))) + ErrorExit("\nUnable to check server status", status); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(1); } - if ( status = mr_auth(program_name) ) { - if (status == MR_USER_AUTH) { - char buf[BUFSIZ]; - com_err(program_name, status, "\nPress [RETURN] to continue"); - fgets(buf, BUFSIZ, stdin); - } else { + if ((status = mr_auth(program_name))) + { + if (status == MR_USER_AUTH) + { + char buf[BUFSIZ]; + com_err(program_name, status, "\nPress [RETURN] to continue"); + fgets(buf, BUFSIZ, stdin); + } + else + { if (status >= ERROR_TABLE_BASE_krb && status <= ERROR_TABLE_BASE_krb + 256) ErrorExit("\nAuthorization failed -- please run kinit", status); @@ -129,55 +129,46 @@ main(argc, argv) } } -/* - * These signals should not be set until just before we fire up the menu - * system. - */ - -#ifndef DEBUG -#ifdef POSIX - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) Signal_Handler; - (void) sigaction(SIGHUP, &act, NULL); - (void) sigaction(SIGQUIT, &act, NULL); - if (use_menu) - (void) sigaction(SIGINT, &act, NULL); - else { - act.sa_handler= (void (*)()) CatchInterrupt; - (void) sigaction(SIGINT, &act, NULL); + /* + * These signals should not be set until just before we fire up the menu + * system. + */ + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) Signal_Handler; + sigaction(SIGHUP, &act, NULL); + sigaction(SIGQUIT, &act, NULL); + if (use_menu) + sigaction(SIGINT, &act, NULL); + else + { + act.sa_handler = (void (*)()) CatchInterrupt; + sigaction(SIGINT, &act, NULL); } -#else - (void) signal(SIGHUP, Signal_Handler); - (void) signal(SIGQUIT, Signal_Handler); - if (use_menu) - (void) signal(SIGINT, Signal_Handler); - else - (void) signal(SIGINT, CatchInterrupt); -#endif /* POSIX */ -#endif /* DEBUG */ - - initialize_gdss_error_table(); - - if (!strcmp(program_name, "listmaint")) - menu = &list_menu; - else if (!strcmp(program_name, "usermaint")) - menu = &user_menu; - else if (!strcmp(program_name, "dcmmaint")) - menu = &dcm_menu; - else - menu = &moira_top_menu; - - if (use_menu) { /* Start menus that execute program */ - Start_paging(); - Start_menu(menu); - Stop_paging(); + + initialize_gdss_error_table(); + + if (!strcmp(program_name, "listmaint")) + menu = &list_menu; + else if (!strcmp(program_name, "usermaint")) + menu = &user_menu; + else if (!strcmp(program_name, "dcmmaint")) + menu = &dcm_menu; + else + menu = &moira_top_menu; + + if (use_menu) /* Start menus that execute program */ + { + Start_paging(); + Start_menu(menu); + Stop_paging(); } - else /* Start program without menus. */ - Start_no_menu(menu); + else /* Start program without menus. */ + Start_no_menu(menu); - mr_disconnect(); - exit(0); + mr_disconnect(); + exit(0); } /* Function Name: ErrorExit @@ -187,14 +178,11 @@ main(argc, argv) * Returns: doesn't return. */ -static void -ErrorExit(buf,status) -int status; -char * buf; +static void ErrorExit(char *buf, int status) { - com_err(program_name, status, buf); - mr_disconnect(); - exit(1); + com_err(program_name, status, buf); + mr_disconnect(); + exit(1); } /* Function Name: usage @@ -203,35 +191,31 @@ char * buf; * Returns: doesn't return. */ -static void -Usage() +static void Usage(void) { - fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", program_name); - exit(1); + fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", + program_name); + exit(1); } -#ifndef DEBUG /* Function Name: Signal_Handler * Description: This function cleans up from a signal interrupt. * Arguments: none. * Returns: doesn't */ -static void -Signal_Handler() +static void Signal_Handler(void) { - Put_message("Signal caught - exiting"); - if (use_menu) - Cleanup_menu(); - mr_disconnect(); - exit(1); + Put_message("Signal caught - exiting"); + if (use_menu) + Cleanup_menu(); + mr_disconnect(); + exit(1); } -static void -CatchInterrupt() +static void CatchInterrupt(void) { - Put_message("Interrupt! Press RETURN to continue"); - interrupt = 1; + Put_message("Interrupt! Press RETURN to continue"); + interrupt = 1; } -#endif diff --git a/clients/moira/menu.c b/clients/moira/menu.c index 015d7e17..100ae685 100644 --- a/clients/moira/menu.c +++ b/clients/moira/menu.c @@ -28,25 +28,16 @@ static char rcsid_menu_c[] = "$Header$"; #include #include #include -#ifdef POSIX #include #include #include -#else -#include -#include -#endif /* POSIX */ #include #include #include #include "menu.h" -#ifndef __STDC__ -#define const -#endif - -#define MAX(A,B) ((A) > (B) ? (A) : (B)) -#define MIN(A,B) ((A) < (B) ? (A) : (B)) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#define MIN(A, B) ((A) < (B) ? (A) : (B)) #define CTL(ch) ((ch) & 037) #define MIN_INPUT 2 /* Minimum number of lines for input window */ @@ -59,12 +50,12 @@ int more_flg = 1; /* Structure for holding current displayed menu */ struct menu_screen { - WINDOW *ms_screen; /* Window for this menu */ - WINDOW *ms_title; /* Title subwindow */ - WINDOW *ms_menu; /* Menu subwindow */ - WINDOW *ms_input; /* Input subwindow */ - int ms_input_y; /* Input subwindow reference coordinate */ -} *cur_ms; + WINDOW *ms_screen; /* Window for this menu */ + WINDOW *ms_title; /* Title subwindow */ + WINDOW *ms_menu; /* Menu subwindow */ + WINDOW *ms_input; /* Input subwindow */ + int ms_input_y; /* Input subwindow reference coordinate */ +} *cur_ms; #define NULLMS ((struct menu_screen *) 0) @@ -78,26 +69,25 @@ char **parsed_argv; /* comand line input */ * printf string (crock...) */ -void -menu_com_err_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5) - const char *who; - long code; - const char *fmt; - caddr_t arg1, arg2, arg3, arg4, arg5; +void menu_com_err_hook(const char *who, long code, const char *fmt, + caddr_t arg1, caddr_t arg2, caddr_t arg3, + caddr_t arg4, caddr_t arg5) { - char buf[BUFSIZ], *cp; - - (void) strcpy(buf, who); - for (cp = buf; *cp; cp++); - *cp++ = ':'; - *cp++ = ' '; - if (code) { - (void) strcpy(cp, error_message(code)); - while (*cp) - cp++; + char buf[BUFSIZ], *cp; + + strcpy(buf, who); + for (cp = buf; *cp; cp++) + ; + *cp++ = ':'; + *cp++ = ' '; + if (code) + { + strcpy(cp, error_message(code)); + while (*cp) + cp++; } - sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5); - Put_message(buf); + sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5); + Put_message(buf); } /* @@ -106,94 +96,90 @@ menu_com_err_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5) * if user functions which run their own menus don't cooperate.) * Start_menu should only be called once, at the start of the program. */ -Start_menu(m) - Menu *m; +int Start_menu(Menu *m) { - struct menu_screen *make_ms(); -#ifdef __STDC__ - register void (*old_hook)(const char *, long, const char *, va_list) = set_com_err_hook((void (*) (const char *, long, const char *, va_list))menu_com_err_hook); -#else - register void (*old_hook)() = set_com_err_hook(menu_com_err_hook); -#endif - - if (initscr() == (WINDOW *)ERR) { - fputs("Can't initialize curses!\n", stderr); - Start_no_menu(m); - } else { - (void) raw(); /* We parse & print everything ourselves */ - (void) noecho(); - cur_ms = make_ms(0); /* So we always have some current */ - /* menu_screen */ - /* Run the menu */ - (void) Do_menu(m, -1, (char **) NULL); + struct menu_screen *make_ms(); + register void (*old_hook)(const char *, long, const char *, va_list) = + set_com_err_hook((void (*) (const char *, long, const char *, va_list))menu_com_err_hook); + + if (initscr() == (WINDOW *)ERR) + { + fputs("Can't initialize curses!\n", stderr); + Start_no_menu(m); } - (void) set_com_err_hook(old_hook); - Cleanup_menu(); + else + { + raw(); /* We parse & print everything ourselves */ + noecho(); + cur_ms = make_ms(0); /* So we always have some current */ + /* menu_screen */ + /* Run the menu */ + Do_menu(m, -1, NULL); + } + set_com_err_hook(old_hook); + Cleanup_menu(); } -Cleanup_menu() +int Cleanup_menu(void) { - if (cur_ms) { - (void) wclear(cur_ms->ms_screen); - (void) wrefresh(cur_ms->ms_screen); + if (cur_ms) + { + wclear(cur_ms->ms_screen); + wrefresh(cur_ms->ms_screen); } - endwin(); + endwin(); } - + /* Like Start_menu, except it doesn't print menus and doesn't use curses */ -Start_no_menu(m) - Menu *m; +int Start_no_menu(Menu *m) { - cur_ms = NULLMS; - COLS = 80; - /* Run the menu */ - (void) Do_menu(m, -1, (char **) NULL); + cur_ms = NULLMS; + COLS = 80; + /* Run the menu */ + Do_menu(m, -1, NULL); } /* * Create a new menu screen template with the specified menu length * and return it. */ -struct menu_screen * -make_ms(length) - int length; +struct menu_screen *make_ms(int length) { - struct menu_screen *ms; + struct menu_screen *ms; - if (MAX_TITLE + length + MIN_INPUT > LINES) { - fputs("Menu too big!\n", stderr); - exit(2); + if (MAX_TITLE + length + MIN_INPUT > LINES) + { + fputs("Menu too big!\n", stderr); + exit(2); } - ms = (struct menu_screen *) malloc(sizeof(struct menu_screen)); + ms = malloc(sizeof(struct menu_screen)); - ms->ms_screen = newwin(0, 0, 0, 0); - ms->ms_title = subwin(ms->ms_screen, MAX_TITLE, 0, 0, 0); - ms->ms_menu = subwin(ms->ms_screen, - length, 0, MAX_TITLE, 0); - ms->ms_input = subwin(ms->ms_screen, 0, 0, - ms->ms_input_y = MAX_TITLE + length, - 0); + ms->ms_screen = newwin(0, 0, 0, 0); + ms->ms_title = subwin(ms->ms_screen, MAX_TITLE, 0, 0, 0); + ms->ms_menu = subwin(ms->ms_screen, length, 0, MAX_TITLE, 0); + ms->ms_input = subwin(ms->ms_screen, 0, 0, + ms->ms_input_y = MAX_TITLE + length, + 0); - scrollok(ms->ms_input, TRUE); - (void) wmove(ms->ms_input, 0, 0); - (void) wclear(ms->ms_screen); + scrollok(ms->ms_input, TRUE); + wmove(ms->ms_input, 0, 0); + wclear(ms->ms_screen); - return (ms); + return ms; } /* * This routine destroys a menu_screen. */ -destroy_ms(ms) - struct menu_screen *ms; +int destroy_ms(struct menu_screen *ms) { - delwin(ms->ms_title); - delwin(ms->ms_menu); - delwin(ms->ms_input); - delwin(ms->ms_screen); - free((char *) ms); + delwin(ms->ms_title); + delwin(ms->ms_menu); + delwin(ms->ms_input); + delwin(ms->ms_screen); + free(ms); } /* @@ -201,340 +187,367 @@ destroy_ms(ms) * Note: if margc < 0, no 'r' option will be displayed (i.e., on the * top level menu) */ -int -Do_menu(m, margc, margv) - Menu *m; - int margc; - char *margv[]; +int Do_menu(Menu *m, int margc, char *margv[]) { - struct menu_screen *my_ms = NULLMS, *old_cur_ms = NULLMS; - char argvals[MAX_ARGC][MAX_ARGLEN]; /* This is where args are stored */ - char buf[MAX_ARGC * MAX_ARGLEN]; - char *argv[MAX_ARGC]; - int line; - int i; - struct menu_line *command, *Find_command(); - int argc; - int quitflag, is_topmenu = (margc < 0); - int toggle_logging(); - - /* Entry function gets called with old menu_screen still current */ - if (m->m_entry != NULLFUNC) { - if (m->m_entry(m, margc, margv) == DM_QUIT) - return DM_NORMAL; - if (parsed_argc > 0) { - margc = parsed_argc + 1; - margv = --parsed_argv; - } else { - margc--; - margv++; + struct menu_screen *my_ms = NULLMS, *old_cur_ms = NULLMS; + char argvals[MAX_ARGC][MAX_ARGLEN]; /* This is where args are stored */ + char buf[MAX_ARGC * MAX_ARGLEN]; + char *argv[MAX_ARGC]; + int line; + int i; + struct menu_line *command, *Find_command(); + int argc; + int quitflag, is_topmenu = (margc < 0); + int toggle_logging(); + + /* Entry function gets called with old menu_screen still current */ + if (m->m_entry != NULLFUNC) + { + if (m->m_entry(m, margc, margv) == DM_QUIT) + return DM_NORMAL; + if (parsed_argc > 0) + { + margc = parsed_argc + 1; + margv = --parsed_argv; + } + else + { + margc--; + margv++; } } - parsed_argc = 0; - - /* The following get run only in curses mode */ - if (cur_ms != NULLMS) { - /* Get a menu_screen */ - old_cur_ms = cur_ms; - /* 2 is for the 2 obligatory lines; quit and toggle */ - cur_ms = my_ms = make_ms(m->m_length + 2 + (is_topmenu ? 0 : 1)); - - /* Now print the title and the menu */ - (void) wclear(my_ms->ms_screen); - (void) wrefresh(my_ms->ms_screen); - (void) wmove(my_ms->ms_title, 0, MAX(0, (COLS - - strlen(m->m_title)) >> 1)); - (void) wstandout(my_ms->ms_title); - (void) waddstr(my_ms->ms_title, m->m_title); - (void) wstandend(my_ms->ms_title); - - for (line = 0; line < m->m_length; line++) { - int len = strlen(m->m_lines[line].ml_command); - if (len > 12) len=12; - - (void) wmove(my_ms->ms_menu, line, 0); - - (void) wprintw(my_ms->ms_menu, "%2d. (%s)%*s %s.", line + 1, - m->m_lines[line].ml_command, - 12-len, "", - m->m_lines[line].ml_doc); + parsed_argc = 0; + + /* The following get run only in curses mode */ + if (cur_ms != NULLMS) + { + /* Get a menu_screen */ + old_cur_ms = cur_ms; + /* 2 is for the 2 obligatory lines; quit and toggle */ + cur_ms = my_ms = make_ms(m->m_length + 2 + (is_topmenu ? 0 : 1)); + + /* Now print the title and the menu */ + wclear(my_ms->ms_screen); + wrefresh(my_ms->ms_screen); + wmove(my_ms->ms_title, 0, MAX(0, (COLS - strlen(m->m_title)) >> 1)); + wstandout(my_ms->ms_title); + waddstr(my_ms->ms_title, m->m_title); + wstandend(my_ms->ms_title); + + for (line = 0; line < m->m_length; line++) + { + int len = strlen(m->m_lines[line].ml_command); + if (len > 12) + len = 12; + + wmove(my_ms->ms_menu, line, 0); + + wprintw(my_ms->ms_menu, "%2d. (%s)%*s %s.", line + 1, + m->m_lines[line].ml_command, 12 - len, "", + m->m_lines[line].ml_doc); } - (void) wmove(my_ms->ms_menu, line++, 0); - if (!is_topmenu) { - (void) waddstr(my_ms->ms_menu, - " r. (return) Return to previous menu."); - (void) wmove(my_ms->ms_menu, line++, 0); + wmove(my_ms->ms_menu, line++, 0); + if (!is_topmenu) + { + waddstr(my_ms->ms_menu, + " r. (return) Return to previous menu."); + wmove(my_ms->ms_menu, line++, 0); } - (void) waddstr(my_ms->ms_menu, - " t. (toggle) Toggle logging on and off."); - (void) wmove(my_ms->ms_menu, line, 0); - (void) waddstr(my_ms->ms_menu, " q. (quit) Quit."); - } else { - Put_message(m->m_title); - for (line = 0; line < m->m_length; line++) { - sprintf(buf, "%2d. (%s)%*s %s.", line + 1, - m->m_lines[line].ml_command, - 12 - strlen(m->m_lines[line].ml_command), "", - m->m_lines[line].ml_doc); - Put_message(buf); + waddstr(my_ms->ms_menu, " t. (toggle) Toggle logging on and off."); + wmove(my_ms->ms_menu, line, 0); + waddstr(my_ms->ms_menu, " q. (quit) Quit."); + } + else + { + Put_message(m->m_title); + for (line = 0; line < m->m_length; line++) + { + sprintf(buf, "%2d. (%s)%*s %s.", line + 1, + m->m_lines[line].ml_command, + 12 - strlen(m->m_lines[line].ml_command), "", + m->m_lines[line].ml_doc); + Put_message(buf); } - if (!is_topmenu) - Put_message(" r. (return) Return to previous menu."); - Put_message(" t. (toggle) Toggle logging on and off."); - Put_message(" q. (quit) Quit."); - Put_message(" ?. Print this information."); + if (!is_topmenu) + Put_message(" r. (return) Return to previous menu."); + Put_message(" t. (toggle) Toggle logging on and off."); + Put_message(" q. (quit) Quit."); + Put_message(" ?. Print this information."); } - for (;;) { - /* This will be set by a return val from func or submenu */ - quitflag = DM_NORMAL; - /* This is here because we may be coming from another menu */ - if (cur_ms != NULL) { - touchwin(my_ms->ms_screen); - wrefresh(my_ms->ms_screen); + for (;;) + { + /* This will be set by a return val from func or submenu */ + quitflag = DM_NORMAL; + /* This is here because we may be coming from another menu */ + if (cur_ms != NULL) + { + touchwin(my_ms->ms_screen); + wrefresh(my_ms->ms_screen); } - if (margc > 1) { - /* Initialize argv */ - for (argc = 0; argc < MAX_ARGC; argc++) - argv[argc] = argvals[argc]; - argc = margc - 1; - for (i = 1; i < margc; i++) - strcpy(argvals[i - 1], margv[i]); - margc = 0; - } else { - /* Get a command */ - if (!Prompt_input("Command: ", buf, sizeof(buf))) { - if (cur_ms == NULLMS && - feof(stdin)) - sprintf(buf, "quit"); - else - continue; - } - /* Parse it into the argument list */ - /* If there's nothing there, try again */ - /* Initialize argv */ - for (argc = 0; argc < MAX_ARGC; argc++) - argv[argc] = argvals[argc]; - - if ((argc = Parse_words(buf, argv, MAX_ARGLEN)) == 0) - continue; + if (margc > 1) + { + /* Initialize argv */ + for (argc = 0; argc < MAX_ARGC; argc++) + argv[argc] = argvals[argc]; + argc = margc - 1; + for (i = 1; i < margc; i++) + strcpy(argvals[i - 1], margv[i]); + margc = 0; } - if ((line = atoi(argv[0])) > 0 && line <= m->m_length) { - command = &m->m_lines[line - 1]; + else + { + /* Get a command */ + if (!Prompt_input("Command: ", buf, sizeof(buf))) + { + if (cur_ms == NULLMS && feof(stdin)) + sprintf(buf, "quit"); + else + continue; + } + /* Parse it into the argument list */ + /* If there's nothing there, try again */ + /* Initialize argv */ + for (argc = 0; argc < MAX_ARGC; argc++) + argv[argc] = argvals[argc]; + + if ((argc = Parse_words(buf, argv, MAX_ARGLEN)) == 0) + continue; } - else if ((!is_topmenu && - (!strcmp(argv[0], "r") || !strcmp(argv[0], "return"))) - || !strcmp(argv[0], "q") || !strcmp(argv[0], "quit")) { - - /* here if it's either return or quit */ - if (cur_ms != NULLMS) { - cur_ms = old_cur_ms; - destroy_ms(my_ms); + if ((line = atoi(argv[0])) > 0 && line <= m->m_length) + command = &m->m_lines[line - 1]; + else if ((!is_topmenu && + (!strcmp(argv[0], "r") || !strcmp(argv[0], "return"))) || + !strcmp(argv[0], "q") || !strcmp(argv[0], "quit")) + { + /* here if it's either return or quit */ + if (cur_ms != NULLMS) + { + cur_ms = old_cur_ms; + destroy_ms(my_ms); } - if (m->m_exit != NULLFUNC) - m->m_exit(m); - return (*argv[0] == 'r' ? DM_NORMAL : DM_QUIT); + if (m->m_exit != NULLFUNC) + m->m_exit(m); + return *argv[0] == 'r' ? DM_NORMAL : DM_QUIT; } - else if (argv[0][0] == '?') { - for (line = 0; line < m->m_length; line++) { - sprintf(buf, "%2d. (%s)%*s %s.", line + 1, - m->m_lines[line].ml_command, - 12 - strlen(m->m_lines[line].ml_command), "", - m->m_lines[line].ml_doc); - Put_message(buf); + else if (argv[0][0] == '?') + { + for (line = 0; line < m->m_length; line++) + { + sprintf(buf, "%2d. (%s)%*s %s.", line + 1, + m->m_lines[line].ml_command, + 12 - strlen(m->m_lines[line].ml_command), "", + m->m_lines[line].ml_doc); + Put_message(buf); } - if (!is_topmenu) - Put_message(" r. (return) Return to previous menu."); - Put_message(" t. (toggle) Toggle logging on and off."); - Put_message(" q. (quit) Quit."); - continue; + if (!is_topmenu) + Put_message(" r. (return) Return to previous menu."); + Put_message(" t. (toggle) Toggle logging on and off."); + Put_message(" q. (quit) Quit."); + continue; } - else if (!strcmp(argv[0], "t") || !strcmp(argv[0], "toggle")) { - toggle_logging(argc, argv); - continue; - } - /* finally, try to find it using Find_command */ - else if ((command = Find_command(m, argvals[0])) == - (struct menu_line *) 0) { - sprintf(buf, "Command not recognized: %s\n", argvals[0]); - Put_message(buf); - continue; + else if (!strcmp(argv[0], "t") || !strcmp(argv[0], "toggle")) + { + toggle_logging(argc, argv); + continue; } - /* If we got to here, command is a valid menu_line */ - /* Send the offical command name into the argv */ - (void) strcpy(argvals[0], command->ml_command); - /* Show that we're working on it */ - Put_message(command->ml_doc); - /* Print args that we've already got */ - for (i = 1; i < argc; i++) { - if (command->ml_args[i].ma_prompt == NULL) - break; - (void) sprintf(buf, "%s%s", command->ml_args[i].ma_prompt, - argv[i]); - Put_message(buf); + /* finally, try to find it using Find_command */ + else if (!(command = Find_command(m, argvals[0]))) + { + sprintf(buf, "Command not recognized: %s\n", argvals[0]); + Put_message(buf); + continue; } - /* Get remaining arguments, if any */ - for (; argc < command->ml_argc; argc++) { - if (!Prompt_input(command->ml_args[argc].ma_prompt, - argvals[argc], sizeof(argvals[argc]))) - goto punt_command; + /* If we got to here, command is a valid menu_line */ + /* Send the offical command name into the argv */ + strcpy(argvals[0], command->ml_command); + /* Show that we're working on it */ + Put_message(command->ml_doc); + /* Print args that we've already got */ + for (i = 1; i < argc; i++) + { + if (!command->ml_args[i].ma_prompt) + break; + sprintf(buf, "%s%s", command->ml_args[i].ma_prompt, argv[i]); + Put_message(buf); } - parsed_argc = argc - command->ml_argc; - parsed_argv = &(argv[command->ml_argc]); - if (command->ml_function != NULLFUNC) { - /* If it's got a function, call it */ - quitflag = command->ml_function(argc, argv); + /* Get remaining arguments, if any */ + for (; argc < command->ml_argc; argc++) + { + if (!Prompt_input(command->ml_args[argc].ma_prompt, + argvals[argc], sizeof(argvals[argc]))) + goto punt_command; } - else if (command->ml_submenu != NULLMENU) { - /* Else see if it is a submenu */ - quitflag = Do_menu(command->ml_submenu, argc, argv); + parsed_argc = argc - command->ml_argc; + parsed_argv = &(argv[command->ml_argc]); + if (command->ml_function != NULLFUNC) + { + /* If it's got a function, call it */ + quitflag = command->ml_function(argc, argv); } - else { - /* If it's got neither, something is wrong */ - Put_message("*INTERNAL ERROR: NO FUNCTION OR MENU FOR LINE*"); + else if (command->ml_submenu != NULLMENU) + { + /* Else see if it is a submenu */ + quitflag = Do_menu(command->ml_submenu, argc, argv); } - if (quitflag == DM_QUIT) { - if (cur_ms != NULLMS) { - cur_ms = old_cur_ms; - destroy_ms(my_ms); + else + { + /* If it's got neither, something is wrong */ + Put_message("*INTERNAL ERROR: NO FUNCTION OR MENU FOR LINE*"); + } + if (quitflag == DM_QUIT) + { + if (cur_ms != NULLMS) + { + cur_ms = old_cur_ms; + destroy_ms(my_ms); } - if (m->m_exit != NULLFUNC) - m->m_exit(m); - parsed_argc = 0; - return (DM_QUIT); + if (m->m_exit != NULLFUNC) + m->m_exit(m); + parsed_argc = 0; + return DM_QUIT; } punt_command: - parsed_argc = 0; + parsed_argc = 0; } } -refresh_screen() +int refresh_screen(void) { - if (cur_ms != NULLMS) { - touchwin(cur_ms->ms_screen); - refresh_ms(cur_ms); + if (cur_ms != NULLMS) + { + touchwin(cur_ms->ms_screen); + refresh_ms(cur_ms); } } /* Prompt the user for input in the input window of cur_ms */ -int Prompt_input(prompt, buf, buflen) - char *prompt; - char *buf; - int buflen; +int Prompt_input(char *prompt, char *buf, int buflen) { - int c; - char *p; - int y, x, oldx, oldy; - - if (cur_ms != NULLMS) { - more_flg = 1; - getyx(cur_ms->ms_input, y, x); - (void) wmove(cur_ms->ms_input, y, 0); - - refresh_screen(); - (void) waddstr(cur_ms->ms_input, prompt); - getyx(cur_ms->ms_input, y, x); - - oldx = x; - oldy = y; - p = buf; - while(1) { - (void) wmove(cur_ms->ms_input, y, x); - (void) touchwin(cur_ms->ms_screen); - (void) wclrtoeol(cur_ms->ms_input); - (void) wrefresh(cur_ms->ms_input); - c = getchar() & 0x7f; - switch (c) { + int c; + char *p; + int y, x, oldx, oldy; + + if (cur_ms != NULLMS) + { + more_flg = 1; + getyx(cur_ms->ms_input, y, x); + wmove(cur_ms->ms_input, y, 0); + + refresh_screen(); + waddstr(cur_ms->ms_input, prompt); + getyx(cur_ms->ms_input, y, x); + + oldx = x; + oldy = y; + p = buf; + while (1) + { + wmove(cur_ms->ms_input, y, x); + touchwin(cur_ms->ms_screen); + wclrtoeol(cur_ms->ms_input); + wrefresh(cur_ms->ms_input); + c = getchar() & 0x7f; + switch (c) + { case CTL('C'): - *p = '\0'; - return 0; + *p = '\0'; + return 0; case CTL('Z'): - (void) kill(getpid(), SIGTSTP); - touchwin(cur_ms->ms_screen); - break; + kill(getpid(), SIGTSTP); + touchwin(cur_ms->ms_screen); + break; case CTL('L'): - (void) wclear(cur_ms->ms_input); - (void) wmove(cur_ms->ms_input, 0, 0); - (void) waddstr(cur_ms->ms_input, prompt); - (void) touchwin(cur_ms->ms_input); - (void) wrefresh(cur_ms->ms_screen); - getyx(cur_ms->ms_input, y, x); - oldy = y; - oldx = x; - p = buf; - break; + wclear(cur_ms->ms_input); + wmove(cur_ms->ms_input, 0, 0); + waddstr(cur_ms->ms_input, prompt); + touchwin(cur_ms->ms_input); + wrefresh(cur_ms->ms_screen); + getyx(cur_ms->ms_input, y, x); + oldy = y; + oldx = x; + p = buf; + break; case '\n': case '\r': - goto end_input; - /* these should be obtained by doing ioctl() on tty */ + goto end_input; + /* these should be obtained by doing ioctl() on tty */ case '\b': case '\177': - if (p > buf) { - p--; - x--; - if (x < 0) { - (void) wmove(cur_ms->ms_input, y, 0); - (void) wclrtoeol(cur_ms->ms_input); - y--; + if (p > buf) + { + p--; + x--; + if (x < 0) + { + wmove(cur_ms->ms_input, y, 0); + wclrtoeol(cur_ms->ms_input); + y--; #ifdef __NetBSD__ - x = cur_ms->ms_input->maxx - 1; + x = cur_ms->ms_input->maxx - 1; #else - x = cur_ms->ms_input->_maxx - 1; + x = cur_ms->ms_input->_maxx - 1; #endif } } - break; + break; case CTL('U'): case CTL('G'): case CTL('['): - x = oldx; - y = oldy; - p = buf; - break; + x = oldx; + y = oldy; + p = buf; + break; default: - /* (buflen - 1) leaves room for the \0 */ - if (isprint(c) && (p - buf < buflen - 1)) { - (void) waddch(cur_ms->ms_input, c); - *p++ = c; - x++; + /* (buflen - 1) leaves room for the \0 */ + if (isprint(c) && (p - buf < buflen - 1)) + { + waddch(cur_ms->ms_input, c); + *p++ = c; + x++; #ifdef __NetBSD__ - if (x >= cur_ms->ms_input->maxx) { + if (x >= cur_ms->ms_input->maxx) #else - if (x >= cur_ms->ms_input->_maxx) { + if (x >= cur_ms->ms_input->_maxx) #endif - x = 0; - y++; + { + x = 0; + y++; } - } else - putchar(CTL('G')); - break; + } + else + putchar(CTL('G')); + break; } } end_input: - (void) waddch(cur_ms->ms_input, '\n'); - - (void) wclrtoeol(cur_ms->ms_input); - refresh_ms(cur_ms); - *p = '\0'; - Start_paging(); - goto gotit; - } else { - printf("%s", prompt); - if (fgets(buf, buflen, stdin) == NULL) - return 0; - if (interrupt) { - interrupt = 0; - return 0; + waddch(cur_ms->ms_input, '\n'); + + wclrtoeol(cur_ms->ms_input); + refresh_ms(cur_ms); + *p = '\0'; + Start_paging(); + goto gotit; + } + else + { + printf("%s", prompt); + if (!fgets(buf, buflen, stdin)) + return 0; + if (interrupt) + { + interrupt = 0; + return 0; } - Start_paging(); - goto gotit; + Start_paging(); + goto gotit; } gotit: - strcpy(buf, strtrim(buf)); - return 1; + strcpy(buf, strtrim(buf)); + return 1; } int lines_left; @@ -542,220 +555,214 @@ int lines_left; /* Start paging */ /* This routine will cause the most recently put message to be the one at the top of the screen when a ---More--- prompt is displayed */ -Start_paging() +int Start_paging(void) { - if (cur_ms != NULLMS) { - lines_left = LINES - cur_ms->ms_input_y - 1; - } - else { - lines_left = 23; - } + if (cur_ms != NULLMS) + lines_left = LINES - cur_ms->ms_input_y - 1; + else + lines_left = 23; } /* Turn off paging */ -Stop_paging() +int Stop_paging(void) { - lines_left = -1; + lines_left = -1; } /* Print a message in the input window of cur_ms. */ -Put_message(msg) -char *msg; +int Put_message(char *msg) { - char *copy, *line, *s; - - copy = (char *) malloc((u_int)COLS); - s = line = msg; - if (log_file) { /* if we're doing logging; we assume that the */ - /* file has already been opened. */ - (void) fprintf(log_file, "%s\n", msg); - fflush(log_file); - } - - while(*s++) { - if (s - line >= COLS-1) { - (void) strncpy(copy, line, COLS-1); - copy[COLS-1] = '\0'; - line += COLS-1; - } else if (*s == '\n') { - *s = '\0'; - (void) strcpy(copy, line); - line = ++s; - } else - continue; - Put_line(copy); + char *copy, *line, *s; + + copy = malloc(COLS); + s = line = msg; + if (log_file) + { + /* if we're doing logging; we assume that the file has already + been opened. */ + fprintf(log_file, "%s\n", msg); + fflush(log_file); } - Put_line(line); - free(copy); + + while (*s++) + { + if (s - line >= COLS - 1) + { + strncpy(copy, line, COLS - 1); + copy[COLS - 1] = '\0'; + line += COLS - 1; + } + else if (*s == '\n') + { + *s = '\0'; + strcpy(copy, line); + line = ++s; + } + else + continue; + Put_line(copy); + } + Put_line(line); + free(copy); } /* Will be truncated to COLS characters. */ -Put_line(msg) -char *msg; +int Put_line(char *msg) { - int y, x, i; - char *msg1, chr; - - if (!more_flg) - return; - - if (lines_left >= 0) { - if (--lines_left == 0) { - /* Give the user a more prompt */ - if (cur_ms != NULLMS) { - (void) wstandout(cur_ms->ms_input); - (void) wprintw(cur_ms->ms_input, "---More---"); - (void) wstandend(cur_ms->ms_input); - refresh_ms(cur_ms); - chr = getchar() & 0x7f;/* We do care what it is */ - if (chr == 'q' || chr == 'Q' || chr == 3 /* ^C */) { - more_flg = 0; - return; + int y, x, i; + char *msg1, chr; + + if (!more_flg) + return; + + if (lines_left >= 0) + { + if (--lines_left == 0) + { + /* Give the user a more prompt */ + if (cur_ms != NULLMS) + { + wstandout(cur_ms->ms_input); + wprintw(cur_ms->ms_input, "---More---"); + wstandend(cur_ms->ms_input); + refresh_ms(cur_ms); + chr = getchar() & 0x7f;/* We do care what it is */ + if (chr == 'q' || chr == 'Q' || chr == 3 /* ^C */) + { + more_flg = 0; + return; } - getyx(cur_ms->ms_input, y, x); - /* x is a bitbucket; avoid lint problems */ - x=x; - (void) wmove(cur_ms->ms_input, y, 0); - (void) wclrtoeol(cur_ms->ms_input); + getyx(cur_ms->ms_input, y, x); + /* x is a bitbucket; avoid lint problems */ + x = x; + wmove(cur_ms->ms_input, y, 0); + wclrtoeol(cur_ms->ms_input); } - else { - printf("---More (hit return)---"); - getchar(); + else + { + printf("---More (hit return)---"); + getchar(); } - Start_paging(); /* Reset lines_left */ + Start_paging(); /* Reset lines_left */ } } - if (cur_ms != NULLMS) { - msg1 = (char *) calloc((u_int)COLS, 1); - (void) strncpy(msg1, msg, COLS-1); - for (i = strlen(msg1); i < COLS - 1; i++) - msg1[i] = ' '; - (void) wprintw(cur_ms->ms_input, "%s\n", msg1); - } - else { - puts(msg); + if (cur_ms != NULLMS) + { + msg1 = calloc(COLS, 1); + strncpy(msg1, msg, COLS - 1); + for (i = strlen(msg1); i < COLS - 1; i++) + msg1[i] = ' '; + wprintw(cur_ms->ms_input, "%s\n", msg1); } + else + puts(msg); } /* Refresh a menu_screen onto the real screen */ -refresh_ms(ms) - struct menu_screen *ms; +int refresh_ms(struct menu_screen *ms) { - (void) wrefresh(ms->ms_title); - (void) wrefresh(ms->ms_menu); - (void) wrefresh(ms->ms_input); + wrefresh(ms->ms_title); + wrefresh(ms->ms_menu); + wrefresh(ms->ms_input); } /* Parse buf into a list of words, which will be placed in strings specified by argv. Space for these strings must have already been allocated. Only the first n characters of each word will be copied */ -Parse_words(buf, argv, n) - char *buf; - char *argv[]; -int n; - +int Parse_words(char *buf, char *argv[], int n) { - char *start, *end; /* For sausage machine */ - int argc; - - start = buf; - for (argc = 0; argc < MAX_ARGC; argc++) { - while (isspace(*start)) - start++; /* Kill whitespace */ - if (*start == '\0') - break; /* Nothing left */ - /* Now find the end of the word */ - for (end = start; *end != '\0' && !isspace(*end); end++); - (void) strncpy(argv[argc], start, MIN(end - start, n)); /* Copy it */ - argv[argc][MIN(end - start, n - 1)] = '\0'; /* Terminate */ - start = end; + char *start, *end; /* For sausage machine */ + int argc; + + start = buf; + for (argc = 0; argc < MAX_ARGC; argc++) + { + while (isspace(*start)) + start++; /* Kill whitespace */ + if (*start == '\0') + break; /* Nothing left */ + /* Now find the end of the word */ + for (end = start; *end != '\0' && !isspace(*end); end++) + ; + strncpy(argv[argc], start, MIN(end - start, n)); /* Copy it */ + argv[argc][MIN(end - start, n - 1)] = '\0'; /* Terminate */ + start = end; } - return (argc); + return argc; } /* This is the internal form of Find_command, which recursively searches for a menu_line with command command in the specified menu */ /* It will search to a maximum depth of d */ -struct menu_line * -find_command_from(c, m, d) - char *c; - struct menu *m; - int d; +struct menu_line *find_command_from(char *c, struct menu *m, int d) { - int line; - struct menu_line *maybe; - - if (d < 0) - return ((struct menu_line *) 0); /* Too deep! */ - for (line = 0; line < m->m_length; line++) { - if (!strcmp(c, m->m_lines[line].ml_command)) { - return (&m->m_lines[line]); - } + int line; + struct menu_line *maybe; + + if (d < 0) + return NULL; /* Too deep! */ + for (line = 0; line < m->m_length; line++) + { + if (!strcmp(c, m->m_lines[line].ml_command)) + return &m->m_lines[line]; } - for (line = 0; line < m->m_length; line++) { - if (m->m_lines[line].ml_submenu != NULLMENU && - (maybe = find_command_from(c, m->m_lines[line].ml_submenu, d - 1)) - != (struct menu_line *) 0) { - return (maybe); - } + for (line = 0; line < m->m_length; line++) + { + if (m->m_lines[line].ml_submenu != NULLMENU && + (maybe = find_command_from(c, m->m_lines[line].ml_submenu, d - 1))) + return maybe; } - /* If we got to here, nothing works */ - return ((struct menu_line *) 0); + /* If we got to here, nothing works */ + return NULL; } /* Find_command searches down the current menu tree */ /* And returns a pointer to a menu_line with the specified command name */ /* It returns (struct menu_line *) 0 if none is found */ -struct menu_line * -Find_command(m, command) - Menu *m; - char *command; +struct menu_line *Find_command(Menu *m, char *command) { - if (m == NULLMENU) { - return ((struct menu_line *) 0); - } - else { - return (find_command_from(command, m, MAX_MENU_DEPTH)); - } + if (m == NULLMENU) + return NULL; + else + return find_command_from(command, m, MAX_MENU_DEPTH); } -/*ARGSUSED*/ -int -toggle_logging(argc, argv) - int argc; - char *argv[]; +int toggle_logging(int argc, char *argv[]) { - int pid; - char buf[BUFSIZ]; - - if (log_file == (FILE *) NULL) { - pid = getpid(); - if (!whoami) { - Put_message("I've lost my SENSE of DIRECTION! I have no IDEA who I AM!"); - Put_message("My God... You've turned him into a DEMOCRAT!!"); - Put_message(" -- Doonesbury"); - Put_message(""); - Put_message("translation: your log file can be found in \"/usr/tmp/a.out.pid\"."); - whoami = "a.out"; - (void) sprintf(buf, "/usr/tmp/%s-log.%d", whoami, pid); + int pid; + char buf[BUFSIZ]; + + if (!log_file) + { + pid = getpid(); + if (!whoami) + { + Put_message("I've lost my SENSE of DIRECTION! I have no IDEA who I AM!"); + Put_message("My God... You've turned him into a DEMOCRAT!!"); + Put_message(" -- Doonesbury"); + Put_message(""); + Put_message("translation: your log file can be found in \"/usr/tmp/a.out.pid\"."); + whoami = "a.out"; + sprintf(buf, "/usr/tmp/%s-log.%d", whoami, pid); } - else - (void) sprintf(buf, "/usr/tmp/%s-log.%d", whoami, pid); - - /* open the file */ - log_file = fopen(buf,"a"); - - if (log_file == (FILE *) NULL) - Put_message("Open of log file failed. Logging is not on."); - else - Put_message("Log file successfully opened."); - } - else { /* log_file is a valid pointer; turn off logging. */ - (void) fflush(log_file); - (void) fclose(log_file); - log_file = (FILE *) NULL; - Put_message("Logging off."); + else + sprintf(buf, "/usr/tmp/%s-log.%d", whoami, pid); + + /* open the file */ + log_file = fopen(buf, "a"); + + if (!log_file) + Put_message("Open of log file failed. Logging is not on."); + else + Put_message("Log file successfully opened."); } - return(DM_NORMAL); -} + else + { /* log_file is a valid pointer; turn off logging. */ + fflush(log_file); + fclose(log_file); + log_file = NULL; + Put_message("Logging off."); + } + return DM_NORMAL; +} diff --git a/clients/moira/menu.h b/clients/moira/menu.h index 9926a088..b6b513d0 100644 --- a/clients/moira/menu.h +++ b/clients/moira/menu.h @@ -10,27 +10,27 @@ #define MAX_MENU_DEPTH 8 typedef struct menu_arg { - char *ma_doc; /* Short doc for completion */ - char *ma_prompt; /* For prompting in menu */ -} Menu_Arg; + char *ma_doc; /* Short doc for completion */ + char *ma_prompt; /* For prompting in menu */ +} Menu_Arg; typedef struct menu_line { - int (*ml_function) (); - struct menu *ml_submenu; - int ml_argc; - struct menu_arg ml_args[MAX_ARGC]; -} Menu_Line; + int (*ml_function)(); + struct menu *ml_submenu; + int ml_argc; + struct menu_arg ml_args[MAX_ARGC]; +} Menu_Line; #define ml_doc ml_args[0].ma_prompt #define ml_command ml_args[0].ma_doc typedef struct menu { - int (*m_entry) (); - int (*m_exit) (); - char *m_title; - int m_length; - struct menu_line m_lines[MAX_LINES]; -} Menu; + int (*m_entry)(); + int (*m_exit)(); + char *m_title; + int m_length; + struct menu_line m_lines[MAX_LINES]; +} Menu; /* Return codes for Do_menu */ /* These should also be used by functions called from Do_menu */ @@ -39,7 +39,7 @@ typedef struct menu { /* Macros for initializing menu lines */ #define NULLFUNC ((int (*)()) 0) -#define NULLMENU ((struct menu *) 0) +#define NULLMENU NULL #define SUBMENU(cmd, doc, menu) { NULLFUNC, menu, 1, { { cmd, doc } } } #define SIMPLEFUNC(cmd, doc, func) { func, NULLMENU, 1, { { cmd, doc } } } diff --git a/clients/moira/menus.c b/clients/moira/menus.c index 3ac4b94b..336b8c49 100644 --- a/clients/moira/menus.c +++ b/clients/moira/menus.c @@ -5,17 +5,17 @@ /* This is the file menus.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: All menu definitions. - * + * * Created: 4/11/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -30,7 +30,7 @@ /* ------------------------- Second Tier Menus ------------------------- */ -/* +/* * Cluster Data Menu */ @@ -55,7 +55,7 @@ Menu cluster_data_menu = { {"delete", "Remove Data from a given Cluster"}, {"clus", "Cluster's Name: "}, {"label", "Label Identifing the data: "}, - } }, + } }, SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) } }; @@ -65,20 +65,20 @@ Menu cluster_data_menu = { */ Menu list_info_menu = { - NULLFUNC, - NULLFUNC, - "List Information Menu", - 3, - { - SIMPLEFUNC("member", - "Show all lists to which a given member belongs", - ListByMember), - SIMPLEFUNC("admin", - "Show all items which a given member can administer", - ListByAdministrator), - SIMPLEFUNC("public", "Show all public mailing lists", - ListAllPublicMailLists), - } + NULLFUNC, + NULLFUNC, + "List Information Menu", + 3, + { + SIMPLEFUNC("member", + "Show all lists to which a given member belongs", + ListByMember), + SIMPLEFUNC("admin", + "Show all items which a given member can administer", + ListByAdministrator), + SIMPLEFUNC("public", "Show all public mailing lists", + ListAllPublicMailLists), + } }; /* @@ -86,20 +86,20 @@ Menu list_info_menu = { */ Menu list_member_menu = { - ListmaintMemberMenuEntry, - ListmaintMemberMenuExit, - NULL, - 7, - { - SIMPLEFUNC("add", "Add a member to this list", AddMember), - SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember), - SIMPLEFUNC("all", "Show the members of this list", ListAllMembers), - SIMPLEFUNC("user", "Show the members of type USER", ListUserMembers), - SIMPLEFUNC("list", "Show the members of type LIST", ListListMembers), - SIMPLEFUNC("string", "Show the members of type STRING", - ListStringMembers), - SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) - } + ListmaintMemberMenuEntry, + ListmaintMemberMenuExit, + NULL, + 7, + { + SIMPLEFUNC("add", "Add a member to this list", AddMember), + SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember), + SIMPLEFUNC("all", "Show the members of this list", ListAllMembers), + SIMPLEFUNC("user", "Show the members of type USER", ListUserMembers), + SIMPLEFUNC("list", "Show the members of type LIST", ListListMembers), + SIMPLEFUNC("string", "Show the members of type STRING", + ListStringMembers), + SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) + } }; /* @@ -118,20 +118,20 @@ Menu mappings_menu = { {"cluster", "Cluster's Name: "}, } }, { AddMachineToCluster, NULLMENU, 3, { - {"addcluster","Add machine to a cluster"}, - {"name","Machine's Name: "}, + {"addcluster", "Add machine to a cluster"}, + {"name", "Machine's Name: "}, {"cluster", "Cluster's Name: "}, } }, { RemoveMachineFromCluster, NULLMENU, 3, { {"remcluster", "Remove machines from clusters"}, - {"name","Machine's Name: "}, + {"name", "Machine's Name: "}, {"cluster", "Cluster's Name: "}, } }, SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode), } }; -/* +/* * Post Office Box Menu */ @@ -156,11 +156,11 @@ Menu pobox_menu = { SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) } }; - + /* * Quota Menu */ - + Menu quota_menu = { NULLFUNC, NULLFUNC, @@ -183,118 +183,118 @@ Menu quota_menu = { SIMPLEFUNC("delquota", "Delete a quota on a filesystem", DeleteQuota), SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) - } + } }; Menu fsgroup_menu = { - NULLFUNC, - NULLFUNC, - "Filesystem Group Menu", - 6, - { - { GetFS, NULLMENU, 2, { - {"get", "Get individual or group filesystem information"}, - {"name", "Name of Filesystem: "} - } }, - { AddFSToGroup, NULLMENU, 3, { - {"add", "Add a new filesystem to an FS group"}, - {"group", "FS Group name: "}, - {"filsys", "Filesystem name: "} - } }, - { RemoveFSFromGroup, NULLMENU, 3, { - {"remove", "Remove a filesystem from an FS group"}, - {"group", "FS Group name: "}, - {"filsys", "Filesystem name: "} - } }, - { ChangeFSGroupOrder, NULLMENU, 2, { - {"order", "Change the order of filesystems in a group"}, - {"group", "FS Group name: "} - } }, - SIMPLEFUNC("help", "Info on Filesystem Groups", FSGroupHelp), - SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) - } + NULLFUNC, + NULLFUNC, + "Filesystem Group Menu", + 6, + { + { GetFS, NULLMENU, 2, { + {"get", "Get individual or group filesystem information"}, + {"name", "Name of Filesystem: "} + } }, + { AddFSToGroup, NULLMENU, 3, { + {"add", "Add a new filesystem to an FS group"}, + {"group", "FS Group name: "}, + {"filsys", "Filesystem name: "} + } }, + { RemoveFSFromGroup, NULLMENU, 3, { + {"remove", "Remove a filesystem from an FS group"}, + {"group", "FS Group name: "}, + {"filsys", "Filesystem name: "} + } }, + { ChangeFSGroupOrder, NULLMENU, 2, { + {"order", "Change the order of filesystems in a group"}, + {"group", "FS Group name: "} + } }, + SIMPLEFUNC("help", "Info on Filesystem Groups", FSGroupHelp), + SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) + } }; Menu service_menu = { - NULLFUNC, - NULLFUNC, - "DCM Service Menu", - 6, - { - { showserv, NULLMENU, 2, { - { "showserv", "Show service information" }, - { "service name", "Name of service: " }, - } }, - { addserv, NULLMENU, 2, { - { "addserv", "Add a new service" }, - { "service name", "Name of service: " }, - } }, - { updateserv, NULLMENU, 2, { - { "updateserv", "Update service information" }, - { "service name", "Name of service: " }, - } }, - { resetsrverr, NULLMENU, 2, { - { "resetsrverr", "Reset service error" }, - { "service name", "Name of service: " }, - } }, - { resetsrvc, NULLMENU, 2, { - { "resetsrvc", "Reset service state" }, - { "service name", "Name of service: " }, - } }, - { delserv, NULLMENU, 2, { - { "delserv", "Delete service info" }, - { "service name", "Name of service: " }, - } }, - } + NULLFUNC, + NULLFUNC, + "DCM Service Menu", + 6, + { + { showserv, NULLMENU, 2, { + { "showserv", "Show service information" }, + { "service name", "Name of service: " }, + } }, + { addserv, NULLMENU, 2, { + { "addserv", "Add a new service" }, + { "service name", "Name of service: " }, + } }, + { updateserv, NULLMENU, 2, { + { "updateserv", "Update service information" }, + { "service name", "Name of service: " }, + } }, + { resetsrverr, NULLMENU, 2, { + { "resetsrverr", "Reset service error" }, + { "service name", "Name of service: " }, + } }, + { resetsrvc, NULLMENU, 2, { + { "resetsrvc", "Reset service state" }, + { "service name", "Name of service: " }, + } }, + { delserv, NULLMENU, 2, { + { "delserv", "Delete service info" }, + { "service name", "Name of service: " }, + } }, + } }; Menu host_menu = { - NULLFUNC, - NULLFUNC, - "DCM Host Menu", - 7, - { - { showhost, NULLMENU, 3, { - { "showhost", "Show service/host tuple information" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { addhost, NULLMENU, 3, { - { "addhost", "Add a new service/host tuple" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { updatehost, NULLMENU, 3, { - { "updatehost", "Update a service/host tuple" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { resethosterr, NULLMENU, 3, { - { "resethosterr", "Reset service/host error" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { resethost, NULLMENU, 3, { - { "resethost", "Reset service/host state" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { sethostor, NULLMENU, 3, { - { "override", "Set service/host override" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - { delhost, NULLMENU, 3, { - { "delhost", "Delete service/host tuple" }, - { "service name", "Name of service: " }, - { "host name", "Name of machine: " }, - } }, - } + NULLFUNC, + NULLFUNC, + "DCM Host Menu", + 7, + { + { showhost, NULLMENU, 3, { + { "showhost", "Show service/host tuple information" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { addhost, NULLMENU, 3, { + { "addhost", "Add a new service/host tuple" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { updatehost, NULLMENU, 3, { + { "updatehost", "Update a service/host tuple" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { resethosterr, NULLMENU, 3, { + { "resethosterr", "Reset service/host error" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { resethost, NULLMENU, 3, { + { "resethost", "Reset service/host state" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { sethostor, NULLMENU, 3, { + { "override", "Set service/host override" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + { delhost, NULLMENU, 3, { + { "delhost", "Delete service/host tuple" }, + { "service name", "Name of service: " }, + { "host name", "Name of machine: " }, + } }, + } }; /* ------------------------- First Tier Menus ------------------------- */ -/* +/* * Cluster Menu */ @@ -310,29 +310,29 @@ Menu cluster_menu = { } }, { AddCluster, NULLMENU, 2, { {"add", "Add a new cluster"}, - {"name","Cluster's Name: "}, + {"name", "Cluster's Name: "}, } }, { UpdateCluster, NULLMENU, 2, { {"update", "Update cluster information"}, - {"name","Cluster's Name: "}, + {"name", "Cluster's Name: "}, } }, { DeleteCluster, NULLMENU, 2, { {"delete", "Delete this cluster"}, {"name", "Cluster's Name: "} } }, - SUBMENU("mappings","Machine To Cluster Mappings Menu", &mappings_menu), - SUBMENU("c_data","Cluster Data Menu", &cluster_data_menu), + SUBMENU("mappings", "Machine To Cluster Mappings Menu", &mappings_menu), + SUBMENU("c_data", "Cluster Data Menu", &cluster_data_menu), SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) } }; -/* +/* * Filesystem Menu */ Menu filesys_menu = { - NULLFUNC, - NULLFUNC, + NULLFUNC, + NULLFUNC, "Filesystem Menu", 10, { @@ -369,7 +369,7 @@ Menu filesys_menu = { {"unalias", "Disassociate from a Filesystem"}, {"name", "alias name : "}, } }, - SUBMENU("quotas","Quota Menu", "a_menu), + SUBMENU("quotas", "Quota Menu", "a_menu), /* SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode), */ /* SIMPLEFUNC("help", "Help ..", AttachHelp) */ } @@ -382,20 +382,20 @@ Menu subnet_menu = { 5, { { ShowSubnetInfo, NULLMENU, 2, { - {"show","Get network information"}, - {"name","Network's Name: "} + {"show", "Get network information"}, + {"name", "Network's Name: "} } }, { AddSubnet, NULLMENU, 2, { - {"add","Add a new network"}, - {"name","Network's Name: "}, + {"add", "Add a new network"}, + {"name", "Network's Name: "}, } }, { UpdateSubnet, NULLMENU, 2, { - {"update","Update network information"}, - {"name","Network's Name: "}, + {"update", "Update network information"}, + {"name", "Network's Name: "}, } }, { DeleteSubnet, NULLMENU, 2, { - {"delete","Delete this network"}, - {"name","Network's Name: "} + {"delete", "Delete this network"}, + {"name", "Network's Name: "} } }, SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) } @@ -408,19 +408,19 @@ Menu cname_menu = { 4, { { ShowCname, NULLMENU, 3, { - {"show","Get host alias information"}, - {"alias","Alias Name (Cname): "}, - {"host","Canonical Host Name: "} + {"show", "Get host alias information"}, + {"alias", "Alias Name (Cname): "}, + {"host", "Canonical Host Name: "} } }, { AddCname, NULLMENU, 3, { - {"add","Add a new host alias"}, - {"alias","Alias Name (Cname): "}, - {"host","Canonical Host Name: "} + {"add", "Add a new host alias"}, + {"alias", "Alias Name (Cname): "}, + {"host", "Canonical Host Name: "} } }, { DeleteCname, NULLMENU, 3, { - {"delete","Delete this alias"}, - {"alias","Alias Name (Cname): "}, - {"host","Canonical Host Name: "} + {"delete", "Delete this alias"}, + {"alias", "Alias Name (Cname): "}, + {"host", "Canonical Host Name: "} } }, SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) } @@ -437,30 +437,30 @@ Menu machine_menu = { 7, { { ShowMachineInfo, NULLMENU, 2, { - {"show","Get machine information"}, - {"name","Machine's Name: "} + {"show", "Get machine information"}, + {"name", "Machine's Name: "} } }, { ShowMachineQuery, NULLMENU, 5, { - {"query", "Lookup machines"}, - {"name", "Machine Name (or leave empty to match any): "}, - {"address", "Address in dotted notation (or leave empty to match any): "}, - {"location", "Location (or leave empty to match any): "}, - {"network", "Network (or leave empty to match any): "} + {"query", "Lookup machines"}, + {"name", "Machine Name (or leave empty to match any): "}, + {"address", "Address in dotted notation (or leave empty to match any): "}, + {"location", "Location (or leave empty to match any): "}, + {"network", "Network (or leave empty to match any): "} } }, { AddMachine, NULLMENU, 2, { - {"add","Add a new machine"}, - {"network","Network assignment: "}, + {"add", "Add a new machine"}, + {"network", "Network assignment: "}, } }, { UpdateMachine, NULLMENU, 2, { - {"update","Update machine information"}, - {"name","Machine's Name: "}, + {"update", "Update machine information"}, + {"name", "Machine's Name: "}, } }, { DeleteMachine, NULLMENU, 2, { - {"delete","Delete this machine"}, - {"name","Machine's Name: "} + {"delete", "Delete this machine"}, + {"name", "Machine's Name: "} } }, - SUBMENU("cnames","Alias names for machines", &cname_menu), - SUBMENU("mappings","Machine To Cluster Mappings Menu", &mappings_menu), + SUBMENU("cnames", "Alias names for machines", &cname_menu), + SUBMENU("mappings", "Machine To Cluster Mappings Menu", &mappings_menu), } }; @@ -469,40 +469,40 @@ Menu machine_menu = { */ Menu list_menu = { - NULLFUNC, - NULLFUNC, - "List Menu", - 9, - { - { ShowListInfo, NULLMENU, 2, { - {"show", "Display information about a list"}, - {"list name", "Name of list: "} - } }, - { NULLFUNC, &list_member_menu, 2, { - {"add", "Create new List"}, - {"list name", "Name of list: "} - } }, - { UpdateList, NULLMENU, 2, { - {"update", "Update characteristics of a list"}, - {"list name", "Name of list: "} - } }, - { DeleteList, NULLMENU, 2, { - {"delete", "Delete a List"}, - {"list name", "Name of list: "} - } }, - SIMPLEFUNC("query_remove", - "Interactively remove an item from all lists", - InterRemoveItemFromLists), - { NULLFUNC, &list_member_menu, 2, { - {"members", "Member Menu - Change/Show Members of a List."}, - {"list name", "Name of list: "} - } }, - SUBMENU("list_info", "List Info Menu", - &list_info_menu), - SUBMENU("quotas","Quota Menu", "a_menu), + NULLFUNC, + NULLFUNC, + "List Menu", + 9, + { + { ShowListInfo, NULLMENU, 2, { + {"show", "Display information about a list"}, + {"list name", "Name of list: "} + } }, + { NULLFUNC, &list_member_menu, 2, { + {"add", "Create new List"}, + {"list name", "Name of list: "} + } }, + { UpdateList, NULLMENU, 2, { + {"update", "Update characteristics of a list"}, + {"list name", "Name of list: "} + } }, + { DeleteList, NULLMENU, 2, { + {"delete", "Delete a List"}, + {"list name", "Name of list: "} + } }, + SIMPLEFUNC("query_remove", + "Interactively remove an item from all lists", + InterRemoveItemFromLists), + { NULLFUNC, &list_member_menu, 2, { + {"members", "Member Menu - Change/Show Members of a List."}, + {"list name", "Name of list: "} + } }, + SUBMENU("list_info", "List Info Menu", + &list_info_menu), + SUBMENU("quotas", "Quota Menu", "a_menu), /* SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode), */ - SIMPLEFUNC("help", "Print Help", ListHelp) - } + SIMPLEFUNC("help", "Print Help", ListHelp) + } }; /* @@ -531,51 +531,51 @@ Menu nfsphys_menu = { { "delete", "Delete NFS server"}, {"machine", "Machine Name: "}, } }, - SUBMENU("quotas","Quota Menu", "a_menu), + SUBMENU("quotas", "Quota Menu", "a_menu), SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode), /* SIMPLEFUNC("help", "Help", NFSHelp), */ } }; Menu krbmap_menu = { - NULLFUNC, - NULLFUNC, - "User Kerberos Mapping Menu", - 3, - { - { GetKrbmap, NULLMENU, 3, { - { "show", "Show Kerberos Mappings" }, - { "user", "User login name: " }, - { "principal", "Principal: " }, - } }, - { AddKrbmap, NULLMENU, 3, { - { "add", "Add Kerberos Mapping" }, - { "user", "User login name: " }, - { "principal", "Principal (this is case sensitive): " }, - } }, - { DeleteKrbmap, NULLMENU, 3, { - { "delete", "Delete Kerberos Mapping" }, - { "user", "User login name: " }, - { "principal", "Principal: " }, - } }, - } + NULLFUNC, + NULLFUNC, + "User Kerberos Mapping Menu", + 3, + { + { GetKrbmap, NULLMENU, 3, { + { "show", "Show Kerberos Mappings" }, + { "user", "User login name: " }, + { "principal", "Principal: " }, + } }, + { AddKrbmap, NULLMENU, 3, { + { "add", "Add Kerberos Mapping" }, + { "user", "User login name: " }, + { "principal", "Principal (this is case sensitive): " }, + } }, + { DeleteKrbmap, NULLMENU, 3, { + { "delete", "Delete Kerberos Mapping" }, + { "user", "User login name: " }, + { "principal", "Principal: " }, + } }, + } }; Menu mitdir_menu = { - NULLFUNC, - NULLFUNC, - "MIT On-line Directory Preferences Menu", - 2, - { - { GetDirFlags, NULLMENU, 2, { - { "show", "Show Directory Preferences" }, - { "login", "Login name: " }, - } }, - { SetDirFlags, NULLMENU, 2, { - { "change", "Change Directory Preference" }, - { "login", "Login name: " }, - } }, - } + NULLFUNC, + NULLFUNC, + "MIT On-line Directory Preferences Menu", + 2, + { + { GetDirFlags, NULLMENU, 2, { + { "show", "Show Directory Preferences" }, + { "login", "Login name: " }, + } }, + { SetDirFlags, NULLMENU, 2, { + { "change", "Change Directory Preference" }, + { "login", "Login name: " }, + } }, + } }; /* @@ -598,18 +598,18 @@ Menu user_menu = { {"last", "Last name: "} } }, {ShowUserByClass, NULLMENU, 2, { - {"class", "Show names of users in a given class"}, - {"login name", "Desired class: "} - } }, + {"class", "Show names of users in a given class"}, + {"login name", "Desired class: "} + } }, {ShowUserById, NULLMENU, 2, { - {"id", "Show user information by ID number"}, - {"ID number", "ID number: "} + {"id", "Show user information by ID number"}, + {"ID number", "ID number: "} } }, {UpdateUser, NULLMENU, 2, { {"modify", "Change all user fields"}, {"login", "Login name: "} } }, - SIMPLEFUNC("adduser", "Add a new user to the database", + SIMPLEFUNC("adduser", "Add a new user to the database", AddNewUser), SIMPLEFUNC("register", "Register a user", RegisterUser), {DeactivateUser, NULLMENU, 2, { @@ -627,29 +627,28 @@ Menu user_menu = { }; Menu dcm_menu = { - NULLFUNC, - NULLFUNC, - "DCM Menu", - 6, - { - SIMPLEFUNC("enable", "Enable/disable DCM", EnableDcm), - SUBMENU("service", "DCM Service Menu", &service_menu), - SUBMENU("host", "DCM Host Menu", &host_menu), - SIMPLEFUNC("active", "Display entries currently being updated", - InProgress), - SIMPLEFUNC("failed", "Display entries with errors to be reset", - DcmFailed), - SIMPLEFUNC("dcm", "Invoke a DCM update now", Dcm), + NULLFUNC, + NULLFUNC, + "DCM Menu", + 6, + { + SIMPLEFUNC("enable", "Enable/disable DCM", EnableDcm), + SUBMENU("service", "DCM Service Menu", &service_menu), + SUBMENU("host", "DCM Host Menu", &host_menu), + SIMPLEFUNC("active", "Display entries currently being updated", + InProgress), + SIMPLEFUNC("failed", "Display entries with errors to be reset", DcmFailed), + SIMPLEFUNC("dcm", "Invoke a DCM update now", Dcm), } }; -/* +/* * Printcap Printer Menu */ Menu printer_menu = { - NULLFUNC, - NULLFUNC, + NULLFUNC, + NULLFUNC, "Printer Menu", 4, { @@ -673,13 +672,13 @@ Menu printer_menu = { }; -/* +/* * Palladium Printer Menu */ Menu palladium_menu = { - NULLFUNC, - NULLFUNC, + NULLFUNC, + NULLFUNC, "Printer Menu", 7, { @@ -724,32 +723,32 @@ Menu palladium_menu = { */ Menu zephyr_menu = { - NULLFUNC, - NULLFUNC, - "Zephyr Menu", - 5, - { - { GetZephyr, NULLMENU, 2, { - {"get", "Get Zephyr Class Information"}, - {"name", "Name of class: "} - } }, - { AddZephyr, NULLMENU, 2, { - {"add", "Add New Zephyr class restrictions"}, - {"name", "Class name: "}, - } }, - { ChngZephyr, NULLMENU, 2, { - {"change", "Update Zephyr class restrictions"}, - {"name", "Class name: "}, - } }, - { DeleteZephyr, NULLMENU, 2, { - {"delete", "Delete Zephyr class restriction"}, - {"name", "Class Name: "} - } }, - { NULLFUNC, &list_member_menu, 2, { - {"members", "Member Menu - Change/Show Members of a List."}, - {"list name", "Name of list: "} - } }, - } + NULLFUNC, + NULLFUNC, + "Zephyr Menu", + 5, + { + { GetZephyr, NULLMENU, 2, { + {"get", "Get Zephyr Class Information"}, + {"name", "Name of class: "} + } }, + { AddZephyr, NULLMENU, 2, { + {"add", "Add New Zephyr class restrictions"}, + {"name", "Class name: "}, + } }, + { ChngZephyr, NULLMENU, 2, { + {"change", "Update Zephyr class restrictions"}, + {"name", "Class name: "}, + } }, + { DeleteZephyr, NULLMENU, 2, { + {"delete", "Delete Zephyr class restriction"}, + {"name", "Class Name: "} + } }, + { NULLFUNC, &list_member_menu, 2, { + {"members", "Member Menu - Change/Show Members of a List."}, + {"list name", "Name of list: "} + } }, + } }; @@ -758,29 +757,29 @@ Menu zephyr_menu = { */ Menu misc_menu = { - NULLFUNC, - NULLFUNC, - "Miscellaneous Menu", - 4, - { - SIMPLEFUNC("statistics", "Show database statistics", TableStats), - SIMPLEFUNC("clients", "Show active Moira clients", ShowClients), - { ShowValue, NULLMENU, 2, { - {"getval", "Show a database variable value"}, - {"name", "variable name: "}, - } }, - { ShowAlias, NULLMENU, 3, { - {"getalias", "Show an alias relation"}, - {"name", "Alias name: "}, - {"type", "Alias type: "}, - } }, - } + NULLFUNC, + NULLFUNC, + "Miscellaneous Menu", + 4, + { + SIMPLEFUNC("statistics", "Show database statistics", TableStats), + SIMPLEFUNC("clients", "Show active Moira clients", ShowClients), + { ShowValue, NULLMENU, 2, { + {"getval", "Show a database variable value"}, + {"name", "variable name: "}, + } }, + { ShowAlias, NULLMENU, 3, { + {"getalias", "Show an alias relation"}, + {"name", "Alias name: "}, + {"type", "Alias type: "}, + } }, + } }; /* ------------------------- Root Menu ------------------------- */ -/* +/* * Moira top menu */ @@ -790,17 +789,17 @@ Menu moira_top_menu = { "Moira Database Manipulation", 12, { - SUBMENU("cluster","Cluster Menu",&cluster_menu), - SUBMENU("filesys","Filesystem Menu", &filesys_menu), - SUBMENU("list","Lists and Group Menu", &list_menu), - SUBMENU("machine","Machine Menu", &machine_menu), + SUBMENU("cluster", "Cluster Menu", &cluster_menu), + SUBMENU("filesys", "Filesystem Menu", &filesys_menu), + SUBMENU("list", "Lists and Group Menu", &list_menu), + SUBMENU("machine", "Machine Menu", &machine_menu), SUBMENU("network", "Network Menu", &subnet_menu), - SUBMENU("nfs","NFS Physical Menu", &nfsphys_menu), + SUBMENU("nfs", "NFS Physical Menu", &nfsphys_menu), SUBMENU("palladium", "Palladium Printer Menu", &palladium_menu), SUBMENU("printcap", "Printcap Printer Menu", &printer_menu), - SUBMENU("user","User Menu", &user_menu), + SUBMENU("user", "User Menu", &user_menu), SUBMENU("zephyr", "Zephyr ACLS Menu", &zephyr_menu), SUBMENU("dcm", "DCM Menu", &dcm_menu), SUBMENU("misc", "Miscellaneous Menu", &misc_menu) } -}; +}; diff --git a/clients/moira/misc.c b/clients/moira/misc.c index 538c4e6c..b553bffb 100644 --- a/clients/moira/misc.c +++ b/clients/moira/misc.c @@ -1,6 +1,6 @@ /* This is the file misc.c for the MOIRA Client, which allows a naieve * user to quickly and easily maintain most parts of the MOIRA database. - * It Contains: + * It Contains: * TableStats * ShowClients * ShowValue @@ -11,10 +11,10 @@ * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -40,16 +40,15 @@ * Returns: DM_NORMAL */ -PrintStats(info) -char **info; +int PrintStats(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]); - Put_message(buf); - sprintf(buf, " %s appends, %s updates, %s deletes", - info[2], info[3], info[4]); - Put_message(buf); + sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]); + Put_message(buf); + sprintf(buf, " %s appends, %s updates, %s deletes", + info[2], info[3], info[4]); + Put_message(buf); } @@ -59,19 +58,20 @@ char **info; * Returns: DM_NORMAL */ -int TableStats() +int TableStats(void) { - int status; - struct qelem *elem = NULL; - - if (status = do_mr_query("get_all_table_stats", 0, NULL, - StoreInfo, (char *)&elem)) { - com_err(program_name, status, " in TableStats"); - return(DM_NORMAL); + int status; + struct qelem *elem = NULL; + + if ((status = do_mr_query("get_all_table_stats", 0, NULL, + StoreInfo, (char *)&elem))) + { + com_err(program_name, status, " in TableStats"); + return DM_NORMAL; } - Loop(QueueTop(elem), PrintStats); - FreeQueue(elem); - return(DM_NORMAL); + Loop(QueueTop(elem), PrintStats); + FreeQueue(elem); + return DM_NORMAL; } @@ -80,25 +80,26 @@ int TableStats() * Arguments: argv */ -PrintClients(info) -char **info; +int PrintClients(char **info) { - char buf[BUFSIZ]; - unsigned long host_address; - struct hostent *host_entry; - - host_address = inet_addr(info[1]); - if (host_address != 0) { - host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET); - if (host_entry != NULL) { - free(info[1]); - info[1] = Strsave(host_entry->h_name); + char buf[BUFSIZ]; + unsigned long host_address; + struct hostent *host_entry; + + host_address = inet_addr(info[1]); + if (host_address) + { + host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET); + if (host_entry) + { + free(info[1]); + info[1] = Strsave(host_entry->h_name); } } - sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]); - Put_message(buf); - sprintf(buf, " Connected at %s, client %s", info[3], info[4]); - Put_message(buf); + sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]); + Put_message(buf); + sprintf(buf, " Connected at %s, client %s", info[3], info[4]); + Put_message(buf); } @@ -108,19 +109,20 @@ char **info; * Returns: DM_NORMAL */ -int ShowClients() +int ShowClients(void) { - int status; - struct qelem *elem = NULL; - - if (status = do_mr_query("_list_users", 0, NULL, - StoreInfo, (char *) &elem)) { - com_err(program_name, status, " in ShowClients"); - return(DM_NORMAL); + int status; + struct qelem *elem = NULL; + + if ((status = do_mr_query("_list_users", 0, NULL, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in ShowClients"); + return DM_NORMAL; } - Loop(QueueTop(elem), PrintClients); - FreeQueue(elem); - return(DM_NORMAL); + Loop(QueueTop(elem), PrintClients); + FreeQueue(elem); + return DM_NORMAL; } @@ -129,13 +131,12 @@ int ShowClients() * Arguments: argv */ -PrintValue(info) -char **info; +int PrintValue(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf, "Value: %s", info[0]); - Put_message(buf); + sprintf(buf, "Value: %s", info[0]); + Put_message(buf); } @@ -145,21 +146,20 @@ char **info; * Returns: DM_NORMAL */ -int ShowValue(argc, argv) -int argc; -char **argv; +int ShowValue(int argc, char **argv) { - int status; - struct qelem *elem = NULL; - - if (status = do_mr_query("get_value", 1, &argv[1], - StoreInfo, (char *) &elem)) { - com_err(program_name, status, " in ShowValue"); - return(DM_NORMAL); + int status; + struct qelem *elem = NULL; + + if ((status = do_mr_query("get_value", 1, &argv[1], + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in ShowValue"); + return DM_NORMAL; } - Loop(elem, PrintValue); - FreeQueue(elem); - return(DM_NORMAL); + Loop(elem, PrintValue); + FreeQueue(elem); + return DM_NORMAL; } @@ -168,14 +168,13 @@ char **argv; * Arguments: argv */ -PrintAlias(info) -char **info; +int PrintAlias(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf, "Name: %-20s Type: %-12s Value: %s", - info[0], info[1], info[2]); - Put_message(buf); + sprintf(buf, "Name: %-20s Type: %-12s Value: %s", + info[0], info[1], info[2]); + Put_message(buf); } @@ -185,23 +184,22 @@ char **info; * Returns: DM_NORMAL */ -int ShowAlias(argc, argv) -int argc; -char **argv; +int ShowAlias(int argc, char **argv) { - int status; - char *info[4]; - struct qelem *elem = NULL; - - info[0] = argv[1]; - info[1] = argv[2]; - info[2] = "*"; - if (status = do_mr_query("get_alias", 3, info, - StoreInfo, (char *) &elem)) { - com_err(program_name, status, " in ShowAlias"); - return(DM_NORMAL); + int status; + char *info[4]; + struct qelem *elem = NULL; + + info[0] = argv[1]; + info[1] = argv[2]; + info[2] = "*"; + if ((status = do_mr_query("get_alias", 3, info, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " in ShowAlias"); + return DM_NORMAL; } - Loop(QueueTop(elem), PrintAlias); - FreeQueue(elem); - return(DM_NORMAL); + Loop(QueueTop(elem), PrintAlias); + FreeQueue(elem); + return DM_NORMAL; } diff --git a/clients/moira/namespace.c b/clients/moira/namespace.c index d07b9775..2764443d 100644 --- a/clients/moira/namespace.c +++ b/clients/moira/namespace.c @@ -5,17 +5,17 @@ /* This is the file main.c for the Moira Client, which allows a nieve * user to quickly and easily maintain most parts of the Moira database. * It Contains: The main driver for the Moira Client. - * + * * Created: 4/12/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -34,8 +34,8 @@ #include "f_defs.h" #include "globals.h" -char * whoami; /* used by menu.c ugh!!! */ -char * moira_server; +char *whoami; /* used by menu.c ugh!!! */ +char *moira_server; int interrupt = 0; int NewListHelp(); @@ -44,19 +44,18 @@ int NewListHelp(); */ Menu list_info_menu = { - NULLFUNC, - NULLFUNC, - "List Information Menu", - 3, - { - SIMPLEFUNC("member", "Show all lists to which a given member belongs", - ListByMember), - SIMPLEFUNC("admin", - "Show all items which a given member can administer", - ListByAdministrator), - SIMPLEFUNC("public", "Show all public mailing lists", - ListAllPublicMailLists), - } + NULLFUNC, + NULLFUNC, + "List Information Menu", + 3, + { + SIMPLEFUNC("member", "Show all lists to which a given member belongs", + ListByMember), + SIMPLEFUNC("admin", "Show all items which a given member can administer", + ListByAdministrator), + SIMPLEFUNC("public", "Show all public mailing lists", + ListAllPublicMailLists), + } }; /* @@ -64,16 +63,16 @@ Menu list_info_menu = { */ Menu list_member_menu = { - ListmaintMemberMenuEntry, - ListmaintMemberMenuExit, - NULL, - 4, - { - SIMPLEFUNC("add", "Add a member to this list", AddMember), - SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember), - SIMPLEFUNC("show", "Show the members of this list", ListAllMembers), - SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) - } + ListmaintMemberMenuEntry, + ListmaintMemberMenuExit, + NULL, + 4, + { + SIMPLEFUNC("add", "Add a member to this list", AddMember), + SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember), + SIMPLEFUNC("show", "Show the members of this list", ListAllMembers), + SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) + } }; /* @@ -81,33 +80,33 @@ Menu list_member_menu = { */ Menu list_menu = { - NULLFUNC, - NULLFUNC, - "List Menu", - 6, - { - { ShowListInfo, NULLMENU, 2, { - {"show", "Display information about a list"}, - {"list name", "Name of list: "} - } }, - { UpdateList, NULLMENU, 2, { - {"update", "Update characteristics of a list"}, - {"list name", "Name of list: "} - } }, - SIMPLEFUNC("query_remove", - "Interactively remove a member from all lists", - InterRemoveItemFromLists), - { NULLFUNC, &list_member_menu, 2, { - {"members", "Member Menu - Change/Show Members of a List."}, - {"list name", "Name of list: "} - } }, - SUBMENU("lists", "Find Mailing Lists Menu", - &list_info_menu), - SIMPLEFUNC("help", "Print Help", NewListHelp) - } + NULLFUNC, + NULLFUNC, + "List Menu", + 6, + { + { ShowListInfo, NULLMENU, 2, { + {"show", "Display information about a list"}, + {"list name", "Name of list: "} + } }, + { UpdateList, NULLMENU, 2, { + {"update", "Update characteristics of a list"}, + {"list name", "Name of list: "} + } }, + SIMPLEFUNC("query_remove", + "Interactively remove a member from all lists", + InterRemoveItemFromLists), + { NULLFUNC, &list_member_menu, 2, { + {"members", "Member Menu - Change/Show Members of a List."}, + {"list name", "Name of list: "} + } }, + SUBMENU("lists", "Find Mailing Lists Menu", + &list_info_menu), + SIMPLEFUNC("help", "Print Help", NewListHelp) + } }; -/* +/* * Post Office Box Menu */ @@ -131,20 +130,20 @@ Menu pobox_menu = { } }, } }; - + /* * Miscellaneous Menu */ Menu misc_menu = { - NULLFUNC, - NULLFUNC, - "Miscellaneous Menu", - 2, - { - SIMPLEFUNC("statistics", "Show database statistics", TableStats), - SIMPLEFUNC("clients", "Show active Moira clients", ShowClients), - } + NULLFUNC, + NULLFUNC, + "Miscellaneous Menu", + 2, + { + SIMPLEFUNC("statistics", "Show database statistics", TableStats), + SIMPLEFUNC("clients", "Show active Moira clients", ShowClients), + } }; @@ -154,8 +153,8 @@ Menu namespace_menu = { "Campus Namespace Database Manipulation", 4, { - SUBMENU("mail","Mail Forwarding", &pobox_menu), - SUBMENU("list","Mailing Lists", &list_menu), + SUBMENU("mail", "Mail Forwarding", &pobox_menu), + SUBMENU("list", "Mailing Lists", &list_menu), {ShowUserByLogin, NULLMENU, 2, { {"account", "Show user account information"}, {"login name", "Desired login name: "} @@ -165,9 +164,7 @@ Menu namespace_menu = { }; -#ifndef DEBUG static void Signal_Handler(), CatchInterrupt(); -#endif static void ErrorExit(), Usage(); char *getlogin(); @@ -182,116 +179,112 @@ Bool use_menu = TRUE; /* whether or not we are using a menu. */ * Returns: doesn't return. */ -void -main(argc, argv) - int argc; - char ** argv; +void main(int argc, char **argv) { - int status; - Menu *menu; - char *motd, **arg; - char pname[ANAME_SZ]; -#ifdef POSIX - struct sigaction act; -#endif - - if ((program_name = strrchr(argv[0], '/')) == NULL) - program_name = argv[0]; - else - program_name++; - program_name = Strsave(program_name); - whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ - - verbose = TRUE; - arg = argv; - moira_server = NULL; - - while (++arg - argv < argc) { - if (**arg == '-') { - if (!strcmp(*arg, "-nomenu")) - use_menu = FALSE; - else if (!strcmp(*arg, "-db")) - if (arg - argv < argc - 1) { - ++arg; - moira_server = *arg; - } else - Usage(argv); + int status; + Menu *menu; + char *motd, **arg; + char pname[ANAME_SZ]; + struct sigaction act; + + if (!(program_name = strrchr(argv[0], '/'))) + program_name = argv[0]; + else + program_name++; + program_name = Strsave(program_name); + whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ + + verbose = TRUE; + arg = argv; + moira_server = NULL; + + while (++arg - argv < argc) + { + if (**arg == '-') + { + if (!strcmp(*arg, "-nomenu")) + use_menu = FALSE; + else if (!strcmp(*arg, "-db")) + if (arg - argv < argc - 1) + { + ++arg; + moira_server = *arg; + } else Usage(argv); + else + Usage(argv); } } - if ( status = mr_connect(moira_server) ) - ErrorExit("\nConnection to Moira server failed", status); + if ((status = mr_connect(moira_server))) + ErrorExit("\nConnection to Moira server failed", status); - /* do this now since calling mr_connect initialized the krb error table - * for us. - */ - if ((status = tf_init(TKT_FILE, R_TKT_FIL)) || - (status = tf_get_pname(pname))) { - com_err(whoami, status, "cannot find your ticket file"); - exit(1); - } - tf_close(); - user = Strsave(pname); - - if ( status = mr_motd(&motd) ) - ErrorExit("\nUnable to check server status", status); - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(1); + /* do this now since calling mr_connect initialized the krb error table + * for us. + */ + if ((status = tf_init(TKT_FILE, R_TKT_FIL)) || + (status = tf_get_pname(pname))) + { + com_err(whoami, status, "cannot find your ticket file"); + exit(1); } + tf_close(); + user = Strsave(pname); - if ( status = mr_auth(program_name) ) { - if (status == MR_USER_AUTH) { - char buf[BUFSIZ]; - com_err(program_name, status, "\nPress [RETURN] to continue"); - fgets(buf, BUFSIZ, stdin); - } else - ErrorExit("\nAuthorization failed -- please run kinit", status); + if ((status = mr_motd(&motd))) + ErrorExit("\nUnable to check server status", status); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(1); } -/* - * These signals should not be set until just before we fire up the menu - * system. - */ + if ((status = mr_auth(program_name))) + { + if (status == MR_USER_AUTH) + { + char buf[BUFSIZ]; + com_err(program_name, status, "\nPress [RETURN] to continue"); + fgets(buf, BUFSIZ, stdin); + } + else + ErrorExit("\nAuthorization failed -- please run kinit", status); + } -#ifndef DEBUG -#ifdef POSIX - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) Signal_Handler; - (void) sigaction(SIGHUP, &act, NULL); - (void) sigaction(SIGQUIT, &act, NULL); - if (use_menu) - (void) sigaction(SIGINT, &act, NULL); - else { - act.sa_handler= (void (*)()) CatchInterrupt; - (void) sigaction(SIGINT, &act, NULL); + /* + * These signals should not be set until just before we fire up the menu + * system. + */ + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) Signal_Handler; + sigaction(SIGHUP, &act, NULL); + sigaction(SIGQUIT, &act, NULL); + if (use_menu) + sigaction(SIGINT, &act, NULL); + else + { + act.sa_handler = (void (*)()) CatchInterrupt; + sigaction(SIGINT, &act, NULL); } -#else - (void) signal(SIGHUP, Signal_Handler); - (void) signal(SIGQUIT, Signal_Handler); - if (use_menu) - (void) signal(SIGINT, Signal_Handler); - else - (void) signal(SIGINT, CatchInterrupt); -#endif /* POSIX */ -#endif /* DEBUG */ - - menu = &namespace_menu; - - if (use_menu) { /* Start menus that execute program */ - Start_paging(); - Start_menu(menu); - Stop_paging(); + + menu = &namespace_menu; + + if (use_menu) /* Start menus that execute program */ + { + Start_paging(); + Start_menu(menu); + Stop_paging(); } - else /* Start program without menus. */ - Start_no_menu(menu); + else /* Start program without menus. */ + Start_no_menu(menu); - mr_disconnect(); - exit(0); + mr_disconnect(); + exit(0); } /* Function Name: ErrorExit @@ -301,14 +294,11 @@ main(argc, argv) * Returns: doesn't return. */ -static void -ErrorExit(buf,status) -int status; -char * buf; +static void ErrorExit(char *buf, int status) { - com_err(program_name, status, buf); - mr_disconnect(); - exit(1); + com_err(program_name, status, buf); + mr_disconnect(); + exit(1); } /* Function Name: usage @@ -317,61 +307,55 @@ char * buf; * Returns: doesn't return. */ -static void -Usage() +static void Usage(void) { - fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); - exit(1); + fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); + exit(1); } -#ifndef DEBUG /* Function Name: Signal_Handler * Description: This function cleans up from a signal interrupt. * Arguments: none. * Returns: doesn't */ -static void -Signal_Handler() +static void Signal_Handler(void) { - Put_message("Signal caught - exiting"); - if (use_menu) - Cleanup_menu(); - mr_disconnect(); - exit(1); + Put_message("Signal caught - exiting"); + if (use_menu) + Cleanup_menu(); + mr_disconnect(); + exit(1); } -static void -CatchInterrupt() +static void CatchInterrupt(void) { - Put_message("Interrupt! Press RETURN to continue"); - interrupt = 1; + Put_message("Interrupt! Press RETURN to continue"); + interrupt = 1; } -#endif /* Dummy routine to be able to link against the rest of the moira client */ -DeleteUser() +int DeleteUser(void) { - return(DM_QUIT); + return DM_QUIT; } -int -NewListHelp() +int NewListHelp(void) { - static char * message[] = { - "A list can be a mailing list, an Athena group list, or both. Each", - "list has an owner and members. The owner of a list may be the list", - "itself, another list, or a user. The members of a list can be users", - "(login names), other lists, or foreign address strings. You can use", - "certain keys to do the following:", - " Refresh the screen - Type ctrl-L.", - " Escape from a function - Type ctrl-C.", - NULL, - }; - - return(PrintHelp(message)); + static char *message[] = { + "A list can be a mailing list, an Athena group list, or both. Each", + "list has an owner and members. The owner of a list may be the list", + "itself, another list, or a user. The members of a list can be users", + "(login names), other lists, or foreign address strings. You can use", + "certain keys to do the following:", + " Refresh the screen - Type ctrl-L.", + " Escape from a function - Type ctrl-C.", + NULL, + }; + + return PrintHelp(message); } diff --git a/clients/moira/nfs.c b/clients/moira/nfs.c index e053011e..98c6b6ff 100644 --- a/clients/moira/nfs.c +++ b/clients/moira/nfs.c @@ -5,17 +5,17 @@ /* This is the file nfs.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: All functions for manipulating NFS Physical directories. - * + * * Created: 5/6/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -45,14 +45,11 @@ * Returns: useful string. */ -static char * -UpdatePrint(info) -char ** info; +static char *UpdatePrint(char **info) { - char temp_buf[BUFSIZ]; - sprintf(temp_buf, "Machine %s Directory %s", - info[NFS_NAME], info[NFS_DIR]); - return(Strsave(temp_buf)); /* Small memory leak here, but no good way + char temp_buf[BUFSIZ]; + sprintf(temp_buf, "Machine %s Directory %s", info[NFS_NAME], info[NFS_DIR]); + return Strsave(temp_buf); /* Small memory leak here, but no good way to avoid it that I see. */ } @@ -62,93 +59,94 @@ char ** info; * Returns: directory of this nfs server, for DeleteNFSService(). */ -static char * -PrintNFSInfo(info) -char ** info; +static char *PrintNFSInfo(char **info) { - char buf[BUFSIZ], status_buf[BUFSIZ]; - int status = atoi(info[NFS_STATUS]); - Bool is_one = FALSE; - - status_buf[0] = '\0'; /* clear string. */ - - if (status & MR_FS_STUDENT) { - strcat(status_buf, "Student"); - is_one = TRUE; + char buf[BUFSIZ], status_buf[BUFSIZ]; + int status = atoi(info[NFS_STATUS]); + Bool is_one = FALSE; + + status_buf[0] = '\0'; /* clear string. */ + + if (status & MR_FS_STUDENT) + { + strcat(status_buf, "Student"); + is_one = TRUE; } - if (status & MR_FS_FACULTY) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Faculty"); - is_one = TRUE; + if (status & MR_FS_FACULTY) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Faculty"); + is_one = TRUE; } - if (status & MR_FS_STAFF) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Staff"); - is_one = TRUE; + if (status & MR_FS_STAFF) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Staff"); + is_one = TRUE; } - if (status & MR_FS_MISC) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Miscellaneous"); + if (status & MR_FS_MISC) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Miscellaneous"); } - /* Add another type here. */ - if (status & MR_FS_GROUPQUOTA) { - if (is_one) - strcat(status_buf, " / "); - strcat(status_buf, "Group Quotas Enabled"); + /* Add another type here. */ + if (status & MR_FS_GROUPQUOTA) + { + if (is_one) + strcat(status_buf, " / "); + strcat(status_buf, "Group Quotas Enabled"); } - if (status_buf[0] == '\0') - strcat(status_buf, "-- None --"); - - Put_message(""); - sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s", - info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]); - Put_message(buf); - sprintf(buf, "Status: %s", status_buf); - Put_message(buf); - sprintf(buf, "Quota Allocated: %-17s Size: %s", - info[NFS_ALLOC], info[NFS_SIZE]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME], - info[NFS_MODWITH]); - Put_message(buf); - return(info[NFS_DIR]); + if (status_buf[0] == '\0') + strcat(status_buf, "-- None --"); + + Put_message(""); + sprintf(buf, "Machine: %-20s Directory: %-15s Device: %s", + info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]); + Put_message(buf); + sprintf(buf, "Status: %s", status_buf); + Put_message(buf); + sprintf(buf, "Quota Allocated: %-17s Size: %s", + info[NFS_ALLOC], info[NFS_SIZE]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME], + info[NFS_MODWITH]); + Put_message(buf); + return info[NFS_DIR]; } /* Function Name: AskNFSInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. * Returns: the arglist to make the update call with. */ -char ** -AskNFSInfo(info) -char ** info; +char **AskNFSInfo(char **info) { - /* Also need name of the machine in this structure. */ - - if (GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]) == - SUB_ERROR) - return(NULL); - if (GetFSTypes(&info[NFS_STATUS], TRUE) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Allocated Space for this filsystem:", - &info[NFS_ALLOC]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Size of this Filsystem:", &info[NFS_SIZE]) == - SUB_ERROR) - return(NULL); - - FreeAndClear(&info[NFS_MODTIME], TRUE); - FreeAndClear(&info[NFS_MODBY], TRUE); - FreeAndClear(&info[NFS_MODWITH], TRUE); - - return(info); + /* Also need name of the machine in this structure. */ + + if (GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]) == + SUB_ERROR) + return NULL; + if (GetFSTypes(&info[NFS_STATUS], TRUE) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Allocated Space for this filsystem:", + &info[NFS_ALLOC]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Size of this Filsystem:", &info[NFS_SIZE]) == + SUB_ERROR) + return NULL; + + FreeAndClear(&info[NFS_MODTIME], TRUE); + FreeAndClear(&info[NFS_MODBY], TRUE); + FreeAndClear(&info[NFS_MODWITH], TRUE); + + return info; } @@ -158,35 +156,31 @@ char ** info; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowNFSService(argc, argv) -int argc; -char **argv; +int ShowNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char *args[10]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[0] = canonicalize_hostname(strsave(argv[1])); - args[1] = strsave(DEFAULT_DIR); - if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) != MR_SUCCESS) - com_err(program_name, stat, " in ShowNFSServices."); - free(args[0]); - free(args[1]); /* prevents memory leaks. */ - - elem = QueueTop(elem); - Loop(elem, (void *) PrintNFSInfo); - - FreeQueue(elem); - return (DM_NORMAL); + register int stat; + struct qelem *elem = NULL; + char *args[10]; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + args[0] = canonicalize_hostname(strsave(argv[1])); + args[1] = strsave(DEFAULT_DIR); + if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) + return DM_NORMAL; + + if ((stat = do_mr_query("get_nfsphys", 2, args, + StoreInfo, &elem))) + com_err(program_name, stat, " in ShowNFSServices."); + free(args[0]); + free(args[1]); /* prevents memory leaks. */ + + elem = QueueTop(elem); + Loop(elem, (void *) PrintNFSInfo); + + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: AddNFSService @@ -195,53 +189,50 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddNFSService(argc, argv) -char **argv; -int argc; +int AddNFSService(int argc, char **argv) { - char **add_args, *args[10]; - char *info[MAX_ARGS_SIZE]; - int stat; - - args[0] = canonicalize_hostname(strsave(argv[1])); - args[1] = strsave(DEFAULT_DIR); - if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) - return(DM_NORMAL); - - if (!ValidName(args[0]) || !ValidName(args[1])) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_nfsphys", 2, args, - NullFunc, (char *) NULL)) == MR_SUCCESS) - stat = MR_EXISTS; - if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in get_nfsphys."); - return(DM_NORMAL); + char **add_args, *args[10]; + char *info[MAX_ARGS_SIZE]; + int stat; + + args[0] = canonicalize_hostname(strsave(argv[1])); + args[1] = strsave(DEFAULT_DIR); + if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) + return DM_NORMAL; + + if (!ValidName(args[0]) || !ValidName(args[1])) + return DM_NORMAL; + + if (!(stat = do_mr_query("get_nfsphys", 2, args, NullFunc, NULL))) + stat = MR_EXISTS; + if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in get_nfsphys."); + return DM_NORMAL; } - - info[NFS_NAME] = Strsave(args[0]); - info[NFS_DIR] = args[1]; /* already saved. */ - info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE); - info[NFS_STATUS] = Strsave(DEFAULT_STATUS); - info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); - info[NFS_SIZE] = Strsave(DEFAULT_SIZE); - info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL; - info[NFS_END] = NULL; - - if ((add_args = AskNFSInfo(info)) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + + info[NFS_NAME] = Strsave(args[0]); + info[NFS_DIR] = args[1]; /* already saved. */ + info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE); + info[NFS_STATUS] = Strsave(DEFAULT_STATUS); + info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); + info[NFS_SIZE] = Strsave(DEFAULT_SIZE); + info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL; + info[NFS_END] = NULL; + + if (!(add_args = AskNFSInfo(info))) + { + Put_message("Aborted."); + return DM_NORMAL; } - - if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args, - Scream, (char *) NULL)) != 0) - com_err(program_name, stat, " in AdsNFSService"); - - FreeInfo(info); - free(args[0]); - return (DM_NORMAL); + + if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args, + Scream, NULL))) + com_err(program_name, stat, " in AdsNFSService"); + + FreeInfo(info); + free(args[0]); + return DM_NORMAL; } /* Function Name: RealUpdateNFSService @@ -251,23 +242,20 @@ int argc; * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateNFSService(info, junk) -char ** info; -Bool junk; +static void RealUpdateNFSService(char **info, Bool junk) { - char ** args; - register int stat; - - if ((args = AskNFSInfo(info)) == NULL) { - Put_message("Aborted."); - return; + char **args; + register int stat; + + if (!(args = AskNFSInfo(info))) + { + Put_message("Aborted."); + return; } - if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args, - Scream, (char *)NULL)) != MR_SUCCESS) - com_err(program_name, stat, " in RealUpdateNFSService"); + if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args, + Scream, NULL))) + com_err(program_name, stat, " in RealUpdateNFSService"); } /* Function Name: UpdateNFSService @@ -276,38 +264,33 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED. */ -int -UpdateNFSService(argc, argv) -char **argv; -int argc; +int UpdateNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char * args[10]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[0] = canonicalize_hostname(strsave(argv[1])); - args[1] = strsave(DEFAULT_DIR); - if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) != MR_SUCCESS) { - com_err(program_name, stat, " in UpdateNFSService."); - return (DM_NORMAL); + register int stat; + struct qelem *elem = NULL; + char *args[10]; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + args[0] = canonicalize_hostname(strsave(argv[1])); + args[1] = strsave(DEFAULT_DIR); + if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) + return DM_NORMAL; + + if ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, (char *) &elem))) + { + com_err(program_name, stat, " in UpdateNFSService."); + return DM_NORMAL; } - free(args[0]); - free(args[1]); /* stop memory leaks. */ + free(args[0]); + free(args[1]); /* stop memory leaks. */ - elem = QueueTop(elem); - QueryLoop(elem, UpdatePrint, RealUpdateNFSService, - "Update NFS Service for"); + elem = QueueTop(elem); + QueryLoop(elem, UpdatePrint, RealUpdateNFSService, "Update NFS Service for"); - FreeQueue(elem); - return (DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: FSPartPrint @@ -316,13 +299,11 @@ int argc; * Returns: none. */ -static void -FSPartPrint(info) -char ** info; +static void FSPartPrint(char **info) { - char buf[BUFSIZ]; - sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]); - Put_message(buf); + char buf[BUFSIZ]; + sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]); + Put_message(buf); } /* Function Name: RealDeleteNFSService @@ -333,52 +314,50 @@ char ** info; * Returns: none. */ -static void -RealDeleteNFSService(info, one_item) -char ** info; -Bool one_item; +static void RealDeleteNFSService(char **info, Bool one_item) { - char temp_buf[BUFSIZ], *args[10]; - struct qelem *elem= NULL; - register int stat; - - sprintf(temp_buf, - "Are you sure that you want to delete the %s directory on %s", - info[NFS_DIR],info[NFS_NAME]); - -/* - * Check to be sure that it is not used by any of the nfs packs. - */ - - if (!one_item || Confirm(temp_buf)) { - args[0] = info[NFS_NAME]; - args[1] = info[NFS_DIR]; - args[2] = NULL; - switch(stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args), - args, StoreInfo, (char *)&elem)) { + char temp_buf[BUFSIZ], *args[10]; + struct qelem *elem = NULL; + register int stat; + + sprintf(temp_buf, + "Are you sure that you want to delete the %s directory on %s", + info[NFS_DIR], info[NFS_NAME]); + + /* + * Check to be sure that it is not used by any of the nfs packs. + */ + + if (!one_item || Confirm(temp_buf)) + { + args[0] = info[NFS_NAME]; + args[1] = info[NFS_DIR]; + args[2] = NULL; + switch ((stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args), + args, StoreInfo, (char *)&elem))) + { case MR_NO_MATCH: /* it is unused, delete it. */ - if ( (stat = do_mr_query("delete_nfsphys", 2, info, Scream, - (char *) NULL )) != MR_SUCCESS) - com_err(program_name, stat, " in DeleteNFSService"); - else - Put_message("Physical Filesystem Deleted."); - break; + if ((stat = do_mr_query("delete_nfsphys", 2, info, Scream, NULL))) + com_err(program_name, stat, " in DeleteNFSService"); + else + Put_message("Physical Filesystem Deleted."); + break; case MR_SUCCESS: /* it is used, print filesys's that use it. */ - elem = QueueTop(elem); - Put_message("The following fileystems are using this partition,"); - Put_message("and must be removed before it can be deleted."); - Put_message(""); - Loop(elem, FSPartPrint); - - FreeQueue(elem); - Put_message(""); - break; + elem = QueueTop(elem); + Put_message("The following fileystems are using this partition,"); + Put_message("and must be removed before it can be deleted."); + Put_message(""); + Loop(elem, FSPartPrint); + + FreeQueue(elem); + Put_message(""); + break; default: - com_err(program_name, stat, " while checking usage of partition"); + com_err(program_name, stat, " while checking usage of partition"); } } - else - Put_message("Physical filesystem not deleted."); + else + Put_message("Physical filesystem not deleted."); } /* Function Name: DeleteNFSService @@ -387,41 +366,38 @@ Bool one_item; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeleteNFSService(argc, argv) -int argc; -char **argv; +int DeleteNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char * args[10]; + register int stat; + struct qelem *elem = NULL; + char *args[10]; - if (!ValidName(argv[1])) - return(DM_NORMAL); + if (!ValidName(argv[1])) + return DM_NORMAL; - args[0] = canonicalize_hostname(strsave(argv[1])); - args[1] = strsave(DEFAULT_DIR); - if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) - return(DM_NORMAL); + args[0] = canonicalize_hostname(strsave(argv[1])); + args[1] = strsave(DEFAULT_DIR); + if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) + return DM_NORMAL; - switch(stat = do_mr_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) { + switch ((stat = do_mr_query("get_nfsphys", 2, args, + StoreInfo, (char *) &elem))) + { case MR_NO_MATCH: - Put_message("This filsystem does not exist!"); - return(DM_NORMAL); + Put_message("This filsystem does not exist!"); + return DM_NORMAL; case MR_SUCCESS: - break; + break; default: - com_err(program_name, stat, " in DeleteNFSService"); - return(DM_NORMAL); + com_err(program_name, stat, " in DeleteNFSService"); + return DM_NORMAL; } - free(args[0]); - free(args[1]); /* stop memory leaks, in your neighborhood. */ + free(args[0]); + free(args[1]); /* stop memory leaks, in your neighborhood. */ - QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService, - "Delete the Physical Filesystem on Directory"); + QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService, + "Delete the Physical Filesystem on Directory"); - FreeQueue(elem); - return(DM_NORMAL); -} + FreeQueue(elem); + return DM_NORMAL; +} diff --git a/clients/moira/pobox.c b/clients/moira/pobox.c index d723de86..17f49841 100644 --- a/clients/moira/pobox.c +++ b/clients/moira/pobox.c @@ -5,17 +5,17 @@ /* This is the file pobox.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: Functions for handling the poboxes. - * + * * Created: 7/10/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -40,17 +40,15 @@ * Returns: MR_CONT */ -static void -PrintPOBox(info) -char ** info; +static void PrintPOBox(char **info) { - char buf[BUFSIZ]; - - sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME], - info[PO_BOX], info[PO_TYPE]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]); - Put_message(buf); + char buf[BUFSIZ]; + + sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME], + info[PO_BOX], info[PO_TYPE]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]); + Put_message(buf); } /* Function Name: RealPrintPOMachines @@ -59,11 +57,9 @@ char ** info; * Returns: none. */ -static void -RealPrintPOMachines(info) -char ** info; +static void RealPrintPOMachines(char **info) { - Print(1, info + 1, (char *) NULL); + Print(1, info + 1, NULL); } /* Function Name: PrintPOMachines @@ -72,23 +68,23 @@ char ** info; * Returns: SUB_ERROR if the machines could not be printed. */ -static int -PrintPOMachines() +static int PrintPOMachines(void) { - register int status; - static char * args[] = {"pop", NULL}; - struct qelem * top = NULL; - - if ( (status = do_mr_query("get_server_locations", CountArgs(args), args, - StoreInfo, (char *)&top)) != MR_SUCCESS) { - com_err(program_name, status, " in get_server_locations."); - return(SUB_ERROR); + register int status; + static char *args[] = {"pop", NULL}; + struct qelem *top = NULL; + + if ((status = do_mr_query("get_server_locations", CountArgs(args), args, + StoreInfo, (char *)&top))) + { + com_err(program_name, status, " in get_server_locations."); + return SUB_ERROR; } - - top = QueueTop(top); - Loop(top, RealPrintPOMachines); - FreeQueue(top); - return(SUB_NORMAL); + + top = QueueTop(top); + Loop(top, RealPrintPOMachines); + FreeQueue(top); + return SUB_NORMAL; } /* Function Name: GetUserPOBox @@ -97,35 +93,32 @@ PrintPOMachines() * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -GetUserPOBox(argc, argv) -int argc; -char ** argv; +int GetUserPOBox(int argc, char **argv) { - register int status; - struct qelem * top = NULL; - char buf[BUFSIZ]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, - (char *)&top)) { + register int status; + struct qelem *top = NULL; + char buf[BUFSIZ]; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, + (char *)&top))) + { case MR_NO_MATCH: - Put_message("This user has no P.O. Box."); - break; + Put_message("This user has no P.O. Box."); + break; case MR_SUCCESS: - sprintf(buf,"Current pobox for user %s: \n", argv[1]); - Put_message(""); - top = QueueTop(top); - Loop(top, PrintPOBox); /* should only return 1 box. */ - FreeQueue(top); - break; + sprintf(buf, "Current pobox for user %s: \n", argv[1]); + Put_message(""); + top = QueueTop(top); + Loop(top, PrintPOBox); /* should only return 1 box. */ + FreeQueue(top); + break; default: - com_err(program_name, status, " in get_pobox."); + com_err(program_name, status, " in get_pobox."); } - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: GetNewLocalPOBox @@ -134,24 +127,23 @@ char ** argv; * Returns: machine - name of the machine for then new pop box, or NULL. */ -static char * -GetNewLocalPOBox(local_user) -char * local_user; +static char *GetNewLocalPOBox(char *local_user) { - char temp_buf[BUFSIZ]; - - sprintf(temp_buf,"%s %s", "Pick one of the following", - "machines for this user's Post Office."); - Put_message(temp_buf); - Put_message(""); - if (PrintPOMachines() == SUB_NORMAL) { - Put_message(""); - if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ)) - return((char *) SUB_ERROR); - return(canonicalize_hostname(strsave(temp_buf))); + char temp_buf[BUFSIZ]; + + sprintf(temp_buf, "%s %s", "Pick one of the following", + "machines for this user's Post Office."); + Put_message(temp_buf); + Put_message(""); + if (PrintPOMachines() == SUB_NORMAL) + { + Put_message(""); + if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ)) + return (char *) SUB_ERROR; + return canonicalize_hostname(strsave(temp_buf)); } - Put_message("Could not get machines to choose from, quitting."); - return((char *) SUB_ERROR); + Put_message("Could not get machines to choose from, quitting."); + return (char *) SUB_ERROR; } /* Function Name: SetUserPOBox @@ -160,107 +152,111 @@ char * local_user; * Returns: DM_NORMAL. */ -int -SetUserPOBox(argc, argv) -int argc; -char **argv; +int SetUserPOBox(int argc, char **argv) { - register int status; - char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ]; - char *temp_box; - struct qelem * top = NULL; - local_user = argv[1]; - - if (!ValidName(local_user)) - return(DM_NORMAL); - - /* Print the current PO Box info */ - switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, - (char *)&top)) { + register int status; + char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ]; + char *temp_box; + struct qelem *top = NULL; + local_user = argv[1]; + + if (!ValidName(local_user)) + return DM_NORMAL; + + /* Print the current PO Box info */ + switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, + (char *)&top))) + { case MR_SUCCESS: - sprintf(temp_buf,"Current pobox for user %s: \n", local_user); - Put_message(""); - top = QueueTop(top); - Loop(top, PrintPOBox); /* should only return 1 box. */ - FreeQueue(top); - break; + sprintf(temp_buf, "Current pobox for user %s: \n", local_user); + Put_message(""); + top = QueueTop(top); + Loop(top, PrintPOBox); /* should only return 1 box. */ + FreeQueue(top); + break; case MR_NO_MATCH: - Put_message("This user has no P.O. Box."); - break; + Put_message("This user has no P.O. Box."); + break; default: - com_err(program_name, status, " in get_pobox."); - return(DM_NORMAL); + com_err(program_name, status, " in get_pobox."); + return DM_NORMAL; } - sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user); - switch (YesNoQuestion(temp_buf, TRUE)) { + sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user); + switch (YesNoQuestion(temp_buf, TRUE)) + { case TRUE: - type = LOCAL_BOX; - switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) { + type = LOCAL_BOX; + switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) + { case TRUE: - switch (status = do_mr_query("set_pobox_pop", 1, - &local_user, Scream, NULL)) { + switch ((status = do_mr_query("set_pobox_pop", 1, + &local_user, Scream, NULL))) + { case MR_SUCCESS: - return(DM_NORMAL); + return DM_NORMAL; case MR_MACHINE: - sprintf(temp_buf, "%s did not have a previous local PO Box.", - local_user); - Put_message(temp_buf); - if ( (temp_box = GetNewLocalPOBox(local_user)) != - (char *) SUB_ERROR) { - strcpy(box, temp_box); - free(temp_box); + sprintf(temp_buf, "%s did not have a previous local PO Box.", + local_user); + Put_message(temp_buf); + if ((temp_box = GetNewLocalPOBox(local_user)) != + (char *) SUB_ERROR) + { + strcpy(box, temp_box); + free(temp_box); } - else - return(DM_NORMAL); - break; + else + return DM_NORMAL; + break; default: - com_err(program_name, status, " in set_pobox_pop."); - return(DM_NORMAL); + com_err(program_name, status, " in set_pobox_pop."); + return DM_NORMAL; } - break; + break; case FALSE: - if ( (temp_box = GetNewLocalPOBox(local_user)) != - (char *) SUB_ERROR) { - strcpy(box, temp_box); - free(temp_box); + if ((temp_box = GetNewLocalPOBox(local_user)) != + (char *) SUB_ERROR) + { + strcpy(box, temp_box); + free(temp_box); } - else - return(DM_NORMAL); - break; + else + return DM_NORMAL; + break; default: - return(DM_NORMAL); + return DM_NORMAL; } - break; + break; case FALSE: - type = FOREIGN_BOX; - sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user); - switch( YesNoQuestion(temp_buf, TRUE)) { + type = FOREIGN_BOX; + sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user); + switch (YesNoQuestion(temp_buf, TRUE)) + { case TRUE: - if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ)) - return(DM_NORMAL); - break; + if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ)) + return DM_NORMAL; + break; case FALSE: default: - return(DM_NORMAL); /* ^C hit. */ + return DM_NORMAL; /* ^C hit. */ } - break; + break; default: /* ^C hit. */ - Put_message("Aborted."); - return(DM_NORMAL); + Put_message("Aborted."); + return DM_NORMAL; } - args[PO_NAME] = local_user; - args[PO_TYPE] = type; - args[PO_BOX] = box; - args[PO_END] = NULL; - if ( (status = do_mr_query("set_pobox", CountArgs(args), args, - Scream, NULL)) != MR_SUCCESS ) - com_err(program_name, status, " in ChangeUserPOBox"); - else - Put_message("PO Box assigned."); - - return (DM_NORMAL); + args[PO_NAME] = local_user; + args[PO_TYPE] = type; + args[PO_BOX] = box; + args[PO_END] = NULL; + if ((status = do_mr_query("set_pobox", CountArgs(args), args, + Scream, NULL))) + com_err(program_name, status, " in ChangeUserPOBox"); + else + Put_message("PO Box assigned."); + + return DM_NORMAL; } /* Function Name: RemoveUserPOBox @@ -269,27 +265,24 @@ char **argv; * Returns: DM_NORMAL. */ -/*ARGSUSED */ -int -RemoveUserPOBox(argc, argv) -int argc; -char ** argv; +int RemoveUserPOBox(int argc, char **argv) { - register int status; - char temp_buf[BUFSIZ]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - sprintf(temp_buf, - "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]); - - if (Confirm(temp_buf)) { - if ( (status = do_mr_query("delete_pobox", 1, argv + 1, - Scream, NULL)) != MR_SUCCESS) - com_err(program_name, status, " in delete_pobox."); - else - Put_message("PO Box removed."); + register int status; + char temp_buf[BUFSIZ]; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)", + argv[1]); + + if (Confirm(temp_buf)) + { + if ((status = do_mr_query("delete_pobox", 1, argv + 1, + Scream, NULL))) + com_err(program_name, status, " in delete_pobox."); + else + Put_message("PO Box removed."); } - return(DM_NORMAL); + return DM_NORMAL; } diff --git a/clients/moira/printer.c b/clients/moira/printer.c index c6a8a62a..8b9d859f 100644 --- a/clients/moira/printer.c +++ b/clients/moira/printer.c @@ -5,17 +5,17 @@ /* This is the file printer.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: Functions for handling the printers. - * + * * Created: 8/16/88 * By: Theodore Y. Ts'o * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -35,32 +35,29 @@ /* Function Name: SetDefaults * Description: sets the default values for filesystem additions. - * Arguments: info - an array of char pointers to recieve defaults. + * Arguments: info - an array of char pointers to recieve defaults. * Returns: char ** (this array, now filled). */ -static char ** -SetDefaults(info, name) -char ** info; -char * name; +static char **SetDefaults(char **info, char *name) { - char spool_dir[256]; - - strcpy(spool_dir, "/usr/spool/printer/"); - strcat(spool_dir, name); - - info[PCAP_NAME] = Strsave(name); - info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE); - info[PCAP_SPOOL_DIR] = Strsave(spool_dir); - info[PCAP_RPRINTER] = Strsave(name); - info[PCAP_QSERVER] = Strsave("[NONE]"); - info[PCAP_AUTH] = Strsave("1"); - info[PCAP_PRICE] = Strsave("10"); - info[PCAP_COMMENTS] = Strsave(""); - info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL; - - info[PCAP_END] = NULL; - return(info); + char spool_dir[256]; + + strcpy(spool_dir, "/usr/spool/printer/"); + strcat(spool_dir, name); + + info[PCAP_NAME] = Strsave(name); + info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE); + info[PCAP_SPOOL_DIR] = Strsave(spool_dir); + info[PCAP_RPRINTER] = Strsave(name); + info[PCAP_QSERVER] = Strsave("[NONE]"); + info[PCAP_AUTH] = Strsave("1"); + info[PCAP_PRICE] = Strsave("10"); + info[PCAP_COMMENTS] = Strsave(""); + info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL; + + info[PCAP_END] = NULL; + return info; } /* Function Name: GetPcapInfo @@ -70,20 +67,18 @@ char * name; * if printer not found. */ -static struct qelem * -GetPcapInfo(name) -char *name; - +static struct qelem *GetPcapInfo(char *name) { - int stat; - struct qelem *elem = NULL; - - if ( (stat = do_mr_query("get_printcap_entry", 1, &name, - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetPcapInfo"); - return(NULL); + int stat; + struct qelem *elem = NULL; + + if ((stat = do_mr_query("get_printcap_entry", 1, &name, + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetPcapInfo"); + return NULL; } - return(QueueTop(elem)); + return QueueTop(elem); } /* Function Name: PrintPcapInfo @@ -92,79 +87,75 @@ char *name; * Returns: none */ -static void -PrintPcapInfo(info) -char ** info; +static void PrintPcapInfo(char **info) { - char buf[BUFSIZ]; - - if (!info) { /* If no informaion */ - Put_message("PrintPcapInfo called with null info!"); - return; + char buf[BUFSIZ]; + + if (!info) /* If no informaion */ + { + Put_message("PrintPcapInfo called with null info!"); + return; } - sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME], - info[PCAP_SPOOL_HOST]); - Put_message(buf); - sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s", - info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]); - Put_message(buf); - sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s", - atoi(info[PCAP_AUTH]) ? "yes" : "no", - info[PCAP_PRICE], info[PCAP_QSERVER]); - Put_message(buf); - sprintf(buf, "Comments: %s", info[PCAP_COMMENTS]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME], - info[PCAP_MODWITH]); - Put_message(buf); + sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME], + info[PCAP_SPOOL_HOST]); + Put_message(buf); + sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s", + info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]); + Put_message(buf); + sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s", + atoi(info[PCAP_AUTH]) ? "yes" : "no", + info[PCAP_PRICE], info[PCAP_QSERVER]); + Put_message(buf); + sprintf(buf, "Comments: %s", info[PCAP_COMMENTS]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME], + info[PCAP_MODWITH]); + Put_message(buf); } /* Function Name: AskPcapInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * printer and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. * Returns: none. */ -static char ** -AskPcapInfo(info) -char ** info; +static char **AskPcapInfo(char **info) { - char temp_buf[BUFSIZ]; - - Put_message(""); - sprintf(temp_buf, "Printcap entry for %s.", - info[PCAP_NAME]); - Put_message(temp_buf); - Put_message(""); - - if (GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]) == SUB_ERROR) - return(NULL); - info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]); - if (GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) == - SUB_ERROR) - return(NULL); - info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]); - if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR) - return(NULL); - - FreeAndClear(&info[PCAP_MODTIME], TRUE); - FreeAndClear(&info[PCAP_MODBY], TRUE); - FreeAndClear(&info[PCAP_MODWITH], TRUE); - - return(info); + char temp_buf[BUFSIZ]; + + Put_message(""); + sprintf(temp_buf, "Printcap entry for %s.", info[PCAP_NAME]); + Put_message(temp_buf); + Put_message(""); + + if (GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]) == SUB_ERROR) + return NULL; + info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]); + if (GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) == + SUB_ERROR) + return NULL; + info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]); + if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR) + return NULL; + + FreeAndClear(&info[PCAP_MODTIME], TRUE); + FreeAndClear(&info[PCAP_MODBY], TRUE); + FreeAndClear(&info[PCAP_MODWITH], TRUE); + + return info; } /* ---------------- Printer Menu ------------------ */ @@ -175,40 +166,33 @@ char ** info; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -GetPcap(argc, argv) -int argc; -char **argv; +int GetPcap(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetPcapInfo(argv[1]); /* get info. */ - Loop(top, (void *) PrintPcapInfo); - FreeQueue(top); /* clean the queue. */ - return (DM_NORMAL); + top = GetPcapInfo(argv[1]); /* get info. */ + Loop(top, (void *) PrintPcapInfo); + FreeQueue(top); /* clean the queue. */ + return DM_NORMAL; } /* Function Name: RealDeletePcap * Description: Does the real deletion work. * Arguments: info - array of char *'s containing all useful info. - * one_item - a Boolean that is true if only one item + * one_item - a Boolean that is true if only one item * in queue that dumped us here. * Returns: none. */ -void -RealDeletePcap(info, one_item) -char ** info; -Bool one_item; +void RealDeletePcap(char **info, Bool one_item) { - int stat; + int stat; - if ( (stat = do_mr_query("delete_printcap_entry", 1, - &info[PCAP_NAME], Scream, NULL)) != 0) - com_err(program_name, stat, " printcap entry not deleted."); - else - Put_message("Printcap entry deleted."); + if ((stat = do_mr_query("delete_printcap_entry", 1, + &info[PCAP_NAME], Scream, NULL))) + com_err(program_name, stat, " printcap entry not deleted."); + else + Put_message("Printcap entry deleted."); } /* Function Name: DeletePcap @@ -217,18 +201,13 @@ Bool one_item; * Returns: none. */ -/* ARGSUSED */ - -int -DeletePcap(argc, argv) -int argc; -char **argv; +int DeletePcap(int argc, char **argv) { - struct qelem *elem = GetPcapInfo(argv[1]); - QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer"); + struct qelem *elem = GetPcapInfo(argv[1]); + QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer"); - FreeQueue(elem); - return (DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: AddPcap @@ -237,73 +216,72 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddPcap(argc, argv) -char **argv; -int argc; +int AddPcap(int argc, char **argv) { - char *info[MAX_ARGS_SIZE], **args; - int stat; - - if ( !ValidName(argv[1]) ) - return(DM_NORMAL); - - if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1, - NullFunc, NULL)) == 0) { - Put_message ("A Printer by that name already exists."); - return(DM_NORMAL); - } else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in AddPcap"); - return(DM_NORMAL); - } - - args = AskPcapInfo(SetDefaults(info, argv[1])); - if (args == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + char *info[MAX_ARGS_SIZE], **args; + int stat; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if (!(stat = do_mr_query("get_printcap_entry", 1, argv + 1, + NullFunc, NULL))) + { + Put_message ("A Printer by that name already exists."); + return DM_NORMAL; + } + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in AddPcap"); + return DM_NORMAL; } - if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args, - NullFunc, NULL)) != 0) - com_err(program_name, stat, " in AddPcap"); + args = AskPcapInfo(SetDefaults(info, argv[1])); + if (!args) + { + Put_message("Aborted."); + return DM_NORMAL; + } + + if ((stat = do_mr_query("add_printcap_entry", CountArgs(args), args, + NullFunc, NULL))) + com_err(program_name, stat, " in AddPcap"); - FreeInfo(info); - return (DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } /* Function Name: ChangePcap * Description: Do the work of changing a pcap * Arguments: argc, argv - printcap info - * Returns: + * Returns: */ -int -ChangePcap(info, one_item) -char **info; -Bool one_item; +int ChangePcap(char **info, Bool one_item) { - int stat; - char **oldinfo; - - oldinfo = CopyInfo(info); - if (AskPcapInfo(info) == NULL) - return(DM_QUIT); - if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME], - Scream, NULL)) != 0) { - com_err(program_name, stat, " printcap entry not deleted."); - return(DM_NORMAL); + int stat; + char **oldinfo; + + oldinfo = CopyInfo(info); + if (!AskPcapInfo(info)) + return DM_QUIT; + if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME], + Scream, NULL))) + { + com_err(program_name, stat, " printcap entry not deleted."); + return DM_NORMAL; } - if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info, - NullFunc, NULL)) != 0) { - com_err(program_name, stat, " in ChngPcap"); - if ((stat = do_mr_query("add_printcap_entry", CountArgs(oldinfo) - 3, - oldinfo, NullFunc, NULL)) != 0) - com_err(program_name, stat, " while attempting to put old info back"); + if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info, + NullFunc, NULL))) + { + com_err(program_name, stat, " in ChngPcap"); + if ((stat = do_mr_query("add_printcap_entry", CountArgs(oldinfo) - 3, + oldinfo, NullFunc, NULL))) + com_err(program_name, stat, " while attempting to put old info back"); } - FreeInfo(oldinfo); - return(DM_NORMAL); + FreeInfo(oldinfo); + return DM_NORMAL; } @@ -313,70 +291,62 @@ Bool one_item; * Returns: DM_NORMAL. */ -int -ChngPcap(argc, argv) - int argc; - char **argv; +int ChngPcap(int argc, char **argv) { - struct qelem *elem = GetPcapInfo(argv[1]); - QueryLoop(elem, NullPrint, ChangePcap, "Change the printer"); - FreeQueue(elem); - return(DM_NORMAL); + struct qelem *elem = GetPcapInfo(argv[1]); + QueryLoop(elem, NullPrint, ChangePcap, "Change the printer"); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: SetPdDefaults * Description: sets the default values for palladium additions. - * Arguments: info - an array of char pointers to recieve defaults. + * Arguments: info - an array of char pointers to recieve defaults. * Returns: char ** (this array, now filled). */ -static char ** -SetPdDefaults(info, name) -char ** info; -char * name; +static char **SetPdDefaults(char **info, char *name) { - info[PD_NAME] = Strsave(name); - info[PD_IDENT] = Strsave("10000"); - info[PD_HOST] = Strsave(DEFAULT_MACHINE); - info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL; + info[PD_NAME] = Strsave(name); + info[PD_IDENT] = Strsave("10000"); + info[PD_HOST] = Strsave(DEFAULT_MACHINE); + info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL; - info[PD_END] = NULL; - return(info); + info[PD_END] = NULL; + return info; } /* Function Name: AskPalladiumInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * printer and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. * Returns: none. */ -static char ** -AskPalladiumInfo(info) -char ** info; +static char **AskPalladiumInfo(char **info) { - char temp_buf[BUFSIZ]; - - Put_message(""); - sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", - info[PD_NAME]); - Put_message(temp_buf); - Put_message(""); - - if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) == - SUB_ERROR) - return(NULL); - info[PD_HOST] = canonicalize_hostname(info[PD_HOST]); - - FreeAndClear(&info[PD_MODTIME], TRUE); - FreeAndClear(&info[PD_MODBY], TRUE); - FreeAndClear(&info[PD_MODWITH], TRUE); - - return(info); + char temp_buf[BUFSIZ]; + + Put_message(""); + sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", + info[PD_NAME]); + Put_message(temp_buf); + Put_message(""); + + if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) == + SUB_ERROR) + return NULL; + info[PD_HOST] = canonicalize_hostname(info[PD_HOST]); + + FreeAndClear(&info[PD_MODTIME], TRUE); + FreeAndClear(&info[PD_MODBY], TRUE); + FreeAndClear(&info[PD_MODWITH], TRUE); + + return info; } @@ -386,207 +356,192 @@ char ** info; * Returns: none */ -static void -PrintPalladiumInfo(info) -char ** info; +static void PrintPalladiumInfo(char **info) { - char buf[BUFSIZ]; - - if (!info) { /* If no informaion */ - Put_message("PrintPalladiumInfo called with null info!"); - return; + char buf[BUFSIZ]; + + if (!info) /* If no informaion */ + { + Put_message("PrintPalladiumInfo called with null info!"); + return; } - sprintf(buf, "Name: %-24s Program #: %s Host: %s", - info[PD_NAME], info[PD_IDENT], info[PD_HOST]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME], - info[PD_MODWITH]); - Put_message(buf); + sprintf(buf, "Name: %-24s Program #: %s Host: %s", + info[PD_NAME], info[PD_IDENT], info[PD_HOST]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME], + info[PD_MODWITH]); + Put_message(buf); } -static struct qelem * -GetPalladiumInfo(name) -char *name; +static struct qelem *GetPalladiumInfo(char *name) { - int status; - struct qelem *elem = NULL; + int status; + struct qelem *elem = NULL; - if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem)) - != 0) { - com_err(program_name, status, " in GetPalladiumInfo"); - return(NULL); + if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))) + { + com_err(program_name, status, " in GetPalladiumInfo"); + return NULL; } - return(QueueTop(elem)); + return QueueTop(elem); } -int ChangePalladium(info, one_item) -char **info; -Bool one_item; +int ChangePalladium(char **info, Bool one_item) { - int status; - - if (AskPalladiumInfo(info) == NULL) - return(DM_QUIT); - if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME], - Scream, NULL)) != 0) { - com_err(program_name, status, " palladium entry not deleted."); - return(DM_NORMAL); + int status; + + if (!AskPalladiumInfo(info)) + return DM_QUIT; + if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME], + Scream, NULL))) + { + com_err(program_name, status, " palladium entry not deleted."); + return DM_NORMAL; } - if ((status = do_mr_query("add_palladium", CountArgs(info), info, - NullFunc, NULL)) != 0) - com_err(program_name, status, " in ChngPalladium"); - return(DM_NORMAL); + if ((status = do_mr_query("add_palladium", CountArgs(info), info, + NullFunc, NULL))) + com_err(program_name, status, " in ChngPalladium"); + return DM_NORMAL; } /* Function Name: RealDeletePalladium * Description: Does the real deletion work. * Arguments: info - array of char *'s containing all useful info. - * one_item - a Boolean that is true if only one item + * one_item - a Boolean that is true if only one item * in queue that dumped us here. * Returns: none. */ -void -RealDeletePalladium(info, one_item) -char ** info; -Bool one_item; +void RealDeletePalladium(char **info, Bool one_item) { - int stat; + int stat; - if ( (stat = do_mr_query("delete_palladium", 1, - &info[PD_NAME], Scream, NULL)) != 0) - com_err(program_name, stat, " palladium entry not deleted."); - else - Put_message("Palladium entry deleted."); + if ((stat = do_mr_query("delete_palladium", 1, + &info[PD_NAME], Scream, NULL))) + com_err(program_name, stat, " palladium entry not deleted."); + else + Put_message("Palladium entry deleted."); } -int GetPalladium(argc, argv) -int argc; -char **argv; +int GetPalladium(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetPalladiumInfo(argv[1]); - Loop(top, PrintPalladiumInfo); - FreeQueue(top); - return(DM_NORMAL); + top = GetPalladiumInfo(argv[1]); + Loop(top, PrintPalladiumInfo); + FreeQueue(top); + return DM_NORMAL; } -int AddPalladium(argc, argv) -int argc; -char **argv; +int AddPalladium(int argc, char **argv) { - char *info[MAX_ARGS_SIZE], **args; - int status; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL)) - == 0) { - Put_message("A server or supervisor by that name already exists."); - return(DM_NORMAL); - } else if (status != MR_NO_MATCH) { - com_err(program_name, status, " in AddPalladium"); - return(DM_NORMAL); + char *info[MAX_ARGS_SIZE], **args; + int status; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if (!(status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))) + { + Put_message("A server or supervisor by that name already exists."); + return DM_NORMAL; + } + else if (status != MR_NO_MATCH) + { + com_err(program_name, status, " in AddPalladium"); + return DM_NORMAL; } - args = AskPalladiumInfo(SetPdDefaults(info, argv[1])); - if (args == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + args = AskPalladiumInfo(SetPdDefaults(info, argv[1])); + if (!args) + { + Put_message("Aborted."); + return DM_NORMAL; } - if ((status = do_mr_query("add_palladium", CountArgs(args), args, - Scream, NULL)) != 0) - com_err(program_name, status, " in AddPalladium"); + if ((status = do_mr_query("add_palladium", CountArgs(args), args, + Scream, NULL))) + com_err(program_name, status, " in AddPalladium"); - FreeInfo(info); - return(DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } -int ChngPalladium(argc, argv) -int argc; -char **argv; +int ChngPalladium(int argc, char **argv) { - struct qelem *elem = GetPalladiumInfo(argv[1]); - QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor"); - FreeQueue(elem); - return(DM_NORMAL); + struct qelem *elem = GetPalladiumInfo(argv[1]); + QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor"); + FreeQueue(elem); + return DM_NORMAL; } -int DeletePalladium(argc, argv) -int argc; -char **argv; +int DeletePalladium(int argc, char **argv) { - struct qelem *elem = GetPalladiumInfo(argv[1]); - QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor"); - FreeQueue(elem); - return(DM_NORMAL); + struct qelem *elem = GetPalladiumInfo(argv[1]); + QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, + "Delete server/supervisor"); + FreeQueue(elem); + return DM_NORMAL; } -int ShowPalladiumAlias(argc, argv) -int argc; -char **argv; +int ShowPalladiumAlias(int argc, char **argv) { - struct qelem *elem = NULL; - char *qargv[3], buf[BUFSIZ]; - int status; - - qargv[0] = argv[1]; - qargv[1] = "PALLADIUM"; - qargv[2] = argv[2]; - if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) { - com_err(program_name, status, " in ShowPalladiumAlias"); - return(DM_NORMAL); + struct qelem *elem = NULL; + char *qargv[3], buf[BUFSIZ]; + int status; + + qargv[0] = argv[1]; + qargv[1] = "PALLADIUM"; + qargv[2] = argv[2]; + if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem))) + { + com_err(program_name, status, " in ShowPalladiumAlias"); + return DM_NORMAL; } - elem = QueueTop(elem); - Put_message(""); - while (elem != NULL) { - char **info = (char **) elem->q_data; - sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]); - Put_message(buf); - elem = elem->q_forw; + elem = QueueTop(elem); + Put_message(""); + while (elem) + { + char **info = (char **) elem->q_data; + sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]); + Put_message(buf); + elem = elem->q_forw; } - FreeQueue(QueueTop(elem)); - return(DM_NORMAL); + FreeQueue(QueueTop(elem)); + return DM_NORMAL; } -int AddPalladiumAlias(argc, argv) -int argc; -char **argv; +int AddPalladiumAlias(int argc, char **argv) { - int status; - char *qargv[3]; - - qargv[0] = argv[1]; - qargv[1] = "PALLADIUM"; - qargv[2] = argv[2]; - if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0) - com_err(program_name, status, " in AddPalladiumAlias"); - return(DM_NORMAL); + int status; + char *qargv[3]; + + qargv[0] = argv[1]; + qargv[1] = "PALLADIUM"; + qargv[2] = argv[2]; + if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL))) + com_err(program_name, status, " in AddPalladiumAlias"); + return DM_NORMAL; } -int DeletePalladiumAlias(argc, argv) -int argc; -char **argv; +int DeletePalladiumAlias(int argc, char **argv) { - int status; - char *qargv[3]; - - qargv[0] = argv[1]; - qargv[1] = "PALLADIUM"; - qargv[2] = argv[2]; - if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0) - com_err(program_name, status, " in DeletePalladiumAlias"); - return(DM_NORMAL); + int status; + char *qargv[3]; + + qargv[0] = argv[1]; + qargv[1] = "PALLADIUM"; + qargv[2] = argv[2]; + if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL))) + com_err(program_name, status, " in DeletePalladiumAlias"); + return DM_NORMAL; } diff --git a/clients/moira/quota.c b/clients/moira/quota.c index 4923abcd..a019916c 100644 --- a/clients/moira/quota.c +++ b/clients/moira/quota.c @@ -5,21 +5,22 @@ /* This is the file quota.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: Functions for manipulating the quota information. - * + * * Created: 7/10/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ #include +#include #include #include #include @@ -30,8 +31,8 @@ #include "f_defs.h" #include "globals.h" -static char * def_quota = NULL; - +static char *def_quota = NULL; + #define DEFAULT_FILESYS DEFAULT_NONE #define DEFAULT_USER user /* this is the user who started moira. */ #define NOBODY "[nobody]" @@ -46,51 +47,51 @@ static char * def_quota = NULL; * one, and it works, so why fuck with it. */ -static char * -GetDefaultUserQuota(override) -Bool override; +static char *GetDefaultUserQuota(Bool override) { register int status; - char ** info; - struct qelem * top = NULL; + char **info; + struct qelem *top = NULL; static char *val[] = {"def_quota", NULL}; - if (override || (def_quota == NULL)) { - if ( (status = do_mr_query("get_value", CountArgs(val), val, - StoreInfo, (char *) &top)) != MR_SUCCESS) { - com_err(program_name, status, " in ShowDefaultQuota"); - if (def_quota == NULL) { - Put_message("No default Quota Found, setting default to 0."); - def_quota = Strsave("0"); + if (override || (def_quota == NULL)) + { + if ((status = do_mr_query("get_value", CountArgs(val), val, + StoreInfo, (char *) &top))) + { + com_err(program_name, status, " in ShowDefaultQuota"); + if (!def_quota) + { + Put_message("No default Quota Found, setting default to 0."); + def_quota = Strsave("0"); + } + else + Put_message("No default Quota Found, retaining old value."); + } + else + { + top = QueueTop(top); + info = (char **) top->q_data; + FreeAndClear(&def_quota, TRUE); + def_quota = Strsave(info[0]); + FreeQueue(top); } - else - Put_message("No default Quota Found, retaining old value."); - } - else { - top = QueueTop(top); - info = (char **) top->q_data; - FreeAndClear(&def_quota, TRUE); - def_quota = Strsave(info[0]); - FreeQueue(top); } - } - return(def_quota); + return def_quota; } - + /* Function Name: PrintDefaultQuota * Description: Prints default quota info in a meaningful way. * Arguments: value of the default quota. * Returns: none. */ -static void -PrintDefaultQuota(quota) -char * quota; +static void PrintDefaultQuota(char *quota) { - char temp_buf[BUFSIZ]; - Put_message(""); - sprintf(temp_buf,"The default quota is %s Kb.", quota); - Put_message(temp_buf); + char temp_buf[BUFSIZ]; + Put_message(""); + sprintf(temp_buf, "The default quota is %s Kb.", quota); + Put_message(temp_buf); } /* Function Name: PrintQuota @@ -99,56 +100,48 @@ char * quota; * Returns: none. */ -static char * -PrintQuota(info) -char ** info; +static char *PrintQuota(char **info) { - char buf[BUFSIZ]; - - Put_message(""); - - if (!strcmp(info[Q_TYPE], "ANY")) - sprintf(buf, "Filesystem: %s", info[Q_FILESYS]); - else - sprintf(buf, "Filesystem: %-45s %s %s", info[Q_FILESYS], - info[Q_TYPE], info[Q_NAME]); - Put_message(buf); - sprintf(buf, "Machine: %-20s Directory: %-15s", - info[Q_MACHINE], info[Q_DIRECTORY]); - Put_message(buf); - sprintf(buf, "Quota: %s", info[Q_QUOTA]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[Q_MODBY], info[Q_MODTIME], info[Q_MODWITH]); - Put_message(buf); - return(info[Q_FILESYS]); + char buf[BUFSIZ]; + + Put_message(""); + + if (!strcmp(info[Q_TYPE], "ANY")) + sprintf(buf, "Filesystem: %s", info[Q_FILESYS]); + else + sprintf(buf, "Filesystem: %-45s %s %s", info[Q_FILESYS], + info[Q_TYPE], info[Q_NAME]); + Put_message(buf); + sprintf(buf, "Machine: %-20s Directory: %-15s", + info[Q_MACHINE], info[Q_DIRECTORY]); + Put_message(buf); + sprintf(buf, "Quota: %s", info[Q_QUOTA]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[Q_MODBY], info[Q_MODTIME], info[Q_MODWITH]); + Put_message(buf); + return info[Q_FILESYS]; } -afsfilsyshelper(argc, argv, hint) -int argc; -char **argv; -int *hint; +int afsfilsyshelper(int argc, char **argv, int *hint) { - *hint = !strcmp(argv[FS_TYPE], "AFS"); - return(0); + *hint = !strcmp(argv[FS_TYPE], "AFS"); + return 0; } -int afsfilesys(name) -char *name; +int afsfilesys(char *name) { - int status, ret = 0; - char *argv[1]; - - if (strchr(name, '*') || strchr(name, '?') || strchr(name, '\\')) - return(0); - argv[0] = name; - status = do_mr_query("get_filesys_by_label", 1, argv, - afsfilsyshelper, &ret); - if (status == MR_SUCCESS) - return(ret); - return(status); - + int status, ret = 0; + char *argv[1]; + + if (strchr(name, '*') || strchr(name, '?') || strchr(name, '\\')) + return 0; + argv[0] = name; + status = do_mr_query("get_filesys_by_label", 1, argv, afsfilsyshelper, &ret); + if (status == MR_SUCCESS) + return ret; + return status; } @@ -158,63 +151,69 @@ char *name; * Returns: the arguments. */ -static char ** -GetQuotaArgs(quota) -Bool quota; +static char **GetQuotaArgs(Bool quota) { - char ** args = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *) ); + char **args = malloc(MAX_ARGS_SIZE * sizeof(char *)); int af; - - if (args == NULL) { - Put_message("Could not allocate memory in GetQuotaArgs."); - return(NULL); - } + + if (!args) + { + Put_message("Could not allocate memory in GetQuotaArgs."); + return NULL; + } args[Q_FILESYS] = Strsave(DEFAULT_FILESYS); args[Q_TYPE] = Strsave(DEFAULT_QTYPE); args[Q_NAME] = Strsave(DEFAULT_USER); - if (quota) { - args[Q_QUOTA] = Strsave(GetDefaultUserQuota(FALSE)); - args[Q_QUOTA+1] = NULL; /* NULL terminate. */ - } - else - args[Q_NAME+1] = NULL; /* NULL terminate. */ + if (quota) + { + args[Q_QUOTA] = Strsave(GetDefaultUserQuota(FALSE)); + args[Q_QUOTA + 1] = NULL; /* NULL terminate. */ + } + else + args[Q_NAME + 1] = NULL; /* NULL terminate. */ /* Get filesystem. */ if (GetValueFromUser("Filesystem", &args[Q_FILESYS]) == SUB_ERROR) - return(NULL); + return NULL; if (quota && !ValidName(args[Q_FILESYS])) - return(NULL); - + return NULL; + af = afsfilesys(args[Q_FILESYS]); - if (af != 0 && af != (1 == 1)) { + if (af != 0 && af != 1) + { if (af == MR_NO_MATCH) Put_message("That filesystem does not exist."); else com_err(program_name, af, " in afsfilesys"); - return(NULL); - } - if (af) { - args[Q_TYPE] = strsave("ANY"); - args[Q_NAME] = strsave(NOBODY); - } - else { + return NULL; + } + if (af) + { + args[Q_TYPE] = strsave("ANY"); + args[Q_NAME] = strsave(NOBODY); + } + else + { if (GetTypeFromUser("Quota type", "quota_type", &args[Q_TYPE]) == SUB_ERROR) - return(NULL); + return NULL; if (GetValueFromUser("Name", &args[Q_NAME]) == SUB_ERROR) - return(NULL); - if (!ValidName(args[Q_NAME])) return(NULL); - } + return NULL; + if (!ValidName(args[Q_NAME])) + return NULL; + } - if (quota) { /* Get and check quota. */ + if (quota) /* Get and check quota. */ + { if (GetValueFromUser("Quota", &args[Q_QUOTA]) == SUB_ERROR) - return(NULL); - if (!ValidName(args[Q_QUOTA])) return(NULL); - } - return(args); -} + return NULL; + if (!ValidName(args[Q_QUOTA])) + return NULL; + } + return args; +} /* Function Name: ShowDefaultQuota * Description: This prints out a default quota for the system. @@ -222,11 +221,10 @@ Bool quota; * Returns: DM_NORMAL. */ -int -ShowDefaultQuota() +int ShowDefaultQuota(void) { PrintDefaultQuota(GetDefaultUserQuota(TRUE)); - return (DM_NORMAL); + return DM_NORMAL; } /* Function Name: ChangeDefaultQuota @@ -235,37 +233,35 @@ ShowDefaultQuota() * Returns: DM_NORMAL. */ -/*ARGSUSED*/ -int -ChangeDefaultQuota(argc, argv) -int argc; -char *argv[]; +int ChangeDefaultQuota(int argc, char *argv[]) { - register int status; - char temp_buf[BUFSIZ]; - static char *newval[] = { - "def_quota", NULL, NULL - }; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - sprintf(temp_buf,"%s %s","Are you sure that you want to", - "change the default quota for all new users"); - if(Confirm(temp_buf)) { - newval[1] = argv[1]; - if ( (status = do_mr_query("update_value", CountArgs(newval), - newval, Scream, NULL)) == MR_SUCCESS ) { + register int status; + char temp_buf[BUFSIZ]; + static char *newval[] = { + "def_quota", NULL, NULL + }; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + sprintf(temp_buf, "%s %s", "Are you sure that you want to", + "change the default quota for all new users"); + if (Confirm(temp_buf)) + { + newval[1] = argv[1]; + if ((status = do_mr_query("update_value", CountArgs(newval), + newval, Scream, NULL)) == MR_SUCCESS) + { FreeAndClear(&def_quota, TRUE); def_quota = Strsave(argv[1]); } - else - com_err(program_name, status, " in update_value"); + else + com_err(program_name, status, " in update_value"); } - else - Put_message("Quota not changed."); + else + Put_message("Quota not changed."); - return (DM_NORMAL); + return DM_NORMAL; } /* ------------------------ Filesystem Quotas -------------------- */ @@ -277,18 +273,17 @@ char *argv[]; * Returns: DM_NORMAL */ -int -GetQuota() +int GetQuota(void) { struct qelem *top = NULL; register int status; - char ** args; + char **args; - if ( (args = GetQuotaArgs(FALSE) ) == NULL) - return(DM_NORMAL); + if (!(args = GetQuotaArgs(FALSE))) + return DM_NORMAL; - if (( status = do_mr_query("get_quota", CountArgs(args), args, - StoreInfo, (char *) &top)) != MR_SUCCESS) + if ((status = do_mr_query("get_quota", CountArgs(args), args, + StoreInfo, (char *) &top)) != MR_SUCCESS) com_err(program_name, status, " in get_quota"); FreeInfo(args); @@ -298,7 +293,7 @@ GetQuota() Loop(top, (void *) PrintQuota); FreeQueue(top); - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: GetQuotaByFilesys @@ -308,25 +303,25 @@ GetQuota() * Returns: DM_NORMAL */ -int -GetQuotaByFilesys() +int GetQuotaByFilesys(void) { struct qelem *top = NULL; register int status; - char **args = (char**)malloc(2*sizeof(char*)); + char **args = malloc(2 * sizeof(char *)); - if (args == NULL) { - Put_message("Could not allocate memory in GetQuotaByFilesys."); - return(DM_NORMAL); - } + if (!args) + { + Put_message("Could not allocate memory in GetQuotaByFilesys."); + return DM_NORMAL; + } args[0] = Strsave(""); args[1] = NULL; if (GetValueFromUser("Filesystem", &args[0]) == SUB_ERROR) - return(DM_NORMAL); + return DM_NORMAL; - if (( status = do_mr_query("get_quota_by_filesys", 1, args, - StoreInfo, (char *) &top)) != MR_SUCCESS) + if ((status = do_mr_query("get_quota_by_filesys", 1, args, + StoreInfo, (char *) &top)) != MR_SUCCESS) com_err(program_name, status, " in get_quota_by_filesys"); FreeInfo(args); @@ -336,7 +331,7 @@ GetQuotaByFilesys() Loop(top, (void *) PrintQuota); FreeQueue(top); - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: AddQuota @@ -345,22 +340,21 @@ GetQuotaByFilesys() * Arguments: None * Returns: DM_NORMAL */ -int -AddQuota() +int AddQuota(void) { - char ** args; + char **args; register int status; - - if ( (args = GetQuotaArgs(TRUE) ) == NULL) - return(DM_NORMAL); - if ( (status = do_mr_query("add_quota", CountArgs(args), args, - Scream, (char *) NULL)) != MR_SUCCESS) + if (!(args = GetQuotaArgs(TRUE))) + return DM_NORMAL; + + if ((status = do_mr_query("add_quota", CountArgs(args), args, + Scream, NULL)) != MR_SUCCESS) com_err(program_name, status, " in add_quota"); - + FreeInfo(args); free(args); - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: RealUpdateQuota @@ -369,26 +363,26 @@ AddQuota() * Returns: none. */ -static void -RealUpdateQuota(info) -char ** info; +static void RealUpdateQuota(char **info) { register int status; char temp_buf[BUFSIZ]; sprintf(temp_buf, "New quota for filesystem %s (in KB)", info[Q_FILESYS]); - if (GetValueFromUser(temp_buf, &info[Q_QUOTA]) == SUB_ERROR) { + if (GetValueFromUser(temp_buf, &info[Q_QUOTA]) == SUB_ERROR) + { Put_message("Not changed."); return; - } + } if (status = do_mr_query("update_quota", 4, info, - Scream, (char *) NULL) != MR_SUCCESS) { - com_err(program_name, status, " in update_quota"); - sprintf(temp_buf,"Could not perform quota change on %s", - info[Q_FILESYS]); - Put_message(temp_buf); - } + Scream, NULL) != MR_SUCCESS) + { + com_err(program_name, status, " in update_quota"); + sprintf(temp_buf, "Could not perform quota change on %s", + info[Q_FILESYS]); + Put_message(temp_buf); + } } /* Function Name: UpdateQuota @@ -398,27 +392,26 @@ char ** info; * Returns: DM_NORMAL */ -int -UpdateQuota() +int UpdateQuota(void) { int status; char **args; struct qelem *top = NULL; - - if ( (args = GetQuotaArgs(FALSE) ) == NULL) - return(DM_NORMAL); - if ( (status = do_mr_query("get_quota", CountArgs(args), args, - StoreInfo, (char *) &top)) != MR_SUCCESS) + if (!(args = GetQuotaArgs(FALSE))) + return DM_NORMAL; + + if ((status = do_mr_query("get_quota", CountArgs(args), args, + StoreInfo, (char *) &top)) != MR_SUCCESS) com_err(program_name, status, " in get_quota"); - + FreeInfo(args); /* done with args, free them. */ free(args); top = QueueTop(top); Loop(top, RealUpdateQuota); FreeQueue(top); - return (DM_NORMAL); + return DM_NORMAL; } @@ -430,31 +423,31 @@ UpdateQuota() * Returns: none. */ -static void -RealDeleteQuota(info, one_item) -char ** info; -Bool one_item; +static void RealDeleteQuota(char **info, Bool one_item) { register int status; char temp_buf[BUFSIZ]; if (!strcmp(info[Q_TYPE], "ANY")) - sprintf(temp_buf, - "Do you really want to delete the quota on %s", - info[Q_FILESYS]); + { + sprintf(temp_buf, "Do you really want to delete the quota on %s", + info[Q_FILESYS]); + } else - sprintf(temp_buf, - "Do you really want to delete the %s %s's quota on %s", - (strcmp(info[Q_TYPE], "USER") ? "group" : "user"), - info[Q_NAME], info[Q_FILESYS]); - - if (!one_item || Confirm(temp_buf)) { - if ( (status = do_mr_query("delete_quota", 3, info, - Scream, (char *) NULL)) != MR_SUCCESS) - com_err(program_name, status, " in delete_quota"); - else - Put_message("Quota sucessfully removed."); - } + { + sprintf(temp_buf, "Do you really want to delete the %s %s's quota on %s", + (strcmp(info[Q_TYPE], "USER") ? "group" : "user"), info[Q_NAME], + info[Q_FILESYS]); + } + + if (!one_item || Confirm(temp_buf)) + { + if ((status = do_mr_query("delete_quota", 3, info, + Scream, NULL)) != MR_SUCCESS) + com_err(program_name, status, " in delete_quota"); + else + Put_message("Quota sucessfully removed."); + } else Put_message("Aborted."); } @@ -466,18 +459,17 @@ Bool one_item; * Returns: DM_NORMAL */ -int -DeleteQuota() +int DeleteQuota(void) { register int status; char **args; struct qelem *top = NULL; - if ( (args = GetQuotaArgs(FALSE) ) == NULL) - return(DM_NORMAL); + if (!(args = GetQuotaArgs(FALSE))) + return DM_NORMAL; - if ( (status = do_mr_query("get_quota", 3, args, - StoreInfo, (char *) &top)) != MR_SUCCESS) + if ((status = do_mr_query("get_quota", 3, args, + StoreInfo, (char *) &top))) com_err(program_name, status, " in get_quota"); FreeInfo(args); @@ -487,7 +479,5 @@ DeleteQuota() "Delete this quota on filesystem"); FreeQueue(top); - return(DM_NORMAL); + return DM_NORMAL; } - - diff --git a/clients/moira/user.c b/clients/moira/user.c index a968d7c1..a434210e 100644 --- a/clients/moira/user.c +++ b/clients/moira/user.c @@ -5,21 +5,22 @@ /* This is the file user.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: Functions for manipulating user information. - * + * * Created: 5/9/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ #include +#include #include #include #include @@ -56,25 +57,27 @@ * Returns: pointer to statically allocated string. */ -static char *states[] = { "Registerable (0)", - "Active (1)", - "Half Registered (2)", - "Deleted (3)", - "Not registerable (4)", - "Enrolled/Registerable (5)", - "Enrolled/Not Registerable (6)", - "Half Enrolled (7)" }; - -static char *UserState(state) -int state; +static char *states[] = { + "Registerable (0)", + "Active (1)", + "Half Registered (2)", + "Deleted (3)", + "Not registerable (4)", + "Enrolled/Registerable (5)", + "Enrolled/Not Registerable (6)", + "Half Enrolled (7)" +}; + +static char *UserState(int state) { - static char buf[BUFSIZ]; + static char buf[BUFSIZ]; - if (state < 0 || state >= US_END) { - sprintf(buf, "Unknown (%d)", state); - return(buf); + if (state < 0 || state >= US_END) + { + sprintf(buf, "Unknown (%d)", state); + return buf; } - return(states[state]); + return states[state]; } @@ -84,14 +87,12 @@ int state; * Returns: none. */ -static void -PrintUserName(info) -char ** info; +static void PrintUserName(char **info) { - char buf[BUFSIZ], print_buf[BUFSIZ]; - sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); - sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]); - Put_message(print_buf); + char buf[BUFSIZ], print_buf[BUFSIZ]; + sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); + sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]); + Put_message(print_buf); } /* Function Name: PrintUserInfo @@ -101,49 +102,42 @@ char ** info; * Returns: none */ -static void -PrintUserInfo(info) -char ** info; +static void PrintUserInfo(char **info) { - char name[BUFSIZ], buf[BUFSIZ]; - int status; + char name[BUFSIZ], buf[BUFSIZ]; + int status; #ifdef GDSS - SigInfo si; + SigInfo si; #endif - sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); - sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name); - Put_message(buf); - sprintf(buf, "User id: %-23s Login shell %-10s Class: %s", - info[U_UID], info[U_SHELL], info[U_CLASS]); - Put_message(buf); + sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); + sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name); + Put_message(buf); + sprintf(buf, "User id: %-23s Login shell %-10s Class: %s", + info[U_UID], info[U_SHELL], info[U_CLASS]); + Put_message(buf); #ifdef GDSS - sprintf(buf, "%s:%s", info[U_NAME], info[U_MITID]); - si.rawsig = NULL; - status = GDSS_Verify(buf, strlen(buf), info[U_SIGNATURE], &si); -#ifdef DEBUG - hex_dump(info[U_SIGNATURE]); - sprintf(buf, "GDSS_Verify => %d", status); - Put_message(buf); -#endif /* DEBUG */ + sprintf(buf, "%s:%s", info[U_NAME], info[U_MITID]); + si.rawsig = NULL; + status = GDSS_Verify(buf, strlen(buf), info[U_SIGNATURE], &si); #else /* GDSS */ - status = 0; + status = 0; #endif /* GDSS */ - sprintf(buf, "Account is: %-20s MIT ID number: %s Signed: %s", - UserState(atoi(info[U_STATE])), info[U_MITID], - *info[U_SIGNATURE] ? (status ? "Bad" : "Yes") : "No"); - Put_message(buf); - if (atoi(info[U_SECURE])) - sprintf(buf, "Secure password set on %s.", atot(info[U_SECURE])); - else - sprintf(buf, "No secure password set."); - Put_message(buf); - sprintf(buf, "Comments: %s", info[U_COMMENT]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME],info[U_MODWITH]); - Put_message(buf); + sprintf(buf, "Account is: %-20s MIT ID number: %s Signed: %s", + UserState(atoi(info[U_STATE])), info[U_MITID], + *info[U_SIGNATURE] ? (status ? "Bad" : "Yes") : "No"); + Put_message(buf); + if (atoi(info[U_SECURE])) + sprintf(buf, "Secure password set on %s.", atot(info[U_SECURE])); + else + sprintf(buf, "No secure password set."); + Put_message(buf); + sprintf(buf, "Comments: %s", info[U_COMMENT]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME], info[U_MODWITH]); + Put_message(buf); } /* Function Name: SetUserDefaults @@ -152,51 +146,50 @@ char ** info; * Returns: args - the filled info structure. */ -static char ** -SetUserDefaults(info) -char ** info; +static char **SetUserDefaults(char **info) { - info[U_NAME] = Strsave(UNIQUE_LOGIN); - info[U_UID] = Strsave(UNIQUE_UID); - info[U_SHELL] = Strsave(DEFAULT_SHELL); - info[U_LAST] = Strsave(DEFAULT_NONE); - info[U_FIRST] = Strsave(DEFAULT_NONE); - info[U_MIDDLE] = Strsave(DEFAULT_NONE); - info[U_STATE] = Strsave(DEFAULT_NO); - info[U_MITID] = Strsave(DEFAULT_NONE); - info[U_CLASS] = Strsave(DEFAULT_CLASS); - info[U_COMMENT] = Strsave(""); - info[U_SIGNATURE] = Strsave(""); - info[U_SECURE] = Strsave("0"); - info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL; - return(info); + info[U_NAME] = Strsave(UNIQUE_LOGIN); + info[U_UID] = Strsave(UNIQUE_UID); + info[U_SHELL] = Strsave(DEFAULT_SHELL); + info[U_LAST] = Strsave(DEFAULT_NONE); + info[U_FIRST] = Strsave(DEFAULT_NONE); + info[U_MIDDLE] = Strsave(DEFAULT_NONE); + info[U_STATE] = Strsave(DEFAULT_NO); + info[U_MITID] = Strsave(DEFAULT_NONE); + info[U_CLASS] = Strsave(DEFAULT_CLASS); + info[U_COMMENT] = Strsave(""); + info[U_SIGNATURE] = Strsave(""); + info[U_SECURE] = Strsave("0"); + info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL; + return info; } -/* Check that the supplied name follows the capitalization rules, and +/* Check that the supplied name follows the capitalization rules, and * offer to correct it if not. */ -CorrectCapitalization(name) -char **name; +int CorrectCapitalization(char **name) { - char temp_buf[BUFSIZ], fixname[BUFSIZ]; - - strcpy(fixname, *name); - FixCase(fixname); - if (strcmp(fixname, *name)) { - Put_message("You entered a name which does not follow the capitalization conventions."); - sprintf(temp_buf, "Correct it to \"%s\"", fixname); - if (YesNoQuestion(temp_buf, 1) == TRUE) { - free(*name); - *name = strsave(fixname); + char temp_buf[BUFSIZ], fixname[BUFSIZ]; + + strcpy(fixname, *name); + FixCase(fixname); + if (strcmp(fixname, *name)) + { + Put_message("You entered a name which does not follow the capitalization conventions."); + sprintf(temp_buf, "Correct it to \"%s\"", fixname); + if (YesNoQuestion(temp_buf, 1) == TRUE) + { + free(*name); + *name = strsave(fixname); } } } /* Function Name: AskUserInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the the structure to put the info into. * flags - Flags asking us which info we want. @@ -205,163 +198,161 @@ char **name; * use the #defined names (e.g args[UID] is not the uid anymore). */ -char ** -AskUserInfo(info, name) -char ** info; -Bool name; +char **AskUserInfo(char **info, Bool name) { - int i; + int i; #ifdef GDSS - SigInfo si; + SigInfo si; #endif - char temp_buf[BUFSIZ], *newname; - - if (name) { - sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]); - Put_message(temp_buf); - } else { - struct qelem *elem = NULL; - char *argv[3]; - - if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_LAST]); - if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_FIRST]); - if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == - SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_MIDDLE]); - argv[0] = info[U_FIRST]; - argv[1] = info[U_LAST]; - if (do_mr_query("get_user_account_by_name", 2, argv, - StoreInfo, (char *) &elem) == 0) { - Put_message("A user by that name already exists in the database."); - Loop(QueueTop(elem), PrintUserInfo); - Loop(QueueTop(elem), FreeInfo); - FreeQueue(elem); - if (YesNoQuestion("Add new user anyway", TRUE) != TRUE) - return(NULL); + char temp_buf[BUFSIZ], *newname; + + if (name) + { + sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]); + Put_message(temp_buf); + } + else + { + struct qelem *elem = NULL; + char *argv[3]; + + if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_LAST]); + if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_FIRST]); + if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_MIDDLE]); + argv[0] = info[U_FIRST]; + argv[1] = info[U_LAST]; + if (do_mr_query("get_user_account_by_name", 2, argv, + StoreInfo, (char *) &elem) == MR_SUCCESS) + { + Put_message("A user by that name already exists in the database."); + Loop(QueueTop(elem), PrintUserInfo); + Loop(QueueTop(elem), FreeInfo); + FreeQueue(elem); + if (YesNoQuestion("Add new user anyway", TRUE) != TRUE) + return NULL; } } - if (name) { - newname = Strsave(info[U_NAME]); - if (GetValueFromUser("The new login name for this user", &newname) == - SUB_ERROR) - return(NULL); - } else if (GetValueFromUser("Login name for this user", &info[U_NAME]) == - SUB_ERROR) - return(NULL); - - if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR) - return(NULL); - if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR) - return(NULL); - if (name) { - if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_LAST]); - if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_FIRST]); - if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == - SUB_ERROR) - return(NULL); - CorrectCapitalization(&info[U_MIDDLE]); + if (name) + { + newname = Strsave(info[U_NAME]); + if (GetValueFromUser("The new login name for this user", &newname) == + SUB_ERROR) + return NULL; } - while (1) { - int i; - if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) == - SUB_ERROR) - return(NULL); - if (isdigit(info[U_STATE][0])) - break; - Put_message("Valid status numbers:"); - for (i = 0; i < US_END; i++) { - sprintf(temp_buf, " %d: %s", i, states[i]); - Put_message(temp_buf); + else if (GetValueFromUser("Login name for this user", &info[U_NAME]) == + SUB_ERROR) + return NULL; + + if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR) + return NULL; + if (name) + { + if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_LAST]); + if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_FIRST]); + if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR) + return NULL; + CorrectCapitalization(&info[U_MIDDLE]); + } + while (1) + { + int i; + if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) == + SUB_ERROR) + return NULL; + if (isdigit(info[U_STATE][0])) + break; + Put_message("Valid status numbers:"); + for (i = 0; i < US_END; i++) + { + sprintf(temp_buf, " %d: %s", i, states[i]); + Put_message(temp_buf); } } - if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR) - return(NULL); - RemoveHyphens(info[U_MITID]); - if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) == - SUB_ERROR) - return(NULL); - if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR) - return(NULL); - - if (YesNoQuestion("Secure password set", - atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE) { - free(info[U_SECURE]); - info[U_SECURE] = strsave("0"); - } else if (!strcmp(info[U_SECURE], "0")) { - char buf[16]; - struct timeval tv; - - gettimeofday(&tv, (struct timezone *)NULL); - sprintf(buf, "%ld", (long) tv.tv_sec); - free(info[U_SECURE]); - info[U_SECURE] = strsave(buf); + if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR) + return NULL; + RemoveHyphens(info[U_MITID]); + if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) == + SUB_ERROR) + return NULL; + if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR) + return NULL; + + if (YesNoQuestion("Secure password set", + atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE) + { + free(info[U_SECURE]); + info[U_SECURE] = strsave("0"); + } + else if (!strcmp(info[U_SECURE], "0")) + { + char buf[16]; + struct timeval tv; + + gettimeofday(&tv, NULL); + sprintf(buf, "%ld", (long) tv.tv_sec); + free(info[U_SECURE]); + info[U_SECURE] = strsave(buf); } - /* Sign record */ + /* Sign record */ #ifdef GDSS - if (strcmp(info[U_NAME], UNIQUE_LOGIN)) { - if (name) - sprintf(temp_buf, "%s:%s", newname, info[U_MITID]); - else - sprintf(temp_buf, "%s:%s", info[U_NAME], info[U_MITID]); - si.rawsig = NULL; - i = GDSS_Verify(temp_buf, strlen(temp_buf), info[U_SIGNATURE], &si); - /* If it's already signed OK, don't resign it. */ - if (i != GDSS_SUCCESS) { - free(info[U_SIGNATURE]); - info[U_SIGNATURE] = malloc(GDSS_Sig_Size() * 2); + if (strcmp(info[U_NAME], UNIQUE_LOGIN)) + { + if (name) + sprintf(temp_buf, "%s:%s", newname, info[U_MITID]); + else + sprintf(temp_buf, "%s:%s", info[U_NAME], info[U_MITID]); + si.rawsig = NULL; + i = GDSS_Verify(temp_buf, strlen(temp_buf), info[U_SIGNATURE], &si); + /* If it's already signed OK, don't resign it. */ + if (i != GDSS_SUCCESS) + { + free(info[U_SIGNATURE]); + info[U_SIGNATURE] = malloc(GDSS_Sig_Size() * 2); sign_again: - i = GDSS_Sign(temp_buf, strlen(temp_buf), info[U_SIGNATURE]); - if (i != GDSS_SUCCESS) - com_err(program_name, gdss2et(i), "Failed to create signature"); - else { - unsigned char buf[256]; - si.rawsig = buf; - i = GDSS_Verify(temp_buf, strlen(temp_buf), - info[U_SIGNATURE], &si); - if (strlen(buf) > 68) { -#ifdef DEBUG - Put_message("Signature too long, trying again"); -#endif /* DEBUG */ - goto sign_again; - } + i = GDSS_Sign(temp_buf, strlen(temp_buf), info[U_SIGNATURE]); + if (i != GDSS_SUCCESS) + com_err(program_name, gdss2et(i), "Failed to create signature"); + else + { + unsigned char buf[256]; + si.rawsig = buf; + i = GDSS_Verify(temp_buf, strlen(temp_buf), + info[U_SIGNATURE], &si); + if (strlen(buf) > 68) + goto sign_again; } -#ifdef DEBUG - Put_message("Made signature:"); - } else { - Put_message("Don't need to remake signature"); -#endif /* DEBUG */ } -#ifdef DEBUG - hex_dump(info[U_SIGNATURE]); -#endif /* DEBUG */ } #else /* GDSS */ - info[U_SIGNATURE] = strsave(""); + info[U_SIGNATURE] = strsave(""); #endif /* GDSS */ - FreeAndClear(&info[U_MODTIME], TRUE); - FreeAndClear(&info[U_MODBY], TRUE); - FreeAndClear(&info[U_MODWITH], TRUE); + FreeAndClear(&info[U_MODTIME], TRUE); + FreeAndClear(&info[U_MODBY], TRUE); + FreeAndClear(&info[U_MODWITH], TRUE); -/* - * Slide the newname into the #2 slot, this screws up all future references - * to this list, since we slip the pointer into a info list it gets freed - * when the rest of the list gets freed. - */ - if (name) - SlipInNewName(info, newname); + /* + * Slide the newname into the #2 slot, this screws up all future references + * to this list, since we slip the pointer into a info list it gets freed + * when the rest of the list gets freed. + */ + if (name) + SlipInNewName(info, newname); - return(info); + return info; } /* Function Name: GetUserInfo @@ -375,64 +366,67 @@ Bool name; * */ -struct qelem * -GetUserInfo(type, name1, name2) -int type; -char *name1, *name2; +struct qelem *GetUserInfo(int type, char *name1, char *name2) { - char * args[2]; - register int status; - struct qelem * elem = NULL; + char *args[2]; + register int status; + struct qelem *elem = NULL; - switch(type) { + switch (type) + { case LOGIN: - args[0] = name1; - if ( (status = do_mr_query("get_user_account_by_login", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, - " when attempting to get_user_account_by_login."); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_user_account_by_login", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, + " when attempting to get_user_account_by_login."); + return NULL; } - break; + break; case UID: - args[0] = name1; - if ( (status = do_mr_query("get_user_account_by_uid", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, - " when attempting to get_user_account_by_uid."); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_user_account_by_uid", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, + " when attempting to get_user_account_by_uid."); + return NULL; } - break; + break; case BY_NAME: - args[0] = name1; - args[1] = name2; - if ( (status = do_mr_query("get_user_account_by_name", 2, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, - " when attempting to get_user_account_by_name."); - return (NULL); + args[0] = name1; + args[1] = name2; + if ((status = do_mr_query("get_user_account_by_name", 2, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, + " when attempting to get_user_account_by_name."); + return NULL; } - break; + break; case CLASS: - args[0] = name1; - if ( (status = do_mr_query("get_user_account_by_class", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, - " when attempting to get_user_account_by_class."); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_user_account_by_class", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, + " when attempting to get_user_account_by_class."); + return NULL; } - break; + break; case ID: - args[0] = name1; - if ( (status = do_mr_query("get_user_account_by_id", 1, args, - StoreInfo, (char *) &elem)) != 0) { - com_err(program_name, status, - " when attempting to get_user_account_by_id."); - return (NULL); + args[0] = name1; + if ((status = do_mr_query("get_user_account_by_id", 1, args, + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, + " when attempting to get_user_account_by_id."); + return NULL; } - break; + break; } - return( QueueTop(elem) ); + return QueueTop(elem) ; } /* Function Name: AddNewUser @@ -441,24 +435,23 @@ char *name1, *name2; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddNewUser() +int AddNewUser(void) { - register int status; - char ** args, *info[MAX_ARGS_SIZE]; + register int status; + char **args, *info[MAX_ARGS_SIZE]; - if ((args = AskUserInfo(SetUserDefaults(info), FALSE)) == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + if (!(args = AskUserInfo(SetUserDefaults(info), FALSE))) + { + Put_message("Aborted."); + return DM_NORMAL; } - if ( (status = do_mr_query("add_user_account", CountArgs(args), - args, Scream, (char *) NULL)) != MR_SUCCESS) - com_err(program_name, status, " in add_user_account"); - else - Put_message("New user added to database."); - FreeInfo(args); - return(DM_NORMAL); + if ((status = do_mr_query("add_user_account", CountArgs(args), + args, Scream, NULL))) + com_err(program_name, status, " in add_user_account"); + else + Put_message("New user added to database."); + FreeInfo(args); + return DM_NORMAL; } @@ -469,16 +462,15 @@ AddNewUser() * Returns: a malloced login name for the user. */ -static char * -GetLoginName() +static char *GetLoginName(void) { - char *name; + char *name; - name = strsave(""); - if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR) - return(NULL); - Put_message("KERBEROS code not added, did not reserve name with kerberos."); - return(name); + name = strsave(""); + if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR) + return NULL; + Put_message("KERBEROS code not added, did not reserve name with kerberos."); + return name; } @@ -488,24 +480,24 @@ GetLoginName() * Returns: uid - the malloced uid of the user that was chosen. */ -static char * -ChooseUser(elem) -struct qelem * elem; +static char *ChooseUser(struct qelem *elem) { - while (elem != NULL) { - char ** info = (char **) elem->q_data; - PrintUserInfo(info); - switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) { + while (elem) + { + char **info = (char **) elem->q_data; + PrintUserInfo(info); + switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) + { case TRUE: - return(Strsave(info[U_UID])); + return Strsave(info[U_UID]); case FALSE: - break; + break; default: /* quit or ^C. */ - return(NULL); + return NULL; } - elem = elem->q_forw; + elem = elem->q_forw; } - return(NULL); + return NULL; } /* Function Name: GetUidNumberFromName @@ -514,50 +506,51 @@ struct qelem * elem; * Returns: uid - a malloced string containing the uid. */ -static char * -GetUidNumberFromName() +static char *GetUidNumberFromName(void) { - char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; - register int status; - struct qelem * top = NULL; - - if (!Prompt_input("First Name: ", first, BUFSIZ)) - return(NULL); - if (!Prompt_input("Last Name: ", last, BUFSIZ)) - return(NULL); - FixCase(first); - FixCase(last); - - args[0] = first; - args[1] = last; - - switch (status = do_mr_query("get_user_account_by_name", 2, args, - StoreInfo, (char *) &top)) { + char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; + register int status; + struct qelem *top = NULL; + + if (!Prompt_input("First Name: ", first, BUFSIZ)) + return NULL; + if (!Prompt_input("Last Name: ", last, BUFSIZ)) + return NULL; + FixCase(first); + FixCase(last); + + args[0] = first; + args[1] = last; + + switch ((status = do_mr_query("get_user_account_by_name", 2, args, + StoreInfo, (char *) &top))) + { case MR_SUCCESS: - break; + break; case MR_NO_MATCH: - Put_message("There is no user in the database with that name."); - return(NULL); + Put_message("There is no user in the database with that name."); + return NULL; default: - com_err(program_name, status, " in get_account_user_by_name."); - return(NULL); + com_err(program_name, status, " in get_account_user_by_name."); + return NULL; } - - top = QueueTop(top); - if (QueueCount(top) == 1) /* This is a unique name. */ { - char ** info = (char **) top->q_data; - Put_message("User ID Number retrieved for the user: "); - Put_message(""); - PrintUserName(info); - uid = Strsave(info[U_UID]); - FreeQueue(top); - return(Strsave(uid)); + + top = QueueTop(top); + if (QueueCount(top) == 1) /* This is a unique name. */ + { + char **info = (char **) top->q_data; + Put_message("User ID Number retrieved for the user: "); + Put_message(""); + PrintUserName(info); + uid = Strsave(info[U_UID]); + FreeQueue(top); + return Strsave(uid); } - Put_message("That name is not unique, choose the user that you want."); - uid = ChooseUser(top); - FreeQueue(top); - return(uid); + Put_message("That name is not unique, choose the user that you want."); + uid = ChooseUser(top); + FreeQueue(top); + return uid; } /* Function Name: SetUserPassword @@ -566,13 +559,11 @@ GetUidNumberFromName() * Returns: none. */ -static void -SetUserPassword(name) -char * name; +static void SetUserPassword(char *name) { - name = name; /* make saber happy. */ - Put_message("Kerberos password not changed, code non-existant."); - /* clever message to call account_admin, if this fails. */ + name = name; /* make saber happy. */ + Put_message("Kerberos password not changed, code non-existant."); + /* clever message to call account_admin, if this fails. */ } /* Function Name: GiveBackLogin @@ -581,13 +572,11 @@ char * name; * Returns: void. */ -static void -GiveBackLogin(name) -char * name; +static void GiveBackLogin(char *name) { - name = name; /* make saber happy. */ - Put_message("kerberos code not implimented, name not given back."); - /* send mail to db maintainer if this fails. */ + name = name; /* make saber happy. */ + Put_message("kerberos code not implimented, name not given back."); + /* send mail to db maintainer if this fails. */ } /* Function Name: RegisterUser @@ -596,61 +585,63 @@ char * name; * Returns: DM_NORMAL. */ -int -RegisterUser() +int RegisterUser(void) { - char * args[MAX_ARGS_SIZE]; - char *login, *fstype = NULL; - char temp_buf[BUFSIZ]; - register int status; - - Put_message("This function has NO kerberos support, so strange things"); - Put_message("may happen if you use it to register a user."); - - switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) { + char *args[MAX_ARGS_SIZE]; + char *login, *fstype = NULL; + char temp_buf[BUFSIZ]; + register int status; + + Put_message("This function has NO kerberos support, so strange things"); + Put_message("may happen if you use it to register a user."); + + switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) + { case TRUE: - Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ); - args[0] = Strsave(temp_buf); - break; + Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ); + args[0] = Strsave(temp_buf); + break; case FALSE: - if ( (args[0] = GetUidNumberFromName()) == NULL) - return(DM_NORMAL); - break; + if (!(args[0] = GetUidNumberFromName())) + return DM_NORMAL; + break; default: - return(DM_NORMAL); + return DM_NORMAL; } - sprintf(temp_buf, "u%s", args[0]); - login = strsave(temp_buf); - if ( (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR) || - ( GetFSTypes(&fstype, FALSE) == SUB_ERROR ) ) { - args[1] = login; - FreeInfo(args); /* This work because the NULL temination is ok. */ - return(DM_NORMAL); + sprintf(temp_buf, "u%s", args[0]); + login = strsave(temp_buf); + if ((GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR) || + (GetFSTypes(&fstype, FALSE) == SUB_ERROR)) + { + args[1] = login; + FreeInfo(args); /* This work because the NULL temination is ok. */ + return DM_NORMAL; } - Put_message("KERBEROS code not added, did not reserve name with kerberos."); - args[1] = login; - args[2] = fstype; - args[3] = NULL; - - switch (status = do_mr_query("register_user", CountArgs(args), - args, Scream, (char *) NULL)) { + Put_message("KERBEROS code not added, did not reserve name with kerberos."); + args[1] = login; + args[2] = fstype; + args[3] = NULL; + + switch ((status = do_mr_query("register_user", CountArgs(args), + args, Scream, NULL))) + { case MR_SUCCESS: - sprintf(temp_buf, "User %s successfully registered.", login); - Put_message(temp_buf); - SetUserPassword(login); - break; + sprintf(temp_buf, "User %s successfully registered.", login); + Put_message(temp_buf); + SetUserPassword(login); + break; case MR_IN_USE: - GiveBackLogin(login); - sprintf(temp_buf, "The username %s is already in use.", login); - Put_message(temp_buf); - break; + GiveBackLogin(login); + sprintf(temp_buf, "The username %s is already in use.", login); + Put_message(temp_buf); + break; default: - com_err(program_name, status, " in register_user"); - break; + com_err(program_name, status, " in register_user"); + break; } - FreeInfo(args); - return(DM_NORMAL); + FreeInfo(args); + return DM_NORMAL; } /* Function Name: RealUpdateUser @@ -660,25 +651,23 @@ RegisterUser() * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateUser(info, junk) -char ** info; -Bool junk; +static void RealUpdateUser(char **info, Bool junk) { - register int status; - char error_buf[BUFSIZ]; - char ** args = AskUserInfo(info, TRUE); - - if (args == NULL) { - Put_message("Aborted."); - return; + register int status; + char error_buf[BUFSIZ]; + char **args = AskUserInfo(info, TRUE); + + if (!args) + { + Put_message("Aborted."); + return; } - if ( (status = do_mr_query("update_user_account", CountArgs(args), - args, Scream, (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, status, " in ModifyFields"); - sprintf(error_buf, "User %s not updated due to errors.", info[NAME]); - Put_message(error_buf); + if ((status = do_mr_query("update_user_account", CountArgs(args), + args, Scream, NULL))) + { + com_err(program_name, status, " in ModifyFields"); + sprintf(error_buf, "User %s not updated due to errors.", info[NAME]); + Put_message(error_buf); } } @@ -688,19 +677,15 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -UpdateUser(argc, argv) -int argc; -char **argv; +int UpdateUser(int argc, char **argv) { - struct qelem * elem; + struct qelem *elem; + + elem = GetUserInfo(LOGIN, argv[1], NULL); + QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user"); - elem = GetUserInfo(LOGIN, argv[1], (char *) NULL); - QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user"); - - FreeQueue(elem); - return(DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: RealDeactivateUser @@ -710,81 +695,91 @@ char **argv; * Returns: none. */ -static void -RealDeactivateUser(info, one_item) -char ** info; -Bool one_item; +static void RealDeactivateUser(char **info, Bool one_item) { - register int status; - char txt_buf[BUFSIZ]; - char * qargs[2], **args; - struct qelem *elem = NULL; - - if (one_item) { - sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]); - if (YesNoQuestion(txt_buf, FALSE) != TRUE) - return; + register int status; + char txt_buf[BUFSIZ]; + char *qargs[2], **args; + struct qelem *elem = NULL; + + if (one_item) + { + sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]); + if (YesNoQuestion(txt_buf, FALSE) != TRUE) + return; } - qargs[0] = info[NAME]; - qargs[1] = "3"; - if ((status = do_mr_query("update_user_status", 2, qargs, Scream, - (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, status, " in update_user_status"); - sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]); - Put_message(txt_buf); - } else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)", - FALSE) == TRUE) { - status = do_mr_query("get_list_info", 1, &(info[NAME]), - StoreInfo, (char *) &elem); - if (status == MR_SUCCESS) { - args =(char **) (QueueTop(elem)->q_data); - free(args[L_ACTIVE]); - args[L_ACTIVE] = strsave("0"); - FreeAndClear(&args[L_MODTIME], TRUE); - FreeAndClear(&args[L_MODBY], TRUE); - FreeAndClear(&args[L_MODWITH], TRUE); - SlipInNewName(args, args[L_NAME]); - if (status = do_mr_query("update_list", CountArgs(args), args, - Scream, (char *) NULL)) { - com_err(program_name, status, " updating list, not deactivating list or filesystem"); - FreeInfo(args); - FreeQueue(elem); - return; + qargs[0] = info[NAME]; + qargs[1] = "3"; + if ((status = do_mr_query("update_user_status", 2, qargs, Scream, NULL))) + { + com_err(program_name, status, " in update_user_status"); + sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]); + Put_message(txt_buf); + } + else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)", + FALSE) == TRUE) + { + status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo, + (char *) &elem); + if (status == MR_SUCCESS) + { + args = (char **) (QueueTop(elem)->q_data); + free(args[L_ACTIVE]); + args[L_ACTIVE] = strsave("0"); + FreeAndClear(&args[L_MODTIME], TRUE); + FreeAndClear(&args[L_MODBY], TRUE); + FreeAndClear(&args[L_MODWITH], TRUE); + SlipInNewName(args, args[L_NAME]); + if ((status = do_mr_query("update_list", CountArgs(args), args, + Scream, NULL))) + { + com_err(program_name, status, " updating list, " + "not deactivating list or filesystem"); + FreeInfo(args); + FreeQueue(elem); + return; } - FreeInfo(args); - FreeQueue(elem); - elem = (struct qelem *) NULL; - } else if (status != MR_NO_MATCH) { - com_err(program_name, status, " getting list info, not deactivating list or filesystem"); - return; + FreeInfo(args); + FreeQueue(elem); + elem = NULL; + } + else if (status != MR_NO_MATCH) + { + com_err(program_name, status, " getting list info, " + "not deactivating list or filesystem"); + return; } - if (status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]), - StoreInfo, (char *) &elem)) { - com_err(program_name, status, " getting filsys info, not deactivating filesystem"); - FreeInfo(args); - FreeQueue(elem); - return; + if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]), + StoreInfo, (char *) &elem))) + { + com_err(program_name, status, " getting filsys info, " + "not deactivating filesystem"); + FreeInfo(args); + FreeQueue(elem); + return; } - args = (char **) (QueueTop(elem)->q_data); - free(args[FS_TYPE]); - args[FS_TYPE] = strsave("ERR"); - free(args[FS_COMMENTS]); - args[FS_COMMENTS] = strsave("Locker disabled; call 3-1325 for help"); - FreeAndClear(&args[FS_MODTIME], TRUE); - FreeAndClear(&args[FS_MODBY], TRUE); - FreeAndClear(&args[FS_MODWITH], TRUE); - SlipInNewName(args, args[FS_NAME]); - if (status = do_mr_query("update_filesys", CountArgs(args), args, - Scream, (char *) NULL)) { - com_err(program_name, status, " updating filesystem, not deactivating filesystem"); - FreeInfo(args); - FreeQueue(elem); - return; + args = (char **) (QueueTop(elem)->q_data); + free(args[FS_TYPE]); + args[FS_TYPE] = strsave("ERR"); + free(args[FS_COMMENTS]); + args[FS_COMMENTS] = strsave("Locker disabled; call 3-1325 for help"); + FreeAndClear(&args[FS_MODTIME], TRUE); + FreeAndClear(&args[FS_MODBY], TRUE); + FreeAndClear(&args[FS_MODWITH], TRUE); + SlipInNewName(args, args[FS_NAME]); + if ((status = do_mr_query("update_filesys", CountArgs(args), args, + Scream, NULL))) + { + com_err(program_name, status, " updating filesystem, " + "not deactivating filesystem"); + FreeInfo(args); + FreeQueue(elem); + return; } - FreeInfo(args); - FreeQueue(elem); + FreeInfo(args); + FreeQueue(elem); } } @@ -795,19 +790,15 @@ Bool one_item; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeactivateUser(argc, argv) -int argc; -char **argv; +int DeactivateUser(int argc, char **argv) { - struct qelem * elem; + struct qelem *elem; - elem = GetUserInfo(LOGIN, argv[1], (char *) NULL); - QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user"); - - FreeQueue(elem); - return(DM_NORMAL); + elem = GetUserInfo(LOGIN, argv[1], NULL); + QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user"); + + FreeQueue(elem); + return DM_NORMAL; } @@ -819,32 +810,29 @@ char **argv; * Description: Deletes the user given a uid number. * Arguments: argc, argv - uid if user in argv[1]. * Returns: DM_NORMAL. - * NOTES: This just gets the username from the mr server + * NOTES: This just gets the username from the mr server * and performs a DeleteUser(). */ -int -DeleteUserByUid(argc, argv) -int argc; -char **argv; +int DeleteUserByUid(int argc, char **argv) { - int status; - struct qelem *elem = NULL; - char ** info; - - if(!ValidName(argv[1])) - return(DM_NORMAL); - - if ( (status = do_mr_query("get_user_account_by_uid", 1, argv+1, StoreInfo, - (char * ) &elem)) != MR_SUCCESS) - com_err(program_name, status, " in get_user_account_by_uid"); - - info = (char **) elem->q_data; - argv[1] = info[U_NAME]; - - (void) DeleteUser(argc, argv); - return(DM_NORMAL); -} + int status; + struct qelem *elem = NULL; + char **info; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo, + (char *) &elem))) + com_err(program_name, status, " in get_user_account_by_uid"); + + info = (char **) elem->q_data; + argv[1] = info[U_NAME]; + + DeleteUser(argc, argv); + return DM_NORMAL; +} /* ------------------------- Show User Information ------------------------- */ @@ -854,19 +842,15 @@ char **argv; * Returns: DM_NORMAL */ -/* ARGSUSED */ -int -ShowUserByLogin(argc, argv) -int argc; -char *argv[]; +int ShowUserByLogin(int argc, char *argv[]) { - struct qelem *top, *elem; + struct qelem *top, *elem; - elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL); - Loop(elem, PrintUserInfo); + elem = top = GetUserInfo(LOGIN, argv[1], NULL); + Loop(elem, PrintUserInfo); - FreeQueue(top); - return (DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } /* Function Name: RetrieveUserByName @@ -876,37 +860,34 @@ char *argv[]; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowUserByName(argc, argv) -int argc; -char *argv[]; +int ShowUserByName(int argc, char *argv[]) { - struct qelem *top; - char buf[BUFSIZ]; + struct qelem *top; + char buf[BUFSIZ]; - top = GetUserInfo(BY_NAME, argv[1], argv[2]); + top = GetUserInfo(BY_NAME, argv[1], argv[2]); - if (top == NULL) /* if there was an error then return. */ - return(DM_NORMAL); + if (!top) /* if there was an error then return. */ + return DM_NORMAL; - if (!PromptWithDefault("Print full information, or just the names (f/n)?", - buf, 2, "f")) - return(DM_NORMAL); + if (!PromptWithDefault("Print full information, or just the names (f/n)?", + buf, 2, "f")) + return DM_NORMAL; - switch(buf[0]) { + switch (buf[0]) + { case 'F': case 'f': - Loop(top, PrintUserInfo); - break; + Loop(top, PrintUserInfo); + break; case 'N': case 'n': - Loop(top, PrintUserName); - break; + Loop(top, PrintUserName); + break; } - - FreeQueue(top); - return (DM_NORMAL); + + FreeQueue(top); + return DM_NORMAL; } /* Function Name: ShowUserByClass @@ -915,21 +896,17 @@ char *argv[]; * Returns: none. */ -/* ARGSUSED */ -int -ShowUserByClass(argc, argv) -int argc; -char **argv; +int ShowUserByClass(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE) - return (DM_NORMAL); - top = GetUserInfo(CLASS, argv[1], (char *) NULL); - Loop(top, PrintUserName); + if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE) + return DM_NORMAL; + top = GetUserInfo(CLASS, argv[1], NULL); + Loop(top, PrintUserName); - FreeQueue(top); - return (DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } @@ -939,19 +916,15 @@ char **argv; * Returns: DM_NORMAL */ -/* ARGSUSED */ -int -ShowUserById(argc, argv) -int argc; -char *argv[]; +int ShowUserById(int argc, char *argv[]) { - struct qelem *top, *elem; + struct qelem *top, *elem; - elem = top = GetUserInfo(ID, argv[1], (char *) NULL); - Loop(elem, PrintUserInfo); + elem = top = GetUserInfo(ID, argv[1], NULL); + Loop(elem, PrintUserInfo); - FreeQueue(top); - return (DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } @@ -962,34 +935,32 @@ char *argv[]; * Returns: none. */ -/* ARGSUSED */ -int -GetKrbmap(argc, argv) -int argc; -char **argv; +int GetKrbmap(int argc, char **argv) { - int stat; - struct qelem *elem = NULL, *top; - char buf[BUFSIZ]; - - if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1], - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetKrbMap."); - return(DM_NORMAL); + int stat; + struct qelem *elem = NULL, *top; + char buf[BUFSIZ]; + + if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1], + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetKrbMap."); + return DM_NORMAL; } - top = elem = QueueTop(elem); - Put_message(""); - while (elem != NULL) { - char **info = (char **) elem->q_data; - sprintf(buf, "User: %-9s Principal: %s", - info[KMAP_USER], info[KMAP_PRINCIPAL]); - Put_message(buf); - elem = elem->q_forw; + top = elem = QueueTop(elem); + Put_message(""); + while (elem) + { + char **info = (char **) elem->q_data; + sprintf(buf, "User: %-9s Principal: %s", + info[KMAP_USER], info[KMAP_PRINCIPAL]); + Put_message(buf); + elem = elem->q_forw; } - FreeQueue(QueueTop(top)); - return(DM_NORMAL); + FreeQueue(QueueTop(top)); + return DM_NORMAL; } @@ -1000,25 +971,23 @@ char **argv; * Returns: none. */ -/* ARGSUSED */ -int -AddKrbmap(argc, argv) -int argc; -char **argv; +int AddKrbmap(int argc, char **argv) { - int stat; + int stat; - if (!strchr(argv[KMAP_PRINCIPAL + 1], '@')) { - Put_message("Please specify a realm for the kerberos principal."); - return(DM_NORMAL); + if (!strchr(argv[KMAP_PRINCIPAL + 1], '@')) + { + Put_message("Please specify a realm for the kerberos principal."); + return DM_NORMAL; } - if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1], - Scream, NULL)) != 0) { - com_err(program_name, stat, " in AddKrbMap."); - if (stat == MR_EXISTS) - Put_message("No user or principal may have more than one mapping."); + if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1], + Scream, NULL))) + { + com_err(program_name, stat, " in AddKrbMap."); + if (stat == MR_EXISTS) + Put_message("No user or principal may have more than one mapping."); } - return(DM_NORMAL); + return DM_NORMAL; } @@ -1029,19 +998,14 @@ char **argv; * Returns: none. */ -/* ARGSUSED */ -int -DeleteKrbmap(argc, argv) -int argc; -char **argv; +int DeleteKrbmap(int argc, char **argv) { - int stat; + int stat; - if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1], - Scream, NULL)) != 0) { - com_err(program_name, stat, " in DeleteKrbMap."); - } - return(DM_NORMAL); + if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1], + Scream, NULL))) + com_err(program_name, stat, " in DeleteKrbMap."); + return DM_NORMAL; } @@ -1051,44 +1015,41 @@ char **argv; * Returns: none. */ -/* ARGSUSED */ -int -GetDirFlags(argc, argv) -int argc; -char **argv; +int GetDirFlags(int argc, char **argv) { - int stat, flags; - struct qelem *elem = NULL; - char buf[BUFSIZ], **info; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - if ((stat = do_mr_query("get_user_directory_flags", 1, &argv[1], - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetDirFlags."); - return(DM_NORMAL); + int stat, flags; + struct qelem *elem = NULL; + char buf[BUFSIZ], **info; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if ((stat = do_mr_query("get_user_directory_flags", 1, &argv[1], + StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetDirFlags."); + return DM_NORMAL; } - info = (char **) QueueTop(elem)->q_data; - flags = atoi(info[0]); - FreeQueue(QueueTop(elem)); - - Put_message(""); - sprintf(buf, "User: %s", argv[1]); - Put_message(buf); - if (flags & DIRFLAGS_SUPPRESS) { - Put_message("Does NOT appear in the on-line directory."); - } else { - Put_message("Does appear in the on-line directory."); - if (flags & DIRFLAGS_NONLOCAL) { - Put_message("Is listed with non-MIT.EDU email address (if known)"); - } else { - Put_message("Is listed with MIT.EDU email address."); - } + info = (char **) QueueTop(elem)->q_data; + flags = atoi(info[0]); + FreeQueue(QueueTop(elem)); + + Put_message(""); + sprintf(buf, "User: %s", argv[1]); + Put_message(buf); + if (flags & DIRFLAGS_SUPPRESS) + Put_message("Does NOT appear in the on-line directory."); + else + { + Put_message("Does appear in the on-line directory."); + if (flags & DIRFLAGS_NONLOCAL) + Put_message("Is listed with non-MIT.EDU email address (if known)"); + else + Put_message("Is listed with MIT.EDU email address."); } - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: SetDirFlags @@ -1097,99 +1058,47 @@ char **argv; * Returns: DM_NORMAL. */ -int -SetDirFlags(argc, argv) -int argc; -char **argv; -{ - int stat, flags; - char **info, buf[BUFSIZ], *args[2]; - struct qelem *elem = NULL; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - /* Fetch current prefs */ - if ((stat = do_mr_query("get_user_directory_flags", 1, &argv[1], - StoreInfo, (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetDirFlags."); - return(DM_NORMAL); - } - info = (char **) QueueTop(elem)->q_data; - flags = atoi(info[0]); - FreeQueue(QueueTop(elem)); - - sprintf(buf, "List %s in the on-line directory (y/n)", argv[1]); - if (YesNoQuestion(buf, !(flags & DIRFLAGS_SUPPRESS))) - flags &= ~DIRFLAGS_SUPPRESS; - else - flags |= DIRFLAGS_SUPPRESS; - - sprintf(buf, "List MIT.EDU email address even when mail is forwarded elsewhere? (y/n)"); - if (YesNoQuestion(buf, !(flags & DIRFLAGS_NONLOCAL))) - flags &= ~DIRFLAGS_NONLOCAL; - else - flags |= DIRFLAGS_NONLOCAL; - - args[0] = argv[1]; - sprintf(buf, "%d", flags); - args[1] = buf; - if ( (stat = do_mr_query("update_user_directory_flags", 2, - args, Scream, NULL)) != MR_SUCCESS) - com_err(program_name, stat, " in SetDirFlags"); - else - Put_message("Directory preferences set."); - - return (DM_NORMAL); -} - -#ifdef DEBUG -hex_dump(p) -unsigned char *p; +int SetDirFlags(int argc, char **argv) { - char buf[BUFSIZ]; - int i; - - sprintf(buf, "Size: %d", strlen(p)); - Put_message(buf); - while (strlen(p) >= 8) { - sprintf(buf, "%02x %02x %02x %02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - Put_message(buf); - p += 8; - } - switch (strlen(p)) { - case 7: - sprintf(buf, "%02x %02x %02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4], p[5], p[6]); - break; - case 6: - sprintf(buf, "%02x %02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4], p[5]); - break; - case 5: - sprintf(buf, "%02x %02x %02x %02x %02x", - p[0], p[1], p[2], p[3], p[4]); - break; - case 4: - sprintf(buf, "%02x %02x %02x %02x", - p[0], p[1], p[2], p[3]); - break; - case 3: - sprintf(buf, "%02x %02x %02x", - p[0], p[1], p[2]); - break; - case 2: - sprintf(buf, "%02x %02x", - p[0], p[1]); - break; - case 1: - sprintf(buf, "%02x", - p[0]); - break; - default: - return; + int stat, flags; + char **info, buf[BUFSIZ], *args[2]; + struct qelem *elem = NULL; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + /* Fetch current prefs */ + if ((stat = do_mr_query("get_user_directory_flags", 1, &argv[1], + StoreInfo, (char *) &elem))) + { + com_err(program_name, stat, " in GetDirFlags."); + return DM_NORMAL; } - Put_message(buf); + info = (char **) QueueTop(elem)->q_data; + flags = atoi(info[0]); + FreeQueue(QueueTop(elem)); + + sprintf(buf, "List %s in the on-line directory (y/n)", argv[1]); + if (YesNoQuestion(buf, !(flags & DIRFLAGS_SUPPRESS))) + flags &= ~DIRFLAGS_SUPPRESS; + else + flags |= DIRFLAGS_SUPPRESS; + + sprintf(buf, "List MIT.EDU email address even when mail is " + "forwarded elsewhere? (y/n)"); + if (YesNoQuestion(buf, !(flags & DIRFLAGS_NONLOCAL))) + flags &= ~DIRFLAGS_NONLOCAL; + else + flags |= DIRFLAGS_NONLOCAL; + + args[0] = argv[1]; + sprintf(buf, "%d", flags); + args[1] = buf; + if ((stat = do_mr_query("update_user_directory_flags", 2, + args, Scream, NULL))) + com_err(program_name, stat, " in SetDirFlags"); + else + Put_message("Directory preferences set."); + + return DM_NORMAL; } -#endif diff --git a/clients/moira/utils.c b/clients/moira/utils.c index 97cb191b..faa90d66 100644 --- a/clients/moira/utils.c +++ b/clients/moira/utils.c @@ -5,21 +5,22 @@ /* This is the file utils.c for the MOIRA Client, which allows a nieve * user to quickly and easily maintain most parts of the MOIRA database. * It Contains: Many useful utility functions. - * + * * Created: 4/25/88 * By: Chris D. Peterson * * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ #include +#include #include #include #include @@ -42,18 +43,17 @@ * Returns: none. */ -static void -AddQueue(elem, pred) -struct qelem * elem, *pred; +static void AddQueue(struct qelem *elem, struct qelem *pred) { - if (pred == NULL) { - elem->q_forw = NULL; - elem->q_back = NULL; - return; + if (!pred) + { + elem->q_forw = NULL; + elem->q_back = NULL; + return; } - elem->q_back = pred; - elem->q_forw = pred->q_forw; - pred->q_forw = elem; + elem->q_back = pred; + elem->q_forw = pred->q_forw; + pred->q_forw = elem; } /* Function Name: RemoveQueue @@ -62,34 +62,31 @@ struct qelem * elem, *pred; * Returns: none. */ -static void -RemoveQueue(elem) -struct qelem *elem; +static void RemoveQueue(struct qelem *elem) { - if (elem->q_forw != NULL) - (elem->q_forw)->q_back = elem->q_back; - if (elem->q_back != NULL) - (elem->q_back)->q_forw = elem->q_forw; + if (elem->q_forw) + elem->q_forw->q_back = elem->q_back; + if (elem->q_back) + elem->q_back->q_forw = elem->q_forw; } -/* CopyInfo: allocates memory for a copy of a NULL terminated array of +/* CopyInfo: allocates memory for a copy of a NULL terminated array of * strings q_back != NULL) - elem = elem->q_back; - return(elem); + if (!elem) /* NULL returns NULL. */ + return NULL; + while (elem->q_back) + elem = elem->q_back; + return elem; } /* Function Name: FreeQueueElem @@ -150,18 +140,17 @@ struct qelem * elem; * Returns: none */ -static void -FreeQueueElem(elem) -struct qelem * elem; +static void FreeQueueElem(struct qelem *elem) { - char ** info = (char **) elem->q_data; + char **info = (char **) elem->q_data; - if (info != (char **) NULL) { - FreeInfo( info ); /* free info fields */ - free(elem->q_data); /* free info array itself. */ + if (info) + { + FreeInfo(info); /* free info fields */ + free(elem->q_data); /* free info array itself. */ } - RemoveQueue(elem); /* remove this element from the queue */ - free(elem); /* free its space. */ + RemoveQueue(elem); /* remove this element from the queue */ + free(elem); /* free its space. */ } /* Function Name: FreeQueue @@ -170,16 +159,15 @@ struct qelem * elem; * Returns: none. */ -void -FreeQueue(elem) -struct qelem * elem; +void FreeQueue(struct qelem *elem) { - struct qelem *temp, *local = QueueTop(elem); + struct qelem *temp, *local = QueueTop(elem); - while(local != NULL) { - temp = local->q_forw; - FreeQueueElem(local); - local = temp; + while (local) + { + temp = local->q_forw; + FreeQueueElem(local); + local = temp; } } @@ -189,17 +177,16 @@ struct qelem * elem; * Returns: none. */ -int -QueueCount(elem) -struct qelem * elem; +int QueueCount(struct qelem *elem) { - int count = 0; - elem = QueueTop(elem); - while (elem != NULL) { - count ++; - elem = elem->q_forw; + int count = 0; + elem = QueueTop(elem); + while (elem) + { + count++; + elem = elem->q_forw; } - return(count); + return count; } /* Function Name: StoreInfo @@ -214,33 +201,30 @@ struct qelem * elem; * Returns: MR_CONT, or MR_ABORT if it has problems. */ -int -StoreInfo(argc, argv, data) -int argc; -char ** argv; -char * data; +int StoreInfo(int argc, char **argv, char *data) { - char ** info = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *)); - struct qelem ** old_elem = (struct qelem **) data; - struct qelem * new_elem = (struct qelem *) malloc (sizeof (struct qelem)); - int count; + char **info = malloc(MAX_ARGS_SIZE * sizeof(char *)); + struct qelem **old_elem = (struct qelem **) data; + struct qelem *new_elem = malloc(sizeof(struct qelem)); + int count; - if ( (new_elem == (struct qelem *) NULL) || (info == (char **) NULL) ) { - Put_message("Could Not allocate more memory."); - FreeQueue(*old_elem); - *old_elem = (struct qelem *) NULL; - return(MR_ABORT); + if (!new_elem || !info) + { + Put_message("Could Not allocate more memory."); + FreeQueue(*old_elem); + *old_elem = NULL; + return MR_ABORT; } - for (count = 0; count < argc; count++) - info[count] = Strsave(argv[count]); - info[count] = NULL; /* NULL terminate this sucker. */ + for (count = 0; count < argc; count++) + info[count] = Strsave(argv[count]); + info[count] = NULL; /* NULL terminate this sucker. */ - new_elem->q_data = (char *) info; - AddQueue(new_elem, *old_elem); + new_elem->q_data = (char *) info; + AddQueue(new_elem, *old_elem); - *old_elem = new_elem; - return(MR_CONT); + *old_elem = new_elem; + return MR_CONT; } /* Function Name: CountArgs @@ -250,19 +234,18 @@ char * data; * Returns: number if args in the list. */ -int -CountArgs(info) -char ** info; +int CountArgs(char **info) { - int number = 0; - - while (*info != NULL) { - number++; - info++; + int number = 0; + + while (*info) + { + number++; + info++; } - return(number); -} + return number; +} /* Function Name: Scream * Description: Bitch Loudly and exit, it is intended as a callback @@ -271,19 +254,18 @@ char ** info; * Returns: doesn't exit. */ -int -Scream() +int Scream(void) { - com_err(program_name, 0, - "\nA Moira update returned a value -- programmer botch\n"); - mr_disconnect(); - exit(1); - /*NOTREACHED*/ - return(-1); + com_err(program_name, 0, + "\nA Moira update returned a value -- programmer botch\n"); + mr_disconnect(); + exit(1); + /*NOTREACHED*/ + return -1; } /* Function Name: PromptWithDefault - * Description: allows a user to be prompted for input, and given a + * Description: allows a user to be prompted for input, and given a * default choice. * Arguments: prompt - the prompt string. * buf, buflen - buffer to be returned and its MAX size? @@ -291,31 +273,28 @@ Scream() * Returns: zero on failure */ -int -PromptWithDefault(prompt, buf, buflen, def) -char *prompt, *buf; -int buflen; -char *def; +int PromptWithDefault(char *prompt, char *buf, int buflen, char *def) { - char tmp[BUFSIZ]; - int ans; + char tmp[BUFSIZ]; + int ans; - if (parsed_argc > 0) { - parsed_argc--; - strncpy(buf, parsed_argv[0], buflen); - sprintf(tmp, "%s: %s", prompt, buf); - Put_message(tmp); - parsed_argv++; - return(1); + if (parsed_argc > 0) + { + parsed_argc--; + strncpy(buf, parsed_argv[0], buflen); + sprintf(tmp, "%s: %s", prompt, buf); + Put_message(tmp); + parsed_argv++; + return 1; } - (void) sprintf(tmp, "%s [%s]: ", prompt, def ? def : ""); - ans = Prompt_input(tmp, buf, buflen); - if (IS_EMPTY(buf)) - (void) strcpy(buf, def); - else if (!strcmp(buf, "\"\"")) - *buf = 0; - return(ans); + sprintf(tmp, "%s [%s]: ", prompt, def ? def : ""); + ans = Prompt_input(tmp, buf, buflen); + if (IS_EMPTY(buf)) + strcpy(buf, def); + else if (!strcmp(buf, "\"\"")) + *buf = 0; + return ans; } /* Function Name: YesNoQuestion @@ -326,29 +305,29 @@ char *def; * Returns: TRUE or FALSE or -1 on error */ -Bool -YesNoQuestion(prompt, bool_def) -char *prompt; -int bool_def; +Bool YesNoQuestion(char *prompt, int bool_def) { - char ans[2]; + char ans[2]; - while (TRUE) { - if (!PromptWithDefault(prompt, ans, 2, bool_def ? "y" : "n")) - return(-1); - switch (ans[0]) { + while (TRUE) + { + if (!PromptWithDefault(prompt, ans, 2, bool_def ? "y" : "n")) + return -1; + switch (ans[0]) + { case 'n': case 'N': - return(FALSE); + return FALSE; case 'y': case 'Y': - return(TRUE); + return TRUE; default: - Put_message("Please answer 'y' or 'n'."); - break; + Put_message("Please answer 'y' or 'n'."); + break; } } } + /* Function Name: YesNoQuitQuestion * Description: This prompts the user for the answer to a yes-no or * true-false question, with a quit option. @@ -359,29 +338,28 @@ int bool_def; * seem to need this functionality. */ -Bool -YesNoQuitQuestion(prompt, bool_def) -char *prompt; -int bool_def; +Bool YesNoQuitQuestion(char *prompt, int bool_def) { - char ans[2]; + char ans[2]; - while (TRUE) { - if (!PromptWithDefault(prompt, ans, 2, bool_def ? "y" : "n")) - return(-1); - switch (ans[0]) { + while (TRUE) + { + if (!PromptWithDefault(prompt, ans, 2, bool_def ? "y" : "n")) + return -1; + switch (ans[0]) + { case 'n': case 'N': - return(FALSE); + return FALSE; case 'y': case 'Y': - return(TRUE); + return TRUE; case 'q': case 'Q': - return(-1); + return -1; default: - Put_message("Please answer 'y', 'n' or 'q'."); - break; + Put_message("Please answer 'y', 'n' or 'q'."); + break; } } } @@ -393,11 +371,9 @@ int bool_def; * Returns: TRUE/FALSE - wether or not the confirmation occured. */ -Bool -Confirm(prompt) -char * prompt; +Bool Confirm(char *prompt) { - return( !verbose || (YesNoQuestion(prompt,FALSE) == TRUE) ); + return !verbose || (YesNoQuestion(prompt, FALSE) == TRUE); } /* Function Name: ValidName @@ -406,19 +382,17 @@ char * prompt; * Returns: TRUE if Valid. */ -Bool -ValidName(s) -char *s; +Bool ValidName(char *s) { - if (IS_EMPTY(s)) - Put_message("Please use a non-empty name."); - else if (strchr(s, ' ')) - Put_message("You cannot use space (' ') in this name."); - else if (strchr(s, '*') || strchr(s, '?')) - Put_message("Wildcards not accepted here."); - else - return TRUE; - return FALSE; + if (IS_EMPTY(s)) + Put_message("Please use a non-empty name."); + else if (strchr(s, ' ')) + Put_message("You cannot use space (' ') in this name."); + else if (strchr(s, '*') || strchr(s, '?')) + Put_message("Wildcards not accepted here."); + else + return TRUE; + return FALSE; } /* Function Name: ToggleVerboseMode @@ -427,30 +401,27 @@ char *s; * Returns: DM_NORMAL. */ -int -ToggleVerboseMode() +int ToggleVerboseMode(void) { - verbose = !verbose; if (verbose) Put_message("Delete functions will first confirm\n"); else Put_message("Delete functions will be silent\n"); - - return(DM_NORMAL); + + return DM_NORMAL; } /* Function Name: NullFunc - * Description: dummy callback routine + * Description: dummy callback routine * Arguments: none * Returns: MR_CONT */ -int -NullFunc() +int NullFunc(void) { - return(MR_CONT); + return MR_CONT; } /* Function Name: SlipInNewName @@ -463,18 +434,14 @@ NullFunc() * big way. */ -void -SlipInNewName(info, name) -char ** info; -char * name; +void SlipInNewName(char **info, char *name) { - register int i; + register int i; - /* This also pushes the NULL down. */ - for (i = CountArgs(info); i > 0; i--) { - info[i+1] = info[i]; - } - info[1] = name; /* now slip in the name. */ + /* This also pushes the NULL down. */ + for (i = CountArgs(info); i > 0; i--) + info[i + 1] = info[i]; + info[1] = name; /* now slip in the name. */ } /* Function Name: GetValueFromUser @@ -486,28 +453,28 @@ char * name; * Returns: SUB_ERROR if break hit (^C). */ -int -GetValueFromUser(prompt, pointer) -char * prompt, ** pointer; +int GetValueFromUser(char *prompt, char **pointer) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - if (PromptWithDefault(prompt, buf, BUFSIZ, *pointer) == 0) - return(SUB_ERROR); + if (PromptWithDefault(prompt, buf, BUFSIZ, *pointer) == 0) + return SUB_ERROR; -/* - * If these are the same then there is no need to allocate a new string. - * - * a difference that makes no difference, IS no difference. - */ + /* + * If these are the same then there is no need to allocate a new string. + * + * a difference that makes no difference, IS no difference. + */ - if (*pointer != NULL) { - if (strcmp(buf, *pointer) != 0) { - free(*pointer); - *pointer = Strsave(buf); + if (*pointer) + { + if (strcmp(buf, *pointer)) + { + free(*pointer); + *pointer = Strsave(buf); } } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: GetYesNoValueFromUser @@ -519,36 +486,35 @@ char * prompt, ** pointer; * Returns: SUB_ERROR if break hit (^C). */ -int -GetYesNoValueFromUser(prompt, pointer) -char * prompt, ** pointer; +int GetYesNoValueFromUser(char *prompt, char **pointer) { - char user_prompt[BUFSIZ]; - Bool default_val; + char user_prompt[BUFSIZ]; + Bool default_val; + + if (!strcmp(*pointer, DEFAULT_YES)) + default_val = TRUE; + else + default_val = FALSE; - if ( strcmp (*pointer, DEFAULT_YES) == 0 ) - default_val = TRUE; - else - default_val = FALSE; - - sprintf(user_prompt, "%s (y/n)", prompt); + sprintf(user_prompt, "%s (y/n)", prompt); - switch (YesNoQuestion(user_prompt, default_val)) { + switch (YesNoQuestion(user_prompt, default_val)) + { case TRUE: - if (*pointer != NULL) - free(*pointer); - *pointer = Strsave(DEFAULT_YES); - break; + if (*pointer) + free(*pointer); + *pointer = Strsave(DEFAULT_YES); + break; case FALSE: - if (*pointer != NULL) - free(*pointer); - *pointer = Strsave(DEFAULT_NO); - break; + if (*pointer) + free(*pointer); + *pointer = Strsave(DEFAULT_NO); + break; case -1: default: - return(SUB_ERROR); + return SUB_ERROR; } - return(SUB_NORMAL); + return SUB_NORMAL; } /* Function Name: GetFSVal @@ -560,23 +526,21 @@ char * prompt, ** pointer; * Returns: TRUE if successful. */ -static Bool -GetFSVal(name, mask, current, new) -char * name; -int mask, current, *new; +static Bool GetFSVal(char *name, int mask, int current, int *new) { - char temp_buf[BUFSIZ]; - sprintf(temp_buf, "Is this a %s filsystem", name); - switch (YesNoQuestion(temp_buf, ( (mask & current) == mask) )) { + char temp_buf[BUFSIZ]; + sprintf(temp_buf, "Is this a %s filsystem", name); + switch (YesNoQuestion(temp_buf, ((mask & current) == mask))) + { case TRUE: - *new |= mask; - break; + *new |= mask; + break; case FALSE: - break; /* zero by default. */ + break; /* zero by default. */ default: - return(FALSE); + return FALSE; } - return(TRUE); + return TRUE; } /* Function Name: GetFSTypes @@ -585,37 +549,35 @@ int mask, current, *new; * Returns: SUB_ERROR on ^C. */ -int -GetFSTypes(current, options) -char ** current; -int options; -{ - int c_value, new_val = 0; /* current value of filesys type (int). */ - char ret_value[BUFSIZ]; - - if (*current == NULL) - c_value = 0; - else - c_value = atoi(*current); - - if (GetFSVal("student", MR_FS_STUDENT, c_value, &new_val) == FALSE) - return(SUB_ERROR); - if (GetFSVal("faculty", MR_FS_FACULTY, c_value, &new_val) == FALSE) - return(SUB_ERROR); - if (GetFSVal("staff", MR_FS_STAFF, c_value, &new_val) == FALSE) - return(SUB_ERROR); - if (GetFSVal("miscellaneous", MR_FS_MISC, c_value, &new_val) == FALSE) - return(SUB_ERROR); - if (options) { - if (GetFSVal("Group Quotas", MR_FS_GROUPQUOTA, c_value, &new_val) == - FALSE) - return(SUB_ERROR); +int GetFSTypes(char **current, int options) +{ + int c_value, new_val = 0; /* current value of filesys type (int). */ + char ret_value[BUFSIZ]; + + if (!*current) + c_value = 0; + else + c_value = atoi(*current); + + if (GetFSVal("student", MR_FS_STUDENT, c_value, &new_val) == FALSE) + return SUB_ERROR; + if (GetFSVal("faculty", MR_FS_FACULTY, c_value, &new_val) == FALSE) + return SUB_ERROR; + if (GetFSVal("staff", MR_FS_STAFF, c_value, &new_val) == FALSE) + return SUB_ERROR; + if (GetFSVal("miscellaneous", MR_FS_MISC, c_value, &new_val) == FALSE) + return SUB_ERROR; + if (options) + { + if (GetFSVal("Group Quotas", MR_FS_GROUPQUOTA, c_value, &new_val) == + FALSE) + return SUB_ERROR; } - FreeAndClear(current, TRUE); - sprintf(ret_value, "%d", new_val); - *current = Strsave(ret_value); - return(SUB_NORMAL); + FreeAndClear(current, TRUE); + sprintf(ret_value, "%d", new_val); + *current = Strsave(ret_value); + return SUB_NORMAL; } /* Function Name: Strsave @@ -624,31 +586,28 @@ int options; * Returns: The malloced string, now safely saved, or NULL. */ -char * -Strsave(str) -char *str; +char *Strsave(char *str) { - register char *newstr = malloc((unsigned) strlen(str) + 1); + register char *newstr = malloc(strlen(str) + 1); - if (newstr == (char *) NULL) - return ((char *) NULL); - else - return (strcpy(newstr, str)); + if (!newstr) + return NULL; + else + return strcpy(newstr, str); } /* atot: convert ASCII integer unix time into human readable date string */ -char *atot(itime) -char *itime; +char *atot(char *itime) { - time_t time; - char *ct, *ctime(); + time_t time; + char *ct, *ctime(); - time = (time_t)atoi(itime); - ct = ctime(&time); - ct[24] = 0; - return(&ct[4]); + time = (time_t) atoi(itime); + ct = ctime(&time); + ct[24] = 0; + return &ct[4]; } @@ -659,44 +618,36 @@ char *itime; * Returns: MR_CONT */ -/* ARGSUSED */ -int -Print(argc, argv, callback) -int argc; -char **argv, *callback; +int Print(int argc, char **argv, char *callback) { - char buf[BUFSIZ]; - register int i; + char buf[BUFSIZ]; + register int i; - found_some = TRUE; - (void) strcpy(buf,argv[0]); /* no newline 'cause Put_message adds one */ - for (i = 1; i < argc; i++) - (void) sprintf(buf,"%s %s",buf,argv[i]); - (void) Put_message(buf); + found_some = TRUE; + strcpy(buf, argv[0]); /* no newline 'cause Put_message adds one */ + for (i = 1; i < argc; i++) + sprintf(buf, "%s %s", buf, argv[i]); + Put_message(buf); - return (MR_CONT); + return MR_CONT; } /* Function Name: PrintByType * Description: This function prints all members of the type specified * by the callback arg, unless the callback is NULL, in which * case it prints all members. - * Arguments: argc, argc - normal arguments for mr_callback function. + * Arguments: argc, argc - normal arguments for mr_callback function. * callback - either a type of member or NULL. * Returns: MR_CONT or MR_QUIT. */ -/*ARGSUSED*/ -int -PrintByType(argc, argv, callback) -int argc; -char **argv, *callback; +int PrintByType(int argc, char **argv, char *callback) { - if (callback == NULL) - return( Print(argc, argv, callback) ); - if (strcmp(argv[0], callback) == 0) - return( Print(argc, argv, callback) ); - return(MR_CONT); + if (!callback) + return Print(argc, argv, callback); + if (!strcmp(argv[0], callback)) + return Print(argc, argv, callback); + return MR_CONT; } /* Function Name: PrintHelp @@ -706,16 +657,14 @@ char **argv, *callback; * Returns: DM_NORMAL. */ -int -PrintHelp(message) -char ** message; +int PrintHelp(char **message) { - register int i; + register int i; - for (i = 0; i < CountArgs(message); i++) - Put_message(message[i]); + for (i = 0; i < CountArgs(message); i++) + Put_message(message[i]); - return(DM_NORMAL); + return DM_NORMAL; } /* Function Name: Loop @@ -726,15 +675,13 @@ char ** message; * Returns: none. */ -void -Loop(elem, func) -FVoid func; -struct qelem * elem; +void Loop(struct qelem *elem, FVoid func) { - while (elem != NULL) { - char ** info = (char **) elem->q_data; - (*func) (info); - elem = elem->q_forw; + while (elem) + { + char **info = (char **) elem->q_data; + (*func) (info); + elem = elem->q_forw; } } @@ -765,38 +712,37 @@ struct qelem * elem; * "Delete the list" */ -void -QueryLoop(elem, print_func, op_func, query_string) -struct qelem *elem; -FVoid op_func; -FCharStar print_func; -char * query_string; -{ - Bool one_item; - char temp_buf[BUFSIZ], *name; - - elem = QueueTop(elem); - one_item = (QueueCount(elem) == 1); - while (elem != NULL) { - char **info = (char **) elem->q_data; - - if (one_item) - (*op_func) (info, one_item); - else { - name = (*print_func) (info); /* call print function. */ - sprintf(temp_buf,"%s %s (y/n/q)", query_string, name); - switch(YesNoQuitQuestion(temp_buf, FALSE)) { +void QueryLoop(struct qelem *elem, FCharStar print_func, + FVoid op_func, char *query_string) +{ + Bool one_item; + char temp_buf[BUFSIZ], *name; + + elem = QueueTop(elem); + one_item = (QueueCount(elem) == 1); + while (elem) + { + char **info = (char **) elem->q_data; + + if (one_item) + (*op_func) (info, one_item); + else + { + name = (*print_func) (info); /* call print function. */ + sprintf(temp_buf, "%s %s (y/n/q)", query_string, name); + switch (YesNoQuitQuestion(temp_buf, FALSE)) + { case TRUE: - (*op_func) (info, one_item); - break; + (*op_func) (info, one_item); + break; case FALSE: - break; + break; default: /* Quit. */ - Put_message("Aborting..."); - return; + Put_message("Aborting..."); + return; } } - elem = elem->q_forw; + elem = elem->q_forw; } } @@ -806,11 +752,9 @@ char * query_string; * Returns: none. */ -char * -NullPrint(info) -char ** info; +char *NullPrint(char **info) { - return(info[NAME]); + return info[NAME]; } @@ -820,45 +764,49 @@ char ** info; * Returns: argv of values */ -struct qelem * -GetTypeValues(tname) -char *tname; +struct qelem *GetTypeValues(char *tname) { - int stat; - char *argv[3], *p, **pp, *strsave(); - struct qelem *elem, *oelem; - static struct qelem *cache = NULL; - struct cache_elem { char *cache_name; struct qelem *cache_data; } *ce; + int stat; + char *argv[3], *p, **pp, *strsave(); + struct qelem *elem, *oelem; + static struct qelem *cache = NULL; + struct cache_elem { + char *cache_name; + struct qelem *cache_data; + } *ce; - for (elem = cache; elem; elem = elem->q_forw) { - ce = (struct cache_elem *)elem->q_data; - if (!strcmp(ce->cache_name, tname)) - return(ce->cache_data); + for (elem = cache; elem; elem = elem->q_forw) + { + ce = (struct cache_elem *) elem->q_data; + if (!strcmp(ce->cache_name, tname)) + return ce->cache_data; } - argv[0] = tname; - argv[1] = "TYPE"; - argv[2] = "*"; - elem = NULL; - if (stat = do_mr_query("get_alias", 3, argv, StoreInfo, (char *)&elem)) { - com_err(program_name, stat, " in GetTypeValues"); - return(NULL); + argv[0] = tname; + argv[1] = "TYPE"; + argv[2] = "*"; + elem = NULL; + if ((stat = do_mr_query("get_alias", 3, argv, StoreInfo, (char *)&elem))) + { + com_err(program_name, stat, " in GetTypeValues"); + return NULL; } - oelem = elem; - for (elem = QueueTop(elem); elem; elem = elem->q_forw) { - pp = (char **) elem->q_data; - p = strsave(pp[2]); - FreeInfo(pp); - elem->q_data = p; + oelem = elem; + for (elem = QueueTop(elem); elem; elem = elem->q_forw) + { + pp = (char **) elem->q_data; + p = strsave(pp[2]); + FreeInfo(pp); + elem->q_data = p; } - elem = (struct qelem *) malloc(sizeof(struct qelem)); - ce = (struct cache_elem *) malloc(sizeof(struct cache_elem)); - ce->cache_name = strsave(tname); - ce->cache_data = QueueTop(oelem); - elem->q_data = (char *)ce; - AddQueue(elem, cache); - cache = QueueTop(elem); - return(ce->cache_data); + elem = malloc(sizeof(struct qelem)); + ce = malloc(sizeof(struct cache_elem)); + ce->cache_name = strsave(tname); + ce->cache_data = QueueTop(oelem); + elem->q_data = (char *) ce; + AddQueue(elem, cache); + cache = QueueTop(elem); + return ce->cache_data; } @@ -868,72 +816,77 @@ char *tname; * Returns: SUB_ERROR if ^C, SUB_NORMAL otherwise */ -int GetTypeFromUser(prompt, tname, pointer) -char *prompt; -char *tname; -char **pointer; +int GetTypeFromUser(char *prompt, char *tname, char **pointer) { - char def[BUFSIZ], buffer[BUFSIZ], *p, *argv[3]; - struct qelem *elem; - int stat; + char def[BUFSIZ], buffer[BUFSIZ], *p, *argv[3]; + struct qelem *elem; + int stat; - strcpy(def, *pointer); - strcpy(buffer, prompt); - strcat(buffer, " ("); - for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) { - strcat(buffer, elem->q_data); - if (elem->q_forw) - strcat(buffer, ", "); + strcpy(def, *pointer); + strcpy(buffer, prompt); + strcat(buffer, " ("); + for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) + { + strcat(buffer, elem->q_data); + if (elem->q_forw) + strcat(buffer, ", "); } - strcat(buffer, ")"); - if (strlen(buffer) > 64) - sprintf(buffer, "%s (? for help)", prompt); - if (GetValueFromUser(buffer, pointer) == SUB_ERROR) - return(SUB_ERROR); - if (**pointer == '?') { - sprintf(buffer, "Type %s is one of:", tname); - Put_message(buffer); - for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) { - Put_message(elem->q_data); - } - *pointer = strsave(def); - return(GetTypeFromUser(prompt, tname, pointer)); + strcat(buffer, ")"); + if (strlen(buffer) > 64) + sprintf(buffer, "%s (? for help)", prompt); + if (GetValueFromUser(buffer, pointer) == SUB_ERROR) + return SUB_ERROR; + if (**pointer == '?') + { + sprintf(buffer, "Type %s is one of:", tname); + Put_message(buffer); + for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) + Put_message(elem->q_data); + *pointer = strsave(def); + return GetTypeFromUser(prompt, tname, pointer); } - for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) { - if (!strcasecmp(elem->q_data, *pointer)) { - strcpy(*pointer, elem->q_data); - return(SUB_NORMAL); + for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) + { + if (!strcasecmp(elem->q_data, *pointer)) + { + strcpy(*pointer, elem->q_data); + return SUB_NORMAL; } } - sprintf(buffer, "\"%s\" is not a legal value for %s. Use one of:", - *pointer, tname); - Put_message(buffer); - for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) { - Put_message(elem->q_data); - } - sprintf(buffer, "Are you sure you want \"%s\" to be a legal %s", - *pointer, tname); - if (YesNoQuestion("Do you want this to be a new legal value", 0) == TRUE && - YesNoQuestion(buffer, 0) == TRUE) { - argv[0] = tname; - argv[1] = "TYPE"; - argv[2] = *pointer; - /* don't uppercase access flags. Do uppercase everything else */ - if (strncmp(tname, "fs_access", 9)) + sprintf(buffer, "\"%s\" is not a legal value for %s. Use one of:", + *pointer, tname); + Put_message(buffer); + for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) + Put_message(elem->q_data); + sprintf(buffer, "Are you sure you want \"%s\" to be a legal %s", + *pointer, tname); + if (YesNoQuestion("Do you want this to be a new legal value", 0) == TRUE && + YesNoQuestion(buffer, 0) == TRUE) + { + argv[0] = tname; + argv[1] = "TYPE"; + argv[2] = *pointer; + /* don't uppercase access flags. Do uppercase everything else */ + if (strncmp(tname, "fs_access", 9)) + { for (p = argv[2]; *p; p++) - if (islower(*p)) - *p = toupper(*p); - if (stat = do_mr_query("add_alias", 3, argv, Scream, NULL)) { - com_err(program_name, stat, " in add_alias"); - } else { - elem = (struct qelem *) malloc(sizeof(struct qelem)); - elem->q_data = strsave(*pointer); - AddQueue(elem, GetTypeValues(tname)); - Put_message("Done."); + { + if (islower(*p)) + *p = toupper(*p); + } + } + if ((stat = do_mr_query("add_alias", 3, argv, Scream, NULL))) + com_err(program_name, stat, " in add_alias"); + else + { + elem = malloc(sizeof(struct qelem)); + elem->q_data = strsave(*pointer); + AddQueue(elem, GetTypeValues(tname)); + Put_message("Done."); } } - *pointer = strsave(def); - return(GetTypeFromUser(prompt, tname, pointer)); + *pointer = strsave(def); + return GetTypeFromUser(prompt, tname, pointer); } @@ -944,54 +897,50 @@ char **pointer; * Returns: SUB_ERROR if ^C, SUB_NORMAL otherwise */ -int GetAddressFromUser(prompt, pointer) -char *prompt; -char **pointer; -{ - char *value, buf[256]; - struct in_addr addr; - int ret; - - addr.s_addr = htonl(atoi(*pointer)); - value = strsave(inet_ntoa(addr)); - ret = GetValueFromUser(prompt, &value); - if (ret == SUB_ERROR) return(SUB_ERROR); - addr.s_addr = inet_addr(value); - free(pointer); - sprintf(buf, "%d", ntohl(addr.s_addr)); - *pointer = strsave(buf); - return(SUB_NORMAL); -} - - -do_mr_query(name, argc, argv, proc, hint) -char *name; -int argc; -char **argv; -int (*proc)(); -char *hint; -{ - int status; - extern char *whoami, *moira_server; - - refresh_screen(); - status = mr_query(name, argc, argv, proc, hint); - if (status != MR_ABORTED && status != MR_NOT_CONNECTED) - return(status); - status = mr_connect(moira_server); - if (status) { - com_err(whoami, status, " while re-connecting to server %s", - moira_server); - return(MR_ABORTED); +int GetAddressFromUser(char *prompt, char **pointer) +{ + char *value, buf[256]; + struct in_addr addr; + int ret; + + addr.s_addr = htonl(atoi(*pointer)); + value = strsave(inet_ntoa(addr)); + ret = GetValueFromUser(prompt, &value); + if (ret == SUB_ERROR) + return SUB_ERROR; + addr.s_addr = inet_addr(value); + free(pointer); + sprintf(buf, "%d", ntohl(addr.s_addr)); + *pointer = strsave(buf); + return SUB_NORMAL; +} + + +int do_mr_query(char *name, int argc, char **argv, int (*proc)(), char *hint) +{ + int status; + extern char *whoami, *moira_server; + + refresh_screen(); + status = mr_query(name, argc, argv, proc, hint); + if (status != MR_ABORTED && status != MR_NOT_CONNECTED) + return status; + status = mr_connect(moira_server); + if (status) + { + com_err(whoami, status, " while re-connecting to server %s", + moira_server); + return MR_ABORTED; } - status = mr_auth(whoami); - if (status) { - com_err(whoami, status, " while re-authenticating to server %s", - moira_server); - mr_disconnect(); - return(MR_ABORTED); + status = mr_auth(whoami); + if (status) + { + com_err(whoami, status, " while re-authenticating to server %s", + moira_server); + mr_disconnect(); + return MR_ABORTED; } - status = mr_query(name, argc, argv, proc, hint); - return(status); + status = mr_query(name, argc, argv, proc, hint); + return status; } diff --git a/clients/moira/zephyr.c b/clients/moira/zephyr.c index b6a94ec8..10241a5e 100644 --- a/clients/moira/zephyr.c +++ b/clients/moira/zephyr.c @@ -3,7 +3,7 @@ * Zephyr ACL routines for the Moira client * * Copyright 1990 by the Massachusetts Institute of Technology. - * + * * For further information on copyright and distribution see the * file mit-copyright.h */ @@ -23,311 +23,308 @@ /* Set the default values for zephyr additions. */ -static char ** -SetDefaults(info, name) -char **info; -char *name; +static char **SetDefaults(char **info, char *name) { - info[ZA_CLASS] = strsave(name); - info[ZA_XMT_TYPE] = strsave("LIST"); - info[ZA_SUB_TYPE] = strsave("LIST"); - info[ZA_IWS_TYPE] = strsave("LIST"); - info[ZA_IUI_TYPE] = strsave("LIST"); - info[ZA_XMT_ID] = strsave("empty"); - info[ZA_SUB_ID] = strsave("empty"); - info[ZA_IWS_ID] = strsave("empty"); - info[ZA_IUI_ID] = strsave("empty"); - info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL; - info[ZA_END] = NULL; - return(info); + info[ZA_CLASS] = strsave(name); + info[ZA_XMT_TYPE] = strsave("LIST"); + info[ZA_SUB_TYPE] = strsave("LIST"); + info[ZA_IWS_TYPE] = strsave("LIST"); + info[ZA_IUI_TYPE] = strsave("LIST"); + info[ZA_XMT_ID] = strsave("empty"); + info[ZA_SUB_ID] = strsave("empty"); + info[ZA_IWS_ID] = strsave("empty"); + info[ZA_IUI_ID] = strsave("empty"); + info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL; + info[ZA_END] = NULL; + return info; } /* Get info from database */ -static struct qelem * -GetZephyrInfo(name) -char *name; +static struct qelem *GetZephyrInfo(char *name) { - int stat; - struct qelem *elem = NULL; - - if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, - (char *)&elem)) != 0) { - com_err(program_name, stat, " in GetZephyrInfo"); - return(NULL); + int stat; + struct qelem *elem = NULL; + + if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, + (char *)&elem))) + { + com_err(program_name, stat, " in GetZephyrInfo"); + return NULL; } - return(QueueTop(elem)); + return QueueTop(elem); } /* Print zephyr acl info */ -static void -PrintZephyrInfo(info) -char **info; +static void PrintZephyrInfo(char **info) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - if (!info) { - Put_message("PrintZephyrInfo called with null info!"); - return; + if (!info) + { + Put_message("PrintZephyrInfo called with null info!"); + return; } - sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]); - Put_message(buf); - if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) { - free(info[ZA_XMT_ID]); - info[ZA_XMT_ID] = strsave("*.*@*"); + sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]); + Put_message(buf); + if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) + { + free(info[ZA_XMT_ID]); + info[ZA_XMT_ID] = strsave("*.*@*"); } - sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE], - strcasecmp(info[ZA_XMT_TYPE], "NONE")?info[ZA_XMT_ID]:""); - Put_message(buf); - if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) { - free(info[ZA_SUB_ID]); - info[ZA_SUB_ID] = strsave("*.*@*"); + sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE], + strcasecmp(info[ZA_XMT_TYPE], "NONE") ? info[ZA_XMT_ID] : ""); + Put_message(buf); + if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) + { + free(info[ZA_SUB_ID]); + info[ZA_SUB_ID] = strsave("*.*@*"); } - sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE], - strcasecmp(info[ZA_SUB_TYPE], "NONE")?info[ZA_SUB_ID]:""); - Put_message(buf); - if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) { - free(info[ZA_IWS_ID]); - info[ZA_IWS_ID] = strsave("*.*@*"); + sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE], + strcasecmp(info[ZA_SUB_TYPE], "NONE") ? info[ZA_SUB_ID] : ""); + Put_message(buf); + if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) + { + free(info[ZA_IWS_ID]); + info[ZA_IWS_ID] = strsave("*.*@*"); } - sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE], - strcasecmp(info[ZA_IWS_TYPE], "NONE")?info[ZA_IWS_ID]:""); - Put_message(buf); - if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) { - free(info[ZA_IUI_ID]); - info[ZA_IUI_ID] = strsave("*.*@*"); + sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE], + strcasecmp(info[ZA_IWS_TYPE], "NONE") ? info[ZA_IWS_ID] : ""); + Put_message(buf); + if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) + { + free(info[ZA_IUI_ID]); + info[ZA_IUI_ID] = strsave("*.*@*"); } - sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE], - strcasecmp(info[ZA_IUI_TYPE], "NONE")?info[ZA_IUI_ID]:""); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], - info[ZA_MODWITH]); - Put_message(buf); + sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE], + strcasecmp(info[ZA_IUI_TYPE], "NONE") ? info[ZA_IUI_ID] : ""); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]); + Put_message(buf); } /* Get info from user. Expects info to already be filled in with defaults */ -static char ** -AskZephyrInfo(info, rename) -char **info; -Bool rename; +static char **AskZephyrInfo(char **info, Bool rename) { - char buf[BUFSIZ], *newname; - - Put_message(""); - sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]); - Put_message(buf); - Put_message(""); - - if (rename) { - while (1) { - newname = Strsave(info[ZA_CLASS]); - if (GetValueFromUser("The new name for this class", &newname) == - SUB_ERROR) - return(NULL); - if (ValidName(newname)) - break; - } + char buf[BUFSIZ], *newname; + + Put_message(""); + sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]); + Put_message(buf); + Put_message(""); + + if (rename) + { + while (1) + { + newname = Strsave(info[ZA_CLASS]); + if (GetValueFromUser("The new name for this class", &newname) == + SUB_ERROR) + return NULL; + if (ValidName(newname)) + break; + } } - if (GetTypeFromUser("What kind of transmit restriction", "ace_type", - &info[ZA_XMT_TYPE]) == SUB_ERROR) - return(NULL); - if (strcasecmp(info[ZA_XMT_TYPE], "NONE") != 0) { - if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) { - free(info[ZA_XMT_ID]); - info[ZA_XMT_ID] = strsave("*.*@*"); + if (GetTypeFromUser("What kind of transmit restriction", "ace_type", + &info[ZA_XMT_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[ZA_XMT_TYPE], "NONE")) + { + if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) + { + free(info[ZA_XMT_ID]); + info[ZA_XMT_ID] = strsave("*.*@*"); } - sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]); - if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR) - return(NULL); - if (!strcmp(info[ZA_XMT_ID], "*.*@*")) { - free(info[ZA_XMT_ID]); - info[ZA_XMT_ID] = strsave("WILDCARD"); + sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]); + if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR) + return NULL; + if (!strcmp(info[ZA_XMT_ID], "*.*@*")) + { + free(info[ZA_XMT_ID]); + info[ZA_XMT_ID] = strsave("WILDCARD"); } } - if (GetTypeFromUser("What kind of subscription restriction", "ace_type", - &info[ZA_SUB_TYPE]) == SUB_ERROR) - return(NULL); - if (strcasecmp(info[ZA_SUB_TYPE], "NONE") != 0) { - if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) { - free(info[ZA_SUB_ID]); - info[ZA_SUB_ID] = strsave("*.*@*"); + if (GetTypeFromUser("What kind of subscription restriction", "ace_type", + &info[ZA_SUB_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[ZA_SUB_TYPE], "NONE")) + { + if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) + { + free(info[ZA_SUB_ID]); + info[ZA_SUB_ID] = strsave("*.*@*"); } - sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]); - if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR) - return(NULL); - if (!strcmp(info[ZA_SUB_ID], "*.*@*")) { - free(info[ZA_SUB_ID]); - info[ZA_SUB_ID] = strsave("WILDCARD"); + sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]); + if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR) + return NULL; + if (!strcmp(info[ZA_SUB_ID], "*.*@*")) + { + free(info[ZA_SUB_ID]); + info[ZA_SUB_ID] = strsave("WILDCARD"); } } - if (GetTypeFromUser("What kind of wildcard instance restriction", - "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR) - return(NULL); - if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0) { - if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) { - free(info[ZA_IWS_ID]); - info[ZA_IWS_ID] = strsave("*.*@*"); + if (GetTypeFromUser("What kind of wildcard instance restriction", + "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0) + { + if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) + { + free(info[ZA_IWS_ID]); + info[ZA_IWS_ID] = strsave("*.*@*"); } - sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]); - if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR) - return(NULL); - if (!strcmp(info[ZA_IWS_ID], "*.*@*")) { - free(info[ZA_IWS_ID]); - info[ZA_IWS_ID] = strsave("WILDCARD"); + sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]); + if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR) + return NULL; + if (!strcmp(info[ZA_IWS_ID], "*.*@*")) + { + free(info[ZA_IWS_ID]); + info[ZA_IWS_ID] = strsave("WILDCARD"); } } - if (GetTypeFromUser("What kind of instance identity restriction", - "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR) - return(NULL); - if (strcasecmp(info[ZA_IUI_TYPE], "NONE") != 0) { - if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) { - free(info[ZA_IUI_ID]); - info[ZA_IUI_ID] = strsave("*.*@*"); + if (GetTypeFromUser("What kind of instance identity restriction", + "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR) + return NULL; + if (strcasecmp(info[ZA_IUI_TYPE], "NONE")) + { + if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) + { + free(info[ZA_IUI_ID]); + info[ZA_IUI_ID] = strsave("*.*@*"); } - sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]); - if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR) - return(NULL); - if (!strcmp(info[ZA_IUI_ID], "*.*@*")) { - free(info[ZA_IUI_ID]); - info[ZA_IUI_ID] = strsave("WILDCARD"); + sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]); + if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR) + return NULL; + if (!strcmp(info[ZA_IUI_ID], "*.*@*")) + { + free(info[ZA_IUI_ID]); + info[ZA_IUI_ID] = strsave("WILDCARD"); } } - FreeAndClear(&info[ZA_MODTIME], TRUE); - FreeAndClear(&info[ZA_MODBY], TRUE); - FreeAndClear(&info[ZA_MODWITH], TRUE); + FreeAndClear(&info[ZA_MODTIME], TRUE); + FreeAndClear(&info[ZA_MODBY], TRUE); + FreeAndClear(&info[ZA_MODWITH], TRUE); - if (rename) - SlipInNewName(info, newname); - return(info); + if (rename) + SlipInNewName(info, newname); + return info; } /* Menu entry for get zephyr */ -int -GetZephyr(argc, argv) -int argc; -char **argv; +int GetZephyr(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetZephyrInfo(argv[1]); - Loop(top, (void *) PrintZephyrInfo); - FreeQueue(top); - return (DM_NORMAL); + top = GetZephyrInfo(argv[1]); + Loop(top, (void *) PrintZephyrInfo); + FreeQueue(top); + return DM_NORMAL; } /* Does the real work of a deletion */ -void -RealDeleteZephyr(info, one_item) -char **info; -Bool one_item; +void RealDeleteZephyr(char **info, Bool one_item) { - int stat; + int stat; - if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS], - Scream, NULL)) != 0) - com_err(program_name, stat, " zephyr class restriction not deleted."); - else - Put_message("Zephyr class restriction deleted."); + if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS], + Scream, NULL))) + com_err(program_name, stat, " zephyr class restriction not deleted."); + else + Put_message("Zephyr class restriction deleted."); } /* Delete a zephyr class given it's name */ -int -DeleteZephyr(argc, argv) -int argc; -char **argv; +int DeleteZephyr(int argc, char **argv) { - struct qelem *elem = GetZephyrInfo(argv[1]); - QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr, - "Delete Zephyr class restriction for class "); - FreeQueue(elem); - return (DM_NORMAL); + struct qelem *elem = GetZephyrInfo(argv[1]); + QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr, + "Delete Zephyr class restriction for class "); + FreeQueue(elem); + return DM_NORMAL; } /* Add a new zephyr class */ -int -AddZephyr(argc, argv) -char **argv; -int argc; +int AddZephyr(int argc, char **argv) { - char *info[MAX_ARGS_SIZE], **args; - int stat; - - if ( !ValidName(argv[1]) ) - return(DM_NORMAL); - - if ((stat = do_mr_query("get_zephyr_class", 1, argv + 1, - NullFunc, NULL)) == 0) { - Put_message ("A Zephyr class by that name already exists."); - return(DM_NORMAL); - } else if (stat != MR_NO_MATCH) { - com_err(program_name, stat, " in AddZehpyr"); - return(DM_NORMAL); - } - - args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE); - if (args == NULL) { - Put_message("Aborted."); - return(DM_NORMAL); + char *info[MAX_ARGS_SIZE], **args; + int stat; + + if (!ValidName(argv[1])) + return DM_NORMAL; + + if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, + NullFunc, NULL))) + { + Put_message ("A Zephyr class by that name already exists."); + return DM_NORMAL; + } + else if (stat != MR_NO_MATCH) + { + com_err(program_name, stat, " in AddZehpyr"); + return DM_NORMAL; + } + + args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE); + if (!args) + { + Put_message("Aborted."); + return DM_NORMAL; } - if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args, - NullFunc, NULL)) != 0) - com_err(program_name, stat, " in AddZephyr"); + if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args, + NullFunc, NULL))) + com_err(program_name, stat, " in AddZephyr"); - FreeInfo(info); - return (DM_NORMAL); + FreeInfo(info); + return DM_NORMAL; } /* Does the work of an update */ -static void -RealUpdateZephyr(info, junk) -char **info; -Bool junk; +static void RealUpdateZephyr(char **info, Bool junk) { - int stat; - char **args; - - if ((args = AskZephyrInfo(info, TRUE)) == NULL) { - Put_message("Aborted."); - return; + int stat; + char **args; + + if (!(args = AskZephyrInfo(info, TRUE))) + { + Put_message("Aborted."); + return; } - if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args, - Scream, (char *) NULL)) != MR_SUCCESS) { - com_err(program_name, stat, " in UpdateZephyr."); - Put_message("Zephyr class ** NOT ** Updated."); + if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args, + Scream, NULL))) + { + com_err(program_name, stat, " in UpdateZephyr."); + Put_message("Zephyr class ** NOT ** Updated."); } - else - Put_message("Zephyr class successfully updated."); + else + Put_message("Zephyr class successfully updated."); } /* Change zephyr info */ -int -ChngZephyr(argc, argv) -int argc; -char **argv; +int ChngZephyr(int argc, char **argv) { - struct qelem *top; + struct qelem *top; - top = GetZephyrInfo(argv[1]); - QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class"); + top = GetZephyrInfo(argv[1]); + QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class"); - FreeQueue(top); - return(DM_NORMAL); + FreeQueue(top); + return DM_NORMAL; } diff --git a/clients/mrcheck/mrcheck.c b/clients/mrcheck/mrcheck.c index f1e45950..d9019727 100644 --- a/clients/mrcheck/mrcheck.c +++ b/clients/mrcheck/mrcheck.c @@ -1,8 +1,8 @@ /* * Verify that all MOIRA updates are successful * - * Copyright 1988, 1991 by the Massachusetts Institute of Technology. - * For copying and distribution information, see the file "mit-copyright.h". + * Copyright 1988, 1991 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file "mit-copyright.h". * * $Header$ * $Author$ @@ -17,35 +17,33 @@ static char *rcsid_chsh_c = "$Header$"; #include #include "mit-copyright.h" #include +#include #include - -char *malloc(); +#include static int count = 0; static char *whoami; static struct timeval now; - struct service { - char name[17]; - char update_int[10]; + char name[17]; + char update_int[10]; }; -/* turn an ascii string containing the number of seconds sinc the epoch +/* turn an ascii string containing the number of seconds since the epoch * into an ascii string containing the corresponding time & date */ -char *atot(itime) -char *itime; +char *atot(char *itime) { - time_t time; - char *ct, *ctime(); + time_t time; + char *ct; - time = atoi(itime); - ct = ctime(&time); - ct[24] = 0; - return(&ct[4]); + time = atoi(itime); + ct = ctime(&time); + ct[24] = 0; + return &ct[4]; } @@ -53,203 +51,195 @@ char *itime; * interval for later use. */ -process_server(argc, argv, sq) -int argc; -char **argv; -struct save_queue *sq; +int process_server(int argc, char **argv, struct save_queue *sq) { - struct service *s; - - if (atoi(argv[SVC_ENABLE])) { - s = (struct service *)malloc(sizeof(struct service)); - strcpy(s->name, argv[SVC_SERVICE]); - strcpy(s->update_int, argv[SVC_INTERVAL]); - sq_save_data(sq, s); + struct service *s; + + if (atoi(argv[SVC_ENABLE])) + { + s = malloc(sizeof(struct service)); + strcpy(s->name, argv[SVC_SERVICE]); + strcpy(s->update_int, argv[SVC_INTERVAL]); + sq_save_data(sq, s); } - if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE])) { - disp_svc(argv, "Error needs to be reset\n"); - } else if (atoi(argv[SVC_HARDERROR]) || - (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK]))) { - disp_svc(argv, "Should this be enabled?\n"); - } else if (atoi(argv[SVC_ENABLE]) && - 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK]) - < now.tv_sec) { - disp_svc(argv, "Service has not been updated\n"); - } - return(MR_CONT); + if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE])) + disp_svc(argv, "Error needs to be reset\n"); + else if (atoi(argv[SVC_HARDERROR]) || + (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK]))) + disp_svc(argv, "Should this be enabled?\n"); + else if (atoi(argv[SVC_ENABLE]) && + 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK]) + < now.tv_sec) + disp_svc(argv, "Service has not been updated\n"); + + return MR_CONT; } /* Format the information about a service. */ -disp_svc(argv, msg) -char **argv; -char *msg; +int disp_svc(char **argv, char *msg) { - char *tmp = strsave(atot(argv[SVC_DFGEN])); - - printf("Service %s Interval %s %s/%s/%s %s\n", - argv[SVC_SERVICE], argv[SVC_INTERVAL], - atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", - atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", - atoi(argv[SVC_HARDERROR]) ? "Error" : "NoError", - atoi(argv[SVC_HARDERROR]) ? argv[SVC_ERRMSG] : ""); - printf(" Generated %s; Last checked %s\n", tmp, atot(argv[SVC_DFCHECK])); - printf(" Last modified by %s at %s with %s\n", - argv[SVC_MODBY], argv[SVC_MODTIME], argv[SVC_MODWITH]); - printf(" * %s\n", msg); - count++; - free(tmp); + char *tmp = strsave(atot(argv[SVC_DFGEN])); + + printf("Service %s Interval %s %s/%s/%s %s\n", + argv[SVC_SERVICE], argv[SVC_INTERVAL], + atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", + atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", + atoi(argv[SVC_HARDERROR]) ? "Error" : "NoError", + atoi(argv[SVC_HARDERROR]) ? argv[SVC_ERRMSG] : ""); + printf(" Generated %s; Last checked %s\n", tmp, atot(argv[SVC_DFCHECK])); + printf(" Last modified by %s at %s with %s\n", + argv[SVC_MODBY], argv[SVC_MODTIME], argv[SVC_MODWITH]); + printf(" * %s\n", msg); + count++; + free(tmp); } -/* Decide if the host has an error or not. - */ +/* Decide if the host has an error or not. */ -process_host(argc, argv, sq) -int argc; -char **argv; -struct save_queue *sq; +int process_host(int argc, char **argv, struct save_queue *sq) { - struct service *s = NULL; - struct save_queue *sq1; - char *update_int = NULL; + struct service *s = NULL; + struct save_queue *sq1; + char *update_int = NULL; - for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next) + for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next) + { if ((s = (struct service *)sq1->q_data) && !strcmp(s->name, argv[SH_SERVICE])) break; - if (s && !strcmp(s->name, argv[SH_SERVICE])) - update_int = s->update_int; - - if (atoi(argv[SH_HOSTERROR]) && atoi(argv[SH_ENABLE])) { - disp_sh(argv, "Error needs to be reset\n"); - } else if (atoi(argv[SH_HOSTERROR]) || - (!atoi(argv[SH_ENABLE]) && atoi(argv[SH_LASTTRY]))) { - disp_sh(argv, "Should this be enabled?\n"); - } else if (atoi(argv[SH_ENABLE]) && update_int && - 60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS]) - < now.tv_sec) { - disp_sh(argv, "Host has not been updated\n"); } - return(MR_CONT); + if (s && !strcmp(s->name, argv[SH_SERVICE])) + update_int = s->update_int; + + if (atoi(argv[SH_HOSTERROR]) && atoi(argv[SH_ENABLE])) + disp_sh(argv, "Error needs to be reset\n"); + else if (atoi(argv[SH_HOSTERROR]) || + (!atoi(argv[SH_ENABLE]) && atoi(argv[SH_LASTTRY]))) + disp_sh(argv, "Should this be enabled?\n"); + else if (atoi(argv[SH_ENABLE]) && update_int && + 60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS]) + < now.tv_sec) + disp_sh(argv, "Host has not been updated\n"); + + return MR_CONT; } /* Format the information about a host. */ -disp_sh(argv, msg) -char **argv; -char *msg; +int disp_sh(char **argv, char *msg) { - char *tmp = strsave(atot(argv[SH_LASTTRY])); - - printf("Host %s:%s %s/%s/%s/%s/%s %s\n", - argv[SH_SERVICE], argv[SH_MACHINE], - atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", - atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", - atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", - atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", - atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError", - atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : ""); - printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS])); - printf(" Last modified by %s at %s with %s\n", - argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]); - printf(" * %s\n", msg); - count++; - free(tmp); + char *tmp = strsave(atot(argv[SH_LASTTRY])); + + printf("Host %s:%s %s/%s/%s/%s/%s %s\n", + argv[SH_SERVICE], argv[SH_MACHINE], + atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", + atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", + atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", + atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", + atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError", + atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : ""); + printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS])); + printf(" Last modified by %s at %s with %s\n", + argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]); + printf(" * %s\n", msg); + count++; + free(tmp); } - -main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { - char *args[2], buf[BUFSIZ], *motd; - struct save_queue *sq; - int status; - int scream(); - int auth_required = 1; - - if ((whoami = strrchr(argv[0], '/')) == NULL) - whoami = argv[0]; - else - whoami++; - - if (argc == 2 && !strcmp(argv[1], "-noauth")) - auth_required = 0; - else if (argc > 1) - usage(); - - status = mr_connect(NULL); - if (status) { - (void) sprintf(buf, "\nConnection to the Moira server failed."); - goto punt; + char *args[2], buf[BUFSIZ], *motd; + struct save_queue *sq; + int status; + int scream(); + int auth_required = 1; + + if ((whoami = strrchr(argv[0], '/')) == NULL) + whoami = argv[0]; + else + whoami++; + + if (argc == 2 && !strcmp(argv[1], "-noauth")) + auth_required = 0; + else if (argc > 1) + usage(); + + status = mr_connect(NULL); + if (status) + { + sprintf(buf, "\nConnection to the Moira server failed."); + goto punt; } - status = mr_motd(&motd); - if (status) { - com_err(whoami, status, " unable to check server status"); - exit(2); + status = mr_motd(&motd); + if (status) + { + com_err(whoami, status, " unable to check server status"); + exit(2); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", - motd); - mr_disconnect(); - exit(2); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(2); } - status = mr_auth("mrcheck"); - if (status && auth_required) { - (void) sprintf(buf, "\nAuthorization failure -- run \"kinit\" \ -and try again"); - goto punt; + status = mr_auth("mrcheck"); + if (status && auth_required) + { + sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again"); + goto punt; } - gettimeofday(&now, 0); - sq = sq_create(); + gettimeofday(&now, 0); + sq = sq_create(); - /* Check services first */ - args[0] = "*"; - if ((status = mr_query("get_server_info", 1, args, - process_server, (char *)sq)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting servers"); + /* Check services first */ + args[0] = "*"; + if ((status = mr_query("get_server_info", 1, args, + process_server, (char *)sq)) && + status != MR_NO_MATCH) + com_err(whoami, status, " while getting servers"); - args[1] = "*"; - if ((status = mr_query("get_server_host_info", 2, args, - process_host, (char *)sq)) && - status != MR_NO_MATCH) - com_err(whoami, status, " while getting servers"); + args[1] = "*"; + if ((status = mr_query("get_server_host_info", 2, args, + process_host, (char *)sq)) && + status != MR_NO_MATCH) + com_err(whoami, status, " while getting servers"); - if (!count) - printf("Nothing has failed at this time\n"); - else - printf("%d thing%s ha%s failed at this time\n", count, - count == 1 ? "" : "s", count == 1 ? "s" : "ve"); + if (!count) + printf("Nothing has failed at this time\n"); + else + printf("%d thing%s ha%s failed at this time\n", count, + count == 1 ? "" : "s", count == 1 ? "s" : "ve"); - mr_disconnect(); - exit(0); + mr_disconnect(); + exit(0); punt: - com_err(whoami, status, buf); - mr_disconnect(); - exit(1); + com_err(whoami, status, buf); + mr_disconnect(); + exit(1); } -scream() +int scream(void) { - com_err(whoami, 0, - "Update to Moira returned a value -- programmer botch.\n"); - mr_disconnect(); - exit(1); + com_err(whoami, 0, + "Update to Moira returned a value -- programmer botch.\n"); + mr_disconnect(); + exit(1); } -usage() +int usage(void) { - fprintf(stderr, "Usage: %s [-noauth]\n", whoami); - exit(1); + fprintf(stderr, "Usage: %s [-noauth]\n", whoami); + exit(1); } diff --git a/clients/mrtest/mrtest.c b/clients/mrtest/mrtest.c index 6c2b2a74..f858ebd7 100644 --- a/clients/mrtest/mrtest.c +++ b/clients/mrtest/mrtest.c @@ -32,439 +32,433 @@ static char *rcsid_test_c = "$Header$"; int recursion = 0, interactive; extern int errno; extern int sending_version_no; -int count, quit=0, cancel=0; +int count, quit = 0, cancel = 0; char *whoami; -#ifdef POSIX sigjmp_buf jb; -#else -jmp_buf jb; -#endif #define MAXARGS 20 -#ifdef POSIX -void -#endif -discard_input(); +void discard_input(); char *mr_gets(); -main(argc, argv) - int argc; - char **argv; -{ - char cmdbuf[BUFSIZ]; -#ifdef POSIX - struct sigaction action; -#endif - - whoami = argv[0]; - interactive = (isatty(0) && isatty(1)); - - initialize_sms_error_table(); - initialize_krb_error_table(); +int main(int argc, char **argv) +{ + char cmdbuf[BUFSIZ]; + struct sigaction action; -#ifdef USE_READLINE - /* we don't want filename completion */ - rl_bind_key ('\t', rl_insert); -#endif + whoami = argv[0]; + interactive = (isatty(0) && isatty(1)); -#ifdef POSIX - action.sa_handler = discard_input; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaction(SIGINT, &action, NULL); - sigsetjmp(jb, 1); -#else - signal(SIGINT, discard_input); - setjmp(jb); + initialize_sms_error_table(); + initialize_krb_error_table(); + +#ifdef USE_READLINE + /* we don't want filename completion */ + rl_bind_key('\t', rl_insert); #endif - while(!quit) { - if(!mr_gets("moira: ",cmdbuf,BUFSIZ)) break; - execute_line(cmdbuf); - } - mr_disconnect(); - exit(0); + action.sa_handler = discard_input; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGINT, &action, NULL); + sigsetjmp(jb, 1); + + while (!quit) + { + if (!mr_gets("moira: ", cmdbuf, BUFSIZ)) + break; + execute_line(cmdbuf); + } + mr_disconnect(); + exit(0); } -#ifdef POSIX -void -#else -int -#endif -discard_input() +void discard_input(void) { putc('\n', stdout); /* if we're inside a script, we have to clean up file descriptors, so don't jump out yet */ - if(recursion) { - cancel=1; - } else { -#ifdef POSIX + if (recursion) + cancel = 1; + else siglongjmp(jb, 1); -#else - longjmp(jb, 1); -#endif - } } -char *mr_gets(prompt, buf, len) - char *prompt, *buf; - size_t len; +char *mr_gets(char *prompt, char *buf, size_t len) { char *in; #ifdef USE_READLINE - if(interactive) { - in=readline(prompt); - - if (!in) return NULL; - if (*in) { - add_history(in); + if (interactive) + { + in = readline(prompt); + + if (!in) + return NULL; + if (*in) + add_history(in); + strncpy(buf, in, len - 1); + buf[len] = 0; + free(in); + + return buf; } - strncpy(buf, in, len-1); - buf[len]=0; - free(in); - - return buf; - } #endif printf("%s", prompt); fflush(stdout); - in=fgets(buf, len, stdin); - if(!in) return in; - if(strchr(buf,'\n')) *(strchr(buf,'\n'))=0; + in = fgets(buf, len, stdin); + if (!in) + return in; + if (strchr(buf, '\n')) + *(strchr(buf, '\n')) = '\0'; return buf; } -execute_line(cmdbuf) - char *cmdbuf; +int execute_line(char *cmdbuf) { int argc; char *argv[MAXARGS]; - argc=parse(cmdbuf, argv); - if(argc==0) return; - if(!strcmp(argv[0],"noop")) + argc = parse(cmdbuf, argv); + if (argc == 0) + return; + if (!strcmp(argv[0], "noop")) test_noop(); - else if(!strcmp(argv[0],"connect") || !strcmp(argv[0],"c")) + else if (!strcmp(argv[0], "connect") || !strcmp(argv[0], "c")) test_connect(argc, argv); - else if(!strcmp(argv[0],"disconnect") || !strcmp(argv[0],"d")) + else if (!strcmp(argv[0], "disconnect") || !strcmp(argv[0], "d")) test_disconnect(); - else if(!strcmp(argv[0],"host")) + else if (!strcmp(argv[0], "host")) test_host(); - else if(!strcmp(argv[0],"new") || !strcmp(argv[0],"2")) + else if (!strcmp(argv[0], "new") || !strcmp(argv[0], "2")) test_new(); - else if(!strcmp(argv[0],"old") || !strcmp(argv[0],"1")) + else if (!strcmp(argv[0], "old") || !strcmp(argv[0], "1")) test_old(); - else if(!strcmp(argv[0],"motd")) + else if (!strcmp(argv[0], "motd")) test_motd(); - else if(!strcmp(argv[0],"query") || !strcmp(argv[0],"qy")) + else if (!strcmp(argv[0], "query") || !strcmp(argv[0], "qy")) test_query(argc, argv); - else if(!strcmp(argv[0],"auth") || !strcmp(argv[0],"a")) + else if (!strcmp(argv[0], "auth") || !strcmp(argv[0], "a")) test_auth(argc, argv); - else if(!strcmp(argv[0],"access")) + else if (!strcmp(argv[0], "access")) test_access(argc, argv); - else if(!strcmp(argv[0],"dcm")) + else if (!strcmp(argv[0], "dcm")) test_dcm(); - else if(!strcmp(argv[0],"script") || !strcmp(argv[0],"s")) + else if (!strcmp(argv[0], "script") || !strcmp(argv[0], "s")) test_script(argc, argv); - else if(!strcmp(argv[0],"list_requests") || - !strcmp(argv[0],"lr") || !strcmp(argv[0],"?")) + else if (!strcmp(argv[0], "list_requests") || + !strcmp(argv[0], "lr") || !strcmp(argv[0], "?")) test_list_requests(); - else if(!strcmp(argv[0],"quit") || !strcmp(argv[0],"Q")) - quit=1; - else fprintf(stderr, "moira: Unknown request \"%s\". Type \"?\" for a request list.\n", argv[0]); + else if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "Q")) + quit = 1; + else + { + fprintf(stderr, "moira: Unknown request \"%s\". " + "Type \"?\" for a request list.\n", argv[0]); + } } -int -parse(buf, argv) - char *buf, *argv[MAXARGS]; +int parse(char *buf, char *argv[MAXARGS]) { char *p; int argc, num; - - if(!*buf) return 0; - - for(p=buf, argc=0, argv[0]=buf; *p && *p!='\n'; p++) { - if(*p=='"') { - char *d=p++; - /* skip to close-quote, copying back over open-quote */ - while(*p!='"') { - if(!*p || *p=='\n') { - fprintf(stderr, "moira: Unbalanced quotes in command line\n"); - return 0; + + if (!*buf) + return 0; + + for (p = buf, argc = 0, argv[0] = buf; *p && *p != '\n'; p++) + { + if (*p == '"') + { + char *d = p++; + /* skip to close-quote, copying back over open-quote */ + while (*p != '"') + { + if (!*p || *p == '\n') + { + fprintf(stderr, + "moira: Unbalanced quotes in command line\n"); + return 0; + } + /* deal with \### or \\ */ + if (*p == '\\') + { + if (*++p != '"' && (*p < '0' || *p > '9') && (*p != '\\')) + { + fprintf(stderr, "moira: Bad use of \\\n"); + return 0; + } + else if (*p >= '0' && *p <= '9') + { + num = (*p - '0') * 64 + (*++p - '0') * 8 + (*++p - '0'); + *p = num; + } + } + *d++ = *p++; + } + if (p == d + 1) + { + *d = '\0'; + p++; + } + else + { + while (p >= d) + *p-- = ' '; + } } - if(*p=='\\') { - if(*++p!='"' && (*p<'0' || *p>'9') && (*p!='\\')) { - fprintf(stderr, "moira: Bad use of \\\n"); - return 0; - } else if (*p>='0' && *p<='9') { - num=(*p-'0')*64 + (*++p-'0')*8 + (*++p-'0'); - *p=num; - } + if (*p == ' ' || *p == '\t') + { + /* skip whitespace */ + for (*p++ = '\0'; *p == ' ' || *p == '\t'; p++) + ; + if (*p && *p != '\n') + argv[++argc] = p--; } - *d++= *p++; - } - if(p==d+1) {*d='\0'; p++;} - else {while(p>=d) *p--=' ';} } - if(*p==' ' || *p=='\t') { - /* skip whitespace */ - for(*p++='\0'; *p==' ' || *p=='\t'; p++); - if(*p && *p!='\n') argv[++argc]=p--; - } - } - if(*p=='\n') *p='\0'; - return argc+1; + if (*p == '\n') + *p = '\0'; + return argc + 1; } -test_noop() +int test_noop(void) { - int status = mr_noop(); - if (status) com_err("moira (noop)", status, ""); + int status = mr_noop(); + if (status) + com_err("moira (noop)", status, ""); } -test_new() +int test_new(void) { - sending_version_no = MR_VERSION_2; + sending_version_no = MR_VERSION_2; } -test_old() +int test_old(void) { - sending_version_no = MR_VERSION_1; + sending_version_no = MR_VERSION_1; } -test_connect(argc, argv) -int argc; -char *argv[]; +int test_connect(int argc, char *argv[]) { - char *server = ""; - int status; - - if (argc > 1) { - server = argv[1]; - } - status = mr_connect(server); - if (status) com_err("moira (connect)", status, ""); + char *server = ""; + int status; + + if (argc > 1) + server = argv[1]; + status = mr_connect(server); + if (status) + com_err("moira (connect)", status, ""); } -test_disconnect() +int test_disconnect(void) { - int status = mr_disconnect(); - if (status) com_err("moira (disconnect)", status, ""); + int status = mr_disconnect(); + if (status) + com_err("moira (disconnect)", status, ""); } -test_host() +int test_host(void) { - char host[BUFSIZ]; - int status; + char host[BUFSIZ]; + int status; - memset(host, 0, sizeof(host)); + memset(host, 0, sizeof(host)); - if (status = mr_host(host, sizeof(host) - 1)) - com_err("moira (host)", status, ""); - else - printf("You are connected to host %s\n", host); + if ((status = mr_host(host, sizeof(host) - 1))) + com_err("moira (host)", status, ""); + else + printf("You are connected to host %s\n", host); } -test_auth(argc, argv) -int argc; -char *argv[]; +int test_auth(int argc, char *argv[]) { - int status; + int status; - status = mr_auth("mrtest"); - if (status) com_err("moira (auth)", status, ""); + status = mr_auth("mrtest"); + if (status) + com_err("moira (auth)", status, ""); } -test_script(argc, argv) -int argc; -char *argv[]; +int test_script(int argc, char *argv[]) { - FILE *inp; - char input[BUFSIZ], *cp; - int status, oldstdout, oldstderr; - - if (recursion > 8) { - com_err("moira (script)", 0, "too many levels deep in script files\n"); - return; + FILE *inp; + char input[BUFSIZ], *cp; + int status, oldstdout, oldstderr; + + if (recursion > 8) + { + com_err("moira (script)", 0, "too many levels deep in script files\n"); + return; } - if (argc < 2) { - com_err("moira (script)", 0, "Usage: script input_file [ output_file ]"); - return; + if (argc < 2) + { + com_err("moira (script)", 0, "Usage: script input_file [ output_file ]"); + return; } - inp = fopen(argv[1], "r"); - if (inp == NULL) { - sprintf(input, "Cannot open input file %s", argv[1]); - com_err("moira (script)", 0, input); - return; + inp = fopen(argv[1], "r"); + if (!inp) + { + sprintf(input, "Cannot open input file %s", argv[1]); + com_err("moira (script)", 0, input); + return; } - if (argc == 3) { - printf("Redirecting output to %s\n", argv[2]); - fflush(stdout); - oldstdout = dup(1); - close(1); - status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664); - if (status != 1) { - close(status); - dup2(oldstdout, 1); - argc = 2; - sprintf(input, "Unable to redirect output to %s\n", argv[2]); - com_err("moira (script)", errno, input); - } else { - fflush(stderr); - oldstderr = dup(2); - close(2); - dup2(1, 2); + if (argc == 3) + { + printf("Redirecting output to %s\n", argv[2]); + fflush(stdout); + oldstdout = dup(1); + close(1); + status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664); + if (status != 1) + { + close(status); + dup2(oldstdout, 1); + argc = 2; + sprintf(input, "Unable to redirect output to %s\n", argv[2]); + com_err("moira (script)", errno, input); + } + else + { + fflush(stderr); + oldstderr = dup(2); + close(2); + dup2(1, 2); } } - recursion++; - - while(!cancel) { - if (fgets(input, BUFSIZ, inp) == NULL) - break; - if ((cp = strchr(input, '\n')) != (char *)NULL) - *cp = 0; - if (input[0] == 0) { - printf("\n"); - continue; + recursion++; + + while (!cancel) + { + if (!fgets(input, BUFSIZ, inp)) + break; + if ((cp = strchr(input, '\n'))) + *cp = '\0'; + if (input[0] == 0) + { + printf("\n"); + continue; } - if (input[0] == '%') { - for (cp = &input[1]; *cp && isspace(*cp); cp++); - printf("Comment: %s\n", cp); - continue; + if (input[0] == '%') + { + for (cp = &input[1]; *cp && isspace(*cp); cp++) + ; + printf("Comment: %s\n", cp); + continue; } - printf("Executing: %s\n", input); - execute_line(input); + printf("Executing: %s\n", input); + execute_line(input); } - recursion--; - if(!recursion) cancel=0; - - fclose(inp); - if (argc == 3) { - fflush(stdout); - close(1); - dup2(oldstdout, 1); - close(oldstdout); - fflush(stderr); - close(2); - dup2(oldstderr, 2); - close(oldstderr); + recursion--; + if (!recursion) + cancel = 0; + + fclose(inp); + if (argc == 3) + { + fflush(stdout); + close(1); + dup2(oldstdout, 1); + close(oldstdout); + fflush(stderr); + close(2); + dup2(oldstderr, 2); + close(oldstderr); } } -print_reply(argc, argv) - int argc; - char **argv; +int print_reply(int argc, char **argv) { - int i; - for (i = 0; i < argc; i++) { - if (i != 0) printf(", "); - printf("%s", argv[i]); - } - printf("\n"); - count++; - return(MR_CONT); + int i; + for (i = 0; i < argc; i++) + { + if (i != 0) + printf(", "); + printf("%s", argv[i]); + } + printf("\n"); + count++; + return MR_CONT; } -test_query(argc, argv) - int argc; - char **argv; +int test_query(int argc, char **argv) { - int status; -#ifdef POSIX - sigset_t sigs; -#else - int mask; -#endif + int status; + sigset_t sigs; - if (argc < 2) { - com_err("moira (query)", 0, "Usage: query handle [ args ... ]"); - return; - } + if (argc < 2) + { + com_err("moira (query)", 0, "Usage: query handle [ args ... ]"); + return; + } - count = 0; - /* Don't allow ^C during the query: it will confuse libmoira's - internal state. (Yay static variables) */ -#ifdef POSIX - sigemptyset(&sigs); - sigaddset(&sigs, SIGINT); - sigprocmask(SIG_BLOCK, &sigs, NULL); -#else - mask = sigblock(SIGINT); -#endif - status = mr_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL); -#ifdef POSIX - sigprocmask(SIG_UNBLOCK, &sigs, NULL); -#else - sigsetmask(mask); -#endif - printf("%d tuple%s\n", count, ((count == 1) ? "" : "s")); - if (status) com_err("moira (query)", status, ""); + count = 0; + /* Don't allow ^C during the query: it will confuse libmoira's + internal state. (Yay static variables) */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGINT); + sigprocmask(SIG_BLOCK, &sigs, NULL); + status = mr_query(argv[1], argc - 2, argv + 2, print_reply, NULL); + sigprocmask(SIG_UNBLOCK, &sigs, NULL); + printf("%d tuple%s\n", count, ((count == 1) ? "" : "s")); + if (status) + com_err("moira (query)", status, ""); } -test_access(argc, argv) - int argc; - char **argv; +int test_access(int argc, char **argv) { - int status; - if (argc < 2) { - com_err("moira (access)", 0, "Usage: access handle [ args ... ]"); - return; - } - status = mr_access(argv[1], argc-2, argv+2); - if (status) com_err("moira (access)", status, ""); + int status; + if (argc < 2) + { + com_err("moira (access)", 0, "Usage: access handle [ args ... ]"); + return; + } + status = mr_access(argv[1], argc - 2, argv + 2); + if (status) + com_err("moira (access)", status, ""); } - -test_dcm(argc, argv) - int argc; - char **argv; +int test_dcm(int argc, char **argv) { - int status; + int status; - if (status = mr_do_update()) - com_err("moira (dcm)", status, " while triggering dcm"); + if ((status = mr_do_update())) + com_err("moira (dcm)", status, " while triggering dcm"); } - -test_motd(argc, argv) - int argc; - char **argv; +int test_motd(int argc, char **argv) { - int status; - char *motd; - - if (status = mr_motd(&motd)) - com_err("moira (motd)", status, " while getting motd"); - if (motd) - printf("%s\n", motd); - else - printf("No message of the day.\n"); + int status; + char *motd; + + if ((status = mr_motd(&motd))) + com_err("moira (motd)", status, " while getting motd"); + if (motd) + printf("%s\n", motd); + else + printf("No message of the day.\n"); } -test_list_requests() +int test_list_requests(void) { - printf("Available moira requests:\n"); - printf("\n"); - printf("noop\t\t\tAsk Moira to do nothing\n"); - printf("connect, c\t\tConnect to Moira server\n"); - printf("disconnect, d\t\tDisconnect from server\n"); - printf("host\t\t\tIdentify the server host\n"); - printf("new, 2\t\t\tUse new protocol\n"); - printf("old, 1\t\t\tUse old protocol\n"); - printf("motd, m\t\t\tGet the Message of the Day\n"); - printf("query, qy\t\tMake a query.\n"); - printf("auth, a\t\t\tAuthenticate to Moira.\n"); - printf("access\t\t\tCheck access to a Moira query.\n"); - printf("dcm\t\t\tTrigger the DCM\n"); - printf("script, s\t\tRead commands from a script.\n"); - printf("list_requests, lr, ?\tList available commands.\n"); - printf("quit, Q\t\t\tLeave the subsystem.\n"); + printf("Available moira requests:\n"); + printf("\n"); + printf("noop\t\t\tAsk Moira to do nothing\n"); + printf("connect, c\t\tConnect to Moira server\n"); + printf("disconnect, d\t\tDisconnect from server\n"); + printf("host\t\t\tIdentify the server host\n"); + printf("new, 2\t\t\tUse new protocol\n"); + printf("old, 1\t\t\tUse old protocol\n"); + printf("motd, m\t\t\tGet the Message of the Day\n"); + printf("query, qy\t\tMake a query.\n"); + printf("auth, a\t\t\tAuthenticate to Moira.\n"); + printf("access\t\t\tCheck access to a Moira query.\n"); + printf("dcm\t\t\tTrigger the DCM\n"); + printf("script, s\t\tRead commands from a script.\n"); + printf("list_requests, lr, ?\tList available commands.\n"); + printf("quit, Q\t\t\tLeave the subsystem.\n"); } diff --git a/clients/passwd/chfn.c b/clients/passwd/chfn.c index e48df592..03a9ac51 100644 --- a/clients/passwd/chfn.c +++ b/clients/passwd/chfn.c @@ -1,6 +1,6 @@ /* * Copyright 1988 by the Massachusetts Institute of Technology. For copying - * and distribution information, see the file "mit-copyright.h". + * and distribution information, see the file "mit-copyright.h". * * $Source$ * $Header$ @@ -14,10 +14,10 @@ static char *rcsid_chfn_c = "$Header$"; /* * Talk to the MOIRA database to change a person's GECOS information. - * - * chfn with no modifiers changes the information of the user who is + * + * chfn with no modifiers changes the information of the user who is * running the program. - * + * * If a commandline argument is given, it is taken to be the username * of the user whose information is to be changed. * @@ -42,304 +42,305 @@ static char *rcsid_chfn_c = "$Header$"; char *whoami; struct finger_info { - char *fullname; - char *nickname; - char *home_address; - char *home_phone; - char *office_address; - char *office_phone; - char *mit_department; - char *mit_year; + char *fullname; + char *nickname; + char *home_address; + char *home_phone; + char *office_address; + char *office_phone; + char *mit_department; + char *mit_year; }; -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { - char pname[ANAME_SZ]; - char *uname = pname; - int k_errno; + char pname[ANAME_SZ]; + char *uname = pname; + int k_errno; - initialize_krb_error_table(); + initialize_krb_error_table(); - if ((whoami = strrchr(argv[0], '/')) == NULL) - whoami = argv[0]; - else - whoami++; + if ((whoami = strrchr(argv[0], '/')) == NULL) + whoami = argv[0]; + else + whoami++; - if (argc > 2) { - usage(); - } - - if (argc == 2) - uname = argv[1]; - else + if (argc > 2) + usage(); + + if (argc == 2) + uname = argv[1]; + else { - /* Do it right; get name from kerberos ticket file rather than - from passord file. */ - - if (k_errno = tf_init(TKT_FILE, R_TKT_FIL)) { - com_err(whoami, k_errno, "reading ticket file"); - exit(1); + /* Do it right; get name from kerberos ticket file rather than + from passord file. */ + + if ((k_errno = tf_init(TKT_FILE, R_TKT_FIL))) + { + com_err(whoami, k_errno, "reading ticket file"); + exit(1); } - - if (k_errno = tf_get_pname(pname)) { - com_err(whoami, k_errno, "getting kerberos principal name"); - exit(1); + + if (k_errno = tf_get_pname(pname)) + { + com_err(whoami, k_errno, "getting kerberos principal name"); + exit(1); } - tf_close(); + tf_close(); } - - exit(chfn(uname)); + + exit(chfn(uname)); } -leave(status) - int status; - /* This should be called rather than exit once connection to moira server - has been established. */ +/* This should be called rather than exit once connection to moira server + has been established. */ +int leave(int status) { - mr_disconnect(); - exit(status); + mr_disconnect(); + exit(status); } -scream() +int scream(void) { - com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); - leave(1); + com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); + leave(1); } -chfn(uname) - char *uname; +int chfn(char *uname) { - int status; /* general purpose exit status */ - int q_argc; /* argc for mr_query */ - char *q_argv[F_END]; /* argv for mr_query */ - char *motd; /* for MR server status */ - int i; + int status; /* general purpose exit status */ + int q_argc; /* argc for mr_query */ + char *q_argv[F_END]; /* argv for mr_query */ + char *motd; /* for MR server status */ + int i; - int get_user_info(); - void get_new_info(); + int get_user_info(); + void get_new_info(); - struct finger_info old_info; - struct finger_info new_info; + struct finger_info old_info; + struct finger_info new_info; - /* Try each query. If we ever fail, print error message and exit. */ + /* Try each query. If we ever fail, print error message and exit. */ - status = mr_connect(NULL); - if (status) { - com_err(whoami, status, "while connecting to Moira"); - exit(1); + status = mr_connect(NULL); + if (status) + { + com_err(whoami, status, "while connecting to Moira"); + exit(1); } - status = mr_motd(&motd); - if (status) { - com_err(whoami, status, "unable to check server status"); - leave(1); + status = mr_motd(&motd); + if (status) + { + com_err(whoami, status, "unable to check server status"); + leave(1); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - leave(1); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + leave(1); } - status = mr_auth("chfn"); /* Don't use argv[0] - too easy to fake */ - if (status) { - com_err(whoami, status, - "while authenticating -- run \"kinit\" and try again."); - leave(1); + status = mr_auth("chfn"); /* Don't use argv[0] - too easy to fake */ + if (status) + { + com_err(whoami, status, + "while authenticating -- run \"kinit\" and try again."); + leave(1); } - /* First, do an access check. */ + /* First, do an access check. */ + + q_argv[F_NAME] = uname; + for (i = F_NAME + 1; i < F_MODTIME; i++) + q_argv[i] = "junk"; + q_argc = F_MODTIME; /* one more than the last updatable field */ - q_argv[F_NAME] = uname; - for (i = F_NAME + 1; i < F_MODTIME; i++) - q_argv[i] = "junk"; - q_argc = F_MODTIME; /* one more than the last updatable field */ - - if (status = mr_access("update_finger_by_login", q_argc, q_argv)) { - com_err(whoami, status, "; finger\ninformation not changed."); - leave(2); + if ((status = mr_access("update_finger_by_login", q_argc, q_argv))) + { + com_err(whoami, status, "; finger\ninformation not changed."); + leave(2); } - printf("Changing finger information for %s.\n", uname); + printf("Changing finger information for %s.\n", uname); - /* Get information */ + /* Get information */ - q_argv[NAME] = uname; - q_argc = NAME + 1; - if (status = mr_query("get_finger_by_login", q_argc, q_argv, - get_user_info, (char *) &old_info)) + q_argv[NAME] = uname; + q_argc = NAME + 1; + if ((status = mr_query("get_finger_by_login", q_argc, q_argv, + get_user_info, (char *) &old_info))) { - com_err(whoami, status, "while getting user information."); - leave(2); + com_err(whoami, status, "while getting user information."); + leave(2); } - /* Get the new information from the user */ + /* Get the new information from the user */ - get_new_info(&old_info, &new_info); + get_new_info(&old_info, &new_info); - /* Do the update */ + /* Do the update */ - printf("Changing finger information...\n"); + printf("Changing finger information...\n"); - q_argv[F_NAME] = uname; - q_argv[F_FULLNAME] = new_info.fullname; - q_argv[F_NICKNAME] = new_info.nickname; - q_argv[F_HOME_ADDR] = new_info.home_address; - q_argv[F_HOME_PHONE] = new_info.home_phone; - q_argv[F_OFFICE_ADDR] = new_info.office_address; - q_argv[F_OFFICE_PHONE] = new_info.office_phone; - q_argv[F_MIT_DEPT] = new_info.mit_department; - q_argv[F_MIT_AFFIL] = new_info.mit_year; - q_argc = F_MODTIME; /* First non-update query argument */ + q_argv[F_NAME] = uname; + q_argv[F_FULLNAME] = new_info.fullname; + q_argv[F_NICKNAME] = new_info.nickname; + q_argv[F_HOME_ADDR] = new_info.home_address; + q_argv[F_HOME_PHONE] = new_info.home_phone; + q_argv[F_OFFICE_ADDR] = new_info.office_address; + q_argv[F_OFFICE_PHONE] = new_info.office_phone; + q_argv[F_MIT_DEPT] = new_info.mit_department; + q_argv[F_MIT_AFFIL] = new_info.mit_year; + q_argc = F_MODTIME; /* First non-update query argument */ - if (status = mr_query("update_finger_by_login", q_argc, q_argv, - scream, (char *)NULL)) + if ((status = mr_query("update_finger_by_login", q_argc, q_argv, + scream, NULL))) { - com_err(whoami, status, "while updating finger information."); - leave(1); + com_err(whoami, status, "while updating finger information."); + leave(1); } - printf("Finger information updated succesfully.\n"); + printf("Finger information updated succesfully.\n"); - return(0); + return 0; } -get_user_info(argc, argv, message) - int argc; - char *argv[]; - char *message; +int get_user_info(int argc, char *argv[], char *message) { - struct finger_info *old_info = (struct finger_info *) message; - - if (argc != F_END) { - fprintf(stderr, "Some internal error occurred; try again.\n"); - leave(3); + struct finger_info *old_info = (struct finger_info *) message; + + if (argc != F_END) + { + fprintf(stderr, "Some internal error occurred; try again.\n"); + leave(3); } - - printf("Info last changed on %s by user %s with %s.\n", - argv[F_MODTIME], argv[F_MODBY], argv[F_MODWITH]); - - old_info->fullname = strsave(argv[F_FULLNAME]); - old_info->nickname = strsave(argv[F_NICKNAME]); - old_info->home_address = strsave(argv[F_HOME_ADDR]); - old_info->home_phone = strsave(argv[F_HOME_PHONE]); - old_info->office_address = strsave(argv[F_OFFICE_ADDR]); - old_info->office_phone = strsave(argv[F_OFFICE_PHONE]); - old_info->mit_department = strsave(argv[F_MIT_DEPT]); - old_info->mit_year = strsave(argv[F_MIT_AFFIL]); - - /* Only pay attention to the first match since login names are - unique in the database. */ - return(MR_ABORT); + + printf("Info last changed on %s by user %s with %s.\n", + argv[F_MODTIME], argv[F_MODBY], argv[F_MODWITH]); + + old_info->fullname = strsave(argv[F_FULLNAME]); + old_info->nickname = strsave(argv[F_NICKNAME]); + old_info->home_address = strsave(argv[F_HOME_ADDR]); + old_info->home_phone = strsave(argv[F_HOME_PHONE]); + old_info->office_address = strsave(argv[F_OFFICE_ADDR]); + old_info->office_phone = strsave(argv[F_OFFICE_PHONE]); + old_info->mit_department = strsave(argv[F_MIT_DEPT]); + old_info->mit_year = strsave(argv[F_MIT_AFFIL]); + + /* Only pay attention to the first match since login names are + unique in the database. */ + return MR_ABORT; } -char *ask(question, def_val, phone_num) - char *question; - char *def_val; - int phone_num; /* True if this must contain only digits */ +char *ask(char *question, char *def_val, int phone_num) { - static char buf[BUFSIZ]; - int ok = FALSE; - char *result; - int i; - int dashes = FALSE; - + static char buf[BUFSIZ]; + int ok = FALSE; + char *result; + int i; + int dashes = FALSE; + #define BLANK "none" - - while (!ok) + + while (!ok) { - ok = TRUE; - printf("%s [%s]: ", question, def_val); - if (fgets(buf, sizeof(buf), stdin) == NULL) - leave(0); - buf[strlen(buf) - 1] = '\0'; - if (strlen(buf) == 0) - result = def_val; - else if (strcasecmp(buf, BLANK) == 0) - result = ""; - else - result = buf; - - for (i = 0; i < strlen(buf); i++) + ok = TRUE; + printf("%s [%s]: ", question, def_val); + if (!fgets(buf, sizeof(buf), stdin)) + leave(0); + buf[strlen(buf) - 1] = '\0'; + if (strlen(buf) == 0) + result = def_val; + else if (!strcasecmp(buf, BLANK)) + result = ""; + else + result = buf; + + for (i = 0; i < strlen(buf); i++) { - switch (buf[i]) + switch (buf[i]) { - case '"': - printf("'\"' is not allowed.\n"); - ok = FALSE; - break; - case ',': - printf("',' is not allowed.\n"); - ok = FALSE; - break; - case ':': - printf("':' is not allowed.\n"); - ok = FALSE; - break; - default: - if (iscntrl(buf[i])) { - printf("Control characters are not allowed.\n"); - ok = FALSE; - break; + case '"': + printf("'\"' is not allowed.\n"); + ok = FALSE; + break; + case ',': + printf("',' is not allowed.\n"); + ok = FALSE; + break; + case ':': + printf("':' is not allowed.\n"); + ok = FALSE; + break; + default: + if (iscntrl(buf[i])) + { + printf("Control characters are not allowed.\n"); + ok = FALSE; + break; } } - if (!ok) - break; + if (!ok) + break; } - - if (phone_num && ok) { - for (i = 0; i < strlen(result); i++) { - if (!isdigit(result[i]) && (result[i] != '-')) { - printf("Phone numbers can contain only digits.\n"); - ok = FALSE; - break; + + if (phone_num && ok) + { + for (i = 0; i < strlen(result); i++) + { + if (!isdigit(result[i]) && (result[i] != '-')) + { + printf("Phone numbers can contain only digits.\n"); + ok = FALSE; + break; } - if (result[i] == '-') - dashes = TRUE; + if (result[i] == '-') + dashes = TRUE; } } } - - /* Remove dashes if necessary */ - if (dashes && result == buf) { - char *tmp1, *tmp2; - tmp1 = tmp2 = (char *)buf; - do { - if (*(tmp1) != '-') - *(tmp2++) = *(tmp1); + + /* Remove dashes if necessary */ + if (dashes && result == buf) + { + char *tmp1, *tmp2; + tmp1 = tmp2 = (char *)buf; + do + { + if (*tmp1 != '-') + *tmp2++ = *tmp1; } - while (*(tmp1++)); + while (*tmp1++); } - - return(result); + + return result; } - -void get_new_info(old_info, new_info) - struct finger_info *old_info; - struct finger_info *new_info; + +void get_new_info(struct finger_info *old_info, struct finger_info *new_info) { - printf("Default values are printed inside of '[]'.\n"); - printf("To accept the default, type .\n"); - printf("To have a blank entry, type the word '%s'.\n\n", BLANK); - -#define GETINFO(m,v,n) \ - new_info->v = strsave(ask(m, old_info->v, n)) - - GETINFO("Full name", fullname, FALSE); - GETINFO("Nickname", nickname, FALSE); - GETINFO("Home address (Ex: Atkinson 304)", home_address, FALSE); - GETINFO("Home phone number (Ex: 3141592)", home_phone, TRUE); - GETINFO("Office address (Exs: E40-342 or 2-108)", - office_address, FALSE); - GETINFO("Office phone (Ex: 3-1300)", office_phone, TRUE); - GETINFO("MIT department (Exs: 9, Biology, Information Services)", - mit_department, FALSE); - GETINFO("MIT year (Exs: 1989, '91, Faculty, Grad)", mit_year, FALSE); + printf("Default values are printed inside of '[]'.\n"); + printf("To accept the default, type .\n"); + printf("To have a blank entry, type the word '%s'.\n\n", BLANK); + +#define GETINFO(m, v, n) new_info->v = strsave(ask(m, old_info->v, n)) + + GETINFO("Full name", fullname, FALSE); + GETINFO("Nickname", nickname, FALSE); + GETINFO("Home address (Ex: Atkinson 304)", home_address, FALSE); + GETINFO("Home phone number (Ex: 3141592)", home_phone, TRUE); + GETINFO("Office address (Exs: E40-342 or 2-108)", + office_address, FALSE); + GETINFO("Office phone (Ex: 3-1300)", office_phone, TRUE); + GETINFO("MIT department (Exs: 9, Biology, Information Services)", + mit_department, FALSE); + GETINFO("MIT year (Exs: 1989, '91, Faculty, Grad)", mit_year, FALSE); } -usage() +int usage(void) { - fprintf(stderr, "Usage: %s [user]\n", whoami); - exit(1); + fprintf(stderr, "Usage: %s [user]\n", whoami); + exit(1); } diff --git a/clients/passwd/chpobox.c b/clients/passwd/chpobox.c index e505628d..ed38d5b0 100644 --- a/clients/passwd/chpobox.c +++ b/clients/passwd/chpobox.c @@ -1,6 +1,6 @@ /* * Copyright 1987 by the Massachusetts Institute of Technology. For copying - * and distribution information, see the file "mit-copyright.h". + * and distribution information, see the file "mit-copyright.h". * * $Source$ * $Header$ @@ -15,9 +15,9 @@ static char *rcsid_chpobox_c = "$Header$"; /* * Talk to the MOIRA database to change a person's home mail machine. This may * be an Athena machine, or a completely arbitrary address. - * + * * chpobox with no modifiers reports the current mailbox. - * + * * chpobox -s [address] means set the mailbox to this address. * * chpobox -p restores the pobox to a previous POP box, if there was one. @@ -50,291 +50,304 @@ int getopt(); static int match; -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { - struct passwd *pwd; - char *mrarg[3], buf[BUFSIZ]; - char *potype(); - char *address, *uname, *machine, *motd; - uid_t u; - char *canonicalize_hostname(); - int get_pobox(), scream(); - int c, setflag, prevpop, usageflag, status; - - extern int optind; - extern char *optarg; - - c = setflag = prevpop = usageflag = 0; - address = uname = (char *) NULL; - u = getuid(); - - if ((whoami = strrchr(argv[0], '/')) == NULL) - whoami = argv[0]; - else - whoami++; - - if (argc > 5) { + struct passwd *pwd; + char *mrarg[3], buf[BUFSIZ]; + char *potype(); + char *address, *uname, *machine, *motd; + uid_t u; + char *canonicalize_hostname(); + int get_pobox(), scream(); + int c, setflag, prevpop, usageflag, status; + + extern int optind; + extern char *optarg; + + c = setflag = prevpop = usageflag = 0; + address = uname = (char *) NULL; + u = getuid(); + + if ((whoami = strrchr(argv[0], '/')) == NULL) + whoami = argv[0]; + else + whoami++; + + if (argc > 5) + usage(); + + while ((c = getopt(argc, argv, "s:pu:")) != -1) + switch (c) + { + case 's': + if (prevpop) + usageflag++; + else + { + setflag++; + strcpy(buf, optarg); + address = buf; + } + break; + case 'p': + if (setflag) + usageflag++; + else + prevpop++; + break; + case 'u': + uname = strsave(optarg); + break; + default: + usageflag++; + break; + } + if (argc == 2 && optind == 1 && !uname) + uname = argv[optind++]; + + if (usageflag || optind != argc) + usage(); + + if (!uname) + { + if (!(uname = getlogin())) usage(); - } - while ((c = getopt(argc, argv, "s:pu:")) != EOF) - switch (c) { - - case 's': - if (prevpop) - usageflag++; - else { - setflag++; - strcpy(buf, optarg); - address = buf; - } - break; - case 'p': - if (setflag) - usageflag++; - else { - prevpop++; - } - break; - case 'u': - uname = strsave(optarg); - break; - default: - usageflag++; - break; - } - if (argc == 2 && optind == 1 && !uname) { - uname = argv[optind++]; - } - if (usageflag || optind != argc) { - usage(); - } - if (!uname) { - if ((uname = getlogin()) == NULL) { - usage(); - } - if (uname[0] == '\0') { - pwd = getpwuid((int) u); - (void) strcpy(uname, pwd->pw_name); + if (uname[0] == '\0') + { + pwd = getpwuid(u); + strcpy(uname, pwd->pw_name); } } - mrarg[0] = uname; + mrarg[0] = uname; - status = mr_connect(NULL); - if (status) { - com_err(whoami, status, " while connecting to Moira"); - exit(1); + status = mr_connect(NULL); + if (status) + { + com_err(whoami, status, " while connecting to Moira"); + exit(1); } - status = mr_motd(&motd); - if (status) { - mr_disconnect(); - com_err(whoami, status, " unable to check server status"); - exit(1); + status = mr_motd(&motd); + if (status) + { + mr_disconnect(); + com_err(whoami, status, " unable to check server status"); + exit(1); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - mr_disconnect(); - exit(1); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + mr_disconnect(); + exit(1); } - status = mr_auth("chpobox"); - if (status) { - com_err(whoami, status, " while authenticating -- run \"kinit\" and try again."); - mr_disconnect(); - exit(1); + status = mr_auth("chpobox"); + if (status) + { + com_err(whoami, status, " while authenticating -- " + "run \"kinit\" and try again."); + mr_disconnect(); + exit(1); } - if (setflag) { - /* Address is of form user@host. Split it up. */ - if (!address) { - fprintf(stderr, "%s: no address was specified.\n", whoami); - goto show; + if (setflag) + { + /* Address is of form user@host. Split it up. */ + if (!address) + { + fprintf(stderr, "%s: no address was specified.\n", whoami); + goto show; } - machine = strchr(address, '@'); - if (machine) { - *machine++ = '\0'; /* get rid of the @ sign */ - machine = strtrim(machine); /* get rid of whitespace */ - } else { - fprintf(stderr, "%s: no at sign (@) in address \"%s\"\n", - whoami, address); - goto show; + machine = strchr(address, '@'); + if (machine) + { + *machine++ = '\0'; /* get rid of the @ sign */ + machine = strtrim(machine); /* get rid of whitespace */ } - mrarg[2] = canonicalize_hostname(strsave(machine)); - mrarg[1] = potype(mrarg[2]); - if (!strcmp(mrarg[1], "POP")) { - if (strcmp(address, uname)) { - fprintf(stderr, - "%s: the name on the POP box must match the username\n", - whoami); - goto show; + else + { + fprintf(stderr, "%s: no at sign (@) in address \"%s\"\n", + whoami, address); + goto show; + } + mrarg[2] = canonicalize_hostname(strsave(machine)); + mrarg[1] = potype(mrarg[2]); + if (!strcmp(mrarg[1], "POP")) + { + if (strcmp(address, uname)) + { + fprintf(stderr, + "%s: the name on the POP box must match the username\n", + whoami); + goto show; } - } else if (!strcmp(mrarg[1], "LOCAL")) { - strcat(address, "@"); - strcat(address, mrarg[2]); - mrarg[2] = address; - if ((address = strchr(address, '@')) && - (address = strchr(address, '.'))) - *address = 0; - strcat(mrarg[2], ".LOCAL"); - mrarg[1] = "SMTP"; - } else if (!strcmp(mrarg[1], "MAILHUB")) { - if (!strcmp(address, uname)) { - fprintf(stderr, - "Error: this will set a mail forwarding loop.\n"); - fprintf(stderr, - "Use \"%s -p\" to set a local post office server.\n", - whoami); - exit(1); + } + else if (!strcmp(mrarg[1], "LOCAL")) + { + strcat(address, "@"); + strcat(address, mrarg[2]); + mrarg[2] = address; + if ((address = strchr(address, '@')) && + (address = strchr(address, '.'))) + *address = 0; + strcat(mrarg[2], ".LOCAL"); + mrarg[1] = "SMTP"; + } + else if (!strcmp(mrarg[1], "MAILHUB")) + { + if (!strcmp(address, uname)) + { + fprintf(stderr, + "Error: this will set a mail forwarding loop.\n"); + fprintf(stderr, + "Use \"%s -p\" to set a local post office server.\n", + whoami); + exit(1); } - fprintf(stderr, "Error: \"%s@%s\" is a local mail address.\n", - address, machine); - fprintf(stderr, "Your mail drop must be on a post office server or an external mail address.\n"); - exit(1); - } else if (mrarg[1]) { - if (*machine != '"' && strcasecmp(mrarg[2], machine)) + fprintf(stderr, "Error: \"%s@%s\" is a local mail address.\n", + address, machine); + fprintf(stderr, "Your mail drop must be on a post office server " + "or an external mail address.\n"); + exit(1); + } + else if (mrarg[1]) + { + if (*machine != '"' && strcasecmp(mrarg[2], machine)) + { fprintf(stderr, "Warning: hostname %s canonicalized to %s\n", machine, mrarg[2]); - strcat(address, "@"); - strcat(address, mrarg[2]); - mrarg[2] = address; + } + strcat(address, "@"); + strcat(address, mrarg[2]); + mrarg[2] = address; } else goto show; - status = mr_query("set_pobox", 3, mrarg, scream, NULL); - if (status) - com_err(whoami, status, - " while setting pobox for %s to type %s, box %s", - mrarg[0], mrarg[1], mrarg[2]); - } else if (prevpop) { - status = mr_query("set_pobox_pop", 1, mrarg, scream, NULL); - if (status == MR_MACHINE) { - fprintf(stderr, - "Moira has no record of a previous POP box for %s\n", uname); - } else if (status != 0) - com_err(whoami, status, " while setting pobox"); + status = mr_query("set_pobox", 3, mrarg, scream, NULL); + if (status) + com_err(whoami, status, + " while setting pobox for %s to type %s, box %s", + mrarg[0], mrarg[1], mrarg[2]); + } + else if (prevpop) + { + status = mr_query("set_pobox_pop", 1, mrarg, scream, NULL); + if (status == MR_MACHINE) + { + fprintf(stderr, + "Moira has no record of a previous POP box for %s\n", uname); + } + else if (status != 0) + com_err(whoami, status, " while setting pobox"); } - /* - * get current box - */ + /* + * get current box + */ show: - status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL); - if (status == MR_NO_MATCH) - printf("User %s has no pobox.\n", uname); - else if (status != 0) - com_err(whoami, status, " while retrieving current mailbox"); - mr_disconnect(); - exit(0); + status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL); + if (status == MR_NO_MATCH) + printf("User %s has no pobox.\n", uname); + else if (status != 0) + com_err(whoami, status, " while retrieving current mailbox"); + mr_disconnect(); + exit(0); } -scream() +int scream(void) { - com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); - mr_disconnect(); - exit(1); + com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); + mr_disconnect(); + exit(1); } /* * get_pobox gets all your poboxes and displays them. */ -/* ARGSUSED */ -int -get_pobox(argc, argv, callarg) - int argc; - char **argv, *callarg; +int get_pobox(int argc, char **argv, char *callarg) { - if (!strcmp(argv[1], "POP")) - printf("User %s, Type %s, Box: %s@%s\n", - argv[0], argv[1], argv[0], argv[2]); - else - printf("User %s, Type %s, Box: %s\n", - argv[0], argv[1], argv[2]); - printf(" Modified by %s on %s with %s\n", argv[4], argv[3], argv[5]); - return (0); + if (!strcmp(argv[1], "POP")) + printf("User %s, Type %s, Box: %s@%s\n", + argv[0], argv[1], argv[0], argv[2]); + else + printf("User %s, Type %s, Box: %s\n", + argv[0], argv[1], argv[2]); + printf(" Modified by %s on %s with %s\n", argv[4], argv[3], argv[5]); + return 0; } /* * given a canonicalized machine name, ask the MR server if it is of type - * pop, or of type local -- if neither, we assume that it's of type foreign. + * pop, or of type local -- if neither, we assume that it's of type foreign. */ -char * -potype(machine) - char *machine; +char *potype(char *machine) { - char *service[1], *argv[3]; - int check_match(), check_match3(), status; - - match = 0; - service[0] = "POP"; - status = mr_query("get_server_locations", 1, service, - check_match, machine); - if (status && (status != MR_NO_MATCH)) { - com_err(whoami, status, " while reading list of POP servers"); - return(NULL); + char *service[1], *argv[3]; + int check_match(), check_match3(), status; + + match = 0; + service[0] = "POP"; + status = mr_query("get_server_locations", 1, service, check_match, machine); + if (status && (status != MR_NO_MATCH)) + { + com_err(whoami, status, " while reading list of POP servers"); + return NULL; } - if (match) - return ("POP"); - - service[0] = "LOCAL"; - status = mr_query("get_server_locations", 1, service, - check_match, machine); - if (status && (status != MR_NO_MATCH)) { - com_err(whoami, status, " while reading list of LOCAL servers"); - return(NULL); + if (match) + return "POP"; + + service[0] = "LOCAL"; + status = mr_query("get_server_locations", 1, service, check_match, machine); + if (status && (status != MR_NO_MATCH)) + { + com_err(whoami, status, " while reading list of LOCAL servers"); + return NULL; } - if (match) - return ("LOCAL"); - - argv[0] = "mailhub"; - argv[1] = "TYPE"; - argv[2] = "*"; - status = mr_query("get_alias", 3, argv, check_match3, machine); - if (status && (status != MR_NO_MATCH)) { - com_err(whoami, status, " while reading list of MAILHUB servers"); - return(NULL); + if (match) + return "LOCAL"; + + argv[0] = "mailhub"; + argv[1] = "TYPE"; + argv[2] = "*"; + status = mr_query("get_alias", 3, argv, check_match3, machine); + if (status && (status != MR_NO_MATCH)) + { + com_err(whoami, status, " while reading list of MAILHUB servers"); + return NULL; } - if (match) - return ("MAILHUB"); - else - return ("SMTP"); + if (match) + return "MAILHUB"; + else + return "SMTP"; } -/* ARGSUSED */ -int -check_match(argc, argv, callback) - int argc; - char **argv, *callback; +int check_match(int argc, char **argv, char *callback) { - if (match) - return (0); + if (match) + return 0; - if (strcasecmp(argv[1], callback) == 0) - match = 1; + if (!strcasecmp(argv[1], callback)) + match = 1; - return (0); + return 0; } -/* ARGSUSED */ -int -check_match3(argc, argv, callback) - int argc; - char **argv, *callback; +int check_match3(int argc, char **argv, char *callback) { - if (match) - return (0); + if (match) + return 0; - if (strcasecmp(argv[2], callback) == 0) - match = 1; + if (!strcasecmp(argv[2], callback)) + match = 1; - return (0); + return 0; } -usage() +int usage(void) { - fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami); - exit(1); + fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami); + exit(1); } diff --git a/clients/passwd/chsh.c b/clients/passwd/chsh.c index 548cb249..06833b04 100644 --- a/clients/passwd/chsh.c +++ b/clients/passwd/chsh.c @@ -1,6 +1,6 @@ /* * Copyright 1988 by the Massachusetts Institute of Technology. For copying - * and distribution information, see the file "mit-copyright.h". + * and distribution information, see the file "mit-copyright.h". * * $Source$ * $Header$ @@ -14,20 +14,18 @@ static char *rcsid_chsh_c = "$Header$"; /* * Talk to the MOIRA database to change a person's login shell. The chosen - * shell must exist. A warning will be issued if the shell is not in + * shell must exist. A warning will be issued if the shell is not in * /etc/shells. - * + * * chsh with no modifiers changes the shell of the user who is running * the program. - * + * * If a commandline argument is given, it is taken to be the username * of the user whose shell is to be changed. * */ -#ifdef POSIX #include -#endif #include #include #include @@ -44,242 +42,248 @@ static char *rcsid_chsh_c = "$Header$"; char *whoami; char *getusershell(); -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { - char pname[ANAME_SZ]; - char *uname = pname; - int k_errno; + char pname[ANAME_SZ]; + char *uname = pname; + int k_errno; - initialize_krb_error_table(); + initialize_krb_error_table(); - if ((whoami = strrchr(argv[0], '/')) == NULL) - whoami = argv[0]; - else - whoami++; + if ((whoami = strrchr(argv[0], '/')) == NULL) + whoami = argv[0]; + else + whoami++; - if (argc > 2) { - usage(); - } - - if (argc == 2) - uname = argv[1]; - else + if (argc > 2) + usage(); + + if (argc == 2) + uname = argv[1]; + else { - /* Do it right; get name from kerberos ticket file rather than - from passord file. */ - - if (k_errno = tf_init(TKT_FILE, R_TKT_FIL)) { - com_err(whoami, k_errno, "reading ticket file"); - exit(1); + /* Do it right; get name from kerberos ticket file rather than + from passord file. */ + + if ((k_errno = tf_init(TKT_FILE, R_TKT_FIL))) + { + com_err(whoami, k_errno, "reading ticket file"); + exit(1); } - - if (k_errno = tf_get_pname(pname)) { - com_err(whoami, k_errno, "getting kerberos principal name"); - exit(1); + + if ((k_errno = tf_get_pname(pname))) + { + com_err(whoami, k_errno, "getting kerberos principal name"); + exit(1); } - tf_close(); + tf_close(); } - - exit(chsh(uname)); + + exit(chsh(uname)); } -leave(status) - int status; - /* This should be called rather than exit once connection to moira server - has been established. */ +/* This should be called rather than exit once connection to moira server + has been established. */ +int leave(int status) { - mr_disconnect(); - exit(status); + mr_disconnect(); + exit(status); } -scream() +int scream(void) { - com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); - leave(1); + com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch"); + leave(1); } -chsh(uname) - char *uname; +int chsh(char *uname) { - int status; /* general purpose exit status */ - int q_argc; /* argc for mr_query */ - char *q_argv[U_END]; /* argv for mr_query */ - char *motd; /* determine MR server status */ - - int got_one = 0; /* have we got a new shell yet? */ - char shell[BUFSIZ]; /* the new shell */ - int get_shell(); - void check_shell(); /* make sure new shell is valid */ - - /* Try each query. If we ever fail, print error message and exit. */ - - status = mr_connect(NULL); - if (status) { - com_err(whoami, status, " while connecting to Moira"); - exit(1); + int status; /* general purpose exit status */ + int q_argc; /* argc for mr_query */ + char *q_argv[U_END]; /* argv for mr_query */ + char *motd; /* determine MR server status */ + + int got_one = 0; /* have we got a new shell yet? */ + char shell[BUFSIZ]; /* the new shell */ + int get_shell(); + void check_shell(); /* make sure new shell is valid */ + + /* Try each query. If we ever fail, print error message and exit. */ + + status = mr_connect(NULL); + if (status) + { + com_err(whoami, status, " while connecting to Moira"); + exit(1); } - status = mr_motd(&motd); - if (status) { - com_err(whoami, status, " unable to check server status"); - leave(1); + status = mr_motd(&motd); + if (status) + { + com_err(whoami, status, " unable to check server status"); + leave(1); } - if (motd) { - fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); - leave(1); + if (motd) + { + fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", + motd); + leave(1); } - status = mr_auth("chsh"); /* Don't use argv[0] - too easy to fake */ - if (status) { - com_err(whoami, status, - " while authenticating -- run \"kinit\" and try again."); - leave(1); + status = mr_auth("chsh"); /* Don't use argv[0] - too easy to fake */ + if (status) + { + com_err(whoami, status, + " while authenticating -- run \"kinit\" and try again."); + leave(1); } - /* First, do an access check */ + /* First, do an access check */ - q_argv[USH_NAME] = uname; - q_argv[USH_SHELL] = "junk"; - q_argc = USH_END; + q_argv[USH_NAME] = uname; + q_argv[USH_SHELL] = "junk"; + q_argc = USH_END; - if (status = mr_access("update_user_shell", q_argc, q_argv)) + if ((status = mr_access("update_user_shell", q_argc, q_argv))) { - com_err(whoami, status, "; shell not\nchanged."); - leave(2); + com_err(whoami, status, "; shell not\nchanged."); + leave(2); } - printf("Changing login shell for %s.\n", uname); + printf("Changing login shell for %s.\n", uname); - /* Display current information */ + /* Display current information */ - q_argv[NAME] = uname; - q_argc = NAME + 1; + q_argv[NAME] = uname; + q_argc = NAME + 1; - if ((status = mr_query("get_user_account_by_login", q_argc, q_argv, - get_shell, (char *) uname))) + if ((status = mr_query("get_user_account_by_login", q_argc, q_argv, + get_shell, (char *) uname))) { - com_err(whoami, status, " while getting user information."); - leave(2); + com_err(whoami, status, " while getting user information."); + leave(2); } - /* Ask for new shell */ - while (!got_one) + /* Ask for new shell */ + while (!got_one) { - printf("New shell: "); - if (fgets(shell, sizeof(shell), stdin) == NULL) - leave(0); - got_one = (strlen(shell) > 1); + printf("New shell: "); + if (!fgets(shell, sizeof(shell), stdin)) + leave(0); + got_one = (strlen(shell) > 1); } - shell[strlen(shell) - 1] = 0; /* strip off newline */ + shell[strlen(shell) - 1] = 0; /* strip off newline */ - /* Make sure we have a valid shell. This routine could exit */ - check_shell(shell); + /* Make sure we have a valid shell. This routine could exit */ + check_shell(shell); - /* Change shell */ + /* Change shell */ - printf("Changing shell to %s...\n", shell); + printf("Changing shell to %s...\n", shell); - q_argv[USH_NAME] = uname; - q_argv[USH_SHELL] = shell; - q_argc = USH_END; - if (status = mr_query("update_user_shell", q_argc, q_argv, - scream, (char *) NULL)) + q_argv[USH_NAME] = uname; + q_argv[USH_SHELL] = shell; + q_argc = USH_END; + if ((status = mr_query("update_user_shell", q_argc, q_argv, + scream, NULL))) { - com_err(whoami, status, " while changing shell."); - leave(2); + com_err(whoami, status, " while changing shell."); + leave(2); } - printf("Shell successfully changed.\n"); - mr_disconnect(); + printf("Shell successfully changed.\n"); + mr_disconnect(); - return(0); + return 0; } -get_shell(argc, argv, uname) - int argc; - char **argv; - char *uname; /* for sanity checking */ +int get_shell(int argc, char **argv, char *uname) { - /* We'll just take the first information we get since login names - cannot be duplicated in the database. */ - - if (argc < U_END || strcmp(argv[U_NAME], uname)) + /* We'll just take the first information we get since login names + cannot be duplicated in the database. */ + + if (argc < U_END || strcmp(argv[U_NAME], uname)) { - fprintf(stderr, "Some internal error has occurred. Try again.\n"); - leave(3); + fprintf(stderr, "Some internal error has occurred. Try again.\n"); + leave(3); } - - printf("Account information last changed on %s\n", argv[U_MODTIME]); - printf("by user %s with %s.\n", argv[U_MODBY], argv[U_MODWITH]); - printf("Current shell for %s is %s.\n", uname, argv[U_SHELL]); - - return(MR_ABORT); /* Don't pay attention to other matches. */ + + printf("Account information last changed on %s\n", argv[U_MODTIME]); + printf("by user %s with %s.\n", argv[U_MODBY], argv[U_MODWITH]); + printf("Current shell for %s is %s.\n", uname, argv[U_SHELL]); + + return MR_ABORT; /* Don't pay attention to other matches. */ } - -void check_shell(shell) - char *shell; + +void check_shell(char *shell) { - char *valid_shell; - int ok = 0; + char *valid_shell; + int ok = 0; - while (valid_shell = getusershell()) { - if (strcmp(shell, valid_shell) == 0) { - ok = 1; - break; + while ((valid_shell = getusershell())) + { + if (!strcmp(shell, valid_shell)) + { + ok = 1; + break; } - else if (strcmp(shell, 1+strrchr(valid_shell, '/')) == 0) { - ok = 1; - (void) strcpy(shell, valid_shell); - break; + else if (!strcmp(shell, 1 + strrchr(valid_shell, '/'))) + { + ok = 1; + strcpy(shell, valid_shell); + break; } } - - if (!ok) { - if (shell[0] != '/') { - fprintf(stderr, "%s is not a standard shell. ", shell); - fprintf(stderr, "You may choose to use a nonstandard\n"); - fprintf(stderr, "shell, but you must specify its complete "); - fprintf(stderr, "path name.\n"); - leave(2); + + if (!ok) + { + if (shell[0] != '/') + { + fprintf(stderr, "%s is not a standard shell. ", shell); + fprintf(stderr, "You may choose to use a nonstandard\n"); + fprintf(stderr, "shell, but you must specify its complete "); + fprintf(stderr, "path name.\n"); + leave(2); } - else if (access(shell, X_OK)) { - fprintf(stderr, "%s is not available.\n", shell); - leave(2); + else if (access(shell, X_OK)) + { + fprintf(stderr, "%s is not available.\n", shell); + leave(2); } - else { - printf("%s exists but is an unusual choice.\n", shell); - printf("Try again if it is not what you wanted.\n"); + else + { + printf("%s exists but is an unusual choice.\n", shell); + printf("Try again if it is not what you wanted.\n"); } } -} +} -usage() +int usage(void) { - fprintf(stderr, "Usage: %s [user]\n", whoami); - exit(1); + fprintf(stderr, "Usage: %s [user]\n", whoami); + exit(1); } -#if defined(ultrix) || defined(_AIX) || defined(sgi) +#ifdef NEED_GETUSERSHELL char *getusershell() { - static int count = 1; + static int count = 1; - switch (count++) { + switch (count++) + { case 1: - return("/bin/sh"); + return "/bin/sh"; case 2: - return("/bin/csh"); + return "/bin/csh"; case 3: - return("/bin/athena/tcsh"); + return "/bin/athena/tcsh"; case 4: - return(NULL); + return NULL; default: - count = 1; - return(getusershell()); + count = 1; + return getusershell(); } } #endif diff --git a/clients/userreg/disable.c b/clients/userreg/disable.c index c4100d18..c7761a89 100644 --- a/clients/userreg/disable.c +++ b/clients/userreg/disable.c @@ -13,13 +13,10 @@ #include #include #include -#ifdef _AUX_SOURCE -#include -#endif /* _AUX_SOURCE */ #include #include "files.h" -#define LISTS (2*BUFSIZ) +#define LISTS (2 * BUFSIZ) #define MAXLIN BUFSIZ #define EXACT 100 @@ -46,227 +43,238 @@ int number(register char c, FILE *f); * will indicate the time that registration will be re-enabled. */ -char *disabled(msg) -char **msg; +char *disabled(char **msg) { - register char *cp; - int hit; + register char *cp; + int hit; - *msg = 0; - init(); - append(DISABLE_FILE); - *listend++ = EOS; - *listend++ = EOS; + *msg = 0; + init(); + append(DISABLE_FILE); + *listend++ = EOS; + *listend++ = EOS; - (void) time(&itime); - itime -= localtime(&itime)->tm_sec; - loct = localtime(&itime); - loct->tm_mon++; /* 1-12 for month */ - if (loct->tm_wday == 0) - loct->tm_wday = 7; /* sunday is 7, not 0 */ - hit = 0; - for(cp = list; *cp != EOS;) { - flag = 0; - cp = cmp(cp, loct->tm_min); - cp = cmp(cp, loct->tm_hour); - cp = cmp(cp, loct->tm_mday); - cp = cmp(cp, loct->tm_mon); - cp = cmp(cp, loct->tm_wday); - if(flag == 0) { - *msg = cp; - hit++; - break; + time(&itime); + itime -= localtime(&itime)->tm_sec; + loct = localtime(&itime); + loct->tm_mon++; /* 1-12 for month */ + if (loct->tm_wday == 0) + loct->tm_wday = 7; /* sunday is 7, not 0 */ + hit = 0; + for (cp = list; *cp != EOS;) + { + flag = 0; + cp = cmp(cp, loct->tm_min); + cp = cmp(cp, loct->tm_hour); + cp = cmp(cp, loct->tm_mday); + cp = cmp(cp, loct->tm_mon); + cp = cmp(cp, loct->tm_wday); + if (flag == 0) + { + *msg = cp; + hit++; + break; } - while(*cp++ != 0) - ; + while (*cp++) + ; } - if (!hit) - return(NULL); - while (hit) { - itime += 60; /* add a minute */ - loct = localtime(&itime); - loct->tm_mon++; /* 1-12 for month */ - if (loct->tm_wday == 0) - loct->tm_wday = 7; /* sunday is 7, not 0 */ - hit = 0; - for(cp = list; *cp != EOS;) { - flag = 0; - cp = cmp(cp, loct->tm_min); - cp = cmp(cp, loct->tm_hour); - cp = cmp(cp, loct->tm_mday); - cp = cmp(cp, loct->tm_mon); - cp = cmp(cp, loct->tm_wday); - if(flag == 0) { - hit++; - break; + if (!hit) + return NULL; + while (hit) + { + itime += 60; /* add a minute */ + loct = localtime(&itime); + loct->tm_mon++; /* 1-12 for month */ + if (loct->tm_wday == 0) + loct->tm_wday = 7; /* sunday is 7, not 0 */ + hit = 0; + for(cp = list; *cp != EOS;) + { + flag = 0; + cp = cmp(cp, loct->tm_min); + cp = cmp(cp, loct->tm_hour); + cp = cmp(cp, loct->tm_mday); + cp = cmp(cp, loct->tm_mon); + cp = cmp(cp, loct->tm_wday); + if (!flag) + { + hit++; + break; } - while(*cp++ != 0) - ; + while(*cp++ != 0) + ; } } - return(ctime(&itime)); + return ctime(&itime); } -char * -cmp(p, v) -char *p; +char *cmp(char *p, int v) { - register char *cp; + register char *cp; - cp = p; - switch(*cp++) { + cp = p; + switch (*cp++) + { + case EXACT: + if (*cp++ != v) + flag++; + return cp; - case EXACT: - if (*cp++ != v) - flag++; - return(cp); + case ANY: + return cp; - case ANY: - return(cp); - - case LIST: - while(*cp != LIST) - if(*cp++ == v) { - while(*cp++ != LIST) - ; - return(cp); - } - flag++; - return(cp+1); - - case RANGE: - if(*cp > v || cp[1] < v) - flag++; - return(cp+2); + case LIST: + while (*cp != LIST) + { + if (*cp++ == v) + { + while (*cp++ != LIST) + ; + return cp; + } } - if(cp[-1] != v) - flag++; - return(cp); + flag++; + return cp + 1; + + case RANGE: + if (*cp > v || cp[1] < v) + flag++; + return cp + 2; + } + if (cp[-1] != v) + flag++; + return cp; } -init() +init(void) { - /* - * Don't free in case was longer than LISTS. Trades off - * the rare case of crontab shrinking vs. the common case of - * extra realloc's needed in append() for a large crontab. - */ - if (list == 0) { - list = malloc(LISTS); - listsize = LISTS; - } - listend = list; + /* + * Don't free in case was longer than LISTS. Trades off + * the rare case of crontab shrinking vs. the common case of + * extra realloc's needed in append() for a large crontab. + */ + if (list == 0) + { + list = malloc(LISTS); + listsize = LISTS; + } + listend = list; } -append(fn) -char *fn; +append(char *fn) { - register int i, c; - register char *cp; - register char *ocp; - register int n; - FILE *f, *fopen(); + register int i, c; + register char *cp; + register char *ocp; + register int n; + FILE *f, *fopen(); - if ((f = fopen(fn, "r")) == (FILE *) NULL) - return; - cp = listend; + if (!(f = fopen(fn, "r"))) + return; + cp = listend; loop: - if(cp > list+listsize-MAXLIN) { - int length = cp - list; + if (cp > list + listsize - MAXLIN) + { + int length = cp - list; - listsize += LISTS; - list = realloc(list, listsize); - cp = list + length; + listsize += LISTS; + list = realloc(list, listsize); + cp = list + length; + } + ocp = cp; + for (i = 0; ; i++) + { + do + c = getc(f); + while(c == ' ' || c == '\t'); + if (c == EOF || c == '\n') + goto ignore; + if (i == 5) + break; + if (c == '*') + { + *cp++ = ANY; + continue; } - ocp = cp; - for(i=0;; i++) { - do - c = getc(f); - while(c == ' ' || c == '\t') - ; - if(c == EOF || c == '\n') - goto ignore; - if(i == 5) - break; - if(c == '*') { - *cp++ = ANY; - continue; - } - if ((n = number(c, f)) < 0) - goto ignore; - c = getc(f); - if(c == ',') - goto mlist; - if(c == '-') - goto mrange; - if(c != '\t' && c != ' ') - goto ignore; - *cp++ = EXACT; - *cp++ = n; - continue; + if ((n = number(c, f)) < 0) + goto ignore; + c = getc(f); + if(c == ',') + goto mlist; + if(c == '-') + goto mrange; + if(c != '\t' && c != ' ') + goto ignore; + *cp++ = EXACT; + *cp++ = n; + continue; - mlist: - *cp++ = LIST; - *cp++ = n; - do { - if ((n = number(getc(f), f)) < 0) - goto ignore; - *cp++ = n; - c = getc(f); - } while (c==','); - if(c != '\t' && c != ' ') - goto ignore; - *cp++ = LIST; - continue; - - mrange: - *cp++ = RANGE; - *cp++ = n; - if ((n = number(getc(f), f)) < 0) - goto ignore; - c = getc(f); - if(c != '\t' && c != ' ') - goto ignore; - *cp++ = n; - } - while(c != '\n') { - if(c == EOF) - goto ignore; - if(c == '%') - c = '\n'; - *cp++ = c; - c = getc(f); + mlist: + *cp++ = LIST; + *cp++ = n; + do + { + if ((n = number(getc(f), f)) < 0) + goto ignore; + *cp++ = n; + c = getc(f); } - *cp++ = '\n'; - *cp++ = 0; - goto loop; + while (c == ','); + if (c != '\t' && c != ' ') + goto ignore; + *cp++ = LIST; + continue; + + mrange: + *cp++ = RANGE; + *cp++ = n; + if ((n = number(getc(f), f)) < 0) + goto ignore; + c = getc(f); + if (c != '\t' && c != ' ') + goto ignore; + *cp++ = n; + } + while (c != '\n') + { + if (c == EOF) + goto ignore; + if (c == '%') + c = '\n'; + *cp++ = c; + c = getc(f); + } + *cp++ = '\n'; + *cp++ = 0; + goto loop; ignore: - cp = ocp; - while(c != '\n') { - if(c == EOF) { - (void) fclose(f); - listend = cp; - return; - } - c = getc(f); + cp = ocp; + while (c != '\n') + { + if (c == EOF) + { + fclose(f); + listend = cp; + return; } - goto loop; + c = getc(f); + } + goto loop; } -number(c, f) -register char c; -FILE *f; +int number(register char c, FILE *f) { - register int n = 0; + register int n = 0; - while (isdigit(c)) { - n = n*10 + c - '0'; - c = getc(f); - } - (void) ungetc(c, f); - if (n>=100) - return(-1); - return(n); + while (isdigit(c)) + { + n = n * 10 + c - '0'; + c = getc(f); + } + ungetc(c, f); + if (n >= 100) + return -1; + return n; } diff --git a/clients/userreg/display.c b/clients/userreg/display.c index bdc527ca..e79cb8ca 100644 --- a/clients/userreg/display.c +++ b/clients/userreg/display.c @@ -21,12 +21,7 @@ static char *rcsid_display_c = "$Header$"; #define DESC_WIDTH 18 #define HEADER "*** Athena User Account Registration ***" -#if defined(ultrix) -#define HELP " Press the key above RETURN to delete a character. Press Ctrl-C to start over." -#endif -#ifndef HELP #define HELP " Press backspace to delete a character. Press Ctrl-C to start over." -#endif #define BORDER_CHAR '-' #define MIN_COLS 80 #define MIN_LINES 24 @@ -37,138 +32,130 @@ WINDOW * fnamew, *midw, *lnamew, *idw, *loginw; extern char typed_mit_id[100]; /* Set up the windows and subwindows on the display */ -setup_display () { - FILE * freopen (); - - initscr (); /* Start up curses */ +setup_display(void) +{ + FILE *freopen(); - if (COLS < MIN_COLS || LINES < MIN_LINES) { - fprintf (stderr, "Screen must be at least %d x %d\n", MIN_LINES, MIN_COLS); - exit (1); - } + initscr(); /* Start up curses */ - noecho (); /* And the tty input */ - raw (); - freopen ("/dev/null", "w", stderr);/* Toss the standard error output */ + if (COLS < MIN_COLS || LINES < MIN_LINES) + { + fprintf(stderr, "Screen must be at least %d x %d\n", + MIN_LINES, MIN_COLS); + exit(1); + } - /* Make sure the place is clean */ - clear (); + noecho(); /* And the tty input */ + raw(); + freopen("/dev/null", "w", stderr);/* Toss the standard error output */ - /* Set up the top-level windows */ - /* First line is the header */ - displayw = subwin (stdscr, 12, 0, 2, 0);/* Lines 2-13 */ - scrollok (displayw, TRUE); + /* Make sure the place is clean */ + clear(); - queryw = subwin (stdscr, 1, 0, 15, 0);/* Line 15 */ - scrollok (queryw, TRUE); + /* Set up the top-level windows */ + /* First line is the header */ + displayw = subwin(stdscr, 12, 0, 2, 0);/* Lines 2-13 */ + scrollok(displayw, TRUE); - dataw = subwin (stdscr, 5, 0, 17, 0);/* Lines 17-21 */ + queryw = subwin(stdscr, 1, 0, 15, 0);/* Line 15 */ + scrollok(queryw, TRUE); - /* Set up the data windows */ - fnamew = subwin (stdscr, 1, 0, 17, DESC_WIDTH); - midw = subwin (stdscr, 1, 0, 18, DESC_WIDTH); - lnamew = subwin (stdscr, 1, 0, 19, DESC_WIDTH); - idw = subwin (stdscr, 1, 0, 20, DESC_WIDTH); - loginw = subwin (stdscr, 1, 0, 21, DESC_WIDTH); + dataw = subwin(stdscr, 5, 0, 17, 0);/* Lines 17-21 */ + /* Set up the data windows */ + fnamew = subwin(stdscr, 1, 0, 17, DESC_WIDTH); + midw = subwin(stdscr, 1, 0, 18, DESC_WIDTH); + lnamew = subwin(stdscr, 1, 0, 19, DESC_WIDTH); + idw = subwin(stdscr, 1, 0, 20, DESC_WIDTH); + loginw = subwin(stdscr, 1, 0, 21, DESC_WIDTH); } /* Clear and restore the display */ -reset_display () { - clear (); - - /* Put back the borders */ - make_border (1); - make_border (14); - make_border (16); - make_border (22); - - - /* Put in the window dressing */ - wmove (dataw, 0, 0); - waddstr (dataw, "First Name:\n"); - waddstr (dataw, "Middle Initial:\n"); - waddstr (dataw, "Family Name:\n"); - waddstr (dataw, "MIT ID #:\n\n"); - waddstr (dataw, "Username:\n"); - wclrtoeol (dataw); - - /* Set up the header */ - mvaddstr (0, (COLS - strlen (HEADER)) / 2, HEADER); - mvaddstr (23, 0, HELP); - - /* Put it all up */ - refresh (); +reset_display(void) +{ + clear(); + + /* Put back the borders */ + make_border(1); + make_border(14); + make_border(16); + make_border(22); + + /* Put in the window dressing */ + wmove(dataw, 0, 0); + waddstr(dataw, "First Name:\n"); + waddstr(dataw, "Middle Initial:\n"); + waddstr(dataw, "Family Name:\n"); + waddstr(dataw, "MIT ID #:\n\n"); + waddstr(dataw, "Username:\n"); + wclrtoeol(dataw); + + /* Set up the header */ + mvaddstr(0, (COLS - strlen (HEADER)) / 2, HEADER); + mvaddstr(23, 0, HELP); + + /* Put it all up */ + refresh(); } /* Make a one-line border on line l of stdscr */ -make_border (l) -int l; +make_border(int l) { - int i; + int i; - move (l, 0); - for (i = 0; i < COLS - 1; i++) { - addch (BORDER_CHAR); - } + move(l, 0); + for(i = 0; i < COLS - 1; i++) + addch(BORDER_CHAR); } /* This replaces several "useful" display functions in the old userreg */ -redisp () { - mvwprintw (fnamew, 0, 0, "%-24s", user.u_first); +redisp(void) +{ + mvwprintw(fnamew, 0, 0, "%-24s", user.u_first); wrefresh(fnamew); - mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init); + mvwprintw(midw, 0, 0, "%-24s", user.u_mid_init); wrefresh(midw); - mvwprintw (lnamew, 0, 0, "%-24s", user.u_last); + mvwprintw(lnamew, 0, 0, "%-24s", user.u_last); wrefresh(lnamew); - mvwprintw (idw, 0, 0, "%-24s", typed_mit_id); + mvwprintw(idw, 0, 0, "%-24s", typed_mit_id); wrefresh(idw); - mvwprintw (loginw, 0, 0, "%-24s", user.u_login); + mvwprintw(loginw, 0, 0, "%-24s", user.u_login); wrefresh(loginw); } /* Input and input_no_echo exist only to save on retyping */ -input (prompt, buf, maxsize, timeout, emptyok) -char *prompt; -char *buf; -int maxsize, timeout, emptyok; +input(char *prompt, char *buf, int maxsize, int timeout, int emptyok) { - query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE); + query_user(prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE); } -input_no_echo (prompt, buf, maxsize, timeout) -char *prompt; -char *buf; -int maxsize, timeout; +input_no_echo(char *prompt, char *buf, int maxsize, int timeout) { - query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE); + query_user(prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE); } /* make the user press any key to continue */ -wait_for_user () +wait_for_user(void) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - redisp(); - query_user ("Press RETURN or ENTER to continue", buf, 1, - 15 * 60, FALSE, TRUE, FALSE); + redisp(); + query_user("Press RETURN or ENTER to continue", buf, 1, + 15 * 60, FALSE, TRUE, FALSE); } /* Gets input through the query buffer */ /* Exit(1)'s on read errors */ /* Signals SIGALRM after 'timeout' seconds */ -query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep) -char *prompt; -char *buf; -int maxsize, timeout; -int echop, emptyok, valuep; +query_user(char *prompt, char *buf, int maxsize, int timeout, + int echop, int emptyok, int valuep) { - int c; - int i; + int c; + int i; struct itimerval it; retry: @@ -177,206 +164,215 @@ retry: it.it_interval.tv_usec = 0; it.it_value.tv_sec = timeout; it.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &it, (struct itimerval *) 0); + setitimer(ITIMER_REAL, &it, NULL); /* Erase the query window and put up a prompt */ - werase (queryw); - mvwaddstr (queryw, 0, 0, prompt); - waddch (queryw, ' '); /* Put in a space, as Blox does */ - wrefresh (queryw); + werase(queryw); + mvwaddstr(queryw, 0, 0, prompt); + waddch(queryw, ' '); /* Put in a space, as Blox does */ + wrefresh(queryw); i = 0; - while ((c = getchar ()) != '\r' && c != '\n') { - switch (c) { - case '\025': /* Ctl-U */ - goto retry; - case EOF: - /* We're in raw mode, so EOF means disaster */ - exit(1); - break; - delchar: - case '\177': /* Delete */ - case '\010': /* Backspace */ - if (i) { - i--; - if (echop) { - int x, y; - getyx(queryw, y, x); - wmove (queryw, y, x - 1); - wclrtoeol (queryw); - wrefresh (queryw); - } + while ((c = getchar()) != '\r' && c != '\n') + { + switch (c) + { + case '\025': /* Ctl-U */ + goto retry; + case EOF: + /* We're in raw mode, so EOF means disaster */ + exit(1); + break; + delchar: + case '\177': /* Delete */ + case '\010': /* Backspace */ + if (i) + { + i--; + if (echop) + { + int x, y; + getyx(queryw, y, x); + wmove(queryw, y, x - 1); + wclrtoeol(queryw); + wrefresh(queryw); + } + } + break; + case '\003': /* Ctrl-C */ + clear(); + restore_display(); + exit(0); + break; + default: + if (c >= ' ') /* Ignore all other control chars */ + { + buf[i++] = c; + if (echop) + { + waddch(queryw, c); + wrefresh(queryw); + } + } + break; } - break; - case '\003': /* Ctrl-C */ - clear(); - restore_display(); - exit(0); - break; - default: - if (c >= ' ') { /* Ignore all other control chars */ - buf[i++] = c; - if (echop) { - waddch (queryw, c); - wrefresh (queryw); - } + if (valuep && i >= maxsize) + { + wfeep(); + wprintw(displayw, "You are not allowed to type more than %d " + "characters for this answer.\n", maxsize - 1); + wrefresh(displayw); + goto delchar; } - break; - } - if (valuep && i >= maxsize) { - wfeep(); - wprintw (displayw, - "You are not allowed to type more than %d characters for this answer.\n", - maxsize-1); - wrefresh (displayw); - goto delchar; } - } - if (i == 0) { + if (i == 0) + { if (emptyok && valuep && (askyn("Do you really want this field left blank (y/n)? ") == NO)) goto retry; - if (!emptyok) { + if (!emptyok) + { wprintw(displayw, "You must enter something here.\n"); wrefresh(displayw); goto retry; - } - } - + } + } + /* Input is complete so disable interval timer. */ it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 0; it.it_value.tv_sec = 0; it.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &it, (struct itimerval *) 0); + setitimer(ITIMER_REAL, &it, NULL); buf[i] = '\0'; /* Put a null on the end */ - werase (queryw); /* Clean up the query window */ - wrefresh (queryw); + werase(queryw); /* Clean up the query window */ + wrefresh(queryw); return; /* And get out of here. */ } -int -askyn(prompt) - char *prompt; +int askyn(char *prompt) { int ypos, xpos; int answer; struct itimerval it; int c; - start: - werase (queryw); - mvwaddstr (queryw, 0, 0, prompt); - wrefresh (queryw); +start: + werase(queryw); + mvwaddstr(queryw, 0, 0, prompt); + wrefresh(queryw); getyx(queryw, ypos, xpos); answer = 2; /* No answer. */ - + /* Reset interval timer for y/n question. */ it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 0; it.it_value.tv_sec = YN_TIMEOUT; it.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &it, (struct itimerval *) 0); - - while ((c = getchar ()) != '\r' && c != '\n') { /* Wait for CR. */ - switch (c) { - case 'n': /* No. */ - case 'N': - wmove(queryw, ypos, xpos); - wclrtoeol(queryw); - waddstr(queryw, "no"); - wrefresh(queryw); - answer = NO; - continue; - case 'y': /* Yes. */ - case 'Y': - wmove(queryw, ypos, xpos); - wclrtoeol(queryw); - waddstr(queryw, "yes"); - wrefresh(queryw); - answer = YES; - continue; - case '\177': /* Delete */ - case '\010': /* Backspace */ - case '\025': /* Ctl-U */ - wmove(queryw, ypos, xpos); - wclrtoeol(queryw); - wrefresh(queryw); - answer = 2; /* No answer. */ - break; - case EOF: - /* We're in raw mode, so EOF means disaster */ - exit(1); - break; - case '\003': /* Ctrl-C */ - clear(); - restore_display(); - exit(0); - break; - default: /* Ignore everything else. */ - break; - } + setitimer(ITIMER_REAL, &it, NULL); + + while ((c = getchar ()) != '\r' && c != '\n') /* Wait for CR. */ + { + switch (c) + { + case 'n': /* No. */ + case 'N': + wmove(queryw, ypos, xpos); + wclrtoeol(queryw); + waddstr(queryw, "no"); + wrefresh(queryw); + answer = NO; + continue; + case 'y': /* Yes. */ + case 'Y': + wmove(queryw, ypos, xpos); + wclrtoeol(queryw); + waddstr(queryw, "yes"); + wrefresh(queryw); + answer = YES; + continue; + case '\177': /* Delete */ + case '\010': /* Backspace */ + case '\025': /* Ctl-U */ + wmove(queryw, ypos, xpos); + wclrtoeol(queryw); + wrefresh(queryw); + answer = 2; /* No answer. */ + break; + case EOF: + /* We're in raw mode, so EOF means disaster */ + exit(1); + break; + case '\003': /* Ctrl-C */ + clear(); + restore_display(); + exit(0); + break; + default: /* Ignore everything else. */ + break; + } } if (answer == 2) /* No answer. */ - { display_text_line(0); + { + display_text_line(0); display_text_line("Please answer y or n."); goto start; } - - return(answer); + + return answer; } /* Display_text_line puts up a line of text in the display window */ /* Special case: if line is 0, clear the display area */ -display_text_line (line) -char *line; +display_text_line(char *line) { - if (line) { - waddstr (displayw, line); - waddch (displayw, '\n'); - } else { - werase (displayw); - } - wrefresh (displayw); + if (line) + { + waddstr(displayw, line); + waddch(displayw, '\n'); + } + else + werase(displayw); + wrefresh(displayw); } /* Display_text displays a canned message from a file. The string * will get imbedded in any %s's in the text. */ -display_text(filename, string) -char *filename; -char *string; +display_text(char *filename, char *string) { FILE * fp; - char buf[100], buf1[110]; + char buf[100], buf1[110]; - werase (displayw); - if ((fp = fopen (filename, "r")) == NULL) { - wprintw (displayw, "Can't open file %s for reading.\n", filename); - return; - } + werase(displayw); + if (!(fp = fopen (filename, "r"))) + { + wprintw (displayw, "Can't open file %s for reading.\n", filename); + return; + } - while (fgets (buf, 100, fp)) { + while (fgets (buf, 100, fp)) + { /* get rid of the newline */ - buf[strlen (buf) - 1] = 0; + buf[strlen(buf) - 1] = '\0'; sprintf(buf1, buf, string); waddstr(displayw, buf1); waddch(displayw, '\n'); - } + } wrefresh(displayw); - fclose (fp); + fclose(fp); } /* Clear_display wipes the display and turns off curses */ -restore_display() +restore_display(void) { clear(); refresh(); @@ -385,7 +381,7 @@ restore_display() endwin(); } -timer_on() +timer_on(void) { struct itimerval it; @@ -393,10 +389,10 @@ timer_on() it.it_interval.tv_usec = 0; it.it_value.tv_sec = TIMER_TIMEOUT; it.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &it, (struct itimerval *) 0); + setitimer(ITIMER_REAL, &it, NULL); } -timer_off() +timer_off(void) { struct itimerval it; @@ -404,12 +400,12 @@ timer_off() it.it_interval.tv_usec = 0; it.it_value.tv_sec = 0; it.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &it, (struct itimerval *) 0); + setitimer(ITIMER_REAL, &it, NULL); } -wfeep() +wfeep(void) { - char buf = '\007'; - write(1, &buf, 1); + char buf = '\007'; + write(1, &buf, 1); } diff --git a/clients/userreg/reg_stubs.c b/clients/userreg/reg_stubs.c index af7526b2..b5eaae96 100644 --- a/clients/userreg/reg_stubs.c +++ b/clients/userreg/reg_stubs.c @@ -18,9 +18,6 @@ static char *rcsid_reg_stubs_c = "$Header$"; #include #include #include -#ifdef _AIX_SOURCE -#include -#endif #include #include #include @@ -48,181 +45,185 @@ extern errno; #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1 << (n))) #endif /* FD_SET */ -ureg_init() +int ureg_init(void) { - struct servent *sp; - char **p, *s; - struct hostent *hp; - struct sockaddr_in s_in; - - initialize_ureg_error_table(); - initialize_krb_error_table(); - initialize_sms_error_table(); - initialize_kadm_error_table(); - - seq_no = getpid(); - - host = NULL; - host = getenv("REGSERVER"); + struct servent *sp; + char **p, *s; + struct hostent *hp; + struct sockaddr_in s_in; + + initialize_ureg_error_table(); + initialize_krb_error_table(); + initialize_sms_error_table(); + initialize_kadm_error_table(); + + seq_no = getpid(); + + host = NULL; + host = getenv("REGSERVER"); #ifdef HESIOD - if (!host || (strlen(host) == 0)) { - p = hes_resolve("registration", "sloc"); - if (p) host = *p; + if (!host || (strlen(host) == 0)) + { + p = hes_resolve("registration", "sloc"); + if (p) + host = *p; } #endif - if (!host || (strlen(host) == 0)) { - host = strsave(MOIRA_SERVER); - s = strchr(host, ':'); - if (s) *s = 0; + if (!host || (strlen(host) == 0)) + { + host = strsave(MOIRA_SERVER); + s = strchr(host, ':'); + if (s) + *s = '\0'; } - hp = gethostbyname(host); - host = strsave(hp->h_name); - if (hp == NULL) return UNKNOWN_HOST; + hp = gethostbyname(host); + host = strsave(hp->h_name); + if (hp == NULL) + return UNKNOWN_HOST; - sp = getservbyname("sms_ureg", "udp"); + sp = getservbyname("sms_ureg", "udp"); - if (sp == NULL) return UNKNOWN_SERVICE; - - (void) close(reg_sock); - reg_sock = socket(AF_INET, SOCK_DGRAM, 0); - if (reg_sock < 0) return errno; + if (sp == NULL) + return UNKNOWN_SERVICE; - memset((char *)&s_in, 0, sizeof(s_in)); - s_in.sin_port = sp->s_port; - memcpy((char *)&s_in.sin_addr, hp->h_addr, sizeof(struct in_addr)); - s_in.sin_family = AF_INET; + close(reg_sock); + reg_sock = socket(AF_INET, SOCK_DGRAM, 0); + if (reg_sock < 0) + return errno; - if (connect(reg_sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) - return errno; - return 0; + memset(&s_in, 0, sizeof(s_in)); + s_in.sin_port = sp->s_port; + memcpy(&s_in.sin_addr, hp->h_addr, sizeof(struct in_addr)); + s_in.sin_family = AF_INET; + + if (connect(reg_sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) + return errno; + return 0; } -int -verify_user(first, last, idnumber, hashidnumber, login) - char *first, *last, *idnumber, *hashidnumber, *login; +int verify_user(char *first, char *last, char *idnumber, + char *hashidnumber, char *login) { - char buf[1024]; - int version = ntohl((u_long)1); - int call = ntohl((u_long)UREG_VERIFY_USER); - des_cblock key; - des_key_schedule ks; - register char *bp = buf; - register int len; - char crypt_src[1024]; - - memcpy(bp, (char *)&version, sizeof(int)); - bp += sizeof(int); - seq_no++; - memcpy(bp, (char *)&seq_no, sizeof(int)); - - bp += sizeof(int); - - memcpy(bp, (char *)&call, sizeof(int)); - - bp += sizeof(int); - - (void) strcpy(bp, first); - bp += strlen(bp)+1; - - (void) strcpy(bp, last); - bp += strlen(bp)+1; - - len = strlen(idnumber) + 1; - memcpy(crypt_src, idnumber, len); - - memcpy(crypt_src+len, hashidnumber, 13); - - des_string_to_key(hashidnumber, key); - des_key_sched(key, ks); - des_pcbc_encrypt(crypt_src, bp, len+13, ks, key, DES_ENCRYPT); - bp += len+14+8; - len = bp - buf; - return do_call(buf, len, seq_no, login); + char buf[1024]; + int version = ntohl((u_long)1); + int call = ntohl((u_long)UREG_VERIFY_USER); + des_cblock key; + des_key_schedule ks; + register char *bp = buf; + register int len; + char crypt_src[1024]; + + memcpy(bp, &version, sizeof(int)); + bp += sizeof(int); + seq_no++; + memcpy(bp, &seq_no, sizeof(int)); + + bp += sizeof(int); + + memcpy(bp, &call, sizeof(int)); + + bp += sizeof(int); + + strcpy(bp, first); + bp += strlen(bp) + 1; + + strcpy(bp, last); + bp += strlen(bp) + 1; + + len = strlen(idnumber) + 1; + memcpy(crypt_src, idnumber, len); + + memcpy(crypt_src + len, hashidnumber, 13); + + des_string_to_key(hashidnumber, key); + des_key_sched(key, ks); + des_pcbc_encrypt(crypt_src, bp, len + 13, ks, key, DES_ENCRYPT); + bp += len + 14 + 8; + len = bp - buf; + return do_call(buf, len, seq_no, login); } -do_operation(first, last, idnumber, hashidnumber, data, opcode) - char *first, *last, *idnumber, *hashidnumber, *data; - u_long opcode; +int do_operation(char *first, char *last, char *idnumber, char *hashidnumber, + char *data, u_long opcode) { - char buf[1024]; - int version = ntohl((u_long)1); - int call = ntohl(opcode); - des_cblock key; - des_key_schedule ks; - register char *bp = buf; - register int len; - - char crypt_src[1024]; - char *cbp; - - memcpy(bp, (char *)&version, sizeof(int)); - bp += sizeof(int); - seq_no++; - memcpy(bp, (char *)&seq_no, sizeof(int)); - - bp += sizeof(int); - - memcpy(bp, (char *)&call, sizeof(int)); - - bp += sizeof(int); - - (void) strcpy(bp, first); - bp += strlen(bp)+1; - - (void) strcpy(bp, last); - bp += strlen(bp)+1; - - len = strlen(idnumber) + 1; - cbp = crypt_src; - - memcpy(crypt_src, idnumber, len); - cbp += len; - - memcpy(cbp, hashidnumber, 14); - cbp += 14; - - len = strlen(data) + 1; - memcpy(cbp, data, len); - cbp += len; - - len = cbp - crypt_src; - des_string_to_key(hashidnumber, key); - des_key_sched(key, ks); - des_pcbc_encrypt(crypt_src, bp, len, ks, key, 1); - len = ((len + 7) >> 3) << 3; - bp += len; - - len = bp - buf; - return do_call(buf, len, seq_no, 0); + char buf[1024]; + int version = ntohl((u_long)1); + int call = ntohl(opcode); + des_cblock key; + des_key_schedule ks; + register char *bp = buf; + register int len; + + char crypt_src[1024]; + char *cbp; + + memcpy(bp, &version, sizeof(int)); + bp += sizeof(int); + seq_no++; + memcpy(bp, &seq_no, sizeof(int)); + + bp += sizeof(int); + + memcpy(bp, &call, sizeof(int)); + + bp += sizeof(int); + + strcpy(bp, first); + bp += strlen(bp) + 1; + + strcpy(bp, last); + bp += strlen(bp) + 1; + len = strlen(idnumber) + 1; + cbp = crypt_src; + + memcpy(crypt_src, idnumber, len); + cbp += len; + + memcpy(cbp, hashidnumber, 14); + cbp += 14; + + len = strlen(data) + 1; + memcpy(cbp, data, len); + cbp += len; + + len = cbp - crypt_src; + des_string_to_key(hashidnumber, key); + des_key_sched(key, ks); + des_pcbc_encrypt(crypt_src, bp, len, ks, key, 1); + len = ((len + 7) >> 3) << 3; + bp += len; + + len = bp - buf; + return do_call(buf, len, seq_no, 0); } -grab_login(first, last, idnumber, hashidnumber, login) - char *first, *last, *idnumber, *hashidnumber, *login; +int grab_login(char *first, char *last, char *idnumber, char *hashidnumber, + char *login) { - return(do_operation(first, last, idnumber, hashidnumber, login, - UREG_RESERVE_LOGIN)); + return do_operation(first, last, idnumber, hashidnumber, login, + UREG_RESERVE_LOGIN); } -enroll_login(first, last, idnumber, hashidnumber, login) - char *first, *last, *idnumber, *hashidnumber, *login; +int enroll_login(char *first, char *last, char *idnumber, char *hashidnumber, + char *login) { - return(do_operation(first, last, idnumber, hashidnumber, login, - UREG_SET_IDENT)); + return do_operation(first, last, idnumber, hashidnumber, login, + UREG_SET_IDENT); } -set_password(first, last, idnumber, hashidnumber, password) - char *first, *last, *idnumber, *hashidnumber, *password; +int set_password(char *first, char *last, char *idnumber, char *hashidnumber, + char *password) { - return(do_operation(first, last, idnumber, hashidnumber, password, - UREG_SET_PASSWORD)); + return do_operation(first, last, idnumber, hashidnumber, password, + UREG_SET_PASSWORD); } -get_krb(first, last, idnumber, hashidnumber, password) - char *first, *last, *idnumber, *hashidnumber, *password; +int get_krb(char *first, char *last, char *idnumber, char *hashidnumber, + char *password) { - return(do_operation(first, last, idnumber, hashidnumber, password, - UREG_GET_KRB)); + return do_operation(first, last, idnumber, hashidnumber, password, + UREG_GET_KRB); } @@ -237,173 +238,159 @@ get_krb(first, last, idnumber, hashidnumber, password) * of failure codes. */ -do_secure_operation(login, idnumber, passwd, newpasswd, opcode) - char *login, *idnumber, *passwd, *newpasswd; - u_long opcode; +int do_secure_operation(char *login, char *idnumber, char *passwd, + char *newpasswd, u_long opcode) { - char buf[1500], data[128], tktstring[128]; - int version = ntohl((u_long)1); - int call = ntohl(opcode); - char inst[INST_SZ], hosti[INST_SZ]; - char *bp = buf, *src, *dst, *realm; - int len, status, i; - KTEXT_ST cred; - CREDENTIALS creds; - Key_schedule keys; - char *krb_get_phost(), *krb_realmofhost(); -#ifdef POSIX - memmove(bp, (char *)&version, sizeof(int)); -#else - bcopy((char *)&version, bp, sizeof(int)); -#endif - bp += sizeof(int); - seq_no++; -#ifdef POSIX - memmove(bp, (char *)&seq_no, sizeof(int)); -#else - bcopy((char *)&seq_no, bp, sizeof(int)); -#endif - - bp += sizeof(int); -#ifdef POSIX - memmove(bp, (char *)&call, sizeof(int)); -#else - bcopy((char *)&call, bp, sizeof(int)); -#endif - - bp += sizeof(int); - - /* put the login name in the firstname field */ - (void) strcpy(bp, login); - bp += strlen(bp)+1; - - /* the old lastname field */ - (void) strcpy(bp, ""); - bp += strlen(bp)+1; - - /* don't overwrite existing ticket file */ - (void) sprintf(tktstring, "/tmp/tkt_cpw_%d",getpid()); - krb_set_tkt_string(tktstring); - - /* get realm and canonizalized hostname of server */ - realm = krb_realmofhost(host); - for (src = host, dst = hosti; *src && *src != '.'; src++) + char buf[1500], data[128], tktstring[128]; + int version = ntohl((u_long)1); + int call = ntohl(opcode); + char inst[INST_SZ], hosti[INST_SZ]; + char *bp = buf, *src, *dst, *realm; + int len, status, i; + KTEXT_ST cred; + CREDENTIALS creds; + Key_schedule keys; + char *krb_get_phost(), *krb_realmofhost(); + + memmove(bp, &version, sizeof(int)); + bp += sizeof(int); + seq_no++; + memmove(bp, &seq_no, sizeof(int)); + + bp += sizeof(int); + memmove(bp, &call, sizeof(int)); + + bp += sizeof(int); + + /* put the login name in the firstname field */ + strcpy(bp, login); + bp += strlen(bp) + 1; + + /* the old lastname field */ + strcpy(bp, ""); + bp += strlen(bp) + 1; + + /* don't overwrite existing ticket file */ + sprintf(tktstring, "/tmp/tkt_cpw_%d", getpid()); + krb_set_tkt_string(tktstring); + + /* get realm and canonizalized hostname of server */ + realm = krb_realmofhost(host); + for (src = host, dst = hosti; *src && *src != '.'; src++) + { if (isupper(*src)) *dst++ = tolower(*src); else *dst++ = *src; - *dst = 0; - inst[0] = 0; - - /* get changepw tickets. We use this service because it's the - * only one that guarantees we used the password rather than a - * ticket granting ticket. - */ - status = krb_get_pw_in_tkt(login, inst, realm, - "changepw", hosti, 5, passwd); - if (status) return (status + krb_err_base); - - status = krb_mk_req(&cred, "changepw", hosti, realm, 0); - if (status) return (status + krb_err_base); - - /* round up to word boundry */ - bp = (char *)((((u_long)bp)+3)&0xfffffffc); - - /* put the ticket in the packet */ - len = cred.length; - cred.length = htonl(cred.length); -#ifdef POSIX - memmove(bp, &(cred), sizeof(int)+len); -#else - bcopy(&(cred), bp, sizeof(int)+len); -#endif -#ifdef DEBUG - com_err("test", 0, "Cred: length %d", len); - for (i = 0; i < len; i += 16) - com_err("test", 0, " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - cred.dat[i+0], cred.dat[i+1], cred.dat[i+2], cred.dat[i+3], - cred.dat[i+4], cred.dat[i+5], cred.dat[i+6], cred.dat[i+7], - cred.dat[i+8], cred.dat[i+9], cred.dat[i+10], cred.dat[i+11], - cred.dat[i+12], cred.dat[i+13], cred.dat[i+14], cred.dat[i+15]); -#endif /* DEBUG */ - bp += sizeof(int) + len; - - /* encrypt the data in the session key */ - sprintf(data, "%s,%s", idnumber, newpasswd); - len = strlen(data); - len = ((len + 7) >> 3) << 3; - - status = krb_get_cred("changepw", hosti, realm, &creds); - if (status) { - memset(data, 0, strlen(data)); - return (status + krb_err_base); } - dest_tkt(); + *dst = '\0'; + inst[0] = '\0'; + + /* get changepw tickets. We use this service because it's the + * only one that guarantees we used the password rather than a + * ticket granting ticket. + */ + status = krb_get_pw_in_tkt(login, inst, realm, "changepw", hosti, 5, passwd); + if (status) + return status + krb_err_base; + + status = krb_mk_req(&cred, "changepw", hosti, realm, 0); + if (status) + return status + krb_err_base; + + /* round up to word boundry */ + bp = (char *)((((u_long)bp) + 3) & 0xfffffffc); + + /* put the ticket in the packet */ + len = cred.length; + cred.length = htonl(cred.length); + memmove(bp, &(cred), sizeof(int) + len); + bp += sizeof(int) + len; + + /* encrypt the data in the session key */ + sprintf(data, "%s,%s", idnumber, newpasswd); + len = strlen(data); + len = ((len + 7) >> 3) << 3; + + status = krb_get_cred("changepw", hosti, realm, &creds); + if (status) + { + memset(data, 0, strlen(data)); + return status + krb_err_base; + } + dest_tkt(); - des_key_sched(creds.session, keys); - des_pcbc_encrypt(data, bp + sizeof(int), len, keys, creds.session, 1); - *((int *)bp) = htonl(len); - memset(data, 0, strlen(data)); + des_key_sched(creds.session, keys); + des_pcbc_encrypt(data, bp + sizeof(int), len, keys, creds.session, 1); + *((int *)bp) = htonl(len); + memset(data, 0, strlen(data)); - bp += len + sizeof(int); - - len = bp - buf; - return do_call(buf, len, seq_no, 0); + bp += len + sizeof(int); + len = bp - buf; + return do_call(buf, len, seq_no, 0); } -do_call(buf, len, seq_no, login) - char *buf; - char *login; - int seq_no; - int len; +int do_call(char *buf, int len, int seq_no, char *login) { - struct timeval timeout; - char ibuf[1024]; - fd_set set; - - int retry = 0; - - do { - if (write(reg_sock, buf, len) != len) return errno; - - FD_ZERO(&set); - FD_SET(reg_sock, &set); - timeout.tv_sec = 30; - timeout.tv_usec = 0; - do { - int rtn; - struct sockaddr_in s_in; - int addrlen = sizeof(s_in); - int vno; - int sno; - int stat; - - rtn = select(reg_sock+1, &set, (fd_set *)0, (fd_set *)0, &timeout); - if (rtn == 0) - break; - else if (rtn < 0) return errno; - - len = recvfrom(reg_sock, ibuf, BUFSIZ, 0, - (struct sockaddr *)&s_in, &addrlen); - if (len < 0) return errno; - if (len < 12) return UREG_BROKEN_PACKET; - memcpy((char *)&vno, ibuf, sizeof(long)); - vno = ntohl((u_long)vno); - if (vno != 1) continue; - memcpy((char *)&sno, ibuf + 4, sizeof(long)); - - if (sno != seq_no) continue; - - memcpy((char *)&stat, ibuf + 8, sizeof(long)); - stat = ntohl((u_long)stat); - if (login && len > 12) { - memcpy(login, ibuf+12, len-12); - login[len-12] = '\0'; - } else if (login) - *login = '\0'; - return stat; - } while (1); - } while (++retry < 10); - return ETIMEDOUT; -} + struct timeval timeout; + char ibuf[1024]; + fd_set set; + + int retry = 0; + + do + { + if (write(reg_sock, buf, len) != len) + return errno; + + FD_ZERO(&set); + FD_SET(reg_sock, &set); + timeout.tv_sec = 30; + timeout.tv_usec = 0; + do + { + int rtn; + struct sockaddr_in s_in; + int addrlen = sizeof(s_in); + int vno; + int sno; + int stat; + + rtn = select(reg_sock + 1, &set, NULL, NULL, &timeout); + if (rtn == 0) + break; + else if (rtn < 0) + return errno; + + len = recvfrom(reg_sock, ibuf, BUFSIZ, 0, + (struct sockaddr *)&s_in, &addrlen); + if (len < 0) + return errno; + if (len < 12) + return UREG_BROKEN_PACKET; + memcpy(&vno, ibuf, sizeof(long)); + vno = ntohl((u_long)vno); + if (vno != 1) + continue; + memcpy(&sno, ibuf + 4, sizeof(long)); + + if (sno != seq_no) + continue; + + memcpy(&stat, ibuf + 8, sizeof(long)); + stat = ntohl((u_long)stat); + if (login && len > 12) + { + memcpy(login, ibuf + 12, len - 12); + login[len - 12] = '\0'; + } + else if (login) + *login = '\0'; + return stat; + } + while (1); + } + while (++retry < 10); + return ETIMEDOUT; +} diff --git a/clients/userreg/register b/clients/userreg/register index ce7b759b..a368040e 100644 --- a/clients/userreg/register +++ b/clients/userreg/register @@ -1,4 +1,4 @@ -#!/bin/csh -f +#!/bin/csh -f set machtype=`machtype` diff --git a/clients/userreg/userreg.c b/clients/userreg/userreg.c index 7afbe2ed..8a9cb199 100644 --- a/clients/userreg/userreg.c +++ b/clients/userreg/userreg.c @@ -52,308 +52,323 @@ char typed_mit_id[100]; fix_display(sig) { -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) SIG_IGN; - sigaction(sig, &act, NULL); -#else - signal(sig, SIG_IGN); /* let us clean up, please */ -#endif - noraw(); - echo(); - endwin(); - exit(1); + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + sigaction(sig, &act, NULL); + noraw(); + echo(); + endwin(); + exit(1); } -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - register int ntimes; - register int reencrypt; - char line[100], *when, *msg; - int status; - char tmpfirst[100], tmplast[100], tmpmid[100]; -#ifdef POSIX - struct sigaction act; -#endif - - status = ureg_init(); - if (status) { - com_err(argv[0], status, "while trying to initialize"); - exit(1); - } - - if (when = disabled(&msg)) { - printf("We're sorry, the registration service is unavailable right now\n"); - if (msg) - printf("because %s\n", msg); - printf("You should be able to register after %s", when); - printf("\nPress ENTER or RETURN to continue "); - fflush(stdout); - getchar(); - exit(0); - } - - /* stash the realm for later use */ - if ((status = krb_get_lrealm(realm, 1)) != KSUCCESS) { - printf("System error; please try another workstation."); - exit(1); - } - - setup_display(); - -#ifdef POSIX - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGINT, &act, NULL); - sigaction(SIGQUIT, &act, NULL); - sigaction(SIGHUP, &act, NULL); -#else - signal(SIGINT, fix_display); - signal(SIGQUIT, fix_display); - signal(SIGHUP, fix_display); -#endif + register int ntimes; + register int reencrypt; + char line[100], *when, *msg; + int status; + char tmpfirst[100], tmplast[100], tmpmid[100]; + struct sigaction act; + + status = ureg_init(); + if (status) + { + com_err(argv[0], status, "while trying to initialize"); + exit(1); + } - while (1) { - setjmp(redo); - reset(); - ntimes = 0; + if (when = disabled(&msg)) + { + printf("We're sorry, the registration service is unavailable right now\n"); + if (msg) + printf("because %s\n", msg); + printf("You should be able to register after %s", when); + printf("\nPress ENTER or RETURN to continue "); + fflush(stdout); + getchar(); + exit(0); + } - display_text(WELCOME, ""); + /* stash the realm for later use */ + if ((status = krb_get_lrealm(realm, 1)) != KSUCCESS) + { + printf("System error; please try another workstation."); + exit(1); + } - gfirst(); - gmi(); - glast(); - strcpy(tmpfirst, user.u_first); - strcpy(tmplast, user.u_last); - FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid); - redisp(); - - gmitid(); - - while (dolook()) { - ntimes++; - if (ntimes > 3) { - display_text_line(0); - display_text_line("Sorry, you still cannot be found in the database."); - display_text_line(" "); - display_text_line("Please call an accounts consultant at x3-1325 for help."); - wait_for_user(); - break; - } - display_text_line(0); /* clear the window */ - display_text_line("You could not be found in the database."); - display_text_line("Do you want to change some input (for example, the spelling"); - display_text_line("of part of your name) and try again?"); - if (askyn("Do you want to try again ? ") == YES) { - reencrypt = 0; - display_text_line(0); - sprintf(line, - "You entered your first name as \"%s\"", user.u_first); - display_text_line(line); - if (askyn("Do you want to change it? ") == YES) { - gfirst(); - strcpy(tmpfirst, user.u_first); - strcpy(tmplast, user.u_last); - FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid); - redisp(); - reencrypt = 1; - } - display_text_line(0); - sprintf(line, - "You entered your middle initial as \"%s\"", user.u_mid_init); - display_text_line(line); - if (askyn("Do you want to change it? ") == YES) - gmi(); - display_text_line(0); - sprintf(line, - "You entered your family name as \"%s\"", user.u_last); - display_text_line(line); - if (askyn("Do you want to change it? ") == YES) { - glast(); - strcpy(tmpfirst, user.u_first); - strcpy(tmplast, user.u_last); - FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid); - redisp(); - reencrypt = 1; - } - display_text_line(0); - sprintf(line, - "You entered your MIT id number as \"%s\"", typed_mit_id); - display_text_line(line); - if (askyn("Do you want to change it? ") == YES) { - gmitid(); - reencrypt = 0; - } - if (reencrypt) { - EncryptID(user.u_mit_id, typed_mit_id, - user.u_first, user.u_last); - } - } else - break; + setup_display(); + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGINT, &act, NULL); + sigaction(SIGQUIT, &act, NULL); + sigaction(SIGHUP, &act, NULL); + + while (1) + { + setjmp(redo); + reset(); + ntimes = 0; + + display_text(WELCOME, ""); + + gfirst(); + gmi(); + glast(); + strcpy(tmpfirst, user.u_first); + strcpy(tmplast, user.u_last); + FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid); + redisp(); + + gmitid(); + + while (dolook()) + { + ntimes++; + if (ntimes > 3) + { + display_text_line(0); + display_text_line("Sorry, you still cannot be found in the database."); + display_text_line(" "); + display_text_line("Please call an accounts consultant at x3-1325 for help."); + wait_for_user(); + break; + } + display_text_line(0); /* clear the window */ + display_text_line("You could not be found in the database."); + display_text_line("Do you want to change some input " + "(for example, the spelling"); + display_text_line("of part of your name) and try again?"); + if (askyn("Do you want to try again ? ") == YES) + { + reencrypt = 0; + display_text_line(0); + sprintf(line, "You entered your first name as \"%s\"", + user.u_first); + display_text_line(line); + if (askyn("Do you want to change it? ") == YES) + { + gfirst(); + strcpy(tmpfirst, user.u_first); + strcpy(tmplast, user.u_last); + FixName(tmplast, tmpfirst, user.u_last, user.u_first, + tmpmid); + redisp(); + reencrypt = 1; } - if (!user_is_valid || already_registered) { - qexit(); - continue; - } - redisp(); - if (!user_has_login) { - if (negotiate_login() == -1) { - qexit(); - continue; - } + display_text_line(0); + sprintf(line, "You entered your middle initial as \"%s\"", + user.u_mid_init); + display_text_line(line); + if (askyn("Do you want to change it? ") == YES) + gmi(); + display_text_line(0); + sprintf(line, "You entered your family name as \"%s\"", + user.u_last); + display_text_line(line); + if (askyn("Do you want to change it? ") == YES) + { + glast(); + strcpy(tmpfirst, user.u_first); + strcpy(tmplast, user.u_last); + FixName(tmplast, tmpfirst, user.u_last, user.u_first, + tmpmid); + redisp(); + reencrypt = 1; } - if (negotiate_passwd() == -1) { - qexit(); - continue; + display_text_line(0); + sprintf(line, "You entered your MIT id number as \"%s\"", + typed_mit_id); + display_text_line(line); + if (askyn("Do you want to change it? ") == YES) + { + gmitid(); + reencrypt = 0; } - sleep(1); - if (!enrollment) - display_text(FINISHED, user.u_login); - else { - display_text(FINISHEDE, user.u_login); - if (askyn("Do you wish to set your mailbox now? (Yes or No) ")) { - clear(); - refresh(); - noraw(); - echo(); - kinit(user.u_login, user.u_password); - system(NAMESPACE_PROG); - dest_tkt(); - qexit(); - exit(0); - } + if (reencrypt) + { + EncryptID(user.u_mit_id, typed_mit_id, + user.u_first, user.u_last); } - wait_for_user(); - qexit(); - break; + } + else + break; } - restore_display(); - exit(0); + if (!user_is_valid || already_registered) + { + qexit(); + continue; + } + redisp(); + if (!user_has_login) + { + if (negotiate_login() == -1) + { + qexit(); + continue; + } + } + if (negotiate_passwd() == -1) + { + qexit(); + continue; + } + sleep(1); + if (!enrollment) + display_text(FINISHED, user.u_login); + else + { + display_text(FINISHEDE, user.u_login); + if (askyn("Do you wish to set your mailbox now? (Yes or No) ")) + { + clear(); + refresh(); + noraw(); + echo(); + kinit(user.u_login, user.u_password); + system(NAMESPACE_PROG); + dest_tkt(); + qexit(); + exit(0); + } + } + wait_for_user(); + qexit(); + break; + } + restore_display(); + exit(0); } -reset() +reset(void) { - reset_display(); - memset(&user, 0, sizeof(user)); - user_is_valid = 0; - already_registered = 0; - enrollment = 0; - redisp(); + reset_display(); + memset(&user, 0, sizeof(user)); + user_is_valid = 0; + already_registered = 0; + enrollment = 0; + redisp(); } -dolook() +int dolook(void) { - /* do the database lookup */ + /* do the database lookup */ - char line[100]; - register int result; - if (user_is_valid) { - /* !! */ - return (0); - } - display_text_line(0); - display_text_line("Looking you up in the database.... This may take from a few seconds to a few"); - display_text_line("minutes, depending on how busy the system is at the moment."); - - timer_off(); - result = verify_user(user.u_first, user.u_last, - typed_mit_id, user.u_mit_id, db_user.u_login); - wfeep(); - display_text_line(0); - timer_on(); - switch(result) { - case 0: - case UREG_ENROLLED: - display_text_line("You have been located in the user registration database."); - user_is_valid = 1; - user_has_login = 0; - sleep(1); - return 0; - case UREG_HALF_ENROLLED: - enrollment = 1; - /* fall through to: */ - case UREG_NO_PASSWD_YET: - user_is_valid = 1; - user_has_login = 1; - display_text_line ("You have chosen a login name, but you have not yet chosen a password."); - sprintf(line, "Remember: the username you chose was '%s'", - db_user.u_login); - strcpy(user.u_login, db_user.u_login); - display_text_line(line); - redisp(); - sleep(5); - return (0); - - case UREG_ALREADY_REGISTERED: - already_registered = 1; - /* - * we have to reset this so we dont ask for a - * new username - */ - user_is_valid = 0; - display_text_line("You are already registered. An account for you probably already exists"); - display_text_line("(if not, it will appear within 24 hours)."); - display_text_line(""); - display_text_line("Refer to the document 'Working on Athena' for help logging in."); - strcpy(user.u_login, db_user.u_login); - sprintf(line, "Remember, the username you chose was '%s'", - db_user.u_login); - display_text_line(line); - redisp(); - wait_for_user(); - return (0); - case UREG_DELETED: - display_text(DELETED_ACCT, db_user.u_login); - wait_for_user(); - restore_display(); - exit(0); - case UREG_NOT_ALLOWED: - display_text(OFFER_ENROLL, db_user.u_login); - redisp(); - if (!askyn("Continue choosing a name and password (Y/N)? ")) { - already_registered = 1; - return(0); - } - user_has_login = 0; - user_is_valid = 1; - enrollment = 1; - return(0); - case UREG_ENROLL_NOT_ALLOWED: - display_text(NOT_ALLOWED, db_user.u_login); - wait_for_user(); - restore_display(); - exit(0); - case UREG_KRB_TAKEN: - display_text(IMPROPER_LOGIN, db_user.u_login); - wait_for_user(); - return(0); - case UREG_USER_NOT_FOUND: - return (1); - - case ECONNREFUSED: - case ETIMEDOUT: - case UREG_MISC_ERROR: - display_text(NETWORK_DOWN, db_user.u_login); - display_text_line(" "); - sprintf(line, "The specific error was: %s", - error_message(result)); - display_text_line(line); - wait_for_user(); - return (0); - - default: - display_text_line("An unexpected error occurred while trying to access the database"); - display_text_line(error_message(result)); - redisp(); - wait_for_user(); - return(1); + char line[100]; + register int result; + + if (user_is_valid) + { + /* !! */ + return 0; + } + display_text_line(0); + display_text_line("Looking you up in the database.... " + "This may take from a few seconds to a few"); + display_text_line("minutes, depending on how busy the system is " + "at the moment."); + + timer_off(); + result = verify_user(user.u_first, user.u_last, typed_mit_id, + user.u_mit_id, db_user.u_login); + wfeep(); + display_text_line(0); + timer_on(); + switch(result) + { + case 0: + case UREG_ENROLLED: + display_text_line("You have been located in the user registration database."); + user_is_valid = 1; + user_has_login = 0; + sleep(1); + return 0; + case UREG_HALF_ENROLLED: + enrollment = 1; + /* fall through to: */ + case UREG_NO_PASSWD_YET: + user_is_valid = 1; + user_has_login = 1; + display_text_line ("You have chosen a login name, but you have not yet chosen a password."); + sprintf(line, "Remember: the username you chose was '%s'", + db_user.u_login); + strcpy(user.u_login, db_user.u_login); + display_text_line(line); + redisp(); + sleep(5); + return 0; + + case UREG_ALREADY_REGISTERED: + already_registered = 1; + /* + * we have to reset this so we dont ask for a + * new username + */ + user_is_valid = 0; + display_text_line("You are already registered. " + "An account for you probably already exists"); + display_text_line("(if not, it will appear within 24 hours)."); + display_text_line(""); + display_text_line("Refer to the document 'Working on Athena' " + "for help logging in."); + strcpy(user.u_login, db_user.u_login); + sprintf(line, "Remember, the username you chose was '%s'", + db_user.u_login); + display_text_line(line); + redisp(); + wait_for_user(); + return 0; + case UREG_DELETED: + display_text(DELETED_ACCT, db_user.u_login); + wait_for_user(); + restore_display(); + exit(0); + case UREG_NOT_ALLOWED: + display_text(OFFER_ENROLL, db_user.u_login); + redisp(); + if (!askyn("Continue choosing a name and password (Y/N)? ")) + { + already_registered = 1; + return 0; } + user_has_login = 0; + user_is_valid = 1; + enrollment = 1; + return 0; + case UREG_ENROLL_NOT_ALLOWED: + display_text(NOT_ALLOWED, db_user.u_login); + wait_for_user(); + restore_display(); + exit(0); + case UREG_KRB_TAKEN: + display_text(IMPROPER_LOGIN, db_user.u_login); + wait_for_user(); + return 0; + case UREG_USER_NOT_FOUND: + return 1; + + case ECONNREFUSED: + case ETIMEDOUT: + case UREG_MISC_ERROR: + display_text(NETWORK_DOWN, db_user.u_login); + display_text_line(" "); + sprintf(line, "The specific error was: %s", error_message(result)); + display_text_line(line); + wait_for_user(); + return 0; + + default: + display_text_line("An unexpected error occurred while trying to " + "access the database"); + display_text_line(error_message(result)); + redisp(); + wait_for_user(); + return 1; + } } @@ -362,413 +377,420 @@ dolook() * message, get confirmation, register name. */ -negotiate_login() +int negotiate_login(void) { - int result, i; - char line[100], old_login[LOGIN_SIZE+2]; - char *error, *cp; - - /* build suggested username */ - cp = user.u_login; - if (isalpha(user.u_first[0])) - *cp++ = user.u_first[0]; - if (isalpha(user.u_mid_init[0])) - *cp++ = user.u_mid_init[0]; - for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++) + int result, i; + char line[100], old_login[LOGIN_SIZE + 2]; + char *error, *cp; + + /* build suggested username */ + cp = user.u_login; + if (isalpha(user.u_first[0])) + *cp++ = user.u_first[0]; + if (isalpha(user.u_mid_init[0])) + *cp++ = user.u_mid_init[0]; + for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++) + { if (isalpha(user.u_last[i])) *cp++ = user.u_last[i]; - for (i=0; user.u_login[i]; i++) + } + for (i = 0; user.u_login[i]; i++) + { if (isupper(user.u_login[i])) - user.u_login[i]=tolower(user.u_login[i]); - strcpy(old_login, user.u_login); - - /* print message */ - display_text(USERNAME_BLURB, user.u_login); - - again: - /* get name from user */ - glogin(); - - display_text_line(0); - display_text_line("Testing that username..."); - error = ""; - if (strlen(user.u_login) < 3) - error = "Your username must be at least 3 characters long."; - else if (strlen(user.u_login) > 8) - error = "Your username cannot be longer than 8 characters."; - else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0])) - error = "Your username must start with a lowercase letter."; - else for (i = 1; i < strlen(user.u_login); i++) - if (!islower(user.u_login[i]) && - !isdigit(user.u_login[i]) && - user.u_login[i] != '_') - error = "Your username must contain only lower case letters, numbers, and underscore"; - timer_off(); - result = krb_get_pw_in_tkt(user.u_login, "", realm, - "krbtgt", realm, 1, ""); - timer_on(); - if (*error == 0 && result != KDC_PR_UNKNOWN) - error = "That username is already taken."; - - /* if it's bad, get another name from user */ - if (*error) { - strcpy(user.u_login, old_login); - redisp(); - display_text_line(error); - display_text_line("Please choose another username."); - goto again; + user.u_login[i] = tolower(user.u_login[i]); } - - /* name is OK, make sure */ - display_text(USERNAME_BLURB2, user.u_login); - if (!askyn("Do you want to register this username? (Yes or No) ")) + strcpy(old_login, user.u_login); + + /* print message */ + display_text(USERNAME_BLURB, user.u_login); + +again: + /* get name from user */ + glogin(); + + display_text_line(0); + display_text_line("Testing that username..."); + error = ""; + if (strlen(user.u_login) < 3) + error = "Your username must be at least 3 characters long."; + else if (strlen(user.u_login) > 8) + error = "Your username cannot be longer than 8 characters."; + else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0])) + error = "Your username must start with a lowercase letter."; + else + for (i = 1; i < strlen(user.u_login); i++) + { + if (!islower(user.u_login[i]) && + !isdigit(user.u_login[i]) && + user.u_login[i] != '_') + error = "Your username must contain only lower case letters, " + "numbers, and underscore"; + } + timer_off(); + result = krb_get_pw_in_tkt(user.u_login, "", realm, "krbtgt", realm, 1, ""); + timer_on(); + if (*error == 0 && result != KDC_PR_UNKNOWN) + error = "That username is already taken."; + + /* if it's bad, get another name from user */ + if (*error) + { + strcpy(user.u_login, old_login); + redisp(); + display_text_line(error); + display_text_line("Please choose another username."); goto again; + } - display_text_line(0); - display_text_line("Trying to assign that username... This may take a few minutes."); - - /* Do It! */ - timer_off(); - if (!enrollment) - result = grab_login(user.u_first, user.u_last, - typed_mit_id, user.u_mit_id, - user.u_login); - else - result = enroll_login(user.u_first, user.u_last, - typed_mit_id, user.u_mit_id, - user.u_login); - wfeep(); - timer_on(); - if (result != 0) { - char buf[BUFSIZ]; - - if (result == UREG_LOGIN_USED) { - /* name was in moira but not kerberos */ - error = "Sorry, that username really was in use after all."; - strcpy(user.u_login, old_login); - redisp(); - display_text_line(error); - display_text_line("Please choose another username."); - goto again; + /* name is OK, make sure */ + display_text(USERNAME_BLURB2, user.u_login); + if (!askyn("Do you want to register this username? (Yes or No) ")) + goto again; + + display_text_line(0); + display_text_line("Trying to assign that username... " + "This may take a few minutes."); + + /* Do It! */ + timer_off(); + if (!enrollment) + { + result = grab_login(user.u_first, user.u_last, typed_mit_id, + user.u_mit_id, user.u_login); + } + else + { + result = enroll_login(user.u_first, user.u_last, typed_mit_id, + user.u_mit_id, user.u_login); + } + wfeep(); + timer_on(); + if (result != 0) + { + char buf[BUFSIZ]; + + if (result == UREG_LOGIN_USED) + { + /* name was in moira but not kerberos */ + error = "Sorry, that username really was in use after all."; + strcpy(user.u_login, old_login); + redisp(); + display_text_line(error); + display_text_line("Please choose another username."); + goto again; } - display_text(NETWORK_DOWN, ""); - display_text_line(" "); - sprintf(buf, "The specific error was: %s", error_message(result)); - display_text_line(buf); - wait_for_user(); - return (qexit()); + display_text(NETWORK_DOWN, ""); + display_text_line(" "); + sprintf(buf, "The specific error was: %s", error_message(result)); + display_text_line(buf); + wait_for_user(); + return qexit(); } - /* at this point we have successfully negotiated a username */ - sprintf(line, "O.K. your username will be \"%s\".", user.u_login); - display_text_line(0); - display_text_line(line); - redisp(); - sleep(3); - return 0; + /* at this point we have successfully negotiated a username */ + sprintf(line, "O.K. your username will be \"%s\".", user.u_login); + display_text_line(0); + display_text_line(line); + redisp(); + sleep(3); + return 0; } -negotiate_passwd() +int negotiate_passwd(void) { - char *passwd, *error; - char old_passwd[256], fullname[256], tktstring[256], inst[INST_SZ]; - char login[ANAME_SZ], lpassword[PASSWORD_SIZE]; - int result; - des_cblock key; - FILE *in; - - again: - display_text(PASSWORD_BLURB, ""); - gpass(); - - /* validate password */ - error = NULL; - passwd = user.u_password; - sprintf(fullname, "%s%s", user.u_first, user.u_last); - if (strlen(passwd) < 6) - error = "Please choose a longer password."; - if (!strpasscmp(passwd, user.u_first) || - !strpasscmp(passwd, user.u_last) || - !strpasscmp(passwd, user.u_login) || - !strpasscmp(passwd, fullname) || - !strpasscmp(passwd, typed_mit_id)) - error = "Please do not use your name or ID number for your password."; - if (!error) { - in = fopen(LOGIN_INFO, "r"); - if (in != NULL) { - fgets(login, sizeof(login), in); - /* trim trailing newline */ - if (strlen(login)) - login[strlen(login) - 1] = 0; - fgets(lpassword, sizeof(lpassword), in); - /* trim trailing newline */ - if (strlen(lpassword)) - lpassword[strlen(lpassword) - 1] = 0; - fclose(in); - } else { - strcpy(login, "moira"); - strcpy(lpassword, "moira"); + char *passwd, *error; + char old_passwd[256], fullname[256], tktstring[256], inst[INST_SZ]; + char login[ANAME_SZ], lpassword[PASSWORD_SIZE]; + int result; + des_cblock key; + FILE *in; + +again: + display_text(PASSWORD_BLURB, ""); + gpass(); + + /* validate password */ + error = NULL; + passwd = user.u_password; + sprintf(fullname, "%s%s", user.u_first, user.u_last); + if (strlen(passwd) < 6) + error = "Please choose a longer password."; + if (!strpasscmp(passwd, user.u_first) || + !strpasscmp(passwd, user.u_last) || + !strpasscmp(passwd, user.u_login) || + !strpasscmp(passwd, fullname) || + !strpasscmp(passwd, typed_mit_id)) + error = "Please do not use your name or ID number for your password."; + if (!error) + { + in = fopen(LOGIN_INFO, "r"); + if (in) + { + fgets(login, sizeof(login), in); + /* trim trailing newline */ + if (strlen(login)) + login[strlen(login) - 1] = '\0'; + fgets(lpassword, sizeof(lpassword), in); + /* trim trailing newline */ + if (strlen(lpassword)) + lpassword[strlen(lpassword) - 1] = '\0'; + fclose(in); + } + else + { + strcpy(login, "moira"); + strcpy(lpassword, "moira"); } - sprintf(tktstring, "/tmp/tkt_cpw_%d", getpid()); - krb_set_tkt_string(tktstring); - des_string_to_key(passwd, key); - inst[0] = 0; - - result = krb_get_pw_in_tkt(login, inst, realm, PWSERV_NAME, - KADM_SINST, 1, lpassword); - if (result == KSUCCESS) - result = kadm_init_link(PWSERV_NAME, KRB_MASTER, realm); - if (result == KSUCCESS) - result = kadm_check_pw(key, passwd, &error); - dest_tkt(); - if (result == KADM_INSECURE_PW) { - error = "You have chosen a passsword that is in the dictionary of commonly\nselected user passwords. You will have to choose a better password."; - } else if (result != KSUCCESS) { - display_text(NETWORK_DOWN); - display_text_line(" "); - sprintf(fullname, "%s while verifying password", - error_message(result)); - display_text_line(fullname); - wait_for_user(); - return(-1); + sprintf(tktstring, "/tmp/tkt_cpw_%d", getpid()); + krb_set_tkt_string(tktstring); + des_string_to_key(passwd, key); + inst[0] = 0; + + result = krb_get_pw_in_tkt(login, inst, realm, PWSERV_NAME, + KADM_SINST, 1, lpassword); + if (result == KSUCCESS) + result = kadm_init_link(PWSERV_NAME, KRB_MASTER, realm); + if (result == KSUCCESS) + result = kadm_check_pw(key, passwd, &error); + dest_tkt(); + if (result == KADM_INSECURE_PW) + { + error = "You have chosen a passsword that is in the dictionary " + "of commonly\nselected user passwords. You will have to choose " + "a better password."; + } + else if (result != KSUCCESS) + { + display_text(NETWORK_DOWN); + display_text_line(" "); + sprintf(fullname, "%s while verifying password", + error_message(result)); + display_text_line(fullname); + wait_for_user(); + return -1; } } - if (error) { - display_text_line(0); - display_text_line(error); - wait_for_user(); - goto again; + if (error) + { + display_text_line(0); + display_text_line(error); + wait_for_user(); + goto again; } - display_text(PASSWORD_BLURB2, ""); - strcpy(old_passwd, user.u_password); - gpass(); - if (strcmp(old_passwd, user.u_password)) { - display_text_line(0); - display_text_line("What you just typed did not match the password you gave the first time."); - sleep(8); - goto again; + display_text(PASSWORD_BLURB2, ""); + strcpy(old_passwd, user.u_password); + gpass(); + if (strcmp(old_passwd, user.u_password)) + { + display_text_line(0); + display_text_line("What you just typed did not match the password " + "you gave the first time."); + sleep(8); + goto again; } - display_text_line("Storing password in the database... This may take a few minutes."); - if (do_replace()) { - return (-1); - } - display_text_line("done."); - return(0); + display_text_line("Storing password in the database... This may take " + "a few minutes."); + if (do_replace()) + return -1; + display_text_line("done."); + return 0; } -gfirst() +gfirst(void) { - /* input the first name */ - char buf[FIRST_NAME_SIZE+2]; -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, fix_display); -#endif - input("Enter first Name:", buf, FIRST_NAME_SIZE+1, - FIRSTNAME_TIMEOUT, TRUE); - strncpy(user.u_first, buf, FIRST_NAME_SIZE); - user.u_first[FIRST_NAME_SIZE - 1] = '\0'; - canon_name(user.u_first); - redisp(); + /* input the first name */ + char buf[FIRST_NAME_SIZE + 2]; + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + input("Enter first Name:", buf, FIRST_NAME_SIZE + 1, + FIRSTNAME_TIMEOUT, TRUE); + strncpy(user.u_first, buf, FIRST_NAME_SIZE); + user.u_first[FIRST_NAME_SIZE - 1] = '\0'; + canon_name(user.u_first); + redisp(); } -glast() +glast(void) { - /* input the last name */ - char buf[LAST_NAME_SIZE+2]; -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, restart); -#endif - input("Enter family Name:", buf, LAST_NAME_SIZE+1, - LASTNAME_TIMEOUT, FALSE); - strncpy(user.u_last, buf, LAST_NAME_SIZE); - user.u_last[LAST_NAME_SIZE - 1] = '\0'; - canon_name(user.u_last); - redisp(); + /* input the last name */ + char buf[LAST_NAME_SIZE + 2]; + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + input("Enter family Name:", buf, LAST_NAME_SIZE + 1, + LASTNAME_TIMEOUT, FALSE); + strncpy(user.u_last, buf, LAST_NAME_SIZE); + user.u_last[LAST_NAME_SIZE - 1] = '\0'; + canon_name(user.u_last); + redisp(); } -gpass() +gpass(void) { - /* input password */ - char new_password[PASSWORD_SIZE + 1]; -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, restart); -#endif - input_no_echo("Enter password:", new_password, - PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT); - strcpy(user.u_password, new_password); - redisp(); + /* input password */ + char new_password[PASSWORD_SIZE + 1]; + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + input_no_echo("Enter password:", new_password, + PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT); + strcpy(user.u_password, new_password); + redisp(); } /* get login name */ -glogin() +glogin(void) { - char buf[LOGIN_SIZE+2]; -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, restart); -#endif - user.u_login[0] = '\0'; - input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE); - strcpy(user.u_login, buf); - redisp(); + char buf[LOGIN_SIZE + 2]; + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + user.u_login[0] = '\0'; + input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE); + strcpy(user.u_login, buf); + redisp(); } -gmitid() +gmitid(void) { - /* get mid id */ - register int i; - char buf[15]; - register char *nbuf = buf; -#ifdef POSIX - struct sigaction act; -#endif - + /* get mid id */ + register int i; + char buf[15]; + register char *nbuf = buf; + struct sigaction act; input_mit_id: -#ifdef POSIX - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, restart); -#endif - input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE); - i = 0; - nbuf = &buf[0]; - while (*nbuf != '\0') { - if (*nbuf == ' ' || *nbuf == '-') { - nbuf++; - continue; - } - if (!isdigit(*nbuf)) { - i = 0; - break; - } - typed_mit_id[i] = *nbuf; - nbuf++; - i++; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE); + i = 0; + nbuf = &buf[0]; + while (*nbuf) + { + if (*nbuf == ' ' || *nbuf == '-') + { + nbuf++; + continue; } - if (i != 9) { - display_text_line( - "Your MIT id must be a nine-digit number. Please try again."); - goto input_mit_id; + if (!isdigit(*nbuf)) + { + i = 0; + break; } - typed_mit_id[9] = '\0'; - redisp(); - EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last); + typed_mit_id[i] = *nbuf; + nbuf++; + i++; + } + if (i != 9) + { + display_text_line("Your MIT id must be a nine-digit number. " + "Please try again."); + goto input_mit_id; + } + typed_mit_id[9] = '\0'; + redisp(); + EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last); } -gmi() +gmi(void) { - /* get middle initial */ - char buf[MID_INIT_SIZE+2]; -#ifdef POSIX - struct sigaction act; - - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler= (void (*)()) fix_display; - sigaction(SIGALRM, &act, NULL); -#else - signal(SIGALRM, restart); -#endif - input("Enter Middle Initial:", buf, MID_INIT_SIZE+1, MI_TIMEOUT, TRUE); - strncpy(user.u_mid_init, buf, MID_INIT_SIZE); - user.u_mid_init[MID_INIT_SIZE - 1] = '\0'; - canon_name(user.u_mid_init); - redisp(); + /* get middle initial */ + char buf[MID_INIT_SIZE + 2]; + struct sigaction act; + + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = (void (*)()) fix_display; + sigaction(SIGALRM, &act, NULL); + input("Enter Middle Initial:", buf, MID_INIT_SIZE + 1, MI_TIMEOUT, TRUE); + strncpy(user.u_mid_init, buf, MID_INIT_SIZE); + user.u_mid_init[MID_INIT_SIZE - 1] = '\0'; + canon_name(user.u_mid_init); + redisp(); } -qexit() +int qexit(void) { - /* exit quickly, not saving anything in the database */ - memset(&user, 0, sizeof(user)); - typed_mit_id[0] = '\0'; - user_is_valid = 0; - already_registered = 0; - enrollment = 0; - sleep(2); /* give the user a chance to see the screen */ - display_text_line(0); - return (EXIT); + /* exit quickly, not saving anything in the database */ + memset(&user, 0, sizeof(user)); + typed_mit_id[0] = '\0'; + user_is_valid = 0; + already_registered = 0; + enrollment = 0; + sleep(2); /* give the user a chance to see the screen */ + display_text_line(0); + return EXIT; } -do_replace() +int do_replace(void) { - int status; - char buf[100]; - - /* - * replaces a user in the database. If there is an error, it informs - * the user and calls qexit(); It returns only if is is successful - */ - timer_off(); - if (!enrollment) - status = set_password(user.u_first, user.u_last, typed_mit_id, - user.u_mit_id, user.u_password); - else - status = get_krb(user.u_first, user.u_last, typed_mit_id, - user.u_mit_id, user.u_password); - wfeep(); - timer_on(); - if (status) { - display_text (NETWORK_DOWN); - display_text_line(" "); - sprintf(buf, "The specific error was: %s", - error_message(status)); - display_text_line(buf); - wait_for_user(); - return (-1); - } else return 0; + int status; + char buf[100]; + + /* + * replaces a user in the database. If there is an error, it informs + * the user and calls qexit(); It returns only if is is successful + */ + timer_off(); + if (!enrollment) + { + status = set_password(user.u_first, user.u_last, typed_mit_id, + user.u_mit_id, user.u_password); + } + else + { + status = get_krb(user.u_first, user.u_last, typed_mit_id, + user.u_mit_id, user.u_password); + } + wfeep(); + timer_on(); + if (status) + { + display_text(NETWORK_DOWN); + display_text_line(" "); + sprintf(buf, "The specific error was: %s", error_message(status)); + display_text_line(buf); + wait_for_user(); + return -1; + } + else + return 0; } -kinit(user, passwd) -char *user, *passwd; +int kinit(char *user, char *passwd) { - int status; - char inst[INST_SZ]; + int status; + char inst[INST_SZ]; - inst[0] = 0; - status = krb_get_pw_in_tkt(user, inst, realm, "krbtgt", - realm, DEFAULT_TKT_LIFE, 0); - return(status); + inst[0] = '\0'; + status = krb_get_pw_in_tkt(user, inst, realm, "krbtgt", + realm, DEFAULT_TKT_LIFE, 0); + return status; } @@ -776,35 +798,35 @@ char *user, *passwd; #define _toupper(c) ((c) & ~0x20) #endif -lenient_strcmp(string1, string2) - register char *string1, *string2; +int lenient_strcmp(register char *string1, register char *string2) { - /* - * a primitive case insensitive string comparison. It returns only 0 - * if the strings are equal (ignoring case) and 1 if they are - * different. Also ignores spaces. - */ - - while (1) { - if (*string1 == '\0' && *string2 == '\0') { - return (0); - } - if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || - *string1 == '\'' || *string1 == '_') { - string1++; - continue; - } - if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || - *string2 == '\'' || *string2 == '_') { - string2++; - continue; - } - if (_toupper(*string1) != _toupper(*string2)) { - return (1); - } - string1++; - string2++; + /* + * a primitive case insensitive string comparison. It returns only 0 + * if the strings are equal (ignoring case) and 1 if they are + * different. Also ignores spaces. + */ + + while (1) + { + if (*string1 == '\0' && *string2 == '\0') + return 0; + if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || + *string1 == '\'' || *string1 == '_') + { + string1++; + continue; } + if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || + *string2 == '\'' || *string2 == '_') + { + string2++; + continue; + } + if (_toupper(*string1) != _toupper(*string2)) + return 1; + string1++; + string2++; + } } @@ -812,50 +834,51 @@ lenient_strcmp(string1, string2) * case and spaces/punctuation. */ -strpasscmp(s1, s2) -char *s1, *s2; +int strpasscmp(char *s1, char *s2) { - char buf[256], *from, *to; + char buf[256], *from, *to; - if (!lenient_strcmp(s1, s2)) - return(0); - /* if s2 is empty, say OK */ - if (!*s2) - return(1); + if (!lenient_strcmp(s1, s2)) + return 0; + /* if s2 is empty, say OK */ + if (!*s2) + return 1; - from = &s2[strlen(s2)]; - from--; - for (to = &buf[0]; from >= s2; from--) - *to++ = *from; + from = &s2[strlen(s2)]; + from--; + for (to = &buf[0]; from >= s2; from--) + *to++ = *from; - return(lenient_strcmp(s1, buf)); + return lenient_strcmp(s1, buf); } /* - * Input timeout handler. Loop back to asking for the first name. + * Input timeout handler. Loop back to asking for the first name. */ -restart() /* Go to asking for first name. */ +restart(void) { - qexit(); - longjmp(redo, 1); + qexit(); + longjmp(redo, 1); } -canon_name(cp) - register char *cp; +canon_name(register char *cp) { - register char *p2 = cp; - - /* Trim whitespace off both ends. */ - for (; *p2 && isspace(*p2); p2++) ; - if (*p2) { - strcpy(cp, p2); - p2 = cp + strlen(cp); - --p2; - while (p2 >= cp && isspace(*p2)) *(--p2) = '\0'; - } - /* Make it capitalized */ - FixCase(cp); + register char *p2 = cp; + + /* Trim whitespace off both ends. */ + for (; *p2 && isspace(*p2); p2++) + ; + if (*p2) + { + strcpy(cp, p2); + p2 = cp + strlen(cp); + --p2; + while (p2 >= cp && isspace(*p2)) + *(--p2) = '\0'; + } + /* Make it capitalized */ + FixCase(cp); } diff --git a/clients/userreg/userreg.h b/clients/userreg/userreg.h index dee6866e..1cf2d4b9 100644 --- a/clients/userreg/userreg.h +++ b/clients/userreg/userreg.h @@ -14,18 +14,18 @@ */ struct user { - char u_first[100]; - char u_mid_init[100]; - char u_last[100]; - char u_login[100]; - char u_password[100]; - char u_mit_id[100]; - char u_home_dir[100]; - int u_status; + char u_first[100]; + char u_mid_init[100]; + char u_last[100]; + char u_login[100]; + char u_password[100]; + char u_mit_id[100]; + char u_home_dir[100]; + int u_status; }; struct alias { - int foo; + int foo; }; #define SUCCESS 0 diff --git a/dbck/dbck.h b/dbck/dbck.h index 6b1a9fc1..aacebee2 100644 --- a/dbck/dbck.h +++ b/dbck/dbck.h @@ -10,10 +10,6 @@ #include #include -#ifndef NULL -#define NULL ((void*)0) -#endif - #define MODE_ASK 1 #define MODE_NO 2 #define MODE_PREEN 3 @@ -26,7 +22,7 @@ extern struct hash *filesys, *nfsphys, *strings, *subnets, *string_dups; #define MAX_ID_VALUE 32765 #define MIN_ID_VALUE 100 -#define dprintf if (debug) printf +#define dprintf if (debug) printf struct user { char login[9]; @@ -64,40 +60,40 @@ struct subnet { }; struct cluster { - char name[33]; - int clu_id; - int modby; + char name[33]; + int clu_id; + int modby; }; struct list { - char name[33]; - char acl_type; - int list_id; - int acl_id; - int members; + char name[33]; + char acl_type; + int list_id; + int acl_id; + int members; }; struct string { - char *name; - int string_id; - int refc; + char *name; + int string_id; + int refc; }; struct filesys { - char name[33]; - char dir[81]; - char type; - int filsys_id; - int mach_id; - int owner; - int owners; - int phys_id; + char name[33]; + char dir[81]; + char type; + int filsys_id; + int mach_id; + int owner; + int owners; + int phys_id; }; struct nfsphys { - char dir[33]; - int mach_id; - int nfsphys_id; - int allocated; - int count; + char dir[33]; + int mach_id; + int nfsphys_id; + int allocated; + int count; }; diff --git a/dbck/dbck.pc b/dbck/dbck.pc index 7bdea4d9..6fd37b8e 100644 --- a/dbck/dbck.pc +++ b/dbck/dbck.pc @@ -25,188 +25,197 @@ int warn = 1; int abort_p = 0; struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys; struct hash *strings, *members, *subnets, *string_dups; -EXEC SQL BEGIN DECLARE SECTION; +EXEC SQL BEGIN DECLARE SECTION; int dcmenable; -EXEC SQL END DECLARE SECTION; +EXEC SQL END DECLARE SECTION; struct save_queue *modtables, *sq_create(); void interrupt(); SQLDA *mr_sqlda; -extern SQLDA *sqlald(int,int,int); +extern SQLDA *sqlald(int, int, int); -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - char **arg = argv; -EXEC SQL BEGIN DECLARE SECTION; - char *database; -EXEC SQL END DECLARE SECTION; - int ingerr(); - int countonly = 0; - - database = "moira"; - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); - - while (++arg - argv < argc) { - if (**arg == '-') - switch ((*arg)[1]) { - case 'd': - debug = atoi((*arg)[2] ? *arg+2 : *++arg); + char **arg = argv; + EXEC SQL BEGIN DECLARE SECTION; + char *database; + EXEC SQL END DECLARE SECTION; + int ingerr(); + int countonly = 0; + + database = "moira"; + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + + while (++arg - argv < argc) + { + if (**arg == '-') + { + switch ((*arg)[1]) + { + case 'd': + debug = atoi((*arg)[2] ? *arg + 2 : *++arg); break; - case 'n': + case 'n': mode = MODE_NO; break; - case 'y': + case 'y': mode = MODE_YES; break; - case 'p': + case 'p': mode = MODE_PREEN; break; - case 'a': + case 'a': mode = MODE_ASK; break; - case 'c': + case 'c': countonly++; break; - case 'f': + case 'f': fast++; break; - case 'w': + case 'w': warn = 0; break; - default: + default: printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n", argv[0]); exit(1); - } - else - database = *arg; + } + } + else + database = *arg; + } + if (countonly) + printf("Only doing counts\n"); + else if (fast) + printf("Doing fast version (skipping some checks)\n"); + if (mode == MODE_NO) + printf("Will NOT modify the database\n"); + else if (mode == MODE_PREEN) + printf("Will fix simple things without asking\n"); + else if (mode == MODE_YES) + printf("Will fix everything without asking\n"); + if (debug) + printf("Debug level is %d\n", debug); + + signal(SIGHUP, interrupt); + signal(SIGQUIT, interrupt); + signal(SIGINT, interrupt); + + modtables = sq_create(); + mr_sqlda = sqlald(1, 255, 0); + + EXEC SQL WHENEVER SQLERROR DO dbmserr(); + printf("Opening database %s...", database); + fflush(stdout); + EXEC SQL CONNECT :database IDENTIFIED BY :database; + printf("done\n"); + EXEC SQL SELECT value INTO :dcmenable FROM numvalues + WHERE name = 'dcm_enable'; + dprintf("DCM disabled (was %d)\n", dcmenable); + EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable'; + + /* Begin transaction here. */ + + if (!countonly) + { + phase1(); + EXEC SQL COMMIT WORK; + phase2(); + EXEC SQL COMMIT WORK; + phase3(); + EXEC SQL COMMIT WORK; } - if (countonly) - printf("Only doing counts\n"); - else if (fast) - printf("Doing fast version (skipping some checks)\n"); - if (mode == MODE_NO) - printf("Will NOT modify the database\n"); - else if (mode == MODE_PREEN) - printf("Will fix simple things without asking\n"); - else if (mode == MODE_YES) - printf("Will fix everything without asking\n"); - if (debug) - printf("Debug level is %d\n", debug); - - signal(SIGHUP, interrupt); - signal(SIGQUIT, interrupt); - signal(SIGINT, interrupt); - - modtables = sq_create(); - mr_sqlda = sqlald(1, 255, 0); - - EXEC SQL WHENEVER SQLERROR DO dbmserr(); - printf("Opening database %s...", database); - fflush(stdout); - EXEC SQL CONNECT :database IDENTIFIED BY :database; - printf("done\n"); - EXEC SQL SELECT value INTO :dcmenable FROM numvalues - WHERE name='dcm_enable'; - dprintf("DCM disabled (was %d)\n", dcmenable); - EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable'; - - /* Begin transaction here. */ - - if (!countonly) { - phase1(); - EXEC SQL COMMIT WORK; - phase2(); - EXEC SQL COMMIT WORK; - phase3(); - EXEC SQL COMMIT WORK; - } else { - count_only_setup(); - EXEC SQL COMMIT WORK; + else + { + count_only_setup(); + EXEC SQL COMMIT WORK; } - phase4(); - EXEC SQL COMMIT WORK; + phase4(); + EXEC SQL COMMIT WORK; - cleanup(); - printf("Done.\n"); - exit(0); + cleanup(); + printf("Done.\n"); + exit(0); } -dbmserr() +int dbmserr(void) { -EXEC SQL BEGIN DECLARE SECTION; - char buf[512]; -EXEC SQL END DECLARE SECTION; - int bufsize=256, msglength=0; - - if (sqlca.sqlcode==1403) return; - printf("A DBMS error occurred, code %d\n", sqlca.sqlcode); - sqlglm(buf, &bufsize, &msglength); - buf[msglength]=0; - printf("%s\n", buf); - printf("Aborting...\n"); - if (!abort_p) { - abort_p++; - EXEC SQL ROLLBACK WORK; + EXEC SQL BEGIN DECLARE SECTION; + char buf[512]; + EXEC SQL END DECLARE SECTION; + int bufsize = 256, msglength = 0; + + if (sqlca.sqlcode == 1403) + return; + printf("A DBMS error occurred, code %d\n", sqlca.sqlcode); + sqlglm(buf, &bufsize, &msglength); + buf[msglength] = '\0'; + printf("%s\n", buf); + printf("Aborting...\n"); + if (!abort_p) + { + abort_p++; + EXEC SQL ROLLBACK WORK; } - exit(1); + exit(1); } -void interrupt() +void interrupt(void) { - printf("Signal caught\n"); - if (prompt("Save database changes")) { - EXEC SQL COMMIT WORK; - cleanup(); - exit(0); + printf("Signal caught\n"); + if (prompt("Save database changes")) + { + EXEC SQL COMMIT WORK; + cleanup(); + exit(0); } - printf("Aborting transaction\n"); - if (!abort_p) { - abort_p++; - EXEC SQL ROLLBACK WORK; + printf("Aborting transaction\n"); + if (!abort_p) + { + abort_p++; + EXEC SQL ROLLBACK WORK; } - EXEC SQL UPDATE numvalues SET value=:dcmenable - WHERE name='dcm_enable'; + EXEC SQL UPDATE numvalues SET value = :dcmenable + WHERE name = 'dcm_enable'; - exit(0); + exit(0); } -modified(table) -char *table; +int modified(char *table) { - sq_save_unique_string(modtables, table); + sq_save_unique_string(modtables, table); } -cleanup() +int cleanup(void) { - EXEC SQL BEGIN DECLARE SECTION; - char *tab; - EXEC SQL END DECLARE SECTION; - - while (sq_get_data(modtables, &tab)) { - EXEC SQL UPDATE tblstats SET modtime=SYSDATE - WHERE table_name = :tab; + EXEC SQL BEGIN DECLARE SECTION; + char *tab; + EXEC SQL END DECLARE SECTION; + + while (sq_get_data(modtables, &tab)) + { + EXEC SQL UPDATE tblstats SET modtime = SYSDATE + WHERE table_name = :tab; } - EXEC SQL UPDATE numvalues SET value = :dcmenable - WHERE name='dcm_enable'; + EXEC SQL UPDATE numvalues SET value = :dcmenable + WHERE name = 'dcm_enable'; } -out_of_mem(msg) -char *msg; +int out_of_mem(char *msg) { - fprintf(stderr, "Out of memory while %s\n", msg); - if (prompt("Save database changes")) { - EXEC SQL COMMIT WORK; - cleanup(); - exit(1); + fprintf(stderr, "Out of memory while %s\n", msg); + if (prompt("Save database changes")) + { + EXEC SQL COMMIT WORK; + cleanup(); + exit(1); } - printf("Aborting transaction\n"); - EXEC SQL ROLLBACK WORK; - exit(1); + printf("Aborting transaction\n"); + EXEC SQL ROLLBACK WORK; + exit(1); } diff --git a/dbck/fix.pc b/dbck/fix.pc index 4c134eee..a23c50ac 100644 --- a/dbck/fix.pc +++ b/dbck/fix.pc @@ -17,143 +17,129 @@ EXEC SQL INCLUDE sqlda; /* SQL Descriptor Area */ static char fix_qc_rcsid[] = "$Header$"; -EXEC SQL BEGIN DECLARE SECTION; +EXEC SQL BEGIN DECLARE SECTION; char *_table; char *_idfield; char stmt_buf[500]; -EXEC SQL END DECLARE SECTION; +EXEC SQL END DECLARE SECTION; extern SQLDA *mr_sqlda; -generic_ffunc(id) -EXEC SQL BEGIN DECLARE SECTION; -int id; -EXEC SQL END DECLARE SECTION; +int generic_ffunc(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount; - EXEC SQL END DECLARE SECTION; - - sprintf(stmt_buf,"DELETE FROM %s WHERE %s.%s = %d", - _table,_table,_idfield,id); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified(_table); + int rowcount; + + sprintf(stmt_buf, "DELETE FROM %s WHERE %s.%s = %d", + _table, _table, _idfield, id); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified(_table); } -generic_delete(sq, pfunc, table, idfield, preen) -struct save_queue *sq; -void (*pfunc)(); -char *table, *idfield; -int preen; +int generic_delete(struct save_queue *sq, void (*pfunc)(), char *table, + char *idfield, int preen) { - _table = table; - _idfield = idfield; - generic_fix(sq, pfunc, "Delete", generic_ffunc, preen); + _table = table; + _idfield = idfield; + generic_fix(sq, pfunc, "Delete", generic_ffunc, preen); } -single_delete(table, idfield, id) -char *table, *idfield; -int id; +int single_delete(char *table, char *idfield, int id) { - _table = table; - _idfield = idfield; - generic_ffunc(id); + _table = table; + _idfield = idfield; + generic_ffunc(id); } -zero_fix(tbl, zrfield, idfield, id) -EXEC SQL BEGIN DECLARE SECTION; -char *tbl, *zrfield, *idfield; -int id; -EXEC SQL END DECLARE SECTION; +int zero_fix(char *tbl, char *zrfield, char *idfield, int id) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount; - EXEC SQL END DECLARE SECTION; - - sprintf(stmt_buf,"UPDATE %s SET %s = 0 WHERE %s.%s = %d", - tbl,zrfield,tbl,idfield,id); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified(tbl); + int rowcount; + + sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s.%s = %d", + tbl, zrfield, tbl, idfield, id); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified(tbl); } -int single_fix(msg, preen) -char *msg; -int preen; +int single_fix(char *msg, int preen) { - if (mode == MODE_PREEN) - return(preen); + if (mode == MODE_PREEN) + return preen; - switch (mode) { + switch (mode) + { case MODE_ASK: - if (!prompt(msg)) - break; - case MODE_YES: - return(1); + if (!prompt(msg)) break; + case MODE_YES: + return 1; + break; case MODE_NO: - ; + ; } - return(0); + return 0; } -generic_fix(sq, pfunc, msg, ffunc, preen) -struct save_queue *sq; -char *msg; -int (*pfunc)(), (*ffunc)(); -int preen; +int generic_fix(struct save_queue *sq, int (*pfunc)(), char *msg, + int (*ffunc)(), int preen) { - int id; + int id; - while (sq_get_data(sq, &id)) { - if ((*pfunc)(id) == 0 && single_fix(msg, preen)) - (*ffunc)(id); + while (sq_get_data(sq, &id)) + { + if ((*pfunc)(id) == 0 && single_fix(msg, preen)) + (*ffunc)(id); } - sq_destroy(sq); + sq_destroy(sq); } -int prompt(msg) -char *msg; +int prompt(char *msg) { - char buf[BUFSIZ]; - EXEC SQL BEGIN DECLARE SECTION; - extern int dcmenable; - EXEC SQL END DECLARE SECTION; - - while (1) { - printf("%s (Y/N/Q)? ", msg); - fflush(stdout); - gets(buf); - if (buf[0] == 'Y' || buf[0] == 'y') - return(1); - if (buf[0] == 'N' || buf[0] == 'n') - return(0); - if (buf[0] == 'Q' || buf[0] == 'q') { - if (prompt("Are you sure you want to quit")) { - if (prompt("Save database changes")) { - EXEC SQL COMMIT WORK; - cleanup(); - exit(0); - } else { - EXEC SQL ROLLBACK WORK; - EXEC SQL UPDATE numvalues SET value = :dcmenable - WHERE name='dcm_enable'; - exit(1); + char buf[BUFSIZ]; + EXEC SQL BEGIN DECLARE SECTION; + extern int dcmenable; + EXEC SQL END DECLARE SECTION; + + while (1) + { + printf("%s (Y/N/Q)? ", msg); + fflush(stdout); + gets(buf); + if (buf[0] == 'Y' || buf[0] == 'y') + return 1; + if (buf[0] == 'N' || buf[0] == 'n') + return 0; + if (buf[0] == 'Q' || buf[0] == 'q') + { + if (prompt("Are you sure you want to quit")) + { + if (prompt("Save database changes")) + { + EXEC SQL COMMIT WORK; + cleanup(); + exit(0); + } + else + { + EXEC SQL ROLLBACK WORK; + EXEC SQL UPDATE numvalues SET value = :dcmenable + WHERE name = 'dcm_enable'; + exit(1); } } } @@ -172,82 +158,77 @@ char *msg; ** **/ -int set_next_object_id(object, tablename) -EXEC SQL BEGIN DECLARE SECTION; - char *object; -EXEC SQL END DECLARE SECTION; - char *tablename; +int set_next_object_id(char *object, char *tablename) { - EXEC SQL BEGIN DECLARE SECTION; - int value; - char stmt_buf[256], out_buf[256]; - EXEC SQL END DECLARE SECTION; - int starting_value, errcode=0; - - EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :object; - if (sqlca.sqlerrd[2] != 1) - return(MR_NO_ID); - - starting_value=value; - while(1) { - if (value > MAX_ID_VALUE) value = MIN_ID_VALUE; - - sprintf(stmt_buf, "SELECT %s FROM %s WHERE %s=%d", - object, tablename, object, value); - EXEC SQL PREPARE inc_stmt FROM :stmt_buf; - EXEC SQL DECLARE inc_crs CURSOR FOR inc_stmt; - EXEC SQL OPEN inc_crs; - mr_sqlda->N = 1; - EXEC SQL DESCRIBE SELECT LIST FOR inc_stmt INTO mr_sqlda; - mr_sqlda->N = mr_sqlda->F; - mr_sqlda->V[0]=out_buf; - mr_sqlda->T[0]=97; - mr_sqlda->L[0]=255; - EXEC SQL FETCH inc_crs USING DESCRIPTOR mr_sqlda; - - /* if we got an error from the FETCH, we have to preserve it or the - close will reset it and the caller with think nothing happened */ - if(sqlca.sqlcode) errcode=sqlca.sqlcode; - - EXEC SQL CLOSE inc_crs; - if (errcode < 0) return(MR_DBMS_ERR); - if (errcode == 1403) break; - - value++; - if (value == starting_value) return (MR_NO_ID); + EXEC SQL BEGIN DECLARE SECTION; + int value; + char stmt_buf[256], out_buf[256]; + EXEC SQL END DECLARE SECTION; + int starting_value, errcode = 0; + + EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :object; + if (sqlca.sqlerrd[2] != 1) + return MR_NO_ID; + + starting_value = value; + while (1) + { + if (value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + + sprintf(stmt_buf, "SELECT %s FROM %s WHERE %s = %d", + object, tablename, object, value); + EXEC SQL PREPARE inc_stmt FROM :stmt_buf; + EXEC SQL DECLARE inc_crs CURSOR FOR inc_stmt; + EXEC SQL OPEN inc_crs; + mr_sqlda->N = 1; + EXEC SQL DESCRIBE SELECT LIST FOR inc_stmt INTO mr_sqlda; + mr_sqlda->N = mr_sqlda->F; + mr_sqlda->V[0] = out_buf; + mr_sqlda->T[0] = 97; + mr_sqlda->L[0] = 255; + EXEC SQL FETCH inc_crs USING DESCRIPTOR mr_sqlda; + + /* if we got an error from the FETCH, we have to preserve it or the + close will reset it and the caller with think nothing happened */ + if (sqlca.sqlcode) + errcode = sqlca.sqlcode; + + EXEC SQL CLOSE inc_crs; + if (errcode < 0) + return MR_DBMS_ERR; + if (errcode == 1403) + break; + + value++; + if (value == starting_value) + return MR_NO_ID; } - printf("setting ID %s to %d\n", object, value); - EXEC SQL UPDATE numvalues SET value = :value WHERE name = :object; - modified("values"); - return(MR_SUCCESS); + printf("setting ID %s to %d\n", object, value); + EXEC SQL UPDATE numvalues SET value = :value WHERE name = :object; + modified("values"); + return MR_SUCCESS; } -generic_fix_id(tbl, idfield, txtfield, oldid, name) - EXEC SQL BEGIN DECLARE SECTION; - char *tbl; - char *idfield; - char *txtfield; - int oldid; - char *name; - EXEC SQL END DECLARE SECTION; +int generic_fix_id(char *tbl, char *idfield, char *txtfield, + int oldid, char *name) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, id; - EXEC SQL END DECLARE SECTION; - - set_next_object_id(tbl, idfield); - EXEC SQL SELECT value INTO :id FROM numvalues - WHERE name = :idfield; - sprintf(stmt_buf,"UPDATE %s SET %s = %d WHERE %s=%d AND %s='%s'", - tbl,idfield,id,idfield,oldid,txtfield,name); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount == 1) - printf("Fixed\n"); - else - printf("Not fixed, rowcount = %d\n", rowcount); - modified(tbl); - return(id); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id; + EXEC SQL END DECLARE SECTION; + + set_next_object_id(tbl, idfield); + EXEC SQL SELECT value INTO :id FROM numvalues WHERE name = :idfield; + sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d AND %s = '%s'", + tbl, idfield, id, idfield, oldid, txtfield, name); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount == 1) + printf("Fixed\n"); + else + printf("Not fixed, rowcount = %d\n", rowcount); + modified(tbl); + return id; } diff --git a/dbck/nhash.c b/dbck/nhash.c index a5bec4c1..40cd1ccf 100644 --- a/dbck/nhash.c +++ b/dbck/nhash.c @@ -13,57 +13,52 @@ /* #include */ struct int_bucket { - struct int_bucket *next; - int key; - int data; + struct int_bucket *next; + int key; + int data; }; struct int_hash { - int size; - struct int_bucket **data; + int size; + struct int_bucket **data; }; -#ifndef NULL -#define NULL 0 -#endif #define int_hash_func(h, key) (key >= 0 ? (key % h->size) : (-key % h->size)) /* Create an int_hash table. The size is just a hint, not a maximum. */ -struct int_hash *create_int_hash(size) -int size; +struct int_hash *create_int_hash(int size) { - struct int_hash *h; - - h = (struct int_hash *) malloc(sizeof(struct int_hash)); - if (h == (struct int_hash *) NULL) - return((struct int_hash *) NULL); - h->size = size; - h->data = (struct int_bucket **) malloc(size * sizeof(char *)); - if (h->data == (struct int_bucket **) NULL) { - free(h); - return((struct int_hash *) NULL); + struct int_hash *h; + + h = malloc(sizeof(struct int_hash)); + if (!h) + return NULL; + h->size = size; + h->data = malloc(size * sizeof(struct int_bucket *)); + if (!h->data) + { + free(h); + return NULL; } - memset(h->data, 0, size * sizeof(char *)); - return(h); + memset(h->data, 0, size * sizeof(char *)); + return h; } -/* Lookup an object in the int_hash table. Returns the value associated with +/* Look up an object in the int_hash table. Returns the value associated with * the key, or NULL (thus NULL is not a very good value to store...) */ -int int_hash_lookup(h, key) -struct int_hash *h; -register int key; +int int_hash_lookup(struct int_hash *h, register int key) { - register struct int_bucket *b; - - b = h->data[int_hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) - return(b->data); - else - return(0); + register struct int_bucket *b; + + b = h->data[int_hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + return b->data; + else + return 0; } @@ -71,59 +66,57 @@ register int key; * existed, or 0 if not. */ -int int_hash_update(h, key, value) -struct int_hash *h; -register int key; -int value; +int int_hash_update(struct int_hash *h, register int key, int value) { - register struct int_bucket *b; - - b = h->data[int_hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) { - b->data = value; - return(1); - } else - return(0); + register struct int_bucket *b; + + b = h->data[int_hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + { + b->data = value; + return 1; + } + else + return 0; } -/* Store an item in the int_hash table. Returns 0 if the key was not previously - * there, 1 if it was, or -1 if we ran out of memory. +/* Store an item in the int_hash table. Returns 0 if the key was not + * previously there, 1 if it was, or -1 if we ran out of memory. */ -int int_hash_store(h, key, value) -struct int_hash *h; -register int key; -int value; +int int_hash_store(struct int_hash *h, register int key, int value) { - register struct int_bucket *b, **p; - - p = &(h->data[int_hash_func(h, key)]); - if (*p == NULL) { - b = *p = (struct int_bucket *) malloc(sizeof(struct int_bucket)); - if (b == (struct int_bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + register struct int_bucket *b, **p; + + p = &(h->data[int_hash_func(h, key)]); + if (!*p) + { + b = *p = malloc(sizeof(struct int_bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } - for (b = *p; b && b->key != key; b = *p) - p = (struct int_bucket **) *p; - if (b && b->key == key) { - b->data = value; - return(1); + for (b = *p; b && b->key != key; b = *p) + p = (struct int_bucket **) *p; + if (b && b->key == key) + { + b->data = value; + return 1; } - b = *p = (struct int_bucket *) malloc(sizeof(struct int_bucket)); - if (b == (struct int_bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + b = *p = malloc(sizeof(struct int_bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } @@ -131,17 +124,16 @@ int value; * data with that value, call the callback proc with the corresponding key. */ -int_hash_search(h, value, callback) -struct int_hash *h; -register int value; -void (*callback)(); +int int_hash_search(struct int_hash *h, register int value, void (*callback)()) { - register struct int_bucket *b, **p; - - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - if (b->data == value) - (*callback)(b->key); + register struct int_bucket *b, **p; + + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + { + if (b->data == value) + (*callback)(b->key); } } } @@ -150,32 +142,30 @@ void (*callback)(); /* Step through the int_hash table, calling the callback proc with each key. */ -int_hash_step(h, callback, hint) -struct int_hash *h; -void (*callback)(); -char *hint; +int int_hash_step(struct int_hash *h, void (*callback)(), char *hint) { - register struct int_bucket *b, **p; + register struct int_bucket *b, **p; - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - (*callback)(b->key, b->data, hint); - } + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + (*callback)(b->key, b->data, hint); } } /* Deallocate all of the memory associated with a table */ -int_hash_destroy(h) -struct int_hash *h; +int int_hash_destroy(struct int_hash *h) { - register struct int_bucket *b, **p, *b1; - - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b1) { - b1 = b->next; - free(b); + register struct int_bucket *b, **p, *b1; + + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b1) + { + b1 = b->next; + free(b); } } } diff --git a/dbck/phase1.pc b/dbck/phase1.pc index 849f583b..52b06b75 100644 --- a/dbck/phase1.pc +++ b/dbck/phase1.pc @@ -8,6 +8,7 @@ #include #include #include +#include #include "dbck.h" EXEC SQL INCLUDE sqlca; @@ -15,721 +16,773 @@ static char phase1_qc_rcsid[] = "$Header$"; EXEC SQL WHENEVER SQLERROR DO dbmserr(); -show_user_id(u) -struct user *u; +int show_user_id(struct user *u) { - printf("User %s (%s, status %d) has duplicate ID\n", - u->login, u->fullname, u->status); - return(0); + printf("User %s (%s, status %d) has duplicate ID\n", + u->login, u->fullname, u->status); + return 0; } -handle_duplicate_logins(sq) -struct save_queue *sq; +handle_duplicate_logins(struct save_queue *sq) { - struct user *u, *uu, *tmp; - - uu = (struct user *)0; - if(sq_get_data(sq,&uu)) { - while (sq_get_data(sq, &u)) { - if (!strcmp(u->login, uu->login)) { - if (uu->status == 1 || u->status == 0) { - tmp = u; - u = uu; - uu = tmp; - } - printf("User %s (%s, status %d) and\n", - u->login, u->fullname, u->status); - printf("User %s (%s, status %d) have duplicate logins\n", - uu->login, uu->fullname, uu->status); - if (!strcmp(u->fullname, uu->fullname) && - single_fix("Delete the second one")) { + struct user *u, *uu, *tmp; + + uu = NULL; + if (sq_get_data(sq, &uu)) + { + while (sq_get_data(sq, &u)) + { + if (!strcmp(u->login, uu->login)) + { + if (uu->status == 1 || u->status == 0) + { + tmp = u; + u = uu; + uu = tmp; + } + printf("User %s (%s, status %d) and\n", + u->login, u->fullname, u->status); + printf("User %s (%s, status %d) have duplicate logins\n", + uu->login, uu->fullname, uu->status); + if (!strcmp(u->fullname, uu->fullname) && + single_fix("Delete the second one")) single_delete("users", "users_id", uu->users_id); - } else if (single_fix("Unregister the second one")) - { - EXEC SQL BEGIN DECLARE SECTION; - int id = uu->users_id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE users SET login = '#' || CHAR(users.unix_uid), - status=0 WHERE users_id = :id; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("users"); - } - } else { + else if (single_fix("Unregister the second one")) + { + EXEC SQL BEGIN DECLARE SECTION; + int id = uu->users_id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE users + SET login = '#' || CHAR(users.unix_uid), status = 0 + WHERE users_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + { + printf("%d entr%s fixed\n", rowcount, + rowcount == 1 ? "y" : "ies"); + } + else + printf("Not fixed\n"); + modified("users"); + } + } + else uu = u; } - } } } -fix_user_id(u) -struct user *u; +fix_user_id(struct user *u) { - u->users_id = generic_fix_id("users", "users_id", "login", - u->users_id, u->login); + u->users_id = generic_fix_id("users", "users_id", "login", + u->users_id, u->login); } -cant_fix(id) -int id; +cant_fix(int id) { - printf("Sorry, don't know how to fix that\n"); + printf("Sorry, don't know how to fix that\n"); } -show_mach_id(m) -struct machine *m; +int show_mach_id(struct machine *m) { - printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id); - return(0); + printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id); + return 0; } -show_mach_name(m) -struct machine *m; +int show_mach_name(struct machine *m) { - printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id); - return(0); + printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id); + return 0; } -fix_mach_id(m) -struct machine *m; +fix_mach_id(struct machine *m) { - m->mach_id = generic_fix_id("machine", "mach_id", "name", - m->mach_id, m->name); + m->mach_id = generic_fix_id("machine", "mach_id", "name", + m->mach_id, m->name); } -show_snet_name(s) -struct subnet *s; +int show_snet_name(struct subnet *s) { - printf("Subnet %s (%d) has duplicate name\n", s->name, s->snet_id); - return(0); + printf("Subnet %s (%d) has duplicate name\n", s->name, s->snet_id); + return 0; } -show_clu_id(c) -struct cluster *c; +int show_clu_id(struct cluster *c) { - printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id); - return(0); + printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id); + return 0; } -show_clu_name(c) -struct cluster *c; +int show_clu_name(struct cluster *c) { - printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id); - return(0); + printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id); + return 0; } -fix_clu_id(c) -struct cluster *c; +fix_clu_id(struct cluster *c) { - c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name); + c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name); } -show_list_id(l) -struct list *l; +int show_list_id(struct list *l) { - printf("List %s has duplicate ID %d\n", l->name, l->list_id); - return(0); + printf("List %s has duplicate ID %d\n", l->name, l->list_id); + return 0; } -show_list_name(l) -struct list *l; +int show_list_name(struct list *l) { - printf("List %s (%d) has duplicate name\n", l->name, l->list_id); - return(0); + printf("List %s (%d) has duplicate name\n", l->name, l->list_id); + return 0; } -fix_list_id(l) -struct list *l; +fix_list_id(struct list *l) { - l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name); + l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name); } -show_fs_id(f) -struct filesys *f; +int show_fs_id(struct filesys *f) { - printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id); - return(0); + printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id); + return 0; } -fix_fs_id(f) -struct filesys *f; +fix_fs_id(struct filesys *f) { - f->filsys_id = generic_fix_id("filesys", "filsys_id", "label", - f->filsys_id, f->name); + f->filsys_id = generic_fix_id("filesys", "filsys_id", "label", + f->filsys_id, f->name); } -show_fs_name(fs) -struct filesys *fs; +int show_fs_name(struct filesys *fs) { - printf("Filesys %s (%d) has duplicate name\n", fs->name, fs->filsys_id); - return(0); + printf("Filesys %s (%d) has duplicate name\n", fs->name, fs->filsys_id); + return 0; } - -show_np_id(n) -struct nfsphys *n; +int show_np_id(struct nfsphys *n) { - printf("NfsPhys %s:%s has duplicate ID %d\n", - ((struct machine *)hash_lookup(machines, n->mach_id))->name, - n->dir, n->nfsphys_id); - return(0); + printf("NfsPhys %s:%s has duplicate ID %d\n", + ((struct machine *)hash_lookup(machines, n->mach_id))->name, + n->dir, n->nfsphys_id); + return 0; } -fix_np_id(n) -struct nfsphys *n; +fix_np_id(struct nfsphys *n) { - n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir", - n->nfsphys_id, n->dir); + n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir", + n->nfsphys_id, n->dir); } -show_str_id(s) -struct string *s; +int show_str_id(struct string *s) { - printf("String %s has duplicate ID %d\n", s->name, s->string_id); - return(0); + printf("String %s has duplicate ID %d\n", s->name, s->string_id); + return 0; } -print_str_id(id) - int id; +int print_str_id(int id) { printf("String %d is a duplicate\n", id); - return(0); + return 0; } -print_dup_map(key, data, hint) - int key; - int data; - char *hint; +print_dup_map(int key, int data, char *hint) { - printf("String %d is a duplicate of string %d\n", key, data); - + printf("String %d is a duplicate of string %d\n", key, data); } -phase1() +phase1(void) { - EXEC SQL BEGIN DECLARE SECTION; - char name[81], name1[81], last[17], first[17], buf[257]; - int id, id1, id2, id3, aid, aid2, status; - int sid, sid2, sid3, sid4, sid5; - EXEC SQL END DECLARE SECTION; - int i, q, retval, tmp; - struct save_queue *sq; - struct user *u; - struct machine *m; - struct subnet *sn; - struct list *l; - struct cluster *c; - struct string *s; - struct filesys *f; - struct nfsphys *n; - - printf("Phase 1 - Looking for duplicates\n"); - - /* self-join strings table on "string" to get duplicate strings, then - build a duplicates table to merge them. */ - - dprintf("Looking for duplicate strings...\n"); - string_dups = create_hash( 100 ); - if(!string_dups) out_of_mem("storing duplicate strings"); - - EXEC SQL DECLARE csr116 CURSOR FOR - SELECT s1.string_id, s2.string_id FROM strings s1, strings s2 - where s1.string = s2.string and s1.string_id < s2.string_id; - EXEC SQL OPEN csr116; - /* The SELECT gives us two columns, both with non-negative integers. - * The number in the left column is always the smaller of the two, - * and each row includes string IDs for identical strings. We use - * them to make a mapping from id-to-delete to id-to-keep for all - * superflous IDs. - */ - q=0; - while(1) { - EXEC SQL FETCH csr116 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - q++; - /* If id2 is already stored, skip this row. */ - i = int_hash_lookup( string_dups, id2 ); - if( i > 0 ) { continue; } - /* Follow the chain of id1 equivalent IDs back to the lowest one. */ - id=id1; - while((tmp=int_hash_lookup(string_dups, id))>0) - id=tmp; - int_hash_store( string_dups, id2, id ); + EXEC SQL BEGIN DECLARE SECTION; + char name[81], name1[81], last[17], first[17], buf[257]; + int id, id1, id2, id3, aid, aid2, status; + int sid, sid2, sid3, sid4, sid5; + EXEC SQL END DECLARE SECTION; + int i, q, retval, tmp; + struct save_queue *sq; + struct user *u; + struct machine *m; + struct subnet *sn; + struct list *l; + struct cluster *c; + struct string *s; + struct filesys *f; + struct nfsphys *n; + + printf("Phase 1 - Looking for duplicates\n"); + + /* self-join strings table on "string" to get duplicate strings, then + build a duplicates table to merge them. */ + + dprintf("Looking for duplicate strings...\n"); + string_dups = create_hash(100); + if (!string_dups) + out_of_mem("storing duplicate strings"); + + EXEC SQL DECLARE csr116 CURSOR FOR + SELECT s1.string_id, s2.string_id FROM strings s1, strings s2 + WHERE s1.string = s2.string and s1.string_id < s2.string_id; + EXEC SQL OPEN csr116; + /* The SELECT gives us two columns, both with non-negative integers. + * The number in the left column is always the smaller of the two, + * and each row includes string IDs for identical strings. We use + * them to make a mapping from id-to-delete to id-to-keep for all + * superflous IDs. + */ + q = 0; + while (1) + { + EXEC SQL FETCH csr116 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + q++; + /* If id2 is already stored, skip this row. */ + i = int_hash_lookup(string_dups, id2); + if (i > 0) + continue; + /* Follow the chain of id1 equivalent IDs back to the lowest one. */ + id = id1; + while ((tmp = int_hash_lookup(string_dups, id)) > 0) + id = tmp; + int_hash_store(string_dups, id2, id); } - EXEC SQL CLOSE csr116; - dprintf("found %d duplicates\n", q); - int_hash_step(string_dups, print_dup_map, NULL); - /* We don't want to delete the duplicates now because if the dbck - is cancelled, a LOT of state will be lost. So, we'll just let - them not get marked as used and then phase3 will clean them up */ - - dprintf("Loading strings...\n"); - sq = sq_create(); - strings = create_hash(75000); - if(!sq || !strings) out_of_mem("loading strings"); - - EXEC SQL DECLARE csr101 CURSOR FOR - SELECT string_id, string FROM strings ORDER BY string_id; - EXEC SQL OPEN csr101; - q=0; - while(1) { - EXEC SQL FETCH csr101 INTO :id, :buf; - if (sqlca.sqlcode != 0) break; - q++; - s = (struct string *) malloc(sizeof(struct string)); - if (s == NULL) - out_of_mem("storing strings"); - s->name = strsave(strtrim(buf)); - s->string_id = id; - s->refc = 0; - retval = hash_store(strings, id, s); - if ( retval == -1 ) { - out_of_mem("storing strings in hash table"); - } else if ( retval == 1 ) { /* duplicate string_id*/ + EXEC SQL CLOSE csr116; + dprintf("found %d duplicates\n", q); + int_hash_step(string_dups, print_dup_map, NULL); + /* We don't want to delete the duplicates now because if the dbck + is cancelled, a LOT of state will be lost. So, we'll just let + them not get marked as used and then phase3 will clean them up */ + + dprintf("Loading strings...\n"); + sq = sq_create(); + strings = create_hash(75000); + if (!sq || !strings) + out_of_mem("loading strings"); + + EXEC SQL DECLARE csr101 CURSOR FOR + SELECT string_id, string FROM strings ORDER BY string_id; + EXEC SQL OPEN csr101; + q = 0; + while (1) + { + EXEC SQL FETCH csr101 INTO :id, :buf; + if (sqlca.sqlcode) + break; + q++; + s = malloc(sizeof(struct string)); + if (!s) + out_of_mem("storing strings"); + s->name = strsave(strtrim(buf)); + s->string_id = id; + s->refc = 0; + retval = hash_store(strings, id, s); + if (retval == -1) + out_of_mem("storing strings in hash table"); + else if (retval == 1) /* duplicate string_id */ + { sq_save_data(sq, hash_lookup(strings, id)); sq_save_data(sq, s); } } - EXEC SQL CLOSE csr101; - /* I'm not at all convinced this will work, so... - generic_delete(sq, show_str_id, "strings", "string_id", 0); - */ - string_check(0); - - printf("Loaded %d strings\n", q); - - dprintf("Loading users...\n"); - sq = sq_create(); - users = create_hash(30000); - if(!sq || !users) out_of_mem("loading users"); - - EXEC SQL DECLARE csr102 CURSOR FOR - SELECT users_id, login, last, first, status, potype, pop_id, box_id, - modby, fmodby, pmodby, comments, sigwho FROM users - ORDER BY users_id; - EXEC SQL OPEN csr102; - while(1) { - EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status, - :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5; - if (sqlca.sqlcode != 0) break; - - u = (struct user *) malloc(sizeof(struct user)); - if (u == NULL) - out_of_mem("storing users"); - strcpy(u->login, strtrim(name)); - u->potype = buf[0]; - sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); - u->fullname = strsave(buf); - u->status = status; - u->users_id = id; - u->modby = sid; - u->fmodby = sid2; - u->pmodby = sid3; - u->comment = sid4; - u->sigwho = sid5; - switch (u->potype) { + EXEC SQL CLOSE csr101; + /* keep string id 0 (the empty string) even if unreferenced */ + string_check(0); + + printf("Loaded %d strings\n", q); + + dprintf("Loading users...\n"); + sq = sq_create(); + users = create_hash(30000); + if (!sq || !users) + out_of_mem("loading users"); + + EXEC SQL DECLARE csr102 CURSOR FOR + SELECT users_id, login, last, first, status, potype, pop_id, box_id, + modby, fmodby, pmodby, comments, sigwho FROM users + ORDER BY users_id; + EXEC SQL OPEN csr102; + while (1) + { + EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status, + :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5; + if (sqlca.sqlcode) + break; + + u = malloc(sizeof(struct user)); + if (!u) + out_of_mem("storing users"); + strcpy(u->login, strtrim(name)); + u->potype = buf[0]; + sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); + u->fullname = strsave(buf); + u->status = status; + u->users_id = id; + u->modby = sid; + u->fmodby = sid2; + u->pmodby = sid3; + u->comment = sid4; + u->sigwho = sid5; + switch (u->potype) + { case 'P': - u->pobox_id = id2; - break; + u->pobox_id = id2; + break; case 'S': - /* If potype is SMTP, box_id is a string_id for the strings tbl */ - u->pobox_id = id3; - break; + /* If potype is SMTP, box_id is a string_id for the strings tbl */ + u->pobox_id = id3; + break; default: - u->pobox_id = 0; + u->pobox_id = 0; } - retval = hash_store(users, id, u); - if ( retval == -1 ) { - out_of_mem("storing users in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(users, id)); - sq_save_data(sq, u); + retval = hash_store(users, id, u); + if (retval == -1) + out_of_mem("storing users in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(users, id)); + sq_save_data(sq, u); } } - EXEC SQL CLOSE csr102; - - generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0); - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("finding duplicate logins"); - - EXEC SQL DECLARE csr103 CURSOR FOR - SELECT u1.users_id FROM users u1, users u2 - WHERE u1.login = u2.login and u1.rowid != u2.rowid; - EXEC SQL OPEN csr103; - while(1) { - EXEC SQL FETCH csr103 INTO :id; - if (sqlca.sqlcode != 0) break; - sq_save_data(sq, hash_lookup(users, id)); + EXEC SQL CLOSE csr102; + + generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0); + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("finding duplicate logins"); + + EXEC SQL DECLARE csr103 CURSOR FOR + SELECT u1.users_id FROM users u1, users u2 + WHERE u1.login = u2.login and u1.rowid != u2.rowid; + EXEC SQL OPEN csr103; + while (1) + { + EXEC SQL FETCH csr103 INTO :id; + if (sqlca.sqlcode) + break; + sq_save_data(sq, hash_lookup(users, id)); } - EXEC SQL CLOSE csr103; - handle_duplicate_logins(sq); + EXEC SQL CLOSE csr103; + handle_duplicate_logins(sq); } - if (!fast) { - dprintf("Scanning krbmap...\n"); - - EXEC SQL DECLARE csr113 CURSOR FOR - SELECT k1.users_id FROM krbmap k1, krbmap k2 - WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid; - EXEC SQL OPEN csr113; - while(1) { - EXEC SQL FETCH csr113 INTO :id; - if (sqlca.sqlcode != 0) break; + if (!fast) + { + dprintf("Scanning krbmap...\n"); + + EXEC SQL DECLARE csr113 CURSOR FOR + SELECT k1.users_id FROM krbmap k1, krbmap k2 + WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid; + EXEC SQL OPEN csr113; + while (1) + { + EXEC SQL FETCH csr113 INTO :id; + if (sqlca.sqlcode) + break; - printf("User %d is in the krbmap more than once!\n", id); - printf("Not fixing this error\n"); + printf("User %d is in the krbmap more than once!\n", id); + printf("Not fixing this error\n"); } - EXEC SQL CLOSE csr113; - - EXEC SQL DECLARE csr114 CURSOR FOR - SELECT k1.string_id FROM krbmap k1, krbmap k2 - WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid; - EXEC SQL OPEN csr114; - while(1) { - EXEC SQL FETCH csr114 INTO :id; - if (sqlca.sqlcode != 0) break; - - printf("Principal %d is in the krbmap more than once!\n", id); - printf("Not fixing this error\n"); + EXEC SQL CLOSE csr113; + + EXEC SQL DECLARE csr114 CURSOR FOR + SELECT k1.string_id FROM krbmap k1, krbmap k2 + WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid; + EXEC SQL OPEN csr114; + while (1) + { + EXEC SQL FETCH csr114 INTO :id; + if (sqlca.sqlcode) + break; + + printf("Principal %d is in the krbmap more than once!\n", id); + printf("Not fixing this error\n"); } - EXEC SQL CLOSE csr114; + EXEC SQL CLOSE csr114; } - dprintf("Loading machines...\n"); - sq = sq_create(); - machines = create_hash(20000); - if(!sq || !machines) out_of_mem("loading machines"); - - EXEC SQL DECLARE csr104 CURSOR FOR - SELECT mach_id, name, snet_id, owner_type, owner_id, - acomment, ocomment, creator, modby - FROM machine ORDER BY mach_id; - EXEC SQL OPEN csr104; - while(1) { - EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2, - :sid3, :sid4, :sid; - if (sqlca.sqlcode != 0) break; - - m = (struct machine *) malloc(sizeof(struct machine)); - if (m == NULL) - out_of_mem("storing machines"); - strcpy(m->name, strtrim(name)); - m->owner_type = buf[0]; - m->owner_id = id3; - m->snet_id = id2; - m->mach_id = id; - m->clucount = 0; - m->acomment=sid2; - m->ocomment=sid3; - m->creator=sid4; - m->modby=sid; - retval = hash_store(machines, id, m); - if ( retval == -1 ) { - out_of_mem("storing machines in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(machines, id)); - sq_save_data(sq, m); + dprintf("Loading machines...\n"); + sq = sq_create(); + machines = create_hash(20000); + if (!sq || !machines) + out_of_mem("loading machines"); + + EXEC SQL DECLARE csr104 CURSOR FOR + SELECT mach_id, name, snet_id, owner_type, owner_id, + acomment, ocomment, creator, modby + FROM machine ORDER BY mach_id; + EXEC SQL OPEN csr104; + while (1) + { + EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2, + :sid3, :sid4, :sid; + if (sqlca.sqlcode) + break; + + m = malloc(sizeof(struct machine)); + if (!m) + out_of_mem("storing machines"); + strcpy(m->name, strtrim(name)); + m->owner_type = buf[0]; + m->owner_id = id3; + m->snet_id = id2; + m->mach_id = id; + m->clucount = 0; + m->acomment = sid2; + m->ocomment = sid3; + m->creator = sid4; + m->modby = sid; + retval = hash_store(machines, id, m); + if (retval == -1) + out_of_mem("storing machines in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(machines, id)); + sq_save_data(sq, m); } } - EXEC SQL CLOSE csr104; - generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("looking for duplicate machine names"); - - EXEC SQL DECLARE csr105 CURSOR FOR - SELECT m1.mach_id FROM machine m1, machine m2 - WHERE m1.name = m2.name AND m1.rowid != m2.rowid; - EXEC SQL OPEN csr105; - while(1) { - EXEC SQL FETCH csr105 INTO :id; - if (sqlca.sqlcode != 0) break; - - sq_save_data(sq, hash_lookup(machines, id)); + EXEC SQL CLOSE csr104; + generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("looking for duplicate machine names"); + + EXEC SQL DECLARE csr105 CURSOR FOR + SELECT m1.mach_id FROM machine m1, machine m2 + WHERE m1.name = m2.name AND m1.rowid != m2.rowid; + EXEC SQL OPEN csr105; + while (1) + { + EXEC SQL FETCH csr105 INTO :id; + if (sqlca.sqlcode) + break; + + sq_save_data(sq, hash_lookup(machines, id)); } - EXEC SQL CLOSE csr105; - generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); - - EXEC SQL DECLARE csr_hal1 CURSOR FOR - SELECT h1.name, m1.mach_id, m2.mach_id - FROM hostalias h1, machine m1, hostalias h2, machine m2 - WHERE h1.name=h2.name AND h1.mach_id!=h2.mach_id - AND m1.mach_id=h1.mach_id AND m2.mach_id=h2.mach_id; - EXEC SQL OPEN csr_hal1; - while(1) { + EXEC SQL CLOSE csr105; + generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); + + EXEC SQL DECLARE csr_hal1 CURSOR FOR + SELECT h1.name, m1.mach_id, m2.mach_id + FROM hostalias h1, machine m1, hostalias h2, machine m2 + WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id + AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id; + EXEC SQL OPEN csr_hal1; + while (1) + { EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2; - if(sqlca.sqlcode!=0) break; + if (sqlca.sqlcode) + break; printf("Aliases for machines %d and %d have duplicate name %s\n", id1, id2, strtrim(name)); cant_fix(0); } - EXEC SQL CLOSE csr_hal1; - - EXEC SQL DECLARE csr_hal2 CURSOR FOR - SELECT h1.name, m1.mach_id, m2.mach_id - FROM hostalias h1, machine m1, machine m2 - WHERE h1.name=m1.name AND h1.mach_id=m2.mach_id; - EXEC SQL OPEN csr_hal2; - while(1) { - EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2; - if(sqlca.sqlcode!=0) break; - printf("Machine %d has alias `%s' that conflicts with machine %d\n", - id2, strtrim(name), id1); - cant_fix(0); - } - EXEC SQL CLOSE csr_hal2; - } - - dprintf("Loading subnets...\n"); - subnets = create_hash(254); - if(!subnets) out_of_mem("loading subnets"); - - EXEC SQL DECLARE csr115 CURSOR FOR - SELECT snet_id, name, owner_type, owner_id, modby from subnet; - EXEC SQL OPEN csr115; - while(1) { - EXEC SQL FETCH csr115 INTO :id, :name, :buf, :id2, :sid; - if (sqlca.sqlcode != 0) break; - - sn = (struct subnet *) malloc(sizeof(struct machine)); - if (sn == NULL) - out_of_mem("storing subnets"); - strcpy(sn->name, strtrim(name)); - sn->owner_type=buf[0]; - sn->owner_id = id2; - sn->snet_id = id; - sn->modby = sid; - retval = hash_store(subnets, id, sn); - if ( retval == -1 ) { - out_of_mem("storing subnets in hash table"); - } else if ( retval == 1 ) { - printf("Duplicate subnet ID: %d (%s)\n", id, name); - /* should add code to delete */ + EXEC SQL CLOSE csr_hal1; + + EXEC SQL DECLARE csr_hal2 CURSOR FOR + SELECT h1.name, m1.mach_id, m2.mach_id + FROM hostalias h1, machine m1, machine m2 + WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id; + EXEC SQL OPEN csr_hal2; + while (1) + { + EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2; + if (sqlca.sqlcode) + break; + printf("Machine %d has alias %s that conflicts with machine %d\n", + id2, strtrim(name), id1); cant_fix(0); - } + } + EXEC SQL CLOSE csr_hal2; } - EXEC SQL CLOSE csr115; - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("looking for duplicate subnet names"); - EXEC SQL DECLARE csr117 CURSOR FOR - SELECT s1.snet_id FROM subnet s1, subnet s2 - WHERE s1.name = s2.name AND s1.rowid != s2.rowid; - EXEC SQL OPEN csr117; - while(1) { - EXEC SQL FETCH csr117 INTO :id; - if (sqlca.sqlcode != 0) break; + dprintf("Loading subnets...\n"); + subnets = create_hash(254); + if (!subnets) + out_of_mem("loading subnets"); + + EXEC SQL DECLARE csr115 CURSOR FOR + SELECT snet_id, name, owner_type, owner_id, modby from subnet; + EXEC SQL OPEN csr115; + while (1) + { + EXEC SQL FETCH csr115 INTO :id, :name, :buf, :id2, :sid; + if (sqlca.sqlcode) + break; + + sn = malloc(sizeof(struct machine)); + if (!sn) + out_of_mem("storing subnets"); + strcpy(sn->name, strtrim(name)); + sn->owner_type = buf[0]; + sn->owner_id = id2; + sn->snet_id = id; + sn->modby = sid; + retval = hash_store(subnets, id, sn); + if (retval == -1) + out_of_mem("storing subnets in hash table"); + else if (retval == 1) + { + printf("Duplicate subnet ID: %d (%s)\n", id, name); + /* should add code to delete */ + cant_fix(0); + } + } + EXEC SQL CLOSE csr115; + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("looking for duplicate subnet names"); + + EXEC SQL DECLARE csr117 CURSOR FOR + SELECT s1.snet_id FROM subnet s1, subnet s2 + WHERE s1.name = s2.name AND s1.rowid != s2.rowid; + EXEC SQL OPEN csr117; + while (1) + { + EXEC SQL FETCH csr117 INTO :id; + if (sqlca.sqlcode) + break; - sq_save_data(sq, hash_lookup(subnets, id)); + sq_save_data(sq, hash_lookup(subnets, id)); } - EXEC SQL CLOSE csr117; - generic_fix(sq, show_snet_name, "Change name", cant_fix, 0); + EXEC SQL CLOSE csr117; + generic_fix(sq, show_snet_name, "Change name", cant_fix, 0); } - - dprintf("Loading clusters...\n"); - sq = sq_create(); - clusters = create_hash(100); - if(!sq || !clusters) out_of_mem("loading clusters"); - - EXEC SQL DECLARE csr106 CURSOR FOR - SELECT clu_id, name, modby FROM clusters; - EXEC SQL OPEN csr106; - while(1) { - EXEC SQL FETCH csr106 INTO :id, :name, :sid; - if (sqlca.sqlcode != 0) break; - - c = (struct cluster *) malloc(sizeof(struct cluster)); - if (c == NULL) - out_of_mem("storing clusters"); - strcpy(c->name, strtrim(name)); - c->clu_id = id; - c->modby = sid; - retval = hash_store(clusters, id, c); - if ( retval == -1 ) { - out_of_mem("storing clusters in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(clusters, id)); - sq_save_data(sq, c); + + dprintf("Loading clusters...\n"); + sq = sq_create(); + clusters = create_hash(100); + if (!sq || !clusters) + out_of_mem("loading clusters"); + + EXEC SQL DECLARE csr106 CURSOR FOR + SELECT clu_id, name, modby FROM clusters; + EXEC SQL OPEN csr106; + while (1) + { + EXEC SQL FETCH csr106 INTO :id, :name, :sid; + if (sqlca.sqlcode) + break; + + c = malloc(sizeof(struct cluster)); + if (!c) + out_of_mem("storing clusters"); + strcpy(c->name, strtrim(name)); + c->clu_id = id; + c->modby = sid; + retval = hash_store(clusters, id, c); + if (retval == -1) + out_of_mem("storing clusters in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(clusters, id)); + sq_save_data(sq, c); } } - EXEC SQL CLOSE csr106; - generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0); - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("looking for duplicate cluster names"); - - EXEC SQL DECLARE csr107 CURSOR FOR - SELECT c1.clu_id FROM clusters c1, clusters c2 - WHERE c1.name=c2.name AND c1.rowid != c2.rowid; - EXEC SQL OPEN csr107; - while(1) { - EXEC SQL FETCH csr107 INTO :id; - if (sqlca.sqlcode != 0) break; - - sq_save_data(sq, hash_lookup(clusters, id)); + EXEC SQL CLOSE csr106; + generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0); + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("looking for duplicate cluster names"); + + EXEC SQL DECLARE csr107 CURSOR FOR + SELECT c1.clu_id FROM clusters c1, clusters c2 + WHERE c1.name = c2.name AND c1.rowid != c2.rowid; + EXEC SQL OPEN csr107; + while (1) + { + EXEC SQL FETCH csr107 INTO :id; + if (sqlca.sqlcode) + break; + + sq_save_data(sq, hash_lookup(clusters, id)); } - EXEC SQL CLOSE csr107; - generic_fix(sq, show_clu_name, "Change name", cant_fix, 0); + EXEC SQL CLOSE csr107; + generic_fix(sq, show_clu_name, "Change name", cant_fix, 0); } - dprintf("Loading lists...\n"); - sq = sq_create(); - lists = create_hash(50000); - if(!sq || !lists) out_of_mem("loading lists"); - - EXEC SQL DECLARE csr108 CURSOR FOR - SELECT list_id, name, acl_id, acl_type, modby FROM list - ORDER BY list_id; - EXEC SQL OPEN csr108; - while(1) { - EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid; - if (sqlca.sqlcode != 0) break; - l = (struct list *) malloc(sizeof(struct list)); - if (l == NULL) - out_of_mem("storing lists"); - strcpy(l->name, strtrim(name)); - l->acl_type = buf[0]; - l->acl_id = aid; - l->list_id = id; - l->members = 0; - retval = hash_store(lists, id, l); - if ( retval == -1 ) { - out_of_mem("storing lists in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(lists, id)); - sq_save_data(sq, l); + dprintf("Loading lists...\n"); + sq = sq_create(); + lists = create_hash(50000); + if (!sq || !lists) + out_of_mem("loading lists"); + + EXEC SQL DECLARE csr108 CURSOR FOR + SELECT list_id, name, acl_id, acl_type, modby FROM list + ORDER BY list_id; + EXEC SQL OPEN csr108; + while (1) + { + EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid; + if (sqlca.sqlcode) + break; + l = malloc(sizeof(struct list)); + if (!l) + out_of_mem("storing lists"); + strcpy(l->name, strtrim(name)); + l->acl_type = buf[0]; + l->acl_id = aid; + l->list_id = id; + l->members = 0; + retval = hash_store(lists, id, l); + if (retval == -1) + out_of_mem("storing lists in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(lists, id)); + sq_save_data(sq, l); } } - EXEC SQL CLOSE csr108; - generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0); - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("looking for duplicate list names"); - - EXEC SQL DECLARE csr109 CURSOR FOR - SELECT l1.list_id FROM list l1, list l2 - WHERE l1.name=l2.name AND l1.rowid != l2.rowid; - EXEC SQL OPEN csr109; - while(1) { - EXEC SQL FETCH csr109 INTO :id; - if (sqlca.sqlcode != 0) break; - - sq_save_data(sq, hash_lookup(lists, id)); + EXEC SQL CLOSE csr108; + generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0); + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("looking for duplicate list names"); + + EXEC SQL DECLARE csr109 CURSOR FOR + SELECT l1.list_id FROM list l1, list l2 + WHERE l1.name = l2.name AND l1.rowid != l2.rowid; + EXEC SQL OPEN csr109; + while (1) + { + EXEC SQL FETCH csr109 INTO :id; + if (sqlca.sqlcode) + break; + + sq_save_data(sq, hash_lookup(lists, id)); } - EXEC SQL CLOSE csr109; - generic_fix(sq, show_list_name, "Change name", cant_fix, 0); + EXEC SQL CLOSE csr109; + generic_fix(sq, show_list_name, "Change name", cant_fix, 0); } - dprintf("Loading filesys...\n"); - sq = sq_create(); - filesys = create_hash(30000); - if(!sq || !filesys) out_of_mem("loading filesys"); - - EXEC SQL DECLARE csr110 CURSOR FOR - SELECT filsys_id, label, owner, owners, phys_id, mach_id, - type, name, modby FROM filesys ORDER BY filsys_id; - EXEC SQL OPEN csr110; - while(1) { - EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3, - :buf, :name1, :sid; - if (sqlca.sqlcode != 0) break; - - f = (struct filesys *) malloc(sizeof(struct filesys)); - if (f == NULL) - out_of_mem("storing filesystems"); - strcpy(f->name, strtrim(name)); - strcpy(f->dir, strtrim(name1)); - f->filsys_id = id; - f->owner = aid; - f->owners = aid2; - f->phys_id = id2; - f->mach_id = id3; - f->type = buf[0]; - retval = hash_store(filesys, id, f); - if ( retval == -1 ) { - out_of_mem("storing filesys in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(filesys, id)); - sq_save_data(sq, f); + dprintf("Loading filesys...\n"); + sq = sq_create(); + filesys = create_hash(30000); + if (!sq || !filesys) + out_of_mem("loading filesys"); + + EXEC SQL DECLARE csr110 CURSOR FOR + SELECT filsys_id, label, owner, owners, phys_id, mach_id, + type, name, modby FROM filesys ORDER BY filsys_id; + EXEC SQL OPEN csr110; + while (1) + { + EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3, + :buf, :name1, :sid; + if (sqlca.sqlcode) + break; + + f = malloc(sizeof(struct filesys)); + if (!f) + out_of_mem("storing filesystems"); + strcpy(f->name, strtrim(name)); + strcpy(f->dir, strtrim(name1)); + f->filsys_id = id; + f->owner = aid; + f->owners = aid2; + f->phys_id = id2; + f->mach_id = id3; + f->type = buf[0]; + retval = hash_store(filesys, id, f); + if (retval == -1) + out_of_mem("storing filesys in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(filesys, id)); + sq_save_data(sq, f); } } - EXEC SQL CLOSE csr110; - - generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0); - - if (!fast) { - sq = sq_create(); - if(!sq) out_of_mem("looking for duplicate filesys names"); - - EXEC SQL DECLARE csr118 CURSOR FOR - SELECT fs1.filsys_id FROM filesys fs1, filesys fs2 - WHERE fs1.label=fs2.label AND fs1.rowid != fs2.rowid; - EXEC SQL OPEN csr118; - while(1) { - EXEC SQL FETCH csr118 INTO :id; - if (sqlca.sqlcode != 0) break; - - sq_save_data(sq, hash_lookup(filesys, id)); + EXEC SQL CLOSE csr110; + + generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0); + + if (!fast) + { + sq = sq_create(); + if (!sq) + out_of_mem("looking for duplicate filesys names"); + + EXEC SQL DECLARE csr118 CURSOR FOR + SELECT fs1.filsys_id FROM filesys fs1, filesys fs2 + WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid; + EXEC SQL OPEN csr118; + while (1) + { + EXEC SQL FETCH csr118 INTO :id; + if (sqlca.sqlcode) + break; + + sq_save_data(sq, hash_lookup(filesys, id)); } - EXEC SQL CLOSE csr118; - generic_fix(sq, show_fs_name, "Change name", cant_fix, 0); + EXEC SQL CLOSE csr118; + generic_fix(sq, show_fs_name, "Change name", cant_fix, 0); } - dprintf("Loading nfsphys...\n"); - sq = sq_create(); - nfsphys = create_hash(500); - if(!sq || !nfsphys) out_of_mem("loading nfsphs"); - - EXEC SQL DECLARE csr111 CURSOR FOR - SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys; - EXEC SQL OPEN csr111; - while(1) { - EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid; - if (sqlca.sqlcode != 0) break; - - n = (struct nfsphys *) malloc(sizeof(struct nfsphys)); - if (n == NULL) - out_of_mem("storing nfsphys"); - strcpy(n->dir, strtrim(name)); - n->mach_id = id2; - n->nfsphys_id = id; - n->allocated = id3; - n->count = 0; - retval = hash_store(nfsphys, id, n); - if ( retval == -1 ) { - out_of_mem("storing nfsphys in hash table"); - } else if ( retval == 1 ) { - sq_save_data(sq, hash_lookup(nfsphys, id)); - sq_save_data(sq, n); + dprintf("Loading nfsphys...\n"); + sq = sq_create(); + nfsphys = create_hash(500); + if (!sq || !nfsphys) + out_of_mem("loading nfsphs"); + + EXEC SQL DECLARE csr111 CURSOR FOR + SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys; + EXEC SQL OPEN csr111; + while (1) + { + EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid; + if (sqlca.sqlcode) + break; + + n = malloc(sizeof(struct nfsphys)); + if (!n) + out_of_mem("storing nfsphys"); + strcpy(n->dir, strtrim(name)); + n->mach_id = id2; + n->nfsphys_id = id; + n->allocated = id3; + n->count = 0; + retval = hash_store(nfsphys, id, n); + if (retval == -1) + out_of_mem("storing nfsphys in hash table"); + else if (retval == 1) + { + sq_save_data(sq, hash_lookup(nfsphys, id)); + sq_save_data(sq, n); } } - EXEC SQL CLOSE csr111; + EXEC SQL CLOSE csr111; - generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0); + generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0); - dprintf("Checking printcap...\n"); + dprintf("Checking printcap...\n"); - EXEC SQL DECLARE csr119 CURSOR FOR - SELECT p1.name FROM printcap p1, printcap p2 - WHERE p1.name=p2.name AND p1.rowid #include +#include #include #include "dbck.h" EXEC SQL INCLUDE sqlca; @@ -15,959 +16,984 @@ static char phase2_qc_rcsid[] = "$Header$"; EXEC SQL WHENEVER SQLERROR DO dbmserr(); -show_mcm_mach(id) -int id; +int show_mcm_mach(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr201 CURSOR FOR - SELECT clusters.name FROM clusters, mcmap - WHERE clusters.clu_id=mcmap.clu_id AND mcmap.mach_id = :iid; - EXEC SQL OPEN csr201; - while(1) { - EXEC SQL FETCH csr201 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - found = 0; - printf("Cluster %s, non-existant machine %d in cluster map\n", name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr201 CURSOR FOR + SELECT clusters.name FROM clusters, mcmap + WHERE clusters.clu_id = mcmap.clu_id AND mcmap.mach_id = :iid; + EXEC SQL OPEN csr201; + while (1) + { + EXEC SQL FETCH csr201 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + found = 0; + printf("Cluster %s, non-existant machine %d in cluster map\n", name, id); } - EXEC SQL CLOSE csr201; - return(found); + EXEC SQL CLOSE csr201; + return found; } -show_mcm_clu(id) -int id; +int show_mcm_clu(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr202 CURSOR FOR - SELECT machine.name FROM machine, mcmap - WHERE machine.mach_id=mcmap.mach_id AND mcmap.clu_id=:iid; - EXEC SQL OPEN csr202; - while(1) { - EXEC SQL FETCH csr202 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - - found = 0; - printf("Machine %s, non-existant cluster %d in cluster map\n", name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr202 CURSOR FOR + SELECT machine.name FROM machine, mcmap + WHERE machine.mach_id = mcmap.mach_id AND mcmap.clu_id = :iid; + EXEC SQL OPEN csr202; + while (1) + { + EXEC SQL FETCH csr202 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + + found = 0; + printf("Machine %s, non-existant cluster %d in cluster map\n", name, id); } - EXEC SQL CLOSE csr202; - return(found); + EXEC SQL CLOSE csr202; + return found; } -show_hostalias(id) -int id; +int show_hostalias(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr234 CURSOR FOR - SELECT name FROM hostalias WHERE mach_id=:iid; - EXEC SQL OPEN csr234; - while(1) { - EXEC SQL FETCH csr234 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - - found = 0; - printf("Alias %s, non-existant machine %d in hostalias map\n", name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr234 CURSOR FOR + SELECT name FROM hostalias WHERE mach_id = :iid; + EXEC SQL OPEN csr234; + while (1) + { + EXEC SQL FETCH csr234 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + + found = 0; + printf("Alias %s, non-existant machine %d in hostalias map\n", name, id); } - EXEC SQL CLOSE csr234; - return(found); + EXEC SQL CLOSE csr234; + return found; } -show_pcap_mach(id) -int id; +int show_pcap_mach(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr235 CURSOR FOR - SELECT name FROM printcap WHERE mach_id=:iid; - EXEC SQL OPEN csr235; - while(1) { - EXEC SQL FETCH csr235 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - - found = 0; - printf("Printer %s, non-existant spool machine %d in printcap table\n", name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr235 CURSOR FOR + SELECT name FROM printcap WHERE mach_id = :iid; + EXEC SQL OPEN csr235; + while (1) + { + EXEC SQL FETCH csr235 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + + found = 0; + printf("Printer %s, non-existant spool machine %d in printcap table\n", + name, id); } - EXEC SQL CLOSE csr235; - return(found); + EXEC SQL CLOSE csr235; + return found; } -show_pcap_quota(id) -int id; +int show_pcap_quota(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr236 CURSOR FOR - SELECT name FROM printcap WHERE quotaserver=:iid; - EXEC SQL OPEN csr236; - while(1) { - EXEC SQL FETCH csr236 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - - found = 0; - printf("Printer %s, non-existant quota server %d in printcap table\n", name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr236 CURSOR FOR + SELECT name FROM printcap WHERE quotaserver = :iid; + EXEC SQL OPEN csr236; + while (1) + { + EXEC SQL FETCH csr236 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + + found = 0; + printf("Printer %s, non-existant quota server %d in printcap table\n", + name, id); } - EXEC SQL CLOSE csr236; - return(found); + EXEC SQL CLOSE csr236; + return found; } -user_check(id, u, hint) - int id; - struct user *u; - int hint; +user_check(int id, struct user *u, int hint) { - u->comment=maybe_fixup_unref_string(u->comment, id, u->login, "users", - "comments", "users_id"); + u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users", + "comments", "users_id"); + + u->modby = maybe_fixup_modby(u->modby, id, u->login, "users", + "modby", "users_id"); - u->modby=maybe_fixup_modby(u->modby, id, u->login, "users", - "modby", "users_id"); + u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users", + "fmodby", "users_id"); - u->fmodby=maybe_fixup_modby(u->fmodby, id, u->login, "users", - "fmodby", "users_id"); + u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users", + "pmodby", "users_id"); - u->pmodby=maybe_fixup_modby(u->pmodby, id, u->login, "users", - "pmodby", "users_id"); + u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users", + "sigwho", "users_id"); - u->sigwho=maybe_fixup_unref_string(u->sigwho, id, u->login, "users", - "sigwho", "users_id"); - pobox_check(id, u, hint); } -maybe_fixup_unref_string(sid, oid, oname, table, field, idfield) - int sid, oid; - char *oname, *table; - char *field, *idfield; +int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table, + char *field, char *idfield) { - int ret=(sid<0)?-sid:sid, doit=0, newid; + int ret = (sid < 0) ? -sid : sid, doit = 0, newid; EXEC SQL BEGIN DECLARE SECTION; int rowcount; char stmt_buf[500]; EXEC SQL END DECLARE SECTION; - - if(newid=int_hash_lookup(string_dups, ret)) { - printf("%s entry %s(%d) has a %s with duplicate string %d\n", - table, oname, oid, field, ret); - if(single_fix("Replace duplicate", 0)){ - ret = newid; - string_check(newid); - doit=1; + + if (newid = int_hash_lookup(string_dups, ret)) + { + printf("%s entry %s(%d) has a %s with duplicate string %d\n", + table, oname, oid, field, ret); + if (single_fix("Replace duplicate", 0)) + { + ret = newid; + string_check(newid); + doit = 1; + } } - } else if(!string_check(ret)) { - printf("%s entry %s(%d) has a %s with non-existant string %d\n", - table, oname, oid, field, ret); - if (single_fix("Delete", 1)) { - ret=0; - doit=1; + else if (!string_check(ret)) + { + printf("%s entry %s(%d) has a %s with non-existant string %d\n", + table, oname, oid, field, ret); + if (single_fix("Delete", 1)) + { + ret = 0; + doit = 1; + } + } + + if (doit) + { + sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d", + table, field, (sid < 0) ? -ret : ret, idfield, oid); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount == 1) + printf("Fixed\n"); + else + printf("Not fixed, rowcount = %d\n", rowcount); + modified(table); } - } - - if(doit){ - sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d", - table, field, (sid<0)?-ret:ret, idfield, oid); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount == 1) - printf("Fixed\n"); - else - printf("Not fixed, rowcount = %d\n", rowcount); - modified(table); - } - - return((sid<0)?-ret:ret); + return (sid < 0) ? -ret : ret; } -maybe_fixup_modby(sid, oid, oname, table, field, idfield) - int sid, oid; - char *oname, *table; - char *field, *idfield; +int maybe_fixup_modby(int sid, int oid, char *oname, char *table, + char *field, char *idfield) { EXEC SQL BEGIN DECLARE SECTION; char stmt_buf[500]; int rowcount; EXEC SQL END DECLARE SECTION; - if(sid<0) + if (sid < 0) return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield); - else { - if(!hash_lookup(users, sid)) { - printf("%s entry %s(%d) has a %s with non-existant user %d\n", - table, oname, oid, field, sid); - if (single_fix("Delete", 1)) { - sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d", - table, field, idfield, oid); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount == 1) - printf("Fixed\n"); - else - printf("Not fixed, rowcount = %d\n", rowcount); - modified(table); - } - return 0; + else + { + if (!hash_lookup(users, sid)) + { + printf("%s entry %s(%d) has a %s with non-existant user %d\n", + table, oname, oid, field, sid); + if (single_fix("Delete", 1)) + { + sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d", + table, field, idfield, oid); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount == 1) + printf("Fixed\n"); + else + printf("Not fixed, rowcount = %d\n", rowcount); + modified(table); + } + return 0; + } } - } return sid; } -maybe_fixup_unref_string2(table, field, cursor, sid) - int sid; - char *field, *table, *cursor; +int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid) { - int ret=(sid<0)?-sid:sid, doit=0, newid; + int ret = (sid < 0) ? -sid : sid, doit = 0, newid; EXEC SQL BEGIN DECLARE SECTION; int rowcount; char stmt_buf[500]; EXEC SQL END DECLARE SECTION; - - if(newid=int_hash_lookup(string_dups, ret)) { - printf("%s entry has a %s with duplicate string %d\n", - table, field, ret); - if(single_fix("Replace duplicate", 0)){ - ret = newid; - string_check(newid); - doit=1; + + if ((newid = int_hash_lookup(string_dups, ret))) + { + printf("%s entry has a %s with duplicate string %d\n", + table, field, ret); + if (single_fix("Replace duplicate", 0)) + { + ret = newid; + string_check(newid); + doit = 1; + } + } + else if (!string_check(ret)) + { + printf("%s entry has a %s with non-existant string %d\n", + table, field, ret); + if (single_fix("Delete", 1)) + { + ret = 0; + doit = 1; + } } - } else if(!string_check(ret)) { - printf("%s entry has a %s with non-existant string %d\n", - table, field, ret); - if (single_fix("Delete", 1)) { - ret=0; - doit=1; + + if (doit) + { + sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s", + table, field, (sid < 0) ? -ret : ret, cursor); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount == 1) + printf("Fixed\n"); + else + printf("Not fixed, rowcount = %d\n", rowcount); + modified(table); } - } - - if(doit){ - sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s", - table, field, (sid<0)?-ret:ret, cursor); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount == 1) - printf("Fixed\n"); - else - printf("Not fixed, rowcount = %d\n", rowcount); - modified(table); - } - return((sid<0)?-ret:ret); + return (sid < 0) ? -ret : ret; } -maybe_fixup_modby2(table, field, cursor, id) +int maybe_fixup_modby2(char *table, char *field, char *cursor, int id) { EXEC SQL BEGIN DECLARE SECTION; char stmt_buf[500]; int rowcount; EXEC SQL END DECLARE SECTION; - if(id<0) return maybe_fixup_unref_string2(table, field, cursor, id); - else { - if(!hash_lookup(users, id)) { - printf("%s entry has a %s with non-existant user %d\n", - table, field, id); - if (single_fix("Delete", 1)) { - sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE CURRENT OF %s", - table, field, cursor); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - rowcount = sqlca.sqlerrd[2]; - if (rowcount == 1) - printf("Fixed\n"); - else - printf("Not fixed, rowcount = %d\n", rowcount); - modified(table); - } - return 0; + if (id < 0) + return maybe_fixup_unref_string2(table, field, cursor, id); + else + { + if (!hash_lookup(users, id)) + { + printf("%s entry has a %s with non-existant user %d\n", + table, field, id); + if (single_fix("Delete", 1)) + { + sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE CURRENT OF %s", + table, field, cursor); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + rowcount = sqlca.sqlerrd[2]; + if (rowcount == 1) + printf("Fixed\n"); + else + printf("Not fixed, rowcount = %d\n", rowcount); + modified(table); + } + return 0; + } } - } return 1; } -pobox_check(id, u, hint) -int id; -struct user *u; -int hint; +pobox_check(int id, struct user *u, int hint) { - switch (u->potype) { - case 'P': - if (!hash_lookup(machines, u->pobox_id)) { - printf("User %s(%s) has P.O.Box on non-existant machine %d\n", - u->login, u->fullname, u->pobox_id); - if (single_fix("Delete", 0)) { - remove_pobox(u->users_id); - u->potype = 'N'; - } - } - break; - case 'S': - if( int_hash_lookup( string_dups, u->pobox_id ) ) { - printf("User %s(%s) has P.O.Box with duplicate string %d\n", - u->login, u->fullname, u->pobox_id); - if(single_fix("Update", 0)){ - printf("Replacing box_id dup string ID %d with %d\n", - u->pobox_id, - int_hash_lookup(string_dups, u->pobox_id)); - u->pobox_id = int_hash_lookup( string_dups, u->pobox_id ); - fix_smtp_pobox(u->users_id, u->pobox_id); - string_check(u->pobox_id); - } - } else if (!string_check(u->pobox_id)) { - printf("User %s(%s) has P.O.Box with non-existant string %d\n", - u->login, u->fullname, u->pobox_id); - if (single_fix("Delete", 0)) { - remove_pobox(u->users_id); - u->potype = 'N'; - } + switch (u->potype) + { + case 'P': + if (!hash_lookup(machines, u->pobox_id)) + { + printf("User %s(%s) has P.O.Box on non-existant machine %d\n", + u->login, u->fullname, u->pobox_id); + if (single_fix("Delete", 0)) + { + remove_pobox(u->users_id); + u->potype = 'N'; + } + } + break; + case 'S': + if (int_hash_lookup(string_dups, u->pobox_id)) + { + printf("User %s(%s) has P.O.Box with duplicate string %d\n", + u->login, u->fullname, u->pobox_id); + if (single_fix("Update", 0)) + { + printf("Replacing box_id dup string ID %d with %d\n", + u->pobox_id, + int_hash_lookup(string_dups, u->pobox_id)); + u->pobox_id = int_hash_lookup(string_dups, u->pobox_id); + fix_smtp_pobox(u->users_id, u->pobox_id); + string_check(u->pobox_id); + } + } + else if (!string_check(u->pobox_id)) + { + printf("User %s(%s) has P.O.Box with non-existant string %d\n", + u->login, u->fullname, u->pobox_id); + if (single_fix("Delete", 0)) + { + remove_pobox(u->users_id); + u->potype = 'N'; + } + } + break; + default: + ; } - break; - default: - ; - } } -remove_pobox(id) -int id; +remove_pobox(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, iid = id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not removed\n"); - modified("users"); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, iid = id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not removed\n"); + modified("users"); } -fix_smtp_pobox(id, sid) -int id, sid; +fix_smtp_pobox(int id, int sid) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, iid = id, isid=sid; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE users SET box_id=:isid WHERE users.users_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s updated\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not updated\n"); - modified("users"); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, iid = id, isid = sid; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not updated\n"); + modified("users"); } -mach_check(id, m, hint) -int id; -struct machine *m; -int hint; +mach_check(int id, struct machine *m, int hint) { - if (!hash_lookup(subnets, m->snet_id)) { - printf("Machine %s is on a non-existant subnet %d\n", - m->name, m->snet_id); - if (single_fix("Move to null-subnet", 1)) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, iid = id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("machine"); + if (!hash_lookup(subnets, m->snet_id)) + { + printf("Machine %s is on a non-existant subnet %d\n", + m->name, m->snet_id); + if (single_fix("Move to null-subnet", 1)) + { + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, iid = id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("machine"); } } - switch (m->owner_type) { + switch (m->owner_type) + { case 'U': - if (!hash_lookup(users, m->owner_id)) { - printf("Machine %s has non-existant USER owner %d\n", - m->name, m->owner_id); - if (single_fix("Set to no owner", 1)) { - clear_mach_owner(m); - } + if (!hash_lookup(users, m->owner_id)) + { + printf("Machine %s has non-existant USER owner %d\n", + m->name, m->owner_id); + if (single_fix("Set to no owner", 1)) + clear_mach_owner(m); } - break; + break; case 'L': - if (!hash_lookup(lists, m->owner_id)) { - printf("Machine %s has non-existant LIST owner %d\n", - m->name, m->owner_id); - if (single_fix("Set to no owner", 1)) { - clear_mach_owner(m); - } + if (!hash_lookup(lists, m->owner_id)) + { + printf("Machine %s has non-existant LIST owner %d\n", + m->name, m->owner_id); + if (single_fix("Set to no owner", 1)) + clear_mach_owner(m); } - break; + break; case 'S': case 'K': - if(m->owner_id) - m->owner_id=maybe_fixup_unref_string(m->owner_id, id, m->name, - "machine", "owner_id", "mach_id"); - if(m->owner_id==0) + if (m->owner_id) + m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name, + "machine", "owner_id", + "mach_id"); + if (m->owner_id == 0) clear_mach_owner(m); } - if(m->acomment) - m->acomment=maybe_fixup_unref_string(m->acomment, id, m->name, + if (m->acomment) + m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name, "machine", "acomment", "mach_id"); - if(m->ocomment) - m->ocomment=maybe_fixup_unref_string(m->ocomment, id, m->name, + if (m->ocomment) + m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name, "machine", "ocomment", "mach_id"); - - m->creator=maybe_fixup_modby(m->creator, id, m->name, "machine", + + m->creator = maybe_fixup_modby(m->creator, id, m->name, "machine", "creator", "mach_id"); - m->modby=maybe_fixup_modby(m->modby, id, m->name, "machine", + m->modby = maybe_fixup_modby(m->modby, id, m->name, "machine", "modby", "mach_id"); } -subnet_check(id, s, hint) -int id; -struct subnet *s; -int hint; +subnet_check(int id, struct subnet *s, int hint) { - switch (s->owner_type) { + switch (s->owner_type) + { case 'U': - if (!hash_lookup(users, s->owner_id)) { - printf("Subnet %s has non-existant USER owner %d\n", - s->name, s->owner_id); - if (single_fix("Set to no owner", 1)) { - clear_subnet_owner(s); - } + if (!hash_lookup(users, s->owner_id)) + { + printf("Subnet %s has non-existant USER owner %d\n", + s->name, s->owner_id); + if (single_fix("Set to no owner", 1)) + clear_subnet_owner(s); } - break; + break; case 'L': - if (!hash_lookup(lists, s->owner_id)) { - printf("Machine %s has non-existant LIST owner %d\n", - s->name, s->owner_id); - if (single_fix("Set to no owner", 1)) { - clear_subnet_owner(s); - } + if (!hash_lookup(lists, s->owner_id)) + { + printf("Machine %s has non-existant LIST owner %d\n", + s->name, s->owner_id); + if (single_fix("Set to no owner", 1)) + clear_subnet_owner(s); } - break; + break; case 'S': case 'K': - if(s->owner_id) - s->owner_id=maybe_fixup_unref_string(s->owner_id, id, s->name, - "machine", "owner_id", "mach_id"); - if(s->owner_id==0) + if (s->owner_id) + s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name, + "machine", "owner_id", + "mach_id"); + if (s->owner_id == 0) clear_subnet_owner(s); } - s->modby=maybe_fixup_modby(s->modby, id, s->name, "subnet", + s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet", "modby", "snet_id"); } - -clear_subnet_owner(s) -struct subnet *s; +clear_subnet_owner(struct subnet *s) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, id = s->snet_id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE subnet SET owner_type='NONE', owner_id=0 - WHERE snet_id = :id; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("subnet"); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = s->snet_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0 + WHERE snet_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("subnet"); } -clear_mach_owner(m) -struct machine *m; +clear_mach_owner(struct machine *m) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, id = m->mach_id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0 - WHERE mach_id = :id; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("machine"); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = m->mach_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0 + WHERE mach_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("machine"); } -cluster_check(id, c, hint) -int id; -struct cluster *c; -int hint; +cluster_check(int id, struct cluster *c, int hint) { - c->modby=maybe_fixup_modby(c->modby, id, c->name, "clusters", + c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters", "modby", "clu_id"); } +int show_svc(int id) +{ + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1; + char label[17], data[33]; + EXEC SQL END DECLARE SECTION; + EXEC SQL DECLARE csr203 CURSOR FOR + SELECT serv_label, serv_cluster FROM svc + WHERE clu_id = :iid; + EXEC SQL OPEN csr203; + while (1) + { + EXEC SQL FETCH csr203 INTO :label, :data; + if (sqlca.sqlcode) + break; -show_svc(id) -int id; -{ - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1; - char label[17], data[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr203 CURSOR FOR - SELECT serv_label, serv_cluster FROM svc - WHERE clu_id = :iid; - EXEC SQL OPEN csr203; - while(1) { - EXEC SQL FETCH csr203 INTO :label, :data; - if (sqlca.sqlcode != 0) break; - - strtrim(label); - strtrim(data); - found = 0; - printf("Cluster data [%s] %s for non-existant cluster %d\n", - label, data, id); + strtrim(label); + strtrim(data); + found = 0; + printf("Cluster data [%s] %s for non-existant cluster %d\n", + label, data, id); } - EXEC SQL CLOSE csr203; - return(found); + EXEC SQL CLOSE csr203; + return found; } -list_check(id, l, hint) -int id; -struct list *l; -int hint; +list_check(int id, struct list *l, int hint) { - switch (l->acl_type) { + switch (l->acl_type) + { case 'L': - if (!hash_lookup(lists, l->acl_id)) { - printf("List %s has bad LIST acl %d\n", l->name, l->acl_id); - if (single_fix("Patch", 1)) { - fix_list_acl(l->list_id); - } + if (!hash_lookup(lists, l->acl_id)) + { + printf("List %s has bad LIST acl %d\n", l->name, l->acl_id); + if (single_fix("Patch", 1)) + fix_list_acl(l->list_id); } - break; + break; case 'U': - if (!hash_lookup(users, l->acl_id)) { - printf("List %s has bad USER acl %d\n", l->name, l->acl_id); - if (single_fix("Patch", 1)) { - fix_list_acl(l->list_id); - } + if (!hash_lookup(users, l->acl_id)) + { + printf("List %s has bad USER acl %d\n", l->name, l->acl_id); + if (single_fix("Patch", 1)) + fix_list_acl(l->list_id); } - break; + break; case 'K': - l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name, - "list", "acl_id", "list_id"); - if (!l->acl_id) { - printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id); - if(single_fix("Patch", 1)) { - fix_list_acl(l->list_id); - } + l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name, + "list", "acl_id", "list_id"); + if (!l->acl_id) + { + printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id); + if (single_fix("Patch", 1)) + fix_list_acl(l->list_id); } - break; + break; } } -fix_list_acl(id) -int id; +fix_list_acl(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, iid = id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST' - WHERE list_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("list"); -} + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, iid = id; + EXEC SQL END DECLARE SECTION; + EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST' + WHERE list_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("list"); +} -show_member_list(id) -int id; +int show_member_list(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int mid, iid = id, found = 1; - char mtype[9], *name = ""; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr204 CURSOR FOR - SELECT member_type, member_id FROM imembers - WHERE list_id = :iid AND direct=1; - EXEC SQL OPEN csr204; - while(1) { - EXEC SQL FETCH csr204 INTO :mtype, :mid; - if (sqlca.sqlcode != 0) break; - - strtrim(mtype); - found = 0; - if (mtype[0] == 'L') - name = ((struct list *) hash_lookup(lists, mid))->name; - else if (mtype[0] == 'U') - name = ((struct user *) hash_lookup(users, mid))->login; - else if (mtype[0] == 'S' || mtype[0] == 'K') - name = ((struct string *) hash_lookup(strings, mid))->name; - printf("Non-existant list %d has member %s %s\n", iid, mtype, name); + EXEC SQL BEGIN DECLARE SECTION; + int mid, iid = id, found = 1; + char mtype[9], *name = ""; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr204 CURSOR FOR + SELECT member_type, member_id FROM imembers + WHERE list_id = :iid AND direct = 1; + EXEC SQL OPEN csr204; + while (1) + { + EXEC SQL FETCH csr204 INTO :mtype, :mid; + if (sqlca.sqlcode) + break; + + strtrim(mtype); + found = 0; + if (mtype[0] == 'L') + name = ((struct list *) hash_lookup(lists, mid))->name; + else if (mtype[0] == 'U') + name = ((struct user *) hash_lookup(users, mid))->login; + else if (mtype[0] == 'S' || mtype[0] == 'K') + name = ((struct string *) hash_lookup(strings, mid))->name; + printf("Non-existant list %d has member %s %s\n", iid, mtype, name); } - EXEC SQL CLOSE csr204; - return(found); + EXEC SQL CLOSE csr204; + return found; } -show_mem_user(id) -int id; +int show_mem_user(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int lid, iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr205 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_id = :iid AND member_type='USER' AND direct=1; - EXEC SQL OPEN csr205; - while(1) { - EXEC SQL FETCH csr205 INTO :lid; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("List %s has non-existant user member, id %d\n", - ((struct list *)hash_lookup(lists, lid))->name, iid); + EXEC SQL BEGIN DECLARE SECTION; + int lid, iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr205 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_id = :iid AND member_type = 'USER' AND direct = 1; + EXEC SQL OPEN csr205; + while (1) + { + EXEC SQL FETCH csr205 INTO :lid; + if (sqlca.sqlcode) + break; + + found = 0; + printf("List %s has non-existant user member, id %d\n", + ((struct list *)hash_lookup(lists, lid))->name, iid); } - EXEC SQL CLOSE csr205; - return(found); + EXEC SQL CLOSE csr205; + return found; } -show_mem_list(id) -int id; +int show_mem_list(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int lid, iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr206 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_id = :iid AND member_type='LIST' AND direct=1; - EXEC SQL OPEN csr206; - while(1) { - EXEC SQL FETCH csr206 INTO :lid; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("List %s has non-existant list member, id %d\n", - ((struct list *)hash_lookup(lists, lid))->name, iid); + EXEC SQL BEGIN DECLARE SECTION; + int lid, iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr206 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_id = :iid AND member_type = 'LIST' AND direct = 1; + EXEC SQL OPEN csr206; + while (1) + { + EXEC SQL FETCH csr206 INTO :lid; + if (sqlca.sqlcode) + break; + + found = 0; + printf("List %s has non-existant list member, id %d\n", + ((struct list *)hash_lookup(lists, lid))->name, iid); } - EXEC SQL CLOSE csr206; - return(found); + EXEC SQL CLOSE csr206; + return found; } -show_mem_str(id) -int id; +int show_mem_str(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int lid, iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr207 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_id = :iid AND member_type='STRING' AND direct=1; - EXEC SQL OPEN csr207; - while(1) { - EXEC SQL FETCH csr207 INTO :lid; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("List %s has non-existant string member, id %d\n", - ((struct list *)hash_lookup(lists, lid))->name, iid); + EXEC SQL BEGIN DECLARE SECTION; + int lid, iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr207 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_id = :iid AND member_type = 'STRING' AND direct = 1; + EXEC SQL OPEN csr207; + while (1) + { + EXEC SQL FETCH csr207 INTO :lid; + if (sqlca.sqlcode) + break; + + found = 0; + printf("List %s has non-existant string member, id %d\n", + ((struct list *)hash_lookup(lists, lid))->name, iid); } - EXEC SQL CLOSE csr207; - return(found); + EXEC SQL CLOSE csr207; + return found; } -show_mem_krb(id) -int id; +int show_mem_krb(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int lid, iid = id, found = 1; - char name[33]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr208 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_id = :iid AND member_type='KERBEROS' AND direct=1; - EXEC SQL OPEN csr208; - while(1) { - EXEC SQL FETCH csr208 INTO :lid; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("List %s has non-existant kerberos member, id %d\n", - ((struct list *)hash_lookup(lists, lid))->name, iid); + EXEC SQL BEGIN DECLARE SECTION; + int lid, iid = id, found = 1; + char name[33]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr208 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_id = :iid AND member_type = 'KERBEROS' AND direct = 1; + EXEC SQL OPEN csr208; + while (1) + { + EXEC SQL FETCH csr208 INTO :lid; + if (sqlca.sqlcode) + break; + + found = 0; + printf("List %s has non-existant kerberos member, id %d\n", + ((struct list *)hash_lookup(lists, lid))->name, iid); } - EXEC SQL CLOSE csr208; - return(found); + EXEC SQL CLOSE csr208; + return found; } -del_mem_user(id) -int id; +del_mem_user(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND - member_id = :iid AND direct = 1; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("imembers"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND + member_id = :iid AND direct = 1; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("imembers"); } -del_mem_list(id) -int id; +del_mem_list(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND - member_id = :iid AND direct=1; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("imembers"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND + member_id = :iid AND direct = 1; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("imembers"); } -del_mem_str(id) -int id; +del_mem_str(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND - member_id = :iid AND direct=1; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("imembers"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND + member_id = :iid AND direct = 1; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("imembers"); } -del_mem_krb(id) -int id; +del_mem_krb(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND - member_id = :iid AND direct=1; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("imembers"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND + member_id = :iid AND direct = 1; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("imembers"); } -show_sh(id) -int id; +int show_sh(int id) { - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int iid = id; - EXEC SQL END DECLARE SECTION; - int found = 1; - - EXEC SQL DECLARE csr209 CURSOR FOR - SELECT service FROM serverhosts - WHERE mach_id = :iid; - EXEC SQL OPEN csr209; - while(1) { - EXEC SQL FETCH csr209 INTO :name; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("ServerHost entry for service %s non-existant host %d\n", - name, id); + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int iid = id; + EXEC SQL END DECLARE SECTION; + int found = 1; + + EXEC SQL DECLARE csr209 CURSOR FOR + SELECT service FROM serverhosts + WHERE mach_id = :iid; + EXEC SQL OPEN csr209; + while (1) + { + EXEC SQL FETCH csr209 INTO :name; + if (sqlca.sqlcode) + break; + + found = 0; + printf("ServerHost entry for service %s non-existant host %d\n", + name, id); } - EXEC SQL CLOSE csr209; - return(found); + EXEC SQL CLOSE csr209; + return found; } -del_sh_mach(id) -int id; +del_sh_mach(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("serverhosts"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("serverhosts"); } static int fnchecklen; -fsmatch(id, n, f) -int id; -struct nfsphys *n; -struct filesys *f; +fsmatch(int id, struct nfsphys *n, struct filesys *f) { - if (n->mach_id == f->mach_id && - !strncmp(f->dir, n->dir, strlen(n->dir)) && - strlen(n->dir) > fnchecklen) { - f->phys_id = id; - fnchecklen = strlen(n->dir); + if (n->mach_id == f->mach_id && + !strncmp(f->dir, n->dir, strlen(n->dir)) && + strlen(n->dir) > fnchecklen) + { + f->phys_id = id; + fnchecklen = strlen(n->dir); } } -check_fs(id, f, hint) -int id; -register struct filesys *f; -int hint; +check_fs(int id, register struct filesys *f, int hint) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, id2, id3, rowcount; - char *dir; - EXEC SQL END DECLARE SECTION; - struct nfsphys *n; - struct machine *m; - - if (!hash_lookup(machines, f->mach_id)) { - printf("Filesys %s with bad machine %d\n", f->name, f->mach_id); - if (single_fix("Fix", 0)) { - EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("filesys"); - f->mach_id = 0; + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, id2, id3, rowcount; + char *dir; + EXEC SQL END DECLARE SECTION; + struct nfsphys *n; + struct machine *m; + + if (!hash_lookup(machines, f->mach_id)) + { + printf("Filesys %s with bad machine %d\n", f->name, f->mach_id); + if (single_fix("Fix", 0)) + { + EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("filesys"); + f->mach_id = 0; } } - if (!hash_lookup(users, f->owner)) { - printf("Filesys %s with bad owning user %d\n", f->name, f->owner); - if (single_fix("Fix", 1)) { - zero_fix("filesys", "owner", "filsys_id", f->filsys_id); - f->owner = 0; + if (!hash_lookup(users, f->owner)) + { + printf("Filesys %s with bad owning user %d\n", f->name, f->owner); + if (single_fix("Fix", 1)) + { + zero_fix("filesys", "owner", "filsys_id", f->filsys_id); + f->owner = 0; } } - if (!hash_lookup(lists, f->owners)) { - printf("Filesys %s with bad owning group %d\n", f->name, f->owners); - if (single_fix("Fix", 1)) { - zero_fix("filesys", "owners", "filsys_id", f->filsys_id); - f->owners = 0; + if (!hash_lookup(lists, f->owners)) + { + printf("Filesys %s with bad owning group %d\n", f->name, f->owners); + if (single_fix("Fix", 1)) + { + zero_fix("filesys", "owners", "filsys_id", f->filsys_id); + f->owners = 0; } } - if (f->type == 'N') { - if (!hash_lookup(nfsphys, f->phys_id)) { - m = (struct machine *)hash_lookup(machines, f->mach_id); - printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id); - if (single_fix("Fix", 1)) { - fnchecklen = 0; - hash_step(nfsphys, fsmatch, f); - if (fnchecklen != 0) { + if (f->type == 'N') + { + if (!hash_lookup(nfsphys, f->phys_id)) + { + m = (struct machine *)hash_lookup(machines, f->mach_id); + printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id); + if (single_fix("Fix", 1)) + { + fnchecklen = 0; + hash_step(nfsphys, fsmatch, f); + if (fnchecklen != 0) + { id1 = f->phys_id; id2 = f->filsys_id; id3 = f->mach_id; - EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2; + EXEC SQL UPDATE filesys SET phys_id = :id1 + WHERE filsys_id = :id2; rowcount = sqlca.sqlerrd[2]; if (rowcount > 0) - printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies"); + printf("%d entr%s fixed\n", rowcount, + rowcount == 1 ? "y" : "ies"); else printf("Not fixed\n"); modified("filesys"); - } else { - printf("No NFSphys exsits for %s:%s\n", m->name, f->dir); - if (single_fix("Create", 0)) { - dir = f->dir; - id1 = f->phys_id; - id2 = f->filsys_id; - id3 = f->mach_id; - if (set_next_object_id("nfsphys_id", "nfsphys") != - MR_SUCCESS) { - printf("Unable to assign unique ID\n"); - return; + } + else + { + printf("No NFSphys exsits for %s:%s\n", m->name, f->dir); + if (single_fix("Create", 0)) + { + dir = f->dir; + id1 = f->phys_id; + id2 = f->filsys_id; + id3 = f->mach_id; + if (set_next_object_id("nfsphys_id", "nfsphys") != + MR_SUCCESS) + { + printf("Unable to assign unique ID\n"); + return; } - EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues - WHERE name='nfsphys_id'; - if (rowcount != 1) { - printf("Unable to retrieve unique ID\n"); - return; + EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues + WHERE name = 'nfsphys_id'; + if (rowcount != 1) + { + printf("Unable to retrieve unique ID\n"); + return; } - EXEC SQL INSERT INTO nfsphys (nfsphys_id, mach_id, - device, dir, status, allocated, size, modtime, - modby, modwith) VALUES (:id1, :id3, '\?\?\?', :dir, - 0, 0, 0, SYSDATE, 0, 'dbck'); + EXEC SQL INSERT INTO nfsphys + (nfsphys_id, mach_id, device, dir, status, allocated, + size, modtime, modby, modwith) VALUES + (:id1, :id3, '\?\?\?', :dir, 0, 0, 0, SYSDATE, 0, + 'dbck'); rowcount = sqlca.sqlerrd[2]; if (rowcount > 0) - printf("%d entr%s created\n", rowcount, - rowcount==1?"y":"ies"); + { + printf("%d entr%s created\n", rowcount, + rowcount == 1 ? "y" : "ies"); + } else printf("Not created\n"); modified("nfsphys"); - n = (struct nfsphys *)malloc(sizeof(struct nfsphys)); - if (n == NULL) + n = malloc(sizeof(struct nfsphys)); + if (!n) out_of_mem("storing new nfsphys"); strcpy(n->dir, dir); n->mach_id = id3; n->nfsphys_id = id1; n->allocated = 0; n->count = 0; - if( hash_store(nfsphys, id1, n) == -1 ) { + if (hash_store(nfsphys, id1, n) == -1) out_of_mem("storing nfsphys in hash table"); - } EXEC SQL UPDATE filesys SET phys_id = :id1 - WHERE filsys_id = :id2; + WHERE filsys_id = :id2; rowcount = sqlca.sqlerrd[2]; if (rowcount > 0) - printf("%d filesys entr%s fixed\n", rowcount, - rowcount==1?"y":"ies"); + { + printf("%d filesys entr%s fixed\n", rowcount, + rowcount == 1 ? "y" : "ies"); + } else printf("Not fixed\n"); modified("filesys"); @@ -978,753 +1004,781 @@ int hint; } } - -check_nfsphys(id, n, hint) -int id; -struct nfsphys *n; -int hint; +check_nfsphys(int id, struct nfsphys *n, int hint) { - if (!hash_lookup(machines, n->mach_id)) { - printf("NFSphys %d(%s) on non-existant machine %d\n", - id, n->dir, n->mach_id); - if (single_fix("Delete", 0)) - single_delete("nfsphys", "nfsphys_id", id); + if (!hash_lookup(machines, n->mach_id)) + { + printf("NFSphys %d(%s) on non-existant machine %d\n", + id, n->dir, n->mach_id); + if (single_fix("Delete", 0)) + single_delete("nfsphys", "nfsphys_id", id); } } -show_fsg_missing(id) -int id; +int show_fsg_missing(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - EXEC SQL END DECLARE SECTION; - struct filesys *f; - - EXEC SQL DECLARE csr210 CURSOR FOR - SELECT filsys_id FROM fsgroup - WHERE group_id = :iid; - EXEC SQL OPEN csr210; - while(1) { - EXEC SQL FETCH csr210 INTO :id1; - if (sqlca.sqlcode != 0) break; - - found = 0; - if (f = (struct filesys *) hash_lookup(filesys, id1)) - printf("Missing fsgroup %d has member filesystem %s\n", id, f->name); - else - printf("Missing fsgroup %d has member filesystem %d\n", id, id1); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + EXEC SQL END DECLARE SECTION; + struct filesys *f; + + EXEC SQL DECLARE csr210 CURSOR FOR + SELECT filsys_id FROM fsgroup + WHERE group_id = :iid; + EXEC SQL OPEN csr210; + while (1) + { + EXEC SQL FETCH csr210 INTO :id1; + if (sqlca.sqlcode) + break; + + found = 0; + if (f = (struct filesys *) hash_lookup(filesys, id1)) + printf("Missing fsgroup %d has member filesystem %s\n", id, f->name); + else + printf("Missing fsgroup %d has member filesystem %d\n", id, id1); } - EXEC SQL CLOSE csr210; - return(found); + EXEC SQL CLOSE csr210; + return found; } -show_fsg_type(f) -struct filesys *f; +int show_fsg_type(struct filesys *f) { - char *t; + char *t; - switch (f->type) { + switch (f->type) + { case 'N': - t = "NFS"; - break; + t = "NFS"; + break; case 'R': - t = "RVD"; - break; + t = "RVD"; + break; case 'A': - t = "AFS"; - break; + t = "AFS"; + break; case 'E': - t = "ERR"; - break; + t = "ERR"; + break; case 'F': - t = "FSGROUP"; - break; + t = "FSGROUP"; + break; case 'M': - t = "MUL"; - break; + t = "MUL"; + break; default: - t = "\?\?\?"; + t = "\?\?\?"; } - printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t); - return(0); + printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t); + return 0; } -fix_fsg_type(f) -struct filesys *f; +fix_fsg_type(struct filesys *f) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, id = f->filsys_id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("filesys"); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = f->filsys_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("filesys"); } -show_fsg_nomember(id) -int id; +int show_fsg_nomember(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - EXEC SQL END DECLARE SECTION; - struct filesys *f; - - EXEC SQL DECLARE csr211 CURSOR FOR - SELECT group_id FROM fsgroup - WHERE filsys_id = :iid; - EXEC SQL OPEN csr211; - while(1) { - EXEC SQL FETCH csr211 INTO :id1; - if (sqlca.sqlcode != 0) break; - - found = 0; - if (f = (struct filesys *) hash_lookup(filesys, id1)) - printf("FSGroup %s has missing member %d\n", f->name, id); - else - printf("FSGroup %d has missing member %d\n", id1, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + EXEC SQL END DECLARE SECTION; + struct filesys *f; + + EXEC SQL DECLARE csr211 CURSOR FOR + SELECT group_id FROM fsgroup + WHERE filsys_id = :iid; + EXEC SQL OPEN csr211; + while (1) + { + EXEC SQL FETCH csr211 INTO :id1; + if (sqlca.sqlcode) + break; + + found = 0; + if (f = (struct filesys *) hash_lookup(filesys, id1)) + printf("FSGroup %s has missing member %d\n", f->name, id); + else + printf("FSGroup %d has missing member %d\n", id1, id); } - EXEC SQL CLOSE csr211; - return(found); + EXEC SQL CLOSE csr211; + return found; } -show_quota_nouser(id) -int id; +int show_quota_nouser(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr212 CURSOR FOR - SELECT filsys_id FROM quota - WHERE entity_id = :iid AND type='USER'; - EXEC SQL OPEN csr212; - while(1) { - EXEC SQL FETCH csr212 INTO :id1; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("Quota on fs %d for non-existant user %d\n", id1, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr212 CURSOR FOR + SELECT filsys_id FROM quota + WHERE entity_id = :iid AND type = 'USER'; + EXEC SQL OPEN csr212; + while (1) + { + EXEC SQL FETCH csr212 INTO :id1; + if (sqlca.sqlcode) + break; + + found = 0; + printf("Quota on fs %d for non-existant user %d\n", id1, id); } - EXEC SQL CLOSE csr212; - return(found); + EXEC SQL CLOSE csr212; + return found; } -show_quota_nolist(id) -int id; +int show_quota_nolist(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr213 CURSOR FOR - SELECT filsys_id FROM quota - WHERE entity_id = :iid AND type='GROUP'; - EXEC SQL OPEN csr213; - while(1) { - EXEC SQL FETCH csr213 INTO :id1; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("Quota on fs %d for non-existant list %d\n", id1, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr213 CURSOR FOR + SELECT filsys_id FROM quota + WHERE entity_id = :iid AND type = 'GROUP'; + EXEC SQL OPEN csr213; + while (1) + { + EXEC SQL FETCH csr213 INTO :id1; + if (sqlca.sqlcode) + break; + + found = 0; + printf("Quota on fs %d for non-existant list %d\n", id1, id); } - EXEC SQL CLOSE csr213; - return(found); + EXEC SQL CLOSE csr213; + return found; } -fix_quota_nouser(id) -int id; +fix_quota_nouser(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount, id1; - EXEC SQL END DECLARE SECTION; - - id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; - EXEC SQL DELETE FROM quota - WHERE entity_id = :iid AND type = 'USER'; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("quota"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount, id1; + EXEC SQL END DECLARE SECTION; + + id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; + EXEC SQL DELETE FROM quota + WHERE entity_id = :iid AND type = 'USER'; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("quota"); } -fix_quota_nolist(id) -int id; +fix_quota_nolist(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount, id1; - EXEC SQL END DECLARE SECTION; - - id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; - EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type='GROUP'; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies"); - else - printf("Not deleted\n"); - modified("quota"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount, id1; + EXEC SQL END DECLARE SECTION; + + id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; + EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP'; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not deleted\n"); + modified("quota"); } -show_quota_nofs(id) -int id; +int show_quota_nofs(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - char type[9]; - EXEC SQL END DECLARE SECTION; - - EXEC SQL DECLARE csr214 CURSOR FOR - SELECT entity_id, type FROM quota - WHERE filsys_id = :iid; - EXEC SQL OPEN csr214; - while(1) { - EXEC SQL FETCH csr214 INTO :id1, :type; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + char type[9]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr214 CURSOR FOR + SELECT entity_id, type FROM quota + WHERE filsys_id = :iid; + EXEC SQL OPEN csr214; + while (1) + { + EXEC SQL FETCH csr214 INTO :id1, :type; + if (sqlca.sqlcode) + break; + + found = 0; + printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id); } - EXEC SQL CLOSE csr214; - return(found); + EXEC SQL CLOSE csr214; + return found; } -fix_quota_nofs(id) +fix_quota_nofs(int id) { - single_delete("quota", "filsys_id", id); + single_delete("quota", "filsys_id", id); } -show_quota_wrongpid(id) -int id; +int show_quota_wrongpid(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, id1, found = 1; - char type[9]; - EXEC SQL END DECLARE SECTION; - struct user *u; - struct filesys *f; - - f = (struct filesys *)hash_lookup(filesys, id); - EXEC SQL DECLARE csr215 CURSOR FOR - SELECT entity_id, type FROM quota - WHERE filsys_id = :iid; - EXEC SQL OPEN csr215; - while(1) { - EXEC SQL FETCH csr215 INTO :id1, :type; - if (sqlca.sqlcode != 0) break; - - found = 0; - printf("Quota for %s %d on filesys %s has wrong phys_id %d\n", - type, id1, f->name, id); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, id1, found = 1; + char type[9]; + EXEC SQL END DECLARE SECTION; + struct user *u; + struct filesys *f; + + f = (struct filesys *)hash_lookup(filesys, id); + EXEC SQL DECLARE csr215 CURSOR FOR + SELECT entity_id, type FROM quota + WHERE filsys_id = :iid; + EXEC SQL OPEN csr215; + while (1) + { + EXEC SQL FETCH csr215 INTO :id1, :type; + if (sqlca.sqlcode) + break; + + found = 0; + printf("Quota for %s %d on filesys %s has wrong phys_id %d\n", + type, id1, f->name, id); } - EXEC SQL CLOSE csr215; - return(found); + EXEC SQL CLOSE csr215; + return found; } -fix_quota_physid(id) -int id; +fix_quota_physid(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount, id1; - EXEC SQL END DECLARE SECTION; - - id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; - EXEC SQL UPDATE quota SET phys_id = :id1 - WHERE filsys_id = :iid AND phys_id != :id1; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("quota"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount, id1; + EXEC SQL END DECLARE SECTION; + + id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id; + EXEC SQL UPDATE quota SET phys_id = :id1 + WHERE filsys_id = :iid AND phys_id != :id1; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("quota"); } -show_srv_user(id) -int id; +int show_srv_user(int id) { - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int iid = id; - EXEC SQL END DECLARE SECTION; - int found = 1; - - EXEC SQL DECLARE csr216 CURSOR FOR - SELECT name FROM servers - WHERE acl_type='USER' and acl_id = :iid; - EXEC SQL OPEN csr216; - while(1) { - EXEC SQL FETCH csr216 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - printf("Service %s has acl non-existant user %d\n", name, id); - found = 0; + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int iid = id; + EXEC SQL END DECLARE SECTION; + int found = 1; + + EXEC SQL DECLARE csr216 CURSOR FOR + SELECT name FROM servers + WHERE acl_type = 'USER' and acl_id = :iid; + EXEC SQL OPEN csr216; + while (1) + { + EXEC SQL FETCH csr216 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + printf("Service %s has acl non-existant user %d\n", name, id); + found = 0; } - EXEC SQL CLOSE csr216; - return(found); + EXEC SQL CLOSE csr216; + return found; } -show_srv_list(id) -int id; +int show_srv_list(int id) { - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int iid = id; - EXEC SQL END DECLARE SECTION; - int found = 1; - - EXEC SQL DECLARE csr217 CURSOR FOR - SELECT name FROM servers - WHERE acl_type='LIST' AND acl_id = :iid; - EXEC SQL OPEN csr217; - while(1) { - EXEC SQL FETCH csr217 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - printf("Service %s has acl non-existant list %d\n", name, id); - found = 0; + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int iid = id; + EXEC SQL END DECLARE SECTION; + int found = 1; + + EXEC SQL DECLARE csr217 CURSOR FOR + SELECT name FROM servers + WHERE acl_type = 'LIST' AND acl_id = :iid; + EXEC SQL OPEN csr217; + while (1) + { + EXEC SQL FETCH csr217 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + printf("Service %s has acl non-existant list %d\n", name, id); + found = 0; } - EXEC SQL CLOSE csr217; - return(found); + EXEC SQL CLOSE csr217; + return found; } -zero_srv_user(id) -int id; +zero_srv_user(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND - acl_type='USER'; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("servers"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND + acl_type = 'USER'; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("servers"); } -zero_srv_list(id) -int id; +zero_srv_list(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, rowcount; - EXEC SQL END DECLARE SECTION; - - EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND - acl_type='LIST'; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("servers"); -} + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, rowcount; + EXEC SQL END DECLARE SECTION; + EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND + acl_type = 'LIST'; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("servers"); +} -show_krb_usr(id) -int id; +int show_krb_usr(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1, id1; - EXEC SQL END DECLARE SECTION; - struct string *s; - char *ss; - - EXEC SQL DECLARE csr218 CURSOR FOR - SELECT string_id FROM krbmap - WHERE users_id = :iid ; - EXEC SQL OPEN csr218; - while(1) { - EXEC SQL FETCH csr218 INTO :id1; - if (sqlca.sqlcode != 0) break; - - if (s = ((struct string *)hash_lookup(strings, id1))) - ss = s->name; - else - ss = "[unknown]"; - found = 0; - printf("Kerberos map for non-existant user %d to principal %s\n", - id, s); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1, id1; + EXEC SQL END DECLARE SECTION; + struct string *s; + char *ss; + + EXEC SQL DECLARE csr218 CURSOR FOR + SELECT string_id FROM krbmap + WHERE users_id = :iid; + EXEC SQL OPEN csr218; + while (1) + { + EXEC SQL FETCH csr218 INTO :id1; + if (sqlca.sqlcode) + break; + + if ((s = ((struct string *)hash_lookup(strings, id1)))) + ss = s->name; + else + ss = "[unknown]"; + found = 0; + printf("Kerberos map for non-existant user %d to principal %s\n", + id, s); } - EXEC SQL CLOSE csr218; - return(found); + EXEC SQL CLOSE csr218; + return found; } - -show_krb_str(id) -int id; +int show_krb_str(int id) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, found = 1, id1; - EXEC SQL END DECLARE SECTION; - struct user *u; - char *s; - - EXEC SQL DECLARE csr219 CURSOR FOR - SELECT users_id FROM krbmap - WHERE string_id = :iid; - EXEC SQL OPEN csr219; - while(1) { - EXEC SQL FETCH csr219 INTO :id1; - if (sqlca.sqlcode != 0) break; - - if (u = ((struct user *)hash_lookup(users, id1))) - s = u->login; - else - s = "[\?\?\?]"; - found = 0; - printf("Kerberos map for user %s (%d) to non-existant string %d\n", - s, id1, id); - } - EXEC SQL CLOSE csr219; - return(found); -} + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, found = 1, id1; + EXEC SQL END DECLARE SECTION; + struct user *u; + char *s; + + EXEC SQL DECLARE csr219 CURSOR FOR + SELECT users_id FROM krbmap + WHERE string_id = :iid; + EXEC SQL OPEN csr219; + while (1) + { + EXEC SQL FETCH csr219 INTO :id1; + if (sqlca.sqlcode) + break; + if ((u = ((struct user *)hash_lookup(users, id1)))) + s = u->login; + else + s = "[\?\?\?]"; + found = 0; + printf("Kerberos map for user %s (%d) to non-existant string %d\n", + s, id1, id); + } + EXEC SQL CLOSE csr219; + return found; +} -show_pdm_mach(id) -int id; +int show_pdm_mach(int id) { - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int iid = id; - EXEC SQL END DECLARE SECTION; - int found = 1; - - EXEC SQL DECLARE csr220 CURSOR FOR - SELECT name FROM palladium - WHERE mach_id = :iid; - EXEC SQL OPEN csr220; - while(1) { - EXEC SQL FETCH csr220 INTO :name; - if (sqlca.sqlcode != 0) break; - - strtrim(name); - printf("Palladium server/supervisor %s is on non-existant machine %d\n", - name, id); - found = 0; - } - EXEC SQL CLOSE csr220; - return(found); + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int iid = id; + EXEC SQL END DECLARE SECTION; + int found = 1; + + EXEC SQL DECLARE csr220 CURSOR FOR + SELECT name FROM palladium + WHERE mach_id = :iid; + EXEC SQL OPEN csr220; + while (1) + { + EXEC SQL FETCH csr220 INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + printf("Palladium server/supervisor %s is on non-existant machine %d\n", + name, id); + found = 0; + } + EXEC SQL CLOSE csr220; + return found; } -phase2() +phase2(void) { - EXEC SQL BEGIN DECLARE SECTION; - int id1, id2, id3, id4, id5; - char type[9], name[33]; - EXEC SQL END DECLARE SECTION; - struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5; - struct filesys *f; - struct list *l; - struct nfsphys *n; - struct machine *m; - - printf("Phase 2 - Checking references\n"); - - dprintf("Checking users...\n"); - hash_step(users, user_check, NULL); - - dprintf("Checking machines...\n"); - hash_step(machines, mach_check, NULL); - - dprintf("Checking subnets...\n"); - hash_step(subnets, subnet_check, NULL); - - dprintf("Checking clusters...\n"); - hash_step(clusters, cluster_check, NULL); - - dprintf("Checking mcmap...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - EXEC SQL DECLARE csr221 CURSOR FOR - SELECT mach_id, clu_id FROM mcmap; - EXEC SQL OPEN csr221; - while(1) { - EXEC SQL FETCH csr221 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - - if (!(m = (struct machine *)hash_lookup(machines, id1))) - sq_save_unique_data(sq1, id1); - else if (!hash_lookup(clusters, id2)) - sq_save_unique_data(sq2, id2); - if (m) m->clucount++; + EXEC SQL BEGIN DECLARE SECTION; + int id1, id2, id3, id4, id5; + char type[9], name[33]; + EXEC SQL END DECLARE SECTION; + struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5; + struct filesys *f; + struct list *l; + struct nfsphys *n; + struct machine *m; + + printf("Phase 2 - Checking references\n"); + + dprintf("Checking users...\n"); + hash_step(users, user_check, NULL); + + dprintf("Checking machines...\n"); + hash_step(machines, mach_check, NULL); + + dprintf("Checking subnets...\n"); + hash_step(subnets, subnet_check, NULL); + + dprintf("Checking clusters...\n"); + hash_step(clusters, cluster_check, NULL); + + dprintf("Checking mcmap...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + EXEC SQL DECLARE csr221 CURSOR FOR + SELECT mach_id, clu_id FROM mcmap; + EXEC SQL OPEN csr221; + while (1) + { + EXEC SQL FETCH csr221 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + + if (!(m = (struct machine *)hash_lookup(machines, id1))) + sq_save_unique_data(sq1, id1); + else if (!hash_lookup(clusters, id2)) + sq_save_unique_data(sq2, id2); + if (m) + m->clucount++; } - EXEC SQL CLOSE csr221; - generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1); - generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1); - - dprintf("Checking service clusters...\n"); - sq1 = sq_create(); - EXEC SQL DECLARE csr222 CURSOR FOR - SELECT clu_id FROM svc; - EXEC SQL OPEN csr222; - while(1) { - EXEC SQL FETCH csr222 INTO :id1; - if (sqlca.sqlcode != 0) break; - - if (!hash_lookup(clusters, id1)) - sq_save_unique_data(sq1, id1); + EXEC SQL CLOSE csr221; + generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1); + generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1); + + dprintf("Checking service clusters...\n"); + sq1 = sq_create(); + EXEC SQL DECLARE csr222 CURSOR FOR + SELECT clu_id FROM svc; + EXEC SQL OPEN csr222; + while (1) + { + EXEC SQL FETCH csr222 INTO :id1; + if (sqlca.sqlcode) + break; + + if (!hash_lookup(clusters, id1)) + sq_save_unique_data(sq1, id1); } - EXEC SQL CLOSE csr222; - generic_delete(sq1, show_svc, "svc", "clu_id", 1); - - dprintf("Checking lists...\n"); - hash_step(lists, list_check, NULL); - - dprintf("Checking members...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - sq3 = sq_create(); - sq4 = sq_create(); - sq5 = sq_create(); - - EXEC SQL DECLARE csr223 CURSOR FOR - SELECT list_id, member_type, member_id, ref_count, direct - FROM imembers FOR UPDATE OF member_id; - EXEC SQL OPEN csr223; - while(1) { - EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4; - if (sqlca.sqlcode != 0) break; - - if ((l = (struct list *) hash_lookup(lists, id1)) == NULL) - sq_save_unique_data(sq1, id1); - else if (type[0] == 'U' && !hash_lookup(users, id2)) - sq_save_unique_data(sq2, id2); - else if (type[0] == 'L' && !hash_lookup(lists, id2)) - sq_save_unique_data(sq3, id2); - else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2)) - sq_save_unique_data(sq4, id2); - else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2)) - sq_save_unique_data(sq5, id2); - else - l->members++; - } - EXEC SQL CLOSE csr223; - generic_delete(sq1, show_member_list, "imembers", "list_id", 1); - generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1); - generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1); - generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1); - generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1); - - dprintf("Checking servers...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - EXEC SQL DECLARE csr224 CURSOR FOR - SELECT name, acl_type, acl_id, modby FROM servers - FOR UPDATE of modby; - EXEC SQL OPEN csr224; - while(1) { - EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("servers","modby","csr224",id2); - strtrim(type); - if (!strcmp(type, "USER") && !hash_lookup(users, id1)) { - sq_save_data(sq1, id1); - } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) { - sq_save_data(sq2, id1); - } + EXEC SQL CLOSE csr222; + generic_delete(sq1, show_svc, "svc", "clu_id", 1); + + dprintf("Checking lists...\n"); + hash_step(lists, list_check, NULL); + + dprintf("Checking members...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + sq3 = sq_create(); + sq4 = sq_create(); + sq5 = sq_create(); + + EXEC SQL DECLARE csr223 CURSOR FOR + SELECT list_id, member_type, member_id, ref_count, direct + FROM imembers FOR UPDATE OF member_id; + EXEC SQL OPEN csr223; + while (1) + { + EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4; + if (sqlca.sqlcode) + break; + + if (!(l = (struct list *) hash_lookup(lists, id1))) + sq_save_unique_data(sq1, id1); + else if (type[0] == 'U' && !hash_lookup(users, id2)) + sq_save_unique_data(sq2, id2); + else if (type[0] == 'L' && !hash_lookup(lists, id2)) + sq_save_unique_data(sq3, id2); + else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2)) + sq_save_unique_data(sq4, id2); + else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2)) + sq_save_unique_data(sq5, id2); + else + l->members++; } - EXEC SQL CLOSE csr224; - generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1); - generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1); - - dprintf("Checking serverhosts...\n"); - sq = sq_create(); - EXEC SQL DECLARE csr225 CURSOR FOR - SELECT mach_id, modby FROM serverhosts - FOR UPDATE OF modby; - EXEC SQL OPEN csr225; - while(1) { - EXEC SQL FETCH csr225 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("serverhosts", "modby", "csr225", id2); - if (!hash_lookup(machines, id1)) - sq_save_data(sq, id1); - } - EXEC SQL CLOSE csr225; - generic_fix(sq, show_sh, "Delete", del_sh_mach, 0); - - dprintf("Checking nfsphys...\n"); - hash_step(nfsphys, check_nfsphys, NULL); - - dprintf("Checking filesys...\n"); - hash_step(filesys, check_fs, NULL); - - dprintf("Checking filesystem groups...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - sq3 = sq_create(); - EXEC SQL DECLARE csr226 CURSOR FOR - SELECT group_id, filsys_id FROM fsgroup; - EXEC SQL OPEN csr226; - while(1) { - EXEC SQL FETCH csr226 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - - if (!(f = (struct filesys *) hash_lookup(filesys, id1))) - sq_save_data(sq1, id1); - if (!hash_lookup(filesys, id2)) - sq_save_data(sq3, id2); + EXEC SQL CLOSE csr223; + generic_delete(sq1, show_member_list, "imembers", "list_id", 1); + generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1); + generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1); + generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1); + generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1); + + dprintf("Checking servers...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + EXEC SQL DECLARE csr224 CURSOR FOR + SELECT name, acl_type, acl_id, modby FROM servers + FOR UPDATE of modby; + EXEC SQL OPEN csr224; + while (1) + { + EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("servers", "modby", "csr224", id2); + strtrim(type); + if (!strcmp(type, "USER") && !hash_lookup(users, id1)) + sq_save_data(sq1, id1); + else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) + sq_save_data(sq2, id1); + } + EXEC SQL CLOSE csr224; + generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1); + generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1); + + dprintf("Checking serverhosts...\n"); + sq = sq_create(); + EXEC SQL DECLARE csr225 CURSOR FOR + SELECT mach_id, modby FROM serverhosts + FOR UPDATE OF modby; + EXEC SQL OPEN csr225; + while (1) + { + EXEC SQL FETCH csr225 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("serverhosts", "modby", "csr225", id2); + if (!hash_lookup(machines, id1)) + sq_save_data(sq, id1); + } + EXEC SQL CLOSE csr225; + generic_fix(sq, show_sh, "Delete", del_sh_mach, 0); + + dprintf("Checking nfsphys...\n"); + hash_step(nfsphys, check_nfsphys, NULL); + + dprintf("Checking filesys...\n"); + hash_step(filesys, check_fs, NULL); + + dprintf("Checking filesystem groups...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + sq3 = sq_create(); + EXEC SQL DECLARE csr226 CURSOR FOR + SELECT group_id, filsys_id FROM fsgroup; + EXEC SQL OPEN csr226; + while (1) + { + EXEC SQL FETCH csr226 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + + if (!(f = (struct filesys *) hash_lookup(filesys, id1))) + sq_save_data(sq1, id1); + if (!hash_lookup(filesys, id2)) + sq_save_data(sq3, id2); } - EXEC SQL CLOSE csr226; - generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0); - generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1); - - dprintf("Checking quotas...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - sq3 = sq_create(); - sq4 = sq_create(); - EXEC SQL DECLARE csr227 CURSOR FOR - SELECT entity_id, type, filsys_id, phys_id, quota, modby - FROM quota FOR UPDATE OF modby; - EXEC SQL OPEN csr227; - while(1) { - EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("quota", "modby", "csr227", id5); - if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1)) - sq_save_data(sq1, id1); - else if (type[0] == 'G' && !hash_lookup(lists, id1)) - sq_save_data(sq4, id1); - else if (!(f = (struct filesys *) hash_lookup(filesys, id2))) - sq_save_data(sq2, id2); - else if (id3 != f->phys_id || - ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) == - (struct nfsphys *)NULL)) - sq_save_data(sq3, id2); - else - n->count += id4; + EXEC SQL CLOSE csr226; + generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0); + generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1); + + dprintf("Checking quotas...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + sq3 = sq_create(); + sq4 = sq_create(); + EXEC SQL DECLARE csr227 CURSOR FOR + SELECT entity_id, type, filsys_id, phys_id, quota, modby + FROM quota FOR UPDATE OF modby; + EXEC SQL OPEN csr227; + while (1) + { + EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("quota", "modby", "csr227", id5); + if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1)) + sq_save_data(sq1, id1); + else if (type[0] == 'G' && !hash_lookup(lists, id1)) + sq_save_data(sq4, id1); + else if (!(f = (struct filesys *) hash_lookup(filesys, id2))) + sq_save_data(sq2, id2); + else if (id3 != f->phys_id || + !(n = (struct nfsphys *) hash_lookup(nfsphys, id3))) + sq_save_data(sq3, id2); + else + n->count += id4; } - EXEC SQL CLOSE csr227; - generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1); - generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0); - generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1); - generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1); - - dprintf("Not checking zephyr.\n"); - - dprintf("Checking hostaccess...\n"); - EXEC SQL DECLARE csr228 CURSOR FOR - SELECT mach_id, acl_type, acl_id, modby FROM hostaccess - FOR UPDATE OF modby; - EXEC SQL OPEN csr228; - while(1) { - EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("hostaccess", "modby", "csr228", id3); - strtrim(type); - if (!hash_lookup(machines, id1)) { - printf("Hostaccess for non-existant host %d\n", id1); - printf("Not fixing this error\n"); + EXEC SQL CLOSE csr227; + generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1); + generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0); + generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1); + generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1); + + dprintf("Not checking zephyr.\n"); + + dprintf("Checking hostaccess...\n"); + EXEC SQL DECLARE csr228 CURSOR FOR + SELECT mach_id, acl_type, acl_id, modby FROM hostaccess + FOR UPDATE OF modby; + EXEC SQL OPEN csr228; + while (1) + { + EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("hostaccess", "modby", "csr228", id3); + strtrim(type); + if (!hash_lookup(machines, id1)) + { + printf("Hostaccess for non-existant host %d\n", id1); + printf("Not fixing this error\n"); } - if (!strcmp(type, "USER") && !hash_lookup(users, id2)) { - printf("Hostaccess for %d is non-existant user %d\n", id1, id2); - printf("Not fixing this error\n"); - } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) { - printf("Hostaccess for %d is non-existant list %d\n", id1, id2); - printf("Not fixing this error\n"); + if (!strcmp(type, "USER") && !hash_lookup(users, id2)) + { + printf("Hostaccess for %d is non-existant user %d\n", id1, id2); + printf("Not fixing this error\n"); } - } - EXEC SQL CLOSE csr228; - - dprintf("Checking palladium...\n"); - sq1 = sq_create(); - EXEC SQL DECLARE csr229 CURSOR FOR - SELECT mach_id, modby FROM palladium - FOR UPDATE OF modby; - EXEC SQL OPEN csr229; - while(1) { - EXEC SQL FETCH csr229 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("palladium", "modby", "csr229", id2); - if (!hash_lookup(machines, id1)) { - sq_save_unique_data(sq1, id1); + else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) + { + printf("Hostaccess for %d is non-existant list %d\n", id1, id2); + printf("Not fixing this error\n"); } } - EXEC SQL CLOSE csr229; - generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1); - - dprintf("Checking krbmap...\n"); - sq1 = sq_create(); - sq2 = sq_create(); - EXEC SQL DECLARE csr230 CURSOR FOR - SELECT users_id, string_id FROM krbmap - FOR UPDATE OF string_id; - EXEC SQL OPEN csr230; - while(1) { - EXEC SQL FETCH csr230 INTO :id1, :id2; - if (sqlca.sqlcode != 0) break; - - if (!hash_lookup(users, id1)) - sq_save_unique_data(sq1, id1); - else if (!maybe_fixup_unref_string2("krbmap","string_id","csr230",id2)) - sq_save_unique_data(sq2, id2); - } - EXEC SQL CLOSE csr230; - generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1); - generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1); - - dprintf("Checking capacls...\n"); - EXEC SQL DECLARE csr231 CURSOR FOR - SELECT list_id, tag FROM capacls; - EXEC SQL OPEN csr231; - while(1) { - EXEC SQL FETCH csr231 INTO :id1, :name; - if (sqlca.sqlcode != 0) break; - - if (!hash_lookup(lists, id1)) { - printf("Capacl for %s is non-existant list %d\n", name, id1); - printf("Not fixing this error\n"); + EXEC SQL CLOSE csr228; + + dprintf("Checking palladium...\n"); + sq1 = sq_create(); + EXEC SQL DECLARE csr229 CURSOR FOR + SELECT mach_id, modby FROM palladium + FOR UPDATE OF modby; + EXEC SQL OPEN csr229; + while (1) + { + EXEC SQL FETCH csr229 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("palladium", "modby", "csr229", id2); + if (!hash_lookup(machines, id1)) + sq_save_unique_data(sq1, id1); + } + EXEC SQL CLOSE csr229; + generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1); + + dprintf("Checking krbmap...\n"); + sq1 = sq_create(); + sq2 = sq_create(); + EXEC SQL DECLARE csr230 CURSOR FOR + SELECT users_id, string_id FROM krbmap + FOR UPDATE OF string_id; + EXEC SQL OPEN csr230; + while (1) + { + EXEC SQL FETCH csr230 INTO :id1, :id2; + if (sqlca.sqlcode) + break; + + if (!hash_lookup(users, id1)) + sq_save_unique_data(sq1, id1); + else if (!maybe_fixup_unref_string2("krbmap", "string_id", "csr230", id2)) + sq_save_unique_data(sq2, id2); + } + EXEC SQL CLOSE csr230; + generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1); + generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1); + + dprintf("Checking capacls...\n"); + EXEC SQL DECLARE csr231 CURSOR FOR + SELECT list_id, tag FROM capacls; + EXEC SQL OPEN csr231; + while (1) + { + EXEC SQL FETCH csr231 INTO :id1, :name; + if (sqlca.sqlcode) + break; + + if (!hash_lookup(lists, id1)) + { + printf("Capacl for %s is non-existant list %d\n", name, id1); + printf("Not fixing this error\n"); } } - EXEC SQL CLOSE csr231; - - dprintf("Checking hostaliases\n"); - sq1 = sq_create(); - EXEC SQL DECLARE csr232 CURSOR FOR - SELECT mach_id FROM hostalias; - EXEC SQL OPEN csr232; - while(1) { - EXEC SQL FETCH csr232 INTO :id1; - if (sqlca.sqlcode != 0) break; - - if (!hash_lookup(machines, id1)) - sq_save_unique_data(sq1, id1); + EXEC SQL CLOSE csr231; + + dprintf("Checking hostaliases\n"); + sq1 = sq_create(); + EXEC SQL DECLARE csr232 CURSOR FOR + SELECT mach_id FROM hostalias; + EXEC SQL OPEN csr232; + while (1) + { + EXEC SQL FETCH csr232 INTO :id1; + if (sqlca.sqlcode) + break; + + if (!hash_lookup(machines, id1)) + sq_save_unique_data(sq1, id1); } - EXEC SQL CLOSE csr232; - generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1); - - dprintf("Checking printcaps\n"); - sq1 = sq_create(); - sq2 = sq_create(); - EXEC SQL DECLARE csr233 CURSOR FOR - SELECT mach_id, quotaserver, modby FROM printcap; - EXEC SQL OPEN csr233; - while(1) { - EXEC SQL FETCH csr233 INTO :id1, :id2, :id3; - if (sqlca.sqlcode != 0) break; - - maybe_fixup_modby2("printcap", "modby", "csr233", id3); - if (!hash_lookup(machines, id1)) - sq_save_unique_data(sq1, id1); - else if(!hash_lookup(machines, id2)) - sq_save_unique_data(sq2, id2); + EXEC SQL CLOSE csr232; + generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1); + + dprintf("Checking printcaps\n"); + sq1 = sq_create(); + sq2 = sq_create(); + EXEC SQL DECLARE csr233 CURSOR FOR + SELECT mach_id, quotaserver, modby FROM printcap; + EXEC SQL OPEN csr233; + while (1) + { + EXEC SQL FETCH csr233 INTO :id1, :id2, :id3; + if (sqlca.sqlcode) + break; + + maybe_fixup_modby2("printcap", "modby", "csr233", id3); + if (!hash_lookup(machines, id1)) + sq_save_unique_data(sq1, id1); + else if (!hash_lookup(machines, id2)) + sq_save_unique_data(sq2, id2); } - EXEC SQL CLOSE csr233; - generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1); - generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1); + EXEC SQL CLOSE csr233; + generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1); + generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1); } diff --git a/dbck/phase3.pc b/dbck/phase3.pc index 529c0e8a..2f7a27b9 100644 --- a/dbck/phase3.pc +++ b/dbck/phase3.pc @@ -6,77 +6,74 @@ */ #include +#include #include "dbck.h" static char phase3_qc_rcsid[] = "$Header$"; -empty_list_check(id, l, hint) -int id, hint; -struct list *l; +empty_list_check(int id, struct list *l, int hint) { - if (l->members == 0 && l->list_id != 0) - printf("Warning: List %s is empty\n", l->name); + if (l->members == 0 && l->list_id != 0) + printf("Warning: List %s is empty\n", l->name); } /* Used by other parts of the program to check that a string_id is good. - * This returns TRUE if it is, or FALSE if it is not, and as a side effect + * This returns the stringif it is, or NULL if it is not, and as a side effect * increments the string reference count. */ -struct string *string_check(id) -int id; +struct string *string_check(int id) { - register struct string *s; + register struct string *s; - s = (struct string *) hash_lookup(strings, id); - if (s == NULL) - return(s); - s->refc++; - return(s); + s = (struct string *) hash_lookup(strings, id); + if (!s) + return s; + s->refc++; + return s; } -unref_string_check(id, s, hint) -int id, hint; -struct string *s; +unref_string_check(int id, struct string *s, int hint) { - if (s->refc == 0) { - printf("Unreferenced string %s id %d\n", s->name, id); - if (single_fix("Delete", 1)) - single_delete("strings", "string_id", id); + if (s->refc == 0) + { + printf("Unreferenced string %s id %d\n", s->name, id); + if (single_fix("Delete", 1)) + single_delete("strings", "string_id", id); } } /* This test was disabled because the MIT Moira server, which - * initially only managed host information for workstations and + * initially only managed host information for workstations and * servers in the Athena Computing Environment, has been extended to * manage all hosts in the MIT.EDU domain (but not subdomains). */ -/* -noclu_mach_check(id, m, hint) -int id, hint; -struct machine *m; +#ifndef ATHENA +noclu_mach_check(int id, struct machine *m, int hint) { - if (m->clucount == 0 && m->mach_id != 0) - printf("Warning: machine %s is not in any clusters\n", m->name); + if (m->clucount == 0 && m->mach_id != 0) + printf("Warning: machine %s is not in any clusters\n", m->name); } -*/ +#endif -phase3() +phase3(void) { - printf("Phase 3 - Finding unused objects\n"); + printf("Phase 3 - Finding unused objects\n"); - if (warn) { -/* dprintf("Checking machines...\n"); - * hash_step(machines, noclu_mach_check, NULL); - */ - dprintf("Checking lists...\n"); - hash_step(lists, empty_list_check, NULL); + if (warn) + { +#ifndef ATHENA + dprintf("Checking machines...\n"); + hash_step(machines, noclu_mach_check, NULL); +#endif + dprintf("Checking lists...\n"); + hash_step(lists, empty_list_check, NULL); } - dprintf("Checking strings...\n"); - hash_step(strings, unref_string_check, NULL); + dprintf("Checking strings...\n"); + hash_step(strings, unref_string_check, NULL); } diff --git a/dbck/phase4.pc b/dbck/phase4.pc index 30f470ea..a6ee75f4 100644 --- a/dbck/phase4.pc +++ b/dbck/phase4.pc @@ -6,6 +6,7 @@ */ #include +#include #include #include "dbck.h" EXEC SQL INCLUDE sqlca; @@ -14,220 +15,223 @@ static char phase4_qc_rcsid[] = "$Header$"; EXEC SQL WHENEVER SQLERROR DO dbmserr(); -count_boxes(id, u, boxes) -int id; -struct user *u; -struct hash *boxes; +count_boxes(int id, struct user *u, struct hash *boxes) { - int i; + int i; - if (u->potype == 'P') { - if (i = (int) hash_lookup(boxes, u->pobox_id)) { - if( hash_store(boxes, u->pobox_id, i+1) == -1 ) { + if (u->potype == 'P') + { + if ((i = (int) hash_lookup(boxes, u->pobox_id))) + { + if (hash_store(boxes, u->pobox_id, i + 1) == -1) out_of_mem("storing poboxes in hash table"); - } - } else { + } + else + { printf("User %s(%s) has pobox on non-POP server %d\n", u->fullname, u->login, u->pobox_id); printf("Not fixing this error\n"); - } + } } } -check_box_counts(id, cnt, counts) -int id, cnt; -struct hash *counts; +check_box_counts(int id, int cnt, struct hash *counts) { - EXEC SQL BEGIN DECLARE SECTION; - int oldval, rowcount, iid = id, icnt = cnt; - EXEC SQL END DECLARE SECTION; - - oldval = (int) hash_lookup(counts, id); - cnt--; - if (oldval != cnt) { - printf("Count wrong on POBox machine %s; is %d in db, counted %d\n", - ((struct machine *) hash_lookup(machines, id))->name, - oldval, cnt); - if (single_fix("Update", 1)) { - EXEC SQL UPDATE serverhosts SET value1 = :icnt - WHERE service='POP' AND mach_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("serverhosts"); + EXEC SQL BEGIN DECLARE SECTION; + int oldval, rowcount, iid = id, icnt = cnt; + EXEC SQL END DECLARE SECTION; + + oldval = (int) hash_lookup(counts, id); + cnt--; + if (oldval != cnt) + { + printf("Count wrong on POBox machine %s; is %d in db, counted %d\n", + ((struct machine *) hash_lookup(machines, id))->name, + oldval, cnt); + if (single_fix("Update", 1)) + { + EXEC SQL UPDATE serverhosts SET value1 = :icnt + WHERE service = 'POP' AND mach_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("serverhosts"); } } } -check_nfs_counts(id, n, hint) -int id, hint; -struct nfsphys *n; +check_nfs_counts(int id, struct nfsphys *n, int hint) { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, val, rowcount; - EXEC SQL END DECLARE SECTION; - - val = n->count; - if (n->allocated != val) { - printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n", - ((struct machine *) hash_lookup(machines, n->mach_id))->name, - n->dir, n->allocated, val); - if (single_fix("Update", 1)) { - EXEC SQL UPDATE nfsphys SET allocated = :val - WHERE nfsphys_id = :iid; - rowcount = sqlca.sqlerrd[2]; - if (rowcount > 0) - printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); - else - printf("Not fixed\n"); - modified("nfsphys"); + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, val, rowcount; + EXEC SQL END DECLARE SECTION; + + val = n->count; + if (n->allocated != val) + { + printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n", + ((struct machine *) hash_lookup(machines, n->mach_id))->name, + n->dir, n->allocated, val); + if (single_fix("Update", 1)) + { + EXEC SQL UPDATE nfsphys SET allocated = :val + WHERE nfsphys_id = :iid; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("nfsphys"); } } } -phase4() +phase4(void) { - struct hash *boxes, *counts; - EXEC SQL BEGIN DECLARE SECTION; - int id, cnt; - EXEC SQL END DECLARE SECTION; - - printf("Phase 4 - Checking counts\n"); - - dprintf("Doing POBoxes...\n"); - boxes = create_hash(10); - counts = create_hash(10); - EXEC SQL DECLARE csr401 CURSOR FOR - SELECT mach_id, value1 FROM serverhosts - WHERE service='POP'; - EXEC SQL OPEN csr401; - while(1) { - EXEC SQL FETCH csr401 INTO :id, :cnt; - if (sqlca.sqlcode != 0) break; - - if( hash_store(boxes, id, 1) == -1 ) { - out_of_mem("storing poboxes"); - } - if( hash_store(counts, id, cnt) == -1 ) { - out_of_mem("storing pobox counts? in hash table"); - } + struct hash *boxes, *counts; + int id, cnt; + + printf("Phase 4 - Checking counts\n"); + + dprintf("Doing POBoxes...\n"); + boxes = create_hash(10); + counts = create_hash(10); + EXEC SQL DECLARE csr401 CURSOR FOR + SELECT mach_id, value1 FROM serverhosts + WHERE service = 'POP'; + EXEC SQL OPEN csr401; + while (1) + { + EXEC SQL FETCH csr401 INTO :id, :cnt; + if (sqlca.sqlcode) + break; + + if (hash_store(boxes, id, 1) == -1) + out_of_mem("storing poboxes"); + if (hash_store(counts, id, cnt) == -1) + out_of_mem("storing pobox counts in hash table"); } - EXEC SQL CLOSE csr401; - hash_step(users, count_boxes, boxes); - hash_step(boxes, check_box_counts, counts); + EXEC SQL CLOSE csr401; + hash_step(users, count_boxes, boxes); + hash_step(boxes, check_box_counts, counts); - dprintf("Doing NFSphys...\n"); - hash_step(nfsphys, check_nfs_counts, 0); + dprintf("Doing NFSphys...\n"); + hash_step(nfsphys, check_nfs_counts, 0); } -count_only_setup() +count_only_setup(void) { - EXEC SQL BEGIN DECLARE SECTION; - int id, status, id2, id3; - char name[33], last[17], first[17], buf[257]; - EXEC SQL END DECLARE SECTION; - struct save_queue *sq; - struct user *u; - struct nfsphys *n; - struct machine *m; - - dprintf("Loading users...\n"); - users = create_hash(30000); - EXEC SQL DECLARE csr402 CURSOR FOR - SELECT users_id, login, last, first, status, - potype, pop_id, box_id FROM users - WHERE potype='POP'; - EXEC SQL OPEN csr402; - while(1) { - EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, - :buf, :id2, :id3; - if (sqlca.sqlcode != 0) break; - - u = (struct user *) malloc(sizeof(struct user)); - if (u == NULL) - out_of_mem("storing users"); - strcpy(u->login, strtrim(name)); - u->potype = buf[0]; - sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); - u->fullname = strsave(buf); - u->status = status; - u->users_id = id; - switch (u->potype) { + EXEC SQL BEGIN DECLARE SECTION; + int id, status, id2, id3; + char name[33], last[17], first[17], buf[257]; + EXEC SQL END DECLARE SECTION; + struct save_queue *sq; + struct user *u; + struct nfsphys *n; + struct machine *m; + + dprintf("Loading users...\n"); + users = create_hash(30000); + EXEC SQL DECLARE csr402 CURSOR FOR + SELECT users_id, login, last, first, status, + potype, pop_id, box_id FROM users + WHERE potype = 'POP'; + EXEC SQL OPEN csr402; + while (1) + { + EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, + :buf, :id2, :id3; + if (sqlca.sqlcode) + break; + + u = malloc(sizeof(struct user)); + if (!u) + out_of_mem("storing users"); + strcpy(u->login, strtrim(name)); + u->potype = buf[0]; + sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); + u->fullname = strsave(buf); + u->status = status; + u->users_id = id; + switch (u->potype) + { case 'P': - u->pobox_id = id2; - break; + u->pobox_id = id2; + break; case 'S': - u->pobox_id = id3; - break; + u->pobox_id = id3; + break; default: - u->pobox_id = 0; - } - if( hash_store(users, id, u) == -1 ) { - out_of_mem("storing users in hash table"); + u->pobox_id = 0; } + if (hash_store(users, id, u) == -1) + out_of_mem("storing users in hash table"); } - EXEC SQL CLOSE csr402; - - dprintf("Loading machines...\n"); - machines = create_hash(20000); - EXEC SQL DECLARE csr403 CURSOR FOR - SELECT mach_id, name FROM machine; - EXEC SQL OPEN csr403; - while(1) { - EXEC SQL FETCH csr403 INTO :id, :name; - if (sqlca.sqlcode != 0) break; - - m = (struct machine *) malloc(sizeof(struct machine)); - if (m == NULL) + EXEC SQL CLOSE csr402; + + dprintf("Loading machines...\n"); + machines = create_hash(20000); + EXEC SQL DECLARE csr403 CURSOR FOR + SELECT mach_id, name FROM machine; + EXEC SQL OPEN csr403; + while (1) + { + EXEC SQL FETCH csr403 INTO :id, :name; + if (sqlca.sqlcode) + break; + + m = malloc(sizeof(struct machine)); + if (!m) out_of_mem("storing machines"); strcpy(m->name, strtrim(name)); m->mach_id = id; - if( hash_store(machines, id, m) == -1 ) { + if (hash_store(machines, id, m) == -1) out_of_mem("storing users in hash table"); - } } - EXEC SQL CLOSE csr403; - - dprintf("Loading nfsphys...\n"); - nfsphys = create_hash(500); - EXEC SQL DECLARE csr404 CURSOR FOR - SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys; - EXEC SQL OPEN csr404; - while(1) { - EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3; - if (sqlca.sqlcode != 0) break; - - n = (struct nfsphys *) malloc(sizeof(struct nfsphys)); - if (n == NULL) - out_of_mem("storing nfsphys"); - strcpy(n->dir, strtrim(name)); - n->mach_id = id2; - n->nfsphys_id = id; - n->allocated = id3; - n->count = 0; - if( hash_store(nfsphys, id, n) == -1 ) { - out_of_mem("storing nfsphys in hash table"); - } - } - EXEC SQL CLOSE csr404; - - dprintf("Counting quotas...\n"); - EXEC SQL DECLARE csr405 CURSOR FOR - SELECT phys_id, quota FROM quota; - EXEC SQL OPEN csr405; - while(1) { - EXEC SQL FETCH csr405 INTO :id, :id2; - if (sqlca.sqlcode != 0) break; - - if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) { - n->count += id2; - } + EXEC SQL CLOSE csr403; + + dprintf("Loading nfsphys...\n"); + nfsphys = create_hash(500); + EXEC SQL DECLARE csr404 CURSOR FOR + SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys; + EXEC SQL OPEN csr404; + while (1) + { + EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3; + if (sqlca.sqlcode) + break; + + n = malloc(sizeof(struct nfsphys)); + if (!n) + out_of_mem("storing nfsphys"); + strcpy(n->dir, strtrim(name)); + n->mach_id = id2; + n->nfsphys_id = id; + n->allocated = id3; + n->count = 0; + if (hash_store(nfsphys, id, n) == -1) + out_of_mem("storing nfsphys in hash table"); + } + EXEC SQL CLOSE csr404; + + dprintf("Counting quotas...\n"); + EXEC SQL DECLARE csr405 CURSOR FOR + SELECT phys_id, quota FROM quota; + EXEC SQL OPEN csr405; + while (1) + { + EXEC SQL FETCH csr405 INTO :id, :id2; + if (sqlca.sqlcode) + break; + + if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) + n->count += id2; } - EXEC SQL CLOSE csr405; + EXEC SQL CLOSE csr405; } diff --git a/dcm/dcm.pc b/dcm/dcm.pc index 7b9bc9ce..e0210356 100644 --- a/dcm/dcm.pc +++ b/dcm/dcm.pc @@ -31,346 +31,391 @@ EXEC SQL INCLUDE sqlca; EXEC SQL WHENEVER SQLERROR DO dbmserr(); #define SQL_NO_MATCH 1403 -#define SOFT_FAIL(x) (((x) == MR_NO_MEM) || ((x) == MR_CANT_CONNECT) || ((x) == MR_CCONFIG) || ((x) == MR_DEADLOCK) || ((x) == MR_BUSY) || ((x) == MR_ABORT)) +#define SOFT_FAIL(x) (((x) == MR_NO_MEM) || ((x) == MR_CANT_CONNECT) || ((x) == MR_CCONFIG) || ((x) == MR_DEADLOCK) || ((x) == MR_BUSY) || ((x) == MR_ABORT)) -char whobuf[256], *whoami=whobuf, *db="moira"; +char whobuf[256], *whoami = whobuf, *db = "moira"; extern CONNECTION conn; -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char **argv) { - int i; - EXEC SQL BEGIN DECLARE SECTION; - char buf[16], *name; - int enable; - EXEC SQL END DECLARE SECTION; - struct save_queue *sq; - int status; - - if (strchr(argv[0], '/')) strcpy(whoami, strrchr(argv[0], '/')+1); - else strcpy(whoami, argv[0]); - umask(7); - - setvbuf(stderr, NULL, _IOLBF, BUFSIZ); - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); - - initialize_sms_error_table(); - initialize_krb_error_table(); - - /* if services were specified on the command line, do just those ones */ - if (argc > 1) { - for (i = 1; i < argc; i++) { - if (generate_service(argv[i], 1)) - do_hosts(argv[i]); + int i; + EXEC SQL BEGIN DECLARE SECTION; + char buf[16], *name; + int enable; + EXEC SQL END DECLARE SECTION; + struct save_queue *sq; + int status; + + if (strchr(argv[0], '/')) + strcpy(whoami, strrchr(argv[0], '/') + 1); + else strcpy(whoami, argv[0]); + umask(7); + + setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + + initialize_sms_error_table(); + initialize_krb_error_table(); + + /* if services were specified on the command line, do just those ones */ + if (argc > 1) + { + for (i = 1; i < argc; i++) + { + if (generate_service(argv[i], 1)) + do_hosts(argv[i]); } - exit(0); + exit(0); } - /* if DCM is not enabled, exit after logging */ - if (!access(NODCMFILE, F_OK)) { - printf("/etc/nodcm exists -- exiting\n"); - exit(1); + /* if DCM is not enabled, exit after logging */ + if (!access(NODCMFILE, F_OK)) + { + printf("/etc/nodcm exists -- exiting\n"); + exit(1); } - - EXEC SQL CONNECT :db IDENTIFIED BY :db; - - EXEC SQL SELECT value INTO :enable FROM numvalues - WHERE name='dcm_enable'; - if (enable == 0) { - printf("dcm_enable not set -- exiting\n"); - exit(1); + + EXEC SQL CONNECT :db IDENTIFIED BY :db; + + EXEC SQL SELECT value INTO :enable FROM numvalues WHERE name = 'dcm_enable'; + if (enable == 0) + { + printf("dcm_enable not set -- exiting\n"); + exit(1); } - - /* fetch list of services */ - EXEC SQL DECLARE csr_svc CURSOR FOR SELECT LOWER(name) FROM servers - WHERE enable=1 AND harderror=0 AND update_int>0; - EXEC SQL OPEN csr_svc; - sq = sq_create(); - while(1) { - EXEC SQL FETCH csr_svc INTO :buf; - if (sqlca.sqlcode) break; - - sq_save_data(sq, strdup(strtrim(buf))); + + /* fetch list of services */ + EXEC SQL DECLARE csr_svc CURSOR FOR SELECT LOWER(name) FROM servers + WHERE enable = 1 AND harderror = 0 AND update_int > 0; + EXEC SQL OPEN csr_svc; + sq = sq_create(); + while (1) + { + EXEC SQL FETCH csr_svc INTO :buf; + if (sqlca.sqlcode) + break; + + sq_save_data(sq, strdup(strtrim(buf))); } - EXEC SQL CLOSE csr_svc; - /* we will repeatedly open and close the db since it seems to get - upset if you keep it open across a fork */ - EXEC SQL COMMIT RELEASE; - - /* Now run through list */ - while (sq_get_data(sq, &name)) { - if (generate_service(name, 0)) { - switch (fork()) { - case -1: - fprintf(stderr, - "dcm: could not fork for service %s -- exiting", - name); - exit(1); - case 0: - sprintf(strchr(whoami, '\0'), " (%s)", name); - do_hosts(name); - com_err(whoami, 0, "exiting"); - exit(0); - default: - break; + EXEC SQL CLOSE csr_svc; + /* we will repeatedly open and close the db since it seems to get + upset if you keep it open across a fork */ + EXEC SQL COMMIT RELEASE; + + /* Now run through list */ + while (sq_get_data(sq, &name)) + { + if (generate_service(name, 0)) + { + switch (fork()) + { + case -1: + fprintf(stderr, "dcm: could not fork for service %s -- exiting", + name); + exit(1); + case 0: + sprintf(strchr(whoami, '\0'), " (%s)", name); + do_hosts(name); + com_err(whoami, 0, "exiting"); + exit(0); + default: + break; } } } - - /* wait for children */ - while (waitpid(0, &status, 0) > 0) ; - com_err(whoami, 0, "exiting"); + + /* wait for children */ + while (waitpid(0, &status, 0) > 0) + ; + com_err(whoami, 0, "exiting"); } int generate_service(char *name, int force) { - EXEC SQL BEGIN DECLARE SECTION; - int interval, dfcheck, status; - time_t now; - char *errmsg; - EXEC SQL END DECLARE SECTION; - char dfgen_prog[64], dfgen_cmd[128]; - struct sigaction action, prevaction; - int waits; - - EXEC SQL CONNECT :db IDENTIFIED BY :db; - - EXEC SQL SELECT update_int, dfcheck INTO :interval, :dfcheck - FROM servers WHERE name=UPPER(:name); - if (sqlca.sqlcode == SQL_NO_MATCH) { - com_err(whoami, 0, "No such service `%s'", name); - EXEC SQL COMMIT RELEASE; - return 0; + EXEC SQL BEGIN DECLARE SECTION; + int interval, dfcheck, status; + time_t now; + char *errmsg; + EXEC SQL END DECLARE SECTION; + char dfgen_prog[64], dfgen_cmd[128]; + struct sigaction action, prevaction; + int waits; + + EXEC SQL CONNECT :db IDENTIFIED BY :db; + + EXEC SQL SELECT update_int, dfcheck INTO :interval, :dfcheck + FROM servers WHERE name = UPPER(:name); + if (sqlca.sqlcode == SQL_NO_MATCH) + { + com_err(whoami, 0, "No such service `%s'", name); + EXEC SQL COMMIT RELEASE; + return 0; } - - time(&now); - - if ((interval * 60 + dfcheck < now) || force) { - sprintf(dfgen_prog, "%s/%s.gen", BIN_DIR, name); - if (access(dfgen_prog, F_OK) != 0) { - com_err(whoami, 0, "prog %s doesn't exist", dfgen_prog); - EXEC SQL COMMIT RELEASE; - return 0; + + time(&now); + + if ((interval * 60 + dfcheck < now) || force) + { + sprintf(dfgen_prog, "%s/%s.gen", BIN_DIR, name); + if (access(dfgen_prog, F_OK) != 0) + { + com_err(whoami, 0, "prog %s doesn't exist", dfgen_prog); + EXEC SQL COMMIT RELEASE; + return 0; } - sprintf(dfgen_cmd, "exec %s %s/%s.out", dfgen_prog, DCM_DIR, name); - com_err(whoami, 0, "running %s", dfgen_prog); - - EXEC SQL UPDATE servers SET inprogress=1 - WHERE name=UPPER(:name); - - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - action.sa_handler = SIG_DFL; - sigaction(SIGCHLD, &action, &prevaction); - waits = system(dfgen_cmd); - sigaction(SIGCHLD, &prevaction, NULL); - if (WIFSIGNALED(waits)) { - status = MR_COREDUMP; - com_err(whoami, status, " %s exited on signal %d", - dfgen_prog, WTERMSIG(waits)); - } else if (WEXITSTATUS(waits)) { - /* extract the process's exit value */ - status = WEXITSTATUS(waits) + ERROR_TABLE_BASE_sms; - if (status != MR_NO_CHANGE) - com_err(whoami, status, "in %s", dfgen_prog); - } else status = MR_SUCCESS; - - if (status == MR_SUCCESS) { - EXEC SQL UPDATE servers SET dfgen = :now, dfcheck = :now, - inprogress = 0 WHERE name=UPPER(:name); - EXEC SQL COMMIT RELEASE; - return 1; - } else if (status == MR_NO_CHANGE) { - EXEC SQL UPDATE servers SET dfcheck = :now, inprogress = 0 - WHERE name=UPPER(:name); - } else if (SOFT_FAIL(status)) { - errmsg = error_message(status); - EXEC SQL UPDATE servers SET errmsg = :errmsg, inprogress = 0 - WHERE name=UPPER(:name); - } else { /* HARD_FAIL(status) */ - errmsg = error_message(status); - EXEC SQL UPDATE servers SET dfcheck = :now, harderror = :status, - errmsg = :errmsg, inprogress = 0 WHERE name=UPPER(:name); - critical_alert("DCM","DCM building config files for %s: %s", - name, errmsg); + sprintf(dfgen_cmd, "exec %s %s/%s.out", dfgen_prog, DCM_DIR, name); + com_err(whoami, 0, "running %s", dfgen_prog); + + EXEC SQL UPDATE servers SET inprogress = 1 + WHERE name = UPPER(:name); + + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + action.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &action, &prevaction); + waits = system(dfgen_cmd); + sigaction(SIGCHLD, &prevaction, NULL); + if (WIFSIGNALED(waits)) + { + status = MR_COREDUMP; + com_err(whoami, status, " %s exited on signal %d", + dfgen_prog, WTERMSIG(waits)); + } + else if (WEXITSTATUS(waits)) + { + /* extract the process's exit value */ + status = WEXITSTATUS(waits) + ERROR_TABLE_BASE_sms; + if (status != MR_NO_CHANGE) + com_err(whoami, status, "in %s", dfgen_prog); + } + else + status = MR_SUCCESS; + + if (status == MR_SUCCESS) + { + EXEC SQL UPDATE servers SET dfgen = :now, dfcheck = :now, + inprogress = 0 WHERE name = UPPER(:name); + EXEC SQL COMMIT RELEASE; + return 1; + } + else if (status == MR_NO_CHANGE) + { + EXEC SQL UPDATE servers SET dfcheck = :now, inprogress = 0 + WHERE name = UPPER(:name); + } + else if (SOFT_FAIL(status)) + { + errmsg = error_message(status); + EXEC SQL UPDATE servers SET errmsg = :errmsg, inprogress = 0 + WHERE name = UPPER(:name); + } + else /* HARD_FAIL(status) */ + { + errmsg = error_message(status); + EXEC SQL UPDATE servers SET dfcheck = :now, harderror = :status, + errmsg = :errmsg, inprogress = 0 WHERE name = UPPER(:name); + critical_alert("DCM", "DCM building config files for %s: %s", + name, errmsg); } } - EXEC SQL COMMIT RELEASE; - return 0; + EXEC SQL COMMIT RELEASE; + return 0; } void do_hosts(char *service) { - EXEC SQL BEGIN DECLARE SECTION; - char type[16], host[73], target[64], script[128], *errmsg; - int status = 0, mid, dfgen, replicated; - time_t now; - EXEC SQL END DECLARE SECTION; - - time(&now); - gdb_init(); - - EXEC SQL CONNECT :db IDENTIFIED BY :db; - - EXEC SQL SELECT dfgen, type, target_file, script - INTO :dfgen, :type, :target, :script - FROM servers WHERE name=UPPER(:service); - replicated = !strncmp(type, "REPLICAT", 8); - - EXEC SQL DECLARE csr_hst1 CURSOR FOR - SELECT m.name FROM machine m, serverhosts sh - WHERE sh.service=UPPER(:service) AND sh.enable=1 AND sh.hosterror=0 - AND sh.lts<:dfgen AND sh.mach_id=m.mach_id - FOR UPDATE OF sh.inprogress, sh.hosterror, sh.hosterrmsg; - EXEC SQL OPEN csr_hst1; - - while (1) { - EXEC SQL FETCH csr_hst1 INTO :host; - if (sqlca.sqlcode == SQL_NO_MATCH) break; - - com_err(whoami, 0, "sending %s data to %s", service, strtrim(host)); - EXEC SQL UPDATE serverhosts SET inprogress = 1 - WHERE CURRENT OF csr_hst1; - status = dcm_send_file(service, host, strtrim(target)); - if (status) { - errmsg = error_message(status); - EXEC SQL UPDATE serverhosts SET hosterrmsg = :errmsg, - inprogress = 0 WHERE CURRENT OF csr_hst1; - if (!SOFT_FAIL(status)) { - EXEC SQL UPDATE serverhosts SET hosterror = :status - WHERE CURRENT OF csr_hst1; - critical_alert("DCM", "DCM updating %s:%s: %s", - service, host, errmsg); + EXEC SQL BEGIN DECLARE SECTION; + char type[16], host[73], target[64], script[128], *errmsg; + int status = 0, mid, dfgen, replicated; + time_t now; + EXEC SQL END DECLARE SECTION; + + time(&now); + gdb_init(); + + EXEC SQL CONNECT :db IDENTIFIED BY :db; + + EXEC SQL SELECT dfgen, type, target_file, script + INTO :dfgen, :type, :target, :script + FROM servers WHERE name = UPPER(:service); + replicated = !strncmp(type, "REPLICAT", 8); + + EXEC SQL DECLARE csr_hst1 CURSOR FOR + SELECT m.name FROM machine m, serverhosts sh + WHERE sh.service = UPPER(:service) + AND sh.enable = 1 AND sh.hosterror = 0 + AND sh.lts < :dfgen AND sh.mach_id = m.mach_id + FOR UPDATE OF sh.inprogress, sh.hosterror, sh.hosterrmsg; + EXEC SQL OPEN csr_hst1; + + while (1) + { + EXEC SQL FETCH csr_hst1 INTO :host; + if (sqlca.sqlcode == SQL_NO_MATCH) + break; + + com_err(whoami, 0, "sending %s data to %s", service, strtrim(host)); + EXEC SQL UPDATE serverhosts SET inprogress = 1 + WHERE CURRENT OF csr_hst1; + status = dcm_send_file(service, host, strtrim(target)); + if (status) + { + errmsg = error_message(status); + EXEC SQL UPDATE serverhosts SET hosterrmsg = :errmsg, + inprogress = 0 WHERE CURRENT OF csr_hst1; + if (!SOFT_FAIL(status)) + { + EXEC SQL UPDATE serverhosts SET hosterror = :status + WHERE CURRENT OF csr_hst1; + critical_alert("DCM", "DCM updating %s:%s: %s", + service, host, errmsg); } - - if (replicated) break; + + if (replicated) + break; } } - EXEC SQL CLOSE csr_hst1; - - if (status == MR_SUCCESS || !replicated) { - EXEC SQL DECLARE csr_hst2 CURSOR FOR - SELECT m.name FROM machine m, serverhosts sh - WHERE sh.service=UPPER(:service) AND sh.inprogress=1 - AND sh.mach_id=m.mach_id - FOR UPDATE OF sh.hosterror, sh.hosterrmsg, sh.inprogress; - EXEC SQL OPEN csr_hst2; - - while (1) { - EXEC SQL FETCH csr_hst2 INTO :host; - if (sqlca.sqlcode == SQL_NO_MATCH) break; - - com_err(whoami, 0, "executing instructions on %s", strtrim(host)); - status = dcm_execute(service, host, strtrim(script)); - if (status) { - errmsg = error_message(status); - EXEC SQL UPDATE serverhosts SET hosterrmsg = :errmsg, - inprogress = 0 WHERE CURRENT OF csr_hst2; - if (!SOFT_FAIL(status)) { - EXEC SQL UPDATE serverhosts SET hosterror = :status - WHERE CURRENT OF csr_hst2; - critical_alert("DCM", "DCM updating %s:%s: %s", - service, host, errmsg); + EXEC SQL CLOSE csr_hst1; + + if (status == MR_SUCCESS || !replicated) + { + EXEC SQL DECLARE csr_hst2 CURSOR FOR + SELECT m.name FROM machine m, serverhosts sh + WHERE sh.service = UPPER(:service) AND sh.inprogress = 1 + AND sh.mach_id = m.mach_id + FOR UPDATE OF sh.hosterror, sh.hosterrmsg, sh.inprogress; + EXEC SQL OPEN csr_hst2; + + while (1) + { + EXEC SQL FETCH csr_hst2 INTO :host; + if (sqlca.sqlcode == SQL_NO_MATCH) + break; + + com_err(whoami, 0, "executing instructions on %s", strtrim(host)); + status = dcm_execute(service, host, strtrim(script)); + if (status) + { + errmsg = error_message(status); + EXEC SQL UPDATE serverhosts SET hosterrmsg = :errmsg, + inprogress = 0 WHERE CURRENT OF csr_hst2; + if (!SOFT_FAIL(status)) + { + EXEC SQL UPDATE serverhosts SET hosterror = :status + WHERE CURRENT OF csr_hst2; + critical_alert("DCM", "DCM updating %s:%s: %s", + service, host, errmsg); } - - if (replicated) { - /* We're giving up, so clear the inprogress flag on - any hosts in this service we haven't gotten to yet */ - EXEC SQL UPDATE serverhosts SET inprogress = 0 - WHERE service=UPPER(:service); - break; + + if (replicated) + { + /* We're giving up, so clear the inprogress flag on + any hosts in this service we haven't gotten to yet */ + EXEC SQL UPDATE serverhosts SET inprogress = 0 + WHERE service = UPPER(:service); + break; } - } else { - EXEC SQL UPDATE serverhosts SET inprogress=0, lts=:now - WHERE CURRENT OF csr_hst2; + } + else + { + EXEC SQL UPDATE serverhosts SET inprogress = 0, lts = :now + WHERE CURRENT OF csr_hst2; } } - EXEC SQL CLOSE csr_hst2; + EXEC SQL CLOSE csr_hst2; } - if (status && replicated) { - EXEC SQL UPDATE servers SET harderror = :status, errmsg = :errmsg - WHERE name = UPPER(:service); + if (status && replicated) + { + EXEC SQL UPDATE servers SET harderror = :status, errmsg = :errmsg + WHERE name = UPPER(:service); } - EXEC SQL COMMIT RELEASE; + EXEC SQL COMMIT RELEASE; } int dcm_send_file(char *service, char *host, char *target) { - char addr[256], data[MAXPATHLEN]; - int code; - - sprintf(addr, "%s:moira_update", host); - conn = start_server_connection(addr, ""); - if (!conn || (connection_status(conn) == CON_STOPPED)) { - com_err(whoami, connection_errno(conn), "can't connect to %s", addr); - return MR_CANT_CONNECT; + char addr[256], data[MAXPATHLEN]; + int code; + + sprintf(addr, "%s:moira_update", host); + conn = start_server_connection(addr, ""); + if (!conn || (connection_status(conn) == CON_STOPPED)) + { + com_err(whoami, connection_errno(conn), "can't connect to %s", addr); + return MR_CANT_CONNECT; } - code = send_auth(host); - if (code) { - com_err(whoami, code, "authenticating to %s", host); - goto done; + code = send_auth(host); + if (code) + { + com_err(whoami, code, "authenticating to %s", host); + goto done; } - sprintf(data, "%s/%s.out", DCM_DIR, service); - code = send_file(data, target, 1); - if (code == MR_UNKNOWN_PROC) code = send_file(data, target, 0); - if (code) com_err(whoami, code, "sending data to %s", host); + sprintf(data, "%s/%s.out", DCM_DIR, service); + code = send_file(data, target, 1); + if (code == MR_UNKNOWN_PROC) + code = send_file(data, target, 0); + if (code) + com_err(whoami, code, "sending data to %s", host); done: - send_quit(); - sever_connection(conn); - return(code); + send_quit(); + sever_connection(conn); + return code; } int dcm_execute(char *service, char *host, char *script) { - char addr[256], inst[MAXPATHLEN]; - int code; - - sprintf(addr, "%s:moira_update", host); - conn = start_server_connection(addr, ""); - if (!conn || (connection_status(conn) == CON_STOPPED)) { - com_err(whoami, connection_errno(conn), "can't connect to %s", addr); - return MR_CANT_CONNECT; + char addr[256], inst[MAXPATHLEN]; + int code; + + sprintf(addr, "%s:moira_update", host); + conn = start_server_connection(addr, ""); + if (!conn || (connection_status(conn) == CON_STOPPED)) + { + com_err(whoami, connection_errno(conn), "can't connect to %s", addr); + return MR_CANT_CONNECT; } - code = send_auth(host); - if (code) { - com_err(whoami, code, "authenticating to %s", host); - goto done; + code = send_auth(host); + if (code) + { + com_err(whoami, code, "authenticating to %s", host); + goto done; } - sprintf(inst, "/tmp/moira-update.XXXXXX"); - mktemp(inst); - code = send_file(script, inst, 0); - if (code) { - com_err(whoami, code, "sending instructions to %s", host); - goto done; + sprintf(inst, "/tmp/moira-update.XXXXXX"); + mktemp(inst); + code = send_file(script, inst, 0); + if (code) + { + com_err(whoami, code, "sending instructions to %s", host); + goto done; } - code = execute(inst); - if (code) com_err(whoami, code, "executing instructions on %s", host); + code = execute(inst); + if (code) + com_err(whoami, code, "executing instructions on %s", host); done: - send_quit(); - sever_connection(conn); - return(code); -} + send_quit(); + sever_connection(conn); + return code; +} void dbmserr(void) { - EXEC SQL BEGIN DECLARE SECTION; - char err_msg[256]; - EXEC SQL END DECLARE SECTION; - int bufsize=256, msglength=0; - - sqlglm(err_msg, &bufsize, &msglength); - err_msg[msglength]=0; - com_err(whoami, 0, "Encountered SQL error:\n%s", err_msg); - com_err(whoami, 0, "exiting"); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + char err_msg[256]; + EXEC SQL END DECLARE SECTION; + int bufsize = 256, msglength = 0; + + sqlglm(err_msg, &bufsize, &msglength); + err_msg[msglength] = '\0'; + com_err(whoami, 0, "Encountered SQL error:\n%s", err_msg); + com_err(whoami, 0, "exiting"); + exit(1); } diff --git a/dcm/startdcm.c b/dcm/startdcm.c index 6f49c4c6..6d9e9001 100644 --- a/dcm/startdcm.c +++ b/dcm/startdcm.c @@ -34,115 +34,123 @@ static char *rcsid_mr_starter_c = "$Header$"; int rdpipe[2]; extern int errno; -void cleanup() +void cleanup(void) { - int stat, serrno = errno; - char buf[BUFSIZ]; - - buf[0]='\0'; - - while (waitpid(-1, &stat, WNOHANG) > 0) { - if (WIFEXITED(stat)) { - if (WEXITSTATUS(stat)) - sprintf(buf, - "exited with code %d\n", - WEXITSTATUS(stat)); - } - if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on signal %d%s\n", - WTERMSIG(stat), - (WCOREDUMP(stat)?"; Core dumped":"")); - } - write(rdpipe[1], buf, strlen(buf)); - close(rdpipe[1]); + int stat, serrno = errno; + char buf[BUFSIZ]; + + buf[0] = '\0'; + + while (waitpid(-1, &stat, WNOHANG) > 0) + { + if (WIFEXITED(stat)) + { + if (WEXITSTATUS(stat)) + sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat)); + } + if (WIFSIGNALED(stat)) + { + sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat), + (WCOREDUMP(stat) ? "; Core dumped" : "")); } - errno = serrno; + write(rdpipe[1], buf, strlen(buf)); + close(rdpipe[1]); + } + errno = serrno; } -main(argc, argv) +int main(int argc, char *argv) { - char buf[BUFSIZ]; - FILE *log, *prog; - int logf, inf, i, done, pid, tty; - struct rlimit rl; - - extern int errno; - extern char *sys_errlist[]; - - struct sigaction action; - int nfds; - - getrlimit(RLIMIT_NOFILE, &rl); - nfds = rl.rlim_cur; - - action.sa_handler = cleanup; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaction(SIGCHLD, &action, NULL); - - sprintf(buf, "%s/%s.log", SMS_DIR, PROG); - logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); - if (logf<0) { - perror(buf); - exit(1); - } - inf = open("/dev/null", O_RDONLY , 0); - if (inf < 0) { - perror("/dev/null"); - exit(1); - } - pipe(rdpipe); - if (fork()) { - exit(0); - } - chdir("/"); - close(0); - close(1); - close(2); - dup2(inf, 0); - dup2(inf, 1); - dup2(inf, 2); - - setpgrp(); - sprintf(buf, "%s/%s", BIN_DIR, PROG); - - if ((pid = fork()) == 0) { - - dup2(inf, 0); - dup2(rdpipe[1], 1); - dup2(1,2); - for (i = 3; i %s", time_s, pid, buf); - fflush(log); - } while (!done); - exit(0); + struct sigaction action; + int nfds; + + getrlimit(RLIMIT_NOFILE, &rl); + nfds = rl.rlim_cur; + + action.sa_handler = cleanup; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGCHLD, &action, NULL); + + sprintf(buf, "%s/%s.log", SMS_DIR, PROG); + logf = open(buf, O_CREAT | O_WRONLY | O_APPEND, 0640); + if (logf < 0) + { + perror(buf); + exit(1); + } + inf = open("/dev/null", O_RDONLY , 0); + if (inf < 0) + { + perror("/dev/null"); + exit(1); + } + pipe(rdpipe); + if (fork()) + exit(0); + chdir("/"); + close(0); + close(1); + close(2); + dup2(inf, 0); + dup2(inf, 1); + dup2(inf, 2); + + setpgrp(); + sprintf(buf, "%s/%s", BIN_DIR, PROG); + + if ((pid = fork()) == 0) + { + dup2(inf, 0); + dup2(rdpipe[1], 1); + dup2(1, 2); + for (i = 3; i < nfds; i++) + close(i); + execl(buf, PROG, 0); + perror("cannot run dcm"); + exit(1); + } + if (pid < 0) + { + perror("startdcm"); + exit(1); + } + + log = fdopen(logf, "w"); + prog = fdopen(rdpipe[0], "r"); + + do + { + char *time_s; + long foo; + + done = 0; + errno = 0; + if (!fgets(buf, BUFSIZ, prog)) + { + if (errno && errno != EINTR) + { + strcpy(buf, "Unable to read from program: "); + strcat(buf, sys_errlist[errno]); + strcat(buf, "\n"); + } + else + break; + } + time(&foo); + time_s = ctime(&foo) + 4; + time_s[strlen(time_s) - 6] = '\0'; + fprintf(log, "%s <%d> %s", time_s, pid, buf); + fflush(log); + } + while (!done); + exit(0); } diff --git a/gen/Imakefile b/gen/Imakefile index e91af556..27abca25 100644 --- a/gen/Imakefile +++ b/gen/Imakefile @@ -25,13 +25,13 @@ DEFINES = $(GDSSINC) #else /* DO_GDSS */ SRCS = util.c moddiff.c passwd.c hesiod.c \ nfs.c mailhub.c pobox.c \ - hosts.c network.c + hosts.c network.c OBJS = util.o moddiff.o passwd.o hesiod.o \ nfs.o mailhub.o pobox.o \ - hosts.o network.o + hosts.o network.o CODE = util.c moddiff.pc passwd.pc hesiod.pc \ nfs.pc mailhub.pc pobox.pc \ - hosts.pc network.pc + hosts.pc network.pc LIBS = -L/usr/athena/lib ../lib/libmoira.a -lcom_err -lzephyr \ -lkrb -ldes -lhesiod ${SQL_LIB} DEFINES = diff --git a/gen/hesiod.pc b/gen/hesiod.pc index 06ad0038..410c114d 100644 --- a/gen/hesiod.pc +++ b/gen/hesiod.pc @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -32,522 +33,590 @@ EXEC SQL INCLUDE sqlca; #define HESIOD_SUBDIR "hesiod" #endif -/* max number of bytes of a data record that can be returned in a hesiod +/* max number of bytes of a data record that can be returned in a hesiod * query. This is 512 - overhead (~66) [derived empirically] */ #define MAXHESSIZE 446 char hesiod_dir[64]; -#define min(x,y) ((x) < (y) ? (x) : (y)) +#define min(x, y) ((x) < (y) ? (x) : (y)) struct hash *machines = NULL; struct hash *users = NULL; char *whoami = "hesiod.gen"; char *db = "moira/moira"; struct grp { - struct grp *next; - char *lid; + struct grp *next; + char *lid; }; struct user { - char name[9]; - struct grp *lists; + char name[9]; + struct grp *lists; }; -void lowercase(); -char *malloc(), *strsave(); - -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - char cmd[64]; - struct stat sb; - int changed = 0; - - if (argc > 2) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); + char cmd[64]; + struct stat sb; + int changed = 0; + + if (argc > 2) + { + fprintf(stderr, "usage: %s [outfile]\n", argv[0]); + exit(MR_ARGS); } - initialize_sms_error_table (); - sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR); - - EXEC SQL CONNECT :db; - - changed = do_passwd(); - changed += do_filsys(); - changed += do_cluster(); - changed += do_printcap(); - changed += do_palladium(); - changed += do_sloc(); - changed += do_service(); - changed += do_groups(); - - if (!changed) { - fprintf(stderr, "No files updated.\n"); - if (argc == 2 && stat(argv[1], &sb) == 0) - exit(MR_NO_CHANGE); + initialize_sms_error_table(); + sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR); + + EXEC SQL CONNECT :db; + + changed = do_passwd(); + changed += do_filsys(); + changed += do_cluster(); + changed += do_printcap(); + changed += do_palladium(); + changed += do_sloc(); + changed += do_service(); + changed += do_groups(); + + 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 .", hesiod_dir, argv[1]); - if (system(cmd)) - exit(MR_TAR_FAIL); + if (argc == 2) + { + fprintf(stderr, "Building tar file.\n"); + sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]); + if (system(cmd)) + exit(MR_TAR_FAIL); } - exit(MR_SUCCESS); + exit(MR_SUCCESS); } -get_mach() +get_mach(void) { - EXEC SQL BEGIN DECLARE SECTION; - int id; - char name[41]; - EXEC SQL END DECLARE SECTION; - - if (machines) - return; - - machines = create_hash(1000); - EXEC SQL DECLARE m_cursor CURSOR FOR - SELECT name, mach_id - FROM machine - WHERE status = 1 and mach_id != 0 - ORDER BY mach_id; - EXEC SQL OPEN m_cursor; - while (1) { - EXEC SQL FETCH m_cursor INTO :name, :id; - if (sqlca.sqlcode != 0) break; - hash_store(machines, id, strsave(strtrim(name))); - } - if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode); - EXEC SQL CLOSE m_cursor; - EXEC SQL COMMIT; + EXEC SQL BEGIN DECLARE SECTION; + int id; + char name[41]; + EXEC SQL END DECLARE SECTION; + + if (machines) + return; + + machines = create_hash(1000); + EXEC SQL DECLARE m_cursor CURSOR FOR + SELECT name, mach_id + FROM machine + WHERE status = 1 and mach_id != 0 + ORDER BY mach_id; + EXEC SQL OPEN m_cursor; + while (1) + { + EXEC SQL FETCH m_cursor INTO :name, :id; + if (sqlca.sqlcode) + break; + hash_store(machines, id, strsave(strtrim(name))); + } + if (sqlca.sqlcode < 0) + db_error(sqlca.sqlcode); + EXEC SQL CLOSE m_cursor; + EXEC SQL COMMIT; } -do_passwd() +int do_passwd(void) { - FILE *pout, *uout, *bout; - char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64]; - struct stat psb, usb, bsb; - time_t ftime; - struct user *u; - char *mach; - EXEC SQL BEGIN DECLARE SECTION; - char login[9], shell[33], fullname[33], oa[17], op[13], hp[17]; - char nn[17], ptype[9]; - int uid, flag1, flag2, id, pid, status; - EXEC SQL END DECLARE SECTION; - - sprintf(poutf, "%s/passwd.db", hesiod_dir); - sprintf(uoutf, "%s/uid.db", hesiod_dir); - sprintf(boutf, "%s/pobox.db", hesiod_dir); - - if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 && - stat(boutf, &bsb) == 0) { - ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime); - if (ModDiff (&flag1, "users", ftime) || - ModDiff (&flag2, "machine", ftime)) - exit (MR_DATE); - if (flag1 < 0 && flag2 < 0) { - fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(poutft, "%s~", poutf); - pout = fopen(poutft, "w"); - if (!pout) { - perror("cannot open passwd.db~ for write"); - exit(MR_OCONFIG); - } - sprintf(uoutft, "%s~", uoutf); - uout = fopen(uoutft, "w"); - if (!uout) { - perror("cannot open uid.db~ for write"); - exit(MR_OCONFIG); - } - sprintf(boutft, "%s~", boutf); - bout = fopen(boutft, "w"); - if (!bout) { - perror("cannot open pobox.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n"); - get_mach(); - - users = create_hash(12001); - EXEC SQL DECLARE u_cursor CURSOR FOR - 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 - ORDER BY users_id; - EXEC SQL OPEN u_cursor; - while (1) { - EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn, - :oa, :op, :hp, :id, :pid, :ptype, :status; - if (sqlca.sqlcode != 0) break; - strtrim(login); - dequote(fullname); - dequote(nn); - dequote(oa); - dequote(op); - dequote(hp); - dequote(shell); - u = (struct user *) malloc(sizeof(struct user)); - strcpy(u->name, login); - u->lists = NULL; - hash_store(users, id, u); - if (status == 1) { - 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\t%s %s \"POP %s %s\"\n", - login, HCLASS, HTYPE, mach, login); - } + FILE *pout, *uout, *bout; + char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64]; + struct stat psb, usb, bsb; + time_t ftime; + struct user *u; + char *mach; + EXEC SQL BEGIN DECLARE SECTION; + char login[9], shell[33], fullname[33], oa[17], op[13], hp[17]; + char nn[17], ptype[9]; + int uid, flag1, flag2, id, pid, status; + EXEC SQL END DECLARE SECTION; + + sprintf(poutf, "%s/passwd.db", hesiod_dir); + sprintf(uoutf, "%s/uid.db", hesiod_dir); + sprintf(boutf, "%s/pobox.db", hesiod_dir); + + if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 && + stat(boutf, &bsb) == 0) + { + ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime); + if (ModDiff (&flag1, "users", ftime) || + ModDiff (&flag2, "machine", ftime)) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0) + { + fprintf(stderr, "Files passwd.db, uid.db, and pobox.db " + "do not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(poutft, "%s~", poutf); + pout = fopen(poutft, "w"); + if (!pout) + { + perror("cannot open passwd.db~ for write"); + exit(MR_OCONFIG); + } + sprintf(uoutft, "%s~", uoutf); + uout = fopen(uoutft, "w"); + if (!uout) + { + perror("cannot open uid.db~ for write"); + exit(MR_OCONFIG); + } + sprintf(boutft, "%s~", boutf); + bout = fopen(boutft, "w"); + if (!bout) + { + perror("cannot open pobox.db for write"); + exit(MR_OCONFIG); } - if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode); - EXEC SQL CLOSE u_cursor; - EXEC SQL COMMIT; - if (fclose(pout) || fclose(uout) || fclose(bout)) { - fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n"); - exit(MR_CCONFIG); + fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n"); + get_mach(); + + users = create_hash(12001); + EXEC SQL DECLARE u_cursor CURSOR FOR + 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 + ORDER BY users_id; + EXEC SQL OPEN u_cursor; + while (1) + { + EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn, + :oa, :op, :hp, :id, :pid, :ptype, :status; + if (sqlca.sqlcode) + break; + strtrim(login); + dequote(fullname); + dequote(nn); + dequote(oa); + dequote(op); + dequote(hp); + dequote(shell); + u = malloc(sizeof(struct user)); + strcpy(u->name, login); + u->lists = NULL; + hash_store(users, id, u); + if (status == 1) + { + 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\t%s %s \"POP %s %s\"\n", + login, HCLASS, HTYPE, mach, login); + } } - fix_file(poutf); - fix_file(uoutf); - fix_file(boutf); - return(1); + if (sqlca.sqlcode < 0) + db_error(sqlca.sqlcode); + EXEC SQL CLOSE u_cursor; + EXEC SQL COMMIT; + + if (fclose(pout) || fclose(uout) || fclose(bout)) + { + fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n"); + exit(MR_CCONFIG); + } + fix_file(poutf); + fix_file(uoutf); + fix_file(boutf); + return 1; } -do_groups() +int do_groups(void) { - FILE *iout, *gout, *lout; - char ioutf[64], goutf[64], loutf[64], buf[2048], *l; - struct hash *groups; - register struct bucket *b, **p; - struct grp *g; - struct user *u; - struct stat isb, gsb, lsb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int gid, id, lid, flag1, flag2, flag3, len; - EXEC SQL END DECLARE SECTION; - - /* open files */ - sprintf(ioutf, "%s/gid.db", hesiod_dir); - sprintf(goutf, "%s/group.db", hesiod_dir); - sprintf(loutf, "%s/grplist.db", hesiod_dir); - - if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) { - ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime)); - if (ModDiff (&flag1, "users", ftime) || - ModDiff (&flag2, "list", ftime) || - ModDiff (&flag3, "imembers", ftime)) - exit (MR_DATE); - if (flag1 < 0 && flag2 < 0 && flag3 < 0) { - fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(buf, "%s~", ioutf); - iout = fopen(buf, "w"); - if (!iout) { - perror("cannot open gid.db for write"); - exit(MR_OCONFIG); - } - sprintf(buf, "%s~", goutf); - gout = fopen(buf, "w"); - if (!gout) { - perror("cannot open group.db for write"); - exit(MR_OCONFIG); - } - sprintf(buf, "%s~", loutf); - lout = fopen(buf, "w"); - if (!lout) { - perror("cannot open grplist.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building gid.db, group.db, and grplist.db\n"); - - /* make space for group list */ - groups = create_hash(15001); - - /* The following WHENEVER is declarative, not executed, - * and applies for the remainder of this file only. - */ - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - EXEC SQL DECLARE l_cursor CURSOR FOR - SELECT name, gid, list_id - FROM list - WHERE grouplist != 0 AND active != 0 - ORDER BY list_id; - EXEC SQL OPEN l_cursor; - while (1) { - EXEC SQL FETCH l_cursor INTO :name, :gid, :lid; - if (sqlca.sqlcode != 0) break; - strtrim(name); - sprintf(buf, "%s:%d", name, gid); - hash_store(groups, lid, strsave(buf)); - 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; - - fflush(iout); - fflush(gout); - - /* now do grplists */ - if (users == NULL) { - users = create_hash(12001); - EXEC SQL DECLARE u_cursor2 CURSOR FOR - SELECT users_id, login - FROM users - WHERE status = 1 - ORDER BY users_id; - EXEC SQL OPEN u_cursor2; - while (1) { - EXEC SQL FETCH u_cursor2 INTO :id, :name; - if (sqlca.sqlcode != 0) break; - u = (struct user *) malloc(sizeof(struct user)); - strcpy(u->name, strtrim(name)); - u->lists = NULL; - hash_store(users, id, u); + FILE *iout, *gout, *lout; + char ioutf[64], goutf[64], loutf[64], buf[2048], *l; + struct hash *groups; + register struct bucket *b, **p; + struct grp *g; + struct user *u; + struct stat isb, gsb, lsb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int gid, id, lid, flag1, flag2, flag3, len; + EXEC SQL END DECLARE SECTION; + + /* open files */ + sprintf(ioutf, "%s/gid.db", hesiod_dir); + sprintf(goutf, "%s/group.db", hesiod_dir); + sprintf(loutf, "%s/grplist.db", hesiod_dir); + + if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && + stat(loutf, &lsb) == 0) + { + ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime)); + if (ModDiff (&flag1, "users", ftime) || + ModDiff (&flag2, "list", ftime) || + ModDiff (&flag3, "imembers", ftime)) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0 && flag3 < 0) + { + fprintf(stderr, "Files gid.db, group.db and grplist.db " + "do not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(buf, "%s~", ioutf); + iout = fopen(buf, "w"); + if (!iout) + { + perror("cannot open gid.db for write"); + exit(MR_OCONFIG); + } + sprintf(buf, "%s~", goutf); + gout = fopen(buf, "w"); + if (!gout) + { + perror("cannot open group.db for write"); + exit(MR_OCONFIG); + } + sprintf(buf, "%s~", loutf); + lout = fopen(buf, "w"); + if (!lout) + { + perror("cannot open grplist.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building gid.db, group.db, and grplist.db\n"); + + /* make space for group list */ + groups = create_hash(15001); + + /* The following WHENEVER is declarative, not executed, + * and applies for the remainder of this file only. + */ + EXEC SQL WHENEVER SQLERROR GOTO sqlerr; + + EXEC SQL DECLARE l_cursor CURSOR FOR + SELECT name, gid, list_id + FROM list + WHERE grouplist != 0 AND active != 0 + ORDER BY list_id; + EXEC SQL OPEN l_cursor; + while (1) + { + EXEC SQL FETCH l_cursor INTO :name, :gid, :lid; + if (sqlca.sqlcode) + break; + strtrim(name); + sprintf(buf, "%s:%d", name, gid); + hash_store(groups, lid, strsave(buf)); + 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; + + fflush(iout); + fflush(gout); + + /* now do grplists */ + if (!users) + { + users = create_hash(12001); + EXEC SQL DECLARE u_cursor2 CURSOR FOR + SELECT users_id, login + FROM users + WHERE status = 1 + ORDER BY users_id; + EXEC SQL OPEN u_cursor2; + while (1) + { + EXEC SQL FETCH u_cursor2 INTO :id, :name; + if (sqlca.sqlcode) + break; + u = malloc(sizeof(struct user)); + strcpy(u->name, strtrim(name)); + u->lists = NULL; + hash_store(users, id, u); } - EXEC SQL CLOSE u_cursor2; - } - - EXEC SQL DECLARE i_cursor CURSOR FOR - SELECT list_id, member_id - FROM imembers - WHERE member_type = 'USER' - ORDER BY list_id; - EXEC SQL OPEN i_cursor; - while (1) { - EXEC SQL FETCH i_cursor INTO :lid, :id; - if (sqlca.sqlcode != 0) break; - if (((l = hash_lookup(groups, lid)) != NULL) && - (u = (struct user *) hash_lookup(users, id))) { - g = (struct grp *) malloc(sizeof(struct grp)); - g->next = u->lists; - u->lists = g; - g->lid = l; + EXEC SQL CLOSE u_cursor2; + } + + EXEC SQL DECLARE i_cursor CURSOR FOR + SELECT list_id, member_id + FROM imembers + WHERE member_type = 'USER' + ORDER BY list_id; + EXEC SQL OPEN i_cursor; + while (1) + { + EXEC SQL FETCH i_cursor INTO :lid, :id; + if (sqlca.sqlcode) + break; + if ((l = hash_lookup(groups, lid)) && + (u = (struct user *) hash_lookup(users, id))) + { + g = malloc(sizeof(struct grp)); + g->next = u->lists; + u->lists = g; + g->lid = l; } } - EXEC SQL CLOSE i_cursor; - - EXEC SQL COMMIT; - - 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\t%s %s \"", - ((struct user *)b->data)->name, HCLASS, HTYPE); - len = 0; - for (; g; g = g->next) { - if (len + strlen(g->lid) + 1 < MAXHESSIZE) { - fputs(g->lid, lout); - if (g->next) - putc(':', lout); - len += strlen(g->lid) + 1; - } else { - com_err(whoami, 0, "truncated grp list for user %s", - ((struct user *)b->data)->name); - break; + EXEC SQL CLOSE i_cursor; + + EXEC SQL COMMIT; + + 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)) + continue; + 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) + { + fputs(g->lid, lout); + if (g->next) + putc(':', lout); + len += strlen(g->lid) + 1; + } + else + { + com_err(whoami, 0, "truncated grp list for user %s", + ((struct user *)b->data)->name); + break; } } - fputs("\"\n", lout); + fputs("\"\n", lout); } } - if (fclose(iout) || fclose(gout) || fclose(lout)) { - fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n"); - exit(MR_CCONFIG); + if (fclose(iout) || fclose(gout) || fclose(lout)) + { + fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n"); + exit(MR_CCONFIG); } - fix_file(ioutf); - fix_file(goutf); - fix_file(loutf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + fix_file(ioutf); + fix_file(goutf); + fix_file(loutf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } -do_filsys() +int do_filsys(void) { - FILE *out; - char outf[64], outft[64], *mach, *group; - register char *p; - struct stat sb; - time_t ftime; - struct save_queue *sq, *sq2, *sq_create(); - EXEC SQL BEGIN DECLARE SECTION; - char name[33], type[9], loc[81], access[2], mount[33], trans[257]; - char comments[65]; - int flag1, flag2, flag3, flag4, id, fid; - EXEC SQL END DECLARE SECTION; - - sprintf(outf, "%s/filsys.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - - if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE); - if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE); - if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE); - if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE); - - if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) { - fprintf(stderr, "File filsys.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open filsys.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building filsys.db\n"); - get_mach(); - sq = sq_create(); - sq2 = sq_create(); - - EXEC SQL DECLARE f_cursor CURSOR FOR - SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id - FROM filesys - ORDER BY filsys_id; - EXEC SQL OPEN f_cursor; - while (1) { - EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access, - :mount, :comments, :fid; - if (sqlca.sqlcode != 0) break; - strtrim(type); - if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) { - if (mach = hash_lookup(machines, id)) { - 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)); + FILE *out; + char outf[64], outft[64], *mach, *group; + register char *p; + struct stat sb; + time_t ftime; + struct save_queue *sq, *sq2, *sq_create(); + EXEC SQL BEGIN DECLARE SECTION; + char name[33], type[9], loc[81], access[2], mount[33], trans[257]; + char comments[65]; + int flag1, flag2, flag3, flag4, id, fid; + EXEC SQL END DECLARE SECTION; + + sprintf(outf, "%s/filsys.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + + if (ModDiff(&flag1, "filesys", ftime)) + exit(MR_DATE); + if (ModDiff(&flag2, "machine", ftime)) + exit(MR_DATE); + if (ModDiff(&flag3, "alias", ftime)) + exit(MR_DATE); + if (ModDiff(&flag4, "fsgroup", ftime)) + exit(MR_DATE); + + if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) + { + fprintf(stderr, "File filsys.db does not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open filsys.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building filsys.db\n"); + get_mach(); + sq = sq_create(); + sq2 = sq_create(); + + EXEC SQL DECLARE f_cursor CURSOR FOR + SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id + FROM filesys + ORDER BY filsys_id; + EXEC SQL OPEN f_cursor; + while (1) + { + EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access, + :mount, :comments, :fid; + if (sqlca.sqlcode) + break; + strtrim(type); + if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) + { + if (mach = hash_lookup(machines, id)) + { + 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\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\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)); - } else if (!strcmp(type, "MUL")) { - sprintf(trans, "%s:%d", strtrim(name), fid); - sq_save_data(sq2, strsave(trans)); + } + else if (!strcmp(type, "AFS")) + { + 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\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)); + } + else if (!strcmp(type, "MUL")) + { + sprintf(trans, "%s:%d", strtrim(name), fid); + sq_save_data(sq2, strsave(trans)); } } - EXEC SQL CLOSE f_cursor; - - while (sq_get_data(sq, &group)) { - 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.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++) { - 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\t%s %s \"%s %s %s %s %s %d\"\n", - group, HCLASS, HTYPE, type, strtrim(loc), mach, - strtrim(access), strtrim(mount), flag1); + EXEC SQL CLOSE f_cursor; + + while (sq_get_data(sq, &group)) + { + 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.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++) + { + EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount, + :comments, :name, :trans; + if (sqlca.sqlcode) + break; + strtrim(type); + if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) + { + if (mach = hash_lookup(machines, id)) + { + 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\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\t%s %s \"ERR %s\"\n", - group, HCLASS, HTYPE, strtrim(comments)); + } + else if (!strcmp(type, "AFS")) + { + 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\t%s %s \"ERR %s\"\n", + group, HCLASS, HTYPE, strtrim(comments)); } } - EXEC SQL CLOSE f_cursor2; - free(group); - } - sq_destroy(sq); - - while (sq_get_data(sq2, &group)) { - 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 - WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid - ORDER BY key, label; - EXEC SQL OPEN f_cursor3; - while (1) { - EXEC SQL FETCH f_cursor3 INTO :name, :trans; - if (sqlca.sqlcode != 0) break; - fprintf(out, " %s", strtrim(name)); + EXEC SQL CLOSE f_cursor2; + free(group); + } + sq_destroy(sq); + + while (sq_get_data(sq2, &group)) + { + 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 + WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid + ORDER BY key, label; + EXEC SQL OPEN f_cursor3; + while (1) + { + EXEC SQL FETCH f_cursor3 INTO :name, :trans; + if (sqlca.sqlcode) + break; + fprintf(out, " %s", strtrim(name)); } - EXEC SQL CLOSE f_cursor3; - fprintf(out, "\"\n"); - free(group); - } - sq_destroy(sq2); - - EXEC SQL DECLARE a_cursor CURSOR FOR - SELECT name, trans - FROM alias - WHERE type = 'FILESYS'; - EXEC SQL OPEN a_cursor; - while (1) { - EXEC SQL FETCH a_cursor INTO :name, :trans; - if (sqlca.sqlcode != 0) break; - fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n", - strtrim(name), HCLASS, strtrim(trans)); - } - EXEC SQL CLOSE a_cursor; - - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of filsys.db\n"); - exit(MR_CCONFIG); - } - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + EXEC SQL CLOSE f_cursor3; + fprintf(out, "\"\n"); + free(group); + } + sq_destroy(sq2); + + EXEC SQL DECLARE a_cursor CURSOR FOR + SELECT name, trans + FROM alias + WHERE type = 'FILESYS'; + EXEC SQL OPEN a_cursor; + while (1) + { + EXEC SQL FETCH a_cursor INTO :name, :trans; + if (sqlca.sqlcode) + break; + fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n", + strtrim(name), HCLASS, strtrim(trans)); + } + EXEC SQL CLOSE a_cursor; + + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of filsys.db\n"); + exit(MR_CCONFIG); + } + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } @@ -559,464 +628,526 @@ int setsize; /* = howmany(setbits, NSETBITS) */ typedef long set_mask; #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */ #ifndef howmany -#define howmany(x, y) (((x)+((y)-1))/(y)) +#define howmany(x, y) (((x) + ((y) - 1)) / (y)) #endif #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS))) #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) memset((char *)(p), 0, setsize * sizeof(set_mask)) -#define SET_CMP(p1, p2) (memcmp((p1), (p2), setsize * sizeof(set_mask))) +#define SET_CREATE() (malloc(setsize * sizeof(set_mask))) +#define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask)) +#define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask))) -int nbitsset(set) -set_mask *set; +int nbitsset(set_mask *set) { - int i, ret; - ret = 0; - for (i = 0; i < setsize * NSETBITS; i++) + int i, ret; + ret = 0; + for (i = 0; i < setsize * NSETBITS; i++) + { if (SET_ISSET(i, set)) ret++; - return(ret); + } + return ret; } -do_cluster() +int do_cluster(void) { - FILE *out; - char outf[64], outft[64], *mach, machbuf[41], *p; - struct stat sb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id; - char name[41], label2[17], data[33]; - EXEC SQL END DECLARE SECTION; - set_mask **machs, *ms, *ps; - int oneclu; - - sprintf(outf, "%s/cluster.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - if (ModDiff (&flag1, "clusters", ftime) - || ModDiff (&flag2, "machine", ftime) - || ModDiff (&flag3, "mcmap", ftime) - || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE); - if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) { - fprintf(stderr, "File cluster.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open cluster.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building cluster.db\n"); - get_mach(); - - 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 **)); - memset(machs, 0, (maxmach + 1) * sizeof(int)); - - EXEC SQL DECLARE p_cursor CURSOR FOR - SELECT mach_id, clu_id - FROM mcmap - ORDER BY mach_id; - EXEC SQL OPEN p_cursor; - while (1) { - EXEC SQL FETCH p_cursor INTO :mid, :cid; - if (sqlca.sqlcode != 0) break; - if (!(ms = machs[mid])) { - ms = machs[mid] = SET_CREATE(); - SET_ZERO(ms); + FILE *out; + char outf[64], outft[64], *mach, machbuf[41], *p; + struct stat sb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id; + char name[41], label2[17], data[33]; + EXEC SQL END DECLARE SECTION; + set_mask **machs, *ms, *ps; + int oneclu; + + sprintf(outf, "%s/cluster.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + if (ModDiff (&flag1, "clusters", ftime) + || ModDiff (&flag2, "machine", ftime) + || ModDiff (&flag3, "mcmap", ftime) + || ModDiff (&flag4, "svc", ftime)) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) + { + fprintf(stderr, "File cluster.db does not need to be rebuilt.\n"); + return 0; } - SET_SET(cid, ms); - } - EXEC SQL CLOSE p_cursor; - - for (mid = 1; mid < maxmach; mid++) { - if (!machs[mid]) - continue; - ms = machs[mid]; - if (nbitsset(ms) > 1) { - oneclu = 0; - for (cid = 1; cid < maxclu; cid++) { - if (SET_ISSET(cid, ms)) { - EXEC SQL DECLARE d_cursor CURSOR FOR - SELECT serv_label, serv_cluster - FROM svc - WHERE clu_id = :cid; - EXEC SQL OPEN d_cursor; - while (1) { - EXEC SQL FETCH d_cursor INTO :label2, :data; - if (sqlca.sqlcode != 0) break; - strtrim(label2); - strtrim(data); - fprintf(out, - "mrinternal-%d.cluster\t%s %s \"%s %s\"\n", - mid, HCLASS, HTYPE, label2, data); + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open cluster.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building cluster.db\n"); + get_mach(); + + 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 = malloc((maxmach + 1) * sizeof(set_mask **)); + memset(machs, 0, (maxmach + 1) * sizeof(int)); + + EXEC SQL DECLARE p_cursor CURSOR FOR + SELECT mach_id, clu_id + FROM mcmap + ORDER BY mach_id; + EXEC SQL OPEN p_cursor; + while (1) + { + EXEC SQL FETCH p_cursor INTO :mid, :cid; + if (sqlca.sqlcode) + break; + if (!(ms = machs[mid])) + { + ms = machs[mid] = SET_CREATE(); + SET_ZERO(ms); + } + SET_SET(cid, ms); + } + EXEC SQL CLOSE p_cursor; + + for (mid = 1; mid < maxmach; mid++) + { + if (!machs[mid]) + continue; + ms = machs[mid]; + if (nbitsset(ms) > 1) + { + oneclu = 0; + for (cid = 1; cid < maxclu; cid++) + { + if (SET_ISSET(cid, ms)) + { + EXEC SQL DECLARE d_cursor CURSOR FOR + SELECT serv_label, serv_cluster + FROM svc + WHERE clu_id = :cid; + EXEC SQL OPEN d_cursor; + while (1) + { + EXEC SQL FETCH d_cursor INTO :label2, :data; + if (sqlca.sqlcode) + break; + strtrim(label2); + strtrim(data); + fprintf(out, "mrinternal-%d.cluster\t%s %s \"%s %s\"\n", + mid, HCLASS, HTYPE, label2, data); } - EXEC SQL CLOSE d_cursor; + EXEC SQL CLOSE d_cursor; } } - } else { - oneclu = 1; - for (cid = 1; cid < maxclu; cid++) - if (SET_ISSET(cid, ms)) break; - - EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid; - strtrim(name); + } + else + { + oneclu = 1; + for (cid = 1; cid < maxclu; cid++) + if (SET_ISSET(cid, ms)) + break; + + EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid; + strtrim(name); } - if (mach = hash_lookup(machines, mid)) { - for (p = machbuf; *mach && *mach != '.'; mach++) - *p++ = *mach; - *p = 0; - if (oneclu) + if ((mach = hash_lookup(machines, mid))) + { + for (p = machbuf; *mach && *mach != '.'; mach++) + *p++ = *mach; + *p = '\0'; + if (oneclu) + { fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", machbuf, HCLASS, name); - else + } + else + { 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)) { - free(ps); - machs[id] = NULL; - if (mach = hash_lookup(machines, id)) { - for (p = machbuf; *mach && *mach != '.'; mach++) - *p++ = *mach; - *p = 0; - if (oneclu) + for (id = mid + 1; id < maxmach; id++) + { + if ((ps = machs[id]) && !SET_CMP(ms, ps)) + { + free(ps); + machs[id] = NULL; + if ((mach = hash_lookup(machines, id))) + { + for (p = machbuf; *mach && *mach != '.'; mach++) + *p++ = *mach; + *p = '\0'; + if (oneclu) + { fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", machbuf, HCLASS, name); - else + } + else + { fprintf(out, "%s.cluster\t%s CNAME mrinternal-%d.cluster\n", machbuf, HCLASS, mid); + } } } } - free(ms); - machs[mid] = NULL; - } - - EXEC SQL DECLARE d_cursor2 CURSOR FOR - SELECT c.name, d.serv_label, d.serv_cluster - FROM svc d, clusters c - WHERE c.clu_id = d.clu_id; - EXEC SQL OPEN d_cursor2; - while (1) { - EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data; - if (sqlca.sqlcode != 0) break; - strtrim(name); - strtrim(label2); - strtrim(data); - fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n", - name, HCLASS, HTYPE, label2, data); - } - free(machs); - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of cluster.db\n"); - exit(MR_CCONFIG); - } - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + free(ms); + machs[mid] = NULL; + } + + EXEC SQL DECLARE d_cursor2 CURSOR FOR + SELECT c.name, d.serv_label, d.serv_cluster + FROM svc d, clusters c + WHERE c.clu_id = d.clu_id; + EXEC SQL OPEN d_cursor2; + while (1) + { + EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data; + if (sqlca.sqlcode) + break; + strtrim(name); + strtrim(label2); + strtrim(data); + fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n", + name, HCLASS, HTYPE, label2, data); + } + free(machs); + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of cluster.db\n"); + exit(MR_CCONFIG); + } + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } -do_printcap() +int do_printcap(void) { - FILE *out; - char outf[64], outft[64]; - struct stat sb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - char name[17], rp[17], sd[33]; - int flag1, flag2, ka, pc, rm, rq; - EXEC SQL END DECLARE SECTION; - - sprintf(outf, "%s/printcap.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - if (ModDiff (&flag1, "printcap", ftime) - || ModDiff (&flag2, "machine", ftime)) - exit (MR_DATE); - if (flag1 < 0 && flag2 < 0) { - fprintf(stderr, "File printcap.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open printcap.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building printcap.db\n"); - get_mach(); - - EXEC SQL DECLARE p_cursor2 CURSOR FOR - SELECT name, rp, dir, mach_id, auth, price, quotaserver - FROM printcap; - EXEC SQL OPEN p_cursor2; - 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\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; - - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of pcap.db\n"); - exit(MR_CCONFIG); - } - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); - } + FILE *out; + char outf[64], outft[64]; + struct stat sb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + char name[17], rp[17], sd[33]; + int flag1, flag2, ka, pc, rm, rq; + EXEC SQL END DECLARE SECTION; + + sprintf(outf, "%s/printcap.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + if (ModDiff (&flag1, "printcap", ftime) + || ModDiff (&flag2, "machine", ftime)) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0) + { + fprintf(stderr, "File printcap.db does not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open printcap.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building printcap.db\n"); + get_mach(); + + EXEC SQL DECLARE p_cursor2 CURSOR FOR + SELECT name, rp, dir, mach_id, auth, price, quotaserver + FROM printcap; + EXEC SQL OPEN p_cursor2; + while (1) + { + EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq; + if (sqlca.sqlcode) + break; + if (!hash_lookup(machines, rm)) + continue; + strtrim(name); + strtrim(rp); + strtrim(sd); + 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; + + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of pcap.db\n"); + exit(MR_CCONFIG); + } + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; +} -do_palladium() +int do_palladium(void) { - FILE *out; - char outf[64], outft[64]; - struct stat sb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - char name[33], trans[129]; - int flag, flag1, identifier, rm; - EXEC SQL END DECLARE SECTION; - - sprintf(outf, "%s/palladium.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - if ((ModDiff (&flag, "palladium", ftime)) || - (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE); - if (flag < 0 && flag1 < 0) { - fprintf(stderr, "File palladium.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open palladium.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building palladium.db\n"); - get_mach(); - - EXEC SQL DECLARE p_cursor3 CURSOR FOR - SELECT name, identifier, mach_id - FROM palladium; - EXEC SQL OPEN p_cursor3; - while (1) { - 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\t%s %s \"%s %d %s interface directory\"\n", - name, HCLASS, HTYPE, hash_lookup(machines, rm), identifier, - name); - } - EXEC SQL CLOSE p_cursor3; - - EXEC SQL DECLARE a_cursor2 CURSOR FOR - SELECT name, trans - FROM alias - WHERE type = 'PALLADIUM'; - EXEC SQL OPEN a_cursor2; - while (1) { - EXEC SQL FETCH a_cursor2 INTO :name, :trans; - if (sqlca.sqlcode != 0) break; - strtrim(name); - strtrim(trans); - fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE, - trans); - } - EXEC SQL CLOSE a_cursor2; - - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of palladium.db\n"); - exit(MR_CCONFIG); - } - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + FILE *out; + char outf[64], outft[64]; + struct stat sb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + char name[33], trans[129]; + int flag, flag1, identifier, rm; + EXEC SQL END DECLARE SECTION; + + sprintf(outf, "%s/palladium.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + if ((ModDiff (&flag, "palladium", ftime)) || + (ModDiff (&flag1, "alias", ftime))) + exit(MR_DATE); + if (flag < 0 && flag1 < 0) + { + fprintf(stderr, "File palladium.db does not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open palladium.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building palladium.db\n"); + get_mach(); + + EXEC SQL DECLARE p_cursor3 CURSOR FOR + SELECT name, identifier, mach_id + FROM palladium; + EXEC SQL OPEN p_cursor3; + while (1) + { + EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm; + if (sqlca.sqlcode) + break; + if (!hash_lookup(machines, rm)) + break; + strtrim(name); + fprintf(out, "%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; + + EXEC SQL DECLARE a_cursor2 CURSOR FOR + SELECT name, trans + FROM alias + WHERE type = 'PALLADIUM'; + EXEC SQL OPEN a_cursor2; + while (1) + { + EXEC SQL FETCH a_cursor2 INTO :name, :trans; + if (sqlca.sqlcode) + break; + strtrim(name); + strtrim(trans); + fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE, trans); + } + EXEC SQL CLOSE a_cursor2; + + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of palladium.db\n"); + exit(MR_CCONFIG); + } + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } -do_sloc() +int do_sloc(void) { - FILE *out; - char outf[64], outft[64], *mach; - struct stat sb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - char service[17]; - int flag1, flag2, id; - EXEC SQL END DECLARE SECTION; - - sprintf(outf, "%s/sloc.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - if ((ModDiff (&flag1, "serverhosts", ftime)) || - (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE); - if (flag1 < 0 && flag2 < 0) { - fprintf(stderr, "File sloc.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open sloc.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building sloc.db\n"); - get_mach(); - - EXEC SQL DECLARE s_cursor CURSOR FOR - SELECT DISTINCT service, mach_id - FROM serverhosts - ORDER BY service; - EXEC SQL OPEN s_cursor; - while (1) { - EXEC SQL FETCH s_cursor INTO :service, :id; - if (sqlca.sqlcode != 0) break; - strtrim(service); - if (mach = hash_lookup(machines, id)) - fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach); - } - EXEC SQL CLOSE s_cursor; - - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of sloc.db\n"); - exit(MR_CCONFIG); - } - - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + FILE *out; + char outf[64], outft[64], *mach; + struct stat sb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + char service[17]; + int flag1, flag2, id; + EXEC SQL END DECLARE SECTION; + + sprintf(outf, "%s/sloc.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + if ((ModDiff (&flag1, "serverhosts", ftime)) || + (ModDiff (&flag2, "machine", ftime))) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0) + { + fprintf(stderr, "File sloc.db does not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open sloc.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building sloc.db\n"); + get_mach(); + + EXEC SQL DECLARE s_cursor CURSOR FOR + SELECT DISTINCT service, mach_id + FROM serverhosts + ORDER BY service; + EXEC SQL OPEN s_cursor; + while (1) + { + EXEC SQL FETCH s_cursor INTO :service, :id; + if (sqlca.sqlcode) + break; + strtrim(service); + if (mach = hash_lookup(machines, id)) + fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach); + } + EXEC SQL CLOSE s_cursor; + + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of sloc.db\n"); + exit(MR_CCONFIG); + } + + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } -do_service() +int do_service(void) { - FILE *out; - char outf[64], outft[64]; - struct stat sb; - time_t ftime; - EXEC SQL BEGIN DECLARE SECTION; - char service[33], protocol[9], altserv[129]; - int port, flag1; - EXEC SQL END DECLARE SECTION; - - sprintf(outf, "%s/service.db", hesiod_dir); - - if (stat(outf, &sb) == 0) { - ftime = sb.st_mtime; - if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE); - if (flag1 < 0) { - fprintf(stderr, "File service.db does not need to be rebuilt.\n"); - return(0); - } - } - - sprintf(outft, "%s~", outf); - out = fopen(outft, "w"); - if (!out) { - perror("cannot open service.db for write"); - exit(MR_OCONFIG); - } - - fprintf(stderr, "Building service.db\n"); - - EXEC SQL DECLARE s_cursor2 CURSOR FOR - SELECT name, protocol, port - FROM services; - EXEC SQL OPEN s_cursor2; - while (1) { - EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port; - if (sqlca.sqlcode != 0) break; - lowercase(protocol); /* Convert protocol to lowercase */ - strtrim(service); - strtrim(protocol); - fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n", - service, HCLASS, HTYPE, service, protocol, port); - } - EXEC SQL CLOSE s_cursor2; - - EXEC SQL DECLARE a_cursor3 CURSOR FOR - SELECT name, trans - FROM alias - WHERE type = 'SERVICE'; - EXEC SQL OPEN a_cursor3; - while (1) { - EXEC SQL FETCH a_cursor3 INTO :service, :altserv; - if (sqlca.sqlcode != 0) break; - strtrim(service); - strtrim(altserv); - fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS, - altserv); - } - EXEC SQL CLOSE a_cursor3; - - EXEC SQL COMMIT; - - if (fclose(out)) { - fprintf(stderr, "Unsuccessful close of service.db\n"); - exit(MR_CCONFIG); - } - fix_file(outf); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - return(0); + FILE *out; + char outf[64], outft[64]; + struct stat sb; + time_t ftime; + EXEC SQL BEGIN DECLARE SECTION; + char service[33], protocol[9], altserv[129]; + int port, flag1; + EXEC SQL END DECLARE SECTION; + + sprintf(outf, "%s/service.db", hesiod_dir); + + if (stat(outf, &sb) == 0) + { + ftime = sb.st_mtime; + if (ModDiff (&flag1, "services", ftime)) + exit(MR_DATE); + if (flag1 < 0) + { + fprintf(stderr, "File service.db does not need to be rebuilt.\n"); + return 0; + } + } + + sprintf(outft, "%s~", outf); + out = fopen(outft, "w"); + if (!out) + { + perror("cannot open service.db for write"); + exit(MR_OCONFIG); + } + + fprintf(stderr, "Building service.db\n"); + + EXEC SQL DECLARE s_cursor2 CURSOR FOR + SELECT name, protocol, port + FROM services; + EXEC SQL OPEN s_cursor2; + while (1) + { + EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port; + if (sqlca.sqlcode) + break; + lowercase(protocol); /* Convert protocol to lowercase */ + strtrim(service); + strtrim(protocol); + fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n", + service, HCLASS, HTYPE, service, protocol, port); + } + EXEC SQL CLOSE s_cursor2; + + EXEC SQL DECLARE a_cursor3 CURSOR FOR + SELECT name, trans + FROM alias + WHERE type = 'SERVICE'; + EXEC SQL OPEN a_cursor3; + while (1) + { + EXEC SQL FETCH a_cursor3 INTO :service, :altserv; + if (sqlca.sqlcode) + break; + strtrim(service); + strtrim(altserv); + fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS, + altserv); + } + EXEC SQL CLOSE a_cursor3; + + EXEC SQL COMMIT; + + if (fclose(out)) + { + fprintf(stderr, "Unsuccessful close of service.db\n"); + exit(MR_CCONFIG); + } + fix_file(outf); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + return 0; } diff --git a/gen/hesiod.sh b/gen/hesiod.sh index 1e9cdeeb..733fdfb4 100644 --- a/gen/hesiod.sh +++ b/gen/hesiod.sh @@ -1,5 +1,5 @@ #!/bin/csh -f -# This script performs updates of hesiod files on hesiod servers. +# This script performs updates of hesiod files on hesiod servers. # $Header$ set path=(/etc /bin /usr/bin /usr/etc /usr/athena/etc) @@ -42,7 +42,7 @@ endif if (! -r $TARFILE) exit $MR_MISSINGFILE # Empty the tar file one file at a time and move each file to the -# appropriate place only if it is not zero length. +# appropriate place only if it is not zero length. cd $SRC_DIR foreach file (`tar tf $TARFILE | awk '{print $1}' | sed 's;/$;;'`) if (. == $file) continue diff --git a/gen/hosts.pc b/gen/hosts.pc index 742c7f6a..ecd35adc 100644 --- a/gen/hosts.pc +++ b/gen/hosts.pc @@ -19,129 +19,145 @@ extern int errno; char *whoami = "hosts.gen"; char *db = "moira/moira"; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *out = stdout; - char *outf = NULL, outft[64], *p, buf[256]; - struct stat sb; - struct timeval now; - int flag1, flag2, i; - struct hash *aliases; - EXEC SQL BEGIN DECLARE SECTION; - int id; - char name[65], vendor[33], model[33], os[33], addr[17]; - EXEC SQL END DECLARE SECTION; + FILE *out = stdout; + char *outf = NULL, outft[64], *p, buf[256]; + struct stat sb; + struct timeval now; + int flag1, flag2, i; + struct hash *aliases; + EXEC SQL BEGIN DECLARE SECTION; + int id; + char name[65], vendor[33], model[33], os[33], addr[17]; + EXEC SQL END DECLARE SECTION; - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db; - 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); + 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); + outf = argv[1]; + sprintf(outft, "%s~", outf); + if (!(out = fopen(outft, "w"))) + { + 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; } + 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 WHENEVER SQLERROR GOTO sqlerr; + gettimeofday(&now, NULL); - gettimeofday(&now, NULL); - - fprintf(out, "; MIT Network Host Table\n;\n"); - fprintf(out, "; \t%cAuthor: $\n", '$'); - fprintf(out, "; \t%cDate: $\n", '$'); - fprintf(out, "; \t%cRevision: $\n;\n", '$'); - fprintf(out, "; Host table generated by Moira at %s;\n", - ctime(&now.tv_sec)); + fprintf(out, "; MIT Network Host Table\n;\n"); + fprintf(out, "; \t%cAuthor: $\n", '$'); + fprintf(out, "; \t%cDate: $\n", '$'); + fprintf(out, "; \t%cRevision: $\n;\n", '$'); + fprintf(out, "; Host table generated by Moira 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 (*strtrim(name) == 0) continue; - if ((i = strlen(name)) < 9 || strcmp(&name[i-8], ".MIT.EDU")) { - fprintf(stderr, "Name %s not in MIT domain\n", name); - continue; - } else { - name[i-8] = 0; + 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) + break; + if (id == 0) + continue; + if (!*strtrim(name)) + continue; + if ((i = strlen(name)) < 9 || strcmp(&name[i - 8], ".MIT.EDU")) + { + fprintf(stderr, "Name %s not in MIT domain\n", name); + 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)); + else + name[i - 8] = 0; + 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 DECLARE x CURSOR FOR SELECT - name, mach_id, vendor, model, os, address - FROM machine WHERE status=1 ORDER BY address; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :name, :id, :vendor, :model, :os, :addr; - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - if (*strtrim(name) == 0) continue; - if ((i = strlen(name)) < 9 || strcmp(&name[i-8], ".MIT.EDU")) { - continue; - } else { - name[i-8] = 0; + EXEC SQL DECLARE x CURSOR FOR SELECT + name, mach_id, vendor, model, os, address + FROM machine WHERE status = 1 ORDER BY address; + EXEC SQL OPEN x; + while (1) + { + EXEC SQL FETCH x INTO :name, :id, :vendor, :model, :os, :addr; + if (sqlca.sqlcode) + break; + if (id == 0) + continue; + if (!*strtrim(name)) + continue; + if ((i = strlen(name)) < 9 || strcmp(&name[i - 8], ".MIT.EDU")) + continue; + else + name[i - 8] = 0; + strtrim(vendor); + strtrim(model); + strtrim(os); + strtrim(addr); + if (*addr == 0 || inet_addr(addr) == -1) + continue; + if ((p = hash_lookup(aliases, id))) + sprintf(buf, "%s,%s", name, p); + else + strcpy(buf, name); + fprintf(out, "HOST : %s : %s : ", addr, buf); + if ((*vendor || *model) && *os) + { + if (*vendor && *model) + fprintf(out, "%s/%s : %s :\n", vendor, model, os); + else + fprintf(out, "%s%s : %s :\n", vendor, model, os); } - strtrim(vendor); - strtrim(model); - strtrim(os); - strtrim(addr); - if (*addr == 0 || inet_addr(addr) == -1) - continue; - if (p = hash_lookup(aliases, id)) - sprintf(buf, "%s,%s", name, p); - else - strcpy(buf, name); - fprintf(out, "HOST : %s : %s : ", addr, buf); - if ((*vendor || *model) && *os) { - if (*vendor && *model) - fprintf(out, "%s/%s : %s :\n", vendor, model, os); - else - fprintf(out, "%s%s : %s :\n", vendor, model, os); - } else - fputs("\n", out); + else + fputs("\n", out); } - EXEC SQL CLOSE x; + EXEC SQL CLOSE x; - EXEC SQL COMMIT; + EXEC SQL COMMIT; - fprintf(out, "; End of automatically generated host table\n"); - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); + fprintf(out, "; End of automatically generated host table\n"); + if (fclose(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); + if (outf) + fix_file(outf); + exit(MR_SUCCESS); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/install_dirs b/gen/install_dirs index a5ce77ed..2fd2c78a 100644 --- a/gen/install_dirs +++ b/gen/install_dirs @@ -1,5 +1,5 @@ #!/bin/csh -f -# This script installs new directories on NFS servers. +# This script installs new directories on NFS servers. # The following exit codes are defined and MUST BE CONSISTENT with the # MR error codes the library uses: @@ -35,7 +35,7 @@ while (1) break; else mkdir $tmpdir - # At some point it may be wise to check the status here and + # At some point it may be wise to check the status here and # return a soft failure, but the current protocol doesn't # support this break @@ -44,12 +44,12 @@ while (1) if (! -d $tmpdir) continue chown $uid.$gid $tmpdir - # At some point, we may wish to add a more elegant way of handling - # locker types. The current arrangement allows for easy adding of + # At some point, we may wish to add a more elegant way of handling + # locker types. The current arrangement allows for easy adding of # default actions here. switch ($type) case HOMEDIR: - + # ***** Remove this when /etc/encorce_quota becomes obsolete! # Give this filesystem a 1200K quota setquota $dev $uid 1200 @@ -59,7 +59,7 @@ while (1) (cd $tmpdir; tar xf $USERTAR) if ($status) set WARN chown $uid.$gid $tmpdir $tmpdir/.??* $tmpdir/* - breaksw + breaksw case COURSE: /bin/chmod 775 $tmpdir breaksw diff --git a/gen/install_quotas b/gen/install_quotas index 1825315b..2f2b703f 100644 --- a/gen/install_quotas +++ b/gen/install_quotas @@ -1,17 +1,17 @@ #!/bin/csh -f # -# This script sets the quota for a uid on a filesystem. +# This script sets the quota for a uid on a filesystem. set dev=$1 -# Checking for /etc/enforce_quota is transitional code and should be +# Checking for /etc/enforce_quota is transitional code and should be # removed when the SMS database has an accurate understanding of what # everyone's quotas are. if ( -f /etc/enforce_quota ) then while (1) # set args = $< will NOT work. $< will be treated as a single word set args = `echo $<` - + if (${#args} != 2) break set uid = $args[1] diff --git a/gen/mailhub.pc b/gen/mailhub.pc index f12de554..ff9aa63e 100644 --- a/gen/mailhub.pc +++ b/gen/mailhub.pc @@ -10,8 +10,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -19,8 +21,6 @@ #include EXEC SQL INCLUDE sqlca; - -extern int errno; char *whoami = "mailhub.gen"; char *db = "moira/moira"; char *perm_malloc(); @@ -33,698 +33,715 @@ char *divide = "##############################################################"; #define FALSE 0 #define TRUE (!FALSE) -FILE *out= stdout; - +FILE *out = stdout; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - long tm = time(NULL); - char filename[64], *targetfile; - struct stat sb; - EXEC SQL BEGIN DECLARE SECTION; - int flag; - EXEC SQL END DECLARE SECTION; - - EXEC SQL CONNECT :db; - - 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); + long tm = time(NULL); + char filename[64], *targetfile; + struct stat sb; + EXEC SQL BEGIN DECLARE SECTION; + int flag; + EXEC SQL END DECLARE SECTION; + + EXEC SQL CONNECT :db; + + 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); } } - 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); + targetfile = argv[1]; + sprintf(filename, "%s~", targetfile); + if (!(out = fopen(filename, "w"))) + { + 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); + } + 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); + 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(); + get_info(); - EXEC SQL COMMIT; + EXEC SQL COMMIT; - fprintf(stderr, "Sorting Info\n"); - sort_info(); + fprintf(stderr, "Sorting Info\n"); + sort_info(); - fprintf(stderr, "Dumping information\n"); - do_people(); + fprintf(stderr, "Dumping information\n"); + do_people(); - fprintf(out, "\n%s\n# End of aliases file\n", divide); + fprintf(out, "\n%s\n# End of aliases file\n", divide); - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); + if (fclose(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - if (argc == 2) - fix_file(targetfile); - exit(MR_SUCCESS); + if (argc == 2) + fix_file(targetfile); + exit(MR_SUCCESS); } struct hash *users, *machines, *strings, *lists, *names; struct user { - char *login; - char *first; - char *last; - char mi; - char *pobox; + char *login; + char *first; + char *last; + char mi; + char *pobox; }; struct member { - struct member *next; - char *name; - int list_id; + struct member *next; + char *name; + int list_id; }; struct list { - char *name; - char maillist; - char *description; - char acl_t; - int acl_id; - struct member *m; + char *name; + char maillist; + char *description; + char acl_t; + int acl_id; + struct member *m; }; struct names { - char *name; - struct names *next; - int keep; - int id; + char *name; + struct names *next; + int keep; + int id; }; -get_info() +get_info(void) { - EXEC SQL BEGIN DECLARE SECTION; - int id, pid, bid, cnt, maillistp, acl, mid; - char name[129], type[9], fname[17], mname[17], lname[17], buf[257]; - EXEC SQL END DECLARE SECTION; - char *s; - register struct user *u; - struct list *l, *memberlist; - register struct member *m; - - /* 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; - - cnt = 0; - machines = create_hash(1000); - - EXEC SQL DECLARE m_cursor CURSOR FOR - SELECT mach_id, name - FROM machine - WHERE status=1 - 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 = strchr(name, '.')) - *s = 0; - else - strtrim(name); + EXEC SQL BEGIN DECLARE SECTION; + int id, pid, bid, cnt, maillistp, acl, mid; + char name[129], type[9], fname[17], mname[17], lname[17], buf[257]; + EXEC SQL END DECLARE SECTION; + char *s; + register struct user *u; + struct list *l, *memberlist; + register struct member *m; + + /* 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; + + cnt = 0; + machines = create_hash(1000); + + EXEC SQL DECLARE m_cursor CURSOR FOR + SELECT mach_id, name + FROM machine + WHERE status = 1 + ORDER BY mach_id; + EXEC SQL OPEN m_cursor; + while (1) + { + EXEC SQL FETCH m_cursor INTO :id, :name; + if (sqlca.sqlcode) + break; + if (s = strchr(name, '.')) + *s = '\0'; + else + strtrim(name); #ifdef ATHENA - strcat(name, ".LOCAL"); + strcat(name, ".LOCAL"); #endif - if (hash_store(machines, id, pstrsave(name)) < 0) { - fprintf(stderr, "Out of memory!\n"); - exit(MR_NO_MEM); + if (hash_store(machines, id, pstrsave(name)) < 0) + { + fprintf(stderr, "Out of memory!\n"); + exit(MR_NO_MEM); } - cnt++; + cnt++; } - EXEC SQL CLOSE m_cursor; - - fprintf(stderr, "Loaded %d machines\n", cnt); - - cnt = 0; - strings = create_hash(11001); - - EXEC SQL DECLARE s_cursor CURSOR FOR - 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(strtrim(name))) < 0) { - fprintf(stderr, "Out of memory!\n"); - exit(MR_NO_MEM); + EXEC SQL CLOSE m_cursor; + + fprintf(stderr, "Loaded %d machines\n", cnt); + + cnt = 0; + strings = create_hash(11001); + + EXEC SQL DECLARE s_cursor CURSOR FOR + 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) + break; + if (hash_store(strings, id, pstrsave(strtrim(name))) < 0) + { + fprintf(stderr, "Out of memory!\n"); + exit(MR_NO_MEM); } - cnt++; + cnt++; } - EXEC SQL CLOSE s_cursor; - - fprintf(stderr, "Loaded %d strings\n", cnt); - - cnt = 0; - users = create_hash(13001); - - EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT users_id, login, first, middle, last, potype, pop_id, box_id - FROM users - WHERE status != 3 - ORDER BY users_id; - EXEC SQL OPEN u_cursor; - while (1) { - EXEC SQL FETCH u_cursor INTO :id, :name, :fname, :mname, :lname, - :type, :pid, :bid; - if (sqlca.sqlcode != 0) break; - u = (struct user *) perm_malloc(sizeof(struct user)); - u->login = pstrsave(strtrim(name)); - u->first = pstrsave(strtrim(fname)); - u->last = pstrsave(strtrim(lname)); - if (mname[0] != ' ') - u->mi = mname[0]; - else - u->mi = 0; - - if (type[0] == 'P' && (s = hash_lookup(machines, pid))) { - sprintf(buf, "%s@%s", u->login, s); - u->pobox = pstrsave(buf); - } else if (type[0] == 'S') { - u->pobox = hash_lookup(strings, bid); - } else - u->pobox = (char *) NULL; - if (hash_store(users, id, u) < 0) { - fprintf(stderr, "Out of memory!\n"); - exit(MR_NO_MEM); + EXEC SQL CLOSE s_cursor; + + fprintf(stderr, "Loaded %d strings\n", cnt); + + cnt = 0; + users = create_hash(13001); + + EXEC SQL DECLARE u_cursor CURSOR FOR + SELECT users_id, login, first, middle, last, potype, pop_id, box_id + FROM users + WHERE status != 3 + ORDER BY users_id; + EXEC SQL OPEN u_cursor; + while (1) + { + EXEC SQL FETCH u_cursor INTO :id, :name, :fname, :mname, :lname, + :type, :pid, :bid; + if (sqlca.sqlcode) + break; + u = (struct user *) perm_malloc(sizeof(struct user)); + u->login = pstrsave(strtrim(name)); + u->first = pstrsave(strtrim(fname)); + u->last = pstrsave(strtrim(lname)); + if (mname[0] != ' ') + u->mi = mname[0]; + else + u->mi = 0; + + if (type[0] == 'P' && (s = hash_lookup(machines, pid))) + { + sprintf(buf, "%s@%s", u->login, s); + u->pobox = pstrsave(buf); + } + else if (type[0] == 'S') + u->pobox = hash_lookup(strings, bid); + else + u->pobox = NULL; + if (hash_store(users, id, u) < 0) + { + fprintf(stderr, "Out of memory!\n"); + exit(MR_NO_MEM); } - cnt++; + cnt++; } - EXEC SQL CLOSE u_cursor; - fprintf(stderr, "Loaded %d users\n", cnt); - - cnt = 0; - lists = create_hash(15000); - - 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 *) perm_malloc(sizeof(struct list)); - l->name = pstrsave(strtrim(name)); - l->maillist = maillistp; - l->description = pstrsave(strtrim(buf)); - l->acl_t = type[0]; - l->acl_id = acl; - l->m = (struct member *) NULL; - if (hash_store(lists, id, l) < 0) { - fprintf(stderr, "Out of memory!\n"); - exit(MR_NO_MEM); + EXEC SQL CLOSE u_cursor; + fprintf(stderr, "Loaded %d users\n", cnt); + + cnt = 0; + lists = create_hash(15000); + + 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) + break; + l = (struct list *) perm_malloc(sizeof(struct list)); + l->name = pstrsave(strtrim(name)); + l->maillist = maillistp; + l->description = pstrsave(strtrim(buf)); + l->acl_t = type[0]; + l->acl_id = acl; + l->m = NULL; + if (hash_store(lists, id, l) < 0) + { + fprintf(stderr, "Out of memory!\n"); + exit(MR_NO_MEM); } - cnt++; + cnt++; } - EXEC SQL CLOSE l_cursor; - fprintf(stderr, "Loaded %d lists\n", cnt); - - cnt = 0; - - EXEC SQL DECLARE m_cursor2 CURSOR FOR - SELECT list_id, member_type, member_id - FROM imembers - WHERE direct = 1 - ORDER BY list_id; - EXEC SQL OPEN m_cursor2; - while (1) { - EXEC SQL FETCH m_cursor2 INTO :id, :type, :mid; - if (sqlca.sqlcode != 0) break; - cnt++; - if (l = (struct list *) hash_lookup(lists, id)) { - m = (struct member *) perm_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->next = l->m; - l->m = m; - m->name = s; + EXEC SQL CLOSE l_cursor; + fprintf(stderr, "Loaded %d lists\n", cnt); + + cnt = 0; + + EXEC SQL DECLARE m_cursor2 CURSOR FOR + SELECT list_id, member_type, member_id + FROM imembers + WHERE direct = 1 + ORDER BY list_id; + EXEC SQL OPEN m_cursor2; + while (1) + { + EXEC SQL FETCH m_cursor2 INTO :id, :type, :mid; + if (sqlca.sqlcode) + break; + cnt++; + if ((l = (struct list *) hash_lookup(lists, id))) + { + m = (struct member *) perm_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->next = l->m; + l->m = m; + m->name = s; } } } - EXEC SQL CLOSE m_cursor2; - fprintf(stderr, "Loaded %d members\n", cnt); - - EXEC SQL COMMIT; - return; - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + EXEC SQL CLOSE m_cursor2; + fprintf(stderr, "Loaded %d members\n", cnt); + + EXEC SQL COMMIT; + return; +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } -save_mlist(id, l, force) -int id; -struct list *l; -int force; +save_mlist(int id, struct list *l, int force) { - register struct member *m; - register struct list *l1; + register struct member *m; + register struct list *l1; - if (l->maillist > 1 || - (l->maillist == 0 && !force)) - return; + if (l->maillist > 1 || (l->maillist == 0 && !force)) + return; - if (l->m && l->m->next == NULL && - !strcasecmp(l->name, l->m->name)) { - l->maillist = 3; - return; + if (l->m && l->m->next == NULL && !strcasecmp(l->name, l->m->name)) + { + l->maillist = 3; + return; } - l->maillist = 2; - insert_name(l->name, -1, TRUE, FALSE); - output_mlist(id, l); - - if (l->acl_t == 'L' && (l1 = (struct list *)hash_lookup(lists, l->acl_id))) - save_mlist(0, l1, TRUE); - - 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, TRUE); + l->maillist = 2; + insert_name(l->name, -1, TRUE, FALSE); + output_mlist(id, l); + + if (l->acl_t == 'L' && (l1 = (struct list *)hash_lookup(lists, l->acl_id))) + save_mlist(0, l1, TRUE); + + 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, TRUE); } } -insert_login(id, u, dummy) -int id; -struct user *u; -int dummy; +insert_login(int id, struct user *u, int dummy) { - if (u->pobox && u->login[0] != '#') - insert_name(u->login, id, TRUE, FALSE); + if (u->pobox && u->login[0] != '#') + insert_name(u->login, id, TRUE, FALSE); } -void insert_names(id, u, dummy) -int id; -struct user *u; -int dummy; +void insert_names(int id, struct user *u, int dummy) { - char buffer[256]; - - insert_name(u->last, id, FALSE, FALSE); - sprintf(buffer, "%s_%s", u->first, u->last); - insert_name(buffer, id, FALSE, TRUE); -/* sprintf(buffer, "%c_%s", u->first[0], u->last); - insert_name(buffer, id, FALSE, TRUE); */ - if (u->mi) { - sprintf(buffer, "%s_%c_%s", u->first, u->mi, u->last); - insert_name(buffer, id, FALSE, TRUE); + char buffer[256]; + + insert_name(u->last, id, FALSE, FALSE); + sprintf(buffer, "%s_%s", u->first, u->last); + insert_name(buffer, id, FALSE, TRUE); +#if 0 + sprintf(buffer, "%c_%s", u->first[0], u->last); + insert_name(buffer, id, FALSE, TRUE); +#endif + if (u->mi) + { + sprintf(buffer, "%s_%c_%s", u->first, u->mi, u->last); + insert_name(buffer, id, FALSE, TRUE); } } int incount = 0; -insert_name(s, id, nodups, copy) -char *s; -int id; -int nodups; -int copy; +insert_name(char *s, int id, int nodups, int copy) { - int code; - register struct names *ns; - - incount++; - code = hashstr(s); - ns = (struct names *) hash_lookup(names, code); - if (ns == NULL) { - if ((ns = (struct names *) perm_malloc(sizeof(struct names))) == NULL) { - fprintf(stderr, "ran out of memory inserting name (sorting)\n"); - exit(MR_NO_MEM); + int code; + register struct names *ns; + + incount++; + code = hashstr(s); + ns = (struct names *) hash_lookup(names, code); + if (!ns) + { + if (!(ns = (struct names *) perm_malloc(sizeof(struct names)))) + { + fprintf(stderr, "ran out of memory inserting name (sorting)\n"); + exit(MR_NO_MEM); } - if (copy) - ns->name = pstrsave(s); - else - ns->name = s; - ns->keep = nodups; - ns->id = id; - ns->next = NULL; - if (hash_store(names, code, ns) < 0) { - fprintf(stderr, "Out of memory!\n"); - exit(MR_NO_MEM); + if (copy) + ns->name = pstrsave(s); + else + ns->name = s; + ns->keep = nodups; + ns->id = id; + ns->next = NULL; + if (hash_store(names, code, ns) < 0) + { + fprintf(stderr, "Out of memory!\n"); + exit(MR_NO_MEM); } - return; + return; } - if (strcasecmp(ns->name, s)) { - while (ns->next) { - ns = ns->next; - if (!strcasecmp(ns->name, s)) - goto foundns; + if (strcasecmp(ns->name, s)) + { + while (ns->next) + { + ns = ns->next; + if (!strcasecmp(ns->name, s)) + goto foundns; } - if ((ns->next = (struct names *) perm_malloc(sizeof(struct names))) - == NULL) { - fprintf(stderr, "ran out of memory insterting name (sorting)\n"); - exit(MR_NO_MEM); + if (!(ns->next = (struct names *) perm_malloc(sizeof(struct names)))) + { + fprintf(stderr, "ran out of memory insterting name (sorting)\n"); + exit(MR_NO_MEM); } - ns = ns->next; - if (copy) - ns->name = pstrsave(s); - else - ns->name = s; - ns->keep = nodups; - ns->id = id; - ns->next = NULL; - return; + ns = ns->next; + if (copy) + ns->name = pstrsave(s); + else + ns->name = s; + ns->keep = nodups; + ns->id = id; + ns->next = NULL; + return; } - foundns: - if (nodups || ns->keep) { - if (nodups && ns->keep) - fprintf(stderr, "duplicated name: %s\n", s); - return; +foundns: + if (nodups || ns->keep) + { + if (nodups && ns->keep) + fprintf(stderr, "duplicated name: %s\n", s); + return; } - ns->id = 0; + ns->id = 0; } /* Illegal chars: ! " % ( ) , / : ; < = > @ [ \ ] ^ { | } */ static int illegalchars[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ - 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, /* SPACE - / */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, /* 0 - ? */ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* P - _ */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, /* p - ^? */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ + 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, /* SPACE - / */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, /* 0 - ? */ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* P - _ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, /* p - ^? */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; /* While hashing the string, punt any illegal characters */ -int hashstr(s) -register char *s; +int hashstr(register char *s) { - register int result; - register int c; - - for (result = 0; c = *s; s++) { - if (illegalchars[c]) { - register char *p; - for (p = s; *p; p++) - *p = p[1]; - continue; + register int result; + register int c; + + for (result = 0; c = *s; s++) + { + if (illegalchars[c]) + { + register char *p; + for (p = s; *p; p++) + *p = p[1]; + continue; } - if (isupper(c)) - c = *s = tolower(c); -/* result = result * 31 + *s; */ - result = (result << 5) - result + c - '`'; + if (isupper(c)) + c = *s = tolower(c); + result = (result << 5) - result + c - '`'; } - return(result < 0 ? -result : result); + return result < 0 ? -result : result; } -sort_info() +sort_info(void) { - names = create_hash(20001); - hash_step(users, insert_login, NULL); - incount = 0; - fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide); - hash_step(lists, save_mlist, FALSE); - fprintf(stderr, "Output %d lists\n", incount); - hash_step(users, insert_names, NULL); - fprintf(stderr, "Inserted %d names\n", incount); + names = create_hash(20001); + hash_step(users, insert_login, NULL); + incount = 0; + fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide); + hash_step(lists, save_mlist, FALSE); + fprintf(stderr, "Output %d lists\n", incount); + hash_step(users, insert_names, NULL); + fprintf(stderr, "Inserted %d names\n", incount); } -output_data(dummy, nms, out) -int dummy; -struct names *nms; -FILE *out; +output_data(int dummy, struct names *nms, FILE *out) { - register struct names *ns; - register struct user *u; - - incount++; - for (ns = nms; ns; ns = ns->next) { - if (ns->name[0] == 0 || ns->name[1] == 0) { - fprintf(stderr, "punting %s due to short name\n", ns->name); - continue; + register struct names *ns; + register struct user *u; + + incount++; + for (ns = nms; ns; ns = ns->next) + { + if (!ns->name[0] || !ns->name[1]) + { + fprintf(stderr, "punting %s due to short name\n", ns->name); + continue; } - if (ns->id > 0) { - u = (struct user *) hash_lookup(users, ns->id); - if (u->pobox) { - fprintf(out, "%s: %s\n", ns->name, u->pobox); - } else { - fprintf(out, "%s: =%s=@nobox\n", ns->name, ns->name); - } - } else if (ns->id == 0) { - fprintf(out, "%s: =%s=@ambig\n", ns->name, ns->name); + if (ns->id > 0) + { + u = (struct user *) hash_lookup(users, ns->id); + if (u->pobox) + fprintf(out, "%s: %s\n", ns->name, u->pobox); + else + fprintf(out, "%s: =%s=@nobox\n", ns->name, ns->name); } + else if (ns->id == 0) + fprintf(out, "%s: =%s=@ambig\n", ns->name, ns->name); } } int lwid, bol, awid; -output_mlist(id, l) -int id; -register struct list *l; +output_mlist(int id, register struct list *l) { - struct list *l1; - register struct member *m; - register struct user *u; - - put_fill(out, l->description); - if (l->acl_t == 'L' && - (l1 = (struct list *) hash_lookup(lists, l->acl_id))) - fprintf(out, "owner-%s: %s\n%s: ", l->name, l1->name, l->name); - else if (l->acl_t == 'U' && + struct list *l1; + register struct member *m; + register struct user *u; + + put_fill(out, l->description); + if (l->acl_t == 'L' && (l1 = (struct list *) hash_lookup(lists, l->acl_id))) + fprintf(out, "owner-%s: %s\n%s: ", l->name, l1->name, l->name); + else if (l->acl_t == 'U' && (u = (struct user *) hash_lookup(users, l->acl_id))) - fprintf(out, "owner-%s: %s\n%s: ", l->name, u->login, l->name); - else - 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"); - incount++; + fprintf(out, "owner-%s: %s\n%s: ", l->name, u->login, l->name); + else + 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) + fprintf(out, "/dev/null"); + fprintf(out, "\n\n"); + incount++; } /* print out strings separated by commas, doing line breaks as appropriate */ -do_member(out, s) -FILE *out; -register char *s; +do_member(FILE *out, register char *s) { - register wwid; - static int cont = 1; - char str[8]; - - wwid = strlen(s); - - if (!bol && awid + wwid + 2 > AL_MAX_WID) { - 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++; - awid = lwid = 17 + wwid; - fputs(s, out); - return; + register wwid; + static int cont = 1; + char str[8]; + + wwid = strlen(s); + + if (!bol && awid + wwid + 2 > AL_MAX_WID) + { + 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++; + awid = lwid = 17 + wwid; + fputs(s, out); + return; } - if (bol) { - lwid += wwid; - awid = lwid; - fputs(s, out); - bol = 0; - 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; + 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); + lwid += wwid + 2; + fprintf(out, ", %s", s); } -put_fill(aliases, string) -FILE *aliases; -register char *string; +put_fill(FILE *aliases, register char *string) { - register char *c; - register int lwid; - register int wwid; - - if (string == 0 || *string == 0) return; - fputs("# ", aliases); - lwid = 3; - - while (1) { - while (*string == ' ') string++; - c = (char *)strchr(string, ' '); - if (c == 0) { - wwid = strlen(string); - } else { - wwid = c - string; - *c = 0; - } + register char *c; + register int lwid; + register int wwid; - if ((lwid + wwid) > ML_WID) { - fputs("\n# ", aliases); - lwid = 3; - fputs(string, aliases); - } else { - fputs(string, aliases); + if (!string || !*string) + return; + fputs("# ", aliases); + lwid = 3; + + while (1) + { + while (*string == ' ') + string++; + c = strchr(string, ' '); + if (!c) + wwid = strlen(string); + else + { + wwid = c - string; + *c = '\0'; } - 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++; + if ((lwid + wwid) > ML_WID) + { + fputs("\n# ", aliases); + lwid = 3; + fputs(string, aliases); + } + else + fputs(string, aliases); + + if (!c) + break; + /* add a space after the word */ + fputc(' ', aliases); + wwid++; + lwid += wwid; + string += wwid; + /* add another if after a period */ + if (*--c == '.') + { + fputc(' ', aliases); + lwid++; } } - (void) fputc('\n', aliases); + fputc('\n', aliases); } -do_people() +do_people(void) { - incount = 0; - fprintf(out, "\n%s\n# People\n%s\n", divide, divide); - hash_step(names, output_data, out); - fprintf(stderr, "Output %d entries\n", incount); + incount = 0; + fprintf(out, "\n%s\n# People\n%s\n", divide, divide); + hash_step(names, output_data, out); + fprintf(stderr, "Output %d entries\n", incount); } #define chunk_size 102400 -char *perm_malloc(size) -unsigned size; +char *perm_malloc(unsigned size) { - static char *pool = NULL; - static unsigned pool_size = 0; - register char *ret; - - if (size > pool_size) { - pool = (char *) malloc(chunk_size); - pool_size = chunk_size; + static char *pool = NULL; + static unsigned pool_size = 0; + register char *ret; + + if (size > pool_size) + { + pool = malloc(chunk_size); + pool_size = chunk_size; } - ret = pool; - pool += size; - pool = (char *)(((unsigned) (pool + 3)) & ~3); - pool_size -= (pool - ret); - return(ret); + ret = pool; + pool += size; + pool = (char *)(((unsigned) (pool + 3)) & ~3); + pool_size -= (pool - ret); + return ret; } /* * Make a (permenant) copy of a string. */ -char * -pstrsave(s) - char *s; +char *pstrsave(char *s) { - register int len; - register char *p; - /* Kludge for sloppy string semantics */ - if (!s) { - printf("NULL != \"\" !!!!\r\n"); - p = perm_malloc(1); - *p = '\0'; - return p; + register int len; + register char *p; + /* Kludge for sloppy string semantics */ + if (!s) + { + printf("NULL != \"\" !!!!\r\n"); + p = perm_malloc(1); + *p = '\0'; + return p; } - len = strlen(s) + 1; - p = perm_malloc((u_int)len); - if (p) memcpy(p, s, len); - return p; + len = strlen(s) + 1; + p = perm_malloc((u_int)len); + if (p) + memcpy(p, s, len); + return p; } #define hash_func(h, key) (key >= 0 ? (key % h->size) : (-key % h->size)) /* Create a hash table. The size is just a hint, not a maximum. */ -struct hash *create_hash(size) -int size; +struct hash *create_hash(int size) { - struct hash *h; - - h = (struct hash *) perm_malloc(sizeof(struct hash)); - if (h == (struct hash *) NULL) - return((struct hash *) NULL); - h->size = size; - h->data = (struct bucket **) perm_malloc(size * sizeof(char *)); - if (h->data == (struct bucket **) NULL) { - return((struct hash *) NULL); - } - memset(h->data, 0, size * sizeof(char *)); - return(h); + struct hash *h; + + h = (struct hash *) perm_malloc(sizeof(struct hash)); + if (!h) + return NULL; + h->size = size; + h->data = (struct bucket **) perm_malloc(size * sizeof(char *)); + if (!h->data) + return NULL; + memset(h->data, 0, size * sizeof(char *)); + return h; } /* Lookup an object in the hash table. Returns the value associated with * the key, or NULL (thus NULL is not a very good value to store...) */ -char *hash_lookup(h, key) -struct hash *h; -register int key; +char *hash_lookup(struct hash *h, register int key) { - register struct bucket *b; - - b = h->data[hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) - return(b->data); - else - return(NULL); + register struct bucket *b; + + b = h->data[hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + return b->data; + else + return NULL; } @@ -732,21 +749,20 @@ register int key; * existed, or 0 if not. */ -int hash_update(h, key, value) -struct hash *h; -register int key; -char *value; +int hash_update(struct hash *h, register int key, char *value) { - register struct bucket *b; - - b = h->data[hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) { - b->data = value; - return(1); - } else - return(0); + register struct bucket *b; + + b = h->data[hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + { + b->data = value; + return 1; + } + else + return 0; } @@ -754,37 +770,36 @@ char *value; * there, 1 if it was, or -1 if we ran out of memory. */ -int hash_store(h, key, value) -struct hash *h; -register int key; -char *value; +int hash_store(struct hash *h, register int key, char *value) { - register struct bucket *b, **p; - - p = &(h->data[hash_func(h, key)]); - if (*p == NULL) { - b = *p = (struct bucket *) perm_malloc(sizeof(struct bucket)); - if (b == (struct bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + register struct bucket *b, **p; + + p = &(h->data[hash_func(h, key)]); + if (!*p) + { + b = *p = (struct bucket *) perm_malloc(sizeof(struct bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } - for (b = *p; b && b->key != key; b = *p) - p = (struct bucket **) *p; - if (b && b->key == key) { - b->data = value; - return(1); + for (b = *p; b && b->key != key; b = *p) + p = (struct bucket **) *p; + if (b && b->key == key) + { + b->data = value; + return 1; } - b = *p = (struct bucket *) perm_malloc(sizeof(struct bucket)); - if (b == (struct bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + b = *p = (struct bucket *) perm_malloc(sizeof(struct bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } @@ -792,17 +807,16 @@ char *value; * data with that value, call the callback proc with the corresponding key. */ -hash_search(h, value, callback) -struct hash *h; -register char *value; -void (*callback)(); +hash_search(struct hash *h, register char *value, void (*callback)()) { - register struct bucket *b, **p; - - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - if (b->data == value) - (*callback)(b->key); + register struct bucket *b, **p; + + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + { + if (b->data == value) + (*callback)(b->key); } } } @@ -811,16 +825,13 @@ void (*callback)(); /* Step through the hash table, calling the callback proc with each key. */ -hash_step(h, callback, hint) -struct hash *h; -void (*callback)(); -char *hint; +hash_step(struct hash *h, void (*callback)(), char *hint) { - register struct bucket *b, **p; + register struct bucket *b, **p; - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - (*callback)(b->key, b->data, hint); - } + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + (*callback)(b->key, b->data, hint); } } diff --git a/gen/moddiff.pc b/gen/moddiff.pc index aa3ba0b7..d04bd094 100644 --- a/gen/moddiff.pc +++ b/gen/moddiff.pc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -14,9 +15,9 @@ #include EXEC SQL INCLUDE sqlca; -static char * MONTHNAMES[] = {"january", "february", "march", "april", "may", - "june", "july", "august", "september", - "october", "november", "december"}; +static char *MONTHNAMES[] = {"january", "february", "march", "april", "may", + "june", "july", "august", "september", + "october", "november", "december"}; static int MONTHDAYS[] = {0,0,31,59,90,120,151,181,212,243,273,304,334}; @@ -26,36 +27,30 @@ static int MONTHDAYS[] = {0,0,31,59,90,120,151,181,212,243,273,304,334}; /** in flag variable. Return 0 if success, else errno. **/ /****************************************************************/ -int ModDiff (flag, tbl, ModTime) -int *flag; -char *tbl; -time_t ModTime; +int ModDiff(int *flag, char *tbl, time_t ModTime) { - time_t filetimeno; - EXEC SQL BEGIN DECLARE SECTION; - char filetime[48], *tbl_name; - EXEC SQL END DECLARE SECTION; - - *flag = 0; - tbl_name = tbl; - 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) { - fprintf(stderr, "Moddiff Query failed: %d\n", sqlca.sqlcode); - return(MR_DATE); + time_t filetimeno; + EXEC SQL BEGIN DECLARE SECTION; + char filetime[48], *tbl_name; + EXEC SQL END DECLARE SECTION; + + *flag = 0; + tbl_name = tbl; + EXEC SQL SELECT TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS') + INTO :filetime FROM tblstats + WHERE table_name = :tbl_name; + if (sqlca.sqlcode) + { + fprintf(stderr, "Moddiff Query failed: %d\n", sqlca.sqlcode); + return MR_DATE; } -#ifdef DEBUG - printf("about to call Date2Sec, flag = 0x%x\n", flag); -#endif - if (Date2Sec (filetime, &filetimeno)) { - fprintf(stderr,"Unable to parse mod. date for file %s\n", tbl); - return(MR_DATE); + if (Date2Sec (filetime, &filetimeno)) + { + fprintf(stderr, "Unable to parse mod. date for file %s\n", tbl); + return MR_DATE; } -#ifdef DEBUG - printf("got time, flag = 0x%x\n", flag); -#endif - *flag = (int) (filetimeno - ModTime); - return(0); + *flag = (int) (filetimeno - ModTime); + return 0; } @@ -65,66 +60,43 @@ time_t ModTime; /** Return 1 if failure, 0 if success **/ /***************************************************/ -Date2Sec(DS, UTime) -char *DS; -time_t *UTime; +int Date2Sec(char *DS, time_t *UTime) { - static int defzone = -1; - int Day, Month, Year, Hour, Minute, Sec, Err, TotalDays, Iter; - struct timeval tv; - struct timezone tz; - - if (defzone == -1) { - if (gettimeofday(&tv, &tz)) - defzone = 0; - else - defzone = tz.tz_minuteswest; + static int defzone = -1; + int Day, Month, Year, Hour, Minute, Sec, Err, TotalDays, Iter; + struct timeval tv; + struct timezone tz; + + if (defzone == -1) + { + if (gettimeofday(&tv, &tz)) + defzone = 0; + else + defzone = tz.tz_minuteswest; } -#ifdef DEBUG - printf("Date2Sec(\"%s\", %d)\n", DS, *UTime); -#endif - Err = ParseDateString (DS, &Day, &Month, &Year, &Hour, &Minute,&Sec); -#ifdef DEBUG - printf("date=%d/%d/%d %d:%d:%d, err=%d\n", Day, Month, Year, - Hour, Minute, Sec, Err); -#endif - if (Err) return (Err); - - if (Year < 1970) { - for (TotalDays = 0, Iter = 1969; Iter > Year; Iter--) { - TotalDays += NumdaysY(Iter);} -#ifdef DEBUG - printf("Days in years : %d\n", TotalDays); -#endif - TotalDays += (NumdaysY(Year) - NumdaysM(Month, Year) - Day); -#ifdef DEBUG - printf("Days after months & days: %d\n", TotalDays); -#endif - *UTime = -((((24 * TotalDays) + 24 - Hour) * 60 - Minute) * 60 - - Sec) + defzone; - return (0); - } else { - for (TotalDays = 0, Iter = 1970; Iter < Year; Iter++) { - TotalDays += NumdaysY(Iter);} -#ifdef DEBUG - printf("Days in years : %d\n", TotalDays); -#endif - TotalDays += NumdaysM(Month, Year); -#ifdef DEBUG - printf("Days after months: %d\n", TotalDays); -#endif - TotalDays += (Day - 1); -#ifdef DEBUG - printf("Days after Days : %d\n", TotalDays); - printf("Calculating seconds...(UTime = 0x%x)\n", *UTime); -#endif - *UTime = (((24 * TotalDays) + Hour) * 60 + Minute) * 60 + - Sec + defzone; -#ifdef DEBUG - printf("Calculated value of %d\n", *UTime); -#endif - return (0); + Err = ParseDateString (DS, &Day, &Month, &Year, &Hour, &Minute, &Sec); + if (Err) + return Err; + + if (Year < 1970) + { + for (TotalDays = 0, Iter = 1969; Iter > Year; Iter--) + TotalDays += NumdaysY(Iter); + TotalDays += (NumdaysY(Year) - NumdaysM(Month, Year) - Day); + *UTime = -((((24 * TotalDays) + 24 - Hour) * 60 - Minute) * 60 - + Sec) + defzone; + return 0; + } + else + { + for (TotalDays = 0, Iter = 1970; Iter < Year; Iter++) + TotalDays += NumdaysY(Iter); + TotalDays += NumdaysM(Month, Year); + TotalDays += (Day - 1); + *UTime = (((24 * TotalDays) + Hour) * 60 + Minute) * 60 + + Sec + defzone; + return 0; } } @@ -133,10 +105,9 @@ time_t *UTime; /** Return the # of days in the Year **/ /*****************************************/ -int NumdaysY(Year) -int Year; +int NumdaysY(int Year) { - return (365 + Leapyear(Year)); + return 365 + Leapyear(Year); } @@ -144,13 +115,12 @@ int Year; /** Return the # of days in the Month **/ /*****************************************/ -int NumdaysM(Month, Year) -int Month, Year; +int NumdaysM(int Month, int Year) { - if ((Month > 2) && (Leapyear (Year))) - return (MONTHDAYS[Month] + 1); - else - return (MONTHDAYS[Month]); + if ((Month > 2) && (Leapyear (Year))) + return MONTHDAYS[Month] + 1; + else + return MONTHDAYS[Month]; } @@ -158,13 +128,12 @@ int Month, Year; /** Return 1 if a leapyear, else 0 **/ /*****************************************/ -int Leapyear (Year) -int Year; +int Leapyear(int Year) { - if ((Year % 4) && (!(Year % 100) || (Year % 1000))) - return (0); - else - return (1); + if ((Year % 4) && (!(Year % 100) || (Year % 1000))) + return 0; + else + return 1; } @@ -173,72 +142,72 @@ int Year; /** Return 0 if success, 1 if failure **/ /************************************************/ -int ParseDateString (DS, Day, Month, Year, Hour, Minute, Sec) -char *DS; -int *Day, *Month, *Year, *Hour, *Minute, *Sec; +int ParseDateString(char *DS, int *Day, int *Month, int *Year, int *Hour, + int *Minute, int *Sec) { - int Gotten; - char *M, *D, *Temp; - int Y=0, H=0, Min=0, S=0, DayNum=0, MonthNum=0; - - M = (char *)malloc(strlen(DS) + 2); - D = (char *)malloc(strlen(DS) + 2); - if (!(M && D)) return (1); - Gotten = sscanf (DS, "%[^-]-%[^-]-%d %d:%d:%d", D, M, &Y, &H, &Min, &S); - if (Gotten < 3) - Gotten = sscanf (DS, "%[^/]/%[^/]/%d %d:%d:%d", D, M, &Y, &H, &Min, &S); - if (Gotten < 3) - Gotten = sscanf (DS, "%s %[^,], %d %d:%d:%d", M, D, &Y, &H, &Min, &S); -#ifdef DEBUG - printf ("Month = %s\nDay = %s\nYear = %d\n", M, D, Y); - printf ("Hour = %d\nMin= %d\nSec = %d\n", H, Min, S); -#endif - if ((Gotten < 3) || !(D && M && Y)) { - free(M); - free(D); - return (1);} /* Couldn't scan in a date */ - if (atoi(M)) { /* Month not text, so M/D/Y not D/M/Y */ - Temp = M; - M = D; - D = Temp;} - DayNum = atoi(D); - MonthNum = MonthNo(M); - free(M); - free(D); -#ifdef DEBUG - printf ("Month = %d\nDay = %d\nYear = %d\n", MonthNum, DayNum, Y); -#endif - if ((DayNum < 1) || (DayNum > 31)) - return (1); /* Bad Day */ - if (!MonthNum) - return (1); /* Bad Month */ - if ((Y < 1) || (Y > 10000)) - return (1); /* Bad Year */ - if (Gotten == 4) - return(1); /* Bad Time (Hour only) */ - if ((Gotten > 4) && (H < 0) || (H > 24)) - return(1); /* Bad Hour */ - if ((Gotten > 4) && ((Min < 0) || (Min > 59))) - return(1); /* Bad Minute */ - if ((Gotten > 5) && ((S < 0) || (S > 59))) - return(1); /* Bad Second */ - *Day = DayNum; - *Month = MonthNum; - if (Y < 100) /* For abreviations like 90 for 1990 */ - Y += 1900; /* (Yes, it will be wrong in 2000) */ - *Year = Y; - if (Gotten > 4) { - *Hour = H; - *Minute = Min; + int Gotten; + char *M, *D, *Temp; + int Y = 0, H = 0, Min = 0, S = 0, DayNum = 0, MonthNum = 0; + + M = malloc(strlen(DS) + 2); + D = malloc(strlen(DS) + 2); + if (!(M && D)) + return 1; + Gotten = sscanf (DS, "%[^-]-%[^-]-%d %d:%d:%d", D, M, &Y, &H, &Min, &S); + if (Gotten < 3) + Gotten = sscanf (DS, "%[^/]/%[^/]/%d %d:%d:%d", D, M, &Y, &H, &Min, &S); + if (Gotten < 3) + Gotten = sscanf (DS, "%s %[^,], %d %d:%d:%d", M, D, &Y, &H, &Min, &S); + if ((Gotten < 3) || !(D && M && Y)) + { + free(M); + free(D); + return 1; /* Couldn't scan in a date */ } - else { - *Hour = 0; - *Minute = 0;} - if (Gotten > 5) - *Sec = S; - else - *Sec = 0; - return(0); + if (atoi(M)) + { /* Month not text, so M/D/Y not D/M/Y */ + Temp = M; + M = D; + D = Temp; + } + DayNum = atoi(D); + MonthNum = MonthNo(M); + free(M); + free(D); + if ((DayNum < 1) || (DayNum > 31)) + return 1; /* Bad Day */ + if (!MonthNum) + return 1; /* Bad Month */ + if ((Y < 1) || (Y > 10000)) + return 1; /* Bad Year */ + if (Gotten == 4) + return 1; /* Bad Time (Hour only) */ + if ((Gotten > 4) && (H < 0) || (H > 24)) + return 1; /* Bad Hour */ + if ((Gotten > 4) && ((Min < 0) || (Min > 59))) + return 1; /* Bad Minute */ + if ((Gotten > 5) && ((S < 0) || (S > 59))) + return 1; /* Bad Second */ + *Day = DayNum; + *Month = MonthNum; + if (Y < 100) /* For abreviations like 90 for 1990 */ + Y += 1900; /* (Yes, it will be wrong in 2000) */ + *Year = Y; + if (Gotten > 4) + { + *Hour = H; + *Minute = Min; + } + else + { + *Hour = 0; + *Minute = 0; + } + if (Gotten > 5) + *Sec = S; + else + *Sec = 0; + return 0; } @@ -246,20 +215,21 @@ int *Day, *Month, *Year, *Hour, *Minute, *Sec; /** Return the Month number of a Month number or string **/ /***********************************************************/ -int MonthNo (M) -char *M; +int MonthNo(char *M) { - int Count; - if (atoi(M)) { - if ((atoi(M) > 0) && (atoi(M) < 13)) - return (atoi(M)); - else - return (0); - } - for (Count = 0; Count < 12; Count++) { - if (!strcasecmp (M, MONTHNAMES[Count]) - || !strncasecmp(M, MONTHNAMES[Count], 3)) - return (Count + 1); + int Count; + if (atoi(M)) + { + if ((atoi(M) > 0) && (atoi(M) < 13)) + return atoi(M); + else + return 0; + } + for (Count = 0; Count < 12; Count++) + { + if (!strcasecmp (M, MONTHNAMES[Count]) + || !strncasecmp(M, MONTHNAMES[Count], 3)) + return Count + 1; } - return (0); + return 0; } diff --git a/gen/network.pc b/gen/network.pc index 655e1797..3bbc8bbb 100644 --- a/gen/network.pc +++ b/gen/network.pc @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -17,90 +18,97 @@ EXEC SQL INCLUDE sqlca; -extern int errno; char *whoami = "network.gen"; char *db = "moira/moira"; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *out = stdout; - 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, saddr; - char name[65], description[65]; - EXEC SQL END DECLARE SECTION; + FILE *out = stdout; + 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, saddr; + char name[65], description[65]; + EXEC SQL END DECLARE SECTION; - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db; - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff(&flag1, "subnet", 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); - } + if (argc == 2) + { + if (stat(argv[1], &sb) == 0) + { + if (ModDiff(&flag1, "subnet", 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); + } } - 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); + outf = argv[1]; + sprintf(outft, "%s~", outf); + if (!(out = fopen(outft, "w"))) + { + 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; } + 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 WHENEVER SQLERROR GOTO sqlerr; + gettimeofday(&now, NULL); - gettimeofday(&now, NULL); - - fprintf(out, "; MIT Network Table\n;\n"); - fprintf(out, "; \t%cAuthor: $\n", '$'); - fprintf(out, "; \t%cDate: $\n", '$'); - fprintf(out, "; \t%cRevision: $\n;\n", '$'); - fprintf(out, "; Network table generated by Moira at %s;\n", - ctime(&now.tv_sec)); + fprintf(out, "; MIT Network Table\n;\n"); + fprintf(out, "; \t%cAuthor: $\n", '$'); + fprintf(out, "; \t%cDate: $\n", '$'); + fprintf(out, "; \t%cRevision: $\n;\n", '$'); + fprintf(out, "; Network table generated by Moira at %s;\n", + ctime(&now.tv_sec)); - EXEC SQL DECLARE x CURSOR FOR SELECT - name, snet_id, saddr, description - FROM subnet ORDER BY saddr; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :name, :id, :saddr, :description; - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - if (*strtrim(name) == 0) continue; - addr.s_addr=htonl(saddr); - fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name, - inet_ntoa(addr), - strtrim(description)); + EXEC SQL DECLARE x CURSOR FOR SELECT + name, snet_id, saddr, description + FROM subnet ORDER BY saddr; + EXEC SQL OPEN x; + while (1) + { + EXEC SQL FETCH x INTO :name, :id, :saddr, :description; + if (sqlca.sqlcode) + break; + if (id == 0) + continue; + if (!*strtrim(name)) + continue; + addr.s_addr = htonl(saddr); + fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name, + inet_ntoa(addr), strtrim(description)); } - EXEC SQL CLOSE x; + EXEC SQL CLOSE x; - EXEC SQL COMMIT; + EXEC SQL COMMIT; - fprintf(out, "; End of automatically generated network table\n"); - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); + fprintf(out, "; End of automatically generated network table\n"); + if (fclose(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); + if (outf) + fix_file(outf); + exit(MR_SUCCESS); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/nfs.pc b/gen/nfs.pc index 2b150bc3..d10d5da1 100644 --- a/gen/nfs.pc +++ b/gen/nfs.pc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -18,473 +19,509 @@ EXEC SQL INCLUDE sqlca; -#define min(x,y) ((x) < (y) ? (x) : (y)) +#define min(x, y) ((x) < (y) ? (x) : (y)) char *whoami = "nfs.gen"; char *db = "moira/moira"; -char *malloc(), *strsave(); +char *strsave(); char nfs_dir[64]; struct hash *users, *groups; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - char cmd[64]; - struct stat sb; - int changed = 0; - - if (argc > 2) { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); + char cmd[64]; + struct stat sb; + int changed = 0; + + if (argc > 2) + { + fprintf(stderr, "usage: %s [outfile]\n", argv[0]); + exit(MR_ARGS); } - initialize_sms_error_table(); - sprintf(nfs_dir, "%s/nfs", DCM_DIR); + initialize_sms_error_table(); + sprintf(nfs_dir, "%s/nfs", DCM_DIR); - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db; - changed = do_nfs(); + changed = do_nfs(); - EXEC SQL COMMIT; + EXEC SQL COMMIT; - if (!changed) { - fprintf(stderr, "No files updated.\n"); - if (argc == 2 && stat(argv[1], &sb) == 0) - exit(MR_NO_CHANGE); + if (!changed) + { + fprintf(stderr, "No files updated.\n"); + if (argc == 2 && stat(argv[1], &sb) == 0) + exit(MR_NO_CHANGE); } - if (argc == 2) { - sprintf(cmd, "cd %s; cp %s/nfs/* .; tar cf %s .", - nfs_dir, SMS_DIR, argv[1]); - if (system(cmd)) - exit(MR_TAR_FAIL); + if (argc == 2) + { + sprintf(cmd, "cd %s; cp %s/nfs/* .; tar cf %s .", + nfs_dir, SMS_DIR, argv[1]); + if (system(cmd)) + exit(MR_TAR_FAIL); } - exit(MR_SUCCESS); + exit(MR_SUCCESS); } /* Generate the files. Returns zero if nothing changed, non-zero otherwise. */ -int do_nfs() +int do_nfs(void) { - EXEC SQL BEGIN DECLARE SECTION; - char machname[41], listname[33]; - EXEC SQL END DECLARE SECTION; - struct save_queue *machs, *lists; - int changed; - - machs = sq_create(); - lists = sq_create(); - - /* 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 s_cursor CURSOR FOR - SELECT m.name, s.value3 - FROM machine m, serverhosts s - WHERE m.mach_id = s.mach_id AND s.service = 'NFS' AND s.enable != 0; - EXEC SQL OPEN s_cursor; - while (1) { - EXEC SQL FETCH s_cursor INTO :machname, :listname; - if (sqlca.sqlcode != 0) break; - sq_save_unique_string(machs, strsave(strtrim(machname))); - sq_save_unique_string(lists, strsave(strtrim(listname))); - } - EXEC SQL CLOSE s_cursor; - - changed = do_lists(lists); - EXEC SQL COMMIT; - changed += do_machs(machs); - return(changed); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + EXEC SQL BEGIN DECLARE SECTION; + char machname[41], listname[33]; + EXEC SQL END DECLARE SECTION; + struct save_queue *machs, *lists; + int changed; + + machs = sq_create(); + lists = sq_create(); + + /* 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 s_cursor CURSOR FOR + SELECT m.name, s.value3 + FROM machine m, serverhosts s + WHERE m.mach_id = s.mach_id AND s.service = 'NFS' AND s.enable != 0; + EXEC SQL OPEN s_cursor; + while (1) + { + EXEC SQL FETCH s_cursor INTO :machname, :listname; + if (sqlca.sqlcode) + break; + sq_save_unique_string(machs, strsave(strtrim(machname))); + sq_save_unique_string(lists, strsave(strtrim(listname))); + } + EXEC SQL CLOSE s_cursor; + + changed = do_lists(lists); + EXEC SQL COMMIT; + changed += do_machs(machs); + return changed; +sqlerr: + 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; +int do_lists(struct save_queue *lists) { - char file[64], *u; - struct stat sb; - FILE *fd; - EXEC SQL BEGIN DECLARE SECTION; - char *listname, *lsname, lname[33], uname[9]; - int uid, id, flag1, flag2, flag3, flag4; - EXEC SQL END DECLARE SECTION; - - sprintf(file, "%s/list-", nfs_dir); - /* - if (stat(file, &sb) == 0) { - if ((ModDiff (&flag1, "users", sb.st_mtime)) || - (ModDiff (&flag2, "list", sb.st_mtime)) || - (ModDiff (&flag3, "imembers", sb.st_mtime)) || - (ModDiff (&flag4, "serverhosts", sb.st_mtime))) exit (MR_DATE); - if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) { - fprintf(stderr, "The lists do not need to be rebuilt.\n"); - return(0); + char file[64], *u; + struct stat sb; + FILE *fd; + EXEC SQL BEGIN DECLARE SECTION; + char *listname, *lsname, lname[33], uname[9]; + int uid, id, flag1, flag2, flag3, flag4; + EXEC SQL END DECLARE SECTION; + + sprintf(file, "%s/list-", nfs_dir); +#if 0 + if (stat(file, &sb) == 0) + { + if ((ModDiff (&flag1, "users", sb.st_mtime)) || + (ModDiff (&flag2, "list", sb.st_mtime)) || + (ModDiff (&flag3, "imembers", sb.st_mtime)) || + (ModDiff (&flag4, "serverhosts", sb.st_mtime))) + exit(MR_DATE); + if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) + { + fprintf(stderr, "The lists do not need to be rebuilt.\n"); + return 0; } } - */ - - - /* build the list of everyone, and store it in a file whose name - * corresponds to the empty list. - */ - do_everyone(); - - fprintf(stderr, "Building specific lists\n"); - /* now do each of the lists used by an NFS server */ - - while (sq_get_data(lists, &listname)) { - if (strlen(listname) == 0) - continue; - sprintf(file, "%s/list-%s", nfs_dir, listname); - fd = fopen(file, "w"); - if (!fd) { - fprintf(stderr, "cannot open %s for output\n", file); - exit(MR_OCONFIG); +#endif + + /* build the list of everyone, and store it in a file whose name + * corresponds to the empty list. + */ + do_everyone(); + + fprintf(stderr, "Building specific lists\n"); + /* now do each of the lists used by an NFS server */ + + while (sq_get_data(lists, &listname)) + { + if (strlen(listname) == 0) + continue; + sprintf(file, "%s/list-%s", nfs_dir, listname); + fd = fopen(file, "w"); + if (!fd) + { + fprintf(stderr, "cannot open %s for output\n", file); + exit(MR_OCONFIG); } - EXEC SQL DECLARE m_cursor CURSOR FOR - SELECT m.member_id - FROM imembers m, list l - WHERE m.list_id=l.list_id AND l.name = :listname AND - m.member_type='USER' - ORDER BY member_id; - EXEC SQL OPEN m_cursor; - while (1) { - EXEC SQL FETCH m_cursor INTO :id; - if (sqlca.sqlcode != 0) break; - if (u = hash_lookup(users, id)) - fprintf(fd, "%s\n", u); + EXEC SQL DECLARE m_cursor CURSOR FOR + SELECT m.member_id + FROM imembers m, list l + WHERE m.list_id = l.list_id AND l.name = :listname + AND m.member_type = 'USER' + ORDER BY member_id; + EXEC SQL OPEN m_cursor; + while (1) + { + EXEC SQL FETCH m_cursor INTO :id; + if (sqlca.sqlcode) + break; + if ((u = hash_lookup(users, id))) + fprintf(fd, "%s\n", u); } - EXEC SQL CLOSE m_cursor; - if (fclose(fd) == EOF) { - fprintf(stderr, "error closing %s\n", file); - exit(MR_CCONFIG); + EXEC SQL CLOSE m_cursor; + if (fclose(fd) == EOF) + { + fprintf(stderr, "error closing %s\n", file); + exit(MR_CCONFIG); } } /* don't free here either sq_destroy(lists); */ - return(1); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } /* Build the list of everybody. */ struct grp { - struct grp *next; - char *lid; + struct grp *next; + char *lid; }; struct user { - char name[9]; - int uid; - struct grp *lists; + char name[9]; + int uid; + struct grp *lists; }; -do_everyone() +do_everyone(void) { - char buf[BUFSIZ], *l; - struct user *u; - struct grp *g; - struct bucket *b, **p; - EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int gid, id, lid, maxid, uid; - EXEC SQL END DECLARE SECTION; - FILE *fd; - int i; - struct save_queue *sq; - - fprintf(stderr, "Building the list of everybody\n"); - sprintf(buf, "%s/list-", nfs_dir); - fd = fopen(buf, "w"); - if (!fd) { - fprintf(stderr, "cannot open %s for output\n", buf); - exit(MR_OCONFIG); + char buf[BUFSIZ], *l; + struct user *u; + struct grp *g; + struct bucket *b, **p; + EXEC SQL BEGIN DECLARE SECTION; + char name[33]; + int gid, id, lid, maxid, uid; + EXEC SQL END DECLARE SECTION; + FILE *fd; + int i; + struct save_queue *sq; + + fprintf(stderr, "Building the list of everybody\n"); + sprintf(buf, "%s/list-", nfs_dir); + fd = fopen(buf, "w"); + if (!fd) + { + fprintf(stderr, "cannot open %s for output\n", buf); + exit(MR_OCONFIG); } - /* make space for group list */ - groups = create_hash(15000); - - /* retrieve simple groups */ - EXEC SQL DECLARE l_cursor CURSOR FOR - SELECT gid, list_id - FROM list - WHERE grouplist != 0 AND active != 0 - ORDER BY list_id; - EXEC SQL OPEN l_cursor; - while (1) { - EXEC SQL FETCH l_cursor INTO :gid, :lid; - if (sqlca.sqlcode != 0) break; - sprintf(buf, ":%d", gid); - hash_store(groups, lid, strsave(buf)); - } - EXEC SQL CLOSE l_cursor; - - /* now do grplists */ - users = create_hash(10000); - EXEC SQL DECLARE u_cursor CURSOR FOR - SELECT users_id, login, unix_uid - FROM users - WHERE status = 1 - ORDER BY users_id; - EXEC SQL OPEN u_cursor; - while (1) { - EXEC SQL FETCH u_cursor INTO :id, :name, :uid; - if (sqlca.sqlcode != 0) break; - u = (struct user *) malloc(sizeof(struct user)); - strcpy(u->name, strtrim(name)); - u->uid = uid; - u->lists = NULL; - hash_store(users, id, u); - } - EXEC SQL CLOSE u_cursor; - - EXEC SQL DECLARE m_cursor2 CURSOR FOR - SELECT list_id, member_id - FROM imembers - WHERE member_type = 'USER' - ORDER BY list_id; - EXEC SQL OPEN m_cursor2; - while (1) { - EXEC SQL FETCH m_cursor2 INTO :lid, :id; - if (sqlca.sqlcode != 0) break; - if ((u = (struct user *) hash_lookup(users, id)) && - ((l = hash_lookup(groups, lid)) != NULL)) { - g = (struct grp *) malloc(sizeof(struct grp)); - g->next = u->lists; - u->lists = g; - g->lid = l; - } - } - EXEC SQL CLOSE m_cursor2; - - for (p = &(users->data[users->size - 1]); p >= users->data; p--) { - for (b = *p; b; b = b->next) { - u = (struct user *)b->data; - sprintf(buf, "%s:%d", u->name, u->uid); - for (g = u->lists; g; g = g->next) - strcat(buf, g->lid); - b->data = strsave(buf); - fprintf(fd, "%s\n", buf); + /* make space for group list */ + groups = create_hash(15000); + + /* retrieve simple groups */ + EXEC SQL DECLARE l_cursor CURSOR FOR + SELECT gid, list_id + FROM list + WHERE grouplist != 0 AND active != 0 + ORDER BY list_id; + EXEC SQL OPEN l_cursor; + while (1) + { + EXEC SQL FETCH l_cursor INTO :gid, :lid; + if (sqlca.sqlcode) + break; + sprintf(buf, ":%d", gid); + hash_store(groups, lid, strsave(buf)); + } + EXEC SQL CLOSE l_cursor; + + /* now do grplists */ + users = create_hash(10000); + EXEC SQL DECLARE u_cursor CURSOR FOR + SELECT users_id, login, unix_uid + FROM users + WHERE status = 1 + ORDER BY users_id; + EXEC SQL OPEN u_cursor; + while (1) + { + EXEC SQL FETCH u_cursor INTO :id, :name, :uid; + if (sqlca.sqlcode) + break; + u = malloc(sizeof(struct user)); + strcpy(u->name, strtrim(name)); + u->uid = uid; + u->lists = NULL; + hash_store(users, id, u); + } + EXEC SQL CLOSE u_cursor; + + EXEC SQL DECLARE m_cursor2 CURSOR FOR + SELECT list_id, member_id + FROM imembers + WHERE member_type = 'USER' + ORDER BY list_id; + EXEC SQL OPEN m_cursor2; + while (1) + { + EXEC SQL FETCH m_cursor2 INTO :lid, :id; + if (sqlca.sqlcode) + break; + if ((u = (struct user *) hash_lookup(users, id)) && + (l = hash_lookup(groups, lid))) + { + g = malloc(sizeof(struct grp)); + g->next = u->lists; + u->lists = g; + g->lid = l; + } + } + EXEC SQL CLOSE m_cursor2; + + for (p = &(users->data[users->size - 1]); p >= users->data; p--) + { + for (b = *p; b; b = b->next) + { + u = (struct user *)b->data; + sprintf(buf, "%s:%d", u->name, u->uid); + for (g = u->lists; g; g = g->next) + strcat(buf, g->lid); + b->data = strsave(buf); + fprintf(fd, "%s\n", buf); } } - fclose(fd); - return(1); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + fclose(fd); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } -/* Now do each of the servers, linking the credentials list file and +/* Now do each of the servers, linking the credentials list file and * compiling the quota and dirs files. */ -int do_machs(machs) -struct save_queue *machs; +int do_machs(struct save_queue *machs) { - EXEC SQL BEGIN DECLARE SECTION; - 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; - int prevuid, quotasum, olddev, oldmach; - FILE *fd; - struct hash *machines; - - fprintf(stderr, "Building machine files\n"); - - - machines = create_hash(100); - while (sq_get_data(machs, &machname)) { - EXEC SQL SELECT s.value3, m.mach_id - INTO :listname, :id - FROM serverhosts s, machine m - WHERE s.mach_id = m.mach_id AND m.name = :machname AND - s.service = 'NFS'; - strtrim(machname); - sprintf(f1, "%s/list-%s", nfs_dir, strtrim(listname)); - sprintf(f2, "%s/%s.cred", nfs_dir, machname); - unlink(f2); /* ignore errors on this unlink */ - if (link(f1, f2)) { - fprintf(stderr, "Cannot link %s to %s\n", f1, f2); - exit(MR_OCONFIG); + EXEC SQL BEGIN DECLARE SECTION; + 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; + int prevuid, quotasum, olddev, oldmach; + FILE *fd; + struct hash *machines; + + fprintf(stderr, "Building machine files\n"); + + machines = create_hash(100); + while (sq_get_data(machs, &machname)) + { + EXEC SQL SELECT s.value3, m.mach_id + INTO :listname, :id + FROM serverhosts s, machine m + WHERE s.mach_id = m.mach_id AND m.name = :machname AND + s.service = 'NFS'; + strtrim(machname); + sprintf(f1, "%s/list-%s", nfs_dir, strtrim(listname)); + sprintf(f2, "%s/%s.cred", nfs_dir, machname); + unlink(f2); /* ignore errors on this unlink */ + if (link(f1, f2)) + { + fprintf(stderr, "Cannot link %s to %s\n", f1, f2); + exit(MR_OCONFIG); } - hash_store(machines, id, machname); + hash_store(machines, id, machname); } - - olddev = oldmach = -1; - fd = stdin; - - EXEC SQL DECLARE q_cursor CURSOR FOR - SELECT DISTINCT q.quota, q.entity_id, q.phys_id, n.device, n.mach_id - FROM quota q, nfsphys n - WHERE n.nfsphys_id = q.phys_id AND q.phys_id != 0 AND - n.status < 16 AND q.type = 'USER' - ORDER BY n.mach_id, q.phys_id, q.entity_id; - EXEC SQL OPEN q_cursor; - while (1) { - EXEC SQL FETCH q_cursor INTO :quota, :uid, :flag1, :dev, :flag2; - if (sqlca.sqlcode != 0) break; - if (flag1 != olddev || flag2 != oldmach) { - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - if (flag2 == 0 || !hash_lookup(machines, flag2)) - continue; - if (fd != stdin) - fclose(fd); - olddev = flag1; - oldmach = flag2; - while (cp = strchr(dev, '/')) *cp = '@'; - sprintf(file, "%s/%s.%s.quotas", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); - fd = fopen(file, "w"); - if (!fd) { - fprintf(stderr, "cannot open %s for output\n", file); - exit(MR_OCONFIG); + olddev = oldmach = -1; + fd = stdin; + + EXEC SQL DECLARE q_cursor CURSOR FOR + SELECT DISTINCT q.quota, q.entity_id, q.phys_id, n.device, n.mach_id + FROM quota q, nfsphys n + WHERE n.nfsphys_id = q.phys_id AND q.phys_id != 0 AND + n.status < 16 AND q.type = 'USER' + ORDER BY n.mach_id, q.phys_id, q.entity_id; + EXEC SQL OPEN q_cursor; + while (1) + { + EXEC SQL FETCH q_cursor INTO :quota, :uid, :flag1, :dev, :flag2; + if (sqlca.sqlcode) + break; + if (flag1 != olddev || flag2 != oldmach) + { + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + if (flag2 == 0 || !hash_lookup(machines, flag2)) + continue; + if (fd != stdin) + fclose(fd); + olddev = flag1; + oldmach = flag2; + while (cp = strchr(dev, '/')) + *cp = '@'; + sprintf(file, "%s/%s.%s.quotas", nfs_dir, + hash_lookup(machines, flag2), strtrim(dev)); + fd = fopen(file, "w"); + if (!fd) + { + fprintf(stderr, "cannot open %s for output\n", file); + exit(MR_OCONFIG); } - prevuid = -1; - quotasum = 0; + prevuid = -1; + quotasum = 0; } - if (uid != prevuid) { - if ((cp = hash_lookup(users, prevuid)) && - (cp = strchr(cp, ':'))) - prevuid = atoi(cp+1); - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - prevuid = uid; - quotasum = quota; - } else { - quotasum += quota; + if (uid != prevuid) + { + if ((cp = hash_lookup(users, prevuid)) && + (cp = strchr(cp, ':'))) + prevuid = atoi(cp + 1); + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + prevuid = uid; + quotasum = quota; } + else + quotasum += quota; + } + EXEC SQL CLOSE q_cursor; + if ((cp = hash_lookup(users, prevuid)) && + (cp = strchr(cp, ':'))) + prevuid = atoi(cp + 1); + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + if (fd != stdin && fclose(fd) == EOF) + { + fprintf(stderr, "error closing %s", file); + exit(MR_CCONFIG); } - EXEC SQL CLOSE q_cursor; - if ((cp = hash_lookup(users, prevuid)) && - (cp = strchr(cp, ':'))) - prevuid = atoi(cp+1); - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - if (fd != stdin && fclose(fd) == EOF) { - fprintf(stderr, "error closing %s", file); - exit(MR_CCONFIG); - } - - olddev = oldmach = -1; - fd = stdin; - EXEC SQL DECLARE q_cursor2 CURSOR FOR - SELECT DISTINCT q.quota, q.entity_id, q.phys_id, n.device, n.mach_id, - n.status - FROM quota q, nfsphys n - WHERE n.nfsphys_id = q.phys_id AND q.phys_id != 0 AND - n.status > 15 AND q.type = 'GROUP' - ORDER BY mach_id, phys_id, entity_id; - EXEC SQL OPEN q_cursor2; - while (1) { - EXEC SQL FETCH q_cursor2 INTO :quota, :gid, :flag1, :dev, - :flag2, :flag3; - if (sqlca.sqlcode != 0) break; - if (flag1 != olddev || flag2 != oldmach) { - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - if (flag2 == 0 || !hash_lookup(machines, flag2)) - continue; - if (fd != stdin) - fclose(fd); - olddev = flag1; - oldmach = flag2; - while (cp = strchr(dev, '/')) *cp = '@'; - sprintf(file, "%s/%s.%s.quotas", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); - fd = fopen(file, "w"); - if (!fd) { - fprintf(stderr, "cannot open %s for output\n", file); - exit(MR_OCONFIG); + + olddev = oldmach = -1; + fd = stdin; + EXEC SQL DECLARE q_cursor2 CURSOR FOR + SELECT DISTINCT q.quota, q.entity_id, q.phys_id, n.device, n.mach_id, + n.status + FROM quota q, nfsphys n + WHERE n.nfsphys_id = q.phys_id AND q.phys_id != 0 AND + n.status > 15 AND q.type = 'GROUP' + ORDER BY mach_id, phys_id, entity_id; + EXEC SQL OPEN q_cursor2; + while (1) + { + EXEC SQL FETCH q_cursor2 INTO :quota, :gid, :flag1, :dev, + :flag2, :flag3; + if (sqlca.sqlcode) + break; + if (flag1 != olddev || flag2 != oldmach) + { + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + if (flag2 == 0 || !hash_lookup(machines, flag2)) + continue; + if (fd != stdin) + fclose(fd); + olddev = flag1; + oldmach = flag2; + while (cp = strchr(dev, '/')) + *cp = '@'; + sprintf(file, "%s/%s.%s.quotas", nfs_dir, + hash_lookup(machines, flag2), strtrim(dev)); + fd = fopen(file, "w"); + if (!fd) + { + fprintf(stderr, "cannot open %s for output\n", file); + exit(MR_OCONFIG); } - prevuid = -1; - quotasum = 0; + prevuid = -1; + quotasum = 0; } - if (gid != prevuid) { - if (cp = hash_lookup(groups, prevuid)) - prevuid = atoi(cp + 1); - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - prevuid = gid; - quotasum = quota; - } else { - quotasum += quota; + if (gid != prevuid) + { + if (cp = hash_lookup(groups, prevuid)) + prevuid = atoi(cp + 1); + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + prevuid = gid; + quotasum = quota; } + else + quotasum += quota; + } + EXEC SQL CLOSE q_cursor2; + if ((cp = hash_lookup(groups, prevuid))) + prevuid = atoi(cp + 1); + if (quotasum) + fprintf(fd, "%d %d\n", prevuid, quotasum); + if (fd != stdin && fclose(fd) == EOF) + { + fprintf(stderr, "error closing %s", file); + exit(MR_CCONFIG); } - EXEC SQL CLOSE q_cursor2; - if (cp = hash_lookup(groups, prevuid)) - prevuid = atoi(cp + 1); - if (quotasum) - fprintf(fd, "%d %d\n", prevuid, quotasum); - if (fd != stdin && fclose(fd) == EOF) { - fprintf(stderr, "error closing %s", file); - exit(MR_CCONFIG); - } - - olddev = oldmach = -1; - fd = stdin; - - EXEC SQL DECLARE q_cursor3 CURSOR FOR - 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 - l.list_id = f.owners AND - f.createflg != 0 AND f.phys_id != 0 AND - f.type = 'NFS' AND - f.phys_id = n.nfsphys_id - ORDER BY mach_id, phys_id; - EXEC SQL OPEN q_cursor3; - while (1) { - EXEC SQL FETCH q_cursor3 INTO :dir, :fstype, :uid, :gid, :flag1, - :flag2, :dev; - if (sqlca.sqlcode != 0) break; - if ((flag1 != olddev || flag2 != oldmach) && - hash_lookup(machines, flag2)) { - if (fd != stdin) - fclose(fd); - olddev = flag1; - oldmach = flag2; - while (cp = strchr(dev, '/')) *cp = '@'; - sprintf(file, "%s/%s.%s.dirs", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); - fd = fopen(file, "w"); - if (!fd) { - fprintf(stderr, "cannot open %s for output\n", file); - exit(MR_OCONFIG); + + olddev = oldmach = -1; + fd = stdin; + + EXEC SQL DECLARE q_cursor3 CURSOR FOR + 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 l.list_id = f.owners + AND f.createflg != 0 AND f.phys_id != 0 AND f.type = 'NFS' + AND f.phys_id = n.nfsphys_id + ORDER BY mach_id, phys_id; + EXEC SQL OPEN q_cursor3; + while (1) + { + EXEC SQL FETCH q_cursor3 INTO :dir, :fstype, :uid, :gid, :flag1, + :flag2, :dev; + if (sqlca.sqlcode) + break; + if ((flag1 != olddev || flag2 != oldmach) && + hash_lookup(machines, flag2)) + { + if (fd != stdin) + fclose(fd); + olddev = flag1; + oldmach = flag2; + while (cp = strchr(dev, '/')) + *cp = '@'; + sprintf(file, "%s/%s.%s.dirs", nfs_dir, + hash_lookup(machines, flag2), strtrim(dev)); + fd = fopen(file, "w"); + if (!fd) + { + fprintf(stderr, "cannot open %s for output\n", file); + exit(MR_OCONFIG); } } - fprintf(fd, "%s %d %d %s\n", strtrim(dir), uid, gid, strtrim(fstype)); - } - EXEC SQL CLOSE q_cursor3; - if (fclose(fd) == EOF) { - fprintf(stderr, "error closing %s", file); - exit(MR_CCONFIG); + fprintf(fd, "%s %d %d %s\n", strtrim(dir), uid, gid, strtrim(fstype)); + } + EXEC SQL CLOSE q_cursor3; + if (fclose(fd) == EOF) + { + fprintf(stderr, "error closing %s", file); + exit(MR_CCONFIG); } - return(1); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + return 1; +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/nfs.sh b/gen/nfs.sh index af3fcef8..1a4baaa1 100644 --- a/gen/nfs.sh +++ b/gen/nfs.sh @@ -27,7 +27,7 @@ rm -rf $SRC_DIR mkdir $SRC_DIR chmod 755 $SRC_DIR -# Note that since MR is going to be exported, assuming .MIT.EDU is +# Note that since MR is going to be exported, assuming .MIT.EDU is # incorrect. For now however, it is probably not worth the effort # to canonicalize the hostname, especially with the upcoming update # protocol redesign diff --git a/gen/passwd.pc b/gen/passwd.pc index d80d7aab..618a00ca 100644 --- a/gen/passwd.pc +++ b/gen/passwd.pc @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -16,84 +17,90 @@ #include EXEC SQL INCLUDE sqlca; -extern int errno; char *whoami = "passwd.gen"; char *db = "moira/moira"; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *out = stdout; - char *outf = NULL, outft[64]; - struct stat sb; - int flag; - EXEC SQL BEGIN DECLARE SECTION; - char login[9], shell[33], fullname[33], oa[17], op[13], hp[17]; - char nickname[17]; - int uid; - EXEC SQL END DECLARE SECTION; + FILE *out = stdout; + char *outf = NULL, outft[64]; + struct stat sb; + int flag; + EXEC SQL BEGIN DECLARE SECTION; + char login[9], shell[33], fullname[33], oa[17], op[13], hp[17]; + char nickname[17]; + int uid; + EXEC SQL END DECLARE SECTION; - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db; - 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); + 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); + outf = argv[1]; + sprintf(outft, "%s~", outf); + if (!(out = fopen(outft, "w"))) + { + 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; } + 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 WHENEVER SQLERROR GOTO sqlerr; - EXEC SQL DECLARE x CURSOR FOR SELECT - login, unix_uid, shell, fullname, office_addr, nickname, - office_phone, home_phone - FROM users WHERE status = 1; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname, + EXEC SQL DECLARE x CURSOR FOR SELECT + login, unix_uid, shell, fullname, office_addr, nickname, + office_phone, home_phone + FROM users WHERE status = 1; + EXEC SQL OPEN x; + while (1) + { + EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname, :op, :hp; - if (sqlca.sqlcode != 0) break; - strtrim(login); - strtrim(fullname); - strtrim(nickname); - strtrim(oa); - strtrim(op); - strtrim(hp); - strtrim(shell); - fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n", - login, uid, fullname, nickname, oa, op, hp, login, shell); + if (sqlca.sqlcode) + break; + strtrim(login); + strtrim(fullname); + strtrim(nickname); + strtrim(oa); + strtrim(op); + strtrim(hp); + strtrim(shell); + fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n", + login, uid, fullname, nickname, oa, op, hp, login, shell); } - EXEC SQL CLOSE x; + EXEC SQL CLOSE x; - EXEC SQL COMMIT; + EXEC SQL COMMIT; - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); + if (fclose(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); + if (outf) + fix_file(outf); + exit(MR_SUCCESS); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/pobox.pc b/gen/pobox.pc index 9dc367bc..c164080c 100644 --- a/gen/pobox.pc +++ b/gen/pobox.pc @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -16,103 +17,114 @@ #include EXEC SQL INCLUDE sqlca; -extern int errno; char *whoami = "pobox.gen"; char *db = "moira/moira"; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *out = stdout; - char *outf = NULL, outft[64]; - struct stat sb; - int flag, i; - EXEC SQL BEGIN DECLARE SECTION; - char login[9], id[18], string[257]; - EXEC SQL END DECLARE SECTION; + FILE *out = stdout; + char *outf = NULL, outft[64]; + struct stat sb; + int flag, i; + EXEC SQL BEGIN DECLARE SECTION; + char login[9], id[18], string[257]; + EXEC SQL END DECLARE SECTION; - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db; - 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); + 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); + outf = argv[1]; + sprintf(outft, "%s~", outf); + if (!(out = fopen(outft, "w"))) + { + 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; } + 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; + /* 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 x CURSOR FOR SELECT - clearid, login - FROM users WHERE status != 3 and potype='POP'; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :id, :login; - if (sqlca.sqlcode != 0) break; - strtrim(login); - strtrim(id); - if (isdigit(id[0])) - fprintf(out, "%s %s@MIT.EDU\n", id, login); + EXEC SQL DECLARE x CURSOR FOR SELECT + clearid, login + FROM users WHERE status != 3 and potype = 'POP'; + EXEC SQL OPEN x; + while (1) + { + EXEC SQL FETCH x INTO :id, :login; + if (sqlca.sqlcode) + break; + strtrim(login); + strtrim(id); + if (isdigit(id[0])) + fprintf(out, "%s %s@MIT.EDU\n", id, login); } - EXEC SQL CLOSE x; + EXEC SQL CLOSE x; - EXEC SQL DECLARE y CURSOR FOR SELECT - u.clearid, s.string - FROM users u, strings s - WHERE u.status != 3 and u.potype='SMTP' and u.box_id = s.string_id; - EXEC SQL OPEN y; - while (1) { - EXEC SQL FETCH y INTO :id, :string; - if (sqlca.sqlcode != 0) break; - strtrim(string); - strtrim(id); - if (isdigit(id[0])) { - if ((i = strlen(string)) > 7 && - !strcasecmp(".local", string + i - 6)) { - string[i-6] = 0; - fprintf(out, "%s %s.mit.edu\n", id, string); - } else if ( !strchr(string, '@') ) { - fprintf(out, "%s %s@mit.edu\n", id, string); - } else - fprintf(out, "%s %s\n", id, string); + EXEC SQL DECLARE y CURSOR FOR SELECT + u.clearid, s.string + FROM users u, strings s + WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id; + EXEC SQL OPEN y; + while (1) + { + EXEC SQL FETCH y INTO :id, :string; + if (sqlca.sqlcode) + break; + strtrim(string); + strtrim(id); + if (isdigit(id[0])) + { + if ((i = strlen(string)) > 7 && + !strcasecmp(".local", string + i - 6)) + { + string[i - 6] = '\0'; + fprintf(out, "%s %s.mit.edu\n", id, string); + } + else if (!strchr(string, '@')) + fprintf(out, "%s %s@mit.edu\n", id, string); + else + fprintf(out, "%s %s\n", id, string); } } - EXEC SQL CLOSE y; + EXEC SQL CLOSE y; - EXEC SQL COMMIT; + EXEC SQL COMMIT; - if (fclose(out)) { - perror("close failed"); - exit(MR_CCONFIG); + if (fclose(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - if (outf) - fix_file(outf); - exit(MR_SUCCESS); + if (outf) + fix_file(outf); + exit(MR_SUCCESS); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/setquota.c b/gen/setquota.c index 46312dea..eb045ca2 100644 --- a/gen/setquota.c +++ b/gen/setquota.c @@ -10,25 +10,6 @@ * Uses the NFS style quota system/quotactl rather than the Melbourne * quota system. * - * $Log$ - * Revision 1.6 1990-03-07 17:41:22 mar - * fix proc delcaration to pass cc - * - * Revision 1.5 90/03/06 15:59:08 jnrees - * x*.5 replaced with x/2; - * x*1.2 with (x*6)/5; - * This avoids linking in the floating-point library. - * - * Revision 1.4 90/01/27 19:48:05 jnrees - * Grows quotas file if necessary - * Allows setting quota for a range of uid's. - * - * Revision 1.3 88/10/06 10:46:08 raeburn - * (mar) Don't expire timers on users currently over quota. - * - * Revision 1.1 87/09/04 21:32:47 wesommer - * Initial revision - * */ #ifndef lint @@ -50,134 +31,143 @@ static char device[20]; static char quotafilename[30]; static struct dqblk zblk = {0}; -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - int uid, uid_low, uid_high, soft_quota, qfd; - struct dqblk db, odb; - int uflag = 0; - int range_mode = 0; - - while (argc > 4 && *argv[1] == '-') { - switch(argv[1][1]) { - case 'u': - uflag = 1; - --argc; - ++argv; - break; - case 'r': - range_mode = 1; - --argc; - ++argv; - break; - default: - goto usage; - } - } - - if ((argc != 4 && !range_mode) || (argc != 5 && range_mode)) { - usage: - fprintf(stderr, "usage: setquota [-u] special uid quota\n\ - setquota -r [-u] special uid_low uid_high quota\n\ --u means set limit to + cur usage\n\ -special is a mounted filesystem special device\n\ -quota is in 1KB units\n"); - exit(1); - } - - if ((!range_mode && - (!isdigit(*argv[2]) || !isdigit(*argv[3]))) || - (range_mode && - (!isdigit(*argv[2]) || !isdigit(*argv[3]) || - !isdigit(*argv[4])))) { - fprintf(stderr, "setquota: uid and quota must be numeric\n"); + int uid, uid_low, uid_high, soft_quota, qfd; + struct dqblk db, odb; + int uflag = 0; + int range_mode = 0; + + while (argc > 4 && *argv[1] == '-') + { + switch (argv[1][1]) + { + case 'u': + uflag = 1; + --argc; + ++argv; + break; + case 'r': + range_mode = 1; + --argc; + ++argv; + break; + default: goto usage; } + } - if (range_mode){ - uid_low = atoi(argv[2]); - uid_high = atoi(argv[3]); - soft_quota = atoi(argv[4]); - if (uid_low > uid_high){ - fprintf(stderr, "setquota: range error\n"); - exit(1); - } - } - else{ - uid_low = uid_high = atoi(argv[2]); - soft_quota = atoi(argv[3]); - } - - get_device(argv[1]); + if ((argc != 4 && !range_mode) || (argc != 5 && range_mode)) + { + usage: + fprintf(stderr, "usage: setquota [-u] special uid quota\n" + "setquota -r [-u] special uid_low uid_high quota\n" + "-u means set limit to + cur usage\n" + "special is a mounted filesystem special device\n" + "quota is in 1KB units\n"); + exit(1); + } - for(uid = uid_low; uid <= uid_high; uid++){ + if ((!range_mode && (!isdigit(*argv[2]) || !isdigit(*argv[3]))) || + (range_mode && (!isdigit(*argv[2]) || !isdigit(*argv[3]) || + !isdigit(*argv[4])))) + { + fprintf(stderr, "setquota: uid and quota must be numeric\n"); + goto usage; + } - if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) { + if (range_mode) + { + uid_low = atoi(argv[2]); + uid_high = atoi(argv[3]); + soft_quota = atoi(argv[4]); + if (uid_low > uid_high) + { + fprintf(stderr, "setquota: range error\n"); + exit(1); + } + } + else + { + uid_low = uid_high = atoi(argv[2]); + soft_quota = atoi(argv[3]); + } + + get_device(argv[1]); - if (!(qfd = open(quotafilename, O_RDWR))){ + for (uid = uid_low; uid <= uid_high; uid++) + { + if (quotactl(Q_GETQUOTA, device, uid, &odb)) + { + if (!(qfd = open(quotafilename, O_RDWR))) + { perror("No quota file"); exit(1); } - lseek(qfd, 32767*sizeof(struct dqblk), L_SET); - write(qfd, &zblk, sizeof(struct dqblk)); - close(qfd); + lseek(qfd, 32767 * sizeof(struct dqblk), L_SET); + write(qfd, &zblk, sizeof(struct dqblk)); + close(qfd); - if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) { + if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) + { perror("Can't get current quota info"); exit(1); } - } - - db.dqb_bsoftlimit = soft_quota; - db.dqb_bhardlimit = (db.dqb_bsoftlimit * 6) / 5; - db.dqb_fsoftlimit = soft_quota / 2; - db.dqb_fhardlimit = (db.dqb_fsoftlimit * 6) / 5; - db.dqb_btimelimit = odb.dqb_btimelimit; - db.dqb_ftimelimit = odb.dqb_ftimelimit; - - db.dqb_bsoftlimit *= btodb(1024); - db.dqb_bhardlimit *= btodb(1024); - - if (uflag) { - db.dqb_bhardlimit += odb.dqb_curblocks; - db.dqb_bsoftlimit += odb.dqb_curblocks; - db.dqb_fhardlimit += odb.dqb_curfiles; - db.dqb_fsoftlimit += odb.dqb_curfiles; - } - - if (quotactl(Q_SETQLIM, device, uid, &db) < 0) { - fprintf (stderr, "quotactl: %d on ", uid); - perror (device); - exit (1); - } } - - if (quotactl(Q_SYNC, device, 0, 0) < 0) { - perror ("can't sync disk quota"); - exit (1); + + db.dqb_bsoftlimit = soft_quota; + db.dqb_bhardlimit = (db.dqb_bsoftlimit * 6) / 5; + db.dqb_fsoftlimit = soft_quota / 2; + db.dqb_fhardlimit = (db.dqb_fsoftlimit * 6) / 5; + db.dqb_btimelimit = odb.dqb_btimelimit; + db.dqb_ftimelimit = odb.dqb_ftimelimit; + + db.dqb_bsoftlimit *= btodb(1024); + db.dqb_bhardlimit *= btodb(1024); + + if (uflag) + { + db.dqb_bhardlimit += odb.dqb_curblocks; + db.dqb_bsoftlimit += odb.dqb_curblocks; + db.dqb_fhardlimit += odb.dqb_curfiles; + db.dqb_fsoftlimit += odb.dqb_curfiles; } - exit (0); + if (quotactl(Q_SETQLIM, device, uid, &db) < 0) + { + fprintf(stderr, "quotactl: %d on ", uid); + perror(device); + exit(1); + } + } + + if (quotactl(Q_SYNC, device, 0, 0) < 0) + { + perror("can't sync disk quota"); + exit(1); + } + + exit(0); } - -get_device(device_or_dir) -char *device_or_dir; + +get_device(char *device_or_dir) { register struct mntent *mntp; FILE *fstab; fstab = setmntent(MNTTAB, "r"); - while(mntp = getmntent(fstab)){ - if ((strcmp(mntp->mnt_fsname, device_or_dir) == 0) || - (strcmp(mntp->mnt_dir, device_or_dir) == 0)){ - strcpy(device, mntp->mnt_fsname); - sprintf(quotafilename, "%s/quotas", mntp->mnt_dir); - endmntent(fstab); - return; + while (mntp = getmntent(fstab)) + { + if (!strcmp(mntp->mnt_fsname, device_or_dir) || + !strcmp(mntp->mnt_dir, device_or_dir)) + { + strcpy(device, mntp->mnt_fsname); + sprintf(quotafilename, "%s/quotas", mntp->mnt_dir); + endmntent(fstab); + return; + } } - } fprintf(stderr, "%s not mounted.\n", device_or_dir); exit(1); } diff --git a/gen/util.c b/gen/util.c index 5c70fffa..2640b2ca 100644 --- a/gen/util.c +++ b/gen/util.c @@ -16,69 +16,72 @@ extern void sqlglm(char buf[], int *, int *); -fix_file(targetfile) -char *targetfile; +fix_file(char *targetfile) { - char oldfile[64], filename[64]; + char oldfile[64], filename[64]; - sprintf(oldfile, "%s.old", targetfile); - sprintf(filename, "%s~", targetfile); - if (rename(targetfile, oldfile) == 0) { - if (rename(filename, targetfile) < 0) { - rename(oldfile, targetfile); - perror("Unable to install new file (rename failed)\n"); - fprintf(stderr, "Filename = %s\n", targetfile); - exit(MR_CCONFIG); + sprintf(oldfile, "%s.old", targetfile); + sprintf(filename, "%s~", targetfile); + if (rename(targetfile, oldfile) == 0) + { + if (rename(filename, targetfile) < 0) + { + rename(oldfile, targetfile); + perror("Unable to install new file (rename failed)\n"); + fprintf(stderr, "Filename = %s\n", targetfile); + exit(MR_CCONFIG); } - } else { - if (rename(filename, targetfile) < 0) { - perror("Unable to rename old file\n"); - fprintf(stderr, "Filename = %s\n", targetfile); - exit(MR_CCONFIG); + } + else + { + if (rename(filename, targetfile) < 0) + { + perror("Unable to rename old file\n"); + fprintf(stderr, "Filename = %s\n", targetfile); + exit(MR_CCONFIG); } } - unlink(oldfile); + unlink(oldfile); } -char *dequote(s) -register char *s; +char *dequote(register char *s) { - char *last = s; + char *last = s; - while (*s) { - if (*s == '"') - *s = '\''; - else if (*s != ' ') - last = s; - s++; + while (*s) + { + if (*s == '"') + *s = '\''; + else if (*s != ' ') + last = s; + s++; } - if (*last == ' ') - *last = '\0'; - else - *(++last) = '\0'; - return(s); + if (*last == ' ') + *last = '\0'; + else + *(++last) = '\0'; + return s; } - -db_error(code) -int code; +db_error(int code) { - extern char *whoami; - char buf[256]; - int bufsize=256, len=0; + extern char *whoami; + char buf[256]; + int bufsize = 256, len = 0; - if (code == -1013) { - com_err(whoami, 0, "build cancelled by user"); - exit(MR_ABORT); + if (code == -1013) + { + com_err(whoami, 0, "build cancelled by user"); + exit(MR_ABORT); } - 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); + 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/warehouse.pc b/gen/warehouse.pc index 0aba5895..cccb6b8e 100644 --- a/gen/warehouse.pc +++ b/gen/warehouse.pc @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -22,9 +23,9 @@ #include #include #include +#include EXEC SQL INCLUDE sqlca; -extern int errno; char *whoami = "warehouse.gen"; char *db = "moira/moira"; @@ -34,135 +35,147 @@ char *db = "moira/moira"; char warehouse_dir[128]; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - int out = 1 /* stdout */; - char *outf = NULL, outft[64]; - char control_fn[80], cmd[256]; - FILE *f; - struct stat sb; - int flag1; - SigInfo si; - struct timeval now; - int records = 0; - EXEC SQL BEGIN DECLARE SECTION; - char login[9], sig[257], id[17], kname[257]; - char fname[17], lname[17], middle[17]; - EXEC SQL VAR sig IS STRING(257); - int timestamp, sigwho; - struct { char login[12]; - char id[12]; - char fname[20]; - char lname[20]; - char middle[20]; - char sig[256]; - } outrec; - EXEC SQL END DECLARE SECTION; - - initialize_sms_error_table (); - - sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR); - - EXEC SQL CONNECT :db; - - if (argc == 2) { - if (stat(argv[1], &sb) == 0) { - if (ModDiff (&flag1, "users", sb.st_mtime) == 0 && - flag1 < 0) { - fprintf(stderr, "File %s does not need to be rebuilt.\n", - argv[1]); - exit(MR_NO_CHANGE); + int out = STDOUT_FILENO; + char *outf = NULL, outft[64]; + char control_fn[80], cmd[256]; + FILE *f; + struct stat sb; + int flag1; + SigInfo si; + struct timeval now; + int records = 0; + EXEC SQL BEGIN DECLARE SECTION; + char login[9], sig[257], id[17], kname[257]; + char fname[17], lname[17], middle[17]; + EXEC SQL VAR sig IS STRING(257); + int timestamp, sigwho; + struct { + char login[12]; + char id[12]; + char fname[20]; + char lname[20]; + char middle[20]; + char sig[256]; + } outrec; + EXEC SQL END DECLARE SECTION; + + initialize_sms_error_table(); + + sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR); + + EXEC SQL CONNECT :db; + + if (argc == 2) + { + if (stat(argv[1], &sb) == 0) + { + if (ModDiff(&flag1, "users", sb.st_mtime) == 0 && flag1 < 0) + { + fprintf(stderr, "File %s does not need to be rebuilt.\n", + argv[1]); + exit(MR_NO_CHANGE); } } - outf = argv[1]; - sprintf(outft, "%s/username_id.map", warehouse_dir); - if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); + outf = argv[1]; + sprintf(outft, "%s/username_id.map", warehouse_dir); + if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) + { + 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; } + 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; - /* 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 x CURSOR FOR - SELECT u.login, u.clearid, u.signature, u.sigdate, s.string, u.sigwho, - u.first, u.last, u.middle - FROM users u, strings s - WHERE (u.status = 1 or u.status=2 or u.status=5 or - u.status=6 or u.status=7) - and u.sigwho = s.string_id; - EXEC SQL OPEN x; - while (1) { - EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname, :sigwho, - :fname, :lname, :middle; - if (sqlca.sqlcode != 0) break; - if (id == 0) continue; - if (!isdigit(id[1])) continue; - strtrim(login); - strtrim(id); - strtrim(kname); - strtrim(fname); - strtrim(lname); - strtrim(middle); - memset(&outrec, 0, sizeof(outrec)); - strcpy(outrec.login, login); - strcpy(outrec.id, id); - strcpy(outrec.fname, fname); - strcpy(outrec.lname, lname); - strcpy(outrec.middle, middle); - if (sigwho) { - si.timestamp = timestamp; - si.SigInfoVersion = 0; /* XXXXXX this isn't used */ - kname_parse(si.pname, si.pinst, si.prealm, kname); - si.rawsig = (unsigned char *)sig; - GDSS_Recompose(&si, outrec.sig); + EXEC SQL DECLARE x CURSOR FOR + SELECT u.login, u.clearid, u.signature, u.sigdate, s.string, u.sigwho, + u.first, u.last, u.middle + FROM users u, strings s + WHERE (u.status = 1 or u.status = 2 or u.status = 5 OR + u.status = 6 or u.status = 7) + AND u.sigwho = s.string_id; + EXEC SQL OPEN x; + while (1) + { + EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname, :sigwho, + :fname, :lname, :middle; + if (sqlca.sqlcode) + break; + if (id == 0) + continue; + if (!isdigit(id[1])) + continue; + strtrim(login); + strtrim(id); + strtrim(kname); + strtrim(fname); + strtrim(lname); + strtrim(middle); + memset(&outrec, 0, sizeof(outrec)); + strcpy(outrec.login, login); + strcpy(outrec.id, id); + strcpy(outrec.fname, fname); + strcpy(outrec.lname, lname); + strcpy(outrec.middle, middle); + if (sigwho) + { + si.timestamp = timestamp; + si.SigInfoVersion = 0; /* XXXXXX this isn't used */ + kname_parse(si.pname, si.pinst, si.prealm, kname); + si.rawsig = (unsigned char *)sig; + GDSS_Recompose(&si, outrec.sig); } - write(out, &outrec, sizeof(outrec)); - records++; + write(out, &outrec, sizeof(outrec)); + records++; } - EXEC SQL CLOSE x; + EXEC SQL CLOSE x; - EXEC SQL COMMIT; + EXEC SQL COMMIT; - if (close(out)) { - perror("close failed"); - exit(MR_CCONFIG); + if (close(out)) + { + perror("close failed"); + exit(MR_CCONFIG); } - sprintf(control_fn, "%s/username_id.ctl", warehouse_dir); + sprintf(control_fn, "%s/username_id.ctl", warehouse_dir); - f = fopen(control_fn, "w"); - if (!f) { - perror("creating username_id control file"); - exit(MR_OCONFIG); + f = fopen(control_fn, "w"); + if (!f) + { + perror("creating username_id control file"); + exit(MR_OCONFIG); } - fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n"); - fprintf(f, "%d records\n", records); - fprintf(f, "%d bytes\n", records * (12+12+20+20+20+256)); - fprintf(f, "Full feed\n"); - fprintf(f, "Fixed format -- binary\n"); - fclose(f); - if (outf) { - fprintf(stderr, "Building tar file.\n"); - sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s", - warehouse_dir, outf); - if (system(cmd)) - exit(MR_TAR_FAIL); + fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n"); + fprintf(f, "%d records\n", records); + fprintf(f, "%d bytes\n", records * (12 + 12 + 20 + 20 + 20 + 256)); + fprintf(f, "Full feed\n"); + fprintf(f, "Fixed format -- binary\n"); + fclose(f); + if (outf) + { + fprintf(stderr, "Building tar file.\n"); + sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s", + warehouse_dir, outf); + if (system(cmd)) + exit(MR_TAR_FAIL); } - - exit(MR_SUCCESS); - sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); + exit(MR_SUCCESS); + +sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); } diff --git a/gen/zero_quotas b/gen/zero_quotas index 02567907..ee7f001a 100644 --- a/gen/zero_quotas +++ b/gen/zero_quotas @@ -18,13 +18,13 @@ if ( -f /etc/zero_old_quotas ) then while (1) # set args = $< will NOT work. $< will be treated as a single word set args = `echo $<` - + if (${#args} != 2) break # end of input set uid = $args[1] @ checksorted = ($current_uid <= $uid) - if (checksorted == 0) then + if (checksorted == 0) then echo "Input not sorted" exit $MR_SETQUOTA endif @@ -39,10 +39,10 @@ if ( -f /etc/zero_old_quotas ) then @ current_uid = $uid + 1 end - + # zero all remaining quotas, except for nobody (32767). if ($current_uid != 32767) setquota -r $dev $current_uid 32766 0 - + endif exit 0 diff --git a/include/moira_site.h b/include/moira_site.h index 18804f77..4e0cf559 100644 --- a/include/moira_site.h +++ b/include/moira_site.h @@ -1,10 +1,10 @@ /* - * This file contains all definitions that allow easy access to + * This file contains all definitions that allow easy access to * elements returned by most of the @i[Moira] queries. It also defines * the default server location and the directories used on the server. * * If the order of the arguments in the @i[Moira] queries change (again) - * then all that needs to be changed are the values of these items + * then all that needs to be changed are the values of these items * and all should be well, (hopefully :-). * * Chris D. Peterson - kit@athena @@ -13,10 +13,10 @@ * $Source$ * $Author$ * $Header$ - * + * * Copyright 1988 by the Massachusetts Institute of Technology. * - * For further information on copyright and distribution + * For further information on copyright and distribution * see the file mit-copyright.h */ @@ -224,7 +224,7 @@ #define Q_FILESYS 0 #define Q_TYPE 1 #define Q_NAME 2 -#define Q_QUOTA 3 +#define Q_QUOTA 3 #define Q_DIRECTORY 4 #define Q_MACHINE 5 #define Q_MODTIME 6 @@ -318,7 +318,7 @@ #define U_LAST 3 #define U_FIRST 4 #define U_MIDDLE 5 -#define U_STATE 6 +#define U_STATE 6 #define U_MITID 7 #define U_CLASS 8 #define U_COMMENT 9 diff --git a/incremental/afs.c b/incremental/afs.c index b9dde505..f9ea3313 100644 --- a/incremental/afs.c +++ b/incremental/afs.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -57,296 +58,314 @@ extern long pr_SIdToName(); static char tbl_buf[1024]; static struct member { - int op; - char list[33]; - char type[9]; - char member[129]; - struct member *next; -} *member_head = 0; - -static int mr_connections=0; - -main(argc, argv) -char **argv; -int argc; + int op; + char list[33]; + char type[9]; + char member[129]; + struct member *next; +} *member_head = NULL; + +static int mr_connections = 0; + +int main(int argc, char **argv) { - int beforec, afterc, i; - char *table, **before, **after; + int beforec, afterc, i; + char *table, **before, **after; - for (i = getdtablesize() - 1; i > 2; i--) - close(i); + for (i = getdtablesize() - 1; i > 2; i--) + close(i); - whoami = ((whoami = strrchr(argv[0], '/')) ? whoami+1 : argv[0]); + whoami = ((whoami = strrchr(argv[0], '/')) ? whoami+1 : argv[0]); - table = argv[1]; - beforec = atoi(argv[2]); - before = &argv[4]; - afterc = atoi(argv[3]); - after = &argv[4 + beforec]; + table = argv[1]; + beforec = atoi(argv[2]); + before = &argv[4]; + afterc = atoi(argv[3]); + after = &argv[4 + beforec]; - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); - strcpy(tbl_buf, table); - strcat(tbl_buf, " ("); - for (i = 0; i < beforec; i++) { - if (i > 0) - strcat(tbl_buf, ","); - strcat(tbl_buf, before[i]); - } - strcat(tbl_buf, ")->("); - for (i = 0; i < afterc; i++) { - if (i > 0) - strcat(tbl_buf, ","); - strcat(tbl_buf, after[i]); + strcpy(tbl_buf, table); + strcat(tbl_buf, " ("); + for (i = 0; i < beforec; i++) + { + if (i > 0) + strcat(tbl_buf, ","); + strcat(tbl_buf, before[i]); } - strcat(tbl_buf, ")"); -#ifdef DEBUG - com_err(whoami, 0, "%s", tbl_buf); -#endif - - initialize_sms_error_table(); - initialize_krb_error_table(); - - if (!strcmp(table, "users")) { - do_user(before, beforec, after, afterc); - } else if (!strcmp(table, "list")) { - do_list(before, beforec, after, afterc); - } else if (!strcmp(table, "imembers")) { - do_member(before, beforec, after, afterc); - } else if (!strcmp(table, "filesys")) { - do_filesys(before, beforec, after, afterc); - } else if (!strcmp(table, "quota")) { - do_quota(before, beforec, after, afterc); + strcat(tbl_buf, ")->("); + for (i = 0; i < afterc; i++) + { + if (i > 0) + strcat(tbl_buf, ","); + strcat(tbl_buf, after[i]); } - exit(0); + strcat(tbl_buf, ")"); + + initialize_sms_error_table(); + initialize_krb_error_table(); + + if (!strcmp(table, "users")) + do_user(before, beforec, after, afterc); + else if (!strcmp(table, "list")) + do_list(before, beforec, after, afterc); + else if (!strcmp(table, "imembers")) + do_member(before, beforec, after, afterc); + else if (!strcmp(table, "filesys")) + do_filesys(before, beforec, after, afterc); + else if (!strcmp(table, "quota")) + do_quota(before, beforec, after, afterc); + + exit(0); } -do_user(before, beforec, after, afterc) -char **before; -int beforec; -char **after; -int afterc; +do_user(char **before, int beforec, char **after, int afterc) { - int astate, bstate, auid, buid, code; - char *av[2]; - - auid = buid = astate = bstate = 0; - if (afterc > U_STATE) astate = atoi(after[U_STATE]); - if (beforec > U_STATE) bstate = atoi(before[U_STATE]); - if (afterc > U_UID) auid = atoi(after[U_UID]); - if (beforec > U_UID) buid = atoi(before[U_UID]); - - /* We consider "half-registered" users to be active */ - if (astate == 2) astate = 1; - if (bstate == 2) bstate = 1; - - if (astate != 1 && bstate != 1) /* inactive user */ - return; + int astate, bstate, auid, buid, code; + char *av[2]; + + auid = buid = astate = bstate = 0; + if (afterc > U_STATE) + astate = atoi(after[U_STATE]); + if (beforec > U_STATE) + bstate = atoi(before[U_STATE]); + if (afterc > U_UID) + auid = atoi(after[U_UID]); + if (beforec > U_UID) + buid = atoi(before[U_UID]); + + /* We consider "half-registered" users to be active */ + if (astate == 2) + astate = 1; + if (bstate == 2) + bstate = 1; + + if (astate != 1 && bstate != 1) /* inactive user */ + return; - if (astate == bstate && auid == buid && - !strcmp(before[U_NAME], after[U_NAME])) - /* No AFS related attributes have changed */ - return; + if (astate == bstate && auid == buid && + !strcmp(before[U_NAME], after[U_NAME])) + /* No AFS related attributes have changed */ + return; - if (astate == bstate) { - /* Only a modify has to be done */ - com_err(whoami, 0, "Changing user %s (uid %d) to %s (uid %d)", - before[U_NAME], buid, after[U_NAME], auid); - - code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, ""); - if (code) { - critical_alert("incremental", - "Couldn't change user %s (id %d) to %s (id %d): %s", - before[U_NAME], buid, after[U_NAME], auid, - error_message(code)); + if (astate == bstate) + { + /* Only a modify has to be done */ + com_err(whoami, 0, "Changing user %s (uid %d) to %s (uid %d)", + before[U_NAME], buid, after[U_NAME], auid); + + code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, ""); + if (code) + { + critical_alert("incremental", + "Couldn't change user %s (id %d) to %s (id %d): %s", + before[U_NAME], buid, after[U_NAME], auid, + error_message(code)); } - return; + return; } - if (bstate == 1) { - com_err(whoami, 0, "Deleting user %s (uid %d)", - before[U_NAME], buid); - - code = pr_try(pr_DeleteByID, buid); - if (code && code != PRNOENT) { - critical_alert("incremental", - "Couldn't delete user %s (id %d): %s", - before[U_NAME], buid, error_message(code)); + if (bstate == 1) + { + com_err(whoami, 0, "Deleting user %s (uid %d)", + before[U_NAME], buid); + + code = pr_try(pr_DeleteByID, buid); + if (code && code != PRNOENT) + { + critical_alert("incremental", "Couldn't delete user %s (id %d): %s", + before[U_NAME], buid, error_message(code)); } - return; + return; } - if (astate == 1) { - com_err(whoami, 0, "%s user %s (uid %d)", - ((bstate != 0) ? "Reactivating" : "Creating"), - after[U_NAME], auid); - - code = pr_try(pr_CreateUser, after[U_NAME], &auid); - /* if we get PRIDEXIST, it's only an error if the username - doesn't match (otherwise it just means the user was deleted - from Moira but not AFS */ - if (code == PRIDEXIST) { - char ename[255]; - - if (pr_try(pr_SIdToName, auid, ename) == 0 && - !strcmp(after[U_NAME], ename)) - return; - } - if (code) { - critical_alert("incremental", - "Couldn't create user %s (id %d): %s", - after[U_NAME], auid, error_message(code)); + if (astate == 1) + { + com_err(whoami, 0, "%s user %s (uid %d)", + ((bstate != 0) ? "Reactivating" : "Creating"), + after[U_NAME], auid); + + code = pr_try(pr_CreateUser, after[U_NAME], &auid); + /* if we get PRIDEXIST, it's only an error if the username + doesn't match (otherwise it just means the user was deleted + from Moira but not AFS */ + if (code == PRIDEXIST) + { + char ename[255]; + + if (pr_try(pr_SIdToName, auid, ename) == 0 && + !strcmp(after[U_NAME], ename)) return; } + if (code) + { + critical_alert("incremental", "Couldn't create user %s (id %d): %s", + after[U_NAME], auid, error_message(code)); + return; + } - if (bstate != 0) { - /* Reactivating a user; get his group list */ - code = moira_connect(); - if (code) { - critical_alert("incremental", - "Error contacting Moira server to retrieve grouplist of user %s: %s", - after[U_NAME], error_message(code)); - return; + if (bstate != 0) + { + /* Reactivating a user; get his group list */ + code = moira_connect(); + if (code) + { + critical_alert("incremental", "Error contacting Moira server " + "to retrieve grouplist of user %s: %s", + after[U_NAME], error_message(code)); + return; + } + av[0] = "ruser"; + av[1] = after[U_NAME]; + code = mr_query("get_lists_of_member", 2, av, add_user_lists, + after[U_NAME]); + if (code && code != MR_NO_MATCH) + { + critical_alert("incremental", + "Couldn't retrieve membership of user %s: %s", + after[U_NAME], error_message(code)); } - av[0] = "ruser"; - av[1] = after[U_NAME]; - code = mr_query("get_lists_of_member", 2, av, - add_user_lists, after[U_NAME]); - if (code && code != MR_NO_MATCH) - critical_alert("incremental", - "Couldn't retrieve membership of user %s: %s", - after[U_NAME], error_message(code)); - moira_disconnect(); + moira_disconnect(); } - return; + return; } } -do_list(before, beforec, after, afterc) -char **before; -int beforec; -char **after; -int afterc; +do_list(char **before, int beforec, char **after, int afterc) { - register int agid, bgid; - int ahide, bhide; - long code, id; - char g1[PR_MAXNAMELEN], g2[PR_MAXNAMELEN]; - char *av[2]; - - agid = bgid = 0; - if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP])) { - bgid = atoi(before[L_GID]); - bhide = atoi(before[L_HIDDEN]); + register int agid, bgid; + int ahide, bhide; + long code, id; + char g1[PR_MAXNAMELEN], g2[PR_MAXNAMELEN]; + char *av[2]; + + agid = bgid = 0; + if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP])) + { + bgid = atoi(before[L_GID]); + bhide = atoi(before[L_HIDDEN]); } - if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP])) { - agid = atoi(after[L_GID]); - ahide = atoi(after[L_HIDDEN]); + if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP])) + { + agid = atoi(after[L_GID]); + ahide = atoi(after[L_HIDDEN]); } - if (agid == 0 && bgid == 0) /* Not active groups */ - return; + if (agid == 0 && bgid == 0) /* Not active groups */ + return; - if (agid && bgid) { - if (strcmp(after[L_NAME], before[L_NAME])) { - /* Only a modify is required */ - strcpy(g1, "system:"); - strcpy(g2, "system:"); - strcat(g1, before[L_NAME]); - strcat(g2, after[L_NAME]); - - com_err(whoami, 0, "Changing group %s (gid %d) to %s (gid %d)", - before[L_NAME], bgid, after[L_NAME], agid); - - code = pr_try(pr_ChangeEntry, g1, g2, -agid, ""); - if (code) { - critical_alert("incremental", - "Couldn't change group %s (id %d) to %s (id %d): %s", - before[L_NAME], -bgid, after[L_NAME], -agid, - error_message(code)); + if (agid && bgid) + { + if (strcmp(after[L_NAME], before[L_NAME])) + { + /* Only a modify is required */ + strcpy(g1, "system:"); + strcpy(g2, "system:"); + strcat(g1, before[L_NAME]); + strcat(g2, after[L_NAME]); + + com_err(whoami, 0, "Changing group %s (gid %d) to %s (gid %d)", + before[L_NAME], bgid, after[L_NAME], agid); + + code = pr_try(pr_ChangeEntry, g1, g2, -agid, ""); + if (code) + { + critical_alert("incremental", "Couldn't change group %s (id %d) " + "to %s (id %d): %s", before[L_NAME], -bgid, + after[L_NAME], -agid, error_message(code)); } } - if (ahide != bhide) { - com_err(whoami, 0, "Making group %s (gid %d) %s", - after[L_NAME], agid, - (ahide ? "hidden" : "visible")); - code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, - (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT, - 0 /*ngroups*/, 0 /*nusers*/); - if (code) { - critical_alert("incremental", - "Couldn't set flags of group %s: %s", - after[L_NAME], error_message(code)); + if (ahide != bhide) + { + com_err(whoami, 0, "Making group %s (gid %d) %s", after[L_NAME], + agid, (ahide ? "hidden" : "visible")); + code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, + (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >> + PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/); + if (code) + { + critical_alert("incremental", + "Couldn't set flags of group %s: %s", + after[L_NAME], error_message(code)); } } - return; + return; } - if (bgid) { - com_err(whoami, 0, "Deleting group %s (gid %d)", - before[L_NAME], bgid); - code = pr_try(pr_DeleteByID, -bgid); - if (code && code != PRNOENT) { - critical_alert("incremental", - "Couldn't delete group %s (id %d): %s", - before[L_NAME], -bgid, error_message(code)); + if (bgid) + { + com_err(whoami, 0, "Deleting group %s (gid %d)", before[L_NAME], bgid); + code = pr_try(pr_DeleteByID, -bgid); + if (code && code != PRNOENT) + { + critical_alert("incremental", + "Couldn't delete group %s (id %d): %s", + before[L_NAME], -bgid, error_message(code)); } - return; + return; } - if (agid) { - strcpy(g1, "system:"); - strcat(g1, after[L_NAME]); - strcpy(g2, "system:administrators"); - id = -agid; - com_err(whoami, 0, "Creating %s group %s (gid %d)", - (ahide ? "hidden" : "visible"), after[L_NAME], agid); - code = pr_try(pr_CreateGroup, g1, g2, &id); - if (code == PRIDEXIST) { - char ename[255]; - - if (pr_try(pr_SIdToName, -agid, ename) == 0 && !strcmp(g1, ename)) - return; - } - if (code) { - critical_alert("incremental", - "Couldn't create group %s (id %d): %s", - after[L_NAME], id, error_message(code)); + if (agid) + { + strcpy(g1, "system:"); + strcat(g1, after[L_NAME]); + strcpy(g2, "system:administrators"); + id = -agid; + com_err(whoami, 0, "Creating %s group %s (gid %d)", + (ahide ? "hidden" : "visible"), after[L_NAME], agid); + code = pr_try(pr_CreateGroup, g1, g2, &id); + if (code == PRIDEXIST) + { + char ename[255]; + + if (pr_try(pr_SIdToName, -agid, ename) == 0 && !strcmp(g1, ename)) return; } - if (ahide) { - code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, - (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT, - 0 /*ngroups*/, 0 /*nusers*/); - if (code) { - critical_alert("incremental", - "Couldn't set flags of group %s: %s", - after[L_NAME], error_message(code)); + if (code) + { + critical_alert("incremental", "Couldn't create group %s (id %d): %s", + after[L_NAME], id, error_message(code)); + return; + } + if (ahide) + { + code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, + (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >> + PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/); + if (code) + { + critical_alert("incremental", + "Couldn't set flags of group %s: %s", + after[L_NAME], error_message(code)); } } - /* We need to make sure the group is properly populated */ - if (beforec < L_ACTIVE) return; + /* We need to make sure the group is properly populated */ + if (beforec < L_ACTIVE) + return; - code = moira_connect(); - if (code) { - critical_alert("incremental", - "Error contacting Moira server to resolve %s: %s", - after[L_NAME], error_message(code)); - return; + code = moira_connect(); + if (code) + { + critical_alert("incremental", + "Error contacting Moira server to resolve %s: %s", + after[L_NAME], error_message(code)); + return; } - av[0] = after[L_NAME]; - code = mr_query("get_end_members_of_list", 1, av, - add_list_members, after[L_NAME]); - if (code) - critical_alert("incremental", - "Couldn't retrieve full membership of list %s: %s", - after[L_NAME], error_message(code)); - moira_disconnect(); - return; + av[0] = after[L_NAME]; + code = mr_query("get_end_members_of_list", 1, av, + add_list_members, after[L_NAME]); + if (code) + { + critical_alert("incremental", + "Couldn't retrieve full membership of list %s: %s", + after[L_NAME], error_message(code)); + } + moira_disconnect(); + return; } } - + #define LM_EXTRA_ACTIVE (LM_END) #define LM_EXTRA_PUBLIC (LM_END+1) #define LM_EXTRA_HIDDEN (LM_END+2) @@ -355,369 +374,360 @@ int afterc; #define LM_EXTRA_GID (LM_END+5) #define LM_EXTRA_END (LM_END+6) -do_member(before, beforec, after, afterc) -char **before; -int beforec; -char **after; -int afterc; +do_member(char **before, int beforec, char **after, int afterc) { - int code; - char *p; + int code; + char *p; - if (afterc) { - if (afterc < LM_EXTRA_END) { - return; - } else + if (afterc) + { + if (afterc < LM_EXTRA_END) + return; + else + { if (!atoi(after[LM_EXTRA_ACTIVE]) || !atoi(after[LM_EXTRA_GROUP])) return; - - edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]); - } else if (beforec) { - if (beforec < LM_EXTRA_END) { - return; - } else + } + + edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]); + } + else if (beforec) + { + if (beforec < LM_EXTRA_END) + return; + else + { if (!atoi(before[LM_EXTRA_ACTIVE]) || !atoi(before[LM_EXTRA_GROUP])) return; - edit_group(0, before[LM_LIST], before[LM_TYPE], before[LM_MEMBER]); + } + edit_group(0, before[LM_LIST], before[LM_TYPE], before[LM_MEMBER]); } } -do_filesys(before, beforec, after, afterc) -char **before; -int beforec; -char **after; -int afterc; +do_filesys(char **before, int beforec, char **after, int afterc) { - char cmd[1024]; - int acreate, atype, bcreate, btype; - - if (afterc < FS_CREATE) { - atype = acreate = 0; - } else { - atype = !strcmp(after[FS_TYPE], "AFS"); - acreate = atoi(after[FS_CREATE]); - } + char cmd[1024]; + int acreate, atype, bcreate, btype; - if (beforec < FS_CREATE) { - if (acreate == 0 || atype == 0) return; + if (afterc < FS_CREATE) + atype = acreate = 0; + else + { + atype = !strcmp(after[FS_TYPE], "AFS"); + acreate = atoi(after[FS_CREATE]); + } - /* new locker creation */ - sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s", - BIN_DIR, BIN_DIR, BIN_DIR, - after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE], - after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]); - run_cmd(cmd); + if (beforec < FS_CREATE) + { + if (acreate == 0 || atype == 0) return; + + /* new locker creation */ + sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s", + BIN_DIR, BIN_DIR, BIN_DIR, + after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE], + after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]); + run_cmd(cmd); + return; } - - btype = !strcmp(before[FS_TYPE], "AFS"); - bcreate = atoi(before[FS_CREATE]); - if (afterc < FS_CREATE) { - if (btype && bcreate) - critical_alert("incremental", - "Cannot delete AFS filesystem %s: Operation not supported", - before[FS_NAME]); - return; + + btype = !strcmp(before[FS_TYPE], "AFS"); + bcreate = atoi(before[FS_CREATE]); + if (afterc < FS_CREATE) + { + if (btype && bcreate) + critical_alert("incremental", "Cannot delete AFS filesystem %s: " + "Operation not supported", before[FS_NAME]); + return; } - if (!acreate) + if (!acreate) + return; + + /* Are we dealing with AFS lockers (could be type ERR lockers) */ + if (!atype && !btype) + { + if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR")) return; + } - /* Are we dealing with AFS lockers (could be type ERR lockers) */ - if (!atype && !btype) - if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR")) - return; - - /* By now, we know we are simply changing AFS filesystem attributes. - * Operations supported: - * Name change: rename/remount - * Path change: remount - * Type change: ERR<-->AFS - */ + /* By now, we know we are simply changing AFS filesystem attributes. + * Operations supported: + * Name change: rename/remount + * Path change: remount + * Type change: ERR<-->AFS + */ #if 0 - if (strcmp(before[FS_OWNER], after[FS_OWNER]) || - strcmp(before[FS_OWNERS], after[FS_OWNERS])) + if (strcmp(before[FS_OWNER], after[FS_OWNER]) || + strcmp(before[FS_OWNERS], after[FS_OWNERS])) { - critical_alert("incremental", - "Cannot change ownership of filesystem %s: Operation not yet supported", - after[FS_NAME]); + critical_alert("incremental", + "Cannot change ownership of filesystem %s: Operation not yet supported", + after[FS_NAME]); } #endif - sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s", - BIN_DIR, BIN_DIR, BIN_DIR, - before[FS_NAME], before[FS_MACHINE], before[FS_TYPE], - before[FS_L_TYPE], before[FS_PACK], - after[FS_NAME], after[FS_MACHINE], after[FS_TYPE], - after[FS_L_TYPE], after[FS_PACK]); - run_cmd(cmd); + sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s", + BIN_DIR, BIN_DIR, BIN_DIR, + before[FS_NAME], before[FS_MACHINE], before[FS_TYPE], + before[FS_L_TYPE], before[FS_PACK], + after[FS_NAME], after[FS_MACHINE], after[FS_TYPE], + after[FS_L_TYPE], after[FS_PACK]); + run_cmd(cmd); } -do_quota(before, beforec, after, afterc) -char **before; -int beforec; -char **after; -int afterc; +do_quota(char **before, int beforec, char **after, int afterc) { - char cmd[1024]; + char cmd[1024]; - if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) || - strncmp("/afs/", after[Q_DIRECTORY], 5)) - return; - - sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s", - BIN_DIR, BIN_DIR, BIN_DIR, - after[Q_DIRECTORY], after[Q_QUOTA]); - run_cmd(cmd); + if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) || + strncmp("/afs/", after[Q_DIRECTORY], 5)) return; + + sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s", + BIN_DIR, BIN_DIR, BIN_DIR, + after[Q_DIRECTORY], after[Q_QUOTA]); + run_cmd(cmd); + return; } -run_cmd(cmd) -char *cmd; +run_cmd(char *cmd) { - int success=0, tries=0; - - check_afs(); - - while (success == 0 && tries < 2) { - if (tries++) - sleep(90); - com_err(whoami, 0, "Executing command: %s", cmd); - if (system(cmd) == 0) - success++; + int success=0, tries=0; + + check_afs(); + + while (success == 0 && tries < 2) + { + if (tries++) + sleep(90); + com_err(whoami, 0, "Executing command: %s", cmd); + if (system(cmd) == 0) + success++; } - if (!success) - critical_alert("incremental", "failed command: %s", cmd); + if (!success) + critical_alert("incremental", "failed command: %s", cmd); } -add_user_lists(ac, av, user) - int ac; - char *av[]; - char *user; +int add_user_lists(int ac, char *av[], char *user) { - if (atoi(av[L_ACTIVE]) && atoi(av[L_GROUP])) /* active group ? */ - edit_group(1, av[L_NAME], "USER", user); - return 0; + if (atoi(av[L_ACTIVE]) && atoi(av[L_GROUP])) /* active group ? */ + edit_group(1, av[L_NAME], "USER", user); + return 0; } -add_list_members(ac, av, group) - int ac; - char *av[]; - char *group; +int add_list_members(int ac, char *av[], char *group) { - edit_group(1, group, av[0], av[1]); - return 0; + edit_group(1, group, av[0], av[1]); + return 0; } - -check_user(ac, av, ustate) - int ac; - char *av[]; - int *ustate; +int check_user(int ac, char *av[], int *ustate) { - *ustate = atoi(av[U_STATE]); - return 0; + *ustate = atoi(av[U_STATE]); + return 0; } -edit_group(op, group, type, member) - int op; - char *group; - char *type; - char *member; +edit_group(int op, char *group, char *type, char *member) { - char *p = 0; - char buf[PR_MAXNAMELEN]; - int code, ustate; - static char local_realm[REALM_SZ+1] = ""; - struct member *m; - - /* The following KERBEROS code allows for the use of entities - * user@foreign_cell. - */ - if (!local_realm[0]) - krb_get_lrealm(local_realm, 1); - if (!strcmp(type, "KERBEROS")) { - p = strchr(member, '@'); - if (p && !strcasecmp(p+1, local_realm)) - *p = 0; - } else if (strcmp(type, "USER")) - return; /* invalid type */ - - /* Cannot risk doing another query during a callback */ - /* We could do this simply for type USER, but eventually this may also - * dynamically add KERBEROS types to the prdb, and we will need to do - * a query to look up the uid of the null-instance user */ - if (mr_connections) { - m = (struct member *)malloc(sizeof(struct member)); - if (!m) { - critical_alert("incremental", "Out of memory"); - exit(1); + char *p = 0; + char buf[PR_MAXNAMELEN]; + int code, ustate; + static char local_realm[REALM_SZ+1] = ""; + struct member *m; + + /* The following KERBEROS code allows for the use of entities + * user@foreign_cell. + */ + if (!local_realm[0]) + krb_get_lrealm(local_realm, 1); + if (!strcmp(type, "KERBEROS")) + { + p = strchr(member, '@'); + if (p && !strcasecmp(p+1, local_realm)) + *p = 0; + } + else if (strcmp(type, "USER")) + return; /* invalid type */ + + /* Cannot risk doing another query during a callback */ + /* We could do this simply for type USER, but eventually this may also + * dynamically add KERBEROS types to the prdb, and we will need to do + * a query to look up the uid of the null-instance user */ + if (mr_connections) + { + m = malloc(sizeof(struct member)); + if (!m) + { + critical_alert("incremental", "Out of memory"); + exit(1); } - m->op = op; - strcpy(m->list, group); - strcpy(m->type, type); - strcpy(m->member, member); - m->next = member_head; - member_head = m; - return; + m->op = op; + strcpy(m->list, group); + strcpy(m->type, type); + strcpy(m->member, member); + m->next = member_head; + member_head = m; + return; } - strcpy(buf, "system:"); - strcat(buf, group); - com_err(whoami, 0, "%s %s %s group %s", - (op ? "Adding" : "Removing"), member, - (op ? "to" : "from"), group); - code=pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf); - if (code) { - if (op==1 && code == PRIDEXIST) return; /* Already added */ - - if (code == PRNOENT) { /* Something is missing */ - if (op==0) return; /* Already deleted */ - if (!strcmp(type, "KERBEROS")) /* Special instances; ok */ - return; - - /* Check whether the member being added is an active user */ - code = moira_connect(); - if (!code) code = mr_query("get_user_by_login", 1, &member, - check_user, (char *)&ustate); - if (code) { - critical_alert("incremental", - "Error contacting Moira server to lookup user %s: %s", - member, error_message(code)); + strcpy(buf, "system:"); + strcat(buf, group); + com_err(whoami, 0, "%s %s %s group %s", (op ? "Adding" : "Removing"), member, + (op ? "to" : "from"), group); + code = pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf); + if (code) + { + if (op==1 && code == PRIDEXIST) + return; /* Already added */ + + if (code == PRNOENT) + { /* Something is missing */ + if (op == 0) + return; /* Already deleted */ + if (!strcmp(type, "KERBEROS")) /* Special instances; ok */ + return; + + /* Check whether the member being added is an active user */ + code = moira_connect(); + if (!code) + { + code = mr_query("get_user_by_login", 1, &member, + check_user, (char *) &ustate); + } + if (code) + { + critical_alert("incremental", "Error contacting Moira server " + "to lookup user %s: %s", member, + error_message(code)); } - /* We don't use moira_disconnect() - * because we may already be in the routine. - */ - mr_disconnect(); - mr_connections--; + /* We don't use moira_disconnect() + * because we may already be in the routine. + */ + mr_disconnect(); + mr_connections--; - if (!code && ustate!=1 && ustate!=2) return; /* inactive user */ - code = PRNOENT; + if (!code && ustate!=1 && ustate!=2) + return; /* inactive user */ + code = PRNOENT; } - critical_alert("incremental", - "Couldn't %s %s %s %s: %s", - op ? "add" : "remove", member, - op ? "to" : "from", buf, - error_message(code)); + critical_alert("incremental", "Couldn't %s %s %s %s: %s", + op ? "add" : "remove", member, + op ? "to" : "from", buf, + error_message(code)); } } -long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8) - long (*fn)(); - char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; +long pr_try(long (*fn)(), char *a1, char *a2, char *a3, char *a4, char *a5, + char *a6, char *a7, char *a8) { - static int initd=0; - register long code; - register int tries = 0; -#ifdef DEBUG - char fname[64]; -#endif + static int initd = 0; + register long code; + register int tries = 0; - check_afs(); + check_afs(); - if (initd) { - code=pr_Initialize(0, AFSCONF_CLIENTNAME, 0); - } else { - code = 0; - initd = 1; + if (initd) + code = pr_Initialize(0, AFSCONF_CLIENTNAME, 0); + else + { + code = 0; + initd = 1; } - if (!code) code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); - if (code) { - critical_alert("incremental", "Couldn't initialize libprot: %s", - error_message(code)); - return; + if (!code) + code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0); + if (code) + { + critical_alert("incremental", "Couldn't initialize libprot: %s", + error_message(code)); + return; } - sleep(1); /* give ptserver room */ - - while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) { -#ifdef DEBUG - long t; - t = time(0); - if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); - else if (fn == pr_RemoveUserFromGroup) - strcpy(fname, "pr_RemoveUserFromGroup"); - else if (fn == pr_CreateUser) strcpy(fname, "pr_CreateUser"); - else if (fn == pr_CreateGroup) strcpy(fname, "pr_CreateGroup"); - else if (fn == pr_DeleteByID) strcpy(fname, "pr_DeleteByID"); - else if (fn == pr_ChangeEntry) strcpy(fname, "pr_ChangeEntry"); - else if (fn == pr_SetFieldsEntry) strcpy(fname, "pr_SetFieldsEntry"); - else if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); - else - sprintf(fname, "pr_??? (0x%08x)", (long)fn); - - com_err(whoami, code, "- %s failed (try %d @%u)", fname, tries+1, t); -#endif - if (++tries > 2) break; /* 3 tries */ - - if (code == UNOQUORUM) sleep(90); - else sleep(15); - - /* Re-initialize the prdb connection */ - code=pr_Initialize(0, AFSCONF_CLIENTNAME, 0); - if (!code) code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); - if (code) { - critical_alert("incremental", "Couldn't re-initialize libprot: %s", - error_message(code)); - initd = 0; /* we lost */ - break; + sleep(1); /* give ptserver room */ + + while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) + { + if (++tries > 2) + break; /* 3 tries */ + + if (code == UNOQUORUM) + sleep(90); + else + sleep(15); + + /* Re-initialize the prdb connection */ + code = pr_Initialize(0, AFSCONF_CLIENTNAME, 0); + if (!code) + code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0); + if (code) + { + critical_alert("incremental", "Couldn't re-initialize libprot: %s", + error_message(code)); + initd = 0; /* we lost */ + break; } } - return code; + return code; } -check_afs() +check_afs(void) { - int i; - - for (i=0; file_exists(STOP_FILE); i++) { - if (i > 30) { - critical_alert("incremental", - "AFS incremental failed (%s exists): %s", - STOP_FILE, tbl_buf); - exit(1); + int i; + + for (i = 0; file_exists(STOP_FILE); i++) + { + if (i > 30) + { + critical_alert("incremental", + "AFS incremental failed (%s exists): %s", + STOP_FILE, tbl_buf); + exit(1); } - sleep(60); + sleep(60); } } -moira_connect() +int moira_connect(void) { - static char hostname[64]; - long code; - - if (!mr_connections++) { - gethostname(hostname, sizeof(hostname)); - code = mr_connect(hostname); - if (!code) code = mr_auth("afs.incr"); - return code; + static char hostname[64]; + long code; + + if (!mr_connections++) + { + gethostname(hostname, sizeof(hostname)); + code = mr_connect(hostname); + if (!code) + code = mr_auth("afs.incr"); + return code; } - return 0; + return 0; } -moira_disconnect() +int moira_disconnect(void) { - struct member *m; - - if (!--mr_connections) { - mr_disconnect(); - while(m = member_head) { - edit_group(m->op, m->list, m->type, m->member); - member_head = m->next; - free(m); + struct member *m; + + if (!--mr_connections) + { + mr_disconnect(); + while (m = member_head) + { + edit_group(m->op, m->list, m->type, m->member); + member_head = m->next; + free(m); } } - return 0; + return 0; } diff --git a/incremental/afs_create.pl b/incremental/afs_create.pl index 311d0543..5049d60a 100644 --- a/incremental/afs_create.pl +++ b/incremental/afs_create.pl @@ -140,7 +140,7 @@ sub athena_proc if ($type eq "ORG") { mkdir("$path/www",0755) && - chown(0,0,"$path/www") || + chown(0,0,"$path/www") || die "Unable to create subdirectories\n"; system("$fs sa $path/www @acl system:anyuser rl -clear") && die "Unable to set acl on www directory\n"; diff --git a/incremental/afs_nightly.pl b/incremental/afs_nightly.pl index 0a3b6349..8dabc11f 100644 --- a/incremental/afs_nightly.pl +++ b/incremental/afs_nightly.pl @@ -34,7 +34,7 @@ for (@new_data) { $ap =~ s:^([^/]):/vicep\1:; } next unless ($as && $ap); - + &afs_lock; truncate(SRV, 0); for (@afs_data) { @@ -43,7 +43,7 @@ for (@new_data) { print SRV $_ unless ($c eq $c2 && $as eq $as2 && $ap eq $ap2); } &afs_unlock; - + open(VOS,"$vos partinfo $as $ap -cell $c -noauth|"); chop(@vos = ); close(VOS); @@ -52,12 +52,12 @@ for (@new_data) { $total = pop(@vos); $used = $total-$vos[5]; $alloc = 0; - + open(VOS,"$vos listvol $as $ap -cell $c -long -noauth|"); @vos = ; close(VOS); next if ($?); - + while ($_ = shift(@vos)) { next unless /On-line/; local($vn,$id) = split(/\s+/, $_); diff --git a/incremental/afs_rename.pl b/incremental/afs_rename.pl index 92d756c3..479ae1d1 100644 --- a/incremental/afs_rename.pl +++ b/incremental/afs_rename.pl @@ -111,7 +111,7 @@ sub check { local($vname) = @_; local(@vos, @a); - + open (VOS, "$vos listvldb -name $vname -cell $oldcell 2>/dev/null|"); chop(@vos = ); close(VOS); diff --git a/incremental/ksrvtgt.c b/incremental/ksrvtgt.c index bae09a47..5053eeab 100644 --- a/incremental/ksrvtgt.c +++ b/incremental/ksrvtgt.c @@ -2,10 +2,10 @@ * $Source$ * $Author$ * - * Copyright 1988 by the Massachusetts Institute of Technology. + * Copyright 1988 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file - * . + * . * * Get a ticket-granting-ticket given a service key file (srvtab) * Modifed from the regular kerberos distribution in that it accepts @@ -22,72 +22,73 @@ char rcsid[] = "$Header$"; -void usage(argv) -char **argv; +void usage(char **argv) { - fprintf(stderr, - "Usage: %s name instance [-r realm] [-s srvtab] [-l lifetime]\n", - argv[0]); - exit(1); + fprintf(stderr, + "Usage: %s name instance [-r realm] [-s srvtab] [-l lifetime]\n", + argv[0]); + exit(1); } -main(argc,argv) - int argc; - char **argv; +int main(int argc, char **argv) { - char realm[REALM_SZ + 1]; - register int code; - int i, lifetime = 1; - char srvtab[MAXPATHLEN + 1]; + char realm[REALM_SZ + 1]; + register int code; + int i, lifetime = 1; + char srvtab[MAXPATHLEN + 1]; - memset(realm, 0, sizeof(realm)); - memset(srvtab, 0, sizeof(srvtab)); + memset(realm, 0, sizeof(realm)); + memset(srvtab, 0, sizeof(srvtab)); - if (argc < 3) - usage(argv); + if (argc < 3) + usage(argv); - for (i = 3; i < argc; i++) { - if (argv[i][0] != '-') - usage(argv); - switch (argv[i][1]) { + for (i = 3; i < argc; i++) + { + if (argv[i][0] != '-') + usage(argv); + switch (argv[i][1]) + { case 'r': - if (i + 1 >= argc) - usage(argv); - strncpy(realm, argv[i++ + 1], sizeof(realm) - 1); - break; + if (i + 1 >= argc) + usage(argv); + strncpy(realm, argv[i++ + 1], sizeof(realm) - 1); + break; case 's': - if (i + 1 >= argc) - usage(argv); - strncpy(srvtab, argv[i++ + 1], sizeof(srvtab) - 1); - break; + if (i + 1 >= argc) + usage(argv); + strncpy(srvtab, argv[i++ + 1], sizeof(srvtab) - 1); + break; case 'l': - if (i + 1 >= argc) - usage(argv); - lifetime = atoi(argv[i++ + 1]); - if (lifetime < 5) - lifetime = 1; - else - lifetime /= 5; - if (lifetime > 255) - lifetime = 255; - break; + if (i + 1 >= argc) + usage(argv); + lifetime = atoi(argv[i++ + 1]); + if (lifetime < 5) + lifetime = 1; + else + lifetime /= 5; + if (lifetime > 255) + lifetime = 255; + break; default: - usage(); + usage(argv); } } - if (srvtab[0] == 0) - (void) strcpy(srvtab, KEYFILE); + if (!*srvtab) + strcpy(srvtab, KEYFILE); - if (realm[0] == 0) - if (krb_get_lrealm(realm, 1) != KSUCCESS) - (void) strcpy(realm, KRB_REALM); + if (!*realm) + { + if (krb_get_lrealm(realm, 1) != KSUCCESS) + strcpy(realm, KRB_REALM); + } - code = krb_get_svc_in_tkt(argv[1], argv[2], realm, - "krbtgt", realm, lifetime, srvtab); - if (code) - fprintf(stderr, "%s\n", krb_err_txt[code]); - exit(code); + code = krb_get_svc_in_tkt(argv[1], argv[2], realm, + "krbtgt", realm, lifetime, srvtab); + if (code) + fprintf(stderr, "%s\n", krb_err_txt[code]); + exit(code); } diff --git a/lib/critical.c b/lib/critical.c index 27913d2e..69960c20 100644 --- a/lib/critical.c +++ b/lib/critical.c @@ -37,35 +37,33 @@ extern char *whoami; * don't necessarily have vsprintf(). */ -void critical_alert(instance, msg, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8) - char *instance; /* Instance for zephyr gram */ - char *msg; /* printf format message */ - char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8; +void critical_alert(char *instance, char *msg, char *arg1, char *arg2, + char *arg3, char *arg4, char *arg5, char *arg6, + char *arg7, char *arg8) { - FILE *crit; /* FILE for critical log file */ - char buf[BUFSIZ]; /* Holds the formatted message */ + FILE *crit; /* FILE for critical log file */ + char buf[BUFSIZ]; /* Holds the formatted message */ - sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - /* Send zephyr notice */ - send_zgram(instance, buf); + /* Send zephyr notice */ + send_zgram(instance, buf); - /* Log message to critical file */ - if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) + /* Log message to critical file */ + if ((crit = fopen(CRITERRLOG, "a"))) { - time_t t; - char *time_s; + time_t t; + char *time_s; - time(&t); - time_s = ctime(&t) + 4; - time_s[strlen(time_s)-6] = '\0'; + time(&t); + time_s = ctime(&t) + 4; + time_s[strlen(time_s) - 6] = '\0'; - fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf); - fclose(crit); + fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf); + fclose(crit); } - com_err(whoami, 0, buf); + com_err(whoami, 0, buf); } @@ -74,34 +72,28 @@ void critical_alert(instance, msg, arg1, arg2, arg3, arg4, * errors while sending message. */ -send_zgram(inst, msg) -char *inst; -char *msg; +send_zgram(char *inst, char *msg) { #ifdef ZEPHYR - ZNotice_t znotice; - -#ifdef POSIX - memset (&znotice, 0, sizeof (znotice)); -#else - bzero (&znotice, sizeof (znotice)); -#endif - znotice.z_kind = UNSAFE; - znotice.z_class = "MOIRA"; - znotice.z_class_inst = inst; - znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n"; - (void) ZInitialize (); - znotice.z_message = msg; - znotice.z_message_len = strlen(msg) + 1; - znotice.z_opcode = ""; - znotice.z_recipient = ""; - ZSendNotice(&znotice, ZNOAUTH); + ZNotice_t znotice; + + memset(&znotice, 0, sizeof(znotice)); + znotice.z_kind = UNSAFE; + znotice.z_class = "MOIRA"; + znotice.z_class_inst = inst; + znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n"; + ZInitialize(); + znotice.z_message = msg; + znotice.z_message_len = strlen(msg) + 1; + znotice.z_opcode = ""; + znotice.z_recipient = ""; + ZSendNotice(&znotice, ZNOAUTH); #endif #ifdef SYSLOG - { - char buf[512]; - sprintf(buf, "MOIRA: %s %s", inst, msg); - syslog(LOG_ERR, buf); - } + { + char buf[512]; + sprintf(buf, "MOIRA: %s %s", inst, msg); + syslog(LOG_ERR, buf); + } #endif } diff --git a/lib/fixhost.c b/lib/fixhost.c index d794157f..989d7c84 100644 --- a/lib/fixhost.c +++ b/lib/fixhost.c @@ -35,58 +35,64 @@ static char *rcsid_fixhost_c = "$Header$"; * realloc'ed, so the old pointer should not be considered valid. */ -char * -canonicalize_hostname(host) - char *host; +char *canonicalize_hostname(char *host) { - register struct hostent *hp; - int n_len; - int has_dot = 0; - char tbuf[BUFSIZ]; - struct utsname name; - register char *cp; - - if (strlen(host) > 2 && host[0] == '"' && host[strlen(host)-1] == '"') { - strcpy(tbuf, host+1); - free(host); - tbuf[strlen(tbuf)-1] = 0; - return(strsave(tbuf)); + register struct hostent *hp; + int n_len; + int has_dot = 0; + char tbuf[BUFSIZ]; + struct utsname name; + register char *cp; + + if (strlen(host) > 2 && host[0] == '"' && host[strlen(host) - 1] == '"') + { + strcpy(tbuf, host + 1); + free(host); + tbuf[strlen(tbuf) - 1] = '\0'; + return strsave(tbuf); } - if (strchr(host, '*') || strchr(host, '?') || strchr(host, '[')) - return(host); + if (strchr(host, '*') || strchr(host, '?') || strchr(host, '[')) + return host; + + hp = gethostbyname(host); - hp = gethostbyname(host); + if (hp) + { + n_len = strlen(hp->h_name) + 1; + host = realloc(host, n_len); - if (hp) { - n_len = strlen(hp->h_name) + 1; - host = realloc(host, (unsigned)n_len); - - (void) strcpy(host, hp->h_name); - return host; - } else { - /* can't get name from nameserver; fix up the format a bit */ - for (cp = host; *cp; cp++) { - register int c; /* pcc doesn't like register char */ - if (islower(c = *cp)) *cp = toupper(c); - has_dot |= (c == '.'); + strcpy(host, hp->h_name); + return host; + } + else + { + /* can't get name from nameserver; fix up the format a bit */ + for (cp = host; *cp; cp++) + { + register int c; /* pcc doesn't like register char */ + if (islower(c = *cp)) + *cp = toupper(c); + has_dot |= (c == '.'); } - if (!has_dot) { - static char *domain = NULL; + if (!has_dot) + { + static char *domain = NULL; - if (domain == NULL) { - (void) uname(&name); - hp = gethostbyname(name.nodename); - cp = strchr(hp->h_name, '.'); - if (cp) - domain = strsave(++cp); - else - domain = ""; + if (domain == NULL) + { + uname(&name); + hp = gethostbyname(name.nodename); + cp = strchr(hp->h_name, '.'); + if (cp) + domain = strsave(++cp); + else + domain = ""; } - (void) sprintf(tbuf, "%s.%s", host, domain); - free(host); - host = strsave(tbuf); + sprintf(tbuf, "%s.%s", host, domain); + free(host); + host = strsave(tbuf); } - return host; + return host; } } diff --git a/lib/fixname.c b/lib/fixname.c index e87ec746..0ce5730c 100644 --- a/lib/fixname.c +++ b/lib/fixname.c @@ -19,137 +19,127 @@ static char *rcsid_fixname_c = "$Header$"; #define LAST_LEN 100 #define FIRST_LEN 100 -void FixName(ilnm, ifnm, last, first, middle) - char *ilnm, *ifnm; - char *first, *last, *middle; +void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle) { - int ends_jr=0, ends_iii=0, ends_iv=0, ends_ii=0, ends_v=0; + int ends_jr = 0, ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0; - uppercase(ilnm); - uppercase(ifnm); - - /* Last name ... */ + uppercase(ilnm); + uppercase(ifnm); - TrimTrailingSpace(ilnm); - LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); - LookForSt(ilnm); - LookForO(ilnm); - FixCase(ilnm); - strncpy(last, ilnm, LAST_LEN); + /* Last name ... */ - /* First name & middle initial ... */ + TrimTrailingSpace(ilnm); + LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); + LookForSt(ilnm); + LookForO(ilnm); + FixCase(ilnm); + strncpy(last, ilnm, LAST_LEN); - TrimTrailingSpace(ifnm); - LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); + /* First name & middle initial ... */ - GetMidInit(ifnm, middle); + TrimTrailingSpace(ifnm); + LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); - FixCase(ifnm); + GetMidInit(ifnm, middle); + + FixCase(ifnm); #ifdef notdef - /* okay, finish up first name */ - AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); + /* okay, finish up first name */ + AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); #endif - strncpy(first, ifnm, FIRST_LEN); + strncpy(first, ifnm, FIRST_LEN); } -FixCase(p) -register char *p; +FixCase(register char *p) { - register int cflag; /* convert to lcase, unless at start or following */ + register int cflag; /* convert to lcase, unless at start or following */ /* a space or punctuation mark (e.g., '-') */ - for (cflag = 0; *p; p++) { - if (cflag && isupper(*p)) - *p = tolower(*p); - else if (!cflag && islower(*p)) - *p = toupper(*p); - if (isalpha(*p)) - cflag = 1; - else - cflag = 0; + for (cflag = 0; *p; p++) + { + if (cflag && isupper(*p)) + *p = tolower(*p); + else if (!cflag && islower(*p)) + *p = toupper(*p); + if (isalpha(*p)) + cflag = 1; + else + cflag = 0; } } -LookForJrAndIII(nm, pends_jr, pends_ii, pends_iii, pends_iv, pends_v) -register char *nm; -register int *pends_jr; -int *pends_ii; -register int *pends_iii; -register int *pends_iv; -int *pends_v; +LookForJrAndIII(register char *nm, register int *pends_jr, int *pends_ii, + register int *pends_iii, register int *pends_iv, + int *pends_v) { - register int len = strlen(nm); + register int len = strlen(nm); - if (len >= 4 && !strcmp(nm + len - 3, " JR")) { - *pends_jr = 1; - nm[len - 3] = '\0'; + if (len >= 4 && !strcmp(nm + len - 3, " JR")) + { + *pends_jr = 1; + nm[len - 3] = '\0'; } - else if (len >= 4 && !strcmp(nm + len - 3, " IV")) { - *pends_iv = 1; - nm[len - 3] = '\0'; + else if (len >= 4 && !strcmp(nm + len - 3, " IV")) + { + *pends_iv = 1; + nm[len - 3] = '\0'; } - else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) { - *pends_jr = 1; - nm[len - 4] = '\0'; + else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) + { + *pends_jr = 1; + nm[len - 4] = '\0'; } - else if (len >= 5 && !strcmp(nm + len - 4, " III")) { - *pends_iii = 1; - nm[len - 4] = '\0'; + else if (len >= 5 && !strcmp(nm + len - 4, " III")) + { + *pends_iii = 1; + nm[len - 4] = '\0'; } - else if (len >= 4 && !strcmp(nm + len - 3, " II")) { - *pends_ii = 1; - nm[len - 3] = '\0'; + else if (len >= 4 && !strcmp(nm + len - 3, " II")) + { + *pends_ii = 1; + nm[len - 3] = '\0'; } - else if (len >= 3 && !strcmp(nm + len - 2, " V")) { - *pends_v = 1; - nm[len - 2] = '\0'; + else if (len >= 3 && !strcmp(nm + len - 2, " V")) + { + *pends_v = 1; + nm[len - 2] = '\0'; } } -LookForSt(nm) /* ST PIERRE, etc. */ -register char *nm; +LookForSt(register char *nm) /* ST PIERRE, etc. */ { - char temp[256]; + char temp[256]; - if (!strcmp(nm,"ST ")) { - strcpy(temp, nm + 3); - strcpy(nm, "ST. "); - strcat(nm, temp); + if (!strcmp(nm, "ST ")) + { + strcpy(temp, nm + 3); + strcpy(nm, "ST. "); + strcat(nm, temp); } } -LookForO(nm) /* O BRIEN, etc. */ -register char *nm; +LookForO(register char *nm) /* O BRIEN, etc. */ { - if (!strcmp(nm, "O ") && isalpha(nm[2])) { - nm[1] = '\''; - } + if (!strcmp(nm, "O ") && isalpha(nm[2])) + nm[1] = '\''; } -TrimTrailingSpace(ip) -register char *ip; +TrimTrailingSpace(register char *ip) { - register char *p; - for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) { - *p = '\0'; - } + register char *p; + for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) + *p = '\0'; } -GetMidInit(nm, mi) -register char *nm; /* truncate at first space, if any such */ -register char *mi; /* set to first char after first space, if any such */ +GetMidInit(register char *nm, register char *mi) { - while (*nm && !isspace(*nm)) { - nm++; - } - if (*nm) { - *nm++ = '\0'; - } - while (*nm && isspace(*nm)) { - nm++; - } - if (*nm) { - *mi++ = *nm; - } - *mi = '\0'; + while (*nm && !isspace(*nm)) + nm++; + if (*nm) + *nm++ = '\0'; + while (*nm && isspace(*nm)) + nm++; + if (*nm) + *mi++ = *nm; + *mi = '\0'; } diff --git a/lib/gdss_convert.c b/lib/gdss_convert.c index 118d0f33..40c421d2 100644 --- a/lib/gdss_convert.c +++ b/lib/gdss_convert.c @@ -5,10 +5,9 @@ #include -gdss2et(code) -int code; +int gdss2et(int code) { - if (code == 0) - return(code); - return(ERROR_TABLE_BASE_gdss - code - 1); + if (code == 0) + return code; + return ERROR_TABLE_BASE_gdss - code - 1; } diff --git a/lib/hash.c b/lib/hash.c index 665925d4..214eae4c 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -20,41 +20,39 @@ /* Create a hash table. The size is just a hint, not a maximum. */ -struct hash *create_hash(size) -int size; +struct hash *create_hash(int size) { - struct hash *h; - - h = (struct hash *) malloc(sizeof(struct hash)); - if (h == (struct hash *) NULL) - return((struct hash *) NULL); - h->size = size; - h->data = (struct bucket **) malloc(size * sizeof(char *)); - if (h->data == (struct bucket **) NULL) { - free(h); - return((struct hash *) NULL); + struct hash *h; + + h = malloc(sizeof(struct hash)); + if (!h) + return NULL; + h->size = size; + h->data = malloc(size * sizeof(char *)); + if (!h->data) + { + free(h); + return NULL; } - memset(h->data, 0, size * sizeof(char *)); - return(h); + memset(h->data, 0, size * sizeof(char *)); + return h; } /* Lookup an object in the hash table. Returns the value associated with * the key, or NULL (thus NULL is not a very good value to store...) */ -char *hash_lookup(h, key) -struct hash *h; -register int key; +char *hash_lookup(struct hash *h, register int key) { - register struct bucket *b; - - b = h->data[hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) - return(b->data); - else - return(NULL); + register struct bucket *b; + + b = h->data[hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + return b->data; + else + return NULL; } @@ -62,21 +60,20 @@ register int key; * existed, or 0 if not. */ -int hash_update(h, key, value) -struct hash *h; -register int key; -char *value; +int hash_update(struct hash *h, register int key, char *value) { - register struct bucket *b; - - b = h->data[hash_func(h, key)]; - while (b && b->key != key) - b = b->next; - if (b && b->key == key) { - b->data = value; - return(1); - } else - return(0); + register struct bucket *b; + + b = h->data[hash_func(h, key)]; + while (b && b->key != key) + b = b->next; + if (b && b->key == key) + { + b->data = value; + return 1; + } + else + return 0; } @@ -84,37 +81,36 @@ char *value; * there, 1 if it was, or -1 if we ran out of memory. */ -int hash_store(h, key, value) -struct hash *h; -register int key; -char *value; +int hash_store(struct hash *h, register int key, char *value) { - register struct bucket *b, **p; - - p = &(h->data[hash_func(h, key)]); - if (*p == NULL) { - b = *p = (struct bucket *) malloc(sizeof(struct bucket)); - if (b == (struct bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + register struct bucket *b, **p; + + p = &(h->data[hash_func(h, key)]); + if (!*p) + { + b = *p = malloc(sizeof(struct bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } - for (b = *p; b && b->key != key; b = *p) - p = (struct bucket **) *p; - if (b && b->key == key) { - b->data = value; - return(1); + for (b = *p; b && b->key != key; b = *p) + p = (struct bucket **) *p; + if (b && b->key == key) + { + b->data = value; + return 1; } - b = *p = (struct bucket *) malloc(sizeof(struct bucket)); - if (b == (struct bucket *) NULL) - return(-1); - b->next = NULL; - b->key = key; - b->data = value; - return(0); + b = *p = malloc(sizeof(struct bucket)); + if (!b) + return -1; + b->next = NULL; + b->key = key; + b->data = value; + return 0; } @@ -122,17 +118,16 @@ char *value; * data with that value, call the callback proc with the corresponding key. */ -hash_search(h, value, callback) -struct hash *h; -register char *value; -void (*callback)(); +hash_search(struct hash *h, register char *value, void (*callback)()) { - register struct bucket *b, **p; - - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - if (b->data == value) - (*callback)(b->key); + register struct bucket *b, **p; + + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + { + if (b->data == value) + (*callback)(b->key); } } } @@ -141,32 +136,30 @@ void (*callback)(); /* Step through the hash table, calling the callback proc with each key. */ -hash_step(h, callback, hint) -struct hash *h; -void (*callback)(); -char *hint; +hash_step(struct hash *h, void (*callback)(), char *hint) { - register struct bucket *b, **p; + register struct bucket *b, **p; - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b->next) { - (*callback)(b->key, b->data, hint); - } + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b->next) + (*callback)(b->key, b->data, hint); } } /* Deallocate all of the memory associated with a table */ -hash_destroy(h) -struct hash *h; +hash_destroy(struct hash *h) { - register struct bucket *b, **p, *b1; - - for (p = &(h->data[h->size - 1]); p >= h->data; p--) { - for (b = *p; b; b = b1) { - b1 = b->next; - free(b); + register struct bucket *b, **p, *b1; + + for (p = &(h->data[h->size - 1]); p >= h->data; p--) + { + for (b = *p; b; b = b1) + { + b1 = b->next; + free(b); } } } diff --git a/lib/idno.c b/lib/idno.c index e98222a6..49883998 100644 --- a/lib/idno.c +++ b/lib/idno.c @@ -10,9 +10,7 @@ #include #include #include -#ifdef POSIX #include -#endif #ifdef USE_CRYPT_H #include #endif @@ -23,36 +21,32 @@ * Returns: none */ -void -RemoveHyphens(str) -char *str; +void RemoveHyphens(char *str) { - char *hyphen; + char *hyphen; - while ((hyphen = strchr(str, '-')) != (char *)0) - (void) strcpy(hyphen, hyphen + 1); + while ((hyphen = strchr(str, '-'))) + strcpy(hyphen, hyphen + 1); } /* Function Name: EncryptMITID - * Description: Encrypts an mit ID number. + * Description: Encrypts an mit ID number. * Arguments: sbuf - the buffer to return the encrypted number in. * idnumber - the id number (string). * first, last - name of the person. * Returns: none. */ -void -EncryptID(sbuf, idnumber, first, last) -char *sbuf, *idnumber, *first, *last; +void EncryptID(char *sbuf, char *idnumber, char *first, char *last) { - char salt[3]; + char salt[3]; - RemoveHyphens(idnumber); - salt[0] = tolower(last[0]); - salt[1] = tolower(first[0]); - salt[2] = 0; + RemoveHyphens(idnumber); + salt[0] = tolower(last[0]); + salt[1] = tolower(first[0]); + salt[2] = '\0'; - (void) strcpy(sbuf, crypt(&idnumber[2], salt)); + strcpy(sbuf, crypt(&idnumber[2], salt)); } diff --git a/lib/kname_unparse.c b/lib/kname_unparse.c index 920ace27..a694b20d 100644 --- a/lib/kname_unparse.c +++ b/lib/kname_unparse.c @@ -8,83 +8,87 @@ #include #include -/* Turn a principal, instance, realm triple into a single non-ambiguous +/* Turn a principal, instance, realm triple into a single non-ambiguous * string. This is the inverse of kname_parse(). It returns a pointer * to a static buffer, or NULL on error. */ -char *kname_unparse(p, i, r) -char *p; -char *i; -char *r; +char *kname_unparse(char *p, char *i, char *r) { - static char name[MAX_K_NAME_SZ]; - char *s; + static char name[MAX_K_NAME_SZ]; + char *s; - s = name; - if (!p || strlen(p) > ANAME_SZ) - return(NULL); - while (*p) { - switch (*p) { + s = name; + if (!p || strlen(p) > ANAME_SZ) + return NULL; + while (*p) + { + switch (*p) + { case '@': - *s++ = '\\'; - *s++ = '@'; - break; + *s++ = '\\'; + *s++ = '@'; + break; case '.': - *s++ = '\\'; - *s++ = '.'; - break; + *s++ = '\\'; + *s++ = '.'; + break; case '\\': - *s++ = '\\'; - *s++ = '\\'; - break; + *s++ = '\\'; + *s++ = '\\'; + break; default: - *s++ = *p; + *s++ = *p; } - p++; + p++; } - if (i && *i) { - if (strlen(i) > INST_SZ) - return(NULL); - *s++ = '.'; - while (*i) { - switch (*i) { + if (i && *i) + { + if (strlen(i) > INST_SZ) + return NULL; + *s++ = '.'; + while (*i) + { + switch (*i) + { case '@': - *s++ = '\\'; - *s++ = '@'; - break; + *s++ = '\\'; + *s++ = '@'; + break; case '.': - *s++ = '\\'; - *s++ = '.'; - break; + *s++ = '\\'; + *s++ = '.'; + break; case '\\': - *s++ = '\\'; - *s++ = '\\'; - break; + *s++ = '\\'; + *s++ = '\\'; + break; default: - *s++ = *i; + *s++ = *i; } - i++; + i++; } } - *s++ = '@'; - if (!r || strlen(r) > REALM_SZ) - return(NULL); - while (*r) { - switch (*r) { + *s++ = '@'; + if (!r || strlen(r) > REALM_SZ) + return NULL; + while (*r) + { + switch (*r) + { case '@': - *s++ = '\\'; - *s++ = '@'; - break; + *s++ = '\\'; + *s++ = '@'; + break; case '\\': - *s++ = '\\'; - *s++ = '\\'; - break; + *s++ = '\\'; + *s++ = '\\'; + break; default: - *s++ = *r; + *s++ = *r; } - r++; + r++; } - *s = '\0'; - return(&name[0]); + *s = '\0'; + return &name[0]; } diff --git a/lib/krb_et.et b/lib/krb_et.et index f703383f..d52e934b 100644 --- a/lib/krb_et.et +++ b/lib/krb_et.et @@ -38,7 +38,7 @@ ec KRB_RES12, "Reserved 12" - + ec KRB_RES13, "Reserved 13" diff --git a/lib/mr_access.c b/lib/mr_access.c index c8633f1d..5c13d9cc 100644 --- a/lib/mr_access.c +++ b/lib/mr_access.c @@ -20,45 +20,42 @@ static char *rcsid_sms_access_c = "$Header$"; /* * Check access to a named query. */ -int mr_access(name, argc, argv) - char *name; /* Query name */ - int argc; /* Arg count */ - char **argv; /* Args */ +int mr_access(char *name, int argc, char **argv) { - register char **nargv = (char **)malloc(sizeof(char *) * (argc+1)); - register int status = 0; - nargv[0] = name; - memcpy((char *)(nargv+1), (char *)argv, sizeof(char *) * argc); - status = mr_access_internal(argc+1, nargv); - free(nargv); - return status; + register char **nargv = malloc(sizeof(char *) * (argc + 1)); + register int status = 0; + + nargv[0] = name; + memcpy(nargv + 1, argv, sizeof(char *) * argc); + status = mr_access_internal(argc + 1, nargv); + free(nargv); + return status; } + /* * Check access to a named query, where the query name is argv[0] * and the arguments are the rest of argv[]. */ -int mr_access_internal(argc, argv) - int argc; /* Arg count */ - char **argv; /* Args */ +int mr_access_internal(int argc, char **argv) { - int status; - mr_params params_st; - register mr_params *params = NULL; - mr_params *reply = NULL; - - CHECK_CONNECTED; + int status; + mr_params params_st; + register mr_params *params = NULL; + mr_params *reply = NULL; + + CHECK_CONNECTED; + + params = ¶ms_st; + params->mr_version_no = sending_version_no; + params->mr_procno = MR_ACCESS; + params->mr_argc = argc; + params->mr_argl = NULL; + params->mr_argv = argv; - params = ¶ms_st; - params->mr_version_no = sending_version_no; - params->mr_procno = MR_ACCESS; - params->mr_argc = argc; - params->mr_argl = NULL; - params->mr_argv = argv; - - if ((status = mr_do_call(params, &reply)) == 0) - status = reply->mr_status; + if ((status = mr_do_call(params, &reply)) == 0) + status = reply->mr_status; - mr_destroy_reply(reply); + mr_destroy_reply(reply); - return status; + return status; } diff --git a/lib/mr_auth.c b/lib/mr_auth.c index 25277cee..51361115 100644 --- a/lib/mr_auth.c +++ b/lib/mr_auth.c @@ -8,7 +8,7 @@ * . * * Handles the client side of the sending of authenticators to - * the mr server. + * the mr server. */ #ifndef lint @@ -26,55 +26,57 @@ static char *rcsid_sms_auth_c = "$Header$"; * client program, and will be recorded in the database. */ -int mr_auth(prog) -char *prog; +int mr_auth(char *prog) { - register int status; - mr_params params_st; - char *args[2]; - int argl[2]; - char realm[REALM_SZ], host[BUFSIZ], *p; + register int status; + mr_params params_st; + char *args[2]; + int argl[2]; + char realm[REALM_SZ], host[BUFSIZ], *p; - register mr_params *params = ¶ms_st; - mr_params *reply = NULL; - KTEXT_ST auth; + register mr_params *params = ¶ms_st; + mr_params *reply = NULL; + KTEXT_ST auth; - CHECK_CONNECTED; - - /* Build a Kerberos authenticator. */ - - memset(host, 0, sizeof(host)); - if (status = mr_host(host, sizeof(host) - 1)) - return status; + CHECK_CONNECTED; - strcpy(realm, (char *)krb_realmofhost(host)); - for (p = host; *p && *p != '.'; p++) + /* Build a Kerberos authenticator. */ + + memset(host, 0, sizeof(host)); + if ((status = mr_host(host, sizeof(host) - 1))) + return status; + + strcpy(realm, (char *)krb_realmofhost(host)); + for (p = host; *p && *p != '.'; p++) + { if (isupper(*p)) *p = tolower(*p); - *p = 0; + } + *p = '\0'; - status = krb_mk_req(&auth, MOIRA_SNAME, host, realm, 0); - if (status != KSUCCESS) { - status += ERROR_TABLE_BASE_krb; - return status; - } - params->mr_version_no = sending_version_no; - params->mr_procno = MR_AUTH; - params->mr_argc = 2; - params->mr_argv = args; - params->mr_argl = argl; - params->mr_argv[0] = (char *)auth.dat; - params->mr_argl[0] = auth.length; - params->mr_argv[1] = prog; - params->mr_argl[1] = strlen(prog) + 1; - - if (sending_version_no == MR_VERSION_1) - params->mr_argc = 1; + status = krb_mk_req(&auth, MOIRA_SNAME, host, realm, 0); + if (status != KSUCCESS) + { + status += ERROR_TABLE_BASE_krb; + return status; + } + params->mr_version_no = sending_version_no; + params->mr_procno = MR_AUTH; + params->mr_argc = 2; + params->mr_argv = args; + params->mr_argl = argl; + params->mr_argv[0] = (char *)auth.dat; + params->mr_argl[0] = auth.length; + params->mr_argv[1] = prog; + params->mr_argl[1] = strlen(prog) + 1; - if ((status = mr_do_call(params, &reply)) == 0) - status = reply->mr_status; + if (sending_version_no == MR_VERSION_1) + params->mr_argc = 1; - mr_destroy_reply(reply); + if ((status = mr_do_call(params, &reply)) == 0) + status = reply->mr_status; - return status; + mr_destroy_reply(reply); + + return status; } diff --git a/lib/mr_call.c b/lib/mr_call.c index 9048dc8a..57bf53da 100644 --- a/lib/mr_call.c +++ b/lib/mr_call.c @@ -15,34 +15,31 @@ static char *rcsid_sms_call_c = "$Header$"; #include #include "mr_private.h" -mr_do_call(params, reply) - struct mr_params *params; - struct mr_params **reply; +int mr_do_call(struct mr_params *params, struct mr_params **reply) { - CHECK_CONNECTED; - - if (!_mr_send_op) - _mr_send_op = create_operation(); - - if (!_mr_recv_op) - _mr_recv_op = create_operation(); - - initialize_operation(_mr_send_op, mr_start_send, (char *)params, - (int (*)())NULL); - queue_operation(_mr_conn, CON_OUTPUT, _mr_send_op); - - initialize_operation(_mr_recv_op, mr_start_recv, (char *)reply, - (int (*)())NULL); - queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); - - /* Block until operation done. */ - mr_complete_operation(_mr_send_op); - mr_complete_operation(_mr_recv_op); - /* Look at results */ - if ((OP_STATUS(_mr_send_op) != OP_COMPLETE) || - (OP_STATUS(_mr_recv_op) != OP_COMPLETE)) { - mr_disconnect(); - return MR_ABORTED; + CHECK_CONNECTED; + + if (!_mr_send_op) + _mr_send_op = create_operation(); + + if (!_mr_recv_op) + _mr_recv_op = create_operation(); + + initialize_operation(_mr_send_op, mr_start_send, (char *)params, NULL); + queue_operation(_mr_conn, CON_OUTPUT, _mr_send_op); + + initialize_operation(_mr_recv_op, mr_start_recv, (char *)reply, NULL); + queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); + + /* Block until operation done. */ + mr_complete_operation(_mr_send_op); + mr_complete_operation(_mr_recv_op); + /* Look at results */ + if ((OP_STATUS(_mr_send_op) != OP_COMPLETE) || + (OP_STATUS(_mr_recv_op) != OP_COMPLETE)) + { + mr_disconnect(); + return MR_ABORTED; } - return 0; + return 0; } diff --git a/lib/mr_connect.c b/lib/mr_connect.c index b619e2d7..4da24acc 100644 --- a/lib/mr_connect.c +++ b/lib/mr_connect.c @@ -6,7 +6,7 @@ * Copyright (C) 1987, 1990 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . - * + * * This routine is part of the client library. It handles * creating a connection to the mr server. */ @@ -30,98 +30,100 @@ static char *mr_server_host = 0; * 4) compiled in default (from sms_app.h). */ -int mr_connect(server) -char *server; +int mr_connect(char *server) { - extern int errno; - char *p, **pp, sbuf[256]; - - if (!mr_inited) mr_init(); - if (_mr_conn) return MR_ALREADY_CONNECTED; - - if (!server || (strlen(server) == 0)) { - server = getenv("MOIRASERVER"); - } + extern int errno; + char *p, **pp, sbuf[256]; + + if (!mr_inited) + mr_init(); + if (_mr_conn) + return MR_ALREADY_CONNECTED; + + if (!server || (strlen(server) == 0)) + server = getenv("MOIRASERVER"); #ifdef HESIOD - if (!server || (strlen(server) == 0)) { - pp = hes_resolve("moira", "sloc"); - if (pp) server = *pp; + if (!server || (strlen(server) == 0)) + { + pp = hes_resolve("moira", "sloc"); + if (pp) + server = *pp; } #endif - if (!server || (strlen(server) == 0)) { - server = MOIRA_SERVER; - } + if (!server || (strlen(server) == 0)) + server = MOIRA_SERVER; - if (!strchr(server, ':')) { - p = strchr(MOIRA_SERVER, ':'); - p++; - sprintf(sbuf, "%s:%s", server, p); - server = sbuf; + if (!strchr(server, ':')) + { + p = strchr(MOIRA_SERVER, ':'); + p++; + sprintf(sbuf, "%s:%s", server, p); + server = sbuf; } - errno = 0; - _mr_conn = start_server_connection(server, ""); - if (_mr_conn == NULL) - return errno; - if (connection_status(_mr_conn) == CON_STOPPED) { - register status = connection_errno(_mr_conn); - if (!status) status = MR_CANT_CONNECT; - mr_disconnect(); - return status; + errno = 0; + _mr_conn = start_server_connection(server, ""); + if (_mr_conn == NULL) + return errno; + if (connection_status(_mr_conn) == CON_STOPPED) + { + register status = connection_errno(_mr_conn); + if (!status) + status = MR_CANT_CONNECT; + mr_disconnect(); + return status; } - /* - * stash hostname for later use - */ + /* + * stash hostname for later use + */ - mr_server_host = strsave(server); - if (p = strchr(mr_server_host, ':')) - *p = 0; - mr_server_host = canonicalize_hostname(mr_server_host); - return 0; + mr_server_host = strsave(server); + if ((p = strchr(mr_server_host, ':'))) + *p = '\0'; + mr_server_host = canonicalize_hostname(mr_server_host); + return 0; } - -int mr_disconnect() + +int mr_disconnect(void) { - CHECK_CONNECTED; - _mr_conn = sever_connection(_mr_conn); - free(mr_server_host); - mr_server_host = 0; - return 0; + CHECK_CONNECTED; + _mr_conn = sever_connection(_mr_conn); + free(mr_server_host); + mr_server_host = 0; + return 0; } -int mr_host(host, size) - char *host; - int size; +int mr_host(char *host, int size) { - CHECK_CONNECTED; + CHECK_CONNECTED; - /* If we are connected, mr_server_host points to a valid string. */ - strncpy(host, mr_server_host, size); - return(0); + /* If we are connected, mr_server_host points to a valid string. */ + strncpy(host, mr_server_host, size); + return 0; } -int mr_noop() +int mr_noop(void) { - int status; - mr_params param_st; - struct mr_params *params = NULL; - struct mr_params *reply = NULL; - - CHECK_CONNECTED; - params = ¶m_st; - params->mr_version_no = sending_version_no; - params->mr_procno = MR_NOOP; - params->mr_argc = 0; - params->mr_argl = NULL; - params->mr_argv = NULL; - - if ((status = mr_do_call(params, &reply)) == 0) - status = reply->mr_status; - - mr_destroy_reply(reply); - - return status; + int status; + mr_params param_st; + struct mr_params *params = NULL; + struct mr_params *reply = NULL; + + CHECK_CONNECTED; + params = ¶m_st; + params->mr_version_no = sending_version_no; + params->mr_procno = MR_NOOP; + params->mr_argc = 0; + params->mr_argl = NULL; + params->mr_argv = NULL; + + if ((status = mr_do_call(params, &reply)) == 0) + status = reply->mr_status; + + mr_destroy_reply(reply); + + return status; } diff --git a/lib/mr_et.et b/lib/mr_et.et index 9da2b906..2d3fa78b 100644 --- a/lib/mr_et.et +++ b/lib/mr_et.et @@ -78,7 +78,7 @@ ec MR_PRINTER, ec MR_QUEUE, "Unknown queue" - + ec MR_DEVICE, "No such device" diff --git a/lib/mr_init.c b/lib/mr_init.c index 7a8055a0..651b77b7 100644 --- a/lib/mr_init.c +++ b/lib/mr_init.c @@ -20,14 +20,15 @@ int mr_inited = 0; /* the reference to link_against_the_moira_version_of_gdb is to make * sure that this is built with the proper libraries. */ -mr_init() +mr_init(void) { - extern int link_against_the_moira_version_of_gdb; - if (mr_inited) return; - - gdb_init(); - initialize_sms_error_table(); - initialize_krb_error_table(); - link_against_the_moira_version_of_gdb = 0; - mr_inited=1; + extern int link_against_the_moira_version_of_gdb; + if (mr_inited) + return; + + gdb_init(); + initialize_sms_error_table(); + initialize_krb_error_table(); + link_against_the_moira_version_of_gdb = 0; + mr_inited = 1; } diff --git a/lib/mr_ops.c b/lib/mr_ops.c index 7e91f131..4a67b302 100644 --- a/lib/mr_ops.c +++ b/lib/mr_ops.c @@ -7,7 +7,7 @@ * Technology * For copying and distribution information, please see the file * . - * + * * This routine is part of the client library. It handles * the protocol operations: invoking an update and getting the * MR message of the day. @@ -24,27 +24,27 @@ static char *rcsid_sms_do_update_c = "$Header$"; /* Invoke a DCM update. */ -int mr_do_update() +int mr_do_update(void) { - int status; - mr_params param_st; - struct mr_params *params = NULL; - struct mr_params *reply = NULL; - - CHECK_CONNECTED; - params = ¶m_st; - params->mr_version_no = sending_version_no; - params->mr_procno = MR_DO_UPDATE; - params->mr_argc = 0; - params->mr_argl = NULL; - params->mr_argv = NULL; - - if ((status = mr_do_call(params, &reply)) == 0) - status = reply->mr_status; - - mr_destroy_reply(reply); + int status; + mr_params param_st; + struct mr_params *params = NULL; + struct mr_params *reply = NULL; - return status; + CHECK_CONNECTED; + params = ¶m_st; + params->mr_version_no = sending_version_no; + params->mr_procno = MR_DO_UPDATE; + params->mr_argc = 0; + params->mr_argl = NULL; + params->mr_argv = NULL; + + if ((status = mr_do_call(params, &reply)) == 0) + status = reply->mr_status; + + mr_destroy_reply(reply); + + return status; } @@ -52,53 +52,54 @@ int mr_do_update() * point to NULL or the motd in a static buffer. */ -int mr_motd(motd) -char **motd; +int mr_motd(char **motd) { - int status; - mr_params param_st; - struct mr_params *params = NULL; - struct mr_params *reply = NULL; - static char buffer[1024]; - - *motd = NULL; - CHECK_CONNECTED; - params = ¶m_st; - params->mr_version_no = sending_version_no; - params->mr_procno = MR_MOTD; - params->mr_argc = 0; - params->mr_argl = NULL; - params->mr_argv = NULL; - - if ((status = mr_do_call(params, &reply))) - goto punt; - - while ((status = reply->mr_status) == MR_MORE_DATA) { - if (reply->mr_argc > 0) { - strncpy(buffer, reply->mr_argv[0], sizeof(buffer)); - *motd = buffer; + int status; + mr_params param_st; + struct mr_params *params = NULL; + struct mr_params *reply = NULL; + static char buffer[1024]; + + *motd = NULL; + CHECK_CONNECTED; + params = ¶m_st; + params->mr_version_no = sending_version_no; + params->mr_procno = MR_MOTD; + params->mr_argc = 0; + params->mr_argl = NULL; + params->mr_argv = NULL; + + if ((status = mr_do_call(params, &reply))) + goto punt; + + while ((status = reply->mr_status) == MR_MORE_DATA) + { + if (reply->mr_argc > 0) + { + strncpy(buffer, reply->mr_argv[0], sizeof(buffer)); + *motd = buffer; } - mr_destroy_reply(reply); - reply = NULL; - - initialize_operation(_mr_recv_op, mr_start_recv, &reply, - (int (*)())NULL); - queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); - - mr_complete_operation(_mr_recv_op); - if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) { - mr_disconnect(); - status = MR_ABORTED; - return(status); + mr_destroy_reply(reply); + reply = NULL; + + initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL); + queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); + + mr_complete_operation(_mr_recv_op); + if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) + { + mr_disconnect(); + status = MR_ABORTED; + return status; } - } - punt: - mr_destroy_reply(reply); - /* for backwards compatability */ - if (status == MR_UNKNOWN_PROC) - return(0); - else - return(status); + } +punt: + mr_destroy_reply(reply); + /* for backwards compatability */ + if (status == MR_UNKNOWN_PROC) + return 0; + else + return status; } @@ -121,15 +122,13 @@ char **motd; static int mr_alternate_input = 0; static int (*mr_alternate_handler)(); -int mr_set_alternate_input(fd, proc) -int fd; -int (*proc)(); +int mr_set_alternate_input(int fd, int (*proc)()) { - if (mr_alternate_input != 0) - return(MR_ALREADY_CONNECTED); - mr_alternate_input = fd; - mr_alternate_handler = proc; - return(MR_SUCCESS); + if (mr_alternate_input != 0) + return MR_ALREADY_CONNECTED; + mr_alternate_input = fd; + mr_alternate_handler = proc; + return MR_SUCCESS; } @@ -137,27 +136,26 @@ int (*proc)(); * handles alternate input streams (such as X) as well. */ -mr_complete_operation(op) -OPERATION op; +int mr_complete_operation(OPERATION op) { - long infd, outfd, exfd; - int rc; - - gdb_progress(); /* try for an immediate completion */ - - if (mr_alternate_input == 0) - return(complete_operation(op)); - - infd = (1<status != OP_COMPLETE && op->status != OP_CANCELLED) { - rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd, - (fd_set *)&exfd, (struct timeval *)NULL); - if (rc > 0 && mr_alternate_handler) { - (*mr_alternate_handler)(); - } + long infd, outfd, exfd; + int rc; + + gdb_progress(); /* try for an immediate completion */ + + if (mr_alternate_input == 0) + return complete_operation(op); + + infd = 1 << mr_alternate_input; + outfd = exfd = 0; + + while (op->status != OP_COMPLETE && op->status != OP_CANCELLED) + { + rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd, + (fd_set *)&exfd, NULL); + if (rc > 0 && mr_alternate_handler) + (*mr_alternate_handler)(); } - return(op->status); + return op->status; } diff --git a/lib/mr_param.c b/lib/mr_param.c index c3f074d7..b0612547 100644 --- a/lib/mr_param.c +++ b/lib/mr_param.c @@ -30,215 +30,211 @@ static char *rcsid_sms_param_c = "$Header$"; * write of the next bunch of data. */ -/*ARGSUSED*/ -mr_cont_send(op, hcon, arg) - OPERATION op; - HALF_CONNECTION hcon; - struct mr_params *arg; +int mr_cont_send(OPERATION op, HALF_CONNECTION hcon, struct mr_params *arg) { - op->result = OP_SUCCESS; - free(arg->mr_flattened); - arg->mr_flattened = NULL; - - return OP_COMPLETE; + op->result = OP_SUCCESS; + free(arg->mr_flattened); + arg->mr_flattened = NULL; + + return OP_COMPLETE; } -mr_start_send(op, hcon, arg) - OPERATION op; - HALF_CONNECTION hcon; - register struct mr_params *arg; +int mr_start_send(OPERATION op, HALF_CONNECTION hcon, + register struct mr_params *arg) { - int i, len; - unsigned int mr_size; - int *argl; - char *buf, *bp; - - /* - * This should probably be split into several routines. - * It could also probably be made more efficient (punting most - * of the argument marshalling stuff) by doing I/O directly - * from the strings. Anyone for a scatter/gather mr_send_data? - * - * that would look a lot like the uio stuff in the kernel.. hmm. - */ - - /* - * Marshall the entire data right now.. - * We are sending the version number, - * total request size, request number, - * argument count, and then each argument. - * At least for now, each argument is a string, which is - * sent as a count of bytes followed by the bytes - * (including the trailing '\0'), padded - * to a 32-bit boundary. - */ - - mr_size = 4 * sizeof(int32); - - argl = (int *)malloc((unsigned)(sizeof(int) * arg->mr_argc)); - - /* - * For each argument, figure out how much space is needed. - */ - - for (i = 0; i < arg->mr_argc; ++i) { - if (arg->mr_argl) - argl[i] = len = arg->mr_argl[i]; - else - argl[i] = len = strlen(arg->mr_argv[i]) + 1; - mr_size += sizeof(int32) + len; - /* Round up to next 32-bit boundary.. */ - mr_size = sizeof(int32) * howmany(mr_size, sizeof(int32)); + int i, len; + unsigned int mr_size; + int *argl; + char *buf, *bp; + + /* + * This should probably be split into several routines. + * It could also probably be made more efficient (punting most + * of the argument marshalling stuff) by doing I/O directly + * from the strings. Anyone for a scatter/gather mr_send_data? + * + * that would look a lot like the uio stuff in the kernel.. hmm. + */ + + /* + * Marshall the entire data right now.. + * We are sending the version number, + * total request size, request number, + * argument count, and then each argument. + * At least for now, each argument is a string, which is + * sent as a count of bytes followed by the bytes + * (including the trailing '\0'), padded + * to a 32-bit boundary. + */ + + mr_size = 4 * sizeof(int32); + + argl = malloc(sizeof(int) * arg->mr_argc); + + /* + * For each argument, figure out how much space is needed. + */ + + for (i = 0; i < arg->mr_argc; ++i) + { + if (arg->mr_argl) + argl[i] = len = arg->mr_argl[i]; + else + argl[i] = len = strlen(arg->mr_argv[i]) + 1; + mr_size += sizeof(int32) + len; + /* Round up to next 32-bit boundary.. */ + mr_size = sizeof(int32) * howmany(mr_size, sizeof(int32)); } - - arg->mr_flattened = buf = malloc(mr_size); - - memset(arg->mr_flattened, 0, mr_size); - - arg->mr_size = mr_size; - - ((int32 *)buf)[0] = htonl(mr_size); - ((int32 *)buf)[1] = htonl(arg->mr_version_no); - ((int32 *)buf)[2] = htonl(arg->mr_procno); - ((int32 *)buf)[3] = htonl(arg->mr_argc); - - /* - * bp is a pointer into the point in the buffer to put - * the next argument. - */ - - bp = (char *)(((int32 *)buf) + 4); - - for (i = 0; imr_argc; ++i) { - len = argl[i]; - *((int32 *)bp) = htonl(len); - bp += sizeof(int32); - memcpy(bp, arg->mr_argv[i], len); - bp += sizeof(int32) * howmany(len, sizeof(int32)); + + arg->mr_flattened = buf = malloc(mr_size); + + memset(arg->mr_flattened, 0, mr_size); + + arg->mr_size = mr_size; + + ((int32 *)buf)[0] = htonl(mr_size); + ((int32 *)buf)[1] = htonl(arg->mr_version_no); + ((int32 *)buf)[2] = htonl(arg->mr_procno); + ((int32 *)buf)[3] = htonl(arg->mr_argc); + + /* + * bp is a pointer into the point in the buffer to put + * the next argument. + */ + + bp = (char *)(((int32 *)buf) + 4); + + for (i = 0; i < arg->mr_argc; ++i) + { + len = argl[i]; + *((int32 *)bp) = htonl(len); + bp += sizeof(int32); + memcpy(bp, arg->mr_argv[i], len); + bp += sizeof(int32) * howmany(len, sizeof(int32)); } - op->fcn.cont = mr_cont_send; - arg->mr_size = mr_size; - - free(argl); - - if (gdb_send_data(hcon, arg->mr_flattened, mr_size) == OP_COMPLETE) - return mr_cont_send(op, hcon, arg); - else return OP_RUNNING; -} - -/*ARGSUSED*/ -mr_cont_recv(op, hcon, argp) - OPERATION op; - HALF_CONNECTION hcon; - mr_params **argp; + op->fcn.cont = mr_cont_send; + arg->mr_size = mr_size; + + free(argl); + + if (gdb_send_data(hcon, arg->mr_flattened, mr_size) == OP_COMPLETE) + return mr_cont_send(op, hcon, arg); + else + return OP_RUNNING; +} + +int mr_cont_recv(OPERATION op, HALF_CONNECTION hcon, mr_params **argp) { - int done = FALSE; - char *cp; - int *ip; - int i; - register mr_params *arg = *argp; - - while (!done) { - switch (arg->mr_state) { + int done = FALSE; + char *cp; + int *ip; + int i; + register mr_params *arg = *argp; + + while (!done) + { + switch (arg->mr_state) + { case S_RECV_START: - arg->mr_state = S_RECV_DATA; - if (gdb_receive_data(hcon, (caddr_t)&arg->mr_size, - sizeof(int32)) == OP_COMPLETE) - continue; - done = TRUE; - break; + arg->mr_state = S_RECV_DATA; + if (gdb_receive_data(hcon, (caddr_t)&arg->mr_size, + sizeof(int32)) == OP_COMPLETE) + continue; + done = TRUE; + break; case S_RECV_DATA: - fflush(stdout); - /* Should validate that length is reasonable */ - arg->mr_size = ntohl(arg->mr_size); - if (arg->mr_size > 65536) { - return OP_CANCELLED; - } - arg->mr_flattened = malloc(arg->mr_size); - arg->mr_state = S_DECODE_DATA; - memcpy(arg->mr_flattened, (caddr_t)&arg->mr_size, sizeof(int32)); - - if (gdb_receive_data(hcon, - arg->mr_flattened + sizeof(int32), - arg->mr_size - sizeof(int32)) - == OP_COMPLETE) - continue; - done = TRUE; - break; + fflush(stdout); + /* Should validate that length is reasonable */ + arg->mr_size = ntohl(arg->mr_size); + if (arg->mr_size > 65536) + return OP_CANCELLED; + arg->mr_flattened = malloc(arg->mr_size); + arg->mr_state = S_DECODE_DATA; + memcpy(arg->mr_flattened, (caddr_t)&arg->mr_size, sizeof(int32)); + + if (gdb_receive_data(hcon, arg->mr_flattened + sizeof(int32), + arg->mr_size - sizeof(int32)) + == OP_COMPLETE) + continue; + done = TRUE; + break; case S_DECODE_DATA: - cp = arg->mr_flattened; - ip = (int *) cp; - /* we already got the overall length.. */ - for(i=1; i <4; i++) ip[i] = ntohl(ip[i]); - arg->mr_version_no = ip[1]; - if (arg->mr_version_no != MR_VERSION_1 && - arg->mr_version_no != MR_VERSION_2) - arg->mr_status = MR_VERSION_MISMATCH; - else arg->mr_status = ip[2]; - arg->mr_argc = ip[3]; - cp += 4 * sizeof(int); - arg->mr_argv=(char **)malloc(arg->mr_argc *sizeof(char **)); - arg->mr_argl=(int *)malloc(arg->mr_argc *sizeof(int *)); - - for (i = 0; imr_argc; ++i) { - u_short nlen = ntohl(* (int *) cp); - cp += sizeof (int32); - if (cp + nlen > arg->mr_flattened + arg->mr_size) { - free(arg->mr_flattened); - arg->mr_flattened = NULL; - return OP_CANCELLED; - } - arg->mr_argv[i] = (char *)malloc(nlen); - memcpy(arg->mr_argv[i], cp, nlen); - arg->mr_argl[i]=nlen; - cp += sizeof(int32) * howmany(nlen, sizeof(int32)); + cp = arg->mr_flattened; + ip = (int *) cp; + /* we already got the overall length.. */ + for (i = 1; i < 4; i++) + ip[i] = ntohl(ip[i]); + arg->mr_version_no = ip[1]; + if (arg->mr_version_no != MR_VERSION_1 && + arg->mr_version_no != MR_VERSION_2) + arg->mr_status = MR_VERSION_MISMATCH; + else arg->mr_status = ip[2]; + arg->mr_argc = ip[3]; + cp += 4 * sizeof(int); + arg->mr_argv = malloc(arg->mr_argc * sizeof(char *)); + arg->mr_argl = malloc(arg->mr_argc * sizeof(int)); + + for (i = 0; i < arg->mr_argc; ++i) + { + u_short nlen = ntohl(*(int *)cp); + cp += sizeof(int32); + if (cp + nlen > arg->mr_flattened + arg->mr_size) + { + free(arg->mr_flattened); + arg->mr_flattened = NULL; + return OP_CANCELLED; + } + arg->mr_argv[i] = malloc(nlen); + memcpy(arg->mr_argv[i], cp, nlen); + arg->mr_argl[i] = nlen; + cp += sizeof(int32) * howmany(nlen, sizeof(int32)); } - free(arg->mr_flattened); - arg->mr_flattened = NULL; - return OP_COMPLETE; + free(arg->mr_flattened); + arg->mr_flattened = NULL; + return OP_COMPLETE; } } - return OP_RUNNING; + return OP_RUNNING; } - -mr_start_recv(op, hcon, argp) - OPERATION op; - HALF_CONNECTION hcon; - struct mr_params **argp; + +int mr_start_recv(OPERATION op, HALF_CONNECTION hcon, struct mr_params **argp) { - register mr_params *arg = *argp; - if (!arg) { - *argp = arg = (mr_params *)malloc(sizeof(mr_params)); - arg->mr_argl = NULL; - arg->mr_argv = NULL; - arg->mr_flattened = NULL; + register mr_params *arg = *argp; + if (!arg) + { + *argp = arg = malloc(sizeof(mr_params)); + arg->mr_argl = NULL; + arg->mr_argv = NULL; + arg->mr_flattened = NULL; } - arg->mr_state = S_RECV_START; - op->fcn.cont = mr_cont_recv; - return mr_cont_recv(op, hcon, argp); + arg->mr_state = S_RECV_START; + op->fcn.cont = mr_cont_recv; + return mr_cont_recv(op, hcon, argp); } -mr_destroy_reply(reply) - mr_params *reply; +mr_destroy_reply(mr_params *reply) { - int i; - if (reply) { - if (reply->mr_argl) - free(reply->mr_argl); - reply->mr_argl = NULL; - if (reply->mr_flattened) - free(reply->mr_flattened); - reply->mr_flattened = NULL; - if (reply->mr_argv) { - for (i=0; imr_argc; i++) { - if (reply->mr_argv[i]) - free (reply->mr_argv[i]); - reply->mr_argv[i] = NULL; + int i; + if (reply) + { + if (reply->mr_argl) + free(reply->mr_argl); + reply->mr_argl = NULL; + if (reply->mr_flattened) + free(reply->mr_flattened); + reply->mr_flattened = NULL; + if (reply->mr_argv) + { + for (i = 0; i < reply->mr_argc; i++) + { + if (reply->mr_argv[i]) + free (reply->mr_argv[i]); + reply->mr_argv[i] = NULL; } - free(reply->mr_argv); + free(reply->mr_argv); } - reply->mr_argv = NULL; - free(reply); + reply->mr_argv = NULL; + free(reply); } } diff --git a/lib/mr_private.h b/lib/mr_private.h index d769f397..14e62c71 100644 --- a/lib/mr_private.h +++ b/lib/mr_private.h @@ -25,5 +25,5 @@ extern int sending_version_no; #define S_DECODE_DATA 3 #define EVER (;;) - + #define CHECK_CONNECTED {if (!_mr_conn) return MR_NOT_CONNECTED;} diff --git a/lib/mr_query.c b/lib/mr_query.c index 16eca18e..3e74d14d 100644 --- a/lib/mr_query.c +++ b/lib/mr_query.c @@ -6,7 +6,7 @@ * Copyright (C) 1987 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . - * + * */ #ifndef lint @@ -26,21 +26,19 @@ static char *rcsid_sms_query_c = "$Header$"; */ static int level = 0; -int mr_query(name, argc, argv, callproc, callarg) - char *name; /* Query name */ - int argc; /* Arg count */ - char **argv; /* Args */ - int (*callproc)(); /* Callback procedure */ - char *callarg; /* Callback argument */ +int mr_query(char *name, int argc, char **argv, + int (*callproc)(), char *callarg) { - register char **nargv = (char **)malloc(sizeof(char *) * (argc+1)); - register int status = 0; - nargv[0] = name; - memcpy((char *)(nargv+1), (char *)argv, sizeof(char *) * argc); - status = mr_query_internal(argc+1, nargv, callproc, callarg); - free(nargv); - return status; + register char **nargv = malloc(sizeof(char *) * (argc + 1)); + register int status = 0; + + nargv[0] = name; + memcpy(nargv + 1, argv, sizeof(char *) * argc); + status = mr_query_internal(argc + 1, nargv, callproc, callarg); + free(nargv); + return status; } + /* * This routine makes an MR query. * @@ -54,54 +52,51 @@ int mr_query(name, argc, argv, callproc, callarg) * way to send it a quench..) */ -int mr_query_internal(argc, argv, callproc, callarg) - int argc; /* Arg count */ - char **argv; /* Args */ - int (*callproc)(); /* Callback procedure */ - char *callarg; /* Callback argument */ +int mr_query_internal(int argc, char **argv, int (*callproc)(), char *callarg) { - int status; - mr_params params_st; - register mr_params *params = NULL; - mr_params *reply = NULL; - int stopcallbacks = 0; + int status; + mr_params params_st; + register mr_params *params = NULL; + mr_params *reply = NULL; + int stopcallbacks = 0; + + if (level) + return MR_QUERY_NOT_REENTRANT; + + CHECK_CONNECTED; + level++; - if (level) return MR_QUERY_NOT_REENTRANT; - - CHECK_CONNECTED; - level++; + params = ¶ms_st; + params->mr_version_no = sending_version_no; + params->mr_procno = MR_QUERY; + params->mr_argc = argc; + params->mr_argl = NULL; + params->mr_argv = argv; - params = ¶ms_st; - params->mr_version_no = sending_version_no; - params->mr_procno = MR_QUERY; - params->mr_argc = argc; - params->mr_argl = NULL; - params->mr_argv = argv; - - if ((status = mr_do_call(params, &reply))) - goto punt; + if ((status = mr_do_call(params, &reply))) + goto punt; - while ((status = reply->mr_status) == MR_MORE_DATA) { - if (!stopcallbacks) - stopcallbacks = - (*callproc)(reply->mr_argc, reply->mr_argv, callarg); - mr_destroy_reply(reply); - reply = NULL; + while ((status = reply->mr_status) == MR_MORE_DATA) + { + if (!stopcallbacks) + stopcallbacks = (*callproc)(reply->mr_argc, reply->mr_argv, callarg); + mr_destroy_reply(reply); + reply = NULL; - initialize_operation(_mr_recv_op, mr_start_recv, &reply, - (int (*)())NULL); - queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); + initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL); + queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); - mr_complete_operation(_mr_recv_op); - if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) { - mr_disconnect(); - status = MR_ABORTED; - goto punt_1; + mr_complete_operation(_mr_recv_op); + if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) + { + mr_disconnect(); + status = MR_ABORTED; + goto punt_1; } - } + } punt: - mr_destroy_reply(reply); + mr_destroy_reply(reply); punt_1: - level--; - return status; + level--; + return status; } diff --git a/lib/nfsparttype.c b/lib/nfsparttype.c index e00a72ac..c9782d1f 100644 --- a/lib/nfsparttype.c +++ b/lib/nfsparttype.c @@ -24,8 +24,8 @@ extern char *strsave(); extern char *strtrim(); struct pair { - int type; - char *name; + int type; + char *name; }; /* @@ -33,84 +33,93 @@ struct pair { */ static struct pair fs_names[] = { - { MR_FS_STUDENT, "Student" }, - { MR_FS_FACULTY, "Faculty" }, - { MR_FS_STAFF, "Staff" }, - { MR_FS_MISC, "Other" }, - { MR_FS_GROUPQUOTA, "GroupQuota" }, - /* Insert new entries before the 0,0 pair */ - { 0, 0 }, + { MR_FS_STUDENT, "Student" }, + { MR_FS_FACULTY, "Faculty" }, + { MR_FS_STAFF, "Staff" }, + { MR_FS_MISC, "Other" }, + { MR_FS_GROUPQUOTA, "GroupQuota" }, + /* Insert new entries before the 0,0 pair */ + { 0, 0 }, }; /* * Given a numeric string containing a filesystem status value, return * a string indicating what allocation type it is. */ -char * -format_filesys_type(fs_status) - char *fs_status; +char *format_filesys_type(char *fs_status) { - char buf[BUFSIZ]; - register struct pair *pp; - - int n_names = 0; - int stat = atoi(fs_status); - - buf[0] = '\0'; + char buf[BUFSIZ]; + register struct pair *pp; - for (pp = fs_names; pp->type; pp++) { - if (stat & pp->type) { - if (n_names) (void) strcat(buf, ", "); - (void) strcat(buf, pp->name); - n_names++; - stat &= ~pp->type; + int n_names = 0; + int stat = atoi(fs_status); + + buf[0] = '\0'; + + for (pp = fs_names; pp->type; pp++) + { + if (stat & pp->type) + { + if (n_names) + strcat(buf, ", "); + strcat(buf, pp->name); + n_names++; + stat &= ~pp->type; } } - if (stat) { - char buf1[100]; - - if (n_names) (void) strcat (buf, ", "); - (void) sprintf(buf1, "Unknown bits 0x%x", stat); - (void) strcat (buf, buf1); + if (stat) + { + char buf1[100]; + + if (n_names) + strcat(buf, ", "); + sprintf(buf1, "Unknown bits 0x%x", stat); + strcat(buf, buf1); } - if (!n_names) (void) strcpy(buf, "none"); - return strsave(buf); + if (!n_names) + strcpy(buf, "none"); + return strsave(buf); } /* * Given a string describing a filesystem allocation type, return the * numeric value. */ -char * -parse_filesys_type(fs_type_name) - char *fs_type_name; +char *parse_filesys_type(char *fs_type_name) { - register struct pair *pp; - register char *cp = fs_type_name; - char temp[BUFSIZ]; - int flags = 0; - - do { - /* Copy next component of type to temp */ - char *t = strchr (cp, ','); - if (t) { - memcpy(temp, cp, t-cp); - temp[t-cp]='\0'; - cp = t + 1; /* one after the comma */ - } else { - (void) strcpy(temp, cp); - cp = NULL; + register struct pair *pp; + register char *cp = fs_type_name; + char temp[BUFSIZ]; + int flags = 0; + + do + { + /* Copy next component of type to temp */ + char *t = strchr(cp, ','); + if (t) + { + memcpy(temp, cp, t - cp); + temp[t - cp] = '\0'; + cp = t + 1; /* one after the comma */ + } + else + { + strcpy(temp, cp); + cp = NULL; } - t = strtrim(temp); /* nuke leading and trailing whitespace */ + t = strtrim(temp); /* nuke leading and trailing whitespace */ - for (pp = fs_names; pp->type; pp++) { - if (strcasecmp(pp->name, t) == 0) { - flags |= pp->type; - break; + for (pp = fs_names; pp->type; pp++) + { + if (!strcasecmp(pp->name, t)) + { + flags |= pp->type; + break; } } - } while (cp); - (void) sprintf(temp, "%d", flags); - return strsave(temp); + } + while (cp); + sprintf(temp, "%d", flags); + return strsave(temp); } diff --git a/lib/sq.c b/lib/sq.c index eac91562..406f0b59 100644 --- a/lib/sq.c +++ b/lib/sq.c @@ -12,137 +12,130 @@ #include #include -struct save_queue * -sq_create() +struct save_queue *sq_create(void) { - register struct save_queue *sq; - - sq = (struct save_queue *)malloc(sizeof (struct save_queue)); - if (!sq) return sq; - sq->q_next = sq; - sq->q_prev = sq; - sq->q_lastget = 0; - return(sq); + register struct save_queue *sq; + + sq = malloc(sizeof(struct save_queue)); + if (!sq) + return sq; + sq->q_next = sq; + sq->q_prev = sq; + sq->q_lastget = 0; + return sq; } -int -sq_save_data(sq, data) - register struct save_queue *sq; - char *data; +int sq_save_data(register struct save_queue *sq, char *data) { - register struct save_queue *q; - - q = (struct save_queue *)malloc(sizeof (struct save_queue)); - if (!q) return 0; - q->q_next = sq; - q->q_prev = sq->q_prev; - sq->q_prev->q_next = q; - sq->q_prev = q; - q->q_data = data; - return 1; + register struct save_queue *q; + + q = malloc(sizeof(struct save_queue)); + if (!q) + return 0; + q->q_next = sq; + q->q_prev = sq->q_prev; + sq->q_prev->q_next = q; + sq->q_prev = q; + q->q_data = data; + return 1; } -int -sq_save_args(argc, argv, sq) - register struct save_queue *sq; - register int argc; - register char *argv[]; +int sq_save_args(register int argc, register char *argv[], + register struct save_queue *sq) { - register char **argv_copy; - register int i; - register int n; - - argv_copy = (char **)malloc(argc * sizeof (char *)); - if (!argv_copy) return 0; - for (i = 0; i < argc; i++) { - n = strlen(argv[i]) + 1; - argv_copy[i] = (char *)malloc(n); - if (!argv_copy[i]) { - for(i--; i>=0; i--) free(argv_copy[i]); - free((char **)argv_copy); + register char **argv_copy; + register int i; + register int n; + + argv_copy = malloc(argc * sizeof(char *)); + if (!argv_copy) + return 0; + for (i = 0; i < argc; i++) + { + n = strlen(argv[i]) + 1; + argv_copy[i] = malloc(n); + if (!argv_copy[i]) + { + for (i--; i >= 0; i--) + free(argv_copy[i]); + free(argv_copy); return 0; } - memcpy(argv_copy[i], argv[i], n); + memcpy(argv_copy[i], argv[i], n); } - return sq_save_data(sq, (char *)argv_copy); + return sq_save_data(sq, (char *)argv_copy); } -int -sq_save_unique_data(sq, data) - register struct save_queue *sq; - char *data; +int sq_save_unique_data(register struct save_queue *sq, char *data) { - register struct save_queue *q; + register struct save_queue *q; - for (q = sq->q_next; q != sq; q = q->q_next) - if (q->q_data == data) return 1; + for (q = sq->q_next; q != sq; q = q->q_next) + { + if (q->q_data == data) + return 1; + } - return sq_save_data(sq, data); + return sq_save_data(sq, data); } -int -sq_save_unique_string(sq, data) - register struct save_queue *sq; - char *data; +int sq_save_unique_string(register struct save_queue *sq, char *data) { - register struct save_queue *q; + register struct save_queue *q; - for (q = sq->q_next; q != sq; q = q->q_next) - if (!strcmp(q->q_data, data)) return 1; + for (q = sq->q_next; q != sq; q = q->q_next) + { + if (!strcmp(q->q_data, data)) + return 1; + } - return sq_save_data(sq, data); + return sq_save_data(sq, data); } -int -sq_get_data(sq, data) - register struct save_queue *sq; - register char **data; +int sq_get_data(register struct save_queue *sq, register char **data) { - if (sq->q_lastget == (struct save_queue *)0) { - sq->q_lastget = sq->q_next; - } else { - sq->q_lastget = sq->q_lastget->q_next; - } - - if (sq->q_lastget == sq) return(0); - *data = sq->q_lastget->q_data; - return(1); + if (sq->q_lastget == (struct save_queue *)0) + sq->q_lastget = sq->q_next; + else + sq->q_lastget = sq->q_lastget->q_next; + + if (sq->q_lastget == sq) + return 0; + *data = sq->q_lastget->q_data; + return 1; } -int -sq_remove_data(sq, data) - register struct save_queue *sq; - register char **data; +int sq_remove_data(register struct save_queue *sq, register char **data) { - if (sq->q_next != sq) { - *data = sq->q_next->q_data; - sq->q_next = sq->q_next->q_next; - free(sq->q_next->q_prev); - sq->q_next->q_prev = sq; - return(1); + if (sq->q_next != sq) + { + *data = sq->q_next->q_data; + sq->q_next = sq->q_next->q_next; + free(sq->q_next->q_prev); + sq->q_next->q_prev = sq; + return 1; } - return(0); + return 0; } -int sq_empty(sq) - register struct save_queue *sq; +int sq_empty(register struct save_queue *sq) { - if (sq->q_next == sq) - return(1); - else - return(0); + if (sq->q_next == sq) + return 1; + else + return 0; } -sq_destroy(sq) - register struct save_queue *sq; +sq_destroy(register struct save_queue *sq) { - register struct save_queue *q; + register struct save_queue *q; - for (q = sq->q_next; q != sq; q = sq->q_next) { - sq->q_next = q->q_next; - free(q); + for (q = sq->q_next; q != sq; q = sq->q_next) + { + sq->q_next = q->q_next; + free(q); } - free(sq); + free(sq); } diff --git a/lib/strs.c b/lib/strs.c index 8845663b..c0b7cd4c 100644 --- a/lib/strs.c +++ b/lib/strs.c @@ -27,129 +27,81 @@ static char *rcsid_strs_c = "$Header$"; /* * Make a copy of a string. */ -char * -strsave(s) - char *s; +char *strsave(char *s) { - register int len; - register char *p; - /* Kludge for sloppy string semantics */ - if (!s) { - p = malloc(1); - *p = '\0'; - return p; + register int len; + register char *p; + /* Kludge for sloppy string semantics */ + if (!s) + { + p = malloc(1); + *p = '\0'; + return p; } - len = strlen(s) + 1; - p = malloc((u_int)len); - if (p) memcpy(p, s, len); - return p; + len = strlen(s) + 1; + p = malloc(len); + if (p) + memcpy(p, s, len); + return p; } + /* * Trim whitespace off both ends of a string. */ -char *strtrim(save) - register char *save; +char *strtrim(register char *save) { - register char *t, *s; - - s = save; - while (isspace(*s)) s++; - /* skip to end of string */ - if (*s == '\0') { - *save = '\0'; - return(save); + register char *t, *s; + + s = save; + while (isspace(*s)) + s++; + /* skip to end of string */ + if (*s == '\0') + { + *save = '\0'; + return save; } - for (t = s; *t; t++) continue; - while (t > s) { - --t; - if (!isspace(*t)) { - t++; - break; + for (t = s; *t; t++) + continue; + while (t > s) + { + --t; + if (!isspace(*t)) + { + t++; + break; } } - if (*t) *t = '\0'; - return s; + if (*t) + *t = '\0'; + return s; } /* Modify a string for all of the letters to be uppercase. */ -char *uppercase(s) -char *s; +char *uppercase(char *s) { - register char *p; + register char *p; - for (p = s; *p; p++) + for (p = s; *p; p++) + { if (islower(*p)) *p = toupper(*p); - return(s); + } + return s; } -char *lowercase(s) -char *s; +char *lowercase(char *s) { - register char *p; + register char *p; - for (p = s; *p; p++) + for (p = s; *p; p++) + { if (isupper(*p)) *p = tolower(*p); - return(s); -} - - -#ifdef NEED_STRCASECMP - -/* Case independant string comparison. Only compile this if your C - * library doesn't have a local routine which is faster. - */ - -static char map[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - ' ', '!', '"', '#', '$', '%', '&', '\'', - '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ':', ';', '<', '=', '>', '?', - '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'k', 'j', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', '[', '\\', ']', '^', '_', - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'k', 'j', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', '{', '|', '}', '~', 127, - 128, 129, 130, 131, 132, 133, 134, 135, - 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, - 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, - 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255 -}; - - -int strcasecmp(s1, s2) -char *s1; -char *s2; -{ - while (map[*s1] == map[*s2]) { - if (*s1 == 0) - return(0); - s1++; - s2++; } - return(map[*s1] - map[*s2]); + return s; } - -#endif /* NEED_STRCASECMP */ diff --git a/lib/ureg_err.et b/lib/ureg_err.et index 959da691..7987cc6a 100644 --- a/lib/ureg_err.et +++ b/lib/ureg_err.et @@ -20,4 +20,4 @@ ec UREG_HALF_ENROLLED, "Halfway enrolled in campus namespace." end - + diff --git a/reg_svr/reg_svr.c b/reg_svr/reg_svr.c index ad7d2234..27bbce4b 100644 --- a/reg_svr/reg_svr.c +++ b/reg_svr/reg_svr.c @@ -21,6 +21,7 @@ static char *rcsid_reg_svr_c = "$Header$"; #include #include +#include #include #include #include @@ -41,104 +42,95 @@ extern char admin_errmsg[]; void reg_com_err_hook(); -main(argc,argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { - struct msg message; /* Storage for parsed packet */ - int status = SUCCESS; /* Error status */ - char retval[BUFSIZ]; /* Buffer to hold return message for client */ - - void req_initialize(); /* Initialize request layer */ - void get_request(); /* Get a request */ - void report(); /* Respond to a request */ - - /* Initialize */ - whoami = argv[0]; - - /* Error messages sent one line at a time */ - setvbuf(stderr, NULL, _IOLBF, BUFSIZ); - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); - set_com_err_hook(reg_com_err_hook); - - /* Initialize com_err error tables */ - init_ureg_err_tbl(); - init_krb_err_tbl(); - init_kadm_err_tbl(); - initialize_gdss_error_table(); - - /* Use com_err or output to stderr for all log messages. */ -#ifdef DEBUG - com_err(whoami, 0, "*** Debugging messages enabled. ***"); -#endif DEBUG - - /* Set the name of our kerberos ticket file */ - krb_set_tkt_string("/tmp/tkt_ureg"); - - /* Connect to the Moira server */ - if ((status = mr_connect(MOIRA_SERVER)) != MR_SUCCESS) + struct msg message; /* Storage for parsed packet */ + int status = SUCCESS; /* Error status */ + char retval[BUFSIZ]; /* Buffer to hold return message for client */ + + void req_initialize(); /* Initialize request layer */ + void get_request(); /* Get a request */ + void report(); /* Respond to a request */ + + /* Initialize */ + whoami = argv[0]; + + /* Error messages sent one line at a time */ + setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + set_com_err_hook(reg_com_err_hook); + + /* Initialize com_err error tables */ + init_ureg_err_tbl(); + init_krb_err_tbl(); + init_kadm_err_tbl(); + initialize_gdss_error_table(); + + /* Set the name of our kerberos ticket file */ + krb_set_tkt_string("/tmp/tkt_ureg"); + + /* Connect to the Moira server */ + if ((status = mr_connect(MOIRA_SERVER)) != MR_SUCCESS) { - com_err(whoami, status, " on mr_connect"); - exit(1); + com_err(whoami, status, " on mr_connect"); + exit(1); } - - /* Authorize, telling the server who you are */ - if ((status = mr_auth(whoami)) != MR_SUCCESS) + + /* Authorize, telling the server who you are */ + if ((status = mr_auth(whoami)) != MR_SUCCESS) { - com_err(whoami, status, " on mr_auth"); - exit(1); + com_err(whoami, status, " on mr_auth"); + exit(1); } - - journal = fopen(REGJOURNAL, "a"); - if (journal == NULL) { - com_err(whoami, errno, " while opening journal file"); - exit(1); + + journal = fopen(REGJOURNAL, "a"); + if (!journal) + { + com_err(whoami, errno, " while opening journal file"); + exit(1); } - - /* Allow request layer to initialize */ - req_initialize(); - - /* Sit around waiting for requests from the client. */ - for (;;) + + /* Allow request layer to initialize */ + req_initialize(); + + /* Sit around waiting for requests from the client. */ + for (;;) { - get_request(&message); - - switch((int)message.request) + get_request(&message); + + switch (message.request) { - case UREG_VERIFY_USER: - status = verify_user(&message,retval); - break; - case UREG_RESERVE_LOGIN: - status = reserve_user(&message,retval); - break; - case UREG_SET_PASSWORD: - case UREG_GET_KRB: - status = set_password(&message,retval); - break; - case UREG_SET_IDENT: - status = set_identity(&message,retval); - break; - case UREG_GET_SECURE: - status = get_secure(&message,retval); - break; - case UREG_SET_SECURE: - status = set_secure(&message,retval); - break; - default: - status = UREG_UNKNOWN_REQUEST; - critical_alert(FAIL_INST,"Unknown request %d from userreg.", - message.request); - break; + case UREG_VERIFY_USER: + status = verify_user(&message, retval); + break; + case UREG_RESERVE_LOGIN: + status = reserve_user(&message, retval); + break; + case UREG_SET_PASSWORD: + case UREG_GET_KRB: + status = set_password(&message, retval); + break; + case UREG_SET_IDENT: + status = set_identity(&message, retval); + break; + case UREG_GET_SECURE: + status = get_secure(&message, retval); + break; + case UREG_SET_SECURE: + status = set_secure(&message, retval); + break; + default: + status = UREG_UNKNOWN_REQUEST; + critical_alert(FAIL_INST, "Unknown request %d from userreg.", + message.request); + break; } - - /* Report what happened to client */ - report(status, retval); + + /* Report what happened to client */ + report(status, retval); } } -int parse_encrypted(message,data) - struct msg *message; /* Formatted packet */ - struct db_data *data; /* Data from the Moira database */ /* This routine makes sure that the ID from the database matches the ID sent accross in the packet. The information in the packet was created in the following way: @@ -149,918 +141,850 @@ int parse_encrypted(message,data) The plain text ID number was encrypted via EncryptID() resulting in the form that would appear in the Moira database. This is - concatinated to the plain text ID so that the ID string contains plain + concatenated to the plain text ID so that the ID string contains plain text ID followed by a null followed by the encrypted ID. Other information such as the username or password is appended. The whole thing is then DES encrypted using the encrypted ID as the source of the key. This routine tries each ID in the database that belongs - to someone with this user's first and last name and tries to - decrypt the packet with this information. If it succeeds, it returns + to someone with this user's first and last name and tries to + decrypt the packet with this information. If it succeeds, it returns zero and initializes all the fields of the formatted packet structure that depend on the encrypted information. */ + +int parse_encrypted(struct msg *message, struct db_data *data) { - des_cblock key; /* The key for DES en/decryption */ - des_key_schedule sched; /* En/decryption schedule */ - static char decrypt[BUFSIZ]; /* Buffer to hold decrypted information */ - long decrypt_len; /* Length of decypted ID information */ - char recrypt[14]; /* Buffer to hold re-encrypted information */ - static char hashid[14]; /* Buffer to hold one-way encrypted ID */ - char idnumber[BUFSIZ]; /* Buffer to hold plain-text ID */ - char *temp; /* A temporary string pointer */ - int len; /* Keeps track of length left in packet */ - int status = SUCCESS; /* Error status */ - -#ifdef DEBUG - com_err(whoami, 0, "Entering parse_encrypted"); -#endif - - /* Make the decrypted information length the same as the encrypted - information length. Both are integral multples of eight bytes - because of the DES encryption routines. */ - decrypt_len = (long)message->encrypted_len; - - /* Get key from the possibly one-way encrypted ID in the Moira database */ - if (data->mit_id[0] >= '0' && data->mit_id[0] <= '9') { - char buf[32]; - - EncryptID(buf, data->mit_id, message->first, message->last); - des_string_to_key(buf, key); - } else - des_string_to_key(data->mit_id, key); - - /* Get schedule from key */ - des_key_sched(key, sched); - /* Decrypt information from packet using this key. Since decrypt_len - is an integral multiple of eight bytes, it will probably be null- - padded. */ - des_pcbc_encrypt(message->encrypted, decrypt, decrypt_len, - sched, key, DES_DECRYPT); - - /* Extract the plain text and encrypted ID fields from the decrypted - packet information. */ - /* Since the decrypted information starts with the plain-text ID - followed by a null, if the decryption worked, this will only - copy the plain text part of the decrypted information. It is - important that strncpy be used because if we are not using the - correct key, there is no guarantee that a null will occur - anywhere in the string. */ - (void) strncpy(idnumber,decrypt,(int)decrypt_len); - /* Check that the idnumber of a mismatched decryption doesn't overflow - * the buffer. - */ - if (strlen(idnumber) != 9) { -#ifdef DEBUG - com_err(whoami, 0, "idnumber wrong size, probable user mismatch\n"); -#endif - return(FAILURE); - } - /* Point temp to the end of the plain text ID number. */ - temp = decrypt + strlen(idnumber) + 1; - /* Find out how much more packet there is. */ - len = message->encrypted_len - (temp - decrypt); - /* Copy the next CRYPT_LEN bytes of the decrypted information into - hashid if there are CRYPT_LEN more bytes to copy. There will be - if we have the right key. */ - (void) strncpy(hashid, temp, min(len, CRYPT_LEN)); - /* Point temp to the end of the encrypted ID field */ - temp += strlen(hashid) + 1; - /* Find out how much more room there is. */ - len = message->encrypted_len - (temp - decrypt); - - /* Now compare encrypted ID and clear text ID for a match. */ - if (strcmp(hashid, data->mit_id) && - strcmp(idnumber, data->mit_id)) - status = FAILURE; - - if (status == SUCCESS) + des_cblock key; /* The key for DES en/decryption */ + des_key_schedule sched; /* En/decryption schedule */ + static char decrypt[BUFSIZ]; /* Buffer to hold decrypted information */ + long decrypt_len; /* Length of decypted ID information */ + char recrypt[14]; /* Buffer to hold re-encrypted information */ + static char hashid[14]; /* Buffer to hold one-way encrypted ID */ + char idnumber[BUFSIZ]; /* Buffer to hold plain-text ID */ + char *temp; /* A temporary string pointer */ + int len; /* Keeps track of length left in packet */ + int status = SUCCESS; /* Error status */ + + /* Make the decrypted information length the same as the encrypted + information length. Both are integral multples of eight bytes + because of the DES encryption routines. */ + decrypt_len = message->encrypted_len; + + /* Get key from the possibly one-way encrypted ID in the Moira database */ + if (data->mit_id[0] >= '0' && data->mit_id[0] <= '9') { - /* We made it. Now we can finish initializing message. */ - /* Point leftover to whatever is left over! */ - message->leftover = temp; - message->leftover_len = len; - /* Since we know we have the right user, fill in the information - from the Moira database. */ - message->db.reg_status = data->reg_status; - (void) strncpy(message->db.uid,data->uid, sizeof(message->db.uid)); - (void) strncpy(message->db.mit_id,data->mit_id, - sizeof(message->db.mit_id)); - (void) strncpy(message->db.login,data->login, sizeof(message->db.login)); + char buf[32]; + + EncryptID(buf, data->mit_id, message->first, message->last); + des_string_to_key(buf, key); + } + else + des_string_to_key(data->mit_id, key); + + /* Get schedule from key */ + des_key_sched(key, sched); + /* Decrypt information from packet using this key. Since decrypt_len + is an integral multiple of eight bytes, it will probably be null- + padded. */ + des_pcbc_encrypt(message->encrypted, decrypt, decrypt_len, + sched, key, DES_DECRYPT); + + /* Extract the plain text and encrypted ID fields from the decrypted + packet information. */ + /* Since the decrypted information starts with the plain-text ID + followed by a null, if the decryption worked, this will only + copy the plain text part of the decrypted information. It is + important that strncpy be used because if we are not using the + correct key, there is no guarantee that a null will occur + anywhere in the string. */ + strncpy(idnumber, decrypt, decrypt_len); + /* Check that the idnumber of a mismatched decryption doesn't overflow + * the buffer. */ + if (strlen(idnumber) != 9) + return FAILURE; + + /* Point temp to the end of the plain text ID number. */ + temp = decrypt + strlen(idnumber) + 1; + /* Find out how much more packet there is. */ + len = message->encrypted_len - (temp - decrypt); + /* Copy the next CRYPT_LEN bytes of the decrypted information into + hashid if there are CRYPT_LEN more bytes to copy. There will be + if we have the right key. */ + strncpy(hashid, temp, min(len, CRYPT_LEN)); + /* Point temp to the end of the encrypted ID field */ + temp += strlen(hashid) + 1; + /* Find out how much more room there is. */ + len = message->encrypted_len - (temp - decrypt); + + /* Now compare encrypted ID and clear text ID for a match. */ + if (strcmp(hashid, data->mit_id) && + strcmp(idnumber, data->mit_id)) + status = FAILURE; + + if (status == SUCCESS) + { + /* We made it. Now we can finish initializing message. */ + /* Point leftover to whatever is left over! */ + message->leftover = temp; + message->leftover_len = len; + /* Since we know we have the right user, fill in the information + from the Moira database. */ + message->db.reg_status = data->reg_status; + strncpy(message->db.uid, data->uid, sizeof(message->db.uid)); + strncpy(message->db.mit_id, data->mit_id, sizeof(message->db.mit_id)); + strncpy(message->db.login, data->login, sizeof(message->db.login)); } - -#ifdef DEBUG - if (status) - com_err(whoami, status, " in parse_encrypted"); - else - com_err(whoami, status, "parse_encrypted succeeded"); -#endif return status; } -int db_callproc(argc,argv,queue) - int argc; /* Number of arguments returned by Moira */ - char *argv[]; /* Arguments returned by Moira */ - struct save_queue *queue; /* Queue to save information in */ /* This function is called by mr_query after each tuple found. It is used by find_user to cache information about each user found. */ +int db_callproc(int argc, char **argv, struct save_queue *queue) { - struct db_data *data; /* Structure to store the information in */ - int status = SUCCESS; /* Error status */ - -#ifdef DEBUG - com_err(whoami, 0, "Entering db_callproc."); -#endif - - if (argc != U_END) + struct db_data *data; /* Structure to store the information in */ + int status = SUCCESS; /* Error status */ + + if (argc != U_END) { - critical_alert - (FAIL_INST, - "Wrong number of arguments returned from get_user_account_by_name."); - status = MR_ABORT; + critical_alert(FAIL_INST, "Wrong number of arguments returned " + "from get_user_account_by_name."); + status = MR_ABORT; } - else + else { - /* extract the needed information from the results of the Moira query */ - data = (struct db_data *)malloc(sizeof(struct db_data)); - data->reg_status = atoi(argv[U_STATE]); - (void) strncpy(data->login,argv[U_NAME],sizeof(data->login)); - (void) strncpy(data->mit_id,argv[U_MITID],sizeof(data->mit_id)); - (void) strncpy(data->uid,argv[U_UID],sizeof(data->uid)); -#ifdef DEBUG - fprintf(stderr,"Found in database:\n"); - fprintf(stderr," Registration status: %d\n",data->reg_status); - fprintf(stderr," login: %s\n",data->login); - fprintf(stderr," MIT ID: %s\n",data->mit_id); - fprintf(stderr," uid: %s\n",data->uid); -#endif - sq_save_data(queue,data); + /* extract the needed information from the results of the Moira query */ + data = malloc(sizeof(struct db_data)); + data->reg_status = atoi(argv[U_STATE]); + strncpy(data->login, argv[U_NAME], sizeof(data->login)); + strncpy(data->mit_id, argv[U_MITID], sizeof(data->mit_id)); + strncpy(data->uid, argv[U_UID], sizeof(data->uid)); + sq_save_data(queue, data); } - return status; + return status; } - -int find_user(message) - struct msg *message; /* Formatted packet structure */ + /* This routine verifies that a user is allowed to register by finding him/her in the Moira database. It returns the status of the Moira query that it calls. */ +int find_user(struct msg *message) { #define GUBN_ARGS 2 /* Arguements needed by get_user_by_name */ - char *q_name; /* Name of query */ - int q_argc; /* Number of arguments for query */ - char *q_argv[GUBN_ARGS]; /* Arguments to query */ - int status = SUCCESS; /* Query return status */ - - struct save_queue *queue; /* Queue to hold Moira data */ - struct db_data *data; /* Structure for data for one tuple */ - short verified = FALSE; /* Have we verified the user? */ - - /* Zero the mit_id field in the formatted packet structure. This - being zeroed means that no user was found. */ - memset(message->db.mit_id,0,sizeof(message->db.mit_id)); - - if (status == SUCCESS) + char *q_name; /* Name of query */ + int q_argc; /* Number of arguments for query */ + char *q_argv[GUBN_ARGS]; /* Arguments to query */ + int status = SUCCESS; /* Query return status */ + + struct save_queue *queue; /* Queue to hold Moira data */ + struct db_data *data; /* Structure for data for one tuple */ + short verified = FALSE; /* Have we verified the user? */ + + /* Zero the mit_id field in the formatted packet structure. This + being zeroed means that no user was found. */ + memset(message->db.mit_id, 0, sizeof(message->db.mit_id)); + + if (status == SUCCESS) { - /* Get ready to make an Moira query */ - q_name = "get_user_account_by_name"; - q_argc = GUBN_ARGS; /* #defined in this routine */ - q_argv[0] = message->first; - q_argv[1] = message->last; - - /* Create queue to hold information */ - queue = sq_create(); - - /* Do it */ - status = mr_query(q_name,q_argc,q_argv,db_callproc,(char *)queue); - -#ifdef DEBUG - fprintf(stderr," %d returned by get_user_by_name\n",status); -#endif - - if (status == MR_SUCCESS) + /* Get ready to make an Moira query */ + q_name = "get_user_account_by_name"; + q_argc = GUBN_ARGS; /* #defined in this routine */ + q_argv[0] = message->first; + q_argv[1] = message->last; + + /* Create queue to hold information */ + queue = sq_create(); + + /* Do it */ + status = mr_query(q_name, q_argc, q_argv, db_callproc, (char *)queue); + + if (status == MR_SUCCESS) { - /* Traverse the list, freeing data as we go. If sq_get_data() - returns zero if there is no more data on the queue. */ - while (sq_get_data(queue,&data)) + /* Traverse the list, freeing data as we go. If sq_get_data() + returns zero if there is no more data on the queue. */ + while (sq_get_data(queue, &data)) { - if (!verified) - /* parse_encrypted returns zero on success */ - verified = (parse_encrypted(message,data) == SUCCESS); - free((char *)data); + if (!verified) + /* parse_encrypted returns zero on success */ + verified = (parse_encrypted(message, data) == SUCCESS); + free(data); } } - /* Destroy the queue */ - sq_destroy(queue); + /* Destroy the queue */ + sq_destroy(queue); } - -#ifdef DEBUG - fprintf(stderr,"Returned from find_user\n"); - fprintf(stderr," MIT ID: %s\n", message->db.mit_id); - fprintf(stderr," Registration status: %d\n",message->db.reg_status); - fprintf(stderr," uid: %s\n",message->db.uid); - fprintf(stderr," login: %s\n",message->db.login); - fprintf(stderr," Status from query: %d\n",status); -#endif DEBGUG - return status; + return status; } -int verify_user(message,retval) - struct msg *message; - char *retval; - /* This routine determines whether a user is in the databse and returns - his state so that other routines can figure out whether he is the - correct state for various transactions. */ - +/* This routine determines whether a user is in the databse and returns + his state so that other routines can figure out whether he is the + correct state for various transactions. */ +int verify_user(struct msg *message, char *retval) { - int status = SUCCESS; /* Return status */ + int status = SUCCESS; /* Return status */ - /* Log that we are about to veryify user */ - com_err(whoami, 0, "verifying user %s %s",message->first,message->last); + /* Log that we are about to veryify user */ + com_err(whoami, 0, "verifying user %s %s", message->first, message->last); - /* Figure out what user (if any) can be found based on the - encrypted information in the packet. (See the comment on - parse_encrypted().) */ + /* Figure out what user (if any) can be found based on the + encrypted information in the packet. (See the comment on + parse_encrypted().) */ - status = find_user(message); + status = find_user(message); - /* If Moira coudn't find the user */ - if (status == MR_NO_MATCH) - status = UREG_USER_NOT_FOUND; - else if (status == MR_SUCCESS) + /* If Moira coudn't find the user */ + if (status == MR_NO_MATCH) + status = UREG_USER_NOT_FOUND; + else if (status == MR_SUCCESS) { - /* If the information sent over in the packet did not point to a - valid user, the mit_id field in the formatted packet structure - will be empty. */ - if (message->db.mit_id[0] == '\0') - status = UREG_USER_NOT_FOUND; - /* If the user was found but the registration has already started, - use this as the status */ - else + /* If the information sent over in the packet did not point to a + valid user, the mit_id field in the formatted packet structure + will be empty. */ + if (message->db.mit_id[0] == '\0') + status = UREG_USER_NOT_FOUND; + /* If the user was found but the registration has already started, + use this as the status */ + else { - switch (message->db.reg_status) + switch (message->db.reg_status) { - case US_NO_LOGIN_YET: - status = SUCCESS; - break; - case US_REGISTERED: - status = UREG_ALREADY_REGISTERED; - break; - case US_NO_PASSWD: - status = UREG_NO_PASSWD_YET; - break; - case US_DELETED: - status = UREG_DELETED; - break; - case US_NOT_ALLOWED: - status = UREG_NOT_ALLOWED; - break; - case US_ENROLLED: - status = UREG_ENROLLED; - break; - case US_ENROLL_NOT_ALLOWED: - status = UREG_ENROLL_NOT_ALLOWED; - break; + case US_NO_LOGIN_YET: + status = SUCCESS; + break; + case US_REGISTERED: + status = UREG_ALREADY_REGISTERED; + break; + case US_NO_PASSWD: + status = UREG_NO_PASSWD_YET; + break; + case US_DELETED: + status = UREG_DELETED; + break; + case US_NOT_ALLOWED: + status = UREG_NOT_ALLOWED; + break; + case US_ENROLLED: + status = UREG_ENROLLED; + break; + case US_ENROLL_NOT_ALLOWED: + status = UREG_ENROLL_NOT_ALLOWED; + break; case US_HALF_ENROLLED: - status = UREG_HALF_ENROLLED; - break; - default: - status = UREG_MISC_ERROR; - critical_alert(FAIL_INST,"Bad user state %d for login %s.", - message->db.reg_status, message->db.login); - break; + status = UREG_HALF_ENROLLED; + break; + default: + status = UREG_MISC_ERROR; + critical_alert(FAIL_INST, "Bad user state %d for login %s.", + message->db.reg_status, message->db.login); + break; } - /* Set retval to the login name so that the client can use - it in the error message it will give the user. */ - (void) strcpy(retval,message->db.login); + /* Set retval to the login name so that the client can use + it in the error message it will give the user. */ + strcpy(retval, message->db.login); } } - - if (status) - com_err(whoami, status, " returned from verify_user"); - else - com_err(whoami, 0, "User verified"); - return status; + if (status) + com_err(whoami, status, " returned from verify_user"); + else + com_err(whoami, 0, "User verified"); + + return status; } - -int ureg_kadm_init() + +int ureg_kadm_init(void) { - unsigned int status = SUCCESS; /* Return status */ - static char krbrealm[REALM_SZ]; /* kerberos realm name */ - static char hostbuf[BUFSIZ], *host; /* local hostname in principal fmt */ - static int inited = 0; - char *p; - -#ifdef DEBUG - com_err(whoami, 0, "Entering ureg_kadm_init"); -#endif DEBUG - - if (!inited) { - inited++; - memset(krbrealm, 0, sizeof(krbrealm)); - if (status = krb_get_lrealm(krbrealm, 1)) { - status += krb_err_base; - com_err(whoami, status, " fetching kerberos realm"); - exit(1); + unsigned int status = SUCCESS; /* Return status */ + static char krbrealm[REALM_SZ]; /* kerberos realm name */ + static char hostbuf[BUFSIZ], *host; /* local hostname in principal fmt */ + static int inited = 0; + char *p; + + if (!inited) + { + inited++; + memset(krbrealm, 0, sizeof(krbrealm)); + if (status = krb_get_lrealm(krbrealm, 1)) + { + status += krb_err_base; + com_err(whoami, status, " fetching kerberos realm"); + exit(1); } - if (gethostname(hostbuf, sizeof(hostbuf)) < 0) - com_err(whoami, errno, "getting local hostname"); - host = canonicalize_hostname(strsave(hostbuf)); - for (p = host; *p && *p != '.'; p++) + if (gethostname(hostbuf, sizeof(hostbuf)) < 0) + com_err(whoami, errno, "getting local hostname"); + host = canonicalize_hostname(strsave(hostbuf)); + for (p = host; *p && *p != '.'; p++) + { if (isupper(*p)) *p = tolower(*p); - *p = 0; + } + *p = 0; } - /* Get keys for interacting with Kerberos admin server. */ - /* principal, instance, realm, service, service instance, life, file */ - if (status = krb_get_svc_in_tkt(MOIRA_SNAME, host, krbrealm, PWSERV_NAME, - KADM_SINST, 1, KEYFILE)) - status += krb_err_base; - - if (status != SUCCESS) - com_err(whoami, status, " while get admin tickets"); - else { - if ((status = kadm_init_link(PWSERV_NAME, KADM_SINST, krbrealm)) != - KADM_SUCCESS) { - com_err(whoami, status, " while initializing kadmin connection"); - } + /* Get keys for interacting with Kerberos admin server. */ + /* principal, instance, realm, service, service instance, life, file */ + if (status = krb_get_svc_in_tkt(MOIRA_SNAME, host, krbrealm, PWSERV_NAME, + KADM_SINST, 1, KEYFILE)) + status += krb_err_base; + + if (status != SUCCESS) + com_err(whoami, status, " while get admin tickets"); + else + { + if ((status = kadm_init_link(PWSERV_NAME, KADM_SINST, krbrealm)) != + KADM_SUCCESS) + com_err(whoami, status, " while initializing kadmin connection"); } - return status; + return status; } -int null_callproc(argc,argv,message) - int argc; - char *argv[]; - char *message; - /* This routine is a null callback that should be used for queries that - do not return tuples. If it ever gets called, something is wrong. */ +/* This routine is a null callback that should be used for queries that + do not return tuples. If it ever gets called, something is wrong. */ +int null_callproc(int argc, char *argv[], char *message) { - critical_alert(FAIL_INST,"Something returned from an update query."); - return FAILURE; + critical_alert(FAIL_INST, "Something returned from an update query."); + return FAILURE; } /* - * This routine reserves a principal in kerberos by setting up a + * This routine reserves a principal in kerberos by setting up a * principal with a random initial key. */ -int reserve_krb(login) - char *login; +int reserve_krb(char *login) { - int status = SUCCESS; - Kadm_vals new; - des_cblock key; - u_long *lkey = (u_long *)key; - -#ifdef DEBUG - com_err(whoami, 0, "Entering reserve_krb"); -#endif DEBUG - - if ((status = ureg_kadm_init()) == SUCCESS) { - memset(&new, 0, sizeof(new)); - SET_FIELD(KADM_DESKEY, new.fields); - SET_FIELD(KADM_NAME, new.fields); - - (void) des_random_key(key); - new.key_low = htonl(lkey[0]); - new.key_high = htonl(lkey[1]); - strcpy(new.name, login); - - com_err(whoami, 0, "Creating kerberos principal for %s", login); - status = kadm_add(&new); - if (status != KADM_SUCCESS) - com_err(whoami, status, " while reserving principal"); - - memset(&new, 0, sizeof(new)); + int status = SUCCESS; + Kadm_vals new; + des_cblock key; + u_long *lkey = (u_long *)key; + + if ((status = ureg_kadm_init()) == SUCCESS) + { + memset(&new, 0, sizeof(new)); + SET_FIELD(KADM_DESKEY, new.fields); + SET_FIELD(KADM_NAME, new.fields); + + des_random_key(key); + new.key_low = htonl(lkey[0]); + new.key_high = htonl(lkey[1]); + strcpy(new.name, login); + + com_err(whoami, 0, "Creating kerberos principal for %s", login); + status = kadm_add(&new); + if (status != KADM_SUCCESS) + com_err(whoami, status, " while reserving principal"); + + memset(&new, 0, sizeof(new)); } - dest_tkt(); + dest_tkt(); - return(status); + return status; } /* - * This routine reserves a principal in kerberos by setting up a + * This routine reserves a principal in kerberos by setting up a * principal with a random initial key. */ -int setpass_krb(login, password) - char *login; - char *password; +int setpass_krb(char *login, char *password) { - int status = SUCCESS; - Kadm_vals new; - des_cblock key; - u_long *lkey = (u_long *)key; - - if ((status = ureg_kadm_init()) == SUCCESS) { - memset(&new, 0, sizeof(new)); - SET_FIELD(KADM_DESKEY, new.fields); - SET_FIELD(KADM_NAME, new.fields); - - (void) des_string_to_key(password, key); - new.key_low = htonl(lkey[0]); - new.key_high = htonl(lkey[1]); - strcpy(new.name, login); - - com_err(whoami, 0, "Setting password for %s", login); - /* First arguement is not used if user has modify privileges */ - if ((status = kadm_mod(&new, &new)) != KADM_SUCCESS) { - if (status == KADM_NOENTRY) { - com_err(whoami, 0, - "kerberos principal doesn't exist; creating"); - if ((status = kadm_add(&new)) != KADM_SUCCESS) - com_err(whoami, status, - " while creating kerberos principal"); + int status = SUCCESS; + Kadm_vals new; + des_cblock key; + u_long *lkey = (u_long *)key; + + if ((status = ureg_kadm_init()) == SUCCESS) + { + memset(&new, 0, sizeof(new)); + SET_FIELD(KADM_DESKEY, new.fields); + SET_FIELD(KADM_NAME, new.fields); + + des_string_to_key(password, key); + new.key_low = htonl(lkey[0]); + new.key_high = htonl(lkey[1]); + strcpy(new.name, login); + + com_err(whoami, 0, "Setting password for %s", login); + /* First arguement is not used if user has modify privileges */ + if ((status = kadm_mod(&new, &new)) != KADM_SUCCESS) + { + if (status == KADM_NOENTRY) + { + com_err(whoami, 0, "kerberos principal doesn't exist; creating"); + if ((status = kadm_add(&new)) != KADM_SUCCESS) + com_err(whoami, status, " while creating kerberos principal"); } - else - com_err(whoami, status, " while setting password"); + else + com_err(whoami, status, " while setting password"); } } - - dest_tkt(); - return(status); + + dest_tkt(); + return status; } -int reserve_user(message,retval) - struct msg *message; - char *retval; +int reserve_user(struct msg *message, char *retval) { - int q_argc; /* Number of arguments to query */ - char *q_argv[3]; /* Arguments to Moira query */ - char *q_name; /* Name of Moira query */ - int status = SUCCESS; /* General purpose error status */ - char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */ - char *login; /* The login name the user wants */ - register int i; /* A counter */ - - /* Log that we are about to reserve a user. */ - com_err(whoami, 0, "reserving user %s %s", - message->first, message->last); - - /* Check to make sure that we can verify this user. */ - if ((status = verify_user(message,retval)) == SUCCESS) + int q_argc; /* Number of arguments to query */ + char *q_argv[3]; /* Arguments to Moira query */ + char *q_name; /* Name of Moira query */ + int status = SUCCESS; /* General purpose error status */ + char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */ + char *login; /* The login name the user wants */ + register int i; /* A counter */ + + /* Log that we are about to reserve a user. */ + com_err(whoami, 0, "reserving user %s %s", message->first, message->last); + + /* Check to make sure that we can verify this user. */ + if ((status = verify_user(message, retval)) == SUCCESS) { - /* Get the requested login name from leftover packet information. */ - login = message->leftover; - - /* Check the login name for validity. The login name is currently - is allowed to contain lowercase letters in any position and - and numbers and underscore characters in any position but the - first. */ - if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME)) - status = UREG_INVALID_UNAME; + /* Get the requested login name from leftover packet information. */ + login = message->leftover; + + /* Check the login name for validity. The login name is currently + is allowed to contain lowercase letters in any position and + and numbers and underscore characters in any position but the + first. */ + if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME)) + status = UREG_INVALID_UNAME; } - if (status == SUCCESS) - if ((login[0] == '_') || isdigit(login[0])) - status = UREG_INVALID_UNAME; - - if (status == SUCCESS) + if (status == SUCCESS) + if ((login[0] == '_') || isdigit(login[0])) + status = UREG_INVALID_UNAME; + + if (status == SUCCESS) { - for (i = 0; i < strlen(login); i++) - if (!islower(login[i]) && !isdigit(login[i]) && - (login[i] != '_')) + for (i = 0; i < strlen(login); i++) + { + if (!islower(login[i]) && !isdigit(login[i]) && + (login[i] != '_')) { - status = UREG_INVALID_UNAME; - break; + status = UREG_INVALID_UNAME; + break; } + } } - if (status == SUCCESS) + if (status == SUCCESS) { - /* Now that we have a valid user with a valid login... */ - - /* First, try to reserve the user in Moira. */ - (void) sprintf(fstype_buf,"%d",MR_FS_STUDENT); - q_name = "register_user"; - q_argv[0] = message->db.uid; - q_argv[1] = login; - q_argv[2] = fstype_buf; - q_argc = 3; - status = mr_query(q_name,q_argc,q_argv,null_callproc,(char *)0); - switch (status) + /* Now that we have a valid user with a valid login... */ + + /* First, try to reserve the user in Moira. */ + sprintf(fstype_buf, "%d", MR_FS_STUDENT); + q_name = "register_user"; + q_argv[0] = message->db.uid; + q_argv[1] = login; + q_argv[2] = fstype_buf; + q_argc = 3; + status = mr_query(q_name, q_argc, q_argv, null_callproc, NULL); + switch (status) { - case MR_SUCCESS: - status = SUCCESS; - break; - case MR_IN_USE: - status = UREG_LOGIN_USED; - break; - case MR_DEADLOCK: - status = UREG_MISC_ERROR; - break; - default: - critical_alert(FAIL_INST,"%s returned from register_user.", - error_message(status)); - status = UREG_MISC_ERROR; - break; + case MR_SUCCESS: + status = SUCCESS; + break; + case MR_IN_USE: + status = UREG_LOGIN_USED; + break; + case MR_DEADLOCK: + status = UREG_MISC_ERROR; + break; + default: + critical_alert(FAIL_INST, "%s returned from register_user.", + error_message(status)); + status = UREG_MISC_ERROR; + break; } } - if (status == SUCCESS) + if (status == SUCCESS) { - /* - * Moira login was successfully created; try to reserve kerberos - * principal. - * - * If this routine fails, store the login in the retval so - * that it can be used in the client-side error message. - */ - if ((status = reserve_krb(login)) != SUCCESS) - (void) strcpy(retval, login); - } - - if (status) - com_err(whoami, status, " returned from reserve_user"); - else { - com_err(whoami, 0, "User reserved"); - } - - return status; + /* + * Moira login was successfully created; try to reserve kerberos + * principal. + * + * If this routine fails, store the login in the retval so + * that it can be used in the client-side error message. + */ + if ((status = reserve_krb(login)) != SUCCESS) + strcpy(retval, login); + } + + if (status) + com_err(whoami, status, " returned from reserve_user"); + else + com_err(whoami, 0, "User reserved"); + + return status; } -int set_final_status(message) -struct msg *message; - /* This routine updates a user's registration status to fully - registered. */ +/* This routine updates a user's registration status to fully + registered. */ +int set_final_status(struct msg *message) { - char *login; - char *q_name; /* Name of Moira query */ - int q_argc; /* Number of arguments for Moira query */ - char *q_argv[2]; /* Arguments to get user by uid */ - char state[7]; /* Can hold a 16 bit integer */ - int status; /* Error status */ - - if (message->request == UREG_SET_PASSWORD) - (void) sprintf(state,"%d",US_REGISTERED); - else if (message->db.reg_status == US_NO_LOGIN_YET) - (void) sprintf(state,"%d",US_ENROLLED); - else - (void) sprintf(state,"%d",US_ENROLL_NOT_ALLOWED); - - login = message->db.login; - com_err(whoami, 0, "Setting final status for %s to %s", login, state); - - q_name = "update_user_status"; - q_argc = 2; - q_argv[0] = login; - q_argv[1] = state; - if ((status = mr_query(q_name, q_argc, q_argv, null_callproc, - (char *)0)) != MR_SUCCESS) { - if (status == MR_DEADLOCK) - status = UREG_MISC_ERROR; - else - critical_alert(FAIL_INST,"%s returned from update_user_status.", - error_message(status)); - } - if (status) - com_err(whoami, status, " returned from set_final_status"); - else - com_err(whoami, 0, "Final status set"); - return status; + char *login; + char *q_name; /* Name of Moira query */ + int q_argc; /* Number of arguments for Moira query */ + char *q_argv[2]; /* Arguments to get user by uid */ + char state[7]; /* Can hold a 16 bit integer */ + int status; /* Error status */ + + if (message->request == UREG_SET_PASSWORD) + sprintf(state, "%d", US_REGISTERED); + else if (message->db.reg_status == US_NO_LOGIN_YET) + sprintf(state, "%d", US_ENROLLED); + else + sprintf(state, "%d", US_ENROLL_NOT_ALLOWED); + + login = message->db.login; + com_err(whoami, 0, "Setting final status for %s to %s", login, state); + + q_name = "update_user_status"; + q_argc = 2; + q_argv[0] = login; + q_argv[1] = state; + if ((status = mr_query(q_name, q_argc, q_argv, null_callproc, NULL)) + != MR_SUCCESS) + { + if (status == MR_DEADLOCK) + status = UREG_MISC_ERROR; + else + critical_alert(FAIL_INST, "%s returned from update_user_status.", + error_message(status)); + } + if (status) + com_err(whoami, status, " returned from set_final_status"); + else + com_err(whoami, 0, "Final status set"); + return status; } -int set_password(message,retval) - struct msg *message; - char *retval; - /* This routine is used to set the initial password for the new user. */ +/* This routine is used to set the initial password for the new user. */ +int set_password(struct msg *message, char *retval) { - int status = SUCCESS; /* Return status */ - char *passwd; /* User's password */ - - com_err(whoami, 0, "setting password %s %s", - message->first, message->last); - - status = verify_user(message,retval); - - /* Don't set the password unless the registration status of the user - is that he exists and has no password. */ - if (status == SUCCESS) - status = UREG_NO_LOGIN_YET; - if (((int)message->request == UREG_SET_PASSWORD && - status == UREG_NO_PASSWD_YET) || - ((int)message->request == UREG_GET_KRB && - status == UREG_HALF_ENROLLED)) + int status = SUCCESS; /* Return status */ + char *passwd; /* User's password */ + + com_err(whoami, 0, "setting password %s %s", message->first, message->last); + + status = verify_user(message, retval); + + /* Don't set the password unless the registration status of the user + is that he exists and has no password. */ + if (status == SUCCESS) + status = UREG_NO_LOGIN_YET; + if ((message->request == UREG_SET_PASSWORD && + status == UREG_NO_PASSWD_YET) || + (message->request == UREG_GET_KRB && + status == UREG_HALF_ENROLLED)) { - /* User is in proper state for this transaction. */ - - passwd = message->leftover; - - /* Set password. */ - if ((status = setpass_krb(message->db.login, passwd)) != SUCCESS) - /* If failure, allow login name to be used in client - error message */ - (void) strcpy(retval,message->db.login); - else - /* Otherwise, mark user as finished. */ - status = set_final_status(message); + /* User is in proper state for this transaction. */ + + passwd = message->leftover; + + /* Set password. */ + if ((status = setpass_krb(message->db.login, passwd)) != SUCCESS) + /* If failure, allow login name to be used in client error message */ + strcpy(retval, message->db.login); + else + /* Otherwise, mark user as finished. */ + status = set_final_status(message); } - if (status) - com_err(whoami, status, " returned from set_passwd"); - else - com_err(whoami, 0, "Password set"); + if (status) + com_err(whoami, status, " returned from set_passwd"); + else + com_err(whoami, 0, "Password set"); - return status; + return status; } -int getuserinfo(argc, argv, qargv) -int argc; -char **argv; -char **qargv; +int getuserinfo(int argc, char **argv, char **qargv) { - int status = SUCCESS; - int i; - - if (argc != U_END) { - critical_alert(FAIL_INST, - "Wrong number of args returned from get_user_by_uid"); - status = MR_ABORT; - } else { - qargv[U_NAME] = strsave(argv[U_NAME]); - for (i = 1; i < U_MODTIME; i++) - qargv[i+1] = strsave(argv[i]); - qargv[U_MODTIME+1] = NULL; + int status = SUCCESS; + int i; + + if (argc != U_END) + { + critical_alert(FAIL_INST, + "Wrong number of args returned from get_user_by_uid"); + status = MR_ABORT; } - return(status); + else + { + qargv[U_NAME] = strsave(argv[U_NAME]); + for (i = 1; i < U_MODTIME; i++) + qargv[i + 1] = strsave(argv[i]); + qargv[U_MODTIME + 1] = NULL; + } + return status; } -int set_identity(message,retval) -struct msg *message; -char *retval; +int set_identity(struct msg *message, char *retval) { - int q_argc; /* Number of arguments to query */ - char *q_argv[U_END]; /* Arguments to Moira query */ - char *q_name; /* Name of Moira query */ - int status = SUCCESS; /* General purpose error status */ - char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */ - char *login; /* The login name the user wants */ - register int i; /* A counter */ - - /* Log that we are about to reserve a user. */ - com_err(whoami, 0, "setting identity %s %s", - message->first, message->last); - - /* Check to make sure that we can verify this user. */ - status = verify_user(message,retval); - if (status == SUCCESS || status == UREG_NOT_ALLOWED) + int q_argc; /* Number of arguments to query */ + char *q_argv[U_END]; /* Arguments to Moira query */ + char *q_name; /* Name of Moira query */ + int status = SUCCESS; /* General purpose error status */ + char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */ + char *login; /* The login name the user wants */ + register int i; /* A counter */ + + /* Log that we are about to reserve a user. */ + com_err(whoami, 0, "setting identity %s %s", + message->first, message->last); + + /* Check to make sure that we can verify this user. */ + status = verify_user(message, retval); + if (status == SUCCESS || status == UREG_NOT_ALLOWED) { - status = SUCCESS; - /* Get the requested login name from leftover packet information. */ - login = message->leftover; - - /* Check the login name for validity. The login name is currently - is allowed to contain lowercase letters in any position and - and numbers and underscore characters in any position but the - first. */ - if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME)) - status = UREG_INVALID_UNAME; + status = SUCCESS; + /* Get the requested login name from leftover packet information. */ + login = message->leftover; + + /* Check the login name for validity. The login name is currently + is allowed to contain lowercase letters in any position and + and numbers and underscore characters in any position but the + first. */ + if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME)) + status = UREG_INVALID_UNAME; + } + if (status == SUCCESS) + { + if ((login[0] == '_') || isdigit(login[0])) + status = UREG_INVALID_UNAME; } - if (status == SUCCESS) - if ((login[0] == '_') || isdigit(login[0])) - status = UREG_INVALID_UNAME; - if (status == SUCCESS) + if (status == SUCCESS) { - for (i = 0; i < strlen(login); i++) - if (!islower(login[i]) && !isdigit(login[i]) && - (login[i] != '_')) + for (i = 0; i < strlen(login); i++) + { + if (!islower(login[i]) && !isdigit(login[i]) && + (login[i] != '_')) { - status = UREG_INVALID_UNAME; - break; + status = UREG_INVALID_UNAME; + break; } + } } - if (status == SUCCESS) + if (status == SUCCESS) { - /* Now that we have a valid user with a valid login... */ - - q_argv[0] = message->db.uid; - status = mr_query("get_user_account_by_uid", 1, q_argv, - getuserinfo, (char *)q_argv); - if (status != SUCCESS) { - com_err(whoami, status, " while getting user info"); - return(status); + /* Now that we have a valid user with a valid login... */ + + q_argv[0] = message->db.uid; + status = mr_query("get_user_account_by_uid", 1, q_argv, + getuserinfo, (char *)q_argv); + if (status != SUCCESS) + { + com_err(whoami, status, " while getting user info"); + return status; } - q_argv[U_NAME+1] = login; - q_argv[U_STATE+1] = "7"; - q_argv[U_SIGNATURE+1] = ""; - status = mr_query("update_user_account", U_MODTIME+1, q_argv, - null_callproc, NULL); - switch (status) + q_argv[U_NAME + 1] = login; + q_argv[U_STATE + 1] = "7"; + q_argv[U_SIGNATURE + 1] = ""; + status = mr_query("update_user_account", U_MODTIME + 1, q_argv, + null_callproc, NULL); + switch (status) { - case MR_SUCCESS: - status = SUCCESS; - break; - case MR_IN_USE: - case MR_NOT_UNIQUE: - status = UREG_LOGIN_USED; - break; - case MR_DEADLOCK: - status = UREG_MISC_ERROR; - break; - default: - critical_alert(FAIL_INST,"%s returned from update_user_account.", - error_message(status)); - status = UREG_MISC_ERROR; - break; + case MR_SUCCESS: + status = SUCCESS; + break; + case MR_IN_USE: + case MR_NOT_UNIQUE: + status = UREG_LOGIN_USED; + break; + case MR_DEADLOCK: + status = UREG_MISC_ERROR; + break; + default: + critical_alert(FAIL_INST, "%s returned from update_user_account.", + error_message(status)); + status = UREG_MISC_ERROR; + break; } } - if (status == SUCCESS) + if (status == SUCCESS) { - /* Moira login was successfully created; try to reserve kerberos - principal. */ - /* If this routine fails, store the login in the retval so - that it can be used in the client-side error message. */ - if ((status = reserve_krb(login)) != SUCCESS) - (void) strcpy(retval, login); + /* Moira login was successfully created; try to reserve kerberos + principal. */ + /* If this routine fails, store the login in the retval so + that it can be used in the client-side error message. */ + if ((status = reserve_krb(login)) != SUCCESS) + strcpy(retval, login); } - if (status) - com_err(whoami, status, " returned from set_identity"); - else - com_err(whoami, 0, "Identity set"); - - return status; + if (status) + com_err(whoami, status, " returned from set_identity"); + else + com_err(whoami, 0, "Identity set"); + + return status; } -void reg_com_err_hook(whoami, code, fmt, pvar) - char *whoami; - int code; - char *fmt; - caddr_t pvar; +void reg_com_err_hook(char *whoami, int code, char *fmt, caddr_t pvar) { - if (whoami) { - fputs(whoami, stderr); - fputs(": ", stderr); - } - if (code) { - fputs(error_message(code), stderr); - } - if (fmt) { - _doprnt(fmt, pvar, stderr); - } - putc('\n', stderr); - fflush(stderr); + if (whoami) + { + fputs(whoami, stderr); + fputs(": ", stderr); + } + if (code) + fputs(error_message(code), stderr); + if (fmt) + _doprnt(fmt, pvar, stderr); + putc('\n', stderr); + fflush(stderr); } -/* Find out of someone's secure instance password is set. +/* Find out if someone's secure instance password is set. * Returns UREG_ALREADY_REGISTERED if set, SUCCESS (0) if not. */ -int get_secure(message, retval) -struct msg *message; -char *retval; +int get_secure(struct msg *message, char *retval) { - int status; - char *argv[U_END]; - - com_err(whoami, 0, "checking status of secure password for %s", - message->first); - argv[0] = message->first; - status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, - (char *)argv); - if (status != SUCCESS) { - com_err(whoami, status, " while getting user info"); - return(status); + int status; + char *argv[U_END]; + + com_err(whoami, 0, "checking status of secure password for %s", + message->first); + argv[0] = message->first; + status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, + (char *)argv); + if (status != SUCCESS) + { + com_err(whoami, status, " while getting user info"); + return status; } - if (atoi(argv[U_SECURE + 1])) - return UREG_ALREADY_REGISTERED; - return SUCCESS; + if (atoi(argv[U_SECURE + 1])) + return UREG_ALREADY_REGISTERED; + return SUCCESS; } /* Set someone's secure instance password. */ -int set_secure(message, retval) -struct msg *message; -char *retval; +int set_secure(struct msg *message, char *retval) { - int status, i; - char *argv[U_END], hostbuf[256], *bp, *p, buf[512], *passwd, *id; - KTEXT_ST creds; - AUTH_DAT auth; - C_Block key; - Key_schedule keys; - Kadm_vals kv; - u_long *lkey = (u_long *)key; - struct timeval now; - static int inited = 0; - static char *host; - extern char *krb_get_phost(char *); - - if (!inited) { - inited++; - if (gethostname(hostbuf, sizeof(hostbuf)) < 0) - com_err(whoami, errno, "getting local hostname"); - host = strsave(krb_get_phost(hostbuf)); + int status, i; + char *argv[U_END], hostbuf[256], *bp, *p, buf[512], *passwd, *id; + KTEXT_ST creds; + AUTH_DAT auth; + C_Block key; + Key_schedule keys; + Kadm_vals kv; + u_long *lkey = (u_long *)key; + struct timeval now; + static int inited = 0; + static char *host; + extern char *krb_get_phost(char *); + + if (!inited) + { + inited++; + if (gethostname(hostbuf, sizeof(hostbuf)) < 0) + com_err(whoami, errno, "getting local hostname"); + host = strsave(krb_get_phost(hostbuf)); } - com_err(whoami, 0, "setting secure passwd for %s", message->first); - argv[0] = message->first; - status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, - (char *)argv); - if (status != SUCCESS) { - com_err(whoami, status, " while getting user info"); - return(status); + com_err(whoami, 0, "setting secure passwd for %s", message->first); + argv[0] = message->first; + status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, + (char *)argv); + if (status != SUCCESS) + { + com_err(whoami, status, " while getting user info"); + return status; } - if (atoi(argv[U_SECURE + 1])) { - com_err(whoami, UREG_ALREADY_REGISTERED, "in set_secure()"); - return UREG_ALREADY_REGISTERED; + if (atoi(argv[U_SECURE + 1])) + { + com_err(whoami, UREG_ALREADY_REGISTERED, "in set_secure()"); + return UREG_ALREADY_REGISTERED; } - bp = message->encrypted; - /* round up to word boundary */ - bp = (char *)((((u_long)bp + 3) >> 2) << 2); - - creds.length = ntohl(*((int *)bp)); - bp += sizeof(int); - memcpy(creds.dat, bp, creds.length); - creds.mbz = 0; - bp += creds.length; - -#ifdef DEBUG - com_err(whoami, 0, "Cred: length %d", creds.length); - for (i = 0; i < creds.length; i += 16) - com_err(whoami, 0, " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - creds.dat[i+0], creds.dat[i+1], creds.dat[i+2], creds.dat[i+3], - creds.dat[i+4], creds.dat[i+5], creds.dat[i+6], creds.dat[i+7], - creds.dat[i+8], creds.dat[i+9], creds.dat[i+10], creds.dat[i+11], - creds.dat[i+12], creds.dat[i+13], creds.dat[i+14], creds.dat[i+15]); -#endif /* DEBUG */ - - status = krb_rd_req(&creds, "changepw", host, cur_req_sender(), - &auth, ""); - if (status) { - status += krb_err_base; - com_err(whoami, status, " verifying credentials in set_secure()"); - return(status); + bp = message->encrypted; + /* round up to word boundary */ + bp = (char *)((((u_long)bp + 3) >> 2) << 2); + + creds.length = ntohl(*((int *)bp)); + bp += sizeof(int); + memcpy(creds.dat, bp, creds.length); + creds.mbz = 0; + bp += creds.length; + + status = krb_rd_req(&creds, "changepw", host, cur_req_sender(), &auth, ""); + if (status) + { + status += krb_err_base; + com_err(whoami, status, " verifying credentials in set_secure()"); + return status; } - message->leftover_len = ntohl(*((int*)(bp))); - bp += sizeof(int); - message->leftover = bp; - - des_key_sched(auth.session, keys); - des_pcbc_encrypt(message->leftover, buf, message->leftover_len, - keys, auth.session, 0); - - id = buf; - passwd = strchr(buf, ','); - *passwd++ = 0; -#ifdef DEBUG - com_err(whoami, 0, "Got id: %s, passwd %d chars", id, strlen(passwd)); -#endif - - if (strcmp(id, argv[U_MITID + 1])) { - char buf[32]; - - EncryptID(buf, id, argv[U_FIRST+1], argv[U_LAST+1]); - if (strcmp(buf, argv[U_MITID + 1])) { - status = UREG_USER_NOT_FOUND; - com_err(whoami, status, "IDs mismatch: %s (%s), %s", id, buf, - argv[U_MITID + 1]); - return status; + message->leftover_len = ntohl(*((int *)(bp))); + bp += sizeof(int); + message->leftover = bp; + + des_key_sched(auth.session, keys); + des_pcbc_encrypt(message->leftover, buf, message->leftover_len, + keys, auth.session, 0); + + id = buf; + passwd = strchr(buf, ','); + *passwd++ = 0; + + if (strcmp(id, argv[U_MITID + 1])) + { + char buf[32]; + + EncryptID(buf, id, argv[U_FIRST + 1], argv[U_LAST + 1]); + if (strcmp(buf, argv[U_MITID + 1])) + { + status = UREG_USER_NOT_FOUND; + com_err(whoami, status, "IDs mismatch: %s (%s), %s", id, buf, + argv[U_MITID + 1]); + return status; } } - /* now do actual password setting stuff */ + /* now do actual password setting stuff */ - if ((status = ureg_kadm_init()) != SUCCESS) { - com_err(whoami, status, "initing kadm stuff"); - return(status); + if ((status = ureg_kadm_init()) != SUCCESS) + { + com_err(whoami, status, "initing kadm stuff"); + return status; } - memset(&kv, 0, sizeof(kv)); - SET_FIELD(KADM_DESKEY, kv.fields); - SET_FIELD(KADM_NAME, kv.fields); - SET_FIELD(KADM_INST, kv.fields); - (void) des_string_to_key(passwd, key); - kv.key_low = htonl(lkey[0]); - kv.key_high = htonl(lkey[1]); - strcpy(kv.name, message->first); - strcpy(kv.instance, "extra"); - - if ((status = kadm_add(&kv)) != KADM_SUCCESS) { - com_err(whoami, status, " while creating kerberos principal"); - return(status); + memset(&kv, 0, sizeof(kv)); + SET_FIELD(KADM_DESKEY, kv.fields); + SET_FIELD(KADM_NAME, kv.fields); + SET_FIELD(KADM_INST, kv.fields); + des_string_to_key(passwd, key); + kv.key_low = htonl(lkey[0]); + kv.key_high = htonl(lkey[1]); + strcpy(kv.name, message->first); + strcpy(kv.instance, "extra"); + + if ((status = kadm_add(&kv)) != KADM_SUCCESS) + { + com_err(whoami, status, " while creating kerberos principal"); + return status; } - argv[0] = message->first; - argv[1] = buf; - gettimeofday(&now, NULL); - sprintf(buf, "%d", now.tv_sec); - status = mr_query("update_user_security_status", 2, argv, getuserinfo, - (char *)argv); - if (status != SUCCESS) { - com_err(whoami, status, " while updating user status"); - return(status); + argv[0] = message->first; + argv[1] = buf; + gettimeofday(&now, NULL); + sprintf(buf, "%d", now.tv_sec); + status = mr_query("update_user_security_status", 2, argv, getuserinfo, + (char *)argv); + if (status != SUCCESS) + { + com_err(whoami, status, " while updating user status"); + return status; } - return SUCCESS; + return SUCCESS; } diff --git a/reg_svr/reg_svr.h b/reg_svr/reg_svr.h index b54bab07..abb75ccc 100644 --- a/reg_svr/reg_svr.h +++ b/reg_svr/reg_svr.h @@ -29,7 +29,7 @@ #define CUR_UREG_VERSION 1 /* Version for the register protocol */ #define SUCCESS 0 /* General purpose success code */ #define FAILURE 1 /* To use when any non-zero number will work */ -#define min(a,b) ((a)>(b)?(b):(a)) +#define min(a,b) ((a) > (b) ? (b) : (a)) #define MIN_UNAME 3 /* Username must be between three and */ #define MAX_UNAME 8 /* eight characters long. */ #define CRYPT_LEN 14 /* crypt() returns a 13 char string */ @@ -40,31 +40,31 @@ extern char *whoami; /* Name of program - used by libraries */ extern int errno; /* Unix error number */ /* This structure holds information from the MOIRA database that will be - worth holding on to. An instance of it appears in the formatted + worth holding on to. An instance of it appears in the formatted packet structure. */ struct db_data { - char mit_id[CRYPT_LEN]; /* Encrypted MIT ID */ - int reg_status; /* Registration status */ - char uid[UID_LEN]; /* Reserved uid */ - char login[LOGIN_LEN]; /* Login (username) */ + char mit_id[CRYPT_LEN]; /* Encrypted MIT ID */ + int reg_status; /* Registration status */ + char uid[UID_LEN]; /* Reserved uid */ + char login[LOGIN_LEN]; /* Login (username) */ }; -/* This structure stores information sent over in the packet in a - more convenient format and also stores some information obtained +/* This structure stores information sent over in the packet in a + more convenient format and also stores some information obtained from the database that will be needed for each transaction. It initialized from format_pkt() and find_user(). */ struct msg -{ - U_32BIT version; /* User registration protocol version */ - U_32BIT request; /* Request */ - char *first; /* First name */ - char *last; /* Last name */ - char *encrypted; /* Encrypted information in packet */ - int encrypted_len; /* Length of encrypted information in packet */ - char *leftover; /* Leftover information sent in the packet */ - int leftover_len; /* Length of leftover information */ - struct db_data db; /* Information from the MOIRA database */ +{ + U_32BIT version; /* User registration protocol version */ + U_32BIT request; /* Request */ + char *first; /* First name */ + char *last; /* Last name */ + char *encrypted; /* Encrypted information in packet */ + int encrypted_len; /* Length of encrypted information in packet */ + char *leftover; /* Leftover information sent in the packet */ + int leftover_len; /* Length of leftover information */ + struct db_data db; /* Information from the MOIRA database */ }; void failure_alert(); /* Log an unexplainable failure */ diff --git a/reg_svr/requests.c b/reg_svr/requests.c index 5e81ba3f..8b859d38 100644 --- a/reg_svr/requests.c +++ b/reg_svr/requests.c @@ -19,7 +19,7 @@ static char *rcsid_requests_c = "$Header$"; /* * Before you add anything to the list of things that are #included and - * #defined, make sure that it is not already done in reg_svr.h + * #defined, make sure that it is not already done in reg_svr.h */ #include @@ -42,212 +42,200 @@ static char *rcsid_requests_c = "$Header$"; #define CUR_REQ (requests[cur_request_index]) /* The current request */ #define NEXT_INDEX(x) (x == NUM_REQUESTS_SAVED - 1) ? 0 : (x + 1) #define PREV_INDEX(x) (x == 0) ? (NUM_REQUESTS_SAVED - 1) : (x - 1) - + static struct servent *sp; /* Service info from /etc/services */ static int s; /* Socket descriptor */ static struct sockaddr_in sin; /* Internet style socket address */ static int addrlen; /* Size of socket address (sin) */ - -/* In order to elegantly handle multiple retransmissions, an instance + +/* In order to elegantly handle multiple retransmissions, an instance of this structure will be retained for the last NUM_REQUESTS_SAVED transactions with the client. */ struct request_save { - char out_pkt[BUFSIZ]; /* Buffer for outgoing packet */ - int out_pktlen; /* Length of outgoing packet */ - U_32BIT seqno; /* Sequence number for packet transmission */ - u_long ip_address; /* Internet address of client host */ - u_short cl_port; /* Port number client used */ + char out_pkt[BUFSIZ]; /* Buffer for outgoing packet */ + int out_pktlen; /* Length of outgoing packet */ + U_32BIT seqno; /* Sequence number for packet transmission */ + u_long ip_address; /* Internet address of client host */ + u_short cl_port; /* Port number client used */ }; static struct request_save requests[NUM_REQUESTS_SAVED]; /* Saved packets */ static int cur_request_index = 0; /* Index to the current request */ -void clear_req(req) - struct request_save *req; +void clear_req(struct request_save *req) { - req->seqno = 0; - req->ip_address = 0; - req->cl_port = 0; + req->seqno = 0; + req->ip_address = 0; + req->cl_port = 0; } -void req_initialize() +void req_initialize(void) { - register int i; + register int i; - /* Get service information from /etc/services */ - if ((sp = getservbyname("sms_ureg", "udp")) == NULL) + /* Get service information from /etc/services */ + if (!(sp = getservbyname("sms_ureg", "udp"))) { - com_err(whoami, errno, " unknown service sms_ureg/udp"); - exit(1); + com_err(whoami, errno, " unknown service sms_ureg/udp"); + exit(1); } - - /* Get an internet style datagram socket */ - if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) + + /* Get an internet style datagram socket */ + if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { - com_err(whoami,errno," socket"); - exit(1); + com_err(whoami, errno, " socket"); + exit(1); } - memset(&sin, 0, sizeof(sin)); - - sin.sin_family = AF_INET; - sin.sin_port = sp->s_port; - sin.sin_addr.s_addr = INADDR_ANY; - - /* Bind a name to the socket */ - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) + memset(&sin, 0, sizeof(sin)); + + sin.sin_family = AF_INET; + sin.sin_port = sp->s_port; + sin.sin_addr.s_addr = INADDR_ANY; + + /* Bind a name to the socket */ + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - com_err(whoami,errno," bind"); - exit(1); + com_err(whoami, errno, " bind"); + exit(1); } - for (i = 0; i < NUM_REQUESTS_SAVED; i++) - clear_req(&(requests[i])); -} + for (i = 0; i < NUM_REQUESTS_SAVED; i++) + clear_req(&(requests[i])); +} -int handle_retransmitted() +int handle_retransmitted(void) { - register int i; /* A counter */ - int status = FALSE; /* Return status */ - - for (i = PREV_INDEX(cur_request_index); i != cur_request_index; - i = PREV_INDEX(i)) + register int i; /* A counter */ + int status = FALSE; /* Return status */ + + for (i = PREV_INDEX(cur_request_index); i != cur_request_index; + i = PREV_INDEX(i)) { - if ((requests[i].seqno == CUR_REQ.seqno) && - (requests[i].ip_address == sin.sin_addr.s_addr) && - (requests[i].cl_port == sin.sin_port)) - /* This is a retransmitted packet */ + if ((requests[i].seqno == CUR_REQ.seqno) && + (requests[i].ip_address == sin.sin_addr.s_addr) && + (requests[i].cl_port == sin.sin_port)) + /* This is a retransmitted packet */ { -#ifdef DEBUG - com_err(whoami, 0, "Retransmitted packet detected."); -#endif - status = TRUE; - (void) sendto(s, requests[i].out_pkt, requests[i].out_pktlen, - 0, (struct sockaddr *)&sin, addrlen); - break; + status = TRUE; + sendto(s, requests[i].out_pkt, requests[i].out_pktlen, + 0, (struct sockaddr *)&sin, addrlen); + break; } } - return status; + return status; } -void respond(status,text) - int status; /* Return status for the client */ - char *text; /* Text for the client */ - /* This routine takes care of sending packets back to the client and - caching the necessary information for retransmission detection. - It is the only place in which cur_request_index should be - changed. */ +/* This routine takes care of sending packets back to the client and + caching the necessary information for retransmission detection. + It is the only place in which cur_request_index should be + changed. */ +void respond(int status, char *text) { - CUR_REQ.out_pktlen = sizeof(CUR_REQ.out_pkt); + CUR_REQ.out_pktlen = sizeof(CUR_REQ.out_pkt); - if (format_pkt(CUR_REQ.out_pkt, &(CUR_REQ.out_pktlen), - CUR_REQ.seqno, status, text)) - com_err(whoami,0,"Client error message was truncated."); - (void) sendto(s, CUR_REQ.out_pkt, CUR_REQ.out_pktlen, 0, - (struct sockaddr *)&sin, addrlen); + if (format_pkt(CUR_REQ.out_pkt, &(CUR_REQ.out_pktlen), + CUR_REQ.seqno, status, text)) + com_err(whoami, 0, "Client error message was truncated."); + sendto(s, CUR_REQ.out_pkt, CUR_REQ.out_pktlen, 0, + (struct sockaddr *)&sin, addrlen); - cur_request_index = NEXT_INDEX(cur_request_index); + cur_request_index = NEXT_INDEX(cur_request_index); } -void get_request(message) - struct msg *message; /* Will contain formatted packet information */ +void get_request(struct msg *message) { - static char packet[BUFSIZ]; /* Buffer for incoming packet */ - int pktlen; /* Length of incoming packet */ - int status = FAILURE; /* Error status */ + static char packet[BUFSIZ]; /* Buffer for incoming packet */ + int pktlen; /* Length of incoming packet */ + int status = FAILURE; /* Error status */ - /* Sit around waiting for requests from the client. */ - for (;;) + /* Sit around waiting for requests from the client. */ + for (;;) { - com_err(whoami, 0, "*** Ready for next request ***"); - addrlen = sizeof(sin); - /* Receive a packet */ - if ((pktlen = recvfrom(s,packet,sizeof(packet),0, - (struct sockaddr *)&sin,&addrlen)) < 0) + com_err(whoami, 0, "*** Ready for next request ***"); + addrlen = sizeof(sin); + /* Receive a packet */ + if ((pktlen = recvfrom(s, packet, sizeof(packet), 0, + (struct sockaddr *)&sin, &addrlen)) < 0) { - com_err(whoami, errno, " recvfrom"); - /* Don't worry if error is interrupted system call. */ - if (errno == EINTR) continue; - exit(1); + com_err(whoami, errno, " recvfrom"); + /* Don't worry if error is interrupted system call. */ + if (errno == EINTR) + continue; + exit(1); } - - /* Store available information */ - CUR_REQ.seqno = 0; - CUR_REQ.ip_address = sin.sin_addr.s_addr; - CUR_REQ.cl_port = sin.sin_port; - - /* Parse a request packet and save sequence number */ - if ((status = parse_pkt(packet, pktlen, message)) - != SUCCESS) + + /* Store available information */ + CUR_REQ.seqno = 0; + CUR_REQ.ip_address = sin.sin_addr.s_addr; + CUR_REQ.cl_port = sin.sin_port; + + /* Parse a request packet and save sequence number */ + if ((status = parse_pkt(packet, pktlen, message)) != SUCCESS) { - /* If error, format packet to send back to the client */ - respond(status, (char *)NULL); + /* If error, format packet to send back to the client */ + respond(status, NULL); } - else + else { - /* Check for retransmitted packet. handle_retransmitted() - returns true if it handled a retransmitted packet. */ - if (!handle_retransmitted()) - break; + /* Check for retransmitted packet. handle_retransmitted() + returns true if it handled a retransmitted packet. */ + if (!handle_retransmitted()) + break; } } } -void report(status, message) - int status; - char * message; +void report(int status, char *message) { - respond(status, message); + respond(status, message); } -int format_pkt(packet, pktlenp, seqno, cl_status, message) - char *packet; /* Packet buffer */ - int *pktlenp; /* Pointer to packet size */ - U_32BIT seqno; /* Sequence number */ - int cl_status; /* Error status to return to client */ - char *message; /* Error message to return to client */ - /* This routine prepares a packet to send back to the client. A - non-zero return status means that the client error message was - truncated. */ +/* This routine prepares a packet to send back to the client. A + non-zero return status means that the client error message was + truncated. */ +int format_pkt(char *packet, int *pktlenp, U_32BIT seqno, + int cl_status, char *message) { - int len; /* Amount of message to send */ - int status = SUCCESS; /* Return status */ - - /* Convert byte order to network byte order */ - U_32BIT vers = htonl((U_32BIT)CUR_UREG_VERSION); - cl_status = htonl((U_32BIT)cl_status); - /* Put current user registration protocol version into the packet */ - memcpy(packet, &vers, sizeof(U_32BIT)); - /* Put sequence number into the packet */ - memcpy(packet+sizeof(U_32BIT), &seqno, sizeof(U_32BIT)); - /* Put error status into the packet */ - memcpy(packet+ 2*sizeof(U_32BIT), &cl_status, sizeof(U_32BIT)); - - /* Find out how much of the message to copy; truncate if too short. */ - /* How much room is there left? */ - len = *pktlenp - sizeof(U_32BIT)*3; - if (message == NULL) message = ""; - if (len < strlen(message) + 1) /* Room for null terminator */ + int len; /* Amount of message to send */ + int status = SUCCESS; /* Return status */ + + /* Convert byte order to network byte order */ + U_32BIT vers = htonl((U_32BIT)CUR_UREG_VERSION); + cl_status = htonl((U_32BIT)cl_status); + /* Put current user registration protocol version into the packet */ + memcpy(packet, &vers, sizeof(U_32BIT)); + /* Put sequence number into the packet */ + memcpy(packet + sizeof(U_32BIT), &seqno, sizeof(U_32BIT)); + /* Put error status into the packet */ + memcpy(packet + 2 * sizeof(U_32BIT), &cl_status, sizeof(U_32BIT)); + + /* Find out how much of the message to copy; truncate if too short. */ + /* How much room is there left? */ + len = *pktlenp - sizeof(U_32BIT) * 3; + if (!message) + message = ""; + if (len < strlen(message) + 1) /* Room for null terminator */ { - status = FAILURE; /* Message was truncated */ - /* Truncate the message */ - message[len-1] = '\0'; + status = FAILURE; /* Message was truncated */ + /* Truncate the message */ + message[len - 1] = '\0'; } - /* Copy the message into the packet */ - (void) strcpy(packet+3*sizeof(U_32BIT), message); - *pktlenp = 3*sizeof(U_32BIT) + strlen(message); - - return status; + /* Copy the message into the packet */ + strcpy(packet + 3 * sizeof(U_32BIT), message); + *pktlenp = 3 * sizeof(U_32BIT) + strlen(message); + + return status; } -/* The ureg_validate_char variable and routine were taken verbatim +/* The ureg_validate_char variable and routine were taken verbatim out of server/qsupport.qc where they are called validate_chars. At some point, it may be desirable to put this functionality in one place. */ /* ureg_validate_char: verify that there are no illegal characters in - * the string. Legal characters are printing chars other than + * the string. Legal characters are printing chars other than * ", *, ?, \, [ and ]. */ static int illegalchars[] = { @@ -269,143 +257,135 @@ static int illegalchars[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; -ureg_validate_char(s) -register char *s; +int ureg_validate_char(register char *s) { - while (*s) + while (*s) + { if (illegalchars[*s++]) - return(FAILURE); - return(SUCCESS); + return FAILURE; + } + return SUCCESS; } -parse_pkt(packet, pktlen, message) - char *packet; - int pktlen; - struct msg *message; - /* This routine checks a packet and puts the information in it in - a structure if it is valid. It also saves the sequence number - in the list of saved requests. */ +/* This routine checks a packet and puts the information in it in + a structure if it is valid. It also saves the sequence number + in the list of saved requests. */ +int parse_pkt(char *packet, int pktlen, struct msg *message) { - int status = SUCCESS; /* Error status */ + int status = SUCCESS; /* Error status */ - com_err(whoami,0,"Packet received"); + com_err(whoami, 0, "Packet received"); - if (pktlen < sizeof(U_32BIT)) status = UREG_BROKEN_PACKET; - if (status == SUCCESS) + if (pktlen < sizeof(U_32BIT)) + status = UREG_BROKEN_PACKET; + if (status == SUCCESS) { - /* Extract the user registration protocol version from the packet */ - memcpy(&message->version, packet, sizeof(long)); - /* Convert byte order from network to host */ - message->version = ntohl(message->version); - /* Verify version */ - if (message->version != CUR_UREG_VERSION) - status = UREG_WRONG_VERSION; + /* Extract the user registration protocol version from the packet */ + memcpy(&message->version, packet, sizeof(long)); + /* Convert byte order from network to host */ + message->version = ntohl(message->version); + /* Verify version */ + if (message->version != CUR_UREG_VERSION) + status = UREG_WRONG_VERSION; } - if (status == SUCCESS) + if (status == SUCCESS) { - packet += sizeof(U_32BIT); - pktlen -= sizeof(U_32BIT); - - if (pktlen < sizeof(U_32BIT)) - status = UREG_BROKEN_PACKET; + packet += sizeof(U_32BIT); + pktlen -= sizeof(U_32BIT); + + if (pktlen < sizeof(U_32BIT)) + status = UREG_BROKEN_PACKET; } - if (status == SUCCESS) + if (status == SUCCESS) { - /* Extract the sequence number from the packet */ - memcpy(&CUR_REQ.seqno, packet, sizeof(long)); - - packet += sizeof(U_32BIT); - pktlen -= sizeof(U_32BIT); - - if (pktlen < sizeof(U_32BIT)) - status = UREG_BROKEN_PACKET; + /* Extract the sequence number from the packet */ + memcpy(&CUR_REQ.seqno, packet, sizeof(long)); + + packet += sizeof(U_32BIT); + pktlen -= sizeof(U_32BIT); + + if (pktlen < sizeof(U_32BIT)) + status = UREG_BROKEN_PACKET; } - if (status == SUCCESS) + if (status == SUCCESS) { - /* Extract the request from the packet */ - memcpy(&message->request, packet, sizeof(U_32BIT)); - message->request = ntohl(message->request); - packet += sizeof(U_32BIT); - pktlen -= sizeof(U_32BIT); - - /* Make sure that the packet contains only valid characters up - to the next null */ - if (ureg_validate_char(packet) != SUCCESS) + /* Extract the request from the packet */ + memcpy(&message->request, packet, sizeof(U_32BIT)); + message->request = ntohl(message->request); + packet += sizeof(U_32BIT); + pktlen -= sizeof(U_32BIT); + + /* Make sure that the packet contains only valid characters up + to the next null */ + if (ureg_validate_char(packet) != SUCCESS) { - com_err(whoami,0,"Packet contains invalid characters."); - status = UREG_USER_NOT_FOUND; + com_err(whoami, 0, "Packet contains invalid characters."); + status = UREG_USER_NOT_FOUND; } - else + else { - /* Extract first name from the packet */ - message->first = packet; - - /* Scan forward until null appears in the packet or there - is no more packet! */ - for (; *packet && pktlen > 0; --pktlen, ++packet) continue; - if (pktlen <= 0) - status = UREG_BROKEN_PACKET; + /* Extract first name from the packet */ + message->first = packet; + + /* Scan forward until null appears in the packet or there + is no more packet! */ + for (; *packet && pktlen > 0; --pktlen, ++packet) + continue; + if (pktlen <= 0) + status = UREG_BROKEN_PACKET; } } - - if (status == SUCCESS) + + if (status == SUCCESS) { - /* Skip over the null */ - packet++, pktlen--; - - if (ureg_validate_char(packet) != SUCCESS) + /* Skip over the null */ + packet++, pktlen--; + + if (ureg_validate_char(packet) != SUCCESS) { - com_err(whoami,0,"Packet contains invalid characters."); - status = UREG_USER_NOT_FOUND; + com_err(whoami, 0, "Packet contains invalid characters."); + status = UREG_USER_NOT_FOUND; } - else + else { - /* Extract last name from the packet */ - message->last = packet; - - for (; *packet && pktlen > 0; --pktlen, ++packet) continue; - if (pktlen <= 0) - status = UREG_BROKEN_PACKET; + /* Extract last name from the packet */ + message->last = packet; + + for (; *packet && pktlen > 0; --pktlen, ++packet) + continue; + if (pktlen <= 0) + status = UREG_BROKEN_PACKET; } } - if (status == SUCCESS) + if (status == SUCCESS) { - packet++, pktlen--; - - if (pktlen <= 0) - status = UREG_BROKEN_PACKET; + packet++, pktlen--; + + if (pktlen <= 0) + status = UREG_BROKEN_PACKET; } - /* Extract encrypted information from packet */ - message->encrypted = packet; - message->encrypted_len = pktlen; - - if (status == SUCCESS) + /* Extract encrypted information from packet */ + message->encrypted = packet; + message->encrypted_len = pktlen; + + if (status == SUCCESS) { -#ifdef DEBUG - com_err(whoami,status,"%s\n%s%d\n%s%d\n%s%s\n%s%s", - "Packet parsed successfully. Packet contains:", - " Protocol version: ",message->version, - " Request: ",message->request, - " First name: ",message->first, - " Last name: ",message->last); -#else /* DEBUG */ - com_err(whoami,status,"Request %d for %s %s",message->request, - message->first,message->last); -#endif DEBUG + com_err(whoami, status, "Request %d for %s %s", message->request, + message->first, message->last); } - else - com_err(whoami,status," - parse packet failed."); + else + com_err(whoami, status, " - parse packet failed."); - return status; + return status; } -u_long cur_req_sender() +u_long cur_req_sender(void) { - return (CUR_REQ.ip_address); + return CUR_REQ.ip_address; } diff --git a/reg_svr/startreg.c b/reg_svr/startreg.c index f2eb88c8..e17be889 100644 --- a/reg_svr/startreg.c +++ b/reg_svr/startreg.c @@ -34,115 +34,123 @@ static char *rcsid_mr_starter_c = "$Header$"; int rdpipe[2]; extern int errno; -void cleanup() +void cleanup(void) { - int stat, serrno = errno; - char buf[BUFSIZ]; - - buf[0]='\0'; - - while (waitpid(-1, &stat, WNOHANG) > 0) { - if (WIFEXITED(stat)) { - if (WEXITSTATUS(stat)) - sprintf(buf, - "exited with code %d\n", - WEXITSTATUS(stat)); - } - if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on signal %d%s\n", - WTERMSIG(stat), - (WCOREDUMP(stat)?"; Core dumped":"")); - } - write(rdpipe[1], buf, strlen(buf)); - close(rdpipe[1]); + int stat, serrno = errno; + char buf[BUFSIZ]; + + buf[0] = '\0'; + + while (waitpid(-1, &stat, WNOHANG) > 0) + { + if (WIFEXITED(stat)) + { + if (WEXITSTATUS(stat)) + sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat)); + } + if (WIFSIGNALED(stat)) + { + sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat), + (WCOREDUMP(stat) ? "; Core dumped" : "")); } - errno = serrno; + write(rdpipe[1], buf, strlen(buf)); + close(rdpipe[1]); + } + errno = serrno; } -main(argc, argv) +int main(int argc, char **argv) { - char buf[BUFSIZ]; - FILE *log, *prog; - int logf, inf, i, done, pid, tty; - struct rlimit rl; - - extern int errno; - extern char *sys_errlist[]; - - struct sigaction action; - int nfds; - - getrlimit(RLIMIT_NOFILE, &rl); - nfds = rl.rlim_cur; - - action.sa_handler = cleanup; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaction(SIGCHLD, &action, NULL); - - sprintf(buf, "%s/%s.log", SMS_DIR, PROG); - logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); - if (logf<0) { - perror(buf); - exit(1); - } - inf = open("/dev/null", O_RDONLY , 0); - if (inf < 0) { - perror("/dev/null"); - exit(1); - } - pipe(rdpipe); - if (fork()) { - exit(0); - } - chdir("/"); - close(0); - close(1); - close(2); - dup2(inf, 0); - dup2(inf, 1); - dup2(inf, 2); - - setpgrp(); - sprintf(buf, "%s/%s", BIN_DIR, PROG); - - if ((pid = fork()) == 0) { - - dup2(inf, 0); - dup2(rdpipe[1], 1); - dup2(1,2); - for (i = 3; i %s", time_s, pid, buf); - fflush(log); - } while (!done); - exit(0); + struct sigaction action; + int nfds; + + getrlimit(RLIMIT_NOFILE, &rl); + nfds = rl.rlim_cur; + + action.sa_handler = cleanup; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGCHLD, &action, NULL); + + sprintf(buf, "%s/%s.log", SMS_DIR, PROG); + logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); + if (logf < 0) + { + perror(buf); + exit(1); + } + inf = open("/dev/null", O_RDONLY , 0); + if (inf < 0) + { + perror("/dev/null"); + exit(1); + } + pipe(rdpipe); + if (fork()) + exit(0); + chdir("/"); + close(0); + close(1); + close(2); + dup2(inf, 0); + dup2(inf, 1); + dup2(inf, 2); + + setpgrp(); + sprintf(buf, "%s/%s", BIN_DIR, PROG); + + if ((pid = fork()) == 0) + { + dup2(inf, 0); + dup2(rdpipe[1], 1); + dup2(1,2); + for (i = 3; i < nfds; i++) + close(i); + execl(buf, PROG, 0); + perror("cannot run reg_svr"); + exit(1); + } + if (pid < 0) + { + perror("startreg"); + exit(1); + } + + log = fdopen(logf, "w"); + prog = fdopen(rdpipe[0], "r"); + + do + { + char *time_s; + long foo; + + done = 0; + errno = 0; + if (!fgets(buf, BUFSIZ, prog)) + { + if (errno && errno != EINTR) + { + strcpy(buf, "Unable to read from program: "); + strcat(buf, sys_errlist[errno]); + strcat(buf, "\n"); + } + else + break; + } + time(&foo); + time_s = ctime(&foo) + 4; + time_s[strlen(time_s) - 6] = '\0'; + fprintf(log, "%s <%d> %s", time_s, pid, buf); + fflush(log); + } + while (!done); + exit(0); } diff --git a/regtape/employee.pc b/regtape/employee.pc index 351f0ad0..c793b0df 100644 --- a/regtape/employee.pc +++ b/regtape/employee.pc @@ -52,19 +52,19 @@ EXEC SQL INCLUDE sqlca; struct entry { - char *name; - char *last; - char *first; - char *middle; - char *title; - char *class; - char *id; - char *eid; - char *dept; - char *address; - char *phone; - char *phone2; - int highid; + char *name; + char *last; + char *first; + char *middle; + char *title; + char *class; + char *id; + char *eid; + char *dept; + char *address; + char *phone; + char *phone2; + int highid; }; @@ -75,342 +75,396 @@ int newfinger = 0; #define SQL_DUPLICATE -2112 -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *in; - 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 = 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++; - else if (!strcmp(argv[i], "-D")) - setenv("ING_SET", "set printqry"); - else if (!strcmp(argv[i], "-n")) - newfinger++; - else if (file != NULL) - fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); - else - file = argv[i]; + FILE *in; + 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 = 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++; + else if (!strcmp(argv[i], "-D")) + setenv("ING_SET", "set printqry"); + else if (!strcmp(argv[i], "-n")) + newfinger++; + else if (file) + fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); + else + file = argv[i]; } - in = fopen(file, "r"); - if (in == NULL) { - fprintf(stderr, "Unable to open %s for input\n", file); - exit(1); + in = fopen(file, "r"); + if (!in) + { + fprintf(stderr, "Unable to open %s for input\n", file); + exit(1); } - initialize_sms_error_table(); + initialize_sms_error_table(); - EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (sqlca.sqlcode != 0) { - dbmserr("opening database", sqlca.sqlcode); - exit(1); + EXEC SQL CONNECT :db IDENTIFIED BY :db; + if (sqlca.sqlcode) + { + dbmserr("opening database", sqlca.sqlcode); + exit(1); } - while (e = get_next_entry(in)) { + while ((e = get_next_entry(in))) + { again: - process_entry(e); - EXEC SQL COMMIT WORK; - if (sqlca.sqlcode != 0) { + process_entry(e); + EXEC SQL COMMIT WORK; + if (sqlca.sqlcode) + { dbmserr("committing work", sqlca.sqlcode); exit(1); } - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); } } - exit(0); + exit(0); } -char *substr(buf, key) -char *buf; -char *key; +char *substr(char *buf, char *key) { - int l; + int l; - for (l = strlen(key); *buf; buf++) + for (l = strlen(key); *buf; buf++) + { if (!strncmp(buf, key, l)) - return(buf); - return(NULL); + return buf; + } + return NULL; } -struct entry *get_next_entry(in) -FILE *in; +struct entry *get_next_entry(FILE *in) { - static struct entry e; - static char buf[BUFSIZ], mid[16], eid[16]; - static char name[LEN_NAME+1], sname[LEN_NAME+1], id[LEN_ID+1]; - static char office[LEN_OFFICE+1], phone[LEN_PHONE+1], phone2[LEN_PHONE2+1]; - static char dept[LEN_DEPT+1], title[LEN_TITLE+1], username[LEN_USERNAME+1]; - static char host[LEN_HOST+1]; - int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v; - char *p; - - if (fgets(buf, sizeof(buf), in) == NULL) - return((struct entry *)NULL); - - strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0; - strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0; - strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE); office[LEN_OFFICE] = 0; - strncpy(phone, &buf[LOC_PHONE], LEN_PHONE); phone[LEN_PHONE] = 0; - strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2); phone2[LEN_PHONE2] = 0; - strncpy(dept, &buf[LOC_DEPT], LEN_DEPT); dept[LEN_DEPT] = 0; - strncpy(title, &buf[LOC_TITLE], LEN_TITLE); title[LEN_TITLE] = 0; - strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME); username[LEN_USERNAME] = 0; - strncpy(host, &buf[LOC_HOST], LEN_HOST); host[LEN_HOST] = 0; - - strcpy(sname, name); - e.name = strtrim(sname); - p = strchr(name, ','); - if (p) - *p = 0; - e.last = strtrim(name); - if (p) { + static struct entry e; + static char buf[BUFSIZ], mid[16], eid[16]; + static char name[LEN_NAME + 1], sname[LEN_NAME + 1], id[LEN_ID + 1]; + static char office[LEN_OFFICE + 1], phone[LEN_PHONE + 1]; + static char phone2[LEN_PHONE2 + 1], dept[LEN_DEPT + 1], title[LEN_TITLE + 1]; + static char username[LEN_USERNAME + 1], host[LEN_HOST + 1]; + int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v; + char *p; + + if (!fgets(buf, sizeof(buf), in)) + return NULL; + + strncpy(id, &buf[LOC_ID], LEN_ID); + id[LEN_ID] = '\0'; + strncpy(name, &buf[LOC_NAME], LEN_NAME); + name[LEN_NAME] = '\0'; + strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE); + office[LEN_OFFICE] = '\0'; + strncpy(phone, &buf[LOC_PHONE], LEN_PHONE); + phone[LEN_PHONE] = '\0'; + strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2); + phone2[LEN_PHONE2] = '\0'; + strncpy(dept, &buf[LOC_DEPT], LEN_DEPT); + dept[LEN_DEPT] = '\0'; + strncpy(title, &buf[LOC_TITLE], LEN_TITLE); + title[LEN_TITLE] = '\0'; + strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME); + username[LEN_USERNAME] = '\0'; + strncpy(host, &buf[LOC_HOST], LEN_HOST); + host[LEN_HOST] = '\0'; + + strcpy(sname, name); + e.name = strtrim(sname); + p = strchr(name, ','); + if (p) + *p = '\0'; + e.last = strtrim(name); + if (p) + { + p++; + while (isspace(*p)) p++; - while (isspace(*p)) - p++; - e.first = p; - if (p = strchr(e.first, ' ')) { - *p = 0; - e.first = strtrim(e.first); - e.middle = strtrim(p + 1); - } else { - e.first = strtrim(e.first); - e.middle = ""; + e.first = p; + if (p = strchr(e.first, ' ')) + { + *p = '\0'; + e.first = strtrim(e.first); + e.middle = strtrim(p + 1); } - } else { - e.first = ""; - e.middle = ""; + else + { + e.first = strtrim(e.first); + e.middle = ""; + } + } + else + { + e.first = ""; + e.middle = ""; } - ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0; - LookForSt(e.last); - LookForO(e.last); - LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, - &ends_ii, &ends_v); - LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, - &ends_ii, &ends_v); - FixCase(e.last); - FixCase(e.first); - FixCase(e.middle); - - e.id = id; - e.eid = eid; - EncryptID(e.eid, e.id, e.first, e.last); - - e.address = strtrim(office); - e.phone = strtrim(phone); - e.phone2 = strtrim(phone2); - e.dept = strtrim(dept); - e.title = strtrim(title); - - e.class = "MITS"; - e.highid = 0; - if (substr(e.title, "PROF") || substr(e.title, "LECTURE")) - e.class = "FACULTY"; - if (!strcmp(e.dept, "LINCOLN LAB")) { - e.class = "LINCOLN"; - e.highid = 1; + ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0; + LookForSt(e.last); + LookForO(e.last); + LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, + &ends_ii, &ends_v); + LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, + &ends_ii, &ends_v); + FixCase(e.last); + FixCase(e.first); + FixCase(e.middle); + + e.id = id; + e.eid = eid; + EncryptID(e.eid, e.id, e.first, e.last); + + e.address = strtrim(office); + e.phone = strtrim(phone); + e.phone2 = strtrim(phone2); + e.dept = strtrim(dept); + e.title = strtrim(title); + + e.class = "MITS"; + e.highid = 0; + if (substr(e.title, "PROF") || substr(e.title, "LECTURE")) + e.class = "FACULTY"; + if (!strcmp(e.dept, "LINCOLN LAB")) + { + e.class = "LINCOLN"; + e.highid = 1; } - return(&e); + return &e; } -process_entry(e) -struct entry *e; +process_entry(struct entry *e) { - int changed, nochange, encrypted; - char buf[BUFSIZ], *from, *to; - EXEC SQL BEGIN DECLARE SECTION; - char *first, *last, *middle, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle; - char *raddr, *rhphone, *rophone, *prog; - char class[9], oaddr[25], ophone[17], dept[128], dfirst[17], dlast[17], dmiddle[17]; - int id, status, who; - EXEC SQL END DECLARE SECTION; - - who = WHO; - prog = PROG; - first = e->first; - if (strlen(first) > 16) - first[16] = 0; - last = e->last; - if (strlen(last) > 16) - last[16] = 0; - middle = e->middle; - eid = e->eid; - sid = e->id; - id = 0; - encrypted = 0; - - /* Get user info */ - EXEC SQL SELECT users_id, first, last, middle, type, office_addr, office_phone, department, status - INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr, :ophone, :dept, :status - FROM users - WHERE clearid = :sid; - if (sqlfail()) { - if (sqlca.sqlcode == SQL_DUPLICATE) { - com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last); - return; - } else - sqlexit(); + int changed, nochange, encrypted; + char buf[BUFSIZ], *from, *to; + EXEC SQL BEGIN DECLARE SECTION; + char *first, *last, *middle, *eid, *sid, *name, *title, *phone2, *rdept; + char *rtitle, *raddr, *rhphone, *rophone, *prog; + char class[9], oaddr[25], ophone[17], dept[128]; + char dfirst[17], dlast[17], dmiddle[17]; + int id, status, who; + EXEC SQL END DECLARE SECTION; + + who = WHO; + prog = PROG; + first = e->first; + if (strlen(first) > 16) + first[16] = '\0'; + last = e->last; + if (strlen(last) > 16) + last[16] = '\0'; + middle = e->middle; + eid = e->eid; + sid = e->id; + id = 0; + encrypted = 0; + + /* Get user info */ + EXEC SQL SELECT users_id, first, last, middle, type, office_addr, + office_phone, department, status + INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr, + :ophone, :dept, :status + FROM users + WHERE clearid = :sid; + if (sqlfail()) + { + if (sqlca.sqlcode == SQL_DUPLICATE) + { + com_err(whoami, 0, "duplicate ID number %s on user %s %s", + sid, first, last); + return; + } + else + sqlexit(); } - if (id == 0) { - EXEC SQL SELECT users_id, first, last, middle, type, office_addr, office_phone, department, status - INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr, :ophone, :dept, :status - FROM users - WHERE last = :last and first = :first and clearid = :eid; - if (sqlfail() && sqlca.sqlcode != SQL_DUPLICATE) { - sqlexit(); - } - encrypted++; - if (id == 0) { - newuser(e); - return; + if (id == 0) + { + EXEC SQL SELECT users_id, first, last, middle, type, office_addr, + office_phone, department, status + INTO :id, :dfirst, :dlast, :dmiddle, :class, :oaddr, + :ophone, :dept, :status + FROM users + WHERE last = :last and first = :first and clearid = :eid; + if (sqlfail() && sqlca.sqlcode != SQL_DUPLICATE) + sqlexit(); + encrypted++; + if (id == 0) + { + newuser(e); + return; } } - /* Update class/state if necessary. (Exclude several spacial cases.) */ - if (strcmp(e->class, strtrim(class)) && - strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") && - strcmp(class, "KNIGHT")) { - com_err(whoami, 0, "updating class for %s %s from %s to %s", - first, last, class, e->class); - 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 UPDATE users - SET type = NVL(:class,CHR(0)), status = :status, modtime = SYSDATE, - modby = :who, modwith = :prog - WHERE users_id = :id; - if (sqlca.sqlcode != 0) { + /* Update class/state if necessary. (Exclude several spacial cases.) */ + if (strcmp(e->class, strtrim(class)) && + strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") && + strcmp(class, "KNIGHT")) + { + com_err(whoami, 0, "updating class for %s %s from %s to %s", + first, last, class, e->class); + 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 UPDATE users + SET type = NVL(:class, CHR(0)), status = :status, modtime = SYSDATE, + modby = :who, modwith = :prog + WHERE users_id = :id; + if (sqlca.sqlcode) + { dbmserr("updating user", sqlca.sqlcode); exit(1); } } - /* Update name if necessary */ - if (strcmp(first, strtrim(dfirst)) || - strcmp(last, strtrim(dlast)) || - strcmp(middle, strtrim(dmiddle))) { - com_err(whoami, 0, "updating real name for %s %s", first, last); - EXEC SQL UPDATE users - 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) { + /* Update name if necessary */ + if (strcmp(first, strtrim(dfirst)) || + strcmp(last, strtrim(dlast)) || + strcmp(middle, strtrim(dmiddle))) + { + com_err(whoami, 0, "updating real name for %s %s", first, last); + EXEC SQL UPDATE users + 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) + { dbmserr("updating name", sqlca.sqlcode); exit(1); } } - changed = nochange = 0; - if (encrypted) changed++; - strcpy(buf, e->address); - while (to = strchr(buf, ',')) - *to = ';'; - while (to = strchr(buf, ':')) - *to = ';'; - if (newfinger) { - if (oaddr[0] == ' ' && buf[0]) { - strncpy(oaddr, buf, 16); - oaddr[16] = 0; - changed++; - } else if (strncmp(strtrim(oaddr), buf, 15)) - nochange++; - } else { - if (strncmp(strtrim(oaddr), buf, 15)) + changed = nochange = 0; + if (encrypted) + changed++; + strcpy(buf, e->address); + while ((to = strchr(buf, ','))) + *to = ';'; + while ((to = strchr(buf, ':'))) + *to = ';'; + if (newfinger) + { + if (oaddr[0] == ' ' && buf[0]) + { + strncpy(oaddr, buf, 16); + oaddr[16] = '\0'; changed++; - strncpy(oaddr, buf, 16); - oaddr[16] = 0; + } + else if (strncmp(strtrim(oaddr), buf, 15)) + nochange++; } - from = e->phone; - to = buf; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; + else + { + if (strncmp(strtrim(oaddr), buf, 15)) + changed++; + strncpy(oaddr, buf, 16); + oaddr[16] = '\0'; } - *to = 0; - if (newfinger) { - if (ophone[0] == ' ') { - strncpy(ophone, buf, 16); - ophone[16] = 0; - } else if (strncmp(strtrim(ophone), buf, 11)) - nochange++; - } else { - if (strncmp(strtrim(ophone), buf, 11)) - changed++; - strncpy(ophone, buf, 16); - ophone[16] = 0; + from = e->phone; + to = buf; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; } - FixCase(e->dept); - FixCase(e->title); - if (newfinger) { - if (dept[0] == ' ') { - strncpy(dept, e->dept, 12); - dept[12] = 0; - } else if (strncmp(strtrim(dept), e->dept, 11)) - nochange++; - } else { - if (strncmp(strtrim(dept), e->dept, 11)) - changed++; - strncpy(dept, e->dept, 12); - dept[12] = 0; + *to = '\0'; + if (newfinger) + { + if (ophone[0] == ' ') + { + strncpy(ophone, buf, 16); + ophone[16] = '\0'; + } + else if (strncmp(strtrim(ophone), buf, 11)) + nochange++; + } + else + { + if (strncmp(strtrim(ophone), buf, 11)) + changed++; + strncpy(ophone, buf, 16); + ophone[16] = '\0'; } - sid = e->id; - name = e->name; - rdept = e->dept; - rtitle = e->title; - raddr = e->address; - rhphone = e->phone; - rophone = e->phone2; - if (changed) { - com_err(whoami, 0, "updating finger for %s %s", first, last); - 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) { + FixCase(e->dept); + FixCase(e->title); + if (newfinger) + { + if (dept[0] == ' ') + { + strncpy(dept, e->dept, 12); + dept[12] = '\0'; + } + else if (strncmp(strtrim(dept), e->dept, 11)) + nochange++; + } + else + { + if (strncmp(strtrim(dept), e->dept, 11)) + changed++; + strncpy(dept, e->dept, 12); + dept[12] = '\0'; + } + sid = e->id; + name = e->name; + rdept = e->dept; + rtitle = e->title; + raddr = e->address; + rhphone = e->phone; + rophone = e->phone2; + if (changed) + { + com_err(whoami, 0, "updating finger for %s %s", first, last); + 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) + { dbmserr(NULL, sqlca.sqlcode); exit(1); } - } else { - 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) { + } + else + { + 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) + { dbmserr(NULL, sqlca.sqlcode); exit(1); } @@ -418,190 +472,202 @@ struct entry *e; } -newuser(e) -struct entry *e; +newuser(struct entry *e) { - char *from, *to; - EXEC SQL BEGIN DECLARE SECTION; - int id, uid, st, who; - char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog; - char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17]; - char *rdept, *rhphone, *rophone; - EXEC SQL END DECLARE SECTION; - - who = WHO; - prog = PROG; - strncpy(oaddr, e->address, 16); - oaddr[16] = 0; - while (to = strchr(oaddr, ',')) - *to = ';'; - while (to = strchr(oaddr, ':')) - *to = ';'; - from = e->phone; - to = ophone; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; + char *from, *to; + EXEC SQL BEGIN DECLARE SECTION; + int id, uid, st, who; + char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog; + char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17]; + char *rdept, *rhphone, *rophone; + EXEC SQL END DECLARE SECTION; + + who = WHO; + prog = PROG; + strncpy(oaddr, e->address, 16); + oaddr[16] = '\0'; + while ((to = strchr(oaddr, ','))) + *to = ';'; + while ((to = strchr(oaddr, ':'))) + *to = ';'; + from = e->phone; + to = ophone; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; } - *to = 0; - FixCase(e->dept); - strncpy(dept, e->dept, 12); - dept[12] = 0; - - id = set_next_users_id(0); - uid = set_next_uid(e->highid); - sprintf(login, "#%d", uid); - last = e->last; - first = e->first; - middle = e->middle; - class = e->class; - if (*middle) - sprintf(fullname, "%s %s %s", first, middle, last); - else - sprintf(fullname, "%s %s", first, last); - st = US_NO_LOGIN_YET; - - sid = e->id; - name = e->name; - rdept = e->dept; - title = e->title; - rhphone = e->phone; - rophone = e->phone2; - - 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', - 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) { + *to = '\0'; + FixCase(e->dept); + strncpy(dept, e->dept, 12); + dept[12] = '\0'; + + id = set_next_users_id(0); + uid = set_next_uid(e->highid); + sprintf(login, "#%d", uid); + last = e->last; + first = e->first; + middle = e->middle; + class = e->class; + if (*middle) + sprintf(fullname, "%s %s %s", first, middle, last); + else + sprintf(fullname, "%s %s", first, last); + st = US_NO_LOGIN_YET; + + sid = e->id; + name = e->name; + rdept = e->dept; + title = e->title; + rhphone = e->phone; + rophone = e->phone2; + + 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', + 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) + { dbmserr("adding user", sqlca.sqlcode); exit(1); - } else - com_err(whoami, 0, "adding user %s %s", e->first, e->last); + } + else + com_err(whoami, 0, "adding user %s %s", e->first, e->last); } -set_next_users_id(limit) - int limit; +set_next_users_id(int limit) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, flag, value, retval; - EXEC SQL END DECLARE SECTION; - - EXEC SQL SELECT value INTO :value FROM numvalues - WHERE name = 'users_id'; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] != 1) { - EXEC SQL ROLLBACK; - com_err(whoami, MR_INTERNAL, "values table inconsistancy"); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, flag, value, retval; + EXEC SQL END DECLARE SECTION; + + EXEC SQL SELECT value INTO :value FROM numvalues + WHERE name = 'users_id'; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] != 1) + { + EXEC SQL ROLLBACK; + com_err(whoami, MR_INTERNAL, "values table inconsistancy"); + exit(1); } + flag = 0; + EXEC SQL SELECT users_id INTO :flag FROM users + WHERE users_id = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT users_id INTO :flag FROM users - WHERE users_id = :value; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] == 0) + while (flag) + { + value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; flag = 0; - while (flag) { - value++; - if (limit && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; + EXEC SQL SELECT users_id INTO :flag FROM users + WHERE users_id = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT users_id INTO :flag FROM users - WHERE users_id = :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 UPDATE numvalues SET value = :value - WHERE name = 'users_id'; - if (sqlca.sqlcode != 0) { - dbmserr("assigning ID", sqlca.sqlcode); - exit(1); + retval = value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + EXEC SQL UPDATE numvalues SET value = :value + WHERE name = 'users_id'; + if (sqlca.sqlcode) + { + dbmserr("assigning ID", sqlca.sqlcode); + exit(1); } - return(retval); + return retval; } -set_next_uid(high) - int high; +set_next_uid(int high) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, flag, value, retval; - char *name; - EXEC SQL END DECLARE SECTION; - - if (high) - name = "high_uid"; - else - name = "unix_uid"; - - EXEC SQL SELECT value INTO :value FROM numvalues - WHERE name = :name; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] != 1) { - EXEC SQL ROLLBACK; - com_err(whoami, MR_INTERNAL, "values table inconsistancy"); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, flag, value, retval; + char *name; + EXEC SQL END DECLARE SECTION; + + if (high) + name = "high_uid"; + else + name = "unix_uid"; + + EXEC SQL SELECT value INTO :value FROM numvalues + WHERE name = :name; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] != 1) + { + EXEC SQL ROLLBACK; + com_err(whoami, MR_INTERNAL, "values table inconsistancy"); + exit(1); } + flag = 0; + EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] == 0) + while (flag) + { + value++; + if (!high && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; flag = 0; - while (flag) { - value++; - if (!high && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; + EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - 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 (!high && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; - EXEC SQL UPDATE numvalues SET value = :value WHERE name = :name; - if (sqlca.sqlcode != 0) { - dbmserr("assigning ID", sqlca.sqlcode); - exit(1); + retval = value++; + if (!high && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + EXEC SQL UPDATE numvalues SET value = :value WHERE name = :name; + if (sqlca.sqlcode) + { + dbmserr("assigning ID", sqlca.sqlcode); + exit(1); } - return(retval); + return retval; } -sqlexit() +sqlexit(void) { - dbmserr(NULL, sqlca.sqlcode); - EXEC SQL ROLLBACK WORK; - exit(1); + dbmserr(NULL, sqlca.sqlcode); + EXEC SQL ROLLBACK WORK; + exit(1); } dbmserr(char *where, int what) { char err_msg[256]; - int bufsize=256, msglength=0; + int bufsize = 256, msglength = 0; sqlglm(err_msg, &bufsize, &msglength); - err_msg[msglength]=0; + err_msg[msglength] = '\0'; - if(where) + if (where) com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where); else com_err(whoami, 0, "DBMS error %s", err_msg); diff --git a/regtape/personel.input b/regtape/personel.input index 33d2adf5..c6760aaa 100644 --- a/regtape/personel.input +++ b/regtape/personel.input @@ -1,10 +1,10 @@ -888209554AALERUD, ROBERT W 38-045 3-2547 RSCH LAB OF ELECT INSTRUMENT MAKER -888523206AARSET, TIMOTHY C LIN-PC-105 1810499 LINCOLN STAFF -888484889ABBATE, MATTHEW E39-215 3-2080 MIT PRESS EDITOR -888461996ABBOT, RICHARD I MILLSTONE 1815604 LINCOLN STAFF -868026428ABE, MASANOBU NE43-639 3-0081 LAB FOR COMP SCI VISITING SCIENTIST AVE @GOLDILOCKS.LCS.MIT.EDU -888265338ABELL, DOROTHY F ENDICOTT HSE 326-5151 ENDICOTT HOUSE HOUSEKEEPER -888363287ABEL, HOWARD NE43-410 3-5856 ELEC ENG & COMP SCI ASSOCIATE PROFESSOR MURREN @ZURICH.AI.MIT.EDU -888506122ABEND, WILLIAM K E25-534 3-0771 3-0772BRAIN & COG SCI VISITING SCIENTIST -888763144ABERNETHY, CRAIG W 66-570 3-4533 CHEMICAL ENG SENIOR SECRETARY -888424227ABERT, CHARLES E LIN-B-325 1812380 LINCOLN ADMINISTRATIVE STAFF +888209554AALERUD, ROBERT W 38-045 3-2547 RSCH LAB OF ELECT INSTRUMENT MAKER +888523206AARSET, TIMOTHY C LIN-PC-105 1810499 LINCOLN STAFF +888484889ABBATE, MATTHEW E39-215 3-2080 MIT PRESS EDITOR +888461996ABBOT, RICHARD I MILLSTONE 1815604 LINCOLN STAFF +868026428ABE, MASANOBU NE43-639 3-0081 LAB FOR COMP SCI VISITING SCIENTIST AVE @GOLDILOCKS.LCS.MIT.EDU +888265338ABELL, DOROTHY F ENDICOTT HSE 326-5151 ENDICOTT HOUSE HOUSEKEEPER +888363287ABEL, HOWARD NE43-410 3-5856 ELEC ENG & COMP SCI ASSOCIATE PROFESSOR MURREN @ZURICH.AI.MIT.EDU +888506122ABEND, WILLIAM K E25-534 3-0771 3-0772BRAIN & COG SCI VISITING SCIENTIST +888763144ABERNETHY, CRAIG W 66-570 3-4533 CHEMICAL ENG SENIOR SECRETARY +888424227ABERT, CHARLES E LIN-B-325 1812380 LINCOLN ADMINISTRATIVE STAFF diff --git a/regtape/rafnu.c b/regtape/rafnu.c index 9c75972e..6bca104c 100644 --- a/regtape/rafnu.c +++ b/regtape/rafnu.c @@ -13,78 +13,73 @@ static char *rcsid_rafnu_c = "$Header$"; #include #include -FixCase(p) - register char *p; +FixCase(register char *p) { - register int cflag; /* convert to lcase, unless at start or - * following */ + register int cflag; - /* a space or punctuation mark (e.g., '-') */ - - for (cflag = 0; *p; p++) { - if (cflag && isupper(*p)) { - *p = tolower(*p); - } - else if (isspace(*p) || ispunct(*p)) { - cflag = 0; - } - else { - cflag = 1; - } + for (cflag = 0; *p; p++) + { + if (cflag && isupper(*p)) + *p = tolower(*p); + else if (isspace(*p) || ispunct(*p)) + cflag = 0; + else + cflag = 1; } } -LookForJrAndIII(nm, pends_sr, pends_jr, pends_iii, pends_iv) - register char *nm; - register int *pends_sr; - register int *pends_jr; - register int *pends_iii; - register int *pends_iv; +LookForJrAndIII(register char *nm, register int *pends_sr, + register int *pends_jr, register int *pends_iii, + register int *pends_iv) { - register int len = strlen(nm); + register int len = strlen(nm); - if (len >= 4 && !strcmp(nm + len - 3, " SR")) { - *pends_sr = 1; - nm[len - 3] = '\0'; + if (len >= 4 && !strcmp(nm + len - 3, " SR")) + { + *pends_sr = 1; + nm[len - 3] = '\0'; } - else if (len >= 4 && !strcmp(nm + len - 3, " JR")) { - *pends_jr = 1; - nm[len - 3] = '\0'; + else if (len >= 4 && !strcmp(nm + len - 3, " JR")) + { + *pends_jr = 1; + nm[len - 3] = '\0'; } - else if (len >= 4 && !strcmp(nm + len - 3, " IV")) { - *pends_iv = 1; - nm[len - 3] = '\0'; + else if (len >= 4 && !strcmp(nm + len - 3, " IV")) + { + *pends_iv = 1; + nm[len - 3] = '\0'; } - else if (len >= 5 && !strcmp(nm + len - 4, " SR.")) { - *pends_sr = 1; - nm[len - 4] = '\0'; + else if (len >= 5 && !strcmp(nm + len - 4, " SR.")) + { + *pends_sr = 1; + nm[len - 4] = '\0'; } - else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) { - *pends_jr = 1; - nm[len - 4] = '\0'; + else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) + { + *pends_jr = 1; + nm[len - 4] = '\0'; } - else if (len >= 5 && !strcmp(nm + len - 4, " III")) { - *pends_iii = 1; - nm[len - 4] = '\0'; + else if (len >= 5 && !strcmp(nm + len - 4, " III")) + { + *pends_iii = 1; + nm[len - 4] = '\0'; } } -LookForSt(nm) /* ST PIERRE, etc. */ - register char *nm; +LookForSt(register char *nm) /* ST PIERRE, etc. */ { - char temp[256]; + char temp[256]; - if (!strcmp(nm, "ST ")) { - (void) strcpy(temp, nm + 3); - (void) strcpy(nm, "ST. "); - (void) strcat(nm, temp); + if (!strcmp(nm, "ST ")) + { + strcpy(temp, nm + 3); + strcpy(nm, "ST. "); + strcat(nm, temp); } } -LookForO(nm) /* O BRIEN, etc. */ - register char *nm; +LookForO(register char *nm) /* O BRIEN, etc. */ { - if (!strcmp(nm, "O ") && isalpha(nm[2])) { - nm[1] = '\''; - } + if (!strcmp(nm, "O ") && isalpha(nm[2])) + nm[1] = '\''; } diff --git a/regtape/registrar.input b/regtape/registrar.input index ac67cbae..48a94c72 100644 --- a/regtape/registrar.input +++ b/regtape/registrar.input @@ -1,10 +1,10 @@ -AALBERTS, DANIEL P 888988312 8 G 93 BROOKLINE ST APT#3 CAMBRIDGE MA 868-8668 3922 ROXBURY DRIVE NW CEDAR RAPIDS IA 258-6451 -ABBAMONDI, JOHN G 888491942 5 1 405 MEMORIAL DRIVE ATO CAMBRIDGE MA 775 BUCKWOOD DR CHOCTAW OK 253-2200 -ABBOTT, FREELAND K 888546516 63 2 BURTON HOUSE RM 454D 225-8414 104 MADISON AVE ARLINGTON MA -ABBOTT, JAMES F 888566359 8 G ASHDOWN HOUSE RM 108C 225-9670 305 MEMORIAL DRIVE CAMBRIDGE MA -ABBOTT, JAMES R 888335960 10 G 60 BROADWAY #1 ARLINGTON MA 641-2518 253-5513 -ABBOTT, JOAN D 888042219 1 4 BEXLEY HALL RM 106 225-9616 3600 60TH STREET NORTH ST PETERSBURG FL -ABBOTT, LYNORE M 888546540 3 3 BURTON HOUSE RM 313A 225-8272 4619 BUCKNALL RD SAN JOSE CA 253-5411 -ABBOTT, NICHOLAS L 888043926 10 G 35 FAIRMONT STREET #2 ARLINGTON MA 643-1048 54 KINGTON TERRACE, NORTH S. AUSTRALIA 5006 AU 253-4548 -ABDALLA, KARIM M 888041973 6 G 550 MEMORIAL DR., APT.#22D3 RM 209 CAMBRIDGE MA 20 SARAY EL GERZIRA, ZAMALEK CAIRO EG 253-7350 -ABDO, RUDAYNA T 888042234 4 4 BURTON HOUSE RM 554B 225-8486 16 ARISTOTELOUS STREET POLITEA 14563 GR +AALBERTS, DANIEL P 888988312 8 G 93 BROOKLINE ST APT#3 CAMBRIDGE MA 868-8668 3922 ROXBURY DRIVE NW CEDAR RAPIDS IA 258-6451 +ABBAMONDI, JOHN G 888491942 5 1 405 MEMORIAL DRIVE ATO CAMBRIDGE MA 775 BUCKWOOD DR CHOCTAW OK 253-2200 +ABBOTT, FREELAND K 888546516 63 2 BURTON HOUSE RM 454D 225-8414 104 MADISON AVE ARLINGTON MA +ABBOTT, JAMES F 888566359 8 G ASHDOWN HOUSE RM 108C 225-9670 305 MEMORIAL DRIVE CAMBRIDGE MA +ABBOTT, JAMES R 888335960 10 G 60 BROADWAY #1 ARLINGTON MA 641-2518 253-5513 +ABBOTT, JOAN D 888042219 1 4 BEXLEY HALL RM 106 225-9616 3600 60TH STREET NORTH ST PETERSBURG FL +ABBOTT, LYNORE M 888546540 3 3 BURTON HOUSE RM 313A 225-8272 4619 BUCKNALL RD SAN JOSE CA 253-5411 +ABBOTT, NICHOLAS L 888043926 10 G 35 FAIRMONT STREET #2 ARLINGTON MA 643-1048 54 KINGTON TERRACE, NORTH S. AUSTRALIA 5006 AU 253-4548 +ABDALLA, KARIM M 888041973 6 G 550 MEMORIAL DR., APT.#22D3 RM 209 CAMBRIDGE MA 20 SARAY EL GERZIRA, ZAMALEK CAIRO EG 253-7350 +ABDO, RUDAYNA T 888042234 4 4 BURTON HOUSE RM 554B 225-8486 16 ARISTOTELOUS STREET POLITEA 14563 GR diff --git a/regtape/sign.pc b/regtape/sign.pc index 35327155..a3afd7be 100644 --- a/regtape/sign.pc +++ b/regtape/sign.pc @@ -18,130 +18,144 @@ EXEC SQL INCLUDE sqlca; char *program; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - char buf[BUFSIZ], *data, *p; - struct save_queue *sq; - SigInfo si; - int found, status, i, wait; - EXEC SQL BEGIN DECLARE SECTION; - char login[10], mid[32], rawsig[256], *db="moira"; - int id, timestamp, sms; - EXEC SQL END DECLARE SECTION; + char buf[BUFSIZ], *data, *p; + struct save_queue *sq; + SigInfo si; + int found, status, i, wait; + EXEC SQL BEGIN DECLARE SECTION; + char login[10], mid[32], rawsig[256], *db = "moira"; + int id, timestamp, sms; + EXEC SQL END DECLARE SECTION; - program = "sign"; - init_krb_err_tbl(); - init_sms_err_tbl(); - initialize_gdss_error_table(); + program = "sign"; + init_krb_err_tbl(); + init_sms_err_tbl(); + initialize_gdss_error_table(); - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-w")) - wait++; - else if (!strcmp(argv[i], "-D")) - setenv("ING_SET", "set printqry"); - else - fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]); + for (i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "-w")) + wait++; + else if (!strcmp(argv[i], "-D")) + setenv("ING_SET", "set printqry"); + else + fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]); } - /* Set the name of our kerberos ticket file */ - krb_set_tkt_string("/tmp/tkt_sign"); - status = 1; - while (status) { - printf("Authenticating as moira.extra:\n"); - status = krb_get_pw_in_tkt("moira", "extra", "ATHENA.MIT.EDU", - "krbtgt", "ATHENA.MIT.EDU", - DEFAULT_TKT_LIFE, 0); - if (status != 0) - com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt"); - } + /* Set the name of our kerberos ticket file */ + krb_set_tkt_string("/tmp/tkt_sign"); + status = 1; + while (status) + { + printf("Authenticating as moira.extra:\n"); + status = krb_get_pw_in_tkt("moira", "extra", "ATHENA.MIT.EDU", + "krbtgt", "ATHENA.MIT.EDU", + DEFAULT_TKT_LIFE, 0); + if (status) + com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt"); + } - EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - exit(1); - } + EXEC SQL CONNECT :db IDENTIFIED BY :db; + if (sqlca.sqlcode) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + exit(1); + } - sms = 0; - EXEC SQL SELECT string_id INTO :sms FROM strings - WHERE string='moira.extra@ATHENA.MIT.EDU'; - if (sms == 0) { - com_err(program, 0, " failed to find string moira.extra@ATHENA.MIT.EDU in database"); - dest_tkt(); - exit(1); - } + sms = 0; + EXEC SQL SELECT string_id INTO :sms FROM strings + WHERE string = 'moira.extra@ATHENA.MIT.EDU'; + if (sms == 0) + { + com_err(program, 0, " failed to find string moira.extra@ATHENA.MIT.EDU " + "in database"); + dest_tkt(); + exit(1); + } - found = 0; - sq = sq_create(); + found = 0; + sq = sq_create(); - EXEC SQL DECLARE c CURSOR FOR - SELECT users_id, login, clearid - FROM users WHERE signature = CHR(0); - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - exit(1); - } - EXEC SQL OPEN c; - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - exit(1); - } - while (1) { - EXEC SQL FETCH c INTO :id, :login, :mid; - if (sqlca.sqlcode != 0) break; - if (login[0] == '#' || !isdigit(mid[0])) - continue; - sprintf(buf, "%d:%s:%s", id, strtrim(login), strtrim(mid)); - sq_save_data(sq, strsave(buf)); - found++; - } - EXEC SQL CLOSE c; - EXEC SQL COMMIT WORK; - printf("Found %d users to sign.\n", found); + EXEC SQL DECLARE c CURSOR FOR + SELECT users_id, login, clearid + FROM users WHERE signature = CHR(0); + if (sqlca.sqlcode) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + exit(1); + } + EXEC SQL OPEN c; + if (sqlca.sqlcode) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + exit(1); + } + while (1) + { + EXEC SQL FETCH c INTO :id, :login, :mid; + if (sqlca.sqlcode) + break; + if (login[0] == '#' || !isdigit(mid[0])) + continue; + sprintf(buf, "%d:%s:%s", id, strtrim(login), strtrim(mid)); + sq_save_data(sq, strsave(buf)); + found++; + } + EXEC SQL CLOSE c; + EXEC SQL COMMIT WORK; + printf("Found %d users to sign.\n", found); - si.rawsig = (unsigned char *) &rawsig[0]; + si.rawsig = (unsigned char *) &rawsig[0]; - while (sq_get_data(sq, &data)) { - p = strchr(data, ':'); - if (!p) { - com_err(program, 0, " malformatted data"); - continue; - } - *p++ = 0; - id = atoi(data); - data = p; - again: - status = GDSS_Sign(data, strlen(data), buf); - if (status) { - com_err(program, gdss2et(status), "signing data"); - continue; - } - status = GDSS_Verify(data, strlen(data), buf, &si); - if (status) { - com_err(program, gdss2et(status), "verifying data"); - continue; - } - if (strlen(rawsig) > 68) { - sleep(1); - goto again; - } + while (sq_get_data(sq, &data)) + { + p = strchr(data, ':'); + if (!p) + { + com_err(program, 0, " malformatted data"); + continue; + } + *p++ = '\0'; + id = atoi(data); + data = p; + again: + status = GDSS_Sign(data, strlen(data), buf); + if (status) + { + com_err(program, gdss2et(status), "signing data"); + continue; + } + status = GDSS_Verify(data, strlen(data), buf, &si); + if (status) + { + com_err(program, gdss2et(status), "verifying data"); + continue; + } + if (strlen(rawsig) > 68) + { + sleep(1); + goto again; + } - timestamp = si.timestamp; - EXEC SQL UPDATE users - SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp - WHERE users_id = :id; - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - exit(1); - } - EXEC SQL COMMIT WORK; - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); - } - } - dest_tkt(); - exit(0); + timestamp = si.timestamp; + EXEC SQL UPDATE users + SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp + WHERE users_id = :id; + if (sqlca.sqlcode) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + exit(1); + } + EXEC SQL COMMIT WORK; + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); + } + } + dest_tkt(); + exit(0); } diff --git a/regtape/students.pc b/regtape/students.pc index f108c2eb..16b32a18 100644 --- a/regtape/students.pc +++ b/regtape/students.pc @@ -55,22 +55,22 @@ EXEC SQL INCLUDE sqlca; #define LEN_MPHONE 12 struct entry { - char *name; - char *last; - char *first; - char *middle; - char *title; - char *id; - char *eid; - char *course; - char *year; - char *address; - char *dorm; - char *city; - char *state; - char *dphone; - char *mphone; - char *class; + char *name; + char *last; + char *first; + char *middle; + char *title; + char *id; + char *eid; + char *course; + char *year; + char *address; + char *dorm; + char *city; + char *state; + char *dphone; + char *mphone; + char *class; }; @@ -80,405 +80,482 @@ int newfinger = 0; #define SQL_DUPLICATE -2112 #define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403) -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *in; - 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 = 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++; - else if (!strcmp(argv[i], "-D")) - setenv("ING_SET", "set printqry"); - else if (!strcmp(argv[i], "-n")) - newfinger++; - else if (file != NULL) - fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); - else - file = argv[i]; - } - - in = fopen(file, "r"); - if (in == NULL) { - fprintf(stderr, "Unable to open %s for input\n", file); - exit(1); - } - - initialize_sms_error_table(); - - EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (sqlca.sqlcode != 0) { - dbmserr("connecting", sqlca.sqlcode); - exit(1); - } - - while (e = get_next_entry(in)) { + FILE *in; + 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 = 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++; + else if (!strcmp(argv[i], "-D")) + setenv("ING_SET", "set printqry"); + else if (!strcmp(argv[i], "-n")) + newfinger++; + else if (file) + fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); + else + file = argv[i]; + } + + in = fopen(file, "r"); + if (!in) + { + fprintf(stderr, "Unable to open %s for input\n", file); + exit(1); + } + + initialize_sms_error_table(); + + EXEC SQL CONNECT :db IDENTIFIED BY :db; + if (sqlca.sqlcode) + { + dbmserr("connecting", sqlca.sqlcode); + exit(1); + } + + while ((e = get_next_entry(in))) + { again: - process_entry(e); - EXEC SQL COMMIT WORK; - if (sqlca.sqlcode != 0) { + process_entry(e); + EXEC SQL COMMIT WORK; + if (sqlca.sqlcode) + { dbmserr("committing work", sqlca.sqlcode); exit(1); } - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); } } - exit(0); + exit(0); } -struct entry *get_next_entry(in) -FILE *in; +struct entry *get_next_entry(FILE *in) { - static struct entry e; - static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12]; - static char name[LEN_NAME+1], id[LEN_ID+1], course[LEN_COURSE+1]; - static char year[LEN_YEAR+1], address[LEN_ADDRESS+1]; - static char dorm_room[LEN_DORM_ROOM+1], city[LEN_CITY+1]; - static char state[LEN_STATE+1], dphone[LEN_DPHONE+1], mphone[LEN_MPHONE+1]; - static char sname[LEN_NAME+1], title[128]; - static int nyear = 0; - int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v; - char *p; - - if (nyear == 0) { - struct tm *tm; - struct timeval tv; - - gettimeofday(&tv, NULL); - tm = localtime(&tv.tv_sec); - nyear = tm->tm_year; - if (tm->tm_mon > 5) - nyear++; - } - - if (fgets(buf, sizeof(buf), in) == NULL) - return((struct entry *)NULL); - - strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0; - strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0; - strncpy(course, &buf[LOC_COURSE], LEN_COURSE); course[LEN_COURSE] = 0; - strncpy(year, &buf[LOC_YEAR], LEN_YEAR); year[LEN_YEAR] = 0; - strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); address[LEN_ADDRESS] = 0; - strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); dorm_room[LEN_DORM_ROOM] = 0; - strncpy(city, &buf[LOC_CITY], LEN_CITY); city[LEN_CITY] = 0; - strncpy(state, &buf[LOC_STATE], LEN_STATE); state[LEN_STATE] = 0; - strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); dphone[LEN_DPHONE] = 0; - strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); mphone[LEN_MPHONE] = 0; - - strcpy(sname, name); - e.name = strtrim(sname); - p = strchr(name, ','); - if (p) - *p = 0; - e.last = strtrim(name); - if (p) { + static struct entry e; + static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12]; + static char name[LEN_NAME + 1], id[LEN_ID + 1], course[LEN_COURSE + 1]; + static char year[LEN_YEAR + 1], address[LEN_ADDRESS + 1]; + static char dorm_room[LEN_DORM_ROOM + 1], city[LEN_CITY + 1]; + static char state[LEN_STATE + 1], dphone[LEN_DPHONE + 1]; + static char mphone[LEN_MPHONE + 1], sname[LEN_NAME + 1], title[128]; + static int nyear = 0; + int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v; + char *p; + + if (nyear == 0) + { + struct tm *tm; + struct timeval tv; + + gettimeofday(&tv, NULL); + tm = localtime(&tv.tv_sec); + nyear = tm->tm_year; + if (tm->tm_mon > 5) + nyear++; + } + + if (!fgets(buf, sizeof(buf), in)) + return NULL; + + strncpy(name, &buf[LOC_NAME], LEN_NAME); + name[LEN_NAME] = '\0'; + strncpy(id, &buf[LOC_ID], LEN_ID); + id[LEN_ID] = '\0'; + strncpy(course, &buf[LOC_COURSE], LEN_COURSE); + course[LEN_COURSE] = '\0'; + strncpy(year, &buf[LOC_YEAR], LEN_YEAR); + year[LEN_YEAR] = '\0'; + strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); + address[LEN_ADDRESS] = '\0'; + strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); + dorm_room[LEN_DORM_ROOM] = '\0'; + strncpy(city, &buf[LOC_CITY], LEN_CITY); + city[LEN_CITY] = '\0'; + strncpy(state, &buf[LOC_STATE], LEN_STATE); + state[LEN_STATE] = '\0'; + strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); + dphone[LEN_DPHONE] = '\0'; + strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); + mphone[LEN_MPHONE] = '\0'; + + strcpy(sname, name); + e.name = strtrim(sname); + p = strchr(name, ','); + if (p) + *p = '\0'; + e.last = strtrim(name); + if (p) + { + p++; + while (isspace(*p)) p++; - while (isspace(*p)) - p++; - e.first = p; - if (p = strchr(e.first, ' ')) { - *p = 0; - e.first = strtrim(e.first); - e.middle = strtrim(p + 1); - } else { - e.first = strtrim(e.first); - e.middle = ""; + e.first = p; + if (p = strchr(e.first, ' ')) + { + *p = '\0'; + e.first = strtrim(e.first); + e.middle = strtrim(p + 1); + } + else + { + e.first = strtrim(e.first); + e.middle = ""; } - } else { - e.first = ""; - e.middle = ""; - } - ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0; - LookForSt(e.last); - LookForO(e.last); - LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, - &ends_ii, &ends_v); - LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, - &ends_ii, &ends_v); - FixCase(e.last); - FixCase(e.first); - FixCase(e.middle); - - e.id = id; - e.id[LEN_ID] = 0; - e.eid = eid; - EncryptID(e.eid, e.id, e.first, e.last); - - e.year = strtrim(year); - e.title = title; - if (e.year[0] == 'G') { - e.class = "G"; - sprintf(title, "Grad Student"); - } else { - e.class = classbuf; - sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900); - sprintf(title, "Undergrad (class of %s)", classbuf); - } - - e.course = strtrim(course); - e.address = strtrim(address); - e.dorm = strtrim(dorm_room); - e.city = strtrim(city); - e.state = strtrim(state); - e.dphone = strtrim(dphone); - e.mphone = strtrim(mphone); - return(&e); + } + else + { + e.first = ""; + e.middle = ""; + } + ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0; + LookForSt(e.last); + LookForO(e.last); + LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv, + &ends_ii, &ends_v); + LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv, + &ends_ii, &ends_v); + FixCase(e.last); + FixCase(e.first); + FixCase(e.middle); + + e.id = id; + e.id[LEN_ID] = '\0'; + e.eid = eid; + EncryptID(e.eid, e.id, e.first, e.last); + + e.year = strtrim(year); + e.title = title; + if (e.year[0] == 'G') + { + e.class = "G"; + sprintf(title, "Grad Student"); + } + else + { + e.class = classbuf; + sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900); + sprintf(title, "Undergrad (class of %s)", classbuf); + } + + e.course = strtrim(course); + e.address = strtrim(address); + e.dorm = strtrim(dorm_room); + e.city = strtrim(city); + e.state = strtrim(state); + e.dphone = strtrim(dphone); + e.mphone = strtrim(mphone); + return &e; } -process_entry(e) -struct entry *e; +process_entry(struct entry *e) { - int changed, nochange, encrypted; - char buf[BUFSIZ], *from, *to; - EXEC SQL BEGIN DECLARE SECTION; - char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept, *rtitle; - char *rophone, *rhphone, *prog; - char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128]; - char dfirst[17], dlast[17], dmiddle[17]; - int id, status, who; - EXEC SQL END DECLARE SECTION; - - who = WHO; - prog = PROG; - first = e->first; - if (strlen(first) > 16) - first[16] = 0; - last = e->last; - if (strlen(last) > 16) - last[16] = 0; - middle = e->middle; - eid = e->eid; - sid = e->id; - id = 0; - encrypted = 0; - - /* Get user info */ - 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 (sqlfail()) { - if (sqlca.sqlcode == SQL_DUPLICATE) { - com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last); - return; - } else - sqlexit(); - } - if (id == 0) { - 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()) sqlexit(); - encrypted++; - if (id == 0) { - newuser(e); - return; + int changed, nochange, encrypted; + char buf[BUFSIZ], *from, *to; + EXEC SQL BEGIN DECLARE SECTION; + char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept; + char *rtitle, *rophone, *rhphone, *prog; + char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128]; + char dfirst[17], dlast[17], dmiddle[17]; + int id, status, who; + EXEC SQL END DECLARE SECTION; + + who = WHO; + prog = PROG; + first = e->first; + if (strlen(first) > 16) + first[16] = '\0'; + last = e->last; + if (strlen(last) > 16) + last[16] = '\0'; + middle = e->middle; + eid = e->eid; + sid = e->id; + id = 0; + encrypted = 0; + + /* Get user info */ + 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 (sqlfail()) + { + if (sqlca.sqlcode == SQL_DUPLICATE) + { + com_err(whoami, 0, "duplicate ID number %s on user %s %s", + sid, first, last); + return; + } + else + sqlexit(); + } + if (id == 0) + { + 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()) + sqlexit(); + encrypted++; + if (id == 0) + { + newuser(e); + return; } } - /* See if class changed: if it's different, and the value in the database - * is not STAFF or SIPBMEM, and the value from the tape is actually - * meaningful, then update the database. Since they were on the - * students tape, make the account usable. - */ - if (strcmp(e->class, strtrim(class)) && - strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") && - e->year[0]) { - com_err(whoami, 0, "updating class for user %s %s from %s to %s", - first, last, class, e->class); - 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 UPDATE users - SET type = NVL(:class,CHR(0)), status = :status, modtime = SYSDATE, - modby = :who, modwith = :prog - WHERE users_id = :id; - if (sqlca.sqlcode != 0) { - dbmserr("updating class", sqlca.sqlcode); - exit(1); + /* See if class changed: if it's different, and the value in the database + * is not STAFF or SIPBMEM, and the value from the tape is actually + * meaningful, then update the database. Since they were on the + * students tape, make the account usable. + */ + if (strcmp(e->class, strtrim(class)) && + strcmp(class, "STAFF") && strcmp(class, "SIPBMEM") && + e->year[0]) + { + com_err(whoami, 0, "updating class for user %s %s from %s to %s", + first, last, class, e->class); + 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 UPDATE users + SET type = NVL(:class, CHR(0)), status = :status, modtime = SYSDATE, + modby = :who, modwith = :prog + WHERE users_id = :id; + if (sqlca.sqlcode) + { + dbmserr("updating class", sqlca.sqlcode); + exit(1); } } - /* Update name if necessary */ - if (strcmp(first, strtrim(dfirst)) || - strcmp(last, strtrim(dlast)) || - strcmp(middle, strtrim(dmiddle))) { - com_err(whoami, 0, "updating real name for %s %s", first, last); - EXEC SQL UPDATE users - 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) { - dbmserr("updating name", sqlca.sqlcode); - exit(1); + /* Update name if necessary */ + if (strcmp(first, strtrim(dfirst)) || + strcmp(last, strtrim(dlast)) || + strcmp(middle, strtrim(dmiddle))) + { + com_err(whoami, 0, "updating real name for %s %s", first, last); + EXEC SQL UPDATE users + 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) + { + dbmserr("updating name", sqlca.sqlcode); + exit(1); } } - /* Deal with updating the finger info if necessary */ - changed = nochange = 0; - if (encrypted) changed++; - strcpy(buf, e->address); - if (*e->dorm) { - strcat(buf, " "); - strcat(buf, e->dorm); - } - if (*e->city) { - strcat(buf, " "); - strcat(buf, e->city); - } - FixCase(buf); - if (*e->state) { - strcat(buf, " "); - strcat(buf, e->state); - } - while (to = strchr(buf, ',')) - *to = ';'; - while (to = strchr(buf, ':')) - *to = ';'; - if (newfinger) { - if (haddr[0] == ' ') { - strncpy(haddr, buf, 80); - haddr[80] = 0; - changed++; - } else if (strncmp(strtrim(haddr), buf, 80)) - nochange++; - } else { - if (strncmp(strtrim(haddr), buf, 80)) - changed++; - strncpy(haddr, buf, 80); - haddr[80] = 0; - } - from = e->dphone; - to = buf; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; - } - *to = 0; - if (newfinger) { - if (hphone[0] == ' ') { - strncpy(hphone, buf, 16); - hphone[16] = 0; - } else if (strncmp(strtrim(hphone), buf, 16)) - nochange++; - } else { - if (strncmp(strtrim(hphone), buf, 16)) - changed++; - strncpy(hphone, buf, 16); - hphone[16] = 0; - } - from = e->mphone; - to = buf; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; - } - *to = 0; - if (newfinger) { - if (ophone[0] == ' ') { - strncpy(ophone, buf, 12); - ophone[12] = 0; - } else if (strncmp(strtrim(ophone), buf, 12)) - nochange++; - } else { - if (strncmp(strtrim(ophone), buf, 12)) - changed++; - strncpy(ophone, buf, 12); - ophone[12] = 0; - } - e->course = e->course; - if (newfinger) { - if (dept[0] == ' ') { - strncpy(dept, e->course, 12); - dept[12] = 0; - } else if (strncmp(strtrim(dept), e->course, 11)) - nochange++; - } else { - if (strncmp(strtrim(dept), e->course, 11)) + /* Deal with updating the finger info if necessary */ + changed = nochange = 0; + if (encrypted) + changed++; + strcpy(buf, e->address); + if (*e->dorm) + { + strcat(buf, " "); + strcat(buf, e->dorm); + } + if (*e->city) + { + strcat(buf, " "); + strcat(buf, e->city); + } + FixCase(buf); + if (*e->state) + { + strcat(buf, " "); + strcat(buf, e->state); + } + while ((to = strchr(buf, ','))) + *to = ';'; + while ((to = strchr(buf, ':'))) + *to = ';'; + if (newfinger) + { + if (haddr[0] == ' ') + { + strncpy(haddr, buf, 80); + haddr[80] = '\0'; changed++; - strncpy(dept, e->course, 12); - dept[12] = 0; - } - sid = e->id; - name = e->name; - rdept = e->course; - rtitle = e->title; - rophone = e->mphone; - rhphone = e->dphone; - strcpy(raddr, e->address); - if (*e->dorm) { - strcat(raddr, " "); - strcat(raddr, e->dorm); - } - strcat(raddr, "|"); - if (*e->city) { - strcat(raddr, e->city); - FixCase(raddr); - if (*e->state) { - strcat(raddr, " "); - if (isupper(e->state[0]) && isupper(e->state[1]) && - isdigit(e->state[2]) && isdigit(e->state[3]) && - isdigit(e->state[4]) && isdigit(e->state[5]) && - isdigit(e->state[6])) { - sprintf(buf, "%c%c %s", e->state[0],e->state[1], - &(e->state[2])); - strcat(raddr, buf); - } else - strcat(raddr, e->state); } - } else { - FixCase(raddr); - strcat(raddr, "MIT INTERDEPARTMENTAL MAIL"); - } - if (changed) { - com_err(whoami, 0, "updating finger for %s %s", first, last); - 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) { + else if (strncmp(strtrim(haddr), buf, 80)) + nochange++; + } + else + { + if (strncmp(strtrim(haddr), buf, 80)) + changed++; + strncpy(haddr, buf, 80); + haddr[80] = '\0'; + } + from = e->dphone; + to = buf; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; + } + *to = '\0'; + if (newfinger) + { + if (hphone[0] == ' ') + { + strncpy(hphone, buf, 16); + hphone[16] = '\0'; + } + else if (strncmp(strtrim(hphone), buf, 16)) + nochange++; + } + else + { + if (strncmp(strtrim(hphone), buf, 16)) + changed++; + strncpy(hphone, buf, 16); + hphone[16] = '\0'; + } + from = e->mphone; + to = buf; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; + } + *to = '\0'; + if (newfinger) + { + if (ophone[0] == ' ') + { + strncpy(ophone, buf, 12); + ophone[12] = '\0'; + } + else if (strncmp(strtrim(ophone), buf, 12)) + nochange++; + } + else + { + if (strncmp(strtrim(ophone), buf, 12)) + changed++; + strncpy(ophone, buf, 12); + ophone[12] = '\0'; + } + e->course = e->course; + if (newfinger) + { + if (dept[0] == ' ') + { + strncpy(dept, e->course, 12); + dept[12] = '\0'; + } + else if (strncmp(strtrim(dept), e->course, 11)) + nochange++; + } + else + { + if (strncmp(strtrim(dept), e->course, 11)) + changed++; + strncpy(dept, e->course, 12); + dept[12] = '\0'; + } + sid = e->id; + name = e->name; + rdept = e->course; + rtitle = e->title; + rophone = e->mphone; + rhphone = e->dphone; + strcpy(raddr, e->address); + if (*e->dorm) + { + strcat(raddr, " "); + strcat(raddr, e->dorm); + } + strcat(raddr, "|"); + if (*e->city) + { + strcat(raddr, e->city); + FixCase(raddr); + if (*e->state) + { + strcat(raddr, " "); + if (isupper(e->state[0]) && isupper(e->state[1]) && + isdigit(e->state[2]) && isdigit(e->state[3]) && + isdigit(e->state[4]) && isdigit(e->state[5]) && + isdigit(e->state[6])) + { + sprintf(buf, "%c%c %s", e->state[0], e->state[1], + &(e->state[2])); + strcat(raddr, buf); + } + else + strcat(raddr, e->state); + } + } + else + { + FixCase(raddr); + strcat(raddr, "MIT INTERDEPARTMENTAL MAIL"); + } + if (changed) + { + com_err(whoami, 0, "updating finger for %s %s", first, last); + 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) + { dbmserr(NULL, sqlca.sqlcode); exit(1); } - } else { - 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) { + } + else + { + 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) + { dbmserr(NULL, sqlca.sqlcode); exit(1); } @@ -486,219 +563,241 @@ struct entry *e; } -newuser(e) -struct entry *e; +newuser(struct entry *e) { - char buf[512], *from, *to; - EXEC SQL BEGIN DECLARE SECTION; - int id, uid, who; - char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog; - char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name; - EXEC SQL END DECLARE SECTION; - - who = WHO; - prog = PROG; - strcpy(buf, e->address); - if (*e->dorm) { - strcat(buf, " "); - strcat(buf, e->dorm); - } - if (*e->city) { - strcat(buf, " "); - strcat(buf, e->city); - } - if (*e->state) { - strcat(buf, " "); - strcat(buf, e->state); - } - strncpy(haddr, buf, 80); - from = e->dphone; - to = buf; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; - } - *to = 0; - strncpy(hphone, buf, 16); - from = e->mphone; - to = buf; - while (*from) { - if (isdigit(*from)) - *to++ = *from; - from++; - } - *to = 0; - strncpy(ophone, buf, 12); - strncpy(dept, e->course, 12); - - id = set_next_users_id(0); - uid = set_next_uid(1); - sprintf(login, "#%d", uid); - last = e->last; - first = e->first; - middle = e->middle; - sid = e->id; - class = e->class; - title = e->title; - if (*middle) - sprintf(fullname, "%s %s %s", first, middle, last); - else - sprintf(fullname, "%s %s", first, last); - name = e->name; - strcpy(raddr, e->address); - if (*e->dorm) { - strcat(raddr, " "); - strcat(raddr, e->dorm); - } - strcat(raddr, "|"); - if (*e->city) { - strcat(raddr, e->city); - FixCase(raddr); - if (*e->state) { - strcat(raddr, " "); - if (isupper(e->state[0]) && isupper(e->state[1]) && - isdigit(e->state[2]) && isdigit(e->state[3]) && - isdigit(e->state[4]) && isdigit(e->state[5]) && - isdigit(e->state[6])) { - sprintf(buf, "%c%c %s", e->state[0],e->state[1], - &(e->state[2])); - strcat(raddr, buf); - } else - strcat(raddr, e->state); + char buf[512], *from, *to; + EXEC SQL BEGIN DECLARE SECTION; + int id, uid, who; + char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog; + char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name; + EXEC SQL END DECLARE SECTION; + + who = WHO; + prog = PROG; + strcpy(buf, e->address); + if (*e->dorm) + { + strcat(buf, " "); + strcat(buf, e->dorm); + } + if (*e->city) + { + strcat(buf, " "); + strcat(buf, e->city); + } + if (*e->state) + { + strcat(buf, " "); + strcat(buf, e->state); + } + strncpy(haddr, buf, 80); + from = e->dphone; + to = buf; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; + } + *to = '\0'; + strncpy(hphone, buf, 16); + from = e->mphone; + to = buf; + while (*from) + { + if (isdigit(*from)) + *to++ = *from; + from++; + } + *to = '\0'; + strncpy(ophone, buf, 12); + strncpy(dept, e->course, 12); + + id = set_next_users_id(0); + uid = set_next_uid(1); + sprintf(login, "#%d", uid); + last = e->last; + first = e->first; + middle = e->middle; + sid = e->id; + class = e->class; + title = e->title; + if (*middle) + sprintf(fullname, "%s %s %s", first, middle, last); + else + sprintf(fullname, "%s %s", first, last); + name = e->name; + strcpy(raddr, e->address); + if (*e->dorm) + { + strcat(raddr, " "); + strcat(raddr, e->dorm); + } + strcat(raddr, "|"); + if (*e->city) + { + strcat(raddr, e->city); + FixCase(raddr); + if (*e->state) + { + strcat(raddr, " "); + if (isupper(e->state[0]) && isupper(e->state[1]) && + isdigit(e->state[2]) && isdigit(e->state[3]) && + isdigit(e->state[4]) && isdigit(e->state[5]) && + isdigit(e->state[6])) + { + sprintf(buf, "%c%c %s", e->state[0], e->state[1], + &(e->state[2])); + strcat(raddr, buf); + } + else + strcat(raddr, e->state); } - } else { - FixCase(raddr); - strcat(raddr, "MIT INTERDEPARTMENTAL MAIL"); - } - 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/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) { + } + else + { + FixCase(raddr); + strcat(raddr, "MIT INTERDEPARTMENTAL MAIL"); + } + 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/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) + { dbmserr("adding user", sqlca.sqlcode); exit(1); - } else - com_err(whoami, 0, "adding user %s %s", e->first, e->last); + } + else + com_err(whoami, 0, "adding user %s %s", e->first, e->last); } - -set_next_users_id(limit) - int limit; +int set_next_users_id(int limit) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, flag, value, retval; - EXEC SQL END DECLARE SECTION; - - EXEC SQL SELECT value INTO :value FROM numvalues - WHERE name = 'users_id'; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] != 1) { - EXEC SQL ROLLBACK; - com_err(whoami, MR_INTERNAL, "values table inconsistancy"); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, flag, value, retval; + EXEC SQL END DECLARE SECTION; + + EXEC SQL SELECT value INTO :value FROM numvalues + WHERE name = 'users_id'; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] != 1) + { + EXEC SQL ROLLBACK; + com_err(whoami, MR_INTERNAL, "values table inconsistancy"); + exit(1); } + flag = 0; + EXEC SQL SELECT users_id INTO :flag FROM users + WHERE users_id = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT users_id INTO :flag FROM users - WHERE users_id = :value; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] == 0) + while (flag) + { + value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; flag = 0; - while (flag) { - value++; - if (limit && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; + EXEC SQL SELECT users_id INTO :flag FROM users + WHERE users_id = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT users_id INTO :flag FROM users - WHERE users_id = :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 UPDATE numvalues SET value = :value - WHERE name = 'users_id'; - if (sqlca.sqlcode != 0) { - dbmserr("updating numvalues", sqlca.sqlcode); - exit(1); - } - return(retval); + } + + retval = value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + EXEC SQL UPDATE numvalues SET value = :value + WHERE name = 'users_id'; + if (sqlca.sqlcode) + { + dbmserr("updating numvalues", sqlca.sqlcode); + exit(1); + } + return retval; } -set_next_uid(limit) - int limit; +int set_next_uid(int limit) { - EXEC SQL BEGIN DECLARE SECTION; - int rowcount, flag, value, retval; - EXEC SQL END DECLARE SECTION; - - EXEC SQL SELECT value INTO :value FROM numvalues - WHERE name = 'unix_uid'; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] != 1) { - EXEC SQL ROLLBACK; - com_err(whoami, MR_INTERNAL, "values table inconsistancy"); - exit(1); + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, flag, value, retval; + EXEC SQL END DECLARE SECTION; + + EXEC SQL SELECT value INTO :value FROM numvalues + WHERE name = 'unix_uid'; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] != 1) + { + EXEC SQL ROLLBACK; + com_err(whoami, MR_INTERNAL, "values table inconsistancy"); + exit(1); } + flag = 0; + EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; - if (sqlfail()) sqlexit(); - if (sqlca.sqlerrd[2] == 0) + while (flag) + { + value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; flag = 0; - while (flag) { - value++; - if (limit && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; + EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value; + if (sqlfail()) + sqlexit(); + if (sqlca.sqlerrd[2] == 0) flag = 0; - 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 UPDATE numvalues SET value = :value WHERE name = 'unix_uid'; - if (sqlca.sqlcode != 0) { - dbmserr("updating numvalues", sqlca.sqlcode); - exit(1); + retval = value++; + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + EXEC SQL UPDATE numvalues SET value = :value WHERE name = 'unix_uid'; + if (sqlca.sqlcode) + { + dbmserr("updating numvalues", sqlca.sqlcode); + exit(1); } - return(retval); + return retval; } -sqlexit() +sqlexit(void) { - dbmserr(NULL, sqlca.sqlcode); - EXEC SQL ROLLBACK WORK; - exit(1); + dbmserr(NULL, sqlca.sqlcode); + EXEC SQL ROLLBACK WORK; + exit(1); } dbmserr(char *where, int what) { char err_msg[256]; - int bufsize=256, msglength=0; + int bufsize = 256, msglength = 0; sqlglm(err_msg, &bufsize, &msglength); - err_msg[msglength]=0; + err_msg[msglength] = '\0'; - if(where) + if (where) com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where); else com_err(whoami, 0, "DBMS error %s", err_msg); diff --git a/regtape/verify.pc b/regtape/verify.pc index 5a42ff7c..d5d28089 100644 --- a/regtape/verify.pc +++ b/regtape/verify.pc @@ -18,254 +18,281 @@ EXEC SQL INCLUDE sqlca; char *program; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - 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; + 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; - initialize_sms_error_table(); - initialize_krb_error_table(); - initialize_gdss_error_table(); + initialize_sms_error_table(); + initialize_krb_error_table(); + initialize_gdss_error_table(); - program = "sign"; - check = debug = fix = 0; + program = "sign"; + check = debug = fix = 0; - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-w")) - wait++; - else if (!strcmp(argv[i], "-d")) - debug++; - else if (!strcmp(argv[i], "-D")) - setenv("ING_SET", "set printqry"); - else if (!strcmp(argv[i], "-fix")) - fix++; - else if (argv[i][0] == '-') - fprintf(stderr, "Usage: %s [-w] [-D] [-fix]\n", argv[0]); - else usercheck[check++] = argv[i]; + for (i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "-w")) + wait++; + else if (!strcmp(argv[i], "-d")) + debug++; + else if (!strcmp(argv[i], "-D")) + setenv("ING_SET", "set printqry"); + else if (!strcmp(argv[i], "-fix")) + fix++; + else if (argv[i][0] == '-') + fprintf(stderr, "Usage: %s [-w] [-D] [-fix]\n", argv[0]); + else usercheck[check++] = argv[i]; } - EXEC SQL CONNECT :db IDENTIFIED BY :db; + EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (fix) { - /* Set the name of our kerberos ticket file */ - krb_set_tkt_string("/tmp/tkt_sign"); - status = 1; - while (status) { - printf("Authenticating as moira.extra:\n"); - status = krb_get_pw_in_tkt("moira", "extra", "ATHENA.MIT.EDU", - "krbtgt", "ATHENA.MIT.EDU", - DEFAULT_TKT_LIFE, 0); - if (status != 0) - com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt"); + if (fix) + { + /* Set the name of our kerberos ticket file */ + krb_set_tkt_string("/tmp/tkt_sign"); + status = 1; + while (status) + { + printf("Authenticating as moira.extra:\n"); + status = krb_get_pw_in_tkt("moira", "extra", "ATHENA.MIT.EDU", + "krbtgt", "ATHENA.MIT.EDU", + DEFAULT_TKT_LIFE, 0); + if (status != 0) + com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt"); } - com_err(program, 0, "authenticated OK"); + com_err(program, 0, "authenticated OK"); - sms = 0; - EXEC SQL SELECT string_id INTO :sms FROM strings - WHERE string='moira.extra@ATHENA.MIT.EDU'; - if (sms == 0) { - com_err(program, 0, " failed to find string moira.extra@ATHENA.MIT.EDU in database"); - dest_tkt(); - exit(1); + sms = 0; + EXEC SQL SELECT string_id INTO :sms FROM strings + WHERE string = 'moira.extra@ATHENA.MIT.EDU'; + if (sms == 0) + { + com_err(program, 0, " failed to find string " + "moira.extra@ATHENA.MIT.EDU in database"); + dest_tkt(); + exit(1); } - sq = sq_create(); + sq = sq_create(); } - if (check == 0) { - EXEC SQL DECLARE c CURSOR FOR - SELECT login, clearid, signature, string, sigdate - FROM users, strings - 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 (sqlca.sqlcode != 0) break; - sprintf(buf, "%s:%s", strtrim(login), strtrim(mid)); - si.timestamp = timestamp; - si.SigInfoVersion = 0; - kname_parse(si.pname, si.pinst, si.prealm, strtrim(who)); - si.rawsig = (unsigned char *) &rawsig[0]; - status = GDSS_Recompose(&si, sigbuf); - if (status) { - com_err(program, gdss2et(status), "recomposing for user %s", - login); - continue; + if (check == 0) + { + EXEC SQL DECLARE c CURSOR FOR + SELECT login, clearid, signature, string, sigdate + FROM users, strings + 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 (sqlca.sqlcode) + break; + sprintf(buf, "%s:%s", strtrim(login), strtrim(mid)); + si.timestamp = timestamp; + si.SigInfoVersion = 0; + kname_parse(si.pname, si.pinst, si.prealm, strtrim(who)); + si.rawsig = (unsigned char *) &rawsig[0]; + status = GDSS_Recompose(&si, sigbuf); + if (status) + { + com_err(program, gdss2et(status), "recomposing for user %s", + login); + continue; } - si.rawsig = NULL; - status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); - if (status) { - com_err(program, gdss2et(status), "verifying user %s", login); - } - if (fix && status == GDSS_E_BADSIG) { - sq_save_data(sq, strsave(buf)); - } - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); + si.rawsig = NULL; + status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); + if (status) + com_err(program, gdss2et(status), "verifying user %s", login); + if (fix && status == GDSS_E_BADSIG) + sq_save_data(sq, strsave(buf)); + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); } } - if (fix) { - while (sq_get_data(sq, &data)) { - strncpy(login, data, 8); - if (strchr(login, ':')) - *strchr(login, ':') = 0; + if (fix) + { + while (sq_get_data(sq, &data)) + { + strncpy(login, data, 8); + if (strchr(login, ':')) + *strchr(login, ':') = '\0'; again: - com_err(program, 0, "fixing sig for %s", login); - status = GDSS_Sign(data, strlen(data), sigbuf, &si); - if (status) { - com_err(program, gdss2et(status), "signing data"); - continue; + com_err(program, 0, "fixing sig for %s", login); + status = GDSS_Sign(data, strlen(data), sigbuf, &si); + if (status) + { + com_err(program, gdss2et(status), "signing data"); + continue; } - si.rawsig = (unsigned char *)rawsig; - status = GDSS_Verify(data, strlen(data), sigbuf, &si); - if (status) { - com_err(program, gdss2et(status), "verifying data"); - continue; + si.rawsig = (unsigned char *)rawsig; + status = GDSS_Verify(data, strlen(data), sigbuf, &si); + if (status) + { + com_err(program, gdss2et(status), "verifying data"); + continue; } - if (strlen(rawsig) > 68) { - sleep(1); - goto again; + if (strlen(rawsig) > 68) + { + sleep(1); + goto again; } - timestamp = si.timestamp; - EXEC SQL UPDATE users - SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp - WHERE login = :login; - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - dest_tkt(); - exit(1); + timestamp = si.timestamp; + EXEC SQL UPDATE users + SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp + WHERE login = :login; + if (sqlca.sqlcode) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + dest_tkt(); + exit(1); } - EXEC SQL COMMIT WORK; + EXEC SQL COMMIT WORK; } } - } else { - for (i = check - 1; i >= 0; i--) { - strcpy(login, usercheck[i]); - EXEC SQL DECLARE s CURSOR FOR - SELECT clearid, signature, string, sigdate - FROM users, strings - WHERE sigwho = string_id and login = :login; - EXEC SQL OPEN s; - while (1) { - EXEC SQL FETCH s INTO :mid, :rawsig, :who, :timestamp; - if (sqlca.sqlcode != 0) break; - sprintf(buf, "%s:%s", strtrim(login), strtrim(mid)); - if (debug) { - printf("Verifying \"%s\"\n", buf); - } - si.timestamp = timestamp; - si.SigInfoVersion = 0; - kname_parse(si.pname, si.pinst, si.prealm, strtrim(who)); - si.rawsig = (unsigned char *) &rawsig[0]; - status = GDSS_Recompose(&si, sigbuf); - if (status) { - com_err(program, gdss2et(status), "recomposing for user %s", login); - continue; + } + else + { + for (i = check - 1; i >= 0; i--) + { + strcpy(login, usercheck[i]); + EXEC SQL DECLARE s CURSOR FOR + SELECT clearid, signature, string, sigdate + FROM users, strings + WHERE sigwho = string_id and login = :login; + EXEC SQL OPEN s; + while (1) + { + EXEC SQL FETCH s INTO :mid, :rawsig, :who, :timestamp; + if (sqlca.sqlcode) + break; + sprintf(buf, "%s:%s", strtrim(login), strtrim(mid)); + if (debug) + printf("Verifying \"%s\"\n", buf); + si.timestamp = timestamp; + si.SigInfoVersion = 0; + kname_parse(si.pname, si.pinst, si.prealm, strtrim(who)); + si.rawsig = (unsigned char *) &rawsig[0]; + status = GDSS_Recompose(&si, sigbuf); + if (status) + { + com_err(program, gdss2et(status), "recomposing for user %s", + login); + continue; } - si.rawsig = NULL; - status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); - if (fix && status == GDSS_E_BADSIG) { - com_err(program, 0, "fixing signature for %s", login); + si.rawsig = NULL; + status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); + if (fix && status == GDSS_E_BADSIG) + { + com_err(program, 0, "fixing signature for %s", login); againagain: - status = GDSS_Sign(buf, strlen(buf), sigbuf); - if (status) { - com_err(program, gdss2et(status), "signing data"); - continue; + status = GDSS_Sign(buf, strlen(buf), sigbuf); + if (status) + { + com_err(program, gdss2et(status), "signing data"); + continue; } - si.rawsig = (unsigned char *) rawsig; - status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); - if (status) { - com_err(program, gdss2et(status), "verifying data"); - continue; + si.rawsig = (unsigned char *) rawsig; + status = GDSS_Verify(buf, strlen(buf), sigbuf, &si); + if (status) + { + com_err(program, gdss2et(status), "verifying data"); + continue; } - if (strlen(rawsig) > 68) { - sleep(1); - goto againagain; + if (strlen(rawsig) > 68) + { + sleep(1); + goto againagain; } - timestamp = si.timestamp; - EXEC SQL UPDATE users - SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp - WHERE login = :login; - if (sqlca.sqlcode != 0) { - com_err(program, 0, "dbms error %d", sqlca.sqlcode); - dest_tkt(); - exit(1); - } - EXEC SQL COMMIT WORK; - } else if (status) - com_err(program, gdss2et(status), "verifying user %s", login); - else { - com_err(program, 0, "signature verified %s", buf); - if (debug == 2) { - hex_dump(sigbuf); + timestamp = si.timestamp; + EXEC SQL UPDATE users + SET signature = :rawsig, sigwho = :sms, + sigdate = :timestamp + WHERE login = :login; + if (sqlca.sqlcode != 0) + { + com_err(program, 0, "dbms error %d", sqlca.sqlcode); + dest_tkt(); + exit(1); } + EXEC SQL COMMIT WORK; + } + else if (status) + com_err(program, gdss2et(status), "verifying user %s", login); + else + { + com_err(program, 0, "signature verified %s", buf); + if (debug == 2) + hex_dump(sigbuf); } - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); } } } } - dest_tkt(); - exit(0); + dest_tkt(); + exit(0); } -hex_dump(p) -unsigned char *p; +hex_dump(unsigned char *p) { - printf("Size: %d\n", strlen(p)); - while (strlen(p) >= 8) { - printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - p += 8; + printf("Size: %d\n", strlen(p)); + while (strlen(p) >= 8) + { + printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); + p += 8; } - switch (strlen(p)) { + switch (strlen(p)) + { case 7: - printf("%02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6]); - break; + printf("%02x %02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6]); + break; case 6: - printf("%02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5]); - break; + printf("%02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5]); + break; case 5: - printf("%02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4]); - break; + printf("%02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4]); + break; case 4: - printf("%02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3]); - break; + printf("%02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3]); + break; case 3: - printf("%02x %02x %02x\n", - p[0], p[1], p[2]); - break; + printf("%02x %02x %02x\n", + p[0], p[1], p[2]); + break; case 2: - printf("%02x %02x\n", - p[0], p[1]); - break; + printf("%02x %02x\n", + p[0], p[1]); + break; case 1: - printf("%02x\n", - p[0]); - break; + printf("%02x\n", + p[0]); + break; default: - return; + return; } } diff --git a/regtape/vote.pc b/regtape/vote.pc index 90b71fa3..8593800a 100644 --- a/regtape/vote.pc +++ b/regtape/vote.pc @@ -11,117 +11,120 @@ EXEC SQL INCLUDE sqlca; struct entry { - char *line; - char id[19]; - char login[9]; + char *line; + char id[19]; + char login[9]; }; char *whoami; int debug; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - FILE *in; - struct entry *e, *get_next_entry(); - int i, wait = 0; - char buf[BUFSIZ], *file = NULL, *p, *p1, *db="moira"; - - debug = 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++; - else if (!strcmp(argv[i], "-D")) - setenv("ING_SET", "set printqry"); - else if (!strcmp(argv[i], "-d")) - debug = 1; - else if (file != NULL) - fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); - else - file = argv[i]; + FILE *in; + struct entry *e, *get_next_entry(); + int i, wait = 0; + char buf[BUFSIZ], *file = NULL, *p, *p1, *db = "moira"; + + debug = 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++; + else if (!strcmp(argv[i], "-D")) + setenv("ING_SET", "set printqry"); + else if (!strcmp(argv[i], "-d")) + debug = 1; + else if (file) + fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami); + else + file = argv[i]; } - in = fopen(file, "r"); - if (in == NULL) { - fprintf(stderr, "Unable to open %s for input\n", file); - exit(1); + in = fopen(file, "r"); + if (!in) + { + fprintf(stderr, "Unable to open %s for input\n", file); + exit(1); } - EXEC SQL CONNECT :db IDENTIFIED BY :db; - if (sqlca.sqlcode != 0) { - com_err(whoami, 0, "ingres error %d", sqlca.sqlcode); - exit(1); + EXEC SQL CONNECT :db IDENTIFIED BY :db; + if (sqlca.sqlcode) + { + com_err(whoami, 0, "ingres error %d", sqlca.sqlcode); + exit(1); } - while (e = get_next_entry(in)) { - i = process_entry(e); - EXEC SQL COMMIT WORK; - if (i == 0) { - p = &(e->line[0]); - for (p1 = e->login; *p1; p1++) - *p++ = *p1; - for (; p < &(e->line[10]); p++) - *p = ' '; - fputs(e->line, stdout); + while ((e = get_next_entry(in))) + { + i = process_entry(e); + EXEC SQL COMMIT WORK; + if (i == 0) + { + p = &(e->line[0]); + for (p1 = e->login; *p1; p1++) + *p++ = *p1; + for (; p < &(e->line[10]); p++) + *p = ' '; + fputs(e->line, stdout); } - if (wait) { - printf("Next"); - fflush(stdout); - gets(buf); + if (wait) + { + printf("Next"); + fflush(stdout); + gets(buf); } } - exit(0); + exit(0); } -struct entry *get_next_entry(in) -FILE *in; +struct entry *get_next_entry(FILE *in) { - static struct entry e; - static char buf[BUFSIZ]; + static struct entry e; + static char buf[BUFSIZ]; - if (fgets(buf, sizeof(buf), in) == NULL) - return((struct entry *)NULL); + if (!fgets(buf, sizeof(buf), in)) + return NULL; - e.line = &buf[0]; - strncpy(e.id, &buf[0], 9); - e.id[9] = 0; - e.login[0] = 0; - return(&e); + e.line = &buf[0]; + strncpy(e.id, &buf[0], 9); + e.id[9] = '\0'; + e.login[0] = '\0'; + return &e; } -process_entry(e) -struct entry *e; +int process_entry(struct entry *e) { - 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 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); + 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 SELECT login INTO :login FROM users WHERE clearid = :id; + if (sqlca.sqlcode) + { + fprintf(stderr, "Error %d on %s\n", sqlca.sqlcode, e->line); + return -1; } - strncpy(e->login, login, 8); - e->login[8] = 0; - if (debug) - printf("Got username %s\n", login); - return(0); + strncpy(e->login, login, 8); + e->login[8] = 0; + if (debug) + printf("Got username %s\n", login); + return 0; } diff --git a/server/cache.pc b/server/cache.pc index 2fe40354..66ca1827 100644 --- a/server/cache.pc +++ b/server/cache.pc @@ -25,13 +25,13 @@ extern char *whoami; #define NAMESZ 257 /* max size of a name */ struct item { - char name[NAMESZ]; - enum tables type; - int nhash; - int id; - struct item *next; - struct item *prev; - struct item *trans; /* keep track of transactions */ + char name[NAMESZ]; + enum tables type; + int nhash; + int id; + struct item *next; + struct item *prev; + struct item *trans; /* keep track of transactions */ }; static struct item cachehead; @@ -43,15 +43,13 @@ int cachehits = 0, cachemisses = 0; /* Name hash function. */ -int hashname(name, type) - char *name; - enum tables type; +int hashname(char *name, enum tables type) { - register int val = type; + register int val = type; - while (*name) - val = (val<<5) - val + *name++ - '`'; - return(val); + while (*name) + val = (val << 5) - val + *name++ - '`'; + return val; } @@ -61,23 +59,26 @@ int hashname(name, type) void flush_cache(void) { - register struct item *i; + register struct item *i; - if (cachehits + cachemisses != 0) + if (cachehits + cachemisses != 0) + { com_err(whoami, 0, "Flushing cache; %d hits, %d misses, %d%% hit rate", cachehits, cachemisses, (100 * cachehits) / (cachehits + cachemisses)); - else - cachehead.next = cachehead.prev = &cachehead; - cachehits = cachemisses = cachesize = 0; - for (i = cachehead.next; i != &cachehead; i = i->next) { - if (i->prev != &cachehead) - free(i->prev); } - if (cachehead.prev != &cachehead) - free(cachehead.prev); + else cachehead.next = cachehead.prev = &cachehead; - cachehead.trans = (struct item *)NULL; + cachehits = cachemisses = cachesize = 0; + for (i = cachehead.next; i != &cachehead; i = i->next) + { + if (i->prev != &cachehead) + free(i->prev); + } + if (cachehead.prev != &cachehead) + free(cachehead.prev); + cachehead.next = cachehead.prev = &cachehead; + cachehead.trans = NULL; } @@ -85,101 +86,104 @@ void flush_cache(void) * it is available, and as a side effect the cache is updated. */ -int name_to_id(name, type, id) - char *name; - enum tables type; - int *id; +int name_to_id(char *name, enum tables type, int *id) { - register struct item *i, *t; - EXEC SQL BEGIN DECLARE SECTION; - char *iname; - int j, h; - EXEC SQL END DECLARE SECTION; - - h = hashname(name, type); - for (i = cachehead.next; i != &cachehead; i = i->next) { - if (i->nhash != h || - strcmp(name, i->name) || - type!=i->type) - continue; - *id = i->id; - cachehits++; - i->next->prev = i->prev; - i->prev->next = i->next; - i->next = cachehead.next; - i->prev = &cachehead; - cachehead.next->prev = i; - cachehead.next = i; - return(MR_SUCCESS); + register struct item *i, *t; + EXEC SQL BEGIN DECLARE SECTION; + char *iname; + int j, h; + EXEC SQL END DECLARE SECTION; + + h = hashname(name, type); + for (i = cachehead.next; i != &cachehead; i = i->next) + { + if (i->nhash != h || strcmp(name, i->name) || type != i->type) + continue; + *id = i->id; + cachehits++; + i->next->prev = i->prev; + i->prev->next = i->next; + i->next = cachehead.next; + i->prev = &cachehead; + cachehead.next->prev = i; + cachehead.next = i; + return MR_SUCCESS; } - cachemisses++; - iname = name; + cachemisses++; + iname = name; - switch (type) - { - case USERS_TABLE: - if (strchr(iname, '@') || (strlen(iname) > 8)) { + switch (type) + { + case USERS_TABLE: + if (strchr(iname, '@') || (strlen(iname) > 8)) + { sqlca.sqlcode = SQL_NO_MATCH; break; } - EXEC SQL SELECT users_id INTO :j FROM users WHERE login=:iname; - break; - case LIST_TABLE: - EXEC SQL SELECT list_id INTO :j FROM list WHERE name=:iname; - break; - case MACHINE_TABLE: - EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=UPPER(:iname); - break; - case SUBNET_TABLE: - EXEC SQL SELECT snet_id INTO :j FROM subnet WHERE name=UPPER(:iname); - break; - case CLUSTER_TABLE: - EXEC SQL SELECT clu_id INTO :j FROM clusters WHERE name=:iname; - break; - case FILESYS_TABLE: - EXEC SQL SELECT filsys_id INTO :j FROM filesys WHERE label=:iname; - break; - case STRINGS_TABLE: - if (!iname[0]) { /* special-case empty string */ - *id=0; + EXEC SQL SELECT users_id INTO :j FROM users WHERE login = :iname; + break; + case LIST_TABLE: + EXEC SQL SELECT list_id INTO :j FROM list WHERE name = :iname; + break; + case MACHINE_TABLE: + EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name = UPPER(:iname); + break; + case SUBNET_TABLE: + EXEC SQL SELECT snet_id INTO :j FROM subnet WHERE name = UPPER(:iname); + break; + case CLUSTER_TABLE: + EXEC SQL SELECT clu_id INTO :j FROM clusters WHERE name = :iname; + break; + case FILESYS_TABLE: + EXEC SQL SELECT filsys_id INTO :j FROM filesys WHERE label = :iname; + break; + case STRINGS_TABLE: + if (!iname[0]) /* special-case empty string */ + { + *id = 0; return MR_SUCCESS; } - EXEC SQL SELECT string_id INTO :j FROM strings WHERE string=:iname; - break; - default: - return(MR_INTERNAL); + EXEC SQL SELECT string_id INTO :j FROM strings WHERE string = :iname; + break; + default: + return MR_INTERNAL; + } + if (sqlca.sqlcode == SQL_NO_MATCH) + return MR_NO_MATCH; + if (sqlca.sqlerrd[2] > 1) + return MR_NOT_UNIQUE; + if (sqlca.sqlcode) + return MR_DBMS_ERR; + *id = j; + if (name[0] == '#' && type != USERS_TABLE) + return MR_SUCCESS; + if (cachesize < CACHESIZE) + { + i = malloc(sizeof(struct item)); + cachesize++; } - if (sqlca.sqlcode == SQL_NO_MATCH) - return(MR_NO_MATCH); - if (sqlca.sqlerrd[2] > 1) - return(MR_NOT_UNIQUE); - if (sqlca.sqlcode != 0) - return(MR_DBMS_ERR); - *id = j; - if (name[0] == '#' && type!=USERS_TABLE) - return(MR_SUCCESS); - if (cachesize < CACHESIZE) { - i = (struct item *) malloc(sizeof(struct item)); - cachesize++; - } else { - i = cachehead.prev; - cachehead.prev = i->prev; - i->prev->next = &cachehead; + else + { + i = cachehead.prev; + cachehead.prev = i->prev; + i->prev->next = &cachehead; } - strcpy(i->name, name); - i->type=type; - i->nhash = h; - i->id = j; - i->next = cachehead.next; - i->prev = &cachehead; - i->trans = NULL; - cachehead.next->prev = i; - cachehead.next = i; - /* find the end of the transaction chain & add this item */ - for (t = &cachehead; t->trans && t != i; t = t->trans); - if (t != i) t->trans = i; - return(MR_SUCCESS); + strcpy(i->name, name); + i->type = type; + i->nhash = h; + i->id = j; + i->next = cachehead.next; + i->prev = &cachehead; + i->trans = NULL; + cachehead.next->prev = i; + cachehead.next = i; + /* find the end of the transaction chain & add this item */ + for (t = &cachehead; t->trans && t != i; t = t->trans) + ; + if (t != i) + t->trans = i; + return MR_SUCCESS; } @@ -188,95 +192,100 @@ int name_to_id(name, type, id) * allocated with the answer. */ -int id_to_name(id, type, name) - int id; - enum tables type; - char **name; +int id_to_name(int id, enum tables type, char **name) { - register struct item *i, *t; - EXEC SQL BEGIN DECLARE SECTION; - char iname[NAMESZ]; - int j; - EXEC SQL END DECLARE SECTION; - - for (i = cachehead.next; i != &cachehead; i = i->next) { - if (i->id != id || type!=i->type) continue; - free(*name); - *name = strsave(i->name); - cachehits++; - i->next->prev = i->prev; - i->prev->next = i->next; - i->next = cachehead.next; - i->prev = &cachehead; - cachehead.next->prev = i; - cachehead.next = i; - return(MR_SUCCESS); + register struct item *i, *t; + EXEC SQL BEGIN DECLARE SECTION; + char iname[NAMESZ]; + int j; + EXEC SQL END DECLARE SECTION; + + for (i = cachehead.next; i != &cachehead; i = i->next) + { + if (i->id != id || type != i->type) + continue; + free(*name); + *name = strsave(i->name); + cachehits++; + i->next->prev = i->prev; + i->prev->next = i->next; + i->next = cachehead.next; + i->prev = &cachehead; + cachehead.next->prev = i; + cachehead.next = i; + return MR_SUCCESS; } - cachemisses++; - j = id; - - switch (type) - { - case USERS_TABLE: - EXEC SQL SELECT login INTO :iname FROM users WHERE users_id=:j; - break; - case LIST_TABLE: - EXEC SQL SELECT name INTO :iname FROM list WHERE list_id=:j; - break; - case MACHINE_TABLE: - EXEC SQL SELECT name INTO :iname FROM machine WHERE mach_id=:j; - break; - case SUBNET_TABLE: - EXEC SQL SELECT name INTO :iname FROM subnet WHERE snet_id=:j; - break; - case CLUSTER_TABLE: - EXEC SQL SELECT name INTO :iname FROM clusters WHERE clu_id=:j; - break; - case FILESYS_TABLE: - EXEC SQL SELECT label INTO :iname FROM filesys WHERE filsys_id=:j; - break; - case STRINGS_TABLE: - EXEC SQL SELECT string INTO :iname FROM strings WHERE string_id=:j; - break; + cachemisses++; + j = id; + + switch (type) + { + case USERS_TABLE: + EXEC SQL SELECT login INTO :iname FROM users WHERE users_id = :j; + break; + case LIST_TABLE: + EXEC SQL SELECT name INTO :iname FROM list WHERE list_id = :j; + break; + case MACHINE_TABLE: + EXEC SQL SELECT name INTO :iname FROM machine WHERE mach_id = :j; + break; + case SUBNET_TABLE: + EXEC SQL SELECT name INTO :iname FROM subnet WHERE snet_id = :j; + break; + case CLUSTER_TABLE: + EXEC SQL SELECT name INTO :iname FROM clusters WHERE clu_id = :j; + break; + case FILESYS_TABLE: + EXEC SQL SELECT label INTO :iname FROM filesys WHERE filsys_id = :j; + break; + case STRINGS_TABLE: + EXEC SQL SELECT string INTO :iname FROM strings WHERE string_id = :j; + break; default: - return(MR_INTERNAL); + return MR_INTERNAL; } - if (sqlca.sqlcode == SQL_NO_MATCH) { - free(*name); - sprintf(iname, "#%d", j); - *name = strsave(iname); - return(MR_NO_MATCH); + if (sqlca.sqlcode == SQL_NO_MATCH) + { + free(*name); + sprintf(iname, "#%d", j); + *name = strsave(iname); + return MR_NO_MATCH; } - if (sqlca.sqlerrd[2] > 1) - return(MR_INTERNAL); - if (sqlca.sqlcode != 0) - return(MR_DBMS_ERR); - free(*name); - *name = strsave(strtrim(iname)); - if (**name == '#' && type!=USERS_TABLE) - return(MR_SUCCESS); - if (cachesize < CACHESIZE) { - i = (struct item *) malloc(sizeof(struct item)); - cachesize++; - } else { - i = cachehead.prev; - cachehead.prev = i->prev; - i->prev->next = &cachehead; + if (sqlca.sqlerrd[2] > 1) + return MR_INTERNAL; + if (sqlca.sqlcode) + return MR_DBMS_ERR; + free(*name); + *name = strsave(strtrim(iname)); + if (**name == '#' && type != USERS_TABLE) + return MR_SUCCESS; + if (cachesize < CACHESIZE) + { + i = malloc(sizeof(struct item)); + cachesize++; } - strcpy(i->name, *name); - i->type=type; - i->nhash = hashname(*name, type); - i->id = id; - i->next = cachehead.next; - i->prev = &cachehead; - i->trans = NULL; - cachehead.next->prev = i; - cachehead.next = i; - /* find the end of the transaction chain & add this item */ - for (t = &cachehead; t->trans && t != i; t = t->trans); - if (t != i) t->trans = i; - return(MR_SUCCESS); + else + { + i = cachehead.prev; + cachehead.prev = i->prev; + i->prev->next = &cachehead; + } + strcpy(i->name, *name); + i->type = type; + i->nhash = hashname(*name, type); + i->id = id; + i->next = cachehead.next; + i->prev = &cachehead; + i->trans = NULL; + cachehead.next->prev = i; + cachehead.next = i; + /* find the end of the transaction chain & add this item */ + for (t = &cachehead; t->trans && t != i; t = t->trans) + ; + if (t != i) + t->trans = i; + return MR_SUCCESS; } @@ -284,67 +293,73 @@ int id_to_name(id, type, name) * database. */ -int cache_entry(name, type, id) - char *name; - enum tables type; - int id; +int cache_entry(char *name, enum tables type, int id) { - register struct item *i, *t; - - for (i = cachehead.next; i != &cachehead; i = i->next) - if (i->id == id && i->type==type) { - if (strcmp(i->name, name)) { + register struct item *i, *t; + + for (i = cachehead.next; i != &cachehead; i = i->next) + { + if (i->id == id && i->type == type) + { + if (strcmp(i->name, name)) + { strcpy(i->name, name); i->nhash = hashname(name, type); - } - return(MR_SUCCESS); - } - if (cachesize < CACHESIZE) { - i = (struct item *) malloc(sizeof(struct item)); - cachesize++; - } else { - i = cachehead.prev; - cachehead.prev = i->prev; - i->prev->next = &cachehead; + } + return MR_SUCCESS; + } + } + if (cachesize < CACHESIZE) + { + i = malloc(sizeof(struct item)); + cachesize++; + } + else + { + i = cachehead.prev; + cachehead.prev = i->prev; + i->prev->next = &cachehead; } - strcpy(i->name, name); - i->type=type; - i->nhash = hashname(name, type); - i->id = id; - i->next = cachehead.next; - i->prev = &cachehead; - i->trans = NULL; - cachehead.next->prev = i; - cachehead.next = i; - /* find the end of the transaction chain & add this item */ - for (t = &cachehead; t->trans && t != i; t = t->trans); - if (t != i) t->trans = i; - return(MR_SUCCESS); + strcpy(i->name, name); + i->type = type; + i->nhash = hashname(name, type); + i->id = id; + i->next = cachehead.next; + i->prev = &cachehead; + i->trans = NULL; + cachehead.next->prev = i; + cachehead.next = i; + /* find the end of the transaction chain & add this item */ + for (t = &cachehead; t->trans && t != i; t = t->trans) + ; + if (t != i) + t->trans = i; + return MR_SUCCESS; } /* Flush something that may or may not already be in the cache. */ -void flush_name(name, type) - char *name; - enum tables type; +void flush_name(char *name, enum tables type) { - register struct item *i; + register struct item *i; - /* first clear it out of the transaction chain */ - for (i = &cachehead; i && i->trans; i = i->trans) { - if (!strcmp(name, i->trans->name) && type==i->trans->type) { - i->trans = i->trans->trans; - } + /* first clear it out of the transaction chain */ + for (i = &cachehead; i && i->trans; i = i->trans) + { + if (!strcmp(name, i->trans->name) && type == i->trans->type) + i->trans = i->trans->trans; } - /* now remove it */ - for (i = cachehead.next; i != &cachehead; i = i->next) { - if (!strcmp(name, i->name) && type==i->type) { - cachesize--; - i->next->prev = i->prev; - i->prev->next = i->next; - free(i); + /* now remove it */ + for (i = cachehead.next; i != &cachehead; i = i->next) + { + if (!strcmp(name, i->name) && type == i->type) + { + cachesize--; + i->next->prev = i->prev; + i->prev->next = i->next; + free(i); } } } @@ -356,7 +371,7 @@ void flush_name(name, type) void cache_commit(void) { - cachehead.trans = (struct item *)NULL; + cachehead.trans = NULL; } @@ -366,11 +381,12 @@ void cache_commit(void) void cache_abort(void) { - register struct item *i, *t; + register struct item *i, *t; - for (i = cachehead.trans; i; i = t) { - t = i->trans; - flush_name(i->name, i->type); + for (i = cachehead.trans; i; i = t) + { + t = i->trans; + flush_name(i->name, i->type); } - cachehead.trans = (struct item *)NULL; + cachehead.trans = NULL; } diff --git a/server/increment.pc b/server/increment.pc index a913f2af..88080612 100644 --- a/server/increment.pc +++ b/server/increment.pc @@ -6,7 +6,7 @@ * Copyright (C) 1989 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . - * + * */ #ifndef lint @@ -48,12 +48,12 @@ static int afterc; struct save_queue *incremental_sq = NULL; struct save_queue *incremental_exec = NULL; struct iupdate { - char *table; - int beforec; - char **before; - int afterc; - char **after; - char *service; + char *table; + int beforec; + char **before; + int afterc; + char **after; + char *service; }; void next_incremental(void); @@ -63,298 +63,267 @@ int table_num(char *table); void incremental_init(void) { - int i; + int i; - if (incremental_sq == NULL) - incremental_sq = sq_create(); - if (incremental_exec == NULL) - incremental_exec = sq_create(); + if (!incremental_sq) + incremental_sq = sq_create(); + if (!incremental_exec) + incremental_exec = sq_create(); - for(i=0; itable = table_name[table]; - iu->beforec = beforec; - iu->before = copy_argv(before, beforec); - iu->afterc = afterc; - iu->after = copy_argv(after, afterc); - sq_save_data(incremental_sq, iu); - -#ifdef DEBUG - sprintf(buffer, "INCREMENTAL(%s, [", table_name[table]); - for (i = 0; i < beforec; i++) { - if (i == 0) - strcat(buffer, strtrim(before[0])); - else { - strcat(buffer, ", "); - strcat(buffer, strtrim(before[i])); - } - } - strcat(buffer, "], ["); - for (i = 0; i < afterc; i++) { - if (i == 0) - strcat(buffer, strtrim(after[0])); - else { - strcat(buffer, ", "); - strcat(buffer, strtrim(after[i])); - } + break; } - strcat(buffer, "])"); - com_err(whoami, 0, buffer); -#endif DEBUG + + iu = malloc(sizeof(struct iupdate)); + iu->table = table_name[table]; + iu->beforec = beforec; + iu->before = copy_argv(before, beforec); + iu->afterc = afterc; + iu->after = copy_argv(after, afterc); + sq_save_data(incremental_sq, iu); } void incremental_clear_after(void) { - incremental_after(NO_TABLE, NULL, NULL); + incremental_after(NO_TABLE, NULL, NULL); } @@ -364,108 +333,112 @@ void incremental_clear_after(void) */ struct inc_cache { - struct inc_cache *next; - char *table, *service; + struct inc_cache *next; + char *table, *service; }; void incremental_update(void) { - static int inited = 0; - static struct inc_cache *cache; - struct inc_cache *c; - EXEC SQL BEGIN DECLARE SECTION; - char tab[17], serv[17]; - EXEC SQL END DECLARE SECTION; - struct iupdate *iu; - - if (!inited) { - inited++; - - EXEC SQL DECLARE inc CURSOR FOR SELECT table_name, service FROM incremental; - EXEC SQL OPEN inc; - while (1) { - EXEC SQL FETCH inc INTO :tab, :serv; - if (sqlca.sqlcode != 0) break; - c = (struct inc_cache *)malloc(sizeof(struct inc_cache)); - c->next = cache; - c->table = strsave(strtrim(tab)); - c->service = strsave(strtrim(serv)); - cache = c; + static int inited = 0; + static struct inc_cache *cache; + struct inc_cache *c; + EXEC SQL BEGIN DECLARE SECTION; + char tab[17], serv[17]; + EXEC SQL END DECLARE SECTION; + struct iupdate *iu; + + if (!inited) + { + inited++; + + EXEC SQL DECLARE inc CURSOR FOR SELECT table_name, service + FROM incremental; + EXEC SQL OPEN inc; + while (1) + { + EXEC SQL FETCH inc INTO :tab, :serv; + if (sqlca.sqlcode) + break; + c = malloc(sizeof(struct inc_cache)); + c->next = cache; + c->table = strsave(strtrim(tab)); + c->service = strsave(strtrim(serv)); + cache = c; } - EXEC SQL CLOSE inc; - EXEC SQL COMMIT WORK; + EXEC SQL CLOSE inc; + EXEC SQL COMMIT WORK; } - while (sq_remove_data(incremental_sq, &iu)) { - for (c = cache; c; c = c->next) { - if (!strcmp(c->table, iu->table)) { - iu->service = c->service; - sq_save_data(incremental_exec, iu); + while (sq_remove_data(incremental_sq, &iu)) + { + for (c = cache; c; c = c->next) + { + if (!strcmp(c->table, iu->table)) + { + iu->service = c->service; + sq_save_data(incremental_exec, iu); } } } - if (inc_running == 0) - next_incremental(); + if (inc_running == 0) + next_incremental(); } void next_incremental(void) { - struct iupdate *iu; - char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ]; - int i; - sigset_t sigs; - - if (incremental_exec == NULL) - incremental_init(); - - if (sq_empty(incremental_exec) || - (inc_running && now - inc_started < INC_TIMEOUT)) - return; - - if (inc_running) - com_err(whoami, 0, "incremental timeout on pid %d", inc_pid); - - sq_remove_data(incremental_exec, &iu); - argv[1] = iu->table; - sprintf(cbefore, "%d", iu->beforec); - argv[2] = cbefore; - sprintf(cafter, "%d", iu->afterc); - argv[3] = cafter; - for (i = 0; i < iu->beforec; i++) - argv[4 + i] = iu->before[i]; - for (i = 0; i < iu->afterc; i++) - argv[4 + iu->beforec + i] = iu->after[i]; - - sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service); -#ifdef DEBUG - com_err(whoami, 0, "forking %s", prog); -#endif - argv[0] = prog; - argv[4 + iu->beforec + iu->afterc] = 0; - - sigemptyset(&sigs); - sigaddset(&sigs, SIGCHLD); - sigprocmask(SIG_BLOCK, &sigs, NULL); - inc_pid = vfork(); - switch (inc_pid) { + struct iupdate *iu; + char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ]; + int i; + sigset_t sigs; + + if (!incremental_exec) + incremental_init(); + + if (sq_empty(incremental_exec) || + (inc_running && now - inc_started < INC_TIMEOUT)) + return; + + if (inc_running) + com_err(whoami, 0, "incremental timeout on pid %d", inc_pid); + + sq_remove_data(incremental_exec, &iu); + argv[1] = iu->table; + sprintf(cbefore, "%d", iu->beforec); + argv[2] = cbefore; + sprintf(cafter, "%d", iu->afterc); + argv[3] = cafter; + for (i = 0; i < iu->beforec; i++) + argv[4 + i] = iu->before[i]; + for (i = 0; i < iu->afterc; i++) + argv[4 + iu->beforec + i] = iu->after[i]; + + sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service); + argv[0] = prog; + argv[4 + iu->beforec + iu->afterc] = 0; + + sigemptyset(&sigs); + sigaddset(&sigs, SIGCHLD); + sigprocmask(SIG_BLOCK, &sigs, NULL); + inc_pid = vfork(); + switch (inc_pid) + { case 0: - execv(prog, argv); - _exit(1); + execv(prog, argv); + _exit(1); case -1: - com_err(whoami, 0, "Failed to start incremental update"); - break; + com_err(whoami, 0, "Failed to start incremental update"); + break; default: - inc_running = 1; - inc_started = now; + inc_running = 1; + inc_started = now; } - sigprocmask(SIG_UNBLOCK, &sigs, NULL); - - free_argv(iu->before, iu->beforec); - free_argv(iu->after, iu->afterc); - free(iu); + sigprocmask(SIG_UNBLOCK, &sigs, NULL); + free_argv(iu->before, iu->beforec); + free_argv(iu->after, iu->afterc); + free(iu); } @@ -475,43 +448,43 @@ void next_incremental(void) void incremental_flush(void) { - struct iupdate *iu; + struct iupdate *iu; - while (sq_get_data(incremental_sq, &iu)) { - free_argv(iu->before, iu->beforec); - free_argv(iu->after, iu->afterc); - free(iu); + while (sq_get_data(incremental_sq, &iu)) + { + free_argv(iu->before, iu->beforec); + free_argv(iu->after, iu->afterc); + free(iu); } - sq_destroy(incremental_sq); - incremental_sq = sq_create(); + sq_destroy(incremental_sq); + incremental_sq = sq_create(); } -char **copy_argv(argv, argc) - char **argv; - int argc; +char **copy_argv(char **argv, int argc) { - char **ret = (char **)malloc(sizeof(char *) * argc); - while (--argc >= 0) - ret[argc] = strsave(strtrim(argv[argc])); - return(ret); + char **ret = malloc(sizeof(char *) * argc); + while (--argc >= 0) + ret[argc] = strsave(strtrim(argv[argc])); + return ret; } -void free_argv(argv, argc) - char **argv; - int argc; +void free_argv(char **argv, int argc) { - while (--argc >= 0) - free(argv[argc]); - free(argv); + while (--argc >= 0) + free(argv[argc]); + free(argv); } int table_num(char *name) { int i; - for(i = num_tables-1; i; i--) - if(!strcmp(table_name[i], name)) break; + for (i = num_tables - 1; i; i--) + { + if (!strcmp(table_name[i], name)) + break; + } return i; /* 0 = "none" if no match */ } diff --git a/server/mr_glue.c b/server/mr_glue.c index 6643a24c..7ad886f1 100644 --- a/server/mr_glue.c +++ b/server/mr_glue.c @@ -34,205 +34,188 @@ extern char *whoami; extern time_t now; void reapchild(); -mr_connect(server) -char *server; +int mr_connect(char *server) { - register int status; - extern int query_timeout; - struct sigaction action; - - if (already_connected) return MR_ALREADY_CONNECTED; - - initialize_sms_error_table(); - initialize_krb_error_table(); - memset((char *)&pseudo_client, 0, sizeof(pseudo_client)); /* XXX */ - - query_timeout = 0; - status = mr_open_database(); - if (!status) already_connected = 1; - - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaddset(&action.sa_mask, SIGCHLD); - action.sa_handler = reapchild; - if (sigaction(SIGCHLD, &action, NULL) < 0) { + register int status; + extern int query_timeout; + struct sigaction action; + + if (already_connected) + return MR_ALREADY_CONNECTED; + + initialize_sms_error_table(); + initialize_krb_error_table(); + memset(&pseudo_client, 0, sizeof(pseudo_client)); + + query_timeout = 0; + status = mr_open_database(); + if (!status) + already_connected = 1; + + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaddset(&action.sa_mask, SIGCHLD); + action.sa_handler = reapchild; + if (sigaction(SIGCHLD, &action, NULL) < 0) + { com_err(whoami, errno, "Unable to establish signal handlers."); exit(1); } - return status; + return status; } -mr_disconnect() +int mr_disconnect(void) { - CHECK_CONNECTED; - mr_close_database(); - already_connected = 0; - return 0; + CHECK_CONNECTED; + mr_close_database(); + already_connected = 0; + return 0; } -mr_noop() +int mr_noop(void) { - CHECK_CONNECTED; - return 0; + CHECK_CONNECTED; + return 0; } + /* * This routine is rather bogus, as it only fills in who you claim to be. */ -mr_auth(prog) -char *prog; +int mr_auth(char *prog) { - struct passwd *pw; - extern char *krb_realm; - char buf[1024], *strsave(); - - CHECK_CONNECTED; - pw = getpwuid(getuid()); - if (!pw) return (KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb); /* XXX hack (we - * need an extended - * error code table) - */ - strcpy(pseudo_client.kname.name, pw->pw_name); - krb_get_lrealm(pseudo_client.kname.realm, 1); - krb_realm = pseudo_client.kname.realm; - - strcpy(buf, pw->pw_name); - strcat(buf, "@"); - strcat(buf, pseudo_client.kname.realm); - strcpy(pseudo_client.clname, buf); - pseudo_client.users_id = 0; - name_to_id(pseudo_client.kname.name, USERS_TABLE, &pseudo_client.users_id); - pseudo_client.client_id = pseudo_client.users_id; - strncpy(pseudo_client.entity, prog, 8); - pseudo_client.args = (mr_params *) malloc(sizeof(mr_params)); - pseudo_client.args->mr_version_no = MR_VERSION_2; - return 0; + struct passwd *pw; + extern char *krb_realm; + char buf[1024], *strsave(); + + CHECK_CONNECTED; + pw = getpwuid(getuid()); + if (!pw) + return KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb; + strcpy(pseudo_client.kname.name, pw->pw_name); + krb_get_lrealm(pseudo_client.kname.realm, 1); + krb_realm = pseudo_client.kname.realm; + + strcpy(buf, pw->pw_name); + strcat(buf, "@"); + strcat(buf, pseudo_client.kname.realm); + strcpy(pseudo_client.clname, buf); + pseudo_client.users_id = 0; + name_to_id(pseudo_client.kname.name, USERS_TABLE, &pseudo_client.users_id); + pseudo_client.client_id = pseudo_client.users_id; + strncpy(pseudo_client.entity, prog, 8); + pseudo_client.args = malloc(sizeof(mr_params)); + pseudo_client.args->mr_version_no = MR_VERSION_2; + return 0; } struct hint { - int (*proc)(); - char *hint; + int (*proc)(); + char *hint; }; -callback(argc, argv, arg) -int argc; -char **argv; -struct hint *arg; +callback(int argc, char **argv, struct hint *arg) { - if (mr_trim_args(argc, argv) == MR_NO_MEM) { - com_err(whoami, MR_NO_MEM, "while trimmming args"); - } - (*arg->proc)(argc, argv, arg->hint); + if (mr_trim_args(argc, argv) == MR_NO_MEM) + com_err(whoami, MR_NO_MEM, "while trimmming args"); + (*arg->proc)(argc, argv, arg->hint); } -int mr_query(name, argc, argv, callproc, callarg) - char *name; /* Query name */ - int argc; /* Arg count */ - char **argv; /* Args */ - int (*callproc)(); /* Callback procedure */ - char *callarg; /* Callback argument */ +int mr_query(char *name, int argc, char **argv, int (*callproc)(), char *callarg) { - struct hint hints; - - time(&now); - hints.proc = callproc; - hints.hint = callarg; - next_incremental(); - return mr_process_query(&pseudo_client, name, argc, - mr_copy_args(argv, argc), callback, - (char *)&hints); - + struct hint hints; + + time(&now); + hints.proc = callproc; + hints.hint = callarg; + next_incremental(); + return mr_process_query(&pseudo_client, name, argc, + mr_copy_args(argv, argc), callback, + (char *)&hints); } -int mr_access(name, argc, argv) - char *name; /* Query name */ - int argc; /* Arg count */ - char **argv; /* Args */ +int mr_access(char *name, int argc, char **argv) { - time(&now); - return mr_check_access(&pseudo_client, name, argc, - mr_copy_args(argv, argc)); + time(&now); + return mr_check_access(&pseudo_client, name, argc, + mr_copy_args(argv, argc)); } -int mr_query_internal(argc, argv, callproc, callarg) - int argc; - char **argv; - int (*callproc)(); - char *callarg; +int mr_query_internal(int argc, char **argv, int (*callproc)(), char *callarg) { - struct hint hints; - - time(&now); - hints.proc = callproc; - hints.hint = callarg; - next_incremental(); - return mr_process_query(&pseudo_client, argv[0], argc-1, - mr_copy_args(argv+1, argc-1), callback, - (char *)&hints); + struct hint hints; + + time(&now); + hints.proc = callproc; + hints.hint = callarg; + next_incremental(); + return mr_process_query(&pseudo_client, argv[0], argc - 1, + mr_copy_args(argv + 1, argc - 1), callback, + (char *)&hints); } -int mr_access_internal(argc, argv) - int argc; - char **argv; +int mr_access_internal(int argc, char **argv) { - time(&now); - return mr_check_access(&pseudo_client, argv[0], argc-1, - mr_copy_args(argv+1, argc-1)); + time(&now); + return mr_check_access(&pseudo_client, argv[0], argc - 1, + mr_copy_args(argv + 1, argc - 1)); } -mr_shutdown(why) - char *why; +mr_shutdown(char *why) { - fprintf(stderr, "Sorry, not implemented\n"); + fprintf(stderr, "Sorry, not implemented\n"); } -/* trigger_dcm is also used as a followup routine to the +/* trigger_dcm is also used as a followup routine to the * set_server_host_override query, hence the two dummy arguments. */ struct query pseudo_query = { - "trigger_dcm", - "tdcm", + "trigger_dcm", + "tdcm", }; -trigger_dcm(dummy0, dummy1, cl) - int dummy0, dummy1; - client *cl; +int trigger_dcm(int dummy0, int dummy1, client *cl) { - register int pid, status; - char prog[128]; - - if (status = check_query_access(&pseudo_query, 0, cl)) - return(status); - - sprintf(prog, "%s/startdcm", BIN_DIR); - pid = vfork(); - switch (pid) { - case 0: - execl(prog, "startdcm", 0); - exit(1); - - case -1: - return(errno); - - default: - return(MR_SUCCESS); - } + register int pid, status; + char prog[128]; + + if ((status = check_query_access(&pseudo_query, 0, cl))) + return status; + + sprintf(prog, "%s/startdcm", BIN_DIR); + pid = vfork(); + switch (pid) + { + case 0: + execl(prog, "startdcm", 0); + exit(1); + + case -1: + return errno; + + default: + return MR_SUCCESS; + } } -void reapchild() +void reapchild(void) { - int status, pid; - - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { - if (pid == inc_pid) { - inc_running = 0; - next_incremental(); + int status, pid; + + while ((pid = waitpid(-1, &status, WNOHANG)) > 0) + { + if (pid == inc_pid) + { + inc_running = 0; + next_incremental(); } - if (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0) + if (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0) + { com_err(whoami, 0, "%d: child exits with signal %d status %d", pid, WTERMSIG(status), WEXITSTATUS(status)); + } } } diff --git a/server/mr_main.c b/server/mr_main.c index d5b13763..c203c32f 100644 --- a/server/mr_main.c +++ b/server/mr_main.c @@ -13,7 +13,7 @@ * * You are in a maze of twisty little finite automata, all different. * Let the reader beware. - * + * */ static char *rcsid_mr_main_c = "$Header$"; @@ -70,257 +70,275 @@ int new_connection(void); * making progress on current connections. */ -/*ARGSUSED*/ -int main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - int status, i; - time_t tardy; - char *port, *p; - extern char *database; - struct stat stbuf; - - whoami = argv[0]; - /* - * Error handler init. - */ - initialize_sms_error_table(); - initialize_krb_error_table(); - initialize_gdss_error_table(); - set_com_err_hook(mr_com_err); - setvbuf(stderr, NULL, _IOLBF, BUFSIZ); - - port = strchr(MOIRA_SERVER, ':') + 1; - - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-db") && i+1 < argc) { - database = argv[i+1]; - i++; - } else if (!strcmp(argv[i], "-p") && i+1 < argc) { - port = argv[i+1]; - i++; - } else { - com_err(whoami, 0, "Usage: moirad [-db database][-p port]"); - exit(1); - } - } - - /* - * GDB initialization. - */ - if(gdb_init() != 0) { - com_err(whoami, 0, "GDB initialization failed."); - exit(1); + int status, i; + time_t tardy; + char *port, *p; + extern char *database; + struct stat stbuf; + + whoami = argv[0]; + /* + * Error handler init. + */ + initialize_sms_error_table(); + initialize_krb_error_table(); + initialize_gdss_error_table(); + set_com_err_hook(mr_com_err); + setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + + port = strchr(MOIRA_SERVER, ':') + 1; + + for (i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "-db") && i + 1 < argc) + { + database = argv[i + 1]; + i++; } - gdb_debug(0); /* this can be patched, if necessary, to enable */ - /* GDB level debugging .. */ - krb_realm = malloc(REALM_SZ); - krb_get_lrealm(krb_realm, 1); - - /* - * Database initialization. Only init if database should be open. - */ - - if (stat(MOIRA_MOTD_FILE, &stbuf) != 0) { - if ((status = mr_open_database()) != 0) { - com_err(whoami, status, " when trying to open database."); - exit(1); - } - sanity_check_database(); - } else { - dormant = ASLEEP; - com_err(whoami, 0, "sleeping, not opening database"); + else if (!strcmp(argv[i], "-p") && i + 1 < argc) + { + port = argv[i + 1]; + i++; } - - sanity_check_queries(); - - /* - * Get moira server hostname for authentication - */ - if (gethostname(hostbuf, sizeof(hostbuf)) < 0) { - com_err(whoami, errno, "Unable to get local hostname"); + else + { + com_err(whoami, 0, "Usage: moirad [-db database][-p port]"); exit(1); } - host = canonicalize_hostname(strsave(hostbuf)); - for (p = host; *p && *p != '.'; p++) - if (isupper(*p)) - *p = tolower(*p); - *p = 0; - - /* - * Set up client array handler. - */ - nclients = 0; - clients = (client **) malloc(0); - - mr_setup_signals(); - - journal = fopen(JOURNAL, "a"); - if (journal == NULL) { - com_err(whoami, errno, " while opening journal file"); - exit(1); + } + + /* + * GDB initialization. + */ + if (gdb_init() != 0) + { + com_err(whoami, 0, "GDB initialization failed."); + exit(1); + } + gdb_debug(0); /* this can be patched, if necessary, to enable */ + /* GDB level debugging .. */ + krb_realm = malloc(REALM_SZ); + krb_get_lrealm(krb_realm, 1); + + /* + * Database initialization. Only init if database should be open. + */ + + if (stat(MOIRA_MOTD_FILE, &stbuf) != 0) + { + if ((status = mr_open_database())) + { + com_err(whoami, status, " when trying to open database."); + exit(1); } + sanity_check_database(); + } + else + { + dormant = ASLEEP; + com_err(whoami, 0, "sleeping, not opening database"); + } - /* - * Establish template connection. - */ - if ((status = do_listen(port)) != 0) { - com_err(whoami, status, - " while trying to create listening connection"); - exit(1); + sanity_check_queries(); + + /* + * Get moira server hostname for authentication + */ + if (gethostname(hostbuf, sizeof(hostbuf)) < 0) + { + com_err(whoami, errno, "Unable to get local hostname"); + exit(1); + } + host = canonicalize_hostname(strsave(hostbuf)); + for (p = host; *p && *p != '.'; p++) + { + if (isupper(*p)) + *p = tolower(*p); + } + *p = '\0'; + + /* + * Set up client array handler. + */ + nclients = 0; + clients = malloc(0); + + mr_setup_signals(); + + journal = fopen(JOURNAL, "a"); + if (!journal) + { + com_err(whoami, errno, " while opening journal file"); + exit(1); + } + + /* + * Establish template connection. + */ + if ((status = do_listen(port))) + { + com_err(whoami, status, " while trying to create listening connection"); + exit(1); + } + + op_list = create_list_of_operations(1, listenop); + + com_err(whoami, 0, "started (pid %d)", getpid()); + com_err(whoami, 0, rcsid_mr_main_c); + if (dormant != ASLEEP) + send_zgram("MOIRA", "server started"); + else + send_zgram("MOIRA", "server started, but database closed"); + + /* + * Run until shut down. + */ + while (!takedown) + { + register int i; + /* + * Block until something happens. + */ + if (dormant == SLEEPY) + { + mr_close_database(); + com_err(whoami, 0, "database closed"); + mr_setup_signals(); + send_zgram("MOIRA", "database closed"); + dormant = ASLEEP; + } + else if (dormant == GROGGY) + { + mr_open_database(); + com_err(whoami, 0, "database open"); + mr_setup_signals(); + send_zgram("MOIRA", "database open again"); + dormant = AWAKE; } - - op_list = create_list_of_operations(1, listenop); - - com_err(whoami, 0, "started (pid %d)", getpid()); - com_err(whoami, 0, rcsid_mr_main_c); - if (dormant != ASLEEP) - send_zgram("MOIRA", "server started"); - else - send_zgram("MOIRA", "server started, but database closed"); - - /* - * Run until shut down. - */ - while(!takedown) { - register int i; - /* - * Block until something happens. - */ -#ifdef notdef - com_err(whoami, 0, "tick"); -#endif notdef - if (dormant == SLEEPY) { - mr_close_database(); - com_err(whoami, 0, "database closed"); - mr_setup_signals(); - send_zgram("MOIRA", "database closed"); - dormant = ASLEEP; - } else if (dormant == GROGGY) { - mr_open_database(); - com_err(whoami, 0, "database open"); - mr_setup_signals(); - send_zgram("MOIRA", "database open again"); - dormant = AWAKE; - } - errno = 0; - status = op_select_any(op_list, 0, - (fd_set *)NULL, (fd_set *)NULL, - (fd_set *)NULL, (struct timeval *)NULL); - - if (status == -1) { - if (errno != EINTR) - com_err(whoami, errno, " error from op_select"); - if (!inc_running || now - inc_started > INC_TIMEOUT) - next_incremental(); - continue; - } else if (status != -2) { - com_err(whoami, 0, " wrong return from op_select_any"); - continue; - } - if (takedown) break; - time(&now); - if (!inc_running || now - inc_started > INC_TIMEOUT) - next_incremental(); -#ifdef notdef - fprintf(stderr, " tick\n"); -#endif notdef - /* - * Handle any new connections; this comes first so - * errno isn't tromped on. - */ - if (OP_DONE(listenop)) { - if (OP_STATUS(listenop) == OP_CANCELLED) { - if (errno == EWOULDBLOCK) { - do_reset_listen(); - } else { - static int count = 0; - com_err(whoami, errno, - " error (%d) on listen", count); - if (count++ > 10) - exit(1); - } - } else if ((status = new_connection()) != 0) { - com_err(whoami, errno, - " Error on listening operation."); - /* - * Sleep here to prevent hosing? - */ - } - /* if the new connection is our only connection, - * and the server is supposed to be down, then go - * down now. - */ - if ((dormant == AWAKE) && (nclients == 1) && - (stat(MOIRA_MOTD_FILE, &stbuf) == 0)) { - com_err(whoami, 0, "motd file exists, slumbertime"); - dormant = SLEEPY; - } - /* on new connection, if we are no longer supposed - * to be down, then wake up. - */ - if ((dormant == ASLEEP) && - (stat(MOIRA_MOTD_FILE, &stbuf) == -1) && - (errno == ENOENT)) { - com_err(whoami, 0, "motd file no longer exists, waking up"); - dormant = GROGGY; - } - - } - /* - * Handle any existing connections. - */ - tardy = now - 30*60; - - for (i=0; ipending_op)) { - cur_client->last_time_used = now; - do_client(cur_client); - } else if (clients[i]->last_time_used < tardy) { - com_err(whoami, 0, "Shutting down connection due to inactivity"); - shutdown(cur_client->con->in.fd, 2); - } - cur_client = NULL; - if (takedown) break; + errno = 0; + status = op_select_any(op_list, 0, NULL, NULL, NULL, NULL); + if (status == -1) + { + if (errno != EINTR) + com_err(whoami, errno, " error from op_select"); + if (!inc_running || now - inc_started > INC_TIMEOUT) + next_incremental(); + continue; + } + else if (status != -2) + { + com_err(whoami, 0, " wrong return from op_select_any"); + continue; + } + if (takedown) + break; + time(&now); + if (!inc_running || now - inc_started > INC_TIMEOUT) + next_incremental(); + + /* + * Handle any new connections; this comes first so + * errno isn't tromped on. + */ + if (OP_DONE(listenop)) + { + if (OP_STATUS(listenop) == OP_CANCELLED) + { + if (errno == EWOULDBLOCK) + do_reset_listen(); + else + { + static int count = 0; + com_err(whoami, errno, " error (%d) on listen", count); + if (count++ > 10) + exit(1); } + } + else if ((status = new_connection())) + { + com_err(whoami, errno, " Error on listening operation."); + /* + * Sleep here to prevent hosing? + */ + } + /* if the new connection is our only connection, + * and the server is supposed to be down, then go + * down now. + */ + if ((dormant == AWAKE) && (nclients == 1) && + (stat(MOIRA_MOTD_FILE, &stbuf) == 0)) + { + com_err(whoami, 0, "motd file exists, slumbertime"); + dormant = SLEEPY; + } + /* on new connection, if we are no longer supposed + * to be down, then wake up. + */ + if ((dormant == ASLEEP) && (stat(MOIRA_MOTD_FILE, &stbuf) == -1) && + (errno == ENOENT)) + { + com_err(whoami, 0, "motd file no longer exists, waking up"); + dormant = GROGGY; + } } - com_err(whoami, 0, "%s", takedown); - if (dormant != ASLEEP) mr_close_database(); - send_zgram("MOIRA", takedown); - return 0; + /* + * Handle any existing connections. + */ + tardy = now - 30 * 60; + + for (i = 0; i < nclients; i++) + { + cur_client = clients[i]; + if (OP_DONE(clients[i]->pending_op)) + { + cur_client->last_time_used = now; + do_client(cur_client); + } + else if (clients[i]->last_time_used < tardy) + { + com_err(whoami, 0, "Shutting down connection due to inactivity"); + shutdown(cur_client->con->in.fd, 2); + } + cur_client = NULL; + if (takedown) + break; + } + } + com_err(whoami, 0, "%s", takedown); + if (dormant != ASLEEP) + mr_close_database(); + send_zgram("MOIRA", takedown); + return 0; } /* * Set up the template connection and queue the first accept. */ -int do_listen(port) - char *port; +int do_listen(char *port) { - listencon = create_listening_connection(port); + listencon = create_listening_connection(port); - if (listencon == NULL) - return errno; + if (!listencon) + return errno; - listenop = create_operation(); - client_addrlen = sizeof(client_addr); + listenop = create_operation(); + client_addrlen = sizeof(client_addr); - start_accepting_client(listencon, listenop, &newconn, - (char *)&client_addr, - &client_addrlen, &client_tuple); - return 0; + start_accepting_client(listencon, listenop, &newconn, (char *)&client_addr, + &client_addrlen, &client_tuple); + return 0; } void do_reset_listen(void) { - client_addrlen = sizeof(client_addr); - start_accepting_client(listencon, listenop, &newconn, - (char *)&client_addr, - &client_addrlen, &client_tuple); + client_addrlen = sizeof(client_addr); + start_accepting_client(listencon, listenop, &newconn, (char *)&client_addr, + &client_addrlen, &client_tuple); } /* @@ -330,123 +348,114 @@ void do_reset_listen(void) */ int new_connection(void) { - register client *cp; - static counter = 0; - - /* - * Make sure there's been no error - */ - if(OP_STATUS(listenop) != OP_COMPLETE) { - return errno; - } - - if (newconn == NULL) { - return MR_NOT_CONNECTED; - } - - /* - * Set up the new connection and reply to the client - */ - cp = (client *)malloc(sizeof *cp); - memset(cp, 0, sizeof(*cp)); - cp->action = CL_ACCEPT; - cp->con = newconn; - cp->id = counter++; - cp->args = NULL; - cp->clname[0] = NULL; - cp->reply.mr_argv = NULL; - cp->first = NULL; - cp->last = NULL; - cp->last_time_used = now; - newconn = NULL; - - cp->pending_op = create_operation(); - reset_operation(cp->pending_op); - oplist_append(&op_list, cp->pending_op); - cur_client = cp; - - /* - * Add a new client to the array.. - */ - clist_append(cp); - - /* - * Let him know we heard him. - */ - start_replying_to_client(cp->pending_op, cp->con, GDB_ACCEPTED, - "", ""); - - cp->haddr = client_addr; - - /* - * Log new connection. - */ - - com_err(whoami, 0, "New connection from %s port %d (now %d client%s)", - inet_ntoa(cp->haddr.sin_addr), - (int)ntohs(cp->haddr.sin_port), - nclients, - nclients!=1?"s":""); - - /* - * Get ready to accept the next connection. - */ - reset_operation(listenop); - client_addrlen = sizeof(client_addr); - - start_accepting_client(listencon, listenop, &newconn, - (char *)&client_addr, - &client_addrlen, &client_tuple); - return 0; + register client *cp; + static counter = 0; + + /* + * Make sure there's been no error + */ + if (OP_STATUS(listenop) != OP_COMPLETE) + return errno; + + if (!newconn) + return MR_NOT_CONNECTED; + + /* + * Set up the new connection and reply to the client + */ + cp = malloc(sizeof(client)); + memset(cp, 0, sizeof(*cp)); + cp->action = CL_ACCEPT; + cp->con = newconn; + cp->id = counter++; + cp->args = NULL; + cp->clname[0] = NULL; + cp->reply.mr_argv = NULL; + cp->first = NULL; + cp->last = NULL; + cp->last_time_used = now; + newconn = NULL; + + cp->pending_op = create_operation(); + reset_operation(cp->pending_op); + oplist_append(&op_list, cp->pending_op); + cur_client = cp; + + /* + * Add a new client to the array.. + */ + clist_append(cp); + + /* + * Let him know we heard him. + */ + start_replying_to_client(cp->pending_op, cp->con, GDB_ACCEPTED, "", ""); + + cp->haddr = client_addr; + + /* + * Log new connection. + */ + com_err(whoami, 0, "New connection from %s port %d (now %d client%s)", + inet_ntoa(cp->haddr.sin_addr), (int)ntohs(cp->haddr.sin_port), + nclients, nclients != 1 ? "s" : ""); + + /* + * Get ready to accept the next connection. + */ + reset_operation(listenop); + client_addrlen = sizeof(client_addr); + + start_accepting_client(listencon, listenop, &newconn, (char *)&client_addr, + &client_addrlen, &client_tuple); + return 0; } /* * Add a new client to the known clients. */ -void clist_append(cp) - client *cp; -{ - client **clients_n; - - nclients++; - clients_n = (client **)malloc - ((unsigned)(nclients * sizeof(client *))); - memcpy((char *)clients_n, (char *)clients, (nclients-1)*sizeof(cp)); - clients_n[nclients-1] = cp; - free((char *)clients); - clients = clients_n; - clients_n = NULL; +void clist_append(client *cp) +{ + client **clients_n; + + nclients++; + clients_n = malloc(nclients * sizeof(client *)); + memcpy(clients_n, clients, (nclients - 1) * sizeof(cp)); + clients_n[nclients - 1] = cp; + free(clients); + clients = clients_n; + clients_n = NULL; } - -void clist_delete(cp) - client *cp; + +void clist_delete(client *cp) { - client **clients_n, **scpp, **dcpp; /* source and dest client */ - /* ptr ptr */ - - int found_it = 0; - - clients_n = (client **)malloc - ((unsigned)((nclients - 1)* sizeof(client *))); - for (scpp = clients, dcpp = clients_n; scpp < clients+nclients; ) { - if (*scpp != cp) { - *dcpp++ = *scpp++; - } else { - scpp++; - if (found_it) abort(); - found_it = 1; - } + client **clients_n, **scpp, **dcpp; /* source and dest client ptr ptr */ + + int found_it = 0; + + clients_n = malloc((nclients - 1) * sizeof(client *)); + for (scpp = clients, dcpp = clients_n; scpp < clients + nclients; ) + { + if (*scpp != cp) + *dcpp++ = *scpp++; + else + { + scpp++; + if (found_it) + abort(); + found_it = 1; } - --nclients; - free((char *)clients); - clients = clients_n; - clients_n = NULL; - oplist_delete(op_list, cp->pending_op); - reset_operation(cp->pending_op); - delete_operation(cp->pending_op); - sever_connection(cp->con); - free((char *)cp); + } + --nclients; + free(clients); + clients = clients_n; + clients_n = NULL; + oplist_delete(op_list, cp->pending_op); + reset_operation(cp->pending_op); + delete_operation(cp->pending_op); + sever_connection(cp->con); + free(cp); } /* @@ -456,131 +465,128 @@ void clist_delete(cp) * cases it won't have to copy the array. */ -void oplist_append(oplp, op) - LIST_OF_OPERATIONS *oplp; - OPERATION op; +void oplist_append(LIST_OF_OPERATIONS *oplp, OPERATION op) { - int count = (*oplp)->count+1; - LIST_OF_OPERATIONS newlist = (LIST_OF_OPERATIONS) - db_alloc(size_of_list_of_operations(count)); - memcpy((char *)newlist, (char *)(*oplp), - size_of_list_of_operations((*oplp)->count)); - newlist->count++; - newlist->op[count-1] = op; - db_free((char *)(*oplp), size_of_list_of_operations(count-1)); - (*oplp) = newlist; + int count = (*oplp)->count + 1; + LIST_OF_OPERATIONS newlist = (LIST_OF_OPERATIONS) + db_alloc(size_of_list_of_operations(count)); + memcpy(newlist, *oplp, size_of_list_of_operations((*oplp)->count)); + newlist->count++; + newlist->op[count - 1] = op; + db_free(*oplp, size_of_list_of_operations(count - 1)); + *oplp = newlist; } - -void oplist_delete(oplp, op) - LIST_OF_OPERATIONS oplp; - OPERATION op; +void oplist_delete(LIST_OF_OPERATIONS oplp, OPERATION op) { - register OPERATION *s; - register int c; - - for (s = oplp->op, c=oplp->count; c; --c, ++s) { - if (*s == op) { - while (c > 0) { - *s = *(s+1); - ++s; - --c; - } - oplp->count--; - return; - } + register OPERATION *s; + register int c; + + for (s = oplp->op, c = oplp->count; c; --c, ++s) + { + if (*s == op) + { + while (c > 0) + { + *s = *(s + 1); + ++s; + --c; + } + oplp->count--; + return; } - abort(); + } + abort(); } -void reapchild(x) - int x; +void reapchild(int x) { - int status, pid; - - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { -#ifdef INCR_DEBUG - com_err(whoami, 0, "Reaping %d (inc_pid=%d, inc_running=%d)", - pid, inc_pid, inc_running); -#endif - if (pid == inc_pid) - inc_running = 0; - if (!takedown && (WTERMSIG(status)!= 0 || WEXITSTATUS(status)!= 0)) - com_err(whoami, 0, "%d: child exits with signal %d status %d", - pid, WTERMSIG(status), WEXITSTATUS(status)); + int status, pid; + + while ((pid = waitpid(-1, &status, WNOHANG)) > 0) + { + if (pid == inc_pid) + inc_running = 0; + if (!takedown && (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0)) + com_err(whoami, 0, "%d: child exits with signal %d status %d", + pid, WTERMSIG(status), WEXITSTATUS(status)); } } -void godormant(x) - int x; +void godormant(int x) { - switch (dormant) { + switch (dormant) + { case AWAKE: case GROGGY: - com_err(whoami, 0, "requested to go dormant"); - break; + com_err(whoami, 0, "requested to go dormant"); + break; case ASLEEP: - com_err(whoami, 0, "already asleep"); - break; + com_err(whoami, 0, "already asleep"); + break; case SLEEPY: - break; + break; } - dormant = SLEEPY; + dormant = SLEEPY; } -void gowakeup(x) - int x; +void gowakeup(int x) { - switch (dormant) { + switch (dormant) + { case ASLEEP: case SLEEPY: - com_err(whoami, 0, "Good morning"); - break; + com_err(whoami, 0, "Good morning"); + break; case AWAKE: - com_err(whoami, 0, "already awake"); - break; + com_err(whoami, 0, "already awake"); + break; case GROGGY: - break; + break; } - dormant = GROGGY; + dormant = GROGGY; } - + void mr_setup_signals(void) { - struct sigaction action; + struct sigaction action; + + action.sa_flags = 0; + sigemptyset(&action.sa_mask); - action.sa_flags = 0; - sigemptyset(&action.sa_mask); + /* There should probably be a few more of these. */ - /* There should probably be a few more of these. */ - - action.sa_handler = sigshut; - if ((sigaction(SIGTERM, &action, NULL) < 0) || - (sigaction(SIGINT, &action, NULL) < 0) || - (sigaction(SIGHUP, &action, NULL) < 0)) { + action.sa_handler = sigshut; + if ((sigaction(SIGTERM, &action, NULL) < 0) || + (sigaction(SIGINT, &action, NULL) < 0) || + (sigaction(SIGHUP, &action, NULL) < 0)) + { com_err(whoami, errno, "Unable to establish signal handlers."); exit(1); } - action.sa_handler = godormant; - if (sigaction(SIGUSR1, &action, NULL) < 0) { + action.sa_handler = godormant; + if (sigaction(SIGUSR1, &action, NULL) < 0) + { com_err(whoami, errno, "Unable to establish signal handlers."); exit(1); } - action.sa_handler = gowakeup; - if (sigaction(SIGUSR2, &action, NULL) < 0) { + action.sa_handler = gowakeup; + if (sigaction(SIGUSR2, &action, NULL) < 0) + { com_err(whoami, errno, "Unable to establish signal handlers."); exit(1); } - action.sa_handler = reapchild; - sigaddset(&action.sa_mask, SIGCHLD); - if (sigaction(SIGCHLD, &action, NULL) < 0) { + action.sa_handler = reapchild; + sigaddset(&action.sa_mask, SIGCHLD); + if (sigaction(SIGCHLD, &action, NULL) < 0) + { com_err(whoami, errno, "Unable to establish signal handlers."); exit(1); } diff --git a/server/mr_sauth.c b/server/mr_sauth.c index f5f8b761..d57cd624 100644 --- a/server/mr_sauth.c +++ b/server/mr_sauth.c @@ -38,95 +38,105 @@ replay_cache *rcache = NULL; * Handle a MOIRA_AUTH RPC request. * * argv[0] is a kerberos authenticator. Decompose it, and if - * successful, store the name the user authenticated to in + * successful, store the name the user authenticated to in * cl->cl_name. */ -void -do_auth(cl) - client *cl; +void do_auth(client *cl) { - KTEXT_ST auth; - AUTH_DAT ad; - int status, ok; - extern int errno; - replay_cache *rc, *rcnew; - time_t now; - - auth.length = cl->args->mr_argl[0]; - memcpy((char *)auth.dat, cl->args->mr_argv[0], auth.length); - auth.mbz = 0; - - if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, - cl->haddr.sin_addr.s_addr, &ad, "")) != 0) { - status += ERROR_TABLE_BASE_krb; - cl->reply.mr_status = status; - if (log_flags & LOG_RES) - com_err(whoami, status, " (authentication failed)"); - return; - } - - if(!rcache) { - rcache = (replay_cache*)malloc(sizeof(replay_cache)); - memset(rcache, 0, sizeof(replay_cache)); - } - - /* scan replay cache */ - for (rc = rcache->next; rc; rc = rc->next) { - if(auth.length == rc->auth.length && - !memcmp(&(auth.dat), &(rc->auth.dat), auth.length)) { - com_err(whoami, 0, "Authenticator replay from %s using authenticator for %s", - inet_ntoa(cl->haddr.sin_addr), - kname_unparse(ad.pname, ad.pinst, ad.prealm)); - com_err(whoami, KE_RD_AP_REPEAT, " (authentication failed)"); - cl->reply.mr_status = KE_RD_AP_REPEAT; - return; - } - } - - /* add new entry */ - time(&now); - rcnew = (replay_cache*)malloc(sizeof(replay_cache)); - memcpy(&(rcnew->auth), &auth, sizeof(KTEXT_ST)); - rcnew->expires = now + 2*CLOCK_SKEW; - rcnew->next = rcache->next; - rcache->next = rcnew; - - /* clean cache */ - for (rc = rcnew; rc->next; ) { - if(rc->next->expires < now) { - rcnew = rc->next; - rc->next = rc->next->next; - free(rcnew); - } else rc = rc->next; + KTEXT_ST auth; + AUTH_DAT ad; + int status, ok; + extern int errno; + replay_cache *rc, *rcnew; + time_t now; + + auth.length = cl->args->mr_argl[0]; + memcpy(auth.dat, cl->args->mr_argv[0], auth.length); + auth.mbz = 0; + + if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, + cl->haddr.sin_addr.s_addr, &ad, ""))) + { + status += ERROR_TABLE_BASE_krb; + cl->reply.mr_status = status; + if (log_flags & LOG_RES) + com_err(whoami, status, " (authentication failed)"); + return; + } + + if (!rcache) + { + rcache = malloc(sizeof(replay_cache)); + memset(rcache, 0, sizeof(replay_cache)); + } + + /* scan replay cache */ + for (rc = rcache->next; rc; rc = rc->next) + { + if (auth.length == rc->auth.length && + !memcmp(&(auth.dat), &(rc->auth.dat), auth.length)) + { + com_err(whoami, 0, + "Authenticator replay from %s using authenticator for %s", + inet_ntoa(cl->haddr.sin_addr), + kname_unparse(ad.pname, ad.pinst, ad.prealm)); + com_err(whoami, KE_RD_AP_REPEAT, " (authentication failed)"); + cl->reply.mr_status = KE_RD_AP_REPEAT; + return; } - - memcpy(cl->kname.name, ad.pname, ANAME_SZ); - memcpy(cl->kname.inst, ad.pinst, INST_SZ); - memcpy(cl->kname.realm, ad.prealm, REALM_SZ); - strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm)); - - if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm)) - ok = 1; - else - ok = 0; - /* this is in a separate function because it accesses the database */ - status = set_krb_mapping(cl->clname, ad.pname, ok, - &cl->client_id, &cl->users_id); - - if (cl->args->mr_version_no == MR_VERSION_2) { - strncpy(cl->entity, cl->args->mr_argv[1], 8); - cl->entity[8] = 0; - } else { - strcpy(cl->entity, "???"); + } + + /* add new entry */ + time(&now); + rcnew = malloc(sizeof(replay_cache)); + memcpy(&(rcnew->auth), &auth, sizeof(KTEXT_ST)); + rcnew->expires = now + 2 * CLOCK_SKEW; + rcnew->next = rcache->next; + rcache->next = rcnew; + + /* clean cache */ + for (rc = rcnew; rc->next; ) + { + if (rc->next->expires < now) + { + rcnew = rc->next; + rc->next = rc->next->next; + free(rcnew); } - memset(&ad, 0, sizeof(ad)); /* Clean up session key, etc. */ - - if (log_flags & LOG_RES) - com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d", - cl->clname, cl->entity, cl->users_id, cl->client_id); - if (status != MR_SUCCESS) - cl->reply.mr_status = status; - else if (cl->users_id == 0) - cl->reply.mr_status = MR_USER_AUTH; + else + rc = rc->next; + } + + memcpy(cl->kname.name, ad.pname, ANAME_SZ); + memcpy(cl->kname.inst, ad.pinst, INST_SZ); + memcpy(cl->kname.realm, ad.prealm, REALM_SZ); + strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm)); + + if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm)) + ok = 1; + else + ok = 0; + /* this is in a separate function because it accesses the database */ + status = set_krb_mapping(cl->clname, ad.pname, ok, + &cl->client_id, &cl->users_id); + + if (cl->args->mr_version_no == MR_VERSION_2) + { + strncpy(cl->entity, cl->args->mr_argv[1], 8); + cl->entity[8] = 0; + } + else + strcpy(cl->entity, "???"); + memset(&ad, 0, sizeof(ad)); /* Clean up session key, etc. */ + + if (log_flags & LOG_RES) + { + com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d", + cl->clname, cl->entity, cl->users_id, cl->client_id); + } + if (status != MR_SUCCESS) + cl->reply.mr_status = status; + else if (cl->users_id == 0) + cl->reply.mr_status = MR_USER_AUTH; } diff --git a/server/mr_scall.c b/server/mr_scall.c index 9a72909c..91e8157f 100644 --- a/server/mr_scall.c +++ b/server/mr_scall.c @@ -41,348 +41,343 @@ int max_row_count = 4096; /* * Welcome to the (finite state) machine (highest level). */ -void -do_client(cp) - client *cp; +void do_client(client *cp) { - struct stat stbuf; - - free_rtn_tuples(cp); - if (OP_STATUS(cp->pending_op) == OP_CANCELLED) { - com_err(whoami, 0, "Closed connection (now %d client%s, %d new queries, %d old)", - nclients-1, - nclients!=2?"s":"", - newqueries, - oldqueries); - clist_delete(cp); - /* if we no longer have any clients, and we're supposed to - * go down, then go down now. - */ - if ((dormant == AWAKE) && (nclients == 0) && - (stat(MOIRA_MOTD_FILE, &stbuf) == 0)) { - com_err(whoami, 0, "motd file exists, slumbertime"); - dormant = SLEEPY; - } - return; + struct stat stbuf; + + free_rtn_tuples(cp); + if (OP_STATUS(cp->pending_op) == OP_CANCELLED) + { + com_err(whoami, 0, + "Closed connection (now %d client%s, %d new queries, %d old)", + nclients - 1, nclients != 2 ? "s" : "", newqueries, oldqueries); + clist_delete(cp); + /* if we no longer have any clients, and we're supposed to + * go down, then go down now. + */ + if ((dormant == AWAKE) && (nclients == 0) && + (stat(MOIRA_MOTD_FILE, &stbuf) == 0)) + { + com_err(whoami, 0, "motd file exists, slumbertime"); + dormant = SLEEPY; } - switch (cp->action) { - case CL_ACCEPT: - case CL_SEND: - /* Start recieving next request */ - initialize_operation(cp->pending_op, mr_start_recv, - (char *)&cp->args, (int (*)())NULL); - queue_operation(cp->con, CON_INPUT, cp->pending_op); - cp->action = CL_RECEIVE; - break; - case CL_RECEIVE: - /* Data is here. Process it & start it heading back */ - do_call(cp); /* This may block for a while. */ - mr_destroy_reply(cp->args); - cp->args = NULL; - initialize_operation(cp->pending_op, mr_start_send, - (char *)&cp->reply, (int (*)())NULL); - queue_operation(cp->con, CON_OUTPUT, cp->pending_op); - cp->action = CL_SEND; - break; - } -} + return; + } + switch (cp->action) + { + case CL_ACCEPT: + case CL_SEND: + /* Start recieving next request */ + initialize_operation(cp->pending_op, mr_start_recv, + (char *)&cp->args, NULL); + queue_operation(cp->con, CON_INPUT, cp->pending_op); + cp->action = CL_RECEIVE; + break; + case CL_RECEIVE: + /* Data is here. Process it & start it heading back */ + do_call(cp); /* This may block for a while. */ + mr_destroy_reply(cp->args); + cp->args = NULL; + initialize_operation(cp->pending_op, mr_start_send, + (char *)&cp->reply, NULL); + queue_operation(cp->con, CON_OUTPUT, cp->pending_op); + cp->action = CL_SEND; + break; + } +} char *procnames[] = { - "noop", - "auth", - "shutdown", - "query", - "access", - "dcm", - "motd", + "noop", + "auth", + "shutdown", + "query", + "access", + "dcm", + "motd", }; -void -do_call(cl) - client *cl; +void do_call(client *cl) { - int pn; - cl->reply.mr_argc = 0; - cl->reply.mr_status = 0; - cl->reply.mr_version_no = cl->args->mr_version_no; - if (((pn = cl->args->mr_procno) < 0) || - (pn > MR_MAX_PROC)) { - com_err(whoami, 0, "procno out of range"); - cl->reply.mr_status = MR_UNKNOWN_PROC; - return; - } - if (log_flags & LOG_ARGS) - log_args(procnames[pn], cl->args->mr_version_no, - cl->args->mr_argc, cl->args->mr_argv); - else if (log_flags & LOG_REQUESTS) - com_err(whoami, 0, "%s", procnames[pn]); - - if ((dormant == ASLEEP || dormant == GROGGY) && - pn != MR_NOOP && pn != MR_MOTD) { - cl->reply.mr_status = MR_DOWN; - if (log_flags & LOG_RES) - com_err(whoami, MR_DOWN, "(query refused)"); - return; - } - - /* make sure this gets cleared before every operation */ - dbms_errno = 0; - - switch(pn) { - case MR_NOOP: - cl->reply.mr_status = 0; - return; - - case MR_AUTH: - do_auth(cl); - return; - - case MR_QUERY: - do_retr(cl); - return; - - case MR_ACCESS: - do_access(cl); - return; - - case MR_SHUTDOWN: - do_shutdown(cl); - return; - - case MR_DO_UPDATE: - trigger_dcm(0, 0, cl); - return; - - case MR_MOTD: - get_motd(cl); - return; - } + int pn; + cl->reply.mr_argc = 0; + cl->reply.mr_status = 0; + cl->reply.mr_version_no = cl->args->mr_version_no; + if (((pn = cl->args->mr_procno) < 0) || (pn > MR_MAX_PROC)) + { + com_err(whoami, 0, "procno out of range"); + cl->reply.mr_status = MR_UNKNOWN_PROC; + return; + } + if (log_flags & LOG_ARGS) + { + log_args(procnames[pn], cl->args->mr_version_no, + cl->args->mr_argc, cl->args->mr_argv); + } + else if (log_flags & LOG_REQUESTS) + com_err(whoami, 0, "%s", procnames[pn]); + + if ((dormant == ASLEEP || dormant == GROGGY) && + pn != MR_NOOP && pn != MR_MOTD) + { + cl->reply.mr_status = MR_DOWN; + if (log_flags & LOG_RES) + com_err(whoami, MR_DOWN, "(query refused)"); + return; + } + + /* make sure this gets cleared before every operation */ + dbms_errno = 0; + + switch (pn) + { + case MR_NOOP: + cl->reply.mr_status = 0; + return; + + case MR_AUTH: + do_auth(cl); + return; + + case MR_QUERY: + do_retr(cl); + return; + + case MR_ACCESS: + do_access(cl); + return; + + case MR_SHUTDOWN: + do_shutdown(cl); + return; + + case MR_DO_UPDATE: + trigger_dcm(0, 0, cl); + return; + + case MR_MOTD: + get_motd(cl); + return; + } } -free_rtn_tuples(cp) - client *cp; +free_rtn_tuples(client *cp) { - register returned_tuples *temp; - for (temp=cp->first; temp && OP_DONE(temp->op); ) { - register returned_tuples *t1=temp; - temp = t1->next; - if (t1 == cp->last) cp->last = NULL; - - mr_destroy_reply(t1->retval); - delete_operation(t1->op); - free(t1); - } - cp->first = temp; -} + register returned_tuples *temp; + for (temp = cp->first; temp && OP_DONE(temp->op); ) + { + register returned_tuples *t1 = temp; + temp = t1->next; + if (t1 == cp->last) + cp->last = NULL; + + mr_destroy_reply(t1->retval); + delete_operation(t1->op); + free(t1); + } + cp->first = temp; +} -retr_callback(argc, argv, p_cp) - register int argc; - register char **argv; - char *p_cp; +retr_callback(register int argc, register char **argv, char *p_cp) { - register client *cp = (client *)p_cp; - mr_params *arg_tmp; - returned_tuples *tp; - OPERATION op_tmp; - register char **nargv; - register int i; - - if (row_count++ >= max_row_count) { - dbms_errno = mr_errcode = MR_NO_MEM; - return; - } - - /* - * This takes too much advantage of the fact that - * serialization of the data happens during the queue operation. - */ - arg_tmp = (mr_params *)db_alloc(sizeof(mr_params)); - tp = (returned_tuples *)db_alloc(sizeof(returned_tuples)); - nargv = (char **)malloc(argc * sizeof(char *)); - - op_tmp = create_operation(); - - if (mr_trim_args(argc, argv) == MR_NO_MEM) { - com_err(whoami, MR_NO_MEM, "while trimming args"); - } - if (log_flags & LOG_RESP) - log_args("return: ", cp->args->mr_version_no, argc, argv); - - tp->op = op_tmp; - tp->retval = arg_tmp; - tp->next = NULL; - - arg_tmp->mr_status = MR_MORE_DATA; - arg_tmp->mr_version_no = cp->args->mr_version_no; - arg_tmp->mr_argc = argc; - arg_tmp->mr_argv = nargv; - for (i = 0; i < argc; i++) { - register int len = strlen(argv[i]) + 1; - nargv[i] = malloc(len); - memcpy(nargv[i], argv[i], len); - } - arg_tmp->mr_flattened = (char *)NULL; - arg_tmp->mr_argl = (int *)NULL; - - if (cp->last) { - cp->last->next = tp; - cp->last = tp; - } else { - cp->last = cp->first = tp; - } - - reset_operation(op_tmp); - initialize_operation(op_tmp, mr_start_send, (char *)arg_tmp, - (int (*)())NULL); - queue_operation(cp->con, CON_OUTPUT, op_tmp); + register client *cp = (client *)p_cp; + mr_params *arg_tmp; + returned_tuples *tp; + OPERATION op_tmp; + register char **nargv; + register int i; + + if (row_count++ >= max_row_count) + { + dbms_errno = mr_errcode = MR_NO_MEM; + return; + } + + /* + * This takes too much advantage of the fact that + * serialization of the data happens during the queue operation. + */ + arg_tmp = db_alloc(sizeof(mr_params)); + tp = db_alloc(sizeof(returned_tuples)); + nargv = malloc(argc * sizeof(char *)); + + op_tmp = create_operation(); + + if (mr_trim_args(argc, argv) == MR_NO_MEM) + com_err(whoami, MR_NO_MEM, "while trimming args"); + if (log_flags & LOG_RESP) + log_args("return: ", cp->args->mr_version_no, argc, argv); + + tp->op = op_tmp; + tp->retval = arg_tmp; + tp->next = NULL; + + arg_tmp->mr_status = MR_MORE_DATA; + arg_tmp->mr_version_no = cp->args->mr_version_no; + arg_tmp->mr_argc = argc; + arg_tmp->mr_argv = nargv; + for (i = 0; i < argc; i++) + { + register int len = strlen(argv[i]) + 1; + nargv[i] = malloc(len); + memcpy(nargv[i], argv[i], len); + } + arg_tmp->mr_flattened = NULL; + arg_tmp->mr_argl = NULL; + + if (cp->last) + { + cp->last->next = tp; + cp->last = tp; + } else + cp->last = cp->first = tp; + + reset_operation(op_tmp); + initialize_operation(op_tmp, mr_start_send, (char *)arg_tmp, NULL); + queue_operation(cp->con, CON_OUTPUT, op_tmp); } -list_users(callbk, callarg) - int (*callbk)(); - char *callarg; +int list_users(int (*callbk)(), char *callarg) { - char *argv[6]; - char buf[30]; - char buf1[30]; - int i; - extern client **clients; - char *cp; - char *ctime(); - - for (i = 0; i < nclients; i++) { - register client *cl = clients[i]; - if (cl->clname) - argv[0] = cl->clname; - else argv[0] = "unauthenticated"; - - argv[1] = inet_ntoa(cl->haddr.sin_addr); - argv[2] = buf; - sprintf(buf, "port %d", ntohs(cl->haddr.sin_port)); - argv[3] = ctime(&cl->last_time_used); - cp = strchr(argv[3], '\n'); - if (cp) *cp = '\0'; - argv[4] = buf1; - sprintf(buf1, "[#%d]", cl->id); - (*callbk)(5, argv, callarg); - } - return 0; + char *argv[6]; + char buf[30]; + char buf1[30]; + int i; + extern client **clients; + char *cp; + char *ctime(); + + for (i = 0; i < nclients; i++) + { + register client *cl = clients[i]; + if (cl->clname) + argv[0] = cl->clname; + else argv[0] = "unauthenticated"; + + argv[1] = inet_ntoa(cl->haddr.sin_addr); + argv[2] = buf; + sprintf(buf, "port %d", ntohs(cl->haddr.sin_port)); + argv[3] = ctime(&cl->last_time_used); + cp = strchr(argv[3], '\n'); + if (cp) + *cp = '\0'; + argv[4] = buf1; + sprintf(buf1, "[#%d]", cl->id); + (*callbk)(5, argv, callarg); + } + return 0; } -do_retr(cl) - register client *cl; +do_retr(register client *cl) { - register char *queryname; - - cl->reply.mr_argc = 0; - cl->reply.mr_status = 0; - row_count = 0; - - if (cl->args->mr_argc < 1) { - cl->reply.mr_status = MR_ARGS; - com_err(whoami, MR_ARGS, "got nameless query"); - return; - } - queryname = cl->args->mr_argv[0]; - - if (cl->args->mr_version_no == MR_VERSION_2) - newqueries++; - else - oldqueries++; - - if (strcmp(queryname, "_list_users") == 0) - cl->reply.mr_status = list_users(retr_callback, (char *)cl); - else { - cl->reply.mr_status = - mr_process_query(cl, - queryname, - cl->args->mr_argc-1, - cl->args->mr_argv+1, - retr_callback, - (char *)cl); - } - if (row_count >= max_row_count) { - critical_alert("moirad", "attempted query %s with %d rows\n", - queryname, row_count); - } - - if (log_flags & LOG_RES) - com_err(whoami, 0, "Query complete."); + register char *queryname; + + cl->reply.mr_argc = 0; + cl->reply.mr_status = 0; + row_count = 0; + + if (cl->args->mr_argc < 1) + { + cl->reply.mr_status = MR_ARGS; + com_err(whoami, MR_ARGS, "got nameless query"); + return; + } + queryname = cl->args->mr_argv[0]; + + if (cl->args->mr_version_no == MR_VERSION_2) + newqueries++; + else + oldqueries++; + + if (!strcmp(queryname, "_list_users")) + cl->reply.mr_status = list_users(retr_callback, (char *)cl); + else + { + cl->reply.mr_status = mr_process_query(cl, queryname, + cl->args->mr_argc - 1, + cl->args->mr_argv + 1, + retr_callback, (char *)cl); + } + if (row_count >= max_row_count) + { + critical_alert("moirad", "attempted query %s with %d rows\n", + queryname, row_count); + } + + if (log_flags & LOG_RES) + com_err(whoami, 0, "Query complete."); } -do_access(cl) - client *cl; +do_access(client *cl) { - if (cl->args->mr_argc < 1) { - cl->reply.mr_status = MR_ARGS; - com_err(whoami, MR_ARGS, "got nameless access"); - return; - } - cl->reply.mr_argc = 0; - - cl->reply.mr_status = - mr_check_access(cl, - cl->args->mr_argv[0], - cl->args->mr_argc-1, - cl->args->mr_argv+1); - - com_err(whoami, 0, "Access check complete."); + if (cl->args->mr_argc < 1) + { + cl->reply.mr_status = MR_ARGS; + com_err(whoami, MR_ARGS, "got nameless access"); + return; + } + cl->reply.mr_argc = 0; + + cl->reply.mr_status = mr_check_access(cl, cl->args->mr_argv[0], + cl->args->mr_argc - 1, + cl->args->mr_argv + 1); + + com_err(whoami, 0, "Access check complete."); } -/* trigger_dcm is also used as a followup routine to the +/* trigger_dcm is also used as a followup routine to the * set_server_host_override query, hence the two dummy arguments. */ struct query pseudo_query = { - "trigger_dcm", - "tdcm", + "trigger_dcm", + "tdcm", }; -trigger_dcm(dummy0, dummy1, cl) - int dummy0, dummy1; - client *cl; +int trigger_dcm(int dummy0, int dummy1, client *cl) { - register int pid; - char prog[128]; - - cl->reply.mr_argc = 0; - - if (cl->reply.mr_status = check_query_access(&pseudo_query, 0, cl) ) - return(cl->reply.mr_status); - - sprintf(prog, "%s/startdcm", BIN_DIR); - pid = vfork(); - switch (pid) { - case 0: - execl(prog, "startdcm", 0); - exit(1); - - case -1: - cl->reply.mr_status = errno; - return(0); - - default: - return(0); - } + register int pid; + char prog[128]; + + cl->reply.mr_argc = 0; + + if ((cl->reply.mr_status = check_query_access(&pseudo_query, 0, cl))) + return cl->reply.mr_status; + + sprintf(prog, "%s/startdcm", BIN_DIR); + pid = vfork(); + switch (pid) + { + case 0: + execl(prog, "startdcm", 0); + exit(1); + + case -1: + cl->reply.mr_status = errno; + return 0; + + default: + return 0; + } } -get_motd(cl) -client *cl; +get_motd(client *cl) { - int motd, len; - char buffer[1024]; - char *arg[1]; - - arg[0] = buffer; - cl->reply.mr_status = 0; - motd = open(MOIRA_MOTD_FILE, 0, O_RDONLY); - if (motd < 0) return; - len = read(motd, buffer, sizeof(buffer) - 1); - close(motd); - buffer[len] = 0; - row_count = 0; - retr_callback(1, arg, cl); - cl->reply.mr_status = 0; + int motd, len; + char buffer[1024]; + char *arg[1]; + + arg[0] = buffer; + cl->reply.mr_status = 0; + motd = open(MOIRA_MOTD_FILE, 0, O_RDONLY); + if (motd < 0) + return; + len = read(motd, buffer, sizeof(buffer) - 1); + close(motd); + buffer[len] = 0; + row_count = 0; + retr_callback(1, arg, cl); + cl->reply.mr_status = 0; } diff --git a/server/mr_server.h b/server/mr_server.h index ca999313..0821036d 100644 --- a/server/mr_server.h +++ b/server/mr_server.h @@ -19,9 +19,9 @@ #include typedef struct returned_tuples { - struct returned_tuples *next; - OPERATION op; - mr_params *retval; + struct returned_tuples *next; + OPERATION op; + mr_params *retval; } returned_tuples; /* @@ -29,9 +29,9 @@ typedef struct returned_tuples { */ struct krbname { - char name[ANAME_SZ]; - char inst[INST_SZ]; - char realm[REALM_SZ]; + char name[ANAME_SZ]; + char inst[INST_SZ]; + char realm[REALM_SZ]; }; /* @@ -40,19 +40,19 @@ struct krbname { */ typedef struct _client { - OPERATION pending_op; /* Primary pending operation */ - CONNECTION con; /* Connection to the client */ - int action; /* what action is pending? */ - mr_params *args, reply; - int id; /* Unique id of client */ - struct sockaddr_in haddr; /* IP address of client */ - char clname[MAX_K_NAME_SZ];/* Name client authenticated to */ - struct krbname kname; /* Parsed version of the above */ - int users_id; /* MR internal ID of authenticated user */ - int client_id; /* MR internal ID of client for modby field */ - returned_tuples *first, *last; - time_t last_time_used; /* Last time connection used */ - char entity[9]; /* entity on other end of the connection */ + OPERATION pending_op; /* Primary pending operation */ + CONNECTION con; /* Connection to the client */ + int action; /* what action is pending? */ + mr_params *args, reply; + int id; /* Unique id of client */ + struct sockaddr_in haddr; /* IP address of client */ + char clname[MAX_K_NAME_SZ]; /* Name client authenticated to */ + struct krbname kname; /* Parsed version of the above */ + int users_id; /* MR internal ID of authenticated user */ + int client_id; /* MR internal ID of client for modby field */ + returned_tuples *first, *last; + time_t last_time_used; /* Last time connection used */ + char entity[9]; /* entity on other end of the connection */ } client; /* @@ -119,7 +119,7 @@ extern time_t inc_started, now; int gdb_init(void); int gdb_debug(int flag); void start_accepting_client(CONNECTION, OPERATION, CONNECTION *, - char *, int*, TUPLE *); + char *, int *, TUPLE *); int initialize_operation(OPERATION, int (*init_function)(), char *, int (*cancel_function)()); int reset_operation(OPERATION); diff --git a/server/mr_shutdown.c b/server/mr_shutdown.c index a32f7d4d..24fa88f4 100644 --- a/server/mr_shutdown.c +++ b/server/mr_shutdown.c @@ -22,18 +22,15 @@ extern char *whoami; void sigshut(int sig) { - takedown = "Shut down by signal."; + takedown = "Shut down by signal."; } -void -do_shutdown(cl) - client *cl; +void do_shutdown(client *cl) { - /* - * This feature is no longer supported. Sorry. - */ - com_err(whoami, 0, "Shutdown request by %s rejected", - cl->clname); - cl->reply.mr_status = EACCES; + /* + * This feature is no longer supported. Sorry. + */ + com_err(whoami, 0, "Shutdown request by %s rejected", cl->clname); + cl->reply.mr_status = EACCES; } - + diff --git a/server/mr_srvdata.c b/server/mr_srvdata.c index 0118d46a..fef155f2 100644 --- a/server/mr_srvdata.c +++ b/server/mr_srvdata.c @@ -36,7 +36,7 @@ LIST_OF_OPERATIONS op_list; * The current number of connected clients, an array of them, and the * "current" client, if any. */ -int nclients=0; +int nclients = 0; client **clients, *cur_client; /* * Socket address of the most recently connected client. @@ -62,7 +62,7 @@ char buf1[BUFSIZ]; * If non-null, reason for shutdown. (Moira will be going down shortly * if this is non-null) */ -char *takedown=NULL; +char *takedown = NULL; /* States for putting the server to sleep & waking it up again. */ int dormant = AWAKE; diff --git a/server/mr_util.c b/server/mr_util.c index 1b5bb337..9b9e67d4 100644 --- a/server/mr_util.c +++ b/server/mr_util.c @@ -21,74 +21,78 @@ static char *rcsid_mr_util_c = "$Header$"; extern char *whoami; -char * -requote(buf, cp, len) - char *buf; - register char *cp; +char *requote(char *buf, register char *cp, int len) { - register int count = 0; - register unsigned char c; - if (len <= 2) return buf; - *buf++ = '"'; count++; len--; - for(; (count < 258) && (len > 1) && (c = *cp); - cp++, --len, ++count) { - if (c == '\\' || c == '"') *buf++ = '\\'; - if (isprint(c)) *buf++ = c; - else { - sprintf(buf, "\\%03o", c); - buf = strchr(buf, '\0'); - } + register int count = 0; + register unsigned char c; + if (len <= 2) + return buf; + *buf++ = '"'; + count++; + len--; + for (; (count < 258) && (len > 1) && (c = *cp); cp++, --len, ++count) + { + if (c == '\\' || c == '"') + *buf++ = '\\'; + if (isprint(c)) + *buf++ = c; + else + { + sprintf(buf, "\\%03o", c); + buf = strchr(buf, '\0'); } - if (len > 1) { *buf++ = '"'; count++; len--; } - if (len > 1) *buf = '\0'; - return buf; + } + if (len > 1) + { + *buf++ = '"'; + count++; + len--; + } + if (len > 1) + *buf = '\0'; + return buf; } -void log_args(tag, version, argc, argv) - char *tag; - int version; - int argc; - char **argv; +void log_args(char *tag, int version, int argc, char **argv) { - char buf[BUFSIZ]; - register int i; - register char *bp; - - i = strlen(tag); - sprintf(buf, "%s[%d]: ", tag, version); - for (bp = buf; *bp; bp++); - - for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++) { - if (i != 0) { - *bp++ = ','; - *bp++ = ' '; - } - bp = requote(bp, argv[i], (buf - bp) + BUFSIZ); + char buf[BUFSIZ]; + register int i; + register char *bp; + + i = strlen(tag); + sprintf(buf, "%s[%d]: ", tag, version); + for (bp = buf; *bp; bp++) + ; + + for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++) + { + if (i != 0) + { + *bp++ = ','; + *bp++ = ' '; } - *bp = '\0'; - com_err(whoami, 0, "%s", buf); + bp = requote(bp, argv[i], (buf - bp) + BUFSIZ); + } + *bp = '\0'; + com_err(whoami, 0, "%s", buf); } - -void mr_com_err(whoami, code, fmt, pvar) - const char *whoami; - long code; - const char *fmt; - va_list pvar; + +void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar) { - extern client *cur_client; - - if (whoami) { - fputs(whoami, stderr); - if (cur_client) fprintf(stderr, "[#%d]", cur_client->id); - fputs(": ", stderr); - } - if (code) { - fputs(error_message(code), stderr); - } - if (fmt) { - _doprnt(fmt, pvar, stderr); - } - putc('\n', stderr); + extern client *cur_client; + + if (whoami) + { + fputs(whoami, stderr); + if (cur_client) + fprintf(stderr, "[#%d]", cur_client->id); + fputs(": ", stderr); + } + if (code) + fputs(error_message(code), stderr); + if (fmt) + _doprnt(fmt, pvar, stderr); + putc('\n', stderr); } @@ -97,51 +101,52 @@ void mr_com_err(whoami, code, fmt, pvar) * appears to be binary instead of ASCII, it will not be trimmed. */ -int mr_trim_args(argc, argv) -int argc; -char **argv; +int mr_trim_args(int argc, char **argv) { - register char **arg; - register unsigned char *p, *lastch; - - for (arg = argv; argc--; arg++) { - for (lastch = p = (unsigned char *) *arg; *p; p++) { - /* If any byte in the string has the high bit set, assume - * that it is binary and we do not want to trim it. - * Setting p = lastch will cause us not to trim the string - * when we break out of this inner loop. - */ - if (*p >= 0x80) { - p = lastch; - break; + register char **arg; + register unsigned char *p, *lastch; + + for (arg = argv; argc--; arg++) + { + for (lastch = p = (unsigned char *) *arg; *p; p++) + { + /* If any byte in the string has the high bit set, assume + * that it is binary and we do not want to trim it. + * Setting p = lastch will cause us not to trim the string + * when we break out of this inner loop. + */ + if (*p >= 0x80) + { + p = lastch; + break; } - if (!isspace(*p)) - lastch = p; + if (!isspace(*p)) + lastch = p; } - if (p != lastch) { - if (isspace(*lastch)) - *lastch = 0; - else - if (*(++lastch)) *lastch = 0; + if (p != lastch) + { + if (isspace(*lastch)) + *lastch = '\0'; + else + if (*(++lastch)) + *lastch = '\0'; } } - return(0); + return 0; } /* returns a copy of the argv and all of it's strings */ -char **mr_copy_args(argv, argc) -char **argv; -int argc; +char **mr_copy_args(char **argv, int argc) { - char **a; - int i; - - a = (char **) malloc(argc * sizeof(char *)); - if (a == 0) - return(a); - for (i = 0; i < argc; i++) - a[i] = strsave(argv[i]); - return(a); + char **a; + int i; + + a = malloc(argc * sizeof(char *)); + if (!a) + return a; + for (i = 0; i < argc; i++) + a[i] = strsave(argv[i]); + return a; } diff --git a/server/qaccess.pc b/server/qaccess.pc index 9596aed2..a1cc322f 100644 --- a/server/qaccess.pc +++ b/server/qaccess.pc @@ -38,15 +38,12 @@ EXEC SQL WHENEVER SQLERROR DO dbmserr(); * now in argv[0] instead of the login name. */ -int access_user(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_user(struct query *q, char *argv[], client *cl) { - if (cl->users_id != *(int *)argv[0]) - return(MR_PERM); - else - return(MR_SUCCESS); + if (cl->users_id != *(int *)argv[0]) + return MR_PERM; + else + return MR_SUCCESS; } @@ -56,38 +53,43 @@ int access_user(q, argv, cl) * argv[0...n] contain search info. q-> */ -int access_login(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_login(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int id; + EXEC SQL END DECLARE SECTION; - if(q->argc != 1) return MR_ARGS; + if (q->argc != 1) + return MR_ARGS; - if(!strcmp(q->shortname, "gual")) { + if (!strcmp(q->shortname, "gual")) + { EXEC SQL SELECT users_id INTO :id FROM users WHERE login LIKE :argv[0] AND users_id != 0; - } else if (!strcmp(q->shortname, "gubl")) { + } + else if (!strcmp(q->shortname, "gubl")) + { EXEC SQL SELECT users_id INTO :id FROM users u WHERE u.login LIKE :argv[0] AND u.users_id != 0; - } else if (!strcmp(q->shortname, "guau")) { + } + else if (!strcmp(q->shortname, "guau")) + { EXEC SQL SELECT users_id INTO :id FROM users WHERE unix_uid = :argv[0] AND users_id != 0; - } else if(!strcmp(q->shortname, "gubu")) { + } + else if (!strcmp(q->shortname, "gubu")) + { EXEC SQL SELECT users_id INTO :id FROM users u WHERE u.unix_uid = :argv[0] AND u.users_id != 0; } - if (sqlca.sqlcode == SQL_NO_MATCH) - return(MR_NO_MATCH); /* ought to be MR_USER, but this is what - gual returns, so we have to be consistent */ - else if (sqlca.sqlerrd[2] != 1 || id != cl->users_id) - return(MR_PERM); - else - return(MR_SUCCESS); + if (sqlca.sqlcode == SQL_NO_MATCH) + return MR_NO_MATCH; /* ought to be MR_USER, but this is what + gual returns, so we have to be consistent */ + else if (sqlca.sqlerrd[2] != 1 || id != cl->users_id) + return MR_PERM; + else + return MR_SUCCESS; } @@ -105,53 +107,58 @@ int access_login(q, argv, cl) * and the list is public, allow access if client = member */ -int access_list(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_list(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int list_id, acl_id, flags, gid, users_id; - char acl_type[9], *newname; - EXEC SQL END DECLARE SECTION; - int status; - - list_id = *(int *)argv[0]; - EXEC SQL SELECT acl_id, acl_type, gid, publicflg - INTO :acl_id, :acl_type, :gid, :flags - FROM list - WHERE list_id = :list_id; - - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - - /* if amtl or dmfl and list is public allow client to add or delete self */ - if (((!strcmp("amtl", q->shortname) && flags) || - (!strcmp("dmfl", q->shortname)))) { - if (!strcmp("USER", argv[1]) && *(int *)argv[2] == cl->users_id) - return(MR_SUCCESS); - if (!strcmp("KERBEROS", argv[1]) && *(int *)argv[2] == -cl->client_id) - return(MR_SUCCESS); - /* if update_list, don't allow them to change the GID or rename to - a username other than their own */ - } else if (!strcmp("ulis", q->shortname)) { - if (!strcmp(argv[7], UNIQUE_GID)) { - if(gid != -1) return MR_PERM; - } else { - if(gid != atoi(argv[7])) return MR_PERM; - } + EXEC SQL BEGIN DECLARE SECTION; + int list_id, acl_id, flags, gid, users_id; + char acl_type[9], *newname; + EXEC SQL END DECLARE SECTION; + int status; + + list_id = *(int *)argv[0]; + EXEC SQL SELECT acl_id, acl_type, gid, publicflg + INTO :acl_id, :acl_type, :gid, :flags + FROM list + WHERE list_id = :list_id; + + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + + /* if amtl or dmfl and list is public allow client to add or delete self */ + if (((!strcmp("amtl", q->shortname) && flags) || + (!strcmp("dmfl", q->shortname)))) + { + if (!strcmp("USER", argv[1]) && *(int *)argv[2] == cl->users_id) + return MR_SUCCESS; + if (!strcmp("KERBEROS", argv[1]) && *(int *)argv[2] == -cl->client_id) + return MR_SUCCESS; + } /* if update_list, don't allow them to change the GID or rename to + a username other than their own */ + else if (!strcmp("ulis", q->shortname)) + { + if (!strcmp(argv[7], UNIQUE_GID)) + { + if (gid != -1) + return MR_PERM; + } + else + { + if (gid != atoi(argv[7])) + return MR_PERM; + } newname = argv[1]; EXEC SQL SELECT users_id INTO :users_id FROM users - WHERE login=:newname; + WHERE login = :newname; if ((sqlca.sqlcode != SQL_NO_MATCH) && (users_id != cl->users_id)) - return MR_PERM; + return MR_PERM; } - /* check for client in access control list */ - status = find_member(acl_type, acl_id, cl); - if (!status) return(MR_PERM); + /* check for client in access control list */ + status = find_member(acl_type, acl_id, cl); + if (!status) + return MR_PERM; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -162,33 +169,30 @@ int access_list(q, argv, cl) * cl - client identifier */ -int access_visible_list(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_visible_list(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int list_id, acl_id, flags ; - char acl_type[9]; - EXEC SQL END DECLARE SECTION; - int status; - - list_id = *(int *)argv[0]; - EXEC SQL SELECT hidden, acl_id, acl_type - INTO :flags, :acl_id, :acl_type - FROM list - WHERE list_id = :list_id; - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - if (!flags) - return(MR_SUCCESS); - - /* check for client in access control list */ - status = find_member(acl_type, acl_id, cl); - if (!status) - return(MR_PERM); - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int list_id, acl_id, flags ; + char acl_type[9]; + EXEC SQL END DECLARE SECTION; + int status; + + list_id = *(int *)argv[0]; + EXEC SQL SELECT hidden, acl_id, acl_type + INTO :flags, :acl_id, :acl_type + FROM list + WHERE list_id = :list_id; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + if (!flags) + return MR_SUCCESS; + + /* check for client in access control list */ + status = find_member(acl_type, acl_id, cl); + if (!status) + return MR_PERM; + + return MR_SUCCESS; } @@ -199,35 +203,32 @@ int access_visible_list(q, argv, cl) * cl - client identifier */ -int access_vis_list_by_name(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_vis_list_by_name(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int acl_id, flags, rowcount; - char acl_type[9], *listname; - EXEC SQL END DECLARE SECTION; - int status; - - listname = argv[0]; - EXEC SQL SELECT hidden, acl_id, acl_type INTO :flags, :acl_id, :acl_type - FROM list WHERE name = :listname; - - rowcount=sqlca.sqlerrd[2]; - if (rowcount > 1) - return(MR_WILDCARD); - if (rowcount == 0) - return(MR_NO_MATCH); - if (!flags) - return(MR_SUCCESS); - - /* check for client in access control list */ - status = find_member(acl_type, acl_id, cl); - if (!status) - return(MR_PERM); - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int acl_id, flags, rowcount; + char acl_type[9], *listname; + EXEC SQL END DECLARE SECTION; + int status; + + listname = argv[0]; + EXEC SQL SELECT hidden, acl_id, acl_type INTO :flags, :acl_id, :acl_type + FROM list WHERE name = :listname; + + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 1) + return MR_WILDCARD; + if (rowcount == 0) + return MR_NO_MATCH; + if (!flags) + return MR_SUCCESS; + + /* check for client in access control list */ + status = find_member(acl_type, acl_id, cl); + if (!status) + return MR_PERM; + + return MR_SUCCESS; } @@ -237,25 +238,24 @@ int access_vis_list_by_name(q, argv, cl) * on the acl of, or the list is visible. */ -int access_member(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_member(struct query *q, char *argv[], client *cl) { - if (!strcmp(argv[0], "LIST") || !strcmp(argv[0], "RLIST")) - return(access_visible_list(q, &argv[1], cl)); + if (!strcmp(argv[0], "LIST") || !strcmp(argv[0], "RLIST")) + return access_visible_list(q, &argv[1], cl); - if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) { - if (cl->users_id == *(int *)argv[1]) - return(MR_SUCCESS); + if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) + { + if (cl->users_id == *(int *)argv[1]) + return MR_SUCCESS; } - if (!strcmp(argv[0], "KERBEROS") || !strcmp(argv[0], "RKERBEROS")) { - if (cl->client_id == -*(int *)argv[1]) - return(MR_SUCCESS); + if (!strcmp(argv[0], "KERBEROS") || !strcmp(argv[0], "RKERBEROS")) + { + if (cl->client_id == -*(int *)argv[1]) + return MR_SUCCESS; } - return(MR_PERM); + return MR_PERM; } @@ -263,14 +263,11 @@ int access_member(q, argv, cl) * access iff argv[0] == "TRUE" and argv[2] == "FALSE". */ -int access_qgli(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_qgli(struct query *q, char *argv[], client *cl) { - if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE")) - return(MR_SUCCESS); - return(MR_PERM); + if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE")) + return MR_SUCCESS; + return MR_PERM; } @@ -278,30 +275,32 @@ int access_qgli(q, argv, cl) * allow access if a wildcard is used. */ -int access_service(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_service(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int acl_id; - char *name, acl_type[9]; - EXEC SQL END DECLARE SECTION; - int status; - char *c; - - name = argv[0]; - for(c=name;*c;c++) if(islower(*c)) *c = toupper(*c); /* uppercasify */ - EXEC SQL SELECT acl_id, acl_type INTO :acl_id, :acl_type FROM servers - WHERE name = :name; - if (sqlca.sqlerrd[2] > 1) - return(MR_PERM); - - /* check for client in access control list */ - status = find_member(acl_type, acl_id, cl); - if (!status) return(MR_PERM); - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int acl_id; + char *name, acl_type[9]; + EXEC SQL END DECLARE SECTION; + int status; + char *c; + + name = argv[0]; + for (c = name; *c; c++) + { + if (islower(*c)) + *c = toupper(*c); + } + EXEC SQL SELECT acl_id, acl_type INTO :acl_id, :acl_type FROM servers + WHERE name = :name; + if (sqlca.sqlerrd[2] > 1) + return MR_PERM; + + /* check for client in access control list */ + status = find_member(acl_type, acl_id, cl); + if (!status) + return MR_PERM; + + return MR_SUCCESS; } @@ -309,30 +308,27 @@ int access_service(q, argv, cl) * named by argv[0] */ -int access_filesys(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_filesys(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int users_id, list_id; - char *name; - EXEC SQL END DECLARE SECTION; - int status; - - name = argv[0]; - EXEC SQL SELECT owner, owners INTO :users_id, :list_id FROM filesys - WHERE label = :name; - - if (sqlca.sqlerrd[2] != 1) - return(MR_PERM); - if (users_id == cl->users_id) - return(MR_SUCCESS); - status = find_member("LIST", list_id, cl); - if (status) - return(MR_SUCCESS); - else - return(MR_PERM); + EXEC SQL BEGIN DECLARE SECTION; + int users_id, list_id; + char *name; + EXEC SQL END DECLARE SECTION; + int status; + + name = argv[0]; + EXEC SQL SELECT owner, owners INTO :users_id, :list_id FROM filesys + WHERE label = :name; + + if (sqlca.sqlerrd[2] != 1) + return MR_PERM; + if (users_id == cl->users_id) + return MR_SUCCESS; + status = find_member("LIST", list_id, cl); + if (status) + return MR_SUCCESS; + else + return MR_PERM; } @@ -341,49 +337,54 @@ int access_filesys(q, argv, cl) int host_access_level = 0; /* 1 for network, 2 for host */ -int access_host(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_host(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int mid, sid, id; - char mtype[9], stype[9]; - EXEC SQL END DECLARE SECTION; - int status; - - if (q->type == APPEND) { - id = *(int *)argv[8]; - EXEC SQL SELECT s.owner_type, s.owner_id - INTO :stype, :sid FROM subnet s - WHERE s.snet_id=:id; - mid =0; - } else if (q->type == RETRIEVE) { - if (strcmp(argv[0], "*") || strcmp(argv[1], "*") || - strcmp(argv[2], "*") || strcmp(argv[3], "*")) - return(MR_SUCCESS); - else - return(MR_PERM); - } else { - id = *(int *)argv[0]; - EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id - INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s - WHERE m.mach_id=:id and s.snet_id=m.snet_id; + EXEC SQL BEGIN DECLARE SECTION; + int mid, sid, id; + char mtype[9], stype[9]; + EXEC SQL END DECLARE SECTION; + int status; + + if (q->type == APPEND) + { + id = *(int *)argv[8]; + EXEC SQL SELECT s.owner_type, s.owner_id + INTO :stype, :sid FROM subnet s + WHERE s.snet_id = :id; + mid = 0; } - if (sqlca.sqlerrd[2] != 1) - return(MR_PERM); - - status = find_member(stype, sid, cl); - if (status) { - host_access_level = 1; - return(MR_SUCCESS); + else if (q->type == RETRIEVE) + { + if (strcmp(argv[0], "*") || strcmp(argv[1], "*") || + strcmp(argv[2], "*") || strcmp(argv[3], "*")) + return MR_SUCCESS; + else + return MR_PERM; + } + else + { + id = *(int *)argv[0]; + EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id + INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s + WHERE m.mach_id = :id and s.snet_id = m.snet_id; + } + if (sqlca.sqlerrd[2] != 1) + return MR_PERM; + + status = find_member(stype, sid, cl); + if (status) + { + host_access_level = 1; + return MR_SUCCESS; + } + status = find_member(mtype, mid, cl); + if (status) + { + host_access_level = 2; + return MR_SUCCESS; } - status = find_member(mtype, mid, cl); - if (status) { - host_access_level = 2; - return(MR_SUCCESS); - } else - return(MR_PERM); + else + return MR_PERM; } @@ -393,41 +394,39 @@ int access_host(q, argv, cl) * If deleting an alias, any owner will do. */ -int access_ahal(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_ahal(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int cnt, id, mid, sid; - char mtype[256], stype[256]; - EXEC SQL END DECLARE SECTION; - int status; - - if (q->type == RETRIEVE) - return(MR_SUCCESS); - - id = *(int *)argv[1]; - - EXEC SQL SELECT count(name) INTO :cnt from hostalias WHERE mach_id = :id; - if (dbms_errno) return(mr_errcode); - /* if the type is APPEND, this is ahal and we need to make sure there - * will be no more than 2 aliases. If it's not, it must be dhal and - * any owner will do. - */ - if (q->type == APPEND && cnt >= 2) - return(MR_PERM); - EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id - INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s - WHERE m.mach_id=:id and s.snet_id=m.snet_id; - status = find_member(mtype, mid, cl); - if (status) - return(MR_SUCCESS); - status = find_member(stype, sid, cl); - if (status) - return(MR_SUCCESS); - else - return(MR_PERM); + EXEC SQL BEGIN DECLARE SECTION; + int cnt, id, mid, sid; + char mtype[256], stype[256]; + EXEC SQL END DECLARE SECTION; + int status; + + if (q->type == RETRIEVE) + return MR_SUCCESS; + + id = *(int *)argv[1]; + + EXEC SQL SELECT count(name) INTO :cnt from hostalias WHERE mach_id = :id; + if (dbms_errno) + return mr_errcode; + /* if the type is APPEND, this is ahal and we need to make sure there + * will be no more than 2 aliases. If it's not, it must be dhal and + * any owner will do. + */ + if (q->type == APPEND && cnt >= 2) + return MR_PERM; + EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id + INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s + WHERE m.mach_id = :id and s.snet_id = m.snet_id; + status = find_member(mtype, mid, cl); + if (status) + return MR_SUCCESS; + status = find_member(stype, sid, cl); + if (status) + return MR_SUCCESS; + else + return MR_PERM; } @@ -435,13 +434,10 @@ int access_ahal(q, argv, cl) /* access_snt - check for retrieving network structure */ -int access_snt(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int access_snt(struct query *q, char *argv[], client *cl) { - if(q->type == RETRIEVE) - return(MR_SUCCESS); + if (q->type == RETRIEVE) + return MR_SUCCESS; - return(MR_PERM); + return MR_PERM; } diff --git a/server/qfollow.pc b/server/qfollow.pc index 7260cc01..52ec5703 100644 --- a/server/qfollow.pc +++ b/server/qfollow.pc @@ -43,23 +43,21 @@ EXEC SQL WHENEVER SQLERROR DO dbmserr(); * the table whose name field matches argv[0]. */ -int set_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_modtime(struct query *q, char *argv[], client *cl) { - char *name, *entity, *table; - int who; + char *name, *entity, *table; + int who; - entity = cl->entity; - who = cl->client_id; - table = table_name[q->rtable]; - name = argv[0]; + entity = cl->entity; + who = cl->client_id; + table = table_name[q->rtable]; + name = argv[0]; - sprintf(stmt_buf,"UPDATE %s SET modtime = SYSDATE, modby = %d, modwith = '%s' WHERE name = '%s'",table,who,entity,name); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " + "modwith = '%s' WHERE name = '%s'", table, who, entity, name); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - return(MR_SUCCESS); + return MR_SUCCESS; } /* generic set_modtime_by_id routine. This takes the table id from @@ -68,95 +66,84 @@ int set_modtime(q, argv, cl) * the table whose id matches argv[0]. */ -int set_modtime_by_id(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_modtime_by_id(struct query *q, char *argv[], client *cl) { - char *entity, *table, *id_name; - int who, id; - - entity = cl->entity; - who = cl->client_id; - table = table_name[q->rtable]; - id_name = q->validate->object_id; - - id = *(int *)argv[0]; - sprintf(stmt_buf,"UPDATE %s SET modtime = SYSDATE, modby = %d, \ -modwith = '%s' WHERE %s = %d",table,who,entity,id_name,id); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - return(MR_SUCCESS); + char *entity, *table, *id_name; + int who, id; + + entity = cl->entity; + who = cl->client_id; + table = table_name[q->rtable]; + id_name = q->validate->object_id; + + id = *(int *)argv[0]; + sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " + "modwith = '%s' WHERE %s = %d", table, who, entity, id_name, id); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + return MR_SUCCESS; } /* Sets the finger modtime on a user record. The users_id will be in argv[0]. */ -int set_finger_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_finger_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int users_id, who; - char *entity; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int users_id, who; + char *entity; + EXEC SQL END DECLARE SECTION; - entity = cl->entity; - who = cl->client_id; - users_id = *(int *)argv[0]; + entity = cl->entity; + who = cl->client_id; + users_id = *(int *)argv[0]; - EXEC SQL UPDATE users SET fmodtime=SYSDATE, fmodby = :who, - fmodwith = :entity WHERE users_id = :users_id; + EXEC SQL UPDATE users SET fmodtime = SYSDATE, fmodby = :who, + fmodwith = :entity WHERE users_id = :users_id; - return(MR_SUCCESS); + return MR_SUCCESS; } /* Sets the pobox modtime on a user record. The users_id will be in argv[0]. */ -int set_pobox_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_pobox_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int users_id, who; - char *entity; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int users_id, who; + char *entity; + EXEC SQL END DECLARE SECTION; - entity = cl->entity; - who = cl->client_id; - users_id = *(int *)argv[0]; + entity = cl->entity; + who = cl->client_id; + users_id = *(int *)argv[0]; - EXEC SQL UPDATE users SET pmodtime=SYSDATE, pmodby = :who, - pmodwith = :entity WHERE users_id = :users_id; + EXEC SQL UPDATE users SET pmodtime = SYSDATE, pmodby = :who, + pmodwith = :entity WHERE users_id = :users_id; - return(MR_SUCCESS); + return MR_SUCCESS; } /* Like set_modtime, but uppercases the name first. */ -int set_uppercase_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_uppercase_modtime(struct query *q, char *argv[], client *cl) { - char *name, *entity, *table; - int who; + char *name, *entity, *table; + int who; - entity = cl->entity; - who = cl->client_id; - table = table_name[q->rtable]; - name = argv[0]; + entity = cl->entity; + who = cl->client_id; + table = table_name[q->rtable]; + name = argv[0]; - sprintf(stmt_buf,"UPDATE %s SET modtime = SYSDATE, modby = %d, modwith = '%s' WHERE name = UPPER('%s')",table,who,entity,name); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " + "modwith = '%s' WHERE name = UPPER('%s')", table, who, entity, name); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -165,23 +152,20 @@ int set_uppercase_modtime(q, argv, cl) * operates on is "mcm", not "machine". */ -int set_mach_modtime_by_id(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_mach_modtime_by_id(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *entity; - int who, id; - EXEC SQL END DECLARE SECTION; - - entity = cl->entity; - who = cl->client_id; - id = *(int *)argv[0]; - EXEC SQL UPDATE machine SET modtime=SYSDATE, modby = :who, - modwith = :entity WHERE mach_id = :id; - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *entity; + int who, id; + EXEC SQL END DECLARE SECTION; + + entity = cl->entity; + who = cl->client_id; + id = *(int *)argv[0]; + EXEC SQL UPDATE machine SET modtime = SYSDATE, modby = :who, + modwith = :entity WHERE mach_id = :id; + + return MR_SUCCESS; } @@ -190,23 +174,20 @@ int set_mach_modtime_by_id(q, argv, cl) * table that query operates on is "svc", not "cluster". */ -int set_cluster_modtime_by_id(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_cluster_modtime_by_id(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *entity; - int who, id; - EXEC SQL END DECLARE SECTION; - - entity = cl->entity; - who = cl->client_id; - - id = *(int *)argv[0]; - EXEC SQL UPDATE clusters SET modtime=SYSDATE, modby = :who, - modwith = :entity WHERE clu_id = :id; - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *entity; + int who, id; + EXEC SQL END DECLARE SECTION; + + entity = cl->entity; + who = cl->client_id; + + id = *(int *)argv[0]; + EXEC SQL UPDATE clusters SET modtime = SYSDATE, modby = :who, + modwith = :entity WHERE clu_id = :id; + return MR_SUCCESS; } @@ -214,25 +195,22 @@ int set_cluster_modtime_by_id(q, argv, cl) * and the mach_id is in argv[1]. */ -int set_serverhost_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_serverhost_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *entity, *serv; - int who, id; - EXEC SQL END DECLARE SECTION; - - entity = cl->entity; - who = cl->client_id; - - serv = argv[0]; - id = *(int *)argv[1]; - EXEC SQL UPDATE serverhosts - SET modtime = SYSDATE, modby = :who, modwith = :entity - WHERE service = :serv AND mach_id = :id; - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *entity, *serv; + int who, id; + EXEC SQL END DECLARE SECTION; + + entity = cl->entity; + who = cl->client_id; + + serv = argv[0]; + id = *(int *)argv[1]; + EXEC SQL UPDATE serverhosts + SET modtime = SYSDATE, modby = :who, modwith = :entity + WHERE service = :serv AND mach_id = :id; + return MR_SUCCESS; } @@ -240,24 +218,21 @@ int set_serverhost_modtime(q, argv, cl) * directory name is in argv[1]. */ -int set_nfsphys_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_nfsphys_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *entity, *dir; - int who, id; - EXEC SQL END DECLARE SECTION; - - entity = cl->entity; - who = cl->client_id; - - id = *(int *)argv[0]; - dir = argv[1]; - EXEC SQL UPDATE nfsphys SET modtime = SYSDATE, modby = :who, - modwith = :entity WHERE dir = :dir AND mach_id = :id; - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *entity, *dir; + int who, id; + EXEC SQL END DECLARE SECTION; + + entity = cl->entity; + who = cl->client_id; + + id = *(int *)argv[0]; + dir = argv[1]; + EXEC SQL UPDATE nfsphys SET modtime = SYSDATE, modby = :who, + modwith = :entity WHERE dir = :dir AND mach_id = :id; + return MR_SUCCESS; } @@ -265,29 +240,25 @@ int set_nfsphys_modtime(q, argv, cl) * label. */ -int set_filesys_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_filesys_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *label, *entity; - int who; - extern int _var_phys_id; - - EXEC SQL END DECLARE SECTION; - - entity = cl->entity; - who = cl->client_id; - - label = argv[0]; - if (!strcmp(q->shortname, "ufil")) - label = argv[1]; - - EXEC SQL UPDATE filesys SET modtime = SYSDATE, modby = :who, - modwith = :entity, phys_id = :_var_phys_id - WHERE label = :label; - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *label, *entity; + int who; + extern int _var_phys_id; + EXEC SQL END DECLARE SECTION; + + entity = cl->entity; + who = cl->client_id; + + label = argv[0]; + if (!strcmp(q->shortname, "ufil")) + label = argv[1]; + + EXEC SQL UPDATE filesys SET modtime = SYSDATE, modby = :who, + modwith = :entity, phys_id = :_var_phys_id + WHERE label = :label; + return MR_SUCCESS; } @@ -295,25 +266,22 @@ int set_filesys_modtime(q, argv, cl) * name. */ -int set_zephyr_modtime(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int set_zephyr_modtime(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *class, *entity; - int who; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + char *class, *entity; + int who; + EXEC SQL END DECLARE SECTION; - entity = cl->entity; - who = cl->client_id; + entity = cl->entity; + who = cl->client_id; - class = argv[0]; + class = argv[0]; - EXEC SQL UPDATE zephyr SET modtime = SYSDATE, modby = :who, - modwith = :entity WHERE class = :class; + EXEC SQL UPDATE zephyr SET modtime = SYSDATE, modby = :who, + modwith = :entity WHERE class = :class; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -322,33 +290,31 @@ int set_zephyr_modtime(q, argv, cl) * passed as a pointer to an integer. This will either turn it into a * username, or # + the users_id. */ -int followup_fix_modby(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_fix_modby(struct query *q, struct save_queue *sq, + struct validate *v, int (*action)(), int actarg, + client *cl) { - register int i, j; - char **argv; - int id, status; - - i = q->vcnt - 2; - while (sq_get_data(sq, &argv)) { - id = atoi(argv[i]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - (*action)(q->vcnt, argv, actarg); - for (j = 0; j < q->vcnt; j++) - free(argv[j]); - free(argv); + register int i, j; + char **argv; + int id, status; + + i = q->vcnt - 2; + while (sq_get_data(sq, &argv)) + { + id = atoi(argv[i]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + (*action)(q->vcnt, argv, actarg); + for (j = 0; j < q->vcnt; j++) + free(argv[j]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -360,68 +326,69 @@ int followup_fix_modby(q, sq, v, action, actarg, cl) * these are ones with U_END return values. "gub*" queries also use this * routine but don't have a signature. */ -int followup_guax(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_guax(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - register int i, j; - char **argv; + register int i, j; + char **argv; #ifdef GDSS - unsigned char sigbuf[256]; - char *kname; - SigInfo si; - EXEC SQL BEGIN DECLARE SECTION; - int timestamp, who, siglen; - char *login; - char rsig[256]; - EXEC SQL VAR rsig IS STRING(256); - EXEC SQL END DECLARE SECTION; + unsigned char sigbuf[256]; + char *kname; + SigInfo si; + EXEC SQL BEGIN DECLARE SECTION; + int timestamp, who, siglen; + char *login; + char rsig[256]; + EXEC SQL VAR rsig IS STRING(256); + EXEC SQL END DECLARE SECTION; #endif /* GDSS */ - int id, status; - - i = q->vcnt - 2; - while (sq_get_data(sq, &argv)) { - id = atoi(argv[i]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); + int id, status; + + i = q->vcnt - 2; + while (sq_get_data(sq, &argv)) + { + id = atoi(argv[i]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; #ifdef GDSS - if (q->vcnt == U_END && strlen(argv[U_SIGNATURE])) { - login = strtrim(argv[U_NAME]); - EXEC SQL SELECT signature, sigdate, sigwho - INTO :rsig, :timestamp, :who FROM users - WHERE login = :login; - if(dbms_errno) return mr_errcode; - kname = malloc(1); - status = id_to_name(who, STRINGS_TABLE, &kname); - si.timestamp = timestamp; - si.SigInfoVersion = 0; /* XXXXX this isn't used */ - kname_parse(si.pname, si.pinst, si.prealm, kname); - free(kname); - si.rawsig = (unsigned char *)strsave(rsig); - if (log_flags & LOG_GDSS) - com_err(whoami, 0, "rawsig length = %d, sig=\"%s\"", strlen(si.rawsig), si.rawsig); - GDSS_Recompose(&si, sigbuf); - free(si.rawsig); - free(argv[U_SIGNATURE]); - argv[U_SIGNATURE] = strsave(sigbuf); - if (log_flags & LOG_GDSS) - com_err(whoami, 0, "generated signature length %d", strlen(sigbuf)); + if (q->vcnt == U_END && strlen(argv[U_SIGNATURE])) + { + login = strtrim(argv[U_NAME]); + EXEC SQL SELECT signature, sigdate, sigwho + INTO :rsig, :timestamp, :who FROM users + WHERE login = :login; + if (dbms_errno) + return mr_errcode; + kname = malloc(1); + status = id_to_name(who, STRINGS_TABLE, &kname); + si.timestamp = timestamp; + si.SigInfoVersion = 0; /* XXXXX this isn't used */ + kname_parse(si.pname, si.pinst, si.prealm, kname); + free(kname); + si.rawsig = (unsigned char *)strsave(rsig); + if (log_flags & LOG_GDSS) + com_err(whoami, 0, "rawsig length = %d, sig=\"%s\"", + strlen(si.rawsig), si.rawsig); + GDSS_Recompose(&si, sigbuf); + free(si.rawsig); + free(argv[U_SIGNATURE]); + argv[U_SIGNATURE] = strsave(sigbuf); + if (log_flags & LOG_GDSS) + com_err(whoami, 0, "generated signature length %d", + strlen(sigbuf)); } #endif /* GDSS */ - (*action)(q->vcnt, argv, actarg); - for (j = 0; j < q->vcnt; j++) - free(argv[j]); - free(argv); + (*action)(q->vcnt, argv, actarg); + for (j = 0; j < q->vcnt; j++) + free(argv[j]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -436,87 +403,91 @@ int followup_guax(q, sq, v, action, actarg, cl) ** **/ -int followup_ausr(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int followup_ausr(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int who, status; - char *login, *entity, *name; - char fullname[129]; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int who, status; + char *login, *entity, *name; + char fullname[129]; + EXEC SQL END DECLARE SECTION; #ifdef GDSS - char databuf[32], *kname_unparse(); - EXEC SQL BEGIN DECLARE SECTION; - char rawsig[128]; - int sigwho, timestamp; - EXEC SQL END DECLARE SECTION; - SigInfo si; + char databuf[32], *kname_unparse(); + EXEC SQL BEGIN DECLARE SECTION; + char rawsig[128]; + int sigwho, timestamp; + EXEC SQL END DECLARE SECTION; + SigInfo si; #endif /* GDSS */ - /* build fullname */ - if (strlen(argv[4]) && strlen(argv[5])) - sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]); - else if (strlen(argv[4])) - sprintf(fullname, "%s %s", argv[4], argv[3]); - else - sprintf(fullname, "%s", argv[3]); + /* build fullname */ + if (strlen(argv[4]) && strlen(argv[5])) + sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]); + else if (strlen(argv[4])) + sprintf(fullname, "%s %s", argv[4], argv[3]); + else + sprintf(fullname, "%s", argv[3]); #ifdef GDSS - if (q->vcnt == U_END && *argv[U_SIGNATURE]) { - sprintf(databuf, "%s:%s", argv[U_NAME], argv[U_MITID]); - /* skip bytes for timestamp & kname */ - si.rawsig = (unsigned char *) rawsig; - status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE], &si); - if (strlen(rawsig) > mr_sig_length) { - com_err(whoami, 0, "GDSS signature would be truncated."); /** untested **/ - return(MR_INTERNAL); + if (q->vcnt == U_END && *argv[U_SIGNATURE]) + { + sprintf(databuf, "%s:%s", argv[U_NAME], argv[U_MITID]); + /* skip bytes for timestamp & kname */ + si.rawsig = (unsigned char *) rawsig; + status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE], &si); + if (strlen(rawsig) > mr_sig_length) + { + com_err(whoami, 0, "GDSS signature would be truncated."); + return MR_INTERNAL; } - if (status == 0) { - name = kname_unparse(si.pname, si.pinst, si.prealm); - status = name_to_id(name, STRINGS_TABLE, &sigwho); - if (status == MR_NO_MATCH) { - sigwho=add_string(name); - } else if (status) - return(status); - timestamp = si.timestamp; - } else { - if (log_flags & LOG_GDSS) - hex_dump(argv[U_SIGNATURE]); - return(gdss2et(status)); + if (status == 0) + { + name = kname_unparse(si.pname, si.pinst, si.prealm); + status = name_to_id(name, STRINGS_TABLE, &sigwho); + if (status == MR_NO_MATCH) + sigwho = add_string(name); + else if (status) + return status; + timestamp = si.timestamp; + } + else + { + if (log_flags & LOG_GDSS) + hex_dump(argv[U_SIGNATURE]); + return gdss2et(status); } - } else { - rawsig[0] = 0; - sigwho = 0; - timestamp = 0; - } + } + else + { + rawsig[0] = '\0'; + sigwho = 0; + timestamp = 0; + } #endif /* GDSS */ - login = argv[0]; - who = cl->client_id; - entity = cl->entity; + login = argv[0]; + who = cl->client_id; + entity = cl->entity; - /* create finger entry, pobox & set modtime on user */ + /* create finger entry, pobox & set modtime on user */ #ifdef GDSS - EXEC SQL UPDATE users - SET modtime=SYSDATE, modby=:who, modwith = :entity, - fullname = NVL(:fullname,CHR(0)), affiliation = type, - signature = NVL(:rawsig,CHR(0)), sigdate = :timestamp, - sigwho = :sigwho, fmodtime=SYSDATE, fmodby = :who, - fmodwith = :entity, potype='NONE', pmodtime=SYSDATE, - pmodby = :who, pmodwith = :entity - WHERE login = :login; + EXEC SQL UPDATE users + SET modtime = SYSDATE, modby = :who, modwith = :entity, + fullname = NVL(:fullname, CHR(0)), affiliation = type, + signature = NVL(:rawsig, CHR(0)), sigdate = :timestamp, + sigwho = :sigwho, fmodtime = SYSDATE, fmodby = :who, + fmodwith = :entity, potype = 'NONE', pmodtime = SYSDATE, + pmodby = :who, pmodwith = :entity + WHERE login = :login; #else /* GDSS */ - EXEC SQL UPDATE users - SET modtime=SYSDATE, modby=:who, modwith = :entity, - fullname = NVL(:fullname,CHR(0)), affiliation = type, - fmodtime=SYSDATE, fmodby = :who, fmodwith = :entity, - potype='NONE', pmodtime=SYSDATE, pmodby = :who, pmodwith = :entity - WHERE login = :login; + EXEC SQL UPDATE users + SET modtime = SYSDATE, modby = :who, modwith = :entity, + fullname = NVL(:fullname, CHR(0)), affiliation = type, + fmodtime = SYSDATE, fmodby = :who, fmodwith = :entity, + potype = 'NONE', pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity + WHERE login = :login; #endif /* GDSS */ - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -529,75 +500,80 @@ int followup_ausr(q, argv, cl) ** **/ -int followup_uuac(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int followup_uuac(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int who, status, id; - char *entity, *name; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int who, status, id; + char *entity, *name; + EXEC SQL END DECLARE SECTION; #ifdef GDSS - char databuf[32], *kname_unparse(); - EXEC SQL BEGIN DECLARE SECTION; - char rawsig[128]; - char *login; - int sigwho, timestamp; - EXEC SQL END DECLARE SECTION; - SigInfo si; + char databuf[32], *kname_unparse(); + EXEC SQL BEGIN DECLARE SECTION; + char rawsig[128]; + char *login; + int sigwho, timestamp; + EXEC SQL END DECLARE SECTION; + SigInfo si; #endif /* GDSS */ - - id = *(int *)argv[0]; - who = cl->client_id; - entity = cl->entity; - + + id = *(int *)argv[0]; + who = cl->client_id; + entity = cl->entity; + #ifdef GDSS - if (q->vcnt == U_MODTIME && *argv[U_SIGNATURE + 1]) { - login = malloc(1); - status = id_to_name(id, USERS_TABLE, &login); - sprintf(databuf, "%s:%s", login, argv[U_MITID+1]); - free(login); - /* skip bytes for timestamp & kname */ - si.rawsig = (unsigned char *) rawsig; - status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE+1], &si); - if (strlen(rawsig) > mr_sig_length) { - com_err(whoami, 0, "GDSS signature would be truncated."); /** untested **/ - return(MR_INTERNAL); + if (q->vcnt == U_MODTIME && *argv[U_SIGNATURE + 1]) + { + login = malloc(1); + status = id_to_name(id, USERS_TABLE, &login); + sprintf(databuf, "%s:%s", login, argv[U_MITID + 1]); + free(login); + /* skip bytes for timestamp & kname */ + si.rawsig = (unsigned char *) rawsig; + status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE + 1], + &si); + if (strlen(rawsig) > mr_sig_length) + { + com_err(whoami, 0, "GDSS signature would be truncated."); + return MR_INTERNAL; } - if (status == 0) { - name = kname_unparse(si.pname, si.pinst, si.prealm); - status = name_to_id(name, STRINGS_TABLE, &sigwho); - if (status == MR_NO_MATCH) { - sigwho=add_string(name); - } else if (status) - return(status); - timestamp = si.timestamp; - } else { - if (log_flags & LOG_GDSS) - hex_dump(argv[U_SIGNATURE+1]); - return(gdss2et(status)); + if (status == 0) + { + name = kname_unparse(si.pname, si.pinst, si.prealm); + status = name_to_id(name, STRINGS_TABLE, &sigwho); + if (status == MR_NO_MATCH) + sigwho = add_string(name); + else if (status) + return status; + timestamp = si.timestamp; + } + else + { + if (log_flags & LOG_GDSS) + hex_dump(argv[U_SIGNATURE + 1]); + return gdss2et(status); } - } else { - rawsig[0] = 0; - sigwho = 0; - timestamp = 0; + } + else + { + rawsig[0] = '\0'; + sigwho = 0; + timestamp = 0; } #endif /* GDSS */ - - /* create finger entry, pobox & set modtime on user */ + + /* create finger entry, pobox & set modtime on user */ #ifdef GDSS - EXEC SQL UPDATE users SET modtime=SYSDATE, modby = :who, modwith = :entity, - signature = NVL(:rawsig,CHR(0)), sigdate = :timestamp, sigwho = :sigwho - WHERE users_id = :id; + EXEC SQL UPDATE users SET modtime = SYSDATE, modby = :who, modwith = :entity, + signature = NVL(:rawsig, CHR(0)), sigdate = :timestamp, sigwho = :sigwho + WHERE users_id = :id; #else /* GDSS */ - EXEC SQL UPDATE users SET modtime=SYSDATE, modby = :who, modwith = :entity - WHERE users_id = :id; + EXEC SQL UPDATE users SET modtime = SYSDATE, modby = :who, modwith = :entity + WHERE users_id = :id; #endif /* GDSS */ - return(MR_SUCCESS); + return MR_SUCCESS; } - + /* followup_gpob: fixes argv[2] based on the IDs currently there and the * type in argv[1]. Then completes the upcall to the user. * @@ -607,59 +583,61 @@ int followup_uuac(q, argv, cl) * are skipped. */ -int followup_gpob(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(); - int actarg; - client *cl; +int followup_gpob(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - char **argv; - char *ptype, *p; - int mid, sid, status, i; - - /* for each row */ - while (sq_get_data(sq, &argv)) { - mr_trim_args(2, argv); - ptype = argv[1]; - p = strchr(argv[2], ':'); - *p++ = 0; - mid = atoi(argv[2]); - sid = atoi(p); - - if (!strcmp(ptype, "POP")) { - status = id_to_name(mid, MACHINE_TABLE, &argv[2]); - if (status == MR_NO_MATCH) - return(MR_MACHINE); - } else if (!strcmp(ptype, "SMTP")) { - status = id_to_name(sid, STRINGS_TABLE, &argv[2]); - if (status == MR_NO_MATCH) - return(MR_STRING); - } else /* ptype == "NONE" */ { - goto skip; + char **argv; + char *ptype, *p; + int mid, sid, status, i; + + /* for each row */ + while (sq_get_data(sq, &argv)) + { + mr_trim_args(2, argv); + ptype = argv[1]; + p = strchr(argv[2], ':'); + *p++ = '\0'; + mid = atoi(argv[2]); + sid = atoi(p); + + if (!strcmp(ptype, "POP")) + { + status = id_to_name(mid, MACHINE_TABLE, &argv[2]); + if (status == MR_NO_MATCH) + return MR_MACHINE; + } + else if (!strcmp(ptype, "SMTP")) + { + status = id_to_name(sid, STRINGS_TABLE, &argv[2]); + if (status == MR_NO_MATCH) + return MR_STRING; } - if (status) return(status); - - if (!strcmp(q->shortname, "gpob")) { - sid = atoi(argv[4]); - if (sid > 0) - status = id_to_name(sid, USERS_TABLE, &argv[4]); - else - status = id_to_name(-sid, STRINGS_TABLE, &argv[4]); + else /* ptype == "NONE" */ + goto skip; + if (status) + return status; + + if (!strcmp(q->shortname, "gpob")) + { + sid = atoi(argv[4]); + if (sid > 0) + status = id_to_name(sid, USERS_TABLE, &argv[4]); + else + status = id_to_name(-sid, STRINGS_TABLE, &argv[4]); } - if (status && status != MR_NO_MATCH) return(status); + if (status && status != MR_NO_MATCH) + return status; - (*action)(q->vcnt, argv, actarg); + (*action)(q->vcnt, argv, actarg); skip: - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return (MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -669,61 +647,61 @@ int followup_gpob(q, sq, v, action, actarg, cl) * Also fixes the modby field by called followup_fix_modby. */ -int followup_gsnt(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - char **argv, *type; - int id, i, idx, status; - - idx = 8; - - while (sq_get_data(sq, &argv)) { - mr_trim_args(q->vcnt, argv); - - id = atoi(argv[i = q->vcnt - 2]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - - id = atoi(argv[idx]); - type = argv[idx - 1]; - - if (!strcmp(type, "LIST")) { - status = id_to_name(id, LIST_TABLE, &argv[idx]); - } else if (!strcmp(type, "USER")) { - status = id_to_name(id, USERS_TABLE, &argv[idx]); - } else if (!strcmp(type, "KERBEROS")) { - status = id_to_name(id, STRINGS_TABLE, &argv[idx]); - } else if (!strcmp(type, "NONE")) { - status = 0; - free(argv[idx]); - argv[idx] = strsave("NONE"); - } else { - status = 0; - free(argv[idx]); - argv[idx] = strsave("???"); + char **argv, *type; + int id, i, idx, status; + + idx = 8; + + while (sq_get_data(sq, &argv)) + { + mr_trim_args(q->vcnt, argv); + + id = atoi(argv[i = q->vcnt - 2]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + + id = atoi(argv[idx]); + type = argv[idx - 1]; + + if (!strcmp(type, "LIST")) + status = id_to_name(id, LIST_TABLE, &argv[idx]); + else if (!strcmp(type, "USER")) + status = id_to_name(id, USERS_TABLE, &argv[idx]); + else if (!strcmp(type, "KERBEROS")) + status = id_to_name(id, STRINGS_TABLE, &argv[idx]); + else if (!strcmp(type, "NONE")) + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("NONE"); + } + else + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("???"); } - if (status && status != MR_NO_MATCH) - return(status); + if (status && status != MR_NO_MATCH) + return status; - /* send the data */ - (*action)(q->vcnt, argv, actarg); + /* send the data */ + (*action)(q->vcnt, argv, actarg); - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return (MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -733,74 +711,76 @@ int followup_gsnt(q, sq, v, action, actarg, cl) * Also fixes the modby field by called followup_fix_modby. */ -int followup_ghst(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - char **argv, *type; - int id, i, idx, status; - - while (sq_get_data(sq, &argv)) { - mr_trim_args(q->vcnt, argv); - - id = atoi(argv[i = q->vcnt - 2]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - - id = atoi(argv[13]); - status = id_to_name(id, STRINGS_TABLE, &argv[13]); - if (status) return(status); - id = atoi(argv[14]); - status = id_to_name(id, STRINGS_TABLE, &argv[14]); - if (status) return(status); - id = atoi(argv[16]); - if (id < 0) - status = id_to_name(-id, STRINGS_TABLE, &argv[16]); - else - status = id_to_name(id, USERS_TABLE, &argv[16]); - if (status && status != MR_NO_MATCH) - return(status); - - idx = 12; - id = atoi(argv[idx]); - type = strtrim(argv[idx - 1]); - - if (!strcmp(type, "LIST")) { - status = id_to_name(id, LIST_TABLE, &argv[idx]); - } else if (!strcmp(type, "USER")) { - status = id_to_name(id, USERS_TABLE, &argv[idx]); - } else if (!strcmp(type, "KERBEROS")) { - status = id_to_name(id, STRINGS_TABLE, &argv[idx]); - } else if (!strcmp(type, "NONE")) { - status = 0; - free(argv[idx]); - argv[idx] = strsave("NONE"); - } else { - status = 0; - free(argv[idx]); - argv[idx] = strsave("???"); + char **argv, *type; + int id, i, idx, status; + + while (sq_get_data(sq, &argv)) + { + mr_trim_args(q->vcnt, argv); + + id = atoi(argv[i = q->vcnt - 2]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + + id = atoi(argv[13]); + status = id_to_name(id, STRINGS_TABLE, &argv[13]); + if (status) + return status; + id = atoi(argv[14]); + status = id_to_name(id, STRINGS_TABLE, &argv[14]); + if (status) + return status; + id = atoi(argv[16]); + if (id < 0) + status = id_to_name(-id, STRINGS_TABLE, &argv[16]); + else + status = id_to_name(id, USERS_TABLE, &argv[16]); + if (status && status != MR_NO_MATCH) + return status; + + idx = 12; + id = atoi(argv[idx]); + type = strtrim(argv[idx - 1]); + + if (!strcmp(type, "LIST")) + status = id_to_name(id, LIST_TABLE, &argv[idx]); + else if (!strcmp(type, "USER")) + status = id_to_name(id, USERS_TABLE, &argv[idx]); + else if (!strcmp(type, "KERBEROS")) + status = id_to_name(id, STRINGS_TABLE, &argv[idx]); + else if (!strcmp(type, "NONE")) + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("NONE"); } - if (status && status != MR_NO_MATCH) - return(status); + else + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("???"); + } + if (status && status != MR_NO_MATCH) + return status; - /* send the data */ - (*action)(q->vcnt, argv, actarg); + /* send the data */ + (*action)(q->vcnt, argv, actarg); - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return (MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -810,68 +790,69 @@ int followup_ghst(q, sq, v, action, actarg, cl) * Also fixes the modby field by called followup_fix_modby. */ -int followup_glin(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_glin(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - char **argv, *type; - int id, i, idx, status; - - idx = 8; - if (!strcmp(q->shortname, "gsin")) - idx = 12; - - while (sq_get_data(sq, &argv)) { - mr_trim_args(q->vcnt, argv); - - id = atoi(argv[i = q->vcnt - 2]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - - id = atoi(argv[idx]); - type = argv[idx - 1]; - - if (!strcmp(type, "LIST")) { - status = id_to_name(id, LIST_TABLE, &argv[idx]); - } else if (!strcmp(type, "USER")) { - status = id_to_name(id, USERS_TABLE, &argv[idx]); - } else if (!strcmp(type, "KERBEROS")) { - status = id_to_name(id, STRINGS_TABLE, &argv[idx]); - } else if (!strcmp(type, "NONE")) { - status = 0; - free(argv[idx]); - argv[idx] = strsave("NONE"); - } else { - status = 0; - free(argv[idx]); - argv[idx] = strsave("???"); + char **argv, *type; + int id, i, idx, status; + + idx = 8; + if (!strcmp(q->shortname, "gsin")) + idx = 12; + + while (sq_get_data(sq, &argv)) + { + mr_trim_args(q->vcnt, argv); + + id = atoi(argv[i = q->vcnt - 2]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + + id = atoi(argv[idx]); + type = argv[idx - 1]; + + if (!strcmp(type, "LIST")) + status = id_to_name(id, LIST_TABLE, &argv[idx]); + else if (!strcmp(type, "USER")) + status = id_to_name(id, USERS_TABLE, &argv[idx]); + else if (!strcmp(type, "KERBEROS")) + status = id_to_name(id, STRINGS_TABLE, &argv[idx]); + else if (!strcmp(type, "NONE")) + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("NONE"); } - if (status && status != MR_NO_MATCH) - return(status); + else + { + status = 0; + free(argv[idx]); + argv[idx] = strsave("???"); + } + if (status && status != MR_NO_MATCH) + return status; - if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) { - argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1); - strcpy(argv[6], UNIQUE_GID); + if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) + { + argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1); + strcpy(argv[6], UNIQUE_GID); } - /* send the data */ - (*action)(q->vcnt, argv, actarg); + /* send the data */ + (*action)(q->vcnt, argv, actarg); - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return (MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -882,76 +863,77 @@ int followup_glin(q, sq, v, action, actarg, cl) * argv[3] = ascii(quota) */ -int followup_gqot(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_gqot(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - register int j; - char **argv; - EXEC SQL BEGIN DECLARE SECTION; - int id; - char *name, *label; - EXEC SQL END DECLARE SECTION; - int status, idx; - - if (!strcmp(q->name, "get_quota") || - !strcmp(q->name, "get_quota_by_filesys")) - idx = 4; - else - idx = 3; - while (sq_get_data(sq, &argv)) { - if (idx == 4) { - switch (argv[1][0]) { + register int j; + char **argv; + EXEC SQL BEGIN DECLARE SECTION; + int id; + char *name, *label; + EXEC SQL END DECLARE SECTION; + int status, idx; + + if (!strcmp(q->name, "get_quota") || + !strcmp(q->name, "get_quota_by_filesys")) + idx = 4; + else + idx = 3; + while (sq_get_data(sq, &argv)) + { + if (idx == 4) + { + switch (argv[1][0]) + { case 'U': - status = id_to_name(atoi(argv[2]), USERS_TABLE, &argv[2]); - break; + status = id_to_name(atoi(argv[2]), USERS_TABLE, &argv[2]); + break; case 'G': case 'L': - status = id_to_name(atoi(argv[2]), LIST_TABLE, &argv[2]); - break; + status = id_to_name(atoi(argv[2]), LIST_TABLE, &argv[2]); + break; case 'A': - free(argv[2]); - argv[2] = strsave("system:anyuser"); - break; + free(argv[2]); + argv[2] = strsave("system:anyuser"); + break; default: - id = atoi(argv[2]); - argv[2] = malloc(8); - sprintf(argv[2], "%d", id); + id = atoi(argv[2]); + argv[2] = malloc(8); + sprintf(argv[2], "%d", id); } } - id = atoi(argv[idx]); - free(argv[idx]); - argv[idx] = malloc(256); - name = argv[idx]; - if (id == 0) { - label = argv[0]; - EXEC SQL SELECT name INTO :name FROM filesys - WHERE label = :label; - } else { - EXEC SQL SELECT dir INTO :name FROM nfsphys - WHERE nfsphys_id = :id; + id = atoi(argv[idx]); + free(argv[idx]); + argv[idx] = malloc(256); + name = argv[idx]; + if (id == 0) + { + label = argv[0]; + EXEC SQL SELECT name INTO :name FROM filesys + WHERE label = :label; } - if (sqlca.sqlerrd[2] != 1) { - sprintf(argv[idx], "#%d", id); + else + { + EXEC SQL SELECT dir INTO :name FROM nfsphys + WHERE nfsphys_id = :id; } - - id = atoi(argv[idx+3]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[idx+3]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[idx+3]); - if (status && status != MR_NO_MATCH) - return(status); - (*action)(q->vcnt, argv, actarg); - for (j = 0; j < q->vcnt; j++) - free(argv[j]); - free(argv); + if (sqlca.sqlerrd[2] != 1) + sprintf(argv[idx], "#%d", id); + + id = atoi(argv[idx + 3]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[idx + 3]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[idx + 3]); + if (status && status != MR_NO_MATCH) + return status; + (*action)(q->vcnt, argv, actarg); + for (j = 0; j < q->vcnt; j++) + free(argv[j]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } @@ -962,337 +944,340 @@ int followup_gqot(q, sq, v, action, actarg, cl) * argv[3 or 2] = ascii(quota) */ -int followup_aqot(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int followup_aqot(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int quota, id, fs, who, physid, table; - char *entity, *qtype, *tname; - EXEC SQL END DECLARE SECTION; - char incr_qual[60]; - char *incr_argv[2]; - int status; - - table=q->rtable; - tname=table_name[table]; - fs = *(int *)argv[0]; - EXEC SQL SELECT phys_id INTO :physid FROM filesys - WHERE filsys_id = :fs; - if(dbms_errno) - return(mr_errcode); - - if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot")) { - qtype = argv[1]; - id = *(int *)argv[2]; - quota = atoi(argv[3]); - sprintf(incr_qual,"q.filsys_id = %d",fs); - } else { - qtype = "USER"; - id = *(int *)argv[1]; - quota = atoi(argv[2]); - sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d", - fs,qtype,id); + EXEC SQL BEGIN DECLARE SECTION; + int quota, id, fs, who, physid, table; + char *entity, *qtype, *tname; + EXEC SQL END DECLARE SECTION; + char incr_qual[60]; + char *incr_argv[2]; + int status; + + table = q->rtable; + tname = table_name[table]; + fs = *(int *)argv[0]; + EXEC SQL SELECT phys_id INTO :physid FROM filesys + WHERE filsys_id = :fs; + if (dbms_errno) + return mr_errcode; + + if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot")) + { + qtype = argv[1]; + id = *(int *)argv[2]; + quota = atoi(argv[3]); + sprintf(incr_qual, "q.filsys_id = %d", fs); + } + else + { + qtype = "USER"; + id = *(int *)argv[1]; + quota = atoi(argv[2]); + sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND " + "q.entity_id = %d", fs, qtype, id); } - /* quota case of incremental_{before|after} only looks at slot 1 */ - incr_argv[1]=qtype; - - /* Follows one of many possible gross hacks to fix these particular - * conflicts between what is possible in the query table and what - * is possible in SQL. - */ - if(q->type==APPEND) { - incremental_clear_before(); - EXEC SQL INSERT INTO quota - (filsys_id, type, entity_id, quota, phys_id) - VALUES (:fs, NVL(:qtype,CHR(0)), :id, :quota, :physid); - incremental_after(table, incr_qual, incr_argv); - } else { - incremental_before(table, incr_qual, incr_argv); - EXEC SQL UPDATE quota SET quota = :quota - WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id; - status = mr_errcode; - incremental_after(table, incr_qual, incr_argv); + /* quota case of incremental_{before|after} only looks at slot 1 */ + incr_argv[1] = qtype; + + /* Follows one of many possible gross hacks to fix these particular + * conflicts between what is possible in the query table and what + * is possible in SQL. + */ + if (q->type == APPEND) + { + incremental_clear_before(); + EXEC SQL INSERT INTO quota + (filsys_id, type, entity_id, quota, phys_id) + VALUES (:fs, NVL(:qtype, CHR(0)), :id, :quota, :physid); + incremental_after(table, incr_qual, incr_argv); + } + else + { + incremental_before(table, incr_qual, incr_argv); + EXEC SQL UPDATE quota SET quota = :quota + WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id; + status = mr_errcode; + incremental_after(table, incr_qual, incr_argv); } - if (dbms_errno) - return(mr_errcode); - flush_name(argv[0], table); - if(q->type==APPEND) { - EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE - WHERE table_name = :tname; - } else { - EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE - WHERE table_name = :tname; + if (dbms_errno) + return mr_errcode; + flush_name(argv[0], table); + if (q->type == APPEND) + { + EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE + WHERE table_name = :tname; + } + else + { + EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE + WHERE table_name = :tname; } - - /* Proceed with original followup */ - who = cl->client_id; - entity = cl->entity; - - EXEC SQL UPDATE quota - SET modtime = SYSDATE, modby = :who, modwith = :entity - WHERE filsys_id = :fs and type = :qtype and entity_id = :id; - EXEC SQL UPDATE nfsphys SET allocated = allocated + :quota - WHERE nfsphys_id = :physid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + + /* Proceed with original followup */ + who = cl->client_id; + entity = cl->entity; + + EXEC SQL UPDATE quota + SET modtime = SYSDATE, modby = :who, modwith = :entity + WHERE filsys_id = :fs and type = :qtype and entity_id = :id; + EXEC SQL UPDATE nfsphys SET allocated = allocated + :quota + WHERE nfsphys_id = :physid; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } /* Necessitated by the requirement of a correlation name by the incremental - * routines, since query table deletes don't provide one. + * routines, since query table deletes don't provide one. */ -int followup_dqot(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int followup_dqot(struct query *q, char **argv, client *cl) { - char *qtype; - int id, fs, table; - char *incr_argv[2]; - EXEC SQL BEGIN DECLARE SECTION; - char incr_qual[80], *tname; - EXEC SQL END DECLARE SECTION; - - table=q->rtable; - tname=table_name[table]; - fs = *(int *)argv[0]; - if (!strcmp(q->shortname, "dqot")) { - qtype = argv[1]; - id = *(int *)argv[2]; - } else { - qtype = "USER"; - id = *(int *)argv[1]; + char *qtype; + int id, fs, table; + char *incr_argv[2]; + EXEC SQL BEGIN DECLARE SECTION; + char incr_qual[80], *tname; + EXEC SQL END DECLARE SECTION; + + table = q->rtable; + tname = table_name[table]; + fs = *(int *)argv[0]; + if (!strcmp(q->shortname, "dqot")) + { + qtype = argv[1]; + id = *(int *)argv[2]; + } + else + { + qtype = "USER"; + id = *(int *)argv[1]; } - sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d", - fs,qtype,id); + sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND q.entity_id = %d", + fs, qtype, id); - /* quota case of incremental_{before|after} only looks at slot 1 */ - incr_argv[1]=qtype; + /* quota case of incremental_{before|after} only looks at slot 1 */ + incr_argv[1] = qtype; - incremental_before(table, incr_qual, incr_argv); - EXEC SQL DELETE FROM quota q WHERE q.filsys_id=:fs AND q.type=:qtype - AND q.entity_id=:id; - incremental_clear_after(); + incremental_before(table, incr_qual, incr_argv); + EXEC SQL DELETE FROM quota q WHERE q.filsys_id = :fs AND q.type = :qtype + AND q.entity_id = :id; + incremental_clear_after(); - if (dbms_errno) - return(mr_errcode); - flush_name(argv[0], table); + if (dbms_errno) + return mr_errcode; + flush_name(argv[0], table); - EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = SYSDATE - WHERE table_name = :tname; - return(MR_SUCCESS); + EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = SYSDATE + WHERE table_name = :tname; + return MR_SUCCESS; } -int followup_gpce(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_gpce(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - register int i, j; - char **argv; - int id, status; - - i = q->vcnt - 2; - while (sq_get_data(sq, &argv)) { - id = atoi(argv[PCAP_QSERVER]); - status = id_to_name(id, MACHINE_TABLE, &argv[PCAP_QSERVER]); - if (status) return (status); - id = atoi(argv[i]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - (*action)(q->vcnt, argv, actarg); - for (j = 0; j < q->vcnt; j++) - free(argv[j]); - free(argv); + register int i, j; + char **argv; + int id, status; + + i = q->vcnt - 2; + while (sq_get_data(sq, &argv)) + { + id = atoi(argv[PCAP_QSERVER]); + status = id_to_name(id, MACHINE_TABLE, &argv[PCAP_QSERVER]); + if (status) + return status; + id = atoi(argv[i]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + (*action)(q->vcnt, argv, actarg); + for (j = 0; j < q->vcnt; j++) + free(argv[j]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } /* followup_gzcl: */ -int followup_gzcl(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_gzcl(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - int id, i, status; - char **argv; - - while (sq_get_data(sq, &argv)) { - mr_trim_args(q->vcnt, argv); - - id = atoi(argv[i = q->vcnt - 2]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[i]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[i]); - if (status && status != MR_NO_MATCH) - return(status); - - for (i = 1; i < 8; i+=2) { - id = atoi(argv[i+1]); - if (!strcmp(argv[i], "LIST")) { - status = id_to_name(id, LIST_TABLE, &argv[i+1]); - } else if (!strcmp(argv[i], "USER")) { - status = id_to_name(id, USERS_TABLE, &argv[i+1]); - } else if (!strcmp(argv[i], "KERBEROS")) { - status = id_to_name(id, STRINGS_TABLE, &argv[i+1]); - } else if (!strcmp(argv[i], "NONE")) { - status = 0; - free(argv[i+1]); - argv[i+1] = strsave("NONE"); - } else { - status = 0; - free(argv[i+1]); - argv[i+1] = strsave("???"); + int id, i, status; + char **argv; + + while (sq_get_data(sq, &argv)) + { + mr_trim_args(q->vcnt, argv); + + id = atoi(argv[i = q->vcnt - 2]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[i]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[i]); + if (status && status != MR_NO_MATCH) + return status; + + for (i = 1; i < 8; i += 2) + { + id = atoi(argv[i + 1]); + if (!strcmp(argv[i], "LIST")) + status = id_to_name(id, LIST_TABLE, &argv[i + 1]); + else if (!strcmp(argv[i], "USER")) + status = id_to_name(id, USERS_TABLE, &argv[i + 1]); + else if (!strcmp(argv[i], "KERBEROS")) + status = id_to_name(id, STRINGS_TABLE, &argv[i + 1]); + else if (!strcmp(argv[i], "NONE")) + { + status = 0; + free(argv[i + 1]); + argv[i + 1] = strsave("NONE"); } - if (status && status != MR_NO_MATCH) - return(status); + else + { + status = 0; + free(argv[i + 1]); + argv[i + 1] = strsave("???"); + } + if (status && status != MR_NO_MATCH) + return status; } - /* send the data */ - (*action)(q->vcnt, argv, actarg); + /* send the data */ + (*action)(q->vcnt, argv, actarg); - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } /* followup_gsha: */ -int followup_gsha(q, sq, v, action, actarg, cl) - struct query *q; - struct save_queue *sq; - struct validate *v; - int (*action)(), actarg; - client *cl; +int followup_gsha(struct query *q, struct save_queue *sq, struct validate *v, + int (*action)(), int actarg, client *cl) { - char **argv; - int i, id, status; - - while (sq_get_data(sq, &argv)) { - mr_trim_args(q->vcnt, argv); - - id = atoi(argv[4]); - if (id > 0) - status = id_to_name(id, USERS_TABLE, &argv[4]); - else - status = id_to_name(-id, STRINGS_TABLE, &argv[4]); - if (status && status != MR_NO_MATCH) - return(status); - - id = atoi(argv[2]); - if (!strcmp(argv[1], "LIST")) { - status = id_to_name(id, LIST_TABLE, &argv[2]); - } else if (!strcmp(argv[1], "USER")) { - status = id_to_name(id, USERS_TABLE, &argv[2]); - } else if (!strcmp(argv[1], "KERBEROS")) { - status = id_to_name(id, STRINGS_TABLE, &argv[2]); - } else if (!strcmp(argv[1], "NONE")) { - status = 0; - free(argv[2]); - argv[2] = strsave("NONE"); - } else { - status = 0; - free(argv[2]); - argv[2] = strsave("???"); + char **argv; + int i, id, status; + + while (sq_get_data(sq, &argv)) + { + mr_trim_args(q->vcnt, argv); + + id = atoi(argv[4]); + if (id > 0) + status = id_to_name(id, USERS_TABLE, &argv[4]); + else + status = id_to_name(-id, STRINGS_TABLE, &argv[4]); + if (status && status != MR_NO_MATCH) + return status; + + id = atoi(argv[2]); + if (!strcmp(argv[1], "LIST")) + status = id_to_name(id, LIST_TABLE, &argv[2]); + else if (!strcmp(argv[1], "USER")) + status = id_to_name(id, USERS_TABLE, &argv[2]); + else if (!strcmp(argv[1], "KERBEROS")) + status = id_to_name(id, STRINGS_TABLE, &argv[2]); + else if (!strcmp(argv[1], "NONE")) + { + status = 0; + free(argv[2]); + argv[2] = strsave("NONE"); + } + else + { + status = 0; + free(argv[2]); + argv[2] = strsave("???"); } - if (status && status != MR_NO_MATCH) - return(status); + if (status && status != MR_NO_MATCH) + return status; - /* send the data */ - (*action)(q->vcnt, argv, actarg); + /* send the data */ + (*action)(q->vcnt, argv, actarg); - /* free saved data */ - for (i = 0; i < q->vcnt; i++) - free(argv[i]); - free(argv); + /* free saved data */ + for (i = 0; i < q->vcnt; i++) + free(argv[i]); + free(argv); } - sq_destroy(sq); - return(MR_SUCCESS); + sq_destroy(sq); + return MR_SUCCESS; } -int _sdl_followup(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int _sdl_followup(struct query *q, char *argv[], client *cl) { - int i; - i = atoi(argv[0]); - log_flags = i; - - if (i & LOG_SQL) { - EXEC SQL ALTER SESSION SET SQL_TRACE TRUE; - } else { - EXEC SQL ALTER SESSION SET SQL_TRACE FALSE; - } - - return(MR_SUCCESS); + int i; + i = atoi(argv[0]); + log_flags = i; + + if (i & LOG_SQL) + EXEC SQL ALTER SESSION SET SQL_TRACE TRUE; + else + EXEC SQL ALTER SESSION SET SQL_TRACE FALSE; + + return MR_SUCCESS; } -static void hex_dump(p) - unsigned char *p; +static void hex_dump(unsigned char *p) { - fprintf(stderr, "Size: %d\n", strlen(p)); - while (strlen(p) >= 8) { - fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - p += 8; + fprintf(stderr, "Size: %d\n", strlen(p)); + while (strlen(p) >= 8) + { + fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); + p += 8; } - switch (strlen(p)) { + switch (strlen(p)) + { case 7: - fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5], p[6]); - break; + fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6]); + break; case 6: - fprintf(stderr, "%02x %02x %02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3], p[4], p[5]); - break; + fprintf(stderr, "%02x %02x %02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3], p[4], p[5]); + break; case 5: - fprintf(stderr, "%02x %02x %02x %02x %02x\n", + fprintf(stderr, "%02x %02x %02x %02x %02x\n", p[0], p[1], p[2], p[3], p[4]); - break; + break; case 4: - fprintf(stderr, "%02x %02x %02x %02x\n", - p[0], p[1], p[2], p[3]); + fprintf(stderr, "%02x %02x %02x %02x\n", + p[0], p[1], p[2], p[3]); break; case 3: - fprintf(stderr, "%02x %02x %02x\n", - p[0], p[1], p[2]); - break; + fprintf(stderr, "%02x %02x %02x\n", + p[0], p[1], p[2]); + break; case 2: - fprintf(stderr, "%02x %02x\n", - p[0], p[1]); - break; + fprintf(stderr, "%02x %02x\n", + p[0], p[1]); + break; case 1: - fprintf(stderr, "%02x\n", - p[0]); - break; + fprintf(stderr, "%02x\n", + p[0]); + break; default: - return; + return; } } diff --git a/server/qrtn.h b/server/qrtn.h index 5f5b0261..6a97dc35 100644 --- a/server/qrtn.h +++ b/server/qrtn.h @@ -1,5 +1,5 @@ -/* $Header$ - * +/* $Header$ + * * Used by the SQL query routines of the Moira server. */ diff --git a/server/qrtn.pc b/server/qrtn.pc index 1801bac9..f111c39f 100644 --- a/server/qrtn.pc +++ b/server/qrtn.pc @@ -6,7 +6,7 @@ * Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . - * + * */ #ifndef lint @@ -22,12 +22,12 @@ EXEC SQL INCLUDE sqlda; /* SQL Descriptor Area */ #include "qrtn.h" SQLDA *mr_sqlda; -EXEC SQL BEGIN DECLARE SECTION; +EXEC SQL BEGIN DECLARE SECTION; int mr_sig_length; -int idummy; -char cdummy[MR_CDUMMY_LEN]; +int idummy; +char cdummy[MR_CDUMMY_LEN]; char stmt_buf[MR_STMTBUF_LEN]; -EXEC SQL END DECLARE SECTION; +EXEC SQL END DECLARE SECTION; char *Argv[QMAXARGS]; extern char *table_name[]; @@ -35,7 +35,7 @@ extern char *sqlbuffer[QMAXARGS]; int dbms_errno = 0; int mr_errcode = 0; -EXEC SQL BEGIN DECLARE SECTION; +EXEC SQL BEGIN DECLARE SECTION; int query_timeout = 30; char *database = "moira"; EXEC SQL END DECLARE SECTION; @@ -66,19 +66,19 @@ int validate_row(struct query *q, char *argv[], struct validate *v); void dbmserr(void) { - EXEC SQL BEGIN DECLARE SECTION; - char err_msg[256]; - EXEC SQL END DECLARE SECTION; - int bufsize=256, msglength=0; - - dbms_errno = -sqlca.sqlcode; - mr_errcode = MR_DBMS_ERR; - com_err(whoami, MR_DBMS_ERR, " code %d\n", dbms_errno); - sqlglm(err_msg, &bufsize, &msglength); - err_msg[msglength]=0; - com_err(whoami, 0, "SQL error text = %s", err_msg); - critical_alert("MOIRA", "Moira server encountered DBMS ERROR %d\n%s", - dbms_errno, err_msg); + EXEC SQL BEGIN DECLARE SECTION; + char err_msg[256]; + EXEC SQL END DECLARE SECTION; + int bufsize = 256, msglength = 0; + + dbms_errno = -sqlca.sqlcode; + mr_errcode = MR_DBMS_ERR; + com_err(whoami, MR_DBMS_ERR, " code %d\n", dbms_errno); + sqlglm(err_msg, &bufsize, &msglength); + err_msg[msglength] = 0; + com_err(whoami, 0, "SQL error text = %s", err_msg); + critical_alert("MOIRA", "Moira server encountered DBMS ERROR %d\n%s", + dbms_errno, err_msg); } /* This is declarative, not executed. Applies from here on, in this file. */ @@ -86,359 +86,403 @@ EXEC SQL WHENEVER SQLERROR DO dbmserr(); int mr_open_database(void) { - register int i; - SQLDA *mr_alloc_sqlda(); - static first_open = 1; + register int i; + SQLDA *mr_alloc_sqlda(); + static first_open = 1; - if (first_open) { - first_open = 0; + if (first_open) + { + first_open = 0; - /* initialize local argv */ - for (i = 0; i < 16; i++) - Argv[i] = malloc(ARGLEN); + /* initialize local argv */ + for (i = 0; i < 16; i++) + Argv[i] = malloc(ARGLEN); - mr_sqlda = mr_alloc_sqlda(); + mr_sqlda = mr_alloc_sqlda(); - incremental_init(); - flush_cache(); + incremental_init(); + flush_cache(); } - - dbms_errno = 0; - mr_errcode = 0; - /* open the database */ - EXEC SQL CONNECT :database IDENTIFIED BY :database; + dbms_errno = 0; + mr_errcode = 0; - if(dbms_errno) - return(mr_errcode); + /* open the database */ + EXEC SQL CONNECT :database IDENTIFIED BY :database; - EXEC SQL SELECT data_length INTO :mr_sig_length FROM user_tab_columns WHERE table_name='USERS' and column_name='SIGNATURE'; - EXEC SQL COMMIT WORK; - if(dbms_errno) - return(mr_errcode); + if (dbms_errno) + return mr_errcode; - return(MR_SUCCESS); + EXEC SQL SELECT data_length INTO :mr_sig_length FROM user_tab_columns + WHERE table_name = 'USERS' and column_name = 'SIGNATURE'; + EXEC SQL COMMIT WORK; + if (dbms_errno) + return mr_errcode; + + return MR_SUCCESS; } void mr_close_database(void) { - flush_cache(); - EXEC SQL COMMIT RELEASE; + flush_cache(); + EXEC SQL COMMIT RELEASE; } -int mr_check_access(cl, name, argc, argv_ro) - client *cl; - char *name, *argv_ro[]; - int argc; +int mr_check_access(client *cl, char *name, int argc, char *argv_ro[]) { - struct query *q; + struct query *q; - dbms_errno = 0; - mr_errcode = 0; + dbms_errno = 0; + mr_errcode = 0; - q = get_query_by_name(name, cl->args->mr_version_no); - if (q == (struct query *)0) - return(MR_NO_HANDLE); + q = get_query_by_name(name, cl->args->mr_version_no); + if (!q) + return MR_NO_HANDLE; - return(mr_verify_query(cl, q, argc, argv_ro)); + return mr_verify_query(cl, q, argc, argv_ro); } -int mr_process_query(cl, name, argc, argv_ro, action, actarg) - client *cl; - char *name, *argv_ro[], *actarg; - int argc, (*action)(); +int mr_process_query(client *cl, char *name, int argc, char *argv_ro[], + int (*action)(), char *actarg) { - register struct query *q; - register int status; - register struct validate *v; - char qual[256]; - char sort[32]; - char *pqual; - char *psort; - EXEC SQL BEGIN DECLARE SECTION; - char *table; - EXEC SQL END DECLARE SECTION; - struct save_queue *sq; - - dbms_errno = 0; - mr_errcode = 0; - - /* list queries command */ - if (!strcmp(name, "_list_queries")) { - list_queries(cl->args->mr_version_no, action, actarg); - return(MR_SUCCESS); - } + register struct query *q; + register int status; + register struct validate *v; + char qual[256]; + char sort[32]; + char *pqual; + char *psort; + EXEC SQL BEGIN DECLARE SECTION; + char *table; + EXEC SQL END DECLARE SECTION; + struct save_queue *sq; + + dbms_errno = 0; + mr_errcode = 0; - /* help query command */ - if (!strcmp(name, "_help")) { - if (argc < 1) - return(MR_ARGS); - q = get_query_by_name(argv_ro[0], cl->args->mr_version_no); - if (q == (struct query *)0) return(MR_NO_HANDLE); - help_query(q, action, actarg); - return(MR_SUCCESS); + /* list queries command */ + if (!strcmp(name, "_list_queries")) + { + list_queries(cl->args->mr_version_no, action, actarg); + return MR_SUCCESS; } - /* get query structure, return error if named query does not exist */ - q = get_query_by_name(name, cl->args->mr_version_no); - if (q == (struct query *)0) return(MR_NO_HANDLE); - v = q->validate; + /* help query command */ + if (!strcmp(name, "_help")) + { + if (argc < 1) + return MR_ARGS; + q = get_query_by_name(argv_ro[0], cl->args->mr_version_no); + if (!q) + return MR_NO_HANDLE; + help_query(q, action, actarg); + return MR_SUCCESS; + } - /* setup argument vector, verify access and arguments */ - if ((status = mr_verify_query(cl, q, argc, argv_ro)) != MR_SUCCESS) + /* get query structure, return error if named query does not exist */ + q = get_query_by_name(name, cl->args->mr_version_no); + if (!q) + return MR_NO_HANDLE; + v = q->validate; + + /* setup argument vector, verify access and arguments */ + if ((status = mr_verify_query(cl, q, argc, argv_ro)) != MR_SUCCESS) + goto out; + + /* perform any special query pre-processing */ + if (v && v->pre_rtn) + { + status = (*v->pre_rtn)(q, Argv, cl, 0); + if (status != MR_SUCCESS) goto out; - - /* perform any special query pre-processing */ - if (v && v->pre_rtn) { - status = (*v->pre_rtn)(q, Argv, cl, 0); - if (status != MR_SUCCESS) - goto out; } - switch (q->type) { + switch (q->type) + { case RETRIEVE: - /* for queries that do not permit wildcarding, check if row - uniquely exists */ - if (v && v->field) { - status = validate_row(q, Argv, v); - if (status != MR_EXISTS) break; + /* for queries that do not permit wildcarding, check if row + uniquely exists */ + if (v && v->field) + { + status = validate_row(q, Argv, v); + if (status != MR_EXISTS) + break; } - /* build "where" clause if needed */ - if (q->qual) { - build_qual(q->qual, q->argc, Argv, qual); - pqual = qual; - } else { - pqual = 0; + /* build "where" clause if needed */ + if (q->qual) + { + build_qual(q->qual, q->argc, Argv, qual); + pqual = qual; } - - /* build "sort" clause if needed */ - if (v && v->valobj) { - psort = build_sort(v, sort); - } else { - psort = 0; - } - - /* if there is a followup routine, then we must save the results */ - /* of the first query for use by the followup routine */ - /* if q->rvar = NULL, perform post_rtn only */ - if (q->rvar) { - if (v && v->post_rtn) { - sq = sq_create(); - status = do_retrieve(q, pqual, psort, sq_save_args, - (char *)sq); - if (status != MR_SUCCESS) { - sq_destroy(sq); - break; + else + pqual = 0; + + /* build "sort" clause if needed */ + if (v && v->valobj) + psort = build_sort(v, sort); + else + psort = 0; + + /* if there is a followup routine, then we must save the results */ + /* of the first query for use by the followup routine */ + /* if q->rvar = NULL, perform post_rtn only */ + if (q->rvar) + { + if (v && v->post_rtn) + { + sq = sq_create(); + status = do_retrieve(q, pqual, psort, sq_save_args, (char *)sq); + if (status != MR_SUCCESS) + { + sq_destroy(sq); + break; } - status = (*v->post_rtn)(q, sq, v, action, actarg, cl); - } else { - /* normal retrieve */ - status = do_retrieve(q, pqual, psort, action, actarg); + status = (*v->post_rtn)(q, sq, v, action, actarg, cl); + } + else + { + /* normal retrieve */ + status = do_retrieve(q, pqual, psort, action, actarg); } - if (status != MR_SUCCESS) break; - } else { - status = (*v->post_rtn)(q, Argv, cl, action, actarg); + if (status != MR_SUCCESS) + break; } + else + status = (*v->post_rtn)(q, Argv, cl, action, actarg); - break; + break; case UPDATE: - /* see if row already exists */ - if (v->field) { - status = validate_row(q, Argv, v); - if (status != MR_EXISTS) break; + /* see if row already exists */ + if (v->field) + { + status = validate_row(q, Argv, v); + if (status != MR_EXISTS) + break; } - /* build "where" clause and perform update */ - /* if q->rvar = NULL, perform post_rtn only */ - if (q->rvar) { - build_qual(q->qual, q->argc, Argv, qual); - incremental_before(q->rtable, qual, argv_ro); - status = do_update(q, &Argv[q->argc], qual, action, actarg); - incremental_after(q->rtable, qual, argv_ro); - if (status != MR_SUCCESS) break; - flush_name(argv_ro[0], q->rtable); - table = table_name[q->rtable]; - if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif")) { - EXEC SQL UPDATE tblstats - SET updates = updates + 1, modtime = SYSDATE - WHERE table_name = :table; + /* build "where" clause and perform update */ + /* if q->rvar = NULL, perform post_rtn only */ + if (q->rvar) + { + build_qual(q->qual, q->argc, Argv, qual); + incremental_before(q->rtable, qual, argv_ro); + status = do_update(q, &Argv[q->argc], qual, action, actarg); + incremental_after(q->rtable, qual, argv_ro); + if (status != MR_SUCCESS) + break; + flush_name(argv_ro[0], q->rtable); + table = table_name[q->rtable]; + if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif")) + { + EXEC SQL UPDATE tblstats + SET updates = updates + 1, modtime = SYSDATE + WHERE table_name = :table; } } - /* execute followup routine (if any) */ - if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl); + /* execute followup routine (if any) */ + if (v->post_rtn) + status = (*v->post_rtn)(q, Argv, cl); - break; + break; case APPEND: - /* see if row already exists */ - if (v->field) { - status = validate_row(q, Argv, v); - if (status != MR_NO_MATCH) break; + /* see if row already exists */ + if (v->field) + { + status = validate_row(q, Argv, v); + if (status != MR_NO_MATCH) + break; } - /* build "where" clause if needed */ - if (q->qual) { - build_qual(q->qual, q->argc, Argv, qual); - pqual = qual; - } else { - pqual = 0; + /* build "where" clause if needed */ + if (q->qual) + { + build_qual(q->qual, q->argc, Argv, qual); + pqual = qual; } + else + pqual = 0; + + /* perform the append */ + /* if q->rvar = NULL, perform post_rtn only */ + if (q->rvar) + { + incremental_clear_before(); + status = do_append(q, &Argv[q->argc], pqual, action, actarg); + if (status != MR_SUCCESS) + break; + if (v && v->object_id) + { + sprintf(qual, "%s.%s = %s", q->rvar, v->object_id, + Argv[q->argc + q->vcnt]); + incremental_after(q->rtable, qual, argv_ro); + } + else + incremental_after(q->rtable, pqual, argv_ro); - /* perform the append */ - /* if q->rvar = NULL, perform post_rtn only */ - if (q->rvar) { - incremental_clear_before(); - status = do_append(q, &Argv[q->argc], pqual, action, actarg); - if (status != MR_SUCCESS) break; - if (v && v->object_id) { - sprintf(qual, "%s.%s = %s",q->rvar, v->object_id, - Argv[q->argc+q->vcnt]); - incremental_after(q->rtable, qual, argv_ro); - } else - incremental_after(q->rtable, pqual, argv_ro); - - table = table_name[q->rtable]; - EXEC SQL UPDATE tblstats - SET appends = appends + 1, modtime = SYSDATE - WHERE table_name = :table; + table = table_name[q->rtable]; + EXEC SQL UPDATE tblstats + SET appends = appends + 1, modtime = SYSDATE + WHERE table_name = :table; } - - /* execute followup routine */ - if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl); - break; + + /* execute followup routine */ + if (v->post_rtn) + status = (*v->post_rtn)(q, Argv, cl); + break; case DELETE: - /* see if row already exists */ - if (v->field) { - status = validate_row(q, Argv, v); - if (status != MR_EXISTS) break; + /* see if row already exists */ + if (v->field) + { + status = validate_row(q, Argv, v); + if (status != MR_EXISTS) + break; } - /* build "where" clause and perform delete */ - /* if q->rvar = NULL, perform post_rtn only */ - if (q->rvar) { - build_qual(q->qual, q->argc, Argv, qual); - table = table_name[q->rtable]; - incremental_before(q->rtable, qual, argv_ro); - status = do_delete(q, qual, action, actarg); - incremental_clear_after(); - if (status != MR_SUCCESS) break; - flush_name(argv_ro[0], q->rtable); - EXEC SQL UPDATE tblstats - SET deletes = deletes + 1, modtime = SYSDATE - WHERE table_name = :table; + /* build "where" clause and perform delete */ + /* if q->rvar = NULL, perform post_rtn only */ + if (q->rvar) + { + build_qual(q->qual, q->argc, Argv, qual); + table = table_name[q->rtable]; + incremental_before(q->rtable, qual, argv_ro); + status = do_delete(q, qual, action, actarg); + incremental_clear_after(); + if (status != MR_SUCCESS) + break; + flush_name(argv_ro[0], q->rtable); + EXEC SQL UPDATE tblstats + SET deletes = deletes + 1, modtime = SYSDATE + WHERE table_name = :table; } - /* execute followup routine */ - if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl); - break; - + /* execute followup routine */ + if (v->post_rtn) + status = (*v->post_rtn)(q, Argv, cl); + break; } out: - if (status == MR_SUCCESS && dbms_errno != 0) { - com_err(whoami, MR_INTERNAL, "Server didn't notice DBMS ERROR %d", - dbms_errno); - status = mr_errcode; + if (status == MR_SUCCESS && dbms_errno != 0) + { + com_err(whoami, MR_INTERNAL, "Server didn't notice DBMS ERROR %d", + dbms_errno); + status = mr_errcode; } - if (q->type == RETRIEVE) { - EXEC SQL COMMIT WORK; - } else { - if (status == MR_SUCCESS) { - EXEC SQL COMMIT WORK; - if (journal) { - char buf[1024]; - int i; - extern time_t now; - - fprintf(journal, "%% %s %s %s", - cl->clname, cl->entity, ctime(&now)); - fprintf(journal, "%s[%d] ", q->name, cl->args->mr_version_no); - for (i = 0; i < argc; i++) { - if (i != 0) { - putc(' ', journal); - } - requote(buf, argv_ro[i], sizeof(buf)); - fputs(buf, journal); + if (q->type == RETRIEVE) + EXEC SQL COMMIT WORK; + else + { + if (status == MR_SUCCESS) + { + EXEC SQL COMMIT WORK; + if (journal) + { + char buf[1024]; + int i; + extern time_t now; + + fprintf(journal, "%% %s %s %s", + cl->clname, cl->entity, ctime(&now)); + fprintf(journal, "%s[%d] ", q->name, cl->args->mr_version_no); + for (i = 0; i < argc; i++) + { + if (i != 0) + putc(' ', journal); + requote(buf, argv_ro[i], sizeof(buf)); + fputs(buf, journal); } - putc('\n', journal); - fflush(journal); + putc('\n', journal); + fflush(journal); } - incremental_update(); - } else { - cache_abort(); - EXEC SQL ROLLBACK WORK; - incremental_flush(); + incremental_update(); + } + else + { + cache_abort(); + EXEC SQL ROLLBACK WORK; + incremental_flush(); } } - cache_commit(); /* commit following abort is safe */ + cache_commit(); /* commit following abort is safe */ - if (status != MR_SUCCESS && log_flags & LOG_RES) - com_err(whoami, status, " (Query failed)"); - return(status); + if (status != MR_SUCCESS && log_flags & LOG_RES) + com_err(whoami, status, " (Query failed)"); + return status; } -int build_qual(fmt_buf, argc, argv, qual) - char *fmt_buf, *argv[], *qual; - int argc; +int build_qual(char *fmt_buf, int argc, char *argv[], char *qual) { - char *res, *fmt; - - for(res=qual, fmt=fmt_buf; *fmt; fmt++) { - if(*fmt=='%') { - if(*++fmt) { - switch(*fmt) { - case '%': /* %% -> % */ - *res++ = *fmt; - break; - case 's': - if(*argv[0]) { - char *p=*argv; - while(*p) { - if(*p=='\'') *res++='\''; /* double the ' */ - *res++=*p++; + char *res, *fmt; + + for (res = qual, fmt = fmt_buf; *fmt; fmt++) + { + if (*fmt == '%') + { + if (*++fmt) + { + switch (*fmt) + { + case '%': /* %% -> % */ + *res++ = *fmt; + break; + case 's': + if (*argv[0]) + { + char *p = *argv; + while (*p) + { + if (*p == '\'') + *res++ = '\''; /* double the ' */ + *res++ = *p++; } } - argv++; - break; - case 'd': - res+=sprintf(res,"%d",*(int *)*argv++); - break; - default: /* Swallow other %? pairs */ + argv++; + break; + case 'd': + res += sprintf(res, "%d", *(int *)*argv++); + break; + default: /* Swallow other %? pairs */ break; } - } else break; - } else *res++ = *fmt; /* text -> result buffer */ + } + else + break; + } + else + *res++ = *fmt; /* text -> result buffer */ } - *res='\0'; + *res = '\0'; } -char *build_sort(v, sort) - struct validate *v; - char *sort; +char *build_sort(struct validate *v, char *sort) { - register struct valobj *vo; - register int n; - char elem[16]; - - n = v->objcnt; - vo = v->valobj; - *sort = 0; - - while (--n >= 0) { - if (vo->type == V_SORT) { - sprintf(elem, "%d", vo->index + 1); /* Result column number */ - if (*sort) strcat(sort, ", "); - strcat(sort, elem); + register struct valobj *vo; + register int n; + char elem[16]; + + n = v->objcnt; + vo = v->valobj; + *sort = '\0'; + + while (--n >= 0) + { + if (vo->type == V_SORT) + { + sprintf(elem, "%d", vo->index + 1); /* Result column number */ + if (*sort) + strcat(sort, ", "); + strcat(sort, elem); } - vo++; + vo++; } - return ((*sort) ? sort : 0); + return (*sort) ? sort : 0; } @@ -446,61 +490,63 @@ char *build_sort(v, sort) int privileged; -int mr_verify_query(cl, q, argc, argv_ro) - client *cl; - struct query *q; - int argc; - char *argv_ro[]; +int mr_verify_query(client *cl, struct query *q, int argc, char *argv_ro[]) { - register int argreq; - register int status; - register struct validate *v = q->validate; - register int i; - register char *to,*fr,*stop; - - privileged = 0; - - /* check argument count */ - argreq = q->argc; - if (q->type == UPDATE || q->type == APPEND) argreq += q->vcnt; - if (argc != argreq) return(MR_ARGS); - - /* copy the arguments into a local argv that we can modify */ - for (i = 0; i < argc; i++) { - for (to=Argv[i], fr=argv_ro[i], stop=to+ARGLEN; (*fr) && (tovalidate; + register int i; + register char *to, *fr, *stop; + + privileged = 0; + + /* check argument count */ + argreq = q->argc; + if (q->type == UPDATE || q->type == APPEND) + argreq += q->vcnt; + if (argc != argreq) + return MR_ARGS; + + /* copy the arguments into a local argv that we can modify */ + for (i = 0; i < argc; i++) + { + for (to = Argv[i], fr = argv_ro[i], stop = to + ARGLEN; (*fr) && (to < stop);) + *to++ = *fr++; + + if (*fr) + return MR_ARG_TOO_LONG; + *to = '\0'; + + if (*--to == '\\') + return MR_BAD_CHAR; } - /* check initial query access */ - status = check_query_access(q, Argv, cl); - if (status != MR_SUCCESS && status != MR_PERM) - return(status); - if (status == MR_SUCCESS) - privileged++; - - /* validate arguments */ - if (v && v->valobj) { - status = validate_fields(q, Argv, v->valobj, v->objcnt); - if (status != MR_SUCCESS) return(status); + /* check initial query access */ + status = check_query_access(q, Argv, cl); + if (status != MR_SUCCESS && status != MR_PERM) + return status; + if (status == MR_SUCCESS) + privileged++; + + /* validate arguments */ + if (v && v->valobj) + { + status = validate_fields(q, Argv, v->valobj, v->objcnt); + if (status != MR_SUCCESS) + return status; } - /* perform special query access check */ - if (!privileged && v && v->acs_rtn) { - status = (*v->acs_rtn)(q, Argv, cl); - if (status != MR_SUCCESS && status != MR_PERM) - return(status); - if (status == MR_SUCCESS) - return(MR_SUCCESS); + /* perform special query access check */ + if (!privileged && v && v->acs_rtn) + { + status = (*v->acs_rtn)(q, Argv, cl); + if (status != MR_SUCCESS && status != MR_PERM) + return status; + if (status == MR_SUCCESS) + return MR_SUCCESS; } - return(privileged ? MR_SUCCESS : MR_PERM); + return privileged ? MR_SUCCESS : MR_PERM; } @@ -508,254 +554,275 @@ int mr_verify_query(cl, q, argc, argv_ro) * in the query structure, and whether that acl contains everybody. */ -int check_query_access(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int check_query_access(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *name; - int acl_id; - static int def_uid; - EXEC SQL END DECLARE SECTION; - - /* initialize default uid */ - if (def_uid == 0) { - EXEC SQL SELECT users_id INTO :def_uid FROM users WHERE login='default'; - } + EXEC SQL BEGIN DECLARE SECTION; + char *name; + int acl_id; + static int def_uid; + EXEC SQL END DECLARE SECTION; - /* get query access control list */ - if (q->acl != 0) - acl_id = q->acl; - else { - name = q->shortname; - EXEC SQL SELECT list_id INTO :acl_id FROM capacls WHERE tag = :name; - if (sqlca.sqlcode < 0) return(MR_DBMS_ERR); - if (sqlca.sqlcode == SQL_NO_MATCH) return(MR_PERM); - q->acl = acl_id; - - /* check for default access */ - EXEC SQL SELECT member_id INTO :acl_id FROM imembers - WHERE list_id = :acl_id AND member_type = 'USER' - AND member_id = :def_uid; - if (sqlca.sqlerrd[2] == 0) - q->everybody = 0; - else - q->everybody = 1; + /* initialize default uid */ + if (def_uid == 0) + EXEC SQL SELECT users_id INTO :def_uid FROM users WHERE login = 'default'; + + /* get query access control list */ + if (q->acl != 0) + acl_id = q->acl; + else + { + name = q->shortname; + EXEC SQL SELECT list_id INTO :acl_id FROM capacls WHERE tag = :name; + if (sqlca.sqlcode < 0) + return MR_DBMS_ERR; + if (sqlca.sqlcode == SQL_NO_MATCH) + return MR_PERM; + q->acl = acl_id; + + /* check for default access */ + EXEC SQL SELECT member_id INTO :acl_id FROM imembers + WHERE list_id = :acl_id AND member_type = 'USER' + AND member_id = :def_uid; + if (sqlca.sqlerrd[2] == 0) + q->everybody = 0; + else + q->everybody = 1; } - if (q->everybody) - return(MR_SUCCESS); + if (q->everybody) + return MR_SUCCESS; - if (find_member("LIST", acl_id, cl)) - return(MR_SUCCESS); - else - return(MR_PERM); + if (find_member("LIST", acl_id, cl)) + return MR_SUCCESS; + else + return MR_PERM; } -int find_member(list_type, list_id, cl) - char *list_type; - int list_id; - client *cl; +int find_member(char *list_type, int list_id, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int flag, users_id, client_id; - EXEC SQL END DECLARE SECTION; - - if (!strcmp(strtrim(list_type), "USER") && - list_id == cl->users_id) - return(1); - - if (!strcmp(strtrim(list_type), "KERBEROS") && - list_id == -cl->client_id) - return(1); - - /* see if client is a member of list */ - flag = 0; - users_id = cl->users_id; - client_id = -cl->client_id; - EXEC SQL SELECT COUNT(member_id) INTO :flag FROM imembers - WHERE list_id = :list_id - AND ( ( member_type = 'USER' AND member_id = :users_id ) - OR (member_type = 'KERBEROS' AND member_id = :client_id ) ); - if (sqlca.sqlcode == 0) - return(flag); - return(0); + EXEC SQL BEGIN DECLARE SECTION; + int flag, users_id, client_id; + EXEC SQL END DECLARE SECTION; + + if (!strcmp(strtrim(list_type), "USER") && list_id == cl->users_id) + return 1; + + if (!strcmp(strtrim(list_type), "KERBEROS") && list_id == -cl->client_id) + return 1; + + /* see if client is a member of list */ + flag = 0; + users_id = cl->users_id; + client_id = -cl->client_id; + EXEC SQL SELECT COUNT(member_id) INTO :flag FROM imembers + WHERE list_id = :list_id + AND ( ( member_type = 'USER' AND member_id = :users_id ) + OR (member_type = 'KERBEROS' AND member_id = :client_id ) ); + if (sqlca.sqlcode == 0) + return flag; + return 0; } -int do_retrieve(q, pqual, psort, action, actarg) - struct query *q; - char *pqual, *psort, *actarg; - int (*action)(); +int do_retrieve(struct query *q, char *pqual, char *psort, + int (*action)(), char *actarg) { - build_sql_stmt(stmt_buf,"SELECT",q->tlist,NULL,pqual); - if(psort) { - strcat(stmt_buf," ORDER BY "); - strcat(stmt_buf,psort); + build_sql_stmt(stmt_buf, "SELECT", q->tlist, NULL, pqual); + if (psort) + { + strcat(stmt_buf, " ORDER BY "); + strcat(stmt_buf, psort); } - return do_for_all_rows(stmt_buf, q->vcnt, action, (int)actarg); + return do_for_all_rows(stmt_buf, q->vcnt, action, (int)actarg); } -char *sqlstrstr(str, pat) - char *str, *pat; +char *sqlstrstr(char *str, char *pat) { - register char *p=pat; - - do { - if(*str=='\'') { /* Skip over single-quote delimited substrings */ - while(*++str && (*str!='\'')) - ; - continue; + register char *p = pat; + + do + { + if (*str == '\'') /* Skip over single-quote delimited substrings */ + { + while (*++str && (*str != '\'')) + ; + continue; } - if(*str==*p) { - register char *s; - s=str; - while(*++p && (*++s==*p)) - ; - if(*p) p=pat; /* failed */ + if (*str == *p) + { + register char *s; + s = str; + while (*++p && (*++s == *p)) + ; + if (*p) + p = pat; /* failed */ } - } while(*p && *++str); + } + while (*p && *++str); - if(!*str) str=NULL; - return(str); + if (!*str) + str = NULL; + return str; } -void optimize_sql_stmt(buf) - char *buf; +void optimize_sql_stmt(char *buf) { - char *point=buf, *pat, *eopat, *esc1, *esc2, *csr; - - for(point=buf; point=sqlstrstr(point,"LIKE"); point++) { - /* Now pointing to string "LIKE" */ - - /* Look at next word */ - for(pat=point+4; *pat==' '; pat++) ; - - /* Is it a single-quote delimited string? */ - if(*pat!='\'') continue; - - /* look for "escape" clause - save escape character */ - /* 1. Find end of pattern */ - for(eopat=pat+1; 1; eopat++) { - if(*eopat=='\'') { - if(eopat[1]=='\'') /* single-quote is self-escaping */ - eopat++; - else - break; + char *point = buf, *pat, *eopat, *esc1, *esc2, *csr; + + for (point = buf; point = sqlstrstr(point, "LIKE"); point++) + { + /* Now pointing to string "LIKE" */ + + /* Look at next word */ + for (pat = point + 4; *pat == ' '; pat++) + ; + + /* Is it a single-quote delimited string? */ + if (*pat != '\'') + continue; + + /* look for "escape" clause - save escape character */ + /* 1. Find end of pattern */ + for (eopat = pat + 1; 1; eopat++) + { + if (*eopat == '\'') + { + if (eopat[1] == '\'') /* single-quote is self-escaping */ + eopat++; + else + break; } } - /* 2. Look at next word */ - for(esc1=eopat; *++esc1==' ';) ; + /* 2. Look at next word */ + for (esc1 = eopat; *++esc1 == ' ';) + ; - /* 3. esc1=0 if not "ESCAPE '?'", where the ? may be any character. */ - if(strncmp(esc1,"ESCAPE",6)) esc1=NULL; + /* 3. esc1 = 0 if not "ESCAPE '?'", where the ? may be any character. */ + if (strncmp(esc1, "ESCAPE", 6)) + esc1 = NULL; - if(esc1) { - for(esc2=esc1+6; *esc2==' '; esc2++) ; - - if(*esc2++!='\'') continue; /* Bad SQL syntax. Skip. */ - /* esc2 now points at the escape character itself */ - if(esc2[1]!='\'') continue; /* Weird escape string. Skip. */ - } else { - esc2="\\"; - } + if (esc1) + { + for (esc2 = esc1 + 6; *esc2 == ' '; esc2++) + ; - /* Is pattern free from special characters? */ - for(csr=pat; csr % */ - *res++ = *fmt; - break; - case 's': - if(*argv[0]) { - char *p=*argv; - while(*p) { - if(*p=='\'') *res++='\''; /* double the ' */ - *res++=*p++; + char fmt_buf[MR_STMTBUF_LEN]; + register char *res, *fmt; + + if (qual) + sprintf(fmt_buf, "%s %s WHERE %s", cmd, targetlist, qual); + else + sprintf(fmt_buf, "%s %s", cmd, targetlist); + + for (res = result_buf, fmt = fmt_buf; *fmt; fmt++) + { + if (*fmt == '%') + { + if (*++fmt) + { + switch (*fmt) + { + case '%': /* %% -> % */ + *res++ = *fmt; + break; + case 's': + if (*argv[0]) + { + char *p = *argv; + while (*p) + { + if (*p == '\'') + *res++ = '\''; /* double the ' */ + *res++ = *p++; } } - argv++; - break; - case 'd': - res+=sprintf(res,"%d",*(int *)*argv++); - break; - default: /* Swallow other %? pairs */ - break; + argv++; + break; + case 'd': + res += sprintf(res, "%d", *(int *)*argv++); + break; + default: /* Swallow other %? pairs */ + break; } - } else break; - } else *res++ = *fmt; /* text -> result buffer */ + } + else + break; + } + else + *res++ = *fmt; /* text -> result buffer */ } - *res='\0'; + *res = '\0'; - optimize_sql_stmt(result_buf); + optimize_sql_stmt(result_buf); } -int do_update(q, argv, qual, action, actarg) - struct query *q; - char *argv[], *qual, *actarg; - int (*action)(); +int do_update(struct query *q, char *argv[], char *qual, + int (*action)(), char *actarg) { - build_sql_stmt(stmt_buf,"UPDATE",q->tlist,argv,qual); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - if (mr_errcode) return(mr_errcode); - return(MR_SUCCESS); + build_sql_stmt(stmt_buf, "UPDATE", q->tlist, argv, qual); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + if (mr_errcode) + return mr_errcode; + return MR_SUCCESS; } -int do_append(q, argv, pqual, action, actarg) - struct query *q; - char *argv[], *pqual, *actarg; - int (*action)(); +int do_append(struct query *q, char *argv[], char *pqual, + int (*action)(), char *actarg) { - build_sql_stmt(stmt_buf,"INSERT",q->tlist,argv,pqual); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - if (mr_errcode) return(mr_errcode); - return(MR_SUCCESS); + build_sql_stmt(stmt_buf, "INSERT", q->tlist, argv, pqual); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + if (mr_errcode) + return mr_errcode; + return MR_SUCCESS; } -int do_delete(q, qual, action, actarg) - struct query *q; - char *qual, *actarg; - int (*action)(); +int do_delete(struct query *q, char *qual, int (*action)(), char *actarg) { - sprintf(stmt_buf,"DELETE FROM %s WHERE %s",table_name[q->rtable],qual); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - if (mr_errcode) return(mr_errcode); - return(MR_SUCCESS); + sprintf(stmt_buf, "DELETE FROM %s WHERE %s", table_name[q->rtable], qual); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + if (mr_errcode) + return mr_errcode; + return MR_SUCCESS; } @@ -771,43 +838,44 @@ int do_delete(q, qual, action, actarg) ** **/ -int set_next_object_id(object, table, limit) - char *object; - enum tables table; - int limit; +int set_next_object_id(char *object, enum tables table, int limit) { - EXEC SQL BEGIN DECLARE SECTION; - int value; - char *obj = object; - EXEC SQL END DECLARE SECTION; - int starting_value; - - EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :obj; - if (sqlca.sqlerrd[2] != 1) - return(MR_NO_ID); - - starting_value=value; - while (1) { - if (limit && value > MAX_ID_VALUE) - value = MIN_ID_VALUE; - - sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s=%d", - object,table_name[table],object,value); - dosql(sqlbuffer); - if (sqlca.sqlcode < 0) return(mr_errcode); - if (sqlca.sqlcode == SQL_NO_MATCH) break; - - value++; - if (limit && value == starting_value) { - com_err(whoami,0,"All id values have been used"); - return(MR_NO_ID); + EXEC SQL BEGIN DECLARE SECTION; + int value; + char *obj = object; + EXEC SQL END DECLARE SECTION; + int starting_value; + + EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :obj; + if (sqlca.sqlerrd[2] != 1) + return MR_NO_ID; + + starting_value = value; + while (1) + { + if (limit && value > MAX_ID_VALUE) + value = MIN_ID_VALUE; + + sprintf(stmt_buf, "SELECT %s FROM %s WHERE %s = %d", + object, table_name[table], object, value); + dosql(sqlbuffer); + if (sqlca.sqlcode < 0) + return mr_errcode; + if (sqlca.sqlcode == SQL_NO_MATCH) + break; + + value++; + if (limit && value == starting_value) + { + com_err(whoami, 0, "All id values have been used"); + return MR_NO_ID; } } - if (LOG_RES) - com_err(whoami, 0, "setting ID %s to %d", object, value); - EXEC SQL UPDATE numvalues SET value = :value WHERE name = :obj; - return(MR_SUCCESS); + if (LOG_RES) + com_err(whoami, 0, "setting ID %s to %d", object, value); + EXEC SQL UPDATE numvalues SET value = :value WHERE name = :obj; + return MR_SUCCESS; } @@ -815,47 +883,49 @@ int set_next_object_id(object, table, limit) * owns. Sets the kerberos ID and user ID. */ -int set_krb_mapping(name, login, ok, kid, uid) - char *name, *login; - int ok, *kid, *uid; +int set_krb_mapping(char *name, char *login, int ok, int *kid, int *uid) { - EXEC SQL BEGIN DECLARE SECTION; - int u_id, k_id; - char *krbname; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int u_id, k_id; + char *krbname; + EXEC SQL END DECLARE SECTION; - krbname = name; - *kid = 0; - *uid = 0; + krbname = name; + *kid = 0; + *uid = 0; - EXEC SQL SELECT km.users_id, km.string_id INTO :u_id, :k_id - FROM krbmap km, strings str - WHERE km.string_id = str.string_id AND str.string = :krbname; - EXEC SQL COMMIT WORK; + EXEC SQL SELECT km.users_id, km.string_id INTO :u_id, :k_id + FROM krbmap km, strings str + WHERE km.string_id = str.string_id AND str.string = :krbname; + EXEC SQL COMMIT WORK; - if (dbms_errno) return(mr_errcode); - - if (sqlca.sqlerrd[2] == 1) { /* rowcount */ - *kid = -k_id; - *uid = u_id; - return(MR_SUCCESS); - } + if (dbms_errno) + return mr_errcode; - if (name_to_id(name, STRINGS_TABLE, &k_id) == MR_SUCCESS) + if (sqlca.sqlerrd[2] == 1) + { *kid = -k_id; + *uid = u_id; + return MR_SUCCESS; + } + + if (name_to_id(name, STRINGS_TABLE, &k_id) == MR_SUCCESS) + *kid = -k_id; - if (!ok) { - *uid = *kid; - return(MR_SUCCESS); + if (!ok) + { + *uid = *kid; + return MR_SUCCESS; } - if (name_to_id(login, USERS_TABLE, uid) != MR_SUCCESS) - *uid = 0; + if (name_to_id(login, USERS_TABLE, uid) != MR_SUCCESS) + *uid = 0; - if (*kid == 0) - *kid = *uid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + if (*kid == 0) + *kid = *uid; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -865,91 +935,99 @@ int set_krb_mapping(name, login, ok, kid, uid) void sanity_check_queries(void) { - register int i; - int maxv = 0, maxa = 0; - extern int QueryCount2; - extern struct query Queries2[]; + register int i; + int maxv = 0, maxa = 0; + extern int QueryCount2; + extern struct query Queries2[]; -#define MAX(x,y) ((x) > (y) ? (x) : (y)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) - for (i = 0; i < QueryCount2; i++) { - maxv = MAX(maxv, Queries2[i].vcnt); - maxa = MAX(maxa, Queries2[i].argc); + for (i = 0; i < QueryCount2; i++) + { + maxv = MAX(maxv, Queries2[i].vcnt); + maxa = MAX(maxa, Queries2[i].argc); } - if (MAX(maxv, maxa) > QMAXARGS) { - com_err(whoami, 0, "A query has more args than QMAXARGS"); - exit(1); + if (MAX(maxv, maxa) > QMAXARGS) + { + com_err(whoami, 0, "A query has more args than QMAXARGS"); + exit(1); } } /* Generically do a SELECT, storing the results in the provided buffers */ -void dosql(buffers) - char *buffers[]; +void dosql(char *buffers[]) { - int i, errcode=0, errlen; + int i, errcode = 0, errlen; EXEC SQL PREPARE inc_stmt FROM :stmt_buf; - if(sqlca.sqlcode) return; + if (sqlca.sqlcode) + return; EXEC SQL DECLARE inc_crs CURSOR FOR inc_stmt; EXEC SQL OPEN inc_crs; mr_sqlda->N = QMAXARGS; EXEC SQL DESCRIBE SELECT LIST FOR inc_stmt INTO mr_sqlda; mr_sqlda->N = mr_sqlda->F; - for(i=0; iN; i++) { - mr_sqlda->V[i]=buffers[i]; - mr_sqlda->T[i]=97; - mr_sqlda->L[i]=ARGLEN; - } + for (i = 0; i < mr_sqlda->N; i++) + { + mr_sqlda->V[i] = buffers[i]; + mr_sqlda->T[i] = 97; + mr_sqlda->L[i] = ARGLEN; + } EXEC SQL FETCH inc_crs USING DESCRIPTOR mr_sqlda; /* if we got an error from the FETCH, we have to preserve it or the close will reset it and the caller will think nothing happened */ - if(sqlca.sqlcode) { - errcode=sqlca.sqlcode; - errlen=sqlca.sqlerrm.sqlerrml; - } + if (sqlca.sqlcode) + { + errcode = sqlca.sqlcode; + errlen = sqlca.sqlerrm.sqlerrml; + } EXEC SQL CLOSE inc_crs; - if(errcode) { - sqlca.sqlcode=errcode; - sqlca.sqlerrm.sqlerrml=errlen; - } + if (errcode) + { + sqlca.sqlcode = errcode; + sqlca.sqlerrm.sqlerrml = errlen; + } } -int do_for_all_rows(query, count, action, actarg) - char *query; - int count, (*action)(), actarg; +int do_for_all_rows(char *query, int count, int (*action)(), int actarg) { - int i, rowcount=0; + int i, rowcount = 0; EXEC SQL BEGIN DECLARE SECTION; char *q = query; EXEC SQL END DECLARE SECTION; EXEC SQL PREPARE stmt FROM :q; - if(sqlca.sqlcode) return; + if (sqlca.sqlcode) + return; EXEC SQL DECLARE curs CURSOR FOR stmt; EXEC SQL OPEN curs; mr_sqlda->N = count; EXEC SQL DESCRIBE SELECT LIST FOR stmt INTO mr_sqlda; mr_sqlda->N = mr_sqlda->F; - for(i=0; iN; i++) { - mr_sqlda->V[i]=sqlbuffer[i]; - mr_sqlda->T[i]=97; - mr_sqlda->L[i]=ARGLEN; - } - - while(1) { - EXEC SQL FETCH curs USING DESCRIPTOR mr_sqlda; - if(sqlca.sqlcode != 0) break; - (*action)(count, sqlbuffer, actarg); - rowcount++; - } + for (i = 0; i < mr_sqlda->N; i++) + { + mr_sqlda->V[i] = sqlbuffer[i]; + mr_sqlda->T[i] = 97; + mr_sqlda->L[i] = ARGLEN; + } + + while (1) + { + EXEC SQL FETCH curs USING DESCRIPTOR mr_sqlda; + if (sqlca.sqlcode) + break; + (*action)(count, sqlbuffer, actarg); + rowcount++; + } EXEC SQL CLOSE curs; - - if (mr_errcode) return(mr_errcode); - return ((rowcount == 0) ? MR_NO_MATCH : MR_SUCCESS); + + if (mr_errcode) + return mr_errcode; + return (rowcount == 0) ? MR_NO_MATCH : MR_SUCCESS; } diff --git a/server/qsetup.pc b/server/qsetup.pc index 9ffe9caa..417fd86d 100644 --- a/server/qsetup.pc +++ b/server/qsetup.pc @@ -47,37 +47,34 @@ int check_nfs(int mach_idx, char *name, char *access); * - if argv[0] == UNIQUE_LOGIN then set argv[0] = "#" */ -int setup_ausr(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int setup_ausr(struct query *q, char *argv[], client *cl) { - int row, err; - EXEC SQL BEGIN DECLARE SECTION; - int nuid; - EXEC SQL END DECLARE SECTION; - - if (!strcmp(q->shortname, "uusr") || !strcmp(q->shortname, "uuac")) - row = 2; - else - row = 1; - if (!strcmp(argv[row], UNIQUE_UID) || atoi(argv[row]) == -1) { - if ((err=set_next_object_id("unix_uid", USERS_TABLE, 1))) - return(err); - EXEC SQL SELECT value INTO :nuid FROM numvalues WHERE name = 'unix_uid'; - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - sprintf(argv[row], "%d", nuid); + int row, err; + EXEC SQL BEGIN DECLARE SECTION; + int nuid; + EXEC SQL END DECLARE SECTION; + + if (!strcmp(q->shortname, "uusr") || !strcmp(q->shortname, "uuac")) + row = 2; + else + row = 1; + if (!strcmp(argv[row], UNIQUE_UID) || atoi(argv[row]) == -1) + { + if ((err = set_next_object_id("unix_uid", USERS_TABLE, 1))) + return err; + EXEC SQL SELECT value INTO :nuid FROM numvalues WHERE name = 'unix_uid'; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + sprintf(argv[row], "%d", nuid); } - if (!strcmp(argv[0], UNIQUE_LOGIN) || atoi(argv[row]) == -1) { - sprintf(argv[0], "#%s", argv[row]); - } + if (!strcmp(argv[0], UNIQUE_LOGIN) || atoi(argv[row]) == -1) + sprintf(argv[0], "#%s", argv[row]); - if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) - return(mr_errcode); + if ((mr_errcode = prefetch_value(q, argv, cl)) != MR_SUCCESS) + return mr_errcode; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -85,96 +82,90 @@ int setup_ausr(q, argv, cl) * and may safely be deleted. */ -int setup_dusr(q, argv) - struct query *q; - char **argv; +int setup_dusr(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int flag, id, cnt; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - - /* For now, only allow users to be deleted if their status is 0 */ - EXEC SQL SELECT status INTO :flag FROM users - WHERE users_id = :id; - if (flag != 0 && flag != 4) - return(MR_IN_USE); - - EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type='USER'; - EXEC SQL DELETE FROM krbmap WHERE users_id = :id; - EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers - WHERE member_id = :id AND member_type = 'USER'; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(label) INTO :cnt FROM filesys - WHERE owner = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(name) INTO :cnt FROM list - WHERE acl_id = :id AND acl_type = 'USER'; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(name) INTO :cnt FROM servers - WHERE acl_id = :id AND acl_type = 'USER'; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(acl_id) INTO :cnt FROM hostaccess - WHERE acl_id = :id AND acl_type = 'USER'; - if (cnt > 0) - return(MR_IN_USE); - if (dbms_errno) - return(mr_errcode); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int flag, id, cnt; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + + /* For now, only allow users to be deleted if their status is 0 */ + EXEC SQL SELECT status INTO :flag FROM users WHERE users_id = :id; + if (flag != 0 && flag != 4) + return MR_IN_USE; + + EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type = 'USER'; + EXEC SQL DELETE FROM krbmap WHERE users_id = :id; + EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers + WHERE member_id = :id AND member_type = 'USER'; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(label) INTO :cnt FROM filesys + WHERE owner = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(name) INTO :cnt FROM list + WHERE acl_id = :id AND acl_type = 'USER'; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(name) INTO :cnt FROM servers + WHERE acl_id = :id AND acl_type = 'USER'; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(acl_id) INTO :cnt FROM hostaccess + WHERE acl_id = :id AND acl_type = 'USER'; + if (cnt > 0) + return MR_IN_USE; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } /* setup_spop: verify that there is already a valid POP machine_id in the * pop_id field. Also take care of keeping track of the post office usage. */ -int setup_spop(q, argv) - struct query *q; - char **argv; +int setup_spop(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int id, mid; - char type[9]; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - EXEC SQL SELECT potype, pop_id INTO :type, :mid FROM users - WHERE users_id = :id; - if(sqlca.sqlerrd[2] = 0) - return(MR_MACHINE); - EXEC SQL SELECT mach_id INTO :mid FROM machine - WHERE mach_id = :mid; - if (sqlca.sqlerrd[2] = 0) - return(MR_MACHINE); - if (strcmp(strtrim(type), "POP")) - set_pop_usage(mid, 1); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, mid; + char type[9]; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + EXEC SQL SELECT potype, pop_id INTO :type, :mid FROM users + WHERE users_id = :id; + if (sqlca.sqlerrd[2] = 0) + return MR_MACHINE; + EXEC SQL SELECT mach_id INTO :mid FROM machine + WHERE mach_id = :mid; + if (sqlca.sqlerrd[2] = 0) + return MR_MACHINE; + if (strcmp(strtrim(type), "POP")) + set_pop_usage(mid, 1); + return MR_SUCCESS; } /* setup_dpob: Take care of keeping track of the post office usage. */ -int setup_dpob(q, argv) - struct query *q; - char **argv; +int setup_dpob(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int id, user; - char type[9]; - EXEC SQL END DECLARE SECTION; - - user = *(int *)argv[0]; - EXEC SQL SELECT potype, pop_id INTO :type, :id FROM users - WHERE users_id = :user; - if (dbms_errno) return(mr_errcode); - - if (!strcmp(strtrim(type), "POP")) - set_pop_usage(id, -1); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, user; + char type[9]; + EXEC SQL END DECLARE SECTION; + + user = *(int *)argv[0]; + EXEC SQL SELECT potype, pop_id INTO :type, :id FROM users + WHERE users_id = :user; + if (dbms_errno) + return mr_errcode; + + if (!strcmp(strtrim(type), "POP")) + set_pop_usage(id, -1); + return MR_SUCCESS; } @@ -182,56 +173,55 @@ int setup_dpob(q, argv) * and may safely be deleted. */ -int setup_dmac(q, argv) - struct query *q; - char **argv; +int setup_dmac(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int flag, id, cnt; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - - EXEC SQL SELECT status INTO :flag FROM machine - WHERE mach_id = :id; - if (flag != 3) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(login) INTO :cnt FROM users - WHERE potype='POP' AND pop_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM serverhosts - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM nfsphys - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM hostaccess - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM printcap - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(quotaserver) INTO :cnt FROM printcap - WHERE quotaserver = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM palladium - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM hostalias - WHERE mach_id = :id; - if (cnt > 0) - return(MR_IN_USE); - - EXEC SQL DELETE FROM mcmap WHERE mach_id = :id; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int flag, id, cnt; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + + EXEC SQL SELECT status INTO :flag FROM machine + WHERE mach_id = :id; + if (flag != 3) + return MR_IN_USE; + EXEC SQL SELECT COUNT(login) INTO :cnt FROM users + WHERE potype = 'POP' AND pop_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM serverhosts + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM nfsphys + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM hostaccess + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM printcap + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(quotaserver) INTO :cnt FROM printcap + WHERE quotaserver = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM palladium + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM hostalias + WHERE mach_id = :id; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL DELETE FROM mcmap WHERE mach_id = :id; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -239,20 +229,18 @@ int setup_dmac(q, argv) * and may safely be deleted. */ -int setup_dsnt(q, argv) - struct query *q; - char **argv; +int setup_dsnt(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int id, cnt = 0; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM machine - WHERE snet_id = :id; - if (cnt > 0) - return(MR_IN_USE); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, cnt = 0; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM machine + WHERE snet_id = :id; + if (cnt > 0) + return MR_IN_USE; + return MR_SUCCESS; } @@ -260,26 +248,24 @@ int setup_dsnt(q, argv) * and may safely be deleted. */ -int setup_dclu(q, argv) - struct query *q; - char **argv; +int setup_dclu(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int id, cnt; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM mcmap - WHERE clu_id = :id; - if (cnt > 0) - return(MR_IN_USE); - EXEC SQL SELECT COUNT(clu_id) INTO :cnt FROM svc - WHERE clu_id = :id; - if (cnt > 0) - return(MR_IN_USE); - if (dbms_errno) - return(mr_errcode); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, cnt; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM mcmap + WHERE clu_id = :id; + if (cnt > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(clu_id) INTO :cnt FROM svc + WHERE clu_id = :id; + if (cnt > 0) + return MR_IN_USE; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -292,61 +278,63 @@ int setup_dclu(q, argv) */ static int badlistchars[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ - 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* 0 - ? */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ - O */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* P - _ */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ + 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* 0 - ? */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ - O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* P - _ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; -int setup_alis(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int setup_alis(struct query *q, char *argv[], client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int ngid; - EXEC SQL END DECLARE SECTION; - unsigned char *p; - int idx, err; - - if (!strcmp(q->shortname, "alis")) - idx = 0; - else if (!strcmp(q->shortname, "ulis")) - idx = 1; - - for (p = (unsigned char *) argv[idx]; *p; p++) + EXEC SQL BEGIN DECLARE SECTION; + int ngid; + EXEC SQL END DECLARE SECTION; + unsigned char *p; + int idx, err; + + if (!strcmp(q->shortname, "alis")) + idx = 0; + else if (!strcmp(q->shortname, "ulis")) + idx = 1; + + for (p = (unsigned char *) argv[idx]; *p; p++) + { if (badlistchars[*p]) - return(MR_BAD_CHAR); - - if (!strcmp(argv[6 + idx], UNIQUE_GID) || atoi(argv[6 + idx]) == -1) { - if (atoi(argv[5 + idx])) { - if ((err=set_next_object_id("gid", LIST_TABLE, 1))) - return(err); - EXEC SQL SELECT value INTO :ngid FROM numvalues - WHERE name = 'gid'; - if (dbms_errno) return(mr_errcode); - sprintf(argv[6 + idx], "%d", ngid); - } else { - strcpy(argv[6 + idx], "-1"); + return MR_BAD_CHAR; + } + + if (!strcmp(argv[6 + idx], UNIQUE_GID) || atoi(argv[6 + idx]) == -1) + { + if (atoi(argv[5 + idx])) + { + if ((err = set_next_object_id("gid", LIST_TABLE, 1))) + return err; + EXEC SQL SELECT value INTO :ngid FROM numvalues + WHERE name = 'gid'; + if (dbms_errno) + return mr_errcode; + sprintf(argv[6 + idx], "%d", ngid); } + else + strcpy(argv[6 + idx], "-1"); } - if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) - return(mr_errcode); + if ((mr_errcode = prefetch_value(q, argv, cl)) != MR_SUCCESS) + return mr_errcode; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -354,59 +342,67 @@ int setup_alis(q, argv, cl) * and may safely be deleted. */ -int setup_dlis(q, argv) - struct query *q; - char *argv[]; +int setup_dlis(struct query *q, char **argv) { - int id; - EXEC SQL BEGIN DECLARE SECTION; - int cnt; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - - EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers - WHERE member_id = :id AND member_type='LIST'; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers - WHERE member_id = :id AND member_type='LIST'; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers - WHERE list_id = :id; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(label) INTO :cnt FROM filesys WHERE owners = :id; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(tag) INTO :cnt FROM capacls WHERE list_id = :id; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(name) INTO :cnt FROM list - WHERE acl_id = :id AND acl_type='LIST' AND list_id != :id; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(name) INTO :cnt FROM servers - WHERE acl_id = :id AND acl_type='LIST'; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(entity_id) INTO :cnt FROM quota - WHERE entity_id = :id AND type='GROUP'; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(acl_id) INTO :cnt FROM hostaccess - WHERE acl_id = :id AND acl_type='LIST'; - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT COUNT(class) INTO :cnt FROM zephyr z - WHERE z.xmt_type = 'LIST' AND z.xmt_id = :id - OR z.sub_type = 'LIST' AND z.sub_id = :id - OR z.iws_type = 'LIST' AND z.iws_id = :id - OR z.iui_type = 'LIST' AND z.iui_id = :id; - if(cnt>0) return MR_IN_USE; - - return(MR_SUCCESS); + int id; + EXEC SQL BEGIN DECLARE SECTION; + int cnt; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + + EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers + WHERE member_id = :id AND member_type = 'LIST'; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers + WHERE member_id = :id AND member_type = 'LIST'; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(member_id) INTO :cnt FROM imembers + WHERE list_id = :id; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(label) INTO :cnt FROM filesys WHERE owners = :id; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(tag) INTO :cnt FROM capacls WHERE list_id = :id; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(name) INTO :cnt FROM list + WHERE acl_id = :id AND acl_type = 'LIST' AND list_id != :id; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(name) INTO :cnt FROM servers + WHERE acl_id = :id AND acl_type = 'LIST'; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(entity_id) INTO :cnt FROM quota + WHERE entity_id = :id AND type = 'GROUP'; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(acl_id) INTO :cnt FROM hostaccess + WHERE acl_id = :id AND acl_type = 'LIST'; + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT COUNT(class) INTO :cnt FROM zephyr z + WHERE z.xmt_type = 'LIST' AND z.xmt_id = :id + OR z.sub_type = 'LIST' AND z.sub_id = :id + OR z.iws_type = 'LIST' AND z.iws_id = :id + OR z.iui_type = 'LIST' AND z.iui_id = :id; + if (cnt > 0) + return MR_IN_USE; + + return MR_SUCCESS; } @@ -414,28 +410,27 @@ int setup_dlis(q, argv) * and may safely be deleted. */ -int setup_dsin(q, argv) - struct query *q; - char **argv; +int setup_dsin(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int ec, cnt; - char *svrname; - EXEC SQL END DECLARE SECTION; - - svrname=argv[0]; - EXEC SQL SELECT COUNT(service) INTO :cnt FROM serverhosts - WHERE service = UPPER(:svrname); - if(cnt>0) return MR_IN_USE; - - EXEC SQL SELECT inprogress INTO :ec FROM servers - WHERE name=UPPER(:svrname); - if(dbms_errno) - return(mr_errcode); - if(ec) - return(MR_IN_USE); - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int ec, cnt; + char *svrname; + EXEC SQL END DECLARE SECTION; + + svrname = argv[0]; + EXEC SQL SELECT COUNT(service) INTO :cnt FROM serverhosts + WHERE service = UPPER(:svrname); + if (cnt > 0) + return MR_IN_USE; + + EXEC SQL SELECT inprogress INTO :ec FROM servers + WHERE name = UPPER(:svrname); + if (dbms_errno) + return mr_errcode; + if (ec) + return MR_IN_USE; + + return MR_SUCCESS; } @@ -443,27 +438,24 @@ int setup_dsin(q, argv) * and may safely be deleted. */ -int setup_dshi(q, argv) - struct query *q; - char **argv; +int setup_dshi(struct query *q, char **argv) { - EXEC SQL BEGIN DECLARE SECTION; - int id, ec; - char *svrname; - EXEC SQL END DECLARE SECTION; - - svrname=argv[0]; - id = *(int *)argv[1]; - - EXEC SQL SELECT inprogress INTO :ec FROM serverhosts - WHERE service=UPPER(:svrname) AND mach_id = :id; - if(dbms_errno) - return(mr_errcode); - if(ec) - return(MR_IN_USE); - - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, ec; + char *svrname; + EXEC SQL END DECLARE SECTION; + + svrname = argv[0]; + id = *(int *)argv[1]; + + EXEC SQL SELECT inprogress INTO :ec FROM serverhosts + WHERE service = UPPER(:svrname) AND mach_id = :id; + if (dbms_errno) + return mr_errcode; + if (ec) + return MR_IN_USE; + + return MR_SUCCESS; } @@ -497,37 +489,36 @@ EXEC SQL BEGIN DECLARE SECTION; int _var_phys_id; EXEC SQL END DECLARE SECTION; -int setup_afil(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int setup_afil(struct query *q, char *argv[], client *cl) { - char *type, *name; - int mach_id; - EXEC SQL BEGIN DECLARE SECTION; - int ok; - char ftype[32], *rwaccess; - EXEC SQL END DECLARE SECTION; - - type = argv[1]; - mach_id = *(int *)argv[2]; - name = argv[3]; - rwaccess = argv[5]; - _var_phys_id = 0; - - sprintf(ftype, "fs_access_%s", type); - EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias - WHERE name = :ftype AND type = 'TYPE' and trans = :rwaccess; - if (dbms_errno) return(mr_errcode); - if (ok == 0) return(MR_FILESYS_ACCESS); - - if((mr_errcode=prefetch_value(q,argv,cl))!=MR_SUCCESS) - return(mr_errcode); - - if (!strcmp(type, "NFS")) - return (check_nfs(mach_id, name, rwaccess)); - - return(MR_SUCCESS); + char *type, *name; + int mach_id; + EXEC SQL BEGIN DECLARE SECTION; + int ok; + char ftype[32], *rwaccess; + EXEC SQL END DECLARE SECTION; + + type = argv[1]; + mach_id = *(int *)argv[2]; + name = argv[3]; + rwaccess = argv[5]; + _var_phys_id = 0; + + sprintf(ftype, "fs_access_%s", type); + EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias + WHERE name = :ftype AND type = 'TYPE' and trans = :rwaccess; + if (dbms_errno) + return mr_errcode; + if (ok == 0) + return MR_FILESYS_ACCESS; + + if ((mr_errcode = prefetch_value(q, argv, cl)) != MR_SUCCESS) + return mr_errcode; + + if (!strcmp(type, "NFS")) + return check_nfs(mach_id, name, rwaccess); + + return MR_SUCCESS; } @@ -536,69 +527,73 @@ int setup_afil(q, argv, cl) * the new phys_id. */ -int setup_ufil(q, argv, cl) - struct query *q; - char *argv[]; - client *cl; +int setup_ufil(struct query *q, char *argv[], client *cl) { - int mach_id, status; - char *type, *name; - EXEC SQL BEGIN DECLARE SECTION; - int fid, total, who, ok; - char *entity, ftype[32], *access; - short int total_null; - EXEC SQL END DECLARE SECTION; - - _var_phys_id = 0; - type = argv[2]; - mach_id = *(int *)argv[3]; - name = argv[4]; - access = argv[6]; - fid = *(int *)argv[0]; - who = cl->client_id; - entity = cl->entity; - - sprintf(ftype, "fs_access_%s", type); - EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias - WHERE name = :ftype AND type='TYPE' AND trans = :access; - if (dbms_errno) return(mr_errcode); - if (ok == 0) return(MR_FILESYS_ACCESS); - - EXEC SQL SELECT type INTO :ftype FROM filesys - WHERE filsys_id = :fid; - if (dbms_errno) return(mr_errcode); - - if (!strcmp(type, "NFS")) { - status = check_nfs(mach_id, name, access); - EXEC SQL UPDATE quota SET phys_id = :_var_phys_id - WHERE filsys_id = :fid; - if (dbms_errno) return(mr_errcode); - return(status); - } else if (!strcmp(type, "AFS") && strcmp(strtrim(ftype), "AFS") - && strcmp(strtrim(ftype), "ERR")) { - total = 0; - EXEC SQL DELETE FROM quota - WHERE type = 'ANY' AND filsys_id = :fid; - EXEC SQL SELECT SUM (quota) INTO :total:total_null FROM quota - WHERE filsys_id = :fid AND phys_id != 0; - if (dbms_errno) return(mr_errcode); - if (!total_null && (total != 0)) { -/* - * append quota (quota = total, filsys_id = fid, - * phys_id = 0, entity_id = 0, type = "ANY", - * modtime = "now", modby = who, modwith = entity) - */ - EXEC SQL INSERT INTO quota (quota, filsys_id, phys_id, entity_id, - type, modtime, modby, modwith) - VALUES (:total, :fid, 0, 0, - 'ANY', SYSDATE, :who, :entity) ; - if (dbms_errno) return(mr_errcode); + int mach_id, status; + char *type, *name; + EXEC SQL BEGIN DECLARE SECTION; + int fid, total, who, ok; + char *entity, ftype[32], *access; + short int total_null; + EXEC SQL END DECLARE SECTION; + + _var_phys_id = 0; + type = argv[2]; + mach_id = *(int *)argv[3]; + name = argv[4]; + access = argv[6]; + fid = *(int *)argv[0]; + who = cl->client_id; + entity = cl->entity; + + sprintf(ftype, "fs_access_%s", type); + EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias + WHERE name = :ftype AND type = 'TYPE' AND trans = :access; + if (dbms_errno) + return mr_errcode; + if (ok == 0) + return MR_FILESYS_ACCESS; + + EXEC SQL SELECT type INTO :ftype FROM filesys + WHERE filsys_id = :fid; + if (dbms_errno) + return mr_errcode; + + if (!strcmp(type, "NFS")) + { + status = check_nfs(mach_id, name, access); + EXEC SQL UPDATE quota SET phys_id = :_var_phys_id + WHERE filsys_id = :fid; + if (dbms_errno) + return mr_errcode; + return status; + } + else if (!strcmp(type, "AFS") && strcmp(strtrim(ftype), "AFS") + && strcmp(strtrim(ftype), "ERR")) + { + total = 0; + EXEC SQL DELETE FROM quota + WHERE type = 'ANY' AND filsys_id = :fid; + EXEC SQL SELECT SUM (quota) INTO :total:total_null FROM quota + WHERE filsys_id = :fid AND phys_id != 0; + if (dbms_errno) + return mr_errcode; + if (!total_null && (total != 0)) + { + EXEC SQL INSERT INTO quota (quota, filsys_id, phys_id, entity_id, + type, modtime, modby, modwith) + VALUES (:total, :fid, 0, 0, 'ANY', SYSDATE, :who, :entity); + if (dbms_errno) + return mr_errcode; } - } else { - EXEC SQL UPDATE quota SET phys_id = 0 WHERE filsys_id = :fid; - if (dbms_errno) return(mr_errcode); } - return(MR_SUCCESS); + else + { + EXEC SQL UPDATE quota SET phys_id = 0 WHERE filsys_id = :fid; + if (dbms_errno) + return mr_errcode; + } + return MR_SUCCESS; } @@ -608,46 +603,49 @@ int setup_ufil(q, argv, cl) * more than one, we sort the query in reverse order by dir name. */ -int check_nfs(mach_id, name, access) - int mach_id; - char *name, *access; +int check_nfs(int mach_id, char *name, char *access) { - EXEC SQL BEGIN DECLARE SECTION; - char dir[81]; - int mid = mach_id; - EXEC SQL END DECLARE SECTION; - register int status; - register char *cp1; - register char *cp2; - - status = MR_NFS; - EXEC SQL DECLARE csr101 CURSOR FOR - SELECT nfsphys_id, dir FROM nfsphys - WHERE mach_id = :mid - ORDER BY 2 DESC; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr101; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr101 INTO :_var_phys_id, :dir; - if(sqlca.sqlcode != 0) break; - cp1 = name; - cp2 = strtrim(dir); - while (*cp2) { - if (*cp1++ != *cp2) break; - cp2++; - } - if (*cp2 == 0) { - status = MR_SUCCESS; + EXEC SQL BEGIN DECLARE SECTION; + char dir[81]; + int mid = mach_id; + EXEC SQL END DECLARE SECTION; + register int status; + register char *cp1; + register char *cp2; + + status = MR_NFS; + EXEC SQL DECLARE csr101 CURSOR FOR + SELECT nfsphys_id, dir FROM nfsphys + WHERE mach_id = :mid + ORDER BY 2 DESC; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr101; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr101 INTO :_var_phys_id, :dir; + if (sqlca.sqlcode) + break; + cp1 = name; + cp2 = strtrim(dir); + while (*cp2) + { + if (*cp1++ != *cp2) break; + cp2++; + } + if (!*cp2) + { + status = MR_SUCCESS; + break; } } - EXEC SQL CLOSE csr101; - if (dbms_errno) - return(mr_errcode); - return(status); + EXEC SQL CLOSE csr101; + if (dbms_errno) + return mr_errcode; + return status; } @@ -655,35 +653,33 @@ int check_nfs(mach_id, name, access) * a filesystem when it is deleted. Also adjust the allocation numbers. */ -int setup_dfil(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_dfil(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id, total, phys_id; - short int none; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - EXEC SQL SELECT SUM (quota) INTO :total:none FROM quota - WHERE filsys_id = :id; - - if(none) total=0; - - /** What if there are multiple phys_id's per f/s? (bad data) **/ - EXEC SQL SELECT phys_id INTO :phys_id FROM filesys - WHERE filsys_id = :id; - EXEC SQL UPDATE nfsphys SET allocated = allocated - :total - WHERE nfsphys_id = :phys_id; - - if(!none) { - EXEC SQL DELETE FROM quota WHERE filsys_id = :id; - } - EXEC SQL DELETE FROM fsgroup WHERE filsys_id = :id; - EXEC SQL DELETE FROM fsgroup WHERE group_id = :id; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, total, phys_id; + short int none; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + EXEC SQL SELECT SUM (quota) INTO :total:none FROM quota + WHERE filsys_id = :id; + + if (none) + total = 0; + + /** What if there are multiple phys_id's per f/s? (bad data) **/ + EXEC SQL SELECT phys_id INTO :phys_id FROM filesys + WHERE filsys_id = :id; + EXEC SQL UPDATE nfsphys SET allocated = allocated - :total + WHERE nfsphys_id = :phys_id; + + if (!none) + EXEC SQL DELETE FROM quota WHERE filsys_id = :id; + EXEC SQL DELETE FROM fsgroup WHERE filsys_id = :id; + EXEC SQL DELETE FROM fsgroup WHERE group_id = :id; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -691,26 +687,23 @@ int setup_dfil(q, argv, cl) * any filesystems assigned to it before allowing it to be deleted. */ -int setup_dnfp(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_dnfp(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id, cnt; - char *dir; - EXEC SQL END DECLARE SECTION; - - id = *(int *)argv[0]; - dir = argv[1]; - EXEC SQL SELECT count(fs.rowid) INTO :cnt FROM filesys fs, nfsphys np - WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id - AND np.mach_id = :id AND np.dir = :dir; - if (cnt > 0) - return(MR_IN_USE); - if (dbms_errno) - return(mr_errcode); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int id, cnt; + char *dir; + EXEC SQL END DECLARE SECTION; + + id = *(int *)argv[0]; + dir = argv[1]; + EXEC SQL SELECT count(fs.rowid) INTO :cnt FROM filesys fs, nfsphys np + WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id + AND np.mach_id = :id AND np.dir = :dir; + if (cnt > 0) + return MR_IN_USE; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -720,34 +713,35 @@ int setup_dnfp(q, argv, cl) * argv[2 or 1] = users_id or list_id */ -int setup_dqot(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_dqot(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int quota, fs, id, physid; - char *qtype; - EXEC SQL END DECLARE SECTION; - - fs = *(int *)argv[0]; - if (!strcmp(q->name, "update_quota") || !strcmp(q->name, "delete_quota")) { - qtype = argv[1]; - id = *(int *)argv[2]; - } else { - qtype = "USER"; - id = *(int *)argv[1]; + EXEC SQL BEGIN DECLARE SECTION; + int quota, fs, id, physid; + char *qtype; + EXEC SQL END DECLARE SECTION; + + fs = *(int *)argv[0]; + if (!strcmp(q->name, "update_quota") || !strcmp(q->name, "delete_quota")) + { + qtype = argv[1]; + id = *(int *)argv[2]; + } + else + { + qtype = "USER"; + id = *(int *)argv[1]; } - EXEC SQL SELECT quota INTO :quota FROM quota - WHERE type = :qtype AND entity_id = :id AND filsys_id = :fs; - EXEC SQL SELECT phys_id INTO :physid FROM filesys - WHERE filsys_id = :fs; - EXEC SQL UPDATE nfsphys SET allocated = allocated - :quota - WHERE nfsphys_id = :physid; + EXEC SQL SELECT quota INTO :quota FROM quota + WHERE type = :qtype AND entity_id = :id AND filsys_id = :fs; + EXEC SQL SELECT phys_id INTO :physid FROM filesys + WHERE filsys_id = :fs; + EXEC SQL UPDATE nfsphys SET allocated = allocated - :quota + WHERE nfsphys_id = :physid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -755,25 +749,25 @@ int setup_dqot(q, argv, cl) * table if necessary. */ -int setup_akum(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_akum(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id; - char *name; - EXEC SQL END DECLARE SECTION; - - name = argv[1]; - if (name_to_id(name, STRINGS_TABLE, &id) != MR_SUCCESS) { - if (q->type != APPEND) return(MR_STRING); - id=add_string(name); - cache_entry(name, STRINGS_TABLE, id); + EXEC SQL BEGIN DECLARE SECTION; + int id; + char *name; + EXEC SQL END DECLARE SECTION; + + name = argv[1]; + if (name_to_id(name, STRINGS_TABLE, &id) != MR_SUCCESS) + { + if (q->type != APPEND) + return MR_STRING; + id = add_string(name); + cache_entry(name, STRINGS_TABLE, id); } - if (dbms_errno) return(mr_errcode); - *(int *)argv[1] = id; - return(MR_SUCCESS); + if (dbms_errno) + return mr_errcode; + *(int *)argv[1] = id; + return MR_SUCCESS; } @@ -782,41 +776,40 @@ int setup_akum(q, argv, cl) * It is a little hack to get around the fact that SQL doesn't let you * do something like INSERT INTO table (foo) VALUES (other_table.bar). * - * It is called from the query table as (*v->pre_rtn)(q,Argv,cl) or + * It is called from the query table as (*v->pre_rtn)(q, Argv, cl) or * from within a setup_...() routine with the appropriate arguments. * * Correct functioning of this routine may depend on the assumption * that this query is an APPEND. */ -int prefetch_value(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int prefetch_value(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *name = q->validate->object_id; - int value; - EXEC SQL END DECLARE SECTION; - int status, limit, argc; - - /* set next object id, limiting it if necessary */ - if(!strcmp(name, "unix_uid") || !strcmp(name, "gid")) - limit = 1; /* So far as I know, this isn't needed. Just CMA. */ - else - limit = 0; - if((status = set_next_object_id(name, q->rtable, limit)) != MR_SUCCESS) - return(status); - - /* fetch object id */ - EXEC SQL SELECT value INTO :value FROM numvalues WHERE name=:name; - if(dbms_errno) return(mr_errcode); - if(sqlca.sqlerrd[2] != 1) return(MR_INTERNAL); - - argc = q->argc + q->vcnt; /* end of Argv for APPENDs */ - sprintf(argv[argc],"%d",value); /** Could save this step by changing tlist from %s to %d **/ - - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + char *name = q->validate->object_id; + int value; + EXEC SQL END DECLARE SECTION; + int status, limit, argc; + + /* set next object id, limiting it if necessary */ + if (!strcmp(name, "unix_uid") || !strcmp(name, "gid")) + limit = 1; /* So far as I know, this isn't needed. Just CMA. */ + else + limit = 0; + if ((status = set_next_object_id(name, q->rtable, limit)) != MR_SUCCESS) + return status; + + /* fetch object id */ + EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :name; + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + + argc = q->argc + q->vcnt; /* end of Argv for APPENDs */ + sprintf(argv[argc], "%d", value); + + return MR_SUCCESS; } /* prefetch_filesys(): @@ -828,286 +821,327 @@ int prefetch_value(q, argv, cl) * Assumes the existence of a row where filsys_id = argv[0], since a * filesys label has already been resolved to a filsys_id. */ -int prefetch_filesys(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int prefetch_filesys(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int fid,phid; - EXEC SQL END DECLARE SECTION; - int argc; + EXEC SQL BEGIN DECLARE SECTION; + int fid, phid; + EXEC SQL END DECLARE SECTION; + int argc; - fid = *(int *)argv[0]; - EXEC SQL SELECT phys_id INTO :phid FROM filesys WHERE filsys_id = :fid; - if(dbms_errno) return(mr_errcode); + fid = *(int *)argv[0]; + EXEC SQL SELECT phys_id INTO :phid FROM filesys WHERE filsys_id = :fid; + if (dbms_errno) + return mr_errcode; - argc=q->argc+q->vcnt; - sprintf(argv[argc++],"%d",phid); - sprintf(argv[argc],"%d",fid); + argc = q->argc + q->vcnt; + sprintf(argv[argc++], "%d", phid); + sprintf(argv[argc], "%d", fid); - return(MR_SUCCESS); + return MR_SUCCESS; } /* setup_ahst(): */ -int setup_ahst(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_ahst(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *name; - int value, id, saddr, mask, high, low, cnt; - EXEC SQL END DECLARE SECTION; - int row; - struct in_addr addr; - extern int host_access_level, privileged; - - if (!strcmp(q->shortname, "uhst")) - row = 1; - else - row = 0; - - /* sanity check name: must start with a letter, contain only - * letters, numerals, and hyphen, and not end with a hyphen. - */ - if (row == 0 || strcmp(argv[1], cl->args->mr_argv[1])) { - char *p = argv[row]; - - if (!isalpha(*p)) return(MR_BAD_CHAR); - for (; *p; p++) { - if ((!isalnum(*p) && *p != '-' && *p != '.') || - (*p == '-' && p[1] == '.')) - return(MR_BAD_CHAR); + EXEC SQL BEGIN DECLARE SECTION; + char *name; + int value, id, saddr, mask, high, low, cnt; + EXEC SQL END DECLARE SECTION; + int row; + struct in_addr addr; + extern int host_access_level, privileged; + + if (!strcmp(q->shortname, "uhst")) + row = 1; + else + row = 0; + + /* sanity check name: must start with a letter, contain only + * letters, numerals, and hyphen, and not end with a hyphen. + */ + if (row == 0 || strcmp(argv[1], cl->args->mr_argv[1])) + { + char *p = argv[row]; + + if (!isalpha(*p)) + return MR_BAD_CHAR; + for (; *p; p++) + { + if ((!isalnum(*p) && *p != '-' && *p != '.') || + (*p == '-' && p[1] == '.')) + return MR_BAD_CHAR; } - if (*(p-1) == '-') return(MR_BAD_CHAR); + if (*(p - 1) == '-') + return MR_BAD_CHAR; } - /* sanity check host vendor: must start with a letter, contain only - * letters, numerals, and hyphen, and end with an alphanumeric. - */ - if (*argv[row+1] && (row == 0 || strcmp(argv[2], cl->args->mr_argv[2]))) { - char *p = argv[row+1]; - - if (!isalpha(*p)) return(MR_BAD_CHAR); - for (; *p; p++) { - if ((!isalnum(*p) && *p != '-' && *p != '.') || - (*p == '-' && p[1] == '.')) - return(MR_BAD_CHAR); + /* sanity check host vendor: must start with a letter, contain only + * letters, numerals, and hyphen, and end with an alphanumeric. + */ + if (*argv[row + 1] && (row == 0 || strcmp(argv[2], cl->args->mr_argv[2]))) + { + char *p = argv[row + 1]; + + if (!isalpha(*p)) + return MR_BAD_CHAR; + for (; *p; p++) + { + if ((!isalnum(*p) && *p != '-' && *p != '.') || + (*p == '-' && p[1] == '.')) + return MR_BAD_CHAR; } - if (!isalnum(*(p-1))) return(MR_BAD_CHAR); + if (!isalnum(*(p - 1))) + return MR_BAD_CHAR; } - /* sanity check host type: must start with a letter, contain only - * letters, numerals, and hyphen, and end with an alphanumeric. - */ - if (*argv[row+2] && (row == 0 || strcmp(argv[3], cl->args->mr_argv[3]))) { - char *p = argv[row+2]; - - if (!isalnum(*p)) return(MR_BAD_CHAR); - for (; *p; p++) { - if ((!isalnum(*p) && *p != '-' && *p != '.') || - (*p == '-' && p[1] == '.')) - return(MR_BAD_CHAR); + /* sanity check host type: must start with a letter, contain only + * letters, numerals, and hyphen, and end with an alphanumeric. + */ + if (*argv[row + 2] && (row == 0 || strcmp(argv[3], cl->args->mr_argv[3]))) + { + char *p = argv[row + 2]; + + if (!isalnum(*p)) + return MR_BAD_CHAR; + for (; *p; p++) + { + if ((!isalnum(*p) && *p != '-' && *p != '.') || + (*p == '-' && p[1] == '.')) + return MR_BAD_CHAR; } - if (!isalnum(*(p-1))) return(MR_BAD_CHAR); + if (!isalnum(*(p - 1))) + return MR_BAD_CHAR; } - /* sanity check host vendor: must start with a letter, contain only - * letters, numerals, and hyphen, and end with an hyphen alphanumeric. - */ - if (*argv[row+3] && (row == 0 || strcmp(argv[4], cl->args->mr_argv[4]))) { - char *p = argv[row+3]; - - if (!isalpha(*p)) return(MR_BAD_CHAR); - for (; *p; p++) { - if ((!isalnum(*p) && *p != '-' && *p != '.') || - (*p == '-' && p[1] == '.')) - return(MR_BAD_CHAR); + /* sanity check host vendor: must start with a letter, contain only + * letters, numerals, and hyphen, and end with an hyphen alphanumeric. + */ + if (*argv[row + 3] && (row == 0 || strcmp(argv[4], cl->args->mr_argv[4]))) + { + char *p = argv[row + 3]; + + if (!isalpha(*p)) + return MR_BAD_CHAR; + for (; *p; p++) + { + if ((!isalnum(*p) && *p != '-' && *p != '.') || + (*p == '-' && p[1] == '.')) + return MR_BAD_CHAR; } - if (!isalnum(*(p-1))) return(MR_BAD_CHAR); + if (!isalnum(*(p - 1))) + return MR_BAD_CHAR; } - /* check for duplicate name */ - name = argv[row]; - EXEC SQL SELECT count(mach_id) INTO :cnt FROM hostalias - WHERE name = :name; - if (dbms_errno) return(mr_errcode); - if (cnt != 0) return(MR_EXISTS); - - /* check address */ - if (!strcmp(argv[9+row], "unassigned")) - value = -1; - else if (!strcmp(argv[9+row], "unique")) { - if (*(int *)argv[8+row] == 0) - value = -1; - else - value = -2; - } else { - value = ntohl(inet_addr(argv[9+row])); - if (value == -1) return(MR_ADDRESS); + /* check for duplicate name */ + name = argv[row]; + EXEC SQL SELECT count(mach_id) INTO :cnt FROM hostalias + WHERE name = :name; + if (dbms_errno) + return mr_errcode; + if (cnt != 0) + return MR_EXISTS; + + /* check address */ + if (!strcmp(argv[9 + row], "unassigned")) + value = -1; + else if (!strcmp(argv[9 + row], "unique")) + { + if (*(int *)argv[8 + row] == 0) + value = -1; + else + value = -2; + } + else + { + value = ntohl(inet_addr(argv[9 + row])); + if (value == -1) + return MR_ADDRESS; } - if (value == 0) return(MR_ADDRESS); - if (value != -1) { - /* - * an address or unique was specified. - */ - id = *(int *)argv[8+row]; - EXEC SQL SELECT saddr, mask, high, low INTO :saddr, :mask, :high, :low - FROM subnet WHERE snet_id = :id; - if (dbms_errno) return(mr_errcode); - if (value != -2) { - /* - * someone specified an IP address for the host record - */ - if ((value & mask) != saddr) return(MR_ADDRESS); - /* - * run the address argument through inet_addr(). This - * has the effect that any out of bounds host addrs will - * be converted to a valid host addr. We do this now - * so that the uniqueness check works. We should also - * link in an inet_addr() that returns an error for - * this case. - */ - addr.s_addr=inet_addr(argv[9+row]); - name = inet_ntoa(addr); - EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine - WHERE address = :name; - if (dbms_errno) return(mr_errcode); - if (cnt > 0) { - /* - * make IP address is unique. If this a modify request - * (row == 1), then we expect one record to exist. - */ - if (row == 0 || row == 1 && cnt > 1) return(MR_ADDRESS); - if (row == 1 && cnt == 1) { - EXEC SQL SELECT mach_id INTO :id FROM machine - WHERE address = :name; - if (id != *(int *)argv[0]) return(MR_ADDRESS); + if (value == 0) + return MR_ADDRESS; + if (value != -1) + { + /* + * an address or unique was specified. + */ + id = *(int *)argv[8 + row]; + EXEC SQL SELECT saddr, mask, high, low INTO :saddr, :mask, :high, :low + FROM subnet WHERE snet_id = :id; + if (dbms_errno) + return mr_errcode; + if (value != -2) + { + /* + * someone specified an IP address for the host record + */ + if ((value & mask) != saddr) + return MR_ADDRESS; + /* + * run the address argument through inet_addr(). This + * has the effect that any out of bounds host addrs will + * be converted to a valid host addr. We do this now + * so that the uniqueness check works. We should also + * link in an inet_addr() that returns an error for + * this case. + */ + addr.s_addr = inet_addr(argv[9 + row]); + name = inet_ntoa(addr); + EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine + WHERE address = :name; + if (dbms_errno) + return mr_errcode; + if (cnt > 0) + { + /* + * make IP address is unique. If this a modify request + * (row == 1), then we expect one record to exist. + */ + if (row == 0 || row == 1 && cnt > 1) + return MR_ADDRESS; + if (row == 1 && cnt == 1) + { + EXEC SQL SELECT mach_id INTO :id FROM machine + WHERE address = :name; + if (id != *(int *)argv[0]) + return MR_ADDRESS; } } - } else { - /* - * a "unique" address was specified. Walk through the - * range specified in the network record, return - * error if no room left. - */ - for (id = low; id <= high; id++) { - if (((id & 0xff) == 0) || - ((id & 0xff) == 255)) - continue; - addr.s_addr = htonl(id); - name = (char *)inet_ntoa(addr); - EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine - WHERE address = :name; - if (dbms_errno) return(mr_errcode); - if (cnt == 0) break; + } + else + { + /* + * a "unique" address was specified. Walk through the + * range specified in the network record, return + * error if no room left. + */ + for (id = low; id <= high; id++) + { + if (((id & 0xff) == 0) || ((id & 0xff) == 255)) + continue; + addr.s_addr = htonl(id); + name = (char *)inet_ntoa(addr); + EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine + WHERE address = :name; + if (dbms_errno) + return mr_errcode; + if (cnt == 0) + break; } - if (cnt != 0) - return(MR_ADDRESS); - else - value = htonl(id); + if (cnt != 0) + return MR_ADDRESS; + else + value = htonl(id); } - /* - * we have an address in value. Convert it to a string and store it. - */ - addr.s_addr = htonl(value); - strcpy(argv[9+row], inet_ntoa(addr)); - } else { - strcpy(argv[9+row], "unassigned"); + /* + * we have an address in value. Convert it to a string and store it. + */ + addr.s_addr = htonl(value); + strcpy(argv[9 + row], inet_ntoa(addr)); } - - /* status checking */ - value = atoi(argv[7+row]); - if (row == 0 && !(value == 1 || value == 0)) - return(MR_TYPE); - if (row == 1) { - id = *(int *)argv[0]; - EXEC SQL SELECT status INTO :cnt FROM machine WHERE mach_id = :id; - if (dbms_errno) return(mr_errcode); - if (value != cnt) { - EXEC SQL UPDATE machine SET statuschange = SYSDATE - WHERE mach_id = :id; + else + strcpy(argv[9 + row], "unassigned"); + + /* status checking */ + value = atoi(argv[7 + row]); + if (row == 0 && !(value == 1 || value == 0)) + return MR_TYPE; + if (row == 1) + { + id = *(int *)argv[0]; + EXEC SQL SELECT status INTO :cnt FROM machine WHERE mach_id = :id; + if (dbms_errno) + return mr_errcode; + if (value != cnt) + { + EXEC SQL UPDATE machine SET statuschange = SYSDATE + WHERE mach_id = :id; } } - if (row == 0 && !privileged) { - /* subnet owner is adding a host */ - /* Non-query owner must set use to zero */ - if (atoi(argv[6]) != 0) return(MR_PERM); - } else if (row == 1 && !privileged) { - EXEC SQL BEGIN DECLARE SECTION; - int i8, i12, i13, i7, i9, i14; - char s6[33], s10[33], s11[9]; - EXEC SQL END DECLARE SECTION; - /* Non-query owner is restricted in changes that can be made */ - id = *(int *)argv[0]; - EXEC SQL SELECT contact, status, address, owner_type, owner_id, - acomment, use, snet_id, ocomment INTO :s6, :i8, :s10, :s11, - :i12, :i13, :i7, :i9, :i14 FROM machine WHERE mach_id = :id; - if (dbms_errno) return(mr_errcode); - /* subnet owner cannot change use, comment, or network */ - if ((i7 != atoi(argv[7])) || (i14 != *(int *)argv[14]) || - (i9 != *(int *)argv[9])) - return(MR_PERM); - /* host owner cannot change contact, status, address, owner_type, - * owner_id, acomment, or subnet */ - if (host_access_level == 2 && - (strcmp(argv[6], strtrim(s6)) || (i8 != atoi(argv[8])) || - strcmp(argv[10], strtrim(s10)) ||strcmp(argv[11], strtrim(s11)) || - (i12 != *(int *)argv[12]) || (i13 != *(int *)argv[13]) || - (i9 != *(int *)argv[9]))) - return(MR_PERM); + if (row == 0 && !privileged) + { + /* subnet owner is adding a host */ + /* Non-query owner must set use to zero */ + if (atoi(argv[6]) != 0) + return MR_PERM; + } + else if (row == 1 && !privileged) + { + EXEC SQL BEGIN DECLARE SECTION; + int i8, i12, i13, i7, i9, i14; + char s6[33], s10[33], s11[9]; + EXEC SQL END DECLARE SECTION; + /* Non-query owner is restricted in changes that can be made */ + id = *(int *)argv[0]; + EXEC SQL SELECT contact, status, address, owner_type, owner_id, + acomment, use, snet_id, ocomment INTO :s6, :i8, :s10, :s11, + :i12, :i13, :i7, :i9, :i14 FROM machine WHERE mach_id = :id; + if (dbms_errno) + return mr_errcode; + /* subnet owner cannot change use, comment, or network */ + if ((i7 != atoi(argv[7])) || (i14 != *(int *)argv[14]) || + (i9 != *(int *)argv[9])) + return MR_PERM; + /* host owner cannot change contact, status, address, owner_type, + * owner_id, acomment, or subnet */ + if (host_access_level == 2 && + (strcmp(argv[6], strtrim(s6)) || (i8 != atoi(argv[8])) || + strcmp(argv[10], strtrim(s10)) || strcmp(argv[11], strtrim(s11)) || + (i12 != *(int *)argv[12]) || (i13 != *(int *)argv[13]) || + (i9 != *(int *)argv[9]))) + return MR_PERM; } - /* - * If this is an update_host query, we're done. - */ - if (row == 1) - return(MR_SUCCESS); - - /* - * For an add_host query, allocate and fill in a new machine id, - * and then insert the creator id. - */ - if ((mr_errcode = prefetch_value(q,argv,cl)) != MR_SUCCESS) - return(mr_errcode); - - sprintf(argv[q->argc + q->vcnt + 1], "%d",cl->client_id); - return(MR_SUCCESS); + /* + * If this is an update_host query, we're done. + */ + if (row == 1) + return MR_SUCCESS; + + /* + * For an add_host query, allocate and fill in a new machine id, + * and then insert the creator id. + */ + if ((mr_errcode = prefetch_value(q, argv, cl)) != MR_SUCCESS) + return mr_errcode; + + sprintf(argv[q->argc + q->vcnt + 1], "%d", cl->client_id); + return MR_SUCCESS; } /* setup_ahal(): */ -int setup_ahal(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int setup_ahal(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *name; - int cnt; - EXEC SQL END DECLARE SECTION; - char *p; - - p = name = argv[0]; - if (!isalpha(*p)) return(MR_BAD_CHAR); - for (; *p; p++) { - if ((!isalnum(*p) && *p != '-' && *p != '.') || - (*p == '-' && p[1] == '.')) - return(MR_BAD_CHAR); + EXEC SQL BEGIN DECLARE SECTION; + char *name; + int cnt; + EXEC SQL END DECLARE SECTION; + char *p; + + p = name = argv[0]; + if (!isalpha(*p)) + return MR_BAD_CHAR; + for (; *p; p++) + { + if ((!isalnum(*p) && *p != '-' && *p != '.') || + (*p == '-' && p[1] == '.')) + return MR_BAD_CHAR; } - if (*(p-1) == '-') return(MR_BAD_CHAR); + if (*(p - 1) == '-') + return MR_BAD_CHAR; - EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine WHERE - name = :name; - if (dbms_errno) return(mr_errcode); - if (cnt > 0) return(MR_EXISTS); + EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine WHERE + name = :name; + if (dbms_errno) + return mr_errcode; + if (cnt > 0) + return MR_EXISTS; - return(MR_SUCCESS); + return MR_SUCCESS; } diff --git a/server/qsubs.c b/server/qsubs.c index d3ea7443..083d198f 100644 --- a/server/qsubs.c +++ b/server/qsubs.c @@ -18,99 +18,68 @@ static char *rcsid_qsubs_c = "$Header$"; #include "mr_server.h" #include "query.h" -#ifdef MULTIPROTOCOLS -extern struct query Queries1[], Queries2[]; -extern int QueryCount1, QueryCount2; -#else extern struct query Queries2[]; extern int QueryCount2; -#endif MULTIPROTOCOLS -struct query * -get_query_by_name(name, version) - register char *name; - int version; +struct query *get_query_by_name(register char *name, int version) { - register struct query *q; - register int i; - -#ifdef MULTIPROTOCOLS - if (version == MR_VERSION_1) { - q = Queries1; - i = QueryCount1; - } else { -#endif - q = Queries2; - i = QueryCount2; -#ifdef MULTIPROTOCOLS - } -#endif - - if (strlen(name) == 4) { - while (--i >= 0) { - if (!strcmp(q->shortname, name)) return(q); - q++; + register struct query *q; + register int i; + + q = Queries2; + i = QueryCount2; + + if (strlen(name) == 4) + { + while (--i >= 0) + { + if (!strcmp(q->shortname, name)) + return q; + q++; } - } else { - while (--i >= 0) { - if (!strcmp(q->name, name)) return(q); - q++; + } + else + { + while (--i >= 0) + { + if (!strcmp(q->name, name)) + return q; + q++; } } - return((struct query *)0); + return NULL; } -void list_queries(version, action, actarg) - int version; - int (*action)(); - char *actarg; +void list_queries(int version, int (*action)(), char *actarg) { register struct query *q; register int i; -#ifdef MULTIPROTOCOLS - static struct query **squeries1 = (struct query **)0; -#endif - static struct query **squeries2 = (struct query **)0; + static struct query **squeries2 = NULL; register struct query **sq; char qnames[80]; char *qnp; int count; int qcmp(); -#ifdef MULTIPROTOCOLS - if (version == MR_VERSION_1) { - count = QueryCount1; - if (squeries1 == (struct query **)0) { - sq = (struct query **)malloc(count * sizeof (struct query *)); - squeries1 = sq; - q = Queries1; - for (i = count; --i >= 0; ) - *sq++ = q++; - qsort(squeries1, count, sizeof (struct query *), qcmp); - } - sq = squeries1; - } else { -#endif - count = QueryCount2; - if (squeries2 == (struct query **)0) { - sq = (struct query **)malloc(count * sizeof (struct query *)); - squeries2 = sq; - q = Queries2; - for (i = count; --i >= 0; ) - *sq++ = q++; - qsort(squeries2, count, sizeof (struct query *), qcmp); - } - sq = squeries2; -#ifdef MULTIPROTOCOLS - } -#endif + count = QueryCount2; + if (!squeries2) + { + sq = malloc(count * sizeof(struct query *)); + squeries2 = sq; + q = Queries2; + for (i = count; --i >= 0; ) + *sq++ = q++; + qsort(squeries2, count, sizeof(struct query *), qcmp); + } + sq = squeries2; qnp = qnames; - for (i = count; --i >= 0; sq++) { + for (i = count; --i >= 0; sq++) + { sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname); (*action)(1, &qnp, actarg); - } + } strcpy(qnames, "_help"); (*action)(1, &qnp, actarg); strcpy(qnames, "_list_queries"); @@ -119,63 +88,65 @@ void list_queries(version, action, actarg) (*action)(1, &qnp, actarg); } -void help_query(q, action, actarg) - register struct query *q; - int (*action)(); - char *actarg; +void help_query(register struct query *q, int (*action)(), char *actarg) { - register int argcount; - register int i; - char argn[32]; - char qname[512]; - char argr[512]; - char *argv[32]; + register int argcount; + register int i; + char argn[32]; + char qname[512]; + char argr[512]; + char *argv[32]; - argcount = q->argc; - if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt; + argcount = q->argc; + if (q->type == UPDATE || q->type == APPEND) + argcount += q->vcnt; - switch (argcount) { + switch (argcount) + { case 0: - sprintf(qname, " %s, %s ()", q->name, q->shortname); - argv[0] = qname; - argcount = 1; - break; + sprintf(qname, " %s, %s ()", q->name, q->shortname); + argv[0] = qname; + argcount = 1; + break; case 1: - sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]); - argv[0] = qname; - argcount = 1; - break; + sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]); + argv[0] = qname; + argcount = 1; + break; case 2: - sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname, - q->fields[0], q->fields[1]); - argv[0] = qname; - argcount = 1; - break; + sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname, + q->fields[0], q->fields[1]); + argv[0] = qname; + argcount = 1; + break; default: - sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]); - argv[0] = qname; - argcount--; - for (i = 1; i < argcount; i++) argv[i] = q->fields[i]; - sprintf(argn, "%s)", q->fields[argcount]); - argv[argcount++] = argn; - break; + sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]); + argv[0] = qname; + argcount--; + for (i = 1; i < argcount; i++) + argv[i] = q->fields[i]; + sprintf(argn, "%s)", q->fields[argcount]); + argv[argcount++] = argn; + break; } - if (q->type == RETRIEVE) { - sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]); - argv[argcount++] = argr; - if (q->vcnt > 1) - for (i = q->argc + 1; i < q->vcnt + q->argc; i++) - argv[argcount++] = q->fields[i]; + + if (q->type == RETRIEVE) + { + sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]); + argv[argcount++] = argr; + if (q->vcnt > 1) + { + for (i = q->argc + 1; i < q->vcnt + q->argc; i++) + argv[argcount++] = q->fields[i]; + } } - (*action)(argcount, argv, actarg); + (*action)(argcount, argv, actarg); } -qcmp(q1, q2) - struct query **q1; - struct query **q2; +int qcmp(struct query **q1, struct query **q2) { - return(strcmp((*q1)->name, (*q2)->name)); + return strcmp((*q1)->name, (*q2)->name); } diff --git a/server/qsupport.pc b/server/qsupport.pc index dd06aaf0..81efe55f 100644 --- a/server/qsupport.pc +++ b/server/qsupport.pc @@ -47,55 +47,59 @@ int qualified_get(struct query *q, char *argv[], int (*action)(), int actarg, */ -int set_pobox(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int set_pobox(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int user, id; - char *box, potype[9]; - EXEC SQL END DECLARE SECTION; - int status; - - box = argv[2]; - user = *(int *)argv[0]; - - EXEC SQL SELECT pop_id, potype INTO :id, :potype FROM users - WHERE users_id = :user; - if (dbms_errno) return(mr_errcode); - if (!strcmp(strtrim(potype), "POP")) - set_pop_usage(id, -1); - - if (!strcmp(argv[1], "POP")) { - status = name_to_id(box, MACHINE_TABLE, &id); - if (status == MR_NO_MATCH) - return(MR_MACHINE); - else if (status) - return(status); - EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id - WHERE users_id = :user; - set_pop_usage(id, 1); - } else if (!strcmp(argv[1], "SMTP")) { - if (strchr(box, '/') || strchr(box, '|')) - return(MR_BAD_CHAR); - status = name_to_id(box, STRINGS_TABLE, &id); - if (status == MR_NO_MATCH) { - id=add_string(box); - } else if (status) - return(status); - EXEC SQL UPDATE users SET potype='SMTP', box_id = :id - WHERE users_id = :user; - } else /* argv[1] == "NONE" */ { - EXEC SQL UPDATE users SET potype='NONE' - WHERE users_id = :user; + EXEC SQL BEGIN DECLARE SECTION; + int user, id; + char *box, potype[9]; + EXEC SQL END DECLARE SECTION; + int status; + + box = argv[2]; + user = *(int *)argv[0]; + + EXEC SQL SELECT pop_id, potype INTO :id, :potype FROM users + WHERE users_id = :user; + if (dbms_errno) + return mr_errcode; + if (!strcmp(strtrim(potype), "POP")) + set_pop_usage(id, -1); + + if (!strcmp(argv[1], "POP")) + { + status = name_to_id(box, MACHINE_TABLE, &id); + if (status == MR_NO_MATCH) + return MR_MACHINE; + else if (status) + return status; + EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id + WHERE users_id = :user; + set_pop_usage(id, 1); + } + else if (!strcmp(argv[1], "SMTP")) + { + if (strchr(box, '/') || strchr(box, '|')) + return MR_BAD_CHAR; + status = name_to_id(box, STRINGS_TABLE, &id); + if (status == MR_NO_MATCH) + id = add_string(box); + else if (status) + return status; + EXEC SQL UPDATE users SET potype = 'SMTP', box_id = :id + WHERE users_id = :user; + } + else /* argv[1] == "NONE" */ + { + EXEC SQL UPDATE users SET potype = 'NONE' + WHERE users_id = :user; } - set_pobox_modtime(q, argv, cl); - EXEC SQL UPDATE tblstats SET updates = updates+1, modtime=SYSDATE - WHERE table_name='users'; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + set_pobox_modtime(q, argv, cl); + EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE + WHERE table_name = 'users'; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -104,105 +108,112 @@ int set_pobox(q, argv, cl) * data. Rest of processing consists of fixing gid, ace_name, and modby. */ -int get_list_info(q, aargv, cl, action, actarg) - struct query *q; - char **aargv; - client *cl; - int (*action)(), actarg; +int get_list_info(struct query *q, char **aargv, client *cl, + int (*action)(), int actarg) { - char *argv[13]; - EXEC SQL BEGIN DECLARE SECTION; - char *name, acl_type[9], listname[33], active[5], public[5], hidden[5]; - char maillist[5], grouplist[5], gid_str[6], desc[256]; - char modtime[27], modwith[9]; - int id, rowcount, acl_id, hid, modby_id; - EXEC SQL END DECLARE SECTION; - int returned, status; - struct save_queue *sq, *sq_create(); - - returned = rowcount = 0; - name = aargv[0]; - convert_wildcards(name); - - sq = sq_create(); - EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list - WHERE name LIKE :name ESCAPE '*'; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr102; - if (dbms_errno) - return(mr_errcode); - while(1) + char *argv[13]; + EXEC SQL BEGIN DECLARE SECTION; + char *name, acl_type[9], listname[33], active[5], public[5], hidden[5]; + char maillist[5], grouplist[5], gid_str[6], desc[256]; + char modtime[27], modwith[9]; + int id, rowcount, acl_id, hid, modby_id; + EXEC SQL END DECLARE SECTION; + int returned, status; + struct save_queue *sq, *sq_create(); + + returned = rowcount = 0; + name = aargv[0]; + convert_wildcards(name); + + sq = sq_create(); + EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list + WHERE name LIKE :name ESCAPE '*'; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr102; + if (dbms_errno) + return mr_errcode; + while (1) { - EXEC SQL FETCH csr102 INTO :id; - if(sqlca.sqlcode!=0) break; - sq_save_data(sq, (char *)id); - rowcount++; + EXEC SQL FETCH csr102 INTO :id; + if (sqlca.sqlcode) + break; + sq_save_data(sq, (char *)id); + rowcount++; } - EXEC SQL CLOSE csr102; - - if (dbms_errno) return(mr_errcode); - if (rowcount == 0) - return(MR_NO_MATCH); - - argv[0] = listname; argv[1] = active; argv[2] = public; argv[3] = hidden; - argv[4] = maillist; argv[5] = grouplist; argv[6] = gid_str; - argv[7] = acl_type; argv[9] = desc; argv[10] = modtime; argv[12] = modwith; - - while (sq_get_data(sq, &id)) { - if (id == 0) - continue; - argv[6] = gid_str; - EXEC SQL SELECT name, active, publicflg, - hidden, hidden, maillist, grouplist, gid, - acl_type, acl_id, description, - TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith - INTO :listname, :active, :public, :hidden, :hid, :maillist, - :grouplist, :gid_str, :acl_type, :acl_id, :desc, - :modtime, :modby_id, :modwith - FROM list WHERE list_id = :id; - - if (dbms_errno) return(mr_errcode); - strtrim(acl_type); - - if (atoi(gid_str) == -1) - argv[6] = UNIQUE_GID; - - argv[8] = malloc(0); - if (!strcmp(acl_type, "LIST")) { - status = id_to_name(acl_id, LIST_TABLE, &argv[8]); - } else if (!strcmp(acl_type, "USER")) { - status = id_to_name(acl_id, USERS_TABLE, &argv[8]); - } else if (!strcmp(acl_type, "KERBEROS")) { - status = id_to_name(acl_id, STRINGS_TABLE, &argv[8]); - } else if (!strcmp(acl_type, "NONE")) { - status = 0; - free(argv[8]); - argv[8] = strsave("NONE"); - } else { - status = 0; - free(argv[8]); - argv[8] = strsave("???"); + EXEC SQL CLOSE csr102; + + if (dbms_errno) + return mr_errcode; + if (rowcount == 0) + return MR_NO_MATCH; + + argv[0] = listname; argv[1] = active; argv[2] = public; argv[3] = hidden; + argv[4] = maillist; argv[5] = grouplist; argv[6] = gid_str; + argv[7] = acl_type; argv[9] = desc; argv[10] = modtime; argv[12] = modwith; + + while (sq_get_data(sq, &id)) + { + if (id == 0) + continue; + argv[6] = gid_str; + EXEC SQL SELECT name, active, publicflg, + hidden, hidden, maillist, grouplist, gid, + acl_type, acl_id, description, + TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith + INTO :listname, :active, :public, :hidden, :hid, :maillist, + :grouplist, :gid_str, :acl_type, :acl_id, :desc, + :modtime, :modby_id, :modwith + FROM list WHERE list_id = :id; + + if (dbms_errno) + return mr_errcode; + strtrim(acl_type); + + if (atoi(gid_str) == -1) + argv[6] = UNIQUE_GID; + + argv[8] = malloc(0); + if (!strcmp(acl_type, "LIST")) + status = id_to_name(acl_id, LIST_TABLE, &argv[8]); + else if (!strcmp(acl_type, "USER")) + status = id_to_name(acl_id, USERS_TABLE, &argv[8]); + else if (!strcmp(acl_type, "KERBEROS")) + status = id_to_name(acl_id, STRINGS_TABLE, &argv[8]); + else if (!strcmp(acl_type, "NONE")) + { + status = 0; + free(argv[8]); + argv[8] = strsave("NONE"); + } + else + { + status = 0; + free(argv[8]); + argv[8] = strsave("???"); } - if (status && status != MR_NO_MATCH) return(status); - - argv[11] = malloc(0); - if (modby_id > 0) - status = id_to_name(modby_id, USERS_TABLE, &argv[11]); - else - status = id_to_name(-modby_id, STRINGS_TABLE, &argv[11]); - if (status && status != MR_NO_MATCH) return(status); - - mr_trim_args(q->vcnt, argv); - returned++; - (*action)(q->vcnt, argv, actarg); - free(argv[8]); - free(argv[11]); + if (status && status != MR_NO_MATCH) + return status; + + argv[11] = malloc(0); + if (modby_id > 0) + status = id_to_name(modby_id, USERS_TABLE, &argv[11]); + else + status = id_to_name(-modby_id, STRINGS_TABLE, &argv[11]); + if (status && status != MR_NO_MATCH) + return status; + + mr_trim_args(q->vcnt, argv); + returned++; + (*action)(q->vcnt, argv, actarg); + free(argv[8]); + free(argv[11]); } - sq_destroy(sq); - if (dbms_errno) return(mr_errcode); - return (MR_SUCCESS); + sq_destroy(sq); + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -212,299 +223,332 @@ int get_list_info(q, aargv, cl, action, actarg) #define MAXLISTDEPTH 1024 -int add_member_to_list(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int add_member_to_list(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id, lid, mid, error, who, ref, rowcnt; - char *mtype, dtype[9], *entity; - EXEC SQL END DECLARE SECTION; - int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a; - int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d; - int status; - char *dtypes[MAXLISTDEPTH]; - char *iargv[3], *buf; - - lid = *(int *)argv[0]; - mtype = argv[1]; - mid = *(int *)argv[2]; - /* if the member is already a direct member of the list, punt */ - EXEC SQL SELECT COUNT(list_id) INTO :rowcnt FROM imembers - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype AND direct = 1; - if (rowcnt > 0) - return(MR_EXISTS); - if (!strcasecmp(mtype, "STRING")) { - buf = malloc(0); - status = id_to_name(mid, STRINGS_TABLE, &buf); - if (status) return(status); - if (strchr(buf, '/') || strchr(buf, '|')) { - free(buf); - return(MR_BAD_CHAR); + EXEC SQL BEGIN DECLARE SECTION; + int id, lid, mid, error, who, ref, rowcnt; + char *mtype, dtype[9], *entity; + EXEC SQL END DECLARE SECTION; + int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a; + int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d; + int status; + char *dtypes[MAXLISTDEPTH]; + char *iargv[3], *buf; + + lid = *(int *)argv[0]; + mtype = argv[1]; + mid = *(int *)argv[2]; + /* if the member is already a direct member of the list, punt */ + EXEC SQL SELECT COUNT(list_id) INTO :rowcnt FROM imembers + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype AND direct = 1; + if (rowcnt > 0) + return MR_EXISTS; + if (!strcasecmp(mtype, "STRING")) + { + buf = malloc(0); + status = id_to_name(mid, STRINGS_TABLE, &buf); + if (status) + return status; + if (strchr(buf, '/') || strchr(buf, '|')) + { + free(buf); + return MR_BAD_CHAR; } - free(buf); + free(buf); } - ancestors[0] = lid; - aref[0] = 1; - acount = 1; - EXEC SQL DECLARE csr103 CURSOR FOR - SELECT list_id, ref_count FROM imembers - WHERE member_id = :lid AND member_type='LIST'; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr103; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr103 INTO :id, :ref; - if(sqlca.sqlcode != 0) break; - aref[acount] = ref; - ancestors[acount++] = id; - if (acount >= MAXLISTDEPTH) break; - } - EXEC SQL CLOSE csr103; - if (dbms_errno) return(mr_errcode); - if (acount >= MAXLISTDEPTH) { - return(MR_INTERNAL); + ancestors[0] = lid; + aref[0] = 1; + acount = 1; + EXEC SQL DECLARE csr103 CURSOR FOR + SELECT list_id, ref_count FROM imembers + WHERE member_id = :lid AND member_type = 'LIST'; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr103; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr103 INTO :id, :ref; + if (sqlca.sqlcode) + break; + aref[acount] = ref; + ancestors[acount++] = id; + if (acount >= MAXLISTDEPTH) + break; } - descendants[0] = mid; - dtypes[0] = mtype; - dref[0] = 1; - dcount = 1; - error = 0; - if (!strcmp(mtype, "LIST")) { - EXEC SQL DECLARE csr104 CURSOR FOR - SELECT member_id, member_type, ref_count - FROM imembers - WHERE list_id = :mid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr104; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr104 INTO :id, :dtype, :ref; - if(sqlca.sqlcode != 0) break; - switch (dtype[0]) { + EXEC SQL CLOSE csr103; + if (dbms_errno) + return mr_errcode; + if (acount >= MAXLISTDEPTH) + return MR_INTERNAL; + descendants[0] = mid; + dtypes[0] = mtype; + dref[0] = 1; + dcount = 1; + error = 0; + if (!strcmp(mtype, "LIST")) + { + EXEC SQL DECLARE csr104 CURSOR FOR + SELECT member_id, member_type, ref_count + FROM imembers + WHERE list_id = :mid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr104; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr104 INTO :id, :dtype, :ref; + if (sqlca.sqlcode) + break; + switch (dtype[0]) + { case 'L': - dtypes[dcount] = "LIST"; - break; + dtypes[dcount] = "LIST"; + break; case 'U': - dtypes[dcount] = "USER"; - break; + dtypes[dcount] = "USER"; + break; case 'S': - dtypes[dcount] = "STRING"; - break; + dtypes[dcount] = "STRING"; + break; case 'K': - dtypes[dcount] = "KERBEROS"; - break; + dtypes[dcount] = "KERBEROS"; + break; default: - error++; - break; + error++; + break; } - dref[dcount] = ref; - descendants[dcount++] = id; - if (dcount >= MAXLISTDEPTH) { - error++; - break; + dref[dcount] = ref; + descendants[dcount++] = id; + if (dcount >= MAXLISTDEPTH) + { + error++; + break; } } - EXEC SQL CLOSE csr104; - if (dbms_errno) return(mr_errcode); - if (error) - return(MR_INTERNAL); + EXEC SQL CLOSE csr104; + if (dbms_errno) + return mr_errcode; + if (error) + return MR_INTERNAL; } - for (a = 0; a < acount; a++) { - lid = ancestors[a]; - for (d = 0; d < dcount; d++) { - mid = descendants[d]; - mtype = dtypes[d]; - if (mid == lid && !strcmp(mtype, "LIST")) { - return(MR_LISTLOOP); - } - EXEC SQL SELECT COUNT(ref_count) INTO :rowcnt - FROM imembers - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype; - ref = aref[a] * dref[d]; - if (rowcnt > 0) { - if (a == 0 && d == 0) { - EXEC SQL UPDATE imembers - SET ref_count = ref_count+:ref, direct=1 - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype; - } else { - EXEC SQL UPDATE imembers - SET ref_count = ref_count+:ref - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype; + for (a = 0; a < acount; a++) + { + lid = ancestors[a]; + for (d = 0; d < dcount; d++) + { + mid = descendants[d]; + mtype = dtypes[d]; + if (mid == lid && !strcmp(mtype, "LIST")) + return MR_LISTLOOP; + EXEC SQL SELECT COUNT(ref_count) INTO :rowcnt + FROM imembers + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype; + ref = aref[a] * dref[d]; + if (rowcnt > 0) + { + if (a == 0 && d == 0) + { + EXEC SQL UPDATE imembers + SET ref_count = ref_count + :ref, direct = 1 + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype; } - } else { - incremental_clear_before(); - if (a == 0 && d == 0) { + else + { + EXEC SQL UPDATE imembers + SET ref_count = ref_count + :ref + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype; + } + } + else + { + incremental_clear_before(); + if (a == 0 && d == 0) + { EXEC SQL INSERT INTO imembers (list_id, member_id, direct, member_type, ref_count) VALUES (:lid, :mid, 1, :mtype, 1); - } else { + } + else + { EXEC SQL INSERT INTO imembers (list_id, member_id, direct, member_type, ref_count) VALUES (:lid, :mid, 0, :mtype, 1); } - iargv[0] = (char *)lid; - iargv[1] = mtype; - iargv[2] = (char *)mid; - incremental_after(IMEMBERS_TABLE, 0, iargv); + iargv[0] = (char *)lid; + iargv[1] = mtype; + iargv[2] = (char *)mid; + incremental_after(IMEMBERS_TABLE, 0, iargv); } } } - lid = *(int *)argv[0]; - entity = cl->entity; - who = cl->client_id; - EXEC SQL UPDATE list - SET modtime=SYSDATE, modby = :who, modwith = :entity - WHERE list_id = :lid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + lid = *(int *)argv[0]; + entity = cl->entity; + who = cl->client_id; + EXEC SQL UPDATE list + SET modtime = SYSDATE, modby = :who, modwith = :entity + WHERE list_id = :lid; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } /* Delete_member_from_list: do list flattening as we go! */ -int delete_member_from_list(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int delete_member_from_list(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - int id, lid, mid, cnt, error, who, ref; - char *mtype, dtype[9], *entity; - EXEC SQL END DECLARE SECTION; - int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a; - int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d; - char *dtypes[MAXLISTDEPTH]; - char *iargv[3]; - - lid = *(int *)argv[0]; - mtype = argv[1]; - mid = *(int *)argv[2]; - /* if the member is not a direct member of the list, punt */ - EXEC SQL SELECT COUNT(list_id) INTO :cnt FROM imembers - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype AND direct = 1; - if (dbms_errno) return(mr_errcode); - if (cnt == 0) - return(MR_NO_MATCH); - ancestors[0] = lid; - aref[0] = 1; - acount = 1; - EXEC SQL DECLARE csr105 CURSOR FOR - SELECT list_id, ref_count FROM imembers - WHERE member_id = :lid AND member_type = 'LIST'; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr105; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr105 INTO :id, :ref; - if(sqlca.sqlcode!=0) break; - aref[acount] = ref; - ancestors[acount++] = id; - if (acount >= MAXLISTDEPTH) break; + EXEC SQL BEGIN DECLARE SECTION; + int id, lid, mid, cnt, error, who, ref; + char *mtype, dtype[9], *entity; + EXEC SQL END DECLARE SECTION; + int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a; + int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d; + char *dtypes[MAXLISTDEPTH]; + char *iargv[3]; + + lid = *(int *)argv[0]; + mtype = argv[1]; + mid = *(int *)argv[2]; + /* if the member is not a direct member of the list, punt */ + EXEC SQL SELECT COUNT(list_id) INTO :cnt FROM imembers + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype AND direct = 1; + if (dbms_errno) + return mr_errcode; + if (cnt == 0) + return MR_NO_MATCH; + ancestors[0] = lid; + aref[0] = 1; + acount = 1; + EXEC SQL DECLARE csr105 CURSOR FOR + SELECT list_id, ref_count FROM imembers + WHERE member_id = :lid AND member_type = 'LIST'; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr105; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr105 INTO :id, :ref; + if (sqlca.sqlcode) + break; + aref[acount] = ref; + ancestors[acount++] = id; + if (acount >= MAXLISTDEPTH) + break; } - EXEC SQL CLOSE csr105; - if (dbms_errno) - return(mr_errcode); - if (acount >= MAXLISTDEPTH) - return(MR_INTERNAL); - descendants[0] = mid; - dtypes[0] = mtype; - dref[0] = 1; - dcount = 1; - error = 0; - if (!strcmp(mtype, "LIST")) { - EXEC SQL DECLARE csr106 CURSOR FOR - SELECT member_id, member_type, ref_count FROM imembers - WHERE list_id = :mid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr106; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr106 INTO :id, :dtype, :ref; - if(sqlca.sqlcode!=0) break; - switch (dtype[0]) { + EXEC SQL CLOSE csr105; + if (dbms_errno) + return mr_errcode; + if (acount >= MAXLISTDEPTH) + return MR_INTERNAL; + descendants[0] = mid; + dtypes[0] = mtype; + dref[0] = 1; + dcount = 1; + error = 0; + if (!strcmp(mtype, "LIST")) + { + EXEC SQL DECLARE csr106 CURSOR FOR + SELECT member_id, member_type, ref_count FROM imembers + WHERE list_id = :mid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr106; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr106 INTO :id, :dtype, :ref; + if (sqlca.sqlcode) + break; + switch (dtype[0]) + { case 'L': - dtypes[dcount] = "LIST"; - break; + dtypes[dcount] = "LIST"; + break; case 'U': - dtypes[dcount] = "USER"; - break; + dtypes[dcount] = "USER"; + break; case 'S': - dtypes[dcount] = "STRING"; - break; + dtypes[dcount] = "STRING"; + break; case 'K': - dtypes[dcount] = "KERBEROS"; - break; + dtypes[dcount] = "KERBEROS"; + break; default: - error++; - break; + error++; + break; } - dref[dcount] = ref; - descendants[dcount++] = id; - if (dcount >= MAXLISTDEPTH) break; + dref[dcount] = ref; + descendants[dcount++] = id; + if (dcount >= MAXLISTDEPTH) + break; } - EXEC SQL CLOSE csr106; - if (dbms_errno) - return(mr_errcode); - if (error) - return(MR_INTERNAL); + EXEC SQL CLOSE csr106; + if (dbms_errno) + return mr_errcode; + if (error) + return MR_INTERNAL; } - for (a = 0; a < acount; a++) { - lid = ancestors[a]; - for (d = 0; d < dcount; d++) { - mid = descendants[d]; - mtype = dtypes[d]; - if (mid == lid && !strcmp(mtype, "LIST")) { - return(MR_LISTLOOP); + for (a = 0; a < acount; a++) + { + lid = ancestors[a]; + for (d = 0; d < dcount; d++) + { + mid = descendants[d]; + mtype = dtypes[d]; + if (mid == lid && !strcmp(mtype, "LIST")) + return MR_LISTLOOP; + EXEC SQL SELECT ref_count INTO :cnt FROM imembers + WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype; + ref = aref[a] * dref[d]; + if (cnt <= ref) + { + iargv[0] = (char *)lid; + iargv[1] = mtype; + iargv[2] = (char *)mid; + incremental_before(IMEMBERS_TABLE, 0, iargv); + EXEC SQL DELETE FROM imembers + WHERE list_id = :lid AND member_id = :mid + AND member_type= :mtype; + incremental_clear_after(); } - EXEC SQL SELECT ref_count INTO :cnt FROM imembers - WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype; - ref = aref[a] * dref[d]; - if (cnt <= ref) { - iargv[0] = (char *)lid; - iargv[1] = mtype; - iargv[2] = (char *)mid; - incremental_before(IMEMBERS_TABLE, 0, iargv); - EXEC SQL DELETE FROM imembers - WHERE list_id = :lid AND member_id = :mid - AND member_type= :mtype; - incremental_clear_after(); - } else if (a == 0 && d == 0) { - EXEC SQL UPDATE imembers - SET ref_count = ref_count - :ref, direct = 0 - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype; - } else { - EXEC SQL UPDATE imembers - SET ref_count = ref_count - :ref - WHERE list_id = :lid AND member_id = :mid - AND member_type = :mtype; + else if (a == 0 && d == 0) + { + EXEC SQL UPDATE imembers + SET ref_count = ref_count - :ref, direct = 0 + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype; + } + else + { + EXEC SQL UPDATE imembers + SET ref_count = ref_count - :ref + WHERE list_id = :lid AND member_id = :mid + AND member_type = :mtype; } } } - lid = *(int *)argv[0]; - entity = cl->entity; - who = cl->client_id; - EXEC SQL UPDATE list SET modtime = SYSDATE, modby = :who, modwith = :entity - WHERE list_id = :lid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + lid = *(int *)argv[0]; + entity = cl->entity; + who = cl->client_id; + EXEC SQL UPDATE list SET modtime = SYSDATE, modby = :who, modwith = :entity + WHERE list_id = :lid; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -516,103 +560,113 @@ int delete_member_from_list(q, argv, cl) * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR. */ -int get_ace_use(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int get_ace_use(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - int found = 0; - EXEC SQL BEGIN DECLARE SECTION; - char *atype; - int aid, listid, id; - EXEC SQL END DECLARE SECTION; - struct save_queue *sq, *sq_create(); - - atype = argv[0]; - aid = *(int *)argv[1]; - if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") || - !strcmp(atype, "KERBEROS")) { - return(get_ace_internal(atype, aid, action, actarg)); - } - - sq = sq_create(); - if (!strcmp(atype, "RLIST")) { - sq_save_data(sq, (char *)aid); - /* get all the list_id's of containing lists */ - EXEC SQL DECLARE csr107 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_type='LIST' AND member_id = :aid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr107; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr107 INTO :listid; - if(sqlca.sqlcode != 0) break; - sq_save_unique_data(sq, (char *)listid); + int found = 0; + EXEC SQL BEGIN DECLARE SECTION; + char *atype; + int aid, listid, id; + EXEC SQL END DECLARE SECTION; + struct save_queue *sq, *sq_create(); + + atype = argv[0]; + aid = *(int *)argv[1]; + if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") || + !strcmp(atype, "KERBEROS")) + return get_ace_internal(atype, aid, action, actarg); + + sq = sq_create(); + if (!strcmp(atype, "RLIST")) + { + sq_save_data(sq, (char *)aid); + /* get all the list_id's of containing lists */ + EXEC SQL DECLARE csr107 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_type = 'LIST' AND member_id = :aid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr107; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr107 INTO :listid; + if (sqlca.sqlcode) + break; + sq_save_unique_data(sq, (char *)listid); } - EXEC SQL CLOSE csr107; - /* now process each one */ - while (sq_get_data(sq, &id)) { - if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) - found++; + EXEC SQL CLOSE csr107; + /* now process each one */ + while (sq_get_data(sq, &id)) + { + if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) + found++; } } - if (!strcmp(atype, "RUSER")) { - EXEC SQL DECLARE csr108 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_type='USER' AND member_id = :aid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr108; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr108 INTO :listid; - if(sqlca.sqlcode != 0) break; - sq_save_data(sq, (char *)listid); + if (!strcmp(atype, "RUSER")) + { + EXEC SQL DECLARE csr108 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_type = 'USER' AND member_id = :aid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr108; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr108 INTO :listid; + if (sqlca.sqlcode) + break; + sq_save_data(sq, (char *)listid); } - EXEC SQL CLOSE csr108; - /* now process each one */ - while (sq_get_data(sq, &id)) { - if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) - found++; + EXEC SQL CLOSE csr108; + /* now process each one */ + while (sq_get_data(sq, &id)) + { + if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) + found++; } - if (get_ace_internal("USER", aid, action, actarg) == MR_SUCCESS) - found++; + if (get_ace_internal("USER", aid, action, actarg) == MR_SUCCESS) + found++; } - if (!strcmp(atype, "RKERBEROS")) { - EXEC SQL DECLARE csr109 CURSOR FOR - SELECT list_id FROM imembers - WHERE member_type='KERBEROS' AND member_id = :aid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr109; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr109 INTO :listid; - if(sqlca.sqlcode != 0) break; - sq_save_data(sq, (char*)listid); + if (!strcmp(atype, "RKERBEROS")) + { + EXEC SQL DECLARE csr109 CURSOR FOR + SELECT list_id FROM imembers + WHERE member_type = 'KERBEROS' AND member_id = :aid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr109; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr109 INTO :listid; + if (sqlca.sqlcode) + break; + sq_save_data(sq, (char *)listid); } - EXEC SQL CLOSE csr109; - /* now process each one */ - while (sq_get_data(sq, &id)) { - if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) - found++; + EXEC SQL CLOSE csr109; + /* now process each one */ + while (sq_get_data(sq, &id)) + { + if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS) + found++; } - if (get_ace_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS) - found++; + if (get_ace_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS) + found++; } - sq_destroy(sq); - if (dbms_errno) return(mr_errcode); - if (!found) return(MR_NO_MATCH); - return(MR_SUCCESS); + sq_destroy(sq); + if (dbms_errno) + return mr_errcode; + if (!found) + return MR_NO_MATCH; + return MR_SUCCESS; } @@ -621,145 +675,161 @@ int get_ace_use(q, argv, cl, action, actarg) * by get_ace_use above. */ -int get_ace_internal(atype, aid, action, actarg) - char *atype; - int aid, (*action)(), actarg; +int get_ace_internal(char *atype, int aid, int (*action)(), int actarg) { - char *rargv[2]; - int found = 0; - EXEC SQL BEGIN DECLARE SECTION; - char name[33], *type = atype; - int id = aid; - EXEC SQL END DECLARE SECTION; - - rargv[1] = name; - if (!strcmp(atype, "LIST")) { - rargv[0] = "FILESYS"; - EXEC SQL DECLARE csr110 CURSOR FOR - SELECT label FROM filesys - WHERE owners = :id; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr110; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr110 INTO :name; - if(sqlca.sqlcode != 0) break; - (*action)(2, rargv, actarg); - found++; + char *rargv[2]; + int found = 0; + EXEC SQL BEGIN DECLARE SECTION; + char name[33], *type = atype; + int id = aid; + EXEC SQL END DECLARE SECTION; + + rargv[1] = name; + if (!strcmp(atype, "LIST")) + { + rargv[0] = "FILESYS"; + EXEC SQL DECLARE csr110 CURSOR FOR + SELECT label FROM filesys + WHERE owners = :id; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr110; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr110 INTO :name; + if (sqlca.sqlcode) + break; + (*action)(2, rargv, actarg); + found++; } - EXEC SQL CLOSE csr110; - - rargv[0] = "QUERY"; - EXEC SQL DECLARE csr111 CURSOR FOR - SELECT capability FROM capacls - WHERE list_id = :id ; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr111; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr111 INTO :name ; - if(sqlca.sqlcode != 0) break; - (*action)(2, rargv, actarg); - found++; + EXEC SQL CLOSE csr110; + + rargv[0] = "QUERY"; + EXEC SQL DECLARE csr111 CURSOR FOR + SELECT capability FROM capacls + WHERE list_id = :id; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr111; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr111 INTO :name; + if (sqlca.sqlcode) + break; + (*action)(2, rargv, actarg); + found++; } - EXEC SQL CLOSE csr111; - } else if (!strcmp(atype, "USER")) { - rargv[0] = "FILESYS"; - EXEC SQL DECLARE csr112 CURSOR FOR - SELECT label FROM filesys - WHERE owner = :id; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr112; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr112 INTO :name ; - if(sqlca.sqlcode != 0) break; - (*action)(2, rargv, actarg); - found++; + EXEC SQL CLOSE csr111; + } + else if (!strcmp(atype, "USER")) + { + rargv[0] = "FILESYS"; + EXEC SQL DECLARE csr112 CURSOR FOR + SELECT label FROM filesys + WHERE owner = :id; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr112; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr112 INTO :name; + if (sqlca.sqlcode) + break; + (*action)(2, rargv, actarg); + found++; } - EXEC SQL CLOSE csr112; + EXEC SQL CLOSE csr112; } - rargv[0] = "LIST"; - EXEC SQL DECLARE csr113 CURSOR FOR - SELECT name FROM list - WHERE acl_type = :type AND acl_id = :id; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr113; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr113 INTO :name; - if(sqlca.sqlcode != 0) break; - (*action)(2, rargv, actarg); - found++; + rargv[0] = "LIST"; + EXEC SQL DECLARE csr113 CURSOR FOR + SELECT name FROM list + WHERE acl_type = :type AND acl_id = :id; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr113; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr113 INTO :name; + if (sqlca.sqlcode) + break; + (*action)(2, rargv, actarg); + found++; } - EXEC SQL CLOSE csr113; - - rargv[0] = "SERVICE"; - EXEC SQL DECLARE csr114 CURSOR FOR - SELECT name FROM servers - WHERE acl_type = :type AND acl_id = :id; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr114; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr114 INTO :name; - if(sqlca.sqlcode != 0) break; - (*action)(2, rargv, actarg); - found++; + EXEC SQL CLOSE csr113; + + rargv[0] = "SERVICE"; + EXEC SQL DECLARE csr114 CURSOR FOR + SELECT name FROM servers + WHERE acl_type = :type AND acl_id = :id; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr114; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr114 INTO :name; + if (sqlca.sqlcode) + break; + (*action)(2, rargv, actarg); + found++; } - EXEC SQL CLOSE csr114; + EXEC SQL CLOSE csr114; - rargv[0] = "HOSTACCESS"; - EXEC SQL DECLARE csr115 CURSOR FOR - SELECT name FROM machine m, hostaccess ha - WHERE m.mach_id = ha.mach_id AND ha.acl_type = :type - AND ha.acl_id = :id; + rargv[0] = "HOSTACCESS"; + EXEC SQL DECLARE csr115 CURSOR FOR + SELECT name FROM machine m, hostaccess ha + WHERE m.mach_id = ha.mach_id AND ha.acl_type = :type + AND ha.acl_id = :id; if (dbms_errno) - return(mr_errcode); + return mr_errcode; EXEC SQL OPEN csr115; if (dbms_errno) - return(mr_errcode); - while(1) { + return mr_errcode; + while (1) + { EXEC SQL FETCH csr115 INTO :name; - if(sqlca.sqlcode != 0) break; + if (sqlca.sqlcode) + break; (*action)(2, rargv, actarg); found++; - } + } EXEC SQL CLOSE csr115; rargv[0] = "ZEPHYR"; EXEC SQL DECLARE csr116 CURSOR FOR SELECT class FROM zephyr z - WHERE z.xmt_type = :type AND z.xmt_id = :id - OR z.sub_type = :type AND z.sub_id = :id - OR z.iws_type = :type AND z.iws_id = :id - OR z.iui_type = :type AND z.iui_id = :id; + WHERE z.xmt_type = :type AND z.xmt_id = :id + OR z.sub_type = :type AND z.sub_id = :id + OR z.iws_type = :type AND z.iws_id = :id + OR z.iui_type = :type AND z.iui_id = :id; if (dbms_errno) - return(mr_errcode); + return mr_errcode; EXEC SQL OPEN csr116; if (dbms_errno) - return(mr_errcode); - while(1) { + return mr_errcode; + while (1) + { EXEC SQL FETCH csr116 INTO :name; - if(sqlca.sqlcode != 0) break; + if (sqlca.sqlcode) + break; (*action)(2, rargv, actarg); found++; - } + } EXEC SQL CLOSE csr116; - if (!found) return(MR_NO_MATCH); - return(MR_SUCCESS); + if (!found) + return MR_NO_MATCH; + return MR_SUCCESS; } @@ -771,90 +841,98 @@ int get_ace_internal(atype, aid, action, actarg) * when the object in question is a direct member. */ -int get_lists_of_member(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int get_lists_of_member(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - int found = 0, direct = 1; - char *rargv[6]; - EXEC SQL BEGIN DECLARE SECTION; - char *atype; - int aid; - char name[33], active[5], public[5], hidden[5], maillist[5], grouplist[5]; - EXEC SQL END DECLARE SECTION; - - atype = argv[0]; - aid = *(int *)argv[1]; - if (!strcmp(atype, "RLIST")) { - atype = "LIST"; - direct = 0; + int found = 0, direct = 1; + char *rargv[6]; + EXEC SQL BEGIN DECLARE SECTION; + char *atype; + int aid; + char name[33], active[5], public[5], hidden[5], maillist[5], grouplist[5]; + EXEC SQL END DECLARE SECTION; + + atype = argv[0]; + aid = *(int *)argv[1]; + if (!strcmp(atype, "RLIST")) + { + atype = "LIST"; + direct = 0; } - if (!strcmp(atype, "RUSER")) { - atype = "USER"; - direct = 0; + if (!strcmp(atype, "RUSER")) + { + atype = "USER"; + direct = 0; } - if (!strcmp(atype, "RSTRING")) { - atype = "STRING"; - direct = 0; + if (!strcmp(atype, "RSTRING")) + { + atype = "STRING"; + direct = 0; } - if (!strcmp(atype, "RKERBEROS")) { - atype = "KERBEROS"; - direct = 0; + if (!strcmp(atype, "RKERBEROS")) + { + atype = "KERBEROS"; + direct = 0; } - rargv[0] = name; - rargv[1] = active; - rargv[2] = public; - rargv[3] = hidden; - rargv[4] = maillist; - rargv[5] = grouplist; - if (direct) { - EXEC SQL DECLARE csr117a CURSOR FOR - SELECT l.name, l.active, l.publicflg, l.hidden, - l.maillist, l.grouplist - FROM list l, imembers im - WHERE l.list_id = im.list_id AND im.direct = 1 - AND im.member_type = :atype AND im.member_id = :aid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr117a; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr117a - INTO :name, :active, :public, :hidden, :maillist, :grouplist; - if(sqlca.sqlcode != 0) break; - (*action)(6, rargv, actarg); - found++; + rargv[0] = name; + rargv[1] = active; + rargv[2] = public; + rargv[3] = hidden; + rargv[4] = maillist; + rargv[5] = grouplist; + if (direct) + { + EXEC SQL DECLARE csr117a CURSOR FOR + SELECT l.name, l.active, l.publicflg, l.hidden, l.maillist, l.grouplist + FROM list l, imembers im + WHERE l.list_id = im.list_id AND im.direct = 1 + AND im.member_type = :atype AND im.member_id = :aid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr117a; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr117a + INTO :name, :active, :public, :hidden, :maillist, :grouplist; + if (sqlca.sqlcode) + break; + (*action)(6, rargv, actarg); + found++; } - EXEC SQL CLOSE csr117a; - } else { - EXEC SQL DECLARE csr117b CURSOR FOR - SELECT l.name, l.active, l.publicflg, l.hidden, - l.maillist, l.grouplist - FROM list l, imembers im - WHERE l.list_id = im.list_id - AND im.member_type = :atype AND im.member_id = :aid; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr117b; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr117b - INTO :name, :active, :public, :hidden, :maillist, :grouplist; - if(sqlca.sqlcode != 0) break; - (*action)(6, rargv, actarg); - found++; + EXEC SQL CLOSE csr117a; + } + else + { + EXEC SQL DECLARE csr117b CURSOR FOR + SELECT l.name, l.active, l.publicflg, l.hidden, l.maillist, l.grouplist + FROM list l, imembers im + WHERE l.list_id = im.list_id + AND im.member_type = :atype AND im.member_id = :aid; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr117b; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr117b + INTO :name, :active, :public, :hidden, :maillist, :grouplist; + if (sqlca.sqlcode) + break; + (*action)(6, rargv, actarg); + found++; } - EXEC SQL CLOSE csr117b; + EXEC SQL CLOSE csr117b; } - if (dbms_errno) return(mr_errcode); - if (!found) return(MR_NO_MATCH); - return(MR_SUCCESS); + if (dbms_errno) + return mr_errcode; + if (!found) + return MR_NO_MATCH; + return MR_SUCCESS; } @@ -866,39 +944,30 @@ int get_lists_of_member(q, argv, cl, action, actarg) static char *lflags[5] = { "active", "publicflg", "hidden", "maillist", "grouplist" }; -int qualified_get_lists(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int qualified_get_lists(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - return(qualified_get(q, argv, action, actarg, "l.list_id != 0", - "l", "name", lflags)); + return qualified_get(q, argv, action, actarg, "l.list_id != 0", + "l", "name", lflags); } /* get_members_of_list - this gets only direct members */ - -int get_members_of_list(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; + +int get_members_of_list(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - return(gmol_internal(q, argv, cl, action, actarg, 1)); + return gmol_internal(q, argv, cl, action, actarg, 1); } - + /* get_end_members_of_list - this gets direct or indirect members */ - -int get_end_members_of_list(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; + +int get_end_members_of_list(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - return(gmol_internal(q, argv, cl, action, actarg, 0)); + return gmol_internal(q, argv, cl, action, actarg, 0); } - + /** gmol_internal - optimized query for retrieval of list members ** used by both get_members_of_list and get_end_members_of_list ** @@ -909,106 +978,115 @@ int get_end_members_of_list(q, argv, cl, action, actarg) ** - retrieve USER members, then LIST members, then STRING members **/ -int gmol_internal(q, argv, cl, action, actarg, flag) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg, flag; +int gmol_internal(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg, int flag) { - EXEC SQL BEGIN DECLARE SECTION; - int list_id, member_id, direct; - char member_name[129], member_type[9]; - EXEC SQL END DECLARE SECTION; - char *targv[2]; - int members; - - /* true/false flag indicates whether to display only direct members. */ - if (flag) - direct = 0; - else - direct = -1; - - list_id = *(int *)argv[0]; - - targv[1] = member_name; - targv[0] = "USER"; - EXEC SQL DECLARE csr119 CURSOR FOR - SELECT u.login FROM users u, imembers im - WHERE im.list_id = :list_id AND im.member_type = 'USER' - AND im.member_id = u.users_id AND im.direct > :direct - ORDER BY 1; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr119; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr119 INTO :member_name; - if(sqlca.sqlcode != 0) break; - (*action)(2, targv, actarg); + EXEC SQL BEGIN DECLARE SECTION; + int list_id, member_id, direct; + char member_name[129], member_type[9]; + EXEC SQL END DECLARE SECTION; + char *targv[2]; + int members; + + /* true/false flag indicates whether to display only direct members. */ + if (flag) + direct = 0; + else + direct = -1; + + list_id = *(int *)argv[0]; + + targv[1] = member_name; + targv[0] = "USER"; + EXEC SQL DECLARE csr119 CURSOR FOR + SELECT u.login FROM users u, imembers im + WHERE im.list_id = :list_id AND im.member_type = 'USER' + AND im.member_id = u.users_id AND im.direct > :direct + ORDER BY 1; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr119; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr119 INTO :member_name; + if (sqlca.sqlcode) + break; + (*action)(2, targv, actarg); } - EXEC SQL CLOSE csr119; - if (dbms_errno) return(mr_errcode); - - targv[0] = "LIST"; - EXEC SQL DECLARE csr120 CURSOR FOR - SELECT l.name FROM list l, imembers im - WHERE im.list_id = :list_id AND im.member_type='LIST' - AND im.member_id = l.list_id AND im.direct > :direct - ORDER BY 1; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr120; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr120 INTO :member_name; - if(sqlca.sqlcode != 0) break; - (*action)(2, targv, actarg); + EXEC SQL CLOSE csr119; + if (dbms_errno) + return mr_errcode; + + targv[0] = "LIST"; + EXEC SQL DECLARE csr120 CURSOR FOR + SELECT l.name FROM list l, imembers im + WHERE im.list_id = :list_id AND im.member_type = 'LIST' + AND im.member_id = l.list_id AND im.direct > :direct + ORDER BY 1; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr120; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr120 INTO :member_name; + if (sqlca.sqlcode) + break; + (*action)(2, targv, actarg); } - EXEC SQL CLOSE csr120; - if (dbms_errno) return(mr_errcode); - - targv[0] = "STRING"; - EXEC SQL DECLARE csr121 CURSOR FOR - SELECT str.string FROM strings str, imembers im - WHERE im.list_id = :list_id AND im.member_type='STRING' - AND im.member_id = str.string_id AND im.direct > :direct - ORDER BY 1; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr121; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr121 INTO :member_name; - if(sqlca.sqlcode != 0) break; - (*action)(2, targv, actarg); + EXEC SQL CLOSE csr120; + if (dbms_errno) + return mr_errcode; + + targv[0] = "STRING"; + EXEC SQL DECLARE csr121 CURSOR FOR + SELECT str.string FROM strings str, imembers im + WHERE im.list_id = :list_id AND im.member_type = 'STRING' + AND im.member_id = str.string_id AND im.direct > :direct + ORDER BY 1; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr121; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr121 INTO :member_name; + if (sqlca.sqlcode) + break; + (*action)(2, targv, actarg); } - EXEC SQL CLOSE csr121; - if (dbms_errno) return(mr_errcode); - - targv[0] = "KERBEROS"; - EXEC SQL DECLARE csr122 CURSOR FOR - SELECT str.string FROM strings str, imembers im - WHERE im.list_id = :list_id AND im.member_type='KERBEROS' - AND im.member_id = str.string_id - AND im.direct > :direct - ORDER BY 1; - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr122; - if (dbms_errno) - return(mr_errcode); - while(1) { - EXEC SQL FETCH csr122 INTO :member_name; - if(sqlca.sqlcode != 0) break; - (*action)(2, targv, actarg); + EXEC SQL CLOSE csr121; + if (dbms_errno) + return mr_errcode; + + targv[0] = "KERBEROS"; + EXEC SQL DECLARE csr122 CURSOR FOR + SELECT str.string FROM strings str, imembers im + WHERE im.list_id = :list_id AND im.member_type = 'KERBEROS' + AND im.member_id = str.string_id + AND im.direct > :direct + ORDER BY 1; + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr122; + if (dbms_errno) + return mr_errcode; + while (1) + { + EXEC SQL FETCH csr122 INTO :member_name; + if (sqlca.sqlcode) + break; + (*action)(2, targv, actarg); } - EXEC SQL CLOSE csr122; - if (dbms_errno) return(mr_errcode); + EXEC SQL CLOSE csr122; + if (dbms_errno) + return mr_errcode; - return(MR_SUCCESS); + return MR_SUCCESS; } @@ -1016,25 +1094,23 @@ int gmol_internal(q, argv, cl, action, actarg, flag) * through the dispatch table. */ -int count_members_of_list(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int count_members_of_list(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - EXEC SQL BEGIN DECLARE SECTION; - int list, ct = 0; - EXEC SQL END DECLARE SECTION; - char *rargv[1], countbuf[5]; - - list = *(int *)argv[0]; - rargv[0] = countbuf; - EXEC SQL SELECT count (*) INTO :ct FROM imembers - WHERE list_id = :list AND direct=1; - if (dbms_errno) return(mr_errcode); - sprintf(countbuf, "%d", ct); - (*action)(1, rargv, actarg); - return(MR_SUCCESS); + EXEC SQL BEGIN DECLARE SECTION; + int list, ct = 0; + EXEC SQL END DECLARE SECTION; + char *rargv[1], countbuf[5]; + + list = *(int *)argv[0]; + rargv[0] = countbuf; + EXEC SQL SELECT count (*) INTO :ct FROM imembers + WHERE list_id = :list AND direct = 1; + if (dbms_errno) + return mr_errcode; + sprintf(countbuf, "%d", ct); + (*action)(1, rargv, actarg); + return MR_SUCCESS; } @@ -1046,16 +1122,13 @@ int count_members_of_list(q, argv, cl, action, actarg) static char *sflags[3] = { "enable", "inprogress", "harderror" }; -int qualified_get_server(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int qualified_get_server(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - return(qualified_get(q, argv, action, actarg, "s.name is not null", - "s", "name", sflags)); - /* of course, name will never be null, but we need something there - to make qualified_get happy */ + return qualified_get(q, argv, action, actarg, "s.name is not null", + "s", "name", sflags); + /* of course, name will never be null, but we need something there + to make qualified_get happy */ } @@ -1068,29 +1141,31 @@ int qualified_get_server(q, argv, cl, action, actarg) * flags - an array of strings, names of the flag variables */ -int qualified_get(q, argv, action, actarg, start, range, field, flags) - struct query *q; - char *argv[], *start, *range, *field, *flags[]; - int (*action)(), actarg; +int qualified_get(struct query *q, char *argv[], int (*action)(), int actarg, + char *start, char *range, char *field, char *flags[]) { - char qual[256]; - int i; - char buf[32]; - - strcpy(qual, start); - for (i = 0; i < q->argc; i++) { - if (!strcmp(argv[i], "TRUE")) { - sprintf(buf, " AND %s.%s != 0", range, flags[i]); - (void) strcat(qual, buf); - } else if (!strcmp(argv[i], "FALSE")) { - sprintf(buf, " AND %s.%s = 0", range, flags[i]); - (void) strcat(qual, buf); + char qual[256]; + int i; + char buf[32]; + + strcpy(qual, start); + for (i = 0; i < q->argc; i++) + { + if (!strcmp(argv[i], "TRUE")) + { + sprintf(buf, " AND %s.%s != 0", range, flags[i]); + strcat(qual, buf); + } + else if (!strcmp(argv[i], "FALSE")) + { + sprintf(buf, " AND %s.%s = 0", range, flags[i]); + strcat(qual, buf); } } - sprintf(stmt_buf,"SELECT %s.%s FROM %s %s WHERE %s",range,field, - table_name[q->rtable],range,qual); - return do_for_all_rows(stmt_buf, 1, action, actarg); + sprintf(stmt_buf, "SELECT %s.%s FROM %s %s WHERE %s", range, field, + table_name[q->rtable], range, qual); + return do_for_all_rows(stmt_buf, 1, action, actarg); } @@ -1103,30 +1178,31 @@ int qualified_get(q, argv, action, actarg, start, range, field, flags) static char *shflags[6] = { "service", "enable", "override", "success", "inprogress", "hosterror" }; -int qualified_get_serverhost(q, argv, cl, action, actarg) - struct query *q; - char *argv[]; - client *cl; - int (*action)(), actarg; +int qualified_get_serverhost(struct query *q, char *argv[], client *cl, + int (*action)(), int actarg) { - char qual[256], buf[32]; - int i; - - sprintf(qual, "m.mach_id = sh.mach_id AND sh.service = UPPER('%s')", - argv[0]); - for (i = 1; i < q->argc; i++) { - if (!strcmp(argv[i], "TRUE")) { - sprintf(buf, " AND sh.%s != 0", shflags[i]); - strcat(qual, buf); - } else if (!strcmp(argv[i], "FALSE")) { - sprintf(buf, " AND sh.%s = 0", shflags[i]); - strcat(qual, buf); + char qual[256], buf[32]; + int i; + + sprintf(qual, "m.mach_id = sh.mach_id AND sh.service = UPPER('%s')", + argv[0]); + for (i = 1; i < q->argc; i++) + { + if (!strcmp(argv[i], "TRUE")) + { + sprintf(buf, " AND sh.%s != 0", shflags[i]); + strcat(qual, buf); + } + else if (!strcmp(argv[i], "FALSE")) + { + sprintf(buf, " AND sh.%s = 0", shflags[i]); + strcat(qual, buf); } } - sprintf(stmt_buf, "SELECT sh.service, m.name FROM serverhosts sh, " - "machine m WHERE %s", qual); - return do_for_all_rows(stmt_buf, 2, action, actarg); + sprintf(stmt_buf, "SELECT sh.service, m.name FROM serverhosts sh, " + "machine m WHERE %s", qual); + return do_for_all_rows(stmt_buf, 2, action, actarg); } @@ -1137,167 +1213,184 @@ int qualified_get_serverhost(q, argv, cl, action, actarg) * MR_FS_STAFF, MR_FS_MISC). */ -int register_user(q, argv, cl) - struct query *q; - char **argv; - client *cl; +int register_user(struct query *q, char **argv, client *cl) { - EXEC SQL BEGIN DECLARE SECTION; - char *login, *entity, directory[129], machname[33]; - int who, rowcount, mid, uid, users_id, utype, list_id; - int ostatus, nstatus, gidval, fsidval; - static int m_id = 0, def_quota = 0; - EXEC SQL END DECLARE SECTION; - char buffer[256], *aargv[3]; - - entity = cl->entity; - who = cl->client_id; - - uid = atoi(argv[0]); - login = argv[1]; - utype = atoi(argv[2]); - - /* find user */ - EXEC SQL SELECT users_id, status INTO :users_id, :ostatus - FROM users - WHERE unix_uid = :uid AND (status=0 OR status=5 OR status=6); - - if (sqlca.sqlerrd[2] == 0) - return(MR_NO_MATCH); - if (sqlca.sqlerrd[2] > 1) - return(MR_NOT_UNIQUE); - - /* check new login name */ - EXEC SQL SELECT COUNT(login) INTO :rowcount FROM users - WHERE login = :login AND users_id != :users_id; - if (dbms_errno) return(mr_errcode); - if (rowcount > 0) return(MR_IN_USE); - EXEC SQL SELECT COUNT(name) INTO :rowcount FROM list - WHERE name = :login; - if (dbms_errno) return(mr_errcode); - if (rowcount > 0) return(MR_IN_USE); - EXEC SQL SELECT COUNT(label) INTO :rowcount FROM filesys - WHERE label = :login; - if (dbms_errno) return(mr_errcode); - if (rowcount > 0) return(MR_IN_USE); - EXEC SQL SELECT COUNT(name) INTO :rowcount FROM alias - WHERE name = :login AND type='FILESYS'; - if (dbms_errno) return(mr_errcode); - if (rowcount > 0) return(MR_IN_USE); - com_err(whoami, 0, "login name OK"); - - /* choose place for pobox, put in mid */ - EXEC SQL DECLARE csr130 CURSOR FOR - SELECT sh.mach_id, m.name FROM serverhosts sh, machine m - WHERE sh.service='POP' AND sh.mach_id=m.mach_id - AND sh.value2 - sh.value1 = - (SELECT MAX(value2 - value1) FROM serverhosts - WHERE service = 'POP'); - if (dbms_errno) - return(mr_errcode); - EXEC SQL OPEN csr130; - if (dbms_errno) - return(mr_errcode); - EXEC SQL FETCH csr130 INTO :mid, :machname; - if (sqlca.sqlerrd[2] == 0) { - EXEC SQL CLOSE csr130; - if (dbms_errno) return(mr_errcode); - return(MR_NO_POBOX); - } else { - EXEC SQL CLOSE csr130; - if (dbms_errno) return(mr_errcode); + EXEC SQL BEGIN DECLARE SECTION; + char *login, *entity, directory[129], machname[33]; + int who, rowcount, mid, uid, users_id, utype, list_id; + int ostatus, nstatus, gidval, fsidval; + static int m_id = 0, def_quota = 0; + EXEC SQL END DECLARE SECTION; + char buffer[256], *aargv[3]; + + entity = cl->entity; + who = cl->client_id; + + uid = atoi(argv[0]); + login = argv[1]; + utype = atoi(argv[2]); + + /* find user */ + EXEC SQL SELECT users_id, status INTO :users_id, :ostatus + FROM users + WHERE unix_uid = :uid AND (status = 0 OR status = 5 OR status = 6); + + if (sqlca.sqlerrd[2] == 0) + return MR_NO_MATCH; + if (sqlca.sqlerrd[2] > 1) + return MR_NOT_UNIQUE; + + /* check new login name */ + EXEC SQL SELECT COUNT(login) INTO :rowcount FROM users + WHERE login = :login AND users_id != :users_id; + if (dbms_errno) + return mr_errcode; + if (rowcount > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(name) INTO :rowcount FROM list + WHERE name = :login; + if (dbms_errno) + return mr_errcode; + if (rowcount > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(label) INTO :rowcount FROM filesys + WHERE label = :login; + if (dbms_errno) + return mr_errcode; + if (rowcount > 0) + return MR_IN_USE; + EXEC SQL SELECT COUNT(name) INTO :rowcount FROM alias + WHERE name = :login AND type = 'FILESYS'; + if (dbms_errno) + return mr_errcode; + if (rowcount > 0) + return MR_IN_USE; + com_err(whoami, 0, "login name OK"); + + /* choose place for pobox, put in mid */ + EXEC SQL DECLARE csr130 CURSOR FOR + SELECT sh.mach_id, m.name FROM serverhosts sh, machine m + WHERE sh.service = 'POP' AND sh.mach_id = m.mach_id + AND sh.value2 - sh.value1 = (SELECT MAX(value2 - value1) FROM serverhosts + WHERE service = 'POP'); + if (dbms_errno) + return mr_errcode; + EXEC SQL OPEN csr130; + if (dbms_errno) + return mr_errcode; + EXEC SQL FETCH csr130 INTO :mid, :machname; + if (sqlca.sqlerrd[2] == 0) + { + EXEC SQL CLOSE csr130; + if (dbms_errno) + return mr_errcode; + return MR_NO_POBOX; + } + else + { + EXEC SQL CLOSE csr130; + if (dbms_errno) + return mr_errcode; } - /* change login name, set pobox */ - sprintf(buffer, "u.users_id = %d", users_id); - incremental_before(USERS_TABLE, buffer, 0); - nstatus = 2; - if (ostatus == 5 || ostatus == 6) - nstatus = 1; - EXEC SQL UPDATE users SET login = :login, status = :nstatus, - modtime=SYSDATE, modby = :who, modwith = :entity, potype='POP', - pop_id = :mid, pmodtime=SYSDATE, pmodby = :who, pmodwith = :entity - WHERE users_id = :users_id; - - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - set_pop_usage(mid, 1); - com_err(whoami, 0, "set login name to %s and pobox to %s", login, - strtrim(machname)); - incremental_after(USERS_TABLE, buffer, 0); - - if (m_id == 0) { - /* Cell Name (I know, it shouldn't be hard coded...) */ - strcpy(machname, "ATHENA.MIT.EDU"); - EXEC SQL SELECT mach_id INTO :m_id FROM machine - WHERE name = :machname; + /* change login name, set pobox */ + sprintf(buffer, "u.users_id = %d", users_id); + incremental_before(USERS_TABLE, buffer, 0); + nstatus = 2; + if (ostatus == 5 || ostatus == 6) + nstatus = 1; + EXEC SQL UPDATE users SET login = :login, status = :nstatus, + modtime = SYSDATE, modby = :who, modwith = :entity, potype = 'POP', + pop_id = :mid, pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity + WHERE users_id = :users_id; + + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + set_pop_usage(mid, 1); + com_err(whoami, 0, "set login name to %s and pobox to %s", login, + strtrim(machname)); + incremental_after(USERS_TABLE, buffer, 0); + + if (m_id == 0) + { + /* Cell Name (I know, it shouldn't be hard coded...) */ + strcpy(machname, "ATHENA.MIT.EDU"); + EXEC SQL SELECT mach_id INTO :m_id FROM machine + WHERE name = :machname; } - EXEC SQL SELECT list_id INTO :list_id FROM list - WHERE name='wheel'; - - /* create filesystem */ - if (set_next_object_id("filsys_id", FILESYS_TABLE, 0)) - return(MR_NO_ID); - incremental_clear_before(); - if (islower(login[0]) && islower(login[1])) { - sprintf(directory, "/afs/athena.mit.edu/user/%c/%c/%s", - login[0], login[1], login); - } else { - sprintf(directory, "/afs/athena.mit.edu/user/other/%s", login); + EXEC SQL SELECT list_id INTO :list_id FROM list + WHERE name = 'wheel'; + + /* create filesystem */ + if (set_next_object_id("filsys_id", FILESYS_TABLE, 0)) + return MR_NO_ID; + incremental_clear_before(); + if (islower(login[0]) && islower(login[1])) + { + sprintf(directory, "/afs/athena.mit.edu/user/%c/%c/%s", + login[0], login[1], login); } - - EXEC SQL SELECT value INTO :fsidval FROM numvalues - WHERE numvalues.name='filsys_id'; - EXEC SQL INSERT INTO filesys - (filsys_id, phys_id, label, type, mach_id, name, - mount, rwaccess, comments, owner, owners, createflg, - lockertype, modtime, modby, modwith) - VALUES - (:fsidval, 0, :login, 'AFS', :m_id, :directory, - '/mit/' || :login, 'w', 'User Locker', :users_id, :list_id, 1, - 'HOMEDIR', SYSDATE, :who, :entity); - - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - sprintf(buffer,"fs.filsys_id = %d",fsidval); - incremental_after(FILESYS_TABLE, buffer, 0); - - /* set quota */ - if (def_quota == 0) { - EXEC SQL SELECT value INTO :def_quota FROM numvalues - WHERE name='def_quota'; - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] != 1) - return(MR_NO_QUOTA); - + else + sprintf(directory, "/afs/athena.mit.edu/user/other/%s", login); + + EXEC SQL SELECT value INTO :fsidval FROM numvalues + WHERE numvalues.name = 'filsys_id'; + EXEC SQL INSERT INTO filesys + (filsys_id, phys_id, label, type, mach_id, name, + mount, rwaccess, comments, owner, owners, createflg, + lockertype, modtime, modby, modwith) + VALUES + (:fsidval, 0, :login, 'AFS', :m_id, :directory, + '/mit/' || :login, 'w', 'User Locker', :users_id, :list_id, 1, + 'HOMEDIR', SYSDATE, :who, :entity); + + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + sprintf(buffer, "fs.filsys_id = %d", fsidval); + incremental_after(FILESYS_TABLE, buffer, 0); + + /* set quota */ + if (def_quota == 0) + { + EXEC SQL SELECT value INTO :def_quota FROM numvalues + WHERE name = 'def_quota'; + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_NO_QUOTA; } - incremental_clear_before(); - EXEC SQL INSERT INTO quota - (entity_id, filsys_id, type, quota, phys_id, modtime, modby, modwith) - VALUES - (0, :fsidval, 'ANY', :def_quota, 0, SYSDATE, :who, :entity); - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] != 1) - return(MR_INTERNAL); - aargv[0] = login; - aargv[1] = "ANY"; - aargv[2] = login; - sprintf(buffer, "q.entity_id = 0 and q.filsys_id = %d and q.type = 'ANY'", fsidval); - incremental_after(QUOTA_TABLE, buffer, aargv); - com_err(whoami, 0, "quota of %d assigned", def_quota); - if (dbms_errno) return(mr_errcode); - - cache_entry(login, USERS_TABLE, users_id); - - EXEC SQL UPDATE tblstats SET updates=updates+1, modtime=SYSDATE - WHERE table_name='users'; - EXEC SQL UPDATE tblstats SET appends=appends+1, modtime=SYSDATE - WHERE table_name='filesys' OR table_name='quota'; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + incremental_clear_before(); + EXEC SQL INSERT INTO quota + (entity_id, filsys_id, type, quota, phys_id, modtime, modby, modwith) + VALUES (0, :fsidval, 'ANY', :def_quota, 0, SYSDATE, :who, :entity); + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_INTERNAL; + aargv[0] = login; + aargv[1] = "ANY"; + aargv[2] = login; + sprintf(buffer, "q.entity_id = 0 and q.filsys_id = %d and q.type = 'ANY'", + fsidval); + incremental_after(QUOTA_TABLE, buffer, aargv); + com_err(whoami, 0, "quota of %d assigned", def_quota); + if (dbms_errno) + return mr_errcode; + + cache_entry(login, USERS_TABLE, users_id); + + EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE + WHERE table_name = 'users'; + EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE + WHERE table_name = 'filesys' OR table_name = 'quota'; + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -1316,14 +1409,15 @@ int register_user(q, argv, cl) int set_pop_usage(id, cnt) int id, cnt; { - EXEC SQL BEGIN DECLARE SECTION; - int iid = id, icnt = cnt; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int iid = id, icnt = cnt; + EXEC SQL END DECLARE SECTION; - EXEC SQL UPDATE serverhosts SET value1 = value1 + :icnt - WHERE serverhosts.service = 'POP' AND serverhosts.mach_id = :iid; + EXEC SQL UPDATE serverhosts SET value1 = value1 + :icnt + WHERE serverhosts.service = 'POP' AND serverhosts.mach_id = :iid; - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } diff --git a/server/queries2.c b/server/queries2.c index d6675b97..0adf1496 100644 --- a/server/queries2.c +++ b/server/queries2.c @@ -174,7 +174,7 @@ int num_tables = 27; * A word about validation objects and locking: The validation object * for a query should also request locks on behalf of the pre-processing * and post-processing routines. This helps to ensure that tables are - * accessed and locked in the proper order and thus avoids deadlock + * accessed and locked in the proper order and thus avoids deadlock * situations */ @@ -210,7 +210,7 @@ static struct valobj VOwild01sort01[] = { {V_WILD, 0}, {V_WILD, 1}, {V_SORT, 0}, - {V_SORT, 1}, + {V_SORT, 1}, }; static struct valobj VOwild012sort0[] = { /* get_alias */ @@ -265,9 +265,9 @@ static struct valobj VOfilsys0user1[] = { static struct validate VDmach = { VOmach0, 1 }; static struct validate VDwild0= { VOwild0, 1 }; static struct validate VDupwild0= { VOupwild0, 1 }; -static struct validate VDwild2sort2 = { VOwild01sort01,4 }; -static struct validate VDwild3sort1 = { VOwild012sort0,4 }; -static struct validate VDsortf = { +static struct validate VDwild2sort2 = { VOwild01sort01, 4 }; +static struct validate VDwild3sort1 = { VOwild012sort0, 4 }; +static struct validate VDsortf = { VOsort0, 1, 0, @@ -279,7 +279,7 @@ static struct validate VDsortf = { followup_fix_modby, }; -static struct validate VDwildsortf = { +static struct validate VDwildsortf = { VOwild0sort, 2, 0, @@ -318,11 +318,11 @@ static char *gual_fields[] = { static char *gubl_fields[] = { LOGIN, - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, MOD1, MOD2, MOD3, }; -static struct validate gubl_validate = +static struct validate gubl_validate = { VOwild0sort, 2, @@ -347,7 +347,7 @@ static char *guan_fields[] = { MIT_ID, CLASS, COMMENTS, SIGNATURE, SECURE, MOD1, MOD2, MOD3, }; -static struct validate guan_validate = +static struct validate guan_validate = { VOwild01sort01, 4, @@ -374,11 +374,11 @@ static char *guam_fields[] = { static char *gubu_fields[] = { UID, - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, MOD1, MOD2, MOD3, }; -static struct validate gubu_validate = +static struct validate gubu_validate = { VOsort0, 1, @@ -393,7 +393,7 @@ static struct validate gubu_validate = static char *gubn_fields[] = { FIRST, LAST, - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, MOD1, MOD2, MOD3, }; @@ -412,13 +412,13 @@ static struct validate gubn_validate = static char *gubc_fields[] = { CLASS, - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, MOD1, MOD2, MOD3, }; static char *gubm_fields[] = { MIT_ID, - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, MOD1, MOD2, MOD3, }; @@ -427,7 +427,7 @@ static char *gudf_fields[] = { "dirsuppress", "dirremote" }; -static struct validate gudf_validate = +static struct validate gudf_validate = { VOuser0, 2, @@ -441,7 +441,7 @@ static struct validate gudf_validate = }; static char *auac_fields[] = { - LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, COMMENTS, SIGNATURE, SECURE, }; @@ -489,11 +489,11 @@ static struct valobj rusr_valobj[] = { {V_LOCK, 0, IMEMBERS_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_LOCK, 0, FILESYS_TABLE, 0, FILSYS_ID, MR_DEADLOCK}, {V_LOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, - {V_RLOCK, 0, MACHINE_TABLE, 0,MACH_ID, MR_DEADLOCK}, + {V_RLOCK, 0, MACHINE_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_LOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_LOCK, 0, NFSPHYS_TABLE, 0, "nfsphys_id", MR_DEADLOCK}, - {V_LOCK, 0, QUOTA_TABLE,0, FILSYS_ID, MR_DEADLOCK}, - {V_RLOCK,0, SERVERHOSTS_TABLE,0, MACH_ID, MR_DEADLOCK}, + {V_LOCK, 0, QUOTA_TABLE, 0, FILSYS_ID, MR_DEADLOCK}, + {V_RLOCK, 0, SERVERHOSTS_TABLE, 0, MACH_ID, MR_DEADLOCK}, }; static struct validate rusr_validate = { @@ -510,7 +510,7 @@ static struct validate rusr_validate = { static char *uuac_fields[] = { LOGIN, - "newlogin", UID, SHELL, LAST, FIRST, MIDDLE, STATUS, + "newlogin", UID, SHELL, LAST, FIRST, MIDDLE, STATUS, MIT_ID, CLASS, COMMENTS, SIGNATURE, SECURE, }; @@ -671,7 +671,6 @@ static struct valobj akum_valobj[] = {V_LOCK, 0, KRBMAP_TABLE, 0, "users_id", MR_DEADLOCK}, {V_ID, 0, USERS_TABLE, LOGIN, USERS_ID, MR_USER}, {V_ID, 1, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, - }; static struct validate akum_validate = @@ -703,7 +702,7 @@ static struct validate dkum_validate = static char *gfbl_fields[] = { LOGIN, LOGIN, "fullname", "nickname", "home_addr", - "home_phone", "office_addr", "office_phone", "department", + "home_phone", "office_addr", "office_phone", "department", "affiliation", MOD1, MOD2, MOD3, }; @@ -722,7 +721,7 @@ static struct validate gfbl_validate = { static char *ufbl_fields[] = { LOGIN, "fullname", "nickname", "home_addr", - "home_phone", "office_addr", "office_phone", "department", + "home_phone", "office_addr", "office_phone", "department", "affiliation", }; @@ -760,7 +759,7 @@ static struct validate gpob_validate = { VOuser0, 1, "potype", - "potype != 'NONE' and users_id=%d", + "potype != 'NONE' and users_id = %d", 1, 0, access_user, @@ -772,7 +771,7 @@ static char *gpox_fields[] = { LOGIN, TYPE, "box", }; -struct valobj gpox_valobj[]={ +struct valobj gpox_valobj[] = { {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, {V_RLOCK, 0, MACHINE_TABLE, 0, MACH_ID, MR_DEADLOCK} }; @@ -863,7 +862,7 @@ static struct valobj ghst_valobj[] = { {V_SORT, 0}, }; -static struct validate ghst_validate = { +static struct validate ghst_validate = { ghst_valobj, 5, 0, @@ -886,7 +885,7 @@ static struct valobj ahst_valobj[] = { {V_CHAR, 3, MACHINE_TABLE, "os"}, {V_CHAR, 4, MACHINE_TABLE, "location"}, {V_CHAR, 5, MACHINE_TABLE, "contact"}, - {V_RLOCK,0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, + {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, {V_LOCK, 0, MACHINE_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_RLOCK, 0, SUBNET_TABLE, 0, SNET_ID, MR_DEADLOCK}, {V_RLOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, @@ -976,8 +975,8 @@ static struct validate dhst_validate = { }; static char *ghal_fields[] = { - ALIAS, "canonical_hostname", - ALIAS, "canonical_hostname" + ALIAS, "canonical_hostname", + ALIAS, "canonical_hostname" }; static struct valobj ghal_valobj[] = { @@ -1035,9 +1034,9 @@ static struct validate dhal_validate = { }; static char *gsnt_fields[] = { - NAME, - NAME, DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, - MOD1, MOD2, MOD3 + NAME, + NAME, DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, + MOD1, MOD2, MOD3 }; static struct valobj gsnt_valobj[] = { @@ -1061,7 +1060,7 @@ static struct validate gsnt_validate = { }; static char *asnt_fields[] = { - NAME, DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, + NAME, DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, }; static struct valobj asnt_valobj[] = { @@ -1075,22 +1074,22 @@ static struct valobj asnt_valobj[] = { {V_TYPEDATA, 8, 0, 0, 0, MR_ACE}, }; -static struct validate asnt_validate = +static struct validate asnt_validate = { - asnt_valobj, - 8, - NAME, - "name = UPPER('%s')", - 1, - SNET_ID, - 0, - prefetch_value, - set_uppercase_modtime, + asnt_valobj, + 8, + NAME, + "name = UPPER('%s')", + 1, + SNET_ID, + 0, + prefetch_value, + set_uppercase_modtime, }; static char *usnt_fields[] = { - NAME, - "newname", DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, + NAME, + "newname", DESC, ADDRESS, "mask", "low", "high", "prefix", ACE_TYPE, ACE_NAME, }; static struct valobj usnt_valobj[] = { @@ -1105,17 +1104,17 @@ static struct valobj usnt_valobj[] = { {V_TYPEDATA, 9, 0, 0, 0, MR_ACE}, }; -static struct validate usnt_validate = +static struct validate usnt_validate = { - usnt_valobj, - 9, - NAME, - "snet_id = %d", - 1, - SNET_ID, - 0, - 0, - set_modtime_by_id, + usnt_valobj, + 9, + NAME, + "snet_id = %d", + 1, + SNET_ID, + 0, + 0, + set_modtime_by_id, }; static char *dsnt_fields[] = { @@ -1142,7 +1141,7 @@ static struct validate dsnt_validate = { static char *gclu_fields[] = { NAME, - NAME, DESC, LOCATION, MOD1, MOD2, MOD3, + NAME, DESC, LOCATION, MOD1, MOD2, MOD3, }; static char *aclu_fields[] = { @@ -1156,7 +1155,7 @@ static struct valobj aclu_valobj[] = { {V_LEN, 2, CLUSTER_TABLE, LOCATION}, }; -static struct validate aclu_validate = +static struct validate aclu_validate = { aclu_valobj, 4, @@ -1260,8 +1259,8 @@ static struct valobj acld_valobj[] = {V_CHAR, 2, SVC_TABLE, "serv_cluster"} }; -static struct validate acld_validate = -{ +static struct validate acld_validate = +{ acld_valobj, 3, CLU_ID, @@ -1278,8 +1277,8 @@ static struct valobj dcld_valobj[] = {V_ID, 0, CLUSTER_TABLE, NAME, CLU_ID, MR_CLUSTER}, }; -static struct validate dcld_validate = -{ +static struct validate dcld_validate = +{ dcld_valobj, 1, CLU_ID, @@ -1367,13 +1366,13 @@ static char *dlis_fields[] = { NAME, }; -static struct valobj dlis_valobj[] ={ +static struct valobj dlis_valobj[] = { {V_RLOCK, 0, CAPACLS_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_RLOCK, 0, IMEMBERS_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_RLOCK, 0, FILESYS_TABLE, 0, FILSYS_ID, MR_DEADLOCK}, {V_LOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_RLOCK, 0, QUOTA_TABLE, 0, FILSYS_ID, MR_DEADLOCK}, - {V_RLOCK, 0, ZEPHYR_TABLE, 0, ZEPH_ID, MR_DEADLOCK}, + {V_RLOCK, 0, ZEPHYR_TABLE, 0, ZEPH_ID, MR_DEADLOCK}, {V_RLOCK, 0, HOSTACCESS_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_ID, 0, LIST_TABLE, NAME, LIST_ID, MR_LIST} }; @@ -1485,14 +1484,14 @@ static char *gmol_fields[] = { "member_type", "member_name", }; -static struct valobj gmol_valobj[]={ +static struct valobj gmol_valobj[] = { {V_LOCK, 0, IMEMBERS_TABLE, 0, LIST_ID, MR_DEADLOCK}, {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, {V_ID, 0, LIST_TABLE, NAME, LIST_ID, MR_LIST}, }; static struct validate gmol_validate = { - gmol_valobj, + gmol_valobj, 3, 0, 0, @@ -1521,12 +1520,12 @@ static char *glom_fields[] = { }; static struct valobj glom_valobj[] = { - {V_LOCK, 0, IMEMBERS_TABLE, 0, LIST_ID, MR_DEADLOCK}, - {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, - {V_RLOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, - {V_TYPE, 0, 0, "rmember", 0, MR_TYPE}, - {V_TYPEDATA, 1, 0, 0, 0, MR_NO_MATCH}, - {V_SORT, 0}, + {V_LOCK, 0, IMEMBERS_TABLE, 0, LIST_ID, MR_DEADLOCK}, + {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, + {V_RLOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, + {V_TYPE, 0, 0, "rmember", 0, MR_TYPE}, + {V_TYPEDATA, 1, 0, 0, 0, MR_NO_MATCH}, + {V_SORT, 0}, }; static struct validate glom_validate = { @@ -1572,7 +1571,7 @@ static struct valobj gsin_valobj[] = {V_UPWILD, 0 }, }; -static struct validate gsin_validate = +static struct validate gsin_validate = { gsin_valobj, 3, @@ -1693,7 +1692,7 @@ static char *gshi_fields[] = { SERVICE, MACHINE, SERVICE, MACHINE, "enable", "override", "success", "inprogress", "hosterror", "hosterrormsg", "ltt", "lts", "value1", "value2", - "value3", MOD1, MOD2, MOD3, + "value3", MOD1, MOD2, MOD3, }; static struct valobj gshi_valobj[] = { @@ -1745,7 +1744,7 @@ static char *ashi_fields[] = { static struct valobj ashi_valobj[] = { {V_LOCK, 0, MACHINE_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_NAME, 0, SERVERS_TABLE, NAME, 0, MR_SERVICE}, - {V_LOCK, 0, SERVERHOSTS_TABLE,0, MACH_ID, MR_DEADLOCK}, + {V_LOCK, 0, SERVERHOSTS_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_ID, 1, MACHINE_TABLE, NAME, MACH_ID, MR_MACHINE}, {V_CHAR, 0, SERVERHOSTS_TABLE, NAME}, {V_LEN, 5, SERVERHOSTS_TABLE, "value3"}, @@ -1764,7 +1763,7 @@ static struct validate ashi_validate = /* ashi & ushi */ set_serverhost_modtime, }; -static struct validate rshe_validate = +static struct validate rshe_validate = { ashi_valobj, 4, @@ -1777,7 +1776,7 @@ static struct validate rshe_validate = set_serverhost_modtime, }; -static struct validate ssho_validate = +static struct validate ssho_validate = { ashi_valobj, 4, @@ -1802,7 +1801,7 @@ static struct valobj sshi_valobj[] = { {V_LEN, 5, SERVERS_TABLE, "errmsg"}, }; -static struct validate sshi_validate = +static struct validate sshi_validate = { sshi_valobj, 4, @@ -1819,7 +1818,7 @@ static char *dshi_fields[] = { SERVICE, MACHINE, }; -static struct validate dshi_validate = +static struct validate dshi_validate = { ashi_valobj, 4, @@ -2014,7 +2013,7 @@ static struct validate dfil_validate = { static char *gfgm_fields[] = { "fsgroup", FILESYS, "sortkey" - }; +}; static struct valobj gfgm_valobj[] = { {V_ID, 0, FILESYS_TABLE, LABEL, FILSYS_ID, MR_FILESYS}, @@ -2309,7 +2308,7 @@ static struct validate dnfq_validate = { static char *gzcl_fields[] = { CLASS, CLASS, "xmt_type", "xmt_name", "sub_type", "sub_name", - "iws_type", "iws_name", "iui_type", "iui_name", MOD1, MOD2, MOD3, + "iws_type", "iws_name", "iui_type", "iui_name", MOD1, MOD2, MOD3, }; static struct valobj gzcl_valobj[] = { @@ -2339,7 +2338,7 @@ static char *azcl_fields[] = { static struct valobj azcl_valobj[] = { {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, {V_RLOCK, 0, LIST_TABLE, 0, LIST_ID, MR_DEADLOCK}, - {V_LOCK, 0, ZEPHYR_TABLE, 0, ZEPH_ID, MR_DEADLOCK}, + {V_LOCK, 0, ZEPHYR_TABLE, 0, ZEPH_ID, MR_DEADLOCK}, {V_CHAR, 0, ZEPHYR_TABLE, CLASS}, {V_TYPE, 1, 0, ACE_TYPE, 0, MR_ACE}, {V_TYPEDATA, 2, 0, 0, LIST_ID, MR_ACE}, @@ -2412,7 +2411,7 @@ static char *gsha_fields[] = { MACHINE, ACE_TYPE, ACE_NAME, MOD1, MOD2, MOD3, }; -static struct validate gsha_validate = +static struct validate gsha_validate = { VOupwild0, 1, @@ -2437,7 +2436,7 @@ static struct valobj asha_valobj[] = { {V_TYPEDATA, 2, 0, 0, 0, MR_ACE}, }; -static struct validate asha_validate = +static struct validate asha_validate = { asha_valobj, 5, @@ -2484,7 +2483,7 @@ static char *gpce_fields[] = { MOD1, MOD2, MOD3, }; -static struct valobj gpce_valobj[]={ +static struct valobj gpce_valobj[] = { {V_RLOCK, 0, USERS_TABLE, 0, USERS_ID, MR_DEADLOCK}, {V_RLOCK, 0, MACHINE_TABLE, 0, MACH_ID, MR_DEADLOCK}, {V_RLOCK, 0, PRINTCAP_TABLE, 0, MACH_ID, MR_DEADLOCK}, @@ -2677,20 +2676,20 @@ static char *gats_fields[] = { }; static char *_sdl_fields[] = { - "level", + "level", }; -static struct validate _sdl_validate = +static struct validate _sdl_validate = { - 0, - 0, - (char *)0, - (char *)0, - 0, - 0, - 0, - 0, - _sdl_followup, + 0, + 0, + (char *)0, + (char *)0, + 0, + 0, + 0, + 0, + _sdl_followup, }; @@ -2716,7 +2715,7 @@ struct query Queries2[] = { 0, &VDsort0, }, - + { /* Q_GAAL - GET_ALL_ACTIVE_LOGINS */ "get_all_active_logins", @@ -2731,7 +2730,7 @@ struct query Queries2[] = { 0, &VDsort0, }, - + { /* Q_GUAL - GET_USER_ACCOUNT_BY_LOGIN */ "get_user_account_by_login", @@ -2746,7 +2745,7 @@ struct query Queries2[] = { 1, &gubl_validate, }, - + { /* Q_GUAU - GET_USER_ACCOUNT_BY_UID */ "get_user_account_by_uid", @@ -2761,7 +2760,7 @@ struct query Queries2[] = { 1, &gubu_validate, }, - + { /* Q_GUAN - GET_USER_ACCOUNT_BY_NAME */ "get_user_account_by_name", @@ -2776,7 +2775,7 @@ struct query Queries2[] = { 2, &guan_validate, }, - + { /* Q_GUAC - GET_USER_ACCOUNT_BY_CLASS */ "get_user_account_by_class", @@ -2791,7 +2790,7 @@ struct query Queries2[] = { 1, &VDsortf, }, - + { /* Q_GUAM - GET_USER_ACCOUNT_BY_MITID */ "get_user_account_by_id", @@ -2806,14 +2805,14 @@ struct query Queries2[] = { 1, &VDwildsortf, }, - + { /* Q_GUBL - GET_USER_BY_LOGIN */ "get_user_by_login", "gubl", RETRIEVE, "u", - USERS_TABLE, + USERS_TABLE, "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u", gubl_fields, 12, @@ -2821,7 +2820,7 @@ struct query Queries2[] = { 1, &gubl_validate, }, - + { /* Q_GUBU - GET_USER_BY_UID */ "get_user_by_uid", @@ -2836,7 +2835,7 @@ struct query Queries2[] = { 1, &gubu_validate, }, - + { /* Q_GUBN - GET_USER_BY_NAME */ "get_user_by_name", @@ -2851,7 +2850,7 @@ struct query Queries2[] = { 2, &gubn_validate, }, - + { /* Q_GUBC - GET_USER_BY_CLASS */ "get_user_by_class", @@ -2866,7 +2865,7 @@ struct query Queries2[] = { 1, &VDsortf, }, - + { /* Q_GUBM - GET_USER_BY_MITID */ "get_user_by_mitid", @@ -2881,7 +2880,7 @@ struct query Queries2[] = { 1, &VDwildsortf, }, - + { /* Q_GUDF - GET_USER_DIRECTORY_FLAGS */ "get_user_directory_flags", @@ -2904,14 +2903,14 @@ struct query Queries2[] = { APPEND, "u", USERS_TABLE, - "INTO users (login, unix_uid, shell, last, first, middle, status, clearid, type, comments, signature, secure, users_id) VALUES ('%s', %s, '%s', NVL('%s',CHR(0)), NVL('%s',CHR(0)), NVL('%s',CHR(0)), %s, NVL('%s',CHR(0)), '%s', %d, LENGTH(NVL('%s',CHR(0))), %s, %s)", /* followup_ausr fixes signature field */ + "INTO users (login, unix_uid, shell, last, first, middle, status, clearid, type, comments, signature, secure, users_id) VALUES ('%s', %s, '%s', NVL('%s', CHR(0)), NVL('%s', CHR(0)), NVL('%s', CHR(0)), %s, NVL('%s', CHR(0)), '%s', %d, LENGTH(NVL('%s', CHR(0))), %s, %s)", /* followup_ausr fixes signature field */ auac_fields, 12, (char *)0, 0, &auac_validate, }, - + { /* Q_AUSR - ADD_USER */ /* uses prefetch_value() for users_id */ "add_user", @@ -2919,14 +2918,14 @@ struct query Queries2[] = { APPEND, "u", USERS_TABLE, - "INTO users (login, unix_uid, shell, last, first, middle, status, clearid, type, comments, signature, secure, users_id) VALUES ('%s', %s, '%s', NVL('%s',CHR(0)), NVL('%s',CHR(0)), NVL('%s',CHR(0)), %s, NVL('%s',CHR(0)), '%s', 0, CHR(0), 0, %s)", + "INTO users (login, unix_uid, shell, last, first, middle, status, clearid, type, comments, signature, secure, users_id) VALUES ('%s', %s, '%s', NVL('%s', CHR(0)), NVL('%s', CHR(0)), NVL('%s', CHR(0)), %s, NVL('%s', CHR(0)), '%s', 0, CHR(0), 0, %s)", auac_fields, 9, 0, 0, &ausr_validate, }, - + { /* Q_RUSR - REGISTER_USER */ "register_user", @@ -2941,7 +2940,7 @@ struct query Queries2[] = { 0, &rusr_validate, }, - + { /* Q_UUAC - UPDATE_USER_ACCOUNT */ "update_user_account", @@ -2949,14 +2948,14 @@ struct query Queries2[] = { UPDATE, "u", USERS_TABLE, - "users SET login = '%s', unix_uid = %s, shell = '%s', last = NVL('%s',CHR(0)), first = NVL('%s',CHR(0)), middle = NVL('%s',CHR(0)), status = %s, clearid = NVL('%s',CHR(0)), type = '%s', comments = %d, signature = LENGTH(NVL('%s',CHR(0))), secure = %s", /* followup_uuac fixes signature */ + "users SET login = '%s', unix_uid = %s, shell = '%s', last = NVL('%s', CHR(0)), first = NVL('%s', CHR(0)), middle = NVL('%s', CHR(0)), status = %s, clearid = NVL('%s', CHR(0)), type = '%s', comments = %d, signature = LENGTH(NVL('%s', CHR(0))), secure = %s", /* followup_uuac fixes signature */ uuac_fields, 12, "users_id = %d", 1, &uuac_validate, }, - + { /* Q_UUSR - UPDATE_USER */ "update_user", @@ -2964,7 +2963,7 @@ struct query Queries2[] = { UPDATE, "u", USERS_TABLE, - "users SET login = '%s', unix_uid = %s, shell = '%s', last = NVL('%s',CHR(0)), first = NVL('%s',CHR(0)), middle = NVL('%s',CHR(0)), status = %s, clearid = NVL('%s',CHR(0)), type = '%s'", + "users SET login = '%s', unix_uid = %s, shell = '%s', last = NVL('%s', CHR(0)), first = NVL('%s', CHR(0)), middle = NVL('%s', CHR(0)), status = %s, clearid = NVL('%s', CHR(0)), type = '%s'", uuac_fields, 9, "users_id = %d", @@ -2979,7 +2978,7 @@ struct query Queries2[] = { UPDATE, "u", USERS_TABLE, - "users SET shell = '%s'", + "users SET shell = '%s'", uush_fields, 1, "users_id = %d", @@ -3016,7 +3015,7 @@ struct query Queries2[] = { 1, &uust_validate, }, - + { /* Q_UUDF - UPDATE_USER_DIRECTORY_FLAGS */ "update_user_directory_flags", @@ -3033,7 +3032,7 @@ struct query Queries2[] = { }, { - /* Q_DUSR - DELETE_USER */ + /* Q_DUSR - DELETE_USER */ "delete_user", "dusr", DELETE, @@ -3063,7 +3062,7 @@ struct query Queries2[] = { }, { - /* Q_GKUM - GET_KERBEROS_USER_MAP */ + /* Q_GKUM - GET_KERBEROS_USER_MAP */ "get_kerberos_user_map", "gkum", RETRIEVE, @@ -3129,7 +3128,7 @@ struct query Queries2[] = { UPDATE, "u", USERS_TABLE, - "users SET fullname= NVL('%s',CHR(0)),nickname= NVL('%s',CHR(0)),home_addr= NVL('%s',CHR(0)),home_phone= NVL('%s',CHR(0)),office_addr= NVL('%s',CHR(0)),office_phone= NVL('%s',CHR(0)),department= NVL('%s',CHR(0)),affiliation= NVL('%s',CHR(0))", + "users SET fullname= NVL('%s', CHR(0)), nickname= NVL('%s', CHR(0)), home_addr= NVL('%s', CHR(0)), home_phone= NVL('%s', CHR(0)), office_addr= NVL('%s', CHR(0)), office_phone= NVL('%s', CHR(0)), department= NVL('%s', CHR(0)), affiliation= NVL('%s', CHR(0))", ufbl_fields, 8, "users_id = %d", @@ -3166,7 +3165,7 @@ struct query Queries2[] = { 0, &gpox_validate, }, - + { /* Q_GPOP - GET_POBOXES_POP */ "get_poboxes_pop", @@ -3252,7 +3251,7 @@ struct query Queries2[] = { "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s", ghst_fields, 21, - "m.name LIKE '%s' ESCAPE '*' AND m.address LIKE '%s' ESCAPE '*' AND m.location LIKE '%s' ESCAPE '*' AND s.name LIKE '%s' ESCAPE '*' AND m.mach_id != 0 AND s.snet_id = m.snet_id", + "m.name LIKE '%s' ESCAPE '*' AND m.address LIKE '%s' ESCAPE '*' AND m.location LIKE '%s' ESCAPE '*' AND s.name LIKE '%s' ESCAPE '*' AND m.mach_id != 0 AND s.snet_id = m.snet_id", 4, &ghst_validate, }, @@ -3264,7 +3263,7 @@ struct query Queries2[] = { APPEND, "m", MACHINE_TABLE, - "INTO machine (name, vendor, model, os, location, contact, use, status, statuschange, snet_id, address, owner_type, owner_id, acomment, ocomment, created, inuse, mach_id, creator) VALUES (UPPER('%s'),NVL(UPPER('%s'),CHR(0)),NVL(UPPER('%s'),CHR(0)),NVL(UPPER('%s'),CHR(0)),NVL(UPPER('%s'),CHR(0)),NVL('%s',CHR(0)),%s,%s,SYSDATE,%d,'%s','%s',%d,%d,%d,SYSDATE,SYSDATE,%s,%s)", + "INTO machine (name, vendor, model, os, location, contact, use, status, statuschange, snet_id, address, owner_type, owner_id, acomment, ocomment, created, inuse, mach_id, creator) VALUES (UPPER('%s'), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL('%s', CHR(0)), %s, %s, SYSDATE, %d, '%s', '%s', %d, %d, %d, SYSDATE, SYSDATE, %s, %s)", ahst_fields, 14, 0, @@ -3279,7 +3278,7 @@ struct query Queries2[] = { UPDATE, "m", MACHINE_TABLE, - "machine SET name=NVL(UPPER('%s'),CHR(0)),vendor=NVL(UPPER('%s'),CHR(0)),model=NVL(UPPER('%s'),CHR(0)),os=NVL(UPPER('%s'),CHR(0)),location=NVL(UPPER('%s'),CHR(0)),contact=NVL('%s',CHR(0)),use=%s,status=%s,snet_id=%d,address='%s',owner_type='%s',owner_id=%d,acomment=%d,ocomment=%d", + "machine SET name = NVL(UPPER('%s'), CHR(0)), vendor = NVL(UPPER('%s'), CHR(0)), model = NVL(UPPER('%s'), CHR(0)), os = NVL(UPPER('%s'), CHR(0)), location = NVL(UPPER('%s'), CHR(0)), contact = NVL('%s', CHR(0)), use = %s, status = %s, snet_id = %d, address = '%s', owner_type = '%s', owner_id = %d, acomment = %d, ocomment = %d", uhst_fields, 14, "mach_id = %d", @@ -3312,7 +3311,7 @@ struct query Queries2[] = { "name, vendor, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM machine", gmac_fields, 5, - "name LIKE '%s' ESCAPE '*' AND mach_id != 0", + "name LIKE '%s' ESCAPE '*' AND mach_id != 0", 1, &VDupwildsortf, }, @@ -3339,7 +3338,7 @@ struct query Queries2[] = { APPEND, "a", HOSTALIAS_TABLE, - "INTO hostalias (name, mach_id) VALUES (UPPER('%s'),%d)", + "INTO hostalias (name, mach_id) VALUES (UPPER('%s'), %d)", ghal_fields, 2, 0, @@ -3384,7 +3383,7 @@ struct query Queries2[] = { APPEND, "s", SUBNET_TABLE, - "INTO subnet (name, description, saddr, mask, low, high, prefix, owner_type, owner_id, snet_id) VALUES (UPPER('%s'), NVL('%s',CHR(0)), %s, %s, %s, %s, NVL('%s',CHR(0)), '%s', %d, %s)", + "INTO subnet (name, description, saddr, mask, low, high, prefix, owner_type, owner_id, snet_id) VALUES (UPPER('%s'), NVL('%s', CHR(0)), %s, %s, %s, %s, NVL('%s', CHR(0)), '%s', %d, %s)", asnt_fields, 9, 0, @@ -3399,7 +3398,7 @@ struct query Queries2[] = { UPDATE, "s", SUBNET_TABLE, - "subnet SET name=UPPER('%s'), description=NVL('%s',CHR(0)), saddr=%s, mask=%s, low=%s, high=%s, prefix=NVL('%s',CHR(0)), owner_type='%s', owner_id=%d", + "subnet SET name = UPPER('%s'), description = NVL('%s', CHR(0)), saddr = %s, mask = %s, low = %s, high = %s, prefix = NVL('%s', CHR(0)), owner_type = '%s', owner_id = %d", usnt_fields, 9, "snet_id = %d", @@ -3444,7 +3443,7 @@ struct query Queries2[] = { APPEND, "c", CLUSTER_TABLE, - "INTO clusters (name, description, location, clu_id) VALUES ('%s',NVL('%s',CHR(0)),NVL('%s',CHR(0)),%s)", + "INTO clusters (name, description, location, clu_id) VALUES ('%s', NVL('%s', CHR(0)), NVL('%s', CHR(0)), %s)", aclu_fields, 3, 0, @@ -3459,7 +3458,7 @@ struct query Queries2[] = { UPDATE, "c", CLUSTER_TABLE, - "clusters SET name = '%s', description = NVL('%s',CHR(0)), location = NVL('%s',CHR(0))", + "clusters SET name = '%s', description = NVL('%s', CHR(0)), location = NVL('%s', CHR(0))", uclu_fields, 3, "clu_id = %d", @@ -3483,7 +3482,7 @@ struct query Queries2[] = { }, { - /* Q_GMCM - GET_MACHINE_TO_CLUSTER_MAP */ + /* Q_GMCM - GET_MACHINE_TO_CLUSTER_MAP */ "get_machine_to_cluster_map", "gmcm", RETRIEVE, @@ -3494,9 +3493,9 @@ struct query Queries2[] = { 2, "m.name LIKE '%s' ESCAPE '*' AND c.name LIKE '%s' ESCAPE '*' AND mcm.clu_id = c.clu_id AND mcm.mach_id = m.mach_id", 2, - &gmcm_validate, + &gmcm_validate, }, - + { /* Q_AMTC - ADD_MACHINE_TO_CLUSTER */ "add_machine_to_cluster", @@ -3549,7 +3548,7 @@ struct query Queries2[] = { APPEND, "svc", SVC_TABLE, - "INTO svc (clu_id, serv_label, serv_cluster) VALUES (%d,'%s','%s')", + "INTO svc (clu_id, serv_label, serv_cluster) VALUES (%d, '%s', '%s')", acld_fields, 3, (char *)0, @@ -3567,7 +3566,7 @@ struct query Queries2[] = { (char *)0, acld_fields, 0, - "clu_id = %d AND serv_label = '%s' AND serv_cluster = '%s'", + "clu_id = %d AND serv_label = '%s' AND serv_cluster = '%s'", 3, &dcld_validate, }, @@ -3583,10 +3582,10 @@ struct query Queries2[] = { glin_fields, 13, 0, - 1, - &glin_validate, + 1, + &glin_validate, }, - + { /* Q_EXLN - EXPAND_LIST_NAMES */ "expand_list_names", @@ -3601,15 +3600,15 @@ struct query Queries2[] = { 1, &VDwild0, }, - + { /* Q_ALIS - ADD_LIST */ /* uses prefetch_value() for list_id */ "add_list", "alis", APPEND, "l", - LIST_TABLE, - "INTO list (name, active, publicflg, hidden, maillist, grouplist, gid, acl_type, acl_id, description, list_id) VALUES ('%s',%s,%s,%s,%s,%s,%s,'%s',%d,NVL('%s',CHR(0)),%s)", + LIST_TABLE, + "INTO list (name, active, publicflg, hidden, maillist, grouplist, gid, acl_type, acl_id, description, list_id) VALUES ('%s', %s, %s, %s, %s, %s, %s, '%s', %d, NVL('%s', CHR(0)), %s)", alis_fields, 10, 0, @@ -3624,7 +3623,7 @@ struct query Queries2[] = { UPDATE, "l", LIST_TABLE, - "list SET name='%s', active=%s, publicflg=%s, hidden=%s, maillist=%s, grouplist=%s, gid=%s, acl_type='%s', acl_id=%d, description=NVL('%s',CHR(0))", + "list SET name = '%s', active = %s, publicflg = %s, hidden = %s, maillist = %s, grouplist = %s, gid = %s, acl_type = '%s', acl_id = %d, description = NVL('%s', CHR(0))", ulis_fields, 10, "list_id = %d", @@ -3736,7 +3735,7 @@ struct query Queries2[] = { 1, &geml_validate, }, - + { /* Q_GLOM - GET_LISTS_OF_MEMBER */ "get_lists_of_member", @@ -3804,7 +3803,7 @@ struct query Queries2[] = { APPEND, "s", SERVERS_TABLE, - "INTO servers (name, update_int, target_file, script, type, enable, acl_type, acl_id) VALUES (UPPER('%s'),%s,'%s','%s','%s',%s,'%s',%d)", + "INTO servers (name, update_int, target_file, script, type, enable, acl_type, acl_id) VALUES (UPPER('%s'), %s, '%s', '%s', '%s', %s, '%s', %d)", asin_fields, 8, (char *)0, @@ -3849,7 +3848,7 @@ struct query Queries2[] = { UPDATE, "s", SERVERS_TABLE, - "servers SET dfgen = %s, dfcheck = %s, inprogress = %s, harderror = %s, errmsg = NVL('%s',CHR(0))", + "servers SET dfgen = %s, dfcheck = %s, inprogress = %s, harderror = %s, errmsg = NVL('%s', CHR(0))", ssif_fields, 5, "name = UPPER('%s')", @@ -3873,7 +3872,7 @@ struct query Queries2[] = { }, { - /* Q_GSHI - GET_SERVER_HOST_INFO */ + /* Q_GSHI - GET_SERVER_HOST_INFO */ "get_server_host_info", "gshi", RETRIEVE, @@ -3909,7 +3908,7 @@ struct query Queries2[] = { APPEND, "sh", SERVERHOSTS_TABLE, - "INTO serverhosts (service, mach_id, enable, value1, value2, value3) VALUES (UPPER('%s'), %d, %s, %s, %s, NVL('%s',CHR(0)))", + "INTO serverhosts (service, mach_id, enable, value1, value2, value3) VALUES (UPPER('%s'), %d, %s, %s, %s, NVL('%s', CHR(0)))", ashi_fields, 6, (char *)0, @@ -3924,7 +3923,7 @@ struct query Queries2[] = { UPDATE, "sh", SERVERHOSTS_TABLE, - "serverhosts SET enable = %s, value1 = %s, value2 = %s, value3 = NVL('%s',CHR(0))", + "serverhosts SET enable = %s, value1 = %s, value2 = %s, value3 = NVL('%s', CHR(0))", ashi_fields, 4, "service = UPPER('%s') AND mach_id = %d", @@ -3969,10 +3968,10 @@ struct query Queries2[] = { UPDATE, "s", SERVERHOSTS_TABLE, - "serverhosts SET override = %s, success = %s, inprogress = %s, hosterror = %s, hosterrmsg = NVL('%s',CHR(0)), ltt = %s, lts = %s", + "serverhosts SET override = %s, success = %s, inprogress = %s, hosterror = %s, hosterrmsg = NVL('%s', CHR(0)), ltt = %s, lts = %s", sshi_fields, 7, - "service = UPPER('%s') AND mach_id = %d", + "service = UPPER('%s') AND mach_id = %d", 2, &sshi_validate, }, @@ -3993,7 +3992,7 @@ struct query Queries2[] = { }, { - /* Q_GSLO - GET_SERVER_LOCATIONS */ + /* Q_GSLO - GET_SERVER_LOCATIONS */ "get_server_locations", "gslo", RETRIEVE, @@ -4008,7 +4007,7 @@ struct query Queries2[] = { }, { - /* Q_GFSL - GET_FILESYS_BY_LABEL */ + /* Q_GFSL - GET_FILESYS_BY_LABEL */ "get_filesys_by_label", "gfsl", RETRIEVE, @@ -4023,7 +4022,7 @@ struct query Queries2[] = { }, { - /* Q_GFSM - GET_FILESYS_BY_MACHINE */ + /* Q_GFSM - GET_FILESYS_BY_MACHINE */ "get_filesys_by_machine", "gfsm", RETRIEVE, @@ -4038,7 +4037,7 @@ struct query Queries2[] = { }, { - /* Q_GFSN - GET_FILESYS_BY_NFSPHYS */ + /* Q_GFSN - GET_FILESYS_BY_NFSPHYS */ "get_filesys_by_nfsphys", "gfsn", RETRIEVE, @@ -4047,13 +4046,13 @@ struct query Queries2[] = { "fs.label, fs.type, m.name, fs.name, fs.mount, fs.rwaccess, fs.comments, u.login, l.name, fs.createflg, fs.lockertype, TO_CHAR(fs.modtime, 'DD-mon-YYYY HH24:MI:SS'), fs.modby, fs.modwith FROM filesys fs, machine m, users u, list l, nfsphys np", gfsn_fields, 14, - "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir LIKE '%s' ESCAPE '*' AND fs.type = 'NFS'", + "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir LIKE '%s' ESCAPE '*' AND fs.type = 'NFS'", 2, &gfsn_validate, }, { - /* Q_GFSG - GET_FILESYS_BY_GROUP */ + /* Q_GFSG - GET_FILESYS_BY_GROUP */ "get_filesys_by_group", "gfsg", RETRIEVE, @@ -4081,7 +4080,7 @@ struct query Queries2[] = { 1, &VDwildsortf, }, - + { /* Q_AFIL - ADD_FILESYS */ /* uses prefetch_value() for filsys_id */ "add_filesys", @@ -4089,7 +4088,7 @@ struct query Queries2[] = { APPEND, "fs", FILESYS_TABLE, - "INTO filesys (label, type, mach_id, name, mount, rwaccess, comments, owner, owners, createflg, lockertype, filsys_id) VALUES ('%s','%s',%d,NVL('%s',CHR(0)),'%s','%s',NVL('%s',CHR(0)),%d,%d,%s,'%s',%s)", + "INTO filesys (label, type, mach_id, name, mount, rwaccess, comments, owner, owners, createflg, lockertype, filsys_id) VALUES ('%s', '%s', %d, NVL('%s', CHR(0)), '%s', '%s', NVL('%s', CHR(0)), %d, %d, %s, '%s', %s)", afil_fields, 11, 0, @@ -4104,12 +4103,12 @@ struct query Queries2[] = { UPDATE, "fs", FILESYS_TABLE, - "filesys SET label = '%s', type = '%s', mach_id = %d, name = NVL('%s',CHR(0)), mount = '%s', rwaccess = '%s', comments = NVL('%s',CHR(0)), owner = %d, owners = %d, createflg = %s, lockertype = '%s'", + "filesys SET label = '%s', type = '%s', mach_id = %d, name = NVL('%s', CHR(0)), mount = '%s', rwaccess = '%s', comments = NVL('%s', CHR(0)), owner = %d, owners = %d, createflg = %s, lockertype = '%s'", ufil_fields, 11, "filsys_id = %d", 1, - &ufil_validate, + &ufil_validate, }, { @@ -4128,7 +4127,7 @@ struct query Queries2[] = { }, { - /* Q_GFGM - GET_FSGROUP_MEMBERS */ + /* Q_GFGM - GET_FSGROUP_MEMBERS */ "get_fsgroup_members", "gfgm", RETRIEVE, @@ -4149,7 +4148,7 @@ struct query Queries2[] = { APPEND, "fg", FSGROUP_TABLE, - "INTO fsgroup (group_id,filsys_id,key) VALUES (%d, %d, '%s')", + "INTO fsgroup (group_id, filsys_id, key) VALUES (%d, %d, '%s')", gfgm_fields, 3, (char *)0, @@ -4173,7 +4172,7 @@ struct query Queries2[] = { }, { - /* Q_GANF - GET_ALL_NFSPHYS */ + /* Q_GANF - GET_ALL_NFSPHYS */ "get_all_nfsphys", "ganf", RETRIEVE, @@ -4188,7 +4187,7 @@ struct query Queries2[] = { }, { - /* Q_GNFP - GET_NFSPHYS */ + /* Q_GNFP - GET_NFSPHYS */ "get_nfsphys", "gnfp", RETRIEVE, @@ -4197,7 +4196,7 @@ struct query Queries2[] = { "m.name, np.dir, np.device, np.status, np.allocated, np.partsize, TO_CHAR(np.modtime, 'DD-mon-YYYY HH24:MI:SS'), np.modby, np.modwith FROM nfsphys np, machine m", gnfp_fields, 9, - "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND m.mach_id = np.mach_id", + "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND m.mach_id = np.mach_id", 2, &gnfp_validate, }, @@ -4209,7 +4208,7 @@ struct query Queries2[] = { APPEND, "np", NFSPHYS_TABLE, - "INTO nfsphys (mach_id, dir, device, status, allocated, partsize, nfsphys_id) VALUES (%d, '%s', NVL('%s',CHR(0)), %s, %s, %s, %s)", + "INTO nfsphys (mach_id, dir, device, status, allocated, partsize, nfsphys_id) VALUES (%d, '%s', NVL('%s', CHR(0)), %s, %s, %s, %s)", ganf_fields, 6, 0, @@ -4224,10 +4223,10 @@ struct query Queries2[] = { UPDATE, "np", NFSPHYS_TABLE, - "nfsphys SET device = NVL('%s',CHR(0)), status = %s, allocated = %s, partsize = %s", + "nfsphys SET device = NVL('%s', CHR(0)), status = %s, allocated = %s, partsize = %s", ganf_fields, 4, - "mach_id = %d AND dir = '%s'", + "mach_id = %d AND dir = '%s'", 2, &unfp_validate, }, @@ -4263,7 +4262,7 @@ struct query Queries2[] = { }, { - /* Q_GQOT - GET_QUOTA */ + /* Q_GQOT - GET_QUOTA */ "get_quota", "gqot", RETRIEVE, @@ -4278,7 +4277,7 @@ struct query Queries2[] = { }, { - /* Q_GQBF - GET_QUOTA_BY_FILESYS */ + /* Q_GQBF - GET_QUOTA_BY_FILESYS */ "get_quota_by_filesys", "gqbf", RETRIEVE, @@ -4338,7 +4337,7 @@ struct query Queries2[] = { }, { - /* Q_GNFQ - GET_NFS_QUOTAS */ + /* Q_GNFQ - GET_NFS_QUOTAS */ "get_nfs_quota", "gnfq", RETRIEVE, @@ -4353,7 +4352,7 @@ struct query Queries2[] = { }, { - /* Q_GNQP - GET_NFS_QUOTAS_BY_PARTITION */ + /* Q_GNQP - GET_NFS_QUOTAS_BY_PARTITION */ "get_nfs_quotas_by_partition", "gnqp", RETRIEVE, @@ -4383,7 +4382,7 @@ struct query Queries2[] = { }, { - /* Q_UNFQ - UPDATE_NFS_QUOTA */ + /* Q_UNFQ - UPDATE_NFS_QUOTA */ "update_nfs_quota", "unfq", UPDATE, @@ -4434,13 +4433,13 @@ struct query Queries2[] = { APPEND, "z", ZEPHYR_TABLE, - "INTO zephyr (class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id, iui_type, iui_id) VALUES ('%s','%s',%d,'%s',%d,'%s',%d,'%s',%d)", + "INTO zephyr (class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id, iui_type, iui_id) VALUES ('%s', '%s', %d, '%s', %d, '%s', %d, '%s', %d)", azcl_fields, 9, 0, 0, &azcl_validate, - }, + }, { /* Q_UZCL - UPDATE_ZEPHYR_CLASS */ @@ -4455,7 +4454,7 @@ struct query Queries2[] = { "class = '%s'", 1, &uzcl_validate, - }, + }, { /* Q_DZCL - DELETE_ZEPHYR_CLASS */ @@ -4470,10 +4469,10 @@ struct query Queries2[] = { "class = '%s'", 1, &dzcl_validate, - }, + }, { - /* Q_GSHA - GET_SERVER_HOST_ACCESS */ + /* Q_GSHA - GET_SERVER_HOST_ACCESS */ "get_server_host_access", "gsha", RETRIEVE, @@ -4494,7 +4493,7 @@ struct query Queries2[] = { APPEND, "ha", HOSTACCESS_TABLE, - "INTO hostaccess (mach_id, acl_type, acl_id) VALUES (%d,'%s',%d)", + "INTO hostaccess (mach_id, acl_type, acl_id) VALUES (%d, '%s', %d)", asha_fields, 3, 0, @@ -4554,7 +4553,7 @@ struct query Queries2[] = { APPEND, "ss", SERVICES_TABLE, - "INTO services (name, protocol, port, description) VALUES ('%s','%s',%s,NVL('%s',CHR(0)))", + "INTO services (name, protocol, port, description) VALUES ('%s', '%s', %s, NVL('%s', CHR(0)))", asvc_fields, 4, (char *)0, @@ -4578,7 +4577,7 @@ struct query Queries2[] = { }, { - /* Q_GPCE - GET_PRINTCAP_ENTRY */ + /* Q_GPCE - GET_PRINTCAP_ENTRY */ "get_printcap_entry", "gpce", RETRIEVE, @@ -4599,7 +4598,7 @@ struct query Queries2[] = { APPEND, "pc", PRINTCAP_TABLE, - "INTO printcap (name, mach_id, dir, rp, quotaserver, auth, price, comments) VALUES ('%s',%d,'%s','%s',%d,%s,%s,NVL('%s',CHR(0)))", + "INTO printcap (name, mach_id, dir, rp, quotaserver, auth, price, comments) VALUES ('%s', %d, '%s', '%s', %d, %s, %s, NVL('%s', CHR(0)))", apce_fields, 8, 0, @@ -4674,7 +4673,7 @@ struct query Queries2[] = { APPEND, "pal", PALLADIUM_TABLE, - "INTO palladium (name, identifier, mach_id) VALUES ('%s',%s,%d)", + "INTO palladium (name, identifier, mach_id) VALUES ('%s', %s, %d)", apdm_fields, 3, 0, @@ -4737,7 +4736,7 @@ struct query Queries2[] = { (char *)0, aali_fields, 0, - "name = '%s' AND type = '%s' AND trans = '%s'", + "name = '%s' AND type = '%s' AND trans = '%s'", 3, &dali_validate, }, @@ -4834,4 +4833,4 @@ struct query Queries2[] = { }; -int QueryCount2 = (sizeof Queries2 / sizeof (struct query)); +int QueryCount2 = (sizeof(Queries2) / sizeof(struct query)); diff --git a/server/query.h b/server/query.h index 3087652a..ffb3af81 100644 --- a/server/query.h +++ b/server/query.h @@ -18,55 +18,55 @@ enum tables {NO_TABLE, USERS_TABLE, KRBMAP_TABLE, MACHINE_TABLE, /* Query Definition Structure */ struct query { - char *name; /* query name */ - char *shortname; /* abbreviated query name (must be 4 chars) */ - enum query_type type; /* query type */ - char *rvar; /* range variable */ - enum tables rtable; /* range table */ - char *tlist; /* target list */ - char **fields; /* input and output variable names (for help) */ - int vcnt; /* variable count */ - char *qual; /* format string for "where" clause */ - int argc; /* number of args for qualifier */ - struct validate *validate; /* validation support */ - int acl; /* hint as to query ACL for this query */ - int everybody; /* is the default user on this ACL? */ + char *name; /* query name */ + char *shortname; /* abbreviated query name (must be 4 chars) */ + enum query_type type; /* query type */ + char *rvar; /* range variable */ + enum tables rtable; /* range table */ + char *tlist; /* target list */ + char **fields; /* input and output variable names (for help) */ + int vcnt; /* variable count */ + char *qual; /* format string for "where" clause */ + int argc; /* number of args for qualifier */ + struct validate *validate; /* validation support */ + int acl; /* hint as to query ACL for this query */ + int everybody; /* is the default user on this ACL? */ }; /* Query Validation Structure */ struct validate { - /* object validation (e.g., user, filesys, type) */ - struct valobj *valobj; /* array of object validation descriptors */ - int objcnt; /* size of array */ - /* row validation - retrieve (exists = any(rvar.field where qual)) */ - char *field; /* field to check for */ - char *qual; /* format string for "where" clause */ - int argc; /* number of args used in qual */ - /* values field containing current max object id */ - char *object_id; - /* routine to verify access permission on objects */ - int (*acs_rtn)(); - /* pre-processing routine (var setup only) */ - int (*pre_rtn)(); - /* post-processing routine */ - int (*post_rtn)(); + /* object validation (e.g., user, filesys, type) */ + struct valobj *valobj; /* array of object validation descriptors */ + int objcnt; /* size of array */ + /* row validation - retrieve (exists = any(rvar.field where qual)) */ + char *field; /* field to check for */ + char *qual; /* format string for "where" clause */ + int argc; /* number of args used in qual */ + /* values field containing current max object id */ + char *object_id; + /* routine to verify access permission on objects */ + int (*acs_rtn)(); + /* pre-processing routine (var setup only) */ + int (*pre_rtn)(); + /* post-processing routine */ + int (*post_rtn)(); }; - + /* Validated Object Types */ -enum vo_type {V_NAME, V_ID, V_TYPE, V_TYPEDATA, V_DATE, +enum vo_type {V_NAME, V_ID, V_TYPE, V_TYPEDATA, V_DATE, V_SORT, V_RENAME, V_CHAR, V_LOCK, V_WILD, V_UPWILD, V_RLOCK, V_LEN}; /* Validated Object Definition */ struct valobj { - enum vo_type type; - int index; /* index of object to validate */ - enum tables table; /* table containing object */ - char *namefield; /* table's fieldname for object */ - char *idfield; /* table's corresponding id field (if any) */ - int error; + enum vo_type type; + int index; /* index of object to validate */ + enum tables table; /* table containing object */ + char *namefield; /* table's fieldname for object */ + char *idfield; /* table's corresponding id field (if any) */ + int error; }; diff --git a/server/qvalidate.pc b/server/qvalidate.pc index 8fbf0624..dbc58fe1 100644 --- a/server/qvalidate.pc +++ b/server/qvalidate.pc @@ -41,134 +41,137 @@ int lock_table(struct valobj *vo); int readlock_table(struct valobj *vo); int convert_wildcards_uppercase(char *arg); -extern SQLDA *sqlald(int,int,int); +extern SQLDA *sqlald(int, int, int); EXEC SQL WHENEVER SQLERROR DO dbmserr(); /* Validation Routines */ -int validate_row(q, argv, v) - register struct query *q; - char *argv[]; - register struct validate *v; +int validate_row(register struct query *q, char *argv[], register struct validate *v) { - EXEC SQL BEGIN DECLARE SECTION; - char qual[128]; - int rowcount; - EXEC SQL END DECLARE SECTION; - - /* build where clause */ - build_qual(v->qual, v->argc, argv, qual); - - if (log_flags & LOG_VALID) - /* tell the logfile what we're doing */ - com_err(whoami, 0, "validating row: %s", qual); - - /* look for the record */ - sprintf(stmt_buf,"SELECT COUNT (*) FROM %s WHERE %s", - table_name[q->rtable],qual); - dosql(sqlbuffer); - if (dbms_errno) return(mr_errcode); - - rowcount = atoi(sqlbuffer[0]); - if (rowcount == 0) return(MR_NO_MATCH); - if (rowcount > 1) return(MR_NOT_UNIQUE); - return(MR_EXISTS); + EXEC SQL BEGIN DECLARE SECTION; + char qual[128]; + int rowcount; + EXEC SQL END DECLARE SECTION; + + /* build where clause */ + build_qual(v->qual, v->argc, argv, qual); + + if (log_flags & LOG_VALID) + /* tell the logfile what we're doing */ + com_err(whoami, 0, "validating row: %s", qual); + + /* look for the record */ + sprintf(stmt_buf, "SELECT COUNT (*) FROM %s WHERE %s", + table_name[q->rtable], qual); + dosql(sqlbuffer); + if (dbms_errno) + return mr_errcode; + + rowcount = atoi(sqlbuffer[0]); + if (rowcount == 0) + return MR_NO_MATCH; + if (rowcount > 1) + return MR_NOT_UNIQUE; + return MR_EXISTS; } -int validate_fields(q, argv, vo, n) - struct query *q; - register char *argv[]; - register struct valobj *vo; - register int n; +int validate_fields(struct query *q, register char *argv[], + register struct valobj *vo, register int n) { - register int status; + register int status; - while (--n >= 0) { - switch (vo->type) { + while (--n >= 0) + { + switch (vo->type) + { case V_NAME: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating %s in %s: %s", - vo->namefield, table_name[vo->table], argv[vo->index]); - status = validate_name(argv, vo); - break; + if (log_flags & LOG_VALID) + { + com_err(whoami, 0, "validating %s in %s: %s", + vo->namefield, table_name[vo->table], argv[vo->index]); + } + status = validate_name(argv, vo); + break; case V_ID: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating %s in %s: %s", - vo->idfield, table_name[vo->table], argv[vo->index]); - status = validate_id(q, argv, vo); - break; - - /* - case V_DATE: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating date: %s", argv[vo->index]); - status = validate_date(argv, vo); - break; - */ + if (log_flags & LOG_VALID) + { + com_err(whoami, 0, "validating %s in %s: %s", + vo->idfield, table_name[vo->table], argv[vo->index]); + } + status = validate_id(q, argv, vo); + break; case V_TYPE: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating %s type: %s", - table_name[vo->table], argv[vo->index]); - status = validate_type(argv, vo); - break; + if (log_flags & LOG_VALID) + { + com_err(whoami, 0, "validating %s type: %s", + table_name[vo->table], argv[vo->index]); + } + status = validate_type(argv, vo); + break; case V_TYPEDATA: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating typed data (%s): %s", - argv[vo->index - 1], argv[vo->index]); - status = validate_typedata(q, argv, vo); - break; + if (log_flags & LOG_VALID) + { + com_err(whoami, 0, "validating typed data (%s): %s", + argv[vo->index - 1], argv[vo->index]); + } + status = validate_typedata(q, argv, vo); + break; case V_RENAME: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating rename %s in %s", - argv[vo->index], table_name[vo->table]); - status = validate_rename(argv, vo); - break; + if (log_flags & LOG_VALID) + { + com_err(whoami, 0, "validating rename %s in %s", + argv[vo->index], table_name[vo->table]); + } + status = validate_rename(argv, vo); + break; case V_CHAR: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating chars: %s", argv[vo->index]); - status = validate_chars(argv, vo); - break; + if (log_flags & LOG_VALID) + com_err(whoami, 0, "validating chars: %s", argv[vo->index]); + status = validate_chars(argv, vo); + break; case V_LEN: - if (log_flags & LOG_VALID) - com_err(whoami, 0, "validating length: %s", argv[vo->index]); - status = validate_len(argv, vo); - break; + if (log_flags & LOG_VALID) + com_err(whoami, 0, "validating length: %s", argv[vo->index]); + status = validate_len(argv, vo); + break; case V_SORT: - status = MR_EXISTS; - break; + status = MR_EXISTS; + break; case V_LOCK: - status = lock_table(vo); - break; + status = lock_table(vo); + break; case V_RLOCK: - status = readlock_table(vo); - break; + status = readlock_table(vo); + break; case V_WILD: - status = convert_wildcards(argv[vo->index]); - break; + status = convert_wildcards(argv[vo->index]); + break; case V_UPWILD: - status = convert_wildcards_uppercase(argv[vo->index]); - break; + status = convert_wildcards_uppercase(argv[vo->index]); + break; } - if (status != MR_EXISTS) return(status); - vo++; + if (status != MR_EXISTS) + return status; + vo++; } - if (dbms_errno) return(mr_errcode); - return(MR_SUCCESS); + if (dbms_errno) + return mr_errcode; + return MR_SUCCESS; } @@ -177,381 +180,407 @@ int validate_fields(q, argv, vo, n) * ", *, ?, \, [ and ]. */ static int illegalchars[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0 - ? */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* : - O */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, /* P - _ */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */ + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0 - ? */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* : - O */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, /* P - _ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; -int validate_chars(argv, vo) - char *argv[]; - register struct valobj *vo; +int validate_chars(char *argv[], register struct valobj *vo) { - char *s=argv[vo->index]; - int arg; - EXEC SQL BEGIN DECLARE SECTION; - int len; - char *tname, *cname; - EXEC SQL END DECLARE SECTION; - - - /* check for bad characters */ - while (*s) + char *s = argv[vo->index]; + int arg; + EXEC SQL BEGIN DECLARE SECTION; + int len; + char *tname, *cname; + EXEC SQL END DECLARE SECTION; + + /* check for bad characters */ + while (*s) + { if (illegalchars[*s++]) - return(MR_BAD_CHAR); + return MR_BAD_CHAR; + } - /* check for length */ - tname = table_name[vo->table]; - cname = vo->namefield; - EXEC SQL SELECT data_length INTO :len FROM user_tab_columns - WHERE table_name=UPPER(:tname) AND column_name=UPPER(:cname); + /* check for length */ + tname = table_name[vo->table]; + cname = vo->namefield; + EXEC SQL SELECT data_length INTO :len FROM user_tab_columns + WHERE table_name = UPPER(:tname) AND column_name = UPPER(:cname); - if((strlen(argv[vo->index]) > len) && - strcmp(argv[vo->index], UNIQUE_LOGIN)) /* kludge... sigh */ - argv[vo->index][len]='\0'; /* truncate */ + if ((strlen(argv[vo->index]) > len) && + strcmp(argv[vo->index], UNIQUE_LOGIN)) /* kludge... sigh */ + argv[vo->index][len] = '\0'; /* truncate */ - return MR_EXISTS; + return MR_EXISTS; } -int validate_id(q, argv, vo) - struct query *q; - char *argv[]; - register struct valobj *vo; +int validate_id(struct query *q, char *argv[], register struct valobj *vo) { - EXEC SQL BEGIN DECLARE SECTION; - char *name, *namefield, *idfield; - int id, rowcount, tbl; - EXEC SQL END DECLARE SECTION; - int status; - register char *c; - - name = argv[vo->index]; - tbl = vo->table; - namefield = vo->namefield; - idfield = vo->idfield; - - if ((tbl==USERS_TABLE && !strcmp(namefield, "login")) || - tbl==MACHINE_TABLE || tbl==SUBNET_TABLE || tbl==FILESYS_TABLE || - tbl==LIST_TABLE || tbl==CLUSTER_TABLE || tbl==STRINGS_TABLE) { - if (tbl==MACHINE_TABLE || tbl==SUBNET_TABLE) - for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c); + EXEC SQL BEGIN DECLARE SECTION; + char *name, *namefield, *idfield; + int id, rowcount, tbl; + EXEC SQL END DECLARE SECTION; + int status; + register char *c; + + name = argv[vo->index]; + tbl = vo->table; + namefield = vo->namefield; + idfield = vo->idfield; + + if ((tbl == USERS_TABLE && !strcmp(namefield, "login")) || + tbl == MACHINE_TABLE || tbl == SUBNET_TABLE || tbl == FILESYS_TABLE || + tbl == LIST_TABLE || tbl == CLUSTER_TABLE || tbl == STRINGS_TABLE) + { + if (tbl == MACHINE_TABLE || tbl == SUBNET_TABLE) + { + for (c = name; *c; c++) + { + if (islower(*c)) + *c = toupper(*c); + } + } status = name_to_id(name, tbl, &id); - if (status == 0) { - *(int *)argv[vo->index] = id; - return(MR_EXISTS); - } else if (status == MR_NO_MATCH && tbl==STRINGS_TABLE && - (q->type == APPEND || q->type == UPDATE)) { - id=add_string(name); - cache_entry(name, STRINGS_TABLE, id); - *(int *)argv[vo->index] = id; - return(MR_EXISTS); - } else if (status == MR_NO_MATCH || status == MR_NOT_UNIQUE) - return(vo->error); + if (status == 0) + { + *(int *)argv[vo->index] = id; + return MR_EXISTS; + } + else if (status == MR_NO_MATCH && tbl == STRINGS_TABLE && + (q->type == APPEND || q->type == UPDATE)) + { + id = add_string(name); + cache_entry(name, STRINGS_TABLE, id); + *(int *)argv[vo->index] = id; + return MR_EXISTS; + } + else if (status == MR_NO_MATCH || status == MR_NOT_UNIQUE) + return vo->error; else - return(status); - } else { + return status; + } + else + { /* else, it's `dubu', which uses unix_uid from users */ EXEC SQL SELECT COUNT(*) INTO :rowcount FROM users WHERE unix_uid = :name; - if (dbms_errno) return(mr_errcode); - if (rowcount != 1) return(vo->error); + if (dbms_errno) + return mr_errcode; + if (rowcount != 1) + return vo->error; EXEC SQL SELECT users_id INTO :id FROM users WHERE unix_uid = :name; *(int *)argv[vo->index] = id; - return(MR_EXISTS); + return MR_EXISTS; } } -int validate_name(argv, vo) - char *argv[]; - register struct valobj *vo; +int validate_name(char *argv[], register struct valobj *vo) { - char *name, *namefield; - register char *c; - - name = argv[vo->index]; - namefield = vo->namefield; - if (vo->table==SERVERS_TABLE && !strcmp(namefield, "name")) { - for (c = name; *c; c++) + char *name, *namefield; + register char *c; + + name = argv[vo->index]; + namefield = vo->namefield; + if (vo->table == SERVERS_TABLE && !strcmp(namefield, "name")) + { + for (c = name; *c; c++) + { if (islower(*c)) *c = toupper(*c); + } } - sprintf(stmt_buf,"SELECT DISTINCT COUNT(*) FROM %s WHERE %s.%s = '%s'", - table_name[vo->table],table_name[vo->table],namefield,name); - dosql(sqlbuffer); + sprintf(stmt_buf, "SELECT DISTINCT COUNT(*) FROM %s WHERE %s.%s = '%s'", + table_name[vo->table], table_name[vo->table], namefield, name); + dosql(sqlbuffer); - if (dbms_errno) return(mr_errcode); - return ((atoi(sqlbuffer[0]) == 1) ? MR_EXISTS : vo->error); + if (dbms_errno) + return mr_errcode; + return (atoi(sqlbuffer[0]) == 1) ? MR_EXISTS : vo->error; } -/* -validate_date(argv, vo) - char *argv[]; - struct valobj *vo; +int validate_rename(char *argv[], struct valobj *vo) { - EXEC SQL BEGIN DECLARE SECTION; - char *idate; - double dd; - int errorno; - EXEC SQL END DECLARE SECTION; - - idate = argv[vo->index]; - EXEC SQL SELECT interval('years',date(:idate)-date('today')) INTO :dd; - if (sqlca.sqlcode != 0 || dd > 5.0) return(MR_DATE); - return(MR_EXISTS); -} -*/ - -int validate_rename(argv, vo) - char *argv[]; - struct valobj *vo; -{ - EXEC SQL BEGIN DECLARE SECTION; - char *name, *namefield, *idfield; - int id; - EXEC SQL END DECLARE SECTION; - int status; - register char *c; - - status = validate_chars(argv, vo); - if(status != MR_EXISTS) return status; - name=argv[vo->index]; - /* minor kludge to upcasify machine names */ - if (vo->table == MACHINE_TABLE) - for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c); - namefield = vo->namefield; - idfield = vo->idfield; - id = -1; - if (idfield == 0) { - if (!strcmp(argv[vo->index], argv[vo->index - 1])) - return(MR_EXISTS); - sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s = '%s'", - namefield,table_name[vo->table],namefield,name); - dosql(sqlbuffer); - - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlcode==SQL_NO_MATCH) - return(MR_EXISTS); /* how's _that_ for intuitive? */ - else - return(vo->error); + EXEC SQL BEGIN DECLARE SECTION; + char *name, *namefield, *idfield; + int id; + EXEC SQL END DECLARE SECTION; + int status; + register char *c; + + status = validate_chars(argv, vo); + if (status != MR_EXISTS) + return status; + name = argv[vo->index]; + /* minor kludge to upcasify machine names */ + if (vo->table == MACHINE_TABLE) + { + for (c = name; *c; c++) + { + if (islower(*c)) + *c = toupper(*c); + } + } + namefield = vo->namefield; + idfield = vo->idfield; + id = -1; + if (idfield == 0) + { + if (!strcmp(argv[vo->index], argv[vo->index - 1])) + return MR_EXISTS; + sprintf(stmt_buf, "SELECT %s FROM %s WHERE %s = '%s'", + namefield, table_name[vo->table], namefield, name); + dosql(sqlbuffer); + + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlcode == SQL_NO_MATCH) + return MR_EXISTS; /* how's _that_ for intuitive? */ + else + return vo->error; } - status = name_to_id(name, vo->table, &id); - if (status == MR_NO_MATCH || id == *(int *)argv[vo->index - 1]) - return(MR_EXISTS); - else - return(vo->error); + status = name_to_id(name, vo->table, &id); + if (status == MR_NO_MATCH || id == *(int *)argv[vo->index - 1]) + return MR_EXISTS; + else + return vo->error; } -int validate_type(argv, vo) - char *argv[]; - register struct valobj *vo; +int validate_type(char *argv[], register struct valobj *vo) { - EXEC SQL BEGIN DECLARE SECTION; - char *typename; - char *val; - int cnt; - EXEC SQL END DECLARE SECTION; - register char *c; - - typename = vo->namefield; - c = val = argv[vo->index]; - while (*c) { - if (illegalchars[*c++]) - return(MR_BAD_CHAR); + EXEC SQL BEGIN DECLARE SECTION; + char *typename; + char *val; + int cnt; + EXEC SQL END DECLARE SECTION; + register char *c; + + typename = vo->namefield; + c = val = argv[vo->index]; + while (*c) + { + if (illegalchars[*c++]) + return MR_BAD_CHAR; } - /* uppercase type fields */ - for (c = val; *c; c++) if (islower(*c)) *c = toupper(*c); + /* uppercase type fields */ + for (c = val; *c; c++) + { + if (islower(*c)) + *c = toupper(*c); + } - EXEC SQL SELECT COUNT(trans) INTO :cnt FROM alias - WHERE name = :typename AND type='TYPE' AND trans = :val; - if (dbms_errno) return(mr_errcode); - return (cnt ? MR_EXISTS : vo->error); + EXEC SQL SELECT COUNT(trans) INTO :cnt FROM alias + WHERE name = :typename AND type = 'TYPE' AND trans = :val; + if (dbms_errno) + return mr_errcode; + return cnt ? MR_EXISTS : vo->error; } /* validate member or type-specific data field */ -int validate_typedata(q, argv, vo) - register struct query *q; - register char *argv[]; - register struct valobj *vo; +int validate_typedata(register struct query *q, register char *argv[], register struct valobj *vo) { - EXEC SQL BEGIN DECLARE SECTION; - char *name; - char *field_type; - char data_type[129]; - int id; - EXEC SQL END DECLARE SECTION; - int status; - register char *c; - - /* get named object */ - name = argv[vo->index]; - - /* get field type string (known to be at index-1) */ - field_type = argv[vo->index-1]; - - /* get corresponding data type associated with field type name */ - EXEC SQL SELECT trans INTO :data_type FROM alias - WHERE name = :field_type AND type='TYPEDATA'; - if (dbms_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] != 1) return(MR_TYPE); - - /* now retrieve the record id corresponding to the named object */ - if (strchr(data_type, ' ')) - *strchr(data_type, ' ') = 0; - if (!strcmp(data_type, "user")) { - /* USER */ - if (strchr(name, '@')) - return(MR_USER); - status = name_to_id(name, USERS_TABLE, &id); - if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)) - return(MR_USER); - if (status) return(status); - } else if (!strcmp(data_type, "list")) { - /* LIST */ - status = name_to_id(name, LIST_TABLE, &id); - if (status && status == MR_NOT_UNIQUE) - return(MR_LIST); - if (status == MR_NO_MATCH) { - /* if idfield is non-zero, then if argv[0] matches the string - * that we're trying to resolve, we should get the value of - * numvalues.[idfield] for the id. - */ - if (vo->idfield && !strcmp(argv[0], argv[vo->index])) { - set_next_object_id(q->validate->object_id, q->rtable, 0); - name = vo->idfield; - EXEC SQL SELECT value INTO :id FROM numvalues - WHERE name = :name; - if (sqlca.sqlerrd[2] != 1) return(MR_LIST); - } else - return(MR_LIST); - } else if (status) return(status); - } else if (!strcmp(data_type, "machine")) { - /* MACHINE */ - for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c); - status = name_to_id(name, MACHINE_TABLE, &id); - if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)) - return(MR_MACHINE); - if (status) return(status); - } else if (!strcmp(data_type, "string")) { - /* STRING */ - status = name_to_id(name, STRINGS_TABLE, &id); - if (status && status == MR_NOT_UNIQUE) - return(MR_STRING); - if (status == MR_NO_MATCH) { - if (q->type != APPEND && q->type != UPDATE) return(MR_STRING); - id=add_string(name); - cache_entry(name, STRINGS_TABLE, id); - } else if (status) return(status); - } else if (!strcmp(data_type, "none")) { - id = 0; - } else { - return(MR_TYPE); + EXEC SQL BEGIN DECLARE SECTION; + char *name; + char *field_type; + char data_type[129]; + int id; + EXEC SQL END DECLARE SECTION; + int status; + register char *c; + + /* get named object */ + name = argv[vo->index]; + + /* get field type string (known to be at index-1) */ + field_type = argv[vo->index - 1]; + + /* get corresponding data type associated with field type name */ + EXEC SQL SELECT trans INTO :data_type FROM alias + WHERE name = :field_type AND type = 'TYPEDATA'; + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlerrd[2] != 1) + return MR_TYPE; + + /* now retrieve the record id corresponding to the named object */ + if (strchr(data_type, ' ')) + *strchr(data_type, ' ') = '\0'; + if (!strcmp(data_type, "user")) + { + /* USER */ + if (strchr(name, '@')) + return MR_USER; + status = name_to_id(name, USERS_TABLE, &id); + if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)) + return MR_USER; + if (status) + return status; + } + else if (!strcmp(data_type, "list")) + { + /* LIST */ + status = name_to_id(name, LIST_TABLE, &id); + if (status && status == MR_NOT_UNIQUE) + return MR_LIST; + if (status == MR_NO_MATCH) + { + /* if idfield is non-zero, then if argv[0] matches the string + * that we're trying to resolve, we should get the value of + * numvalues.[idfield] for the id. + */ + if (vo->idfield && !strcmp(argv[0], argv[vo->index])) + { + set_next_object_id(q->validate->object_id, q->rtable, 0); + name = vo->idfield; + EXEC SQL SELECT value INTO :id FROM numvalues + WHERE name = :name; + if (sqlca.sqlerrd[2] != 1) + return MR_LIST; + } + else + return MR_LIST; + } + else if (status) + return status; + } + else if (!strcmp(data_type, "machine")) + { + /* MACHINE */ + for (c = name; *c; c++) + { + if (islower(*c)) + *c = toupper(*c); + } + status = name_to_id(name, MACHINE_TABLE, &id); + if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)) + return MR_MACHINE; + if (status) + return status; + } + else if (!strcmp(data_type, "string")) + { + /* STRING */ + status = name_to_id(name, STRINGS_TABLE, &id); + if (status && status == MR_NOT_UNIQUE) + return MR_STRING; + if (status == MR_NO_MATCH) + { + if (q->type != APPEND && q->type != UPDATE) + return MR_STRING; + id = add_string(name); + cache_entry(name, STRINGS_TABLE, id); + } + else if (status) + return status; } + else if (!strcmp(data_type, "none")) + id = 0; + else + return MR_TYPE; - /* now set value in argv */ - *(int *)argv[vo->index] = id; + /* now set value in argv */ + *(int *)argv[vo->index] = id; - return (MR_EXISTS); + return MR_EXISTS; } /* Make sure the data fits in the field */ -int validate_len(argv, vo) - register char *argv[]; - register struct valobj *vo; +int validate_len(register char *argv[], register struct valobj *vo) { - EXEC SQL BEGIN DECLARE SECTION; - int len; - char *tname, *cname; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int len; + char *tname, *cname; + EXEC SQL END DECLARE SECTION; - tname = table_name[vo->table]; - cname = vo->namefield; - EXEC SQL SELECT data_length INTO :len FROM user_tab_columns - WHERE table_name=UPPER(:tname) AND column_name=UPPER(:cname); + tname = table_name[vo->table]; + cname = vo->namefield; + EXEC SQL SELECT data_length INTO :len FROM user_tab_columns + WHERE table_name = UPPER(:tname) AND column_name = UPPER(:cname); - if((strlen(argv[vo->index]) > len) && - strcmp(argv[vo->index], UNIQUE_LOGIN)) /* kludge... sigh */ - argv[vo->index][len]='\0'; /* truncate */ + if ((strlen(argv[vo->index]) > len) && + strcmp(argv[vo->index], UNIQUE_LOGIN)) /* kludge... sigh */ + argv[vo->index][len] = '\0'; /* truncate */ - return MR_EXISTS; + return MR_EXISTS; } /* Lock the table named by the validation object */ -int lock_table(vo) - struct valobj *vo; +int lock_table(struct valobj *vo) { #ifdef DO_LOCKING - sprintf(stmt_buf, "LOCK TABLE %s IN EXCLUSIVE MODE", table_name[vo->table]); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - if (dbms_errno) - return(mr_errcode); - else + sprintf(stmt_buf, "LOCK TABLE %s IN EXCLUSIVE MODE", table_name[vo->table]); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + if (dbms_errno) + return mr_errcode; + else #endif - return(MR_EXISTS); + return MR_EXISTS; } /* * Get a read lock on the table by accessing the magic lock * record. Certain tables are constructed so that they contain - * an id field whose value is zero and a modtime field. We - * manipulate the modtime field of the id 0 record to effect + * an id field whose value is zero and a modtime field. We + * manipulate the modtime field of the id 0 record to effect * locking of the table */ -int readlock_table(vo) - struct valobj *vo; +int readlock_table(struct valobj *vo) { #ifdef DO_LOCKING - sprintf(stmt_buf, "LOCK TABLE %s IN SHARE MODE", table_name[vo->table]); - EXEC SQL EXECUTE IMMEDIATE :stmt_buf; + sprintf(stmt_buf, "LOCK TABLE %s IN SHARE MODE", table_name[vo->table]); + EXEC SQL EXECUTE IMMEDIATE :stmt_buf; - if (dbms_errno) - return(mr_errcode); - if (sqlca.sqlcode) - return(vo->error); + if (dbms_errno) + return mr_errcode; + if (sqlca.sqlcode) + return vo->error; #endif - return(MR_EXISTS); /* validate_fields expects us to return - * this value if everything went okay - */ + return MR_EXISTS; /* validate_fields expects us to return + * this value if everything went okay + */ } /* Check the database at startup time. */ void sanity_check_database(void) { - EXEC SQL BEGIN DECLARE SECTION; - int oid, id; - EXEC SQL END DECLARE SECTION; + EXEC SQL BEGIN DECLARE SECTION; + int oid, id; + EXEC SQL END DECLARE SECTION; - /* Sometimes a crash can leave strings_id in numvalues in an - incorrect state. Check for that and fix it. */ + /* Sometimes a crash can leave strings_id in numvalues in an + incorrect state. Check for that and fix it. */ - EXEC SQL SELECT value INTO :oid FROM numvalues WHERE name='strings_id'; + EXEC SQL SELECT value INTO :oid FROM numvalues WHERE name = 'strings_id'; - for (id=oid+1; sqlca.sqlcode==0; id++) - EXEC SQL SELECT string_id INTO :id FROM strings - WHERE string_id=:id; + for (id = oid + 1; sqlca.sqlcode == 0; id++) + { + EXEC SQL SELECT string_id INTO :id FROM strings + WHERE string_id = :id; + } - if (id!=oid+1) - EXEC SQL UPDATE numvalues SET value=:id-1 WHERE name='strings_id'; + if (id != oid + 1) + EXEC SQL UPDATE numvalues SET value = :id - 1 WHERE name = 'strings_id'; } @@ -560,47 +589,64 @@ char *sqlbuffer[QMAXARGS]; /* Dynamic SQL support routines */ SQLDA *mr_alloc_sqlda() { - SQLDA *it; - register int j; - - it=sqlald(QMAXARGS, ARGLEN, 0); - if(it==NULL) { - com_err(whoami, MR_NO_MEM, "setting up SQLDA"); - exit(1); + SQLDA *it; + register int j; + + it = sqlald(QMAXARGS, ARGLEN, 0); + if (!it) + { + com_err(whoami, MR_NO_MEM, "setting up SQLDA"); + exit(1); } - for(j=0; jV[j]=sqlbuffer[j]=malloc(ARGLEN); - it->T[j]=97; /* 97 = CHARZ = null-terminated string */ - it->L[j]=ARGLEN; + for (j = 0; j < QMAXARGS; j++) + { + it->V[j] = sqlbuffer[j] = malloc(ARGLEN); + it->T[j] = 97; /* 97 = CHARZ = null-terminated string */ + it->L[j] = ARGLEN; } - return it; + return it; } /* Convert normal Unix-style wildcards to SQL voodoo */ -int convert_wildcards(arg) - char *arg; +int convert_wildcards(char *arg) { - static char buffer[ARGLEN]; - register char *s, *d; - - for(d=buffer,s=arg;*s;s++) { - switch(*s) { - case '*': *d++='%'; *d++='%'; break; - case '?': *d++='_'; break; - case '_': *d++='*'; *d++ = *s; break; - case '%': *d++='*'; *d++='%'; *d++='%'; break; - default: *d++ = *s; break; + static char buffer[ARGLEN]; + register char *s, *d; + + for (d = buffer, s = arg; *s; s++) + { + switch (*s) + { + case '*': + *d++ = '%'; + *d++ = '%'; + break; + case '?': + *d++ = '_'; + break; + case '_': + *d++ = '*'; + *d++ = *s; + break; + case '%': + *d++ = '*'; + *d++ = '%'; + *d++ = '%'; + break; + default: + *d++ = *s; + break; } } - *d='\0'; + *d = '\0'; - /* Copy back into argv */ - strcpy(arg,buffer); + /* Copy back into argv */ + strcpy(arg, buffer); - return(MR_EXISTS); + return MR_EXISTS; } /* This version includes uppercase conversion, for things like gmac. @@ -608,46 +654,60 @@ int convert_wildcards(arg) * Including it in a wildcard routine saves making two passes over * the argument string. */ -int convert_wildcards_uppercase(arg) - char *arg; +int convert_wildcards_uppercase(char *arg) { - static char buffer[ARGLEN]; - register char *s, *d; - - for(d=buffer,s=arg;*s;s++) { - switch(*s) { - case '*': *d++='%'; *d++='%'; break; - case '?': *d++='_'; break; - case '_': *d++='*'; *d++ = *s; break; - case '%': *d++='*'; *d++='%'; *d++='%'; break; - default: *d++=toupper(*s); break; /* This is the only diff. */ + static char buffer[ARGLEN]; + register char *s, *d; + + for (d = buffer, s = arg; *s; s++) + { + switch (*s) + { + case '*': + *d++ = '%'; + *d++ = '%'; + break; + case '?': + *d++ = '_'; + break; + case '_': + *d++ = '*'; + *d++ = *s; + break; + case '%': + *d++ = '*'; + *d++ = '%'; + *d++ = '%'; + break; + default: + *d++ = toupper(*s); /* This is the only diff. */ + break; } } - *d='\0'; + *d = '\0'; - /* Copy back into argv */ - strcpy(arg,buffer); + /* Copy back into argv */ + strcpy(arg, buffer); - return(MR_EXISTS); + return MR_EXISTS; } /* Adds a string to the string table. Returns the id number. - * + * */ -int add_string(nm) - char *nm; +int add_string(char *nm) { - EXEC SQL BEGIN DECLARE SECTION; - char buf[256], *name = nm; - int id; - EXEC SQL END DECLARE SECTION; - - EXEC SQL SELECT value INTO :id FROM numvalues WHERE name = 'strings_id'; - id++; - EXEC SQL UPDATE numvalues SET value = :id WHERE name = 'strings_id'; - - EXEC SQL INSERT INTO strings (string_id, string) VALUES (:id, :nm); - - return(id); + EXEC SQL BEGIN DECLARE SECTION; + char buf[256], *name = nm; + int id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL SELECT value INTO :id FROM numvalues WHERE name = 'strings_id'; + id++; + EXEC SQL UPDATE numvalues SET value = :id WHERE name = 'strings_id'; + + EXEC SQL INSERT INTO strings (string_id, string) VALUES (:id, :nm); + + return id; } diff --git a/server/startmoira.c b/server/startmoira.c index 760f9cb9..14db9d5c 100644 --- a/server/startmoira.c +++ b/server/startmoira.c @@ -9,7 +9,7 @@ * * This program starts the moira server in a "clean" environment. * and then waits for it to exit. - * + * */ #ifndef lint @@ -37,123 +37,130 @@ int rdpipe[2]; extern int errno; char *whoami; -void cleanup() +void cleanup(void) { - int stat, serrno = errno; - char buf[BUFSIZ]; - - buf[0]='\0'; - - while (waitpid(-1, &stat, WNOHANG) > 0) { - if (WIFEXITED(stat)) { - if (WEXITSTATUS(stat)) { - sprintf(buf, - "exited with code %d\n", - WEXITSTATUS(stat)); - critical_alert("startmoira", "%s", buf); - } - } - if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on signal %d%s\n", - WTERMSIG(stat), - (WCOREDUMP(stat)?"; Core dumped":"")); - if(WCOREDUMP(stat)) - critical_alert("startmoira", "%s", buf); - } - write(rdpipe[1], buf, strlen(buf)); - close(rdpipe[1]); + int stat, serrno = errno; + char buf[BUFSIZ]; + + buf[0] = '\0'; + + while (waitpid(-1, &stat, WNOHANG) > 0) + { + if (WIFEXITED(stat)) + { + if (WEXITSTATUS(stat)) + { + sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat)); + critical_alert("startmoira", "%s", buf); + } } - errno = serrno; + if (WIFSIGNALED(stat)) + { + sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat), + (WCOREDUMP(stat) ? "; Core dumped" : "")); + if (WCOREDUMP(stat)) + critical_alert("startmoira", "%s", buf); + } + write(rdpipe[1], buf, strlen(buf)); + close(rdpipe[1]); + } + errno = serrno; } -main(argc, argv) - int argc; - char *argv[]; +int main(int argc, char *argv[]) { - char buf[BUFSIZ]; - FILE *log, *prog; - int logf, inf, i, done, pid, tty; - struct rlimit rl; - - extern int errno; - extern char *sys_errlist[]; - - struct sigaction action; - int nfds; - - whoami = argv[0]; - - getrlimit(RLIMIT_NOFILE, &rl); - nfds = rl.rlim_cur; - - action.sa_handler = cleanup; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaction(SIGCHLD, &action, NULL); - - sprintf(buf, "%s/moira.log", SMS_DIR); - logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); - if (logf<0) { - perror(buf); - exit(1); - } - inf = open("/dev/null", O_RDONLY , 0); - if (inf < 0) { - perror("/dev/null"); - exit(1); - } - pipe(rdpipe); - if (fork()) { - exit(0); - } - chdir("/"); - close(0); - close(1); - close(2); - dup2(inf, 0); - dup2(inf, 1); - dup2(inf, 2); - - setpgrp(); - sprintf(buf, "%s/%s", BIN_DIR, PROG); - - if ((pid = fork()) == 0) { - - dup2(inf, 0); - dup2(rdpipe[1], 1); - dup2(1,2); - for (i = 3; i dat; - MAX_STRING_SIZE(data) = ticket->length; - code = send_object(conn, (char *)&data, STRING_T); - if (code) { - return(connection_errno(conn)); - } - code = receive_object(conn, (char *)&response, INTEGER_T); - if (code) { - return(connection_errno(conn)); - } - if (response) { - return(response); + KTEXT_ST ticket_st; + KTEXT ticket = &ticket_st; + STRING data; + register int code; + int response; + int auth_version = 2; + + code = get_mr_update_ticket(host_name, ticket); + if (code) + return code; + STRING_DATA(data) = "AUTH_002"; + MAX_STRING_SIZE(data) = 9; + code = send_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + code = receive_object(conn, (char *)&response, INTEGER_T); + if (code) + return connection_errno(conn); + if (response) + { + STRING_DATA(data) = "AUTH_001"; + MAX_STRING_SIZE(data) = 9; + code = send_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + code = receive_object(conn, (char *)&response, INTEGER_T); + if (code) + return connection_errno(conn); + if (response) + return response; + auth_version = 1; } - - if (auth_version == 2) { - des_key_schedule sched; - C_Block enonce; - - code = receive_object(conn, (char *)&data, STRING_T); - if (code) { - return(connection_errno(conn)); - } - des_key_sched(session, sched); - des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1); - STRING_DATA(data) = enonce; - code = send_object(conn, (char *)&data, STRING_T); - if (code) { - return(connection_errno(conn)); - } - code = receive_object(conn, (char *)&response, INTEGER_T); - if (code) { - return(connection_errno(conn)); - } - if (response) { - return(response); - } + STRING_DATA(data) = (char *)ticket->dat; + MAX_STRING_SIZE(data) = ticket->length; + code = send_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + code = receive_object(conn, (char *)&response, INTEGER_T); + if (code) + return connection_errno(conn); + if (response) + return response; + + if (auth_version == 2) + { + des_key_schedule sched; + C_Block enonce; + + code = receive_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + des_key_sched(session, sched); + des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1); + STRING_DATA(data) = enonce; + code = send_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + code = receive_object(conn, (char *)&response, INTEGER_T); + if (code) + return connection_errno(conn); + if (response) + return response; } - return(MR_SUCCESS); + return MR_SUCCESS; } -execute(path) - char *path; +int execute(char *path) { - int response; - STRING data; - register int code; - - string_alloc(&data, BUFSIZ); - sprintf(STRING_DATA(data), "EXEC_002 %s", path); - code = send_object(conn, (char *)&data, STRING_T); - if (code) - return(connection_errno(conn)); - code = receive_object(conn, (char *)&response, INTEGER_T); - if (code) - return(connection_errno(conn)); - if (response) - return(response); - return(MR_SUCCESS); + int response; + STRING data; + register int code; + + string_alloc(&data, BUFSIZ); + sprintf(STRING_DATA(data), "EXEC_002 %s", path); + code = send_object(conn, (char *)&data, STRING_T); + if (code) + return connection_errno(conn); + code = receive_object(conn, (char *)&response, INTEGER_T); + if (code) + return connection_errno(conn); + if (response) + return response; + return MR_SUCCESS; } -send_quit() +send_quit(void) { - STRING str; - if (!conn) - return; - string_alloc(&str, 5); - (void) strcpy(STRING_DATA(str), "quit"); - (void) send_object(conn, (char *)&str, STRING_T); - string_free(&str); + STRING str; + if (!conn) + return; + string_alloc(&str, 5); + strcpy(STRING_DATA(str), "quit"); + send_object(conn, (char *)&str, STRING_T); + string_free(&str); } diff --git a/update/config.c b/update/config.c index 99e88cee..c76592c3 100644 --- a/update/config.c +++ b/update/config.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -39,90 +40,102 @@ static char **config_keys, **config_values; static init() { - int fd, count = 0; - struct stat st; - char *p, *start; - - /* Only execute once */ - if (config_buf) return(MR_SUCCESS); - - fd = open(CONFIG_FILE, O_RDONLY, 0); - if (fd < 0) { - config_buf = ""; - config_keys = (char **)malloc(sizeof(char *) * 2); - config_keys[0] = config_keys[1] = NULL; - return(MR_SUCCESS); + int fd, count = 0; + struct stat st; + char *p, *start; + + /* Only execute once */ + if (config_buf) + return MR_SUCCESS; + + fd = open(CONFIG_FILE, O_RDONLY, 0); + if (fd < 0) + { + config_buf = ""; + config_keys = malloc(sizeof(char *) * 2); + config_keys[0] = config_keys[1] = NULL; + return MR_SUCCESS; } - if (fstat(fd, &st) < 0) { - return(MR_INTERNAL); + if (fstat(fd, &st) < 0) + return MR_INTERNAL; + config_buf = malloc(st.st_size + 2); + if (!config_buf) + return MR_NO_MEM; + if (read(fd, config_buf, st.st_size) < st.st_size) + { + free(config_buf); + config_buf = NULL; + return MR_INTERNAL; } - config_buf = (char *) malloc(st.st_size + 2); - if (config_buf == NULL) { - return(MR_NO_MEM); - } - if (read(fd, config_buf, st.st_size) < st.st_size) { - free(config_buf); - config_buf = NULL; - return(MR_INTERNAL); - } - config_buf[st.st_size] = '\0'; - - for (p = config_buf; *p; p++) - if (*p == '\n') count++; - count++; - config_keys = (char **)malloc(count * sizeof(char *)); - config_values = (char **)malloc(count * sizeof(char *)); - if (config_keys == NULL || config_values == NULL) { - free(config_buf); - config_buf = NULL; - return(MR_NO_MEM); + config_buf[st.st_size] = '\0'; + + for (p = config_buf; *p; p++) + { + if (*p == '\n') + count++; } - count = 0; - for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n")) { - config_keys[count++] = p; + count++; + config_keys = malloc(count * sizeof(char *)); + config_values = malloc(count * sizeof(char *)); + if (!config_keys || !config_values) + { + free(config_buf); + config_buf = NULL; + return MR_NO_MEM; } - config_keys[count] = NULL; - for (count = 0; config_keys[count]; count++) { - config_values[count] = ""; - for (p = config_keys[count]; *p; p++) - if (isspace(*p)) { + count = 0; + for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n")) + config_keys[count++] = p; + config_keys[count] = NULL; + for (count = 0; config_keys[count]; count++) + { + config_values[count] = ""; + for (p = config_keys[count]; *p; p++) + { + if (isspace(*p)) + { *p++ = '\0'; - while (*p && isspace(*p)) p++; + while (*p && isspace(*p)) + p++; config_values[count] = p; - } + } + } } - return(MR_SUCCESS); + return MR_SUCCESS; } -/* Given a key, lookup the associated value. +/* Given a key, lookup the associated value. * Returns "" on a key without a value, NULL on a non-existant key. * If a key appears multiple times, successive calls will cycle through * the possible values. */ -char *config_lookup(key) -char *key; +char *config_lookup(char *key) { - static int i = 0; - int start; + static int i = 0; + int start; - if (init() != MR_SUCCESS) - return(NULL); + if (init() != MR_SUCCESS) + return NULL; - start = i++; - if (config_keys[i] == NULL) i = 0; - if (config_keys[i] == NULL) return(NULL); + start = i++; + if (!config_keys[i]) + i = 0; + if (!config_keys[i]) + return NULL; - do { + do + { if (!strcasecmp(key, config_keys[i])) - return(config_values[i]); - if (config_keys[++i] == NULL) + return config_values[i]; + if (!config_keys[++i]) i = 0; - } while (i != start); + } + while (i != start); - if (!strcasecmp(key, config_keys[i])) - return(config_values[i]); + if (!strcasecmp(key, config_keys[i])) + return config_values[i]; - return(NULL); + return NULL; } diff --git a/update/exec_002.c b/update/exec_002.c index fcf0d96f..50f81739 100644 --- a/update/exec_002.c +++ b/update/exec_002.c @@ -14,13 +14,7 @@ static char *rcsid_exec_002_c = "$Header$"; #include #include #include -#ifdef _AIX -#undef _BSD -#endif #include -#ifdef _AIX -#define _BSD 44 -#endif #include #include #include @@ -30,116 +24,86 @@ extern CONNECTION conn; extern int code, errno, uid, log_priority, have_authorization; extern char *whoami; -#if defined(vax) || defined(ibm032) -#define WEXITSTATUS(waitb) ((waitb).w_retcode) -#endif - - -int -exec_002(str) - char *str; +int exec_002(char *str) { -#ifdef POSIX - int waitb; - sigset_t mask,oldmask; -#else - union wait waitb; - int mask; -#endif - int n, pid; + int waitb; + sigset_t mask, oldmask; + int n, pid; - if (!have_authorization) { - reject_call(MR_PERM); - return(0); + if (!have_authorization) + { + reject_call(MR_PERM); + return 0; } - if (config_lookup("noexec")) { - code = EPERM; - send_object(conn, (char *)&code, INTEGER_T); - com_err(whoami, code, "Not allowed to execute"); - return(0); + if (config_lookup("noexec")) + { + code = EPERM; + send_object(conn, (char *)&code, INTEGER_T); + com_err(whoami, code, "Not allowed to execute"); + return 0; } - str += 8; - while (*str == ' ') - str++; -#ifdef POSIX - sigemptyset(&mask); - sigaddset(&mask,SIGCHLD); - sigprocmask(SIG_BLOCK,&mask,&oldmask); -#else - mask = sigblock(sigmask(SIGCHLD)); -#endif - pid = fork(); - switch (pid) { + str += 8; + while (*str == ' ') + str++; + sigemptyset(&mask); + sigaddset(&mask, SIGCHLD); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + pid = fork(); + switch (pid) + { case -1: - n = errno; -#ifdef POSIX - sigprocmask(SIG_UNBLOCK,&oldmask,&mask); -#else - sigsetmask(mask); -#endif - log_priority = log_ERROR; - com_err(whoami, errno, ": can't fork to run install script"); - code = send_object(conn, (char *)&n, INTEGER_T); - if (code) - exit(1); - return(0); + n = errno; + sigprocmask(SIG_UNBLOCK, &oldmask, &mask); + log_priority = log_ERROR; + com_err(whoami, errno, ": can't fork to run install script"); + code = send_object(conn, (char *)&n, INTEGER_T); + if (code) + exit(1); + return 0; case 0: - if (setuid(uid) < 0) { - com_err(whoami, errno, "Unable to setuid to %d\n", uid); - exit(1); + if (setuid(uid) < 0) + { + com_err(whoami, errno, "Unable to setuid to %d\n", uid); + exit(1); } -#ifdef POSIX - sigprocmask(SIG_UNBLOCK,&oldmask,&mask); -#else - sigsetmask(mask); -#endif - execlp(str, str, (char *)NULL); - n = errno; -#ifdef POSIX - sigprocmask(SIG_UNBLOCK,&oldmask,&mask); -#else - sigsetmask(mask); -#endif - log_priority = log_ERROR; - com_err(whoami, n, ": %s", str); - (void) send_object(conn, (char *)&n, INTEGER_T); - exit(1); + sigprocmask(SIG_UNBLOCK, &oldmask, &mask); + execlp(str, str, NULL); + n = errno; + sigprocmask(SIG_UNBLOCK, &oldmask, &mask); + log_priority = log_ERROR; + com_err(whoami, n, ": %s", str); + send_object(conn, (char *)&n, INTEGER_T); + exit(1); default: - do { - n = wait(&waitb); - } while (n != -1 && n != pid); -#ifdef POSIX - sigprocmask(SIG_UNBLOCK,&oldmask,&mask); -#else - sigsetmask(mask); -#endif -#ifdef POSIX - if ( (WIFEXITED(waitb) && (WEXITSTATUS(waitb)!=0)) || WIFSIGNALED(waitb) ) { - log_priority = log_ERROR; - if (WIFSIGNALED(waitb)) { - n = MR_COREDUMP; - com_err(whoami, n, " child exited on signal %d", - WTERMSIG(waitb)); - } else { - n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms; - com_err(whoami, n, " child exited with status %d", - WEXITSTATUS(waitb)); + do + n = wait(&waitb); + while (n != -1 && n != pid); + sigprocmask(SIG_UNBLOCK, &oldmask, &mask); + if ((WIFEXITED(waitb) && (WEXITSTATUS(waitb) != 0)) || + WIFSIGNALED(waitb)) + { + log_priority = log_ERROR; + if (WIFSIGNALED(waitb)) + { + n = MR_COREDUMP; + com_err(whoami, n, " child exited on signal %d", + WTERMSIG(waitb)); } -#else - if (waitb.w_status) { - n = waitb.w_retcode + ERROR_TABLE_BASE_sms; - log_priority = log_ERROR; - com_err(whoami, n, " child exited with status %d", - waitb.w_retcode); -#endif - code = send_object(conn, (char *)&n, INTEGER_T); - if (code) { - exit(1); + else + { + n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms; + com_err(whoami, n, " child exited with status %d", + WEXITSTATUS(waitb)); } - } else { - code = send_ok(); - if (code) - exit(1); + code = send_object(conn, (char *)&n, INTEGER_T); + if (code) + exit(1); + } + else + { + code = send_ok(); + if (code) + exit(1); } } } diff --git a/update/get_file.c b/update/get_file.c index 19fad0f2..e8d6de67 100644 --- a/update/get_file.c +++ b/update/get_file.c @@ -24,7 +24,7 @@ static char *rcsid_get_file_c = "$Header$"; #include "update.h" #ifndef MIN -#define MIN(a,b) (((a) < (b))?(a):(b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif /* MIN */ extern CONNECTION conn; @@ -72,179 +72,182 @@ static int get_block(); * */ -int -get_file(pathname, file_size, checksum, mode, encrypt) - char *pathname; - int file_size; - int checksum; - int mode; - int encrypt; +int get_file(char *pathname, int file_size, int checksum, + int mode, int encrypt) { - int fd, n_written; - int found_checksum; - - if (!have_authorization) { - reject_call(MR_PERM); - return(1); + int fd, n_written; + int found_checksum; + + if (!have_authorization) + { + reject_call(MR_PERM); + return 1; } - if (done) /* re-initialize data */ - initialize(); -#ifdef POSIX - if (setuid(uid) < 0) { -#else - if (setreuid(0, uid) < 0) { -#endif - com_err(whoami, errno, "Unable to setuid to %d\n", uid); - exit(1); + if (done) /* re-initialize data */ + initialize(); + if (setuid(uid) < 0) + { + com_err(whoami, errno, "Unable to setuid to %d\n", uid); + exit(1); } - /* unlink old file */ - if (!config_lookup("noclobber")) - (void) unlink(pathname); - /* open file descriptor */ - fd = open(pathname, O_CREAT|O_EXCL|O_WRONLY, mode); - if (fd == -1) { - code = errno; - sprintf(buf, "%s: creating file %s (get_file)", - error_message(code), pathname); - mr_log_error(buf); - report_error("reporting file creation error (get_file)"); - if (setuid(0) < 0) { - com_err(whoami, errno, "Unable to setuid back to %d\n", 0); - exit(1); + /* unlink old file */ + if (!config_lookup("noclobber")) + unlink(pathname); + /* open file descriptor */ + fd = open(pathname, O_CREAT|O_EXCL|O_WRONLY, mode); + if (fd == -1) + { + code = errno; + sprintf(buf, "%s: creating file %s (get_file)", + error_message(code), pathname); + mr_log_error(buf); + report_error("reporting file creation error (get_file)"); + if (setuid(0) < 0) + { + com_err(whoami, errno, "Unable to setuid back to %d\n", 0); + exit(1); } - return(1); + return 1; } - /* check to see if we've got the disk space */ - n_written = 0; - while (n_written < file_size) { - register int n_wrote; - n_wrote = write(fd, buf, sizeof(buf)); - if (n_wrote == -1) { - code = errno; - sprintf(buf, "%s: verifying free disk space for %s (get_file)", - error_message(code), pathname); - mr_log_error(buf); - /* do all we can to free the space */ - (void) unlink(pathname); - (void) ftruncate(fd, 0); - (void) close(fd); - report_error("reporting test-write error (get_file)"); - if (setuid(0) < 0) { - com_err(whoami, errno, "Unable to setuid back to %d\n", 0); - exit(1); + /* check to see if we've got the disk space */ + n_written = 0; + while (n_written < file_size) + { + register int n_wrote; + n_wrote = write(fd, buf, sizeof(buf)); + if (n_wrote == -1) + { + code = errno; + sprintf(buf, "%s: verifying free disk space for %s (get_file)", + error_message(code), pathname); + mr_log_error(buf); + /* do all we can to free the space */ + unlink(pathname); + ftruncate(fd, 0); + close(fd); + report_error("reporting test-write error (get_file)"); + if (setuid(0) < 0) + { + com_err(whoami, errno, "Unable to setuid back to %d\n", 0); + exit(1); } - return(1); + return 1; } - n_written += n_wrote; + n_written += n_wrote; } - lseek(fd, 0, L_SET); - if (send_ok()) - lose("sending okay for file transfer (get_file)"); - if (encrypt) { -#ifdef DEBUG - com_err(whoami, 0, "Session %02x %02x %02x %02x %02x %02x %02x %02x", - session[0], session[1], session[2], session[3], - session[4], session[5], session[6], session[7]); -#endif /* DEBUG */ - des_key_sched(session, sched); - memcpy(ivec, session, sizeof(ivec)); + lseek(fd, 0, L_SET); + if (send_ok()) + lose("sending okay for file transfer (get_file)"); + if (encrypt) + { + des_key_sched(session, sched); + memcpy(ivec, session, sizeof(ivec)); } - n_written = 0; - while (n_written < file_size && code == 0) { - int n_got = get_block(fd, file_size - n_written, encrypt); - if (n_got == -1) { - /* get_block has already printed a message */ - unlink(pathname); - if (setuid(0) < 0) { - com_err(whoami, errno, "Unable to setuid back to %d\n", 0); - exit(1); + n_written = 0; + while (n_written < file_size && code == 0) + { + int n_got = get_block(fd, file_size - n_written, encrypt); + if (n_got == -1) + { + /* get_block has already printed a message */ + unlink(pathname); + if (setuid(0) < 0) + { + com_err(whoami, errno, "Unable to setuid back to %d\n", 0); + exit(1); } - return(1); + return 1; + } + n_written += n_got; + if (n_written != file_size) + { + if (send_ok()) + lose("receiving data"); } - n_written += n_got; - if (n_written != file_size) - if (send_ok()) - lose("receiving data"); } - if (code) { - code = connection_errno(conn); - report_error("reading file (get_file)"); - if (setuid(0) < 0) { - com_err(whoami, errno, "Unable to setuid back to %d\n", 0); - exit(1); + if (code) + { + code = connection_errno(conn); + report_error("reading file (get_file)"); + if (setuid(0) < 0) + { + com_err(whoami, errno, "Unable to setuid back to %d\n", 0); + exit(1); } - return(1); + return 1; } - fsync(fd); - ftruncate(fd, file_size); - fsync(fd); - close(fd); - if (setuid(0) < 0) { - com_err(whoami, errno, "Unable to setuid back to %d\n", 0); - exit(1); + fsync(fd); + ftruncate(fd, file_size); + fsync(fd); + close(fd); + if (setuid(0) < 0) + { + com_err(whoami, errno, "Unable to setuid back to %d\n", 0); + exit(1); } - /* validate checksum */ - found_checksum = checksum_file(pathname); - if (checksum != found_checksum) { - code = MR_MISSINGFILE; - com_err(whoami, code, ": expected = %d, found = %d", - checksum, found_checksum); - report_error("checksum error"); - return(1); + /* validate checksum */ + found_checksum = checksum_file(pathname); + if (checksum != found_checksum) + { + code = MR_MISSINGFILE; + com_err(whoami, code, ": expected = %d, found = %d", + checksum, found_checksum); + report_error("checksum error"); + return 1; } - /* send ack or nack */ - have_file = 1; - if (send_ok()) { - code = connection_errno(conn); - (void) unlink(pathname); - lose("sending ok after file transfer (get_file)"); - return(1); + /* send ack or nack */ + have_file = 1; + if (send_ok()) + { + code = connection_errno(conn); + unlink(pathname); + lose("sending ok after file transfer (get_file)"); + return 1; } - return(0); + return 0; } -static int -get_block(fd, max_size, encrypt) - int fd; - int max_size; - int encrypt; +static int get_block(int fd, int max_size, int encrypt) { - STRING data; - unsigned char dst[UPDATE_BUFSIZ + 8], *src; - int n_read, n, i; + STRING data; + unsigned char dst[UPDATE_BUFSIZ + 8], *src; + int n_read, n, i; - code = receive_object(conn, (char *)&data, STRING_T); - if (code) { - code = connection_errno(conn); - lose("receiving data file (get_file)"); + code = receive_object(conn, (char *)&data, STRING_T); + if (code) + { + code = connection_errno(conn); + lose("receiving data file (get_file)"); } - if (encrypt) { - src = (unsigned char *)STRING_DATA(data); - n = MAX_STRING_SIZE(data); - des_pcbc_encrypt(src, dst, n, sched, ivec, 1); - for (i = 0; i < 8; i++) - ivec[i] = src[n - 8 + i] ^ dst[n - 8 + i]; - memcpy(STRING_DATA(data), dst, n); + if (encrypt) + { + src = (unsigned char *)STRING_DATA(data); + n = MAX_STRING_SIZE(data); + des_pcbc_encrypt(src, dst, n, sched, ivec, 1); + for (i = 0; i < 8; i++) + ivec[i] = src[n - 8 + i] ^ dst[n - 8 + i]; + memcpy(STRING_DATA(data), dst, n); } - n_read = MIN(MAX_STRING_SIZE(data), max_size); - n = 0; - while (n < n_read) { - register int n_wrote; - n_wrote = write(fd, STRING_DATA(data)+n, - n_read-n); - if (n_wrote == -1) { - code = errno; - sprintf(buf, "%s: writing file (get_file)", error_message(code)); - mr_log_error(buf); - string_free(&data); - report_error("reporting write error (get_file)"); - close(fd); - return(-1); + n_read = MIN(MAX_STRING_SIZE(data), max_size); + n = 0; + while (n < n_read) + { + register int n_wrote; + n_wrote = write(fd, STRING_DATA(data) + n, n_read - n); + if (n_wrote == -1) + { + code = errno; + sprintf(buf, "%s: writing file (get_file)", error_message(code)); + mr_log_error(buf); + string_free(&data); + report_error("reporting write error (get_file)"); + close(fd); + return -1; } - n += n_wrote; + n += n_wrote; } - string_free(&data); - return(n); + string_free(&data); + return n; } diff --git a/update/hostname.c b/update/hostname.c index 1cb89e37..081d731c 100644 --- a/update/hostname.c +++ b/update/hostname.c @@ -18,21 +18,23 @@ static char *rcsid_hostname_c = "$Header$"; #include #include #include -char * -PrincipalHostname(alias) - char *alias; + +char *PrincipalHostname(char *alias) { - struct hostent *h; - char *phost = alias; - if ((h=gethostbyname(alias)) != (struct hostent *)NULL) { - char *p = strchr(h->h_name, '.'); - if (p) - *p = NULL; - p = phost = h->h_name; - do { - if (isupper(*p)) - *p = tolower(*p); - } while (*p++); - } - return(phost); + struct hostent *h; + char *phost = alias; + if ((h = gethostbyname(alias))) + { + char *p = strchr(h->h_name, '.'); + if (p) + *p = NULL; + p = phost = h->h_name; + do + { + if (isupper(*p)) + *p = tolower(*p); + } + while (*p++); + } + return phost; } diff --git a/update/log.c b/update/log.c index 05c2453c..2f31db2f 100644 --- a/update/log.c +++ b/update/log.c @@ -24,12 +24,7 @@ static char *rcsid_log_c = "$Header$"; #include #include #include "com_err.h" -#ifdef __STDC__ #include -#else -#include -#define const -#endif #include "update.h" #include @@ -41,81 +36,70 @@ static char *rcsid_log_c = "$Header$"; #ifdef use_syslog int syslog_prio[] = { - LOG_DEBUG, - LOG_INFO, - LOG_WARNING, - LOG_ERR + LOG_DEBUG, + LOG_INFO, + LOG_WARNING, + LOG_ERR }; #endif extern int log_priority; extern char *whoami; -void mr_update_com_err_hook(whoami, code, fmt, args) - const char *whoami; - long code; - const char *fmt; - va_list args; +void mr_update_com_err_hook(const char *whoami, long code, + const char *fmt, va_list args) { - char buf[BUFSIZ], *cp; - FILE _strbuf; + char buf[BUFSIZ], *cp; + FILE _strbuf; #ifndef use_syslog - strcpy(buf, whoami); - for (cp = buf; *cp; cp++) - ; - *cp++ = ':'; - *cp++ = ' '; + strcpy(buf, whoami); + for (cp = buf; *cp; cp++) + ; + *cp++ = ':'; + *cp++ = ' '; #else - cp = buf; - *cp = '\0'; + cp = buf; + *cp = '\0'; #endif - if (code) { - strcpy(cp, error_message(code)); - while (*cp) - cp++; + if (code) + { + strcpy(cp, error_message(code)); + while (*cp) + cp++; } -#ifdef HAS_VSPRINTF - vsprintf(cp, fmt, args); -#else - _strbuf._flag = _IOWRT+_IOSTRG; - _strbuf._ptr = cp; - _strbuf._cnt = BUFSIZ-(cp-buf); - _doprnt(fmt, args, &_strbuf); - putc('\0', &_strbuf); -#endif + vsprintf(cp, fmt, args); #ifdef use_syslog - syslog(syslog_prio[log_priority], "%s", buf); + syslog(syslog_prio[log_priority], "%s", buf); #endif #ifdef use_tty - puts(buf); + puts(buf); #endif } -mr_update_initialize() +mr_update_initialize(void) { - static int initialized = 0; - if (initialized) - return; + static int initialized = 0; + if (initialized) + return; #ifdef use_syslog - openlog(whoami, LOG_PID, LOG_DAEMON); + openlog(whoami, LOG_PID, LOG_DAEMON); #endif - (void) set_com_err_hook(mr_update_com_err_hook); - log_priority = log_INFO; - initialized = 1; + set_com_err_hook(mr_update_com_err_hook); + log_priority = log_INFO; + initialized = 1; } static char fmt[] = "[%s] %s"; -#define def(name,level,prio) \ - name(msg) \ - char *msg; \ +#define def(name, level, prio) \ +name(char *msg)\ {\ - register int old_prio; \ - old_prio = log_priority; \ - mr_update_initialize(); \ - com_err(whoami, 0, fmt, level, msg); \ - log_priority = old_prio; \ + register int old_prio; \ + old_prio = log_priority; \ + mr_update_initialize(); \ + com_err(whoami, 0, fmt, level, msg); \ + log_priority = old_prio; \ } def(mr_log_error, "error", log_ERROR) diff --git a/update/send_file.c b/update/send_file.c index 55773913..b5ff17fc 100644 --- a/update/send_file.c +++ b/update/send_file.c @@ -20,9 +20,7 @@ static char *rcsid_send_file_c = "$Header$"; #include #include #include -#ifdef POSIX #include -#endif extern CONNECTION conn; extern int errno; @@ -47,148 +45,144 @@ extern char *whoami; * 1 on error (file not found, etc) */ -int -send_file(pathname, target_path, encrypt) -char *pathname; -char *target_path; -int encrypt; +int send_file(char *pathname, char *target_path, int encrypt) { - int n, fd, code, n_to_send, i; - STRING data; - unsigned char dst[UPDATE_BUFSIZ + 8], *src; - struct stat statb; - des_key_schedule sched; - des_cblock ivec; + int n, fd, code, n_to_send, i; + STRING data; + unsigned char dst[UPDATE_BUFSIZ + 8], *src; + struct stat statb; + des_key_schedule sched; + des_cblock ivec; - /* send file over */ - fd = open(pathname, O_RDONLY, 0); - if (fd < 0) { - com_err(whoami, errno, "unable to open %s for read", pathname); - return(MR_OCONFIG); + /* send file over */ + fd = open(pathname, O_RDONLY, 0); + if (fd < 0) + { + com_err(whoami, errno, "unable to open %s for read", pathname); + return MR_OCONFIG; } - if (fstat(fd, &statb)) { - com_err(whoami, errno, "unable to stat %s", pathname); - close(fd); - return(MR_OCONFIG); + if (fstat(fd, &statb)) + { + com_err(whoami, errno, "unable to stat %s", pathname); + close(fd); + return MR_OCONFIG; } - n_to_send = statb.st_size; - - string_alloc(&data, UPDATE_BUFSIZ); - sprintf(STRING_DATA(data), "XFER_00%c %d %d %s", - (encrypt ? '3' : '2'), n_to_send, - checksum_file(pathname), target_path); - code = send_object(conn, (char *)&data, STRING_T); - if (code) { - com_err(whoami, connection_errno(conn), " sending XFER request"); - close(fd); - return(connection_errno(conn)); + n_to_send = statb.st_size; + + string_alloc(&data, UPDATE_BUFSIZ); + sprintf(STRING_DATA(data), "XFER_00%c %d %d %s", + (encrypt ? '3' : '2'), n_to_send, + checksum_file(pathname), target_path); + code = send_object(conn, (char *)&data, STRING_T); + if (code) + { + com_err(whoami, connection_errno(conn), " sending XFER request"); + close(fd); + return connection_errno(conn); } - code = receive_object(conn, (char *)&n, INTEGER_T); - if (code) { - com_err(whoami, connection_errno(conn), - " getting reply from XFER request"); - close(fd); - return(connection_errno(conn)); + code = receive_object(conn, (char *)&n, INTEGER_T); + if (code) + { + com_err(whoami, connection_errno(conn), + " getting reply from XFER request"); + close(fd); + return connection_errno(conn); } - if (n) { - com_err(whoami, n, " transfer request (XFER) rejected"); - close(fd); - return(n); + if (n) + { + com_err(whoami, n, " transfer request (XFER) rejected"); + close(fd); + return n; } - - code = receive_object(conn, (char *)&n, INTEGER_T); - if (code) { - com_err(whoami, connection_errno(conn), ": lost connection"); - close(fd); - return(connection_errno(conn)); + + code = receive_object(conn, (char *)&n, INTEGER_T); + if (code) + { + com_err(whoami, connection_errno(conn), ": lost connection"); + close(fd); + return connection_errno(conn); } - if (n) { - com_err(whoami, n, " from remote server: can't update %s", - pathname); - close(fd); - return(n); + if (n) + { + com_err(whoami, n, " from remote server: can't update %s", pathname); + close(fd); + return n; } - if (encrypt) { -#ifdef DEBUG - printf("Session key %02x %02x %02x %02x %02x %02x %02x %02x\n", - session[0], session[1], session[2], session[3], - session[4], session[5], session[6], session[7]); -#endif /* DEBUG */ - des_key_sched(session, sched); -#ifdef POSIX - memmove(ivec, session, sizeof(ivec)); -#else - bcopy(session, ivec, sizeof(ivec)); -#endif + if (encrypt) + { + des_key_sched(session, sched); + memmove(ivec, session, sizeof(ivec)); } - while (n_to_send > 0) { -#ifdef DEBUG - printf("n_to_send = %d\n", n_to_send); -#endif /* DEBUG */ - n = read(fd, STRING_DATA(data), UPDATE_BUFSIZ); - if (n < 0) { - com_err(whoami, errno, " reading %s for transmission", pathname); - close(fd); - return(MR_ABORTED); + while (n_to_send > 0) + { + n = read(fd, STRING_DATA(data), UPDATE_BUFSIZ); + if (n < 0) + { + com_err(whoami, errno, " reading %s for transmission", pathname); + close(fd); + return MR_ABORTED; } - MAX_STRING_SIZE(data) = n; - if (encrypt) { - src = (unsigned char *)STRING_DATA(data); -#ifdef POSIX - memmove(dst, src, n); -#else - bcopy(src, dst, n); -#endif - memset(dst + n, 0, 7); - /* encrypt! */ - des_pcbc_encrypt(dst, src, n, sched, ivec, 0); - /* save vector to continue chaining */ - for (i = 0; i < 8; i++) - ivec[i] = dst[n - 8 + i] ^ src[n - 8 + i]; - /* round up to multiple of 8 */ - data.length = (data.length + 7) & 0xfffffff8; + MAX_STRING_SIZE(data) = n; + if (encrypt) + { + src = (unsigned char *)STRING_DATA(data); + memmove(dst, src, n); + memset(dst + n, 0, 7); + /* encrypt! */ + des_pcbc_encrypt(dst, src, n, sched, ivec, 0); + /* save vector to continue chaining */ + for (i = 0; i < 8; i++) + ivec[i] = dst[n - 8 + i] ^ src[n - 8 + i]; + /* round up to multiple of 8 */ + data.length = (data.length + 7) & 0xfffffff8; } - code = send_object(conn, (char *)&data, STRING_T); - if (code) { - com_err(whoami, connection_errno(conn), " transmitting file %s", - pathname); - close(fd); - return(connection_errno(conn)); + code = send_object(conn, (char *)&data, STRING_T); + if (code) + { + com_err(whoami, connection_errno(conn), " transmitting file %s", + pathname); + close(fd); + return connection_errno(conn); } - n_to_send -= n; - code = receive_object(conn, (char *)&n, INTEGER_T); - if (code) { - com_err(whoami, connection_errno(conn), - " awaiting ACK remote server during transmission of %s", - pathname); - close(fd); - return(connection_errno(conn)); + n_to_send -= n; + code = receive_object(conn, (char *)&n, INTEGER_T); + if (code) + { + com_err(whoami, connection_errno(conn), + " awaiting ACK remote server during transmission of %s", + pathname); + close(fd); + return connection_errno(conn); } - if (n) { - com_err(whoami, n, " from remote server during transmission of %s", - pathname); - close(fd); - return(n); + if (n) + { + com_err(whoami, n, " from remote server during transmission of %s", + pathname); + close(fd); + return n; } } - if (statb.st_size == 0) { - code = receive_object(conn, (char *)&n, INTEGER_T); - if (code) { - com_err(whoami, connection_errno(conn), - " awaiting ACK remote server after transmission of %s", - pathname); - close(fd); - return(connection_errno(conn)); + if (statb.st_size == 0) + { + code = receive_object(conn, (char *)&n, INTEGER_T); + if (code) + { + com_err(whoami, connection_errno(conn), + " awaiting ACK remote server after transmission of %s", + pathname); + close(fd); + return connection_errno(conn); } - if (n) { - com_err(whoami, n, " from remote server after transmission of %s", - pathname); - close(fd); - return(n); + if (n) + { + com_err(whoami, n, " from remote server after transmission of %s", + pathname); + close(fd); + return n; } } - close(fd); - return(MR_SUCCESS); + close(fd); + return MR_SUCCESS; } diff --git a/update/smskey.c b/update/smskey.c index cb5ba08a..c2d6f096 100644 --- a/update/smskey.c +++ b/update/smskey.c @@ -10,38 +10,39 @@ #include #include #include -int debug=0; /* goddamn des library breakage */ +int debug = 0; /* goddamn des library breakage */ char string[] = "sms\0\0Athena\0\1"; char srvtab[] = "/etc/srvtab"; char insecure[] = "\7\7\7This program MUST be run on the console, for security reasons.\n"; -main(argc,argv) - int argc; - char **argv; +int main(int argc, char **argv) { - int fd; - C_Block key; - char *tty, *ttyname(); - tty = ttyname(0); - if (!tty || strcmp(tty, "/dev/console")) { - fprintf(stderr, insecure); - exit(1); + int fd; + C_Block key; + char *tty, *ttyname(); + tty = ttyname(0); + if (!tty || strcmp(tty, "/dev/console")) + { + fprintf(stderr, insecure); + exit(1); } - fd = open(srvtab, O_WRONLY|O_APPEND, 0); - if (!fd) { - perror(srvtab); - exit(1); + fd = open(srvtab, O_WRONLY|O_APPEND, 0); + if (!fd) + { + perror(srvtab); + exit(1); } - if (sizeof(string)-1 != 13) { - fprintf(stderr, "string size bad\n"); - exit(1); + if (sizeof(string) - 1 != 13) + { + fprintf(stderr, "string size bad\n"); + exit(1); } - des_read_password(key, "Enter SMS update password: ", 0); - write(fd, string, sizeof(string)-1); - write(fd, key, sizeof(C_Block)); - if (fsync(fd)) - perror(srvtab); - close(fd); - printf("\nKey written.\n"); + des_read_password(key, "Enter SMS update password: ", 0); + write(fd, string, sizeof(string) - 1); + write(fd, key, sizeof(C_Block)); + if (fsync(fd)) + perror(srvtab); + close(fd); + printf("\nKey written.\n"); } diff --git a/update/ticket.c b/update/ticket.c index 1ce5e795..36aee351 100644 --- a/update/ticket.c +++ b/update/ticket.c @@ -30,67 +30,70 @@ static char service[ANAME_SZ] = "rcmd"; C_Block session; -static init() +static init(void) { - static int initialized = 0; + static int initialized = 0; - if (!initialized) { - if (krb_get_lrealm(realm, 1)) - strcpy(realm, KRB_REALM); - initialize_krb_error_table(); - initialized=1; + if (!initialized) + { + if (krb_get_lrealm(realm, 1)) + strcpy(realm, KRB_REALM); + initialize_krb_error_table(); + initialized = 1; } } -int -get_mr_update_ticket(host, ticket) - char *host; - KTEXT ticket; +int get_mr_update_ticket(char *host, KTEXT ticket) { - register int code; - register int pass; - char phost[BUFSIZ]; - CREDENTIALS cr; + register int code; + register int pass; + char phost[BUFSIZ]; + CREDENTIALS cr; - pass = 1; - init(); - strcpy(phost, (char*)krb_get_phost(host)); - try_it: - code = krb_mk_req(ticket, service, phost, realm, (long)0); - if (code) { - if (pass == 1) { - /* maybe we're taking too long? */ - if ((code = get_mr_tgt()) != 0) { - com_err(whoami, code, "can't get Kerberos TGT"); - return(code); - } - pass++; - goto try_it; - } - code += ERROR_TABLE_BASE_krb; - com_err(whoami, code, "in krb_mk_req"); - } else { - code = krb_get_cred(service, phost, realm, &cr); - if (code) code += ERROR_TABLE_BASE_krb; - memcpy(session, cr.session, sizeof(session)); - } - return(code); + pass = 1; + init(); + strcpy(phost, (char *)krb_get_phost(host)); +try_it: + code = krb_mk_req(ticket, service, phost, realm, (long)0); + if (code) + { + if (pass == 1) + { + /* maybe we're taking too long? */ + if ((code = get_mr_tgt())) + { + com_err(whoami, code, "can't get Kerberos TGT"); + return code; + } + pass++; + goto try_it; + } + code += ERROR_TABLE_BASE_krb; + com_err(whoami, code, "in krb_mk_req"); + } + else + { + code = krb_get_cred(service, phost, realm, &cr); + if (code) + code += ERROR_TABLE_BASE_krb; + memcpy(session, cr.session, sizeof(session)); + } + return code; } -int -get_mr_tgt() +int get_mr_tgt(void) { - register int code; - char linst[INST_SZ], kinst[INST_SZ]; + register int code; + char linst[INST_SZ], kinst[INST_SZ]; - init(); - linst[0] = '\0'; - strcpy(kinst, "krbtgt"); - code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm, - DEFAULT_TKT_LIFE, srvtab); - if (!code) - return(0); - else - return(code + ERROR_TABLE_BASE_krb); + init(); + linst[0] = '\0'; + strcpy(kinst, "krbtgt"); + code = krb_get_svc_in_tkt(master, linst, realm, kinst, realm, + DEFAULT_TKT_LIFE, srvtab); + if (!code) + return 0; + else + return code + ERROR_TABLE_BASE_krb; } diff --git a/update/update_server.c b/update/update_server.c index a74fd87c..d6ccb66d 100644 --- a/update/update_server.c +++ b/update/update_server.c @@ -46,161 +46,152 @@ int done = 0; int uid = 0; #define send_int(n) \ - (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T)) + (_send_int = (n), send_object(conn, (char *)&_send_int, INTEGER_T)) int _send_int; struct _dt { - char *str; - int (*proc)(); + char *str; + int (*proc)(); } dispatch_table[] = { - { "AUTH_002", auth_002 }, - { "XFER_002", xfer_002 }, - { "XFER_003", xfer_003 }, - { "EXEC_002", exec_002 }, - { "quit", quit }, - { (char *)NULL, (int (*)())abort } + { "AUTH_002", auth_002 }, + { "XFER_002", xfer_002 }, + { "XFER_003", xfer_003 }, + { "EXEC_002", exec_002 }, + { "quit", quit }, + { NULL, (int (*)())abort } }; /* general scratch space -- useful for building error messages et al... */ char buf[BUFSIZ]; - -main(argc, argv) - int argc; - char **argv; +int main(int argc, char **argv) { - STRING str; - struct _dt *d; - char *p; - int n; - -#ifdef DEBUG - gdb_debug(GDB_NOFORK); -#endif /* DEBUG */ - - whoami = strrchr(argv[0], '/'); - if (whoami) - whoami++; - else - whoami = argv[0]; - - /* interpret arguments here */ - if (argc != 1) { - fprintf(stderr, "Usage: %s\n", whoami); + STRING str; + struct _dt *d; + char *p; + int n; + + whoami = strrchr(argv[0], '/'); + if (whoami) + whoami++; + else + whoami = argv[0]; + + /* interpret arguments here */ + if (argc != 1) + { + fprintf(stderr, "Usage: %s\n", whoami); + exit(1); + } + + if (!config_lookup("nofork")) + { + if (fork()) + exit(0); + setsid(); + } + else + gdb_debug(GDB_NOFORK); + + umask(0022); + initialize_sms_error_table(); + initialize_krb_error_table(); + mr_update_initialize(); + + /* wait for connection */ + gdb_init(); + /* If the config file contains a line "port portname", the daemon + * will listen on the named port rather than SERVICE_NAME "sms_update" + */ + if (!(p = config_lookup("port"))) + p = SERVICE_NAME; + conn = create_forking_server(p, 0); + + /* If the config file contains a line "user username", the + * daemon will run with that user's UID. + */ + if ((p = config_lookup("user"))) + { + struct passwd *pw; + pw = getpwnam(p); + if (!pw) + { + com_err(whoami, errno, "Unable to find user %s\n", p); exit(1); - } + } + uid = pw->pw_uid; + } -#ifndef DEBUG - if (!config_lookup("nofork")) { - if (fork()) - exit(0); -#ifdef POSIX - setsid(); -#else - n = open("/dev/tty", O_RDWR|FNDELAY); - if (n > 0) { - (void) ioctl(n, TIOCNOTTY, (char *)NULL); - (void) close(n); - } -#endif - } else - gdb_debug(GDB_NOFORK); -#endif + /* If the config file contains a line "chroot /dir/name", the + * daemon will run chrooted to that directory. + */ + if ((p = config_lookup("chroot"))) + { + if (chroot(p) < 0) + { + com_err(whoami, errno, "unable to chroot to %s", p); + exit(1); + } + } - umask(0022); - initialize_sms_error_table(); - initialize_krb_error_table(); - mr_update_initialize(); - - /* wait for connection */ - gdb_init(); - /* If the config file contains a line "port portname", the daemon - * will listen on the named port rather than SERVICE_NAME "sms_update" - */ - if ((p = config_lookup("port")) == NULL) - p = SERVICE_NAME; - conn = create_forking_server(p, 0); - - /* If the config file contains a line "user username", the - * daemon will run with that user's UID. - */ - if (p = config_lookup("user")) { - struct passwd *pw; - pw = getpwnam(p); - if (pw == 0) { - com_err(whoami, errno, "Unable to find user %s\n", p); - exit(1); - } - uid = pw->pw_uid; - } - - /* If the config file contains a line "chroot /dir/name", the - * daemon will run chrooted to that directory. - */ - if (p = config_lookup("chroot")) { - if (chroot(p) < 0) { - com_err(whoami, errno, "unable to chroot to %s", p); - exit(1); - } - } - - if (!conn) { - com_err(whoami, errno, "can't get connection"); - exit(1); - } - if (connection_status(conn) == CON_STOPPED) { - com_err(whoami, connection_errno(conn), ": can't get connection"); - exit(1); - } - - mr_log_info("got connection"); - /* got a connection; loop forever */ - while (1) { - register char *cp; - code = receive_object(conn, (char *)&str, STRING_T); - if (code) { - com_err(whoami, connection_errno(conn), "receiving command"); - sever_connection(conn); - exit(1); - } - cp = strchr(STRING_DATA(str), ' '); - if (cp) - *cp = '\0'; - for (d = dispatch_table; d->str; d++) { - if (!strcmp(d->str, STRING_DATA(str))) { - if (cp) - *cp = ' '; -#ifdef DEBUG - printf("got request: %s\n", STRING_DATA(str)); -#endif /* DEBUG */ - (void)(d->proc)(STRING_DATA(str)); - goto ok; - } - } - sprintf(buf, "unknown request received: %s\n", STRING_DATA(str)); - mr_log_error(buf); - code = send_int(MR_UNKNOWN_PROC); - if (code) { - com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC"); - } - ok: - string_free(&str); - } + if (!conn) + { + com_err(whoami, errno, "can't get connection"); + exit(1); + } + if (connection_status(conn) == CON_STOPPED) + { + com_err(whoami, connection_errno(conn), ": can't get connection"); + exit(1); + } + + mr_log_info("got connection"); + /* got a connection; loop forever */ + while (1) + { + register char *cp; + code = receive_object(conn, (char *)&str, STRING_T); + if (code) + { + com_err(whoami, connection_errno(conn), "receiving command"); + sever_connection(conn); + exit(1); + } + cp = strchr(STRING_DATA(str), ' '); + if (cp) + *cp = '\0'; + for (d = dispatch_table; d->str; d++) + { + if (!strcmp(d->str, STRING_DATA(str))) + { + if (cp) + *cp = ' '; + (d->proc)(STRING_DATA(str)); + goto ok; + } + } + sprintf(buf, "unknown request received: %s\n", STRING_DATA(str)); + mr_log_error(buf); + code = send_int(MR_UNKNOWN_PROC); + if (code) + com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC"); + ok: + string_free(&str); + } } -int -send_ok() +int send_ok(void) { - static int zero = 0; - return((code = send_object(conn, (char *)&zero, INTEGER_T))); + static int zero = 0; + return code = send_object(conn, (char *)&zero, INTEGER_T); } -initialize() +initialize(void) { - /* keep have_authorization around */ - have_file = 0; - done = 0; + /* keep have_authorization around */ + have_file = 0; + done = 0; } @@ -215,17 +206,12 @@ initialize() * function: * closes connection from MR */ -int -quit(str) - char *str; +int quit(char *str) { -#ifdef lint - str = (char *)NULL; -#endif /* lint */ - (void) send_ok(); - sever_connection(conn); - mr_log_info("Closing connection."); - exit(0); + send_ok(); + sever_connection(conn); + mr_log_info("Closing connection."); + exit(0); } @@ -235,13 +221,12 @@ quit(str) * put to log as error, break connection, and exit */ -lose(msg) - char *msg; +lose(char *msg) { - com_err(whoami, code, msg); - if (conn) - sever_connection(conn); - exit(1); + com_err(whoami, code, msg); + if (conn) + sever_connection(conn); + exit(1); } /* @@ -250,13 +235,13 @@ lose(msg) * send back (external) ; if error, punt big with */ -report_error(msg) - char *msg; +report_error(char *msg) { - code = send_object(conn, (char *)&code, INTEGER_T); - if (code) { - code = connection_errno(conn); - lose(msg); + code = send_object(conn, (char *)&code, INTEGER_T); + if (code) + { + code = connection_errno(conn); + lose(msg); } } @@ -266,9 +251,8 @@ report_error(msg) * set (external) to and call */ -reject_call(c) - int c; +reject_call(int c) { - code = c; - report_error("call rejected"); + code = c; + report_error("call rejected"); } diff --git a/update/update_test.c b/update/update_test.c index 8e15a324..e3fefcb5 100644 --- a/update/update_test.c +++ b/update/update_test.c @@ -1,7 +1,7 @@ /* $Header$ * * Test client for update_server protocol. - * + * * Reads commands from the command line: * test host [commands...] * -s file file sends file to host @@ -27,100 +27,110 @@ CONNECTION conn; char *whoami; -main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { - char *host, service_address[256], *file, *rfile, buf[256]; - int code, i, count=0; + char *host, service_address[256], *file, *rfile, buf[256]; + int code, i, count = 0; - whoami = argv[0]; - initialize_sms_error_table(); - initialize_krb_error_table(); - gdb_init(); + whoami = argv[0]; + initialize_sms_error_table(); + initialize_krb_error_table(); + gdb_init(); - if (argc < 2) usage(); - host = argv[1]; + if (argc < 2) + usage(); + host = argv[1]; - sprintf(service_address, "%s:%s", host, SERVICE_NAME); - conn = start_server_connection(service_address, ""); - if (!conn || (connection_status(conn) == CON_STOPPED)) { - com_err(whoami, connection_errno(conn), - " can't connect to update %s", service_address); - return(MR_CANT_CONNECT); - } - code = send_auth(host); - if (code) { - com_err(whoami, code, " authorization attempt failed"); + sprintf(service_address, "%s:%s", host, SERVICE_NAME); + conn = start_server_connection(service_address, ""); + if (!conn || (connection_status(conn) == CON_STOPPED)) + { + com_err(whoami, connection_errno(conn), + " can't connect to update %s", service_address); + return MR_CANT_CONNECT; } + code = send_auth(host); + if (code) + com_err(whoami, code, " authorization attempt failed"); - for (i = 2; i < argc; i++) { - if (argv[i][0] != '-') usage(); - switch (argv[i][1]) { + for (i = 2; i < argc; i++) + { + if (argv[i][0] != '-') + usage(); + switch (argv[i][1]) + { case 's': - if (i+2 >= argc) usage(); - file = argv[++i]; - rfile = argv[++i]; - fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile); - send_file(file, rfile, 0); - break; + if (i + 2 >= argc) + usage(); + file = argv[++i]; + rfile = argv[++i]; + fprintf(stderr, "Sending file %s to %s as %s\n", file, host, rfile); + send_file(file, rfile, 0); + break; case 'S': - if (i+2 >= argc) usage(); - file = argv[++i]; - rfile = argv[++i]; - fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", file, host, rfile); - send_file(file, rfile, 1); - break; + if (i + 2 >= argc) + usage(); + file = argv[++i]; + rfile = argv[++i]; + fprintf(stderr, "Sending (encrypted) file %s to %s as %s\n", + file, host, rfile); + send_file(file, rfile, 1); + break; case 'i': - if (i+1 >= argc) usage(); - file = argv[++i]; - strcpy(buf, "/tmp/moira-updateXXXXX"); - mktemp(buf); - fprintf(stderr, "Sending instructions %s to %s as %s\n", - file, host, buf); - send_file(file, buf, 0); - break; + if (i + 1 >= argc) + usage(); + file = argv[++i]; + strcpy(buf, "/tmp/moira-updateXXXXX"); + mktemp(buf); + fprintf(stderr, "Sending instructions %s to %s as %s\n", + file, host, buf); + send_file(file, buf, 0); + break; case 'I': - if (i+2 >= argc) usage(); - file = argv[++i]; - rfile = argv[++i]; - strcpy(buf, rfile); - fprintf(stderr, "Sending instructions %s to %s as %s\n", - file, host, buf); - send_file(file, buf, 0); - break; + if (i + 2 >= argc) + usage(); + file = argv[++i]; + rfile = argv[++i]; + strcpy(buf, rfile); + fprintf(stderr, "Sending instructions %s to %s as %s\n", + file, host, buf); + send_file(file, buf, 0); + break; case 'x': - fprintf(stderr, "Executing instructions %s on %s\n", buf, host); - code = execute(buf); - if (code) com_err(whoami, code, "executing"); - break; + fprintf(stderr, "Executing instructions %s on %s\n", buf, host); + code = execute(buf); + if (code) + com_err(whoami, code, "executing"); + break; case 'X': - if (i+1 >= argc) usage(); - file = argv[++i]; - fprintf(stderr, "Executing instructions %s on %s\n", file, host); - code = execute(file); - if (code) com_err(whoami, code, "executing"); - break; + if (i + 1 >= argc) + usage(); + file = argv[++i]; + fprintf(stderr, "Executing instructions %s on %s\n", file, host); + code = execute(file); + if (code) + com_err(whoami, code, "executing"); + break; case 'n': - break; + break; default: - usage(); + usage(); } } - send_quit(); - conn = sever_connection(conn); - exit(code); + send_quit(); + conn = sever_connection(conn); + exit(code); } -usage() +usage(void) { - fprintf(stderr, "Usage: test host [commands...]\n"); - fprintf(stderr, " Commands are:\n"); - fprintf(stderr, "\t-s srcfile dstfile\tsends file\n"); - fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n"); - fprintf(stderr, "\t-i srcfile\t\tsends instructions\n"); - fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n"); - fprintf(stderr, "\t-x\t\texecutes last instructions\n"); - fprintf(stderr, "\t-X file\t\texecutes file\n"); - exit(1); + fprintf(stderr, "Usage: test host [commands...]\n"); + fprintf(stderr, " Commands are:\n"); + fprintf(stderr, "\t-s srcfile dstfile\tsends file\n"); + fprintf(stderr, "\t-S srcfile dstfile\tsends encrypted file\n"); + fprintf(stderr, "\t-i srcfile\t\tsends instructions\n"); + fprintf(stderr, "\t-I srcfile dstfile\tsends instructions\n"); + fprintf(stderr, "\t-x\t\texecutes last instructions\n"); + fprintf(stderr, "\t-X file\t\texecutes file\n"); + exit(1); } diff --git a/update/xfer_002.c b/update/xfer_002.c index 553b734f..3b87970c 100644 --- a/update/xfer_002.c +++ b/update/xfer_002.c @@ -47,51 +47,52 @@ extern int have_authorization, have_file, done; * of all at once; use checksums */ -int -xfer_002(str) - char *str; +int xfer_002(char *str) { - int file_size; - int checksum; - char *pathname; - - str += 8; - while (*str == ' ') - str++; - if (!*str) { + int file_size; + int checksum; + char *pathname; + + str += 8; + while (*str == ' ') + str++; + if (!*str) + { failure: - reject_call(MR_ARGS); - return(0); + reject_call(MR_ARGS); + return 0; } - file_size = atoi(str); - while (isdigit(*str)) - str++; - while (*str == ' ') - str++; - checksum = atoi(str); - while (isdigit(*str)) - str++; - while (*str == ' ') - str++; - if (*str != '/') - goto failure; - pathname = str; - if (!have_authorization) { - reject_call(MR_PERM); - return(0); + file_size = atoi(str); + while (isdigit(*str)) + str++; + while (*str == ' ') + str++; + checksum = atoi(str); + while (isdigit(*str)) + str++; + while (*str == ' ') + str++; + if (*str != '/') + goto failure; + pathname = str; + if (!have_authorization) + { + reject_call(MR_PERM); + return 0; } - if (done) /* re-initialize data */ - initialize(); - code = send_ok(); - if (code) - lose("sending ok for file xfer (2)"); - code = get_file(pathname, file_size, checksum, 0700, 0); - if (!code) { - char buf[BUFSIZ]; - have_file = 1; - strcpy(buf, "transferred file "); - strcat(buf, pathname); - mr_log_info(buf); + if (done) /* re-initialize data */ + initialize(); + code = send_ok(); + if (code) + lose("sending ok for file xfer (2)"); + code = get_file(pathname, file_size, checksum, 0700, 0); + if (!code) + { + char buf[BUFSIZ]; + have_file = 1; + strcpy(buf, "transferred file "); + strcat(buf, pathname); + mr_log_info(buf); } - return(0); + return 0; } diff --git a/update/xfer_003.c b/update/xfer_003.c index f1aa2592..78069983 100644 --- a/update/xfer_003.c +++ b/update/xfer_003.c @@ -46,51 +46,52 @@ extern int have_authorization, have_file, done; * this version of transfer encrypts the file being transferred. */ -int -xfer_003(str) - char *str; +int xfer_003(char *str) { - int file_size; - int checksum; - char *pathname; - - str += 8; - while (*str == ' ') - str++; - if (!*str) { + int file_size; + int checksum; + char *pathname; + + str += 8; + while (*str == ' ') + str++; + if (!*str) + { failure: - reject_call(MR_ARGS); - return(0); + reject_call(MR_ARGS); + return 0; } - file_size = atoi(str); - while (isdigit(*str)) - str++; - while (*str == ' ') - str++; - checksum = atoi(str); - while (isdigit(*str)) - str++; - while (*str == ' ') - str++; - if (*str != '/') - goto failure; - pathname = str; - if (!have_authorization) { - reject_call(MR_PERM); - return(0); + file_size = atoi(str); + while (isdigit(*str)) + str++; + while (*str == ' ') + str++; + checksum = atoi(str); + while (isdigit(*str)) + str++; + while (*str == ' ') + str++; + if (*str != '/') + goto failure; + pathname = str; + if (!have_authorization) + { + reject_call(MR_PERM); + return 0; } - if (done) /* re-initialize data */ - initialize(); - code = send_ok(); - if (code) - lose("sending ok for file xfer (2)"); - code = get_file(pathname, file_size, checksum, 0444, 1); - if (!code) { - char buf[BUFSIZ]; - have_file = 1; - strcpy(buf, "transferred file "); - strcat(buf, pathname); - mr_log_info(buf); + if (done) /* re-initialize data */ + initialize(); + code = send_ok(); + if (code) + lose("sending ok for file xfer (2)"); + code = get_file(pathname, file_size, checksum, 0444, 1); + if (!code) + { + char buf[BUFSIZ]; + have_file = 1; + strcpy(buf, "transferred file "); + strcat(buf, pathname); + mr_log_info(buf); } - return(0); + return 0; } -- 2.45.2