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 if (asprintf(aname, "[%s]", tp) < 0)
434 if (*aname == NULL) {
441 *aname = malloc(1); /* return fake string */
449 SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
452 struct afsconf_cell tcell;
455 char caller[MAXKTCNAMELEN];
456 char clones[MAXHOSTSPERCELL];
458 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
463 bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname);
466 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
472 for (i = 0; i < tcell.numServers; i++) {
473 if (strcmp(tcell.hostName[i], aname) == 0) {
484 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
485 memset(tcell.hostName[which], 0, MAXHOSTCHARS);
487 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
491 osi_auditU(acall, BOS_DeleteHostEvent, code, AUD_STR, aname, AUD_END);
496 SBOZO_AddCellHost(struct rx_call *acall, char *aname)
499 struct afsconf_cell tcell;
502 char caller[MAXKTCNAMELEN];
503 char clones[MAXHOSTSPERCELL];
507 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
512 bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname);
515 afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell,
522 *(n + strlen(n) - 1) = 0;
528 for (i = 0; i < tcell.numServers; i++) {
529 if (strcmp(tcell.hostName[i], n) == 0) {
535 which = tcell.numServers;
539 * Check that tcell has enough space for an additional host.
541 * We assume that tcell.hostAddr[] and tcell.hostName[] have the
542 * same number of entries.
544 if (tcell.numServers >
545 sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]) {
547 ("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n",
548 (long)(sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]),
554 /* Check that tcell has enough space for the new hostname. */
555 if (strlen(aname) > sizeof tcell.hostName[0] - 1) {
557 ("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n",
558 aname, (long)(sizeof tcell.hostName[0] - 1));
564 memset(&tcell.hostAddr[which], 0, sizeof(struct sockaddr_in));
565 strcpy(tcell.hostName[which], n);
566 clones[which] = isClone;
568 afsconf_SetExtendedCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
572 osi_auditU(acall, BOS_AddHostEvent, code, AUD_STR, aname, AUD_END);
577 SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
578 struct bozo_key *akey, struct bozo_keyInfo *akeyinfo)
580 struct afsconf_keys tkeys;
584 char caller[MAXKTCNAMELEN];
585 rxkad_level enc_level = rxkad_clear;
587 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
592 bozo_Log("%s is executing ListKeys\n", caller);
594 code = afsconf_GetKeys(bozo_confdir, &tkeys);
598 if (tkeys.nkeys <= an) {
602 *akvno = tkeys.key[an].kvno;
603 memset(akeyinfo, 0, sizeof(struct bozo_keyInfo));
605 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
606 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
608 * only return actual keys in noauth or if this is an encrypted connection
611 if ((noauth) || (enc_level == rxkad_crypt)) {
612 memcpy(akey, tkeys.key[an].key, 8);
616 code = stat(AFSDIR_SERVER_KEY_FILEPATH, &tstat);
618 akeyinfo->mod_sec = tstat.st_mtime;
621 /* This will return an error if the key is 'bad' (bad checksum, weak DES
622 * key, etc). But we don't care, since we can still return the other
623 * information about the key, so ignore the result. */
624 (void)ka_KeyCheckSum(tkeys.key[an].key, &akeyinfo->keyCheckSum);
628 osi_auditU(acall, BOS_UnAuthListKeysEvent, code, AUD_END);
629 osi_auditU(acall, BOS_ListKeysEvent, code, AUD_END);
634 SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
637 char caller[MAXKTCNAMELEN];
638 rxkad_level enc_level = rxkad_clear;
641 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
645 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
646 rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
647 if ((!noauth) && (enc_level != rxkad_crypt)) {
652 bozo_Log("%s is executing AddKey\n", caller);
654 code = afsconf_AddKey(bozo_confdir, an, akey->data, 0);
655 if (code == AFSCONF_KEYINUSE)
656 code = BZKEYINUSE; /* Unique code for afs rpc calls */
658 osi_auditU(acall, BOS_AddKeyEvent, code, AUD_END);
663 SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag)
666 char caller[MAXKTCNAMELEN];
668 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
673 bozo_Log("%s is executing Set No Authentication\n", caller);
675 afsconf_SetNoAuthFlag(bozo_confdir, aflag);
678 osi_auditU(acall, BOS_SetNoAuthEvent, code, AUD_LONG, aflag, AUD_END);
683 SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
686 char caller[MAXKTCNAMELEN];
688 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
693 bozo_Log("%s is executing DeleteKey\n", caller);
695 code = afsconf_DeleteKey(bozo_confdir, an);
698 osi_auditU(acall, BOS_DeleteKeyEvent, code, AUD_END);
704 SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, char **aname)
709 tp = *aname = malloc(256);
710 *tp = 0; /* in case getnthuser doesn't null-terminate the string */
711 code = afsconf_GetNthUser(bozo_confdir, an, tp, 256);
714 osi_auditU(acall, BOS_ListSUserEvent, code, AUD_END);
719 SBOZO_AddSUser(struct rx_call *acall, char *aname)
722 char caller[MAXKTCNAMELEN];
724 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
729 bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname);
731 code = afsconf_AddUser(bozo_confdir, aname);
734 osi_auditU(acall, BOS_AddSUserEvent, code, AUD_END);
739 SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
742 char caller[MAXKTCNAMELEN];
744 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
750 bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname);
752 code = afsconf_DeleteUser(bozo_confdir, aname);
755 osi_auditU(acall, BOS_DeleteSUserEvent, code, AUD_END);
760 SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
761 char *ap1, char *ap2, char *ap3, char *ap4, char *ap5,
766 char caller[MAXKTCNAMELEN];
768 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
772 if (bozo_isrestricted) {
773 const char *salvpath = AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH;
774 /* for DAFS, 'bos salvage' will pass "salvageserver -client" instead */
775 const char *salsrvpath = AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH " -client ";
777 /* still allow 'bos salvage' to work */
778 if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp")
779 || strcmp(ap2, "now")
780 || (strncmp(ap1, salvpath, strlen(salvpath))
781 && strncmp(ap1, salsrvpath, strlen(salsrvpath)))) {
789 bnode_Create(atype, ainstance, &tb, ap1, ap2, ap3, ap4, ap5, notifier,
792 bnode_SetStat(tb, BSTAT_NORMAL);
795 osi_auditU(acall, BOS_CreateBnodeEvent, code, AUD_END);
800 SBOZO_WaitAll(struct rx_call *acall)
803 char caller[MAXKTCNAMELEN];
805 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
811 bozo_Log("%s is executing Wait for All\n", caller);
813 code = bnode_WaitAll();
816 osi_auditU(acall, BOS_WaitAllEvent, code, AUD_END);
821 SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
824 char caller[MAXKTCNAMELEN];
826 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
830 if (bozo_isrestricted) {
835 bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance);
837 code = bnode_DeleteName(ainstance);
840 osi_auditU(acall, BOS_DeleteBnodeEvent, code, AUD_STR, ainstance,
846 swproc(struct bnode *abnode, void *arock)
848 if (abnode->goal == BSTAT_NORMAL)
849 return 0; /* this one's not shutting down */
850 /* otherwise, we are shutting down */
852 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
853 bnode_Release(abnode);
854 return 0; /* don't stop apply function early, no matter what */
858 stproc(struct bnode *abnode, void *arock)
860 if (abnode->fileGoal == BSTAT_SHUTDOWN)
861 return 0; /* don't do these guys */
864 bnode_ResetErrorCount(abnode);
865 bnode_SetStat(abnode, BSTAT_NORMAL);
866 bnode_Release(abnode);
871 sdproc(struct bnode *abnode, void *arock)
874 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
875 bnode_Release(abnode);
879 /* shutdown and leave down */
881 SBOZO_ShutdownAll(struct rx_call *acall)
883 /* iterate over all bnodes, setting the status to temporarily disabled */
885 char caller[MAXKTCNAMELEN];
887 /* check for authorization */
888 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
893 bozo_Log("%s is executing ShutdownAll\n", caller);
895 code = bnode_ApplyInstance(sdproc, NULL);
898 osi_auditU(acall, BOS_ShutdownAllEvent, code, AUD_END);
902 /* shutdown and restart */
904 SBOZO_RestartAll(struct rx_call *acall)
907 char caller[MAXKTCNAMELEN];
909 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
914 bozo_Log("%s is executing RestartAll\n", caller);
916 /* start shutdown of all processes */
917 code = bnode_ApplyInstance(sdproc, NULL);
921 /* wait for all done */
922 code = bnode_ApplyInstance(swproc, NULL);
926 /* start them up again */
927 code = bnode_ApplyInstance(stproc, NULL);
930 osi_auditU(acall, BOS_RestartAllEvent, code, AUD_END);
935 SBOZO_ReBozo(struct rx_call *acall)
938 char caller[MAXKTCNAMELEN];
940 /* acall is null if called internally to restart bosserver */
941 if (acall && !afsconf_SuperUser(bozo_confdir, acall, caller)) {
946 bozo_Log("%s is executing ReBozo\n", caller);
948 /* start shutdown of all processes */
949 code = bnode_ApplyInstance(sdproc, NULL);
953 /* wait for all done */
954 code = bnode_ApplyInstance(swproc, NULL);
959 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
961 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
964 rx_EndCall(acall, 0); /* try to get it done */
966 bozo_ReBozo(); /* this reexecs us, and doesn't return, of course */
969 /* Differentiate between external and internal ReBozo; prevents AFS_Aud_NoCall event */
971 osi_auditU(acall, BOS_RebozoEvent, code, AUD_END);
973 osi_audit(BOS_RebozoIntEvent, code, AUD_END);
974 return code; /* should only get here in unusual circumstances */
977 /* make sure all are running */
979 SBOZO_StartupAll(struct rx_call *acall)
982 char caller[MAXKTCNAMELEN];
984 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
989 bozo_Log("%s is executing StartupAll\n", caller);
990 code = bnode_ApplyInstance(stproc, NULL);
993 osi_auditU(acall, BOS_StartupAllEvent, code, AUD_END);
998 SBOZO_Restart(struct rx_call *acall, char *ainstance)
1002 char caller[MAXKTCNAMELEN];
1004 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1009 bozo_Log("%s is executing Restart '%s'\n", caller, ainstance);
1011 tb = bnode_FindInstance(ainstance);
1018 bnode_SetStat(tb, BSTAT_SHUTDOWN);
1019 code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN); /* this can fail */
1020 bnode_ResetErrorCount(tb);
1021 bnode_SetStat(tb, BSTAT_NORMAL);
1025 osi_auditU(acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
1029 /* set temp status */
1031 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1035 char caller[MAXKTCNAMELEN];
1037 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1042 bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
1044 tb = bnode_FindInstance(ainstance);
1050 bnode_ResetErrorCount(tb);
1051 code = bnode_SetStat(tb, astatus);
1055 osi_auditU(acall, BOS_SetTempStatusEvent, code, AUD_STR, ainstance,
1061 SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
1065 char caller[MAXKTCNAMELEN];
1067 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1072 bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller,
1073 ainstance, astatus);
1075 tb = bnode_FindInstance(ainstance);
1081 bnode_SetFileGoal(tb, astatus);
1082 code = bnode_SetStat(tb, astatus);
1086 osi_auditU(acall, BOS_SetStatusEvent, code, AUD_STR, ainstance, AUD_END);
1091 SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat,
1097 tb = bnode_FindInstance(ainstance);
1104 code = bnode_GetStat(tb, astat);
1110 *astatDescr = malloc(BOZO_BSSIZE);
1111 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1114 (*astatDescr)[0] = 0; /* null string means no further info */
1118 *astatDescr = malloc(1);
1129 eifunc(struct bnode *abnode, void *param)
1131 struct eidata *arock = (struct eidata *)param;
1133 if (arock->counter-- == 0) {
1135 strcpy(arock->iname, abnode->name);
1144 ZapFile(const char *adir, const char *aname)
1147 if (snprintf(tbuffer, 256, "%s/%s", adir, aname)<256)
1148 return unlink(tbuffer);
1154 SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
1160 char caller[MAXKTCNAMELEN];
1162 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1166 if (bozo_isrestricted) {
1171 bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags);
1173 /* first scan AFS binary directory */
1174 dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH);
1176 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1177 i = strlen(tde->d_name);
1178 if (aflags & BOZO_PRUNEOLD) {
1179 if (i >= 4 && strncmp(tde->d_name + i - 4, ".OLD", 4) == 0)
1180 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1182 if (aflags & BOZO_PRUNEBAK) {
1183 if (i >= 4 && strncmp(tde->d_name + i - 4, ".BAK", 4) == 0)
1184 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1190 /* then scan AFS log directory */
1191 dirp = opendir(AFSDIR_SERVER_LOGS_DIRPATH);
1193 for (tde = readdir(dirp); tde; tde = readdir(dirp)) {
1194 if (aflags & BOZO_PRUNECORE) {
1195 if (strncmp(tde->d_name, AFSDIR_CORE_FILE, 4) == 0)
1196 ZapFile(AFSDIR_SERVER_LOGS_DIRPATH, tde->d_name);
1204 osi_auditU(acall, BOS_PruneLogs, code, AUD_END);
1209 SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum,
1212 struct eidata tdata;
1214 *ainstance = malloc(BOZO_BSSIZE);
1216 tdata.counter = anum;
1217 tdata.iname = *ainstance;
1218 bnode_ApplyInstance(eifunc, &tdata);
1219 if (tdata.counter >= 0)
1220 return BZDOM; /* anum > # of actual instances */
1225 struct bozo_bosEntryStats bozo_bosEntryStats[] = {
1226 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_AFS_DIRPATH */
1227 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_ETC_DIRPATH */
1228 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_BIN_DIRPATH */
1229 {NULL, 1, 1, 0755, 02}, /* AFSDIR_SERVER_LOGS_DIRPATH */
1230 {NULL, 1, 0, 0700, 07}, /* AFSDIR_SERVER_BACKUP_DIRPATH */
1231 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_DB_DIRPATH */
1232 {NULL, 1, 1, 0700, 07}, /* AFSDIR_SERVER_LOCAL_DIRPATH */
1233 {NULL, 0, 1, 0600, 07}, /* AFSDIR_SERVER_KEY_FILEPATH */
1234 {NULL, 0, 1, 0600, 03}
1235 }; /* AFSDIR_SERVER_ULIST_FILEPATH */
1236 int bozo_nbosEntryStats =
1237 sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
1239 /* This function performs initialization of the bozo_bosEntrystats[]
1240 * array. This array contains the list of dirs that the bosserver
1241 * is interested in along with their recommended permissions
1242 * NOTE: This initialization is a bit ugly. This was caused because
1243 * the path names require procedural as opposed to static initialization.
1244 * The other fields in the struct are however, statically initialized.
1247 initBosEntryStats(void)
1249 bozo_bosEntryStats[0].path = AFSDIR_SERVER_AFS_DIRPATH;
1250 bozo_bosEntryStats[1].path = AFSDIR_SERVER_ETC_DIRPATH;
1251 bozo_bosEntryStats[2].path = AFSDIR_SERVER_BIN_DIRPATH;
1252 bozo_bosEntryStats[3].path = AFSDIR_SERVER_LOGS_DIRPATH;
1253 bozo_bosEntryStats[4].path = AFSDIR_SERVER_BACKUP_DIRPATH;
1254 bozo_bosEntryStats[5].path = AFSDIR_SERVER_DB_DIRPATH;
1255 bozo_bosEntryStats[6].path = AFSDIR_SERVER_LOCAL_DIRPATH;
1256 bozo_bosEntryStats[7].path = AFSDIR_SERVER_KEY_FILEPATH;
1257 bozo_bosEntryStats[8].path = AFSDIR_SERVER_ULIST_FILEPATH;
1262 /* StatEachEntry - If it's not there, it is okay. If anything else goes wrong
1263 * complain. Otherwise check permissions: shouldn't allow write or (usually)
1267 StatEachEntry(IN struct bozo_bosEntryStats *stats)
1270 if (stat(stats->path, &info)) {
1271 if (errno == ENOENT)
1272 return 1; /* no such entry: just ignore it */
1273 return 0; /* something else went wrong */
1276 if (((info.st_mode & S_IFDIR) != 0) != stats->dir)
1277 return 0; /* not expected type */
1278 if (stats->rootOwner && (info.st_uid != 0))
1279 return 0; /* not owned by root */
1280 rights = (info.st_mode & 0000777);
1281 if ((rights & stats->reqPerm) != stats->reqPerm)
1282 return 0; /* required permissions not present */
1283 if ((rights & stats->proPerm) != 0)
1284 return 0; /* prohibited permissions present */
1289 /* DirAccessOK - checks the mode bits on the AFS dir and decendents and
1290 * returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
1291 * this check more often than every 5 seconds. */
1297 /* underlying filesystem may not support directory protection */
1300 static afs_uint32 lastTime = 0;
1301 afs_uint32 now = FT_ApproxTime();
1302 static int lastResult = -1;
1306 if ((now - lastTime) < 5)
1311 for (i = 0; i < bozo_nbosEntryStats; i++) {
1312 struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i];
1313 if (!StatEachEntry(e)) {
1314 bozo_Log("unhappy with %s which is a %s that should "
1315 "have at least rights %o, at most rights %o %s\n",
1316 e->path, e->dir ? "dir" : "file", e->reqPerm,
1317 (~e->proPerm & 0777),
1318 e->rootOwner ? ", owned by root" : "");
1324 if (result != lastResult) { /* log changes */
1325 bozo_Log("Server directory access is %sokay\n",
1326 (result ? "" : "not "));
1328 lastResult = result;
1330 #endif /* AFS_NT40_ENV */
1334 GetRequiredDirPerm(const char *path)
1337 for (i = 0; i < bozo_nbosEntryStats; i++)
1338 if (strcmp(path, bozo_bosEntryStats[i].path) == 0)
1339 return bozo_bosEntryStats[i].reqPerm;
1344 SBOZO_GetInstanceInfo(IN struct rx_call *acall,
1347 OUT struct bozo_status *astatus)
1351 tb = bnode_FindInstance(ainstance);
1352 *atype = malloc(BOZO_BSSIZE);
1357 strcpy(*atype, tb->type->name);
1359 (*atype)[0] = 0; /* null string */
1360 memset(astatus, 0, sizeof(struct bozo_status)); /* good defaults */
1361 astatus->goal = tb->goal;
1362 astatus->fileGoal = tb->fileGoal;
1363 astatus->procStartTime = tb->procStartTime;
1364 astatus->procStarts = tb->procStarts;
1365 astatus->lastAnyExit = tb->lastAnyExit;
1366 astatus->lastErrorExit = tb->lastErrorExit;
1367 astatus->errorCode = tb->errorCode;
1368 astatus->errorSignal = tb->errorSignal;
1369 if (tb->flags & BNODE_ERRORSTOP)
1370 astatus->flags |= BOZO_ERRORSTOP;
1371 if (bnode_HasCore(tb))
1372 astatus->flags |= BOZO_HASCORE;
1374 astatus->flags |= BOZO_BADDIRACCESS;
1379 SBOZO_GetInstanceParm(struct rx_call *acall,
1388 tp = malloc(BOZO_BSSIZE);
1390 *tp = 0; /* null-terminate string in error case */
1391 tb = bnode_FindInstance(ainstance);
1397 memcpy(tp, tb->notifier, strlen(tb->notifier) + 1);
1400 code = BZNOENT; /* XXXXX */
1402 code = bnode_GetParm(tb, anum, tp, BOZO_BSSIZE);
1405 /* Not Currently Audited */
1410 SBOZO_GetLog(struct rx_call *acall, char *aname)
1417 char caller[MAXKTCNAMELEN];
1419 /* Check access since 'aname' could specify a file outside of the
1420 * AFS log directory (which is bosserver's working directory).
1422 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1426 if (bozo_isrestricted && strchr(aname, '/')
1427 && strcmp(aname, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH)) {
1432 /* construct local path from canonical (wire-format) path */
1433 if (ConstructLocalLogPath(aname, &logpath)) {
1437 bozo_Log("%s is executing GetLog '%s'\n", caller, logpath);
1438 tfile = fopen(logpath, "r");
1448 continue; /* our termination condition on other end */
1452 if (rx_Write(acall, &buffer, 1) != 1) {
1459 /* all done, cleanup and return */
1462 /* write out the end delimeter */
1464 if (rx_Write(acall, &buffer, 1) != 1)
1469 osi_auditU(acall, BOS_GetLogsEvent, code, AUD_END);
1474 SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
1475 char **as1, char **as2, char **as3, char **as4)
1485 tb = bnode_FindInstance(abnodeName);
1489 /* now, return the appropriate error string, if any */
1490 if (tb->lastErrorName) {
1491 *as1 = strdup(tb->lastErrorName);
1505 SBOZO_GetRestrictedMode(struct rx_call *acall, afs_int32 *arestmode)
1507 *arestmode = bozo_isrestricted;
1512 SBOZO_SetRestrictedMode(struct rx_call *acall, afs_int32 arestmode)
1515 char caller[MAXKTCNAMELEN];
1517 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1520 if (bozo_isrestricted) {
1523 if (arestmode != 0 && arestmode != 1) {
1526 bozo_isrestricted = arestmode;
1527 code = WriteBozoFile(0);
1533 bozo_ShutdownAndExit(void *param)
1535 int asignal = (intptr_t)param;
1539 ("Shutdown of BOS server and processes in response to signal %d\n",
1542 /* start shutdown of all processes */
1543 if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) {
1544 /* wait for shutdown to complete */
1545 code = bnode_ApplyInstance(swproc, NULL);
1549 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",