]>
Commit | Line | Data |
---|---|---|
67796c83 | 1 | /* $Header$ |
2 | * | |
3 | * This generates a master /etc/passwd containing all active (status != 0) | |
4 | * accounts. | |
5 | */ | |
6 | ||
7 | #include <stdio.h> | |
c6c0644d | 8 | #include <sms.h> |
5076cbb9 | 9 | #include <sys/types.h> |
10 | #include <sys/stat.h> | |
11 | #include <sys/time.h> | |
67796c83 | 12 | |
13 | extern int errno; | |
5076cbb9 | 14 | char *ingres_date_and_time(); |
9854e61c | 15 | char *whoami = "passwd.gen"; |
5076cbb9 | 16 | |
67796c83 | 17 | |
18 | main(argc, argv) | |
19 | int argc; | |
20 | char **argv; | |
21 | { | |
67796c83 | 22 | FILE *out = stdout; |
c6c0644d | 23 | char *outf, outft[64]; |
5076cbb9 | 24 | struct stat sb; |
25 | ## char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime; | |
26 | ## int uid, error, flag; | |
9854e61c | 27 | int ingerr(); |
5076cbb9 | 28 | |
9854e61c | 29 | IIseterr(ingerr); |
5076cbb9 | 30 | ## ingres sms |
67796c83 | 31 | |
32 | if (argc == 2) { | |
5076cbb9 | 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]); | |
c6c0644d | 40 | exit(SMS_NO_CHANGE); |
5076cbb9 | 41 | } |
42 | } | |
c6c0644d | 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); | |
67796c83 | 48 | } |
49 | } else if (argc != 1) { | |
50 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
c6c0644d | 51 | exit(SMS_ARGS); |
52 | } else { | |
53 | outf = NULL; | |
67796c83 | 54 | } |
55 | ||
67796c83 | 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) | |
c6c0644d | 62 | ## where u.status = 1 { |
b9d8f082 | 63 | strtrim(login); |
64 | strtrim(fullname); | |
65 | strtrim(oa); | |
66 | strtrim(op); | |
67 | strtrim(hp); | |
68 | strtrim(shell); | |
67796c83 | 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); | |
c6c0644d | 75 | exit(SMS_INGRES_ERR); |
67796c83 | 76 | } |
77 | ||
78 | ## exit | |
79 | ||
80 | if (fclose(out)) { | |
81 | perror("close failed"); | |
c6c0644d | 82 | exit(SMS_CCONFIG); |
67796c83 | 83 | } |
c6c0644d | 84 | if (outf) |
85 | fix_file(outf); | |
86 | exit(SMS_SUCCESS); | |
67796c83 | 87 | } |
9854e61c | 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 | } |