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 rxJumbograms = 0; /* default is to not send and receive jumbo grams */
56 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);
113 * Return true if this name is a member of the local realm.
116 vldb_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
118 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
119 afs_int32 islocal = 0; /* default to no */
122 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
125 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
126 code, name, inst, cell));
131 /* Main server module */
133 #include "AFS_component_version_number.c"
157 main(int argc, char **argv)
161 struct rx_service *tservice;
162 struct rx_securityClass **securityClasses;
163 afs_int32 numClasses;
164 struct afsconf_dir *tdir;
165 struct ktc_encryptionKey tkey;
166 struct afsconf_cell info;
168 char hostname[VL_MAXNAMELEN];
170 char clones[MAXHOSTSPERCELL];
171 afs_uint32 host = ntohl(INADDR_ANY);
172 struct cmd_syndesc *opts;
178 char *auditFileName = NULL;
179 char *interface = NULL;
180 char *optstring = NULL;
184 * The following signal action for AIX is necessary so that in case of a
185 * crash (i.e. core is generated) we can include the user's data section
186 * in the core dump. Unfortunately, by default, only a partial core is
187 * generated which, in many cases, isn't too useful.
189 struct sigaction nsa;
191 rx_extraPackets = 100; /* should be a switch, I guess... */
192 sigemptyset(&nsa.sa_mask);
193 nsa.sa_handler = SIG_DFL;
194 nsa.sa_flags = SA_FULLDUMP;
195 sigaction(SIGABRT, &nsa, NULL);
196 sigaction(SIGSEGV, &nsa, NULL);
200 /* Initialize dirpaths */
201 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
203 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
205 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
210 vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
211 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
212 logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH);
214 cmd_DisableAbbreviations();
215 cmd_DisablePositionalCommands();
216 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
218 /* vlserver specific options */
219 cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG,
220 CMD_OPTIONAL, "disable authentication");
221 cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG,
222 CMD_OPTIONAL, "optimise for small memory systems");
224 /* general server options */
225 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
226 CMD_OPTIONAL, "location of audit log");
227 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
228 CMD_OPTIONAL, "interface to use for audit logging");
229 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
230 CMD_OPTIONAL, "configuration location");
231 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE,
232 CMD_OPTIONAL, "debug level");
233 cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE,
234 CMD_OPTIONAL, "database file");
235 cmd_AddParmAlias(opts, OPT_database, "-db");
236 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
237 CMD_OPTIONAL, "location of logfile");
238 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
239 "number of threads");
240 #if !defined(AFS_NT40_ENV)
241 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
242 CMD_OPTIONAL, "log to syslog");
246 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
247 CMD_OPTIONAL, "enable RX transport statistics");
248 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
249 CMD_OPTIONAL, "enable RX RPC statistics");
250 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
251 CMD_OPTIONAL, "disable jumbograms");
252 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG,
253 CMD_OPTIONAL, "enable jumbograms");
254 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG,
255 CMD_OPTIONAL, "bind only to the primary interface");
256 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
257 CMD_OPTIONAL, "maximum MTU for RX");
258 cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE,
259 CMD_OPTIONAL, "rx trace file");
262 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
263 CMD_FLAG, CMD_OPTIONAL,
264 "permit Kerberos 5 principals with dots");
266 code = cmd_Parse(argc, argv, &opts);
270 /* vlserver options */
271 cmd_OptionAsFlag(opts, OPT_noauth, &noAuth);
272 cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem);
273 if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) {
274 extern char rxi_tracename[80];
275 strcpy(rxi_tracename, optstring);
280 /* general server options */
282 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
284 if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) {
285 if (osi_audit_interface(interface)) {
286 printf("Invalid audit interface '%s'\n", interface);
292 cmd_OptionAsString(opts, OPT_config, &configDir);
293 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
294 cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
295 cmd_OptionAsString(opts, OPT_logfile, &logFile);
297 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
299 printf("Warning: '-p %d' is too big; using %d instead\n",
305 if (cmd_OptionPresent(opts, OPT_syslog)) {
307 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
312 if (cmd_OptionPresent(opts, OPT_peer))
313 rx_enablePeerRPCStats();
314 if (cmd_OptionPresent(opts, OPT_process))
315 rx_enableProcessRPCStats();
316 if (cmd_OptionPresent(opts, OPT_nojumbo))
318 if (cmd_OptionPresent(opts, OPT_jumbo))
321 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
323 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
326 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
329 osi_audit_file(auditFileName);
333 serverLogSyslogTag = "vlserver";
335 OpenLog(logFile); /* set up logging */
338 tdir = afsconf_Open(configDir);
341 ("vlserver: can't open configuration files in dir %s, giving up.\n",
346 /* initialize audit user check */
347 osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch);
350 /* initialize winsock */
351 if (afs_winsockInit() < 0) {
352 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
353 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
358 gethostname(hostname, sizeof(hostname));
359 th = gethostbyname(hostname);
361 printf("vlserver: couldn't get address of this host (%s).\n",
365 memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
367 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
368 signal(SIGXCPU, CheckSignal_Signal);
370 /* get list of servers */
372 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
375 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
379 vldb_confdir = tdir; /* Preserve our configuration dir */
380 /* rxvab no longer supported */
381 memset(&tkey, 0, sizeof(tkey));
384 afsconf_SetNoAuthFlag(tdir, 1);
389 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
390 AFSDIR_SERVER_NETINFO_FILEPATH) {
392 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
393 ADDRSPERSITE, reason,
394 AFSDIR_SERVER_NETINFO_FILEPATH,
395 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
399 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
402 host = SHostAddrs[0];
403 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
410 if (rxMaxMTU != -1) {
411 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
412 printf("rxMaxMTU %d invalid\n", rxMaxMTU);
418 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
419 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
420 afsconf_CheckAuth, tdir);
422 ubik_SyncWriterCacheProc = vlsynccache;
424 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
425 vl_dbaseName, &VL_dbase);
427 printf("vlserver: Ubik init failed: %s\n", afs_error_message(code));
430 rx_SetRxDeadTime(50);
432 memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
433 memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
436 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
439 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
440 securityClasses, numClasses,
442 if (tservice == (struct rx_service *)0) {
443 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
446 rx_SetMinProcs(tservice, 2);
449 rx_SetMaxProcs(tservice, lwps);
451 if (rxkadDisableDotCheck) {
452 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
453 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
457 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
458 securityClasses, numClasses,
459 RXSTATS_ExecuteRequest);
460 if (tservice == (struct rx_service *)0) {
461 printf("vlserver: Could not create rpc stats rx service\n");
464 rx_SetMinProcs(tservice, 2);
465 rx_SetMaxProcs(tservice, 4);
467 LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
468 printf("%s\n", cml_version_number); /* Goes to the log */
470 /* allow super users to manage RX statistics */
471 rx_SetRxStatUserOk(vldb_rxstat_userok);
473 rx_StartServer(1); /* Why waste this idle process?? */
475 return 0; /* not reachable */