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>
19 #include <WINNT/afsevent.h>
21 #include <netinet/in.h>
36 #include <sys/types.h>
45 #include <rx/rx_globals.h>
46 #include <afs/cellconfig.h>
48 #include <afs/bubasics.h>
49 #include <afs/afsutil.h>
50 #include <afs/com_err.h>
55 #include "budb_errs.h"
57 #include "error_macros.h"
59 #include "afs/audit.h"
61 struct ubik_dbase *BU_dbase;
62 struct afsconf_dir *BU_conf; /* for getting cell info */
64 char lcell[MAXKTCREALMLEN];
68 /* server's global configuration information. This is exported to other
72 buServerConfT globalConf;
73 buServerConfP globalConfPtr = &globalConf;
74 char dbDir[AFSDIR_PATH_MAX], cellConfDir[AFSDIR_PATH_MAX];
75 /* debugging control */
78 /* check whether caller is authorized to manage RX statistics */
80 BU_rxstat_userok(call)
83 return afsconf_SuperUser(BU_conf, call, NULL);
87 convert_cell_to_ubik(cellinfo, myHost, serverList)
88 struct afsconf_cell *cellinfo;
90 afs_int32 *serverList;
97 gethostname(hostname, sizeof(hostname));
98 th = gethostbyname(hostname);
100 printf("prserver: couldn't get address of this host.\n");
103 memcpy(myHost, th->h_addr, sizeof(afs_int32));
105 for (i = 0; i < cellinfo->numServers; i++)
106 /* omit my host from serverList */
107 if (cellinfo->hostAddr[i].sin_addr.s_addr != *myHost)
108 *serverList++ = cellinfo->hostAddr[i].sin_addr.s_addr;
110 *serverList = 0; /* terminate list */
115 * The whole purpose of MyBeforeProc is to detect
116 * if the -help option was not within the command line.
117 * If it were, this routine would never have been called.
121 register struct cmd_syndesc *as;
127 /* initializeCommands
128 * initialize all the supported commands and their arguments
131 initializeArgHandler()
133 struct cmd_syndesc *cptr;
137 cmd_SetBeforeProc(MyBeforeProc, NULL);
139 cptr = cmd_CreateSyntax(NULL, argHandler, NULL, "Backup database server");
141 cmd_AddParm(cptr, "-database", CMD_SINGLE, CMD_OPTIONAL,
142 "database directory");
144 cmd_AddParm(cptr, "-cellservdb", CMD_SINGLE, CMD_OPTIONAL,
145 "cell configuration directory");
147 cmd_AddParm(cptr, "-resetdb", CMD_FLAG, CMD_OPTIONAL,
148 "truncate the database");
150 cmd_AddParm(cptr, "-noauth", CMD_FLAG, CMD_OPTIONAL,
151 "run without authentication");
153 cmd_AddParm(cptr, "-smallht", CMD_FLAG, CMD_OPTIONAL,
154 "use small hash tables");
156 cmd_AddParm(cptr, "-servers", CMD_LIST, CMD_OPTIONAL,
157 "list of ubik database servers");
159 cmd_AddParm(cptr, "-ubikbuffers", CMD_SINGLE, CMD_OPTIONAL,
160 "the number of ubik buffers");
165 argHandler(as, arock)
166 struct cmd_syndesc *as;
170 /* globalConfPtr provides the handle for the configuration information */
172 /* database directory */
173 if (as->parms[0].items != 0) {
174 globalConfPtr->databaseDirectory =
175 (char *)malloc(strlen(as->parms[0].items->data) + 1);
176 if (globalConfPtr->databaseDirectory == 0)
178 strcpy(globalConfPtr->databaseDirectory, as->parms[0].items->data);
181 /* -cellservdb, cell configuration directory */
182 if (as->parms[1].items != 0) {
183 globalConfPtr->cellConfigdir =
184 (char *)malloc(strlen(as->parms[1].items->data) + 1);
185 if (globalConfPtr->cellConfigdir == 0)
188 strcpy(globalConfPtr->cellConfigdir, as->parms[1].items->data);
190 globalConfPtr->debugFlags |= DF_RECHECKNOAUTH;
193 /* truncate the database */
194 if (as->parms[2].items != 0)
197 /* run without authentication */
198 if (as->parms[3].items != 0)
199 globalConfPtr->debugFlags |= DF_NOAUTH;
201 /* use small hash tables */
202 if (as->parms[4].items != 0)
203 globalConfPtr->debugFlags |= DF_SMALLHT;
205 /* user provided list of ubik database servers */
206 if (as->parms[5].items != 0)
207 parseServerList(as->parms[5].items);
209 /* user provided the number of ubik buffers */
210 if (as->parms[6].items != 0)
211 ubik_nBuffers = atoi(as->parms[6].items->data);
220 parseServerList(itemPtr)
221 struct cmd_item *itemPtr;
223 struct cmd_item *save;
226 afs_int32 nservers = 0;
231 /* compute number of servers in the list */
234 itemPtr = itemPtr->next;
237 LogDebug(3, "%d servers\n", nservers);
239 /* now can allocate the space for the server arguments */
240 serverArgs = (char **)malloc((nservers + 2) * sizeof(char *));
248 /* now go through and construct the list of servers */
251 *ptr++ = itemPtr->data;
252 itemPtr = itemPtr->next;
256 ubik_ParseServerList(nservers + 2, serverArgs, &globalConfPtr->myHost,
257 globalConfPtr->serverList);
261 /* free space for the server args */
262 free((char *)serverArgs);
269 * truncates just the database file.
279 (char *)malloc(strlen(globalConfPtr->databaseDirectory) +
280 strlen(globalConfPtr->databaseName) +
281 strlen(globalConfPtr->databaseExtension) + 1);
285 /* construct the database name */
286 strcpy(path, globalConfPtr->databaseDirectory);
287 strcat(path, globalConfPtr->databaseName);
288 strcat(path, globalConfPtr->databaseExtension);
290 fd = open(path, O_RDWR, 0755);
294 if (ftruncate(fd, 0) != 0) {
307 #include "AFS_component_version_number.c"
313 char *whoami = argv[0];
315 struct afsconf_cell cellinfo;
319 struct rx_service *tservice;
320 struct rx_securityClass *sca[3];
322 extern int afsconf_ServerAuth();
323 extern int afsconf_CheckAuth();
325 extern int rx_stackSize;
326 extern int BUDB_ExecuteRequest();
329 /* initialize winsock */
330 if (afs_winsockInit() < 0) {
331 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
332 fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami);
339 * The following signal action for AIX is necessary so that in case of a
340 * crash (i.e. core is generated) we can include the user's data section
341 * in the core dump. Unfortunately, by default, only a partial core is
342 * generated which, in many cases, isn't too useful.
344 struct sigaction nsa;
346 sigemptyset(&nsa.sa_mask);
347 nsa.sa_handler = SIG_DFL;
348 nsa.sa_flags = SA_FULLDUMP;
349 sigaction(SIGSEGV, &nsa, NULL);
350 sigaction(SIGABRT, &nsa, NULL);
352 osi_audit(BUDB_StartEvent, 0, AUD_END);
354 initialize_BUDB_error_table();
355 initializeArgHandler();
357 /* Initialize dirpaths */
358 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
360 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
362 com_err(whoami, errno, "; Unable to obtain AFS server directory.");
366 memset(globalConfPtr, 0, sizeof(*globalConfPtr));
368 /* set default configuration values */
369 strcpy(dbDir, AFSDIR_SERVER_DB_DIRPATH);
371 globalConfPtr->databaseDirectory = dbDir;
372 globalConfPtr->databaseName = DEFAULT_DBPREFIX;
373 strcpy(cellConfDir, AFSDIR_SERVER_ETC_DIRPATH);
374 globalConfPtr->cellConfigdir = cellConfDir;
376 /* open the log file */
378 globalConfPtr->log = fopen(DEFAULT_LOGNAME,"a");
379 if ( globalConfPtr->log == NULL )
381 printf("Can't open log file %s - aborting\n", DEFAULT_LOGNAME);
388 /* process the user supplied args */
390 code = cmd_Dispatch(argc, argv);
394 /* exit if there was a help option */
398 /* open the log file */
399 globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
400 if (globalConfPtr->log == NULL) {
401 printf("Can't open log file %s - aborting\n",
402 AFSDIR_SERVER_BUDBLOG_FILEPATH);
406 /* keep log closed so can remove it */
408 fclose(globalConfPtr->log);
410 /* open the cell's configuration directory */
411 LogDebug(4, "opening %s\n", globalConfPtr->cellConfigdir);
413 BU_conf = afsconf_Open(globalConfPtr->cellConfigdir);
415 LogError(code, "Failed getting cell info\n");
416 com_err(whoami, code, "Failed getting cell info");
420 code = afsconf_GetLocalCell(BU_conf, lcell, sizeof(lcell));
422 LogError(0, "** Can't determine local cell name!\n");
426 if (globalConfPtr->myHost == 0) {
427 /* if user hasn't supplied a list of servers, extract server
428 * list from the cell's database
431 LogDebug(1, "Using server list from %s cell database.\n", lcell);
433 code = afsconf_GetCellInfo(BU_conf, lcell, 0, &cellinfo);
435 convert_cell_to_ubik(&cellinfo, &globalConfPtr->myHost,
436 globalConfPtr->serverList);
441 /* initialize ubik */
442 ubik_CRXSecurityProc = afsconf_ClientAuth;
443 ubik_CRXSecurityRock = (char *)BU_conf;
445 ubik_SRXSecurityProc = afsconf_ServerAuth;
446 ubik_SRXSecurityRock = (char *)BU_conf;
448 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
449 ubik_CheckRXSecurityRock = (char *)BU_conf;
451 if (ubik_nBuffers == 0)
454 LogError(0, "Will allocate %d ubik buffers\n", ubik_nBuffers);
457 (char *)malloc(strlen(globalConfPtr->databaseDirectory) +
458 strlen(globalConfPtr->databaseName) + 1);
462 /* construct the database name */
463 strcpy(dbNamePtr, globalConfPtr->databaseDirectory);
464 strcat(dbNamePtr, globalConfPtr->databaseName); /* name prefix */
466 rx_SetRxDeadTime(60); /* 60 seconds inactive before timeout */
468 code = ubik_ServerInit(globalConfPtr->myHost, htons(AFSCONF_BUDBPORT), globalConfPtr->serverList, dbNamePtr, /* name prefix */
471 LogError(code, "Ubik init failed\n");
472 com_err(whoami, code, "Ubik init failed");
476 sca[RX_SCINDEX_NULL] = rxnull_NewServerSecurityObject();
477 sca[RX_SCINDEX_VAB] = 0;
478 sca[RX_SCINDEX_KAD] =
479 rxkad_NewServerSecurityObject(rxkad_clear, BU_conf, afsconf_GetKey,
482 /* Disable jumbograms */
486 rx_NewService(0, BUDB_SERVICE, "BackupDatabase", sca, 3,
487 BUDB_ExecuteRequest);
488 if (tservice == (struct rx_service *)0) {
489 LogError(0, "Could not create backup database rx service\n");
490 printf("Could not create backup database rx service\n");
493 rx_SetMinProcs(tservice, 1);
494 rx_SetMaxProcs(tservice, 3);
495 rx_SetStackSize(tservice, 10000);
497 /* allow super users to manage RX statistics */
498 rx_SetRxStatUserOk(BU_rxstat_userok);
500 /* misc. initialization */
502 /* database dump synchronization */
503 memset(dumpSyncPtr, 0, sizeof(*dumpSyncPtr));
504 Lock_Init(&dumpSyncPtr->ds_lock);
506 rx_StartServer(0); /* start handling requests */
513 currentTime = time(0);
514 LogError(0, "Ready to process requests at %s\n", ctime(¤tTime));
516 rx_ServerProc(); /* donate this LWP */
519 osi_audit(BUDB_FinishEvent, code, AUD_END);
526 /* do consistency checks on structure sizes */
527 if ((sizeof(struct htBlock) > BLOCKSIZE)
528 || (sizeof(struct vfBlock) > BLOCKSIZE)
529 || (sizeof(struct viBlock) > BLOCKSIZE)
530 || (sizeof(struct dBlock) > BLOCKSIZE)
531 || (sizeof(struct tBlock) > BLOCKSIZE)
533 fprintf(stderr, "Block layout error!\n");
539 LogDebug(level, a, b, c, d, e, f, g, h, i)
541 char *a, *b, *c, *d, *e, *f, *g, *h, *i;
544 if (debugging >= level) {
545 /* log normally closed so can remove it */
546 globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
547 if (globalConfPtr->log != NULL) {
548 fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
549 fflush(globalConfPtr->log);
550 fclose(globalConfPtr->log);
559 static char timestamp[20];
562 strftime(timestamp, 20, "%m/%d/%Y %T", lt);
567 Log(a, b, c, d, e, f, g, h, i)
568 char *a, *b, *c, *d, *e, *f, *g, *h, *i;
572 globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
573 if (globalConfPtr->log != NULL) {
575 fprintf(globalConfPtr->log, "%s ", TimeStamp(now));
577 fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
578 fflush(globalConfPtr->log);
579 fclose(globalConfPtr->log);
584 LogError(code, a, b, c, d, e, f, g, h, i)
586 char *a, *b, *c, *d, *e, *f, *g, *h, *i;
590 globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
592 if (globalConfPtr->log != NULL) {
594 fprintf(globalConfPtr->log, "%s ", TimeStamp(now));
597 fprintf(globalConfPtr->log, "%s: %s\n", error_table_name(code),
598 error_message(code));
599 fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
600 fflush(globalConfPtr->log);
601 fclose(globalConfPtr->log);
613 struct dump *dumpPtr;
615 struct dump hostDump;
616 extern buServerConfP globalConfPtr;
618 dump_ntoh(dumpPtr, &hostDump);
620 globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
621 if (globalConfPtr->log != NULL) {
622 printDump(globalConfPtr->log, &hostDump);
623 fclose(globalConfPtr->log);