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>
29 #include <afs/cellconfig.h>
32 #include <afs/audit.h>
33 #include <afs/com_err.h>
36 #include <afs/afsutil.h>
39 #include "vlserver_internal.h"
42 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
45 struct vldstats dynamic_statistics;
46 struct ubik_dbase *VL_dbase;
47 afs_uint32 rd_HostAddress[MAXSERVERID + 1];
48 afs_uint32 wr_HostAddress[MAXSERVERID + 1];
50 static void *CheckSignal(void*);
53 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
54 int rxJumbograms = 0; /* default is to not send and receive jumbo grams */
57 int rxkadDisableDotCheck = 0;
59 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
60 afs_uint32 SHostAddrs[ADDRSPERSITE];
63 CheckSignal_Signal(int unused)
65 #if defined(AFS_PTHREAD_ENV)
68 IOMGR_SoftSig(CheckSignal, 0);
73 CheckSignal(void *unused)
79 Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
80 return (void *)(intptr_t)errorcode;
81 VLog(0, ("Dump name hash table out\n"));
82 for (i = 0; i < HASHSIZE; i++) {
85 VLog(0, ("Dump id hash table out\n"));
86 for (i = 0; i < HASHSIZE; i++) {
89 return ((void *)(intptr_t)ubik_EndTrans(ctx.trans));
93 /* Initialize the stats for the opcodes */
95 initialize_dstats(void)
99 dynamic_statistics.start_time = (afs_uint32) time(0);
100 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
101 dynamic_statistics.requests[i] = 0;
102 dynamic_statistics.aborts[i] = 0;
106 /* check whether caller is authorized to manage RX statistics */
108 vldb_rxstat_userok(struct rx_call *call)
110 return afsconf_SuperUser(vldb_confdir, call, NULL);
114 * Return true if this name is a member of the local realm.
117 vldb_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
119 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
120 afs_int32 islocal = 0; /* default to no */
123 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
126 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
127 code, name, inst, cell));
132 /* Main server module */
134 #include "AFS_component_version_number.c"
159 main(int argc, char **argv)
163 struct rx_service *tservice;
164 struct rx_securityClass **securityClasses;
165 afs_int32 numClasses;
166 struct afsconf_dir *tdir;
167 struct ktc_encryptionKey tkey;
168 struct afsconf_cell info;
170 char hostname[VL_MAXNAMELEN];
172 char clones[MAXHOSTSPERCELL];
173 afs_uint32 host = ntohl(INADDR_ANY);
174 struct cmd_syndesc *opts;
180 char *auditFileName = NULL;
181 char *interface = NULL;
182 char *optstring = NULL;
184 char *restricted_query_parameter = NULL;
188 * The following signal action for AIX is necessary so that in case of a
189 * crash (i.e. core is generated) we can include the user's data section
190 * in the core dump. Unfortunately, by default, only a partial core is
191 * generated which, in many cases, isn't too useful.
193 struct sigaction nsa;
195 rx_extraPackets = 100; /* should be a switch, I guess... */
196 sigemptyset(&nsa.sa_mask);
197 nsa.sa_handler = SIG_DFL;
198 nsa.sa_flags = SA_FULLDUMP;
199 sigaction(SIGABRT, &nsa, NULL);
200 sigaction(SIGSEGV, &nsa, NULL);
204 /* Initialize dirpaths */
205 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
207 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
209 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
214 vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
215 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
216 logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH);
218 cmd_DisableAbbreviations();
219 cmd_DisablePositionalCommands();
220 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
222 /* vlserver specific options */
223 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
224 CMD_OPTIONAL, "disable authentication");
225 cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG,
226 CMD_OPTIONAL, "optimise for small memory systems");
228 /* general server options */
229 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
230 CMD_OPTIONAL, "location of audit log");
231 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
232 CMD_OPTIONAL, "interface to use for audit logging");
233 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
234 CMD_OPTIONAL, "configuration location");
235 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE,
236 CMD_OPTIONAL, "debug level");
237 cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE,
238 CMD_OPTIONAL, "database file");
239 cmd_AddParmAlias(opts, OPT_database, "-db");
240 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
241 CMD_OPTIONAL, "location of logfile");
242 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
243 "number of threads");
244 #if !defined(AFS_NT40_ENV)
245 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
246 CMD_OPTIONAL, "log to syslog");
250 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
251 CMD_OPTIONAL, "enable RX transport statistics");
252 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
253 CMD_OPTIONAL, "enable RX RPC statistics");
254 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
255 CMD_OPTIONAL, "disable jumbograms");
256 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG,
257 CMD_OPTIONAL, "enable jumbograms");
258 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
259 CMD_OPTIONAL, "bind only to the primary interface");
260 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
261 CMD_OPTIONAL, "maximum MTU for RX");
262 cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE,
263 CMD_OPTIONAL, "rx trace file");
264 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
265 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
269 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
270 CMD_FLAG, CMD_OPTIONAL,
271 "permit Kerberos 5 principals with dots");
273 code = cmd_Parse(argc, argv, &opts);
274 if (code == CMD_HELP) {
280 cmd_OptionAsString(opts, OPT_config, &configDir);
282 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
283 cmd_SetCommandName("vlserver");
285 /* vlserver options */
286 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
287 cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem);
288 if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) {
289 extern char rxi_tracename[80];
290 strcpy(rxi_tracename, optstring);
295 /* general server options */
297 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
299 if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) {
300 if (osi_audit_interface(interface)) {
301 printf("Invalid audit interface '%s'\n", interface);
307 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
308 cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
309 cmd_OptionAsString(opts, OPT_logfile, &logFile);
311 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
313 printf("Warning: '-p %d' is too big; using %d instead\n",
319 if (cmd_OptionPresent(opts, OPT_syslog)) {
321 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
326 if (cmd_OptionPresent(opts, OPT_peer))
327 rx_enablePeerRPCStats();
328 if (cmd_OptionPresent(opts, OPT_process))
329 rx_enableProcessRPCStats();
330 if (cmd_OptionPresent(opts, OPT_nojumbo))
332 if (cmd_OptionPresent(opts, OPT_jumbo))
335 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
337 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
340 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
342 /* restricted query */
343 if (cmd_OptionAsString(opts, OPT_restricted_query,
344 &restricted_query_parameter) == 0) {
345 if (strcmp(restricted_query_parameter, "anyuser") == 0)
346 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
347 else if (strcmp(restricted_query_parameter, "admin") == 0)
348 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
350 printf("invalid argument for -restricted_query: %s\n",
351 restricted_query_parameter);
354 free(restricted_query_parameter);
358 osi_audit_file(auditFileName);
362 serverLogSyslogTag = "vlserver";
364 OpenLog(logFile); /* set up logging */
367 tdir = afsconf_Open(configDir);
370 ("vlserver: can't open configuration files in dir %s, giving up.\n",
375 /* initialize audit user check */
376 osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch);
379 /* initialize winsock */
380 if (afs_winsockInit() < 0) {
381 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
382 VLog(0, ("vlserver: couldn't initialize winsock. \n"));
387 gethostname(hostname, sizeof(hostname));
388 th = gethostbyname(hostname);
390 VLog(0, ("vlserver: couldn't get address of this host (%s).\n",
394 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
396 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
397 signal(SIGXCPU, CheckSignal_Signal);
399 /* get list of servers */
401 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
404 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
408 vldb_confdir = tdir; /* Preserve our configuration dir */
409 /* rxvab no longer supported */
410 memset(&tkey, 0, sizeof(tkey));
413 afsconf_SetNoAuthFlag(tdir, 1);
418 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
419 AFSDIR_SERVER_NETINFO_FILEPATH) {
421 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
422 ADDRSPERSITE, reason,
423 AFSDIR_SERVER_NETINFO_FILEPATH,
424 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
428 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
431 host = SHostAddrs[0];
432 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
439 if (rxMaxMTU != -1) {
440 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
441 VLog(0, ("rxMaxMTU %d invalid\n", rxMaxMTU));
447 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
448 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
449 afsconf_CheckAuth, tdir);
451 ubik_SyncWriterCacheProc = vlsynccache;
453 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
454 vl_dbaseName, &VL_dbase);
456 VLog(0, ("vlserver: Ubik init failed: %s\n", afs_error_message(code)));
459 rx_SetRxDeadTime(50);
461 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
462 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
465 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
468 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
469 securityClasses, numClasses,
471 if (tservice == (struct rx_service *)0) {
472 VLog(0, ("vlserver: Could not create VLDB_SERVICE rx service\n"));
475 rx_SetMinProcs(tservice, 2);
478 rx_SetMaxProcs(tservice, lwps);
480 if (rxkadDisableDotCheck) {
481 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
482 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
486 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
487 securityClasses, numClasses,
488 RXSTATS_ExecuteRequest);
489 if (tservice == (struct rx_service *)0) {
490 VLog(0, ("vlserver: Could not create rpc stats rx service\n"));
493 rx_SetMinProcs(tservice, 2);
494 rx_SetMaxProcs(tservice, 4);
496 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
497 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
500 VLog(0, ("%s\n", cml_version_number));
502 /* allow super users to manage RX statistics */
503 rx_SetRxStatUserOk(vldb_rxstat_userok);
505 rx_StartServer(1); /* Why waste this idle process?? */
507 return 0; /* not reachable */