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"
160 OPT_restricted_query,
165 main(int argc, char **argv)
169 struct rx_service *tservice;
170 struct rx_securityClass **securityClasses;
171 afs_int32 numClasses;
172 struct afsconf_dir *tdir;
173 struct ktc_encryptionKey tkey;
174 struct afsconf_cell info;
176 char hostname[VL_MAXNAMELEN];
178 char clones[MAXHOSTSPERCELL];
180 afs_uint32 host = ntohl(INADDR_ANY);
181 struct cmd_syndesc *opts;
182 struct logOptions logopts;
187 char *auditFileName = NULL;
188 char *interface = NULL;
189 char *optstring = NULL;
191 char *restricted_query_parameter = NULL;
195 * The following signal action for AIX is necessary so that in case of a
196 * crash (i.e. core is generated) we can include the user's data section
197 * in the core dump. Unfortunately, by default, only a partial core is
198 * generated which, in many cases, isn't too useful.
200 struct sigaction nsa;
202 rx_extraPackets = 100; /* should be a switch, I guess... */
203 sigemptyset(&nsa.sa_mask);
204 nsa.sa_handler = SIG_DFL;
205 nsa.sa_flags = SA_FULLDUMP;
206 sigaction(SIGABRT, &nsa, NULL);
207 sigaction(SIGSEGV, &nsa, NULL);
211 memset(&logopts, 0, sizeof(logopts));
213 /* Initialize dirpaths */
214 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
216 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
218 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
223 vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
224 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
226 cmd_DisableAbbreviations();
227 cmd_DisablePositionalCommands();
228 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
230 /* vlserver specific options */
231 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
232 CMD_OPTIONAL, "disable authentication");
233 cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG,
234 CMD_OPTIONAL, "optimise for small memory systems");
236 /* general server options */
237 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
238 CMD_OPTIONAL, "location of audit log");
239 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
240 CMD_OPTIONAL, "interface to use for audit logging");
241 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
242 CMD_OPTIONAL, "configuration location");
243 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE,
244 CMD_OPTIONAL, "debug level");
245 cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE,
246 CMD_OPTIONAL, "database file");
247 cmd_AddParmAlias(opts, OPT_database, "-db");
248 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
249 CMD_OPTIONAL, "location of logfile");
250 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
251 "number of threads");
253 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
254 CMD_OPTIONAL, "log to syslog");
256 cmd_AddParmAtOffset(opts, OPT_transarc_logs, "-transarc-logs", CMD_FLAG,
257 CMD_OPTIONAL, "enable Transarc style logging");
260 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
261 CMD_OPTIONAL, "enable RX transport statistics");
262 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
263 CMD_OPTIONAL, "enable RX RPC statistics");
264 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
265 CMD_OPTIONAL, "disable jumbograms");
266 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG,
267 CMD_OPTIONAL, "enable jumbograms");
268 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
269 CMD_OPTIONAL, "bind only to the primary interface");
270 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
271 CMD_OPTIONAL, "maximum MTU for RX");
272 cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE,
273 CMD_OPTIONAL, "rx trace file");
274 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
275 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
279 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
280 CMD_FLAG, CMD_OPTIONAL,
281 "permit Kerberos 5 principals with dots");
283 code = cmd_Parse(argc, argv, &opts);
284 if (code == CMD_HELP) {
290 cmd_OptionAsString(opts, OPT_config, &configDir);
292 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
293 cmd_SetCommandName("vlserver");
295 /* vlserver options */
296 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
297 cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem);
298 if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) {
299 extern char rxi_tracename[80];
300 strcpy(rxi_tracename, optstring);
305 /* general server options */
307 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
309 if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) {
310 if (osi_audit_interface(interface)) {
311 printf("Invalid audit interface '%s'\n", interface);
317 cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
319 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
321 printf("Warning: '-p %d' is too big; using %d instead\n",
327 cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
329 if (cmd_OptionPresent(opts, OPT_syslog)) {
330 if (cmd_OptionPresent(opts, OPT_logfile)) {
331 fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
334 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
335 fprintf(stderr, "Invalid options: -syslog and -transarc-logs are exclusive.\n");
339 logopts.lopt_dest = logDest_syslog;
340 logopts.lopt_facility = LOG_DAEMON; /* default value */
341 logopts.lopt_tag = "vlserver";
342 cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
346 logopts.lopt_dest = logDest_file;
347 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
348 logopts.lopt_rotateOnOpen = 1;
349 logopts.lopt_rotateStyle = logRotate_old;
351 if (cmd_OptionPresent(opts, OPT_logfile))
352 cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
354 logopts.lopt_filename = AFSDIR_SERVER_VLOG_FILEPATH;
359 if (cmd_OptionPresent(opts, OPT_peer))
360 rx_enablePeerRPCStats();
361 if (cmd_OptionPresent(opts, OPT_process))
362 rx_enableProcessRPCStats();
363 if (cmd_OptionPresent(opts, OPT_nojumbo))
365 if (cmd_OptionPresent(opts, OPT_jumbo))
368 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
370 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
373 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
375 /* restricted query */
376 if (cmd_OptionAsString(opts, OPT_restricted_query,
377 &restricted_query_parameter) == 0) {
378 if (strcmp(restricted_query_parameter, "anyuser") == 0)
379 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
380 else if (strcmp(restricted_query_parameter, "admin") == 0)
381 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
383 printf("invalid argument for -restricted_query: %s\n",
384 restricted_query_parameter);
387 free(restricted_query_parameter);
391 osi_audit_file(auditFileName);
395 #ifdef AFS_PTHREAD_ENV
397 SetupLogSoftSignals();
402 tdir = afsconf_Open(configDir);
405 ("vlserver: can't open configuration files in dir %s, giving up.\n",
410 /* initialize audit user check */
411 osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch);
414 /* initialize winsock */
415 if (afs_winsockInit() < 0) {
416 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
417 VLog(0, ("vlserver: couldn't initialize winsock. \n"));
422 gethostname(hostname, sizeof(hostname));
423 th = gethostbyname(hostname);
425 VLog(0, ("vlserver: couldn't get address of this host (%s).\n",
429 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
431 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
432 signal(SIGXCPU, CheckSignal_Signal);
434 /* get list of servers */
436 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
439 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
443 vldb_confdir = tdir; /* Preserve our configuration dir */
444 /* rxvab no longer supported */
445 memset(&tkey, 0, sizeof(tkey));
448 afsconf_SetNoAuthFlag(tdir, 1);
453 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
454 AFSDIR_SERVER_NETINFO_FILEPATH) {
456 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
457 ADDRSPERSITE, reason,
458 AFSDIR_SERVER_NETINFO_FILEPATH,
459 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
463 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
466 host = SHostAddrs[0];
473 if (rxMaxMTU != -1) {
474 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
475 VLog(0, ("rxMaxMTU %d invalid\n", rxMaxMTU));
480 VLog(0, ("vlserver binding rx to %s:%d\n",
481 afs_inet_ntoa_r(host, hoststr), AFSCONF_VLDBPORT));
482 code = rx_InitHost(host, htons(AFSCONF_VLDBPORT));
484 VLog(0, ("vlserver: Rx init failed: %d\n", code));
487 rx_SetRxDeadTime(50);
490 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
491 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
492 afsconf_CheckAuth, tdir);
494 ubik_SyncWriterCacheProc = vlsynccache;
496 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
497 vl_dbaseName, &VL_dbase);
499 VLog(0, ("vlserver: Ubik init failed: %s\n", afs_error_message(code)));
503 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
504 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
507 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
510 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
511 securityClasses, numClasses,
513 if (tservice == (struct rx_service *)0) {
514 VLog(0, ("vlserver: Could not create VLDB_SERVICE rx service\n"));
517 rx_SetMinProcs(tservice, 2);
520 rx_SetMaxProcs(tservice, lwps);
522 if (rxkadDisableDotCheck) {
523 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
524 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
528 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
529 securityClasses, numClasses,
530 RXSTATS_ExecuteRequest);
531 if (tservice == (struct rx_service *)0) {
532 VLog(0, ("vlserver: Could not create rpc stats rx service\n"));
535 rx_SetMinProcs(tservice, 2);
536 rx_SetMaxProcs(tservice, 4);
538 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
539 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
542 VLog(0, ("%s\n", cml_version_number));
544 /* allow super users to manage RX statistics */
545 rx_SetRxStatUserOk(vldb_rxstat_userok);
547 rx_StartServer(1); /* Why waste this idle process?? */
549 return 0; /* not reachable */