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>
17 #include <moira_site.h>
22 #define min(x,y) ((x) < (y) ? (x) : (y))
23 struct hash *users = NULL;
24 char *whoami = "sync";
26 char *malloc(), *strsave();
38 fprintf(stderr, "usage: %s outfile\n", argv[0]);
42 dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660);
44 perror("opening file %s", argv[1]);
48 initialize_sms_error_table ();
51 ## set lockmode session where level = table
55 status = PR_AddToGroup(NULL, USERSMS, SYSADMINID);
57 prserror(status, "adding MR to system:administrators", 0, 0);
69 * ingerr: (supposedly) called when Ingres indicates an error.
70 * I have not yet been able to get this to work to intercept a
71 * database open error.
73 #define INGRES_DEADLOCK 4700
75 static int ingerr(num)
83 ingres_errno = MR_DEADLOCK;
86 ingres_errno = MR_INGRES_ERR;
88 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
93 prserror(status, msg, arg1, arg2)
96 unsigned long arg1, arg2;
100 sprintf(buf, msg, arg1, arg2);
103 msg = "name already exists";
106 msg = "ID already exists";
109 msg = "no IDs available";
112 msg = "database failed";
115 msg = "no space left in database";
118 msg = "permission denied";
133 msg = "unknown code";
136 fprintf(stderr, "%s (%d): %s\n", msg, status, buf);
144 ## int uid, id, status;
146 fprintf(stderr, "Doing users\n");
147 users = create_hash(10000);
148 ## range of u is users
149 ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
150 ## where u.#status = 1 {
152 hash_store(users, id, uid);
153 status = PR_INewEntry(NULL, login, uid, 0);
155 prserror(status, "adding user %s uid %d", login, uid);
166 ## char name[33], namebuf[128];
169 fprintf(stderr, "Doing groups\n");
171 /* make space for group list */
172 groups = create_hash(15000);
174 /* retrieve simple groups */
175 ## range of l is list
176 ## range of m is imembers
177 /* get lock records */
178 ## retrieve (name = l.modtime) where l.list_id = 0
179 ## retrieve (name = users.modtime) where users.users_id = 0
181 ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
182 ## where l.group != 0 and l.active != 0 {
184 sprintf(namebuf, "system:%s", name);
185 hash_store(groups, lid, -gid);
186 status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID);
188 prserror(status, "adding list %s gid %d", namebuf, -gid);
192 fprintf(stderr, "Doing members\n");
194 ## retrieve (lid = m.list_id, id = m.member_id)
195 ## where m.member_type = "USER" {
196 if ((u = (long) hash_lookup(users, id)) &&
197 (g = (long) hash_lookup(groups, lid))) {
198 status = PR_AddToGroup(NULL, u, g);
200 prserror(status, "adding %d to group %d", u, -g);