]>
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> | |
12 | #include <rx/xdr.h> | |
13 | #include "print.h" | |
14 | #include "prserver.h" | |
15 | #include "prerror.h" | |
f00f36ed | 16 | #include <moira.h> |
17 | #include <moira_site.h> | |
62b40972 | 18 | #include <ctype.h> |
19 | ||
278dd826 | 20 | #define USERSMS 14487 |
62b40972 | 21 | |
22 | #define min(x,y) ((x) < (y) ? (x) : (y)) | |
23 | struct hash *users = NULL; | |
24 | char *whoami = "sync"; | |
25 | ||
26 | char *malloc(), *strsave(); | |
27 | int dbase_fd; | |
28 | ||
29 | ||
30 | main(argc, argv) | |
31 | int argc; | |
32 | char **argv; | |
33 | { | |
278dd826 | 34 | int status; |
62b40972 | 35 | int ingerr(); |
36 | ||
37 | if (argc != 2) { | |
38 | fprintf(stderr, "usage: %s outfile\n", argv[0]); | |
f00f36ed | 39 | exit(MR_ARGS); |
62b40972 | 40 | } |
41 | ||
42 | dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660); | |
43 | if (dbase_fd < 0) { | |
44 | perror("opening file %s", argv[1]); | |
45 | exit(1); | |
46 | } | |
47 | IIseterr(ingerr); | |
48 | initialize_sms_error_table (); | |
49 | ||
50 | ## ingres sms | |
51 | ## set lockmode session where level = table | |
52 | ## begin transaction | |
53 | ||
54 | do_passwd(); | |
278dd826 | 55 | status = PR_AddToGroup(NULL, USERSMS, SYSADMINID); |
56 | if (status) { | |
f00f36ed | 57 | prserror(status, "adding MR to system:administrators", 0, 0); |
278dd826 | 58 | } |
62b40972 | 59 | do_groups(); |
60 | ||
61 | ## end transaction | |
62 | ## exit | |
63 | ||
f00f36ed | 64 | exit(MR_SUCCESS); |
62b40972 | 65 | } |
66 | ||
67 | ||
68 | /* | |
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. | |
72 | */ | |
73 | #define INGRES_DEADLOCK 4700 | |
74 | ||
75 | static int ingerr(num) | |
76 | int *num; | |
77 | { | |
78 | char buf[256]; | |
79 | int ingres_errno; | |
80 | ||
81 | switch (*num) { | |
82 | case INGRES_DEADLOCK: | |
f00f36ed | 83 | ingres_errno = MR_DEADLOCK; |
62b40972 | 84 | break; |
85 | default: | |
f00f36ed | 86 | ingres_errno = MR_INGRES_ERR; |
62b40972 | 87 | } |
f00f36ed | 88 | com_err(whoami, MR_INGRES_ERR, " code %d\n", *num); |
62b40972 | 89 | exit(ingres_errno); |
90 | } | |
91 | ||
92 | ||
93 | prserror(status, msg, arg1, arg2) | |
94 | int status; | |
95 | char *msg; | |
96 | unsigned long arg1, arg2; | |
97 | { | |
98 | char buf[512]; | |
99 | ||
100 | sprintf(buf, msg, arg1, arg2); | |
101 | switch (status) { | |
102 | case PREXIST: | |
103 | msg = "name already exists"; | |
104 | break; | |
105 | case PRIDEXIST: | |
106 | msg = "ID already exists"; | |
107 | break; | |
108 | case PRNOIDS: | |
109 | msg = "no IDs available"; | |
110 | break; | |
111 | case PRDBFAIL: | |
112 | msg = "database failed"; | |
113 | break; | |
114 | case PRNOENT: | |
115 | msg = "no space left in database"; | |
116 | break; | |
117 | case PRPERM: | |
118 | msg = "permission denied"; | |
119 | break; | |
120 | case PRNOTGROUP: | |
121 | msg = "not a group"; | |
122 | break; | |
123 | case PRNOTUSER: | |
124 | msg = "not a user"; | |
125 | break; | |
126 | case PRBADNAM: | |
127 | msg = "bad name"; | |
128 | break; | |
129 | case 0: | |
130 | msg = "no error"; | |
131 | break; | |
132 | default: | |
133 | msg = "unknown code"; | |
134 | break; | |
135 | } | |
136 | fprintf(stderr, "%s (%d): %s\n", msg, status, buf); | |
137 | } | |
138 | ||
139 | ||
140 | ||
141 | do_passwd() | |
142 | ##{ | |
143 | ## char login[9]; | |
144 | ## int uid, id, status; | |
145 | ||
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 { | |
151 | strtrim(login); | |
152 | hash_store(users, id, uid); | |
153 | status = PR_INewEntry(NULL, login, uid, 0); | |
154 | if (status) { | |
155 | prserror(status, "adding user %s uid %d", login, uid); | |
156 | } | |
157 | ## } | |
158 | ##} | |
159 | ||
160 | ||
161 | ||
162 | do_groups() | |
163 | ##{ | |
164 | struct hash *groups; | |
165 | long u, g, status; | |
166 | ## char name[33], namebuf[128]; | |
167 | ## int gid, id, lid; | |
168 | ||
169 | fprintf(stderr, "Doing groups\n"); | |
170 | ||
171 | /* make space for group list */ | |
172 | groups = create_hash(15000); | |
173 | ||
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 | |
180 | ||
181 | ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) | |
182 | ## where l.group != 0 and l.active != 0 { | |
183 | strtrim(name); | |
184 | sprintf(namebuf, "system:%s", name); | |
185 | hash_store(groups, lid, -gid); | |
186 | status = PR_INewEntry(NULL, namebuf, -gid, SYSADMINID); | |
187 | if (status) | |
188 | prserror(status, "adding list %s gid %d", namebuf, -gid); | |
189 | ## } | |
190 | ||
191 | ||
192 | fprintf(stderr, "Doing members\n"); | |
193 | ||
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); | |
199 | if (status) { | |
200 | prserror(status, "adding %d to group %d", u, -g); | |
201 | } | |
202 | } | |
203 | ## } | |
204 | ||
205 | ##} | |
206 |