]> andersk Git - moira.git/blame - gen/passwd.dc
New database and column names for Moira2.
[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 *
a99210a5 6 * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology.
0a5ff702 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>
2ce085d2 13#include <moira.h>
5076cbb9 14#include <sys/types.h>
15#include <sys/stat.h>
16#include <sys/time.h>
a99210a5 17EXEC SQL INCLUDE sqlca;
67796c83 18
19extern int errno;
9854e61c 20char *whoami = "passwd.gen";
5076cbb9 21
67796c83 22
23main(argc, argv)
24int argc;
25char **argv;
26{
67796c83 27 FILE *out = stdout;
5f1ae373 28 char *outf = NULL, outft[64];
5076cbb9 29 struct stat sb;
a99210a5 30 int flag;
31 EXEC SQL BEGIN DECLARE SECTION;
32 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
33 char nickname[17];
34 int uid;
35 EXEC SQL END DECLARE SECTION;
5076cbb9 36
a99210a5 37#ifsql INGRES
9fd1c2b8 38 EXEC SQL CONNECT moira;
a99210a5 39#endsql
40#ifsql INFORMIX
9fd1c2b8 41 EXEC SQL DATABASE moira;
a99210a5 42#endsql
67796c83 43
44 if (argc == 2) {
5076cbb9 45 if (stat(argv[1], &sb) == 0) {
a99210a5 46 if (ModDiff (&flag, "users", sb.st_mtime))
47 exit(MR_DATE);
5076cbb9 48 if (flag < 0) {
49 fprintf(stderr, "File %s does not need to be rebuilt.\n",
50 argv[1]);
2ce085d2 51 exit(MR_NO_CHANGE);
5076cbb9 52 }
53 }
c6c0644d 54 outf = argv[1];
55 sprintf(outft, "%s~", outf);
56 if ((out = fopen(outft, "w")) == NULL) {
57 fprintf(stderr, "unable to open %s for output\n", outf);
2ce085d2 58 exit(MR_OCONFIG);
67796c83 59 }
60 } else if (argc != 1) {
61 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
2ce085d2 62 exit(MR_ARGS);
c6c0644d 63 } else {
64 outf = NULL;
67796c83 65 }
66
9fd1c2b8 67 /* The following is declarative, not executed,
68 * and so is dependent on where it is in the file,
69 * not in the order of execution of statements.
70 */
a99210a5 71 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
72
73 EXEC SQL DECLARE x CURSOR FOR SELECT
74 login, uid, shell, fullname, office_addr, nickname,
75 office_phone, home_phone
76 FROM users WHERE status = 1;
77 EXEC SQL OPEN x;
78 while (1) {
79 EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname,
80 :op, :hp;
81 if (sqlca.sqlcode != 0) break;
82 strtrim(login);
83 strtrim(fullname);
84 strtrim(nickname);
85 strtrim(oa);
86 strtrim(op);
87 strtrim(hp);
88 strtrim(shell);
89 fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n",
90 login, uid, fullname, nickname, oa, op, hp, login, shell);
67796c83 91 }
92
a99210a5 93 EXEC SQL CLOSE x;
94#ifsql INGRES
95 EXEC SQL DISCONNECT;
96#endsql
5f1ae373 97#ifsql INFORMIX
98 EXEC SQL CLOSE DATABASE;
99#endsql
67796c83 100
101 if (fclose(out)) {
102 perror("close failed");
2ce085d2 103 exit(MR_CCONFIG);
67796c83 104 }
c6c0644d 105 if (outf)
106 fix_file(outf);
2ce085d2 107 exit(MR_SUCCESS);
9854e61c 108
a99210a5 109 sqlerr:
110 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
111 critical_alert("DCM", "Passwd build encountered INGRES ERROR %d",
112 sqlca.sqlcode);
113 exit(MR_INGRES_ERR);
9854e61c 114}
This page took 0.089215 seconds and 5 git commands to generate.