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>
14 #include <afs/procmgmt.h>
17 #ifdef IGNORE_SOME_GCC_WARNINGS
18 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
21 #ifdef HAVE_SYS_RESOURCE_H
22 #include <sys/resource.h>
27 #include <WINNT/afsevent.h>
28 #endif /* AFS_NT40_ENV */
32 #include <rx/rx_globals.h>
34 #include <rx/rxstat.h>
36 #include <afs/ktime.h>
37 #include <afs/afsutil.h>
38 #include <afs/fileutil.h>
39 #include <afs/audit.h>
40 #include <afs/cellconfig.h>
42 #if defined(AFS_SGI_ENV)
43 #include <afs/afs_args.h>
48 #include "bosprototypes.h"
50 #define BOZO_LWP_STACKSIZE 16000
51 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
53 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
54 static PROCESS bozo_pid;
55 const char *bozo_fileName;
58 static int bozo_argc = 0;
59 static char** bozo_argv = NULL;
65 const char *DoPidFiles = NULL;
67 int DoSyslogFacility = LOG_DAEMON;
69 static afs_int32 nextRestart;
70 static afs_int32 nextDay;
72 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
75 int rxkadDisableDotCheck = 0;
77 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
78 afs_uint32 SHostAddrs[ADDRSPERSITE];
80 int bozo_isrestricted = 0;
81 int bozo_restdisable = 0;
84 bozo_insecureme(int sig)
86 signal(SIGFPE, bozo_insecureme);
87 bozo_isrestricted = 0;
95 /* check whether caller is authorized to manage RX statistics */
97 bozo_rxstat_userok(struct rx_call *call)
99 return afsconf_SuperUser(bozo_confdir, call, NULL);
103 * Return true if this name is a member of the local realm.
106 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
108 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
109 afs_int32 islocal = 0; /* default to no */
112 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
114 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
115 code, name, inst, cell);
120 /* restart bozo process */
125 /* exit with restart code; SCM integrator process will restart bosserver with
126 the same arguments */
127 exit(BOSEXIT_RESTART);
129 /* exec new bosserver process */
132 /* close random fd's */
133 for (i = 3; i < 64; i++) {
137 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
139 execv(bozo_argv[0], bozo_argv); /* should not return */
141 #endif /* AFS_NT40_ENV */
144 /* make sure a dir exists */
146 MakeDir(const char *adir)
150 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
153 reqPerm = GetRequiredDirPerm(adir);
157 /* underlying filesystem may not support directory protection */
160 code = mkdir(adir, reqPerm);
167 /* create all the bozo dirs */
169 CreateDirs(const char *coredir)
172 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
173 strlen(AFSDIR_USR_DIRPATH)))
176 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
177 strlen(AFSDIR_USR_DIRPATH)))) {
178 MakeDir(AFSDIR_USR_DIRPATH);
181 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
182 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
183 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
185 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
186 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
187 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
188 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
189 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
192 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
193 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
194 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
196 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
198 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
199 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
200 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
201 #endif /* AFS_NT40_ENV */
207 /* strip the \\n from the end of the line, if it is present */
209 StripLine(char *abuffer)
213 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
215 return 0; /* null string, no last character to check */
216 tp--; /* aim at last character */
222 /* write one bnode's worth of entry into the file */
224 bzwrite(struct bnode *abnode, void *arock)
226 struct bztemp *at = (struct bztemp *)arock;
228 char tbuffer[BOZO_BSSIZE];
231 if (abnode->notifier)
232 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
233 abnode->name, abnode->fileGoal, abnode->notifier);
235 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
236 abnode->name, abnode->fileGoal);
238 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
244 fprintf(at->file, "parm %s\n", tbuffer);
246 fprintf(at->file, "end\n");
252 ReadBozoFile(char *aname)
255 char tbuffer[BOZO_BSSIZE];
257 char *instp, *typep, *notifier, *notp;
259 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
262 char *parms[MAXPARMS];
263 char *thisparms[MAXPARMS];
266 /* rename BozoInit to BosServer for the user */
268 /* if BozoInit exists and BosConfig doesn't, try a rename */
269 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
270 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
272 renamefile(AFSDIR_SERVER_BOZINIT_FILEPATH,
273 AFSDIR_SERVER_BOZCONF_FILEPATH);
275 perror("bosconfig rename");
277 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
279 renamefile(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
280 AFSDIR_SERVER_BOZCONF_FILEPATH);
282 perror("bosconfig rename");
286 /* don't do server restarts by default */
287 bozo_nextRestartKT.mask = KTIME_NEVER;
288 bozo_nextRestartKT.hour = 0;
289 bozo_nextRestartKT.min = 0;
290 bozo_nextRestartKT.day = 0;
292 /* restart processes at 5am if their binaries have changed */
293 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
294 bozo_nextDayKT.hour = 5;
295 bozo_nextDayKT.min = 0;
297 for (code = 0; code < MAXPARMS; code++)
301 aname = (char *)bozo_fileName;
302 tfile = fopen(aname, "r");
305 instp = malloc(BOZO_BSSIZE);
306 typep = malloc(BOZO_BSSIZE);
307 notifier = notp = malloc(BOZO_BSSIZE);
309 /* ok, read lines giving parms and such from the file */
310 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
312 break; /* all done */
314 if (strncmp(tbuffer, "restarttime", 11) == 0) {
316 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
317 &kthour, &ktmin, &ktsec);
322 /* otherwise we've read in the proper ktime structure; now assign
323 * it and continue processing */
324 bozo_nextRestartKT.mask = ktmask;
325 bozo_nextRestartKT.day = ktday;
326 bozo_nextRestartKT.hour = kthour;
327 bozo_nextRestartKT.min = ktmin;
328 bozo_nextRestartKT.sec = ktsec;
332 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
334 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
335 &ktday, &kthour, &ktmin, &ktsec);
340 /* otherwise we've read in the proper ktime structure; now assign
341 * it and continue processing */
342 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
343 bozo_nextDayKT.day = ktday;
344 bozo_nextDayKT.hour = kthour;
345 bozo_nextDayKT.min = ktmin;
346 bozo_nextDayKT.sec = ktsec;
350 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
351 code = sscanf(tbuffer, "restrictmode %d", &rmode);
356 if (rmode != 0 && rmode != 1) {
360 bozo_isrestricted = rmode;
364 if (strncmp("bnode", tbuffer, 5) != 0) {
370 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
375 } else if (code == 3)
378 memset(thisparms, 0, sizeof(thisparms));
380 for (i = 0; i < MAXPARMS; i++) {
381 /* now read the parms, until we see an "end" line */
382 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
388 if (!strncmp(tbuffer, "end", 3))
390 if (strncmp(tbuffer, "parm ", 5)) {
392 goto fail; /* no "parm " either */
394 if (!parms[i]) /* make sure there's space */
395 parms[i] = malloc(BOZO_BSSIZE);
396 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
397 thisparms[i] = parms[i];
400 /* ok, we have the type and parms, now create the object */
402 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
403 thisparms[2], thisparms[3], thisparms[4], notifier,
404 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
408 /* bnode created in 'temporarily shutdown' state;
409 * check to see if we are supposed to run this guy,
410 * and if so, start the process up */
412 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
414 bnode_SetStat(tb, BSTAT_SHUTDOWN);
425 for (i = 0; i < MAXPARMS; i++)
433 /* write a new bozo file */
435 WriteBozoFile(char *aname)
438 char tbuffer[AFSDIR_PATH_MAX];
443 aname = (char *)bozo_fileName;
444 strcpy(tbuffer, aname);
445 strcat(tbuffer, ".NBZ");
446 tfile = fopen(tbuffer, "w");
451 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
452 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
453 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
454 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
455 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
456 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
458 code = bnode_ApplyInstance(bzwrite, &btemp);
459 if (code || (code = ferror(tfile))) { /* something went wrong */
464 /* close the file, check for errors and snap new file into place */
465 if (fclose(tfile) == EOF) {
469 code = renamefile(tbuffer, aname);
478 bdrestart(struct bnode *abnode, void *arock)
482 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
483 return 0; /* don't restart stopped bnodes */
485 code = bnode_RestartP(abnode);
487 /* restart the dude */
488 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
489 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
490 bnode_SetStat(abnode, BSTAT_NORMAL);
492 bnode_Release(abnode);
493 return 0; /* keep trying all bnodes */
496 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
497 /* lwp to handle system restarts */
499 BozoDaemon(void *unused)
503 /* now initialize the values */
507 now = FT_ApproxTime();
509 if (bozo_restdisable) {
510 bozo_Log("Restricted mode disabled by signal\n");
511 bozo_restdisable = 0;
514 if (bozo_newKTs) { /* need to recompute restart times */
515 bozo_newKTs = 0; /* done for a while */
516 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
517 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
520 /* see if we should do a restart */
521 if (now > nextRestart) {
522 SBOZO_ReBozo(0); /* doesn't come back */
525 /* see if we should restart a server */
527 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
529 /* call the bnode restartp function, and restart all that require it */
530 bnode_ApplyInstance(bdrestart, 0);
542 int s, sb_max, ipfragttl;
546 f = popen("/usr/sbin/no -o sb_max", "r");
547 s = fscanf(f, "sb_max = %d", &sb_max);
551 f = popen("/usr/sbin/no -o ipfragttl", "r");
552 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
562 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
571 * This routine causes the calling process to go into the background and
572 * to lose its controlling tty.
574 * It does not close or otherwise alter the standard file descriptors.
576 * It writes warning messages to the standard error output if certain
577 * fundamental errors occur.
579 * This routine has been tested on:
595 * A process is a process group leader if its process ID
596 * (getpid()) and its process group ID (getpgrp()) are the same.
600 * To create a new session (and thereby lose our controlling
601 * terminal) we cannot be a process group leader.
603 * To guarantee we are not a process group leader, we fork and
604 * let the parent process exit.
607 if (getpid() == getpgrp()) {
612 abort(); /* leave footprints */
616 default: /* parent */
623 * By here, we are not a process group leader, so we can make a
624 * new session and become the session leader.
628 pid_t sid = setsid();
631 static char err[] = "bosserver: WARNING: setsid() failed\n";
632 write(STDERR_FILENO, err, sizeof err - 1);
637 * Once we create a new session, the current process is a
638 * session leader without a controlling tty.
640 * On some systems, the first tty device the session leader
641 * opens automatically becomes the controlling tty for the
644 * So, to guarantee we do not acquire a controlling tty, we fork
645 * and let the parent process exit. The child process is not a
646 * session leader, and so it will not acquire a controlling tty
647 * even if it should happen to open a tty device.
650 if (getpid() == getpgrp()) {
655 abort(); /* leave footprints */
659 default: /* parent */
666 * check that we no longer have a controlling tty
672 fd = open("/dev/tty", O_RDONLY);
676 "bosserver: WARNING: /dev/tty still attached\n";
678 write(STDERR_FILENO, err, sizeof err - 1);
682 #endif /* ! AFS_NT40_ENV */
686 make_pid_filename(char *ainst, char *aname)
690 if (aname && *aname) {
691 asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
693 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
696 asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
698 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
705 * Write a file containing the pid of the named process.
707 * @param ainst instance name
708 * @param aname sub-process name of the instance, may be null
709 * @param apid process id of the newly started process
714 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
717 char *pidfile = NULL;
720 pidfile = make_pid_filename(ainst, aname);
724 if ((fp = fopen(pidfile, "w")) == NULL) {
725 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
729 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
732 if (fclose(fp) != 0) {
740 * Clean a pid file for a process which just exited.
742 * @param ainst instance name
743 * @param aname sub-process name of the instance, may be null
748 bozo_DeletePidFile(char *ainst, char *aname)
750 char *pidfile = NULL;
751 pidfile = make_pid_filename(ainst, aname);
760 * Create the rxbind file of this bosserver.
762 * @param host bind address of this server
767 bozo_CreateRxBindFile(afs_uint32 host)
772 if (host == htonl(INADDR_ANY)) {
773 host = htonl(0x7f000001);
776 afs_inet_ntoa_r(host, buffer);
777 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
778 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
779 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
780 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
782 fprintf(fp, "%s\n", buffer);
787 /* start a process and monitor it */
789 #include "AFS_component_version_number.c"
792 main(int argc, char **argv, char **envp)
794 struct rx_service *tservice;
796 struct afsconf_dir *tdir;
799 char namebuf[AFSDIR_PATH_MAX];
801 afs_uint32 host = htonl(INADDR_ANY);
802 char *auditFileName = NULL;
803 struct rx_securityClass **securityClasses;
804 afs_int32 numClasses;
810 struct sigaction nsa;
812 /* for some reason, this permits user-mode RX to run a lot faster.
813 * we do it here in the bosserver, so we don't have to do it
814 * individually in each server.
819 * The following signal action for AIX is necessary so that in case of a
820 * crash (i.e. core is generated) we can include the user's data section
821 * in the core dump. Unfortunately, by default, only a partial core is
822 * generated which, in many cases, isn't too useful.
824 sigemptyset(&nsa.sa_mask);
825 nsa.sa_handler = SIG_DFL;
826 nsa.sa_flags = SA_FULLDUMP;
827 sigaction(SIGSEGV, &nsa, NULL);
828 sigaction(SIGABRT, &nsa, NULL);
831 signal(SIGFPE, bozo_insecureme);
834 /* Initialize winsock */
835 if (afs_winsockInit() < 0) {
836 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
837 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
842 /* Initialize dirpaths */
843 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
845 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
847 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
852 /* some path inits */
853 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
854 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
856 /* initialize the list of dirpaths that the bosserver has
857 * an interest in monitoring */
860 #if defined(AFS_SGI_ENV)
861 /* offer some protection if AFS isn't loaded */
862 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
863 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
869 /* save args for restart */
871 bozo_argv = malloc((argc+1) * sizeof(char*));
873 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
876 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
877 bozo_argv[bozo_argc] = NULL; /* null terminate list */
878 #endif /* AFS_NT40_ENV */
881 for (code = 1; code < argc; code++) {
883 bozo_argv[code] = argv[code];
884 #endif /* AFS_NT40_ENV */
885 if (strcmp(argv[code], "-noauth") == 0) {
886 /* set noauth flag */
888 } else if (strcmp(argv[code], "-log") == 0) {
889 /* set extra logging flag */
893 else if (strcmp(argv[code], "-syslog") == 0) {
894 /* set syslog logging flag */
896 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
898 DoSyslogFacility = atoi(argv[code] + 8);
899 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
900 if (strcmp((argv[code]+7), "none") == 0)
903 DoCore = (argv[code]+7);
904 } else if (strcmp(argv[code], "-nofork") == 0) {
908 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
909 rx_enablePeerRPCStats();
910 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
911 rx_enableProcessRPCStats();
913 else if (strcmp(argv[code], "-restricted") == 0) {
914 bozo_isrestricted = 1;
916 else if (strcmp(argv[code], "-rxbind") == 0) {
919 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
920 rxkadDisableDotCheck = 1;
922 else if (!strcmp(argv[code], "-rxmaxmtu")) {
923 if ((code + 1) >= argc) {
924 fprintf(stderr, "missing argument for -rxmaxmtu\n");
927 rxMaxMTU = atoi(argv[++code]);
929 else if (strcmp(argv[code], "-auditlog") == 0) {
930 auditFileName = argv[++code];
932 } else if (strcmp(argv[code], "-audit-interface") == 0) {
933 char *interface = argv[++code];
935 if (osi_audit_interface(interface)) {
936 printf("Invalid audit interface '%s'\n", interface);
939 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
940 DoPidFiles = (argv[code]+10);
941 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
942 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
946 /* hack to support help flag */
949 printf("Usage: bosserver [-noauth] [-log] "
950 "[-auditlog <log path>] "
951 "[-audit-interafce <file|sysvmq> (default is file)] "
952 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
953 "[-syslog[=FACILITY]] "
955 "[-enable_peer_stats] [-enable_process_stats] "
956 "[-cores=<none|path>] \n"
957 "[-pidfiles[=path]] "
958 "[-nofork] " "[-help]\n");
960 printf("Usage: bosserver [-noauth] [-log] "
961 "[-auditlog <log path>] "
962 "[-audit-interafce <file|sysvmq> (default is file)] "
963 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
965 "[-enable_peer_stats] [-enable_process_stats] "
966 "[-cores=<none|path>] \n"
967 "[-pidfiles[=path]] "
976 osi_audit_file(auditFileName);
980 if (geteuid() != 0) {
981 printf("bosserver: must be run as root.\n");
988 printf("bosserver: could not init bnode package, code %d\n", code);
992 bnode_Register("fs", &fsbnode_ops, 3);
993 bnode_Register("dafs", &dafsbnode_ops, 4);
994 bnode_Register("simple", &ezbnode_ops, 1);
995 bnode_Register("cron", &cronbnode_ops, 2);
997 /* create useful dirs */
1000 /* chdir to AFS log directory */
1004 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1007 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1011 /* go into the background and remove our controlling tty, close open
1015 #ifndef AFS_NT40_ENV
1018 #endif /* ! AFS_NT40_ENV */
1021 #ifndef AFS_NT40_ENV
1022 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1023 !(S_ISFIFO(sb.st_mode)))
1026 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1027 strcat(namebuf, ".old");
1028 renamefile(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1029 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1030 if (!bozo_logFile) {
1031 printf("bosserver: can't initialize log file (%s).\n",
1032 AFSDIR_SERVER_BOZLOG_FILEPATH);
1035 /* keep log closed normally, so can be removed */
1036 fclose(bozo_logFile);
1038 #ifndef AFS_NT40_ENV
1039 openlog("bosserver", LOG_PID, DoSyslogFacility);
1043 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1046 getrlimit(RLIMIT_CORE, &rlp);
1050 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1051 setrlimit(RLIMIT_CORE, &rlp);
1052 getrlimit(RLIMIT_CORE, &rlp);
1053 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1057 /* Write current state of directory permissions to log file */
1062 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1063 AFSDIR_SERVER_NETINFO_FILEPATH) {
1065 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1066 ADDRSPERSITE, reason,
1067 AFSDIR_SERVER_NETINFO_FILEPATH,
1068 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1070 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1073 host = SHostAddrs[0];
1076 for (i = 0; i < 10; i++) {
1078 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1080 code = rx_Init(htons(AFSCONF_NANNYPORT));
1083 bozo_Log("can't initialize rx: code=%d\n", code);
1089 bozo_Log("Bos giving up, can't initialize rx\n");
1093 /* Disable jumbograms */
1096 if (rxMaxMTU != -1) {
1097 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1098 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1103 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1104 /* param */ NULL , "bozo-the-clown",
1107 /* try to read the key from the config file */
1108 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1110 /* try to create local cell config file */
1111 struct afsconf_cell tcell;
1112 strcpy(tcell.name, "localcell");
1113 tcell.numServers = 1;
1114 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1116 bozo_Log("failed to get hostname, code %d\n", errno);
1119 if (tcell.hostName[0][0] == 0) {
1120 bozo_Log("host name not set, can't start\n");
1121 bozo_Log("try the 'hostname' command\n");
1124 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1126 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1130 ("could not create cell database in '%s' (code %d), quitting\n",
1131 AFSDIR_SERVER_ETC_DIRPATH, code);
1134 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1137 ("failed to open newly-created cell database, quitting\n");
1142 /* initialize audit user check */
1143 osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
1145 /* read init file, starting up programs */
1146 if ((code = ReadBozoFile(0))) {
1148 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1149 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1153 bozo_CreateRxBindFile(host); /* for local scripts */
1155 /* opened the cell databse */
1156 bozo_confdir = tdir;
1158 /* allow super users to manage RX statistics */
1159 rx_SetRxStatUserOk(bozo_rxstat_userok);
1161 afsconf_SetNoAuthFlag(tdir, noAuth);
1162 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1165 bozo_CreatePidFile("bosserver", NULL, getpid());
1168 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1169 "bozo", securityClasses, numClasses,
1170 BOZO_ExecuteRequest);
1171 rx_SetMinProcs(tservice, 2);
1172 rx_SetMaxProcs(tservice, 4);
1173 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1174 if (rxkadDisableDotCheck) {
1175 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1176 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1180 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1181 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1182 rx_SetMinProcs(tservice, 2);
1183 rx_SetMaxProcs(tservice, 4);
1184 rx_StartServer(1); /* donate this process */
1189 bozo_Log(char *format, ...)
1195 va_start(ap, format);
1198 #ifndef AFS_NT40_ENV
1199 vsyslog(LOG_INFO, format, ap);
1203 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1206 /* log normally closed, so can be removed */
1208 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1209 if (bozo_logFile == NULL) {
1210 printf("bosserver: WARNING: problem with %s\n",
1211 AFSDIR_SERVER_BOZLOG_FILEPATH);
1212 printf("%s ", tdate);
1213 vprintf(format, ap);
1216 fprintf(bozo_logFile, "%s ", tdate);
1217 vfprintf(bozo_logFile, format, ap);
1219 /* close so rm BosLog works */
1220 fclose(bozo_logFile);