Enabled Digest calculations for data going to TSM - useful for verification

This commit is contained in:
Deon George 2013-11-07 18:06:56 +11:00
parent b3334a2401
commit 0046a593ab
5 changed files with 81 additions and 4 deletions

View File

@ -1,5 +1,9 @@
TSMAPIDIR=/opt/tivoli/tsm/client/api/bin/sample TSMAPIDIR=/opt/tivoli/tsm/client/api/bin/sample
TSMLIB=-lApiDS
# ** For Digest Calculations, we need to link to openssl libraries, and enable USE_DIGEST in tsmpipe.h **
#TSMLIB=-lApiDS
TSMLIB=-lApiDS -lssl
CC=gcc CC=gcc
CFLAGS=-g -W -Wall -Wextra -O -m32 -I$(TSMAPIDIR) CFLAGS=-g -W -Wall -Wextra -O -m32 -I$(TSMAPIDIR)
LDFLAGS= LDFLAGS=

View File

@ -1,5 +1,9 @@
TSMAPIDIR=/opt/tivoli/tsm/client/api/bin64/sample TSMAPIDIR=/opt/tivoli/tsm/client/api/bin64/sample
TSMLIB=-lApiTSM64
# ** For Digest Calculations, we need to link to openssl libraries, and enable USE_DIGEST in tsmpipe.h **
#TSMLIB=-lApiTSM64
TSMLIB=-lApiTSM64 -lssl
CC=gcc CC=gcc
CFLAGS=-g -W -Wall -Wextra -O -m64 -I$(TSMAPIDIR) CFLAGS=-g -W -Wall -Wextra -O -m64 -I$(TSMAPIDIR)
LDFLAGS= LDFLAGS=

View File

@ -28,6 +28,10 @@
#include "../tsmpipe.h" #include "../tsmpipe.h"
#ifdef USE_DIGEST
#include <openssl/evp.h>
#endif
int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) { int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
struct matchone_cb_data *cbdata = userdata; struct matchone_cb_data *cbdata = userdata;
@ -118,7 +122,11 @@ int tsm_regfs(dsUint32_t dsmHandle, char *fsname) {
} }
/* Send data to TSM for storage */ /* Send data to TSM for storage */
#ifdef USE_DIGEST
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, char *digest) {
#else
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype) { int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype) {
#endif
extern int verbose; extern int verbose;
char *buffer; char *buffer;
dsInt16_t rc=0; dsInt16_t rc=0;
@ -138,6 +146,24 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
exit(255); exit(255);
} }
#ifdef USE_DIGEST
EVP_MD_CTX mdctx;
const EVP_MD *md=NULL;
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len, i;
if (digest) {
OpenSSL_add_all_digests();
md = EVP_get_digestbyname(digest);
if (! md) {
printf("tsm_sendfile: Unknown message digest %s\n", digest);
return 0;
}
}
#endif
// Register our filespace // Register our filespace
if (! tsm_regfs(dsmHandle,fsname)) if (! tsm_regfs(dsmHandle,fsname))
exit(3); exit(3);
@ -210,6 +236,13 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
return(0); return(0);
} }
#ifdef USE_DIGEST
if (digest) {
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
}
#endif
memset(&dataBlk,0x00,sizeof(DataBlk)); memset(&dataBlk,0x00,sizeof(DataBlk));
dataBlk.stVersion = DataBlkVersion; dataBlk.stVersion = DataBlkVersion;
@ -224,6 +257,11 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
break; break;
} }
#ifdef USE_DIGEST
if (digest)
EVP_DigestUpdate(&mdctx, buffer, nbytes);
#endif
dataBlk.bufferLen = nbytes; dataBlk.bufferLen = nbytes;
dataBlk.numBytes = 0; dataBlk.numBytes = 0;
dataBlk.bufferPtr = buffer; dataBlk.bufferPtr = buffer;
@ -274,6 +312,17 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
} }
} }
#ifdef USE_DIGEST
if (digest) {
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx);
fprintf(stderr,"%s: ",digest);
for(i=0; i<md_len; i++) fprintf(stderr,"%02x",md_value[i]);
fprintf(stderr,"\n");
}
#endif
return 1; return 1;
} }

View File

