00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "rodsClient.h"
00010 #include "parseCommandLine.h"
00011 #include "readServerConfig.h"
00012
00013 #include "rodsUser.h"
00014
00015 #include "icatHighLevelRoutines.h"
00016 #include "icatMidLevelRoutines.h"
00017
00018 #include <string.h>
00019
00020 extern icatSessionStruct *chlGetRcs();
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 rodsEnv myEnv;
00031
00032 int testRegUser(rsComm_t *rsComm, char *name,
00033 char *zone, char *userType, char *dn) {
00034 userInfo_t userInfo;
00035
00036 strncpy(userInfo.userName, name, sizeof userInfo.userName);
00037 strncpy(userInfo.rodsZone, zone, sizeof userInfo.rodsZone);
00038 strncpy(userInfo.userType, userType, sizeof userInfo.userType);
00039 strncpy(userInfo.authInfo.authStr, dn, sizeof userInfo.authInfo.authStr);
00040
00041
00042 return(0);
00043 }
00044
00045 int testRegRule(rsComm_t *rsComm, char *name) {
00046 ruleExecSubmitInp_t ruleInfo;
00047
00048 memset(&ruleInfo,0,sizeof(ruleInfo));
00049
00050 strncpy(ruleInfo.ruleName, name, sizeof ruleInfo.ruleName);
00051
00052 strncpy(ruleInfo.reiFilePath,"../config/packedRei/rei.file1",
00053 sizeof ruleInfo.reiFilePath);
00054 strncpy(ruleInfo.userName,"Wayne", sizeof ruleInfo.userName);
00055 strncpy(ruleInfo.exeAddress, "Bermuda", sizeof ruleInfo.exeAddress);
00056 strncpy(ruleInfo.exeTime,"whenEver", sizeof ruleInfo.exeTime);
00057 strncpy(ruleInfo.exeFrequency,"every 2 days", sizeof ruleInfo.exeFrequency);
00058 strncpy(ruleInfo.priority,"high", sizeof ruleInfo.priority);
00059 strncpy(ruleInfo.estimateExeTime,"2 hours", sizeof ruleInfo.estimateExeTime);
00060 strncpy(ruleInfo.notificationAddr,"noone@nowhere.com",
00061 sizeof ruleInfo.notificationAddr);
00062 return(chlRegRuleExec(rsComm, &ruleInfo));
00063 }
00064
00065 int testRename(rsComm_t *rsComm, char *id, char *newName) {
00066 rodsLong_t intId;
00067 int status;
00068 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00069 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00070 intId = strtoll(id, 0, 0);
00071 status = chlRenameObject(rsComm, intId, newName);
00072 if (status) return(status);
00073 return(chlCommit(rsComm));
00074 }
00075
00076 int testLogin(rsComm_t *rsComm, char *User, char *pw, char *pw1) {
00077 int status;
00078 rcComm_t *Conn;
00079 rErrMsg_t errMsg;
00080
00081 Conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
00082 myEnv.rodsZone, 0, &errMsg);
00083 if (Conn == NULL) {
00084 printf("rcConnect failure");
00085 return -1;
00086 }
00087
00088 status = clientLoginWithPassword(Conn, pw1);
00089 if (status ==0) {
00090 rstrcpy (Conn->clientUser.userName, User,
00091 sizeof Conn->clientUser.userName);
00092 rstrcpy (Conn->clientUser.rodsZone, myEnv.rodsZone,
00093 sizeof Conn->clientUser.rodsZone);
00094 status = clientLoginWithPassword(Conn, pw);
00095 }
00096
00097 rcDisconnect(Conn);
00098
00099 return(status);
00100 }
00101
00102 int testMove(rsComm_t *rsComm, char *id, char *destId) {
00103 rodsLong_t intId, intDestId;
00104 int status;
00105 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00106 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00107 intId = strtoll(id, 0, 0);
00108 intDestId = strtoll(destId, 0, 0);
00109 status = chlMoveObject(rsComm, intId, intDestId);
00110 if (status) return(status);
00111 return(chlCommit(rsComm));
00112 }
00113
00114 int testTempPw(rsComm_t *rsComm) {
00115 int status;
00116 char pwValueToHash[500];
00117 status = chlMakeTempPw(rsComm, pwValueToHash);
00118 printf("pwValueToHash: %s\n", pwValueToHash);
00119
00120 return(status);
00121 }
00122
00123 int testTempPwConvert(char *s1, char *s2) {
00124 char md5Buf[100];
00125 unsigned char digest[RESPONSE_LEN+2];
00126 char digestStr[100];
00127 MD5_CTX context;
00128
00129
00130
00131
00132
00133
00134 memset(md5Buf, 0, sizeof(md5Buf));
00135 strncpy(md5Buf, s2, sizeof md5Buf);
00136 strncat(md5Buf, s1, sizeof md5Buf);
00137
00138 MD5Init (&context);
00139 MD5Update (&context, (unsigned char*)md5Buf, sizeof md5Buf);
00140 MD5Final (digest, &context);
00141
00142 md5ToStr(digest, digestStr);
00143 printf("digestStr (derived temp pw)=%s\n", digestStr);
00144
00145 return(0);
00146 }
00147
00148
00149 int testTempPwCombined(rsComm_t *rsComm, char *s1) {
00150 int status;
00151 char pwValueToHash[500];
00152 char md5Buf[100];
00153 unsigned char digest[RESPONSE_LEN+2];
00154 char digestStr[100];
00155 MD5_CTX context;
00156
00157 status = chlMakeTempPw(rsComm, pwValueToHash);
00158 if (status) return(status);
00159
00160 printf("pwValueToHash: %s\n", pwValueToHash);
00161
00162
00163
00164
00165
00166
00167 memset(md5Buf, 0, sizeof(md5Buf));
00168 strncpy(md5Buf, pwValueToHash, sizeof md5Buf);
00169 strncat(md5Buf, s1, sizeof md5Buf);
00170
00171 MD5Init (&context);
00172 MD5Update (&context, (unsigned char*)md5Buf, sizeof md5Buf);
00173 MD5Final (digest, &context);
00174
00175 md5ToStr(digest, digestStr);
00176 printf("digestStr (derived temp pw)=%s\n", digestStr);
00177
00178 return(0);
00179 }
00180 int testCheckAuth(rsComm_t *rsComm, char *testAdminUser, char *testUser,
00181 char *testUserZone) {
00182
00183
00184 char response[RESPONSE_LEN+2];
00185 char challenge[CHALLENGE_LEN+2];
00186 int userPrivLevel;
00187 int clientPrivLevel;
00188 int status, i;
00189 char userNameAndZone[NAME_LEN*2];
00190
00191 strncpy(rsComm->clientUser.userName, testUser,
00192 sizeof rsComm->clientUser.userName);
00193 strncpy(rsComm->clientUser.rodsZone, testUserZone,
00194 sizeof rsComm->clientUser.rodsZone);
00195
00196 for (i=0;i<CHALLENGE_LEN+2;i++) challenge[i]=' ';
00197
00198 i=0;
00199 response[i++]=0xd6;
00200 response[i++]=0x8a;
00201 response[i++]=0xaf;
00202 response[i++]=0xc4;
00203 response[i++]=0x83;
00204 response[i++]=0x46;
00205 response[i++]=0x1b;
00206 response[i++]=0xa2;
00207 response[i++]=0x5c;
00208 response[i++]=0x8c;
00209 response[i++]=0x6d;
00210 response[i++]=0xc5;
00211 response[i++]=0xb1;
00212 response[i++]=0x41;
00213 response[i++]=0x84;
00214 response[i++]=0xeb;
00215 response[i++]=0x00;
00216
00217 strncpy(userNameAndZone, testAdminUser, sizeof userNameAndZone);
00218 userNameAndZone[ sizeof( userNameAndZone ) - 1 ] = '\0';
00219 strncat(userNameAndZone, "#", sizeof userNameAndZone);
00220 strncat(userNameAndZone, testUserZone, sizeof userNameAndZone);
00221
00222 status = chlCheckAuth(rsComm, challenge, response,
00223 userNameAndZone,
00224 &userPrivLevel, &clientPrivLevel);
00225
00226 if (status == 0) {
00227 printf("clientPrivLevel=%d\n",clientPrivLevel);
00228 }
00229 return(status);
00230
00231 }
00232
00233 int testDelUser(rsComm_t *rsComm, char *name, char *zone) {
00234 userInfo_t userInfo;
00235
00236 strncpy(userInfo.userName, name, sizeof userInfo.userName);
00237 strncpy(userInfo.rodsZone, zone, sizeof userInfo.rodsZone);
00238
00239
00240 return(0);
00241 }
00242
00243 int testDelFile(rsComm_t *rsComm, char *name, char *replica) {
00244 dataObjInfo_t dataObjInfo;
00245 keyValPair_t *condInput;
00246
00247 memset(&dataObjInfo, 0, sizeof(dataObjInfo));
00248 if (replica != NULL && *replica != 0) {
00249 int ireplica;
00250 ireplica = atoi(replica);
00251 if (ireplica >= 0) {
00252 dataObjInfo.replNum = ireplica;
00253 }
00254 if (ireplica == 999999) {
00255 dataObjInfo.replNum = -1;
00256 }
00257 }
00258 strncpy(dataObjInfo.objPath, name, sizeof dataObjInfo.objPath);
00259
00260 memset (&condInput, 0, sizeof (condInput));
00261
00262 return(chlUnregDataObj(rsComm, &dataObjInfo, condInput));
00263 }
00264
00265 int testDelFilePriv(rsComm_t *rsComm, char *name, char *dataId,
00266 char *replica) {
00267 dataObjInfo_t dataObjInfo;
00268 keyValPair_t condInput;
00269
00270 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00271 memset (&condInput, 0, sizeof (condInput));
00272 addKeyVal(&condInput, IRODS_ADMIN_KW, " ");
00273
00274 memset(&dataObjInfo, 0, sizeof(dataObjInfo));
00275
00276 if (dataId != NULL && *dataId != 0) {
00277 rodsLong_t idataId;
00278 idataId = strtoll(dataId, NULL, 0);
00279 if (idataId >= 0) {
00280 dataObjInfo.dataId = idataId;
00281 }
00282 }
00283 dataObjInfo.replNum = -1;
00284 if (replica != NULL && *replica != 0) {
00285 int ireplica;
00286 ireplica = atoi(replica);
00287 if (ireplica >= 0) {
00288 dataObjInfo.replNum = ireplica;
00289 }
00290 }
00291 strncpy(dataObjInfo.objPath, name, sizeof dataObjInfo.objPath);
00292
00293 return(chlUnregDataObj(rsComm, &dataObjInfo, &condInput));
00294 }
00295
00296 int testDelFileTrash(rsComm_t *rsComm, char *name, char *dataId) {
00297 dataObjInfo_t dataObjInfo;
00298 keyValPair_t condInput;
00299
00300 char *replica=0;
00301
00302 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00303 memset (&condInput, 0, sizeof (condInput));
00304 addKeyVal(&condInput, IRODS_ADMIN_RMTRASH_KW, " ");
00305
00306 memset(&dataObjInfo, 0, sizeof(dataObjInfo));
00307
00308 if (dataId != NULL && *dataId != 0) {
00309 rodsLong_t idataId;
00310 idataId = strtoll(dataId, NULL, 0);
00311 if (idataId >= 0) {
00312 dataObjInfo.dataId = idataId;
00313 }
00314 }
00315 dataObjInfo.replNum = -1;
00316 if (replica != NULL && *replica != 0) {
00317 int ireplica;
00318 ireplica = atoi(replica);
00319 if (ireplica >= 0) {
00320 dataObjInfo.replNum = ireplica;
00321 }
00322 }
00323 strncpy(dataObjInfo.objPath, name, sizeof dataObjInfo.objPath);
00324
00325 return(chlUnregDataObj(rsComm, &dataObjInfo, &condInput));
00326 }
00327
00328 int testRegColl(rsComm_t *rsComm, char *name) {
00329
00330 collInfo_t collInp;
00331
00332 strncpy(collInp.collName, name, sizeof collInp.collName);
00333
00334 return(chlRegColl(rsComm, &collInp));
00335 }
00336
00337 int testDelColl(rsComm_t *rsComm, char *name) {
00338
00339 collInfo_t collInp;
00340
00341 strncpy(collInp.collName, name, sizeof collInp.collName);
00342
00343 return(chlDelColl(rsComm, &collInp));
00344 }
00345
00346 int testDelRule(rsComm_t *rsComm, char *ruleName, char *userName) {
00347 if (userName!=NULL && strlen(userName)>0) {
00348 rsComm->clientUser.authInfo.authFlag = LOCAL_USER_AUTH;
00349 rsComm->proxyUser.authInfo.authFlag = LOCAL_USER_AUTH;
00350 strncpy(rsComm->clientUser.userName, userName,
00351 sizeof rsComm->clientUser.userName);
00352 }
00353 else {
00354 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00355 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00356 }
00357 return(chlDelRuleExec(rsComm, ruleName));
00358 }
00359
00360 int testRegDataObj(rsComm_t *rsComm, char *name,
00361 char *dataType, char *filePath) {
00362 dataObjInfo_t dataObjInfo;
00363 memset(&dataObjInfo,0,sizeof(dataObjInfo_t));
00364
00365 strcpy(dataObjInfo.objPath, name);
00366 dataObjInfo.replNum=1;
00367 strcpy(dataObjInfo.version, "12");
00368 strcpy(dataObjInfo.dataType, dataType);
00369 dataObjInfo.dataSize=42;
00370
00371 strcpy(dataObjInfo.rescName, "demoResc");
00372 strcpy(dataObjInfo.filePath, filePath);
00373
00374 dataObjInfo.replStatus=5;
00375
00376 return (chlRegDataObj(rsComm, &dataObjInfo));
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 int testRegDataMulti(rsComm_t *rsComm, char *count,
00397 char *nameBase, char *dataType, char *filePath) {
00398 int status;
00399 int myCount=100;
00400 int i;
00401 char myName[MAX_NAME_LEN];
00402
00403 myCount = atoi(count);
00404 if (myCount <=0) {
00405 printf("Invalid input: count\n");
00406 return(USER_INPUT_OPTION_ERR);
00407 }
00408
00409 for (i=0;i<myCount;i++) {
00410 snprintf (myName, sizeof myName, "%s.%d", nameBase, i);
00411 status = testRegDataObj(rsComm, myName, dataType, filePath);
00412 if (status) return(status);
00413 }
00414
00415 status = chlCommit(rsComm);
00416 return(status);
00417 }
00418
00419 int testModDataObjMeta(rsComm_t *rsComm, char *name,
00420 char *dataType, char *filePath) {
00421 dataObjInfo_t dataObjInfo;
00422 int status;
00423 keyValPair_t regParam;
00424 char tmpStr[LONG_NAME_LEN], tmpStr2[LONG_NAME_LEN];
00425
00426
00427 memset(&dataObjInfo,0,sizeof(dataObjInfo_t));
00428
00429 memset (®Param, 0, sizeof (regParam));
00430
00431
00432
00433
00434
00435
00436 snprintf (tmpStr, sizeof tmpStr, "fake timestamp");
00437 addKeyVal (®Param, "dataCreate", tmpStr);
00438
00439 snprintf (tmpStr2, sizeof tmpStr2, "test comment");
00440 addKeyVal (®Param, "dataComments", tmpStr2);
00441
00442 strcpy(dataObjInfo.objPath, name);
00443
00444 dataObjInfo.replNum=0;
00445
00446 strcpy(dataObjInfo.version, "12");
00447 strcpy(dataObjInfo.dataType, dataType);
00448 dataObjInfo.dataSize=42;
00449
00450 strcpy(dataObjInfo.rescName, "resc A");
00451
00452 strcpy(dataObjInfo.filePath, filePath);
00453
00454 dataObjInfo.replStatus=5;
00455
00456 status = chlModDataObjMeta(rsComm, &dataObjInfo, ®Param);
00457
00458
00459 return(status);
00460 }
00461
00462 int testModDataObjMeta2(rsComm_t *rsComm, char *name,
00463 char *dataType, char *filePath) {
00464 dataObjInfo_t dataObjInfo;
00465 int status;
00466 keyValPair_t regParam;
00467 char tmpStr[LONG_NAME_LEN], tmpStr2[LONG_NAME_LEN];
00468
00469 memset(&dataObjInfo,0,sizeof(dataObjInfo_t));
00470
00471 memset (®Param, 0, sizeof (regParam));
00472
00473 snprintf (tmpStr, sizeof tmpStr, "whatever");
00474 addKeyVal (®Param, "all", tmpStr);
00475
00476 snprintf (tmpStr2, sizeof tmpStr2, "42");
00477 addKeyVal (®Param, "dataSize", tmpStr2);
00478
00479 strcpy(dataObjInfo.objPath, name);
00480 dataObjInfo.replNum=0;
00481 strcpy(dataObjInfo.version, "12");
00482 strcpy(dataObjInfo.dataType, dataType);
00483 dataObjInfo.dataSize=42;
00484
00485 strcpy(dataObjInfo.rescName, "resc A");
00486
00487 strcpy(dataObjInfo.filePath, filePath);
00488
00489 dataObjInfo.replStatus=5;
00490
00491 status = chlModDataObjMeta(rsComm, &dataObjInfo, ®Param);
00492
00493
00494 return(status);
00495 }
00496
00497 int testModColl(rsComm_t *rsComm, char *name, char *type,
00498 char *info1, char *info2) {
00499 int status;
00500 collInfo_t collInp;
00501
00502 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00503 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00504
00505 memset(&collInp,0,sizeof(collInp));
00506
00507 if (name!=NULL && strlen(name)>0) {
00508 strncpy(collInp.collName, name, sizeof collInp.collName);
00509 }
00510 if (type!=NULL && strlen(type)>0) {
00511 strncpy(collInp.collType, type, sizeof collInp.collType);
00512 }
00513 if (info1!=NULL && strlen(info1)>0) {
00514 strncpy(collInp.collInfo1, info1, sizeof collInp.collInfo1);
00515 }
00516 if (info2!=NULL && strlen(info2)>0) {
00517 strncpy(collInp.collInfo2, info2, sizeof collInp.collInfo2);
00518 }
00519
00520 status = chlModColl(rsComm, &collInp);
00521
00522 if (status != 0) return(status);
00523
00524 status = chlCommit(rsComm);
00525 return(status);
00526 }
00527
00528 int testModRuleMeta(rsComm_t *rsComm, char *id,
00529 char *attrName, char *attrValue) {
00530
00531 char ruleId[100];
00532 int status;
00533 keyValPair_t regParam;
00534 char tmpStr[LONG_NAME_LEN];
00535
00536
00537
00538 memset (®Param, 0, sizeof (regParam));
00539
00540 rstrcpy (tmpStr, attrValue, sizeof tmpStr);
00541
00542 addKeyVal (®Param, attrName, tmpStr);
00543
00544 strcpy(ruleId, id);
00545
00546 status = chlModRuleExec(rsComm, ruleId, ®Param);
00547
00548 return(status);
00549 }
00550
00551 int testModResourceFreeSpace(rsComm_t *rsComm, char *rescName,
00552 char *numberString, char *option) {
00553 int number, status;
00554 if (*numberString=='\\') numberString++;
00555 number = atoi(numberString);
00556 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00557 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00558 status = chlModRescFreeSpace(rsComm, rescName, number);
00559 if (status != 0) return(status);
00560 if (option != NULL && strcmp(option, "rollback")==0 ) {
00561 status = chlRollback(rsComm);
00562 }
00563 if (option != NULL && strcmp(option, "close")==0 ) {
00564 status = chlClose();
00565 return(status);
00566 }
00567 status = chlCommit(rsComm);
00568 return(status);
00569 }
00570
00571 int testRegReplica(rsComm_t *rsComm, char *srcPath, char *srcDataId,
00572 char *srcReplNum, char *dstPath) {
00573 dataObjInfo_t srcDataObjInfo;
00574 dataObjInfo_t dstDataObjInfo;
00575 keyValPair_t condInput;
00576 int status;
00577
00578 memset(&srcDataObjInfo,0,sizeof(dataObjInfo_t));
00579 memset(&dstDataObjInfo,0,sizeof(dataObjInfo_t));
00580 memset(&condInput,0,sizeof(condInput));
00581
00582 strcpy(srcDataObjInfo.objPath, srcPath);
00583 srcDataObjInfo.dataId=atoi(srcDataId);
00584 srcDataObjInfo.replNum=atoi(srcReplNum);
00585
00586
00587 strcpy(dstDataObjInfo.rescName, "resc A");
00588 strcpy(dstDataObjInfo.rescGroupName, "resc A");
00589 strcpy(dstDataObjInfo.filePath, dstPath);
00590
00591 dstDataObjInfo.replStatus=5;
00592
00593 status = chlRegReplica(rsComm, &srcDataObjInfo, &dstDataObjInfo,
00594 &condInput);
00595 return(status);
00596 }
00597
00598 int testSimpleQ(rsComm_t *rsComm, char *sql, char *arg1, char *format) {
00599 char bigBuf[1000];
00600 int status;
00601 int control;
00602 int form;
00603
00604 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00605 rsComm->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00606
00607 control=0;
00608 form = 1;
00609 if (format != NULL) form = atoi(format);
00610
00611 status = chlSimpleQuery(rsComm, sql, arg1, 0, 0, 0,
00612 form, &control, bigBuf, 1000);
00613 if (status==0) printf("%s",bigBuf);
00614
00615 while (control && (status==0) ) {
00616 status = chlSimpleQuery(rsComm, sql, 0, 0, 0, 0,
00617 form, &control, bigBuf, 1000);
00618 if (status==0) printf("%s",bigBuf);
00619 }
00620 return(status);
00621 }
00622
00623 int testChmod(rsComm_t *rsComm, char *user, char *zone,
00624 char *access, char *path) {
00625 int status;
00626 status = chlModAccessControl(rsComm, 0, user, zone, access, path);
00627
00628 return(status);
00629 }
00630
00631 int testServerLoad(rsComm_t *rsComm, char *option) {
00632 int status;
00633
00634 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00635
00636 status = chlRegServerLoad(rsComm, "host", "resc", option, "2", "3",
00637 "4", "5", "6", "7");
00638 return(status);
00639 }
00640
00641 int testPurgeServerLoad(rsComm_t *rsComm, char *option) {
00642 int status;
00643
00644 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00645
00646 if (option == NULL) {
00647 status = chlPurgeServerLoad(rsComm, "2000");
00648 }
00649 else {
00650 status = chlPurgeServerLoad(rsComm, option);
00651 }
00652
00653 return(status);
00654 }
00655
00656 int testServerLoadDigest(rsComm_t *rsComm, char *option) {
00657 int status;
00658
00659 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00660
00661 status = chlRegServerLoadDigest(rsComm, "resc", option);
00662 return(status);
00663 }
00664
00665 int testPurgeServerLoadDigest(rsComm_t *rsComm, char *option) {
00666 int status;
00667
00668 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00669
00670 if (option == NULL) {
00671 status = chlPurgeServerLoadDigest(rsComm, "2000");
00672 }
00673 else {
00674 status = chlPurgeServerLoadDigest(rsComm, option);
00675 }
00676
00677 return(status);
00678 }
00679
00680 int testCheckQuota(rsComm_t *rsComm, char *userName, char *rescName,
00681 char *expectedQuota, char *expectedStatus) {
00682 int status;
00683 int quotaStatus;
00684 rodsLong_t userQuota;
00685
00686 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00687
00688 status = chlCheckQuota(rsComm, userName, rescName,
00689 &userQuota, "aStatus);
00690
00691 rodsLog (LOG_SQL,
00692 "chlCheckQuota status: userName:%s rescName:%s userQuota:%lld quotaStatus:%d\n",
00693 userName, rescName, userQuota, quotaStatus);
00694
00695 if (status==0) {
00696 int iExpectedStatus;
00697 rodsLong_t iExpectedQuota;
00698 if (expectedQuota != NULL && strlen(expectedQuota)>0 ) {
00699 rodsLong_t i;
00700 iExpectedQuota = atoll(expectedQuota);
00701 if (expectedQuota[0]=='m') {
00702 i = atoll((char *)&expectedQuota[1]);
00703 iExpectedQuota = -i;
00704 }
00705 if (iExpectedQuota != userQuota) status = -1;
00706 }
00707 if (expectedStatus != NULL && strlen(expectedStatus)>0 ) {
00708 iExpectedStatus = atoi(expectedStatus);
00709 if (iExpectedStatus != quotaStatus) status = -2;
00710 }
00711 }
00712 return(status);
00713 }
00714
00715 rodsLong_t
00716 testCurrent(rsComm_t *rsComm) {
00717 rodsLong_t status;
00718 icatSessionStruct *icss;
00719
00720 icss = chlGetRcs();
00721
00722 status = cmlGetCurrentSeqVal(icss);
00723 return(status);
00724 }
00725
00726 int
00727 testAddRule(rsComm_t *rsComm, char *baseName, char *ruleName,
00728 char *ruleHead, char *ruleCondition, char *ruleAction,
00729 char *ruleRecovery) {
00730 int status;
00731 char ruleIdStr[200];
00732 char myTime[]="01277237323";
00733 char priority[] ="1";
00734 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00735
00736 status = chlInsRuleTable(rsComm, baseName, priority, ruleName,
00737 ruleHead, ruleCondition, ruleAction,
00738 ruleRecovery, (char *)&ruleIdStr, (char *)&myTime);
00739
00740 if (status == 0) {
00741 printf("ruleIdStr: %s\n",ruleIdStr);
00742 }
00743 return(status);
00744 }
00745
00746 int
00747 testVersionRuleBase(rsComm_t *rsComm, char *baseName) {
00748 int status;
00749 char myTime[]="01277237323";
00750 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00751
00752 status = chlVersionRuleBase(rsComm, baseName, (char *)&myTime);
00753
00754 return(status);
00755 }
00756
00757 int
00758 testVersionDvmBase(rsComm_t *rsComm, char *baseName) {
00759 int status;
00760 char myTime[]="01277237323";
00761 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00762
00763 status = chlVersionDvmBase(rsComm, baseName, (char *)&myTime);
00764
00765 return(status);
00766 }
00767
00768 int
00769 testInsFnmTable(rsComm_t *rsComm, char *arg1, char *arg2, char *arg3,
00770 char *arg4) {
00771 int status;
00772 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00773
00774 status = chlInsFnmTable(rsComm, arg1, arg2, arg3, arg4);
00775
00776 return(status);
00777 }
00778
00779 int
00780 testInsMsrvcTable(rsComm_t *rsComm, char *arg1, char *arg2, char *arg3,
00781 char *arg4, char *arg5, char *arg6, char *arg7, char *arg8,
00782 char *arg9) {
00783 int status;
00784 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00785
00786 status = chlInsMsrvcTable(rsComm, arg1, arg2, arg3, arg4,
00787 arg5, arg6, arg7, arg8, arg9,"0");
00788
00789 return(status);
00790 }
00791
00792 int
00793 testInsDvmTable(rsComm_t *rsComm, char *arg1, char *arg2, char *arg3,
00794 char *arg4) {
00795 int status;
00796 char myTime[]="01277237323";
00797 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00798
00799 status = chlInsDvmTable(rsComm, arg1, arg2, arg3, arg4, myTime);
00800 return(status);
00801 }
00802
00803 int
00804 testVersionFnmBase(rsComm_t *rsComm, char *arg1) {
00805 int status;
00806 char myTime[]="01277237323";
00807 rsComm->clientUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH;
00808
00809 status = chlVersionFnmBase(rsComm, arg1, myTime);
00810
00811 return(status);
00812 }
00813
00814
00815 int
00816 main(int argc, char **argv) {
00817 int status;
00818 rsComm_t *Comm;
00819
00820 rodsArguments_t myRodsArgs;
00821 char *mySubName;
00822 char *myName;
00823 int didOne;
00824 rodsServerConfig_t serverConfig;
00825
00826 Comm = (rsComm_t*)malloc (sizeof (rsComm_t));
00827 memset (Comm, 0, sizeof (rsComm_t));
00828
00829 parseCmdLineOpt(argc, argv, "", 0, &myRodsArgs);
00830
00831 rodsLogLevel(LOG_NOTICE);
00832
00833 rodsLogSqlReq(1);
00834
00835 if (argc < 2) {
00836 printf("Usage: test_chl testName [args...]\n");
00837 exit(3);
00838 }
00839
00840 status = getRodsEnv (&myEnv);
00841 if (status < 0) {
00842 rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
00843 status);
00844 exit (1);
00845 }
00846
00847 if (strstr(myEnv.rodsDebug, "CAT") != NULL) {
00848 chlDebug(myEnv.rodsDebug);
00849 }
00850
00851 memset(&serverConfig, 0, sizeof(serverConfig));
00852 status = readServerConfig(&serverConfig);
00853
00854 strncpy(Comm->clientUser.userName, myEnv.rodsUserName,
00855 sizeof Comm->clientUser.userName);
00856
00857 strncpy(Comm->clientUser.rodsZone, myEnv.rodsZone,
00858 sizeof Comm->clientUser.rodsZone);
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868 if ((status = chlOpen(serverConfig.DBUsername,
00869 serverConfig.DBPassword)) != 0) {
00870 rodsLog (LOG_SYS_FATAL,
00871 "initInfoWithRcat: chlopen Error. Status = %d",
00872 status);
00873 free( Comm );
00874 return (status);
00875 }
00876
00877 didOne=0;
00878 if (strcmp(argv[1],"reg")==0) {
00879 status = testRegDataObj(Comm, argv[2], argv[3], argv[4]);
00880 didOne=1;
00881 }
00882 if (strcmp(argv[1],"regmulti")==0) {
00883 status = testRegDataMulti(Comm, argv[2], argv[3], argv[4], argv[5]);
00884 didOne=1;
00885 }
00886
00887 if (strcmp(argv[1],"mod")==0) {
00888 status = testModDataObjMeta(Comm, argv[2], argv[3], argv[4]);
00889 didOne=1;
00890 }
00891
00892 if (strcmp(argv[1],"mod2")==0) {
00893 status = testModDataObjMeta2(Comm, argv[2], argv[3], argv[4]);
00894 didOne=1;
00895 }
00896
00897 if (strcmp(argv[1],"modr")==0) {
00898 status = testModRuleMeta(Comm, argv[2], argv[3], argv[4]);
00899 didOne=1;
00900 }
00901
00902 if (strcmp(argv[1],"modc")==0) {
00903 status = testModColl(Comm, argv[2], argv[3], argv[4], argv[5]);
00904 didOne=1;
00905 }
00906
00907 if (strcmp(argv[1],"rmrule")==0) {
00908 status = testDelRule(Comm, argv[2], argv[3]);
00909 didOne=1;
00910 }
00911
00912 if (strcmp(argv[1],"modrfs")==0) {
00913 status = testModResourceFreeSpace(Comm, argv[2], argv[3], argv[4]);
00914 didOne=1;
00915 }
00916
00917 if (strcmp(argv[1],"rep")==0) {
00918 if (argc < 6) {
00919 printf("too few arguments\n");
00920 exit(1);
00921 }
00922 status = testRegReplica(Comm, argv[2], argv[3], argv[4], argv[5]);
00923 didOne=1;
00924 }
00925
00926
00927
00928
00929
00930
00931
00932
00933 if (strcmp(argv[1],"rmuser")==0) {
00934 status = testDelUser(Comm, argv[2], argv[3]);
00935 didOne=1;
00936 }
00937
00938 if (strcmp(argv[1],"mkdir")==0) {
00939 status = testRegColl(Comm, argv[2]);
00940 didOne=1;
00941 }
00942
00943 if (strcmp(argv[1],"rmdir")==0) {
00944 status = testDelColl(Comm, argv[2]);
00945 didOne=1;
00946 }
00947
00948 if (strcmp(argv[1],"sql")==0) {
00949 status = testSimpleQ(Comm, argv[2], argv[3], argv[4]);
00950 didOne=1;
00951 }
00952
00953 if (strcmp(argv[1],"rm")==0) {
00954 status = testDelFile(Comm, argv[2], argv[3]);
00955 didOne=1;
00956 }
00957
00958 if (strcmp(argv[1],"rmtrash")==0) {
00959 status = testDelFileTrash(Comm, argv[2], argv[3]);
00960 didOne=1;
00961 }
00962
00963 if (strcmp(argv[1],"rmpriv")==0) {
00964 status = testDelFilePriv(Comm, argv[2], argv[3], argv[4]);
00965 didOne=1;
00966 }
00967
00968 if (strcmp(argv[1],"chmod")==0) {
00969 status = testChmod(Comm, argv[2], argv[3], argv[4], argv[5]);
00970 didOne=1;
00971 }
00972
00973 if (strcmp(argv[1],"regrule")==0) {
00974 status = testRegRule(Comm, argv[2]);
00975 didOne=1;
00976 }
00977
00978 if (strcmp(argv[1],"rename")==0) {
00979 status = testRename(Comm, argv[2], argv[3]);
00980 testCurrent(Comm);
00981
00982 didOne=1;
00983 }
00984
00985 if (strcmp(argv[1],"login")==0) {
00986 status = testLogin(Comm, argv[2], argv[3], argv[4]);
00987 didOne=1;
00988 }
00989
00990 if (strcmp(argv[1],"move")==0) {
00991 status = testMove(Comm, argv[2], argv[3]);
00992 didOne=1;
00993 }
00994
00995 if (strcmp(argv[1],"checkauth")==0) {
00996 status = testCheckAuth(Comm, argv[2], argv[3], argv[4]);
00997 didOne=1;
00998 }
00999
01000 if (strcmp(argv[1],"temppw")==0) {
01001 status = testTempPw(Comm);
01002 didOne=1;
01003 }
01004
01005 if (strcmp(argv[1],"tpc")==0) {
01006 status = testTempPwConvert(argv[2], argv[3]);
01007 didOne=1;
01008 }
01009
01010 if (strcmp(argv[1],"tpw")==0) {
01011 status = testTempPwCombined(Comm, argv[2]);
01012 didOne=1;
01013 }
01014
01015 if (strcmp(argv[1],"serverload")==0) {
01016 status = testServerLoad(Comm, argv[2]);
01017 didOne=1;
01018 }
01019
01020 if (strcmp(argv[1],"purgeload")==0) {
01021 status = testPurgeServerLoad(Comm, argv[2]);
01022 didOne=1;
01023 }
01024
01025 if (strcmp(argv[1],"serverdigest")==0) {
01026 status = testServerLoadDigest(Comm, argv[2]);
01027 didOne=1;
01028 }
01029
01030 if (strcmp(argv[1],"purgedigest")==0) {
01031 status = testPurgeServerLoadDigest(Comm, argv[2]);
01032 didOne=1;
01033 }
01034
01035 if (strcmp(argv[1],"checkquota")==0) {
01036 if (argc < 5) {
01037 status = testCheckQuota(Comm, argv[2], argv[3],
01038 NULL, NULL);
01039 }
01040 else {
01041 status = testCheckQuota(Comm, argv[2], argv[3],
01042 argv[4], argv[5]);
01043 }
01044 didOne=1;
01045 }
01046
01047 if (strcmp(argv[1],"open")==0) {
01048 int i;
01049 for (i=0;i<3;i++) {
01050 status = chlClose();
01051 if (status) {
01052 printf ("close %d error", i);
01053 }
01054
01055 if ((status = chlOpen(serverConfig.DBUsername,
01056 serverConfig.DBPassword)) != 0) {
01057 rodsLog (LOG_SYS_FATAL,
01058 "initInfoWithRcat: chlopen %d Error. Status = %d",
01059 i, status);
01060 return (status);
01061 }
01062 }
01063 didOne=1;
01064 }
01065
01066 if (strcmp(argv[1],"addrule")==0) {
01067 status = testAddRule(Comm, argv[2], argv[3],
01068 argv[4], argv[5],
01069 argv[6], argv[7]);
01070 didOne=1;
01071 }
01072
01073 if (strcmp(argv[1],"versionrulebase")==0) {
01074 status = testVersionRuleBase(Comm, argv[2]);
01075 didOne=1;
01076 }
01077
01078 if (strcmp(argv[1],"versiondvmbase")==0) {
01079 status = testVersionDvmBase(Comm, argv[2]);
01080 didOne=1;
01081 }
01082
01083 if (strcmp(argv[1],"versionfnmbase")==0) {
01084 status = testVersionFnmBase(Comm, argv[2]);
01085 didOne=1;
01086 }
01087
01088 if (strcmp(argv[1],"insfnmtable")==0) {
01089 status = testInsFnmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
01090 didOne=1;
01091 }
01092
01093 if (strcmp(argv[1],"insdvmtable")==0) {
01094 status = testInsDvmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
01095 didOne=1;
01096 }
01097
01098 if (strcmp(argv[1],"insmsrvctable")==0) {
01099 status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
01100 argv[6], argv[7], argv[8], argv[9], argv[10]);
01101 if (status==0) {
01102
01103
01104
01105
01106 status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
01107 argv[6], argv[7], argv[8], argv[9], argv[10]);
01108 }
01109 didOne=1;
01110 }
01111
01112 if (status != 0) {
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126 myName = rodsErrorName(status, &mySubName);
01127 rodsLog (LOG_ERROR, "%s failed with error %d %s %s", argv[1],
01128 status, myName, mySubName);
01129 }
01130 else {
01131 if (didOne) printf("Completed successfully\n");
01132 }
01133
01134 if (didOne==0) {
01135 printf("Unknown test type: %s\n", argv[1]);
01136 }
01137
01138 exit(status);
01139 }