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>
18 #ifdef IGNORE_SOME_GCC_WARNINGS
20 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
26 #ifdef HAVE_SYS_RESOURCE_H
27 #include <sys/resource.h>
31 #define PATH_DELIM '\\'
33 #include <WINNT/afsevent.h>
34 #endif /* AFS_NT40_ENV */
36 #define PATH_DELIM '/'
39 #include <rx/rx_globals.h>
41 #include <rx/rxstat.h>
43 #include <afs/ktime.h>
44 #include <afs/afsutil.h>
45 #include <afs/fileutil.h>
46 #include <afs/audit.h>
47 #include <afs/cellconfig.h>
49 #if defined(AFS_SGI_ENV)
50 #include <afs/afs_args.h>
55 #include "bnode_internal.h"
56 #include "bosprototypes.h"
58 #define BOZO_LWP_STACKSIZE 16000
59 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
61 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
62 static PROCESS bozo_pid;
63 const char *bozo_fileName;
66 static int bozo_argc = 0;
67 static char** bozo_argv = NULL;
73 const char *DoPidFiles = NULL;
75 int DoSyslogFacility = LOG_DAEMON;
77 static afs_int32 nextRestart;
78 static afs_int32 nextDay;
80 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
83 int rxkadDisableDotCheck = 0;
85 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
86 afs_uint32 SHostAddrs[ADDRSPERSITE];
88 int bozo_isrestricted = 0;
89 int bozo_restdisable = 0;
92 bozo_insecureme(int sig)
94 signal(SIGFPE, bozo_insecureme);
95 bozo_isrestricted = 0;
103 /* check whether caller is authorized to manage RX statistics */
105 bozo_rxstat_userok(struct rx_call *call)
107 return afsconf_SuperUser(bozo_confdir, call, NULL);
111 * Return true if this name is a member of the local realm.
114 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
116 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
117 afs_int32 islocal = 0; /* default to no */
120 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
122 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
123 code, name, inst, cell);
128 /* restart bozo process */
133 /* exit with restart code; SCM integrator process will restart bosserver with
134 the same arguments */
135 exit(BOSEXIT_RESTART);
137 /* exec new bosserver process */
140 /* close random fd's */
141 for (i = 3; i < 64; i++) {
145 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
147 execv(bozo_argv[0], bozo_argv); /* should not return */
149 #endif /* AFS_NT40_ENV */
153 * Make directory with parents.
155 * \param[in] adir directory path to create
156 * \param[in] areqPerm permissions to set on the last component of adir
157 * \return 0 on success
160 MakeDirParents(const char *adir, int areqPerm)
166 int parent_perm = 0777; /* use umask for parent perms */
174 /* strip trailing slashes */
180 while (p != tdir && *p == PATH_DELIM) {
186 /* skip drive letter */
187 if (isalpha(p[0]) && p[1] == ':') {
191 /* skip leading slashes */
192 while (*p == PATH_DELIM) {
196 /* create parent directories with default perms */
197 p = strchr(p, PATH_DELIM);
200 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
201 if (mkdir(tdir, parent_perm) != 0) {
208 /* skip back to back slashes */
209 while (*p == PATH_DELIM) {
212 p = strchr(p, PATH_DELIM);
215 /* set required perms on the last path component */
216 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
217 if (mkdir(tdir, areqPerm) != 0) {
227 /* make sure a dir exists */
229 MakeDir(const char *adir)
233 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
236 reqPerm = GetRequiredDirPerm(adir);
239 code = MakeDirParents(adir, reqPerm);
245 /* create all the bozo dirs */
247 CreateDirs(const char *coredir)
250 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
251 strlen(AFSDIR_USR_DIRPATH)))
254 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
255 strlen(AFSDIR_USR_DIRPATH)))) {
256 MakeDir(AFSDIR_USR_DIRPATH);
259 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
260 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
261 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
263 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
264 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
265 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
266 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
267 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
270 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
271 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
272 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
274 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
276 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
277 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
278 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
279 #endif /* AFS_NT40_ENV */
285 /* strip the \\n from the end of the line, if it is present */
287 StripLine(char *abuffer)
291 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
293 return 0; /* null string, no last character to check */
294 tp--; /* aim at last character */
300 /* write one bnode's worth of entry into the file */
302 bzwrite(struct bnode *abnode, void *arock)
304 struct bztemp *at = (struct bztemp *)arock;
306 char tbuffer[BOZO_BSSIZE];
309 if (abnode->notifier)
310 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
311 abnode->name, abnode->fileGoal, abnode->notifier);
313 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
314 abnode->name, abnode->fileGoal);
316 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
322 fprintf(at->file, "parm %s\n", tbuffer);
324 fprintf(at->file, "end\n");
330 ReadBozoFile(char *aname)
333 char tbuffer[BOZO_BSSIZE];
335 char *instp, *typep, *notifier, *notp;
337 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
340 char *parms[MAXPARMS];
341 char *thisparms[MAXPARMS];
344 /* rename BozoInit to BosServer for the user */
346 /* if BozoInit exists and BosConfig doesn't, try a rename */
347 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
348 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
349 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
350 AFSDIR_SERVER_BOZCONF_FILEPATH);
352 perror("bosconfig rename");
354 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
355 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
356 AFSDIR_SERVER_BOZCONF_FILEPATH);
358 perror("bosconfig rename");
362 /* don't do server restarts by default */
363 bozo_nextRestartKT.mask = KTIME_NEVER;
364 bozo_nextRestartKT.hour = 0;
365 bozo_nextRestartKT.min = 0;
366 bozo_nextRestartKT.day = 0;
368 /* restart processes at 5am if their binaries have changed */
369 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
370 bozo_nextDayKT.hour = 5;
371 bozo_nextDayKT.min = 0;
373 for (code = 0; code < MAXPARMS; code++)
376 aname = (char *)bozo_fileName;
377 tfile = fopen(aname, "r");
380 instp = malloc(BOZO_BSSIZE);
381 typep = malloc(BOZO_BSSIZE);
382 notp = malloc(BOZO_BSSIZE);
384 /* ok, read lines giving parms and such from the file */
385 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
387 break; /* all done */
389 if (strncmp(tbuffer, "restarttime", 11) == 0) {
391 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
392 &kthour, &ktmin, &ktsec);
397 /* otherwise we've read in the proper ktime structure; now assign
398 * it and continue processing */
399 bozo_nextRestartKT.mask = ktmask;
400 bozo_nextRestartKT.day = ktday;
401 bozo_nextRestartKT.hour = kthour;
402 bozo_nextRestartKT.min = ktmin;
403 bozo_nextRestartKT.sec = ktsec;
407 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
409 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
410 &ktday, &kthour, &ktmin, &ktsec);
415 /* otherwise we've read in the proper ktime structure; now assign
416 * it and continue processing */
417 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
418 bozo_nextDayKT.day = ktday;
419 bozo_nextDayKT.hour = kthour;
420 bozo_nextDayKT.min = ktmin;
421 bozo_nextDayKT.sec = ktsec;
425 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
426 code = sscanf(tbuffer, "restrictmode %d", &rmode);
431 if (rmode != 0 && rmode != 1) {
435 bozo_isrestricted = rmode;
439 if (strncmp("bnode", tbuffer, 5) != 0) {
445 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
450 } else if (code == 3)
453 memset(thisparms, 0, sizeof(thisparms));
455 for (i = 0; i < MAXPARMS; i++) {
456 /* now read the parms, until we see an "end" line */
457 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
463 if (!strncmp(tbuffer, "end", 3))
465 if (strncmp(tbuffer, "parm ", 5)) {
467 goto fail; /* no "parm " either */
469 if (!parms[i]) /* make sure there's space */
470 parms[i] = malloc(BOZO_BSSIZE);
471 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
472 thisparms[i] = parms[i];
475 /* ok, we have the type and parms, now create the object */
477 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
478 thisparms[2], thisparms[3], thisparms[4], notifier,
479 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
483 /* bnode created in 'temporarily shutdown' state;
484 * check to see if we are supposed to run this guy,
485 * and if so, start the process up */
487 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
489 bnode_SetStat(tb, BSTAT_SHUTDOWN);
500 for (i = 0; i < MAXPARMS; i++)
508 /* write a new bozo file */
510 WriteBozoFile(char *aname)
513 char tbuffer[AFSDIR_PATH_MAX];
518 aname = (char *)bozo_fileName;
519 strcpy(tbuffer, aname);
520 strcat(tbuffer, ".NBZ");
521 tfile = fopen(tbuffer, "w");
526 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
527 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
528 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
529 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
530 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
531 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
533 code = bnode_ApplyInstance(bzwrite, &btemp);
534 if (code || (code = ferror(tfile))) { /* something went wrong */
539 /* close the file, check for errors and snap new file into place */
540 if (fclose(tfile) == EOF) {
544 code = rk_rename(tbuffer, aname);
553 bdrestart(struct bnode *abnode, void *arock)
557 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
558 return 0; /* don't restart stopped bnodes */
560 code = bnode_RestartP(abnode);
562 /* restart the dude */
563 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
564 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
565 bnode_SetStat(abnode, BSTAT_NORMAL);
567 bnode_Release(abnode);
568 return 0; /* keep trying all bnodes */
571 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
572 /* lwp to handle system restarts */
574 BozoDaemon(void *unused)
578 /* now initialize the values */
582 now = FT_ApproxTime();
584 if (bozo_restdisable) {
585 bozo_Log("Restricted mode disabled by signal\n");
586 bozo_restdisable = 0;
589 if (bozo_newKTs) { /* need to recompute restart times */
590 bozo_newKTs = 0; /* done for a while */
591 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
592 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
595 /* see if we should do a restart */
596 if (now > nextRestart) {
597 SBOZO_ReBozo(0); /* doesn't come back */
600 /* see if we should restart a server */
602 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
604 /* call the bnode restartp function, and restart all that require it */
605 bnode_ApplyInstance(bdrestart, 0);
617 int s, sb_max, ipfragttl;
621 f = popen("/usr/sbin/no -o sb_max", "r");
622 s = fscanf(f, "sb_max = %d", &sb_max);
626 f = popen("/usr/sbin/no -o ipfragttl", "r");
627 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
637 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
645 make_pid_filename(char *ainst, char *aname)
649 if (aname && *aname) {
650 asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
652 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
655 asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
657 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
664 * Write a file containing the pid of the named process.
666 * @param ainst instance name
667 * @param aname sub-process name of the instance, may be null
668 * @param apid process id of the newly started process
673 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
676 char *pidfile = NULL;
679 pidfile = make_pid_filename(ainst, aname);
683 if ((fp = fopen(pidfile, "w")) == NULL) {
684 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
688 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
691 if (fclose(fp) != 0) {
699 * Clean a pid file for a process which just exited.
701 * @param ainst instance name
702 * @param aname sub-process name of the instance, may be null
707 bozo_DeletePidFile(char *ainst, char *aname)
709 char *pidfile = NULL;
710 pidfile = make_pid_filename(ainst, aname);
719 * Create the rxbind file of this bosserver.
721 * @param host bind address of this server
726 bozo_CreateRxBindFile(afs_uint32 host)
731 afs_inet_ntoa_r(host, buffer);
732 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
733 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
734 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
735 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
737 /* If listening on any interface, write the loopback interface
738 to the rxbind file to give local scripts a usable addresss. */
739 if (host == htonl(INADDR_ANY)) {
740 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
742 fprintf(fp, "%s\n", buffer);
747 /* start a process and monitor it */
749 #include "AFS_component_version_number.c"
752 main(int argc, char **argv, char **envp)
754 struct rx_service *tservice;
756 struct afsconf_dir *tdir;
759 char namebuf[AFSDIR_PATH_MAX];
761 afs_uint32 host = htonl(INADDR_ANY);
762 char *auditFileName = NULL;
763 struct rx_securityClass **securityClasses;
764 afs_int32 numClasses;
770 struct sigaction nsa;
772 /* for some reason, this permits user-mode RX to run a lot faster.
773 * we do it here in the bosserver, so we don't have to do it
774 * individually in each server.
779 * The following signal action for AIX is necessary so that in case of a
780 * crash (i.e. core is generated) we can include the user's data section
781 * in the core dump. Unfortunately, by default, only a partial core is
782 * generated which, in many cases, isn't too useful.
784 sigemptyset(&nsa.sa_mask);
785 nsa.sa_handler = SIG_DFL;
786 nsa.sa_flags = SA_FULLDUMP;
787 sigaction(SIGSEGV, &nsa, NULL);
788 sigaction(SIGABRT, &nsa, NULL);
791 signal(SIGFPE, bozo_insecureme);
794 /* Initialize winsock */
795 if (afs_winsockInit() < 0) {
796 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
797 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
802 /* Initialize dirpaths */
803 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
805 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
807 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
812 /* some path inits */
813 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
814 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
816 /* initialize the list of dirpaths that the bosserver has
817 * an interest in monitoring */
820 #if defined(AFS_SGI_ENV)
821 /* offer some protection if AFS isn't loaded */
822 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
823 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
829 /* save args for restart */
831 bozo_argv = malloc((argc+1) * sizeof(char*));
833 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
836 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
837 bozo_argv[bozo_argc] = NULL; /* null terminate list */
838 #endif /* AFS_NT40_ENV */
841 for (code = 1; code < argc; code++) {
843 bozo_argv[code] = argv[code];
844 #endif /* AFS_NT40_ENV */
845 if (strcmp(argv[code], "-noauth") == 0) {
846 /* set noauth flag */
848 } else if (strcmp(argv[code], "-log") == 0) {
849 /* set extra logging flag */
853 else if (strcmp(argv[code], "-syslog") == 0) {
854 /* set syslog logging flag */
856 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
858 DoSyslogFacility = atoi(argv[code] + 8);
859 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
860 if (strcmp((argv[code]+7), "none") == 0)
863 DoCore = (argv[code]+7);
864 } else if (strcmp(argv[code], "-nofork") == 0) {
868 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
869 rx_enablePeerRPCStats();
870 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
871 rx_enableProcessRPCStats();
873 else if (strcmp(argv[code], "-restricted") == 0) {
874 bozo_isrestricted = 1;
876 else if (strcmp(argv[code], "-rxbind") == 0) {
879 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
880 rxkadDisableDotCheck = 1;
882 else if (!strcmp(argv[code], "-rxmaxmtu")) {
883 if ((code + 1) >= argc) {
884 fprintf(stderr, "missing argument for -rxmaxmtu\n");
887 rxMaxMTU = atoi(argv[++code]);
889 else if (strcmp(argv[code], "-auditlog") == 0) {
890 auditFileName = argv[++code];
892 } else if (strcmp(argv[code], "-audit-interface") == 0) {
893 char *interface = argv[++code];
895 if (osi_audit_interface(interface)) {
896 printf("Invalid audit interface '%s'\n", interface);
899 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
900 DoPidFiles = (argv[code]+10);
901 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
902 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
906 /* hack to support help flag */
909 printf("Usage: bosserver [-noauth] [-log] "
910 "[-auditlog <log path>] "
911 "[-audit-interface <file|sysvmq> (default is file)] "
912 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
913 "[-syslog[=FACILITY]] "
915 "[-enable_peer_stats] [-enable_process_stats] "
916 "[-cores=<none|path>] \n"
917 "[-pidfiles[=path]] "
918 "[-nofork] " "[-help]\n");
920 printf("Usage: bosserver [-noauth] [-log] "
921 "[-auditlog <log path>] "
922 "[-audit-interface <file|sysvmq> (default is file)] "
923 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
925 "[-enable_peer_stats] [-enable_process_stats] "
926 "[-cores=<none|path>] \n"
927 "[-pidfiles[=path]] "
936 osi_audit_file(auditFileName);
940 if (geteuid() != 0) {
941 printf("bosserver: must be run as root.\n");
948 printf("bosserver: could not init bnode package, code %d\n", code);
952 bnode_Register("fs", &fsbnode_ops, 3);
953 bnode_Register("dafs", &dafsbnode_ops, 4);
954 bnode_Register("simple", &ezbnode_ops, 1);
955 bnode_Register("cron", &cronbnode_ops, 2);
957 /* create useful dirs */
960 /* chdir to AFS log directory */
964 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
966 /* go into the background and remove our controlling tty, close open
973 #endif /* ! AFS_NT40_ENV */
977 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
978 !(S_ISFIFO(sb.st_mode)))
981 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
982 strcat(namebuf, ".old");
983 rk_rename(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
984 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
986 printf("bosserver: can't initialize log file (%s).\n",
987 AFSDIR_SERVER_BOZLOG_FILEPATH);
990 /* keep log closed normally, so can be removed */
991 fclose(bozo_logFile);
994 openlog("bosserver", LOG_PID, DoSyslogFacility);
998 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1001 getrlimit(RLIMIT_CORE, &rlp);
1005 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1006 setrlimit(RLIMIT_CORE, &rlp);
1007 getrlimit(RLIMIT_CORE, &rlp);
1008 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1012 /* Write current state of directory permissions to log file */
1017 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1018 AFSDIR_SERVER_NETINFO_FILEPATH) {
1020 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1021 ADDRSPERSITE, reason,
1022 AFSDIR_SERVER_NETINFO_FILEPATH,
1023 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1025 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1028 host = SHostAddrs[0];
1031 for (i = 0; i < 10; i++) {
1033 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1035 code = rx_Init(htons(AFSCONF_NANNYPORT));
1038 bozo_Log("can't initialize rx: code=%d\n", code);
1044 bozo_Log("Bos giving up, can't initialize rx\n");
1048 /* Disable jumbograms */
1051 if (rxMaxMTU != -1) {
1052 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1053 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1058 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1059 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1061 bozo_Log("Failed to create daemon thread\n");
1065 /* try to read the key from the config file */
1066 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1068 /* try to create local cell config file */
1069 struct afsconf_cell tcell;
1070 strcpy(tcell.name, "localcell");
1071 tcell.numServers = 1;
1072 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1074 bozo_Log("failed to get hostname, code %d\n", errno);
1077 if (tcell.hostName[0][0] == 0) {
1078 bozo_Log("host name not set, can't start\n");
1079 bozo_Log("try the 'hostname' command\n");
1082 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1084 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1088 ("could not create cell database in '%s' (code %d), quitting\n",
1089 AFSDIR_SERVER_ETC_DIRPATH, code);
1092 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1095 ("failed to open newly-created cell database, quitting\n");
1100 /* initialize audit user check */
1101 osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
1103 /* read init file, starting up programs */
1104 if ((code = ReadBozoFile(0))) {
1106 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1107 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1111 bozo_CreateRxBindFile(host); /* for local scripts */
1113 /* opened the cell databse */
1114 bozo_confdir = tdir;
1116 /* allow super users to manage RX statistics */
1117 rx_SetRxStatUserOk(bozo_rxstat_userok);
1119 afsconf_SetNoAuthFlag(tdir, noAuth);
1120 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1123 bozo_CreatePidFile("bosserver", NULL, getpid());
1126 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1127 "bozo", securityClasses, numClasses,
1128 BOZO_ExecuteRequest);
1129 rx_SetMinProcs(tservice, 2);
1130 rx_SetMaxProcs(tservice, 4);
1131 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1132 if (rxkadDisableDotCheck) {
1133 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1134 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1138 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1139 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1140 rx_SetMinProcs(tservice, 2);
1141 rx_SetMaxProcs(tservice, 4);
1142 rx_StartServer(1); /* donate this process */
1147 bozo_Log(char *format, ...)
1153 va_start(ap, format);
1156 #ifndef AFS_NT40_ENV
1157 vsyslog(LOG_INFO, format, ap);
1161 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1164 /* log normally closed, so can be removed */
1166 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1167 if (bozo_logFile == NULL) {
1168 printf("bosserver: WARNING: problem with %s\n",
1169 AFSDIR_SERVER_BOZLOG_FILEPATH);
1170 printf("%s ", tdate);
1171 vprintf(format, ap);
1174 fprintf(bozo_logFile, "%s ", tdate);
1175 vfprintf(bozo_logFile, format, ap);
1177 /* close so rm BosLog works */
1178 fclose(bozo_logFile);