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 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 */
150 * Make directory with parents.
152 * \param[in] adir directory path to create
153 * \param[in] areqPerm permissions to set on the last component of adir
154 * \return 0 on success
157 MakeDirParents(const char *adir, int areqPerm)
163 int parent_perm = 0777; /* use umask for parent perms */
171 /* strip trailing slashes */
177 while (p != tdir && *p == PATH_DELIM) {
183 /* skip drive letter */
184 if (isalpha(p[0]) && p[1] == ':') {
188 /* skip leading slashes */
189 while (*p == PATH_DELIM) {
193 /* create parent directories with default perms */
194 p = strchr(p, PATH_DELIM);
197 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
198 if (mkdir(tdir, parent_perm) != 0) {
205 /* skip back to back slashes */
206 while (*p == PATH_DELIM) {
209 p = strchr(p, PATH_DELIM);
212 /* set required perms on the last path component */
213 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
214 if (mkdir(tdir, areqPerm) != 0) {
224 /* make sure a dir exists */
226 MakeDir(const char *adir)
230 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
233 reqPerm = GetRequiredDirPerm(adir);
236 code = MakeDirParents(adir, reqPerm);
242 /* create all the bozo dirs */
244 CreateDirs(const char *coredir)
247 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
248 strlen(AFSDIR_USR_DIRPATH)))
251 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
252 strlen(AFSDIR_USR_DIRPATH)))) {
253 if (MakeDir(AFSDIR_USR_DIRPATH))
257 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
258 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
259 if (MakeDir(AFSDIR_SERVER_AFS_DIRPATH))
262 if (MakeDir(AFSDIR_SERVER_BIN_DIRPATH))
264 if (MakeDir(AFSDIR_SERVER_ETC_DIRPATH))
266 if (MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH))
268 if (MakeDir(AFSDIR_SERVER_DB_DIRPATH))
270 if (MakeDir(AFSDIR_SERVER_LOGS_DIRPATH))
274 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
275 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
276 if (MakeDir(AFSDIR_CLIENT_VICE_DIRPATH))
279 if (MakeDir(AFSDIR_CLIENT_ETC_DIRPATH))
282 if (symlink(AFSDIR_SERVER_THISCELL_FILEPATH,
283 AFSDIR_CLIENT_THISCELL_FILEPATH)) {
284 if (errno != EEXIST) {
288 if (symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
289 AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) {
290 if (errno != EEXIST) {
294 #endif /* AFS_NT40_ENV */
296 if (MakeDir(coredir))
302 /* strip the \\n from the end of the line, if it is present */
304 StripLine(char *abuffer)
308 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
310 return 0; /* null string, no last character to check */
311 tp--; /* aim at last character */
317 /* write one bnode's worth of entry into the file */
319 bzwrite(struct bnode *abnode, void *arock)
321 struct bztemp *at = (struct bztemp *)arock;
323 char tbuffer[BOZO_BSSIZE];
326 if (abnode->notifier)
327 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
328 abnode->name, abnode->fileGoal, abnode->notifier);
330 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
331 abnode->name, abnode->fileGoal);
333 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
339 fprintf(at->file, "parm %s\n", tbuffer);
341 fprintf(at->file, "end\n");
347 ReadBozoFile(char *aname)
350 char tbuffer[BOZO_BSSIZE];
352 char *instp, *typep, *notifier, *notp;
354 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
357 char *parms[MAXPARMS];
358 char *thisparms[MAXPARMS];
361 /* rename BozoInit to BosServer for the user */
363 /* if BozoInit exists and BosConfig doesn't, try a rename */
364 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
365 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
366 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
367 AFSDIR_SERVER_BOZCONF_FILEPATH);
369 perror("bosconfig rename");
371 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
372 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
373 AFSDIR_SERVER_BOZCONF_FILEPATH);
375 perror("bosconfig rename");
379 /* don't do server restarts by default */
380 bozo_nextRestartKT.mask = KTIME_NEVER;
381 bozo_nextRestartKT.hour = 0;
382 bozo_nextRestartKT.min = 0;
383 bozo_nextRestartKT.day = 0;
385 /* restart processes at 5am if their binaries have changed */
386 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
387 bozo_nextDayKT.hour = 5;
388 bozo_nextDayKT.min = 0;
390 for (code = 0; code < MAXPARMS; code++)
393 aname = (char *)bozo_fileName;
394 tfile = fopen(aname, "r");
397 instp = malloc(BOZO_BSSIZE);
398 typep = malloc(BOZO_BSSIZE);
399 notp = malloc(BOZO_BSSIZE);
401 /* ok, read lines giving parms and such from the file */
402 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
404 break; /* all done */
406 if (strncmp(tbuffer, "restarttime", 11) == 0) {
408 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
409 &kthour, &ktmin, &ktsec);
414 /* otherwise we've read in the proper ktime structure; now assign
415 * it and continue processing */
416 bozo_nextRestartKT.mask = ktmask;
417 bozo_nextRestartKT.day = ktday;
418 bozo_nextRestartKT.hour = kthour;
419 bozo_nextRestartKT.min = ktmin;
420 bozo_nextRestartKT.sec = ktsec;
424 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
426 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
427 &ktday, &kthour, &ktmin, &ktsec);
432 /* otherwise we've read in the proper ktime structure; now assign
433 * it and continue processing */
434 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
435 bozo_nextDayKT.day = ktday;
436 bozo_nextDayKT.hour = kthour;
437 bozo_nextDayKT.min = ktmin;
438 bozo_nextDayKT.sec = ktsec;
442 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
443 code = sscanf(tbuffer, "restrictmode %d", &rmode);
448 if (rmode != 0 && rmode != 1) {
452 bozo_isrestricted = rmode;
456 if (strncmp("bnode", tbuffer, 5) != 0) {
462 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
467 } else if (code == 3)
470 memset(thisparms, 0, sizeof(thisparms));
472 for (i = 0; i < MAXPARMS; i++) {
473 /* now read the parms, until we see an "end" line */
474 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
480 if (!strncmp(tbuffer, "end", 3))
482 if (strncmp(tbuffer, "parm ", 5)) {
484 goto fail; /* no "parm " either */
486 if (!parms[i]) /* make sure there's space */
487 parms[i] = malloc(BOZO_BSSIZE);
488 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
489 thisparms[i] = parms[i];
492 /* ok, we have the type and parms, now create the object */
494 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
495 thisparms[2], thisparms[3], thisparms[4], notifier,
496 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
500 /* bnode created in 'temporarily shutdown' state;
501 * check to see if we are supposed to run this guy,
502 * and if so, start the process up */
504 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
506 bnode_SetStat(tb, BSTAT_SHUTDOWN);
517 for (i = 0; i < MAXPARMS; i++)
525 /* write a new bozo file */
527 WriteBozoFile(char *aname)
530 char *tbuffer = NULL;
536 aname = (char *)bozo_fileName;
537 if (asprintf(&tbuffer, "%s.NBZ", aname) < 0)
540 tfile = fopen(tbuffer, "w");
547 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
548 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
549 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
550 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
551 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
552 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
554 code = bnode_ApplyInstance(bzwrite, &btemp);
555 if (code || (code = ferror(tfile))) { /* something went wrong */
561 /* close the file, check for errors and snap new file into place */
562 if (fclose(tfile) == EOF) {
567 code = rk_rename(tbuffer, aname);
580 bdrestart(struct bnode *abnode, void *arock)
584 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
585 return 0; /* don't restart stopped bnodes */
587 code = bnode_RestartP(abnode);
589 /* restart the dude */
590 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
591 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
592 bnode_SetStat(abnode, BSTAT_NORMAL);
594 bnode_Release(abnode);
595 return 0; /* keep trying all bnodes */
598 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
599 /* lwp to handle system restarts */
601 BozoDaemon(void *unused)
605 /* now initialize the values */
609 now = FT_ApproxTime();
611 if (bozo_restdisable) {
612 bozo_Log("Restricted mode disabled by signal\n");
613 bozo_restdisable = 0;
616 if (bozo_newKTs) { /* need to recompute restart times */
617 bozo_newKTs = 0; /* done for a while */
618 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
619 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
622 /* see if we should do a restart */
623 if (now > nextRestart) {
624 SBOZO_ReBozo(0); /* doesn't come back */
627 /* see if we should restart a server */
629 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
631 /* call the bnode restartp function, and restart all that require it */
632 bnode_ApplyInstance(bdrestart, 0);
644 int s, sb_max, ipfragttl;
648 f = popen("/usr/sbin/no -o sb_max", "r");
649 s = fscanf(f, "sb_max = %d", &sb_max);
653 f = popen("/usr/sbin/no -o ipfragttl", "r");
654 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
664 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
672 make_pid_filename(char *ainst, char *aname)
677 if (aname && *aname) {
678 r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
679 if (r < 0 || buffer == NULL)
680 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
683 r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
684 if (r < 0 || buffer == NULL)
685 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
692 * Write a file containing the pid of the named process.
694 * @param ainst instance name
695 * @param aname sub-process name of the instance, may be null
696 * @param apid process id of the newly started process
701 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
704 char *pidfile = NULL;
707 pidfile = make_pid_filename(ainst, aname);
711 if ((fp = fopen(pidfile, "w")) == NULL) {
712 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
716 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
719 if (fclose(fp) != 0) {
727 * Clean a pid file for a process which just exited.
729 * @param ainst instance name
730 * @param aname sub-process name of the instance, may be null
735 bozo_DeletePidFile(char *ainst, char *aname)
737 char *pidfile = NULL;
738 pidfile = make_pid_filename(ainst, aname);
747 * Create the rxbind file of this bosserver.
749 * @param host bind address of this server
754 bozo_CreateRxBindFile(afs_uint32 host)
759 afs_inet_ntoa_r(host, buffer);
760 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
761 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
762 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
763 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
765 /* If listening on any interface, write the loopback interface
766 to the rxbind file to give local scripts a usable addresss. */
767 if (host == htonl(INADDR_ANY)) {
768 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
770 fprintf(fp, "%s\n", buffer);
776 * Get an interface address in network byte order, modulo the
777 * NetInfo/NetRestrict configuration files. Return the INADDR_ANY if no
778 * interface address is found.
781 GetRxBindAddress(void)
784 afs_int32 ccode; /* number of addresses found */
786 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
788 ccode = afsconf_ParseNetFiles(&addr, NULL, NULL, 1, reason,
789 AFSDIR_SERVER_NETINFO_FILEPATH,
790 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
792 /* Get the first non-loopback address from the kernel. */
793 ccode = rx_getAllAddr(&addr, 1);
797 addr = htonl(INADDR_ANY);
803 * Try to create local cell config file.
805 static struct afsconf_dir *
806 CreateLocalCellConfig(void)
809 struct afsconf_dir *tdir = NULL;
810 struct afsconf_cell tcell;
812 memset(&tcell, 0, sizeof(tcell));
813 strcpy(tcell.name, "localcell"); /* assume name is big enough for the default value */
814 tcell.numServers = 1;
815 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
817 bozo_Log("failed to get hostname, code %d\n", errno);
820 if (tcell.hostName[0][0] == 0) {
821 bozo_Log("host name not set, can't start\n");
822 bozo_Log("try the 'hostname' command\n");
825 code = afsconf_SetCellInfo(NULL, AFSDIR_SERVER_ETC_DIRPATH, &tcell);
828 ("could not create cell database in '%s' (code %d), quitting\n",
829 AFSDIR_SERVER_ETC_DIRPATH, code);
832 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
834 bozo_Log("failed to open newly-created cell database, quitting\n");
840 /* start a process and monitor it */
842 #include "AFS_component_version_number.c"
845 main(int argc, char **argv, char **envp)
847 struct rx_service *tservice;
849 struct afsconf_dir *tdir;
854 afs_uint32 host = htonl(INADDR_ANY);
855 char *auditFileName = NULL;
856 struct rx_securityClass **securityClasses;
857 afs_int32 numClasses;
858 int DoPeerRPCStats = 0;
859 int DoProcessRPCStats = 0;
865 struct sigaction nsa;
867 /* for some reason, this permits user-mode RX to run a lot faster.
868 * we do it here in the bosserver, so we don't have to do it
869 * individually in each server.
874 * The following signal action for AIX is necessary so that in case of a
875 * crash (i.e. core is generated) we can include the user's data section
876 * in the core dump. Unfortunately, by default, only a partial core is
877 * generated which, in many cases, isn't too useful.
879 sigemptyset(&nsa.sa_mask);
880 nsa.sa_handler = SIG_DFL;
881 nsa.sa_flags = SA_FULLDUMP;
882 sigaction(SIGSEGV, &nsa, NULL);
883 sigaction(SIGABRT, &nsa, NULL);
886 signal(SIGFPE, bozo_insecureme);
889 /* Initialize winsock */
890 if (afs_winsockInit() < 0) {
891 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
892 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
897 /* Initialize dirpaths */
898 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
900 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
902 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
907 /* some path inits */
908 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
909 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
911 /* initialize the list of dirpaths that the bosserver has
912 * an interest in monitoring */
915 #if defined(AFS_SGI_ENV)
916 /* offer some protection if AFS isn't loaded */
917 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
918 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
924 /* save args for restart */
926 bozo_argv = malloc((argc+1) * sizeof(char*));
928 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
931 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
932 bozo_argv[bozo_argc] = NULL; /* null terminate list */
933 #endif /* AFS_NT40_ENV */
936 for (code = 1; code < argc; code++) {
938 bozo_argv[code] = argv[code];
939 #endif /* AFS_NT40_ENV */
940 if (strcmp(argv[code], "-noauth") == 0) {
941 /* set noauth flag */
943 } else if (strcmp(argv[code], "-log") == 0) {
944 /* set extra logging flag */
948 else if (strcmp(argv[code], "-syslog") == 0) {
949 /* set syslog logging flag */
951 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
953 DoSyslogFacility = atoi(argv[code] + 8);
954 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
955 if (strcmp((argv[code]+7), "none") == 0)
958 DoCore = (argv[code]+7);
959 } else if (strcmp(argv[code], "-nofork") == 0) {
963 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
965 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
966 DoProcessRPCStats = 1;
968 else if (strcmp(argv[code], "-restricted") == 0) {
969 bozo_isrestricted = 1;
971 else if (strcmp(argv[code], "-rxbind") == 0) {
974 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
975 rxkadDisableDotCheck = 1;
977 else if (!strcmp(argv[code], "-rxmaxmtu")) {
978 if ((code + 1) >= argc) {
979 fprintf(stderr, "missing argument for -rxmaxmtu\n");
982 rxMaxMTU = atoi(argv[++code]);
984 else if (strcmp(argv[code], "-auditlog") == 0) {
985 auditFileName = argv[++code];
987 } else if (strcmp(argv[code], "-audit-interface") == 0) {
988 char *interface = argv[++code];
990 if (osi_audit_interface(interface)) {
991 printf("Invalid audit interface '%s'\n", interface);
994 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
995 DoPidFiles = (argv[code]+10);
996 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
997 DoPidFiles = AFSDIR_LOCAL_DIR;
1001 /* hack to support help flag */
1003 #ifndef AFS_NT40_ENV
1004 printf("Usage: bosserver [-noauth] [-log] "
1005 "[-auditlog <log path>] "
1006 "[-audit-interface <file|sysvmq> (default is file)] "
1007 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
1008 "[-syslog[=FACILITY]] "
1010 "[-enable_peer_stats] [-enable_process_stats] "
1011 "[-cores=<none|path>] \n"
1012 "[-pidfiles[=path]] "
1013 "[-nofork] " "[-help]\n");
1015 printf("Usage: bosserver [-noauth] [-log] "
1016 "[-auditlog <log path>] "
1017 "[-audit-interface <file|sysvmq> (default is file)] "
1018 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
1020 "[-enable_peer_stats] [-enable_process_stats] "
1021 "[-cores=<none|path>] \n"
1022 "[-pidfiles[=path]] "
1030 if (auditFileName) {
1031 osi_audit_file(auditFileName);
1034 #ifndef AFS_NT40_ENV
1035 if (geteuid() != 0) {
1036 printf("bosserver: must be run as root.\n");
1041 /* create useful dirs */
1042 i = CreateDirs(DoCore);
1044 printf("bosserver: could not set up directories, code %d\n", i);
1049 /* Support logging to named pipes by not renaming. */
1050 if ((lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0)
1051 && !(S_ISFIFO(sb.st_mode))) {
1052 if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
1053 printf("bosserver: out of memory\n");
1056 rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);
1059 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "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);
1074 * go into the background and remove our controlling tty, close open
1078 #ifndef AFS_NT40_ENV
1081 printf("bosserver: warning - daemon() returned code %d\n", errno);
1083 #endif /* ! AFS_NT40_ENV */
1085 /* Write current state of directory permissions to log file */
1088 /* chdir to AFS log directory */
1092 i = chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1094 printf("bosserver: could not change to %s, code %d\n",
1095 DoCore ? DoCore : AFSDIR_SERVER_LOGS_DIRPATH, errno);
1099 /* try to read the key from the config file */
1100 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1102 tdir = CreateLocalCellConfig();
1104 /* opened the cell databse */
1105 bozo_confdir = tdir;
1107 code = bnode_Init();
1109 printf("bosserver: could not init bnode package, code %d\n", code);
1113 bnode_Register("fs", &fsbnode_ops, 3);
1114 bnode_Register("dafs", &dafsbnode_ops, 4);
1115 bnode_Register("simple", &ezbnode_ops, 1);
1116 bnode_Register("cron", &cronbnode_ops, 2);
1118 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1121 getrlimit(RLIMIT_CORE, &rlp);
1125 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1126 setrlimit(RLIMIT_CORE, &rlp);
1127 getrlimit(RLIMIT_CORE, &rlp);
1128 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1132 /* Read init file, starting up programs. Also starts watcher threads. */
1133 if ((code = ReadBozoFile(0))) {
1135 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1136 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1141 host = GetRxBindAddress();
1143 for (i = 0; i < 10; i++) {
1145 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1147 code = rx_Init(htons(AFSCONF_NANNYPORT));
1150 bozo_Log("can't initialize rx: code=%d\n", code);
1156 bozo_Log("Bos giving up, can't initialize rx\n");
1160 /* Set some rx config */
1162 rx_enablePeerRPCStats();
1163 if (DoProcessRPCStats)
1164 rx_enableProcessRPCStats();
1166 /* Disable jumbograms */
1169 if (rxMaxMTU != -1) {
1170 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1171 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1176 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1177 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1179 bozo_Log("Failed to create daemon thread\n");
1183 /* initialize audit user check */
1184 osi_audit_set_user_check(bozo_confdir, bozo_IsLocalRealmMatch);
1186 bozo_CreateRxBindFile(host); /* for local scripts */
1188 /* allow super users to manage RX statistics */
1189 rx_SetRxStatUserOk(bozo_rxstat_userok);
1191 afsconf_SetNoAuthFlag(tdir, noAuth);
1192 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1195 bozo_CreatePidFile("bosserver", NULL, getpid());
1198 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1199 "bozo", securityClasses, numClasses,
1200 BOZO_ExecuteRequest);
1201 rx_SetMinProcs(tservice, 2);
1202 rx_SetMaxProcs(tservice, 4);
1203 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1204 if (rxkadDisableDotCheck) {
1205 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1206 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1210 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1211 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1212 rx_SetMinProcs(tservice, 2);
1213 rx_SetMaxProcs(tservice, 4);
1214 rx_StartServer(1); /* donate this process */
1219 bozo_Log(const char *format, ...)
1225 va_start(ap, format);
1228 #ifndef AFS_NT40_ENV
1229 vsyslog(LOG_INFO, format, ap);
1233 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1236 /* log normally closed, so can be removed */
1238 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1239 if (bozo_logFile == NULL) {
1240 printf("bosserver: WARNING: problem with %s\n",
1241 AFSDIR_SERVER_BOZLOG_FILEPATH);
1242 printf("%s ", tdate);
1243 vprintf(format, ap);
1246 fprintf(bozo_logFile, "%s ", tdate);
1247 vfprintf(bozo_logFile, format, ap);
1249 /* close so rm BosLog works */
1250 fclose(bozo_logFile);