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();
40 if (!strcmp(argv[1], "-db")) {
41 strncpy(db, argv[2], sizeof(db)-1);
46 fprintf(stderr, "usage: %s [-db sms] outfile\n", whoami);
50 dbase_fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0660);
52 perror("opening file %s", argv[1]);
57 initialize_sms_error_table();
58 initialize_pt_error_table();
59 Initdb(); /* Initialize prdb */
61 users = create_hash(10000);
62 groups = create_hash(15000);
65 ## set lockmode session where level = table
81 ## int uid, id, status;
83 struct prentry tentry;
86 fprintf(stderr, "Doing users: %s", ctime(&t));
88 ## range of u is users
89 ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id)
90 ## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) {
91 lowercase(strtrim(login));
96 status = CreateEntry(0,login,&uid,1/*idflag*/,0/*gflag*/,
97 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
99 fprintf(stderr, "Error adding user %s uid %d: %s\n",
100 login, uid, error_message(status));
102 hash_store(users, id, uid);
110 long u, g, status, gpos, upos;
111 struct prentry gentry, uentry;
115 ## int gid, id, lid, hide;
118 fprintf(stderr, "Doing groups: %s", ctime(&t));
120 ## range of l is list
121 ## range of m is imembers
122 /* get lock records */
123 ## retrieve (name = l.modtime) where l.list_id = 0
124 ## retrieve (name = users.modtime) where users.users_id = 0
126 ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden)
127 ## where l.group != 0 and l.active != 0 and l.#gid > 0 {
128 lowercase(strtrim(name));
129 sprintf(namebuf, "system:%s", name);
132 if (FindByID(0, aid))
135 status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/,
136 SYSADMINID/*oid*/, SYSADMINID/*cid*/);
138 fprintf(stderr, "Error adding group %s id %d: %s\n",
139 namebuf, aid, error_message(status));
141 hash_store(groups, lid, aid);
143 /* If this list is hidden, set the pts entry to be s---- */
144 if (hide && (status==0 || status==PRIDEXIST)) {
145 gpos = FindByID(0, aid);
146 status = pr_ReadEntry(0, 0, gpos, &gentry);
148 gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY;
149 status = pr_WriteEntry(0, 0, gpos, &gentry);
153 "Error setting flags on group %s: %s\n",
154 namebuf, error_message(status));
159 fprintf(stderr, "Doing members: %s", ctime(&t));
161 ## retrieve (lid = m.list_id, id = m.member_id)
162 ## where m.member_type = "USER" {
163 if ((u = (long) hash_lookup(users, id)) &&
164 (g = (long) hash_lookup(groups, lid))) {
165 if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) {
167 } else if ((gpos = FindByID(0,g)) && (upos = FindByID(0,u))) {
168 status = pr_ReadEntry(0,0,upos,&uentry);
169 if (!status) status = pr_ReadEntry(0,0,gpos,&gentry);
170 if (!status) status = AddToEntry (0, &gentry, gpos, u);
171 if (!status) status = AddToEntry (0, &uentry, upos, g);
176 fprintf(stderr, "Error adding uid %d to group %d: %s\n",
177 u, -g, error_message(status));
182 fprintf(stderr, "Done: %s", ctime(&t));
188 * ingerr: (supposedly) called when Ingres indicates an error.
189 * I have not yet been able to get this to work to intercept a
190 * database open error.
192 #define INGRES_DEADLOCK 4700
194 static int ingerr(num)
201 case INGRES_DEADLOCK:
202 ingres_errno = MR_DEADLOCK;
205 ingres_errno = MR_INGRES_ERR;
207 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);