]> andersk Git - moira.git/blame - afssync/sync.qc
Initial revision
[moira.git] / afssync / sync.qc
CommitLineData
62b40972 1/* $Header$
2 *
3 * This generates the zone files necessary to load a hesiod server.
4 * The following zones are generated: passwd, uid, pobox, group,
5 * grplist, gid, filsys, cluster, pcap, sloc, service.
6 *
7 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
10 */
11
12#include <mit-copyright.h>
13#include <stdio.h>
14#include <sys/file.h>
15#include <rx/xdr.h>
16#include "print.h"
17#include "prserver.h"
18#include "prerror.h"
19#include <sms.h>
20#include <sms_app.h>
21#include <ctype.h>
22
23
24#define min(x,y) ((x) < (y) ? (x) : (y))
25struct hash *users = NULL;
26char *whoami = "sync";
27
28char *malloc(), *strsave();
29int dbase_fd;
30
31
32main(argc, argv)
33int argc;
34char **argv;
35{
36 int ingerr();
37
38 if (argc != 2) {
39 fprintf(stderr, "usage: %s outfile\n", argv[0]);
40 exit(SMS_ARGS);
41 }
42
43 dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660);
44 if (dbase_fd < 0) {
45 perror("opening file %s", argv[1]);
46 exit(1);
47 }
48 IIseterr(ingerr);
49 initialize_sms_error_table ();
50
51## ingres sms
52## set lockmode session where level = table
53## begin transaction
54
55 do_passwd();
56 do_groups();
57
58## end transaction
59## exit
60
61 exit(SMS_SUCCESS);
62}
63
64
65/*
66 * ingerr: (supposedly) called when Ingres indicates an error.
67 * I have not yet been able to get this to work to intercept a
68 * database open error.
69 */
70#define INGRES_DEADLOCK 4700
71
72static int ingerr(num)
73 int *num;
74{
75 char buf[256];
76 int ingres_errno;
77
78 switch (*num) {
79 case INGRES_DEADLOCK:
80 ingres_errno = SMS_DEADLOCK;
81 break;
82 default:
83 ingres_errno = SMS_INGRES_ERR;
84 }
85 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
86 exit(ingres_errno);
87}
88
89
90prserror(status, msg, arg1, arg2)
91int status;
92char *msg;
93unsigned long arg1, arg2;
94{
95 char buf[512];
96
97 sprintf(buf, msg, arg1, arg2);
98 switch (status) {
99 case PREXIST:
100 msg = "name already exists";
101 break;
102 case PRIDEXIST:
103 msg = "ID already exists";
104 break;
105 case PRNOIDS:
106 msg = "no IDs available";
107 break;
108 case PRDBFAIL:
109 msg = "database failed";
110 break;
111 case PRNOENT:
112 msg = "no space left in database";
113 break;
114 case PRPERM:
115 msg = "permission denied";
116 break;
117 case PRNOTGROUP:
118 msg = "not a group";
119 break;
120 case PRNOTUSER:
121 msg = "not a user";
122 break;
123 case PRBADNAM:
124 msg = "bad name";
125 break;
126 case 0:
127 msg = "no error";
128 break;
129 default:
130 msg = "unknown code";
131 break;
132 }
133 fprintf(stderr, "%s (%d): %s\n", msg, status, buf);
134}
135
136
137
138do_passwd()
139##{
140## char login[9];
141## int uid, id, status;
142
143 fprintf(stderr, "Doing users\n");
144 users = create_hash(10000);
145## range of u is users
146## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
147## where u.#status = 1 {
148 strtrim(login);
149 hash_store(users, id, uid);
150 status = PR_INewEntry(NULL, login, uid, 0);
151 if (status) {
152 prserror(status, "adding user %s uid %d", login, uid);
153 }
154## }
155##}
156
157
158
159do_groups()
160##{
161 struct hash *groups;
162 long u, g, status;
163## char name[33], namebuf[128];
164## int gid, id, lid;
165
166 fprintf(stderr, "Doing groups\n");
167
168 /* make space for group list */
169 groups = create_hash(15000);
170
171 /* retrieve simple groups */
172## range of l is list
173## range of m is imembers
174 /* get lock records */
175## retrieve (name = l.modtime) where l.list_id = 0
176## retrieve (name = users.modtime) where users.users_id = 0
177
178## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
179## where l.group != 0 and l.active != 0 {
180 strtrim(name);
181 sprintf(namebuf, "system:%s", name);
182 hash_store(groups, lid, -gid);
183 status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID);
184 if (status)
185 prserror(status, "adding list %s gid %d", namebuf, -gid);
186## }
187
188
189 fprintf(stderr, "Doing members\n");
190
191## retrieve (lid = m.list_id, id = m.member_id)
192## where m.member_type = "USER" {
193 if ((u = (long) hash_lookup(users, id)) &&
194 (g = (long) hash_lookup(groups, lid))) {
195 status = PR_AddToGroup(NULL, u, g);
196 if (status) {
197 prserror(status, "adding %d to group %d", u, -g);
198 }
199 }
200## }
201
202##}
203
This page took 0.071325 seconds and 5 git commands to generate.