]>
Commit | Line | Data |
---|---|---|
62b40972 | 1 | /* $Header$ |
2 | * | |
62b40972 | 3 | * |
f00f36ed | 4 | * (c) Copyright 1989 by the Massachusetts Institute of Technology. |
62b40972 | 5 | * For copying and distribution information, please see the file |
6 | * <mit-copyright.h>. | |
7 | */ | |
8 | ||
9 | #include <mit-copyright.h> | |
10 | #include <stdio.h> | |
11 | #include <sys/file.h> | |
8ec23c21 | 12 | |
62b40972 | 13 | #include <rx/xdr.h> |
8ec23c21 | 14 | #include "ptint.h" |
15 | #include "ptserver.h" | |
16 | #include "pterror.h" | |
17 | ||
f00f36ed | 18 | #include <moira.h> |
19 | #include <moira_site.h> | |
62b40972 | 20 | #include <ctype.h> |
21 | ||
62b40972 | 22 | #define min(x,y) ((x) < (y) ? (x) : (y)) |
62b40972 | 23 | char *whoami = "sync"; |
24 | ||
25 | char *malloc(), *strsave(); | |
26 | int dbase_fd; | |
27 | ||
67919620 | 28 | struct hash *users; |
29 | struct hash *groups; | |
62b40972 | 30 | |
31 | main(argc, argv) | |
32 | int argc; | |
33 | char **argv; | |
34 | { | |
67919620 | 35 | ## char db[9]; |
36 | ||
278dd826 | 37 | int status; |
62b40972 | 38 | int ingerr(); |
39 | ||
67919620 | 40 | if (!strcmp(argv[1], "-db")) { |
41 | strncpy(db, argv[2], sizeof(db)-1); | |
42 | argc -= 2; | |
43 | argv += 2; | |
44 | } | |
62b40972 | 45 | if (argc != 2) { |
67919620 | 46 | fprintf(stderr, "usage: %s [-db sms] outfile\n", whoami); |
f00f36ed | 47 | exit(MR_ARGS); |
62b40972 | 48 | } |
49 | ||
67919620 | 50 | dbase_fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0660); |
62b40972 | 51 | if (dbase_fd < 0) { |
52 | perror("opening file %s", argv[1]); | |
53 | exit(1); | |
54 | } | |
55 | IIseterr(ingerr); | |
67919620 | 56 | |
da6101af | 57 | initialize_sms_error_table(); |
58 | initialize_pt_error_table(); | |
67919620 | 59 | Initdb(); /* Initialize prdb */ |
60 | ||
67919620 | 61 | users = create_hash(10000); |
62 | groups = create_hash(15000); | |
63 | ||
64 | ## ingres db | |
62b40972 | 65 | ## set lockmode session where level = table |
66 | ## begin transaction | |
67 | ||
68 | do_passwd(); | |
69 | do_groups(); | |
70 | ||
71 | ## end transaction | |
72 | ## exit | |
73 | ||
f00f36ed | 74 | exit(MR_SUCCESS); |
62b40972 | 75 | } |
76 | ||
77 | ||
62b40972 | 78 | do_passwd() |
79 | ##{ | |
80 | ## char login[9]; | |
81 | ## int uid, id, status; | |
67919620 | 82 | int t; |
83 | struct prentry tentry; | |
62b40972 | 84 | |
67919620 | 85 | t = time(0); |
86 | fprintf(stderr, "Doing users: %s", ctime(&t)); | |
87 | ||
62b40972 | 88 | ## range of u is users |
89 | ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id) | |
da6101af | 90 | ## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) { |
67919620 | 91 | lowercase(strtrim(login)); |
92 | ||
93 | if (FindByID(0,uid)) | |
da6101af | 94 | status = PRIDEXIST; |
95 | else | |
67919620 | 96 | status = CreateEntry(0,login,&uid,1/*idflag*/,0/*gflag*/, |
da6101af | 97 | SYSADMINID/*oid*/, SYSADMINID/*cid*/); |
98 | if (status) | |
99 | fprintf(stderr, "Error adding user %s uid %d: %s\n", | |
100 | login, uid, error_message(status)); | |
67919620 | 101 | else |
102 | hash_store(users, id, uid); | |
62b40972 | 103 | ## } |
104 | ##} | |
105 | ||
106 | ||
107 | ||
108 | do_groups() | |
109 | ##{ | |
da6101af | 110 | long u, g, status, gpos, upos; |
111 | struct prentry gentry, uentry; | |
67919620 | 112 | char namebuf[41]; |
113 | int aid, t; | |
114 | ## char name[33]; | |
8ec23c21 | 115 | ## int gid, id, lid, hide; |
62b40972 | 116 | |
67919620 | 117 | t = time(0); |
118 | fprintf(stderr, "Doing groups: %s", ctime(&t)); | |
62b40972 | 119 | |
62b40972 | 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 | |
125 | ||
8ec23c21 | 126 | ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden) |
da6101af | 127 | ## where l.group != 0 and l.active != 0 and l.#gid > 0 { |
67919620 | 128 | lowercase(strtrim(name)); |
62b40972 | 129 | sprintf(namebuf, "system:%s", name); |
da6101af | 130 | aid = -gid; |
67919620 | 131 | |
132 | if (FindByID(0, aid)) | |
da6101af | 133 | status = PRIDEXIST; |
134 | else | |
135 | status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/, | |
136 | SYSADMINID/*oid*/, SYSADMINID/*cid*/); | |
62b40972 | 137 | if (status) |
da6101af | 138 | fprintf(stderr, "Error adding group %s id %d: %s\n", |
139 | namebuf, aid, error_message(status)); | |
67919620 | 140 | else |
141 | hash_store(groups, lid, aid); | |
da6101af | 142 | |
725411bc | 143 | /* Set modes on hidden lists (S----) */ |
da6101af | 144 | if (hide && (status==0 || status==PRIDEXIST)) { |
fb82aa2c | 145 | gpos = FindByID(0, aid); |
725411bc | 146 | status = pr_Read(0, 0, gpos, &gentry, sizeof(gentry)); |
da6101af | 147 | if (!status) { |
725411bc | 148 | gentry.flags = htonl(PRGRP|PRACCESS|PRP_STATUS_ANY); |
149 | status = pr_Write(0, 0, gpos, &gentry, sizeof(gentry)); | |
da6101af | 150 | } |
8ec23c21 | 151 | if (status) |
67919620 | 152 | fprintf(stderr, |
153 | "Error setting flags on group %s: %s\n", | |
da6101af | 154 | namebuf, error_message(status)); |
8ec23c21 | 155 | } |
62b40972 | 156 | ## } |
157 | ||
67919620 | 158 | t = time(0); |
159 | fprintf(stderr, "Doing members: %s", ctime(&t)); | |
62b40972 | 160 | |
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))) { | |
da6101af | 165 | if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) { |
166 | status = PRPERM; | |
fb82aa2c | 167 | } else if ((gpos = FindByID(0,g)) && (upos = FindByID(0,u))) { |
da6101af | 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); | |
172 | } else { | |
173 | status = PRNOENT; | |
62b40972 | 174 | } |
da6101af | 175 | if (status) |
176 | fprintf(stderr, "Error adding uid %d to group %d: %s\n", | |
177 | u, -g, error_message(status)); | |
62b40972 | 178 | } |
179 | ## } | |
180 | ||
67919620 | 181 | t = time(0); |
182 | fprintf(stderr, "Done: %s", ctime(&t)); | |
183 | ||
62b40972 | 184 | ##} |
185 | ||
67919620 | 186 | |
67919620 | 187 | /* |
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. | |
191 | */ | |
192 | #define INGRES_DEADLOCK 4700 | |
193 | ||
194 | static int ingerr(num) | |
195 | int *num; | |
196 | { | |
197 | char buf[256]; | |
198 | int ingres_errno; | |
199 | ||
200 | switch (*num) { | |
201 | case INGRES_DEADLOCK: | |
202 | ingres_errno = MR_DEADLOCK; | |
203 | break; | |
204 | default: | |
205 | ingres_errno = MR_INGRES_ERR; | |
206 | } | |
207 | com_err(whoami, MR_INGRES_ERR, " code %d\n", *num); | |
208 | exit(ingres_errno); | |
209 | } |