]> andersk Git - moira.git/blame - incremental/afs/afs.c
Build shared libmoira via libtool.
[moira.git] / incremental / afs / afs.c
CommitLineData
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
dfaf9b68 10#include <moira.h>
11#include <moira_site.h>
12#include <moira_schema.h>
13
16838ad1 14#include <stdio.h>
5eaef520 15#include <stdlib.h>
7ac48069 16#include <sys/resource.h>
60c22e5f 17#include <sys/types.h>
7ac48069 18#include <sys/utsname.h>
60c22e5f 19#include <sys/file.h>
f19e3bf8 20#include <string.h>
e2666aac 21#include <unistd.h>
60c22e5f 22
7ac48069 23#include <com_err.h>
cb974713 24#ifdef HAVE_KRB4
d1be2e3a 25#include <krb.h>
cb974713 26#endif
27#include <krb5.h>
f633445d 28
60c22e5f 29#include <afs/param.h>
30#include <afs/cellconfig.h>
31#include <afs/venus.h>
32#include <afs/ptclient.h>
33#include <afs/pterror.h>
fb8809f4 34
df2f7fb7 35/* Cheesy test for determining AFS more recent than 3.4a */
36#ifndef AFSCONF_CLIENTNAME
37#include <afs/dirpath.h>
38#define AFSCONF_CLIENTNAME AFSDIR_CLIENT_ETC_DIRPATH
39#endif
40
d1be2e3a 41#define STOP_FILE "/moira/afs/noafs"
60c22e5f 42#define file_exists(file) (access((file), F_OK) == 0)
fb8809f4 43
44char *whoami;
45
eb63ae5f 46/* Main stub routines */
7ac48069 47void do_user(char **before, int beforec, char **after, int afterc);
48void do_list(char **before, int beforec, char **after, int afterc);
49void do_member(char **before, int beforec, char **after, int afterc);
50void do_filesys(char **before, int beforec, char **after, int afterc);
51void do_quota(char **before, int beforec, char **after, int afterc);
eb63ae5f 52
53/* Support stub routines */
7ac48069 54void run_cmd(char *cmd);
55int add_user_lists(int ac, char **av, void *user);
56int add_list_members(int ac, char **av, void *group);
57int check_user(int ac, char **av, void *ustate);
58void edit_group(int op, char *group, char *type, char *member);
e2666aac 59long pr_try();
7ac48069 60void check_afs(void);
61int moira_connect(void);
62int moira_disconnect(void);
eb63ae5f 63
64/* libprot.a routines */
65extern long pr_Initialize();
66extern long pr_CreateUser();
67extern long pr_CreateGroup();
68extern long pr_DeleteByID();
69extern long pr_ChangeEntry();
70extern long pr_SetFieldsEntry();
71extern long pr_AddToGroup();
72extern long pr_RemoveUserFromGroup();
0beb8644 73extern long pr_SIdToName();
eb63ae5f 74
75static char tbl_buf[1024];
2cb1f02c 76static struct member {
5eaef520 77 int op;
dfaf9b68 78 char list[LIST_NAME_SIZE];
79 char type[IMEMBERS_MEMBER_TYPE_SIZE];
80 char member[MAX_FIELD_WIDTH];
5eaef520 81 struct member *next;
82} *member_head = NULL;
83
84static int mr_connections = 0;
85
86int main(int argc, char **argv)
fb8809f4 87{
5eaef520 88 int beforec, afterc, i;
89 char *table, **before, **after;
7ac48069 90 struct rlimit rl;
fb8809f4 91
7ac48069 92 getrlimit(RLIMIT_NOFILE, &rl);
93 for (i = rl.rlim_cur; i > 2; i--)
5eaef520 94 close(i);
a7fdf2de 95
5eaef520 96 whoami = ((whoami = strrchr(argv[0], '/')) ? whoami+1 : argv[0]);
d4ea75d6 97
5eaef520 98 table = argv[1];
99 beforec = atoi(argv[2]);
100 before = &argv[4];
101 afterc = atoi(argv[3]);
102 after = &argv[4 + beforec];
f10e3ca2 103
5eaef520 104 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
eb63ae5f 105
5eaef520 106 strcpy(tbl_buf, table);
107 strcat(tbl_buf, " (");
108 for (i = 0; i < beforec; i++)
109 {
110 if (i > 0)
111 strcat(tbl_buf, ",");
112 strcat(tbl_buf, before[i]);
810d12a7 113 }
5eaef520 114 strcat(tbl_buf, ")->(");
115 for (i = 0; i < afterc; i++)
116 {
117 if (i > 0)
118 strcat(tbl_buf, ",");
119 strcat(tbl_buf, after[i]);
fb8809f4 120 }
5eaef520 121 strcat(tbl_buf, ")");
122
123 initialize_sms_error_table();
124 initialize_krb_error_table();
125
126 if (!strcmp(table, "users"))
127 do_user(before, beforec, after, afterc);
128 else if (!strcmp(table, "list"))
129 do_list(before, beforec, after, afterc);
130 else if (!strcmp(table, "imembers"))
131 do_member(before, beforec, after, afterc);
132 else if (!strcmp(table, "filesys"))
133 do_filesys(before, beforec, after, afterc);
134 else if (!strcmp(table, "quota"))
135 do_quota(before, beforec, after, afterc);
136
137 exit(0);
fb8809f4 138}
139
140
7ac48069 141void do_user(char **before, int beforec, char **after, int afterc)
fb8809f4 142{
5eaef520 143 int astate, bstate, auid, buid, code;
144 char *av[2];
145
146 auid = buid = astate = bstate = 0;
147 if (afterc > U_STATE)
148 astate = atoi(after[U_STATE]);
149 if (beforec > U_STATE)
150 bstate = atoi(before[U_STATE]);
151 if (afterc > U_UID)
152 auid = atoi(after[U_UID]);
153 if (beforec > U_UID)
154 buid = atoi(before[U_UID]);
155
156 /* We consider "half-registered" users to be active */
157 if (astate == 2)
158 astate = 1;
159 if (bstate == 2)
160 bstate = 1;
161
162 if (astate != 1 && bstate != 1) /* inactive user */
163 return;
60c22e5f 164
5eaef520 165 if (astate == bstate && auid == buid &&
166 !strcmp(before[U_NAME], after[U_NAME]))
167 /* No AFS related attributes have changed */
168 return;
fb8809f4 169
5eaef520 170 if (astate == bstate)
171 {
172 /* Only a modify has to be done */
173 com_err(whoami, 0, "Changing user %s (uid %d) to %s (uid %d)",
174 before[U_NAME], buid, after[U_NAME], auid);
175
176 code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, "");
177 if (code)
178 {
a816420b 179 critical_alert(whoami, "incremental",
5eaef520 180 "Couldn't change user %s (id %d) to %s (id %d): %s",
181 before[U_NAME], buid, after[U_NAME], auid,
182 error_message(code));
60c22e5f 183 }
5eaef520 184 return;
60c22e5f 185 }
5eaef520 186 if (bstate == 1)
187 {
188 com_err(whoami, 0, "Deleting user %s (uid %d)",
189 before[U_NAME], buid);
190
191 code = pr_try(pr_DeleteByID, buid);
192 if (code && code != PRNOENT)
193 {
a816420b 194 critical_alert(whoami, "incremental", "Couldn't delete user %s (id %d): %s",
5eaef520 195 before[U_NAME], buid, error_message(code));
60c22e5f 196 }
5eaef520 197 return;
60c22e5f 198 }
5eaef520 199 if (astate == 1)
200 {
201 com_err(whoami, 0, "%s user %s (uid %d)",
202 ((bstate != 0) ? "Reactivating" : "Creating"),
203 after[U_NAME], auid);
204
205 code = pr_try(pr_CreateUser, after[U_NAME], &auid);
206 /* if we get PRIDEXIST, it's only an error if the username
207 doesn't match (otherwise it just means the user was deleted
208 from Moira but not AFS */
209 if (code == PRIDEXIST)
210 {
dfaf9b68 211 char ename[PR_MAXNAMELEN];
5eaef520 212
213 if (pr_try(pr_SIdToName, auid, ename) == 0 &&
214 !strcmp(after[U_NAME], ename))
96786144 215 return;
60c22e5f 216 }
5eaef520 217 if (code)
218 {
a816420b 219 critical_alert(whoami, "incremental", "Couldn't create user %s (id %d): %s",
5eaef520 220 after[U_NAME], auid, error_message(code));
221 return;
222 }
2dbcb756 223
5eaef520 224 if (bstate != 0)
225 {
226 /* Reactivating a user; get his group list */
227 code = moira_connect();
228 if (code)
229 {
a816420b 230 critical_alert(whoami, "incremental", "Error contacting Moira server "
5eaef520 231 "to retrieve grouplist of user %s: %s",
232 after[U_NAME], error_message(code));
233 return;
234 }
235 av[0] = "ruser";
236 av[1] = after[U_NAME];
237 code = mr_query("get_lists_of_member", 2, av, add_user_lists,
238 after[U_NAME]);
239 if (code && code != MR_NO_MATCH)
240 {
a816420b 241 critical_alert(whoami, "incremental",
5eaef520 242 "Couldn't retrieve membership of user %s: %s",
243 after[U_NAME], error_message(code));
9b273918 244 }
5eaef520 245 moira_disconnect();
9b273918 246 }
5eaef520 247 return;
fb8809f4 248 }
249}
250
251
7ac48069 252void do_list(char **before, int beforec, char **after, int afterc)
fb8809f4 253{
44d12d58 254 int agid, bgid;
5eaef520 255 int ahide, bhide;
256 long code, id;
257 char g1[PR_MAXNAMELEN], g2[PR_MAXNAMELEN];
258 char *av[2];
259
260 agid = bgid = 0;
261 if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP]))
262 {
263 bgid = atoi(before[L_GID]);
264 bhide = atoi(before[L_HIDDEN]);
8ec23c21 265 }
5eaef520 266 if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP]))
267 {
268 agid = atoi(after[L_GID]);
269 ahide = atoi(after[L_HIDDEN]);
8ec23c21 270 }
fb8809f4 271
5eaef520 272 if (agid == 0 && bgid == 0) /* Not active groups */
273 return;
60c22e5f 274
5eaef520 275 if (agid && bgid)
276 {
277 if (strcmp(after[L_NAME], before[L_NAME]))
278 {
279 /* Only a modify is required */
280 strcpy(g1, "system:");
281 strcpy(g2, "system:");
282 strcat(g1, before[L_NAME]);
283 strcat(g2, after[L_NAME]);
284
285 com_err(whoami, 0, "Changing group %s (gid %d) to %s (gid %d)",
286 before[L_NAME], bgid, after[L_NAME], agid);
287
288 code = pr_try(pr_ChangeEntry, g1, g2, -agid, "");
289 if (code)
290 {
a816420b 291 critical_alert(whoami, "incremental", "Couldn't change group %s (id %d) "
5eaef520 292 "to %s (id %d): %s", before[L_NAME], -bgid,
293 after[L_NAME], -agid, error_message(code));
8ec23c21 294 }
295 }
5eaef520 296 if (ahide != bhide)
297 {
298 com_err(whoami, 0, "Making group %s (gid %d) %s", after[L_NAME],
299 agid, (ahide ? "hidden" : "visible"));
300 code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS,
301 (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>
302 PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/);
303 if (code)
304 {
a816420b 305 critical_alert(whoami, "incremental",
5eaef520 306 "Couldn't set flags of group %s: %s",
307 after[L_NAME], error_message(code));
8ec23c21 308 }
60c22e5f 309 }
5eaef520 310 return;
fb8809f4 311 }
5eaef520 312 if (bgid)
313 {
314 com_err(whoami, 0, "Deleting group %s (gid %d)", before[L_NAME], bgid);
315 code = pr_try(pr_DeleteByID, -bgid);
316 if (code && code != PRNOENT)
317 {
a816420b 318 critical_alert(whoami, "incremental",
5eaef520 319 "Couldn't delete group %s (id %d): %s",
320 before[L_NAME], -bgid, error_message(code));
60c22e5f 321 }
5eaef520 322 return;
fb8809f4 323 }
5eaef520 324 if (agid)
325 {
326 strcpy(g1, "system:");
327 strcat(g1, after[L_NAME]);
328 strcpy(g2, "system:administrators");
329 id = -agid;
330 com_err(whoami, 0, "Creating %s group %s (gid %d)",
331 (ahide ? "hidden" : "visible"), after[L_NAME], agid);
332 code = pr_try(pr_CreateGroup, g1, g2, &id);
333 if (code == PRIDEXIST)
334 {
dfaf9b68 335 char ename[PR_MAXNAMELEN];
5eaef520 336
337 if (pr_try(pr_SIdToName, -agid, ename) == 0 && !strcmp(g1, ename))
60c22e5f 338 return;
339 }
5eaef520 340 if (code)
341 {
a816420b 342 critical_alert(whoami, "incremental", "Couldn't create group %s (id %d): %s",
5eaef520 343 after[L_NAME], id, error_message(code));
344 return;
345 }
346 if (ahide)
347 {
348 code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS,
349 (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>
350 PRIVATE_SHIFT, 0 /*ngroups*/, 0 /*nusers*/);
351 if (code)
352 {
a816420b 353 critical_alert(whoami, "incremental",
5eaef520 354 "Couldn't set flags of group %s: %s",
355 after[L_NAME], error_message(code));
8ec23c21 356 }
357 }
60c22e5f 358
5eaef520 359 /* We need to make sure the group is properly populated */
360 if (beforec < L_ACTIVE)
361 return;
60c22e5f 362
5eaef520 363 code = moira_connect();
364 if (code)
365 {
a816420b 366 critical_alert(whoami, "incremental",
5eaef520 367 "Error contacting Moira server to resolve %s: %s",
368 after[L_NAME], error_message(code));
369 return;
ed9a5300 370 }
5eaef520 371 av[0] = after[L_NAME];
372 code = mr_query("get_end_members_of_list", 1, av,
373 add_list_members, after[L_NAME]);
374 if (code)
375 {
a816420b 376 critical_alert(whoami, "incremental",
5eaef520 377 "Couldn't retrieve full membership of list %s: %s",
378 after[L_NAME], error_message(code));
379 }
380 moira_disconnect();
381 return;
60c22e5f 382 }
fb8809f4 383}
384
385
5eaef520 386
f2cf09f5 387#define LM_EXTRA_ACTIVE (LM_END)
388#define LM_EXTRA_PUBLIC (LM_END+1)
389#define LM_EXTRA_HIDDEN (LM_END+2)
390#define LM_EXTRA_MAILLIST (LM_END+3)
391#define LM_EXTRA_GROUP (LM_END+4)
392#define LM_EXTRA_GID (LM_END+5)
393#define LM_EXTRA_END (LM_END+6)
394
7ac48069 395void do_member(char **before, int beforec, char **after, int afterc)
fb8809f4 396{
5eaef520 397 if (afterc)
398 {
399 if (afterc < LM_EXTRA_END)
400 return;
401 else
402 {
a859d2ed 403 if (!atoi(after[LM_EXTRA_ACTIVE]) || !atoi(after[LM_EXTRA_GROUP]))
f2cf09f5 404 return;
5eaef520 405 }
406
407 edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]);
408 }
409 else if (beforec)
410 {
411 if (beforec < LM_EXTRA_END)
412 return;
413 else
414 {
a859d2ed 415 if (!atoi(before[LM_EXTRA_ACTIVE]) || !atoi(before[LM_EXTRA_GROUP]))
f2cf09f5 416 return;
5eaef520 417 }
418 edit_group(0, before[LM_LIST], before[LM_TYPE], before[LM_MEMBER]);
f2cf09f5 419 }
ed9a5300 420}
421
422
7ac48069 423void do_filesys(char **before, int beforec, char **after, int afterc)
eb63ae5f 424{
5eaef520 425 char cmd[1024];
426 int acreate, atype, bcreate, btype;
89e513d9 427
5eaef520 428 if (afterc < FS_CREATE)
429 atype = acreate = 0;
430 else
431 {
432 atype = !strcmp(after[FS_TYPE], "AFS");
433 acreate = atoi(after[FS_CREATE]);
434 }
eb63ae5f 435
5eaef520 436 if (beforec < FS_CREATE)
437 {
438 if (acreate == 0 || atype == 0)
eb63ae5f 439 return;
5eaef520 440
441 /* new locker creation */
442 sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s",
443 BIN_DIR, BIN_DIR, BIN_DIR,
444 after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE],
445 after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]);
446 run_cmd(cmd);
447 return;
eb63ae5f 448 }
5eaef520 449
450 btype = !strcmp(before[FS_TYPE], "AFS");
451 bcreate = atoi(before[FS_CREATE]);
452 if (afterc < FS_CREATE)
453 {
454 if (btype && bcreate)
a816420b 455 critical_alert(whoami, "incremental", "Cannot delete AFS filesystem %s: "
5eaef520 456 "Operation not supported", before[FS_NAME]);
457 return;
eb63ae5f 458 }
3b1e9c5f 459
5eaef520 460 if (!acreate)
461 return;
462
463 /* Are we dealing with AFS lockers (could be type ERR lockers) */
464 if (!atype && !btype)
465 {
466 if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR"))
3b1e9c5f 467 return;
5eaef520 468 }
3b1e9c5f 469
5eaef520 470 /* By now, we know we are simply changing AFS filesystem attributes.
471 * Operations supported:
472 * Name change: rename/remount
473 * Path change: remount
474 * Type change: ERR<-->AFS
475 */
0f82335a 476
477#if 0
5eaef520 478 if (strcmp(before[FS_OWNER], after[FS_OWNER]) ||
479 strcmp(before[FS_OWNERS], after[FS_OWNERS]))
3b1e9c5f 480 {
a816420b 481 critical_alert(whoami, "incremental",
5eaef520 482 "Cannot change ownership of filesystem %s: Operation not yet supported",
483 after[FS_NAME]);
3b1e9c5f 484 }
0f82335a 485#endif
3b1e9c5f 486
5eaef520 487 sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s",
488 BIN_DIR, BIN_DIR, BIN_DIR,
489 before[FS_NAME], before[FS_MACHINE], before[FS_TYPE],
490 before[FS_L_TYPE], before[FS_PACK],
491 after[FS_NAME], after[FS_MACHINE], after[FS_TYPE],
492 after[FS_L_TYPE], after[FS_PACK]);
493 run_cmd(cmd);
eb63ae5f 494}
495
496
7ac48069 497void do_quota(char **before, int beforec, char **after, int afterc)
eb63ae5f 498{
5eaef520 499 char cmd[1024];
eb63ae5f 500
5eaef520 501 if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) ||
502 strncmp("/afs/", after[Q_DIRECTORY], 5))
eb63ae5f 503 return;
5eaef520 504
505 sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s",
506 BIN_DIR, BIN_DIR, BIN_DIR,
507 after[Q_DIRECTORY], after[Q_QUOTA]);
508 run_cmd(cmd);
509 return;
eb63ae5f 510}
511
512
7ac48069 513void run_cmd(char *cmd)
eb63ae5f 514{
5eaef520 515 int success=0, tries=0;
516
517 check_afs();
518
519 while (success == 0 && tries < 2)
520 {
521 if (tries++)
522 sleep(90);
523 com_err(whoami, 0, "Executing command: %s", cmd);
524 if (system(cmd) == 0)
525 success++;
eb63ae5f 526 }
5eaef520 527 if (!success)
a816420b 528 critical_alert(whoami, "incremental", "failed command: %s", cmd);
eb63ae5f 529}
530
531
7ac48069 532int add_user_lists(int ac, char **av, void *user)
eb63ae5f 533{
5eaef520 534 if (atoi(av[L_ACTIVE]) && atoi(av[L_GROUP])) /* active group ? */
535 edit_group(1, av[L_NAME], "USER", user);
536 return 0;
eb63ae5f 537}
538
539
7ac48069 540int add_list_members(int ac, char **av, void *group)
ed9a5300 541{
5eaef520 542 edit_group(1, group, av[0], av[1]);
543 return 0;
ed9a5300 544}
545
7ac48069 546int check_user(int ac, char **av, void *ustate)
c69d9f2c 547{
7ac48069 548 *(int *)ustate = atoi(av[U_STATE]);
5eaef520 549 return 0;
c69d9f2c 550}
551
552
7ac48069 553void edit_group(int op, char *group, char *type, char *member)
ed9a5300 554{
5eaef520 555 char *p = 0;
556 char buf[PR_MAXNAMELEN];
557 int code, ustate;
cb974713 558 static char *local_realm = NULL;
5eaef520 559 struct member *m;
cb974713 560 krb5_context context = NULL;
5eaef520 561
562 /* The following KERBEROS code allows for the use of entities
563 * user@foreign_cell.
564 */
cb974713 565 if (!local_realm)
566 {
567 code = krb5_init_context(&context);
568 if (code)
569 goto out;
570
571 code = krb5_get_default_realm(context, &local_realm);
572 if (code)
573 goto out;
574 }
575
5eaef520 576 if (!strcmp(type, "KERBEROS"))
577 {
578 p = strchr(member, '@');
579 if (p && !strcasecmp(p+1, local_realm))
580 *p = 0;
581 }
582 else if (strcmp(type, "USER"))
583 return; /* invalid type */
584
585 /* Cannot risk doing another query during a callback */
586 /* We could do this simply for type USER, but eventually this may also
587 * dynamically add KERBEROS types to the prdb, and we will need to do
588 * a query to look up the uid of the null-instance user */
589 if (mr_connections)
590 {
591 m = malloc(sizeof(struct member));
592 if (!m)
593 {
a816420b 594 critical_alert(whoami, "incremental", "Out of memory");
5eaef520 595 exit(1);
2cb1f02c 596 }
5eaef520 597 m->op = op;
598 strcpy(m->list, group);
599 strcpy(m->type, type);
600 strcpy(m->member, member);
601 m->next = member_head;
602 member_head = m;
603 return;
2cb1f02c 604 }
605
5eaef520 606 strcpy(buf, "system:");
607 strcat(buf, group);
608 com_err(whoami, 0, "%s %s %s group %s", (op ? "Adding" : "Removing"), member,
609 (op ? "to" : "from"), group);
610 code = pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf);
611 if (code)
612 {
613 if (op==1 && code == PRIDEXIST)
614 return; /* Already added */
615
616 if (code == PRNOENT)
617 { /* Something is missing */
618 if (op == 0)
619 return; /* Already deleted */
620 if (!strcmp(type, "KERBEROS")) /* Special instances; ok */
621 return;
622
623 /* Check whether the member being added is an active user */
624 code = moira_connect();
625 if (!code)
626 {
627 code = mr_query("get_user_by_login", 1, &member,
628 check_user, (char *) &ustate);
629 }
630 if (code)
631 {
a816420b 632 critical_alert(whoami, "incremental", "Error contacting Moira server "
5eaef520 633 "to lookup user %s: %s", member,
634 error_message(code));
c69d9f2c 635 }
6250582e 636
5eaef520 637 /* We don't use moira_disconnect()
638 * because we may already be in the routine.
639 */
640 mr_disconnect();
641 mr_connections--;
6250582e 642
5eaef520 643 if (!code && ustate!=1 && ustate!=2)
644 return; /* inactive user */
645 code = PRNOENT;
60c22e5f 646 }
c69d9f2c 647
cb974713 648 out:
649 if (context)
650 krb5_free_context(context);
651 if (local_realm)
652 free(local_realm);
653
a816420b 654 critical_alert(whoami, "incremental", "Couldn't %s %s %s %s: %s",
5eaef520 655 op ? "add" : "remove", member,
656 op ? "to" : "from", buf,
657 error_message(code));
57bc9f26 658 }
fb8809f4 659}
660
661
5eaef520 662long pr_try(long (*fn)(), char *a1, char *a2, char *a3, char *a4, char *a5,
663 char *a6, char *a7, char *a8)
fb8809f4 664{
5eaef520 665 static int initd = 0;
44d12d58 666 long code;
667 int tries = 0;
eb63ae5f 668
5eaef520 669 check_afs();
d4ea75d6 670
5eaef520 671 if (initd)
672 code = pr_Initialize(0, AFSCONF_CLIENTNAME, 0);
673 else
674 {
675 code = 0;
676 initd = 1;
9b9540a1 677 }
5eaef520 678 if (!code)
679 code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
680 if (code)
681 {
a816420b 682 critical_alert(whoami, "incremental", "Couldn't initialize libprot: %s",
5eaef520 683 error_message(code));
7ac48069 684 return code;
7fca28a9 685 }
686
5eaef520 687 sleep(1); /* give ptserver room */
688
7ac48069 689 while ((code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)))
5eaef520 690 {
691 if (++tries > 2)
692 break; /* 3 tries */
693
694 if (code == UNOQUORUM)
695 sleep(90);
ca72bfeb 696 else if (code == PRPERM)
697 system("/bin/athena/aklog");
5eaef520 698 else
699 sleep(15);
700
701 /* Re-initialize the prdb connection */
702 code = pr_Initialize(0, AFSCONF_CLIENTNAME, 0);
703 if (!code)
704 code = pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
705 if (code)
706 {
a816420b 707 critical_alert(whoami, "incremental", "Couldn't re-initialize libprot: %s",
5eaef520 708 error_message(code));
709 initd = 0; /* we lost */
710 break;
16838ad1 711 }
9b9540a1 712 }
5eaef520 713 return code;
fb8809f4 714}
715
716
7ac48069 717void check_afs(void)
fb8809f4 718{
5eaef520 719 int i;
720
721 for (i = 0; file_exists(STOP_FILE); i++)
722 {
723 if (i > 30)
724 {
a816420b 725 critical_alert(whoami, "incremental",
5eaef520 726 "AFS incremental failed (%s exists): %s",
727 STOP_FILE, tbl_buf);
728 exit(1);
eb63ae5f 729 }
5eaef520 730 sleep(60);
eb63ae5f 731 }
fb8809f4 732}
14d69e25 733
734
5eaef520 735int moira_connect(void)
14d69e25 736{
5eaef520 737 long code;
738
739 if (!mr_connections++)
740 {
7ac48069 741 struct utsname uts;
742 uname(&uts);
743 code = mr_connect(uts.nodename);
5eaef520 744 if (!code)
991417e4 745 code = mr_krb5_auth("afs.incr");
5eaef520 746 return code;
14d69e25 747 }
5eaef520 748 return 0;
14d69e25 749}
750
5eaef520 751int moira_disconnect(void)
14d69e25 752{
5eaef520 753 struct member *m;
754
755 if (!--mr_connections)
756 {
757 mr_disconnect();
7ac48069 758 while ((m = member_head))
5eaef520 759 {
760 edit_group(m->op, m->list, m->type, m->member);
761 member_head = m->next;
762 free(m);
2cb1f02c 763 }
14d69e25 764 }
5eaef520 765 return 0;
14d69e25 766}
This page took 0.237019 seconds and 5 git commands to generate.