]>
Commit | Line | Data |
---|---|---|
fb8809f4 | 1 | /* $Header$ |
2 | * | |
3 | * Do AFS incremental updates | |
4 | * | |
60c22e5f | 5 | * Copyright (C) 1989,1992 by the Massachusetts Institute of Technology |
fb8809f4 | 6 | * for copying and distribution information, please see the file |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
16838ad1 | 10 | #include <stdio.h> |
60c22e5f | 11 | #include <sys/types.h> |
12 | #include <sys/file.h> | |
13 | #include <strings.h> | |
14 | ||
d1be2e3a | 15 | #include <krb.h> |
2ce085d2 | 16 | #include <moira.h> |
17 | #include <moira_site.h> | |
f633445d | 18 | |
60c22e5f | 19 | #include <afs/param.h> |
20 | #include <afs/cellconfig.h> | |
21 | #include <afs/venus.h> | |
22 | #include <afs/ptclient.h> | |
23 | #include <afs/pterror.h> | |
fb8809f4 | 24 | |
d1be2e3a | 25 | #define STOP_FILE "/moira/afs/noafs" |
60c22e5f | 26 | #define file_exists(file) (access((file), F_OK) == 0) |
fb8809f4 | 27 | |
16838ad1 | 28 | #if defined(vax) && !defined(__STDC__) |
29 | #define volatile | |
30 | #endif | |
31 | ||
fb8809f4 | 32 | char *whoami; |
33 | ||
eb63ae5f | 34 | /* Main stub routines */ |
35 | int do_user(); | |
36 | int do_list(); | |
37 | int do_member(); | |
38 | int do_filesys(); | |
39 | int do_quota(); | |
40 | ||
41 | /* Support stub routines */ | |
42 | int run_cmd(); | |
43 | int add_user_lists(); | |
063819ef | 44 | int add_list_members(); |
c69d9f2c | 45 | int check_user(); |
eb63ae5f | 46 | int edit_group(); |
47 | int pr_try(); | |
48 | int check_afs(); | |
49 | ||
50 | /* libprot.a routines */ | |
51 | extern long pr_Initialize(); | |
52 | extern long pr_CreateUser(); | |
53 | extern long pr_CreateGroup(); | |
54 | extern long pr_DeleteByID(); | |
55 | extern long pr_ChangeEntry(); | |
56 | extern long pr_SetFieldsEntry(); | |
57 | extern long pr_AddToGroup(); | |
58 | extern long pr_RemoveUserFromGroup(); | |
59 | ||
60 | static char tbl_buf[1024]; | |
2cb1f02c | 61 | static struct member { |
62 | int op; | |
63 | char list[33]; | |
64 | char type[9]; | |
65 | char member[129]; | |
66 | struct member *next; | |
67 | } *member_head = 0; | |
68 | ||
69 | static int mr_connections=0; | |
eb63ae5f | 70 | |
fb8809f4 | 71 | main(argc, argv) |
72 | char **argv; | |
73 | int argc; | |
74 | { | |
a7fdf2de | 75 | int beforec, afterc, i; |
fb8809f4 | 76 | char *table, **before, **after; |
77 | ||
a7fdf2de | 78 | for (i = getdtablesize() - 1; i > 2; i--) |
79 | close(i); | |
80 | ||
fb8809f4 | 81 | table = argv[1]; |
82 | beforec = atoi(argv[2]); | |
83 | before = &argv[4]; | |
84 | afterc = atoi(argv[3]); | |
85 | after = &argv[4 + beforec]; | |
48c9cd1f | 86 | whoami = argv[0]; |
f10e3ca2 | 87 | |
eb63ae5f | 88 | setlinebuf(stdout); |
89 | ||
90 | strcpy(tbl_buf, table); | |
91 | strcat(tbl_buf, " ("); | |
810d12a7 | 92 | for (i = 0; i < beforec; i++) { |
93 | if (i > 0) | |
eb63ae5f | 94 | strcat(tbl_buf, ","); |
95 | strcat(tbl_buf, before[i]); | |
810d12a7 | 96 | } |
eb63ae5f | 97 | strcat(tbl_buf, ")->("); |
810d12a7 | 98 | for (i = 0; i < afterc; i++) { |
99 | if (i > 0) | |
eb63ae5f | 100 | strcat(tbl_buf, ","); |
101 | strcat(tbl_buf, after[i]); | |
810d12a7 | 102 | } |
eb63ae5f | 103 | strcat(tbl_buf, ")"); |
d1be2e3a | 104 | #ifdef DEBUG |
eb63ae5f | 105 | printf("%s\n", tbl_buf); |
810d12a7 | 106 | #endif |
107 | ||
fb8809f4 | 108 | initialize_sms_error_table(); |
109 | initialize_krb_error_table(); | |
110 | ||
111 | if (!strcmp(table, "users")) { | |
112 | do_user(before, beforec, after, afterc); | |
113 | } else if (!strcmp(table, "list")) { | |
114 | do_list(before, beforec, after, afterc); | |
115 | } else if (!strcmp(table, "members")) { | |
116 | do_member(before, beforec, after, afterc); | |
117 | } else if (!strcmp(table, "filesys")) { | |
118 | do_filesys(before, beforec, after, afterc); | |
1f377b55 | 119 | } else if (!strcmp(table, "quota")) { |
fb8809f4 | 120 | do_quota(before, beforec, after, afterc); |
121 | } | |
fb8809f4 | 122 | exit(0); |
123 | } | |
124 | ||
125 | ||
fb8809f4 | 126 | do_user(before, beforec, after, afterc) |
127 | char **before; | |
128 | int beforec; | |
129 | char **after; | |
130 | int afterc; | |
131 | { | |
eb63ae5f | 132 | int astate, bstate, auid, buid, code; |
9b273918 | 133 | char *av[2]; |
60c22e5f | 134 | |
135 | auid = buid = astate = bstate = 0; | |
136 | if (afterc > U_STATE) astate = atoi(after[U_STATE]); | |
137 | if (beforec > U_STATE) bstate = atoi(before[U_STATE]); | |
138 | if (afterc > U_UID) auid = atoi(after[U_UID]); | |
139 | if (beforec > U_UID) buid = atoi(before[U_UID]); | |
140 | ||
141 | /* We consider "half-registered" users to be active */ | |
810d12a7 | 142 | if (astate == 2) astate = 1; |
143 | if (bstate == 2) bstate = 1; | |
fb8809f4 | 144 | |
60c22e5f | 145 | if (astate != 1 && bstate != 1) /* inactive user */ |
fb8809f4 | 146 | return; |
60c22e5f | 147 | |
148 | if (astate == bstate && auid == buid && | |
149 | !strcmp(before[U_NAME], after[U_NAME])) | |
150 | /* No AFS related attributes have changed */ | |
fb8809f4 | 151 | return; |
fb8809f4 | 152 | |
60c22e5f | 153 | if (astate == bstate) { |
154 | /* Only a modify has to be done */ | |
eb63ae5f | 155 | code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, ""); |
60c22e5f | 156 | if (code) { |
157 | critical_alert("incremental", | |
158 | "Couldn't change user %s (id %d) to %s (id %d): %s", | |
159 | before[U_NAME], buid, after[U_NAME], auid, | |
160 | error_message(code)); | |
161 | } | |
162 | return; | |
163 | } | |
164 | if (bstate == 1) { | |
eb63ae5f | 165 | code = pr_try(pr_DeleteByID, buid); |
60c22e5f | 166 | if (code && code != PRNOENT) { |
167 | critical_alert("incremental", | |
168 | "Couldn't delete user %s (id %d): %s", | |
169 | before[U_NAME], buid, error_message(code)); | |
170 | } | |
171 | return; | |
172 | } | |
173 | if (astate == 1) { | |
eb63ae5f | 174 | code = pr_try(pr_CreateUser, after[U_NAME], &auid); |
60c22e5f | 175 | if (code) { |
176 | critical_alert("incremental", | |
177 | "Couldn't create user %s (id %d): %s", | |
178 | after[U_NAME], auid, error_message(code)); | |
96786144 | 179 | return; |
60c22e5f | 180 | } |
2dbcb756 | 181 | |
0f82335a | 182 | if (bstate != 0) { |
9b273918 | 183 | /* Reactivating a user; get his group list */ |
14d69e25 | 184 | code = moira_connect(); |
9b273918 | 185 | if (code) { |
186 | critical_alert("incremental", | |
187 | "Error contacting Moira server to retrieve grouplist of user %s: %s", | |
188 | after[U_NAME], error_message(code)); | |
189 | return; | |
190 | } | |
2dbcb756 | 191 | av[0] = "ruser"; |
9b273918 | 192 | av[1] = after[U_NAME]; |
193 | code = mr_query("get_lists_of_member", 2, av, | |
194 | add_user_lists, after[U_NAME]); | |
b80d6d78 | 195 | if (code && code != MR_NO_MATCH) |
9b273918 | 196 | critical_alert("incremental", |
197 | "Couldn't retrieve membership of user %s: %s", | |
198 | after[U_NAME], error_message(code)); | |
14d69e25 | 199 | moira_disconnect(); |
9b273918 | 200 | } |
60c22e5f | 201 | return; |
fb8809f4 | 202 | } |
203 | } | |
204 | ||
205 | ||
fb8809f4 | 206 | do_list(before, beforec, after, afterc) |
207 | char **before; | |
208 | int beforec; | |
209 | char **after; | |
210 | int afterc; | |
211 | { | |
8ec23c21 | 212 | register int agid, bgid; |
eb63ae5f | 213 | int ahide, bhide; |
60c22e5f | 214 | long code, id; |
215 | char g1[PR_MAXNAMELEN], g2[PR_MAXNAMELEN]; | |
ed9a5300 | 216 | char *av[2]; |
fb8809f4 | 217 | |
60c22e5f | 218 | agid = bgid = 0; |
8ec23c21 | 219 | if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP])) { |
60c22e5f | 220 | bgid = atoi(before[L_GID]); |
8ec23c21 | 221 | bhide = atoi(before[L_HIDDEN]); |
222 | } | |
223 | if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP])) { | |
60c22e5f | 224 | agid = atoi(after[L_GID]); |
8ec23c21 | 225 | ahide = atoi(after[L_HIDDEN]); |
226 | } | |
fb8809f4 | 227 | |
60c22e5f | 228 | if (agid == 0 && bgid == 0) /* Not active groups */ |
229 | return; | |
60c22e5f | 230 | |
60c22e5f | 231 | if (agid && bgid) { |
8ec23c21 | 232 | if (strcmp(after[L_NAME], before[L_NAME])) { |
233 | /* Only a modify is required */ | |
234 | strcpy(g1, "system:"); | |
235 | strcpy(g2, "system:"); | |
236 | strcat(g1, before[L_NAME]); | |
237 | strcat(g2, after[L_NAME]); | |
eb63ae5f | 238 | code = pr_try(pr_ChangeEntry, g1, g2, -agid, ""); |
8ec23c21 | 239 | if (code) { |
240 | critical_alert("incremental", | |
241 | "Couldn't change group %s (id %d) to %s (id %d): %s", | |
242 | before[L_NAME], -bgid, after[L_NAME], -agid, | |
243 | error_message(code)); | |
244 | } | |
245 | } | |
246 | if (ahide != bhide) { | |
eb63ae5f | 247 | code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, |
248 | (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT, | |
249 | 0 /*ngroups*/, 0 /*nusers*/); | |
8ec23c21 | 250 | if (code) { |
251 | critical_alert("incremental", | |
252 | "Couldn't set flags of group %s: %s", | |
253 | after[L_NAME], error_message(code)); | |
254 | } | |
60c22e5f | 255 | } |
fb8809f4 | 256 | return; |
257 | } | |
60c22e5f | 258 | if (bgid) { |
eb63ae5f | 259 | code = pr_try(pr_DeleteByID, -bgid); |
60c22e5f | 260 | if (code && code != PRNOENT) { |
261 | critical_alert("incremental", | |
262 | "Couldn't delete group %s (id %d): %s", | |
263 | before[L_NAME], -bgid, error_message(code)); | |
264 | } | |
fb8809f4 | 265 | return; |
266 | } | |
60c22e5f | 267 | if (agid) { |
268 | strcpy(g1, "system:"); | |
269 | strcat(g1, after[L_NAME]); | |
270 | strcpy(g2, "system:administrators"); | |
271 | id = -agid; | |
eb63ae5f | 272 | code = pr_try(pr_CreateGroup, g1, g2, &id); |
60c22e5f | 273 | if (code) { |
274 | critical_alert("incremental", | |
275 | "Couldn't create group %s (id %d): %s", | |
ed9a5300 | 276 | after[L_NAME], id, error_message(code)); |
60c22e5f | 277 | return; |
278 | } | |
8ec23c21 | 279 | if (ahide) { |
eb63ae5f | 280 | code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS, |
281 | (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT, | |
282 | 0 /*ngroups*/, 0 /*nusers*/); | |
8ec23c21 | 283 | if (code) { |
284 | critical_alert("incremental", | |
285 | "Couldn't set flags of group %s: %s", | |
286 | after[L_NAME], error_message(code)); | |
287 | } | |
288 | } | |
60c22e5f | 289 | |
290 | /* We need to make sure the group is properly populated */ | |
c69d9f2c | 291 | if (beforec < L_ACTIVE) return; |
60c22e5f | 292 | |
14d69e25 | 293 | code = moira_connect(); |
ed9a5300 | 294 | if (code) { |
295 | critical_alert("incremental", | |
296 | "Error contacting Moira server to resolve %s: %s", | |
297 | after[L_NAME], error_message(code)); | |
298 | return; | |
299 | } | |
cdf6674b | 300 | av[0] = after[L_NAME]; |
301 | code = mr_query("get_end_members_of_list", 1, av, | |
063819ef | 302 | add_list_members, after[L_NAME]); |
303 | if (code) | |
304 | critical_alert("incremental", | |
305 | "Couldn't retrieve full membership of list %s: %s", | |
306 | after[L_NAME], error_message(code)); | |
14d69e25 | 307 | moira_disconnect(); |
ed9a5300 | 308 | return; |
60c22e5f | 309 | } |
fb8809f4 | 310 | } |
311 | ||
312 | ||
313 | do_member(before, beforec, after, afterc) | |
314 | char **before; | |
315 | int beforec; | |
316 | char **after; | |
317 | int afterc; | |
318 | { | |
60c22e5f | 319 | int code; |
320 | char *p; | |
321 | ||
bd70a79d | 322 | if ((beforec < 4 || !atoi(before[LM_END])) && |
323 | (afterc < 4 || !atoi(after[LM_END]))) | |
fb8809f4 | 324 | return; |
60c22e5f | 325 | |
ed9a5300 | 326 | if (afterc) |
327 | edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]); | |
328 | if (beforec) | |
e9f07a3b | 329 | edit_group(0, before[LM_LIST], before[LM_TYPE], before[LM_MEMBER]); |
ed9a5300 | 330 | } |
331 | ||
332 | ||
eb63ae5f | 333 | do_filesys(before, beforec, after, afterc) |
334 | char **before; | |
335 | int beforec; | |
336 | char **after; | |
337 | int afterc; | |
338 | { | |
339 | char cmd[1024]; | |
89e513d9 | 340 | int acreate, atype, btype; |
341 | ||
342 | if (afterc < FS_CREATE) { | |
343 | atype = acreate = 0; | |
344 | } else { | |
345 | atype = !strcmp(after[FS_TYPE], "AFS"); | |
346 | acreate = atoi(after[FS_CREATE]); | |
347 | } | |
348 | ||
eb63ae5f | 349 | if (beforec < FS_CREATE) { |
89e513d9 | 350 | if (acreate == 0 || atype == 0) return; |
eb63ae5f | 351 | |
352 | /* new locker creation */ | |
353 | sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s", | |
354 | BIN_DIR, BIN_DIR, BIN_DIR, | |
355 | after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE], | |
356 | after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]); | |
357 | run_cmd(cmd); | |
358 | return; | |
359 | } | |
89e513d9 | 360 | |
89e513d9 | 361 | btype = !strcmp(before[FS_TYPE], "AFS"); |
eb63ae5f | 362 | if (afterc < FS_CREATE) { |
89e513d9 | 363 | if (btype) |
eb63ae5f | 364 | critical_alert("incremental", |
3b1e9c5f | 365 | "Cannot delete AFS filesystem %s: Operation not supported", |
eb63ae5f | 366 | before[FS_NAME]); |
367 | return; | |
eb63ae5f | 368 | } |
3b1e9c5f | 369 | |
370 | if (!acreate) | |
371 | return; | |
372 | ||
373 | /* Are we dealing with AFS lockers (could be type ERR lockers) */ | |
374 | if (!atype && !btype) | |
375 | if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR")) | |
376 | return; | |
377 | ||
378 | /* By now, we know we are simply changing AFS filesystem attributes. | |
379 | * Operations supported: | |
380 | * Name change: rename/remount | |
381 | * Path change: remount | |
382 | * Type change: ERR<-->AFS | |
383 | */ | |
0f82335a | 384 | |
385 | #if 0 | |
3b1e9c5f | 386 | if (strcmp(before[FS_OWNER], after[FS_OWNER]) || |
3ae9c0f3 | 387 | strcmp(before[FS_OWNERS], after[FS_OWNERS])) |
3b1e9c5f | 388 | { |
389 | critical_alert("incremental", | |
390 | "Cannot change ownership of filesystem %s: Operation not yet supported", | |
391 | after[FS_NAME]); | |
392 | } | |
0f82335a | 393 | #endif |
3b1e9c5f | 394 | |
395 | sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s", | |
396 | BIN_DIR, BIN_DIR, BIN_DIR, | |
3ae9c0f3 | 397 | before[FS_NAME], before[FS_MACHINE], before[FS_TYPE], |
3b1e9c5f | 398 | before[FS_L_TYPE], before[FS_PACK], |
3ae9c0f3 | 399 | after[FS_NAME], after[FS_MACHINE], after[FS_TYPE], |
3b1e9c5f | 400 | after[FS_L_TYPE], after[FS_PACK]); |
401 | run_cmd(cmd); | |
eb63ae5f | 402 | } |
403 | ||
404 | ||
405 | do_quota(before, beforec, after, afterc) | |
406 | char **before; | |
407 | int beforec; | |
408 | char **after; | |
409 | int afterc; | |
410 | { | |
411 | char cmd[1024]; | |
412 | ||
413 | if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) || | |
414 | strncmp("/afs/", after[Q_DIRECTORY], 5)) | |
415 | return; | |
416 | ||
417 | sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s", | |
418 | BIN_DIR, BIN_DIR, BIN_DIR, | |
419 | after[Q_DIRECTORY], after[Q_QUOTA]); | |
420 | run_cmd(cmd); | |
421 | return; | |
422 | } | |
423 | ||
424 | ||
425 | run_cmd(cmd) | |
426 | char *cmd; | |
427 | { | |
428 | int success=0, tries=0; | |
429 | ||
430 | check_afs(); | |
431 | ||
432 | while (success == 0 && tries < 2) { | |
433 | if (tries++) | |
434 | sleep(90); | |
435 | com_err(whoami, 0, "Executing command: %s", cmd); | |
436 | if (system(cmd) == 0) | |
437 | success++; | |
438 | } | |
439 | if (!success) | |
440 | critical_alert("incremental", "failed command: %s", cmd); | |
441 | } | |
442 | ||
443 | ||
444 | add_user_lists(ac, av, user) | |
445 | int ac; | |
446 | char *av[]; | |
447 | char *user; | |
448 | { | |
2cb1f02c | 449 | if (atoi(av[L_ACTIVE]) && atoi(av[L_GROUP])) /* active group ? */ |
450 | edit_group(1, av[L_NAME], "USER", user); | |
eb63ae5f | 451 | } |
452 | ||
453 | ||
063819ef | 454 | add_list_members(ac, av, group) |
ed9a5300 | 455 | int ac; |
456 | char *av[]; | |
457 | char *group; | |
458 | { | |
063819ef | 459 | edit_group(1, group, av[0], av[1]); |
ed9a5300 | 460 | } |
461 | ||
462 | ||
c69d9f2c | 463 | check_user(ac, av, ustate) |
464 | int ac; | |
465 | char *av[]; | |
466 | int *ustate; | |
467 | { | |
2cb1f02c | 468 | *ustate = atoi(av[U_STATE]); |
c69d9f2c | 469 | } |
470 | ||
471 | ||
ed9a5300 | 472 | edit_group(op, group, type, member) |
473 | int op; | |
474 | char *group; | |
475 | char *type; | |
476 | char *member; | |
477 | { | |
478 | char *p = 0; | |
479 | char buf[PR_MAXNAMELEN]; | |
c69d9f2c | 480 | int code, ustate; |
d1be2e3a | 481 | static char local_realm[REALM_SZ+1] = ""; |
2cb1f02c | 482 | struct member *m; |
ed9a5300 | 483 | |
60c22e5f | 484 | /* The following KERBEROS code allows for the use of entities |
485 | * user@foreign_cell. | |
486 | */ | |
d1be2e3a | 487 | if (!local_realm[0]) |
488 | krb_get_lrealm(local_realm, 1); | |
ed9a5300 | 489 | if (!strcmp(type, "KERBEROS")) { |
490 | p = index(member, '@'); | |
d1be2e3a | 491 | if (p && !strcasecmp(p+1, local_realm)) |
60c22e5f | 492 | *p = 0; |
ed9a5300 | 493 | } else if (strcmp(type, "USER")) |
494 | return; /* invalid type */ | |
60c22e5f | 495 | |
2cb1f02c | 496 | /* Cannot risk doing another query during a callback */ |
497 | /* We could do this simply for type USER, but eventually this may also | |
498 | * dynamically add KERBEROS types to the prdb, and we will need to do | |
499 | * a query to look up the uid of the null-instance user */ | |
500 | if (mr_connections) { | |
501 | m = (struct member *)malloc(sizeof(struct member)); | |
502 | if (!m) { | |
503 | critical_alert("incremental", "Out of memory"); | |
504 | exit(1); | |
505 | } | |
506 | m->op = op; | |
507 | strcpy(m->list, group); | |
508 | strcpy(m->type, type); | |
509 | strcpy(m->member, member); | |
510 | m->next = member_head; | |
511 | member_head = m; | |
512 | return; | |
513 | } | |
514 | ||
ed9a5300 | 515 | strcpy(buf, "system:"); |
516 | strcat(buf, group); | |
eb63ae5f | 517 | code=pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf); |
ed9a5300 | 518 | if (code) { |
c69d9f2c | 519 | if (op==1 && code == PRIDEXIST) return; /* Already added */ |
520 | ||
521 | if (code == PRNOENT) { /* Something is missing */ | |
522 | if (op==0) return; /* Already deleted */ | |
523 | if (!strcmp(type, "KERBEROS")) /* Special instances; ok */ | |
524 | return; | |
525 | ||
526 | /* Check whether the member being added is an active user */ | |
14d69e25 | 527 | code = moira_connect(); |
c69d9f2c | 528 | if (!code) code = mr_query("get_user_by_login", 1, &member, |
529 | check_user, &ustate); | |
530 | if (code) { | |
531 | critical_alert("incremental", | |
532 | "Error contacting Moira server to lookup user %s: %s", | |
533 | member, error_message(code)); | |
534 | } | |
14d69e25 | 535 | moira_disconnect(); |
c69d9f2c | 536 | if (!code && ustate!=1 && ustate!=2) return; /* inactive user */ |
60c22e5f | 537 | } |
c69d9f2c | 538 | |
539 | critical_alert("incremental", | |
540 | "Couldn't %s %s %s %s: %s", | |
541 | op ? "add" : "remove", member, | |
542 | op ? "to" : "from", buf, | |
543 | error_message(code)); | |
57bc9f26 | 544 | } |
fb8809f4 | 545 | } |
546 | ||
547 | ||
eb63ae5f | 548 | long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8) |
549 | long (*fn)(); | |
550 | char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; | |
fb8809f4 | 551 | { |
eb63ae5f | 552 | static int initd=0; |
16838ad1 | 553 | volatile register long code; |
eb63ae5f | 554 | register int tries = 0; |
555 | #ifdef DEBUG | |
556 | char fname[64]; | |
557 | #endif | |
558 | ||
559 | check_afs(); | |
60c22e5f | 560 | |
eb63ae5f | 561 | if (!initd) { |
562 | code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); | |
563 | if (code) { | |
564 | critical_alert("incremental", "Couldn't initialize libprot: %s", | |
565 | error_message(code)); | |
60c22e5f | 566 | return; |
eb63ae5f | 567 | } |
568 | initd = 1; | |
9b9540a1 | 569 | } |
16838ad1 | 570 | sleep(1); /* give ptserver room */ |
9b9540a1 | 571 | |
eb63ae5f | 572 | while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) { |
573 | #ifdef DEBUG | |
574 | long t; | |
575 | t = time(0); | |
576 | if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); | |
577 | else if (fn == pr_RemoveUserFromGroup) | |
578 | strcpy(fname, "pr_RemoveUserFromGroup"); | |
579 | else if (fn == pr_CreateUser) strcpy(fname, "pr_CreateUser"); | |
580 | else if (fn == pr_CreateGroup) strcpy(fname, "pr_CreateGroup"); | |
581 | else if (fn == pr_DeleteByID) strcpy(fname, "pr_DeleteByID"); | |
582 | else if (fn == pr_ChangeEntry) strcpy(fname, "pr_ChangeEntry"); | |
583 | else if (fn == pr_SetFieldsEntry) strcpy(fname, "pr_SetFieldsEntry"); | |
584 | else if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); | |
16838ad1 | 585 | else |
eb63ae5f | 586 | sprintf(fname, "pr_??? (0x%08x)", (long)fn); |
eb63ae5f | 587 | |
16838ad1 | 588 | com_err(whoami, code, "- %s failed (try %d @%u)", fname, tries+1, t); |
eb63ae5f | 589 | #endif |
16838ad1 | 590 | if (++tries > 2) break; /* 3 tries */ |
591 | ||
592 | if (code == UNOQUORUM) sleep(90); | |
593 | else sleep(15); | |
594 | ||
595 | /* Re-initialize the prdb connection */ | |
596 | code=pr_Initialize(0, AFSCONF_CLIENTNAME, 0); | |
597 | if (!code) code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); | |
598 | if (code) { | |
599 | critical_alert("incremental", "Couldn't re-initialize libprot: %s", | |
600 | error_message(code)); | |
601 | initd = 0; /* we lost */ | |
602 | break; | |
603 | } | |
9b9540a1 | 604 | } |
eb63ae5f | 605 | return code; |
fb8809f4 | 606 | } |
607 | ||
608 | ||
eb63ae5f | 609 | check_afs() |
fb8809f4 | 610 | { |
eb63ae5f | 611 | int i; |
612 | ||
613 | for (i=0; file_exists(STOP_FILE); i++) { | |
614 | if (i > 30) { | |
615 | critical_alert("incremental", | |
616 | "AFS incremental failed (%s exists): %s", | |
617 | STOP_FILE, tbl_buf); | |
618 | exit(1); | |
619 | } | |
620 | sleep(60); | |
621 | } | |
fb8809f4 | 622 | } |
14d69e25 | 623 | |
624 | ||
14d69e25 | 625 | moira_connect() |
626 | { | |
627 | static char hostname[64]; | |
628 | long code; | |
629 | ||
630 | if (!mr_connections++) { | |
631 | gethostname(hostname, sizeof(hostname)); | |
632 | code = mr_connect(hostname); | |
633 | if (!code) code = mr_auth("afs.incr"); | |
634 | return code; | |
635 | } | |
636 | return 0; | |
637 | } | |
638 | ||
639 | moira_disconnect() | |
640 | { | |
2cb1f02c | 641 | struct member *m; |
642 | ||
14d69e25 | 643 | if (!--mr_connections) { |
0415047d | 644 | while(member_head) { |
645 | m = member_head; | |
2cb1f02c | 646 | edit_group(m->op, m->list, m->type, m->member); |
647 | member_head = m->next; | |
648 | free(m); | |
649 | } | |
14d69e25 | 650 | mr_disconnect(); |
651 | } | |
652 | return 0; | |
653 | } |