]> andersk Git - moira.git/blame - gen/passwd.dc
do better locking
[moira.git] / gen / passwd.dc
CommitLineData
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
18extern int errno;
5076cbb9 19char *ingres_date_and_time();
9854e61c 20char *whoami = "passwd.gen";
5076cbb9 21
67796c83 22
23main(argc, argv)
24int argc;
25char **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;
537c6b4e 31## char nickname[17];
5076cbb9 32## int uid, error, flag;
9854e61c 33 int ingerr();
5076cbb9 34
9854e61c 35 IIseterr(ingerr);
5076cbb9 36## ingres sms
8b585119 37## set lockmode session where level = table
67796c83 38
39 if (argc == 2) {
5076cbb9 40 if (stat(argv[1], &sb) == 0) {
41 filetime = ingres_date_and_time(sb.st_mtime);
42## retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
43## where tblstats.table = "users"
44 if (flag < 0) {
45 fprintf(stderr, "File %s does not need to be rebuilt.\n",
46 argv[1]);
c6c0644d 47 exit(SMS_NO_CHANGE);
5076cbb9 48 }
49 }
c6c0644d 50 outf = argv[1];
51 sprintf(outft, "%s~", outf);
52 if ((out = fopen(outft, "w")) == NULL) {
53 fprintf(stderr, "unable to open %s for output\n", outf);
54 exit(SMS_OCONFIG);
67796c83 55 }
56 } else if (argc != 1) {
57 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
c6c0644d 58 exit(SMS_ARGS);
59 } else {
60 outf = NULL;
67796c83 61 }
62
67796c83 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,
537c6b4e 66## nickname = u.#nickname,
67796c83 67## op = u.office_phone, hp = u.home_phone)
c6c0644d 68## where u.status = 1 {
b9d8f082 69 strtrim(login);
70 strtrim(fullname);
537c6b4e 71 strtrim(nickname);
b9d8f082 72 strtrim(oa);
73 strtrim(op);
74 strtrim(hp);
75 strtrim(shell);
537c6b4e 76 fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n",
77 login, uid, fullname, nickname, oa, op, hp, login, shell);
67796c83 78## }
79## inquire_equel(error = "errorno")
80 if (error) {
81 fprintf(out, "Ingres error %d\n", error);
c6c0644d 82 exit(SMS_INGRES_ERR);
67796c83 83 }
84
85## exit
86
87 if (fclose(out)) {
88 perror("close failed");
c6c0644d 89 exit(SMS_CCONFIG);
67796c83 90 }
c6c0644d 91 if (outf)
92 fix_file(outf);
93 exit(SMS_SUCCESS);
67796c83 94}
9854e61c 95
96
97/*
98 * ingerr: (supposedly) called when Ingres indicates an error.
99 * I have not yet been able to get this to work to intercept a
100 * database open error.
101 */
102#define INGRES_DEADLOCK 4700
103
104static int ingerr(num)
105 int *num;
106{
107 char buf[256];
108 int ingres_errno;
109
110 switch (*num) {
111 case INGRES_DEADLOCK:
112 ingres_errno = SMS_DEADLOCK;
113 break;
114 default:
115 ingres_errno = SMS_INGRES_ERR;
116 }
117 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
118 critical_alert("DCM", "Passwd build encountered INGRES ERROR %d", *num);
119 exit(ingres_errno);
120}
This page took 0.069974 seconds and 5 git commands to generate.