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++)
303 aname = (char *)bozo_fileName;
304 tfile = fopen(aname, "r");
307 instp = malloc(BOZO_BSSIZE);
308 typep = malloc(BOZO_BSSIZE);
309 notp = malloc(BOZO_BSSIZE);
311 /* ok, read lines giving parms and such from the file */
312 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
314 break; /* all done */
316 if (strncmp(tbuffer, "restarttime", 11) == 0) {
318 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
319 &kthour, &ktmin, &ktsec);
324 /* otherwise we've read in the proper ktime structure; now assign
325 * it and continue processing */
326 bozo_nextRestartKT.mask = ktmask;
327 bozo_nextRestartKT.day = ktday;
328 bozo_nextRestartKT.hour = kthour;
329 bozo_nextRestartKT.min = ktmin;
330 bozo_nextRestartKT.sec = ktsec;
334 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
336 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
337 &ktday, &kthour, &ktmin, &ktsec);
342 /* otherwise we've read in the proper ktime structure; now assign
343 * it and continue processing */
344 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
345 bozo_nextDayKT.day = ktday;
346 bozo_nextDayKT.hour = kthour;
347 bozo_nextDayKT.min = ktmin;
348 bozo_nextDayKT.sec = ktsec;
352 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
353 code = sscanf(tbuffer, "restrictmode %d", &rmode);
358 if (rmode != 0 && rmode != 1) {
362 bozo_isrestricted = rmode;
366 if (strncmp("bnode", tbuffer, 5) != 0) {
372 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
377 } else if (code == 3)
380 memset(thisparms, 0, sizeof(thisparms));
382 for (i = 0; i < MAXPARMS; i++) {
383 /* now read the parms, until we see an "end" line */
384 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
390 if (!strncmp(tbuffer, "end", 3))
392 if (strncmp(tbuffer, "parm ", 5)) {
394 goto fail; /* no "parm " either */
396 if (!parms[i]) /* make sure there's space */
397 parms[i] = malloc(BOZO_BSSIZE);
398 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
399 thisparms[i] = parms[i];
402 /* ok, we have the type and parms, now create the object */
404 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
405 thisparms[2], thisparms[3], thisparms[4], notifier,
406 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
410 /* bnode created in 'temporarily shutdown' state;
411 * check to see if we are supposed to run this guy,
412 * and if so, start the process up */
414 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
416 bnode_SetStat(tb, BSTAT_SHUTDOWN);
427 for (i = 0; i < MAXPARMS; i++)
435 /* write a new bozo file */
437 WriteBozoFile(char *aname)
440 char tbuffer[AFSDIR_PATH_MAX];
445 aname = (char *)bozo_fileName;
446 strcpy(tbuffer, aname);
447 strcat(tbuffer, ".NBZ");
448 tfile = fopen(tbuffer, "w");
453 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
454 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
455 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
456 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
457 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
458 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
460 code = bnode_ApplyInstance(bzwrite, &btemp);
461 if (code || (code = ferror(tfile))) { /* something went wrong */
466 /* close the file, check for errors and snap new file into place */
467 if (fclose(tfile) == EOF) {
471 code = rk_rename(tbuffer, aname);
480 bdrestart(struct bnode *abnode, void *arock)
484 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
485 return 0; /* don't restart stopped bnodes */
487 code = bnode_RestartP(abnode);
489 /* restart the dude */
490 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
491 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
492 bnode_SetStat(abnode, BSTAT_NORMAL);
494 bnode_Release(abnode);
495 return 0; /* keep trying all bnodes */
498 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
499 /* lwp to handle system restarts */
501 BozoDaemon(void *unused)
505 /* now initialize the values */
509 now = FT_ApproxTime();
511 if (bozo_restdisable) {
512 bozo_Log("Restricted mode disabled by signal\n");
513 bozo_restdisable = 0;
516 if (bozo_newKTs) { /* need to recompute restart times */
517 bozo_newKTs = 0; /* done for a while */
518 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
519 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
522 /* see if we should do a restart */
523 if (now > nextRestart) {
524 SBOZO_ReBozo(0); /* doesn't come back */
527 /* see if we should restart a server */
529 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
531 /* call the bnode restartp function, and restart all that require it */
532 bnode_ApplyInstance(bdrestart, 0);
544 int s, sb_max, ipfragttl;
548 f = popen("/usr/sbin/no -o sb_max", "r");
549 s = fscanf(f, "sb_max = %d", &sb_max);
553 f = popen("/usr/sbin/no -o ipfragttl", "r");
554 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
564 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
573 * This routine causes the calling process to go into the background and
574 * to lose its controlling tty.
576 * It does not close or otherwise alter the standard file descriptors.
578 * It writes warning messages to the standard error output if certain
579 * fundamental errors occur.
581 * This routine has been tested on:
597 * A process is a process group leader if its process ID
598 * (getpid()) and its process group ID (getpgrp()) are the same.
602 * To create a new session (and thereby lose our controlling
603 * terminal) we cannot be a process group leader.
605 * To guarantee we are not a process group leader, we fork and
606 * let the parent process exit.
609 if (getpid() == getpgrp()) {
614 abort(); /* leave footprints */
618 default: /* parent */
625 * By here, we are not a process group leader, so we can make a
626 * new session and become the session leader.
630 pid_t sid = setsid();
633 static char err[] = "bosserver: WARNING: setsid() failed\n";
634 write(STDERR_FILENO, err, sizeof err - 1);
639 * Once we create a new session, the current process is a
640 * session leader without a controlling tty.
642 * On some systems, the first tty device the session leader
643 * opens automatically becomes the controlling tty for the
646 * So, to guarantee we do not acquire a controlling tty, we fork
647 * and let the parent process exit. The child process is not a
648 * session leader, and so it will not acquire a controlling tty
649 * even if it should happen to open a tty device.
652 if (getpid() == getpgrp()) {
657 abort(); /* leave footprints */
661 default: /* parent */
668 * check that we no longer have a controlling tty
674 fd = open("/dev/tty", O_RDONLY);
678 "bosserver: WARNING: /dev/tty still attached\n";
680 write(STDERR_FILENO, err, sizeof err - 1);
684 #endif /* ! AFS_NT40_ENV */
688 make_pid_filename(char *ainst, char *aname)
692 if (aname && *aname) {
693 asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
695 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
698 asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
700 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
707 * Write a file containing the pid of the named process.
709 * @param ainst instance name
710 * @param aname sub-process name of the instance, may be null
711 * @param apid process id of the newly started process
716 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
719 char *pidfile = NULL;
722 pidfile = make_pid_filename(ainst, aname);
726 if ((fp = fopen(pidfile, "w")) == NULL) {
727 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
731 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
734 if (fclose(fp) != 0) {
742 * Clean a pid file for a process which just exited.
744 * @param ainst instance name
745 * @param aname sub-process name of the instance, may be null
750 bozo_DeletePidFile(char *ainst, char *aname)
752 char *pidfile = NULL;
753 pidfile = make_pid_filename(ainst, aname);
762 * Create the rxbind file of this bosserver.
764 * @param host bind address of this server
769 bozo_CreateRxBindFile(afs_uint32 host)
774 afs_inet_ntoa_r(host, buffer);
775 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
776 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
777 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
778 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
780 /* If listening on any interface, write the loopback interface
781 to the rxbind file to give local scripts a usable addresss. */
782 if (host == htonl(INADDR_ANY)) {
783 afs_inet_ntoa_r(htonl(0x7f000001), buffer);
785 fprintf(fp, "%s\n", buffer);
790 /* start a process and monitor it */
792 #include "AFS_component_version_number.c"
795 main(int argc, char **argv, char **envp)
797 struct rx_service *tservice;
799 struct afsconf_dir *tdir;
802 char namebuf[AFSDIR_PATH_MAX];
804 afs_uint32 host = htonl(INADDR_ANY);
805 char *auditFileName = NULL;
806 struct rx_securityClass **securityClasses;
807 afs_int32 numClasses;
813 struct sigaction nsa;
815 /* for some reason, this permits user-mode RX to run a lot faster.
816 * we do it here in the bosserver, so we don't have to do it
817 * individually in each server.
822 * The following signal action for AIX is necessary so that in case of a
823 * crash (i.e. core is generated) we can include the user's data section
824 * in the core dump. Unfortunately, by default, only a partial core is
825 * generated which, in many cases, isn't too useful.
827 sigemptyset(&nsa.sa_mask);
828 nsa.sa_handler = SIG_DFL;
829 nsa.sa_flags = SA_FULLDUMP;
830 sigaction(SIGSEGV, &nsa, NULL);
831 sigaction(SIGABRT, &nsa, NULL);
834 signal(SIGFPE, bozo_insecureme);
837 /* Initialize winsock */
838 if (afs_winsockInit() < 0) {
839 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
840 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
845 /* Initialize dirpaths */
846 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
848 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
850 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
855 /* some path inits */
856 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
857 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
859 /* initialize the list of dirpaths that the bosserver has
860 * an interest in monitoring */
863 #if defined(AFS_SGI_ENV)
864 /* offer some protection if AFS isn't loaded */
865 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
866 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
872 /* save args for restart */
874 bozo_argv = malloc((argc+1) * sizeof(char*));
876 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
879 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
880 bozo_argv[bozo_argc] = NULL; /* null terminate list */
881 #endif /* AFS_NT40_ENV */
884 for (code = 1; code < argc; code++) {
886 bozo_argv[code] = argv[code];
887 #endif /* AFS_NT40_ENV */
888 if (strcmp(argv[code], "-noauth") == 0) {
889 /* set noauth flag */
891 } else if (strcmp(argv[code], "-log") == 0) {
892 /* set extra logging flag */
896 else if (strcmp(argv[code], "-syslog") == 0) {
897 /* set syslog logging flag */
899 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
901 DoSyslogFacility = atoi(argv[code] + 8);
902 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
903 if (strcmp((argv[code]+7), "none") == 0)
906 DoCore = (argv[code]+7);
907 } else if (strcmp(argv[code], "-nofork") == 0) {
911 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
912 rx_enablePeerRPCStats();
913 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
914 rx_enableProcessRPCStats();
916 else if (strcmp(argv[code], "-restricted") == 0) {
917 bozo_isrestricted = 1;
919 else if (strcmp(argv[code], "-rxbind") == 0) {
922 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
923 rxkadDisableDotCheck = 1;
925 else if (!strcmp(argv[code], "-rxmaxmtu")) {
926 if ((code + 1) >= argc) {
927 fprintf(stderr, "missing argument for -rxmaxmtu\n");
930 rxMaxMTU = atoi(argv[++code]);
932 else if (strcmp(argv[code], "-auditlog") == 0) {
933 auditFileName = argv[++code];
935 } else if (strcmp(argv[code], "-audit-interface") == 0) {
936 char *interface = argv[++code];
938 if (osi_audit_interface(interface)) {
939 printf("Invalid audit interface '%s'\n", interface);
942 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
943 DoPidFiles = (argv[code]+10);
944 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
945 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
949 /* hack to support help flag */
952 printf("Usage: bosserver [-noauth] [-log] "
953 "[-auditlog <log path>] "
954 "[-audit-interface <file|sysvmq> (default is file)] "
955 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
956 "[-syslog[=FACILITY]] "
958 "[-enable_peer_stats] [-enable_process_stats] "
959 "[-cores=<none|path>] \n"
960 "[-pidfiles[=path]] "
961 "[-nofork] " "[-help]\n");
963 printf("Usage: bosserver [-noauth] [-log] "
964 "[-auditlog <log path>] "
965 "[-audit-interface <file|sysvmq> (default is file)] "
966 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
968 "[-enable_peer_stats] [-enable_process_stats] "
969 "[-cores=<none|path>] \n"
970 "[-pidfiles[=path]] "
979 osi_audit_file(auditFileName);
983 if (geteuid() != 0) {
984 printf("bosserver: must be run as root.\n");
991 printf("bosserver: could not init bnode package, code %d\n", code);
995 bnode_Register("fs", &fsbnode_ops, 3);
996 bnode_Register("dafs", &dafsbnode_ops, 4);
997 bnode_Register("simple", &ezbnode_ops, 1);
998 bnode_Register("cron", &cronbnode_ops, 2);
1000 /* create useful dirs */
1003 /* chdir to AFS log directory */
1007 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1010 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1014 /* go into the background and remove our controlling tty, close open
1018 #ifndef AFS_NT40_ENV
1021 #endif /* ! AFS_NT40_ENV */
1024 #ifndef AFS_NT40_ENV
1025 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1026 !(S_ISFIFO(sb.st_mode)))
1029 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1030 strcat(namebuf, ".old");
1031 rk_rename(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1032 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1033 if (!bozo_logFile) {
1034 printf("bosserver: can't initialize log file (%s).\n",
1035 AFSDIR_SERVER_BOZLOG_FILEPATH);
1038 /* keep log closed normally, so can be removed */
1039 fclose(bozo_logFile);
1041 #ifndef AFS_NT40_ENV
1042 openlog("bosserver", LOG_PID, DoSyslogFacility);
1046 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1049 getrlimit(RLIMIT_CORE, &rlp);
1053 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1054 setrlimit(RLIMIT_CORE, &rlp);
1055 getrlimit(RLIMIT_CORE, &rlp);
1056 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1060 /* Write current state of directory permissions to log file */
1065 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1066 AFSDIR_SERVER_NETINFO_FILEPATH) {
1068 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1069 ADDRSPERSITE, reason,
1070 AFSDIR_SERVER_NETINFO_FILEPATH,
1071 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1073 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1076 host = SHostAddrs[0];
1079 for (i = 0; i < 10; i++) {
1081 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1083 code = rx_Init(htons(AFSCONF_NANNYPORT));
1086 bozo_Log("can't initialize rx: code=%d\n", code);
1092 bozo_Log("Bos giving up, can't initialize rx\n");
1096 /* Disable jumbograms */
1099 if (rxMaxMTU != -1) {
1100 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1101 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1106 LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1107 /* param */ NULL , "bozo-the-clown", &bozo_pid);
1109 /* try to read the key from the config file */
1110 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1112 /* try to create local cell config file */
1113 struct afsconf_cell tcell;
1114 strcpy(tcell.name, "localcell");
1115 tcell.numServers = 1;
1116 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1118 bozo_Log("failed to get hostname, code %d\n", errno);
1121 if (tcell.hostName[0][0] == 0) {
1122 bozo_Log("host name not set, can't start\n");
1123 bozo_Log("try the 'hostname' command\n");
1126 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1128 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1132 ("could not create cell database in '%s' (code %d), quitting\n",
1133 AFSDIR_SERVER_ETC_DIRPATH, code);
1136 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1139 ("failed to open newly-created cell database, quitting\n");
1144 /* initialize audit user check */
1145 osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
1147 /* read init file, starting up programs */
1148 if ((code = ReadBozoFile(0))) {
1150 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1151 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1155 bozo_CreateRxBindFile(host); /* for local scripts */
1157 /* opened the cell databse */
1158 bozo_confdir = tdir;
1160 /* allow super users to manage RX statistics */
1161 rx_SetRxStatUserOk(bozo_rxstat_userok);
1163 afsconf_SetNoAuthFlag(tdir, noAuth);
1164 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1167 bozo_CreatePidFile("bosserver", NULL, getpid());
1170 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1171 "bozo", securityClasses, numClasses,
1172 BOZO_ExecuteRequest);
1173 rx_SetMinProcs(tservice, 2);
1174 rx_SetMaxProcs(tservice, 4);
1175 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1176 if (rxkadDisableDotCheck) {
1177 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1178 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1182 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1183 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1184 rx_SetMinProcs(tservice, 2);
1185 rx_SetMaxProcs(tservice, 4);
1186 rx_StartServer(1); /* donate this process */
1191 bozo_Log(char *format, ...)
1197 va_start(ap, format);
1200 #ifndef AFS_NT40_ENV
1201 vsyslog(LOG_INFO, format, ap);
1205 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1208 /* log normally closed, so can be removed */
1210 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1211 if (bozo_logFile == NULL) {
1212 printf("bosserver: WARNING: problem with %s\n",
1213 AFSDIR_SERVER_BOZLOG_FILEPATH);
1214 printf("%s ", tdate);
1215 vprintf(format, ap);
1218 fprintf(bozo_logFile, "%s ", tdate);
1219 vfprintf(bozo_logFile, format, ap);
1221 /* close so rm BosLog works */
1222 fclose(bozo_logFile);