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/com_err.h>
46 #include <afs/tcdata.h>
47 #include <afs/bubasics.h>
48 #include <afs/budb_errs.h>
49 #include <afs/budb_client.h>
50 #include <afs/bucoord_prototypes.h>
52 #include <afs/kautils.h>
55 #include "error_macros.h"
57 #include "butc_xbsa.h"
58 #include "butc_prototypes.h"
60 #define N_SECURITY_OBJECTS 3
61 #define ERRCODE_RANGE 8 /* from error_table.h */
63 #define TE_PREFIX "TE"
64 #define TL_PREFIX "TL"
65 #define CFG_PREFIX "CFG"
67 struct ubik_client *cstruct;
68 FILE *logIO, *ErrorlogIO, *centralLogIO, *lastLogIO;
69 char lFile[AFSDIR_PATH_MAX];
71 char ErrorlogFile[256];
72 char lastLogFile[256];
73 char eFile[AFSDIR_PATH_MAX];
74 char tapeConfigFile[AFSDIR_PATH_MAX];
75 char pFile[AFSDIR_PATH_MAX];
77 struct tapeConfig globalTapeConfig;
78 struct deviceSyncNode *deviceLatch;
79 char globalCellName[64];
80 char *whoami = "butc";
82 /* GLOBAL CONFIGURATION PARAMETERS */
98 #define MINGROUPID 0x1
99 #define MAXGROUPID 0x7FFFFFFF
100 afs_int32 statusSize;
102 #define MAXSTATUS 0x7fffffff
103 afs_int32 BufferSize; /* Size in B stored for data */
104 char *centralLogFile;
105 afs_int32 lastLog; /* Log last pass info */
108 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
109 afs_uint32 SHostAddrs[ADDRSPERSITE];
111 /* dummy routine for the audit work. It should do nothing since audits */
112 /* occur at the server level and bos is not a server. */
126 while ((tc = *anum)) {
127 if (tc < '0' || tc > '9')
137 * Convert a string into an afs_int32.
138 * Returned afs_int32 is in Bytes, Kb, Mb, Gb, or Tb. Based on crunit char.
139 * This routine only converts unsigned float values.
140 * The returned value is a whole number.
142 * numstring - text string to be converted.
143 * crunit - value returned in 'B', 'K', 'M', 'G', 'T'.
144 * ' ' or NULL ==> 'B' (bytes).
146 * number - returned value in requested crunit - rounded
147 * to nearest whole number.
150 * -1 - error in conversion
152 * should deal with signed numbers. Should signal error if no digits
156 atocl(char *numstring, char crunit, afs_int32 *number)
165 /* Determine which units to report in */
199 sscanf(numstring, "%f%c%s", &total, &cunit, rest);
200 if ((count > 2) || (count <= 0))
203 cunit = 'B'; /* bytes */
237 /* Go to correct unit */
238 for (; units < runits; units += 3)
240 for (; units > runits; units -= 3)
243 total += 0.5; /* Round up */
244 if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */
251 /* replace last two ocurrences of / by _ */
254 stringReplace(char *name)
259 pos = strrchr(name, '/');
262 pos = strrchr(name, '/');
264 strcat(name, buffer);
270 stringNowReplace(char *logFile, char *deviceName)
273 char storeDevice[256];
274 int mvFlag = 0, devPrefLen;
276 char devPrefix[] = "\\\\.";
278 char devPrefix[] = "/dev";
281 devPrefLen = strlen(devPrefix);
282 strcpy(storeDevice, deviceName);
283 if (strncmp(deviceName, devPrefix, devPrefLen) == 0) {
284 deviceName += devPrefLen;
287 while ((pos = strchr(deviceName, devPrefix[0]))) /* look for / or \ */
289 strcat(logFile, deviceName);
290 /* now put back deviceName to the way it was */
293 deviceName -= devPrefLen;
295 strcpy(deviceName, storeDevice);
302 * get the configuration information for a particular tape device
303 * as specified by the portoffset
305 * filename - full pathname of file containing the tape device
306 * configuration information
307 * config - for return results
308 * portOffset - for which configuration is required
310 * logging not available when this routine is called
311 * caller return value checks
313 * 0 => Found entry with same port, return info in config.
314 * -1 => Error encountered trying to read the file.
315 * 1 => Desired entry does not exist or file does not exist.
320 GetDeviceConfig(char *filename, struct tapeConfig *config, afs_int32 portOffset)
324 char devName[LINESIZE], tcapacity[LINESIZE], tfmsize[LINESIZE],
329 afs_int32 code = 0, count;
331 /* Initialize the config struct */
332 config->capacity = 0;
333 config->fileMarkSize = 0;
334 config->portOffset = portOffset;
335 strcpy(config->device, "");
337 devFile = fopen(filename, "r");
341 fprintf(stderr, "Error %d: Can't open %s\n", errno, filename);
345 while (fgets(line, LINESIZE - 1, devFile)) {
347 sscanf(line, "%s %s %s %u%s\n", tcapacity, tfmsize, devName,
350 if (count == 4 || count == 5) {
351 if (atocl(tcapacity, 'K', &capacity)) {
353 "tapeconfig: Tape capacity parse error in: %s\n",
357 if (atocl(tfmsize, 'B', &fmSize)) {
359 "tapeconfig: File-mark size parse error in: %s\n",
364 count = sscanf(line, "%s %u%s\n", devName, &aport, trest);
365 if (count == 2 || count == 3) {
366 capacity = 0x7fffffff;
369 fprintf(stderr, "tapeconfig: Parse error in: %s\n", line);
374 if ((aport < 0) || (aport > BC_MAXPORTOFFSET)) {
375 fprintf(stderr, "tapeconfig: Port offset parse error in: %s\n",
380 if (aport != portOffset)
384 fprintf(stderr, "Invalid file mark size, %d, in: %s\n", fmSize,
389 config->capacity = capacity;
390 config->fileMarkSize = fmSize;
391 config->portOffset = aport;
392 strncpy(config->device, devName, 100);
397 /* fprintf(stderr, "Can't find tapeconfig entry for port offset %d\n", portOffset); */
409 GetConfigParams(char *filename, afs_int32 port)
413 char line[LINESIZE], cmd[LINESIZE], value[LINESIZE];
417 /* DEFAULT SETTINGS FOR GLOBAL PARAMETERS */
418 dump_namecheck = 1; /* check tape name on dumps */
419 queryoperator = 1; /* can question operator */
420 autoQuery = 1; /* prompt for first tape */
421 isafile = 0; /* Do not dump to a file */
422 opencallout = NULL; /* open callout routine */
423 closecallout = NULL; /* close callout routine */
424 tapemounted = 0; /* tape is not mounted */
426 BufferSize = (CONF_XBSA ? XBSADFLTBUFFER : BUTM_BLOCKSIZE);
427 dumpRestAuthnLevel = rpc_c_protect_level_default;
428 xbsaObjectOwner = NULL; /* bsaObjectOwner */
429 appObjectOwner = NULL; /* appObjectOwner */
430 adsmServerName = NULL; /* TSM server name - same as ADSM */
431 xbsaSecToken = NULL; /* XBSA sercurity token */
432 xbsalGName = NULL; /* XBSA IGName */
434 BufferSize = BUTM_BLOCKSIZE;
436 centralLogFile = NULL; /* Log for all butcs */
437 centralLogIO = 0; /* Log for all butcs */
438 statusSize = 0; /* size before status message */
439 maxpass = PASSESDFLT; /* dump passes */
440 lastLog = 0; /* separate log for last pass */
441 lastLogIO = 0; /* separate log for last pass */
442 groupId = 0; /* Group id for multiple dumps */
444 /* Try opening the CFG_<port> file */
445 sprintf(paramFile, "%s_%d", filename, port);
446 devFile = fopen(paramFile, "r");
448 /* Set log names to TL_<port>, TL_<port>.lp and TE_<port> */
449 sprintf(logFile, "%s_%d", lFile, port);
450 sprintf(lastLogFile, "%s_%d.lp", lFile, port);
451 sprintf(ErrorlogFile, "%s_%d", eFile, port);
452 } else if (CONF_XBSA) {
453 /* If configured as XBSA, a configuration file CFG_<port> must exist */
454 printf("Cannot open configuration file %s", paramFile);
457 /* Try the CFG_<device> name as the device file */
458 strcpy(paramFile, filename);
459 stringNowReplace(paramFile, globalTapeConfig.device);
460 /* Set log names to TL_<device>, TL_<device> and TE_<device> */
461 strcpy(logFile, lFile);
462 stringNowReplace(logFile, globalTapeConfig.device);
463 strcpy(lastLogFile, lFile);
464 stringNowReplace(lastLogFile, globalTapeConfig.device);
465 strcat(lastLogFile, ".lp");
466 strcpy(ErrorlogFile, eFile);
467 stringNowReplace(ErrorlogFile, globalTapeConfig.device);
469 /* Now open the device file */
470 devFile = fopen(paramFile, "r");
472 ERROR_EXIT(0); /* CFG file doesn't exist for non-XBSA and that's ok */
475 /* Read each line of the Configuration file */
476 while (fgets(line, LINESIZE - 1, devFile)) {
477 cnt = sscanf(line, "%s %s", cmd, value);
480 printf("Bad line in %s: %s\n", paramFile, line);
484 for (cnt = 0; cnt < strlen(cmd); cnt++)
485 if (islower(cmd[cnt]))
486 cmd[cnt] = toupper(cmd[cnt]);
488 if (!strcmp(cmd, "NAME_CHECK")) {
491 ("Warning: The %s parameter is ignored with a Backup Service\n",
496 for (cnt = 0; cnt < strlen(value); cnt++)
497 if (islower(value[cnt]))
498 value[cnt] = toupper(value[cnt]);
500 if (!strcmp(value, "NO")) {
501 printf("Dump tape name check is disabled\n");
504 printf("Dump tape name check is enabled\n");
509 else if (!strcmp(cmd, "MOUNT")) {
512 ("Warning: The %s parameter is ignored with a Backup Service\n",
517 opencallout = strdup(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 = strdup(value);
530 printf("Tape unmount callout routine is %s\n", closecallout);
533 else if (!strcmp(cmd, "ASK")) {
534 for (cnt = 0; cnt < strlen(value); cnt++)
535 if (islower(value[cnt]))
536 value[cnt] = toupper(value[cnt]);
538 if (!strcmp(value, "NO")) {
539 printf("Operator queries are disabled\n");
542 printf("Operator queries are enabled\n");
547 else if (!strcmp(cmd, "FILE")) {
550 ("Warning: The %s parameter is ignored with a Backup Service\n",
555 for (cnt = 0; cnt < strlen(value); cnt++)
556 if (islower(value[cnt]))
557 value[cnt] = toupper(value[cnt]);
559 if (!strcmp(value, "YES")) {
560 printf("Will dump to a file\n");
563 printf("Will not dump to a file\n");
568 else if (!strcmp(cmd, "AUTOQUERY")) {
571 ("Warning: The %s parameter is ignored with a Backup Service\n",
576 for (cnt = 0; cnt < strlen(value); cnt++)
577 if (islower(value[cnt]))
578 value[cnt] = toupper(value[cnt]);
580 if (!strcmp(value, "NO")) {
581 printf("Auto query is disabled\n");
584 printf("Auto query is enabled\n");
589 else if (!strcmp(cmd, "BUFFERSIZE")) {
591 afs_int32 tapeblocks;
594 if (atocl(value, 'K', &size)) {
595 fprintf(stderr, "BUFFERSIZE parse error\n");
599 /* A tapeblock is 16KB. Determine # of tapeblocks. Then
600 * determine BufferSize needed for that many tapeblocks.
602 tapeblocks = size / 16;
605 printf("BUFFERSIZE is %u KBytes\n", (tapeblocks * 16));
606 BufferSize = tapeblocks * BUTM_BLOCKSIZE;
609 if (atocl(value, 'B', &size)) {
610 fprintf(stderr, "BUFFERSIZE parse error\n");
613 if (size < XBSAMINBUFFER)
614 size = XBSAMINBUFFER;
615 if (size > XBSAMAXBUFFER)
616 size = XBSAMAXBUFFER;
617 printf("XBSA buffer size is %u Bytes\n", size);
623 /* All the xbsa spacific parameters */
624 else if (!strcmp(cmd, "TYPE") || !strcmp(cmd, "NODE")
625 || !strcmp(cmd, "SERVER") || !strcmp(cmd, "PASSWORD")
626 || !strcmp(cmd, "PASSFILE") || !strcmp(cmd, "MGMTCLASS")) {
627 printf("This binary does not have XBSA support\n");
631 else if (!strcmp(cmd, "TYPE")) { /* required for XBSA */
634 ("Warning: The %s parameter is ignored with a tape drive\n",
639 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
640 if (islower(value[cnt]))
641 value[cnt] = toupper(value[cnt]);
643 if (strcmp(value, "TSM") == 0) {
644 xbsaType = XBSA_SERVER_TYPE_ADSM; /* Known XBSA server type */
646 printf("Configuration file error, %s %s is not recognized\n",
648 xbsaType = XBSA_SERVER_TYPE_UNKNOWN;
650 printf("XBSA type is %s\n",
652 XBSA_SERVER_TYPE_UNKNOWN) ? "Unknown" : value));
655 else if (!strcmp(cmd, "NODE")) {
658 ("Warning: The %s parameter is ignored with a tape drive\n",
662 xbsaObjectOwner = strdup(value);
663 printf("XBSA node is %s\n", xbsaObjectOwner);
666 else if (!strcmp(cmd, "SERVER")) { /* required for XBSA */
669 ("Warning: The %s parameter is ignored with a tape drive\n",
673 adsmServerName = strdup(value);
674 printf("XBSA server is %s\n", adsmServerName);
677 else if (!strcmp(cmd, "PASSWORD")) { /* This or PASSFILE required for XBSA */
680 ("Warning: The %s parameter is ignored with a tape drive\n",
686 ("Warning: The %s parameter is ignored. Already read password\n",
691 xbsaSecToken = strdup(value);
692 printf("XBSA Password has been read\n");
695 else if (!strcmp(cmd, "PASSFILE")) { /* This or PASSWORD required for XBSA */
699 ("Warning: The %s parameter is ignored with a tape drive\n",
705 ("Warning: The %s parameter is ignored. Already read password\n",
710 pwdFile = fopen(value, "r");
713 ("Configuration file error, cannot open password file %s\n",
717 xbsaSecToken = malloc(LINESIZE);
718 if (!fscanf(pwdFile, "%s", xbsaSecToken)) {
720 ("Configuration file error, cannot read password file %s\n",
724 printf("XBSA password retrieved from password file\n");
727 else if (!strcmp(cmd, "MGMTCLASS")) { /* XBSA */
730 ("Warning: The %s parameter is ignored with a tape drive\n",
734 xbsalGName = strdup(value);
735 printf("XBSA management class is %s\n", xbsalGName);
739 else if (!strcmp(cmd, "MAXPASS")) {
740 maxpass = SafeATOL(value);
741 if (maxpass < PASSESMIN)
743 if (maxpass > PASSESMAX)
745 printf("MAXPASS is %d\n", maxpass);
748 else if (!strcmp(cmd, "GROUPID")) {
749 groupId = SafeATOL(value);
750 if ((groupId < MINGROUPID) || (groupId > MAXGROUPID)) {
751 printf("Configuration file error, %s %s is invalid\n", cmd,
755 printf("Group Id is %d\n", groupId);
758 else if (!strcmp(cmd, "LASTLOG")) {
759 for (cnt = 0; (size_t) cnt < strlen(value); cnt++)
760 if (islower(value[cnt]))
761 value[cnt] = toupper(value[cnt]);
763 lastLog = (strcmp(value, "YES") == 0);
764 printf("Will %sgenerate a last log\n", (lastLog ? "" : "not "));
767 else if (!strcmp(cmd, "CENTRALLOG")) {
768 centralLogFile = strdup(value);
769 printf("Central log file is %s\n", centralLogFile);
772 else if (!strcmp(cmd, "STATUS")) {
773 if (atocl(value, 'B', &statusSize)) {
774 fprintf(stderr, "STATUS parse error\n");
777 if (statusSize < MINSTATUS)
778 statusSize = MINSTATUS;
779 if (statusSize > MAXSTATUS)
780 statusSize = MAXSTATUS;
784 printf("Warning: Unrecognized configuration parameter: %s", line);
789 /* Statussize is in bytes and requires that BufferSize be set first */
790 statusSize *= BufferSize;
792 statusSize = 0x7fffffff; /*max size */
793 printf("Status every %ld Bytes\n", afs_printable_int32_ld(statusSize));
800 /* If the butc is configured as XBSA, check for required parameters */
802 if (!code && CONF_XBSA) {
803 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
805 ("Configuration file error, the TYPE parameter must be specified, or\n");
806 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
810 if (!adsmServerName) {
812 ("Configuration file error, the SERVER parameter must be specified\n");
817 ("Configuration file error, the PASSWORD or PASSFILE parameter must be specified\n");
826 WorkerBee(struct cmd_syndesc *as, void *arock)
829 struct rx_securityClass *(securityObjects[3]);
830 struct rx_service *service;
834 /*process arguments */
835 afs_int32 portOffset = 0;
836 #ifdef AFS_PTHREAD_ENV
837 pthread_t dbWatcherPid;
838 pthread_attr_t tattr;
841 PROCESS dbWatcherPid;
843 afs_uint32 host = htonl(INADDR_ANY);
847 /*initialize the error tables */
848 initialize_KA_error_table();
849 initialize_RXK_error_table();
850 initialize_KTC_error_table();
851 initialize_ACFG_error_table();
852 initialize_CMD_error_table();
853 initialize_VL_error_table();
854 initialize_BUTM_error_table();
855 initialize_BUTC_error_table();
857 initialize_BUTX_error_table();
859 initialize_VOLS_error_table();
860 initialize_BUDB_error_table();
861 initialize_BUCD_error_table();
863 if (as->parms[0].items) {
864 portOffset = SafeATOL(as->parms[0].items->data);
865 if (portOffset == -1) {
866 fprintf(stderr, "Illegal port offset '%s'\n",
867 as->parms[0].items->data);
869 } else if (portOffset > BC_MAXPORTOFFSET) {
870 fprintf(stderr, "%u exceeds max port offset %u\n", portOffset,
876 xbsaType = XBSA_SERVER_TYPE_NONE; /* default */
877 if (as->parms[3].items) { /* -device */
878 globalTapeConfig.capacity = 0x7fffffff; /* 2T for max tape capacity */
879 globalTapeConfig.fileMarkSize = 0;
880 globalTapeConfig.portOffset = portOffset;
881 strncpy(globalTapeConfig.device, as->parms[3].items->data, 100);
882 xbsaType = XBSA_SERVER_TYPE_NONE; /* Not XBSA */
884 /* Search for an entry in tapeconfig file */
885 code = GetDeviceConfig(tapeConfigFile, &globalTapeConfig, portOffset);
887 fprintf(stderr, "Problem in reading config file %s\n",
891 /* Set xbsaType. If code == 1, no entry was found in the tapeconfig file so
892 * it's an XBSA server. Don't know if its ADSM or not so its unknown.
895 ((code == 1) ? XBSA_SERVER_TYPE_UNKNOWN : XBSA_SERVER_TYPE_NONE);
898 if (as->parms[6].items) { /* -restoretofile */
899 restoretofile = strdup(as->parms[6].items->data);
900 printf("Restore to file '%s'\n", restoretofile);
903 /* Go and read the config file: CFG_<device> or CFG_<port>. We will also set
904 * the exact xbsaType within the call (won't be unknown) - double check.
906 code = GetConfigParams(pFile, portOffset);
910 if (xbsaType == XBSA_SERVER_TYPE_UNKNOWN) {
912 ("\nConfiguration file error, the TYPE parameter must be specified, or\n");
913 printf("an entry must exist in %s for port %d\n", tapeConfigFile,
918 /* Not compiled for XBSA code so we can't support it */
920 printf("\nNo entry found in %s for port %d\n", tapeConfigFile,
922 printf("This binary does not have XBSA support\n");
927 /* Open the log files. The pathnames were set in GetConfigParams() */
928 logIO = fopen(logFile, "a");
930 fprintf(stderr, "Failed to open %s\n", logFile);
933 ErrorlogIO = fopen(ErrorlogFile, "a");
935 fprintf(stderr, "Failed to open %s\n", ErrorlogFile);
939 lastLogIO = fopen(lastLogFile, "a");
941 fprintf(stderr, "Failed to open %s\n", lastLogFile);
945 if (centralLogFile) {
949 char path[AFSDIR_PATH_MAX];
952 statcode = stat(centralLogFile, &sbuf);
953 centralLogIO = fopen(centralLogFile, "a");
955 fprintf(stderr, "Failed to open %s; error %d\n", centralLogFile,
960 /* Make sure it is not in AFS, has to have been created first */
961 if (!realpath(centralLogFile, path)) {
963 "Warning: can't determine real path of '%s' (%d)\n",
964 centralLogFile, errno);
966 if (strncmp(path, "/afs/", 5) == 0) {
967 fprintf(stderr, "The central log '%s' should not be in AFS\n",
974 /* Write header if created it */
977 "TASK START DATE/TIME END DATE/TIME ELAPSED VOLUMESET\n";
979 "----- ------------------- ------------------- -------- ---------\n";
980 /* File didn't exist before so write the header lines */
981 fwrite(h1, strlen(h1), 1, centralLogIO);
982 fwrite(h2, strlen(h2), 1, centralLogIO);
983 fflush(centralLogIO);
987 if (as->parms[1].items) {
988 debugLevel = SafeATOL(as->parms[1].items->data);
989 if (debugLevel == -1) {
990 TLog(0, "Illegal debug level '%s'\n", as->parms[1].items->data);
995 /* Setup XBSA library interface */
998 rc = xbsa_MountLibrary(&butxInfo, xbsaType);
999 if (rc != XBSA_SUCCESS) {
1000 TapeLog(0, 0, rc, 0, "Unable to mount the XBSA library\n");
1004 forcemultiple = (as->parms[7].items ? 1 : 0);/*-xbsaforcemultiple */
1006 printf("Force XBSA multiple server support\n");
1008 rc = InitToServer(0 /*taskid */ , &butxInfo, adsmServerName);
1009 if (rc != XBSA_SUCCESS)
1015 if (as->parms[2].items)
1016 strncpy(cellName, as->parms[2].items->data, sizeof(cellName));
1020 if (as->parms[4].items)
1023 localauth = (as->parms[5].items ? 1 : 0);
1024 rxBind = (as->parms[8].items ? 1 : 0);
1028 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
1029 AFSDIR_SERVER_NETINFO_FILEPATH) {
1031 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
1032 ADDRSPERSITE, reason,
1033 AFSDIR_SERVER_NETINFO_FILEPATH,
1034 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1037 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
1040 host = SHostAddrs[0];
1043 code = rx_InitHost(host, htons(BC_TAPEPORT + portOffset));
1045 TapeLog(0, 0, code, 0, "rx init failed on port %u\n",
1046 BC_TAPEPORT + portOffset);
1049 rx_SetRxDeadTime(150);
1051 /* Establish connection with the vldb server */
1052 code = vldbClientInit(0, localauth, cellName, &cstruct, &tokenExpires);
1054 TapeLog(0, 0, code, 0, "Can't access vldb\n");
1058 strcpy(globalCellName, cellName);
1060 /*initialize the dumpNode list */
1061 InitNodeList(portOffset);
1063 deviceLatch = malloc(sizeof(struct deviceSyncNode));
1064 Lock_Init(&(deviceLatch->lock));
1065 deviceLatch->flags = 0;
1067 /* initialize database support, volume support, and logs */
1069 /* Create a single security object, in this case the null security
1070 * object, for unauthenticated connections, which will be used to control
1071 * security on connections made to this server
1074 securityObjects[0] = rxnull_NewServerSecurityObject();
1075 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
1076 if (!securityObjects[0]) {
1077 TLog(0, "rxnull_NewServerSecurityObject");
1082 rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
1084 TLog(0, "rx_NewService");
1087 rx_SetMaxProcs(service, 4);
1089 /* Establish connection to the backup database */
1090 code = udbClientInit(0, localauth, cellName);
1092 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1095 /* This call is here to verify that we are authentiated.
1096 * The call does nothing and will return BUDB_NOTPERMITTED
1097 * if we don't belong.
1099 code = bcdb_deleteDump(0, 0, 0, 0);
1100 if (code == BUDB_NOTPERMITTED) {
1101 TapeLog(0, 0, code, 0, "Can't access backup database\n");
1106 #ifdef AFS_PTHREAD_ENV
1107 code = pthread_attr_init(&tattr);
1109 TapeLog(0, 0, code, 0,
1110 "Can't pthread_attr_init database monitor task");
1113 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
1115 TapeLog(0, 0, code, 0,
1116 "Can't pthread_attr_setdetachstate database monitor task");
1120 code = pthread_create(&dbWatcherPid, &tattr, dbWatcher, (void *)2);
1121 AFS_SIGSET_RESTORE();
1124 LWP_CreateProcess(dbWatcher, 20480, LWP_NORMAL_PRIORITY, (void *)2,
1125 "dbWatcher", &dbWatcherPid);
1128 TapeLog(0, 0, code, 0, "Can't create database monitor task");
1132 TLog(0, "Starting Tape Coordinator: Port offset %u Debug level %u\n",
1133 portOffset, debugLevel);
1134 TLog(0, "Token expires: %s\n", cTIME(&tokenExpires));
1136 rx_StartServer(1); /* Donate this process to the server process pool */
1137 TLog(0, "Error: StartServer returned");
1141 #ifndef AFS_NT40_ENV
1142 #include "AFS_component_version_number.c"
1146 main(int argc, char **argv)
1148 struct cmd_syndesc *ts;
1149 struct cmd_item *ti;
1151 #ifdef AFS_AIX32_ENV
1153 * The following signal action for AIX is necessary so that in case of a
1154 * crash (i.e. core is generated) we can include the user's data section
1155 * in the core dump. Unfortunately, by default, only a partial core is
1156 * generated which, in many cases, isn't too useful.
1158 struct sigaction nsa;
1160 sigemptyset(&nsa.sa_mask);
1161 nsa.sa_handler = SIG_DFL;
1162 nsa.sa_flags = SA_FULLDUMP;
1163 sigaction(SIGSEGV, &nsa, NULL);
1164 sigaction(SIGABRT, &nsa, NULL);
1169 ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "tape coordinator");
1170 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "port offset");
1171 cmd_AddParm(ts, "-debuglevel", CMD_SINGLE, CMD_OPTIONAL, "0 | 1 | 2");
1172 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1173 cmd_AddParm(ts, "-device", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1174 "tape device path");
1175 cmd_AddParm(ts, "-noautoquery", CMD_FLAG, CMD_OPTIONAL,
1176 "do not query operator for first tape");
1177 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1178 "create tickets from KeyFile");
1179 cmd_AddParm(ts, "-restoretofile", CMD_SINGLE, (CMD_OPTIONAL | CMD_HIDE),
1180 "file to restore to");
1181 cmd_AddParm(ts, "-xbsaforcemultiple", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
1182 "Force multiple XBSA server support");
1183 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1186 /* Initialize dirpaths */
1187 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1189 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1191 fprintf(stderr, "Unable to obtain AFS server directory.\n");
1195 /* setup the file paths */
1196 strcompose(eFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1197 TE_PREFIX, (char *)NULL);
1198 strcompose(lFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1199 TL_PREFIX, (char *)NULL);
1200 strcompose(pFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
1201 CFG_PREFIX, (char *)NULL);
1202 strcpy(tapeConfigFile, AFSDIR_SERVER_TAPECONFIG_FILEPATH);
1204 /* special case "no args" case since cmd_dispatch gives help message
1208 ts = calloc(1, sizeof(struct cmd_syndesc));
1210 ti = malloc(sizeof(struct cmd_item));
1213 ts->parms[0].items = ti;
1214 ti = malloc(sizeof(struct cmd_item));
1217 ts->parms[1].items = ti;
1218 ts->parms[2].items = (struct cmd_item *)NULL;
1219 ts->parms[3].items = (struct cmd_item *)NULL;
1220 ts->parms[4].items = (struct cmd_item *)NULL;
1221 ts->parms[5].items = (struct cmd_item *)NULL;
1222 return WorkerBee(ts, NULL);
1224 return cmd_Dispatch(argc, argv);