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>
16 #include <sys/types.h>
20 #include <sys/utime.h>
23 #include <netinet/in.h>
24 #endif /* AFS_NT40_ENV */
29 #include <afs/cellconfig.h>
35 #include <afs/afsutil.h>
36 #include <afs/fileutil.h>
37 #include <afs/ktime.h>
38 #include <afs/audit.h>
44 extern struct ktime bozo_nextRestartKT, bozo_nextDayKT;
46 extern struct afsconf_dir *bozo_confdir;
47 extern struct rx_securityClass *bozo_rxsc[2];
48 extern int bozo_newKTs;
50 #ifdef BOS_RESTRICTED_MODE
51 extern int bozo_isrestricted;
54 BOZO_GetRestartTime(acall, atype, aktime)
55 struct rx_call *acall;
57 struct ktime *aktime; {
58 register afs_int32 code;
60 code = 0; /* assume success */
63 bcopy(&bozo_nextRestartKT, aktime, sizeof(struct ktime));
67 bcopy(&bozo_nextDayKT, aktime, sizeof(struct ktime));
78 BOZO_SetRestartTime(acall, atype, aktime)
79 struct rx_call *acall;
81 struct ktime *aktime; {
82 register afs_int32 code;
83 char caller[MAXKTCNAMELEN];
85 /* check for proper permissions */
86 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
90 if (DoLogging) bozo_Log("%s is executing SetRestartTime\n", caller);
92 code = 0; /* assume success */
95 bcopy(aktime, &bozo_nextRestartKT, sizeof(struct ktime));
99 bcopy(aktime, &bozo_nextDayKT, sizeof(struct ktime));
108 /* try to update the bozo init file */
109 code = WriteBozoFile(0);
114 osi_auditU (acall, BOS_SetRestartEvent, code, AUD_END);
118 BOZO_Exec(acall, acmd)
119 struct rx_call *acall;
122 char caller[MAXKTCNAMELEN];
125 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
129 #ifdef BOS_RESTRICTED_MODE
130 if (bozo_isrestricted) {
135 if (DoLogging) bozo_Log("%s is executing the shell command '%s'\n", caller, acmd);
137 /* should copy output to acall, but don't yet cause its hard */
138 /* hard... NOT! Nnow _at least_ return the exit status */
140 osi_auditU (acall, BOS_ExecEvent, code, AUD_STR, acmd, AUD_END);
146 BOZO_GetDates(acall, aname, atime, abakTime, aoldTime)
147 struct rx_call *acall;
149 afs_int32 *atime, *abakTime, *aoldTime; {
150 register afs_int32 code;
153 char tbuffer[AFSDIR_PATH_MAX];
155 *atime = *abakTime = *aoldTime = 0;
157 /* construct local path from canonical (wire-format) path */
158 if (ConstructLocalBinPath(aname, &strp)) {
161 strcpy(tbuffer, strp);
164 strp = tbuffer + strlen(tbuffer);
166 if (!stat(tbuffer, &tstat)) {
167 *atime = tstat.st_mtime;
170 strcpy(strp, ".BAK");
171 if (!stat(tbuffer, &tstat)) {
172 *abakTime = tstat.st_mtime;
175 strcpy(strp, ".OLD");
176 if (!stat(tbuffer, &tstat)) {
177 *aoldTime = tstat.st_mtime;
182 BOZO_UnInstall(acall, aname)
183 struct rx_call *acall;
184 register char *aname; {
186 char fpOld[AFSDIR_PATH_MAX], fpBak[AFSDIR_PATH_MAX];
188 char caller[MAXKTCNAMELEN];
191 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
193 osi_auditU (acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
196 #ifdef BOS_RESTRICTED_MODE
197 if (bozo_isrestricted) {
199 osi_auditU (acall, BOS_UnInstallEvent, code, AUD_STR, aname, AUD_END);
204 /* construct local path from canonical (wire-format) path */
205 if (ConstructLocalBinPath(aname, &filepath)) {
209 if (DoLogging) bozo_Log("%s is executing UnInstall '%s'\n", caller, filepath);
211 strcpy(fpBak, filepath);
212 strcat(fpBak, ".BAK");
213 strcpy(fpOld, filepath);
214 strcat(fpOld, ".OLD");
216 code = renamefile(fpBak, filepath);
218 /* can't find .BAK, try .OLD */
219 code = renamefile(fpOld, filepath);
220 if (code && errno == ENOENT) /* If doesn't exist don't fail */
223 /* now rename .OLD to .BAK */
224 if (stat(fpOld, &tstat) == 0)
225 code = renamefile(fpOld, fpBak);
230 osi_auditU (acall, BOS_UnInstallEvent, code, AUD_STR, filepath, AUD_END);
236 #define BOZO_OLDTIME (7*24*3600) /* 7 days old */
237 static void SaveOldFiles(char *aname)
239 register afs_int32 code;
240 char bbuffer[AFSDIR_PATH_MAX], obuffer[AFSDIR_PATH_MAX];
242 register afs_int32 now;
243 afs_int32 oldTime, bakTime;
245 strcpy(bbuffer, aname);
246 strcat(bbuffer, ".BAK");
247 strcpy(obuffer, aname);
248 strcat(obuffer, ".OLD");
249 now = FT_ApproxTime();
251 code = stat(aname, &tstat);
252 if (code < 0) return; /* can't stat file */
254 code = stat(obuffer, &tstat); /* discover old file's time */
255 if (code) oldTime = 0;
256 else oldTime = tstat.st_mtime;
258 code = stat(bbuffer, &tstat); /* discover back file's time */
259 if (code) bakTime = 0;
260 else bakTime = tstat.st_mtime;
262 if (bakTime && (oldTime == 0 || bakTime < now - BOZO_OLDTIME)) {
263 /* no .OLD file, or .BAK is at least a week old */
264 code = renamefile(bbuffer, obuffer);
267 /* finally rename to .BAK extension */
268 renamefile(aname, bbuffer);
271 BOZO_Install(acall, aname, asize, mode, amtime)
272 struct rx_call *acall;
282 struct _utimbuf utbuf;
284 struct timeval tvb[2];
286 char filepath[AFSDIR_PATH_MAX], tbuffer[AFSDIR_PATH_MAX], *fpp;
287 char caller[MAXKTCNAMELEN];
289 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) return BZACCESS;
290 #ifdef BOS_RESTRICTED_MODE
291 if (bozo_isrestricted) return BZACCESS;
294 /* construct local path from canonical (wire-format) path */
295 if (ConstructLocalBinPath(aname, &fpp)) {
298 strcpy(filepath, fpp);
301 if (DoLogging) bozo_Log("%s is executing Install '%s'\n", caller, filepath);
304 fpp = filepath + strlen(filepath);
305 strcpy(fpp, ".NEW"); /* append ".NEW" to end of filepath */
306 fd = open(filepath, O_CREAT | O_RDWR | O_TRUNC, 0777);
307 if (fd < 0) return errno;
310 len = rx_Read(acall, tbuffer, sizeof(tbuffer));
316 if (len == 0) break; /* no more input */
317 code = write(fd, tbuffer, len);
323 total += len; /* track total written for safety check at end */
326 if (asize != total) {
328 return 101; /* wrong size */
332 *fpp = '\0'; /* remove ".NEW" from end of filepath */
333 SaveOldFiles(filepath); /* don't care if it works, still install */
335 /* all done, rename to final name */
336 strcpy(tbuffer, filepath);
337 strcat(tbuffer, ".NEW");
338 code = (renamefile(tbuffer, filepath) ? errno : 0);
340 /* label file with same time for our sanity */
342 utbuf.actime = utbuf.modtime = amtime;
343 _utime(filepath, &utbuf);
345 tvb[0].tv_sec = tvb[1].tv_sec = amtime;
346 tvb[0].tv_usec = tvb[1].tv_usec = 0;
347 utimes(filepath, tvb);
348 #endif /* AFS_NT40_ENV */
351 chmod(filepath, mode);
354 osi_auditU (acall, BOS_InstallEvent, code, AUD_STR, filepath, AUD_END);
360 BOZO_SetCellName(acall, aname)
361 struct rx_call *acall;
363 struct afsconf_cell tcell;
364 register afs_int32 code;
365 char caller[MAXKTCNAMELEN];
367 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
371 if (DoLogging) bozo_Log("%s is executing SetCellName '%s'\n", caller, aname);
373 code = afsconf_GetCellInfo(bozo_confdir, (char *) 0, (char *) 0, &tcell);
377 /* Check that tcell has enough space for the new cellname. */
378 if (strlen(aname) > sizeof tcell.name - 1) {
379 bozo_Log("ERROR: SetCellName: cell name '%s' exceeds %ld bytes (cell name not changed)\n",
380 aname, (long)(sizeof tcell.name - 1));
385 strcpy(tcell.name, aname);
386 code = afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH, &tcell);
389 osi_auditU (acall, BOS_SetCellEvent, code, AUD_STR, aname, AUD_END);
393 BOZO_GetCellName(acall, aname)
394 struct rx_call *acall;
396 register afs_int32 code;
397 char tname[MAXCELLCHARS];
399 code = afsconf_GetLocalCell(bozo_confdir, tname, sizeof(tname));
401 /* must set output parameters even if aborting */
402 *aname = (char *) malloc(1);
406 *aname = (char *) malloc(strlen(tname)+1);
407 strcpy(*aname, tname);
413 BOZO_GetCellHost(acall, awhich, aname)
414 struct rx_call *acall;
417 register afs_int32 code;
418 struct afsconf_cell tcell;
421 code = afsconf_GetCellInfo(bozo_confdir, (char *) 0, (char *) 0, &tcell);
424 if (awhich >= tcell.numServers) {
429 tp = tcell.hostName[awhich];
430 *aname = (char *) malloc(strlen(tp)+1);
435 *aname = (char *) malloc(1); /* return fake string */
442 BOZO_DeleteCellHost(acall, aname)
443 struct rx_call *acall;
445 register afs_int32 code;
446 struct afsconf_cell tcell;
449 char caller[MAXKTCNAMELEN];
451 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
456 bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname);
458 code = afsconf_GetCellInfo(bozo_confdir, (char *) 0, (char *) 0, &tcell);
463 for(i=0;i<tcell.numServers;i++) {
464 if (strcmp(tcell.hostName[i], aname) == 0) {
475 bzero(&tcell.hostAddr[which], sizeof(struct sockaddr_in));
476 bzero(tcell.hostName[which], MAXHOSTCHARS);
477 code = afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH, &tcell);
480 osi_auditU( acall, BOS_DeleteHostEvent, code, AUD_STR, aname, AUD_END);
484 BOZO_AddCellHost(acall, aname)
485 struct rx_call *acall;
487 register afs_int32 code;
488 struct afsconf_cell tcell;
491 char caller[MAXKTCNAMELEN];
493 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
498 bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname);
500 code = afsconf_GetCellInfo(bozo_confdir, (char *) 0, (char *) 0, &tcell);
505 for(i=0;i<tcell.numServers;i++) {
506 if (strcmp(tcell.hostName[i], aname) == 0) {
512 which = tcell.numServers;
516 * Check that tcell has enough space for an additional host.
518 * We assume that tcell.hostAddr[] and tcell.hostName[] have the
519 * same number of entries.
521 if (tcell.numServers > sizeof tcell.hostAddr/sizeof tcell.hostAddr[0]) {
522 bozo_Log("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n",
523 (long)(sizeof tcell.hostAddr/sizeof tcell.hostAddr[0]), aname);
528 /* Check that tcell has enough space for the new hostname. */
529 if (strlen(aname) > sizeof tcell.hostName[0] - 1) {
530 bozo_Log("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n",
531 aname, (long)(sizeof tcell.hostName[0] - 1));
537 bzero(&tcell.hostAddr[which], sizeof(struct sockaddr_in));
538 strcpy(tcell.hostName[which], aname);
539 code = afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH, &tcell);
542 osi_auditU(acall, BOS_AddHostEvent, code, AUD_STR, aname, AUD_END);
546 BOZO_ListKeys(acall, an, akvno, akey, akeyinfo)
547 struct rx_call *acall;
550 struct bozo_keyInfo *akeyinfo;
551 struct bozo_key *akey;
553 struct afsconf_keys tkeys;
554 register afs_int32 code;
557 char caller[MAXKTCNAMELEN];
558 rxkad_level enc_level = rxkad_clear;
560 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
564 if (DoLogging) bozo_Log("%s is executing ListKeys\n", caller);
566 code = afsconf_GetKeys(bozo_confdir, &tkeys);
570 if (tkeys.nkeys <= an) {
574 *akvno = tkeys.key[an].kvno;
575 bzero(akeyinfo, sizeof(struct bozo_keyInfo));
577 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
578 rxkad_GetServerInfo(acall->conn, &enc_level, 0, 0, 0, 0, 0);
580 * only return actual keys in noauth or if this is an encrypted connection
583 if ((noauth) || (enc_level == rxkad_crypt)) {
584 bcopy(tkeys.key[an].key, akey, 8);
586 else bzero (akey, 8);
588 code = stat(AFSDIR_SERVER_KEY_FILEPATH, &tstat);
590 akeyinfo->mod_sec = tstat.st_mtime;
592 ka_KeyCheckSum (tkeys.key[an].key, &akeyinfo->keyCheckSum);
593 /* only errors is bad key parity */
597 osi_auditU(acall, BOS_UnAuthListKeysEvent, code, AUD_END);
598 osi_auditU(acall, BOS_ListKeysEvent, code, AUD_END);
602 BOZO_AddKey(acall, an, akey)
603 struct rx_call *acall;
605 struct bozo_key *akey; {
606 register afs_int32 code;
607 char caller[MAXKTCNAMELEN];
608 rxkad_level enc_level = rxkad_clear;
611 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
615 noauth = afsconf_GetNoAuthFlag(bozo_confdir);
616 rxkad_GetServerInfo(acall->conn, &enc_level, 0, 0, 0, 0, 0);
617 if ((!noauth) && (enc_level != rxkad_crypt)) {
621 if (DoLogging) bozo_Log("%s is executing AddKey\n", caller);
623 code = afsconf_AddKey(bozo_confdir, an, akey, 0);
624 if (code == AFSCONF_KEYINUSE)
625 code = BZKEYINUSE; /* Unique code for afs rpc calls */
627 osi_auditU(acall, BOS_AddKeyEvent, code, AUD_END);
631 BOZO_SetNoAuthFlag(acall, aflag)
632 register struct rx_call *acall;
634 register afs_int32 code = 0;
635 char caller[MAXKTCNAMELEN];
637 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
641 if (DoLogging) bozo_Log("%s is executing Set No Authentication\n", caller);
643 afsconf_SetNoAuthFlag(bozo_confdir, aflag);
646 osi_auditU(acall, BOS_SetNoAuthEvent, code, AUD_LONG, aflag, AUD_END);
650 BOZO_DeleteKey(acall, an)
651 struct rx_call *acall;
653 register afs_int32 code;
654 char caller[MAXKTCNAMELEN];
656 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
660 if (DoLogging) bozo_Log("%s is executing DeleteKey\n", caller);
662 code = afsconf_DeleteKey(bozo_confdir, an);
665 osi_auditU(acall, BOS_DeleteKeyEvent, code, AUD_END);
670 BOZO_ListSUsers(acall, an, aname)
671 struct rx_call *acall;
673 register char **aname; {
674 register afs_int32 code;
677 tp = *aname = (char *) malloc(256);
678 *tp = 0; /* in case getnthuser doesn't null-terminate the string */
679 code = afsconf_GetNthUser(bozo_confdir, an, tp, 256);
682 osi_auditU(acall, BOS_ListSUserEvent, code, AUD_END);
686 BOZO_AddSUser(acall, aname)
687 struct rx_call *acall;
689 register afs_int32 code;
690 char caller[MAXKTCNAMELEN];
692 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
697 bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname);
699 code = afsconf_AddUser(bozo_confdir, aname);
702 osi_auditU(acall, BOS_AddSUserEvent, code, AUD_END);
706 BOZO_DeleteSUser(acall, aname)
707 struct rx_call *acall;
709 register afs_int32 code;
710 char caller[MAXKTCNAMELEN];
712 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
718 bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname);
720 code = afsconf_DeleteUser(bozo_confdir, aname);
723 osi_auditU(acall, BOS_DeleteSUserEvent, code, AUD_END);
727 BOZO_CreateBnode(acall, atype, ainstance, ap1, ap2, ap3, ap4, ap5, notifier)
728 struct rx_call *acall;
731 char *ap1, *ap2, *ap3, *ap4, *ap5;
735 char caller[MAXKTCNAMELEN];
737 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
741 #ifdef BOS_RESTRICTED_MODE
742 if (bozo_isrestricted) {
743 if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp") ||
744 strcmp(ap2, "now") ||
745 strncmp(ap1, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH,
746 strlen(AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH))) {
753 code = bnode_Create(atype, ainstance, &tb, ap1, ap2, ap3, ap4, ap5, notifier,BSTAT_NORMAL);
755 bnode_SetStat(tb, BSTAT_NORMAL);
758 osi_auditU(acall, BOS_CreateBnodeEvent, code, AUD_END);
763 register struct rx_call *acall; {
764 register afs_int32 code;
765 char caller[MAXKTCNAMELEN];
767 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
772 if (DoLogging) bozo_Log("%s is executing Wait for All\n", caller);
774 code = bnode_WaitAll();
777 osi_auditU(acall, BOS_WaitAllEvent, code, AUD_END);
781 BOZO_DeleteBnode(acall, ainstance)
782 struct rx_call *acall;
784 register afs_int32 code;
785 char caller[MAXKTCNAMELEN];
787 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
791 #ifdef BOS_RESTRICTED_MODE
792 if (bozo_isrestricted) {
797 if (DoLogging) bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance);
799 code = bnode_DeleteName(ainstance);
802 osi_auditU(acall, BOS_DeleteBnodeEvent, code, AUD_STR, ainstance, AUD_END);
806 static swproc(abnode, arock)
807 register struct bnode *abnode;
809 if (abnode->goal == BSTAT_NORMAL) return 0; /* this one's not shutting down */
810 /* otherwise, we are shutting down */
812 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
813 bnode_Release(abnode);
814 return 0; /* don't stop apply function early, no matter what */
817 static stproc(abnode, arock)
818 struct bnode *abnode;
820 if (abnode->fileGoal == BSTAT_SHUTDOWN) return 0; /* don't do these guys */
823 bnode_SetStat(abnode, BSTAT_NORMAL);
824 bnode_Release(abnode);
828 static sdproc(abnode, arock)
829 struct bnode *abnode;
832 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
833 bnode_Release(abnode);
837 /* shutdown and leave down */
838 BOZO_ShutdownAll(acall)
839 struct rx_call *acall; {
840 /* iterate over all bnodes, setting the status to temporarily disabled */
841 register afs_int32 code;
842 char caller[MAXKTCNAMELEN];
844 /* check for authorization */
845 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
849 if (DoLogging) bozo_Log("%s is executing ShutdownAll\n", caller);
851 code = bnode_ApplyInstance(sdproc, (char *) 0);
854 osi_auditU (acall, BOS_ShutdownAllEvent, code, AUD_END);
858 /* shutdown and restart */
859 BOZO_RestartAll(acall)
860 struct rx_call *acall; {
861 register afs_int32 code;
862 char caller[MAXKTCNAMELEN];
864 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
868 if (DoLogging) bozo_Log("%s is executing RestartAll\n", caller);
870 /* start shutdown of all processes */
871 code = bnode_ApplyInstance(sdproc, (char *) 0);
874 /* wait for all done */
875 code = bnode_ApplyInstance(swproc, (char *) 0);
878 /* start them up again */
879 code = bnode_ApplyInstance(stproc, (char *) 0);
882 osi_auditU (acall, BOS_RestartAllEvent, code, AUD_END);
887 register struct rx_call *acall; {
888 register afs_int32 code;
889 char caller[MAXKTCNAMELEN];
891 /* acall is null if called internally to restart bosserver */
892 if (acall && !afsconf_SuperUser(bozo_confdir, acall, caller)) {
896 if (DoLogging) bozo_Log("%s is executing ReBozo\n", caller);
898 /* start shutdown of all processes */
899 code = bnode_ApplyInstance(sdproc, (char *) 0);
902 /* wait for all done */
903 code = bnode_ApplyInstance(swproc, (char *) 0);
906 if (acall) osi_auditU (acall, BOS_RebozoEvent, code, AUD_END);
907 else osi_audit (BOS_RebozoIntEvent, code, AUD_END);
909 if (acall) rx_EndCall(acall, 0); /* try to get it done */
911 bozo_ReBozo(); /* this reexecs us, and doesn't return, of course */
914 /* Differentiate between external and internal ReBozo; prevents AFS_Aud_NoCall event */
915 if (acall) osi_auditU (acall, BOS_RebozoEvent, code, AUD_END);
916 else osi_audit (BOS_RebozoIntEvent, code, AUD_END);
917 return code; /* should only get here in unusual circumstances */
920 /* make sure all are running */
921 BOZO_StartupAll(acall)
922 struct rx_call *acall; {
923 register afs_int32 code;
924 char caller[MAXKTCNAMELEN];
926 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
930 if (DoLogging) bozo_Log("%s is executing StartupAll\n", caller);
931 code = bnode_ApplyInstance(stproc, (char *) 0);
934 osi_auditU (acall, BOS_StartupAllEvent, code, AUD_END);
938 BOZO_Restart(acall, ainstance)
939 struct rx_call *acall;
940 register char *ainstance; {
941 register struct bnode *tb;
942 register afs_int32 code;
943 char caller[MAXKTCNAMELEN];
945 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
949 if (DoLogging) bozo_Log("%s is executing Restart '%s'\n", caller, ainstance);
951 tb = bnode_FindInstance(ainstance);
957 /* setup return code */
961 bnode_SetStat(tb, BSTAT_SHUTDOWN);
962 code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN); /* this can fail */
963 bnode_SetStat(tb, BSTAT_NORMAL);
967 osi_auditU (acall, BOS_RestartEvent, code, AUD_STR, ainstance, AUD_END);
971 /* set temp status */
972 BOZO_SetTStatus(acall, ainstance, astatus)
973 struct rx_call *acall;
976 register struct bnode *tb;
977 register afs_int32 code;
978 char caller[MAXKTCNAMELEN];
980 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
984 if (DoLogging) bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance);
986 tb = bnode_FindInstance(ainstance);
992 code = bnode_SetStat(tb, astatus);
996 osi_auditU (acall, BOS_SetTempStatusEvent, code, AUD_STR, ainstance, AUD_END);
1000 BOZO_SetStatus(acall, ainstance, astatus)
1001 struct rx_call *acall;
1003 afs_int32 astatus; {
1004 register struct bnode *tb;
1005 register afs_int32 code;
1006 char caller[MAXKTCNAMELEN];
1008 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1012 if (DoLogging) bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller, ainstance, astatus);
1014 tb = bnode_FindInstance(ainstance);
1020 bnode_SetFileGoal(tb, astatus);
1021 code = bnode_SetStat(tb, astatus);
1025 osi_auditU (acall, BOS_SetStatusEvent, code, AUD_STR, ainstance, AUD_END);
1029 BOZO_GetStatus(acall, ainstance, astat, astatDescr)
1030 struct rx_call *acall;
1033 char **astatDescr; {
1034 register struct bnode *tb;
1035 register afs_int32 code;
1037 tb = bnode_FindInstance(ainstance);
1044 code = bnode_GetStat(tb, astat);
1050 *astatDescr = (char *) malloc(BOZO_BSSIZE);
1051 code = bnode_GetString(tb, *astatDescr, BOZO_BSSIZE);
1053 if (code) (*astatDescr)[0] = 0; /* null string means no further info */
1057 *astatDescr = (char *) malloc(1);
1067 static eifunc(abnode, arock)
1068 struct bnode *abnode;
1069 struct eidata *arock; {
1070 if (arock->counter-- == 0) {
1072 strcpy(arock->iname, abnode->name);
1081 static ZapFile(adir, aname)
1082 register char *adir;
1083 register char *aname; {
1085 strcpy(tbuffer, adir);
1086 strcat(tbuffer, "/");
1087 strcat(tbuffer, aname);
1088 return unlink(tbuffer);
1091 BOZO_Prune(acall, aflags)
1092 struct rx_call *acall;
1094 register afs_int32 code;
1096 register struct dirent *tde;
1098 char caller[MAXKTCNAMELEN];
1100 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1104 #ifdef BOS_RESTRICTED_MODE
1105 if (bozo_isrestricted) {
1110 if (DoLogging) bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags);
1112 /* first scan AFS binary directory */
1113 dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH);
1115 for(tde=readdir(dirp);tde;tde=readdir(dirp)) {
1116 i = strlen(tde->d_name);
1117 if (aflags & BOZO_PRUNEOLD) {
1118 if(i >= 4 && strncmp(tde->d_name+i-4, ".OLD", 4)==0)
1119 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1121 if (aflags & BOZO_PRUNEBAK) {
1122 if(i >= 4 && strncmp(tde->d_name+i-4, ".BAK", 4)==0)
1123 ZapFile(AFSDIR_SERVER_BIN_DIRPATH, tde->d_name);
1129 /* then scan AFS log directory */
1130 dirp = opendir(AFSDIR_SERVER_LOGS_DIRPATH);
1132 for(tde=readdir(dirp);tde;tde=readdir(dirp)) {
1133 if (aflags & BOZO_PRUNECORE) {
1134 if(strncmp(tde->d_name, AFSDIR_CORE_FILE, 4)==0)
1135 ZapFile(AFSDIR_SERVER_LOGS_DIRPATH, tde->d_name);
1143 osi_auditU ( acall, BOS_PruneLogs, code, AUD_END);
1147 BOZO_EnumerateInstance(acall, anum, ainstance)
1148 struct rx_call *acall;
1151 struct eidata tdata;
1153 *ainstance = (char *) malloc(BOZO_BSSIZE);
1155 tdata.counter = anum;
1156 tdata.iname = *ainstance;
1157 bnode_ApplyInstance(eifunc, &tdata);
1158 if (tdata.counter >= 0) return BZDOM; /* anum > # of actual instances */
1162 struct bozo_bosEntryStats bozo_bosEntryStats[] = {
1163 {NULL, 1,1, 0755, 02}, /* AFSDIR_SERVER_AFS_DIRPATH */
1164 {NULL, 1,1, 0755, 02}, /* AFSDIR_SERVER_ETC_DIRPATH */
1165 {NULL, 1,1, 0755, 02}, /* AFSDIR_SERVER_BIN_DIRPATH */
1166 {NULL, 1,1, 0755, 02}, /* AFSDIR_SERVER_LOGS_DIRPATH */
1167 {NULL, 1,0, 0700, 07}, /* AFSDIR_SERVER_BACKUP_DIRPATH */
1168 {NULL, 1,1, 0700, 07}, /* AFSDIR_SERVER_DB_DIRPATH */
1169 {NULL, 1,1, 0700, 07}, /* AFSDIR_SERVER_LOCAL_DIRPATH */
1170 {NULL, 0,1, 0600, 07}, /* AFSDIR_SERVER_KEY_FILEPATH */
1171 {NULL, 0,1, 0600, 03}};/* AFSDIR_SERVER_ULIST_FILEPATH */
1172 int bozo_nbosEntryStats =
1173 sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
1175 /* This function performs initialization of the bozo_bosEntrystats[]
1176 * array. This array contains the list of dirs that the bosserver
1177 * is interested in along with their recommended permissions
1178 * NOTE: This initialization is a bit ugly. This was caused because
1179 * the path names require procedural as opposed to static initialization.
1180 * The other fields in the struct are however, statically initialized.
1182 int initBosEntryStats()
1184 bozo_bosEntryStats[0].path = AFSDIR_SERVER_AFS_DIRPATH;
1185 bozo_bosEntryStats[1].path = AFSDIR_SERVER_ETC_DIRPATH;
1186 bozo_bosEntryStats[2].path = AFSDIR_SERVER_BIN_DIRPATH;
1187 bozo_bosEntryStats[3].path = AFSDIR_SERVER_LOGS_DIRPATH;
1188 bozo_bosEntryStats[4].path = AFSDIR_SERVER_BACKUP_DIRPATH;
1189 bozo_bosEntryStats[5].path = AFSDIR_SERVER_DB_DIRPATH;
1190 bozo_bosEntryStats[6].path = AFSDIR_SERVER_LOCAL_DIRPATH;
1191 bozo_bosEntryStats[7].path = AFSDIR_SERVER_KEY_FILEPATH;
1192 bozo_bosEntryStats[8].path = AFSDIR_SERVER_ULIST_FILEPATH;
1195 /* StatEachEntry - If it's not there, it is okay. If anything else goes wrong
1196 * complain. Otherwise check permissions: shouldn't allow write or (usually)
1199 static int StatEachEntry (stats)
1200 IN struct bozo_bosEntryStats *stats;
1203 if (stat (stats->path, &info)) {
1204 if (errno == ENOENT) return 1; /* no such entry: just ignore it */
1205 return 0; /* something else went wrong */
1208 if (((info.st_mode & S_IFDIR) != 0) != stats->dir)
1209 return 0; /* not expected type */
1210 if (stats->rootOwner && (info.st_uid != 0))
1211 return 0; /* not owned by root */
1212 rights = (info.st_mode & 0000777);
1213 if ((rights & stats->reqPerm) != stats->reqPerm)
1214 return 0; /* required permissions not present */
1215 if ((rights & stats->proPerm) != 0)
1216 return 0; /* prohibited permissions present */
1221 /* DirAccessOK - checks the mode bits on the AFS dir and decendents and
1222 * returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
1223 * this check more often than every 5 seconds. */
1228 /* underlying filesystem may not support directory protection */
1231 static afs_uint32 lastTime = 0;
1232 afs_uint32 now = FT_ApproxTime();
1233 static int lastResult = -1;
1237 if ((now-lastTime) < 5) return lastResult;
1241 for (i=0; i<bozo_nbosEntryStats; i++) {
1242 struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i];
1243 if (!StatEachEntry (e)) {
1249 if (result != lastResult) { /* log changes */
1250 bozo_Log ("Server directory access is %sokay\n",
1251 (result ? "" : "not "));
1253 lastResult = result;
1255 #endif /* AFS_NT40_ENV */
1258 int GetRequiredDirPerm (path)
1262 for (i=0; i<bozo_nbosEntryStats; i++)
1263 if (strcmp (path, bozo_bosEntryStats[i].path) == 0)
1264 return bozo_bosEntryStats[i].reqPerm;
1268 BOZO_GetInstanceInfo(acall, ainstance, atype, astatus)
1269 IN struct rx_call *acall;
1272 OUT struct bozo_status *astatus;
1274 register struct bnode *tb;
1276 tb = bnode_FindInstance(ainstance);
1277 *atype = (char *) malloc(BOZO_BSSIZE);
1279 if (!tb) return BZNOENT;
1281 strcpy(*atype, tb->type->name);
1283 (*atype)[0] = 0; /* null string */
1284 bzero(astatus, sizeof(struct bozo_status)); /* good defaults */
1285 astatus->goal = tb->goal;
1286 astatus->fileGoal = tb->fileGoal;
1287 astatus->procStartTime = tb->procStartTime;
1288 astatus->procStarts = tb->procStarts;
1289 astatus->lastAnyExit = tb->lastAnyExit;
1290 astatus->lastErrorExit = tb->lastErrorExit;
1291 astatus->errorCode = tb->errorCode;
1292 astatus->errorSignal = tb->errorSignal;
1293 if (tb->flags & BNODE_ERRORSTOP)
1294 astatus->flags |= BOZO_ERRORSTOP;
1295 if (bnode_HasCore(tb))
1296 astatus->flags |= BOZO_HASCORE;
1298 astatus->flags |= BOZO_BADDIRACCESS;
1302 BOZO_GetInstanceParm(acall, ainstance, anum, aparm)
1303 struct rx_call *acall;
1307 register struct bnode *tb;
1309 register afs_int32 code;
1311 tp = (char *) malloc(BOZO_BSSIZE);
1313 *tp = 0; /* null-terminate string in error case */
1314 tb = bnode_FindInstance(ainstance);
1315 if (!tb) return BZNOENT;
1319 bcopy(tb->notifier, tp, strlen(tb->notifier)+1);
1322 code = BZNOENT; /* XXXXX */
1324 code = bnode_GetParm(tb, anum, tp, BOZO_BSSIZE);
1327 /* Not Currently Audited */
1331 BOZO_GetLog(acall, aname)
1332 register struct rx_call *acall;
1334 register afs_int32 code;
1339 char caller[MAXKTCNAMELEN];
1341 /* Check access since 'aname' could specify a file outside of the
1342 * AFS log directory (which is bosserver's working directory).
1344 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1348 #ifdef BOS_RESTRICTED_MODE
1349 if (bozo_isrestricted && strchr(aname, '/') &&
1350 strcmp(aname, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH)) {
1356 /* construct local path from canonical (wire-format) path */
1357 if (ConstructLocalLogPath(aname, &logpath)) {
1360 if (DoLogging) bozo_Log("%s is executing GetLog '%s'\n", caller, logpath);
1361 tfile = fopen(logpath, "r");
1370 if (tc == 0) continue; /* our termination condition on other end */
1371 if (tc == EOF) break;
1373 if (rx_Write(acall, &buffer, 1) != 1) {
1380 /* all done, cleanup and return */
1383 /* write out the end delimeter */
1385 if (rx_Write(acall, &buffer, 1) != 1) return BZNET;
1389 osi_auditU( acall, BOS_GetLogsEvent, code, AUD_END);
1393 BOZO_GetInstanceStrings(acall, abnodeName, as1, as2, as3, as4)
1394 struct rx_call *acall;
1396 char **as1, **as2, **as3, **as4; {
1397 register struct bnode *tb;
1399 *as2 = (char *) malloc(1);
1401 *as3 = (char *) malloc(1);
1403 *as4 = (char *) malloc(1);
1405 tb = bnode_FindInstance(abnodeName);
1408 /* now, return the appropriate error string, if any */
1409 if (tb->lastErrorName) {
1410 *as1 = (char *) malloc(strlen(tb->lastErrorName)+1);
1411 strcpy(*as1, tb->lastErrorName);
1414 *as1 = (char *) malloc(1);
1420 *as1 = (char *) malloc(1);
1425 #ifdef BOS_RESTRICTED_MODE
1426 BOZO_GetRestrictedMode(acall, arestmode)
1427 struct rx_call *acall;
1428 afs_int32 *arestmode;
1430 *arestmode=bozo_isrestricted;
1434 BOZO_SetRestrictedMode(acall, arestmode)
1435 struct rx_call *acall;
1436 afs_int32 arestmode;
1439 char caller[MAXKTCNAMELEN];
1441 if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
1444 if (bozo_isrestricted) {
1447 if (arestmode !=0 && arestmode !=1) {
1450 bozo_isrestricted=arestmode;
1451 code = WriteBozoFile(0);
1456 BOZO_GetRestrictedMode(acall, arestmode)
1457 struct rx_call *acall;
1458 afs_int32 *arestmode;
1460 return RXGEN_OPCODE;
1463 BOZO_SetRestrictedMode(acall, arestmode)
1464 struct rx_call *acall;
1465 afs_int32 arestmode;
1467 return RXGEN_OPCODE;
1471 void bozo_ShutdownAndExit(int asignal)
1475 bozo_Log("Shutdown of BOS server and processes in response to signal %d\n",
1478 /* start shutdown of all processes */
1479 if ((code = bnode_ApplyInstance(sdproc, (char *) 0)) == 0) {
1480 /* wait for shutdown to complete */
1481 code = bnode_ApplyInstance(swproc, (char *) 0);
1485 bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n",