2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/utime.h>
18 #endif /* AFS_NT40_ENV */
23 #include <afs/cellconfig.h>
25 #include <afs/afsutil.h>
26 #include <afs/fileutil.h>
27 #include <afs/ktime.h>
28 #include <afs/audit.h>
29 #include <afs/kautils.h>
32 #include "bnode_internal.h"
34 #include "bosprototypes.h"
36 extern struct ktime bozo_nextRestartKT, bozo_nextDayKT;
38 extern struct afsconf_dir *bozo_confdir;
39 extern int bozo_newKTs;
41 extern int bozo_isrestricted;
44 SBOZO_GetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
48 code = 0; /* assume success */
51 memcpy(aktime, &bozo_nextRestartKT, sizeof(struct ktime));
55 memcpy(aktime, &bozo_nextDayKT, sizeof(struct ktime));
67 SBOZO_SetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
70 char caller[MAXKTCNAMELEN];
72 /* check for proper permissions */
73 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
78 bozo_Log("%s is executing SetRestartTime\n", caller);
80 code = 0; /* assume success */
83 memcpy(&bozo_nextRestartKT, aktime, sizeof(struct ktime));
87 memcpy(&bozo_nextDayKT, aktime, sizeof(struct ktime));
96 /* try to update the bozo init file */
97 code = WriteBozoFile(0);
102 osi_auditU(acall, BOS_SetRestartEvent, code, AUD_END);
107 SBOZO_Exec(struct rx_call *acall, char *acmd)
110 char caller[MAXKTCNAMELEN];
113 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
117 if (bozo_isrestricted) {
122 bozo_Log("%s is executing the shell command '%s'\n", caller, acmd);
124 /* should copy output to acall, but don't yet cause its hard */
125 /* hard... NOT! Nnow _at least_ return the exit status */
127 osi_auditU(acall, BOS_ExecEvent, code, AUD_STR, acmd, AUD_END);
134 SBOZO_GetDates(struct rx_call *acall, char *aname, afs_int32 *atime,
135 afs_int32 *abakTime, afs_int32 *aoldTime)
139 char tbuffer[AFSDIR_PATH_MAX];
141 *atime = *abakTime = *aoldTime = 0;
143 /* construct local path from canonical (wire-format) path */
144 if (ConstructLocalBinPath(aname, &strp)) {
147 strcpy(tbuffer, strp);
150 strp = tbuffer + strlen(tbuffer);
152 if (!stat(tbuffer, &tstat)) {
153 *atime = tstat.st_mtime;
156 strcpy(strp, ".BAK");
157 if (!stat(tbuffer, &tstat)) {
158 *abakTime = tstat.st_mtime;
161 strcpy(strp, ".OLD");
162 if (!stat(tbuffer, &tstat)) {
163 *aoldTime = tstat.st_mtime;
169 SBOZO_UnInstall(struct rx_call *acall, char *aname)
172 char fpOld[AFSDIR_PATH_MAX], fpBak[AFSDIR_PATH_MAX];
174 char caller[MAXKTCNAMELEN];
177 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
179 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
182 if (bozo_isrestricted) {
184 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
188 /* construct local path from canonical (wire-format) path */
189 if (ConstructLocalBinPath(aname, &filepath)) {
194 bozo_Log("%s is executing UnInstall '%s'\n", caller, filepath);
196 strcpy(fpBak, filepath);
197 strcat(fpBak, ".BAK");
198 strcpy(fpOld, filepath);
199 strcat(fpOld, ".OLD");
201 code = rk_rename(fpBak, filepath);
203 /* can't find .BAK, try .OLD */
204 code = rk_rename(fpOld, filepath);
205 if (code && errno == ENOENT) /* If doesn't exist don't fail */
208 /* now rename .OLD to .BAK */
209 if (stat(fpOld, &tstat) == 0)
210 code = rk_rename(fpOld, fpBak);
215 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, filepath, AUD_END);
221 #define BOZO_OLDTIME (7*24*3600) /* 7 days old */
223 SaveOldFiles(char *aname)
226 char bbuffer[AFSDIR_PATH_MAX], obuffer[AFSDIR_PATH_MAX];
229 afs_int32 oldTime, bakTime;
231 strcpy(bbuffer, aname);
232 strcat(bbuffer, ".BAK");
233 strcpy(obuffer, aname);
234 strcat(obuffer, ".OLD");
235 now = FT_ApproxTime();
237 code = stat(aname, &tstat);
239 return; /* can't stat file */
241 code = stat(obuffer, &tstat); /* discover old file's time */
245 oldTime = tstat.st_mtime;
247 code = stat(bbuffer, &tstat); /* discover back file's time */
251 bakTime = tstat.st_mtime;
253 if (bakTime && (oldTime == 0 || bakTime < now - BOZO_OLDTIME)) {
254 /* no .OLD file, or .BAK is at least a week old */
255 rk_rename(bbuffer, obuffer);
258 /* finally rename to .BAK extension */
259 rk_rename(aname, bbuffer);
263 SBOZO_Install(struct rx_call *acall, char *aname, afs_int32 asize, afs_int32 mode, afs_int32 amtime)
270 struct _utimbuf utbuf;
272 struct timeval tvb[2];
274 char filepath[AFSDIR_PATH_MAX], tbuffer[AFSDIR_PATH_MAX], *fpp;
275 char caller[MAXKTCNAMELEN];
277 if (!afsconf_SuperUser(bozo_confdir, acall, caller))
279 if (bozo_isrestricted)
282 /* construct local path from canonical (wire-format) path */
283 if (ConstructLocalBinPath(aname, &fpp)) {
286 strcpy(filepath, fpp);
290 bozo_Log("%s is executing Install '%s'\n", caller, filepath);
293 fpp = filepath + strlen(filepath);
294 strcpy(fpp, ".NEW"); /* append ".NEW" to end of filepath */
295 fd = open(filepath, O_CREAT | O_RDWR | O_TRUNC, 0777);
300 len = rx_Read(acall, tbuffer, sizeof(tbuffer));
307 break; /* no more input */
308 code = write(fd, tbuffer, len);
314 total += len; /* track total written for safety check at end */
317 if (asize != total) {
319 return 101; /* wrong size */
323 *fpp = '\0'; /* remove ".NEW" from end of filepath */
324 SaveOldFiles(filepath); /* don't care if it works, still install */
326 /* all done, rename to final name */
327 strcpy(tbuffer, filepath);
328 strcat(tbuffer, ".NEW");
329 code = (rk_rename(tbuffer, filepath) ? errno : 0);
331 /* label file with same time for our sanity */
333 utbuf.actime = utbuf.modtime = amtime;
334 _utime(filepath, &utbuf);
336 tvb[0].tv_sec = tvb[1].tv_sec = amtime;
337 tvb[0].tv_usec = tvb[1].tv_usec = 0;
338 utimes(filepath, tvb);
339 #endif /* AFS_NT40_ENV */
342 chmod(filepath, mode);
345 osi_auditU(acall, BOS_InstallEvent, code, AUD_STR, filepath, AUD_END);
352 SBOZO_SetCellName(struct rx_call *acall, char *aname)
354 struct afsconf_cell tcell;
356 char caller[MAXKTCNAMELEN];
357 char clones[MAXHOSTSPERCELL];
359 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
364 bozo_Log("%s is executing SetCellName '%s'\n", caller, aname);
367 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
372 /* Check that tcell has enough space for the new cellname. */
373 if (strlen(aname) > sizeof tcell.name - 1) {
375 ("ERROR: SetCellName: cell name '%s' exceeds %ld bytes (cell name not changed)\n",
376 aname, (long)(sizeof tcell.name - 1));
381 strcpy(tcell.name, aname);
383 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
387 osi_auditU(acall, BOS_SetCellEvent, code, AUD_STR, aname, AUD_END);
392 SBOZO_GetCellName(struct rx_call *acall, char **aname)
395 char tname[MAXCELLCHARS];
397 code = afsconf_GetLocalCell(bozo_confdir, tname, sizeof(tname));
399 /* must set output parameters even if aborting */
403 *aname = strdup(tname);
410 SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
413 struct afsconf_cell tcell;
415 char clones[MAXHOSTSPERCELL];
418 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
423 if (awhich >= tcell.numServers) {
428 tp = tcell.hostName[awhich];
429 if (clones[awhich]) {
430 asprintf(aname, "[%s]", tp);
436 *aname = malloc(1); /* return fake string */
444 SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
447 struct afsconf_cell tcell;
450 char caller[MAXKTCNAMELEN];
451 char clones[MAXHOSTSPERCELL];
453 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
458 bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname);
461 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
467 for (i = 0; i < tcell.numServers; i++) {
468 if (strcmp(tcell.hostName[i], aname) == 0) {
479 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
480 memset(tcell.hostName[which], 0, MAXHOSTCHARS);
482 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
486 osi_auditU(acall, BOS_DeleteHostEvent, code, AUD_STR, aname, AUD_END);
491 SBOZO_AddCellHost(struct rx_call *acall, char *aname)
494 struct afsconf_cell tcell;
497 char caller[MAXKTCNAMELEN];
498 char clones[MAXHOSTSPERCELL];
502 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
507 bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname);
510 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
517 *(n + strlen(n) - 1) = 0;
523 for (i = 0; i < tcell.numServers; i++) {
524 if (strcmp(tcell.hostName[i], n) == 0) {
530 which = tcell.numServers;
534 * Check that tcell has enough space for an additional host.
536 * We assume that tcell.hostAddr[] and tcell.hostName[] have the
537 * same number of entries.
539 if (tcell.numServers >
540 sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]) {
542 ("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n",
543 (long)(sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]),
549 /* Check that tcell has enough space for the new hostname. */
550 if (strlen(aname) > sizeof tcell.hostName[0] - 1) {
552 ("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n",
553 aname, (long)(sizeof tcell.hostName[0] - 1));
559 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
560 strcpy(tcell.hostName[which], n);
561 clones[which] = isClone;
563 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
567 osi_auditU(acall, BOS_AddHostEvent, code, AUD_STR, aname, AUD_END);
572 SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
573 struct bozo_key *akey, struct bozo_keyInfo *akeyinfo)
575 struct afsconf_keys tkeys;
579 char caller[MAXKTCNAMELEN];
580 rxkad_level enc_level = rxkad_clear;
582 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
587 bozo_Log("%s is executing ListKeys\n", caller);
589 code = afsconf_GetKeys(bozo_confdir, &tkeys);
593 if (tkeys.nkeys <= an) {
597 *akvno = tkeys.key[an].kvno;
598 memset(akeyinfo, 0, sizeof(struct bozo_keyInfo));
600 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
601 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
603 * only return actual keys in noauth or if this is an encrypted connection
606 if ((noauth) || (enc_level == rxkad_crypt)) {
607 memcpy(akey, tkeys.key[an].key, 8);
611 code = stat(AFSDIR_SERVER_KEY_FILEPATH, &tstat);
613 akeyinfo->mod_sec = tstat.st_mtime;
616 /* This will return an error if the key is 'bad' (bad checksum, weak DES
617 * key, etc). But we don't care, since we can still return the other
618 * information about the key, so ignore the result. */
619 (void)ka_KeyCheckSum(tkeys.key[an].key, &akeyinfo->keyCheckSum);
623 osi_auditU(acall, BOS_UnAuthListKeysEvent, code, AUD_END);
624 osi_auditU(acall, BOS_ListKeysEvent, code, AUD_END);
629 SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
632 char caller[MAXKTCNAMELEN];
633 rxkad_level enc_level = rxkad_clear;
636 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
640 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
641 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
642 if ((!noauth) && (enc_level != rxkad_crypt)) {
647 bozo_Log("%s is executing AddKey\n", caller);
649 code = afsconf_AddKey(bozo_confdir, an, akey->data, 0);
650 if (code == AFSCONF_KEYINUSE)
651 code = BZKEYINUSE; /* Unique code for afs rpc calls */
653 osi_auditU(acall, BOS_AddKeyEvent, code, AUD_END);
658 SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag)
661 char caller[MAXKTCNAMELEN];
663 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
668 bozo_Log("%s is executing Set No Authentication\n", caller);
670 afsconf_SetNoAuthFlag(bozo_confdir, aflag);
673 osi_auditU(acall, BOS_SetNoAuthEvent, code, AUD_LONG, aflag, AUD_END);
678 SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
681 char caller[MAXKTCNAMELEN];
683 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
688 bozo_Log("%s is executing DeleteKey\n", caller);
690 code = afsconf_DeleteKey(bozo_confdir, an);
693 osi_auditU(acall, BOS_DeleteKeyEvent, code, AUD_END);
699 SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, char **aname)
704 tp = *aname = malloc(256);
705 *tp = 0; /* in case getnthuser doesn't null-terminate the string */
706 code = afsconf_GetNthUser(bozo_confdir, an, tp, 256);
709 osi_auditU(acall, BOS_ListSUserEvent, code, AUD_END);
714 SBOZO_AddSUser(struct rx_call *acall, char *aname)
717 char caller[MAXKTCNAMELEN];
719 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
724 bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname);
726 code = afsconf_AddUser(bozo_confdir, aname);
729 osi_auditU(acall, BOS_AddSUserEvent, code, AUD_END);
734 SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
737 char caller[MAXKTCNAMELEN];
739 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
745 bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname);
747 code = afsconf_DeleteUser(bozo_confdir, aname);
750 osi_auditU(acall, BOS_DeleteSUserEvent, code, AUD_END);
755 SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
756 char *ap1, char *ap2, char *ap3, char *ap4, char *ap5,
761 char caller[MAXKTCNAMELEN];
763 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
767 if (bozo_isrestricted) {
768 const char *salvpath = AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH;
769 /* for DAFS, 'bos salvage' will pass "salvageserver -client" instead */
770 const char *salsrvpath = AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH " -client ";
772 /* still allow 'bos salvage' to work */
773 if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp")
774 || strcmp(ap2, "now")
775 || (strncmp(ap1, salvpath, strlen(salvpath))
776 && strncmp(ap1, salsrvpath, strlen(salsrvpath)))) {
784 bnode_Create(atype, ainstance, &tb, ap1, ap2, ap3, ap4, ap5, notifier,
787 bnode_SetStat(tb, BSTAT_NORMAL);
790 osi_auditU(acall, BOS_CreateBnodeEvent, code, AUD_END);
795 SBOZO_WaitAll(struct rx_call *acall)
798 char caller[MAXKTCNAMELEN];
800 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
806 bozo_Log("%s is executing Wait for All\n", caller);
808 code = bnode_WaitAll();
811 osi_auditU(acall, BOS_WaitAllEvent, code, AUD_END);
816 SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
819 char caller[MAXKTCNAMELEN];
821 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
825 if (bozo_isrestricted) {
830 bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance);
832 code = bnode_DeleteName(ainstance);
835 osi_auditU(acall, BOS_DeleteBnodeEvent, code, AUD_STR, ainstance,
841 swproc(struct bnode *abnode, void *arock)
843 if (abnode->goal == BSTAT_NORMAL)
844 return 0; /* this one's not shutting down */
845 /* otherwise, we are shutting down */
847 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
848 bnode_Release(abnode);
849 return 0; /* don't stop apply function early, no matter what */
853 stproc(struct bnode *abnode, void *arock)
855 if (abnode->fileGoal == BSTAT_SHUTDOWN)
856 return 0; /* don't do these guys */
859 bnode_ResetErrorCount(abnode);
860 bnode_SetStat(abnode, BSTAT_NORMAL);
861 bnode_Release(abnode);
866 sdproc(struct bnode *abnode, void *arock)
869 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
870 bnode_Release(abnode);
874 /* shutdown and leave down */
876 SBOZO_ShutdownAll(struct rx_call *acall)
878 /* iterate over all bnodes, setting the status to temporarily disabled */
880 char caller[MAXKTCNAMELEN];
882 /* check for authorization */
883 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
888 bozo_Log("%s is executing ShutdownAll\n", caller);
890 code = bnode_ApplyInstance(sdproc, NULL);
893 osi_auditU(acall, BOS_ShutdownAllEvent, code, AUD_END);
897 /* shutdown and restart */
899 SBOZO_RestartAll(struct rx_call *acall)
902 char caller[MAXKTCNAMELEN];
904 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
909 bozo_Log("%s is executing RestartAll\n", caller);
911 /* start shutdown of all processes */
912 code = bnode_ApplyInstance(sdproc, NULL);
916 /* wait for all done */
917 code = bnode_ApplyInstance(swproc, NULL);
921 /* start them up again */
922 code = bnode_ApplyInstance(stproc, NULL);
925 osi_auditU(acall, BOS_RestartAllEvent, code, AUD_END);
930 SBOZO_ReBozo(struct rx_call *acall)
933 char caller[MAXKTCNAMELEN];
935 /* acall is null if called internally to restart bosserver */
936 if (acall && !afsconf_SuperUser(bozo_confdir, acall, caller)) {
941 bozo_Log("%s is executing ReBozo\n", caller);
943 /* start shutdown of all processes */
944 code = bnode_ApplyInstance(sdproc, NULL);
948 /* wait for all done */
949 code = bnode_ApplyInstance(swproc, NULL);
954 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
956 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
959 rx_EndCall(acall, 0); /* try to get it done */
961 bozo_ReBozo(); /* this reexecs us, and doesn't return, of course */
964 /* Differentiate between external and internal ReBozo; prevents AFS_Aud_NoCall event */
966 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
968 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
969 return code; /* should only get here in unusual circumstances */
972 /* make sure all are running */
974 SBOZO_StartupAll(struct rx_call *acall)
977 char caller[MAXKTCNAMELEN];
979 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
984 bozo_Log("%s is executing StartupAll\n", caller);
985 code = bnode_ApplyInstance(stproc, NULL);
988 osi_auditU(acall, BOS_StartupAllEvent, code, AUD_END);
993 SBOZO_Restart(struct rx_call *acall, char *ainstance)
997 char caller[MAXKTCNAMELEN];
999 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1004 bozo_Log("%s is executing Restart '%s'\n", caller, ainstance);
1006 tb = bnode_FindInstance(ainstance);
1013 bnode_SetStat(tb, BSTAT_SHUTDOWN);
1014 code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN); /* this can fail */
1015 bnode_ResetErrorCount(tb);
1016 bnode_SetStat(tb, BSTAT_NORMAL);
1020 osi_auditU(acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
1024 /* set temp status */
1026 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1030 char caller[MAXKTCNAMELEN];
1032 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1037 bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
1039 tb = bnode_FindInstance(ainstance);
1045 bnode_ResetErrorCount(tb);
1046 code = bnode_SetStat(tb, astatus);
1050 osi_auditU(acall, BOS_SetTempStatusEvent, code, AUD_STR, ainstance,
1056 SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1060 char caller[MAXKTCNAMELEN];
1062 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1067 bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller,
1068 ainstance, astatus);
1070 tb = bnode_FindInstance(ainstance);
1076 bnode_SetFileGoal(tb, astatus);
1077 code = bnode_SetStat(tb, astatus);
1081 osi_auditU(acall, BOS_SetStatusEvent, code, AUD_STR, ainstance, AUD_END);
1086 SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat,
1092 tb = bnode_FindInstance(ainstance);
1099 code = bnode_GetStat(tb, astat);
1105 *astatDescr = malloc(BOZO_BSSIZE);
1106 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1109 (*astatDescr)[0] = 0; /* null string means no further info */
1113 *astatDescr = malloc(1);
1124 eifunc(struct bnode *abnode, void *param)
1126 struct eidata *arock = (struct eidata *)param;
1128 if (arock->counter-- == 0) {
1130 strcpy(arock->iname, abnode->name);
1139 ZapFile(const char *adir, const char *aname)
1142 if (snprintf(tbuffer, 256, "%s/%s", adir, aname)<256)
1143 return unlink(tbuffer);
1149 SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
1155 char caller[MAXKTCNAMELEN];
1157 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1161 if (bozo_isrestricted) {
1166 bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags);
1168 /* first scan AFS binary directory */
1169 dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH);
1171 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1172 i = strlen(tde->d_name);
1173 if (aflags & BOZO_PRUNEOLD) {
1174 if (i >= 4 && strncmp(tde->d_name + i - 4, ".OLD", 4) == 0)
1175 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1177 if (aflags & BOZO_PRUNEBAK) {
1178 if (i >= 4 && strncmp(tde->d_name + i - 4, ".BAK", 4) == 0)
1179 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1185 /* then scan AFS log directory */
1186 dirp = opendir(AFSDIR_SERVER_LOGS_DIRPATH);
1188 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1189 if (aflags & BOZO_PRUNECORE) {
1190 if (strncmp(tde->d_name, AFSDIR_CORE_FILE, 4) == 0)
1191 ZapFile(AFSDIR_SERVER_LOGS_DIRPATH, tde->d_name);
1199 osi_auditU(acall, BOS_PruneLogs, code, AUD_END);
1204 SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum,
1207 struct eidata tdata;
1209 *ainstance = malloc(BOZO_BSSIZE);
1211 tdata.counter = anum;
1212 tdata.iname = *ainstance;
1213 bnode_ApplyInstance(eifunc, &tdata);
1214 if (tdata.counter >= 0)
1215 return BZDOM; /* anum > # of actual instances */
1220 struct bozo_bosEntryStats bozo_bosEntryStats[] = {
1221 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_AFS_DIRPATH */
1222 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_ETC_DIRPATH */
1223 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_BIN_DIRPATH */
1224 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_LOGS_DIRPATH */
1225 {NULL, 1, 0, 0700, 07}, /* AFSDIR_SERVER_BACKUP_DIRPATH */
1226 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_DB_DIRPATH */
1227 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_LOCAL_DIRPATH */
1228 {NULL, 0, 1, 0600, 07}, /* AFSDIR_SERVER_KEY_FILEPATH */
1229 {NULL, 0, 1, 0600, 03}
1230 }; /* AFSDIR_SERVER_ULIST_FILEPATH */
1231 int bozo_nbosEntryStats =
1232 sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
1234 /* This function performs initialization of the bozo_bosEntrystats[]
1235 * array. This array contains the list of dirs that the bosserver
1236 * is interested in along with their recommended permissions
1237 * NOTE: This initialization is a bit ugly. This was caused because
1238 * the path names require procedural as opposed to static initialization.
1239 * The other fields in the struct are however, statically initialized.
1242 initBosEntryStats(void)
1244 bozo_bosEntryStats[0].path = AFSDIR_SERVER_AFS_DIRPATH;
1245 bozo_bosEntryStats[1].path = AFSDIR_SERVER_ETC_DIRPATH;
1246 bozo_bosEntryStats[2].path = AFSDIR_SERVER_BIN_DIRPATH;
1247 bozo_bosEntryStats[3].path = AFSDIR_SERVER_LOGS_DIRPATH;
1248 bozo_bosEntryStats[4].path = AFSDIR_SERVER_BACKUP_DIRPATH;
1249 bozo_bosEntryStats[5].path = AFSDIR_SERVER_DB_DIRPATH;
1250 bozo_bosEntryStats[6].path = AFSDIR_SERVER_LOCAL_DIRPATH;
1251 bozo_bosEntryStats[7].path = AFSDIR_SERVER_KEY_FILEPATH;
1252 bozo_bosEntryStats[8].path = AFSDIR_SERVER_ULIST_FILEPATH;
1257 /* StatEachEntry - If it's not there, it is okay. If anything else goes wrong
1258 * complain. Otherwise check permissions: shouldn't allow write or (usually)
1262 StatEachEntry(IN struct bozo_bosEntryStats *stats)
1265 if (stat(stats->path, &info)) {
1266 if (errno == ENOENT)
1267 return 1; /* no such entry: just ignore it */
1268 return 0; /* something else went wrong */
1271 if (((info.st_mode & S_IFDIR) != 0) != stats->dir)
1272 return 0; /* not expected type */
1273 if (stats->rootOwner && (info.st_uid != 0))
1274 return 0; /* not owned by root */
1275 rights = (info.st_mode & 0000777);
1276 if ((rights & stats->reqPerm) != stats->reqPerm)
1277 return 0; /* required permissions not present */
1278 if ((rights & stats->proPerm) != 0)
1279 return 0; /* prohibited permissions present */
1284 /* DirAccessOK - checks the mode bits on the AFS dir and decendents and
1285 * returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
1286 * this check more often than every 5 seconds. */
1292 /* underlying filesystem may not support directory protection */
1295 static afs_uint32 lastTime = 0;
1296 afs_uint32 now = FT_ApproxTime();
1297 static int lastResult = -1;
1301 if ((now - lastTime) < 5)
1306 for (i = 0; i < bozo_nbosEntryStats; i++) {
1307 struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i];
1308 if (!StatEachEntry(e)) {
1309 bozo_Log("unhappy with %s which is a %s that should "
1310 "have at least rights %o, at most rights %o %s\n",
1311 e->path, e->dir ? "dir" : "file", e->reqPerm,
1312 (~e->proPerm & 0777),
1313 e->rootOwner ? ", owned by root" : "");
1319 if (result != lastResult) { /* log changes */
1320 bozo_Log("Server directory access is %sokay\n",
1321 (result ? "" : "not "));
1323 lastResult = result;
1325 #endif /* AFS_NT40_ENV */
1329 GetRequiredDirPerm(const char *path)
1332 for (i = 0; i < bozo_nbosEntryStats; i++)
1333 if (strcmp(path, bozo_bosEntryStats[i].path) == 0)
1334 return bozo_bosEntryStats[i].reqPerm;
1339 SBOZO_GetInstanceInfo(IN struct rx_call *acall,
1342 OUT struct bozo_status *astatus)
1346 tb = bnode_FindInstance(ainstance);
1347 *atype = malloc(BOZO_BSSIZE);
1352 strcpy(*atype, tb->type->name);
1354 (*atype)[0] = 0; /* null string */
1355 memset(astatus, 0, sizeof(struct bozo_status)); /* good defaults */
1356 astatus->goal = tb->goal;
1357 astatus->fileGoal = tb->fileGoal;
1358 astatus->procStartTime = tb->procStartTime;
1359 astatus->procStarts = tb->procStarts;
1360 astatus->lastAnyExit = tb->lastAnyExit;
1361 astatus->lastErrorExit = tb->lastErrorExit;
1362 astatus->errorCode = tb->errorCode;
1363 astatus->errorSignal = tb->errorSignal;
1364 if (tb->flags & BNODE_ERRORSTOP)
1365 astatus->flags |= BOZO_ERRORSTOP;
1366 if (bnode_HasCore(tb))
1367 astatus->flags |= BOZO_HASCORE;
1369 astatus->flags |= BOZO_BADDIRACCESS;
1374 SBOZO_GetInstanceParm(struct rx_call *acall,
1383 tp = malloc(BOZO_BSSIZE);
1385 *tp = 0; /* null-terminate string in error case */
1386 tb = bnode_FindInstance(ainstance);
1392 memcpy(tp, tb->notifier, strlen(tb->notifier) + 1);
1395 code = BZNOENT; /* XXXXX */
1397 code = bnode_GetParm(tb, anum, tp, BOZO_BSSIZE);
1400 /* Not Currently Audited */
1405 SBOZO_GetLog(struct rx_call *acall, char *aname)
1412 char caller[MAXKTCNAMELEN];
1414 /* Check access since 'aname' could specify a file outside of the
1415 * AFS log directory (which is bosserver's working directory).
1417 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1421 if (bozo_isrestricted && strchr(aname, '/')
1422 && strcmp(aname, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH)) {
1427 /* construct local path from canonical (wire-format) path */
1428 if (ConstructLocalLogPath(aname, &logpath)) {
1432 bozo_Log("%s is executing GetLog '%s'\n", caller, logpath);
1433 tfile = fopen(logpath, "r");
1443 continue; /* our termination condition on other end */
1447 if (rx_Write(acall, &buffer, 1) != 1) {
1454 /* all done, cleanup and return */
1457 /* write out the end delimeter */
1459 if (rx_Write(acall, &buffer, 1) != 1)
1464 osi_auditU(acall, BOS_GetLogsEvent, code, AUD_END);
1469 SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
1470 char **as1, char **as2, char **as3, char **as4)
1480 tb = bnode_FindInstance(abnodeName);
1484 /* now, return the appropriate error string, if any */
1485 if (tb->lastErrorName) {
1486 *as1 = strdup(tb->lastErrorName);
1500 SBOZO_GetRestrictedMode(struct rx_call *acall, afs_int32 *arestmode)
1502 *arestmode = bozo_isrestricted;
1507 SBOZO_SetRestrictedMode(struct rx_call *acall, afs_int32 arestmode)
1510 char caller[MAXKTCNAMELEN];
1512 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1515 if (bozo_isrestricted) {
1518 if (arestmode != 0 && arestmode != 1) {
1521 bozo_isrestricted = arestmode;
1522 code = WriteBozoFile(0);
1528 bozo_ShutdownAndExit(void *param)
1530 int asignal = (intptr_t)param;
1534 ("Shutdown of BOS server and processes in response to signal %d\n",
1537 /* start shutdown of all processes */
1538 if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) {
1539 /* wait for shutdown to complete */
1540 code = bnode_ApplyInstance(swproc, NULL);
1544 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",