Beispiel #1
0
int
tsminit(char *fs, int restore)
{
	regFSData	regFS;
	dsmApiVersionEx	apiLibVer, apiApplVer;
	dsmInitExIn_t	initIn;
	dsmInitExOut_t	initOut;
	dsInt16_t	rv, appVersion, libVersion;
	ApiSessInfo	apis;

	memset(&apiLibVer, 0, sizeof(apiLibVer));
	dsmQueryApiVersionEx(&apiLibVer);

	appVersion = (10000 * DSM_API_VERSION)+(1000 * DSM_API_RELEASE) +
		(100 * DSM_API_LEVEL) + DSM_API_SUBLEVEL;

	libVersion = (apiLibVer.version * 10000) + (apiLibVer.release * 1000) +
	    (apiLibVer.level * 100) + (apiLibVer.subLevel);

	if (libVersion < appVersion)
		errx(1, "libVersion (%x) < appVersion (%x)",
		    libVersion, appVersion);

	memset(&initIn, 0, sizeof(dsmInitExIn_t));
	memset(&initOut, 0, sizeof(dsmInitExOut_t));
	memset(&apiApplVer, 0, sizeof(dsmApiVersionEx));
	apiApplVer.version = DSM_API_VERSION;
	apiApplVer.release = DSM_API_RELEASE;
	apiApplVer.level = DSM_API_LEVEL;
	apiApplVer.subLevel = DSM_API_SUBLEVEL;


	initIn.stVersion = dsmInitExInVersion;
	initIn.apiVersionExP = &apiApplVer;
	initIn.clientNodeNameP = NULL;
	initIn.clientOwnerNameP = NULL;
	initIn.clientPasswordP = NULL;
	initIn.applicationTypeP = "OpenAFS";
	initIn.configfile = NULL;
	initIn.options = NULL;
	initIn.userNameP = NULL;
	initIn.userPasswordP = NULL;

	rv = dsmInitEx(&dsmHandle, &initIn, &initOut);
	if (rv != 0) {
		if (rv == DSM_RC_REJECT_VERIFIER_EXPIRED)
			errx(1, "TSM password expired");
		else
			tsmerror("dsmInitEx failed", rv);
		return rv;
	}

	memset(&apis, 0, sizeof(ApiSessInfo));
	apis.stVersion = ApiSessInfoVersion;
	if ((rv = dsmQuerySessInfo(dsmHandle, &apis)) == DSM_RC_OK)
		maxobjtxn = apis.maxObjPerTxn;

	if (rv != 0) {
		tsmerror("dsmQuerySessInfo failed", rv);
		return rv;
	}

        if (restore == 0) {
		memset(&regFS, 0, sizeof(regFS));
		regFS.fsName = fs;
		regFS.fsType = "OpenAFS";
		if ((rv = dsmRegisterFS(dsmHandle, &regFS)) != DSM_RC_OK &&
		    rv != DSM_RC_FS_ALREADY_REGED)
			tsmerror("dsmRegisterFS", rv);
		if (rv == DSM_RC_FS_ALREADY_REGED) {
			TADEBUG("filespace %s already registered\n", fs);
			rv = 0;
		} else
			TADEBUG("filespace %s registered\n", fs);
	}
	return rv;
}
Beispiel #2
0
int
main(int argc,char **argv) {
  
  int fdesc, usingfile=0, done=0;
  struct stat statbuf;
  FILE* stream;
  
  dsInt16_t dsmresult;
  dsUint32_t myhandle;

  optStruct *my_opts;

  dsmInitExIn_t *init_in;
  dsmInitExOut_t *init_out;

  dsmLogExIn_t *log_in;
  dsmLogExOut_t *log_out;

  char strbuf[1024];

  if (((2 == argc)&&(strncmp(argv[1],"-f",2))) ||	\
      ((3 == argc)&&(strncmp(argv[1],"-f",2)==0))) {
    
    /* handle -f case first */
    if (3 == argc) {
      usingfile=1;
      fdesc=open(argv[2],O_RDONLY);
      if (fdesc < 0) {
	printf("Could not open file %s\n", argv[2]);
	exit(1);
      }

      if (0==fstat(fdesc, &statbuf)) {
	if ((statbuf.st_size > 5*1024) || \
	    (statbuf.st_size < 2)) {
	  printf("Input file %s too small/large to send: %lld\n",
		 argv[2], statbuf.st_size);
	  exit(1);
	}
#ifdef DEBUG
	else {
	  printf("Size of file: %lld\n",statbuf.st_size);
	}
#endif /* DEBUG */
      } else {
	perror("fstat()");
	exit(1);
      }

      stream=fdopen(fdesc,"r");
      if (NULL==stream) {
	perror("fdopen failed");
	exit(1);
      }
    } 
    
    if ((my_opts=(optStruct*)calloc(1,sizeof(*my_opts))) == NULL) {
      printf("No mem for calloc\n");
      exit(1);
    }
#ifdef DEBUG
    else {
      printf("Sizeof optstruct: %d\n",sizeof(*my_opts));
    }
#endif /* DEBUG */
    
    dsmresult=dsmQueryCliOptions(my_opts);
#ifdef DEBUG
    printf("dsmQuery returned: %d\n",dsmresult);
#endif /* DEBUG */
    
    if ((init_in=(dsmInitExIn_t*)calloc(1,sizeof(*init_in))) == NULL) {
      printf("No mem for init_in\n");
      exit(1);
    }    
#ifdef DEBUG
    else {
      printf("sizeof: %d\n",sizeof(*init_in));
    }
#endif /* DEBUG */
    
    if ((init_out=(dsmInitExOut_t*)calloc(1,sizeof(*init_out))) == NULL) {
      printf("No mem for init_out\n");
      exit(1);
    }
#ifdef DEBUG
    else {
      printf("sizeof: %d\n",sizeof(*init_out));
    }
#endif /* DEBUG */
    
    if ((log_in=(dsmLogExIn_t*)calloc(1,sizeof(*log_in))) == NULL) {
      printf("No mem for log_in\n");
      exit(1);
    }    
#ifdef DEBUG
    else {
      printf("sizeof: %d\n",sizeof(*log_in));
    }
#endif /* DEBUG */
    
    if ((log_out=(dsmLogExOut_t*)calloc(1,sizeof(*log_out))) == NULL) {
      printf("No mem for log_out\n");
      exit(1);
    }
#ifdef DEBUG
    else {
      printf("Sizeof: %d\n",sizeof(*log_out));
    }
#endif /* DEBUG */
    
    /* Preparing the initial settings */
    init_in->stVersion        = dsmInitExInVersion;
    init_in->apiVersionExP    = &apiApplVer;
    init_in->clientNodeNameP  = NULL;
    init_in->clientOwnerNameP = NULL;
    init_in->clientPasswordP  = NULL;
    init_in->applicationTypeP = NULL;
    init_in->configfile       = NULL;
    init_in->options          = NULL;
    init_in->userNameP        = NULL;
    init_in->userPasswordP    = NULL;
    
    dsmresult=dsmInitEx(&myhandle,init_in,init_out);
    if (DSM_RC_OK != dsmresult) {
      printdsmerror(myhandle,dsmresult);
      printf("dsmInitEx failed: %d\n",dsmresult);
      exit(1);
    }
#ifdef DEBUG
    printf("dsmInitEx returned: %d\n",dsmresult);
#endif /* DEBUG */


    /* set common settings for both cmdline and file log shipping */
    log_in->severity = logSevInfo; /* ANE4990 */
    strncpy(log_in->appMsgID, "IPN4711",8);

    if(0==usingfile) {
      log_in->message        = argv[1];
      log_in->logType        = logBoth;
      done=1;
    } else {
      log_in->logType        = logServer;
      log_in->message        = fgets(strbuf,1010,stream);
    }

    do {

#ifdef DEBUG
      printf("would send string: %s", log_in->message);
#else     
      dsmresult=dsmLogEventEx(myhandle,log_in,log_out);
      if (DSM_RC_OK != dsmresult) {
	printdsmerror(myhandle, dsmresult);
	if (dsmresult == DSM_RC_STRING_TOO_LONG) {
	  printf("(max ~1000 chars)\n");
	}
	/* wont stop, we still want to run the exit cleanup */
      } else {
	printf("Message sent ok.\n");
      }
#endif /* DEBUG */

      if (usingfile) {
	log_in->message        = fgets(strbuf,1010,stream);
	if (log_in->message == NULL) {
	  done=1; /* break out of loop in case fgets stops
		   reading useful data out of the file */
	}
      }

    } while (!done);
    



    dsmresult=dsmTerminate(myhandle);
    if (DSM_RC_OK != dsmresult) {
      printdsmerror(myhandle, dsmresult);
    } else {
      printf("Exiting\n");
    }
      
    exit(0);
  } else {
    printf("Usage #1: %s <string in quotes to send>\n", argv[0]);
    printf("Usage #2: %s -f <filename to send>\n", argv[0]);
    exit(1);
  }
}