4 * (c) Copyright 1989 by the Massachusetts Institute of Technology.
5 * For copying and distribution information, please see the file
9 #include <mit-copyright.h>
19 #include <moira_site.h>
22 #define min(x,y) ((x) < (y) ? (x) : (y))
23 char *whoami = "sync";
25 char *malloc(), *strsave();
43 struct member *members;
58 if (!strcmp(argv[1], "-db")) {
59 strncpy(db, argv[2], sizeof(db)-1);
64 fprintf(stderr, "usage: %s [-db sms] outfile\n", whoami);
68 dbase_fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0660);
70 perror("opening file %s", argv[1]);
75 initialize_sms_error_table();
76 initialize_pt_error_table();
77 Initdb(); /* Initialize prdb */
79 users = create_hash(10000);
80 groups = create_hash(15000);
83 ## set lockmode session where level = table
90 fprintf(stderr, "Done (%d users, %d groups, %d members): %s",
91 ucount, gcount, mcount, ctime(&t));
103 ## int uid, id, status;
105 struct prentry tentry;
109 fprintf(stderr, "Doing users: %s", ctime(&t));
111 ## range of u is users
112 ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
113 ## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) {
114 lowercase(strtrim(login));
119 status = CreateEntry(0,login,&uid,1/*idflag*/,0/*gflag*/,
120 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
122 fprintf(stderr, "Error adding user %s uid %d: %s\n",
123 login, uid, error_message(status));
125 u = (struct entry *)malloc(sizeof(struct entry));
128 hash_store(users, id, u);
139 struct prentry gentry, uentry;
142 struct bucket **p, *b;
146 ## int gid, id, lid, hide;
149 fprintf(stderr, "Doing groups: %s", ctime(&t));
151 ## range of l is list
152 ## range of m is imembers
153 /* get lock records */
154 ## retrieve (name = l.modtime) where l.list_id = 0
155 ## retrieve (name = users.modtime) where users.users_id = 0
157 ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
158 ## where l.group != 0 and l.active != 0 and l.#gid > 0 {
159 lowercase(strtrim(name));
160 sprintf(namebuf, "system:%s", name);
163 if (FindByID(0, aid))
166 status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/,
167 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
169 fprintf(stderr, "Error adding group %s id %d: %s\n",
170 namebuf, aid, error_message(status));
172 if ((status==0 || status==PRIDEXIST) &&
173 (aid!=ANYUSERID && aid!=AUTHUSERID)) {
175 g = (struct entry *)malloc(sizeof(struct entry));
178 hash_store(groups, lid, g);
181 /* Set modes on hidden lists (S----) */
183 pos = FindByID(0, aid);
184 status = pr_Read(0, 0, pos, &gentry, sizeof(gentry));
186 gentry.flags = htonl(PRGRP|PRACCESS|PRP_STATUS_ANY);
187 status = pr_Write(0, 0, pos, &gentry, sizeof(gentry));
191 "Error setting flags on group %s: %s\n",
192 namebuf, error_message(status));
198 fprintf(stderr, "Doing members: %s", ctime(&t));
200 ## retrieve (lid = m.list_id, id = m.member_id)
201 ## where m.member_type = "USER" {
202 if ((u = (struct entry *)hash_lookup(users, id)) &&
203 (g = (struct entry *)hash_lookup(groups, lid))) {
204 m = (struct member *)malloc(sizeof(struct member));
207 m->unext = u->members;
208 m->gnext = g->members;
209 u->members = g->members = m;
214 /* Do the bulk of the membership quickly.
215 * Add PRSIZE members into the user/group record. After that, we
216 * require the use of continuation records, but we assume this is
217 * few enough that we do this the slow way (AddToEntry).
219 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
220 for (b = *p; b; b = b->next) {
221 if ((u = (struct entry *)b->data)->members == 0)
223 pos = FindByID(0, u->id);
224 pr_Read(0, 0, pos, &uentry, sizeof(uentry));
225 for (t=0, m=u->members; m && t<PRSIZE; m=m->unext, t++)
226 uentry.entries[t] = htonl(m->group->id);
227 uentry.count = htonl(t);
228 pr_Write(0, 0, pos, &uentry, sizeof(uentry));
230 pr_ReadEntry(0, 0, pos, &uentry);
232 AddToEntry(0, &uentry, pos, m->group->id);
238 for (p = &(groups->data[groups->size - 1]); p >= groups->data; p--) {
239 for (b = *p; b; b = b->next) {
240 if ((g = (struct entry *)b->data)->members == 0)
242 pos = FindByID(0, g->id);
243 pr_Read(0, 0, pos, &gentry, sizeof(gentry));
244 for (t=0, m=g->members; m && t<PRSIZE; m=m->gnext, t++)
245 gentry.entries[t] = htonl(m->user->id);
246 gentry.count = htonl(t);
247 pr_Write(0, 0, pos, &gentry, sizeof(gentry));
249 pr_ReadEntry(0, 0, pos, &gentry);
251 AddToEntry(0, &gentry, pos, m->user->id);
263 struct prentry gentry, uentry;
266 struct bucket **p, *b;
270 ## int gid, id, lid, hide;
273 fprintf(stderr, "Doing kerberos members: %s", ctime(&t));
275 ## range of s is strings
276 ## range of m is imembers
277 /* get lock records */
278 ## retrieve (name = list.modtime) where list.list_id = 0
279 ## retrieve (name = s.modtime) where s.string_id = 0
281 ## retrieve (lid = m.list_id, id = m.member_id)
282 ## where m.member_type = "KERBEROS" {
293 * ingerr: (supposedly) called when Ingres indicates an error.
294 * I have not yet been able to get this to work to intercept a
295 * database open error.
297 #define INGRES_DEADLOCK 4700
299 static int ingerr(num)
306 case INGRES_DEADLOCK:
307 ingres_errno = MR_DEADLOCK;
310 ingres_errno = MR_INGRES_ERR;
312 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);