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 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();
49 initialize_pt_error_table();
53 ## set lockmode session where level = table
67 * ingerr: (supposedly) called when Ingres indicates an error.
68 * I have not yet been able to get this to work to intercept a
69 * database open error.
71 #define INGRES_DEADLOCK 4700
73 static int ingerr(num)
81 ingres_errno = MR_DEADLOCK;
84 ingres_errno = MR_INGRES_ERR;
86 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
95 ## int uid, id, status;
97 fprintf(stderr, "Doing users\n");
98 users = create_hash(10000);
99 ## range of u is users
100 ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
101 ## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) {
103 hash_store(users, id, uid);
104 if (FindByID (0, uid))
107 status = CreateEntry(0, login, &uid, 1/*idflag*/, 0/*gflag*/,
108 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
110 fprintf(stderr, "Error adding user %s uid %d: %s\n",
111 login, uid, error_message(status));
120 long u, g, status, gpos, upos;
121 struct prentry gentry, uentry;
122 ## char name[33], namebuf[128];
123 ## int gid, id, lid, hide;
126 fprintf(stderr, "Doing groups\n");
128 /* make space for group list */
129 groups = create_hash(15000);
131 /* retrieve simple groups */
132 ## range of l is list
133 ## range of m is imembers
134 /* get lock records */
135 ## retrieve (name = l.modtime) where l.list_id = 0
136 ## retrieve (name = users.modtime) where users.users_id = 0
138 ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
139 ## where l.group != 0 and l.active != 0 and l.#gid > 0 {
141 sprintf(namebuf, "system:%s", name);
142 hash_store(groups, lid, -gid);
144 if (gpos = FindByID (0, aid))
147 status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/,
148 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
150 fprintf(stderr, "Error adding group %s id %d: %s\n",
151 namebuf, aid, error_message(status));
153 /* If this list is hidden, set the pts entry to be s---- */
154 if (hide && (status==0 || status==PRIDEXIST)) {
156 gpos = FindByID(0, aid);
157 status = pr_ReadEntry(0, 0, gpos, &gentry);
159 gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
160 status = pr_WriteEntry(0, 0, gpos, &gentry);
163 fprintf(stderr, "Error setting flags on group %s: %s\n",
164 namebuf, error_message(status));
169 fprintf(stderr, "Doing members\n");
171 ## retrieve (lid = m.list_id, id = m.member_id)
172 ## where m.member_type = "USER" {
173 if ((u = (long) hash_lookup(users, id)) &&
174 (g = (long) hash_lookup(groups, lid))) {
175 if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) {
177 } else if ((gpos = FindByID(0, g)) && (upos = FindByID(0, u))) {
178 status = pr_ReadEntry(0,0,upos,&uentry);
179 if (!status) status = pr_ReadEntry(0,0,gpos,&gentry);
180 if (!status) status = AddToEntry (0, &gentry, gpos, u);
181 if (!status) status = AddToEntry (0, &uentry, upos, g);
186 fprintf(stderr, "Error adding uid %d to group %d: %s\n",
187 u, -g, error_message(status));