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;
615 ka_KeyCheckSum(tkeys.key[an].key, &akeyinfo->keyCheckSum);
616 /* only errors is bad key parity */
620 osi_auditU(acall, BOS_UnAuthListKeysEvent, code, AUD_END);
621 osi_auditU(acall, BOS_ListKeysEvent, code, AUD_END);
626 SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
629 char caller[MAXKTCNAMELEN];
630 rxkad_level enc_level = rxkad_clear;
633 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
637 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
638 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
639 if ((!noauth) && (enc_level != rxkad_crypt)) {
644 bozo_Log("%s is executing AddKey\n", caller);
646 code = afsconf_AddKey(bozo_confdir, an, akey->data, 0);
647 if (code == AFSCONF_KEYINUSE)
648 code = BZKEYINUSE; /* Unique code for afs rpc calls */
650 osi_auditU(acall, BOS_AddKeyEvent, code, AUD_END);
655 SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag)
658 char caller[MAXKTCNAMELEN];
660 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
665 bozo_Log("%s is executing Set No Authentication\n", caller);
667 afsconf_SetNoAuthFlag(bozo_confdir, aflag);
670 osi_auditU(acall, BOS_SetNoAuthEvent, code, AUD_LONG, aflag, AUD_END);
675 SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
678 char caller[MAXKTCNAMELEN];
680 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
685 bozo_Log("%s is executing DeleteKey\n", caller);
687 code = afsconf_DeleteKey(bozo_confdir, an);
690 osi_auditU(acall, BOS_DeleteKeyEvent, code, AUD_END);
696 SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, char **aname)
701 tp = *aname = malloc(256);
702 *tp = 0; /* in case getnthuser doesn't null-terminate the string */
703 code = afsconf_GetNthUser(bozo_confdir, an, tp, 256);
706 osi_auditU(acall, BOS_ListSUserEvent, code, AUD_END);
711 SBOZO_AddSUser(struct rx_call *acall, char *aname)
714 char caller[MAXKTCNAMELEN];
716 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
721 bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname);
723 code = afsconf_AddUser(bozo_confdir, aname);
726 osi_auditU(acall, BOS_AddSUserEvent, code, AUD_END);
731 SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
734 char caller[MAXKTCNAMELEN];
736 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
742 bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname);
744 code = afsconf_DeleteUser(bozo_confdir, aname);
747 osi_auditU(acall, BOS_DeleteSUserEvent, code, AUD_END);
752 SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
753 char *ap1, char *ap2, char *ap3, char *ap4, char *ap5,
758 char caller[MAXKTCNAMELEN];
760 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
764 if (bozo_isrestricted) {
765 const char *salvpath = AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH;
766 /* for DAFS, 'bos salvage' will pass "salvageserver -client" instead */
767 const char *salsrvpath = AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH " -client ";
769 /* still allow 'bos salvage' to work */
770 if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp")
771 || strcmp(ap2, "now")
772 || (strncmp(ap1, salvpath, strlen(salvpath))
773 && strncmp(ap1, salsrvpath, strlen(salsrvpath)))) {
781 bnode_Create(atype, ainstance, &tb, ap1, ap2, ap3, ap4, ap5, notifier,
784 bnode_SetStat(tb, BSTAT_NORMAL);
787 osi_auditU(acall, BOS_CreateBnodeEvent, code, AUD_END);
792 SBOZO_WaitAll(struct rx_call *acall)
795 char caller[MAXKTCNAMELEN];
797 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
803 bozo_Log("%s is executing Wait for All\n", caller);
805 code = bnode_WaitAll();
808 osi_auditU(acall, BOS_WaitAllEvent, code, AUD_END);
813 SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
816 char caller[MAXKTCNAMELEN];
818 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
822 if (bozo_isrestricted) {
827 bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance);
829 code = bnode_DeleteName(ainstance);
832 osi_auditU(acall, BOS_DeleteBnodeEvent, code, AUD_STR, ainstance,
838 swproc(struct bnode *abnode, void *arock)
840 if (abnode->goal == BSTAT_NORMAL)
841 return 0; /* this one's not shutting down */
842 /* otherwise, we are shutting down */
844 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
845 bnode_Release(abnode);
846 return 0; /* don't stop apply function early, no matter what */
850 stproc(struct bnode *abnode, void *arock)
852 if (abnode->fileGoal == BSTAT_SHUTDOWN)
853 return 0; /* don't do these guys */
856 bnode_ResetErrorCount(abnode);
857 bnode_SetStat(abnode, BSTAT_NORMAL);
858 bnode_Release(abnode);
863 sdproc(struct bnode *abnode, void *arock)
866 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
867 bnode_Release(abnode);
871 /* shutdown and leave down */
873 SBOZO_ShutdownAll(struct rx_call *acall)
875 /* iterate over all bnodes, setting the status to temporarily disabled */
877 char caller[MAXKTCNAMELEN];
879 /* check for authorization */
880 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
885 bozo_Log("%s is executing ShutdownAll\n", caller);
887 code = bnode_ApplyInstance(sdproc, NULL);
890 osi_auditU(acall, BOS_ShutdownAllEvent, code, AUD_END);
894 /* shutdown and restart */
896 SBOZO_RestartAll(struct rx_call *acall)
899 char caller[MAXKTCNAMELEN];
901 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
906 bozo_Log("%s is executing RestartAll\n", caller);
908 /* start shutdown of all processes */
909 code = bnode_ApplyInstance(sdproc, NULL);
913 /* wait for all done */
914 code = bnode_ApplyInstance(swproc, NULL);
918 /* start them up again */
919 code = bnode_ApplyInstance(stproc, NULL);
922 osi_auditU(acall, BOS_RestartAllEvent, code, AUD_END);
927 SBOZO_ReBozo(struct rx_call *acall)
930 char caller[MAXKTCNAMELEN];
932 /* acall is null if called internally to restart bosserver */
933 if (acall && !afsconf_SuperUser(bozo_confdir, acall, caller)) {
938 bozo_Log("%s is executing ReBozo\n", caller);
940 /* start shutdown of all processes */
941 code = bnode_ApplyInstance(sdproc, NULL);
945 /* wait for all done */
946 code = bnode_ApplyInstance(swproc, NULL);
951 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
953 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
956 rx_EndCall(acall, 0); /* try to get it done */
958 bozo_ReBozo(); /* this reexecs us, and doesn't return, of course */
961 /* Differentiate between external and internal ReBozo; prevents AFS_Aud_NoCall event */
963 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
965 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
966 return code; /* should only get here in unusual circumstances */
969 /* make sure all are running */
971 SBOZO_StartupAll(struct rx_call *acall)
974 char caller[MAXKTCNAMELEN];
976 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
981 bozo_Log("%s is executing StartupAll\n", caller);
982 code = bnode_ApplyInstance(stproc, NULL);
985 osi_auditU(acall, BOS_StartupAllEvent, code, AUD_END);
990 SBOZO_Restart(struct rx_call *acall, char *ainstance)
994 char caller[MAXKTCNAMELEN];
996 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1001 bozo_Log("%s is executing Restart '%s'\n", caller, ainstance);
1003 tb = bnode_FindInstance(ainstance);
1010 bnode_SetStat(tb, BSTAT_SHUTDOWN);
1011 code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN); /* this can fail */
1012 bnode_ResetErrorCount(tb);
1013 bnode_SetStat(tb, BSTAT_NORMAL);
1017 osi_auditU(acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
1021 /* set temp status */
1023 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1027 char caller[MAXKTCNAMELEN];
1029 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1034 bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
1036 tb = bnode_FindInstance(ainstance);
1042 bnode_ResetErrorCount(tb);
1043 code = bnode_SetStat(tb, astatus);
1047 osi_auditU(acall, BOS_SetTempStatusEvent, code, AUD_STR, ainstance,
1053 SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1057 char caller[MAXKTCNAMELEN];
1059 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1064 bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller,
1065 ainstance, astatus);
1067 tb = bnode_FindInstance(ainstance);
1073 bnode_SetFileGoal(tb, astatus);
1074 code = bnode_SetStat(tb, astatus);
1078 osi_auditU(acall, BOS_SetStatusEvent, code, AUD_STR, ainstance, AUD_END);
1083 SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat,
1089 tb = bnode_FindInstance(ainstance);
1096 code = bnode_GetStat(tb, astat);
1102 *astatDescr = malloc(BOZO_BSSIZE);
1103 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1106 (*astatDescr)[0] = 0; /* null string means no further info */
1110 *astatDescr = malloc(1);
1121 eifunc(struct bnode *abnode, void *param)
1123 struct eidata *arock = (struct eidata *)param;
1125 if (arock->counter-- == 0) {
1127 strcpy(arock->iname, abnode->name);
1136 ZapFile(const char *adir, const char *aname)
1139 if (snprintf(tbuffer, 256, "%s/%s", adir, aname)<256)
1140 return unlink(tbuffer);
1146 SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
1152 char caller[MAXKTCNAMELEN];
1154 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1158 if (bozo_isrestricted) {
1163 bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags);
1165 /* first scan AFS binary directory */
1166 dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH);
1168 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1169 i = strlen(tde->d_name);
1170 if (aflags & BOZO_PRUNEOLD) {
1171 if (i >= 4 && strncmp(tde->d_name + i - 4, ".OLD", 4) == 0)
1172 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1174 if (aflags & BOZO_PRUNEBAK) {
1175 if (i >= 4 && strncmp(tde->d_name + i - 4, ".BAK", 4) == 0)
1176 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1182 /* then scan AFS log directory */
1183 dirp = opendir(AFSDIR_SERVER_LOGS_DIRPATH);
1185 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1186 if (aflags & BOZO_PRUNECORE) {
1187 if (strncmp(tde->d_name, AFSDIR_CORE_FILE, 4) == 0)
1188 ZapFile(AFSDIR_SERVER_LOGS_DIRPATH, tde->d_name);
1196 osi_auditU(acall, BOS_PruneLogs, code, AUD_END);
1201 SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum,
1204 struct eidata tdata;
1206 *ainstance = malloc(BOZO_BSSIZE);
1208 tdata.counter = anum;
1209 tdata.iname = *ainstance;
1210 bnode_ApplyInstance(eifunc, &tdata);
1211 if (tdata.counter >= 0)
1212 return BZDOM; /* anum > # of actual instances */
1217 struct bozo_bosEntryStats bozo_bosEntryStats[] = {
1218 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_AFS_DIRPATH */
1219 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_ETC_DIRPATH */
1220 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_BIN_DIRPATH */
1221 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_LOGS_DIRPATH */
1222 {NULL, 1, 0, 0700, 07}, /* AFSDIR_SERVER_BACKUP_DIRPATH */
1223 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_DB_DIRPATH */
1224 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_LOCAL_DIRPATH */
1225 {NULL, 0, 1, 0600, 07}, /* AFSDIR_SERVER_KEY_FILEPATH */
1226 {NULL, 0, 1, 0600, 03}
1227 }; /* AFSDIR_SERVER_ULIST_FILEPATH */
1228 int bozo_nbosEntryStats =
1229 sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
1231 /* This function performs initialization of the bozo_bosEntrystats[]
1232 * array. This array contains the list of dirs that the bosserver
1233 * is interested in along with their recommended permissions
1234 * NOTE: This initialization is a bit ugly. This was caused because
1235 * the path names require procedural as opposed to static initialization.
1236 * The other fields in the struct are however, statically initialized.
1239 initBosEntryStats(void)
1241 bozo_bosEntryStats[0].path = AFSDIR_SERVER_AFS_DIRPATH;
1242 bozo_bosEntryStats[1].path = AFSDIR_SERVER_ETC_DIRPATH;
1243 bozo_bosEntryStats[2].path = AFSDIR_SERVER_BIN_DIRPATH;
1244 bozo_bosEntryStats[3].path = AFSDIR_SERVER_LOGS_DIRPATH;
1245 bozo_bosEntryStats[4].path = AFSDIR_SERVER_BACKUP_DIRPATH;
1246 bozo_bosEntryStats[5].path = AFSDIR_SERVER_DB_DIRPATH;
1247 bozo_bosEntryStats[6].path = AFSDIR_SERVER_LOCAL_DIRPATH;
1248 bozo_bosEntryStats[7].path = AFSDIR_SERVER_KEY_FILEPATH;
1249 bozo_bosEntryStats[8].path = AFSDIR_SERVER_ULIST_FILEPATH;
1254 /* StatEachEntry - If it's not there, it is okay. If anything else goes wrong
1255 * complain. Otherwise check permissions: shouldn't allow write or (usually)
1259 StatEachEntry(IN struct bozo_bosEntryStats *stats)
1262 if (stat(stats->path, &info)) {
1263 if (errno == ENOENT)
1264 return 1; /* no such entry: just ignore it */
1265 return 0; /* something else went wrong */
1268 if (((info.st_mode & S_IFDIR) != 0) != stats->dir)
1269 return 0; /* not expected type */
1270 if (stats->rootOwner && (info.st_uid != 0))
1271 return 0; /* not owned by root */
1272 rights = (info.st_mode & 0000777);
1273 if ((rights & stats->reqPerm) != stats->reqPerm)
1274 return 0; /* required permissions not present */
1275 if ((rights & stats->proPerm) != 0)
1276 return 0; /* prohibited permissions present */
1281 /* DirAccessOK - checks the mode bits on the AFS dir and decendents and
1282 * returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
1283 * this check more often than every 5 seconds. */
1289 /* underlying filesystem may not support directory protection */
1292 static afs_uint32 lastTime = 0;
1293 afs_uint32 now = FT_ApproxTime();
1294 static int lastResult = -1;
1298 if ((now - lastTime) < 5)
1303 for (i = 0; i < bozo_nbosEntryStats; i++) {
1304 struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i];
1305 if (!StatEachEntry(e)) {
1306 bozo_Log("unhappy with %s which is a %s that should "
1307 "have at least rights %o, at most rights %o %s\n",
1308 e->path, e->dir ? "dir" : "file", e->reqPerm,
1309 (~e->proPerm & 0777),
1310 e->rootOwner ? ", owned by root" : "");
1316 if (result != lastResult) { /* log changes */
1317 bozo_Log("Server directory access is %sokay\n",
1318 (result ? "" : "not "));
1320 lastResult = result;
1322 #endif /* AFS_NT40_ENV */
1326 GetRequiredDirPerm(const char *path)
1329 for (i = 0; i < bozo_nbosEntryStats; i++)
1330 if (strcmp(path, bozo_bosEntryStats[i].path) == 0)
1331 return bozo_bosEntryStats[i].reqPerm;
1336 SBOZO_GetInstanceInfo(IN struct rx_call *acall,
1339 OUT struct bozo_status *astatus)
1343 tb = bnode_FindInstance(ainstance);
1344 *atype = malloc(BOZO_BSSIZE);
1349 strcpy(*atype, tb->type->name);
1351 (*atype)[0] = 0; /* null string */
1352 memset(astatus, 0, sizeof(struct bozo_status)); /* good defaults */
1353 astatus->goal = tb->goal;
1354 astatus->fileGoal = tb->fileGoal;
1355 astatus->procStartTime = tb->procStartTime;
1356 astatus->procStarts = tb->procStarts;
1357 astatus->lastAnyExit = tb->lastAnyExit;
1358 astatus->lastErrorExit = tb->lastErrorExit;
1359 astatus->errorCode = tb->errorCode;
1360 astatus->errorSignal = tb->errorSignal;
1361 if (tb->flags & BNODE_ERRORSTOP)
1362 astatus->flags |= BOZO_ERRORSTOP;
1363 if (bnode_HasCore(tb))
1364 astatus->flags |= BOZO_HASCORE;
1366 astatus->flags |= BOZO_BADDIRACCESS;
1371 SBOZO_GetInstanceParm(struct rx_call *acall,
1380 tp = malloc(BOZO_BSSIZE);
1382 *tp = 0; /* null-terminate string in error case */
1383 tb = bnode_FindInstance(ainstance);
1389 memcpy(tp, tb->notifier, strlen(tb->notifier) + 1);
1392 code = BZNOENT; /* XXXXX */
1394 code = bnode_GetParm(tb, anum, tp, BOZO_BSSIZE);
1397 /* Not Currently Audited */
1402 SBOZO_GetLog(struct rx_call *acall, char *aname)
1409 char caller[MAXKTCNAMELEN];
1411 /* Check access since 'aname' could specify a file outside of the
1412 * AFS log directory (which is bosserver's working directory).
1414 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1418 if (bozo_isrestricted && strchr(aname, '/')
1419 && strcmp(aname, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH)) {
1424 /* construct local path from canonical (wire-format) path */
1425 if (ConstructLocalLogPath(aname, &logpath)) {
1429 bozo_Log("%s is executing GetLog '%s'\n", caller, logpath);
1430 tfile = fopen(logpath, "r");
1440 continue; /* our termination condition on other end */
1444 if (rx_Write(acall, &buffer, 1) != 1) {
1451 /* all done, cleanup and return */
1454 /* write out the end delimeter */
1456 if (rx_Write(acall, &buffer, 1) != 1)
1461 osi_auditU(acall, BOS_GetLogsEvent, code, AUD_END);
1466 SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
1467 char **as1, char **as2, char **as3, char **as4)
1477 tb = bnode_FindInstance(abnodeName);
1481 /* now, return the appropriate error string, if any */
1482 if (tb->lastErrorName) {
1483 *as1 = strdup(tb->lastErrorName);
1497 SBOZO_GetRestrictedMode(struct rx_call *acall, afs_int32 *arestmode)
1499 *arestmode = bozo_isrestricted;
1504 SBOZO_SetRestrictedMode(struct rx_call *acall, afs_int32 arestmode)
1507 char caller[MAXKTCNAMELEN];
1509 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1512 if (bozo_isrestricted) {
1515 if (arestmode != 0 && arestmode != 1) {
1518 bozo_isrestricted = arestmode;
1519 code = WriteBozoFile(0);
1525 bozo_ShutdownAndExit(void *param)
1527 int asignal = (intptr_t)param;
1531 ("Shutdown of BOS server and processes in response to signal %d\n",
1534 /* start shutdown of all processes */
1535 if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) {
1536 /* wait for shutdown to complete */
1537 code = bnode_ApplyInstance(swproc, NULL);
1541 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",