]> andersk Git - moira.git/blobdiff - gen/passwd.dc
fixed name section
[moira.git] / gen / passwd.dc
index fd52754eadc097ae9738e8038a4f25e4c24bd380..52b8101af35aa5938083b74c01e7347136bcce18 100644 (file)
@@ -2,15 +2,22 @@
  *
  * This generates a master /etc/passwd containing all active (status != 0)
  * accounts.
+ *
+ *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
  */
 
+#include <mit-copyright.h>
 #include <stdio.h>
+#include <sms.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 
 extern int errno;
 char *ingres_date_and_time();
+char *whoami = "passwd.gen";
 
 
 main(argc, argv)
@@ -18,10 +25,13 @@ int argc;
 char **argv;
 {
     FILE *out = stdout;
+    char *outf, outft[64];
     struct stat sb;
 ##  char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
 ##  int uid, error, flag;
+    int ingerr();
 
+    IIseterr(ingerr);
 ##  ingres sms
 
     if (argc == 2) {
@@ -32,16 +42,20 @@ char **argv;
            if (flag < 0) {
                fprintf(stderr, "File %s does not need to be rebuilt.\n",
                        argv[1]);
-               exit(0);
+               exit(SMS_NO_CHANGE);
            }
        }
-       if ((out = fopen(argv[1], "w")) == NULL) {
-           fprintf(stderr, "unable to open %s for output\n", argv[1]);
-           exit(errno);
+       outf = argv[1];
+       sprintf(outft, "%s~", outf);
+       if ((out = fopen(outft, "w")) == NULL) {
+           fprintf(stderr, "unable to open %s for output\n", outf);
+           exit(SMS_OCONFIG);
        }
     } else if (argc != 1) {
        fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
-       exit(-1);
+       exit(SMS_ARGS);
+    } else {
+       outf = NULL;
     }
 
 ##  set lockmode on users where readlock = nolock
@@ -50,27 +64,55 @@ char **argv;
 ##  retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
 ##           fullname = u.#fullname, oa = u.office_addr,
 ##           op = u.office_phone, hp = u.home_phone)
-##     where u.status != 0 sort by #login {
-           trim(login);
-           trim(fullname);
-           trim(oa);
-           trim(op);
-           trim(hp);
-           trim(shell);
+##     where u.status = 1 {
+           strtrim(login);
+           strtrim(fullname);
+           strtrim(oa);
+           strtrim(op);
+           strtrim(hp);
+           strtrim(shell);
            fprintf(out, "%s:*:%d:101:%s,%s,%s,%s:/mit/%s:%s\n",
                    login, uid, fullname, oa, op, hp, login, shell);
 ##  }
 ##  inquire_equel(error = "errorno")
     if (error)  {
        fprintf(out, "Ingres error %d\n", error);
-       exit(error);
+       exit(SMS_INGRES_ERR);
     }
 
 ##  exit
 
     if (fclose(out)) {
        perror("close failed");
-       exit(errno);
+       exit(SMS_CCONFIG);
+    }
+    if (outf)
+      fix_file(outf);
+    exit(SMS_SUCCESS);
+}
+
+
+/*
+ * ingerr: (supposedly) called when Ingres indicates an error.
+ * I have not yet been able to get this to work to intercept a
+ * database open error.
+ */
+#define INGRES_DEADLOCK 4700
+
+static int ingerr(num)
+    int *num;
+{
+    char buf[256];
+    int ingres_errno;
+
+    switch (*num) {
+    case INGRES_DEADLOCK:
+       ingres_errno = SMS_DEADLOCK;
+       break;
+    default:
+       ingres_errno = SMS_INGRES_ERR;
     }
-    exit(0);
+    com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
+    critical_alert("DCM", "Passwd build encountered INGRES ERROR %d", *num);
+    exit(ingres_errno);
 }
This page took 0.773886 seconds and 4 git commands to generate.