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>
44 #include <afs/cellconfig.h>
46 #include <afs/volser.h>
48 #include <afs/com_err.h>
51 #include <afs/tcdata.h>
52 #include <afs/bubasics.h>
54 #include "error_macros.h"
55 #include <afs/budb_errs.h>
58 #include "butc_xbsa.h"
59 #include "butc_prototypes.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 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 */
110 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
111 afs_uint32 SHostAddrs[ADDRSPERSITE];
113 /* dummy routine for the audit work. It should do nothing since audits */
114 /* occur at the server level and bos is not a server. */
121 SafeATOL(register char *anum)
123 register afs_int32 total;
128 if (tc < '0' || tc > '9')
138 * Convert a string into an afs_int32.
139 * Returned afs_int32 is in Bytes, Kb, Mb, Gb, or Tb. Based on crunit char.
140 * This routine only converts unsigned float values.
141 * The returned value is a whole number.
143 * numstring - text string to be converted.
144 * crunit - value returned in 'B', 'K', 'M', 'G', 'T'.
145 * ' ' or NULL ==> 'B' (bytes).
147 * number - returned value in requested crunit - rounded
148 * to nearest whole number.
151 * -1 - error in conversion
153 * should deal with signed numbers. Should signal error if no digits
157 atocl(char *numstring, char crunit, afs_int32 *number)
166 /* Determine which units to report in */
200 sscanf(numstring, "%f%c%s", &total, &cunit, rest);
201 if ((count > 2) || (count <= 0))
204 cunit = 'B'; /* bytes */
238 /* Go to correct unit */
239 for (; units < runits; units += 3)
241 for (; units > runits; units -= 3)
244 total += 0.5; /* Round up */
245 if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */
252 /* replace last two ocurrences of / by _ */
254 stringReplace(char *name)
259 pos = strrchr(name, '/');
262 pos = strrchr(name, '/');
264 strcat(name, buffer);
269 stringNowReplace(char *logFile, char *deviceName)
272 char storeDevice[256];
273 int mvFlag = 0, devPrefLen;
275 char devPrefix[] = "\\\\.";
277 char devPrefix[] = "/dev";
280 devPrefLen = strlen(devPrefix);
281 strcpy(storeDevice, deviceName);
282 if (strncmp(deviceName, devPrefix, devPrefLen) == 0) {
283 deviceName += devPrefLen;
286 while (pos = strchr(deviceName, devPrefix[0])) /* look for / or \ */
288 strcat(logFile, deviceName);
289 /* now put back deviceName to the way it was */
292 deviceName -= devPrefLen;
294 strcpy(deviceName, storeDevice);
301 * get the configuration information for a particular tape device
302 * as specified by the portoffset
304 * filename - full pathname of file containing the tape device
305 * configuration information
306 * config - for return results
307 * portOffset - for which configuration is required
309 * logging not available when this routine is called
310 * caller return value checks
312 * 0 => Found entry with same port, return info in config.
313 * -1 => Error encountered trying to read the file.
314 * 1 => Desired entry does not exist or file does not exist.
319 GetDeviceConfig(char *filename, struct tapeConfig *config, afs_int32 portOffset)
323 char devName[LINESIZE], tcapacity[LINESIZE], tfmsize[LINESIZE],
328 afs_int32 code = 0, count;
330 /* Initialize the config struct */
331 config->capacity = 0;
332 config->fileMarkSize = 0;
333 config->portOffset = portOffset;
334 strcpy(config->device, "");
336 devFile = fopen(filename, "r");
340 fprintf(stderr, "Error %d: Can't open %s\n", errno, filename);
344 while (fgets(line, LINESIZE - 1, devFile)) {
346 sscanf(line, "%s %s %s %u%s\n", tcapacity, tfmsize, devName,
349 if (count == 4 || count == 5) {
350 if (atocl(tcapacity, 'K', &capacity)) {
352 "tapeconfig: Tape capacity parse error in: %s\n",
356 if (atocl(tfmsize, 'B', &fmSize)) {
358 "tapeconfig: File-mark size parse error in: %s\n",
363 count = sscanf(line, "%s %u%s\n", devName, &aport, trest);
364 if (count == 2 || count == 3) {
365 capacity = 0x7fffffff;
368 fprintf(stderr, "tapeconfig: Parse error in: %s\n", line);
373 if ((aport < 0) || (aport > BC_MAXPORTOFFSET)) {
374 fprintf(stderr, "tapeconfig: Port offset parse error in: %s\n",
379 if (aport != portOffset)
383 fprintf(stderr, "Invalid file mark size, %d, in: %s\n", fmSize,
388 config->capacity = capacity;
389 config->fileMarkSize = fmSize;
390 config->portOffset = aport;
391 strncpy(config->device, devName, 100);
396 /* fprintf(stderr, "Can't find tapeconfig entry for port offset %d\n", portOffset); */
408 GetConfigParams(char *filename, afs_int32 port)
412 char line[LINESIZE], cmd[LINESIZE], value[LINESIZE];
416 /* DEFAULT SETTINGS FOR GLOBAL PARAMETERS */
417 dump_namecheck = 1; /* check tape name on dumps */
418 queryoperator = 1; /* can question operator */
419 autoQuery = 1; /* prompt for first tape */
420 isafile = 0; /* Do not dump to a file */
421 opencallout = NULL; /* open callout routine */
422 closecallout = NULL; /* close callout routine */
423 tapemounted = 0; /* tape is not mounted */
425 BufferSize = (CONF_XBSA ? XBSADFLTBUFFER : BUTM_BLOCKSIZE);
426 dumpRestAuthnLevel = rpc_c_protect_level_default;
427 xbsaObjectOwner = NULL; /* bsaObjectOwner */
428 appObjectOwner = NULL; /* appObjectOwner */
429 adsmServerName = NULL; /* TSM server name - same as ADSM */
430 xbsaSecToken = NULL; /* XBSA sercurity token */
431 xbsalGName = NULL; /* XBSA IGName */
433 BufferSize = BUTM_BLOCKSIZE;
435 centralLogFile = NULL; /* Log for all butcs */
436 centralLogIO = 0; /* Log for all butcs */
437 statusSize = 0; /* size before status message */
438 maxpass = PASSESDFLT; /* dump passes */
439 lastLog = 0; /* separate log for last pass */
440 lastLogIO = 0; /* separate log for last pass */
441 groupId = 0; /* Group id for multiple dumps */
443 /* Try opening the CFG_<port> file */
444 sprintf(paramFile, "%s_%d", filename, port);
445 devFile = fopen(paramFile, "r");
447 /* Set log names to TL_<port>, TL_<port>.lp and TE_<port> */
448 sprintf(logFile, "%s_%d", lFile, port);
449 sprintf(lastLogFile, "%s_%d.lp", lFile, port);
450 sprintf(ErrorlogFile, "%s_%d", eFile, port);
451 } else if (CONF_XBSA) {
452 /* If configured as XBSA, a configuration file CFG_<port> must exist */
453 printf("Cannot open configuration file %s", paramFile);
456 /* Try the CFG_<device> name as the device file */
457 strcpy(paramFile, filename);
458 stringNowReplace(paramFile, globalTapeConfig.device);
459 /* Set log names to TL_<device>, TL_<device> and TE_<device> */
460 strcpy(logFile, lFile);
461 stringNowReplace(logFile, globalTapeConfig.device);
462 strcpy(lastLogFile, lFile);
463 stringNowReplace(lastLogFile, globalTapeConfig.device);
464 strcat(lastLogFile, ".lp");
465 strcpy(ErrorlogFile, eFile);
466 stringNowReplace(ErrorlogFile, globalTapeConfig.device);
468 /* Now open the device file */
469 devFile = fopen(paramFile, "r");
471 ERROR_EXIT(0); /* CFG file doesn't exist for non-XBSA and that's ok */
474 /* Read each line of the Configuration file */
475 while (fgets(line, LINESIZE - 1, devFile)) {
476 cnt = sscanf(line, "%s %s", cmd, value);
479 printf("Bad line in %s: %s\n", paramFile, line);
483 for (cnt = 0; cnt < strlen(cmd); cnt++)
484 if (islower(cmd[cnt]))
485 cmd[cnt] = toupper(cmd[cnt]);
487 if (!strcmp(cmd, "NAME_CHECK")) {
490 ("Warning: The %s parameter is ignored with a Backup Service\n",
495 for (cnt = 0; cnt < strlen(value); cnt++)
496 if (islower(value[cnt]))
497 value[cnt] = toupper(value[cnt]);
499 if (!strcmp(value, "NO")) {
500 printf("Dump tape name check is disabled\n");
503 printf("Dump tape name check is enabled\n");
508 else if (!strcmp(cmd, "MOUNT")) {
511 ("Warning: The %s parameter is ignored with a Backup Service\n",
516 opencallout = (char *)malloc(strlen(value) + 1);
517 strcpy(opencallout, value);
518 printf("Tape mount callout routine is %s\n", opencallout);
521 else if (!strcmp(cmd, "UNMOUNT")) {
524 ("Warning: The %s parameter is ignored with a Backup Service\n",
529 closecallout = (char *)malloc(strlen(value) + 1);
530 strcpy(closecallout, value);
531 printf("Tape unmount callout routine is %s\n", closecallout);
534 else if (!strcmp(cmd, "ASK")) {
535 for (cnt = 0; cnt < strlen(value); cnt++)
536 if (islower(value[cnt]))
537 value[cnt] = toupper(value[cnt]);
539 if (!strcmp(value, "NO")) {
540 printf("Operator queries are disabled\n");
543 printf("Operator queries are enabled\n");
548 else if (!strcmp(cmd, "FILE")) {
551 ("Warning: The %s parameter is ignored with a Backup Service\n",
556 for (cnt = 0; cnt < strlen(value); cnt++)
557 if (islower(value[cnt]))
558 value[cnt] = toupper(value[cnt]);
560 if (!strcmp(value, "YES")) {
561 printf("Will dump to a file\n");
564 printf("Will not dump to a file\n");
569 else if (!strcmp(cmd, "AUTOQUERY")) {
572 ("Warning: The %s parameter is ignored with a Backup Service\n",
577 for (cnt = 0; cnt < strlen(value); cnt++)
578 if (islower(value[cnt]))
579 value[cnt] = toupper(value[cnt]);
581 if (!strcmp(value, "NO")) {
582 printf("Auto query is disabled\n");
585 printf("Auto query is enabled\n");
590 else if (!strcmp(cmd, "BUFFERSIZE")) {
592 afs_int32 tapeblocks;
595 if (atocl(value, 'K', &size)) {
596 fprintf(stderr, "BUFFERSIZE parse error\n");
600 /* A tapeblock is 16KB. Determine # of tapeblocks. Then
601 * determine BufferSize needed for that many tapeblocks.
603 tapeblocks = size / 16;
606 printf("BUFFERSIZE is %u KBytes\n", (tapeblocks * 16));
607 BufferSize = tapeblocks * BUTM_BLOCKSIZE;
610 if (atocl(value, 'B', &size)) {
611 fprintf(stderr, "BUFFERSIZE parse error\n");
614 if (size < XBSAMINBUFFER)
615 size = XBSAMINBUFFER;
616 if (size > XBSAMAXBUFFER)
617 size = XBSAMAXBUFFER;
618 printf("XBSA buffer size is %u Bytes\n", size);
624 /* All the xbsa spacific parameters */
625 else if (!strcmp(cmd, "TYPE") || !strcmp(cmd, "NODE")
626 || !strcmp(cmd, "SERVER") || !strcmp(cmd, "PASSWORD")
627 || !strcmp(cmd, "PASSFILE") || !strcmp(cmd, "MGMTCLASS")) {
628 printf("This binary does not have XBSA support\n");
632 else if (!strcmp(cmd, "TYPE")) { /* required for XBSA */
635 ("Warning: The %s parameter is ignored with a tape drive\n",
640 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
641 if (islower(value[cnt]))
642 value[cnt] = toupper(value[cnt]);
644 if (strcmp(value, "TSM") == 0) {
645 xbsaType = XBSA_SERVER_TYPE_ADSM; /* Known XBSA server type */
647 printf("Configuration file error, %s %s is not recognized\n",
649 xbsaType = XBSA_SERVER_TYPE_UNKNOWN;
651 printf("XBSA type is %s\n",
653 XBSA_SERVER_TYPE_UNKNOWN) ? "Unknown" : value));
656 else if (!strcmp(cmd, "NODE")) {
659 ("Warning: The %s parameter is ignored with a tape drive\n",
663 xbsaObjectOwner = malloc(strlen(value) + 1);
664 strcpy(xbsaObjectOwner, value);
665 printf("XBSA node is %s\n", xbsaObjectOwner);
668 else if (!strcmp(cmd, "SERVER")) { /* required for XBSA */
671 ("Warning: The %s parameter is ignored with a tape drive\n",
675 adsmServerName = malloc(strlen(value) + 1);
676 strcpy(adsmServerName, value);
677 printf("XBSA server is %s\n", adsmServerName);
680 else if (!strcmp(cmd, "PASSWORD")) { /* This or PASSFILE required for XBSA */
683 ("Warning: The %s parameter is ignored with a tape drive\n",
689 ("Warning: The %s parameter is ignored. Already read password\n",
694 xbsaSecToken = malloc(strlen(value) + 1);
695 strcpy(xbsaSecToken, value);
696 printf("XBSA Password has been read\n");
699 else if (!strcmp(cmd, "PASSFILE")) { /* This or PASSWORD required for XBSA */
703 ("Warning: The %s parameter is ignored with a tape drive\n",
709 ("Warning: The %s parameter is ignored. Already read password\n",
714 pwdFile = fopen(value, "r");
717 ("Configuration file error, cannot open password file %s\n",
721 xbsaSecToken = malloc(LINESIZE);
722 if (!fscanf(pwdFile, "%s", xbsaSecToken)) {
724 ("Configuration file error, cannot read password file %s\n",
728 printf("XBSA password retrieved from password file\n");
731 else if (!strcmp(cmd, "MGMTCLASS")) { /* XBSA */
734 ("Warning: The %s parameter is ignored with a tape drive\n",
738 xbsalGName = malloc(strlen(value) + 1);
739 strcpy(xbsalGName, value);
740 printf("XBSA management class is %s\n", xbsalGName);
744 else if (!strcmp(cmd, "MAXPASS")) {
745 maxpass = SafeATOL(value);
746 if (maxpass < PASSESMIN)
748 if (maxpass > PASSESMAX)
750 printf("MAXPASS is %d\n", maxpass);
753 else if (!strcmp(cmd, "GROUPID")) {
754 groupId = SafeATOL(value);
755 if ((groupId < MINGROUPID) || (groupId > MAXGROUPID)) {
756 printf("Configuration file error, %s %s is invalid\n", cmd,
760 printf("Group Id is %d\n", groupId);
763 else if (!strcmp(cmd, "LASTLOG")) {
764 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
765 if (islower(value[cnt]))
766 value[cnt] = toupper(value[cnt]);
768 lastLog = (strcmp(value, "YES") == 0);
769 printf("Will %sgenerate a last log\n", (lastLog ? "" : "not "));
772 else if (!strcmp(cmd, "CENTRALLOG")) {
773 centralLogFile = malloc(strlen(value) + 1);
774 strcpy(centralLogFile, value);
775 printf("Central log file is %s\n", centralLogFile);
778 else if (!strcmp(cmd, "STATUS")) {
779 if (atocl(value, 'B', &statusSize)) {
780 fprintf(stderr, "STATUS parse error\n");
783 if (statusSize < MINSTATUS)
784 statusSize = MINSTATUS;
785 if (statusSize > MAXSTATUS)
786 statusSize = MAXSTATUS;
790 printf("Warning: Unrecognized configuration parameter: %s", line);
795 /* Statussize is in bytes and requires that BufferSize be set first */
796 statusSize *= BufferSize;
798 statusSize = 0x7fffffff; /*max size */
799 printf("Status every %ld Bytes\n", statusSize);
806 /* If the butc is configured as XBSA, check for required parameters */
808 if (!code && CONF_XBSA) {
809 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
811 ("Configuration file error, the TYPE parameter must be specified, or\n");
812 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
816 if (!adsmServerName) {
818 ("Configuration file error, the SERVER parameter must be specified\n");
823 ("Configuration file error, the PASSWORD or PASSFILE parameter must be specified\n");
832 WorkerBee(struct cmd_syndesc *as, void *arock)
834 register afs_int32 code;
835 struct rx_securityClass *(securityObjects[3]);
836 struct rx_service *service;
837 struct ktc_token ttoken;
840 /*process arguments */
841 afs_int32 portOffset = 0;
842 #ifdef AFS_PTHREAD_ENV
843 pthread_t dbWatcherPid;
844 pthread_attr_t tattr;
847 PROCESS dbWatcherPid;
850 afs_uint32 host = htonl(INADDR_ANY);
854 /*initialize the error tables */
855 initialize_KA_error_table();
856 initialize_RXK_error_table();
857 initialize_KTC_error_table();
858 initialize_ACFG_error_table();
859 initialize_CMD_error_table();
860 initialize_VL_error_table();
861 initialize_BUTM_error_table();
862 initialize_BUTC_error_table();
864 initialize_BUTX_error_table();
866 initialize_VOLS_error_table();
867 initialize_BUDB_error_table();
868 initialize_BUCD_error_table();
870 if (as->parms[0].items) {
871 portOffset = SafeATOL(as->parms[0].items->data);
872 if (portOffset == -1) {
873 fprintf(stderr, "Illegal port offset '%s'\n",
874 as->parms[0].items->data);
876 } else if (portOffset > BC_MAXPORTOFFSET) {
877 fprintf(stderr, "%u exceeds max port offset %u\n", portOffset,
883 xbsaType = XBSA_SERVER_TYPE_NONE; /* default */
884 if (as->parms[3].items) { /* -device */
885 globalTapeConfig.capacity = 0x7fffffff; /* 2T for max tape capacity */
886 globalTapeConfig.fileMarkSize = 0;
887 globalTapeConfig.portOffset = portOffset;
888 strncpy(globalTapeConfig.device, as->parms[3].items->data, 100);
889 xbsaType = XBSA_SERVER_TYPE_NONE; /* Not XBSA */
891 /* Search for an entry in tapeconfig file */
892 code = GetDeviceConfig(tapeConfigFile, &globalTapeConfig, portOffset);
894 fprintf(stderr, "Problem in reading config file %s\n",
898 /* Set xbsaType. If code == 1, no entry was found in the tapeconfig file so
899 * it's an XBSA server. Don't know if its ADSM or not so its unknown.
902 ((code == 1) ? XBSA_SERVER_TYPE_UNKNOWN : XBSA_SERVER_TYPE_NONE);
905 if (as->parms[6].items) { /* -restoretofile */
906 int s = strlen(as->parms[6].items->data);
907 restoretofile = malloc(s + 1);
908 strncpy(restoretofile, as->parms[6].items->data, s + 1);
909 printf("Restore to file '%s'\n", restoretofile);
912 /* Go and read the config file: CFG_<device> or CFG_<port>. We will also set
913 * the exact xbsaType within the call (won't be unknown) - double check.
915 code = GetConfigParams(pFile, portOffset);
919 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
921 ("\nConfiguration file error, the TYPE parameter must be specified, or\n");
922 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
927 /* Not compiled for XBSA code so we can't support it */
929 printf("\nNo entry found in %s for port %d\n", tapeConfigFile,
931 printf("This binary does not have XBSA support\n");
936 /* Open the log files. The pathnames were set in GetConfigParams() */
937 logIO = fopen(logFile, "a");
939 fprintf(stderr, "Failed to open %s\n", logFile);
942 ErrorlogIO = fopen(ErrorlogFile, "a");
944 fprintf(stderr, "Failed to open %s\n", ErrorlogFile);
948 lastLogIO = fopen(lastLogFile, "a");
950 fprintf(stderr, "Failed to open %s\n", lastLogFile);
954 if (centralLogFile) {
958 char path[AFSDIR_PATH_MAX];
961 statcode = stat(centralLogFile, &sbuf);
962 centralLogIO = fopen(centralLogFile, "a");
964 fprintf(stderr, "Failed to open %s; error %d\n", centralLogFile,
969 /* Make sure it is not in AFS, has to have been created first */
970 if (!realpath(centralLogFile, path)) {
972 "Warning: can't determine real path of '%s' (%d)\n",
973 centralLogFile, errno);
975 if (strncmp(path, "/afs/", 5) == 0) {
976 fprintf(stderr, "The central log '%s' should not be in AFS\n",
983 /* Write header if created it */
986 "TASK START DATE/TIME END DATE/TIME ELAPSED VOLUMESET\n";
988 "----- ------------------- ------------------- -------- ---------\n";
989 /* File didn't exist before so write the header lines */
990 fwrite(h1, strlen(h1), 1, centralLogIO);
991 fwrite(h2, strlen(h2), 1, centralLogIO);
992 fflush(centralLogIO);
996 if (as->parms[1].items) {
997 debugLevel = SafeATOL(as->parms[1].items->data);
998 if (debugLevel == -1) {
999 TLog(0, "Illegal debug level '%s'\n", as->parms[1].items->data);
1004 /* Setup XBSA library interface */
1007 rc = xbsa_MountLibrary(&butxInfo, xbsaType);
1008 if (rc != XBSA_SUCCESS) {
1009 TapeLog(0, 0, rc, 0, "Unable to mount the XBSA library\n");
1013 forcemultiple = (as->parms[7].items ? 1 : 0);/*-xbsaforcemultiple */
1015 printf("Force XBSA multiple server support\n");
1017 rc = InitToServer(0 /*taskid */ , &butxInfo, adsmServerName);
1018 if (rc != XBSA_SUCCESS)
1024 if (as->parms[2].items)
1025 strncpy(cellName, as->parms[2].items->data, sizeof(cellName));
1029 if (as->parms[4].items)
1032 localauth = (as->parms[5].items ? 1 : 0);
1033 rxBind = (as->parms[8].items ? 1 : 0);
1037 #ifndef AFS_NT40_ENV
1038 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1039 AFSDIR_SERVER_NETINFO_FILEPATH) {
1041 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1042 ADDRSPERSITE, reason,
1043 AFSDIR_SERVER_NETINFO_FILEPATH,
1044 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1048 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1051 host = SHostAddrs[0];
1054 code = rx_InitHost(host, htons(BC_TAPEPORT + portOffset));
1056 TapeLog(0, 0, code, 0, "rx init failed on port %u\n",
1057 BC_TAPEPORT + portOffset);
1060 rx_SetRxDeadTime(150);
1062 /* Establish connection with the vldb server */
1063 code = vldbClientInit(0, localauth, cellName, &cstruct, &ttoken);
1065 TapeLog(0, 0, code, 0, "Can't access vldb\n");
1069 strcpy(globalCellName, cellName);
1071 /*initialize the dumpNode list */
1072 InitNodeList(portOffset);
1075 (struct deviceSyncNode *)(malloc(sizeof(struct deviceSyncNode)));
1076 Lock_Init(&(deviceLatch->lock));
1077 deviceLatch->flags = 0;
1079 /* initialize database support, volume support, and logs */
1081 /* Create a single security object, in this case the null security
1082 * object, for unauthenticated connections, which will be used to control
1083 * security on connections made to this server
1086 securityObjects[0] = rxnull_NewServerSecurityObject();
1087 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
1088 if (!securityObjects[0]) {
1089 TLog(0, "rxnull_NewServerSecurityObject");
1094 rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
1096 TLog(0, "rx_NewService");
1099 rx_SetMaxProcs(service, 4);
1101 /* Establish connection to the backup database */
1102 code = udbClientInit(0, localauth, cellName);
1104 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1107 /* This call is here to verify that we are authentiated.
1108 * The call does nothing and will return BUDB_NOTPERMITTED
1109 * if we don't belong.
1111 code = bcdb_deleteDump(0, 0, 0, 0);
1112 if (code == BUDB_NOTPERMITTED) {
1113 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1118 #ifdef AFS_PTHREAD_ENV
1119 code = pthread_attr_init(&tattr);
1121 TapeLog(0, 0, code, 0,
1122 "Can't pthread_attr_init database monitor task");
1125 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
1127 TapeLog(0, 0, code, 0,
1128 "Can't pthread_attr_setdetachstate database monitor task");
1132 code = pthread_create(&dbWatcherPid, &tattr, dbWatcher, (void *)2);
1133 AFS_SIGSET_RESTORE();
1136 LWP_CreateProcess(dbWatcher, 20480, LWP_NORMAL_PRIORITY, (void *)2,
1137 "dbWatcher", &dbWatcherPid);
1140 TapeLog(0, 0, code, 0, "Can't create database monitor task");
1144 TLog(0, "Starting Tape Coordinator: Port offset %u Debug level %u\n",
1145 portOffset, debugLevel);
1147 TLog(0, "Token expires: %s\n", cTIME(&t));
1149 rx_StartServer(1); /* Donate this process to the server process pool */
1150 TLog(0, "Error: StartServer returned");
1154 #ifndef AFS_NT40_ENV
1155 #include "AFS_component_version_number.c"
1159 main(int argc, char **argv)
1161 register struct cmd_syndesc *ts;
1162 register struct cmd_item *ti;
1164 #ifdef AFS_AIX32_ENV
1166 * The following signal action for AIX is necessary so that in case of a
1167 * crash (i.e. core is generated) we can include the user's data section
1168 * in the core dump. Unfortunately, by default, only a partial core is
1169 * generated which, in many cases, isn't too useful.
1171 struct sigaction nsa;
1173 sigemptyset(&nsa.sa_mask);
1174 nsa.sa_handler = SIG_DFL;
1175 nsa.sa_flags = SA_FULLDUMP;
1176 sigaction(SIGSEGV, &nsa, NULL);
1177 sigaction(SIGABRT, &nsa, NULL);
1182 ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "tape coordinator");
1183 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "port offset");
1184 cmd_AddParm(ts, "-debuglevel", CMD_SINGLE, CMD_OPTIONAL, "0 | 1 | 2");
1185 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1186 cmd_AddParm(ts, "-device", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1187 "tape device path");
1188 cmd_AddParm(ts, "-noautoquery", CMD_FLAG, CMD_OPTIONAL,
1189 "do not query operator for first tape");
1190 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1191 "create tickets from KeyFile");
1192 cmd_AddParm(ts, "-restoretofile", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1193 "file to restore to");
1194 cmd_AddParm(ts, "-xbsaforcemultiple", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
1195 "Force multiple XBSA server support");
1196 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1199 /* Initialize dirpaths */
1200 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1202 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1204 fprintf(stderr, "Unable to obtain AFS server directory.\n");
1208 /* setup the file paths */
1209 strcompose(eFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1211 strcompose(lFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1213 strcompose(pFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1215 strcpy(tapeConfigFile, AFSDIR_SERVER_TAPECONFIG_FILEPATH);
1217 /* special case "no args" case since cmd_dispatch gives help message
1221 ts = (struct cmd_syndesc *)malloc(sizeof(struct cmd_syndesc));
1222 memset(ts, 0, sizeof(*ts));
1224 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
1227 ts->parms[0].items = ti;
1228 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
1231 ts->parms[1].items = ti;
1232 ts->parms[2].items = (struct cmd_item *)NULL;
1233 ts->parms[3].items = (struct cmd_item *)NULL;
1234 ts->parms[4].items = (struct cmd_item *)NULL;
1235 ts->parms[5].items = (struct cmd_item *)NULL;
1236 return WorkerBee(ts, NULL);
1238 return cmd_Dispatch(argc, argv);