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 <WINNT/afsevent.h>
20 #ifdef HAVE_SYS_FILE_H
26 #include <rx/rx_globals.h>
27 #include <rx/rxstat.h>
28 #include <afs/cellconfig.h>
31 #include <afs/audit.h>
32 #include <afs/com_err.h>
35 #include <afs/afsutil.h>
38 #include "vlserver_internal.h"
41 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
44 struct vldstats dynamic_statistics;
45 struct ubik_dbase *VL_dbase;
46 afs_uint32 rd_HostAddress[MAXSERVERID + 1];
47 afs_uint32 wr_HostAddress[MAXSERVERID + 1];
49 static void *CheckSignal(void*);
52 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
55 int rxkadDisableDotCheck = 0;
58 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
59 afs_uint32 SHostAddrs[ADDRSPERSITE];
62 CheckSignal_Signal(int unused)
64 #if defined(AFS_PTHREAD_ENV)
67 IOMGR_SoftSig(CheckSignal, 0);
72 CheckSignal(void *unused)
78 Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
79 return (void *)(intptr_t)errorcode;
80 VLog(0, ("Dump name hash table out\n"));
81 for (i = 0; i < HASHSIZE; i++) {
84 VLog(0, ("Dump id hash table out\n"));
85 for (i = 0; i < HASHSIZE; i++) {
88 return ((void *)(intptr_t)ubik_EndTrans(ctx.trans));
92 /* Initialize the stats for the opcodes */
94 initialize_dstats(void)
98 dynamic_statistics.start_time = (afs_uint32) time(0);
99 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
100 dynamic_statistics.requests[i] = 0;
101 dynamic_statistics.aborts[i] = 0;
105 /* check whether caller is authorized to manage RX statistics */
107 vldb_rxstat_userok(struct rx_call *call)
109 return afsconf_SuperUser(vldb_confdir, call, NULL);
112 /* Main server module */
114 #include "AFS_component_version_number.c"
117 main(int argc, char **argv)
121 struct rx_service *tservice;
122 struct rx_securityClass **securityClasses;
123 afs_int32 numClasses;
124 struct afsconf_dir *tdir;
125 struct ktc_encryptionKey tkey;
126 struct afsconf_cell info;
128 char hostname[VL_MAXNAMELEN];
129 int noAuth = 0, index;
130 char clones[MAXHOSTSPERCELL];
131 char *auditFileName = NULL;
132 afs_uint32 host = ntohl(INADDR_ANY);
134 const char *vl_dbaseName;
135 const char *configDir;
140 * The following signal action for AIX is necessary so that in case of a
141 * crash (i.e. core is generated) we can include the user's data section
142 * in the core dump. Unfortunately, by default, only a partial core is
143 * generated which, in many cases, isn't too useful.
145 struct sigaction nsa;
147 rx_extraPackets = 100; /* should be a switch, I guess... */
148 sigemptyset(&nsa.sa_mask);
149 nsa.sa_handler = SIG_DFL;
150 nsa.sa_flags = SA_FULLDUMP;
151 sigaction(SIGABRT, &nsa, NULL);
152 sigaction(SIGSEGV, &nsa, NULL);
156 /* Initialize dirpaths */
157 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
159 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
161 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
166 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
167 configDir = AFSDIR_SERVER_ETC_DIRPATH;
168 logFile = AFSDIR_SERVER_PTLOG_FILEPATH;
170 /* Parse command line */
171 for (index = 1; index < argc; index++) {
172 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",
181 } else if (strcmp(argv[index], "-d") == 0) {
182 if ((index + 1) >= argc) {
183 fprintf(stderr, "missing argument for -d\n");
186 debuglevel = atoi(argv[++index]);
187 LogLevel = debuglevel;
188 } else if (strcmp(argv[index], "-nojumbo") == 0) {
190 } else if (strcmp(argv[index], "-jumbo") == 0) {
192 } else if (strcmp(argv[index], "-rxbind") == 0) {
194 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
195 rxkadDisableDotCheck = 1;
196 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
197 if ((index + 1) >= argc) {
198 fprintf(stderr, "missing argument for -rxmaxmtu\n");
201 rxMaxMTU = atoi(argv[++index]);
202 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
203 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
204 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
205 rxMaxMTU, RX_MIN_PACKET_SIZE,
206 RX_MAX_PACKET_DATA_SIZE);
210 } else if (strcmp(argv[index], "-smallmem") == 0) {
213 } else if (strcmp(argv[index], "-trace") == 0) {
214 extern char rxi_tracename[80];
215 strcpy(rxi_tracename, argv[++index]);
217 } else if (strcmp(argv[index], "-auditlog") == 0) {
218 auditFileName = argv[++index];
220 } else if (strcmp(argv[index], "-audit-interface") == 0) {
221 char *interface = argv[++index];
223 if (osi_audit_interface(interface)) {
224 printf("Invalid audit interface '%s'\n", interface);
228 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
229 rx_enablePeerRPCStats();
230 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
231 rx_enableProcessRPCStats();
233 } else if (strcmp(argv[index], "-syslog") == 0) {
234 /* set syslog logging flag */
236 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
238 serverLogSyslogFacility = atoi(argv[index] + 8);
240 } else if ((strcmp(argv[index], "-database") == 0)
241 || (strcmp(argv[index], "-db") == 0)) {
242 vl_dbaseName = argv[++index];
243 } else if (strcmp(argv[index], "-config") == 0) {
244 if ((index + 1) > argc) {
245 fprintf(stderr, "missing argument for -config\n");
248 configDir = argv[++index];
249 } else if (strcmp(argv[index], "-logfile") == 0) {
250 if ((index + 1) > argc) {
251 fprintf(stderr, "missing argument for -logfile\n");
254 logFile = argv[++index];
256 /* support help flag */
257 printf("Usage: vlserver [-database <db path] "
258 "[-p <number of processes>] [-nojumbo] "
259 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
260 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
261 "[-config <config directory path>] "
262 "[-logfile <log file path>] ");
264 printf("[-syslog[=FACILITY]] ");
266 printf("[-enable_peer_stats] [-enable_process_stats] "
274 osi_audit_file(auditFileName);
278 serverLogSyslogTag = "vlserver";
280 OpenLog(logFile); /* set up logging */
283 tdir = afsconf_Open(configDir);
286 ("vlserver: can't open configuration files in dir %s, giving up.\n",
291 /* initialize winsock */
292 if (afs_winsockInit() < 0) {
293 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
294 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
299 gethostname(hostname, sizeof(hostname));
300 th = gethostbyname(hostname);
302 printf("vlserver: couldn't get address of this host (%s).\n",
306 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
308 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
309 signal(SIGXCPU, CheckSignal_Signal);
311 /* get list of servers */
313 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
316 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
320 vldb_confdir = tdir; /* Preserve our configuration dir */
321 /* rxvab no longer supported */
322 memset(&tkey, 0, sizeof(tkey));
325 afsconf_SetNoAuthFlag(tdir, 1);
330 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
331 AFSDIR_SERVER_NETINFO_FILEPATH) {
333 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
334 ADDRSPERSITE, reason,
335 AFSDIR_SERVER_NETINFO_FILEPATH,
336 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
340 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
343 host = SHostAddrs[0];
344 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
349 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
350 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
351 afsconf_CheckAuth, tdir);
353 ubik_SyncWriterCacheProc = vlsynccache;
355 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
356 vl_dbaseName, &VL_dbase);
358 printf("vlserver: Ubik init failed: %s\n", afs_error_message(code));
364 if (rxMaxMTU != -1) {
365 rx_SetMaxMTU(rxMaxMTU);
367 rx_SetRxDeadTime(50);
369 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
370 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
373 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
376 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
377 securityClasses, numClasses,
379 if (tservice == (struct rx_service *)0) {
380 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
383 rx_SetMinProcs(tservice, 2);
386 rx_SetMaxProcs(tservice, lwps);
388 if (rxkadDisableDotCheck) {
389 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
390 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
394 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
395 securityClasses, numClasses,
396 RXSTATS_ExecuteRequest);
397 if (tservice == (struct rx_service *)0) {
398 printf("vlserver: Could not create rpc stats rx service\n");
401 rx_SetMinProcs(tservice, 2);
402 rx_SetMaxProcs(tservice, 4);
404 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
405 printf("%s\n", cml_version_number); /* Goes to the log */
407 /* allow super users to manage RX statistics */
408 rx_SetRxStatUserOk(vldb_rxstat_userok);
410 rx_StartServer(1); /* Why waste this idle process?? */
412 return 0; /* not reachable */