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>
13 #include <afs/procmgmt.h>
18 #ifdef IGNORE_SOME_GCC_WARNINGS
19 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
23 #include <WINNT/afsevent.h>
29 #include <rx/rx_globals.h>
33 #include <afs/afsint.h>
34 #include <afs/prs_fs.h>
36 #include <afs/vlserver.h>
39 #include <afs/afsutil.h>
40 #include <afs/cellconfig.h>
42 #include <afs/volser.h>
44 #include <afs/audit.h>
45 #include <afs/com_err.h>
47 #include <afs/tcdata.h>
48 #include <afs/bubasics.h>
49 #include <afs/budb_errs.h>
50 #include <afs/budb_client.h>
51 #include <afs/bucoord_prototypes.h>
53 #include <afs/kautils.h>
56 #include "error_macros.h"
58 #include "butc_xbsa.h"
59 #include "butc_prototypes.h"
60 #include "butc_internal.h"
62 #define N_SECURITY_OBJECTS 3
63 #define ERRCODE_RANGE 8 /* from error_table.h */
65 #define TE_PREFIX "TE"
66 #define TL_PREFIX "TL"
67 #define CFG_PREFIX "CFG"
69 struct ubik_client *cstruct;
70 FILE *logIO, *ErrorlogIO, *centralLogIO, *lastLogIO;
71 char lFile[AFSDIR_PATH_MAX];
73 char ErrorlogFile[256];
74 char lastLogFile[256];
75 char eFile[AFSDIR_PATH_MAX];
76 char tapeConfigFile[AFSDIR_PATH_MAX];
77 char pFile[AFSDIR_PATH_MAX];
79 struct tapeConfig globalTapeConfig;
80 struct deviceSyncNode *deviceLatch;
81 char globalCellName[64];
82 char *whoami = "butc";
84 /* GLOBAL CONFIGURATION PARAMETERS */
100 #define MINGROUPID 0x1
101 #define MAXGROUPID 0x7FFFFFFF
102 afs_int32 statusSize;
104 #define MAXSTATUS 0x7fffffff
105 afs_int32 BufferSize; /* Size in B stored for data */
106 char *centralLogFile;
107 afs_int32 lastLog; /* Log last pass info */
109 struct afsconf_dir *butc_confdir;
111 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
112 afs_uint32 SHostAddrs[ADDRSPERSITE];
121 while ((tc = *anum)) {
122 if (tc < '0' || tc > '9')
132 * Convert a string into an afs_int32.
133 * Returned afs_int32 is in Bytes, Kb, Mb, Gb, or Tb. Based on crunit char.
134 * This routine only converts unsigned float values.
135 * The returned value is a whole number.
137 * numstring - text string to be converted.
138 * crunit - value returned in 'B', 'K', 'M', 'G', 'T'.
139 * ' ' or NULL ==> 'B' (bytes).
141 * number - returned value in requested crunit - rounded
142 * to nearest whole number.
145 * -1 - error in conversion
147 * should deal with signed numbers. Should signal error if no digits
151 atocl(char *numstring, char crunit, afs_int32 *number)
160 /* Determine which units to report in */
194 sscanf(numstring, "%f%c%s", &total, &cunit, rest);
195 if ((count > 2) || (count <= 0))
198 cunit = 'B'; /* bytes */
232 /* Go to correct unit */
233 for (; units < runits; units += 3)
235 for (; units > runits; units -= 3)
238 total += 0.5; /* Round up */
239 if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */
246 /* replace last two ocurrences of / by _ */
249 stringReplace(char *name)
254 pos = strrchr(name, '/');
257 pos = strrchr(name, '/');
259 strcat(name, buffer);
265 stringNowReplace(char *logFile, char *deviceName)
268 char storeDevice[256];
269 int mvFlag = 0, devPrefLen;
271 char devPrefix[] = "\\\\.";
273 char devPrefix[] = "/dev";
276 devPrefLen = strlen(devPrefix);
277 strcpy(storeDevice, deviceName);
278 if (strncmp(deviceName, devPrefix, devPrefLen) == 0) {
279 deviceName += devPrefLen;
282 while ((pos = strchr(deviceName, devPrefix[0]))) /* look for / or \ */
284 strcat(logFile, deviceName);
285 /* now put back deviceName to the way it was */
287 deviceName -= devPrefLen;
289 strcpy(deviceName, storeDevice);
296 * get the configuration information for a particular tape device
297 * as specified by the portoffset
299 * filename - full pathname of file containing the tape device
300 * configuration information
301 * config - for return results
302 * portOffset - for which configuration is required
304 * logging not available when this routine is called
305 * caller return value checks
307 * 0 => Found entry with same port, return info in config.
308 * -1 => Error encountered trying to read the file.
309 * 1 => Desired entry does not exist or file does not exist.
314 GetDeviceConfig(char *filename, struct tapeConfig *config, afs_int32 portOffset)
318 char devName[LINESIZE], tcapacity[LINESIZE], tfmsize[LINESIZE],
323 afs_int32 code = 0, count;
325 /* Initialize the config struct */
326 config->capacity = 0;
327 config->fileMarkSize = 0;
328 config->portOffset = portOffset;
329 strcpy(config->device, "");
331 devFile = fopen(filename, "r");
335 fprintf(stderr, "Error %d: Can't open %s\n", errno, filename);
339 while (fgets(line, LINESIZE - 1, devFile)) {
341 sscanf(line, "%s %s %s %u%s\n", tcapacity, tfmsize, devName,
344 if (count == 4 || count == 5) {
345 if (atocl(tcapacity, 'K', &capacity)) {
347 "tapeconfig: Tape capacity parse error in: %s\n",
351 if (atocl(tfmsize, 'B', &fmSize)) {
353 "tapeconfig: File-mark size parse error in: %s\n",
358 count = sscanf(line, "%s %u%s\n", devName, &aport, trest);
359 if (count == 2 || count == 3) {
360 capacity = 0x7fffffff;
363 fprintf(stderr, "tapeconfig: Parse error in: %s\n", line);
368 if ((aport < 0) || (aport > BC_MAXPORTOFFSET)) {
369 fprintf(stderr, "tapeconfig: Port offset parse error in: %s\n",
374 if (aport != portOffset)
378 fprintf(stderr, "Invalid file mark size, %d, in: %s\n", fmSize,
383 config->capacity = capacity;
384 config->fileMarkSize = fmSize;
385 config->portOffset = aport;
386 strncpy(config->device, devName, 100);
391 /* fprintf(stderr, "Can't find tapeconfig entry for port offset %d\n", portOffset); */
403 GetConfigParams(char *filename, afs_int32 port)
407 char line[LINESIZE], cmd[LINESIZE], value[LINESIZE];
411 /* DEFAULT SETTINGS FOR GLOBAL PARAMETERS */
412 dump_namecheck = 1; /* check tape name on dumps */
413 queryoperator = 1; /* can question operator */
414 autoQuery = 1; /* prompt for first tape */
415 isafile = 0; /* Do not dump to a file */
416 opencallout = NULL; /* open callout routine */
417 closecallout = NULL; /* close callout routine */
418 tapemounted = 0; /* tape is not mounted */
420 BufferSize = (CONF_XBSA ? XBSADFLTBUFFER : BUTM_BLOCKSIZE);
421 dumpRestAuthnLevel = rpc_c_protect_level_default;
422 xbsaObjectOwner = NULL; /* bsaObjectOwner */
423 appObjectOwner = NULL; /* appObjectOwner */
424 adsmServerName = NULL; /* TSM server name - same as ADSM */
425 xbsaSecToken = NULL; /* XBSA sercurity token */
426 xbsalGName = NULL; /* XBSA IGName */
428 BufferSize = BUTM_BLOCKSIZE;
430 centralLogFile = NULL; /* Log for all butcs */
431 centralLogIO = 0; /* Log for all butcs */
432 statusSize = 0; /* size before status message */
433 maxpass = PASSESDFLT; /* dump passes */
434 lastLog = 0; /* separate log for last pass */
435 lastLogIO = 0; /* separate log for last pass */
436 groupId = 0; /* Group id for multiple dumps */
438 /* Try opening the CFG_<port> file */
439 sprintf(paramFile, "%s_%d", filename, port);
440 devFile = fopen(paramFile, "r");
442 /* Set log names to TL_<port>, TL_<port>.lp and TE_<port> */
443 sprintf(logFile, "%s_%d", lFile, port);
444 sprintf(lastLogFile, "%s_%d.lp", lFile, port);
445 sprintf(ErrorlogFile, "%s_%d", eFile, port);
446 } else if (CONF_XBSA) {
447 /* If configured as XBSA, a configuration file CFG_<port> must exist */
448 printf("Cannot open configuration file %s", paramFile);
451 /* Try the CFG_<device> name as the device file */
452 strcpy(paramFile, filename);
453 stringNowReplace(paramFile, globalTapeConfig.device);
454 /* Set log names to TL_<device>, TL_<device> and TE_<device> */
455 strcpy(logFile, lFile);
456 stringNowReplace(logFile, globalTapeConfig.device);
457 strcpy(lastLogFile, lFile);
458 stringNowReplace(lastLogFile, globalTapeConfig.device);
459 strcat(lastLogFile, ".lp");
460 strcpy(ErrorlogFile, eFile);
461 stringNowReplace(ErrorlogFile, globalTapeConfig.device);
463 /* Now open the device file */
464 devFile = fopen(paramFile, "r");
466 ERROR_EXIT(0); /* CFG file doesn't exist for non-XBSA and that's ok */
469 /* Read each line of the Configuration file */
470 while (fgets(line, LINESIZE - 1, devFile)) {
471 cnt = sscanf(line, "%s %s", cmd, value);
474 printf("Bad line in %s: %s\n", paramFile, line);
478 for (cnt = 0; cnt < strlen(cmd); cnt++)
479 if (islower(cmd[cnt]))
480 cmd[cnt] = toupper(cmd[cnt]);
482 if (!strcmp(cmd, "NAME_CHECK")) {
485 ("Warning: The %s parameter is ignored with a Backup Service\n",
490 for (cnt = 0; cnt < strlen(value); cnt++)
491 if (islower(value[cnt]))
492 value[cnt] = toupper(value[cnt]);
494 if (!strcmp(value, "NO")) {
495 printf("Dump tape name check is disabled\n");
498 printf("Dump tape name check is enabled\n");
503 else if (!strcmp(cmd, "MOUNT")) {
506 ("Warning: The %s parameter is ignored with a Backup Service\n",
511 opencallout = strdup(value);
512 printf("Tape mount callout routine is %s\n", opencallout);
515 else if (!strcmp(cmd, "UNMOUNT")) {
518 ("Warning: The %s parameter is ignored with a Backup Service\n",
523 closecallout = strdup(value);
524 printf("Tape unmount callout routine is %s\n", closecallout);
527 else if (!strcmp(cmd, "ASK")) {
528 for (cnt = 0; cnt < strlen(value); cnt++)
529 if (islower(value[cnt]))
530 value[cnt] = toupper(value[cnt]);
532 if (!strcmp(value, "NO")) {
533 printf("Operator queries are disabled\n");
536 printf("Operator queries are enabled\n");
541 else if (!strcmp(cmd, "FILE")) {
544 ("Warning: The %s parameter is ignored with a Backup Service\n",
549 for (cnt = 0; cnt < strlen(value); cnt++)
550 if (islower(value[cnt]))
551 value[cnt] = toupper(value[cnt]);
553 if (!strcmp(value, "YES")) {
554 printf("Will dump to a file\n");
557 printf("Will not dump to a file\n");
562 else if (!strcmp(cmd, "AUTOQUERY")) {
565 ("Warning: The %s parameter is ignored with a Backup Service\n",
570 for (cnt = 0; cnt < strlen(value); cnt++)
571 if (islower(value[cnt]))
572 value[cnt] = toupper(value[cnt]);
574 if (!strcmp(value, "NO")) {
575 printf("Auto query is disabled\n");
578 printf("Auto query is enabled\n");
583 else if (!strcmp(cmd, "BUFFERSIZE")) {
585 afs_int32 tapeblocks;
588 if (atocl(value, 'K', &size)) {
589 fprintf(stderr, "BUFFERSIZE parse error\n");
593 /* A tapeblock is 16KB. Determine # of tapeblocks. Then
594 * determine BufferSize needed for that many tapeblocks.
596 tapeblocks = size / 16;
599 printf("BUFFERSIZE is %u KBytes\n", (tapeblocks * 16));
600 BufferSize = tapeblocks * BUTM_BLOCKSIZE;
603 if (atocl(value, 'B', &size)) {
604 fprintf(stderr, "BUFFERSIZE parse error\n");
607 if (size < XBSAMINBUFFER)
608 size = XBSAMINBUFFER;
609 if (size > XBSAMAXBUFFER)
610 size = XBSAMAXBUFFER;
611 printf("XBSA buffer size is %u Bytes\n", size);
617 /* All the xbsa spacific parameters */
618 else if (!strcmp(cmd, "TYPE") || !strcmp(cmd, "NODE")
619 || !strcmp(cmd, "SERVER") || !strcmp(cmd, "PASSWORD")
620 || !strcmp(cmd, "PASSFILE") || !strcmp(cmd, "MGMTCLASS")) {
621 printf("This binary does not have XBSA support\n");
625 else if (!strcmp(cmd, "TYPE")) { /* required for XBSA */
628 ("Warning: The %s parameter is ignored with a tape drive\n",
633 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
634 if (islower(value[cnt]))
635 value[cnt] = toupper(value[cnt]);
637 if (strcmp(value, "TSM") == 0) {
638 xbsaType = XBSA_SERVER_TYPE_ADSM; /* Known XBSA server type */
640 printf("Configuration file error, %s %s is not recognized\n",
642 xbsaType = XBSA_SERVER_TYPE_UNKNOWN;
644 printf("XBSA type is %s\n",
646 XBSA_SERVER_TYPE_UNKNOWN) ? "Unknown" : value));
649 else if (!strcmp(cmd, "NODE")) {
652 ("Warning: The %s parameter is ignored with a tape drive\n",
656 xbsaObjectOwner = strdup(value);
657 printf("XBSA node is %s\n", xbsaObjectOwner);
660 else if (!strcmp(cmd, "SERVER")) { /* required for XBSA */
663 ("Warning: The %s parameter is ignored with a tape drive\n",
667 adsmServerName = strdup(value);
668 printf("XBSA server is %s\n", adsmServerName);
671 else if (!strcmp(cmd, "PASSWORD")) { /* This or PASSFILE required for XBSA */
674 ("Warning: The %s parameter is ignored with a tape drive\n",
680 ("Warning: The %s parameter is ignored. Already read password\n",
685 xbsaSecToken = strdup(value);
686 printf("XBSA Password has been read\n");
689 else if (!strcmp(cmd, "PASSFILE")) { /* This or PASSWORD required for XBSA */
693 ("Warning: The %s parameter is ignored with a tape drive\n",
699 ("Warning: The %s parameter is ignored. Already read password\n",
704 pwdFile = fopen(value, "r");
707 ("Configuration file error, cannot open password file %s\n",
711 xbsaSecToken = malloc(LINESIZE);
712 if (!fscanf(pwdFile, "%s", xbsaSecToken)) {
714 ("Configuration file error, cannot read password file %s\n",
718 printf("XBSA password retrieved from password file\n");
721 else if (!strcmp(cmd, "MGMTCLASS")) { /* XBSA */
724 ("Warning: The %s parameter is ignored with a tape drive\n",
728 xbsalGName = strdup(value);
729 printf("XBSA management class is %s\n", xbsalGName);
733 else if (!strcmp(cmd, "MAXPASS")) {
734 maxpass = SafeATOL(value);
735 if (maxpass < PASSESMIN)
737 if (maxpass > PASSESMAX)
739 printf("MAXPASS is %d\n", maxpass);
742 else if (!strcmp(cmd, "GROUPID")) {
743 groupId = SafeATOL(value);
744 if ((groupId < MINGROUPID) || (groupId > MAXGROUPID)) {
745 printf("Configuration file error, %s %s is invalid\n", cmd,
749 printf("Group Id is %d\n", groupId);
752 else if (!strcmp(cmd, "LASTLOG")) {
753 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
754 if (islower(value[cnt]))
755 value[cnt] = toupper(value[cnt]);
757 lastLog = (strcmp(value, "YES") == 0);
758 printf("Will %sgenerate a last log\n", (lastLog ? "" : "not "));
761 else if (!strcmp(cmd, "CENTRALLOG")) {
762 centralLogFile = strdup(value);
763 printf("Central log file is %s\n", centralLogFile);
766 else if (!strcmp(cmd, "STATUS")) {
767 if (atocl(value, 'B', &statusSize)) {
768 fprintf(stderr, "STATUS parse error\n");
771 if (statusSize < MINSTATUS)
772 statusSize = MINSTATUS;
773 if (statusSize > MAXSTATUS)
774 statusSize = MAXSTATUS;
778 printf("Warning: Unrecognized configuration parameter: %s", line);
783 /* Statussize is in bytes and requires that BufferSize be set first */
784 statusSize *= BufferSize;
786 statusSize = 0x7fffffff; /*max size */
787 printf("Status every %ld Bytes\n", afs_printable_int32_ld(statusSize));
794 /* If the butc is configured as XBSA, check for required parameters */
796 if (!code && CONF_XBSA) {
797 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
799 ("Configuration file error, the TYPE parameter must be specified, or\n");
800 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
804 if (!adsmServerName) {
806 ("Configuration file error, the SERVER parameter must be specified\n");
811 ("Configuration file error, the PASSWORD or PASSFILE parameter must be specified\n");
823 xbsa_Finalize(&butxInfo);
829 tc_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
831 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
832 afs_int32 islocal = 0; /* default to no */
835 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
837 TLog(0, ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
838 code, name, inst, cell));
844 WorkerBee(struct cmd_syndesc *as, void *arock)
847 struct rx_securityClass *(securityObjects[1]);
848 struct rx_service *service;
852 /*process arguments */
853 afs_int32 portOffset = 0;
854 #ifdef AFS_PTHREAD_ENV
855 pthread_t dbWatcherPid;
856 pthread_attr_t tattr;
859 PROCESS dbWatcherPid;
861 afs_uint32 host = htonl(INADDR_ANY);
862 char *auditFileName = NULL;
863 char *auditInterface = NULL;
867 /*initialize the error tables */
868 initialize_KA_error_table();
869 initialize_RXK_error_table();
870 initialize_KTC_error_table();
871 initialize_ACFG_error_table();
872 initialize_CMD_error_table();
873 initialize_VL_error_table();
874 initialize_BUTM_error_table();
875 initialize_BUTC_error_table();
877 initialize_BUTX_error_table();
879 initialize_VOLS_error_table();
880 initialize_BUDB_error_table();
881 initialize_BUCD_error_table();
883 if (as->parms[0].items) {
884 portOffset = SafeATOL(as->parms[0].items->data);
885 if (portOffset == -1) {
886 fprintf(stderr, "Illegal port offset '%s'\n",
887 as->parms[0].items->data);
889 } else if (portOffset > BC_MAXPORTOFFSET) {
890 fprintf(stderr, "%u exceeds max port offset %u\n", portOffset,
896 xbsaType = XBSA_SERVER_TYPE_NONE; /* default */
897 if (as->parms[3].items) { /* -device */
898 globalTapeConfig.capacity = 0x7fffffff; /* 2T for max tape capacity */
899 globalTapeConfig.fileMarkSize = 0;
900 globalTapeConfig.portOffset = portOffset;
901 strncpy(globalTapeConfig.device, as->parms[3].items->data, 100);
902 xbsaType = XBSA_SERVER_TYPE_NONE; /* Not XBSA */
904 /* Search for an entry in tapeconfig file */
905 code = GetDeviceConfig(tapeConfigFile, &globalTapeConfig, portOffset);
907 fprintf(stderr, "Problem in reading config file %s\n",
911 /* Set xbsaType. If code == 1, no entry was found in the tapeconfig file so
912 * it's an XBSA server. Don't know if its ADSM or not so its unknown.
915 ((code == 1) ? XBSA_SERVER_TYPE_UNKNOWN : XBSA_SERVER_TYPE_NONE);
918 if (as->parms[6].items) { /* -restoretofile */
919 restoretofile = strdup(as->parms[6].items->data);
920 printf("Restore to file '%s'\n", restoretofile);
923 /* Go and read the config file: CFG_<device> or CFG_<port>. We will also set
924 * the exact xbsaType within the call (won't be unknown) - double check.
926 code = GetConfigParams(pFile, portOffset);
930 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
932 ("\nConfiguration file error, the TYPE parameter must be specified, or\n");
933 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
938 /* Not compiled for XBSA code so we can't support it */
940 printf("\nNo entry found in %s for port %d\n", tapeConfigFile,
942 printf("This binary does not have XBSA support\n");
947 /* Open the log files. The pathnames were set in GetConfigParams() */
948 logIO = fopen(logFile, "a");
950 fprintf(stderr, "Failed to open %s\n", logFile);
953 ErrorlogIO = fopen(ErrorlogFile, "a");
955 fprintf(stderr, "Failed to open %s\n", ErrorlogFile);
959 lastLogIO = fopen(lastLogFile, "a");
961 fprintf(stderr, "Failed to open %s\n", lastLogFile);
965 if (centralLogFile) {
972 statcode = stat(centralLogFile, &sbuf);
973 centralLogIO = fopen(centralLogFile, "a");
975 fprintf(stderr, "Failed to open %s; error %d\n", centralLogFile,
980 /* Make sure it is not in AFS, has to have been created first */
981 path = malloc(AFSDIR_PATH_MAX);
982 if (path == NULL || !realpath(centralLogFile, path)) {
984 "Warning: can't determine real path of '%s' (%d)\n",
985 centralLogFile, errno);
987 if (strncmp(path, "/afs/", 5) == 0) {
988 fprintf(stderr, "The central log '%s' should not be in AFS\n",
996 /* Write header if created it */
999 "TASK START DATE/TIME END DATE/TIME ELAPSED VOLUMESET\n";
1001 "----- ------------------- ------------------- -------- ---------\n";
1002 /* File didn't exist before so write the header lines */
1003 fwrite(h1, strlen(h1), 1, centralLogIO);
1004 fwrite(h2, strlen(h2), 1, centralLogIO);
1005 fflush(centralLogIO);
1009 /* Open the configuration directory */
1010 butc_confdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1011 if (butc_confdir == NULL) {
1012 TLog(0, "Failed to open server configuration directory");
1016 /* Start auditing */
1018 if (as->parms[9].items) {
1019 auditFileName = as->parms[9].items->data;
1021 if (auditFileName != NULL)
1022 osi_audit_file(auditFileName);
1023 if (as->parms[10].items) {
1024 auditInterface = as->parms[10].items->data;
1025 if (osi_audit_interface(auditInterface)) {
1026 TLog(0, "Invalid audit interface '%s'\n", auditInterface);
1030 osi_audit(TC_StartEvent, 0, AUD_END);
1031 osi_audit_set_user_check(butc_confdir, tc_IsLocalRealmMatch);
1033 if (as->parms[1].items) {
1034 debugLevel = SafeATOL(as->parms[1].items->data);
1035 if (debugLevel == -1) {
1036 TLog(0, "Illegal debug level '%s'\n", as->parms[1].items->data);
1041 /* Setup XBSA library interface */
1044 rc = xbsa_MountLibrary(&butxInfo, xbsaType);
1045 if (rc != XBSA_SUCCESS) {
1046 TapeLog(0, 0, rc, 0, "Unable to mount the XBSA library\n");
1050 forcemultiple = (as->parms[7].items ? 1 : 0);/*-xbsaforcemultiple */
1052 printf("Force XBSA multiple server support\n");
1054 rc = InitToServer(0 /*taskid */ , &butxInfo, adsmServerName);
1055 if (rc != XBSA_SUCCESS)
1057 (void)signal(SIGINT, xbsa_shutdown);
1058 (void)signal(SIGHUP, xbsa_shutdown);
1063 if (as->parms[2].items)
1064 strncpy(cellName, as->parms[2].items->data, sizeof(cellName));
1068 if (as->parms[4].items)
1071 localauth = (as->parms[5].items ? 1 : 0);
1072 rxBind = (as->parms[8].items ? 1 : 0);
1076 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1077 AFSDIR_SERVER_NETINFO_FILEPATH) {
1079 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
1080 ADDRSPERSITE, reason,
1081 AFSDIR_SERVER_NETINFO_FILEPATH,
1082 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1085 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1088 host = SHostAddrs[0];
1091 code = rx_InitHost(host, htons(BC_TAPEPORT + portOffset));
1093 TapeLog(0, 0, code, 0, "rx init failed on port %u\n",
1094 BC_TAPEPORT + portOffset);
1097 rx_SetRxDeadTime(150);
1099 /* Establish connection with the vldb server */
1100 code = vldbClientInit(0, localauth, cellName, &cstruct, &tokenExpires);
1102 TapeLog(0, 0, code, 0, "Can't access vldb\n");
1106 strcpy(globalCellName, cellName);
1108 /*initialize the dumpNode list */
1109 InitNodeList(portOffset);
1111 deviceLatch = malloc(sizeof(struct deviceSyncNode));
1112 Lock_Init(&(deviceLatch->lock));
1113 deviceLatch->flags = 0;
1115 /* initialize database support, volume support, and logs */
1117 /* Create a single security object, in this case the null security
1118 * object, for unauthenticated connections, which will be used to control
1119 * security on connections made to this server
1122 securityObjects[RX_SECIDX_NULL] = rxnull_NewServerSecurityObject();
1123 if (!securityObjects[RX_SECIDX_NULL]) {
1124 TLog(0, "rxnull_NewServerSecurityObject");
1129 rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 1, TC_ExecuteRequest);
1131 TLog(0, "rx_NewService");
1134 rx_SetMaxProcs(service, 4);
1136 /* Establish connection to the backup database */
1137 code = udbClientInit(0, localauth, cellName);
1139 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1142 /* This call is here to verify that we are authentiated.
1143 * The call does nothing and will return BUDB_NOTPERMITTED
1144 * if we don't belong.
1146 code = bcdb_deleteDump(0, 0, 0, 0);
1147 if (code == BUDB_NOTPERMITTED) {
1148 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1153 #ifdef AFS_PTHREAD_ENV
1154 code = pthread_attr_init(&tattr);
1156 TapeLog(0, 0, code, 0,
1157 "Can't pthread_attr_init database monitor task");
1160 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
1162 TapeLog(0, 0, code, 0,
1163 "Can't pthread_attr_setdetachstate database monitor task");
1167 code = pthread_create(&dbWatcherPid, &tattr, dbWatcher, (void *)2);
1168 AFS_SIGSET_RESTORE();
1171 LWP_CreateProcess(dbWatcher, 20480, LWP_NORMAL_PRIORITY, (void *)2,
1172 "dbWatcher", &dbWatcherPid);
1175 TapeLog(0, 0, code, 0, "Can't create database monitor task");
1179 TLog(0, "Starting Tape Coordinator: Port offset %u Debug level %u\n",
1180 portOffset, debugLevel);
1181 TLog(0, "Token expires: %s\n", cTIME(&tokenExpires));
1183 rx_StartServer(1); /* Donate this process to the server process pool */
1184 TLog(0, "Error: StartServer returned");
1188 #ifndef AFS_NT40_ENV
1189 #include "AFS_component_version_number.c"
1193 main(int argc, char **argv)
1195 struct cmd_syndesc *ts;
1196 struct cmd_item *ti;
1198 #ifdef AFS_AIX32_ENV
1200 * The following signal action for AIX is necessary so that in case of a
1201 * crash (i.e. core is generated) we can include the user's data section
1202 * in the core dump. Unfortunately, by default, only a partial core is
1203 * generated which, in many cases, isn't too useful.
1205 struct sigaction nsa;
1207 sigemptyset(&nsa.sa_mask);
1208 nsa.sa_handler = SIG_DFL;
1209 nsa.sa_flags = SA_FULLDUMP;
1210 sigaction(SIGSEGV, &nsa, NULL);
1211 sigaction(SIGABRT, &nsa, NULL);
1216 ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, 0, "tape coordinator");
1217 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "port offset");
1218 cmd_AddParm(ts, "-debuglevel", CMD_SINGLE, CMD_OPTIONAL, "0 | 1 | 2");
1219 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1220 cmd_AddParm(ts, "-device", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1221 "tape device path");
1222 cmd_AddParm(ts, "-noautoquery", CMD_FLAG, CMD_OPTIONAL,
1223 "do not query operator for first tape");
1224 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1225 "create tickets from KeyFile");
1226 cmd_AddParm(ts, "-restoretofile", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1227 "file to restore to");
1228 cmd_AddParm(ts, "-xbsaforcemultiple", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
1229 "Force multiple XBSA server support");
1230 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1232 cmd_AddParm(ts, "-auditlog", CMD_SINGLE, CMD_OPTIONAL, "location of audit log");
1233 cmd_AddParm(ts, "-audit-interface", CMD_SINGLE, CMD_OPTIONAL,
1234 "interface to use for audit logging");
1236 /* Initialize dirpaths */
1237 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1239 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1241 fprintf(stderr, "Unable to obtain AFS server directory.\n");
1245 /* setup the file paths */
1246 strcompose(eFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1247 TE_PREFIX, (char *)NULL);
1248 strcompose(lFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1249 TL_PREFIX, (char *)NULL);
1250 strcompose(pFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1251 CFG_PREFIX, (char *)NULL);
1252 strcpy(tapeConfigFile, AFSDIR_SERVER_TAPECONFIG_FILEPATH);
1254 /* special case "no args" case since cmd_dispatch gives help message
1258 ts = calloc(1, sizeof(struct cmd_syndesc));
1260 ti = malloc(sizeof(struct cmd_item));
1263 ts->parms[0].items = ti;
1264 ti = malloc(sizeof(struct cmd_item));
1267 ts->parms[1].items = ti;
1268 ts->parms[2].items = NULL;
1269 ts->parms[3].items = NULL;
1270 ts->parms[4].items = NULL;
1271 ts->parms[5].items = NULL;
1272 return WorkerBee(ts, NULL);
1274 return cmd_Dispatch(argc, argv);