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 = (char *)malloc(strlen(tname) + 1);
403 strcpy(*aname, 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 *aname = (char *)malloc(strlen(tp) + 3);
430 if (clones[awhich]) {
439 *aname = (char *)malloc(1); /* return fake string */
447 SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
450 struct afsconf_cell tcell;
453 char caller[MAXKTCNAMELEN];
454 char clones[MAXHOSTSPERCELL];
456 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
461 bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname);
464 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
470 for (i = 0; i < tcell.numServers; i++) {
471 if (strcmp(tcell.hostName[i], aname) == 0) {
482 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
483 memset(tcell.hostName[which], 0, MAXHOSTCHARS);
485 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
489 osi_auditU(acall, BOS_DeleteHostEvent, code, AUD_STR, aname, AUD_END);
494 SBOZO_AddCellHost(struct rx_call *acall, char *aname)
497 struct afsconf_cell tcell;
500 char caller[MAXKTCNAMELEN];
501 char clones[MAXHOSTSPERCELL];
505 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
510 bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname);
513 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
520 *(n + strlen(n) - 1) = 0;
526 for (i = 0; i < tcell.numServers; i++) {
527 if (strcmp(tcell.hostName[i], n) == 0) {
533 which = tcell.numServers;
537 * Check that tcell has enough space for an additional host.
539 * We assume that tcell.hostAddr[] and tcell.hostName[] have the
540 * same number of entries.
542 if (tcell.numServers >
543 sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]) {
545 ("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n",
546 (long)(sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]),
552 /* Check that tcell has enough space for the new hostname. */
553 if (strlen(aname) > sizeof tcell.hostName[0] - 1) {
555 ("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n",
556 aname, (long)(sizeof tcell.hostName[0] - 1));
562 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
563 strcpy(tcell.hostName[which], n);
564 clones[which] = isClone;
566 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
570 osi_auditU(acall, BOS_AddHostEvent, code, AUD_STR, aname, AUD_END);
575 SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
576 struct bozo_key *akey, struct bozo_keyInfo *akeyinfo)
578 struct afsconf_keys tkeys;
582 char caller[MAXKTCNAMELEN];
583 rxkad_level enc_level = rxkad_clear;
585 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
590 bozo_Log("%s is executing ListKeys\n", caller);
592 code = afsconf_GetKeys(bozo_confdir, &tkeys);
596 if (tkeys.nkeys <= an) {
600 *akvno = tkeys.key[an].kvno;
601 memset(akeyinfo, 0, sizeof(struct bozo_keyInfo));
603 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
604 rxkad_GetServerInfo(acall->conn, &enc_level, 0, 0, 0, 0, 0);
606 * only return actual keys in noauth or if this is an encrypted connection
609 if ((noauth) || (enc_level == rxkad_crypt)) {
610 memcpy(akey, tkeys.key[an].key, 8);
614 code = stat(AFSDIR_SERVER_KEY_FILEPATH, &tstat);
616 akeyinfo->mod_sec = tstat.st_mtime;
618 ka_KeyCheckSum(tkeys.key[an].key, &akeyinfo->keyCheckSum);
619 /* only errors is bad key parity */
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(acall->conn, &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 = (char *)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_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_SetStat(tb, BSTAT_NORMAL);
1021 osi_auditU(acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
1025 /* set temp status */
1027 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1031 char caller[MAXKTCNAMELEN];
1033 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1038 bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
1040 tb = bnode_FindInstance(ainstance);
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 = (char *)malloc(BOZO_BSSIZE);
1106 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1109 (*astatDescr)[0] = 0; /* null string means no further info */
1113 *astatDescr = (char *)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 = (char *)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 = (char *)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 = (char *)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)
1474 *as2 = (char *)malloc(1);
1476 *as3 = (char *)malloc(1);
1478 *as4 = (char *)malloc(1);
1480 tb = bnode_FindInstance(abnodeName);
1484 /* now, return the appropriate error string, if any */
1485 if (tb->lastErrorName) {
1486 *as1 = (char *)malloc(strlen(tb->lastErrorName) + 1);
1487 strcpy(*as1, tb->lastErrorName);
1489 *as1 = (char *)malloc(1);
1495 *as1 = (char *)malloc(1);
1501 SBOZO_GetRestrictedMode(struct rx_call *acall, afs_int32 *arestmode)
1503 *arestmode = bozo_isrestricted;
1508 SBOZO_SetRestrictedMode(struct rx_call *acall, afs_int32 arestmode)
1511 char caller[MAXKTCNAMELEN];
1513 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1516 if (bozo_isrestricted) {
1519 if (arestmode != 0 && arestmode != 1) {
1522 bozo_isrestricted = arestmode;
1523 code = WriteBozoFile(0);
1529 bozo_ShutdownAndExit(void *param)
1531 int asignal = (intptr_t)param;
1535 ("Shutdown of BOS server and processes in response to signal %d\n",
1538 /* start shutdown of all processes */
1539 if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) {
1540 /* wait for shutdown to complete */
1541 code = bnode_ApplyInstance(swproc, NULL);
1545 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",