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 = 0; /* default is to not send and receive jumbo grams */
69 int rxkadDisableDotCheck = 0;
72 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
73 afs_uint32 SHostAddrs[ADDRSPERSITE];
78 #if defined(AFS_PTHREAD_ENV)
81 IOMGR_SoftSig(CheckSignal, 0);
86 CheckSignal(void *unused)
88 register int i, errorcode;
89 struct ubik_trans *trans;
92 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
93 return (void *)errorcode;
94 VLog(0, ("Dump name hash table out\n"));
95 for (i = 0; i < HASHSIZE; i++) {
98 VLog(0, ("Dump id hash table out\n"));
99 for (i = 0; i < HASHSIZE; i++) {
100 HashIdDump(trans, i);
102 return ((void *)ubik_EndTrans(trans));
106 /* Initialize the stats for the opcodes */
112 dynamic_statistics.start_time = (afs_uint32) time(0);
113 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
114 dynamic_statistics.requests[i] = 0;
115 dynamic_statistics.aborts[i] = 0;
119 /* check whether caller is authorized to manage RX statistics */
121 vldb_rxstat_userok(call)
122 struct rx_call *call;
124 return afsconf_SuperUser(vldb_confdir, call, NULL);
127 /* Main server module */
129 #include "AFS_component_version_number.c"
135 register afs_int32 code;
137 struct rx_service *tservice;
138 struct rx_securityClass *sc[3];
139 extern int VL_ExecuteRequest();
140 extern int RXSTATS_ExecuteRequest();
141 struct afsconf_dir *tdir;
142 struct ktc_encryptionKey tkey;
143 struct afsconf_cell info;
145 char hostname[VL_MAXNAMELEN];
146 int noAuth = 0, index, i;
147 extern int rx_extraPackets;
148 char commandLine[150];
149 char clones[MAXHOSTSPERCELL];
150 afs_uint32 host = ntohl(INADDR_ANY);
154 * The following signal action for AIX is necessary so that in case of a
155 * crash (i.e. core is generated) we can include the user's data section
156 * in the core dump. Unfortunately, by default, only a partial core is
157 * generated which, in many cases, isn't too useful.
159 struct sigaction nsa;
161 rx_extraPackets = 100; /* should be a switch, I guess... */
162 sigemptyset(&nsa.sa_mask);
163 nsa.sa_handler = SIG_DFL;
164 nsa.sa_flags = SA_FULLDUMP;
165 sigaction(SIGABRT, &nsa, NULL);
166 sigaction(SIGSEGV, &nsa, NULL);
170 /* Parse command line */
171 for (index = 1; index < argc; index++) {
172 if (strcmp(argv[index], "-noauth") == 0) {
174 } else if (strcmp(argv[index], "-p") == 0) {
175 lwps = atoi(argv[++index]);
177 printf("Warning: '-p %d' is too big; using %d instead\n",
181 } else if (strcmp(argv[index], "-d") == 0) {
182 if ((index + 1) >= argc) {
183 fprintf(stderr, "missing argument for -d\n");
186 debuglevel = atoi(argv[++index]);
187 LogLevel = debuglevel;
188 } else if (strcmp(argv[index], "-nojumbo") == 0) {
190 } else if (strcmp(argv[index], "-jumbo") == 0) {
192 } else if (strcmp(argv[index], "-rxbind") == 0) {
194 } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
195 rxkadDisableDotCheck = 1;
196 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
197 if ((index + 1) >= argc) {
198 fprintf(stderr, "missing argument for -rxmaxmtu\n");
201 rxMaxMTU = atoi(argv[++i]);
202 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
203 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
204 printf("rxMaxMTU %d invalid; must be between %d-%d\n",
205 rxMaxMTU, RX_MIN_PACKET_SIZE,
206 RX_MAX_PACKET_DATA_SIZE);
210 } else if (strcmp(argv[index], "-smallmem") == 0) {
213 } else if (strcmp(argv[index], "-trace") == 0) {
214 extern char rxi_tracename[80];
215 strcpy(rxi_tracename, argv[++index]);
217 } else if (strcmp(argv[index], "-auditlog") == 0) {
220 char oldName[MAXPATHLEN];
221 char *fileName = argv[++index];
226 if ((lstat(fileName, &statbuf) == 0)
227 && (S_ISFIFO(statbuf.st_mode))) {
228 flags = O_WRONLY | O_NONBLOCK;
232 strcpy(oldName, fileName);
233 strcat(oldName, ".old");
234 renamefile(fileName, oldName);
235 flags = O_WRONLY | O_TRUNC | O_CREAT;
237 tempfd = open(fileName, flags, 0666);
239 auditout = fdopen(tempfd, "a");
241 osi_audit_file(auditout);
243 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
245 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
246 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
247 rx_enablePeerRPCStats();
248 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
249 rx_enableProcessRPCStats();
251 } else if (strcmp(argv[index], "-syslog") == 0) {
252 /* set syslog logging flag */
254 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
256 serverLogSyslogFacility = atoi(argv[index] + 8);
259 /* support help flag */
261 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
262 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
263 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
264 "[-syslog[=FACILITY]] "
265 "[-enable_peer_stats] [-enable_process_stats] "
268 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
269 "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
270 "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
271 "[-enable_peer_stats] [-enable_process_stats] "
279 /* Initialize dirpaths */
280 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
282 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
284 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
288 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
291 serverLogSyslogTag = "vlserver";
293 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
296 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
299 ("vlserver: can't open configuration files in dir %s, giving up.\n",
300 AFSDIR_SERVER_ETC_DIRPATH);
304 /* initialize winsock */
305 if (afs_winsockInit() < 0) {
306 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
307 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
312 gethostname(hostname, sizeof(hostname));
313 th = gethostbyname(hostname);
315 printf("vlserver: couldn't get address of this host (%s).\n",
319 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
321 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
322 signal(SIGXCPU, CheckSignal_Signal);
324 /* get list of servers */
326 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
329 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
333 vldb_confdir = tdir; /* Preserve our configuration dir */
334 /* rxvab no longer supported */
335 memset(&tkey, 0, sizeof(tkey));
338 afsconf_SetNoAuthFlag(tdir, 1);
343 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
344 AFSDIR_SERVER_NETINFO_FILEPATH) {
346 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
347 ADDRSPERSITE, reason,
348 AFSDIR_SERVER_NETINFO_FILEPATH,
349 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
353 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
356 host = SHostAddrs[0];
357 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
362 ubik_CRXSecurityProc = afsconf_ClientAuth;
363 ubik_CRXSecurityRock = (char *)tdir;
364 ubik_SRXSecurityProc = afsconf_ServerAuth;
365 ubik_SRXSecurityRock = (char *)tdir;
366 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
367 ubik_CheckRXSecurityRock = (char *)tdir;
369 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
370 vl_dbaseName, &VL_dbase);
372 printf("vlserver: Ubik init failed with code %d\n", code);
378 if (rxMaxMTU != -1) {
379 rx_SetMaxMTU(rxMaxMTU);
381 rx_SetRxDeadTime(50);
383 memset(HostAddress, 0, sizeof(HostAddress));
386 sc[0] = rxnull_NewServerSecurityObject();
387 sc[1] = (struct rx_securityClass *)0;
388 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
391 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
393 if (tservice == (struct rx_service *)0) {
394 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
397 rx_SetMinProcs(tservice, 2);
400 rx_SetMaxProcs(tservice, lwps);
402 if (rxkadDisableDotCheck) {
403 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
404 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
408 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
409 RXSTATS_ExecuteRequest);
410 if (tservice == (struct rx_service *)0) {
411 printf("vlserver: Could not create rpc stats rx service\n");
414 rx_SetMinProcs(tservice, 2);
415 rx_SetMaxProcs(tservice, 4);
417 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
419 strcat(commandLine, " ");
420 strcat(commandLine, argv[i]);
423 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
424 printf("%s\n", cml_version_number); /* Goes to the log */
426 /* allow super users to manage RX statistics */
427 rx_SetRxStatUserOk(vldb_rxstat_userok);
429 rx_StartServer(1); /* Why waste this idle process?? */
431 return 0; /* not reachable */