]>
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]; | |
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 | } | |
300 | av[0] = "LIST"; | |
301 | av[1] = after[L_NAME]; | |
302 | get_members(2, av, after[L_NAME]); | |
303 | ||
14d69e25 | 304 | moira_disconnect(); |
ed9a5300 | 305 | return; |
60c22e5f | 306 | } |
fb8809f4 | 307 | } |
308 | ||
309 | ||
310 | do_member(before, beforec, after, afterc) | |
311 | char **before; | |
312 | int beforec; | |
313 | char **after; | |
314 | int afterc; | |
315 | { | |
60c22e5f | 316 | int code; |
317 | char *p; | |
318 | ||
bd70a79d | 319 | if ((beforec < 4 || !atoi(before[LM_END])) && |
320 | (afterc < 4 || !atoi(after[LM_END]))) | |
fb8809f4 | 321 | return; |
60c22e5f | 322 | |
ed9a5300 | 323 | if (afterc) |
324 | edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]); | |
325 | if (beforec) | |
e9f07a3b | 326 | edit_group(0, before[LM_LIST], before[LM_TYPE], before[LM_MEMBER]); |
ed9a5300 | 327 | } |
328 | ||
329 | ||
eb63ae5f | 330 | do_filesys(before, beforec, after, afterc) |
331 | char **before; | |
332 | int beforec; | |
333 | char **after; | |
334 | int afterc; | |
335 | { | |
336 | char cmd[1024]; | |
89e513d9 | 337 | int acreate, atype, btype; |
338 | ||
339 | if (afterc < FS_CREATE) { | |
340 | atype = acreate = 0; | |
341 | } else { | |
342 | atype = !strcmp(after[FS_TYPE], "AFS"); | |
343 | acreate = atoi(after[FS_CREATE]); | |
344 | } | |
345 | ||
eb63ae5f | 346 | if (beforec < FS_CREATE) { |
89e513d9 | 347 | if (acreate == 0 || atype == 0) return; |
eb63ae5f | 348 | |
349 | /* new locker creation */ | |
350 | sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s", | |
351 | BIN_DIR, BIN_DIR, BIN_DIR, | |
352 | after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE], | |
353 | after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]); | |
354 | run_cmd(cmd); | |
355 | return; | |
356 | } | |
89e513d9 | 357 | |
89e513d9 | 358 | btype = !strcmp(before[FS_TYPE], "AFS"); |
eb63ae5f | 359 | if (afterc < FS_CREATE) { |
89e513d9 | 360 | if (btype) |
eb63ae5f | 361 | critical_alert("incremental", |
3b1e9c5f | 362 | "Cannot delete AFS filesystem %s: Operation not supported", |
eb63ae5f | 363 | before[FS_NAME]); |
364 | return; | |
eb63ae5f | 365 | } |
3b1e9c5f | 366 | |
367 | if (!acreate) | |
368 | return; | |
369 | ||
370 | /* Are we dealing with AFS lockers (could be type ERR lockers) */ | |
371 | if (!atype && !btype) | |
372 | if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR")) | |
373 | return; | |
374 | ||
375 | /* By now, we know we are simply changing AFS filesystem attributes. | |
376 | * Operations supported: | |
377 | * Name change: rename/remount | |
378 | * Path change: remount | |
379 | * Type change: ERR<-->AFS | |
380 | */ | |
0f82335a | 381 | |
382 | #if 0 | |
3b1e9c5f | 383 | if (strcmp(before[FS_OWNER], after[FS_OWNER]) || |
3ae9c0f3 | 384 | strcmp(before[FS_OWNERS], after[FS_OWNERS])) |
3b1e9c5f | 385 | { |
386 | critical_alert("incremental", | |
387 | "Cannot change ownership of filesystem %s: Operation not yet supported", | |
388 | after[FS_NAME]); | |
389 | } | |
0f82335a | 390 | #endif |
3b1e9c5f | 391 | |
392 | sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s", | |
393 | BIN_DIR, BIN_DIR, BIN_DIR, | |
3ae9c0f3 | 394 | before[FS_NAME], before[FS_MACHINE], before[FS_TYPE], |
3b1e9c5f | 395 | before[FS_L_TYPE], before[FS_PACK], |
3ae9c0f3 | 396 | after[FS_NAME], after[FS_MACHINE], after[FS_TYPE], |
3b1e9c5f | 397 | after[FS_L_TYPE], after[FS_PACK]); |
398 | run_cmd(cmd); | |
eb63ae5f | 399 | } |
400 | ||
401 | ||
402 | do_quota(before, beforec, after, afterc) | |
403 | char **before; | |
404 | int beforec; | |
405 | char **after; | |
406 | int afterc; | |
407 | { | |
408 | char cmd[1024]; | |
409 | ||
410 | if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) || | |
411 | strncmp("/afs/", after[Q_DIRECTORY], 5)) | |
412 | return; | |
413 | ||
414 | sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s", | |
415 | BIN_DIR, BIN_DIR, BIN_DIR, | |
416 | after[Q_DIRECTORY], after[Q_QUOTA]); | |
417 | run_cmd(cmd); | |
418 | return; | |
419 | } | |
420 | ||
421 | ||
422 | run_cmd(cmd) | |
423 | char *cmd; | |
424 | { | |
425 | int success=0, tries=0; | |
426 | ||
427 | check_afs(); | |
428 | ||
429 | while (success == 0 && tries < 2) { | |
430 | if (tries++) | |
431 | sleep(90); | |
432 | com_err(whoami, 0, "Executing command: %s", cmd); | |
433 | if (system(cmd) == 0) | |
434 | success++; | |
435 | } | |
436 | if (!success) | |
437 | critical_alert("incremental", "failed command: %s", cmd); | |
438 | } | |
439 | ||
440 | ||
441 | add_user_lists(ac, av, user) | |
442 | int ac; | |
443 | char *av[]; | |
444 | char *user; | |
445 | { | |
2cb1f02c | 446 | if (atoi(av[L_ACTIVE]) && atoi(av[L_GROUP])) /* active group ? */ |
447 | edit_group(1, av[L_NAME], "USER", user); | |
eb63ae5f | 448 | } |
449 | ||
450 | ||
ed9a5300 | 451 | get_members(ac, av, group) |
452 | int ac; | |
453 | char *av[]; | |
454 | char *group; | |
455 | { | |
456 | int code=0; | |
457 | ||
2cb1f02c | 458 | code = mr_query("get_end_members_of_list", 1, &av[1], get_members, group); |
459 | if (code) | |
460 | critical_alert("incremental", | |
461 | "Couldn't retrieve full membership of %s: %s", | |
462 | group, error_message(code)); | |
ed9a5300 | 463 | return code; |
464 | } | |
465 | ||
466 | ||
c69d9f2c | 467 | check_user(ac, av, ustate) |
468 | int ac; | |
469 | char *av[]; | |
470 | int *ustate; | |
471 | { | |
2cb1f02c | 472 | *ustate = atoi(av[U_STATE]); |
c69d9f2c | 473 | } |
474 | ||
475 | ||
ed9a5300 | 476 | edit_group(op, group, type, member) |
477 | int op; | |
478 | char *group; | |
479 | char *type; | |
480 | char *member; | |
481 | { | |
482 | char *p = 0; | |
483 | char buf[PR_MAXNAMELEN]; | |
c69d9f2c | 484 | int code, ustate; |
d1be2e3a | 485 | static char local_realm[REALM_SZ+1] = ""; |
2cb1f02c | 486 | struct member *m; |
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 | |
2cb1f02c | 500 | /* Cannot risk doing another query during a callback */ |
501 | /* We could do this simply for type USER, but eventually this may also | |
502 | * dynamically add KERBEROS types to the prdb, and we will need to do | |
503 | * a query to look up the uid of the null-instance user */ | |
504 | if (mr_connections) { | |
505 | m = (struct member *)malloc(sizeof(struct member)); | |
506 | if (!m) { | |
507 | critical_alert("incremental", "Out of memory"); | |
508 | exit(1); | |
509 | } | |
510 | m->op = op; | |
511 | strcpy(m->list, group); | |
512 | strcpy(m->type, type); | |
513 | strcpy(m->member, member); | |
514 | m->next = member_head; | |
515 | member_head = m; | |
516 | return; | |
517 | } | |
518 | ||
ed9a5300 | 519 | strcpy(buf, "system:"); |
520 | strcat(buf, group); | |
eb63ae5f | 521 | code=pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf); |
ed9a5300 | 522 | if (code) { |
c69d9f2c | 523 | if (op==1 && code == PRIDEXIST) return; /* Already added */ |
524 | ||
525 | if (code == PRNOENT) { /* Something is missing */ | |
526 | if (op==0) return; /* Already deleted */ | |
527 | if (!strcmp(type, "KERBEROS")) /* Special instances; ok */ | |
528 | return; | |
529 | ||
530 | /* Check whether the member being added is an active user */ | |
14d69e25 | 531 | code = moira_connect(); |
c69d9f2c | 532 | if (!code) code = mr_query("get_user_by_login", 1, &member, |
533 | check_user, &ustate); | |
534 | if (code) { | |
535 | critical_alert("incremental", | |
536 | "Error contacting Moira server to lookup user %s: %s", | |
537 | member, error_message(code)); | |
538 | } | |
14d69e25 | 539 | moira_disconnect(); |
c69d9f2c | 540 | if (!code && ustate!=1 && ustate!=2) return; /* inactive user */ |
60c22e5f | 541 | } |
c69d9f2c | 542 | |
543 | critical_alert("incremental", | |
544 | "Couldn't %s %s %s %s: %s", | |
545 | op ? "add" : "remove", member, | |
546 | op ? "to" : "from", buf, | |
547 | error_message(code)); | |
57bc9f26 | 548 | } |
fb8809f4 | 549 | } |
550 | ||
551 | ||
eb63ae5f | 552 | long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8) |
553 | long (*fn)(); | |
554 | char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; | |
fb8809f4 | 555 | { |
eb63ae5f | 556 | static int initd=0; |
16838ad1 | 557 | volatile register long code; |
eb63ae5f | 558 | register int tries = 0; |
559 | #ifdef DEBUG | |
560 | char fname[64]; | |
561 | #endif | |
562 | ||
563 | check_afs(); | |
60c22e5f | 564 | |
eb63ae5f | 565 | if (!initd) { |
566 | code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); | |
567 | if (code) { | |
568 | critical_alert("incremental", "Couldn't initialize libprot: %s", | |
569 | error_message(code)); | |
60c22e5f | 570 | return; |
eb63ae5f | 571 | } |
572 | initd = 1; | |
9b9540a1 | 573 | } |
16838ad1 | 574 | sleep(1); /* give ptserver room */ |
9b9540a1 | 575 | |
eb63ae5f | 576 | while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) { |
577 | #ifdef DEBUG | |
578 | long t; | |
579 | t = time(0); | |
580 | if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); | |
581 | else if (fn == pr_RemoveUserFromGroup) | |
582 | strcpy(fname, "pr_RemoveUserFromGroup"); | |
583 | else if (fn == pr_CreateUser) strcpy(fname, "pr_CreateUser"); | |
584 | else if (fn == pr_CreateGroup) strcpy(fname, "pr_CreateGroup"); | |
585 | else if (fn == pr_DeleteByID) strcpy(fname, "pr_DeleteByID"); | |
586 | else if (fn == pr_ChangeEntry) strcpy(fname, "pr_ChangeEntry"); | |
587 | else if (fn == pr_SetFieldsEntry) strcpy(fname, "pr_SetFieldsEntry"); | |
588 | else if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup"); | |
16838ad1 | 589 | else |
eb63ae5f | 590 | sprintf(fname, "pr_??? (0x%08x)", (long)fn); |
eb63ae5f | 591 | |
16838ad1 | 592 | com_err(whoami, code, "- %s failed (try %d @%u)", fname, tries+1, t); |
eb63ae5f | 593 | #endif |
16838ad1 | 594 | if (++tries > 2) break; /* 3 tries */ |
595 | ||
596 | if (code == UNOQUORUM) sleep(90); | |
597 | else sleep(15); | |
598 | ||
599 | /* Re-initialize the prdb connection */ | |
600 | code=pr_Initialize(0, AFSCONF_CLIENTNAME, 0); | |
601 | if (!code) code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0); | |
602 | if (code) { | |
603 | critical_alert("incremental", "Couldn't re-initialize libprot: %s", | |
604 | error_message(code)); | |
605 | initd = 0; /* we lost */ | |
606 | break; | |
607 | } | |
9b9540a1 | 608 | } |
eb63ae5f | 609 | return code; |
fb8809f4 | 610 | } |
611 | ||
612 | ||
eb63ae5f | 613 | check_afs() |
fb8809f4 | 614 | { |
eb63ae5f | 615 | int i; |
616 | ||
617 | for (i=0; file_exists(STOP_FILE); i++) { | |
618 | if (i > 30) { | |
619 | critical_alert("incremental", | |
620 | "AFS incremental failed (%s exists): %s", | |
621 | STOP_FILE, tbl_buf); | |
622 | exit(1); | |
623 | } | |
624 | sleep(60); | |
625 | } | |
fb8809f4 | 626 | } |
14d69e25 | 627 | |
628 | ||
14d69e25 | 629 | moira_connect() |
630 | { | |
631 | static char hostname[64]; | |
632 | long code; | |
633 | ||
634 | if (!mr_connections++) { | |
635 | gethostname(hostname, sizeof(hostname)); | |
636 | code = mr_connect(hostname); | |
637 | if (!code) code = mr_auth("afs.incr"); | |
638 | return code; | |
639 | } | |
640 | return 0; | |
641 | } | |
642 | ||
643 | moira_disconnect() | |
644 | { | |
2cb1f02c | 645 | struct member *m; |
646 | ||
14d69e25 | 647 | if (!--mr_connections) { |
0415047d | 648 | while(member_head) { |
649 | m = member_head; | |
2cb1f02c | 650 | edit_group(m->op, m->list, m->type, m->member); |
651 | member_head = m->next; | |
652 | free(m); | |
653 | } | |
14d69e25 | 654 | mr_disconnect(); |
655 | } | |
656 | return 0; | |
657 | } |