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>
16 #include <sys/types.h>
20 #include <WINNT/afsevent.h>
22 #include <netinet/in.h>
25 #include <afs/procmgmt.h>
27 #include <afs/afsint.h>
29 #ifdef AFS_PTHREAD_ENV
32 #include <afs/assert.h>
34 #include <afs/prs_fs.h>
37 #include <afs/vlserver.h>
40 #include <afs/afsutil.h>
42 #include <rx/rx_globals.h>
45 #include <afs/cellconfig.h>
47 #include <afs/volser.h>
49 #include <afs/com_err.h>
52 #include <afs/tcdata.h>
53 #include <afs/bubasics.h>
55 #include "error_macros.h"
56 #include <afs/budb_errs.h>
59 #include "butc_xbsa.h"
61 #define N_SECURITY_OBJECTS 3
62 #define ERRCODE_RANGE 8 /* from error_table.h */
64 #define TE_PREFIX "TE"
65 #define TL_PREFIX "TL"
66 #define CFG_PREFIX "CFG"
68 struct ubik_client *cstruct;
69 extern void TC_ExecuteRequest();
70 extern int dbWatcher();
71 FILE *logIO, *ErrorlogIO, *centralLogIO, *lastLogIO;
72 char lFile[AFSDIR_PATH_MAX];
74 char ErrorlogFile[256];
75 char lastLogFile[256];
76 char eFile[AFSDIR_PATH_MAX];
77 char tapeConfigFile[AFSDIR_PATH_MAX];
78 char pFile[AFSDIR_PATH_MAX];
80 struct tapeConfig globalTapeConfig;
81 struct deviceSyncNode *deviceLatch;
82 char globalCellName[64];
83 char *whoami = "butc";
85 /* GLOBAL CONFIGURATION PARAMETERS */
101 #define MINGROUPID 0x1
102 #define MAXGROUPID 0x7FFFFFFF
103 afs_int32 statusSize;
105 #define MAXSTATUS 0x7fffffff
106 afs_int32 BufferSize; /* Size in B stored for data */
107 char *centralLogFile;
108 afs_int32 lastLog; /* Log last pass info */
111 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
112 afs_uint32 SHostAddrs[ADDRSPERSITE];
114 /* dummy routine for the audit work. It should do nothing since audits */
115 /* occur at the server level and bos is not a server. */
125 register afs_int32 total;
130 if (tc < '0' || tc > '9')
140 * Convert a string into an afs_int32.
141 * Returned afs_int32 is in Bytes, Kb, Mb, Gb, or Tb. Based on crunit char.
142 * This routine only converts unsigned float values.
143 * The returned value is a whole number.
145 * numstring - text string to be converted.
146 * crunit - value returned in 'B', 'K', 'M', 'G', 'T'.
147 * ' ' or NULL ==> 'B' (bytes).
149 * number - returned value in requested crunit - rounded
150 * to nearest whole number.
153 * -1 - error in conversion
155 * should deal with signed numbers. Should signal error if no digits
158 atocl(numstring, crunit, number)
160 char crunit; /* Units to report number in */
170 /* Determine which units to report in */
204 sscanf(numstring, "%f%c%s", &total, &cunit, rest);
205 if ((count > 2) || (count <= 0))
208 cunit = 'B'; /* bytes */
242 /* Go to correct unit */
243 for (; units < runits; units += 3)
245 for (; units > runits; units -= 3)
248 total += 0.5; /* Round up */
249 if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */
256 /* replace last two ocurrences of / by _ */
264 pos = strrchr(name, '/');
267 pos = strrchr(name, '/');
269 strcat(name, buffer);
274 stringNowReplace(logFile, deviceName)
275 char *logFile, *deviceName;
279 char storeDevice[256];
280 int mvFlag = 0, devPrefLen;
282 char devPrefix[] = "\\\\.";
284 char devPrefix[] = "/dev";
287 devPrefLen = strlen(devPrefix);
288 strcpy(storeDevice, deviceName);
289 if (strncmp(deviceName, devPrefix, devPrefLen) == 0) {
290 deviceName += devPrefLen;
293 while (pos = strchr(deviceName, devPrefix[0])) /* look for / or \ */
295 strcat(logFile, deviceName);
296 /* now put back deviceName to the way it was */
299 deviceName -= devPrefLen;
301 strcpy(deviceName, storeDevice);
308 * get the configuration information for a particular tape device
309 * as specified by the portoffset
311 * filename - full pathname of file containing the tape device
312 * configuration information
313 * config - for return results
314 * portOffset - for which configuration is required
316 * logging not available when this routine is called
317 * caller return value checks
319 * 0 => Found entry with same port, return info in config.
320 * -1 => Error encountered trying to read the file.
321 * 1 => Desired entry does not exist or file does not exist.
326 GetDeviceConfig(filename, config, portOffset)
328 struct tapeConfig *config;
329 afs_int32 portOffset;
333 char devName[LINESIZE], tcapacity[LINESIZE], tfmsize[LINESIZE],
338 afs_int32 code = 0, count;
340 /* Initialize the config struct */
341 config->capacity = 0;
342 config->fileMarkSize = 0;
343 config->portOffset = portOffset;
344 strcpy(config->device, "");
346 devFile = fopen(filename, "r");
350 fprintf(stderr, "Error %d: Can't open %s\n", errno, filename);
354 while (fgets(line, LINESIZE - 1, devFile)) {
356 sscanf(line, "%s %s %s %u%s\n", tcapacity, tfmsize, devName,
359 if (count == 4 || count == 5) {
360 if (atocl(tcapacity, 'K', &capacity)) {
362 "tapeconfig: Tape capacity parse error in: %s\n",
366 if (atocl(tfmsize, 'B', &fmSize)) {
368 "tapeconfig: File-mark size parse error in: %s\n",
373 count = sscanf(line, "%s %u%s\n", devName, &aport, trest);
374 if (count == 2 || count == 3) {
375 capacity = 0x7fffffff;
378 fprintf(stderr, "tapeconfig: Parse error in: %s\n", line);
383 if ((aport < 0) || (aport > BC_MAXPORTOFFSET)) {
384 fprintf(stderr, "tapeconfig: Port offset parse error in: %s\n",
389 if (aport != portOffset)
393 fprintf(stderr, "Invalid file mark size, %d, in: %s\n", fmSize,
398 config->capacity = capacity;
399 config->fileMarkSize = fmSize;
400 config->portOffset = aport;
401 strncpy(config->device, devName, 100);
406 /* fprintf(stderr, "Can't find tapeconfig entry for port offset %d\n", portOffset); */
418 GetConfigParams(filename, port)
424 char line[LINESIZE], cmd[LINESIZE], value[LINESIZE];
428 /* DEFAULT SETTINGS FOR GLOBAL PARAMETERS */
429 dump_namecheck = 1; /* check tape name on dumps */
430 queryoperator = 1; /* can question operator */
431 autoQuery = 1; /* prompt for first tape */
432 isafile = 0; /* Do not dump to a file */
433 opencallout = NULL; /* open callout routine */
434 closecallout = NULL; /* close callout routine */
435 tapemounted = 0; /* tape is not mounted */
437 BufferSize = (CONF_XBSA ? XBSADFLTBUFFER : BUTM_BLOCKSIZE);
438 dumpRestAuthnLevel = rpc_c_protect_level_default;
439 xbsaObjectOwner = NULL; /* bsaObjectOwner */
440 appObjectOwner = NULL; /* appObjectOwner */
441 adsmServerName = NULL; /* TSM server name - same as ADSM */
442 xbsaSecToken = NULL; /* XBSA sercurity token */
443 xbsalGName = NULL; /* XBSA IGName */
445 BufferSize = BUTM_BLOCKSIZE;
447 centralLogFile = NULL; /* Log for all butcs */
448 centralLogIO = 0; /* Log for all butcs */
449 statusSize = 0; /* size before status message */
450 maxpass = PASSESDFLT; /* dump passes */
451 lastLog = 0; /* separate log for last pass */
452 lastLogIO = 0; /* separate log for last pass */
453 groupId = 0; /* Group id for multiple dumps */
455 /* Try opening the CFG_<port> file */
456 sprintf(paramFile, "%s_%d", filename, port);
457 devFile = fopen(paramFile, "r");
459 /* Set log names to TL_<port>, TL_<port>.lp and TE_<port> */
460 sprintf(logFile, "%s_%d", lFile, port);
461 sprintf(lastLogFile, "%s_%d.lp", lFile, port);
462 sprintf(ErrorlogFile, "%s_%d", eFile, port);
463 } else if (CONF_XBSA) {
464 /* If configured as XBSA, a configuration file CFG_<port> must exist */
465 printf("Cannot open configuration file %s", paramFile);
468 /* Try the CFG_<device> name as the device file */
469 strcpy(paramFile, filename);
470 stringNowReplace(paramFile, globalTapeConfig.device);
471 /* Set log names to TL_<device>, TL_<device> and TE_<device> */
472 strcpy(logFile, lFile);
473 stringNowReplace(logFile, globalTapeConfig.device);
474 strcpy(lastLogFile, lFile);
475 stringNowReplace(lastLogFile, globalTapeConfig.device);
476 strcat(lastLogFile, ".lp");
477 strcpy(ErrorlogFile, eFile);
478 stringNowReplace(ErrorlogFile, globalTapeConfig.device);
480 /* Now open the device file */
481 devFile = fopen(paramFile, "r");
483 ERROR_EXIT(0); /* CFG file doesn't exist for non-XBSA and that's ok */
486 /* Read each line of the Configuration file */
487 while (fgets(line, LINESIZE - 1, devFile)) {
488 cnt = sscanf(line, "%s %s", cmd, value);
491 printf("Bad line in %s: %s\n", paramFile, line);
495 for (cnt = 0; cnt < strlen(cmd); cnt++)
496 if (islower(cmd[cnt]))
497 cmd[cnt] = toupper(cmd[cnt]);
499 if (!strcmp(cmd, "NAME_CHECK")) {
502 ("Warning: The %s parameter is ignored with a Backup Service\n",
507 for (cnt = 0; cnt < strlen(value); cnt++)
508 if (islower(value[cnt]))
509 value[cnt] = toupper(value[cnt]);
511 if (!strcmp(value, "NO")) {
512 printf("Dump tape name check is disabled\n");
515 printf("Dump tape name check is enabled\n");
520 else if (!strcmp(cmd, "MOUNT")) {
523 ("Warning: The %s parameter is ignored with a Backup Service\n",
528 opencallout = (char *)malloc(strlen(value) + 1);
529 strcpy(opencallout, value);
530 printf("Tape mount callout routine is %s\n", opencallout);
533 else if (!strcmp(cmd, "UNMOUNT")) {
536 ("Warning: The %s parameter is ignored with a Backup Service\n",
541 closecallout = (char *)malloc(strlen(value) + 1);
542 strcpy(closecallout, value);
543 printf("Tape unmount callout routine is %s\n", closecallout);
546 else if (!strcmp(cmd, "ASK")) {
547 for (cnt = 0; cnt < strlen(value); cnt++)
548 if (islower(value[cnt]))
549 value[cnt] = toupper(value[cnt]);
551 if (!strcmp(value, "NO")) {
552 printf("Operator queries are disabled\n");
555 printf("Operator queries are enabled\n");
560 else if (!strcmp(cmd, "FILE")) {
563 ("Warning: The %s parameter is ignored with a Backup Service\n",
568 for (cnt = 0; cnt < strlen(value); cnt++)
569 if (islower(value[cnt]))
570 value[cnt] = toupper(value[cnt]);
572 if (!strcmp(value, "YES")) {
573 printf("Will dump to a file\n");
576 printf("Will not dump to a file\n");
581 else if (!strcmp(cmd, "AUTOQUERY")) {
584 ("Warning: The %s parameter is ignored with a Backup Service\n",
589 for (cnt = 0; cnt < strlen(value); cnt++)
590 if (islower(value[cnt]))
591 value[cnt] = toupper(value[cnt]);
593 if (!strcmp(value, "NO")) {
594 printf("Auto query is disabled\n");
597 printf("Auto query is enabled\n");
602 else if (!strcmp(cmd, "BUFFERSIZE")) {
604 afs_int32 tapeblocks;
607 if (atocl(value, 'K', &size)) {
608 fprintf(stderr, "BUFFERSIZE parse error\n");
612 /* A tapeblock is 16KB. Determine # of tapeblocks. Then
613 * determine BufferSize needed for that many tapeblocks.
615 tapeblocks = size / 16;
618 printf("BUFFERSIZE is %u KBytes\n", (tapeblocks * 16));
619 BufferSize = tapeblocks * BUTM_BLOCKSIZE;
622 if (atocl(value, 'B', &size)) {
623 fprintf(stderr, "BUFFERSIZE parse error\n");
626 if (size < XBSAMINBUFFER)
627 size = XBSAMINBUFFER;
628 if (size > XBSAMAXBUFFER)
629 size = XBSAMAXBUFFER;
630 printf("XBSA buffer size is %u Bytes\n", size);
636 /* All the xbsa spacific parameters */
637 else if (!strcmp(cmd, "TYPE") || !strcmp(cmd, "NODE")
638 || !strcmp(cmd, "SERVER") || !strcmp(cmd, "PASSWORD")
639 || !strcmp(cmd, "PASSFILE") || !strcmp(cmd, "MGMTCLASS")) {
640 printf("This binary does not have XBSA support\n");
644 else if (!strcmp(cmd, "TYPE")) { /* required for XBSA */
647 ("Warning: The %s parameter is ignored with a tape drive\n",
652 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
653 if (islower(value[cnt]))
654 value[cnt] = toupper(value[cnt]);
656 if (strcmp(value, "TSM") == 0) {
657 xbsaType = XBSA_SERVER_TYPE_ADSM; /* Known XBSA server type */
659 printf("Configuration file error, %s %s is not recognized\n",
661 xbsaType = XBSA_SERVER_TYPE_UNKNOWN;
663 printf("XBSA type is %s\n",
665 XBSA_SERVER_TYPE_UNKNOWN) ? "Unknown" : value));
668 else if (!strcmp(cmd, "NODE")) {
671 ("Warning: The %s parameter is ignored with a tape drive\n",
675 xbsaObjectOwner = malloc(strlen(value) + 1);
676 strcpy(xbsaObjectOwner, value);
677 printf("XBSA node is %s\n", xbsaObjectOwner);
680 else if (!strcmp(cmd, "SERVER")) { /* required for XBSA */
683 ("Warning: The %s parameter is ignored with a tape drive\n",
687 adsmServerName = malloc(strlen(value) + 1);
688 strcpy(adsmServerName, value);
689 printf("XBSA server is %s\n", adsmServerName);
692 else if (!strcmp(cmd, "PASSWORD")) { /* This or PASSFILE required for XBSA */
695 ("Warning: The %s parameter is ignored with a tape drive\n",
701 ("Warning: The %s parameter is ignored. Already read password\n",
706 xbsaSecToken = malloc(strlen(value) + 1);
707 strcpy(xbsaSecToken, value);
708 printf("XBSA Password has been read\n");
711 else if (!strcmp(cmd, "PASSFILE")) { /* This or PASSWORD required for XBSA */
715 ("Warning: The %s parameter is ignored with a tape drive\n",
721 ("Warning: The %s parameter is ignored. Already read password\n",
726 pwdFile = fopen(value, "r");
729 ("Configuration file error, cannot open password file %s\n",
733 xbsaSecToken = malloc(LINESIZE);
734 if (!fscanf(pwdFile, "%s", xbsaSecToken)) {
736 ("Configuration file error, cannot read password file %s\n",
740 printf("XBSA password retrieved from password file\n");
743 else if (!strcmp(cmd, "MGMTCLASS")) { /* XBSA */
746 ("Warning: The %s parameter is ignored with a tape drive\n",
750 xbsalGName = malloc(strlen(value) + 1);
751 strcpy(xbsalGName, value);
752 printf("XBSA management class is %s\n", xbsalGName);
756 else if (!strcmp(cmd, "MAXPASS")) {
757 maxpass = SafeATOL(value);
758 if (maxpass < PASSESMIN)
760 if (maxpass > PASSESMAX)
762 printf("MAXPASS is %d\n", maxpass);
765 else if (!strcmp(cmd, "GROUPID")) {
766 groupId = SafeATOL(value);
767 if ((groupId < MINGROUPID) || (groupId > MAXGROUPID)) {
768 printf("Configuration file error, %s %s is invalid\n", cmd,
772 printf("Group Id is %d\n", groupId);
775 else if (!strcmp(cmd, "LASTLOG")) {
776 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
777 if (islower(value[cnt]))
778 value[cnt] = toupper(value[cnt]);
780 lastLog = (strcmp(value, "YES") == 0);
781 printf("Will %sgenerate a last log\n", (lastLog ? "" : "not "));
784 else if (!strcmp(cmd, "CENTRALLOG")) {
785 centralLogFile = malloc(strlen(value) + 1);
786 strcpy(centralLogFile, value);
787 printf("Central log file is %s\n", centralLogFile);
790 else if (!strcmp(cmd, "STATUS")) {
791 if (atocl(value, 'B', &statusSize)) {
792 fprintf(stderr, "STATUS parse error\n");
795 if (statusSize < MINSTATUS)
796 statusSize = MINSTATUS;
797 if (statusSize > MAXSTATUS)
798 statusSize = MAXSTATUS;
802 printf("Warning: Unrecognized configuration parameter: %s", line);
807 /* Statussize is in bytes and requires that BufferSize be set first */
808 statusSize *= BufferSize;
810 statusSize = 0x7fffffff; /*max size */
811 printf("Status every %ld Bytes\n", statusSize);
818 /* If the butc is configured as XBSA, check for required parameters */
820 if (!code && CONF_XBSA) {
821 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
823 ("Configuration file error, the TYPE parameter must be specified, or\n");
824 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
828 if (!adsmServerName) {
830 ("Configuration file error, the SERVER parameter must be specified\n");
835 ("Configuration file error, the PASSWORD or PASSFILE parameter must be specified\n");
845 struct cmd_syndesc *as;
848 register afs_int32 code;
849 struct rx_securityClass *(securityObjects[3]);
850 struct rx_service *service;
851 struct ktc_token ttoken;
854 /*process arguments */
855 afs_int32 portOffset = 0;
856 #ifdef AFS_PTHREAD_ENV
857 pthread_t dbWatcherPid;
858 pthread_attr_t tattr;
861 PROCESS dbWatcherPid;
864 afs_uint32 host = htonl(INADDR_ANY);
868 /*initialize the error tables */
869 initialize_KA_error_table();
870 initialize_RXK_error_table();
871 initialize_KTC_error_table();
872 initialize_ACFG_error_table();
873 initialize_CMD_error_table();
874 initialize_VL_error_table();
875 initialize_BUTM_error_table();
876 initialize_BUTC_error_table();
878 initialize_BUTX_error_table();
880 initialize_VOLS_error_table();
881 initialize_BUDB_error_table();
882 initialize_BUCD_error_table();
884 if (as->parms[0].items) {
885 portOffset = SafeATOL(as->parms[0].items->data);
886 if (portOffset == -1) {
887 fprintf(stderr, "Illegal port offset '%s'\n",
888 as->parms[0].items->data);
890 } else if (portOffset > BC_MAXPORTOFFSET) {
891 fprintf(stderr, "%u exceeds max port offset %u\n", portOffset,
897 xbsaType = XBSA_SERVER_TYPE_NONE; /* default */
898 if (as->parms[3].items) { /* -device */
899 globalTapeConfig.capacity = 0x7fffffff; /* 2T for max tape capacity */
900 globalTapeConfig.fileMarkSize = 0;
901 globalTapeConfig.portOffset = portOffset;
902 strncpy(globalTapeConfig.device, as->parms[3].items->data, 100);
903 xbsaType = XBSA_SERVER_TYPE_NONE; /* Not XBSA */
905 /* Search for an entry in tapeconfig file */
906 code = GetDeviceConfig(tapeConfigFile, &globalTapeConfig, portOffset);
908 fprintf(stderr, "Problem in reading config file %s\n",
912 /* Set xbsaType. If code == 1, no entry was found in the tapeconfig file so
913 * it's an XBSA server. Don't know if its ADSM or not so its unknown.
916 ((code == 1) ? XBSA_SERVER_TYPE_UNKNOWN : XBSA_SERVER_TYPE_NONE);
919 if (as->parms[6].items) { /* -restoretofile */
920 int s = strlen(as->parms[6].items->data);
921 restoretofile = malloc(s + 1);
922 strncpy(restoretofile, as->parms[6].items->data, s + 1);
923 printf("Restore to file '%s'\n", restoretofile);
926 /* Go and read the config file: CFG_<device> or CFG_<port>. We will also set
927 * the exact xbsaType within the call (won't be unknown) - double check.
929 code = GetConfigParams(pFile, portOffset);
933 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
935 ("\nConfiguration file error, the TYPE parameter must be specified, or\n");
936 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
941 /* Not compiled for XBSA code so we can't support it */
943 printf("\nNo entry found in %s for port %d\n", tapeConfigFile,
945 printf("This binary does not have XBSA support\n");
950 /* Open the log files. The pathnames were set in GetConfigParams() */
951 logIO = fopen(logFile, "a");
953 fprintf(stderr, "Failed to open %s\n", logFile);
956 ErrorlogIO = fopen(ErrorlogFile, "a");
958 fprintf(stderr, "Failed to open %s\n", ErrorlogFile);
962 lastLogIO = fopen(lastLogFile, "a");
964 fprintf(stderr, "Failed to open %s\n", lastLogFile);
968 if (centralLogFile) {
972 char path[AFSDIR_PATH_MAX];
975 statcode = stat(centralLogFile, &sbuf);
976 centralLogIO = fopen(centralLogFile, "a");
978 fprintf(stderr, "Failed to open %s; error %d\n", centralLogFile,
983 /* Make sure it is not in AFS, has to have been created first */
984 if (!realpath(centralLogFile, path)) {
986 "Warning: can't determine real path of '%s' (%d)\n",
987 centralLogFile, errno);
989 if (strncmp(path, "/afs/", 5) == 0) {
990 fprintf(stderr, "The central log '%s' should not be in AFS\n",
997 /* Write header if created it */
1000 "TASK START DATE/TIME END DATE/TIME ELAPSED VOLUMESET\n";
1002 "----- ------------------- ------------------- -------- ---------\n";
1003 /* File didn't exist before so write the header lines */
1004 fwrite(h1, strlen(h1), 1, centralLogIO);
1005 fwrite(h2, strlen(h2), 1, centralLogIO);
1006 fflush(centralLogIO);
1010 if (as->parms[1].items) {
1011 debugLevel = SafeATOL(as->parms[1].items->data);
1012 if (debugLevel == -1) {
1013 TLog(0, "Illegal debug level '%s'\n", as->parms[1].items->data);
1018 /* Setup XBSA library interface */
1021 rc = xbsa_MountLibrary(&butxInfo, xbsaType);
1022 if (rc != XBSA_SUCCESS) {
1023 TapeLog(0, 0, rc, 0, "Unable to mount the XBSA library\n");
1027 forcemultiple = (as->parms[7].items ? 1 : 0);/*-xbsaforcemultiple */
1029 printf("Force XBSA multiple server support\n");
1031 rc = InitToServer(0 /*taskid */ , &butxInfo, adsmServerName);
1032 if (rc != XBSA_SUCCESS)
1038 if (as->parms[2].items)
1039 strncpy(cellName, as->parms[2].items->data, sizeof(cellName));
1043 if (as->parms[4].items)
1046 localauth = (as->parms[5].items ? 1 : 0);
1047 rxBind = (as->parms[8].items ? 1 : 0);
1051 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1052 AFSDIR_SERVER_NETINFO_FILEPATH) {
1054 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1055 ADDRSPERSITE, reason,
1056 AFSDIR_SERVER_NETINFO_FILEPATH,
1057 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1059 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1062 host = SHostAddrs[0];
1065 code = rx_InitHost(host, htons(BC_TAPEPORT + portOffset));
1067 TapeLog(0, 0, code, 0, "rx init failed on port %u\n",
1068 BC_TAPEPORT + portOffset);
1071 rx_SetRxDeadTime(150);
1073 /* Establish connection with the vldb server */
1074 code = vldbClientInit(0, localauth, cellName, &cstruct, &ttoken);
1076 TapeLog(0, 0, code, 0, "Can't access vldb\n");
1080 strcpy(globalCellName, cellName);
1082 /*initialize the dumpNode list */
1083 InitNodeList(portOffset);
1086 (struct deviceSyncNode *)(malloc(sizeof(struct deviceSyncNode)));
1087 Lock_Init(&(deviceLatch->lock));
1088 deviceLatch->flags = 0;
1090 /* initialize database support, volume support, and logs */
1092 /* Create a single security object, in this case the null security
1093 * object, for unauthenticated connections, which will be used to control
1094 * security on connections made to this server
1097 securityObjects[0] = rxnull_NewServerSecurityObject();
1098 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
1099 if (!securityObjects[0]) {
1100 TLog(0, "rxnull_NewServerSecurityObject");
1105 rx_NewServiceHost, (host, 0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
1107 TLog(0, "rx_NewService");
1110 rx_SetMaxProcs(service, 4);
1112 /* Establish connection to the backup database */
1113 code = udbClientInit(0, localauth, cellName);
1115 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1118 /* This call is here to verify that we are authentiated.
1119 * The call does nothing and will return BUDB_NOTPERMITTED
1120 * if we don't belong.
1122 code = bcdb_deleteDump(0, 0, 0, 0);
1123 if (code == BUDB_NOTPERMITTED) {
1124 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1129 #ifdef AFS_PTHREAD_ENV
1130 code = pthread_attr_init(&tattr);
1132 TapeLog(0, 0, code, 0,
1133 "Can't pthread_attr_init database monitor task");
1136 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
1138 TapeLog(0, 0, code, 0,
1139 "Can't pthread_attr_setdetachstate database monitor task");
1143 code = pthread_create(&dbWatcherPid, &tattr, dbWatcher, (void *)2);
1144 AFS_SIGSET_RESTORE();
1147 LWP_CreateProcess(dbWatcher, 20480, LWP_NORMAL_PRIORITY, (void *)2,
1148 "dbWatcher", &dbWatcherPid);
1151 TapeLog(0, 0, code, 0, "Can't create database monitor task");
1155 TLog(0, "Starting Tape Coordinator: Port offset %u Debug level %u\n",
1156 portOffset, debugLevel);
1158 TLog(0, "Token expires: %s\n", cTIME(&t));
1160 rx_StartServer(1); /* Donate this process to the server process pool */
1161 TLog(0, "Error: StartServer returned");
1165 #ifndef AFS_NT40_ENV
1166 #include "AFS_component_version_number.c"
1173 register struct cmd_syndesc *ts;
1174 register struct cmd_item *ti;
1176 #ifdef AFS_AIX32_ENV
1178 * The following signal action for AIX is necessary so that in case of a
1179 * crash (i.e. core is generated) we can include the user's data section
1180 * in the core dump. Unfortunately, by default, only a partial core is
1181 * generated which, in many cases, isn't too useful.
1183 struct sigaction nsa;
1185 sigemptyset(&nsa.sa_mask);
1186 nsa.sa_handler = SIG_DFL;
1187 nsa.sa_flags = SA_FULLDUMP;
1188 sigaction(SIGSEGV, &nsa, NULL);
1189 sigaction(SIGABRT, &nsa, NULL);
1194 ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "tape coordinator");
1195 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "port offset");
1196 cmd_AddParm(ts, "-debuglevel", CMD_SINGLE, CMD_OPTIONAL, "0 | 1 | 2");
1197 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1198 cmd_AddParm(ts, "-device", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1199 "tape device path");
1200 cmd_AddParm(ts, "-noautoquery", CMD_FLAG, CMD_OPTIONAL,
1201 "do not query operator for first tape");
1202 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1203 "create tickets from KeyFile");
1204 cmd_AddParm(ts, "-restoretofile", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1205 "file to restore to");
1206 cmd_AddParm(ts, "-xbsaforcemultiple", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
1207 "Force multiple XBSA server support");
1208 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1211 /* Initialize dirpaths */
1212 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1214 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1216 fprintf(stderr, "Unable to obtain AFS server directory.\n");
1220 /* setup the file paths */
1221 strcompose(eFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1223 strcompose(lFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1225 strcompose(pFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1227 strcpy(tapeConfigFile, AFSDIR_SERVER_TAPECONFIG_FILEPATH);
1229 /* special case "no args" case since cmd_dispatch gives help message
1233 ts = (struct cmd_syndesc *)malloc(sizeof(struct cmd_syndesc));
1234 memset(ts, 0, sizeof(*ts));
1236 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
1239 ts->parms[0].items = ti;
1240 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
1243 ts->parms[1].items = ti;
1244 ts->parms[2].items = (struct cmd_item *)NULL;
1245 ts->parms[3].items = (struct cmd_item *)NULL;
1246 ts->parms[4].items = (struct cmd_item *)NULL;
1247 ts->parms[5].items = (struct cmd_item *)NULL;
1248 return WorkerBee(ts, NULL);
1250 return cmd_Dispatch(argc, argv);