]> andersk Git - moira.git/blob - gen/passwd.dc
4964a55421011af6ba5b337e70506289e60b4479
[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
16
17 main(argc, argv)
18 int argc;
19 char **argv;
20 {
21     FILE *out = stdout;
22     char *outf, outft[64];
23     struct stat sb;
24 ##  char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
25 ##  int uid, error, flag;
26
27 ##  ingres sms
28
29     if (argc == 2) {
30         if (stat(argv[1], &sb) == 0) {
31             filetime = ingres_date_and_time(sb.st_mtime);
32 ##          retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
33 ##              where tblstats.table = "users"
34             if (flag < 0) {
35                 fprintf(stderr, "File %s does not need to be rebuilt.\n",
36                         argv[1]);
37                 exit(SMS_NO_CHANGE);
38             }
39         }
40         outf = argv[1];
41         sprintf(outft, "%s~", outf);
42         if ((out = fopen(outft, "w")) == NULL) {
43             fprintf(stderr, "unable to open %s for output\n", outf);
44             exit(SMS_OCONFIG);
45         }
46     } else if (argc != 1) {
47         fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
48         exit(SMS_ARGS);
49     } else {
50         outf = NULL;
51     }
52
53 ##  set lockmode on users where readlock = nolock
54
55 ##  range of u is users
56 ##  retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
57 ##            fullname = u.#fullname, oa = u.office_addr,
58 ##            op = u.office_phone, hp = u.home_phone)
59 ##      where u.status = 1 {
60             strtrim(login);
61             strtrim(fullname);
62             strtrim(oa);
63             strtrim(op);
64             strtrim(hp);
65             strtrim(shell);
66             fprintf(out, "%s:*:%d:101:%s,%s,%s,%s:/mit/%s:%s\n",
67                     login, uid, fullname, oa, op, hp, login, shell);
68 ##  }
69 ##  inquire_equel(error = "errorno")
70     if (error)  {
71         fprintf(out, "Ingres error %d\n", error);
72         exit(SMS_INGRES_ERR);
73     }
74
75 ##  exit
76
77     if (fclose(out)) {
78         perror("close failed");
79         exit(SMS_CCONFIG);
80     }
81     if (outf)
82       fix_file(outf);
83     exit(SMS_SUCCESS);
84 }
This page took 0.028498 seconds and 3 git commands to generate.