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