]> andersk Git - moira.git/blame - gen/passwd.pc
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / gen / passwd.pc
CommitLineData
7ac48069 1/* $Id$
67796c83 2 *
3 * This generates a master /etc/passwd containing all active (status != 0)
4 * accounts.
0a5ff702 5 *
7ac48069 6 * Copyright (C) 1988-1998 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>
2ce085d2 12#include <moira.h>
7ac48069 13
5076cbb9 14#include <sys/stat.h>
7ac48069 15#include <sys/types.h>
16
17#include <stdio.h>
18
19#include "util.h"
20
a99210a5 21EXEC SQL INCLUDE sqlca;
67796c83 22
7ac48069 23RCSID("$Header$");
24
9854e61c 25char *whoami = "passwd.gen";
9c04b191 26char *db = "moira/moira";
67796c83 27
5eaef520 28int main(int argc, char **argv)
67796c83 29{
5eaef520 30 FILE *out = stdout;
31 char *outf = NULL, outft[64];
32 struct stat sb;
33 int flag;
34 EXEC SQL BEGIN DECLARE SECTION;
35 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
36 char nickname[17];
37 int uid;
38 EXEC SQL END DECLARE SECTION;
5076cbb9 39
5eaef520 40 EXEC SQL CONNECT :db;
67796c83 41
5eaef520 42 if (argc == 2)
43 {
44 if (stat(argv[1], &sb) == 0)
45 {
46 if (ModDiff (&flag, "users", sb.st_mtime))
47 exit(MR_DATE);
48 if (flag < 0)
49 {
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
51 argv[1]);
52 exit(MR_NO_CHANGE);
5076cbb9 53 }
54 }
5eaef520 55 outf = argv[1];
56 sprintf(outft, "%s~", outf);
57 if (!(out = fopen(outft, "w")))
58 {
59 fprintf(stderr, "unable to open %s for output\n", outf);
60 exit(MR_OCONFIG);
67796c83 61 }
67796c83 62 }
5eaef520 63 else if (argc != 1)
64 {
65 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
66 exit(MR_ARGS);
67 }
68 else
69 outf = NULL;
67796c83 70
5eaef520 71 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
a99210a5 72
5eaef520 73 EXEC SQL DECLARE x CURSOR FOR SELECT
74 login, unix_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 {
80 EXEC SQL FETCH x INTO :login, :uid, :shell, :fullname, :oa, :nickname,
a99210a5 81 :op, :hp;
5eaef520 82 if (sqlca.sqlcode)
83 break;
84 strtrim(login);
85 strtrim(fullname);
86 strtrim(nickname);
87 strtrim(oa);
88 strtrim(op);
89 strtrim(hp);
90 strtrim(shell);
91 fprintf(out, "%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\n",
92 login, uid, fullname, nickname, oa, op, hp, login, shell);
67796c83 93 }
94
5eaef520 95 EXEC SQL CLOSE x;
9c04b191 96
5eaef520 97 EXEC SQL COMMIT;
67796c83 98
5eaef520 99 if (fclose(out))
100 {
101 perror("close failed");
102 exit(MR_CCONFIG);
67796c83 103 }
5eaef520 104 if (outf)
105 fix_file(outf);
106 exit(MR_SUCCESS);
9854e61c 107
5eaef520 108sqlerr:
109 db_error(sqlca.sqlcode);
110 exit(MR_DBMS_ERR);
9854e61c 111}
This page took 0.109501 seconds and 5 git commands to generate.