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