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 <sys/types.h>
26 #include <WINNT/afsevent.h>
28 #ifdef HAVE_SYS_FILE_H
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
42 #include <rx/rx_globals.h>
43 #include <afs/cellconfig.h>
48 #include <afs/afsutil.h>
53 const char *vl_dbaseName;
54 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
57 struct vldstats dynamic_statistics;
58 struct ubik_dbase *VL_dbase;
59 afs_uint32 HostAddress[MAXSERVERID + 1];
60 extern int afsconf_CheckAuth();
61 extern int afsconf_ServerAuth();
63 static void *CheckSignal(void*);
66 int rxJumbograms = 1; /* default is to send and receive jumbo grams */
69 int rxkadDisableDotCheck = 0;
71 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
72 afs_uint32 SHostAddrs[ADDRSPERSITE];
77 IOMGR_SoftSig(CheckSignal, 0);
81 CheckSignal(void *unused)
83 register int i, errorcode;
84 struct ubik_trans *trans;
87 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
89 VLog(0, ("Dump name hash table out\n"));
90 for (i = 0; i < HASHSIZE; i++) {
93 VLog(0, ("Dump id hash table out\n"));
94 for (i = 0; i < HASHSIZE; i++) {
97 return ((void *)ubik_EndTrans(trans));
101 /* Initialize the stats for the opcodes */
107 dynamic_statistics.start_time = (afs_uint32) time(0);
108 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
109 dynamic_statistics.requests[i] = 0;
110 dynamic_statistics.aborts[i] = 0;
114 /* check whether caller is authorized to manage RX statistics */
116 vldb_rxstat_userok(call)
117 struct rx_call *call;
119 return afsconf_SuperUser(vldb_confdir, call, NULL);
122 /* Main server module */
124 #include "AFS_component_version_number.c"
130 register afs_int32 code;
132 struct rx_service *tservice;
133 struct rx_securityClass *sc[3];
134 extern int VL_ExecuteRequest();
135 extern int RXSTATS_ExecuteRequest();
136 struct afsconf_dir *tdir;
137 struct ktc_encryptionKey tkey;
138 struct afsconf_cell info;
140 char hostname[VL_MAXNAMELEN];
141 int noAuth = 0, index, i;
142 extern int rx_extraPackets;
143 char commandLine[150];
144 char clones[MAXHOSTSPERCELL];
145 afs_uint32 host = ntohl(INADDR_ANY);
149 * The following signal action for AIX is necessary so that in case of a
150 * crash (i.e. core is generated) we can include the user's data section
151 * in the core dump. Unfortunately, by default, only a partial core is
152 * generated which, in many cases, isn't too useful.
154 struct sigaction nsa;
156 rx_extraPackets = 100; /* should be a switch, I guess... */
157 sigemptyset(&nsa.sa_mask);
158 nsa.sa_handler = SIG_DFL;
159 nsa.sa_flags = SA_FULLDUMP;
160 sigaction(SIGABRT, &nsa, NULL);
161 sigaction(SIGSEGV, &nsa, NULL);
165 /* Parse command line */
166 for (index = 1; index < argc; index++) {
167 if (strcmp(argv[index], "-noauth") == 0) {
170 } else if (strcmp(argv[index], "-p") == 0) {
171 lwps = atoi(argv[++index]);
173 printf("Warning: '-p %d' is too big; using %d instead\n",
178 } else if (strcmp(argv[index], "-nojumbo") == 0) {
181 } else if (strcmp(argv[index], "-rxbind") == 0) {
183 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
184 rxkadDisableDotCheck = 1;
185 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
186 if ((index + 1) >= argc) {
187 fprintf(stderr, "missing argument for -rxmaxmtu\n");
190 rxMaxMTU = atoi(argv[++i]);
191 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
192 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
193 printf("rxMaxMTU %d invalid; must be between %d-%d\n",
194 rxMaxMTU, RX_MIN_PACKET_SIZE,
195 RX_MAX_PACKET_DATA_SIZE);
199 } else if (strcmp(argv[index], "-smallmem") == 0) {
202 } else if (strcmp(argv[index], "-trace") == 0) {
203 extern char rxi_tracename[80];
204 strcpy(rxi_tracename, argv[++index]);
206 } else if (strcmp(argv[index], "-auditlog") == 0) {
209 char oldName[MAXPATHLEN];
210 char *fileName = argv[++index];
215 if ((lstat(fileName, &statbuf) == 0)
216 && (S_ISFIFO(statbuf.st_mode))) {
217 flags = O_WRONLY | O_NONBLOCK;
221 strcpy(oldName, fileName);
222 strcat(oldName, ".old");
223 renamefile(fileName, oldName);
224 flags = O_WRONLY | O_TRUNC | O_CREAT;
226 tempfd = open(fileName, flags, 0666);
228 auditout = fdopen(tempfd, "a");
230 osi_audit_file(auditout);
232 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
234 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
235 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
236 rx_enablePeerRPCStats();
237 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
238 rx_enableProcessRPCStats();
240 } else if (strcmp(argv[index], "-syslog") == 0) {
241 /* set syslog logging flag */
243 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
245 serverLogSyslogFacility = atoi(argv[index] + 8);
248 /* support help flag */
250 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
251 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
252 "[-auditlog <log path>] "
253 "[-syslog[=FACILITY]] "
254 "[-enable_peer_stats] [-enable_process_stats] "
257 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
258 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
259 "[-auditlog <log path>] "
260 "[-enable_peer_stats] [-enable_process_stats] "
268 /* Initialize dirpaths */
269 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
271 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
273 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
277 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
280 serverLogSyslogTag = "vlserver";
282 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
285 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
288 ("vlserver: can't open configuration files in dir %s, giving up.\n",
289 AFSDIR_SERVER_ETC_DIRPATH);
293 /* initialize winsock */
294 if (afs_winsockInit() < 0) {
295 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
296 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
301 gethostname(hostname, sizeof(hostname));
302 th = gethostbyname(hostname);
304 printf("vlserver: couldn't get address of this host (%s).\n",
308 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
310 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
311 signal(SIGXCPU, CheckSignal_Signal);
313 /* get list of servers */
315 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
318 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
322 vldb_confdir = tdir; /* Preserve our configuration dir */
323 /* rxvab no longer supported */
324 memset(&tkey, 0, sizeof(tkey));
327 afsconf_SetNoAuthFlag(tdir, 1);
332 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
333 AFSDIR_SERVER_NETINFO_FILEPATH) {
335 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
336 ADDRSPERSITE, reason,
337 AFSDIR_SERVER_NETINFO_FILEPATH,
338 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
342 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
345 host = SHostAddrs[0];
346 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
351 ubik_CRXSecurityProc = afsconf_ClientAuth;
352 ubik_CRXSecurityRock = (char *)tdir;
353 ubik_SRXSecurityProc = afsconf_ServerAuth;
354 ubik_SRXSecurityRock = (char *)tdir;
355 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
356 ubik_CheckRXSecurityRock = (char *)tdir;
358 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
359 vl_dbaseName, &VL_dbase);
361 printf("vlserver: Ubik init failed with code %d\n", code);
367 if (rxMaxMTU != -1) {
368 rx_SetMaxMTU(rxMaxMTU);
370 rx_SetRxDeadTime(50);
372 memset(HostAddress, 0, sizeof(HostAddress));
375 sc[0] = rxnull_NewServerSecurityObject();
376 sc[1] = (struct rx_securityClass *)0;
377 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
380 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
382 if (tservice == (struct rx_service *)0) {
383 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
386 rx_SetMinProcs(tservice, 2);
389 rx_SetMaxProcs(tservice, lwps);
391 if (rxkadDisableDotCheck) {
392 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
393 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK,
398 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
399 RXSTATS_ExecuteRequest);
400 if (tservice == (struct rx_service *)0) {
401 printf("vlserver: Could not create rpc stats rx service\n");
404 rx_SetMinProcs(tservice, 2);
405 rx_SetMaxProcs(tservice, 4);
407 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
409 strcat(commandLine, " ");
410 strcat(commandLine, argv[i]);
413 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
414 printf("%s\n", cml_version_number); /* Goes to the log */
416 /* allow super users to manage RX statistics */
417 rx_SetRxStatUserOk(vldb_rxstat_userok);
419 rx_StartServer(1); /* Why waste this idle process?? */
421 return 0; /* not reachable */