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;
61 const char *DoPidFiles = NULL;
63 int DoSyslogFacility = LOG_DAEMON;
65 static afs_int32 nextRestart;
66 static afs_int32 nextDay;
68 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
71 int rxkadDisableDotCheck = 0;
73 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
74 afs_uint32 SHostAddrs[ADDRSPERSITE];
76 int bozo_isrestricted = 0;
77 int bozo_restdisable = 0;
80 bozo_insecureme(int sig)
82 signal(SIGFPE, bozo_insecureme);
83 bozo_isrestricted = 0;
91 /* check whether caller is authorized to manage RX statistics */
93 bozo_rxstat_userok(struct rx_call *call)
95 return afsconf_SuperUser(bozo_confdir, call, NULL);
98 /* restart bozo process */
103 /* exit with restart code; SCM integrator process will restart bosserver */
104 int status = BOSEXIT_RESTART;
106 /* if noauth flag is set, pass "-noauth" to new bosserver */
107 if (afsconf_GetNoAuthFlag(bozo_confdir)) {
108 status |= BOSEXIT_NOAUTH_FLAG;
110 /* if logging is on, pass "-log" to new bosserver */
112 status |= BOSEXIT_LOGGING_FLAG;
114 /* if rxbind is set, pass "-rxbind" to new bosserver */
116 status |= BOSEXIT_RXBIND_FLAG;
120 /* exec new bosserver process */
124 argv[i] = (char *)AFSDIR_SERVER_BOSVR_FILEPATH;
127 /* if noauth flag is set, pass "-noauth" to new bosserver */
128 if (afsconf_GetNoAuthFlag(bozo_confdir)) {
132 /* if logging is on, pass "-log" to new bosserver */
137 /* if rxbind is set, pass "-rxbind" to new bosserver */
143 /* if syslog logging is on, pass "-syslog" to new bosserver */
145 char *arg = (char *)malloc(40); /* enough for -syslog=# */
146 if (DoSyslogFacility != LOG_DAEMON) {
147 snprintf(arg, 40, "-syslog=%d", DoSyslogFacility);
149 strcpy(arg, "-syslog");
156 /* null-terminate argument list */
159 /* close random fd's */
160 for (i = 3; i < 64; i++) {
164 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
166 execv(argv[0], argv); /* should not return */
168 #endif /* AFS_NT40_ENV */
171 /* make sure a dir exists */
173 MakeDir(const char *adir)
177 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
180 reqPerm = GetRequiredDirPerm(adir);
184 /* underlying filesystem may not support directory protection */
187 code = mkdir(adir, reqPerm);
194 /* create all the bozo dirs */
196 CreateDirs(const char *coredir)
199 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
200 strlen(AFSDIR_USR_DIRPATH)))
203 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
204 strlen(AFSDIR_USR_DIRPATH)))) {
205 MakeDir(AFSDIR_USR_DIRPATH);
208 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
209 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
210 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
212 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
213 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
214 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
215 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
216 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
219 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
220 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
221 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
223 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
225 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
226 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
227 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
228 #endif /* AFS_NT40_ENV */
234 /* strip the \\n from the end of the line, if it is present */
236 StripLine(char *abuffer)
240 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
242 return 0; /* null string, no last character to check */
243 tp--; /* aim at last character */
249 /* write one bnode's worth of entry into the file */
251 bzwrite(struct bnode *abnode, void *arock)
253 struct bztemp *at = (struct bztemp *)arock;
255 char tbuffer[BOZO_BSSIZE];
258 if (abnode->notifier)
259 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
260 abnode->name, abnode->fileGoal, abnode->notifier);
262 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
263 abnode->name, abnode->fileGoal);
265 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
271 fprintf(at->file, "parm %s\n", tbuffer);
273 fprintf(at->file, "end\n");
279 ReadBozoFile(char *aname)
282 char tbuffer[BOZO_BSSIZE];
284 char *instp, *typep, *notifier, *notp;
286 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
289 char *parms[MAXPARMS];
290 char *thisparms[MAXPARMS];
293 /* rename BozoInit to BosServer for the user */
295 /* if BozoInit exists and BosConfig doesn't, try a rename */
296 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
297 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
299 renamefile(AFSDIR_SERVER_BOZINIT_FILEPATH,
300 AFSDIR_SERVER_BOZCONF_FILEPATH);
302 perror("bosconfig rename");
304 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
306 renamefile(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
307 AFSDIR_SERVER_BOZCONF_FILEPATH);
309 perror("bosconfig rename");
313 /* don't do server restarts by default */
314 bozo_nextRestartKT.mask = KTIME_NEVER;
315 bozo_nextRestartKT.hour = 0;
316 bozo_nextRestartKT.min = 0;
317 bozo_nextRestartKT.day = 0;
319 /* restart processes at 5am if their binaries have changed */
320 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
321 bozo_nextDayKT.hour = 5;
322 bozo_nextDayKT.min = 0;
324 for (code = 0; code < MAXPARMS; code++)
328 aname = (char *)bozo_fileName;
329 tfile = fopen(aname, "r");
332 instp = malloc(BOZO_BSSIZE);
333 typep = malloc(BOZO_BSSIZE);
334 notifier = notp = malloc(BOZO_BSSIZE);
336 /* ok, read lines giving parms and such from the file */
337 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
339 break; /* all done */
341 if (strncmp(tbuffer, "restarttime", 11) == 0) {
343 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
344 &kthour, &ktmin, &ktsec);
349 /* otherwise we've read in the proper ktime structure; now assign
350 * it and continue processing */
351 bozo_nextRestartKT.mask = ktmask;
352 bozo_nextRestartKT.day = ktday;
353 bozo_nextRestartKT.hour = kthour;
354 bozo_nextRestartKT.min = ktmin;
355 bozo_nextRestartKT.sec = ktsec;
359 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
361 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
362 &ktday, &kthour, &ktmin, &ktsec);
367 /* otherwise we've read in the proper ktime structure; now assign
368 * it and continue processing */
369 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
370 bozo_nextDayKT.day = ktday;
371 bozo_nextDayKT.hour = kthour;
372 bozo_nextDayKT.min = ktmin;
373 bozo_nextDayKT.sec = ktsec;
377 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
378 code = sscanf(tbuffer, "restrictmode %d", &rmode);
383 if (rmode != 0 && rmode != 1) {
387 bozo_isrestricted = rmode;
391 if (strncmp("bnode", tbuffer, 5) != 0) {
397 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
402 } else if (code == 3)
405 memset(thisparms, 0, sizeof(thisparms));
407 for (i = 0; i < MAXPARMS; i++) {
408 /* now read the parms, until we see an "end" line */
409 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
415 if (!strncmp(tbuffer, "end", 3))
417 if (strncmp(tbuffer, "parm ", 5)) {
419 goto fail; /* no "parm " either */
421 if (!parms[i]) /* make sure there's space */
422 parms[i] = (char *)malloc(BOZO_BSSIZE);
423 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
424 thisparms[i] = parms[i];
427 /* ok, we have the type and parms, now create the object */
429 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
430 thisparms[2], thisparms[3], thisparms[4], notifier,
431 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
435 /* bnode created in 'temporarily shutdown' state;
436 * check to see if we are supposed to run this guy,
437 * and if so, start the process up */
439 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
441 bnode_SetStat(tb, BSTAT_SHUTDOWN);
452 for (i = 0; i < MAXPARMS; i++)
460 /* write a new bozo file */
462 WriteBozoFile(char *aname)
465 char tbuffer[AFSDIR_PATH_MAX];
470 aname = (char *)bozo_fileName;
471 strcpy(tbuffer, aname);
472 strcat(tbuffer, ".NBZ");
473 tfile = fopen(tbuffer, "w");
478 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
479 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
480 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
481 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
482 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
483 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
485 code = bnode_ApplyInstance(bzwrite, &btemp);
486 if (code || (code = ferror(tfile))) { /* something went wrong */
491 /* close the file, check for errors and snap new file into place */
492 if (fclose(tfile) == EOF) {
496 code = renamefile(tbuffer, aname);
505 bdrestart(struct bnode *abnode, void *arock)
509 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
510 return 0; /* don't restart stopped bnodes */
512 code = bnode_RestartP(abnode);
514 /* restart the dude */
515 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
516 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
517 bnode_SetStat(abnode, BSTAT_NORMAL);
519 bnode_Release(abnode);
520 return 0; /* keep trying all bnodes */
523 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
524 /* lwp to handle system restarts */
526 BozoDaemon(void *unused)
530 /* now initialize the values */
534 now = FT_ApproxTime();
536 if (bozo_restdisable) {
537 bozo_Log("Restricted mode disabled by signal\n");
538 bozo_restdisable = 0;
541 if (bozo_newKTs) { /* need to recompute restart times */
542 bozo_newKTs = 0; /* done for a while */
543 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
544 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
547 /* see if we should do a restart */
548 if (now > nextRestart) {
549 SBOZO_ReBozo(0); /* doesn't come back */
552 /* see if we should restart a server */
554 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
556 /* call the bnode restartp function, and restart all that require it */
557 bnode_ApplyInstance(bdrestart, 0);
569 int s, sb_max, ipfragttl;
573 f = popen("/usr/sbin/no -o sb_max", "r");
574 s = fscanf(f, "sb_max = %d", &sb_max);
578 f = popen("/usr/sbin/no -o ipfragttl", "r");
579 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
589 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
598 * This routine causes the calling process to go into the background and
599 * to lose its controlling tty.
601 * It does not close or otherwise alter the standard file descriptors.
603 * It writes warning messages to the standard error output if certain
604 * fundamental errors occur.
606 * This routine requires
608 * #include <sys/types.h>
609 * #include <sys/stat.h>
611 * #include <unistd.h>
612 * #include <stdlib.h>
614 * and has been tested on:
630 * A process is a process group leader if its process ID
631 * (getpid()) and its process group ID (getpgrp()) are the same.
635 * To create a new session (and thereby lose our controlling
636 * terminal) we cannot be a process group leader.
638 * To guarantee we are not a process group leader, we fork and
639 * let the parent process exit.
642 if (getpid() == getpgrp()) {
647 abort(); /* leave footprints */
651 default: /* parent */
658 * By here, we are not a process group leader, so we can make a
659 * new session and become the session leader.
663 pid_t sid = setsid();
666 static char err[] = "bosserver: WARNING: setsid() failed\n";
667 write(STDERR_FILENO, err, sizeof err - 1);
672 * Once we create a new session, the current process is a
673 * session leader without a controlling tty.
675 * On some systems, the first tty device the session leader
676 * opens automatically becomes the controlling tty for the
679 * So, to guarantee we do not acquire a controlling tty, we fork
680 * and let the parent process exit. The child process is not a
681 * session leader, and so it will not acquire a controlling tty
682 * even if it should happen to open a tty device.
685 if (getpid() == getpgrp()) {
690 abort(); /* leave footprints */
694 default: /* parent */
701 * check that we no longer have a controlling tty
707 fd = open("/dev/tty", O_RDONLY);
711 "bosserver: WARNING: /dev/tty still attached\n";
713 write(STDERR_FILENO, err, sizeof err - 1);
717 #endif /* ! AFS_NT40_ENV */
721 make_pid_filename(char *ainst, char *aname)
726 length = strlen(DoPidFiles) + strlen(ainst) + 6;
727 if (aname && *aname) {
728 length += strlen(aname) + 1;
730 buffer = malloc(length * sizeof(char));
733 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
736 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
739 if (aname && *aname) {
740 snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
743 snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
750 * Write a file containing the pid of the named process.
752 * @param ainst instance name
753 * @param aname sub-process name of the instance, may be null
754 * @param apid process id of the newly started process
759 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
762 char *pidfile = NULL;
765 pidfile = make_pid_filename(ainst, aname);
769 if ((fp = fopen(pidfile, "w")) == NULL) {
770 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
774 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
777 if (fclose(fp) != 0) {
785 * Clean a pid file for a process which just exited.
787 * @param ainst instance name
788 * @param aname sub-process name of the instance, may be null
793 bozo_DeletePidFile(char *ainst, char *aname)
795 char *pidfile = NULL;
796 pidfile = make_pid_filename(ainst, aname);
805 * Create the rxbind file of this bosserver.
807 * @param host bind address of this server
812 bozo_CreateRxBindFile(afs_uint32 host)
817 if (host == htonl(INADDR_ANY)) {
818 host = htonl(0x7f000001);
821 afs_inet_ntoa_r(host, buffer);
822 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
823 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
824 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
825 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
827 fprintf(fp, "%s\n", buffer);
832 /* start a process and monitor it */
834 #include "AFS_component_version_number.c"
837 main(int argc, char **argv, char **envp)
839 struct rx_service *tservice;
841 struct afsconf_dir *tdir;
844 char namebuf[AFSDIR_PATH_MAX];
846 afs_uint32 host = htonl(INADDR_ANY);
847 char *auditFileName = NULL;
848 struct rx_securityClass **securityClasses;
849 afs_int32 numClasses;
855 struct sigaction nsa;
857 /* for some reason, this permits user-mode RX to run a lot faster.
858 * we do it here in the bosserver, so we don't have to do it
859 * individually in each server.
864 * The following signal action for AIX is necessary so that in case of a
865 * crash (i.e. core is generated) we can include the user's data section
866 * in the core dump. Unfortunately, by default, only a partial core is
867 * generated which, in many cases, isn't too useful.
869 sigemptyset(&nsa.sa_mask);
870 nsa.sa_handler = SIG_DFL;
871 nsa.sa_flags = SA_FULLDUMP;
872 sigaction(SIGSEGV, &nsa, NULL);
873 sigaction(SIGABRT, &nsa, NULL);
876 signal(SIGFPE, bozo_insecureme);
879 /* Initialize winsock */
880 if (afs_winsockInit() < 0) {
881 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
882 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
887 /* Initialize dirpaths */
888 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
890 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
892 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
897 /* some path inits */
898 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
899 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
901 /* initialize the list of dirpaths that the bosserver has
902 * an interest in monitoring */
905 #if defined(AFS_SGI_ENV)
906 /* offer some protection if AFS isn't loaded */
907 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
908 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
914 for (code = 1; code < argc; code++) {
915 if (strcmp(argv[code], "-noauth") == 0) {
916 /* set noauth flag */
918 } else if (strcmp(argv[code], "-log") == 0) {
919 /* set extra logging flag */
923 else if (strcmp(argv[code], "-syslog") == 0) {
924 /* set syslog logging flag */
926 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
928 DoSyslogFacility = atoi(argv[code] + 8);
929 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
930 if (strcmp((argv[code]+7), "none") == 0)
933 DoCore = (argv[code]+7);
934 } else if (strcmp(argv[code], "-nofork") == 0) {
938 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
939 rx_enablePeerRPCStats();
940 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
941 rx_enableProcessRPCStats();
943 else if (strcmp(argv[code], "-restricted") == 0) {
944 bozo_isrestricted = 1;
946 else if (strcmp(argv[code], "-rxbind") == 0) {
949 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
950 rxkadDisableDotCheck = 1;
952 else if (!strcmp(argv[code], "-rxmaxmtu")) {
953 if ((code + 1) >= argc) {
954 fprintf(stderr, "missing argument for -rxmaxmtu\n");
957 rxMaxMTU = atoi(argv[++code]);
958 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
959 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
960 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
961 rxMaxMTU, RX_MIN_PACKET_SIZE,
962 RX_MAX_PACKET_DATA_SIZE);
966 else if (strcmp(argv[code], "-auditlog") == 0) {
967 auditFileName = argv[++code];
969 } else if (strcmp(argv[code], "-audit-interface") == 0) {
970 char *interface = argv[++code];
972 if (osi_audit_interface(interface)) {
973 printf("Invalid audit interface '%s'\n", interface);
976 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
977 DoPidFiles = (argv[code]+10);
978 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
979 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
983 /* hack to support help flag */
986 printf("Usage: bosserver [-noauth] [-log] "
987 "[-auditlog <log path>] "
988 "[-audit-interafce <file|sysvmq> (default is file)] "
989 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
990 "[-syslog[=FACILITY]] "
991 "[-enable_peer_stats] [-enable_process_stats] "
992 "[-cores=<none|path>] \n"
993 "[-pidfiles[=path]] "
994 "[-nofork] " "[-help]\n");
996 printf("Usage: bosserver [-noauth] [-log] "
997 "[-auditlog <log path>] "
998 "[-audit-interafce <file|sysvmq> (default is file)] "
999 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
1000 "[-enable_peer_stats] [-enable_process_stats] "
1001 "[-cores=<none|path>] \n"
1002 "[-pidfiles[=path]] "
1010 if (auditFileName) {
1011 osi_audit_file(auditFileName);
1014 #ifndef AFS_NT40_ENV
1015 if (geteuid() != 0) {
1016 printf("bosserver: must be run as root.\n");
1021 code = bnode_Init();
1023 printf("bosserver: could not init bnode package, code %d\n", code);
1027 bnode_Register("fs", &fsbnode_ops, 3);
1028 bnode_Register("dafs", &dafsbnode_ops, 4);
1029 bnode_Register("simple", &ezbnode_ops, 1);
1030 bnode_Register("cron", &cronbnode_ops, 2);
1032 /* create useful dirs */
1035 /* chdir to AFS log directory */
1039 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1042 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1046 /* go into the background and remove our controlling tty, close open
1050 #ifndef AFS_NT40_ENV
1053 #endif /* ! AFS_NT40_ENV */
1056 #ifndef AFS_NT40_ENV
1057 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1058 !(S_ISFIFO(sb.st_mode)))
1061 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1062 strcat(namebuf, ".old");
1063 renamefile(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1064 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1065 if (!bozo_logFile) {
1066 printf("bosserver: can't initialize log file (%s).\n",
1067 AFSDIR_SERVER_BOZLOG_FILEPATH);
1070 /* keep log closed normally, so can be removed */
1071 fclose(bozo_logFile);
1073 #ifndef AFS_NT40_ENV
1074 openlog("bosserver", LOG_PID, DoSyslogFacility);
1078 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1081 getrlimit(RLIMIT_CORE, &rlp);
1085 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1086 setrlimit(RLIMIT_CORE, &rlp);
1087 getrlimit(RLIMIT_CORE, &rlp);
1088 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1092 /* Write current state of directory permissions to log file */
1097 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1098 AFSDIR_SERVER_NETINFO_FILEPATH) {
1100 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1101 ADDRSPERSITE, reason,
1102 AFSDIR_SERVER_NETINFO_FILEPATH,
1103 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1105 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1108 host = SHostAddrs[0];
1111 for (i = 0; i < 10; i++) {
1113 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1115 code = rx_Init(htons(AFSCONF_NANNYPORT));
1118 bozo_Log("can't initialize rx: code=%d\n", code);
1124 bozo_Log("Bos giving up, can't initialize rx\n");
1128 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1129 /* param */ NULL , "bozo-the-clown",
1132 /* try to read the key from the config file */
1133 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1135 /* try to create local cell config file */
1136 struct afsconf_cell tcell;
1137 strcpy(tcell.name, "localcell");
1138 tcell.numServers = 1;
1139 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1141 bozo_Log("failed to get hostname, code %d\n", errno);
1144 if (tcell.hostName[0][0] == 0) {
1145 bozo_Log("host name not set, can't start\n");
1146 bozo_Log("try the 'hostname' command\n");
1149 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1151 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1155 ("could not create cell database in '%s' (code %d), quitting\n",
1156 AFSDIR_SERVER_ETC_DIRPATH, code);
1159 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1162 ("failed to open newly-created cell database, quitting\n");
1167 /* read init file, starting up programs */
1168 if ((code = ReadBozoFile(0))) {
1170 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1171 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1175 bozo_CreateRxBindFile(host); /* for local scripts */
1177 /* opened the cell databse */
1178 bozo_confdir = tdir;
1180 /* allow super users to manage RX statistics */
1181 rx_SetRxStatUserOk(bozo_rxstat_userok);
1183 afsconf_SetNoAuthFlag(tdir, noAuth);
1184 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1187 bozo_CreatePidFile("bosserver", NULL, getpid());
1190 /* Disable jumbograms */
1193 if (rxMaxMTU != -1) {
1194 rx_SetMaxMTU(rxMaxMTU);
1197 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1198 "bozo", securityClasses, numClasses,
1199 BOZO_ExecuteRequest);
1200 rx_SetMinProcs(tservice, 2);
1201 rx_SetMaxProcs(tservice, 4);
1202 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1203 if (rxkadDisableDotCheck) {
1204 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1205 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1209 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1210 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1211 rx_SetMinProcs(tservice, 2);
1212 rx_SetMaxProcs(tservice, 4);
1213 rx_StartServer(1); /* donate this process */
1218 bozo_Log(char *format, ...)
1224 va_start(ap, format);
1227 #ifndef AFS_NT40_ENV
1228 vsyslog(LOG_INFO, format, ap);
1232 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1235 /* log normally closed, so can be removed */
1237 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1238 if (bozo_logFile == NULL) {
1239 printf("bosserver: WARNING: problem with %s\n",
1240 AFSDIR_SERVER_BOZLOG_FILEPATH);
1241 printf("%s ", tdate);
1242 vprintf(format, ap);
1245 fprintf(bozo_logFile, "%s ", tdate);
1246 vfprintf(bozo_logFile, format, ap);
1248 /* close so rm BosLog works */
1249 fclose(bozo_logFile);