]> andersk Git - moira.git/blob - gen/passwd.dc
c3984dab024ba7f21e54875ab86460b59e99271d
[moira.git] / gen / passwd.dc
1 /* $Header$
2  *
3  * This generates a master /etc/passwd containing all active (status != 0)
4  * accounts.
5  */
6
7 #include <stdio.h>
8 #include <sms.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/time.h>
12
13 extern int errno;
14 char *ingres_date_and_time();
15 char *whoami = "passwd.gen";
16
17
18 main(argc, argv)
19 int argc;
20 char **argv;
21 {
22     FILE *out = stdout;
23     char *outf, outft[64];
24     struct stat sb;
25 ##  char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
26 ##  int uid, error, flag;
27     int ingerr();
28
29     IIseterr(ingerr);
30 ##  ingres sms
31
32     if (argc == 2) {
33         if (stat(argv[1], &sb) == 0) {
34             filetime = ingres_date_and_time(sb.st_mtime);
35 ##          retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
36 ##              where tblstats.table = "users"
37             if (flag < 0) {
38                 fprintf(stderr, "File %s does not need to be rebuilt.\n",
39                         argv[1]);
40                 exit(SMS_NO_CHANGE);
41             }
42         }
43         outf = argv[1];
44         sprintf(outft, "%s~", outf);
45         if ((out = fopen(outft, "w")) == NULL) {
46             fprintf(stderr, "unable to open %s for output\n", outf);
47             exit(SMS_OCONFIG);
48         }
49     } else if (argc != 1) {
50         fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
51         exit(SMS_ARGS);
52     } else {
53         outf = NULL;
54     }
55
56 ##  set lockmode on users where readlock = nolock
57
58 ##  range of u is users
59 ##  retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
60 ##            fullname = u.#fullname, oa = u.office_addr,
61 ##            op = u.office_phone, hp = u.home_phone)
62 ##      where u.status = 1 {
63             strtrim(login);
64             strtrim(fullname);
65             strtrim(oa);
66             strtrim(op);
67             strtrim(hp);
68             strtrim(shell);
69             fprintf(out, "%s:*:%d:101:%s,%s,%s,%s:/mit/%s:%s\n",
70                     login, uid, fullname, oa, op, hp, login, shell);
71 ##  }
72 ##  inquire_equel(error = "errorno")
73     if (error)  {
74         fprintf(out, "Ingres error %d\n", error);
75         exit(SMS_INGRES_ERR);
76     }
77
78 ##  exit
79
80     if (fclose(out)) {
81         perror("close failed");
82         exit(SMS_CCONFIG);
83     }
84     if (outf)
85       fix_file(outf);
86     exit(SMS_SUCCESS);
87 }
88
89
90 /*
91  * ingerr: (supposedly) called when Ingres indicates an error.
92  * I have not yet been able to get this to work to intercept a
93  * database open error.
94  */
95 #define INGRES_DEADLOCK 4700
96
97 static int ingerr(num)
98     int *num;
99 {
100     char buf[256];
101     int ingres_errno;
102
103     switch (*num) {
104     case INGRES_DEADLOCK:
105         ingres_errno = SMS_DEADLOCK;
106         break;
107     default:
108         ingres_errno = SMS_INGRES_ERR;
109     }
110     com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
111     critical_alert("DCM", "Passwd build encountered INGRES ERROR %d", *num);
112     exit(ingres_errno);
113 }
This page took 0.07058 seconds and 3 git commands to generate.