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]);
959 else if (strcmp(argv[code], "-auditlog") == 0) {
960 auditFileName = argv[++code];
962 } else if (strcmp(argv[code], "-audit-interface") == 0) {
963 char *interface = argv[++code];
965 if (osi_audit_interface(interface)) {
966 printf("Invalid audit interface '%s'\n", interface);
969 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
970 DoPidFiles = (argv[code]+10);
971 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
972 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
976 /* hack to support help flag */
979 printf("Usage: bosserver [-noauth] [-log] "
980 "[-auditlog <log path>] "
981 "[-audit-interafce <file|sysvmq> (default is file)] "
982 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
983 "[-syslog[=FACILITY]] "
985 "[-enable_peer_stats] [-enable_process_stats] "
986 "[-cores=<none|path>] \n"
987 "[-pidfiles[=path]] "
988 "[-nofork] " "[-help]\n");
990 printf("Usage: bosserver [-noauth] [-log] "
991 "[-auditlog <log path>] "
992 "[-audit-interafce <file|sysvmq> (default is file)] "
993 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
995 "[-enable_peer_stats] [-enable_process_stats] "
996 "[-cores=<none|path>] \n"
997 "[-pidfiles[=path]] "
1005 if (auditFileName) {
1006 osi_audit_file(auditFileName);
1009 #ifndef AFS_NT40_ENV
1010 if (geteuid() != 0) {
1011 printf("bosserver: must be run as root.\n");
1016 code = bnode_Init();
1018 printf("bosserver: could not init bnode package, code %d\n", code);
1022 bnode_Register("fs", &fsbnode_ops, 3);
1023 bnode_Register("dafs", &dafsbnode_ops, 4);
1024 bnode_Register("simple", &ezbnode_ops, 1);
1025 bnode_Register("cron", &cronbnode_ops, 2);
1027 /* create useful dirs */
1030 /* chdir to AFS log directory */
1034 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1037 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1041 /* go into the background and remove our controlling tty, close open
1045 #ifndef AFS_NT40_ENV
1048 #endif /* ! AFS_NT40_ENV */
1051 #ifndef AFS_NT40_ENV
1052 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1053 !(S_ISFIFO(sb.st_mode)))
1056 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1057 strcat(namebuf, ".old");
1058 renamefile(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1059 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1060 if (!bozo_logFile) {
1061 printf("bosserver: can't initialize log file (%s).\n",
1062 AFSDIR_SERVER_BOZLOG_FILEPATH);
1065 /* keep log closed normally, so can be removed */
1066 fclose(bozo_logFile);
1068 #ifndef AFS_NT40_ENV
1069 openlog("bosserver", LOG_PID, DoSyslogFacility);
1073 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1076 getrlimit(RLIMIT_CORE, &rlp);
1080 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1081 setrlimit(RLIMIT_CORE, &rlp);
1082 getrlimit(RLIMIT_CORE, &rlp);
1083 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1087 /* Write current state of directory permissions to log file */
1092 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1093 AFSDIR_SERVER_NETINFO_FILEPATH) {
1095 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1096 ADDRSPERSITE, reason,
1097 AFSDIR_SERVER_NETINFO_FILEPATH,
1098 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1100 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1103 host = SHostAddrs[0];
1106 for (i = 0; i < 10; i++) {
1108 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1110 code = rx_Init(htons(AFSCONF_NANNYPORT));
1113 bozo_Log("can't initialize rx: code=%d\n", code);
1119 bozo_Log("Bos giving up, can't initialize rx\n");
1123 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1124 /* param */ NULL , "bozo-the-clown",
1127 /* try to read the key from the config file */
1128 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1130 /* try to create local cell config file */
1131 struct afsconf_cell tcell;
1132 strcpy(tcell.name, "localcell");
1133 tcell.numServers = 1;
1134 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1136 bozo_Log("failed to get hostname, code %d\n", errno);
1139 if (tcell.hostName[0][0] == 0) {
1140 bozo_Log("host name not set, can't start\n");
1141 bozo_Log("try the 'hostname' command\n");
1144 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1146 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1150 ("could not create cell database in '%s' (code %d), quitting\n",
1151 AFSDIR_SERVER_ETC_DIRPATH, code);
1154 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1157 ("failed to open newly-created cell database, quitting\n");
1162 /* read init file, starting up programs */
1163 if ((code = ReadBozoFile(0))) {
1165 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1166 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1170 bozo_CreateRxBindFile(host); /* for local scripts */
1172 /* opened the cell databse */
1173 bozo_confdir = tdir;
1175 /* allow super users to manage RX statistics */
1176 rx_SetRxStatUserOk(bozo_rxstat_userok);
1178 afsconf_SetNoAuthFlag(tdir, noAuth);
1179 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1182 bozo_CreatePidFile("bosserver", NULL, getpid());
1185 /* Disable jumbograms */
1188 if (rxMaxMTU != -1) {
1189 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1190 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1195 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1196 "bozo", securityClasses, numClasses,
1197 BOZO_ExecuteRequest);
1198 rx_SetMinProcs(tservice, 2);
1199 rx_SetMaxProcs(tservice, 4);
1200 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1201 if (rxkadDisableDotCheck) {
1202 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1203 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1207 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1208 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1209 rx_SetMinProcs(tservice, 2);
1210 rx_SetMaxProcs(tservice, 4);
1211 rx_StartServer(1); /* donate this process */
1216 bozo_Log(char *format, ...)
1222 va_start(ap, format);
1225 #ifndef AFS_NT40_ENV
1226 vsyslog(LOG_INFO, format, ap);
1230 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1233 /* log normally closed, so can be removed */
1235 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1236 if (bozo_logFile == NULL) {
1237 printf("bosserver: WARNING: problem with %s\n",
1238 AFSDIR_SERVER_BOZLOG_FILEPATH);
1239 printf("%s ", tdate);
1240 vprintf(format, ap);
1243 fprintf(bozo_logFile, "%s ", tdate);
1244 vfprintf(bozo_logFile, format, ap);
1246 /* close so rm BosLog works */
1247 fclose(bozo_logFile);