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