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>
15 #include <sys/types.h>
24 #include <WINNT/afsevent.h>
26 #ifdef HAVE_SYS_FILE_H
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
40 #include <rx/rx_globals.h>
41 #include <rx/rxstat.h>
42 #include <afs/cellconfig.h>
45 #include <afs/audit.h>
48 #include <afs/afsutil.h>
50 #include "vlserver_internal.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];
61 static void *CheckSignal(void*);
64 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
67 int rxkadDisableDotCheck = 0;
70 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
71 afs_uint32 SHostAddrs[ADDRSPERSITE];
74 CheckSignal_Signal(int unused)
76 #if defined(AFS_PTHREAD_ENV)
79 IOMGR_SoftSig(CheckSignal, 0);
84 CheckSignal(void *unused)
86 register int i, errorcode;
87 struct ubik_trans *trans;
90 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
91 return (void *)(intptr_t)errorcode;
92 VLog(0, ("Dump name hash table out\n"));
93 for (i = 0; i < HASHSIZE; i++) {
96 VLog(0, ("Dump id hash table out\n"));
97 for (i = 0; i < HASHSIZE; i++) {
100 return ((void *)(intptr_t)ubik_EndTrans(trans));
104 /* Initialize the stats for the opcodes */
106 initialize_dstats(void)
110 dynamic_statistics.start_time = (afs_uint32) time(0);
111 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
112 dynamic_statistics.requests[i] = 0;
113 dynamic_statistics.aborts[i] = 0;
117 /* check whether caller is authorized to manage RX statistics */
119 vldb_rxstat_userok(struct rx_call *call)
121 return afsconf_SuperUser(vldb_confdir, call, NULL);
124 /* Main server module */
126 #include "AFS_component_version_number.c"
129 main(int argc, char **argv)
131 register afs_int32 code;
133 struct rx_service *tservice;
134 struct rx_securityClass *sc[3];
135 struct afsconf_dir *tdir;
136 struct ktc_encryptionKey tkey;
137 struct afsconf_cell info;
139 char hostname[VL_MAXNAMELEN];
140 int noAuth = 0, index, i;
141 char commandLine[150];
142 char clones[MAXHOSTSPERCELL];
143 char *auditFileName = NULL;
144 afs_uint32 host = ntohl(INADDR_ANY);
148 * The following signal action for AIX is necessary so that in case of a
149 * crash (i.e. core is generated) we can include the user's data section
150 * in the core dump. Unfortunately, by default, only a partial core is
151 * generated which, in many cases, isn't too useful.
153 struct sigaction nsa;
155 rx_extraPackets = 100; /* should be a switch, I guess... */
156 sigemptyset(&nsa.sa_mask);
157 nsa.sa_handler = SIG_DFL;
158 nsa.sa_flags = SA_FULLDUMP;
159 sigaction(SIGABRT, &nsa, NULL);
160 sigaction(SIGSEGV, &nsa, NULL);
164 /* Parse command line */
165 for (index = 1; index < argc; index++) {
166 if (strcmp(argv[index], "-noauth") == 0) {
168 } else if (strcmp(argv[index], "-p") == 0) {
169 lwps = atoi(argv[++index]);
171 printf("Warning: '-p %d' is too big; using %d instead\n",
175 } else if (strcmp(argv[index], "-d") == 0) {
176 if ((index + 1) >= argc) {
177 fprintf(stderr, "missing argument for -d\n");
180 debuglevel = atoi(argv[++index]);
181 LogLevel = debuglevel;
182 } else if (strcmp(argv[index], "-nojumbo") == 0) {
184 } else if (strcmp(argv[index], "-jumbo") == 0) {
186 } else if (strcmp(argv[index], "-rxbind") == 0) {
188 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
189 rxkadDisableDotCheck = 1;
190 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
191 if ((index + 1) >= argc) {
192 fprintf(stderr, "missing argument for -rxmaxmtu\n");
195 rxMaxMTU = atoi(argv[++index]);
196 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
197 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
198 printf("rxMaxMTU %d invalid; must be between %d-%lu\n",
199 rxMaxMTU, RX_MIN_PACKET_SIZE,
200 RX_MAX_PACKET_DATA_SIZE);
204 } else if (strcmp(argv[index], "-smallmem") == 0) {
207 } else if (strcmp(argv[index], "-trace") == 0) {
208 extern char rxi_tracename[80];
209 strcpy(rxi_tracename, argv[++index]);
211 } else if (strcmp(argv[index], "-auditlog") == 0) {
212 auditFileName = argv[++index];
214 } else if (strcmp(argv[index], "-audit-interface") == 0) {
215 char *interface = argv[++index];
217 if (osi_audit_interface(interface)) {
218 printf("Invalid audit interface '%s'\n", interface);
222 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
223 rx_enablePeerRPCStats();
224 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
225 rx_enableProcessRPCStats();
227 } else if (strcmp(argv[index], "-syslog") == 0) {
228 /* set syslog logging flag */
230 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
232 serverLogSyslogFacility = atoi(argv[index] + 8);
235 /* support help flag */
237 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
238 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
239 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
240 "[-syslog[=FACILITY]] "
241 "[-enable_peer_stats] [-enable_process_stats] "
244 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
245 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
246 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
247 "[-enable_peer_stats] [-enable_process_stats] "
256 osi_audit_file(auditFileName);
259 /* Initialize dirpaths */
260 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
262 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
264 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
268 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
271 serverLogSyslogTag = "vlserver";
273 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
276 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
279 ("vlserver: can't open configuration files in dir %s, giving up.\n",
280 AFSDIR_SERVER_ETC_DIRPATH);
284 /* initialize winsock */
285 if (afs_winsockInit() < 0) {
286 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
287 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
292 gethostname(hostname, sizeof(hostname));
293 th = gethostbyname(hostname);
295 printf("vlserver: couldn't get address of this host (%s).\n",
299 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
301 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
302 signal(SIGXCPU, CheckSignal_Signal);
304 /* get list of servers */
306 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
309 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
313 vldb_confdir = tdir; /* Preserve our configuration dir */
314 /* rxvab no longer supported */
315 memset(&tkey, 0, sizeof(tkey));
318 afsconf_SetNoAuthFlag(tdir, 1);
323 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
324 AFSDIR_SERVER_NETINFO_FILEPATH) {
326 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
327 ADDRSPERSITE, reason,
328 AFSDIR_SERVER_NETINFO_FILEPATH,
329 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
333 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
336 host = SHostAddrs[0];
337 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
342 ubik_CRXSecurityProc = afsconf_ClientAuth;
343 ubik_CRXSecurityRock = (char *)tdir;
344 ubik_SRXSecurityProc = afsconf_ServerAuth;
345 ubik_SRXSecurityRock = (char *)tdir;
346 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
347 ubik_CheckRXSecurityRock = (char *)tdir;
349 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
350 vl_dbaseName, &VL_dbase);
352 printf("vlserver: Ubik init failed with code %d\n", code);
358 if (rxMaxMTU != -1) {
359 rx_SetMaxMTU(rxMaxMTU);
361 rx_SetRxDeadTime(50);
363 memset(HostAddress, 0, sizeof(HostAddress));
366 sc[0] = rxnull_NewServerSecurityObject();
367 sc[1] = (struct rx_securityClass *)0;
368 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
371 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
373 if (tservice == (struct rx_service *)0) {
374 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
377 rx_SetMinProcs(tservice, 2);
380 rx_SetMaxProcs(tservice, lwps);
382 if (rxkadDisableDotCheck) {
383 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
384 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
388 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
389 RXSTATS_ExecuteRequest);
390 if (tservice == (struct rx_service *)0) {
391 printf("vlserver: Could not create rpc stats rx service\n");
394 rx_SetMinProcs(tservice, 2);
395 rx_SetMaxProcs(tservice, 4);
397 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
399 strcat(commandLine, " ");
400 strcat(commandLine, argv[i]);
403 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
404 printf("%s\n", cml_version_number); /* Goes to the log */
406 /* allow super users to manage RX statistics */
407 rx_SetRxStatUserOk(vldb_rxstat_userok);
409 rx_StartServer(1); /* Why waste this idle process?? */
411 return 0; /* not reachable */