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>
50 #if defined(AFS_SGI_ENV)
51 #include <afs/afs_args.h>
56 #include "bnode_internal.h"
57 #include "bosprototypes.h"
59 #define BOZO_LWP_STACKSIZE 16000
60 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
62 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
63 static PROCESS bozo_pid;
64 const char *bozo_fileName;
67 static int bozo_argc = 0;
68 static char** bozo_argv = NULL;
74 char *DoPidFiles = NULL;
76 int DoSyslogFacility = LOG_DAEMON;
78 int DoTransarcLogs = 0;
79 static afs_int32 nextRestart;
80 static afs_int32 nextDay;
82 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
85 int rxkadDisableDotCheck = 0;
87 int bozo_isrestricted = 0;
88 int bozo_restdisable = 0;
91 bozo_insecureme(int sig)
93 signal(SIGFPE, bozo_insecureme);
94 bozo_isrestricted = 0;
102 /* check whether caller is authorized to manage RX statistics */
104 bozo_rxstat_userok(struct rx_call *call)
106 return afsconf_SuperUser(bozo_confdir, call, NULL);
110 * Return true if this name is a member of the local realm.
113 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
115 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
116 afs_int32 islocal = 0; /* default to no */
119 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
121 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
122 code, name, inst, cell);
127 /* restart bozo process */
132 /* exit with restart code; SCM integrator process will restart bosserver with
133 the same arguments */
134 exit(BOSEXIT_RESTART);
136 /* exec new bosserver process */
139 /* close random fd's */
140 for (i = 3; i < 64; i++) {
144 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
146 execv(bozo_argv[0], bozo_argv); /* should not return */
148 #endif /* AFS_NT40_ENV */
152 * Make directory with parents.
154 * \param[in] adir directory path to create
155 * \param[in] areqPerm permissions to set on the last component of adir
156 * \return 0 on success
159 MakeDirParents(const char *adir, int areqPerm)
165 int parent_perm = 0777; /* use umask for parent perms */
173 /* strip trailing slashes */
179 while (p != tdir && *p == PATH_DELIM) {
185 /* skip drive letter */
186 if (isalpha(p[0]) && p[1] == ':') {
190 /* skip leading slashes */
191 while (*p == PATH_DELIM) {
195 /* create parent directories with default perms */
196 p = strchr(p, PATH_DELIM);
199 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
200 if (mkdir(tdir, parent_perm) != 0) {
207 /* skip back to back slashes */
208 while (*p == PATH_DELIM) {
211 p = strchr(p, PATH_DELIM);
214 /* set required perms on the last path component */
215 if (stat(tdir, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
216 if (mkdir(tdir, areqPerm) != 0) {
226 /* make sure a dir exists */
228 MakeDir(const char *adir)
232 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
235 reqPerm = GetRequiredDirPerm(adir);
238 code = MakeDirParents(adir, reqPerm);
244 /* create all the bozo dirs */
246 CreateDirs(const char *coredir)
249 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
250 strlen(AFSDIR_USR_DIRPATH)))
253 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
254 strlen(AFSDIR_USR_DIRPATH)))) {
255 if (MakeDir(AFSDIR_USR_DIRPATH))
259 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
260 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
261 if (MakeDir(AFSDIR_SERVER_AFS_DIRPATH))
264 if (MakeDir(AFSDIR_SERVER_BIN_DIRPATH))
266 if (MakeDir(AFSDIR_SERVER_ETC_DIRPATH))
268 if (MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH))
270 if (MakeDir(AFSDIR_SERVER_DB_DIRPATH))
272 if (MakeDir(AFSDIR_SERVER_LOGS_DIRPATH))
276 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
277 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
278 if (MakeDir(AFSDIR_CLIENT_VICE_DIRPATH))
281 if (MakeDir(AFSDIR_CLIENT_ETC_DIRPATH))
284 if (symlink(AFSDIR_SERVER_THISCELL_FILEPATH,
285 AFSDIR_CLIENT_THISCELL_FILEPATH)) {
286 if (errno != EEXIST) {
290 if (symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
291 AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) {
292 if (errno != EEXIST) {
296 #endif /* AFS_NT40_ENV */
298 if (MakeDir(coredir))
304 /* strip the \\n from the end of the line, if it is present */
306 StripLine(char *abuffer)
310 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
312 return 0; /* null string, no last character to check */
313 tp--; /* aim at last character */
319 /* write one bnode's worth of entry into the file */
321 bzwrite(struct bnode *abnode, void *arock)
323 struct bztemp *at = (struct bztemp *)arock;
325 char tbuffer[BOZO_BSSIZE];
328 if (abnode->notifier)
329 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
330 abnode->name, abnode->fileGoal, abnode->notifier);
332 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
333 abnode->name, abnode->fileGoal);
335 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
341 fprintf(at->file, "parm %s\n", tbuffer);
343 fprintf(at->file, "end\n");
349 ReadBozoFile(char *aname)
352 char tbuffer[BOZO_BSSIZE];
354 char *instp, *typep, *notifier, *notp;
356 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
359 char *parms[MAXPARMS];
360 char *thisparms[MAXPARMS];
363 /* rename BozoInit to BosServer for the user */
365 /* if BozoInit exists and BosConfig doesn't, try a rename */
366 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
367 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
368 code = rk_rename(AFSDIR_SERVER_BOZINIT_FILEPATH,
369 AFSDIR_SERVER_BOZCONF_FILEPATH);
371 perror("bosconfig rename");
373 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
374 code = rk_rename(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
375 AFSDIR_SERVER_BOZCONF_FILEPATH);
377 perror("bosconfig rename");
381 /* don't do server restarts by default */
382 bozo_nextRestartKT.mask = KTIME_NEVER;
383 bozo_nextRestartKT.hour = 0;
384 bozo_nextRestartKT.min = 0;
385 bozo_nextRestartKT.day = 0;
387 /* restart processes at 5am if their binaries have changed */
388 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
389 bozo_nextDayKT.hour = 5;
390 bozo_nextDayKT.min = 0;
392 for (code = 0; code < MAXPARMS; code++)
395 aname = (char *)bozo_fileName;
396 tfile = fopen(aname, "r");
399 instp = malloc(BOZO_BSSIZE);
400 typep = malloc(BOZO_BSSIZE);
401 notp = malloc(BOZO_BSSIZE);
403 /* ok, read lines giving parms and such from the file */
404 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
406 break; /* all done */
408 if (strncmp(tbuffer, "restarttime", 11) == 0) {
410 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
411 &kthour, &ktmin, &ktsec);
416 /* otherwise we've read in the proper ktime structure; now assign
417 * it and continue processing */
418 bozo_nextRestartKT.mask = ktmask;
419 bozo_nextRestartKT.day = ktday;
420 bozo_nextRestartKT.hour = kthour;
421 bozo_nextRestartKT.min = ktmin;
422 bozo_nextRestartKT.sec = ktsec;
426 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
428 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
429 &ktday, &kthour, &ktmin, &ktsec);
434 /* otherwise we've read in the proper ktime structure; now assign
435 * it and continue processing */
436 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
437 bozo_nextDayKT.day = ktday;
438 bozo_nextDayKT.hour = kthour;
439 bozo_nextDayKT.min = ktmin;
440 bozo_nextDayKT.sec = ktsec;
444 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
445 code = sscanf(tbuffer, "restrictmode %d", &rmode);
450 if (rmode != 0 && rmode != 1) {
454 bozo_isrestricted = rmode;
458 if (strncmp("bnode", tbuffer, 5) != 0) {
464 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
469 } else if (code == 3)
472 memset(thisparms, 0, sizeof(thisparms));
474 for (i = 0; i < MAXPARMS; i++) {
475 /* now read the parms, until we see an "end" line */
476 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
482 if (!strncmp(tbuffer, "end", 3))
484 if (strncmp(tbuffer, "parm ", 5)) {
486 goto fail; /* no "parm " either */
488 if (!parms[i]) /* make sure there's space */
489 parms[i] = malloc(BOZO_BSSIZE);
490 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
491 thisparms[i] = parms[i];
494 /* ok, we have the type and parms, now create the object */
496 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
497 thisparms[2], thisparms[3], thisparms[4], notifier,
498 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
502 /* bnode created in 'temporarily shutdown' state;
503 * check to see if we are supposed to run this guy,
504 * and if so, start the process up */
506 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
508 bnode_SetStat(tb, BSTAT_SHUTDOWN);
519 for (i = 0; i < MAXPARMS; i++)
527 /* write a new bozo file */
529 WriteBozoFile(char *aname)
532 char *tbuffer = NULL;
538 aname = (char *)bozo_fileName;
539 if (asprintf(&tbuffer, "%s.NBZ", aname) < 0)
542 tfile = fopen(tbuffer, "w");
549 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
550 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
551 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
552 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
553 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
554 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
556 code = bnode_ApplyInstance(bzwrite, &btemp);
557 if (code || (code = ferror(tfile))) { /* something went wrong */
563 /* close the file, check for errors and snap new file into place */
564 if (fclose(tfile) == EOF) {
569 code = rk_rename(tbuffer, aname);
582 bdrestart(struct bnode *abnode, void *arock)
586 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
587 return 0; /* don't restart stopped bnodes */
589 code = bnode_RestartP(abnode);
591 /* restart the dude */
592 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
593 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
594 bnode_SetStat(abnode, BSTAT_NORMAL);
596 bnode_Release(abnode);
597 return 0; /* keep trying all bnodes */
600 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
601 /* lwp to handle system restarts */
603 BozoDaemon(void *unused)
607 /* now initialize the values */
611 now = FT_ApproxTime();
613 if (bozo_restdisable) {
614 bozo_Log("Restricted mode disabled by signal\n");
615 bozo_restdisable = 0;
618 if (bozo_newKTs) { /* need to recompute restart times */
619 bozo_newKTs = 0; /* done for a while */
620 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
621 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
624 /* see if we should do a restart */
625 if (now > nextRestart) {
626 SBOZO_ReBozo(0); /* doesn't come back */
629 /* see if we should restart a server */
631 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
633 /* call the bnode restartp function, and restart all that require it */
634 bnode_ApplyInstance(bdrestart, 0);
637 AFS_UNREACHED(return(NULL));
646 int s, sb_max, ipfragttl;
650 f = popen("/usr/sbin/no -o sb_max", "r");
651 s = fscanf(f, "sb_max = %d", &sb_max);
655 f = popen("/usr/sbin/no -o ipfragttl", "r");
656 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
666 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
674 make_pid_filename(char *ainst, char *aname)
679 if (aname && *aname) {
680 r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
681 if (r < 0 || buffer == NULL)
682 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
685 r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
686 if (r < 0 || buffer == NULL)
687 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
694 * Write a file containing the pid of the named process.
696 * @param ainst instance name
697 * @param aname sub-process name of the instance, may be null
698 * @param apid process id of the newly started process
703 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
706 char *pidfile = NULL;
709 pidfile = make_pid_filename(ainst, aname);
713 if ((fp = fopen(pidfile, "w")) == NULL) {
714 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
718 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
721 if (fclose(fp) != 0) {
729 * Clean a pid file for a process which just exited.
731 * @param ainst instance name
732 * @param aname sub-process name of the instance, may be null
737 bozo_DeletePidFile(char *ainst, char *aname)
739 char *pidfile = NULL;
740 pidfile = make_pid_filename(ainst, aname);
749 * Create the rxbind file of this bosserver.
751 * @param host bind address of this server
756 bozo_CreateRxBindFile(afs_uint32 host)
761 afs_inet_ntoa_r(host, buffer);
762 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
763 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
764 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
765 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
767 /* If listening on any interface, write the loopback interface
768 to the rxbind file to give local scripts a usable addresss. */
769 if (host == htonl(INADDR_ANY)) {
770 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
772 fprintf(fp, "%s\n", buffer);
778 * Get an interface address in network byte order, modulo the
779 * NetInfo/NetRestrict configuration files. Return the INADDR_ANY if no
780 * interface address is found.
783 GetRxBindAddress(void)
786 afs_int32 ccode; /* number of addresses found */
788 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
790 ccode = afsconf_ParseNetFiles(&addr, NULL, NULL, 1, reason,
791 AFSDIR_SERVER_NETINFO_FILEPATH,
792 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
794 /* Get the first non-loopback address from the kernel. */
795 ccode = rx_getAllAddr(&addr, 1);
799 addr = htonl(INADDR_ANY);
805 * Try to create local cell config file.
807 static struct afsconf_dir *
808 CreateLocalCellConfig(void)
811 struct afsconf_dir *tdir = NULL;
812 struct afsconf_cell tcell;
814 memset(&tcell, 0, sizeof(tcell));
815 strcpy(tcell.name, "localcell"); /* assume name is big enough for the default value */
816 tcell.numServers = 1;
817 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
819 bozo_Log("failed to get hostname, code %d\n", errno);
822 if (tcell.hostName[0][0] == 0) {
823 bozo_Log("host name not set, can't start\n");
824 bozo_Log("try the 'hostname' command\n");
827 code = afsconf_SetCellInfo(NULL, AFSDIR_SERVER_ETC_DIRPATH, &tcell);
830 ("could not create cell database in '%s' (code %d), quitting\n",
831 AFSDIR_SERVER_ETC_DIRPATH, code);
834 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
836 bozo_Log("failed to open newly-created cell database, quitting\n");
842 /* start a process and monitor it */
844 #include "AFS_component_version_number.c"
863 #endif /* AFS_NT40_ENV */
867 main(int argc, char **argv, char **envp)
869 struct cmd_syndesc *opts;
871 struct rx_service *tservice;
873 struct afsconf_dir *tdir;
878 afs_uint32 host = htonl(INADDR_ANY);
879 char *auditIface = NULL;
880 char *auditFileName = NULL;
881 struct rx_securityClass **securityClasses;
882 afs_int32 numClasses;
883 int DoPeerRPCStats = 0;
884 int DoProcessRPCStats = 0;
890 struct sigaction nsa;
892 /* for some reason, this permits user-mode RX to run a lot faster.
893 * we do it here in the bosserver, so we don't have to do it
894 * individually in each server.
899 * The following signal action for AIX is necessary so that in case of a
900 * crash (i.e. core is generated) we can include the user's data section
901 * in the core dump. Unfortunately, by default, only a partial core is
902 * generated which, in many cases, isn't too useful.
904 sigemptyset(&nsa.sa_mask);
905 nsa.sa_handler = SIG_DFL;
906 nsa.sa_flags = SA_FULLDUMP;
907 sigaction(SIGSEGV, &nsa, NULL);
908 sigaction(SIGABRT, &nsa, NULL);
911 signal(SIGFPE, bozo_insecureme);
914 /* Initialize winsock */
915 if (afs_winsockInit() < 0) {
916 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
917 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
922 /* Initialize dirpaths */
923 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
925 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
927 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
932 /* some path inits */
933 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
934 DoCore = strdup(AFSDIR_SERVER_LOGS_DIRPATH);
936 fprintf(stderr, "bosserver: Failed to allocate memory.\n");
940 /* initialize the list of dirpaths that the bosserver has
941 * an interest in monitoring */
944 #if defined(AFS_SGI_ENV)
945 /* offer some protection if AFS isn't loaded */
946 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
947 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
953 /* save args for restart */
955 bozo_argv = malloc((argc+1) * sizeof(char*));
957 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
960 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
961 bozo_argv[bozo_argc] = NULL; /* null terminate list */
962 for (i = 1; i < argc; i++) {
963 bozo_argv[i] = argv[i];
965 #endif /* AFS_NT40_ENV */
968 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
970 /* bosserver specific options */
971 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
972 CMD_OPTIONAL, "disable authentication");
973 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG,
974 CMD_OPTIONAL, "enable logging of privileged commands");
975 cmd_AddParmAtOffset(opts, OPT_restricted, "-restricted", CMD_FLAG,
976 CMD_OPTIONAL, "enable restricted mode");
977 cmd_AddParmAtOffset(opts, OPT_pidfiles, "-pidfiles", CMD_SINGLE_OR_FLAG,
978 CMD_OPTIONAL, "enable creating pid files");
980 cmd_AddParmAtOffset(opts, OPT_nofork, "-nofork", CMD_FLAG,
981 CMD_OPTIONAL, "run in the foreground");
982 cmd_AddParmAtOffset(opts, OPT_cores, "-cores", CMD_SINGLE,
983 CMD_OPTIONAL, "none | path for core files");
984 #endif /* AFS_NT40_ENV */
986 /* general server options */
987 cmd_AddParmAtOffset(opts, OPT_auditinterface, "-audit-interface", CMD_SINGLE,
988 CMD_OPTIONAL, "audit interface (file or sysvmq)");
989 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
990 CMD_OPTIONAL, "audit log path");
991 cmd_AddParmAtOffset(opts, OPT_transarc_logs, "-transarc-logs", CMD_FLAG,
992 CMD_OPTIONAL, "enable Transarc style logging");
995 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
996 CMD_OPTIONAL, "log to syslog");
1000 cmd_AddParmAtOffset(opts, OPT_peer_stats, "-enable_peer_stats", CMD_FLAG,
1001 CMD_OPTIONAL, "enable RX RPC statistics by peer");
1002 cmd_AddParmAtOffset(opts, OPT_process_stats, "-enable_process_stats", CMD_FLAG,
1003 CMD_OPTIONAL, "enable RX RPC statistics");
1004 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
1005 CMD_OPTIONAL, "bind only to the primary interface");
1006 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1007 CMD_OPTIONAL, "maximum MTU for RX");
1009 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG,
1010 CMD_OPTIONAL, "permit Kerberos 5 principals with dots");
1012 code = cmd_Parse(argc, argv, &opts);
1013 if (code == CMD_HELP) {
1019 /* bosserver options */
1020 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
1021 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
1022 cmd_OptionAsFlag(opts, OPT_restricted, &bozo_isrestricted);
1024 if (cmd_OptionPresent(opts, OPT_pidfiles)) {
1025 if (cmd_OptionAsString(opts, OPT_pidfiles, &DoPidFiles) != 0) {
1026 DoPidFiles = strdup(AFSDIR_LOCAL_DIR);
1028 fprintf(stderr, "bosserver: Failed to allocate memory\n");
1034 #ifndef AFS_NT40_ENV
1035 cmd_OptionAsFlag(opts, OPT_nofork, &nofork);
1037 if (cmd_OptionAsString(opts, OPT_cores, &DoCore) == 0) {
1038 if (strcmp(DoCore, "none")) {
1045 /* general server options */
1046 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1048 if (cmd_OptionAsString(opts, OPT_auditinterface, &auditIface) == 0) {
1049 if (osi_audit_interface(auditIface)) {
1050 printf("Invalid audit interface '%s'\n", auditIface);
1057 cmd_OptionAsFlag(opts, OPT_transarc_logs, &DoTransarcLogs);
1059 #ifndef AFS_NT40_ENV
1060 if (cmd_OptionPresent(opts, OPT_syslog)) {
1062 cmd_OptionAsInt(opts, OPT_syslog, &DoSyslogFacility);
1067 cmd_OptionAsFlag(opts, OPT_peer_stats, &DoPeerRPCStats);
1068 cmd_OptionAsFlag(opts, OPT_process_stats, &DoProcessRPCStats);
1069 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1070 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1073 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1075 #ifndef AFS_NT40_ENV
1076 if (geteuid() != 0) {
1077 printf("bosserver: must be run as root.\n");
1082 /* create useful dirs */
1083 i = CreateDirs(DoCore);
1085 printf("bosserver: could not set up directories, code %d\n", i);
1090 /* Support logging to named pipes by not renaming. */
1092 && (lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0)
1093 && !(S_ISFIFO(sb.st_mode))) {
1094 if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
1095 printf("bosserver: out of memory\n");
1098 rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);
1101 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1102 if (!bozo_logFile) {
1103 printf("bosserver: can't initialize log file (%s).\n",
1104 AFSDIR_SERVER_BOZLOG_FILEPATH);
1107 /* keep log closed normally, so can be removed */
1108 fclose(bozo_logFile);
1110 #ifndef AFS_NT40_ENV
1111 openlog("bosserver", LOG_PID, DoSyslogFacility);
1116 * go into the background and remove our controlling tty, close open
1120 #ifndef AFS_NT40_ENV
1123 printf("bosserver: warning - daemon() returned code %d\n", errno);
1125 #endif /* ! AFS_NT40_ENV */
1127 /* Write current state of directory permissions to log file */
1130 /* chdir to AFS log directory */
1134 i = chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1136 printf("bosserver: could not change to %s, code %d\n",
1137 DoCore ? DoCore : AFSDIR_SERVER_LOGS_DIRPATH, errno);
1141 if (auditFileName != NULL)
1142 osi_audit_file(auditFileName);
1144 /* try to read the key from the config file */
1145 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1147 tdir = CreateLocalCellConfig();
1149 /* opened the cell databse */
1150 bozo_confdir = tdir;
1152 if (afsconf_CountKeys(bozo_confdir) == 0) {
1153 bozo_Log("WARNING: No encryption keys found! "
1154 "All authenticated accesses will fail. "
1155 "Run akeyconvert or asetkey to import encryption keys.\n");
1158 code = bnode_Init();
1160 printf("bosserver: could not init bnode package, code %d\n", code);
1164 bnode_Register("fs", &fsbnode_ops, 3);
1165 bnode_Register("dafs", &dafsbnode_ops, 4);
1166 bnode_Register("simple", &ezbnode_ops, 1);
1167 bnode_Register("cron", &cronbnode_ops, 2);
1169 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1172 getrlimit(RLIMIT_CORE, &rlp);
1176 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1177 setrlimit(RLIMIT_CORE, &rlp);
1178 getrlimit(RLIMIT_CORE, &rlp);
1179 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1183 /* Read init file, starting up programs. Also starts watcher threads. */
1184 if ((code = ReadBozoFile(0))) {
1186 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1187 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1192 host = GetRxBindAddress();
1194 for (i = 0; i < 10; i++) {
1195 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1197 bozo_Log("can't initialize rx: code=%d\n", code);
1203 bozo_Log("Bos giving up, can't initialize rx\n");
1207 /* Set some rx config */
1209 rx_enablePeerRPCStats();
1210 if (DoProcessRPCStats)
1211 rx_enableProcessRPCStats();
1213 /* Disable jumbograms */
1216 if (rxMaxMTU != -1) {
1217 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1218 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1223 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1224 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1226 bozo_Log("Failed to create daemon thread\n");
1230 /* initialize audit user check */
1231 osi_audit_set_user_check(bozo_confdir, bozo_IsLocalRealmMatch);
1233 bozo_CreateRxBindFile(host); /* for local scripts */
1235 /* allow super users to manage RX statistics */
1236 rx_SetRxStatUserOk(bozo_rxstat_userok);
1238 afsconf_SetNoAuthFlag(tdir, noAuth);
1239 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1242 bozo_CreatePidFile("bosserver", NULL, getpid());
1245 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1246 "bozo", securityClasses, numClasses,
1247 BOZO_ExecuteRequest);
1248 rx_SetMinProcs(tservice, 2);
1249 rx_SetMaxProcs(tservice, 4);
1250 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1251 if (rxkadDisableDotCheck) {
1252 code = rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1253 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1255 bozo_Log("Failed to allow dotted principals: code %d\n", code);
1261 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1262 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1263 rx_SetMinProcs(tservice, 2);
1264 rx_SetMaxProcs(tservice, 4);
1265 rx_StartServer(1); /* donate this process */
1270 bozo_Log(const char *format, ...)
1276 va_start(ap, format);
1279 #ifndef AFS_NT40_ENV
1280 vsyslog(LOG_INFO, format, ap);
1284 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1287 /* log normally closed, so can be removed */
1289 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1290 if (bozo_logFile == NULL) {
1291 printf("bosserver: WARNING: problem with %s\n",
1292 AFSDIR_SERVER_BOZLOG_FILEPATH);
1293 printf("%s ", tdate);
1294 vprintf(format, ap);
1297 fprintf(bozo_logFile, "%s ", tdate);
1298 vfprintf(bozo_logFile, format, ap);
1300 /* close so rm BosLog works */
1301 fclose(bozo_logFile);