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