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