]> andersk Git - moira.git/commitdiff
translate to SQL
authormar <mar>
Mon, 4 Jan 1993 15:57:08 +0000 (15:57 +0000)
committermar <mar>
Mon, 4 Jan 1993 15:57:08 +0000 (15:57 +0000)
regtape/employee.dc
regtape/sign.dc
regtape/verify.dc [new file with mode: 0644]

index f3a23d16220982c9f8ca6650fe7c46f95eae692a..75c754348d35d2087395d808de856dfae52f9405 100644 (file)
@@ -7,10 +7,11 @@
 #include <sys/time.h>
 #include <moira.h>
 #include <moira_site.h>
+EXEC SQL INCLUDE sqlca;
 
 
-##define WHO 11859             /* root */
-##define PROG "emp-tape"
+#define WHO 11859              /* root */
+#define PROG "emp-tape"
 
 #define MAX_ID_VALUE   31999
 #define MIN_ID_VALUE   101
@@ -74,7 +75,7 @@ int newfinger = 0;
 main(argc, argv)
 int argc;
 char **argv;
-##{
+{
     FILE *in;
     struct entry *e, *get_next_entry();
     int i, wait = 0;
@@ -108,11 +109,11 @@ char **argv;
     setlinebuf(stdout);
     setlinebuf(stderr);
 
-##  ingres sms
-##  range of u is users
+    EXEC SQL CONNECT moira;
 
     while (e = get_next_entry(in)) {
        process_entry(e);
+       EXEC SQL COMMIT;
        if (wait) {
            printf("Next");
            fflush(stdout);
@@ -120,9 +121,8 @@ char **argv;
        }
     }
 
-##  exit
     exit(0);
-##}
+}
 
 
 char *substr(buf, key)
@@ -226,13 +226,15 @@ FILE *in;
 
 process_entry(e)
 struct entry *e;
