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>
17 #include <sys/types.h>
26 #include <WINNT/afsevent.h>
28 #ifdef HAVE_SYS_FILE_H
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
42 #include <rx/rx_globals.h>
43 #include <afs/cellconfig.h>
48 #include <afs/afsutil.h>
53 const char *vl_dbaseName;
54 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
57 struct vldstats dynamic_statistics;
58 struct ubik_dbase *VL_dbase;
59 afs_uint32 HostAddress[MAXSERVERID + 1];
60 extern int afsconf_CheckAuth();
61 extern int afsconf_ServerAuth();
63 static void *CheckSignal(void*);
66 int rxJumbograms = 1; /* default is to send and receive jumbo grams */
69 int rxkadDisableDotCheck = 0;
71 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
72 afs_uint32 SHostAddrs[ADDRSPERSITE];
77 #if defined(AFS_PTHREAD_ENV)
80 IOMGR_SoftSig(CheckSignal, 0);
85 CheckSignal(void *unused)
87 register int i, errorcode;
88 struct ubik_trans *trans;
91 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
92 return (void *)errorcode;
93 VLog(0, ("Dump name hash table out\n"));
94 for (i = 0; i < HASHSIZE; i++) {
97 VLog(0, ("Dump id hash table out\n"));
98 for (i = 0; i < HASHSIZE; i++) {
101 return ((void *)ubik_EndTrans(trans));
105 /* Initialize the stats for the opcodes */
111 dynamic_statistics.start_time = (afs_uint32) time(0);
112 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
113 dynamic_statistics.requests[i] = 0;
114 dynamic_statistics.aborts[i] = 0;
118 /* check whether caller is authorized to manage RX statistics */
120 vldb_rxstat_userok(call)
121 struct rx_call *call;
123 return afsconf_SuperUser(vldb_confdir, call, NULL);
126 /* Main server module */
128 #include "AFS_component_version_number.c"
134 register afs_int32 code;
136 struct rx_service *tservice;
137 struct rx_securityClass *sc[3];
138 extern int VL_ExecuteRequest();
139 extern int RXSTATS_ExecuteRequest();
140 struct afsconf_dir *tdir;
141 struct ktc_encryptionKey tkey;
142 struct afsconf_cell info;
144 char hostname[VL_MAXNAMELEN];
145 int noAuth = 0, index, i;
146 extern int rx_extraPackets;
147 char commandLine[150];
148 char clones[MAXHOSTSPERCELL];
149 afs_uint32 host = ntohl(INADDR_ANY);
153 * The following signal action for AIX is necessary so that in case of a
154 * crash (i.e. core is generated) we can include the user's data section
155 * in the core dump. Unfortunately, by default, only a partial core is
156 * generated which, in many cases, isn't too useful.
158 struct sigaction nsa;
160 rx_extraPackets = 100; /* should be a switch, I guess... */
161 sigemptyset(&nsa.sa_mask);
162 nsa.sa_handler = SIG_DFL;
163 nsa.sa_flags = SA_FULLDUMP;
164 sigaction(SIGABRT, &nsa, NULL);
165 sigaction(SIGSEGV, &nsa, NULL);
169 /* Parse command line */
170 for (index = 1; index < argc; index++) {
171 if (strcmp(argv[index], "-noauth") == 0) {
174 } else if (strcmp(argv[index], "-p") == 0) {
175 lwps = atoi(argv[++index]);
177 printf("Warning: '-p %d' is too big; using %d instead\n",
182 } else if (strcmp(argv[index], "-nojumbo") == 0) {
185 } else if (strcmp(argv[index], "-rxbind") == 0) {
187 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
188 rxkadDisableDotCheck = 1;
189 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
190 if ((index + 1) >= argc) {
191 fprintf(stderr, "missing argument for -rxmaxmtu\n");
194 rxMaxMTU = atoi(argv[++i]);
195 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
196 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
197 printf("rxMaxMTU %d invalid; must be between %d-%d\n",
198 rxMaxMTU, RX_MIN_PACKET_SIZE,
199 RX_MAX_PACKET_DATA_SIZE);
203 } else if (strcmp(argv[index], "-smallmem") == 0) {
206 } else if (strcmp(argv[index], "-trace") == 0) {
207 extern char rxi_tracename[80];
208 strcpy(rxi_tracename, argv[++index]);
210 } else if (strcmp(argv[index], "-auditlog") == 0) {
213 char oldName[MAXPATHLEN];
214 char *fileName = argv[++index];
219 if ((lstat(fileName, &statbuf) == 0)
220 && (S_ISFIFO(statbuf.st_mode))) {
221 flags = O_WRONLY | O_NONBLOCK;
225 strcpy(oldName, fileName);
226 strcat(oldName, ".old");
227 renamefile(fileName, oldName);
228 flags = O_WRONLY | O_TRUNC | O_CREAT;
230 tempfd = open(fileName, flags, 0666);
232 auditout = fdopen(tempfd, "a");
234 osi_audit_file(auditout);
236 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
238 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
239 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
240 rx_enablePeerRPCStats();
241 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
242 rx_enableProcessRPCStats();
244 } else if (strcmp(argv[index], "-syslog") == 0) {
245 /* set syslog logging flag */
247 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
249 serverLogSyslogFacility = atoi(argv[index] + 8);
252 /* support help flag */
254 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
255 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
256 "[-auditlog <log path>] "
257 "[-syslog[=FACILITY]] "
258 "[-enable_peer_stats] [-enable_process_stats] "
261 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
262 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
263 "[-auditlog <log path>] "
264 "[-enable_peer_stats] [-enable_process_stats] "
272 /* Initialize dirpaths */
273 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
275 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
277 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
281 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
284 serverLogSyslogTag = "vlserver";
286 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
289 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
292 ("vlserver: can't open configuration files in dir %s, giving up.\n",
293 AFSDIR_SERVER_ETC_DIRPATH);
297 /* initialize winsock */
298 if (afs_winsockInit() < 0) {
299 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
300 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
305 gethostname(hostname, sizeof(hostname));
306 th = gethostbyname(hostname);
308 printf("vlserver: couldn't get address of this host (%s).\n",
312 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
314 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
315 signal(SIGXCPU, CheckSignal_Signal);
317 /* get list of servers */
319 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
322 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
326 vldb_confdir = tdir; /* Preserve our configuration dir */
327 /* rxvab no longer supported */
328 memset(&tkey, 0, sizeof(tkey));
331 afsconf_SetNoAuthFlag(tdir, 1);
336 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
337 AFSDIR_SERVER_NETINFO_FILEPATH) {
339 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
340 ADDRSPERSITE, reason,
341 AFSDIR_SERVER_NETINFO_FILEPATH,
342 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
346 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
349 host = SHostAddrs[0];
350 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
355 ubik_CRXSecurityProc = afsconf_ClientAuth;
356 ubik_CRXSecurityRock = (char *)tdir;
357 ubik_SRXSecurityProc = afsconf_ServerAuth;
358 ubik_SRXSecurityRock = (char *)tdir;
359 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
360 ubik_CheckRXSecurityRock = (char *)tdir;
362 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
363 vl_dbaseName, &VL_dbase);
365 printf("vlserver: Ubik init failed with code %d\n", code);
371 if (rxMaxMTU != -1) {
372 rx_SetMaxMTU(rxMaxMTU);
374 rx_SetRxDeadTime(50);
376 memset(HostAddress, 0, sizeof(HostAddress));
379 sc[0] = rxnull_NewServerSecurityObject();
380 sc[1] = (struct rx_securityClass *)0;
381 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
384 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
386 if (tservice == (struct rx_service *)0) {
387 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
390 rx_SetMinProcs(tservice, 2);
393 rx_SetMaxProcs(tservice, lwps);
395 if (rxkadDisableDotCheck) {
396 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
397 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK,
402 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
403 RXSTATS_ExecuteRequest);
404 if (tservice == (struct rx_service *)0) {
405 printf("vlserver: Could not create rpc stats rx service\n");
408 rx_SetMinProcs(tservice, 2);
409 rx_SetMaxProcs(tservice, 4);
411 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
413 strcat(commandLine, " ");
414 strcat(commandLine, argv[i]);
417 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
418 printf("%s\n", cml_version_number); /* Goes to the log */
420 /* allow super users to manage RX statistics */
421 rx_SetRxStatUserOk(vldb_rxstat_userok);
423 rx_StartServer(1); /* Why waste this idle process?? */
425 return 0; /* not reachable */