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 #ifdef AFS_PTHREAD_ENV
16 # include <opr/softsig.h>
17 # include <afs/procmgmt_softsig.h> /* must come after softsig.h */
21 #include <WINNT/afsevent.h>
24 #ifdef HAVE_SYS_FILE_H
30 #include <rx/rx_globals.h>
31 #include <rx/rxstat.h>
33 #include <afs/cellconfig.h>
36 #include <afs/audit.h>
37 #include <afs/com_err.h>
40 #include <afs/afsutil.h>
43 #include "vlserver_internal.h"
46 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
49 struct vldstats dynamic_statistics;
50 struct ubik_dbase *VL_dbase;
51 afs_uint32 rd_HostAddress[MAXSERVERID + 1];
52 afs_uint32 wr_HostAddress[MAXSERVERID + 1];
54 static void *CheckSignal(void*);
56 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
57 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
60 int rxkadDisableDotCheck = 0;
62 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
63 afs_uint32 SHostAddrs[ADDRSPERSITE];
66 CheckSignal_Signal(int unused)
68 #if defined(AFS_PTHREAD_ENV)
71 IOMGR_SoftSig(CheckSignal, 0);
76 CheckSignal(void *unused)
82 Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
83 return (void *)(intptr_t)errorcode;
84 VLog(0, ("Dump name hash table out\n"));
85 for (i = 0; i < HASHSIZE; i++) {
88 VLog(0, ("Dump id hash table out\n"));
89 for (i = 0; i < HASHSIZE; i++) {
92 return ((void *)(intptr_t)ubik_EndTrans(ctx.trans));
96 /* Initialize the stats for the opcodes */
98 initialize_dstats(void)
102 dynamic_statistics.start_time = (afs_uint32) time(0);
103 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
104 dynamic_statistics.requests[i] = 0;
105 dynamic_statistics.aborts[i] = 0;
109 /* check whether caller is authorized to manage RX statistics */
111 vldb_rxstat_userok(struct rx_call *call)
113 return afsconf_SuperUser(vldb_confdir, call, NULL);
117 * Return true if this name is a member of the local realm.
120 vldb_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
122 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
123 afs_int32 islocal = 0; /* default to no */
126 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
129 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
130 code, name, inst, cell));
135 /* Main server module */
137 #include "AFS_component_version_number.c"
164 main(int argc, char **argv)
168 struct rx_service *tservice;
169 struct rx_securityClass **securityClasses;
170 afs_int32 numClasses;
171 struct afsconf_dir *tdir;
172 struct ktc_encryptionKey tkey;
173 struct afsconf_cell info;
175 char hostname[VL_MAXNAMELEN];
177 char clones[MAXHOSTSPERCELL];
178 afs_uint32 host = ntohl(INADDR_ANY);
179 struct cmd_syndesc *opts;
180 struct logOptions logopts;
185 char *auditFileName = NULL;
186 char *interface = NULL;
187 char *optstring = NULL;
189 char *restricted_query_parameter = NULL;
193 * The following signal action for AIX is necessary so that in case of a
194 * crash (i.e. core is generated) we can include the user's data section
195 * in the core dump. Unfortunately, by default, only a partial core is
196 * generated which, in many cases, isn't too useful.
198 struct sigaction nsa;
200 rx_extraPackets = 100; /* should be a switch, I guess... */
201 sigemptyset(&nsa.sa_mask);
202 nsa.sa_handler = SIG_DFL;
203 nsa.sa_flags = SA_FULLDUMP;
204 sigaction(SIGABRT, &nsa, NULL);
205 sigaction(SIGSEGV, &nsa, NULL);
209 memset(&logopts, 0, sizeof(logopts));
211 /* Initialize dirpaths */
212 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
214 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
216 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
221 vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
222 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
224 cmd_DisableAbbreviations();
225 cmd_DisablePositionalCommands();
226 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
228 /* vlserver specific options */
229 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
230 CMD_OPTIONAL, "disable authentication");
231 cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG,
232 CMD_OPTIONAL, "optimise for small memory systems");
234 /* general server options */
235 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
236 CMD_OPTIONAL, "location of audit log");
237 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
238 CMD_OPTIONAL, "interface to use for audit logging");
239 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
240 CMD_OPTIONAL, "configuration location");
241 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE,
242 CMD_OPTIONAL, "debug level");
243 cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE,
244 CMD_OPTIONAL, "database file");
245 cmd_AddParmAlias(opts, OPT_database, "-db");
246 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
247 CMD_OPTIONAL, "location of logfile");
248 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
249 "number of threads");
251 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
252 CMD_OPTIONAL, "log to syslog");
256 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
257 CMD_OPTIONAL, "enable RX transport statistics");
258 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
259 CMD_OPTIONAL, "enable RX RPC statistics");
260 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
261 CMD_OPTIONAL, "disable jumbograms");
262 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG,
263 CMD_OPTIONAL, "enable jumbograms");
264 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
265 CMD_OPTIONAL, "bind only to the primary interface");
266 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
267 CMD_OPTIONAL, "maximum MTU for RX");
268 cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE,
269 CMD_OPTIONAL, "rx trace file");
270 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
271 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
275 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
276 CMD_FLAG, CMD_OPTIONAL,
277 "permit Kerberos 5 principals with dots");
279 code = cmd_Parse(argc, argv, &opts);
280 if (code == CMD_HELP) {
286 cmd_OptionAsString(opts, OPT_config, &configDir);
288 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
289 cmd_SetCommandName("vlserver");
291 /* vlserver options */
292 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
293 cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem);
294 if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) {
295 extern char rxi_tracename[80];
296 strcpy(rxi_tracename, optstring);
301 /* general server options */
303 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
305 if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) {
306 if (osi_audit_interface(interface)) {
307 printf("Invalid audit interface '%s'\n", interface);
313 cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
315 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
317 printf("Warning: '-p %d' is too big; using %d instead\n",
323 cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
325 if (cmd_OptionPresent(opts, OPT_syslog)) {
326 if (cmd_OptionPresent(opts, OPT_logfile)) {
327 fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
331 logopts.lopt_dest = logDest_syslog;
332 logopts.lopt_facility = LOG_DAEMON; /* default value */
333 logopts.lopt_tag = "vlserver";
334 cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
338 logopts.lopt_dest = logDest_file;
339 logopts.lopt_rotateOnOpen = 1;
340 logopts.lopt_rotateStyle = logRotate_old;
342 if (cmd_OptionPresent(opts, OPT_logfile))
343 cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
345 logopts.lopt_filename = AFSDIR_SERVER_VLOG_FILEPATH;
350 if (cmd_OptionPresent(opts, OPT_peer))
351 rx_enablePeerRPCStats();
352 if (cmd_OptionPresent(opts, OPT_process))
353 rx_enableProcessRPCStats();
354 if (cmd_OptionPresent(opts, OPT_nojumbo))
356 if (cmd_OptionPresent(opts, OPT_jumbo))
359 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
361 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
364 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
366 /* restricted query */
367 if (cmd_OptionAsString(opts, OPT_restricted_query,
368 &restricted_query_parameter) == 0) {
369 if (strcmp(restricted_query_parameter, "anyuser") == 0)
370 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
371 else if (strcmp(restricted_query_parameter, "admin") == 0)
372 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
374 printf("invalid argument for -restricted_query: %s\n",
375 restricted_query_parameter);
378 free(restricted_query_parameter);
382 osi_audit_file(auditFileName);
386 #ifdef AFS_PTHREAD_ENV
388 SetupLogSoftSignals();
393 tdir = afsconf_Open(configDir);
396 ("vlserver: can't open configuration files in dir %s, giving up.\n",
401 /* initialize audit user check */
402 osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch);
405 /* initialize winsock */
406 if (afs_winsockInit() < 0) {
407 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
408 VLog(0, ("vlserver: couldn't initialize winsock. \n"));
413 gethostname(hostname, sizeof(hostname));
414 th = gethostbyname(hostname);
416 VLog(0, ("vlserver: couldn't get address of this host (%s).\n",
420 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
422 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
423 signal(SIGXCPU, CheckSignal_Signal);
425 /* get list of servers */
427 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
430 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
434 vldb_confdir = tdir; /* Preserve our configuration dir */
435 /* rxvab no longer supported */
436 memset(&tkey, 0, sizeof(tkey));
439 afsconf_SetNoAuthFlag(tdir, 1);
444 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
445 AFSDIR_SERVER_NETINFO_FILEPATH) {
447 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
448 ADDRSPERSITE, reason,
449 AFSDIR_SERVER_NETINFO_FILEPATH,
450 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
454 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
457 host = SHostAddrs[0];
458 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
465 if (rxMaxMTU != -1) {
466 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
467 VLog(0, ("rxMaxMTU %d invalid\n", rxMaxMTU));
473 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
474 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
475 afsconf_CheckAuth, tdir);
477 ubik_SyncWriterCacheProc = vlsynccache;
479 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
480 vl_dbaseName, &VL_dbase);
482 VLog(0, ("vlserver: Ubik init failed: %s\n", afs_error_message(code)));
485 rx_SetRxDeadTime(50);
487 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
488 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
491 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
494 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
495 securityClasses, numClasses,
497 if (tservice == (struct rx_service *)0) {
498 VLog(0, ("vlserver: Could not create VLDB_SERVICE rx service\n"));
501 rx_SetMinProcs(tservice, 2);
504 rx_SetMaxProcs(tservice, lwps);
506 if (rxkadDisableDotCheck) {
507 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
508 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
512 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
513 securityClasses, numClasses,
514 RXSTATS_ExecuteRequest);
515 if (tservice == (struct rx_service *)0) {
516 VLog(0, ("vlserver: Could not create rpc stats rx service\n"));
519 rx_SetMinProcs(tservice, 2);
520 rx_SetMaxProcs(tservice, 4);
522 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
523 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
526 VLog(0, ("%s\n", cml_version_number));
528 /* allow super users to manage RX statistics */
529 rx_SetRxStatUserOk(vldb_rxstat_userok);
531 rx_StartServer(1); /* Why waste this idle process?? */
533 return 0; /* not reachable */