@ -65,7 +65,7 @@ void usage(void) {
fprintf(stderr, fprintf(stderr,
"tsmpipe %s, usage:\n" "tsmpipe %s, usage:\n"
"\n" "\n"
"tsmpipe [-i] [-A|-B] [-c|-x|-d|-t] -s fsname -f filepath [-l len]\n" "tsmpipe [-i]|[[-A|-B] [-c|-x|-d|-t] -s fsname -f filepath [-l len] ...]\n"
" -i Show session information:\n" " -i Show session information:\n"
" -A and -B are mutually exclusive:\n" " -A and -B are mutually exclusive:\n"
" -A Use Archive objects\n" " -A Use Archive objects\n"
@ -87,6 +87,9 @@ void usage(void) {
" -e expdate Expire Date lower bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n" " -e expdate Expire Date lower bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n"
" -E expdate Expire Date upper bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n" " -E expdate Expire Date upper bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n"
" -O options Extra options to pass to dsmInitEx\n" " -O options Extra options to pass to dsmInitEx\n"
#ifdef USE_DIGEST
" -m digest Calculate digest for data being stored in TSM, eg: md5, sha1, sha512..."
#endif
" -v Verbose. More -v's gives more verbosity\n" " -v Verbose. More -v's gives more verbosity\n"
,_TSMPIPE_VERSION); ,_TSMPIPE_VERSION);
@ -112,8 +115,11 @@ int main(int argc, char *argv[]) {
qryBackupData qbData; qryBackupData qbData;
dsmObjName objName; dsmObjName objName;
int rc=0; int rc=0;
#ifdef USE_DIGEST
char *digest=NULL;
#endif
while ((c = getopt(argc, argv, "hiABcxdtve:E:f:l:n:N:s:D:O:P:")) != -1) { while ((c = getopt(argc, argv, "hiABcxdtve:E:f:l:m:n:N:s:D:O:P:")) != -1) {
switch(c) { switch(c) {
case 'h': usage(); break; case 'h': usage(); break;
case 'A': qType = qtArchive; break; case 'A': qType = qtArchive; break;
@ -131,6 +137,9 @@ int main(int argc, char *argv[]) {
case 'l': lenstr = optarg; break; case 'l': lenstr = optarg; break;
case 'D': desc = optarg; break; case 'D': desc = optarg; break;
#ifdef USE_DIGEST
case 'm': digest = optarg; break;
#endif
case 'O': options = optarg; break; case 'O': options = optarg; break;
case 'P': pitdate = optarg; break; case 'P': pitdate = optarg; break;
@ -224,7 +233,11 @@ int main(int argc, char *argv[]) {
if (length <= 0) if (length <= 0)
debugLog(0,stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing",1); debugLog(0,stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing",1);
#ifdef USE_DIGEST
rc = tsm_sendfile(dsmHandle,space,filename,length,desc,((qType == qtArchive) ? stArchiveMountWait : stBackupMountWait),digest);
#else
rc = tsm_sendfile(dsmHandle,space,filename,length,desc,((qType == qtArchive) ? stArchiveMountWait : stBackupMountWait)); rc = tsm_sendfile(dsmHandle,space,filename,length,desc,((qType == qtArchive) ? stArchiveMountWait : stBackupMountWait));
#endif
break; break;
case ACTION_DELETE: case ACTION_DELETE:

View File

@ -6,6 +6,9 @@
#define ACTION_DELETE 4 #define ACTION_DELETE 4
#define ACTION_LIST 5 #define ACTION_LIST 5
// If you want to use MD5/SHA1 calculations as the data goes in here, ensure this is defined.
#define USE_DIGEST
typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *); typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *);
struct matchone_cb_data { int numfound; dsStruct64_t objId; dsUint32_t copyGroup; }; struct matchone_cb_data { int numfound; dsStruct64_t objId; dsUint32_t copyGroup; };
@ -22,7 +25,11 @@ extern dsBool_t compressEnabled;
extern int tsm_deletefile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData); extern int tsm_deletefile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
extern int tsm_listfile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData); extern int tsm_listfile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
extern int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData); extern int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
#ifdef USE_DIGEST
extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, char *digest);
#else
extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype); extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype);
#endif
extern int tsm_sessioninfo(dsUint32_t dsmHandle); extern int tsm_sessioninfo(dsUint32_t dsmHandle);
extern char *dsmDateToStr(dsmDate date); extern char *dsmDateToStr(dsmDate date);