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