-##{
+{
     int changed, nochange;
     char buf[BUFSIZ], *from, *to;
-##  char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
-##  char *raddr, *rhphone, *rophone;
-##  char class[9], oaddr[25], ophone[17], dept[128];
-##  int id, status;
+    EXEC SQL BEGIN DECLARE SECTION;
+    char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
+    char *raddr, *rhphone, *rophone;
+    char class[9], oaddr[25], ophone[17], dept[128];
+    int id, status;
+    EXEC SQL END DECLARE SECTION;
 
     first = e->first;
     if (strlen(first) > 16)
@@ -245,14 +247,15 @@ struct entry *e;
     id = 0;
 
     /* Get user info */
-##  repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
-##           ophone = u.office_phone, dept = u.mit_dept, status = u.#status)
-##     where u.#last = @last and u.#first = @first and u.mit_id = @sid
+    EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
+      INTO :id, :class, :oaddr, :ophone, :dept, :status
+      FROM users
+      WHERE last = :last and first = :first and clearid = :sid;
     if (id == 0) {
-##     repeat retrieve (id = u.users_id, class = u.mit_year, 
-##                      oaddr = u.office_addr, ophone = u.office_phone,
-##                      dept = u.mit_dept, status = u.#status)
-##             where u.#last = @last and u.#first = @first and u.mit_id = @eid
+       EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
+         INTO :id, :class, :oaddr, :ophone, :dept, :status
+         FROM users
+         WHERE last = :last and first = :first and clearid = :eid;
        if (id == 0) {
            newuser(e);
            return;
@@ -268,9 +271,10 @@ struct entry *e;
        if (status == US_ENROLL_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
          status = US_ENROLLED;
        strcpy(class, e->class);
-##     repeat replace u (mit_year = @class, #status = @status,
-##                modtime = "now", modby = WHO, modwith = PROG)
-##         where u.users_id = @id
+       EXEC SQL UPDATE users
+         SET type = :class, status = :status, modtime = 'now',
+               modby = WHO, modwith = PROG
+         WHERE users_id = :id;
     }
 
     changed = nochange = 0;
@@ -335,31 +339,36 @@ struct entry *e;
     rophone = e->phone2;
     if (changed) {
        com_err(whoami, 0, "updating finger for %s %s", first, last);
-##     repeat replace u (office_addr = @oaddr,
-##                office_phone = @ophone, #mit_dept = @dept,
-##                fmodtime = "now", fmodby = WHO, fmodwith = PROG,
-##                xname = @name, xdept = @rdept, xtitle = @rtitle,
-##                xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
-##                xmodtime = date("now"), mit_id = @sid)
-##         where u.users_id = @id
+       EXEC SQL REPEATED UPDATE users
+         SET office_addr = :oaddr, office_phone = :ophone, mit_dept = :dept,
+           fmodtime = 'now', fmodby = WHO, fmodwith = PROG,
+           xname = :name, xdept = :rdept, xtitle = :rtitle,
+           xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
+           xmodtime = 'now', mit_id = :sid
+         WHERE users_id = :id;
     } else {
-##     repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle,
-##                xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
-##                xmodtime = date("now"), mit_id = @sid)
-##         where u.users_id = @id
+       EXEC SQL REPEATED UPDATE users
+         SET xname = :name, xdept = :rdept, xtitle = :rtitle,
+           xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
+           xmodtime = 'now', mit_id = :sid
+         WHERE users_id = :id;
     }
-##}
+}
 
 
 newuser(e)
 struct entry *e;
-##{
+{
     char *from, *to;
-##  int id, uid, st;
-##  char *last, *first, *class, *middle, login[9], *sid, fullname[65];
-##  char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17];
-##  char *rdept, *rhphone, *rophone;
-
+    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 = index(oaddr, ','))
@@ -400,52 +409,52 @@ struct entry *e;
     rhphone = e->phone;
     rophone = e->phone2;
 
-
-##  append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
-##               #last = last, #first = first, #middle = middle, status = st,
-##               #mit_id = sid, #mit_year = class,
-##               modtime = "now", modby = WHO, modwith = PROG,
-##               #fullname = fullname, office_addr = oaddr,
-##               office_phone = ophone, #mit_dept = dept,
-##               fmodtime = "now", fmodby = WHO, fmodwith = PROG,
-##               potype = "NONE",
-##               xname = name, xdept = rdept, xtitle = title,
-##               xaddress = oaddr, xphone1 = rhphone, xphone2 = rophone,
-##               xmodtime = date("now"))
-
-##}
+    EXEC SQL INSERT INTO users
+      (login, users_id, 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/csh', :last, :first, :middle, :st,
+             :sid, :class, 'now', :who, :prog, :fullname, :oaddr, :ophone,
+             :dept, 'now', :who, :prog, 'NONE', :name, :rdept,
+             :title, :oaddr, :rhphone, :rophone, 'now');
+}
 
 
 set_next_object_id(object, limit)
     char *object;
     int limit;
-##{
-##  char *name;
-##  int rowcount, exists, value;
+{
+    EXEC SQL BEGIN DECLARE SECTION;
+    char *name;
+    int rowcount, flag, value;
+    EXEC SQL END DECLARE SECTION;
 
     name = object;
-##  begin transaction
-##  repeat retrieve (value = values.#value) where values.#name = @name
-##  inquire_equel(rowcount = "rowcount")
-    if (rowcount != 1) {
-##     abort
-       return(0);
+    EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :name;
+    if (sqlca.sqlerrd[2] != 1) {
+       EXEC SQL ROLLBACK;
+       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
+       exit(1);
     }
 
-##  retrieve (exists = any(users.name where users.name = value))
-##  inquire_equel(rowcount = "rowcount")
-    if (rowcount != 1) {
-##     abort
-       return(0);
-    }
-    while (exists) {
+    flag = 0;
+    EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
+    if (sqlca.sqlerrd[2] == 0)
+      flag = 0;
+    while (flag) {
        value++;
        if (limit && value > MAX_ID_VALUE)
            value = MIN_ID_VALUE;
-##     retrieve (exists = any(users.name where users.name = value))
+       flag = 0;
+       EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
+       if (sqlca.sqlerrd[2] == 0)
+         flag = 0;
     }
 
-##  repeat replace values (#value = @value) where values.#name = @name
-##  end transaction
+    value++;
+    if (limit && value > MAX_ID_VALUE)
+      value = MIN_ID_VALUE;
+    EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = :name;
     return(value);
-##}
+}
index 775cfcf31422174ed5bd4a977dde7514bfb6ceb0..e4fa5bd536dac5971fff1973bb78d9435bda7348 100644 (file)
@@ -13,6 +13,7 @@
 #include <krb.h>
 #include <krb_err.h>
 #include <gdss.h>
+EXEC SQL INCLUDE sqlca;
 
 
 char *program;
@@ -20,13 +21,15 @@ char *program;
 main(argc, argv)
 int argc;
 char **argv;
-##{
+{
      char buf[BUFSIZ], *data, *p;
      struct save_queue *sq;
      SigInfo si;
      int found, status, i, wait;
-##   char login[10], mid[32], rawsig[256];
-##   int id, timestamp, sms;
+     EXEC SQL BEGIN DECLARE SECTION;
+     char login[10], mid[32], rawsig[256];
+     int id, timestamp, sms;
+     EXEC SQL END DECLARE SECTION;
 
      program = "sign";
      init_krb_err_tbl();
@@ -53,12 +56,11 @@ char **argv;
           com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt");
      }
 
-##   ingres #sms
-##   range of u is users
-##   range of s is strings
+     EXEC SQL CONNECT moira;
 
      sms = 0;
-##   retrieve (sms = s.string_id) where s.string="moira.extra@ATHENA.MIT.EDU"
+     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();
@@ -68,14 +70,19 @@ char **argv;
      found = 0;
      sq = sq_create();
 
-##   retrieve (id = u.users_id, login = u.#login, mid = u.mit_id)
-##     where u.signature = "" and u.xmodtime > date("01-jul-92") {
-       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 DECLARE c CURSOR FOR
+       SELECT users_id, login, clearid
+       FROM users WHERE signature = '';
+     EXEC SQL OPEN c;
+     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++;
+     }
 
      printf("Found %d users to sign.\n", found);
 
@@ -90,6 +97,7 @@ char **argv;
         *p++ = 0;
         id = atoi(data);
         data = p;
+     again:
         status = GDSS_Sign(data, strlen(data), buf);
         if (status) {
             com_err(program, gdss2et(status), "signing data");
@@ -100,10 +108,15 @@ char **argv;
             com_err(program, gdss2et(status), "verifying data");
             continue;
         }
+        if (strlen(rawsig) > 68) {
+            sleep(1);
+            goto again;
+        }
 
         timestamp = si.timestamp;
-##      replace u (signature = rawsig, sigwho = sms, sigdate = timestamp)
-##        where u.users_id = id
+        EXEC SQL REPEATED UPDATE users 
+          SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp
+          WHERE users_id = :id;
         if (wait) {
             printf("Next");
             fflush(stdout);
@@ -111,6 +124,5 @@ char **argv;
         }
      }
      dest_tkt();
-##   exit
      exit(0);
-##}
+}
diff --git a/regtape/verify.dc b/regtape/verify.dc
new file mode 100644 (file)
index 0000000..9561e55
--- /dev/null
@@ -0,0 +1,172 @@
+/* $Header$
+ *
+ * This program will verify signatures on user records in the database.
+ */
+
+#include <stdio.h>
+#include <strings.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <moira.h>
+#include <moira_site.h>
+#include <des.h>
+#include <krb.h>
+#include <gdss.h>
+EXEC SQL INCLUDE sqlca;
+
+
+char *program;
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+    char buf[BUFSIZ], *usercheck[100], sigbuf[256];
+    SigInfo si;
+    int status, i, wait, check, debug;
+    EXEC SQL BEGIN DECLARE SECTION;
+    char login[10], mid[32], rawsig[256], who[257];
+    int id, timestamp;
+    EXEC SQL END DECLARE SECTION;
+
+    initialize_sms_error_table();
+    initialize_krb_error_table();
+    initialize_gdss_error_table();
+
+    program = "sign";
+    check = debug = 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 (argv[i][0] == '-')
+         fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]);
+       else usercheck[check++] = argv[i];
+    }
+
+    EXEC SQL CONNECT moira;
+
+    if (check == 0) {
+       EXEC SQL DECLARE c CURSOR FOR
+         SELECT login, clearid, signature, string, sigdate
+         FROM users, strings
+         WHERE signature != '' 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;
+           }
+           si.rawsig = NULL;
+           status = GDSS_Verify(buf, strlen(buf), sigbuf, &si);
+           if (status) {
+               com_err(program, gdss2et(status), "verifying user %s", login);
+           }
+           if (wait) {
+               printf("Next");
+               fflush(stdout);
+               gets(buf);
+           }
+       }
+    } 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 signature != '' and 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;
+               }
+               si.rawsig = NULL;
+               status = GDSS_Verify(buf, strlen(buf), sigbuf, &si);
+               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);
+               }
+           }
+       }
+    }
+
+     exit(0);
+}
+
+
+hex_dump(p)
+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;
+    }
+    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;
+    case 6:
+       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;
+    case 4:
+       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;
+    case 2:
+       printf("%02x %02x\n",
+               p[0], p[1]);
+       break;
+    case 1:
+       printf("%02x\n",
+               p[0]);
+       break;
+    default:
+       return;
+    }
+}
This page took 0.245931 seconds and 5 git commands to generate.