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
18 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
21 #ifdef HAVE_SYS_RESOURCE_H
22 #include <sys/resource.h>
27 #include <WINNT/afsevent.h>
28 #endif /* AFS_NT40_ENV */
32 #include <rx/rx_globals.h>
34 #include <rx/rxstat.h>
36 #include <afs/ktime.h>
37 #include <afs/afsutil.h>
38 #include <afs/fileutil.h>
39 #include <afs/audit.h>
40 #include <afs/cellconfig.h>
42 #if defined(AFS_SGI_ENV)
43 #include <afs/afs_args.h>
48 #include "bosprototypes.h"
50 #define BOZO_LWP_STACKSIZE 16000
51 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
53 struct afsconf_dir *bozo_confdir = 0; /* bozo configuration dir */
54 static PROCESS bozo_pid;
55 const char *bozo_fileName;
58 static int bozo_argc = 0;
59 static char** bozo_argv = NULL;
65 const char *DoPidFiles = NULL;
67 int DoSyslogFacility = LOG_DAEMON;
69 static afs_int32 nextRestart;
70 static afs_int32 nextDay;
72 struct ktime bozo_nextRestartKT, bozo_nextDayKT;
75 int rxkadDisableDotCheck = 0;
77 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
78 afs_uint32 SHostAddrs[ADDRSPERSITE];
80 int bozo_isrestricted = 0;
81 int bozo_restdisable = 0;
84 bozo_insecureme(int sig)
86 signal(SIGFPE, bozo_insecureme);
87 bozo_isrestricted = 0;
95 /* check whether caller is authorized to manage RX statistics */
97 bozo_rxstat_userok(struct rx_call *call)
99 return afsconf_SuperUser(bozo_confdir, call, NULL);
103 * Return true if this name is a member of the local realm.
106 bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
108 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
109 afs_int32 islocal = 0; /* default to no */
112 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
114 bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
115 code, name, inst, cell);
120 /* restart bozo process */
125 /* exit with restart code; SCM integrator process will restart bosserver with
126 the same arguments */
127 exit(BOSEXIT_RESTART);
129 /* exec new bosserver process */
132 /* close random fd's */
133 for (i = 3; i < 64; i++) {
137 unlink(AFSDIR_SERVER_BOZRXBIND_FILEPATH);
139 execv(bozo_argv[0], bozo_argv); /* should not return */
141 #endif /* AFS_NT40_ENV */
144 /* make sure a dir exists */
146 MakeDir(const char *adir)
150 if (stat(adir, &tstat) < 0 || (tstat.st_mode & S_IFMT) != S_IFDIR) {
153 reqPerm = GetRequiredDirPerm(adir);
157 /* underlying filesystem may not support directory protection */
160 code = mkdir(adir, reqPerm);
167 /* create all the bozo dirs */
169 CreateDirs(const char *coredir)
172 (AFSDIR_USR_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
173 strlen(AFSDIR_USR_DIRPATH)))
176 (AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
177 strlen(AFSDIR_USR_DIRPATH)))) {
178 MakeDir(AFSDIR_USR_DIRPATH);
181 (AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
182 strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
183 MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
185 MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
186 MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
187 MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
188 MakeDir(AFSDIR_SERVER_DB_DIRPATH);
189 MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
192 (AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
193 strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
194 MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
196 MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
198 symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
199 symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
200 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
201 #endif /* AFS_NT40_ENV */
207 /* strip the \\n from the end of the line, if it is present */
209 StripLine(char *abuffer)
213 tp = abuffer + strlen(abuffer); /* starts off pointing at the null */
215 return 0; /* null string, no last character to check */
216 tp--; /* aim at last character */
222 /* write one bnode's worth of entry into the file */
224 bzwrite(struct bnode *abnode, void *arock)
226 struct bztemp *at = (struct bztemp *)arock;
228 char tbuffer[BOZO_BSSIZE];
231 if (abnode->notifier)
232 fprintf(at->file, "bnode %s %s %d %s\n", abnode->type->name,
233 abnode->name, abnode->fileGoal, abnode->notifier);
235 fprintf(at->file, "bnode %s %s %d\n", abnode->type->name,
236 abnode->name, abnode->fileGoal);
238 code = bnode_GetParm(abnode, i, tbuffer, BOZO_BSSIZE);
244 fprintf(at->file, "parm %s\n", tbuffer);
246 fprintf(at->file, "end\n");
252 ReadBozoFile(char *aname)
255 char tbuffer[BOZO_BSSIZE];
257 char *instp, *typep, *notifier, *notp;
259 afs_int32 ktmask, ktday, kthour, ktmin, ktsec;
262 char *parms[MAXPARMS];
263 char *thisparms[MAXPARMS];
266 /* rename BozoInit to BosServer for the user */
268 /* if BozoInit exists and BosConfig doesn't, try a rename */
269 if (access(AFSDIR_SERVER_BOZINIT_FILEPATH, 0) == 0
270 && access(AFSDIR_SERVER_BOZCONF_FILEPATH, 0) != 0) {
272 renamefile(AFSDIR_SERVER_BOZINIT_FILEPATH,
273 AFSDIR_SERVER_BOZCONF_FILEPATH);
275 perror("bosconfig rename");
277 if (access(AFSDIR_SERVER_BOZCONFNEW_FILEPATH, 0) == 0) {
279 renamefile(AFSDIR_SERVER_BOZCONFNEW_FILEPATH,
280 AFSDIR_SERVER_BOZCONF_FILEPATH);
282 perror("bosconfig rename");
286 /* don't do server restarts by default */
287 bozo_nextRestartKT.mask = KTIME_NEVER;
288 bozo_nextRestartKT.hour = 0;
289 bozo_nextRestartKT.min = 0;
290 bozo_nextRestartKT.day = 0;
292 /* restart processes at 5am if their binaries have changed */
293 bozo_nextDayKT.mask = KTIME_HOUR | KTIME_MIN;
294 bozo_nextDayKT.hour = 5;
295 bozo_nextDayKT.min = 0;
297 for (code = 0; code < MAXPARMS; code++)
301 aname = (char *)bozo_fileName;
302 tfile = fopen(aname, "r");
305 instp = malloc(BOZO_BSSIZE);
306 typep = malloc(BOZO_BSSIZE);
307 notifier = notp = malloc(BOZO_BSSIZE);
309 /* ok, read lines giving parms and such from the file */
310 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
312 break; /* all done */
314 if (strncmp(tbuffer, "restarttime", 11) == 0) {
316 sscanf(tbuffer, "restarttime %d %d %d %d %d", &ktmask, &ktday,
317 &kthour, &ktmin, &ktsec);
322 /* otherwise we've read in the proper ktime structure; now assign
323 * it and continue processing */
324 bozo_nextRestartKT.mask = ktmask;
325 bozo_nextRestartKT.day = ktday;
326 bozo_nextRestartKT.hour = kthour;
327 bozo_nextRestartKT.min = ktmin;
328 bozo_nextRestartKT.sec = ktsec;
332 if (strncmp(tbuffer, "checkbintime", 12) == 0) {
334 sscanf(tbuffer, "checkbintime %d %d %d %d %d", &ktmask,
335 &ktday, &kthour, &ktmin, &ktsec);
340 /* otherwise we've read in the proper ktime structure; now assign
341 * it and continue processing */
342 bozo_nextDayKT.mask = ktmask; /* time to restart the system */
343 bozo_nextDayKT.day = ktday;
344 bozo_nextDayKT.hour = kthour;
345 bozo_nextDayKT.min = ktmin;
346 bozo_nextDayKT.sec = ktsec;
350 if (strncmp(tbuffer, "restrictmode", 12) == 0) {
351 code = sscanf(tbuffer, "restrictmode %d", &rmode);
356 if (rmode != 0 && rmode != 1) {
360 bozo_isrestricted = rmode;
364 if (strncmp("bnode", tbuffer, 5) != 0) {
370 sscanf(tbuffer, "bnode %s %s %d %s", typep, instp, &goal,
375 } else if (code == 3)
378 memset(thisparms, 0, sizeof(thisparms));
380 for (i = 0; i < MAXPARMS; i++) {
381 /* now read the parms, until we see an "end" line */
382 tp = fgets(tbuffer, sizeof(tbuffer), tfile);
388 if (!strncmp(tbuffer, "end", 3))
390 if (strncmp(tbuffer, "parm ", 5)) {
392 goto fail; /* no "parm " either */
394 if (!parms[i]) /* make sure there's space */
395 parms[i] = (char *)malloc(BOZO_BSSIZE);
396 strcpy(parms[i], tbuffer + 5); /* remember the parameter for later */
397 thisparms[i] = parms[i];
400 /* ok, we have the type and parms, now create the object */
402 bnode_Create(typep, instp, &tb, thisparms[0], thisparms[1],
403 thisparms[2], thisparms[3], thisparms[4], notifier,
404 goal ? BSTAT_NORMAL : BSTAT_SHUTDOWN, 0);
408 /* bnode created in 'temporarily shutdown' state;
409 * check to see if we are supposed to run this guy,
410 * and if so, start the process up */
412 bnode_SetStat(tb, BSTAT_NORMAL); /* set goal, taking effect immediately */
414 bnode_SetStat(tb, BSTAT_SHUTDOWN);
425 for (i = 0; i < MAXPARMS; i++)
433 /* write a new bozo file */
435 WriteBozoFile(char *aname)
438 char tbuffer[AFSDIR_PATH_MAX];
443 aname = (char *)bozo_fileName;
444 strcpy(tbuffer, aname);
445 strcat(tbuffer, ".NBZ");
446 tfile = fopen(tbuffer, "w");
451 fprintf(tfile, "restrictmode %d\n", bozo_isrestricted);
452 fprintf(tfile, "restarttime %d %d %d %d %d\n", bozo_nextRestartKT.mask,
453 bozo_nextRestartKT.day, bozo_nextRestartKT.hour,
454 bozo_nextRestartKT.min, bozo_nextRestartKT.sec);
455 fprintf(tfile, "checkbintime %d %d %d %d %d\n", bozo_nextDayKT.mask,
456 bozo_nextDayKT.day, bozo_nextDayKT.hour, bozo_nextDayKT.min,
458 code = bnode_ApplyInstance(bzwrite, &btemp);
459 if (code || (code = ferror(tfile))) { /* something went wrong */
464 /* close the file, check for errors and snap new file into place */
465 if (fclose(tfile) == EOF) {
469 code = renamefile(tbuffer, aname);
478 bdrestart(struct bnode *abnode, void *arock)
482 if (abnode->fileGoal != BSTAT_NORMAL || abnode->goal != BSTAT_NORMAL)
483 return 0; /* don't restart stopped bnodes */
485 code = bnode_RestartP(abnode);
487 /* restart the dude */
488 bnode_SetStat(abnode, BSTAT_SHUTDOWN);
489 bnode_WaitStatus(abnode, BSTAT_SHUTDOWN);
490 bnode_SetStat(abnode, BSTAT_NORMAL);
492 bnode_Release(abnode);
493 return 0; /* keep trying all bnodes */
496 #define BOZO_MINSKIP 3600 /* minimum to advance clock */
497 /* lwp to handle system restarts */
499 BozoDaemon(void *unused)
503 /* now initialize the values */
507 now = FT_ApproxTime();
509 if (bozo_restdisable) {
510 bozo_Log("Restricted mode disabled by signal\n");
511 bozo_restdisable = 0;
514 if (bozo_newKTs) { /* need to recompute restart times */
515 bozo_newKTs = 0; /* done for a while */
516 nextRestart = ktime_next(&bozo_nextRestartKT, BOZO_MINSKIP);
517 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
520 /* see if we should do a restart */
521 if (now > nextRestart) {
522 SBOZO_ReBozo(0); /* doesn't come back */
525 /* see if we should restart a server */
527 nextDay = ktime_next(&bozo_nextDayKT, BOZO_MINSKIP);
529 /* call the bnode restartp function, and restart all that require it */
530 bnode_ApplyInstance(bdrestart, 0);
542 int s, sb_max, ipfragttl;
546 f = popen("/usr/sbin/no -o sb_max", "r");
547 s = fscanf(f, "sb_max = %d", &sb_max);
551 f = popen("/usr/sbin/no -o ipfragttl", "r");
552 s = fscanf(f, "ipfragttl = %d", &ipfragttl);
562 sprintf(c, "/usr/sbin/no -o sb_max=%d -o ipfragttl=%d", sb_max,
571 * This routine causes the calling process to go into the background and
572 * to lose its controlling tty.
574 * It does not close or otherwise alter the standard file descriptors.
576 * It writes warning messages to the standard error output if certain
577 * fundamental errors occur.
579 * This routine has been tested on:
595 * A process is a process group leader if its process ID
596 * (getpid()) and its process group ID (getpgrp()) are the same.
600 * To create a new session (and thereby lose our controlling
601 * terminal) we cannot be a process group leader.
603 * To guarantee we are not a process group leader, we fork and
604 * let the parent process exit.
607 if (getpid() == getpgrp()) {
612 abort(); /* leave footprints */
616 default: /* parent */
623 * By here, we are not a process group leader, so we can make a
624 * new session and become the session leader.
628 pid_t sid = setsid();
631 static char err[] = "bosserver: WARNING: setsid() failed\n";
632 write(STDERR_FILENO, err, sizeof err - 1);
637 * Once we create a new session, the current process is a
638 * session leader without a controlling tty.
640 * On some systems, the first tty device the session leader
641 * opens automatically becomes the controlling tty for the
644 * So, to guarantee we do not acquire a controlling tty, we fork
645 * and let the parent process exit. The child process is not a
646 * session leader, and so it will not acquire a controlling tty
647 * even if it should happen to open a tty device.
650 if (getpid() == getpgrp()) {
655 abort(); /* leave footprints */
659 default: /* parent */
666 * check that we no longer have a controlling tty
672 fd = open("/dev/tty", O_RDONLY);
676 "bosserver: WARNING: /dev/tty still attached\n";
678 write(STDERR_FILENO, err, sizeof err - 1);
682 #endif /* ! AFS_NT40_ENV */
686 make_pid_filename(char *ainst, char *aname)
691 length = strlen(DoPidFiles) + strlen(ainst) + 6;
692 if (aname && *aname) {
693 length += strlen(aname) + 1;
695 buffer = malloc(length * sizeof(char));
698 bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
701 bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
704 if (aname && *aname) {
705 snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
708 snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
715 * Write a file containing the pid of the named process.
717 * @param ainst instance name
718 * @param aname sub-process name of the instance, may be null
719 * @param apid process id of the newly started process
724 bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
727 char *pidfile = NULL;
730 pidfile = make_pid_filename(ainst, aname);
734 if ((fp = fopen(pidfile, "w")) == NULL) {
735 bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
739 if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
742 if (fclose(fp) != 0) {
750 * Clean a pid file for a process which just exited.
752 * @param ainst instance name
753 * @param aname sub-process name of the instance, may be null
758 bozo_DeletePidFile(char *ainst, char *aname)
760 char *pidfile = NULL;
761 pidfile = make_pid_filename(ainst, aname);
770 * Create the rxbind file of this bosserver.
772 * @param host bind address of this server
777 bozo_CreateRxBindFile(afs_uint32 host)
782 if (host == htonl(INADDR_ANY)) {
783 host = htonl(0x7f000001);
786 afs_inet_ntoa_r(host, buffer);
787 bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT);
788 if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) {
789 bozo_Log("Unable to open rxbind address file: %s, code=%d\n",
790 AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno);
792 fprintf(fp, "%s\n", buffer);
797 /* start a process and monitor it */
799 #include "AFS_component_version_number.c"
802 main(int argc, char **argv, char **envp)
804 struct rx_service *tservice;
806 struct afsconf_dir *tdir;
809 char namebuf[AFSDIR_PATH_MAX];
811 afs_uint32 host = htonl(INADDR_ANY);
812 char *auditFileName = NULL;
813 struct rx_securityClass **securityClasses;
814 afs_int32 numClasses;
820 struct sigaction nsa;
822 /* for some reason, this permits user-mode RX to run a lot faster.
823 * we do it here in the bosserver, so we don't have to do it
824 * individually in each server.
829 * The following signal action for AIX is necessary so that in case of a
830 * crash (i.e. core is generated) we can include the user's data section
831 * in the core dump. Unfortunately, by default, only a partial core is
832 * generated which, in many cases, isn't too useful.
834 sigemptyset(&nsa.sa_mask);
835 nsa.sa_handler = SIG_DFL;
836 nsa.sa_flags = SA_FULLDUMP;
837 sigaction(SIGSEGV, &nsa, NULL);
838 sigaction(SIGABRT, &nsa, NULL);
841 signal(SIGFPE, bozo_insecureme);
844 /* Initialize winsock */
845 if (afs_winsockInit() < 0) {
846 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
847 fprintf(stderr, "%s: Couldn't initialize winsock.\n", argv[0]);
852 /* Initialize dirpaths */
853 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
855 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
857 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
862 /* some path inits */
863 bozo_fileName = AFSDIR_SERVER_BOZCONF_FILEPATH;
864 DoCore = AFSDIR_SERVER_LOGS_DIRPATH;
866 /* initialize the list of dirpaths that the bosserver has
867 * an interest in monitoring */
870 #if defined(AFS_SGI_ENV)
871 /* offer some protection if AFS isn't loaded */
872 if (syscall(AFS_SYSCALL, AFSOP_ENDLOG) < 0 && errno == ENOPKG) {
873 printf("bosserver: AFS doesn't appear to be configured in O.S..\n");
879 /* save args for restart */
881 bozo_argv = malloc((argc+1) * sizeof(char*));
883 fprintf(stderr, "%s: Failed to allocate argument list.\n", argv[0]);
886 bozo_argv[0] = (char*)AFSDIR_SERVER_BOSVR_FILEPATH; /* expected path */
887 bozo_argv[bozo_argc] = NULL; /* null terminate list */
888 #endif /* AFS_NT40_ENV */
891 for (code = 1; code < argc; code++) {
893 bozo_argv[code] = argv[code];
894 #endif /* AFS_NT40_ENV */
895 if (strcmp(argv[code], "-noauth") == 0) {
896 /* set noauth flag */
898 } else if (strcmp(argv[code], "-log") == 0) {
899 /* set extra logging flag */
903 else if (strcmp(argv[code], "-syslog") == 0) {
904 /* set syslog logging flag */
906 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
908 DoSyslogFacility = atoi(argv[code] + 8);
909 } else if (strncmp(argv[code], "-cores=", 7) == 0) {
910 if (strcmp((argv[code]+7), "none") == 0)
913 DoCore = (argv[code]+7);
914 } else if (strcmp(argv[code], "-nofork") == 0) {
918 else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
919 rx_enablePeerRPCStats();
920 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
921 rx_enableProcessRPCStats();
923 else if (strcmp(argv[code], "-restricted") == 0) {
924 bozo_isrestricted = 1;
926 else if (strcmp(argv[code], "-rxbind") == 0) {
929 else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
930 rxkadDisableDotCheck = 1;
932 else if (!strcmp(argv[code], "-rxmaxmtu")) {
933 if ((code + 1) >= argc) {
934 fprintf(stderr, "missing argument for -rxmaxmtu\n");
937 rxMaxMTU = atoi(argv[++code]);
939 else if (strcmp(argv[code], "-auditlog") == 0) {
940 auditFileName = argv[++code];
942 } else if (strcmp(argv[code], "-audit-interface") == 0) {
943 char *interface = argv[++code];
945 if (osi_audit_interface(interface)) {
946 printf("Invalid audit interface '%s'\n", interface);
949 } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
950 DoPidFiles = (argv[code]+10);
951 } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
952 DoPidFiles = AFSDIR_BOSCONFIG_DIR;
956 /* hack to support help flag */
959 printf("Usage: bosserver [-noauth] [-log] "
960 "[-auditlog <log path>] "
961 "[-audit-interafce <file|sysvmq> (default is file)] "
962 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
963 "[-syslog[=FACILITY]] "
965 "[-enable_peer_stats] [-enable_process_stats] "
966 "[-cores=<none|path>] \n"
967 "[-pidfiles[=path]] "
968 "[-nofork] " "[-help]\n");
970 printf("Usage: bosserver [-noauth] [-log] "
971 "[-auditlog <log path>] "
972 "[-audit-interafce <file|sysvmq> (default is file)] "
973 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
975 "[-enable_peer_stats] [-enable_process_stats] "
976 "[-cores=<none|path>] \n"
977 "[-pidfiles[=path]] "
986 osi_audit_file(auditFileName);
990 if (geteuid() != 0) {
991 printf("bosserver: must be run as root.\n");
998 printf("bosserver: could not init bnode package, code %d\n", code);
1002 bnode_Register("fs", &fsbnode_ops, 3);
1003 bnode_Register("dafs", &dafsbnode_ops, 4);
1004 bnode_Register("simple", &ezbnode_ops, 1);
1005 bnode_Register("cron", &cronbnode_ops, 2);
1007 /* create useful dirs */
1010 /* chdir to AFS log directory */
1014 chdir(AFSDIR_SERVER_LOGS_DIRPATH);
1017 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1021 /* go into the background and remove our controlling tty, close open
1025 #ifndef AFS_NT40_ENV
1028 #endif /* ! AFS_NT40_ENV */
1031 #ifndef AFS_NT40_ENV
1032 && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
1033 !(S_ISFIFO(sb.st_mode)))
1036 strcpy(namebuf, AFSDIR_BOZLOG_FILE);
1037 strcat(namebuf, ".old");
1038 renamefile(AFSDIR_BOZLOG_FILE, namebuf); /* try rename first */
1039 bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
1040 if (!bozo_logFile) {
1041 printf("bosserver: can't initialize log file (%s).\n",
1042 AFSDIR_SERVER_BOZLOG_FILEPATH);
1045 /* keep log closed normally, so can be removed */
1046 fclose(bozo_logFile);
1048 #ifndef AFS_NT40_ENV
1049 openlog("bosserver", LOG_PID, DoSyslogFacility);
1053 #if defined(RLIMIT_CORE) && defined(HAVE_GETRLIMIT)
1056 getrlimit(RLIMIT_CORE, &rlp);
1060 rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY;
1061 setrlimit(RLIMIT_CORE, &rlp);
1062 getrlimit(RLIMIT_CORE, &rlp);
1063 bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max);
1067 /* Write current state of directory permissions to log file */
1072 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1073 AFSDIR_SERVER_NETINFO_FILEPATH) {
1075 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1076 ADDRSPERSITE, reason,
1077 AFSDIR_SERVER_NETINFO_FILEPATH,
1078 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1080 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1083 host = SHostAddrs[0];
1086 for (i = 0; i < 10; i++) {
1088 code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
1090 code = rx_Init(htons(AFSCONF_NANNYPORT));
1093 bozo_Log("can't initialize rx: code=%d\n", code);
1099 bozo_Log("Bos giving up, can't initialize rx\n");
1103 /* Disable jumbograms */
1106 if (rxMaxMTU != -1) {
1107 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1108 bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
1113 code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
1114 /* param */ NULL , "bozo-the-clown",
1117 /* try to read the key from the config file */
1118 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1120 /* try to create local cell config file */
1121 struct afsconf_cell tcell;
1122 strcpy(tcell.name, "localcell");
1123 tcell.numServers = 1;
1124 code = gethostname(tcell.hostName[0], MAXHOSTCHARS);
1126 bozo_Log("failed to get hostname, code %d\n", errno);
1129 if (tcell.hostName[0][0] == 0) {
1130 bozo_Log("host name not set, can't start\n");
1131 bozo_Log("try the 'hostname' command\n");
1134 memset(tcell.hostAddr, 0, sizeof(tcell.hostAddr)); /* not computed */
1136 afsconf_SetCellInfo(bozo_confdir, AFSDIR_SERVER_ETC_DIRPATH,
1140 ("could not create cell database in '%s' (code %d), quitting\n",
1141 AFSDIR_SERVER_ETC_DIRPATH, code);
1144 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1147 ("failed to open newly-created cell database, quitting\n");
1152 /* initialize audit user check */
1153 osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
1155 /* read init file, starting up programs */
1156 if ((code = ReadBozoFile(0))) {
1158 ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n",
1159 code, AFSDIR_SERVER_BOZCONF_FILEPATH);
1163 bozo_CreateRxBindFile(host); /* for local scripts */
1165 /* opened the cell databse */
1166 bozo_confdir = tdir;
1168 /* allow super users to manage RX statistics */
1169 rx_SetRxStatUserOk(bozo_rxstat_userok);
1171 afsconf_SetNoAuthFlag(tdir, noAuth);
1172 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
1175 bozo_CreatePidFile("bosserver", NULL, getpid());
1178 tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
1179 "bozo", securityClasses, numClasses,
1180 BOZO_ExecuteRequest);
1181 rx_SetMinProcs(tservice, 2);
1182 rx_SetMaxProcs(tservice, 4);
1183 rx_SetStackSize(tservice, BOZO_LWP_STACKSIZE); /* so gethostbyname works (in cell stuff) */
1184 if (rxkadDisableDotCheck) {
1185 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1186 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1190 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
1191 securityClasses, numClasses, RXSTATS_ExecuteRequest);
1192 rx_SetMinProcs(tservice, 2);
1193 rx_SetMaxProcs(tservice, 4);
1194 rx_StartServer(1); /* donate this process */
1199 bozo_Log(char *format, ...)
1205 va_start(ap, format);
1208 #ifndef AFS_NT40_ENV
1209 vsyslog(LOG_INFO, format, ap);
1213 strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */
1216 /* log normally closed, so can be removed */
1218 bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
1219 if (bozo_logFile == NULL) {
1220 printf("bosserver: WARNING: problem with %s\n",
1221 AFSDIR_SERVER_BOZLOG_FILEPATH);
1222 printf("%s ", tdate);
1223 vprintf(format, ap);
1226 fprintf(bozo_logFile, "%s ", tdate);
1227 vfprintf(bozo_logFile, format, ap);
1229 /* close so rm BosLog works */
1230 fclose(bozo_logFile);