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>
33 #include "bosprototypes.h"
35 extern struct ktime bozo_nextRestartKT, bozo_nextDayKT;
37 extern struct afsconf_dir *bozo_confdir;
38 extern int bozo_newKTs;
40 extern int bozo_isrestricted;
43 SBOZO_GetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
47 code = 0; /* assume success */
50 memcpy(aktime, &bozo_nextRestartKT, sizeof(struct ktime));
54 memcpy(aktime, &bozo_nextDayKT, sizeof(struct ktime));
66 SBOZO_SetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
69 char caller[MAXKTCNAMELEN];
71 /* check for proper permissions */
72 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
77 bozo_Log("%s is executing SetRestartTime\n", caller);
79 code = 0; /* assume success */
82 memcpy(&bozo_nextRestartKT, aktime, sizeof(struct ktime));
86 memcpy(&bozo_nextDayKT, aktime, sizeof(struct ktime));
95 /* try to update the bozo init file */
96 code = WriteBozoFile(0);
101 osi_auditU(acall, BOS_SetRestartEvent, code, AUD_END);
106 SBOZO_Exec(struct rx_call *acall, char *acmd)
109 char caller[MAXKTCNAMELEN];
112 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
116 if (bozo_isrestricted) {
121 bozo_Log("%s is executing the shell command '%s'\n", caller, acmd);
123 /* should copy output to acall, but don't yet cause its hard */
124 /* hard... NOT! Nnow _at least_ return the exit status */
126 osi_auditU(acall, BOS_ExecEvent, code, AUD_STR, acmd, AUD_END);
133 SBOZO_GetDates(struct rx_call *acall, char *aname, afs_int32 *atime,
134 afs_int32 *abakTime, afs_int32 *aoldTime)
138 char tbuffer[AFSDIR_PATH_MAX];
140 *atime = *abakTime = *aoldTime = 0;
142 /* construct local path from canonical (wire-format) path */
143 if (ConstructLocalBinPath(aname, &strp)) {
146 strcpy(tbuffer, strp);
149 strp = tbuffer + strlen(tbuffer);
151 if (!stat(tbuffer, &tstat)) {
152 *atime = tstat.st_mtime;
155 strcpy(strp, ".BAK");
156 if (!stat(tbuffer, &tstat)) {
157 *abakTime = tstat.st_mtime;
160 strcpy(strp, ".OLD");
161 if (!stat(tbuffer, &tstat)) {
162 *aoldTime = tstat.st_mtime;
168 SBOZO_UnInstall(struct rx_call *acall, char *aname)
171 char fpOld[AFSDIR_PATH_MAX], fpBak[AFSDIR_PATH_MAX];
173 char caller[MAXKTCNAMELEN];
176 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
178 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
181 if (bozo_isrestricted) {
183 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
187 /* construct local path from canonical (wire-format) path */
188 if (ConstructLocalBinPath(aname, &filepath)) {
193 bozo_Log("%s is executing UnInstall '%s'\n", caller, filepath);
195 strcpy(fpBak, filepath);
196 strcat(fpBak, ".BAK");
197 strcpy(fpOld, filepath);
198 strcat(fpOld, ".OLD");
200 code = renamefile(fpBak, filepath);
202 /* can't find .BAK, try .OLD */
203 code = renamefile(fpOld, filepath);
204 if (code && errno == ENOENT) /* If doesn't exist don't fail */
207 /* now rename .OLD to .BAK */
208 if (stat(fpOld, &tstat) == 0)
209 code = renamefile(fpOld, fpBak);
214 osi_auditU(acall, BOS_UnInstallEvent, code, AUD_STR, filepath, AUD_END);
220 #define BOZO_OLDTIME (7*24*3600) /* 7 days old */
222 SaveOldFiles(char *aname)
225 char bbuffer[AFSDIR_PATH_MAX], obuffer[AFSDIR_PATH_MAX];
228 afs_int32 oldTime, bakTime;
230 strcpy(bbuffer, aname);
231 strcat(bbuffer, ".BAK");
232 strcpy(obuffer, aname);
233 strcat(obuffer, ".OLD");
234 now = FT_ApproxTime();
236 code = stat(aname, &tstat);
238 return; /* can't stat file */
240 code = stat(obuffer, &tstat); /* discover old file's time */
244 oldTime = tstat.st_mtime;
246 code = stat(bbuffer, &tstat); /* discover back file's time */
250 bakTime = tstat.st_mtime;
252 if (bakTime && (oldTime == 0 || bakTime < now - BOZO_OLDTIME)) {
253 /* no .OLD file, or .BAK is at least a week old */
254 code = renamefile(bbuffer, obuffer);
257 /* finally rename to .BAK extension */
258 renamefile(aname, bbuffer);
262 SBOZO_Install(struct rx_call *acall, char *aname, afs_int32 asize, afs_int32 mode, afs_int32 amtime)
269 struct _utimbuf utbuf;
271 struct timeval tvb[2];
273 char filepath[AFSDIR_PATH_MAX], tbuffer[AFSDIR_PATH_MAX], *fpp;
274 char caller[MAXKTCNAMELEN];
276 if (!afsconf_SuperUser(bozo_confdir, acall, caller))
278 if (bozo_isrestricted)
281 /* construct local path from canonical (wire-format) path */
282 if (ConstructLocalBinPath(aname, &fpp)) {
285 strcpy(filepath, fpp);
289 bozo_Log("%s is executing Install '%s'\n", caller, filepath);
292 fpp = filepath + strlen(filepath);
293 strcpy(fpp, ".NEW"); /* append ".NEW" to end of filepath */
294 fd = open(filepath, O_CREAT | O_RDWR | O_TRUNC, 0777);
299 len = rx_Read(acall, tbuffer, sizeof(tbuffer));
306 break; /* no more input */
307 code = write(fd, tbuffer, len);
313 total += len; /* track total written for safety check at end */
316 if (asize != total) {
318 return 101; /* wrong size */
322 *fpp = '\0'; /* remove ".NEW" from end of filepath */
323 SaveOldFiles(filepath); /* don't care if it works, still install */
325 /* all done, rename to final name */
326 strcpy(tbuffer, filepath);
327 strcat(tbuffer, ".NEW");
328 code = (renamefile(tbuffer, filepath) ? errno : 0);
330 /* label file with same time for our sanity */
332 utbuf.actime = utbuf.modtime = amtime;
333 _utime(filepath, &utbuf);
335 tvb[0].tv_sec = tvb[1].tv_sec = amtime;
336 tvb[0].tv_usec = tvb[1].tv_usec = 0;
337 utimes(filepath, tvb);
338 #endif /* AFS_NT40_ENV */
341 chmod(filepath, mode);
344 osi_auditU(acall, BOS_InstallEvent, code, AUD_STR, filepath, AUD_END);
351 SBOZO_SetCellName(struct rx_call *acall, char *aname)
353 struct afsconf_cell tcell;
355 char caller[MAXKTCNAMELEN];
356 char clones[MAXHOSTSPERCELL];
358 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
363 bozo_Log("%s is executing SetCellName '%s'\n", caller, aname);
366 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
371 /* Check that tcell has enough space for the new cellname. */
372 if (strlen(aname) > sizeof tcell.name - 1) {
374 ("ERROR: SetCellName: cell name '%s' exceeds %ld bytes (cell name not changed)\n",
375 aname, (long)(sizeof tcell.name - 1));
380 strcpy(tcell.name, aname);
382 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
386 osi_auditU(acall, BOS_SetCellEvent, code, AUD_STR, aname, AUD_END);
391 SBOZO_GetCellName(struct rx_call *acall, char **aname)
394 char tname[MAXCELLCHARS];
396 code = afsconf_GetLocalCell(bozo_confdir, tname, sizeof(tname));
398 /* must set output parameters even if aborting */
399 *aname = (char *)malloc(1);
402 *aname = strdup(tname);
409 SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
412 struct afsconf_cell tcell;
414 char clones[MAXHOSTSPERCELL];
417 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
422 if (awhich >= tcell.numServers) {
427 tp = tcell.hostName[awhich];
428 *aname = (char *)malloc(strlen(tp) + 3);
429 if (clones[awhich]) {
438 *aname = (char *)malloc(1); /* return fake string */
446 SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
449 struct afsconf_cell tcell;
452 char caller[MAXKTCNAMELEN];
453 char clones[MAXHOSTSPERCELL];
455 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
460 bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname);
463 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
469 for (i = 0; i < tcell.numServers; i++) {
470 if (strcmp(tcell.hostName[i], aname) == 0) {
481 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
482 memset(tcell.hostName[which], 0, MAXHOSTCHARS);
484 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
488 osi_auditU(acall, BOS_DeleteHostEvent, code, AUD_STR, aname, AUD_END);
493 SBOZO_AddCellHost(struct rx_call *acall, char *aname)
496 struct afsconf_cell tcell;
499 char caller[MAXKTCNAMELEN];
500 char clones[MAXHOSTSPERCELL];
504 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
509 bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname);
512 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
519 *(n + strlen(n) - 1) = 0;
525 for (i = 0; i < tcell.numServers; i++) {
526 if (strcmp(tcell.hostName[i], n) == 0) {
532 which = tcell.numServers;
536 * Check that tcell has enough space for an additional host.
538 * We assume that tcell.hostAddr[] and tcell.hostName[] have the
539 * same number of entries.
541 if (tcell.numServers >
542 sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]) {
544 ("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n",
545 (long)(sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]),
551 /* Check that tcell has enough space for the new hostname. */
552 if (strlen(aname) > sizeof tcell.hostName[0] - 1) {
554 ("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n",
555 aname, (long)(sizeof tcell.hostName[0] - 1));
561 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
562 strcpy(tcell.hostName[which], n);
563 clones[which] = isClone;
565 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
569 osi_auditU(acall, BOS_AddHostEvent, code, AUD_STR, aname, AUD_END);
574 SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
575 struct bozo_key *akey, struct bozo_keyInfo *akeyinfo)
577 struct afsconf_keys tkeys;
581 char caller[MAXKTCNAMELEN];
582 rxkad_level enc_level = rxkad_clear;
584 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
589 bozo_Log("%s is executing ListKeys\n", caller);
591 code = afsconf_GetKeys(bozo_confdir, &tkeys);
595 if (tkeys.nkeys <= an) {
599 *akvno = tkeys.key[an].kvno;
600 memset(akeyinfo, 0, sizeof(struct bozo_keyInfo));
602 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
603 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
605 * only return actual keys in noauth or if this is an encrypted connection
608 if ((noauth) || (enc_level == rxkad_crypt)) {
609 memcpy(akey, tkeys.key[an].key, 8);
613 code = stat(AFSDIR_SERVER_KEY_FILEPATH, &tstat);
615 akeyinfo->mod_sec = tstat.st_mtime;
617 ka_KeyCheckSum(tkeys.key[an].key, &akeyinfo->keyCheckSum);
618 /* only errors is bad key parity */
622 osi_auditU(acall, BOS_UnAuthListKeysEvent, code, AUD_END);
623 osi_auditU(acall, BOS_ListKeysEvent, code, AUD_END);
628 SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
631 char caller[MAXKTCNAMELEN];
632 rxkad_level enc_level = rxkad_clear;
635 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
639 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
640 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
641 if ((!noauth) && (enc_level != rxkad_crypt)) {
646 bozo_Log("%s is executing AddKey\n", caller);
648 code = afsconf_AddKey(bozo_confdir, an, akey->data, 0);
649 if (code == AFSCONF_KEYINUSE)
650 code = BZKEYINUSE; /* Unique code for afs rpc calls */
652 osi_auditU(acall, BOS_AddKeyEvent, code, AUD_END);
657 SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag)
660 char caller[MAXKTCNAMELEN];
662 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
667 bozo_Log("%s is executing Set No Authentication\n", caller);
669 afsconf_SetNoAuthFlag(bozo_confdir, aflag);
672 osi_auditU(acall, BOS_SetNoAuthEvent, code, AUD_LONG, aflag, AUD_END);
677 SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
680 char caller[MAXKTCNAMELEN];
682 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
687 bozo_Log("%s is executing DeleteKey\n", caller);
689 code = afsconf_DeleteKey(bozo_confdir, an);
692 osi_auditU(acall, BOS_DeleteKeyEvent, code, AUD_END);
698 SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, char **aname)
703 tp = *aname = (char *)malloc(256);
704 *tp = 0; /* in case getnthuser doesn't null-terminate the string */
705 code = afsconf_GetNthUser(bozo_confdir, an, tp, 256);
708 osi_auditU(acall, BOS_ListSUserEvent, code, AUD_END);
713 SBOZO_AddSUser(struct rx_call *acall, char *aname)
716 char caller[MAXKTCNAMELEN];
718 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
723 bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname);
725 code = afsconf_AddUser(bozo_confdir, aname);
728 osi_auditU(acall, BOS_AddSUserEvent, code, AUD_END);
733 SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
736 char caller[MAXKTCNAMELEN];
738 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
744 bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname);
746 code = afsconf_DeleteUser(bozo_confdir, aname);
749 osi_auditU(acall, BOS_DeleteSUserEvent, code, AUD_END);
754 SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
755 char *ap1, char *ap2, char *ap3, char *ap4, char *ap5,
760 char caller[MAXKTCNAMELEN];
762 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
766 if (bozo_isrestricted) {
767 const char *salvpath = AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH;
768 /* for DAFS, 'bos salvage' will pass "salvageserver -client" instead */
769 const char *salsrvpath = AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH " -client ";
771 /* still allow 'bos salvage' to work */
772 if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp")
773 || strcmp(ap2, "now")
774 || (strncmp(ap1, salvpath, strlen(salvpath))
775 && strncmp(ap1, salsrvpath, strlen(salsrvpath)))) {
783 bnode_Create(atype, ainstance, &tb, ap1, ap2, ap3, ap4, ap5, notifier,
786 bnode_SetStat(tb, BSTAT_NORMAL);
789 osi_auditU(acall, BOS_CreateBnodeEvent, code, AUD_END);
794 SBOZO_WaitAll(struct rx_call *acall)
797 char caller[MAXKTCNAMELEN];
799 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
805 bozo_Log("%s is executing Wait for All\n", caller);
807 code = bnode_WaitAll();
810 osi_auditU(acall, BOS_WaitAllEvent, code, AUD_END);
815 SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
818 char caller[MAXKTCNAMELEN];
820 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
824 if (bozo_isrestricted) {
829 bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance);
831 code = bnode_DeleteName(ainstance);
834 osi_auditU(acall, BOS_DeleteBnodeEvent, code, AUD_STR, ainstance,
840 swproc(struct bnode *abnode, void *arock)
842 if (abnode->goal == BSTAT_NORMAL)
843 return 0; /* this one's not shutting down */
844 /* otherwise, we are shutting down */
846 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
847 bnode_Release(abnode);
848 return 0; /* don't stop apply function early, no matter what */
852 stproc(struct bnode *abnode, void *arock)
854 if (abnode->fileGoal == BSTAT_SHUTDOWN)
855 return 0; /* don't do these guys */
858 bnode_ResetErrorCount(abnode);
859 bnode_SetStat(abnode, BSTAT_NORMAL);
860 bnode_Release(abnode);
865 sdproc(struct bnode *abnode, void *arock)
868 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
869 bnode_Release(abnode);
873 /* shutdown and leave down */
875 SBOZO_ShutdownAll(struct rx_call *acall)
877 /* iterate over all bnodes, setting the status to temporarily disabled */
879 char caller[MAXKTCNAMELEN];
881 /* check for authorization */
882 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
887 bozo_Log("%s is executing ShutdownAll\n", caller);
889 code = bnode_ApplyInstance(sdproc, NULL);
892 osi_auditU(acall, BOS_ShutdownAllEvent, code, AUD_END);
896 /* shutdown and restart */
898 SBOZO_RestartAll(struct rx_call *acall)
901 char caller[MAXKTCNAMELEN];
903 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
908 bozo_Log("%s is executing RestartAll\n", caller);
910 /* start shutdown of all processes */
911 code = bnode_ApplyInstance(sdproc, NULL);
915 /* wait for all done */
916 code = bnode_ApplyInstance(swproc, NULL);
920 /* start them up again */
921 code = bnode_ApplyInstance(stproc, NULL);
924 osi_auditU(acall, BOS_RestartAllEvent, code, AUD_END);
929 SBOZO_ReBozo(struct rx_call *acall)
932 char caller[MAXKTCNAMELEN];
934 /* acall is null if called internally to restart bosserver */
935 if (acall && !afsconf_SuperUser(bozo_confdir, acall, caller)) {
940 bozo_Log("%s is executing ReBozo\n", caller);
942 /* start shutdown of all processes */
943 code = bnode_ApplyInstance(sdproc, NULL);
947 /* wait for all done */
948 code = bnode_ApplyInstance(swproc, NULL);
953 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
955 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
958 rx_EndCall(acall, 0); /* try to get it done */
960 bozo_ReBozo(); /* this reexecs us, and doesn't return, of course */
963 /* Differentiate between external and internal ReBozo; prevents AFS_Aud_NoCall event */
965 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
967 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
968 return code; /* should only get here in unusual circumstances */
971 /* make sure all are running */
973 SBOZO_StartupAll(struct rx_call *acall)
976 char caller[MAXKTCNAMELEN];
978 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
983 bozo_Log("%s is executing StartupAll\n", caller);
984 code = bnode_ApplyInstance(stproc, NULL);
987 osi_auditU(acall, BOS_StartupAllEvent, code, AUD_END);
992 SBOZO_Restart(struct rx_call *acall, char *ainstance)
996 char caller[MAXKTCNAMELEN];
998 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1003 bozo_Log("%s is executing Restart '%s'\n", caller, ainstance);
1005 tb = bnode_FindInstance(ainstance);
1011 /* setup return code */
1015 bnode_SetStat(tb, BSTAT_SHUTDOWN);
1016 code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN); /* this can fail */
1017 bnode_ResetErrorCount(tb);
1018 bnode_SetStat(tb, BSTAT_NORMAL);
1022 osi_auditU(acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
1026 /* set temp status */
1028 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1032 char caller[MAXKTCNAMELEN];
1034 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1039 bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
1041 tb = bnode_FindInstance(ainstance);
1047 bnode_ResetErrorCount(tb);
1048 code = bnode_SetStat(tb, astatus);
1052 osi_auditU(acall, BOS_SetTempStatusEvent, code, AUD_STR, ainstance,
1058 SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1062 char caller[MAXKTCNAMELEN];
1064 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1069 bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller,
1070 ainstance, astatus);
1072 tb = bnode_FindInstance(ainstance);
1078 bnode_SetFileGoal(tb, astatus);
1079 code = bnode_SetStat(tb, astatus);
1083 osi_auditU(acall, BOS_SetStatusEvent, code, AUD_STR, ainstance, AUD_END);
1088 SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat,
1094 tb = bnode_FindInstance(ainstance);
1101 code = bnode_GetStat(tb, astat);
1107 *astatDescr = (char *)malloc(BOZO_BSSIZE);
1108 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1111 (*astatDescr)[0] = 0; /* null string means no further info */
1115 *astatDescr = (char *)malloc(1);
1126 eifunc(struct bnode *abnode, void *param)
1128 struct eidata *arock = (struct eidata *)param;
1130 if (arock->counter-- == 0) {
1132 strcpy(arock->iname, abnode->name);
1141 ZapFile(const char *adir, const char *aname)
1144 if (snprintf(tbuffer, 256, "%s/%s", adir, aname)<256)
1145 return unlink(tbuffer);
1151 SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
1157 char caller[MAXKTCNAMELEN];
1159 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1163 if (bozo_isrestricted) {
1168 bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags);
1170 /* first scan AFS binary directory */
1171 dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH);
1173 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1174 i = strlen(tde->d_name);
1175 if (aflags & BOZO_PRUNEOLD) {
1176 if (i >= 4 && strncmp(tde->d_name + i - 4, ".OLD", 4) == 0)
1177 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1179 if (aflags & BOZO_PRUNEBAK) {
1180 if (i >= 4 && strncmp(tde->d_name + i - 4, ".BAK", 4) == 0)
1181 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1187 /* then scan AFS log directory */
1188 dirp = opendir(AFSDIR_SERVER_LOGS_DIRPATH);
1190 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1191 if (aflags & BOZO_PRUNECORE) {
1192 if (strncmp(tde->d_name, AFSDIR_CORE_FILE, 4) == 0)
1193 ZapFile(AFSDIR_SERVER_LOGS_DIRPATH, tde->d_name);
1201 osi_auditU(acall, BOS_PruneLogs, code, AUD_END);
1206 SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum,
1209 struct eidata tdata;
1211 *ainstance = (char *)malloc(BOZO_BSSIZE);
1213 tdata.counter = anum;
1214 tdata.iname = *ainstance;
1215 bnode_ApplyInstance(eifunc, &tdata);
1216 if (tdata.counter >= 0)
1217 return BZDOM; /* anum > # of actual instances */
1222 struct bozo_bosEntryStats bozo_bosEntryStats[] = {
1223 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_AFS_DIRPATH */
1224 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_ETC_DIRPATH */
1225 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_BIN_DIRPATH */
1226 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_LOGS_DIRPATH */
1227 {NULL, 1, 0, 0700, 07}, /* AFSDIR_SERVER_BACKUP_DIRPATH */
1228 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_DB_DIRPATH */
1229 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_LOCAL_DIRPATH */
1230 {NULL, 0, 1, 0600, 07}, /* AFSDIR_SERVER_KEY_FILEPATH */
1231 {NULL, 0, 1, 0600, 03}
1232 }; /* AFSDIR_SERVER_ULIST_FILEPATH */
1233 int bozo_nbosEntryStats =
1234 sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
1236 /* This function performs initialization of the bozo_bosEntrystats[]
1237 * array. This array contains the list of dirs that the bosserver
1238 * is interested in along with their recommended permissions
1239 * NOTE: This initialization is a bit ugly. This was caused because
1240 * the path names require procedural as opposed to static initialization.
1241 * The other fields in the struct are however, statically initialized.
1244 initBosEntryStats(void)
1246 bozo_bosEntryStats[0].path = AFSDIR_SERVER_AFS_DIRPATH;
1247 bozo_bosEntryStats[1].path = AFSDIR_SERVER_ETC_DIRPATH;
1248 bozo_bosEntryStats[2].path = AFSDIR_SERVER_BIN_DIRPATH;
1249 bozo_bosEntryStats[3].path = AFSDIR_SERVER_LOGS_DIRPATH;
1250 bozo_bosEntryStats[4].path = AFSDIR_SERVER_BACKUP_DIRPATH;
1251 bozo_bosEntryStats[5].path = AFSDIR_SERVER_DB_DIRPATH;
1252 bozo_bosEntryStats[6].path = AFSDIR_SERVER_LOCAL_DIRPATH;
1253 bozo_bosEntryStats[7].path = AFSDIR_SERVER_KEY_FILEPATH;
1254 bozo_bosEntryStats[8].path = AFSDIR_SERVER_ULIST_FILEPATH;
1259 /* StatEachEntry - If it's not there, it is okay. If anything else goes wrong
1260 * complain. Otherwise check permissions: shouldn't allow write or (usually)
1264 StatEachEntry(IN struct bozo_bosEntryStats *stats)
1267 if (stat(stats->path, &info)) {
1268 if (errno == ENOENT)
1269 return 1; /* no such entry: just ignore it */
1270 return 0; /* something else went wrong */
1273 if (((info.st_mode & S_IFDIR) != 0) != stats->dir)
1274 return 0; /* not expected type */
1275 if (stats->rootOwner && (info.st_uid != 0))
1276 return 0; /* not owned by root */
1277 rights = (info.st_mode & 0000777);
1278 if ((rights & stats->reqPerm) != stats->reqPerm)
1279 return 0; /* required permissions not present */
1280 if ((rights & stats->proPerm) != 0)
1281 return 0; /* prohibited permissions present */
1286 /* DirAccessOK - checks the mode bits on the AFS dir and decendents and
1287 * returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
1288 * this check more often than every 5 seconds. */
1294 /* underlying filesystem may not support directory protection */
1297 static afs_uint32 lastTime = 0;
1298 afs_uint32 now = FT_ApproxTime();
1299 static int lastResult = -1;
1303 if ((now - lastTime) < 5)
1308 for (i = 0; i < bozo_nbosEntryStats; i++) {
1309 struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i];
1310 if (!StatEachEntry(e)) {
1311 bozo_Log("unhappy with %s which is a %s that should "
1312 "have at least rights %o, at most rights %o %s\n",
1313 e->path, e->dir ? "dir" : "file", e->reqPerm,
1314 (~e->proPerm & 0777),
1315 e->rootOwner ? ", owned by root" : "");
1321 if (result != lastResult) { /* log changes */
1322 bozo_Log("Server directory access is %sokay\n",
1323 (result ? "" : "not "));
1325 lastResult = result;
1327 #endif /* AFS_NT40_ENV */
1331 GetRequiredDirPerm(const char *path)
1334 for (i = 0; i < bozo_nbosEntryStats; i++)
1335 if (strcmp(path, bozo_bosEntryStats[i].path) == 0)
1336 return bozo_bosEntryStats[i].reqPerm;
1341 SBOZO_GetInstanceInfo(IN struct rx_call *acall,
1344 OUT struct bozo_status *astatus)
1348 tb = bnode_FindInstance(ainstance);
1349 *atype = (char *)malloc(BOZO_BSSIZE);
1354 strcpy(*atype, tb->type->name);
1356 (*atype)[0] = 0; /* null string */
1357 memset(astatus, 0, sizeof(struct bozo_status)); /* good defaults */
1358 astatus->goal = tb->goal;
1359 astatus->fileGoal = tb->fileGoal;
1360 astatus->procStartTime = tb->procStartTime;
1361 astatus->procStarts = tb->procStarts;
1362 astatus->lastAnyExit = tb->lastAnyExit;
1363 astatus->lastErrorExit = tb->lastErrorExit;
1364 astatus->errorCode = tb->errorCode;
1365 astatus->errorSignal = tb->errorSignal;
1366 if (tb->flags & BNODE_ERRORSTOP)
1367 astatus->flags |= BOZO_ERRORSTOP;
1368 if (bnode_HasCore(tb))
1369 astatus->flags |= BOZO_HASCORE;
1371 astatus->flags |= BOZO_BADDIRACCESS;
1376 SBOZO_GetInstanceParm(struct rx_call *acall,
1385 tp = (char *)malloc(BOZO_BSSIZE);
1387 *tp = 0; /* null-terminate string in error case */
1388 tb = bnode_FindInstance(ainstance);
1394 memcpy(tp, tb->notifier, strlen(tb->notifier) + 1);
1397 code = BZNOENT; /* XXXXX */
1399 code = bnode_GetParm(tb, anum, tp, BOZO_BSSIZE);
1402 /* Not Currently Audited */
1407 SBOZO_GetLog(struct rx_call *acall, char *aname)
1414 char caller[MAXKTCNAMELEN];
1416 /* Check access since 'aname' could specify a file outside of the
1417 * AFS log directory (which is bosserver's working directory).
1419 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1423 if (bozo_isrestricted && strchr(aname, '/')
1424 && strcmp(aname, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH)) {
1429 /* construct local path from canonical (wire-format) path */
1430 if (ConstructLocalLogPath(aname, &logpath)) {
1434 bozo_Log("%s is executing GetLog '%s'\n", caller, logpath);
1435 tfile = fopen(logpath, "r");
1445 continue; /* our termination condition on other end */
1449 if (rx_Write(acall, &buffer, 1) != 1) {
1456 /* all done, cleanup and return */
1459 /* write out the end delimeter */
1461 if (rx_Write(acall, &buffer, 1) != 1)
1466 osi_auditU(acall, BOS_GetLogsEvent, code, AUD_END);
1471 SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
1472 char **as1, char **as2, char **as3, char **as4)
1476 *as2 = (char *)malloc(1);
1478 *as3 = (char *)malloc(1);
1480 *as4 = (char *)malloc(1);
1482 tb = bnode_FindInstance(abnodeName);
1486 /* now, return the appropriate error string, if any */
1487 if (tb->lastErrorName) {
1488 *as1 = strdup(tb->lastErrorName);
1490 *as1 = (char *)malloc(1);
1496 *as1 = (char *)malloc(1);
1502 SBOZO_GetRestrictedMode(struct rx_call *acall, afs_int32 *arestmode)
1504 *arestmode = bozo_isrestricted;
1509 SBOZO_SetRestrictedMode(struct rx_call *acall, afs_int32 arestmode)
1512 char caller[MAXKTCNAMELEN];
1514 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1517 if (bozo_isrestricted) {
1520 if (arestmode != 0 && arestmode != 1) {
1523 bozo_isrestricted = arestmode;
1524 code = WriteBozoFile(0);
1530 bozo_ShutdownAndExit(void *param)
1532 int asignal = (intptr_t)param;
1536 ("Shutdown of BOS server and processes in response to signal %d\n",
1539 /* start shutdown of all processes */
1540 if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) {
1541 /* wait for shutdown to complete */
1542 code = bnode_ApplyInstance(swproc, NULL);
1546 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",