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
19 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
21 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
25 #ifdef HAVE_SYS_RESOURCE_H
26 #include <sys/resource.h>
31 #include <WINNT/afsevent.h>
32 #endif /* AFS_NT40_ENV */
36 #include <rx/rx_globals.h>
38 #include <rx/rxstat.h>
40 #include <afs/ktime.h>
41 #include <afs/afsutil.h>
42 #include <afs/fileutil.h>
43 #include <afs/audit.h>
44 #include <afs/cellconfig.h>
46 #if defined(AFS_SGI_ENV)
47 #include <afs/afs_args.h>
52 #include "bnode_internal.h"
53 #include "bosprototypes.h"
55 #define BOZO_LWP_STACKSIZE 16000
56 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
58 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
59 static PROCESS bozo_pid;
60 const char *bozo_fileName;
63 static int bozo_argc = 0;
64 static char** bozo_argv = NULL;
70 const char *DoPidFiles = NULL;
72 int DoSyslogFacility = LOG_DAEMON;
74 static afs_int32 nextRestart;
75 static afs_int32 nextDay;
77 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
80 int rxkadDisableDotCheck = 0;
82 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
83 afs_uint32 SHostAddrs[ADDRSPERSITE];
85 int bozo_isrestricted = 0;
86 int bozo_restdisable = 0;
89 bozo_insecureme(int sig)
91 signal(SIGFPE, bozo_insecureme);
92 bozo_isrestricted = 0;
100 /* check whether caller is authorized to manage RX statistics */
102 bozo_rxstat_userok(struct rx_call *call)
104 return afsconf_SuperUser(bozo_confdir, call, NULL);
108 * Return true if this name is a member of the local realm.
111 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
113 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
114 afs_int32 islocal = 0; /* default to no */
117 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
119 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
120 code, name, inst, cell);
125 /* restart bozo process */
130 /* exit with restart code; SCM integrator process will restart bosserver with
131 the same arguments */
132 exit(BOSEXIT_RESTART);
134 /* exec new bosserver process */
137 /* close random fd's */
138 for (i = 3; i < 64; i++) {
142 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
144 execv(bozo_argv[0], bozo_argv); /* should not return */
146 #endif /* AFS_NT40_ENV */
149 /* make sure a dir exists */
151 MakeDir(const char *adir)
155 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
158 reqPerm = GetRequiredDirPerm(adir);
162 /* underlying filesystem may not support directory protection */
165 code = mkdir(adir, reqPerm);
172 /* create all the bozo dirs */
174 CreateDirs(const char *coredir)
177 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
178 strlen(AFSDIR_USR_DIRPATH)))
181 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
182 strlen(AFSDIR_USR_DIRPATH)))) {
183 MakeDir(AFSDIR_USR_DIRPATH);
186 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
187 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
188 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
190 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
191 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
192 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
193 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
194 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
197 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
198 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
199 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
201 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
203 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
204 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
205 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
206 #endif /* AFS_NT40_ENV */
212 /* strip the \\n from the end of the line, if it is present */
214 StripLine(char *abuffer)
218 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
220 return 0; /* null string, no last character to check */
221 tp--; /* aim at last character */
227 /* write one bnode's worth of entry into the file */
229 bzwrite(struct bnode *abnode, void *arock)
231 struct bztemp *at = (struct bztemp *)arock;
233 char tbuffer[BOZO_BSSIZE];
236 if (abnode->notifier)
237 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
238 abnode->name, abnode->fileGoal, abnode->notifier);
240 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
241 abnode->name, abnode->fileGoal);
243 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
249 fprintf(at->file, "parm %s\n", tbuffer);
251 fprintf(at->file, "end\n");
257 ReadBozoFile(char *aname)
260 char tbuffer[BOZO_BSSIZE];
262 char *instp, *typep, *notifier, *notp;
264 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
267 char *parms[MAXPARMS];
268 char *thisparms[MAXPARMS];
271 /* rename BozoInit to BosServer for the user */
273 /* if BozoInit exists and BosConfig doesn't, try a rename */
274 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
275 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
276 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
277 AFSDIR_SERVER_BOZCONF_FILEPATH);
279 perror("bosconfig rename");
281 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
282 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
283 AFSDIR_SERVER_BOZCONF_FILEPATH);
285 perror("bosconfig rename");
289 /* don't do server restarts by default */
290 bozo_nextRestartKT.mask = KTIME_NEVER;
291 bozo_nextRestartKT.hour = 0;
292 bozo_nextRestartKT.min = 0;
293 bozo_nextRestartKT.day = 0;
295 /* restart processes at 5am if their binaries have changed */
296 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
297 bozo_nextDayKT.hour = 5;
298 bozo_nextDayKT.min = 0;
300 for (code = 0; code < MAXPARMS; code++)
304 aname = (char *)bozo_fileName;
305 tfile = fopen(aname, "r");
308 instp = malloc(BOZO_BSSIZE);
309 typep = malloc(BOZO_BSSIZE);
310 notifier = notp = malloc(BOZO_BSSIZE);
312 /* ok, read lines giving parms and such from the file */
313 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
315 break; /* all done */
317 if (strncmp(tbuffer, "restarttime", 11) == 0) {
319 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
320 &kthour, &ktmin, &ktsec);
325 /* otherwise we've read in the proper ktime structure; now assign
326 * it and continue processing */
327 bozo_nextRestartKT.mask = ktmask;
328 bozo_nextRestartKT.day = ktday;
329 bozo_nextRestartKT.hour = kthour;
330 bozo_nextRestartKT.min = ktmin;
331 bozo_nextRestartKT.sec = ktsec;
335 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
337 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
338 &ktday, &kthour, &ktmin, &ktsec);
343 /* otherwise we've read in the proper ktime structure; now assign
344 * it and continue processing */
345 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
346 bozo_nextDayKT.day = ktday;
347 bozo_nextDayKT.hour = kthour;
348 bozo_nextDayKT.min = ktmin;
349 bozo_nextDayKT.sec = ktsec;
353 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
354 code = sscanf(tbuffer, "restrictmode %d", &rmode);
359 if (rmode != 0 && rmode != 1) {
363 bozo_isrestricted = rmode;
367 if (strncmp("bnode", tbuffer, 5) != 0) {
373 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
378 } else if (code == 3)
381 memset(thisparms, 0, sizeof(thisparms));
383 for (i = 0; i < MAXPARMS; i++) {
384 /* now read the parms, until we see an "end" line */
385 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
391 if (!strncmp(tbuffer, "end", 3))
393 if (strncmp(tbuffer, "parm ", 5)) {
395 goto fail; /* no "parm " either */
397 if (!parms[i]) /* make sure there's space */
398 parms[i] = malloc(BOZO_BSSIZE);
399 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
400 thisparms[i] = parms[i];
403 /* ok, we have the type and parms, now create the object */
405 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
406 thisparms[2], thisparms[3], thisparms[4], notifier,
407 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
411 /* bnode created in 'temporarily shutdown' state;
412 * check to see if we are supposed to run this guy,
413 * and if so, start the process up */
415 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
417 bnode_SetStat(tb, BSTAT_SHUTDOWN);
428 for (i = 0; i < MAXPARMS; i++)
436 /* write a new bozo file */
438 WriteBozoFile(char *aname)
441 char tbuffer[AFSDIR_PATH_MAX];
446 aname = (char *)bozo_fileName;
447 strcpy(tbuffer, aname);
448 strcat(tbuffer, ".NBZ");
449 tfile = fopen(tbuffer, "w");
454 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
455 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
456 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
457 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
458 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
459 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
461 code = bnode_ApplyInstance(bzwrite, &btemp);
462 if (code || (code = ferror(tfile))) { /* something went wrong */
467 /* close the file, check for errors and snap new file into place */
468 if (fclose(tfile) == EOF) {
472 code = rk_rename(tbuffer, aname);
481 bdrestart(struct bnode *abnode, void *arock)
485 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
486 return 0; /* don't restart stopped bnodes */
488 code = bnode_RestartP(abnode);
490 /* restart the dude */
491 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
492 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
493 bnode_SetStat(abnode, BSTAT_NORMAL);
495 bnode_Release(abnode);
496 return 0; /* keep trying all bnodes */
499 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
500 /* lwp to handle system restarts */
502 BozoDaemon(void *unused)
506 /* now initialize the values */
510 now = FT_ApproxTime();
512 if (bozo_restdisable) {
513 bozo_Log("Restricted mode disabled by signal\n");
514 bozo_restdisable = 0;
517 if (bozo_newKTs) { /* need to recompute restart times */
518 bozo_newKTs = 0; /* done for a while */
519 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
520 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
523 /* see if we should do a restart */
524 if (now > nextRestart) {
525 SBOZO_ReBozo(0); /* doesn't come back */
528 /* see if we should restart a server */
530 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
532 /* call the bnode restartp function, and restart all that require it */
533 bnode_ApplyInstance(bdrestart, 0);
545 int s, sb_max, ipfragttl;
549 f = popen("/usr/sbin/no -o sb_max", "r");
550 s = fscanf(f, "sb_max = %d", &sb_max);
554 f = popen("/usr/sbin/no -o ipfragttl", "r");
555 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
565 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
574 * This routine causes the calling process to go into the background and
575 * to lose its controlling tty.
577 * It does not close or otherwise alter the standard file descriptors.
579 * It writes warning messages to the standard error output if certain
580 * fundamental errors occur.
582 * This routine has been tested on:
598 * A process is a process group leader if its process ID
599 * (getpid()) and its process group ID (getpgrp()) are the same.
603 * To create a new session (and thereby lose our controlling
604 * terminal) we cannot be a process group leader.
606 * To guarantee we are not a process group leader, we fork and
607 * let the parent process exit.
610 if (getpid() == getpgrp()) {
615 abort(); /* leave footprints */
619 default: /* parent */
626 * By here, we are not a process group leader, so we can make a
627 * new session and become the session leader.
631 pid_t sid = setsid();
634 static char err[] = "bosserver: WARNING: setsid() failed\n";
635 write(STDERR_FILENO, err, sizeof err - 1);
640 * Once we create a new session, the current process is a
641 * session leader without a controlling tty.
643 * On some systems, the first tty device the session leader
644 * opens automatically becomes the controlling tty for the
647 * So, to guarantee we do not acquire a controlling tty, we fork
648 * and let the parent process exit. The child process is not a
649 * session leader, and so it will not acquire a controlling tty
650 * even if it should happen to open a tty device.
653 if (getpid() == getpgrp()) {
658 abort(); /* leave footprints */
662 default: /* parent */
669 * check that we no longer have a controlling tty
675 fd = open("/dev/tty", O_RDONLY);
679 "bosserver: WARNING: /dev/tty still attached\n";
681 write(STDERR_FILENO, err, sizeof err - 1);
685 #endif /* ! AFS_NT40_ENV */
689 make_pid_filename(char *ainst, char *aname)
693 if (aname && *aname) {
694 asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
696 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
699 asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
701 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
708 * Write a file containing the pid of the named process.
710 * @param ainst instance name
711 * @param aname sub-process name of the instance, may be null
712 * @param apid process id of the newly started process
717 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
720 char *pidfile = NULL;
723 pidfile = make_pid_filename(ainst, aname);
727 if ((fp = fopen(pidfile, "w")) == NULL) {
728 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
732 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
735 if (fclose(fp) != 0) {
743 * Clean a pid file for a process which just exited.
745 * @param ainst instance name
746 * @param aname sub-process name of the instance, may be null
751 bozo_DeletePidFile(char *ainst, char *aname)
753 char *pidfile = NULL;
754 pidfile = make_pid_filename(ainst, aname);
763 * Create the rxbind file of this bosserver.
765 * @param host bind address of this server
770 bozo_CreateRxBindFile(afs_uint32 host)
775 afs_inet_ntoa_r(host, buffer);
776 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
777 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
778 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
779 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
781 /* If listening on any interface, write the loopback interface
782 to the rxbind file to give local scripts a usable addresss. */
783 if (host == htonl(INADDR_ANY)) {
784 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
786 fprintf(fp, "%s\n", buffer);
791 /* start a process and monitor it */
793 #include "AFS_component_version_number.c"
796 main(int argc, char **argv, char **envp)
798 struct rx_service *tservice;
800 struct afsconf_dir *tdir;
803 char namebuf[AFSDIR_PATH_MAX];
805 afs_uint32 host = htonl(INADDR_ANY);
806 char *auditFileName = NULL;
807 struct rx_securityClass **securityClasses;
808 afs_int32 numClasses;
814 struct sigaction nsa;
816 /* for some reason, this permits user-mode RX to run a lot faster.
817 * we do it here in the bosserver, so we don't have to do it
818 * individually in each server.
823 * The following signal action for AIX is necessary so that in case of a
824 * crash (i.e. core is generated) we can include the user's data section
825 * in the core dump. Unfortunately, by default, only a partial core is
826 * generated which, in many cases, isn't too useful.
828 sigemptyset(&nsa.sa_mask);
829 nsa.sa_handler = SIG_DFL;
830 nsa.sa_flags = SA_FULLDUMP;
831 sigaction(SIGSEGV, &nsa, NULL);
832 sigaction(SIGABRT, &nsa, NULL);
835 signal(SIGFPE, bozo_insecureme);
838 /* Initialize winsock */
839 if (afs_winsockInit() < 0) {
840 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
841 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
846 /* Initialize dirpaths */
847 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
849 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
851 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
856 /* some path inits */
857 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
858 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
860 /* initialize the list of dirpaths that the bosserver has
861 * an interest in monitoring */
864 #if defined(AFS_SGI_ENV)
865 /* offer some protection if AFS isn't loaded */
866 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
867 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
873 /* save args for restart */
875 bozo_argv = malloc((argc+1) * sizeof(char*));
877 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
880 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
881 bozo_argv[bozo_argc] = NULL; /* null terminate list */
882 #endif /* AFS_NT40_ENV */
885 for (code = 1; code < argc; code++) {
887 bozo_argv[code] = argv[code];
888 #endif /* AFS_NT40_ENV */
889 if (strcmp(argv[code], "-noauth") == 0) {
890 /* set noauth flag */
892 } else if (strcmp(argv[code], "-log") == 0) {
893 /* set extra logging flag */
897 else if (strcmp(argv[code], "-syslog") == 0) {
898 /* set syslog logging flag */
900 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
902 DoSyslogFacility = atoi(argv[code] + 8);
903 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
904 if (strcmp((argv[code]+7), "none") == 0)
907 DoCore = (argv[code]+7);
908 } else if (strcmp(argv[code], "-nofork") == 0) {
912 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
913 rx_enablePeerRPCStats();
914 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
915 rx_enableProcessRPCStats();
917 else if (strcmp(argv[code], "-restricted") == 0) {
918 bozo_isrestricted = 1;
920 else if (strcmp(argv[code], "-rxbind") == 0) {
923 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
924 rxkadDisableDotCheck = 1;
926 else if (!strcmp(argv[code], "-rxmaxmtu")) {
927 if ((code + 1) >= argc) {
928 fprintf(stderr, "missing argument for -rxmaxmtu\n");
931 rxMaxMTU = atoi(argv[++code]);
933 else if (strcmp(argv[code], "-auditlog") == 0) {
934 auditFileName = argv[++code];
936 } else if (strcmp(argv[code], "-audit-interface") == 0) {
937 char *interface = argv[++code];
939 if (osi_audit_interface(interface)) {
940 printf("Invalid audit interface '%s'\n", interface);
943 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
944 DoPidFiles = (argv[code]+10);
945 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
946 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
950 /* hack to support help flag */
953 printf("Usage: bosserver [-noauth] [-log] "
954 "[-auditlog <log path>] "
955 "[-audit-interface <file|sysvmq> (default is file)] "
956 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
957 "[-syslog[=FACILITY]] "
959 "[-enable_peer_stats] [-enable_process_stats] "
960 "[-cores=<none|path>] \n"
961 "[-pidfiles[=path]] "
962 "[-nofork] " "[-help]\n");
964 printf("Usage: bosserver [-noauth] [-log] "
965 "[-auditlog <log path>] "
966 "[-audit-interface <file|sysvmq> (default is file)] "
967 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
969 "[-enable_peer_stats] [-enable_process_stats] "
970 "[-cores=<none|path>] \n"
971 "[-pidfiles[=path]] "
980 osi_audit_file(auditFileName);
984 if (geteuid() != 0) {
985 printf("bosserver: must be run as root.\n");
992 printf("bosserver: could not init bnode package, code %d\n", code);
996 bnode_Register("fs", &fsbnode_ops, 3);
997 bnode_Register("dafs", &dafsbnode_ops, 4);
998 bnode_Register("simple", &ezbnode_ops, 1);
999 bnode_Register("cron", &cronbnode_ops, 2);
1001 /* create useful dirs */
1004 /* chdir to AFS log directory */
1008 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1011 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1015 /* go into the background and remove our controlling tty, close open
1019 #ifndef AFS_NT40_ENV
1022 #endif /* ! AFS_NT40_ENV */
1025 #ifndef AFS_NT40_ENV
1026 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1027 !(S_ISFIFO(sb.st_mode)))
1030 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1031 strcat(namebuf, ".old");
1032 rk_rename(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1033 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1034 if (!bozo_logFile) {
1035 printf("bosserver: can't initialize log file (%s).\n",
1036 AFSDIR_SERVER_BOZLOG_FILEPATH);
1039 /* keep log closed normally, so can be removed */
1040 fclose(bozo_logFile);
1042 #ifndef AFS_NT40_ENV
1043 openlog("bosserver", LOG_PID, DoSyslogFacility);
1047 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1050 getrlimit(RLIMIT_CORE, &rlp);
1054 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1055 setrlimit(RLIMIT_CORE, &rlp);
1056 getrlimit(RLIMIT_CORE, &rlp);
1057 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1061 /* Write current state of directory permissions to log file */
1066 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1067 AFSDIR_SERVER_NETINFO_FILEPATH) {
1069 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1070 ADDRSPERSITE, reason,
1071 AFSDIR_SERVER_NETINFO_FILEPATH,
1072 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1074 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1077 host = SHostAddrs[0];
1080 for (i = 0; i < 10; i++) {
1082 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1084 code = rx_Init(htons(AFSCONF_NANNYPORT));
1087 bozo_Log("can't initialize rx: code=%d\n", code);
1093 bozo_Log("Bos giving up, can't initialize rx\n");
1097 /* Disable jumbograms */
1100 if (rxMaxMTU != -1) {
1101 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1102 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1107 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1108 /* param */ NULL , "bozo-the-clown",
1111 /* try to read the key from the config file */
1112 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1114 /* try to create local cell config file */
1115 struct afsconf_cell tcell;
1116 strcpy(tcell.name, "localcell");
1117 tcell.numServers = 1;
1118 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1120 bozo_Log("failed to get hostname, code %d\n", errno);
1123 if (tcell.hostName[0][0] == 0) {
1124 bozo_Log("host name not set, can't start\n");
1125 bozo_Log("try the 'hostname' command\n");
1128 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1130 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1134 ("could not create cell database in '%s' (code %d), quitting\n",
1135 AFSDIR_SERVER_ETC_DIRPATH, code);
1138 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1141 ("failed to open newly-created cell database, quitting\n");
1146 /* initialize audit user check */
1147 osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
1149 /* read init file, starting up programs */
1150 if ((code = ReadBozoFile(0))) {
1152 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1153 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1157 bozo_CreateRxBindFile(host); /* for local scripts */
1159 /* opened the cell databse */
1160 bozo_confdir = tdir;
1162 /* allow super users to manage RX statistics */
1163 rx_SetRxStatUserOk(bozo_rxstat_userok);
1165 afsconf_SetNoAuthFlag(tdir, noAuth);
1166 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1169 bozo_CreatePidFile("bosserver", NULL, getpid());
1172 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1173 "bozo", securityClasses, numClasses,
1174 BOZO_ExecuteRequest);
1175 rx_SetMinProcs(tservice, 2);
1176 rx_SetMaxProcs(tservice, 4);
1177 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1178 if (rxkadDisableDotCheck) {
1179 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1180 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1184 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1185 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1186 rx_SetMinProcs(tservice, 2);
1187 rx_SetMaxProcs(tservice, 4);
1188 rx_StartServer(1); /* donate this process */
1193 bozo_Log(char *format, ...)
1199 va_start(ap, format);
1202 #ifndef AFS_NT40_ENV
1203 vsyslog(LOG_INFO, format, ap);
1207 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1210 /* log normally closed, so can be removed */
1212 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1213 if (bozo_logFile == NULL) {
1214 printf("bosserver: WARNING: problem with %s\n",
1215 AFSDIR_SERVER_BOZLOG_FILEPATH);
1216 printf("%s ", tdate);
1217 vprintf(format, ap);
1220 fprintf(bozo_logFile, "%s ", tdate);
1221 vfprintf(bozo_logFile, format, ap);
1223 /* close so rm BosLog works */
1224 fclose(bozo_logFile);