00001
00002
00003
00004
00005 #ifndef windows_platform
00006
00007 #include <sys/types.h>
00008 #include <sys/wait.h>
00009 #endif
00010 #include "objMetaOpr.h"
00011 #include "resource.h"
00012 #include "collection.h"
00013 #include "specColl.h"
00014 #if 0
00015 #include "modDataObjMeta.h"
00016 #include "ruleExecSubmit.h"
00017 #include "ruleExecDel.h"
00018 #include "reSysDataObjOpr.h"
00019 #endif
00020 #include "genQuery.h"
00021 #include "icatHighLevelRoutines.h"
00022 #include "miscUtil.h"
00023 #include "rodsClient.h"
00024 #include "rsIcatOpr.h"
00025
00026
00027
00028 #include "eirods_resource_redirect.h"
00029 #include "eirods_hierarchy_parser.h"
00030
00031 int
00032 svrCloseQueryOut (rsComm_t *rsComm, genQueryOut_t *genQueryOut)
00033 {
00034 genQueryInp_t genQueryInp;
00035 genQueryOut_t *junk = NULL;
00036 int status;
00037
00038 if (genQueryOut->continueInx <= 0) {
00039 return (0);
00040 }
00041
00042 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00043
00044
00045 genQueryInp.maxRows = 0;;
00046 genQueryInp.continueInx = genQueryOut->continueInx;
00047
00048 status = rsGenQuery (rsComm, &genQueryInp, &junk);
00049
00050 return (status);
00051 }
00052
00053 int
00054 isData (rsComm_t *rsComm, char *objName, rodsLong_t *dataId)
00055 {
00056 genQueryInp_t genQueryInp;
00057 genQueryOut_t *genQueryOut = NULL;
00058 char tmpStr[MAX_NAME_LEN];
00059 char logicalEndName[MAX_NAME_LEN];
00060 char logicalParentDirName[MAX_NAME_LEN];
00061 int status;
00062
00063 status = splitPathByKey(objName,
00064 logicalParentDirName, logicalEndName, '/');
00065 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00066 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName);
00067 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr);
00068 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00069 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName);
00070 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
00071 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00072 genQueryInp.maxRows = 2;
00073 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00074 if (status >= 0) {
00075 sqlResult_t *dataIdRes;
00076
00077 if ((dataIdRes = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) ==
00078 NULL) {
00079 rodsLog (LOG_ERROR,
00080 "isData: getSqlResultByInx for COL_D_DATA_ID failed");
00081 return (UNMATCHED_KEY_OR_INDEX);
00082 }
00083 if (dataId != NULL) {
00084 *dataId = strtoll (dataIdRes->value, 0, 0);
00085 }
00086 freeGenQueryOut (&genQueryOut);
00087 }
00088
00089 clearGenQueryInp (&genQueryInp);
00090 return(status);
00091 }
00092
00093 int
00094 getPhyPath (
00095 rsComm_t* _comm,
00096 char* _obj_name,
00097 char* _resource,
00098 char* _phy_path,
00099 char* _resc_hier ) {
00100
00101
00102
00103
00104
00105
00106
00107 std::string resc_hier;
00108 dataObjInp_t data_inp;
00109 memset( &data_inp, 0, sizeof( data_inp ) );
00110 strncpy( data_inp.objPath, _obj_name, MAX_NAME_LEN );
00111 eirods::error ret = eirods::resolve_resource_hierarchy(
00112 eirods::EIRODS_OPEN_OPERATION,
00113 _comm,
00114 &data_inp,
00115 resc_hier );
00116 if( ret.ok() ) {
00117 std::string root_resc;
00118 eirods::hierarchy_parser parser;
00119 parser.set_string( resc_hier );
00120 parser.first_resc( root_resc );
00121
00122
00123
00124
00125 genQueryOut_t* gen_out = NULL;
00126 char tmp_str [ MAX_NAME_LEN ];
00127 char logical_end_name [ MAX_NAME_LEN ];
00128 char logical_parent_dir_name[ MAX_NAME_LEN ];
00129
00130
00131
00132 int status = splitPathByKey(
00133 _obj_name,
00134 logical_parent_dir_name,
00135 logical_end_name, '/' );
00136
00137 genQueryInp_t gen_inp;
00138 memset( &gen_inp, 0, sizeof( genQueryInp_t ) );
00139
00140
00141
00142 snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_end_name );
00143 addInxVal( &gen_inp.sqlCondInp, COL_DATA_NAME, tmp_str );
00144
00145
00146
00147 snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_parent_dir_name );
00148 addInxVal( &gen_inp.sqlCondInp, COL_COLL_NAME, tmp_str );
00149
00150
00151
00152 snprintf( tmp_str, MAX_NAME_LEN, "='%s'", resc_hier.c_str() );
00153 addInxVal( &gen_inp.sqlCondInp, COL_D_RESC_HIER, tmp_str );
00154
00155
00156
00157 addInxIval( &gen_inp.selectInp, COL_D_DATA_PATH, 1 );
00158
00159
00160
00161 gen_inp.maxRows = 2;
00162 status = rsGenQuery( _comm, &gen_inp, &gen_out );
00163 if( status >= 0 ) {
00164
00165
00166 sqlResult_t* phy_path_res = getSqlResultByInx( gen_out, COL_D_DATA_PATH );
00167 if( !phy_path_res ) {
00168 rodsLog (LOG_ERROR,
00169 "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed");
00170 return (UNMATCHED_KEY_OR_INDEX);
00171 }
00172
00173
00174
00175 strncpy( _phy_path, phy_path_res->value, MAX_NAME_LEN );
00176 strncpy( _resource, root_resc.c_str(), root_resc.size() );
00177 strncpy( _resc_hier, resc_hier.c_str(), resc_hier.size() );
00178
00179 freeGenQueryOut( &gen_out );
00180 }
00181
00182 clearGenQueryInp( &gen_inp );
00183
00184 return status;
00185
00186 } else {
00187 eirods::log( PASS( ret ) );
00188 return -1;
00189 }
00190
00191 #if 0
00192 else {
00193 eirods::log( PASS( ret ) );
00194
00195 genQueryOut_t* gen_out = NULL;
00196 char tmp_str [ MAX_NAME_LEN ];
00197 char logical_end_name [ MAX_NAME_LEN ];
00198 char logical_parent_dir_name[ MAX_NAME_LEN ];
00199
00200
00201
00202 int status = splitPathByKey(
00203 _obj_name,
00204 logical_parent_dir_name,
00205 logical_end_name, '/' );
00206 genQueryInp_t gen_inp;
00207 memset( &gen_inp, 0, sizeof( genQueryInp_t ) );
00208
00209
00210
00211 snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_end_name );
00212 addInxVal( &gen_inp.sqlCondInp, COL_DATA_NAME, tmp_str );
00213
00214
00215
00216 snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_parent_dir_name );
00217 addInxVal( &gen_inp.sqlCondInp, COL_COLL_NAME, tmp_str );
00218
00219
00220
00221 addInxIval( &gen_inp.selectInp, COL_D_DATA_PATH, 1 );
00222 addInxIval( &gen_inp.selectInp, COL_D_RESC_HIER, 1 );
00223
00224
00225
00226 gen_inp.maxRows = 2;
00227 status = rsGenQuery( _comm, &gen_inp, &gen_out );
00228 if( status >= 0 ) {
00229
00230
00231 sqlResult_t * phy_path_res = NULL;
00232 if (( phy_path_res = getSqlResultByInx ( gen_out, COL_D_DATA_PATH)) ==
00233 NULL) {
00234 rodsLog (LOG_ERROR,
00235 "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed");
00236 return (UNMATCHED_KEY_OR_INDEX);
00237 }
00238 if ( _phy_path != NULL) {
00239 rstrcpy ( _phy_path, phy_path_res->value, MAX_NAME_LEN );
00240 }
00241 sqlResult_t *resc_hier_resc = NULL;
00242 if ((resc_hier_resc = getSqlResultByInx ( gen_out, COL_D_RESC_HIER)) ==
00243 NULL) {
00244 rodsLog (LOG_ERROR,
00245 "getPhyPath: getSqlResultByInx for COL_D_RESC_HIER failed");
00246 return (UNMATCHED_KEY_OR_INDEX);
00247 }
00248 if ( _resc_hier != NULL) {
00249 rstrcpy (_resc_hier, resc_hier_resc->value, MAX_NAME_LEN);
00250
00251 }
00252 freeGenQueryOut (&gen_out);
00253 } else {
00254 rodsLog (LOG_ERROR,
00255 "getPhyPath: genQuery Failed" );
00256 }
00257
00258 clearGenQueryInp (&gen_inp);
00259 return(status);
00260
00261 }
00262 #endif
00263 }
00264
00265 int
00266 isCollAllKinds (rsComm_t *rsComm, char *objName, rodsLong_t *collId)
00267 {
00268 dataObjInp_t dataObjInp;
00269 int status;
00270 rodsObjStat_t *rodsObjStatOut = NULL;
00271
00272 bzero (&dataObjInp, sizeof (dataObjInp));
00273 rstrcpy (dataObjInp.objPath, objName, MAX_NAME_LEN);
00274 status = collStatAllKinds (rsComm, &dataObjInp, &rodsObjStatOut);
00275 if (status >= 0 && collId != NULL && NULL != rodsObjStatOut) {
00276 *collId = strtoll (rodsObjStatOut->dataId, 0, 0);
00277 }
00278 if (rodsObjStatOut != NULL)
00279 freeRodsObjStat (rodsObjStatOut);
00280 return status;
00281 }
00282
00283 int
00284 isColl (rsComm_t *rsComm, char *objName, rodsLong_t *collId)
00285 {
00286 genQueryInp_t genQueryInp;
00287 genQueryOut_t *genQueryOut = NULL;
00288 char tmpStr[MAX_NAME_LEN];
00289 int status;
00290
00291 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00292 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", objName);
00293 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
00294 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00295 genQueryInp.maxRows = 2;
00296 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00297 if (status >= 0) {
00298 sqlResult_t *collIdRes;
00299
00300 if ((collIdRes = getSqlResultByInx (genQueryOut, COL_COLL_ID)) ==
00301 NULL) {
00302 rodsLog (LOG_ERROR,
00303 "isColl: getSqlResultByInx for COL_D_DATA_ID failed");
00304 return (UNMATCHED_KEY_OR_INDEX);
00305 }
00306
00307 if (collId != NULL) {
00308 *collId = strtoll (collIdRes->value, 0, 0);
00309 }
00310 freeGenQueryOut (&genQueryOut);
00311 }
00312
00313 clearGenQueryInp (&genQueryInp);
00314 return(status);
00315 }
00316
00317 int
00318 isUser(rsComm_t *rsComm, char *objName)
00319 {
00320 genQueryInp_t genQueryInp;
00321 genQueryOut_t *genQueryOut = NULL;
00322 char tmpStr[NAME_LEN];
00323 int status;
00324
00325 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00326 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00327 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr);
00328 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
00329 genQueryInp.maxRows = 2;
00330 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00331 freeGenQueryOut (&genQueryOut);
00332 clearGenQueryInp (&genQueryInp);
00333 return(status);
00334 }
00335
00336 int
00337 isResc (rsComm_t *rsComm, char *objName)
00338 {
00339 genQueryInp_t genQueryInp;
00340 genQueryOut_t *genQueryOut = NULL;
00341 char tmpStr[NAME_LEN];
00342 int status;
00343
00344 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00345 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00346 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, tmpStr);
00347 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00348 genQueryInp.maxRows = 2;
00349 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00350 freeGenQueryOut (&genQueryOut);
00351 clearGenQueryInp (&genQueryInp);
00352 return(status);
00353 }
00354
00355 int
00356 isRescGroup (rsComm_t *rsComm, char *objName)
00357 {
00358 genQueryInp_t genQueryInp;
00359 genQueryOut_t *genQueryOut = NULL;
00360 char tmpStr[NAME_LEN];
00361 int status;
00362
00363 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00364 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00365 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_GROUP_NAME, tmpStr);
00366 addInxIval (&genQueryInp.selectInp, COL_RESC_GROUP_ID, 1);
00367 genQueryInp.maxRows = 2;
00368 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00369 freeGenQueryOut (&genQueryOut);
00370 clearGenQueryInp (&genQueryInp);
00371 return(status);
00372 }
00373
00374 int
00375 isMeta(rsComm_t *rsComm, char *objName)
00376 {
00377
00378 return(INVALID_OBJECT_TYPE);
00379 }
00380
00381 int
00382 isToken(rsComm_t *rsComm, char *objName)
00383 {
00384
00385 return(INVALID_OBJECT_TYPE);
00386 }
00387
00388 int
00389 getObjType(rsComm_t *rsComm, char *objName, char * objType)
00390 {
00391 if (isData(rsComm, objName, NULL) >= 0)
00392 strcpy(objType,"-d");
00393 else if (isColl(rsComm, objName, NULL) >= 0)
00394 strcpy(objType,"-c");
00395 else if (isResc(rsComm, objName) == 0)
00396 strcpy(objType,"-r");
00397 else if (isRescGroup(rsComm, objName) == 0)
00398 strcpy(objType,"-g");
00399 else if (isUser(rsComm, objName) == 0)
00400 strcpy(objType,"-u");
00401 else if (isMeta(rsComm, objName) == 0)
00402 strcpy(objType,"-m");
00403 else if (isToken(rsComm, objName) == 0)
00404 strcpy(objType,"-t");
00405 else
00406 return(INVALID_OBJECT_TYPE);
00407 return (0);
00408 }
00409
00410 int
00411 addAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00412 keyValPair_t *kVP)
00413 {
00414 int i,j;
00415 char objType[10];
00416 modAVUMetadataInp_t modAVUMetadataInp;
00417
00418 bzero (&modAVUMetadataInp, sizeof (modAVUMetadataInp));
00419 if (strcmp(inObjType,"-1")) {
00420 strcpy(objType,inObjType);
00421 }
00422 else {
00423 i = getObjType(rsComm, objName,objType);
00424 if (i < 0)
00425 return(i);
00426 }
00427
00428 modAVUMetadataInp.arg0 = "add";
00429 for (i = 0; i < kVP->len ; i++) {
00430
00431
00432
00433
00434 modAVUMetadataInp.arg1 = objType;
00435 modAVUMetadataInp.arg2 = objName;
00436 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00437 modAVUMetadataInp.arg4 = kVP->value[i];
00438 modAVUMetadataInp.arg5 = "";
00439 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00440 if (j < 0)
00441 return(j);
00442 }
00443 return(0);
00444 }
00445
00446
00447 int
00448 setAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00449 keyValPair_t *kVP)
00450 {
00451 int i,j;
00452 char objType[10];
00453 modAVUMetadataInp_t modAVUMetadataInp;
00454
00455 bzero (&modAVUMetadataInp, sizeof(modAVUMetadataInp));
00456 if (strcmp(inObjType, "-1")) {
00457 strcpy(objType, inObjType);
00458 }
00459 else {
00460 i = getObjType(rsComm, objName, objType);
00461 if (i < 0)
00462 return(i);
00463 }
00464 for (i = 0; i < kVP->len ; i++) {
00465
00466
00467
00468
00469 modAVUMetadataInp.arg0 = "set";
00470 modAVUMetadataInp.arg1 = objType;
00471 modAVUMetadataInp.arg2 = objName;
00472 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00473 modAVUMetadataInp.arg4 = kVP->value[i];
00474 modAVUMetadataInp.arg5 = NULL;
00475 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00476 if (j < 0)
00477 return j;
00478 }
00479 return 0;
00480 }
00481
00482 int
00483 getStructFileType (specColl_t *specColl)
00484 {
00485 if (specColl == NULL) {
00486 return (-1);
00487 }
00488
00489 if (specColl->collClass == STRUCT_FILE_COLL) {
00490 return ((int) specColl->type);
00491 } else {
00492 return (-1);
00493 }
00494 }
00495
00496 int
00497 removeAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00498 keyValPair_t *kVP)
00499 {
00500 int i,j;
00501 char objType[10];
00502 modAVUMetadataInp_t modAVUMetadataInp;
00503
00504 if (strcmp(inObjType,"-1")) {
00505 strcpy(objType,inObjType);
00506 }
00507 else {
00508 i = getObjType(rsComm, objName,objType);
00509 if (i < 0)
00510 return(i);
00511 }
00512
00513 modAVUMetadataInp.arg0 = "rm";
00514 for (i = 0; i < kVP->len ; i++) {
00515
00516
00517
00518
00519 modAVUMetadataInp.arg1 = objType;
00520 modAVUMetadataInp.arg2 = objName;
00521 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00522 modAVUMetadataInp.arg4 = kVP->value[i];
00523 modAVUMetadataInp.arg5 = "";
00524 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00525 if (j < 0)
00526 return(j);
00527 }
00528 return(0);
00529 }
00530
00531 int
00532 getTokenId(rsComm_t *rsComm, char *tokenNameSpace, char *tokenName)
00533 {
00534
00535 genQueryInp_t genQueryInp;
00536 genQueryOut_t *genQueryOut = NULL;
00537 char tmpStr[MAX_NAME_LEN];
00538 char tmpStr2[MAX_NAME_LEN];
00539 int status;
00540
00541 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00542 snprintf (tmpStr, NAME_LEN, "='%s'", tokenNameSpace);
00543 snprintf (tmpStr2, NAME_LEN, "='%s'", tokenName);
00544 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, tmpStr);
00545 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAME, tmpStr2);
00546 addInxIval (&genQueryInp.selectInp, COL_TOKEN_ID, 1);
00547 genQueryInp.maxRows = 2;
00548 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00549 clearGenQueryInp (&genQueryInp);
00550 if (status >= 0) {
00551 sqlResult_t *tokenIdRes;
00552
00553 if ((tokenIdRes = getSqlResultByInx (genQueryOut, COL_TOKEN_ID)) ==
00554 NULL) {
00555 rodsLog (LOG_ERROR,
00556 "getTokenId: getSqlResultByInx for COL_TOKEN_ID failed");
00557 freeGenQueryOut (&genQueryOut);
00558 return (UNMATCHED_KEY_OR_INDEX);
00559 }
00560 status = atoi(tokenIdRes->value);
00561 freeGenQueryOut (&genQueryOut);
00562 }
00563 return(status);
00564 }
00565
00566 int
00567 getUserId(rsComm_t *rsComm, char *userName, char *zoneName)
00568 {
00569
00570 genQueryInp_t genQueryInp;
00571 genQueryOut_t *genQueryOut = NULL;
00572 char tmpStr[MAX_NAME_LEN];
00573 char tmpStr2[MAX_NAME_LEN];
00574 int status;
00575
00576 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00577 snprintf (tmpStr, NAME_LEN, "='%s'", userName);
00578 snprintf (tmpStr2, NAME_LEN, "='%s'", zoneName);
00579 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr);
00580 addInxVal (&genQueryInp.sqlCondInp, COL_USER_ZONE, tmpStr2);
00581 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
00582 genQueryInp.maxRows = 2;
00583 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00584 clearGenQueryInp (&genQueryInp);
00585 if (status >= 0) {
00586 sqlResult_t *userIdRes;
00587
00588 if ((userIdRes = getSqlResultByInx (genQueryOut, COL_USER_ID)) ==
00589 NULL) {
00590 rodsLog (LOG_ERROR,
00591 "getUserId: getSqlResultByInx for COL_USER_ID failed");
00592 freeGenQueryOut (&genQueryOut);
00593 return (UNMATCHED_KEY_OR_INDEX);
00594 }
00595 status = atoi(userIdRes->value);
00596 freeGenQueryOut (&genQueryOut);
00597 }
00598 return(status);
00599 }
00600
00601
00602 int
00603 checkPermitForDataObject(rsComm_t *rsComm, char *objName, int userId, int operId)
00604 {
00605 genQueryInp_t genQueryInp;
00606 genQueryOut_t *genQueryOut = NULL;
00607 char t1[MAX_NAME_LEN];
00608 char t11[MAX_NAME_LEN];
00609 char t2[MAX_NAME_LEN];
00610 char t3[MAX_NAME_LEN];
00611 char logicalEndName[MAX_NAME_LEN];
00612 char logicalParentDirName[MAX_NAME_LEN];
00613 int status;
00614
00615 status = splitPathByKey(objName,
00616 logicalParentDirName, logicalEndName, '/');
00617 snprintf (t1, MAX_NAME_LEN, " = '%s'", logicalEndName);
00618 snprintf (t11, MAX_NAME_LEN, " = '%s'", logicalParentDirName);
00619 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00620 snprintf (t3, MAX_NAME_LEN, " >= '%i' ", operId);
00621
00622 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00623 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00624 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, t1);
00625 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, t11);
00626 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_ACCESS_USER_ID, t2);
00627 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_ACCESS_TYPE, t3);
00628 genQueryInp.maxRows = 2;
00629 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00630 clearGenQueryInp (&genQueryInp);
00631 if (status >= 0) {
00632 freeGenQueryOut (&genQueryOut);
00633 return(1);
00634 }
00635 else
00636 return(0);
00637 }
00638
00639 int
00640 checkPermitForCollection(rsComm_t *rsComm, char *objName, int userId, int operId)
00641 {
00642 genQueryInp_t genQueryInp;
00643 genQueryOut_t *genQueryOut = NULL;
00644 char t1[MAX_NAME_LEN];
00645 char t2[MAX_NAME_LEN];
00646 char t4[MAX_NAME_LEN];
00647 int status;
00648
00649 snprintf (t1, MAX_NAME_LEN, " = '%s'", objName);
00650 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00651 snprintf (t4, MAX_NAME_LEN, " >= '%i' ", operId);
00652
00653 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00654 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00655 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, t1);
00656 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_ACCESS_USER_ID, t2);
00657 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_ACCESS_TYPE, t4);
00658 genQueryInp.maxRows = 2;
00659 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00660 clearGenQueryInp (&genQueryInp);
00661 if (status >= 0) {
00662 freeGenQueryOut (&genQueryOut);
00663 return(1);
00664 }
00665 else
00666 return(0);
00667 }
00668
00669 int
00670 checkPermitForResource(rsComm_t *rsComm, char *objName, int userId, int operId)
00671 {
00672 genQueryInp_t genQueryInp;
00673 genQueryOut_t *genQueryOut = NULL;
00674 char t1[MAX_NAME_LEN];
00675 char t2[MAX_NAME_LEN];
00676 char t4[MAX_NAME_LEN];
00677 int status;
00678
00679 snprintf (t1, MAX_NAME_LEN, " = '%s'", objName);
00680 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00681 snprintf (t4, MAX_NAME_LEN, " >= '%i' ", operId);
00682
00683 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00684 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00685 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, t1);
00686 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_ACCESS_USER_ID, t2);
00687 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_ACCESS_TYPE, t4);
00688 genQueryInp.maxRows = 2;
00689 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00690 clearGenQueryInp (&genQueryInp);
00691 if (status >= 0) {
00692 freeGenQueryOut (&genQueryOut);
00693 return(1);
00694 }
00695 else
00696 return(0);
00697 }
00698
00699
00700 int
00701 checkPermissionByObjType(rsComm_t *rsComm, char *objName, char *objType, char *user, char *zone, char *oper)
00702 {
00703 int i;
00704 int operId;
00705 int userId;
00706 operId = getTokenId(rsComm, "access_type", oper);
00707 if (operId < 0)
00708 return(operId);
00709
00710 userId = getUserId(rsComm, user, zone);
00711 if (userId < 0)
00712 return(userId);
00713
00714 if (!strcmp(objType,"-d"))
00715 i = checkPermitForDataObject(rsComm, objName, userId, operId);
00716 else if (!strcmp(objType,"-c"))
00717 i = checkPermitForCollection(rsComm, objName, userId, operId);
00718 else if (!strcmp(objType,"-r"))
00719 i = checkPermitForResource(rsComm, objName, userId, operId);
00720
00721
00722
00723
00724 else
00725 i = INVALID_OBJECT_TYPE;
00726 return(i);
00727 }
00728
00729
00730
00731
00732 int
00733 checkDupReplica (rsComm_t *rsComm, rodsLong_t dataId, char *rescName,
00734 char *filePath)
00735 {
00736 genQueryInp_t genQueryInp;
00737 genQueryOut_t *genQueryOut = NULL;
00738 char tmpStr[MAX_NAME_LEN];
00739 int status;
00740
00741 if (rsComm == NULL || rescName == NULL || filePath == NULL)
00742 return USER__NULL_INPUT_ERR;
00743
00744 bzero (&genQueryInp, sizeof (genQueryInp_t));
00745
00746 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", rescName);
00747 addInxVal (&genQueryInp.sqlCondInp, COL_D_RESC_NAME, tmpStr);
00748 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", filePath);
00749 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr);
00750 snprintf (tmpStr, MAX_NAME_LEN, "='%lld'", dataId);
00751 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr);
00752
00753 addInxIval (&genQueryInp.selectInp, COL_DATA_REPL_NUM, 1);
00754 genQueryInp.maxRows = 2;
00755 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00756 clearGenQueryInp (&genQueryInp);
00757 if (status >= 0) {
00758 int intReplNum;
00759 sqlResult_t *replNum;
00760 if ((replNum = getSqlResultByInx (genQueryOut, COL_DATA_REPL_NUM)) ==
00761 NULL) {
00762 rodsLog (LOG_ERROR,
00763 "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed");
00764 return (UNMATCHED_KEY_OR_INDEX);
00765 }
00766 intReplNum = atoi (replNum->value);
00767 freeGenQueryOut (&genQueryOut);
00768 return (intReplNum);
00769 } else {
00770 return status;
00771 }
00772 }
00773
00774
00775 int
00776 getNumSubfilesInBunfileObj (rsComm_t *rsComm, char *objPath)
00777 {
00778 int status;
00779 genQueryOut_t *genQueryOut = NULL;
00780 genQueryInp_t genQueryInp;
00781 int totalRowCount;
00782 char condStr[MAX_NAME_LEN];
00783
00784 bzero (&genQueryInp, sizeof (genQueryInp));
00785 genQueryInp.maxRows = 1;
00786 genQueryInp.options = RETURN_TOTAL_ROW_COUNT;
00787
00788 snprintf (condStr, MAX_NAME_LEN, "='%s'", objPath);
00789 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr);
00790 snprintf (condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS);
00791 addInxVal (&genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr);
00792 addKeyVal (&genQueryInp.condInput, ZONE_KW, objPath);
00793
00794 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00795 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
00796 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1);
00797
00798 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00799 if ( genQueryOut == NULL || status < 0) {
00800 clearGenQueryInp (&genQueryInp);
00801 if (status == CAT_NO_ROWS_FOUND) {
00802 return 0;
00803 } else {
00804 return status;
00805 }
00806 }
00807 totalRowCount = genQueryOut->totalRowCount;
00808 freeGenQueryOut (&genQueryOut);
00809
00810 genQueryInp.maxRows = 0;
00811 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00812 clearGenQueryInp (&genQueryInp);
00813
00814 return totalRowCount;
00815 }
00816
00817
00818