00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "eirods_error.h"
00022 #include "eirods_zone_info.h"
00023 #include "eirods_sql_logger.h"
00024 #include "eirods_string_tokenize.h"
00025 #include "eirods_log.h"
00026 #include "eirods_tmp_string.h"
00027 #include "eirods_children_parser.h"
00028 #include "eirods_stacktrace.h"
00029 #include "eirods_hierarchy_parser.h"
00030 #include "eirods_catalog_properties.h"
00031 #include "eirods_kvp_string_parser.h"
00032 #include "eirods_auth_object.h"
00033 #include "eirods_auth_factory.h"
00034 #include "eirods_auth_plugin.h"
00035 #include "eirods_auth_manager.h"
00036 #include "eirods_auth_constants.h"
00037
00038
00039
00040 #include "rods.h"
00041 #include "rcMisc.h"
00042 #include "icatMidLevelRoutines.h"
00043 #include "icatMidLevelHelpers.h"
00044 #include "icatHighLevelRoutines.h"
00045 #include "icatLowLevel.h"
00046
00047
00048
00049 #include <string>
00050 #include <iostream>
00051 #include <sstream>
00052 #include <vector>
00053 #include <boost/regex.hpp>
00054
00055 extern int get64RandomBytes(char *buf);
00056
00057 static char prevChalSig[200];
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #define AP_READ "read"
00086 #define AP_WRITE "write"
00087 #define AP_OWN "own"
00088 #define AP_NULL "null"
00089
00090 #define MAX_PASSWORDS 40
00091
00092
00093
00094
00095
00096
00097
00098 #define TEMP_PASSWORD_TIME 120
00099 #define TEMP_PASSWORD_MAX_TIME 1000
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 #define IRODS_PAM_PASSWORD_LEN 20
00110
00111
00112
00113
00114 #define IRODS_PAM_PASSWORD_MIN_TIME "121"
00115 #define IRODS_PAM_PASSWORD_MAX_TIME "1209600"
00116 #ifdef PAM_AUTH_NO_EXTEND
00117 #define IRODS_PAM_PASSWORD_DEFAULT_TIME "28800"
00118 #else
00119 #define IRODS_PAM_PASSWORD_DEFAULT_TIME "1209600"
00120 #endif
00121
00122 #define PASSWORD_SCRAMBLE_PREFIX ".E_"
00123 #define PASSWORD_KEY_ENV_VAR "irodsPKey"
00124 #define PASSWORD_DEFAULT_KEY "a9_3fker"
00125
00126 #define MAX_HOST_STR 2700
00127
00128 int logSQL=0;
00129
00130 static int _delColl(rsComm_t *rsComm, collInfo_t *collInfo);
00131 static int removeAVUs();
00132
00133 icatSessionStruct icss={0};
00134 char localZone[MAX_NAME_LEN]={""};
00135
00136 int creatingUserByGroupAdmin=0;
00137
00138
00139
00140
00141
00142 int chlDebug(char *debugMode) {
00143 if (strstr(debugMode, "SQL")) {
00144 logSQL=1;
00145 chlDebugGenQuery(1);
00146 chlDebugGenUpdate(1);
00147 cmlDebug(2);
00148 }
00149 else {
00150 if (strstr(debugMode, "sql")) {
00151 logSQL=1;
00152 chlDebugGenQuery(1);
00153 chlDebugGenUpdate(1);
00154 cmlDebug(1);
00155 }
00156 else {
00157 logSQL=0;
00158 chlDebugGenQuery(0);
00159 chlDebugGenUpdate(0);
00160 cmlDebug(0);
00161 }
00162 }
00163 return(0);
00164 }
00165
00166
00167
00168
00169
00170 static int
00171 icatDescramble(char *pw) {
00172 char *cp1, *cp2, *cp3;
00173 int i,len;
00174 char pw2[MAX_PASSWORD_LEN+10];
00175 char unscrambled[MAX_PASSWORD_LEN+10];
00176
00177 len = strlen(PASSWORD_SCRAMBLE_PREFIX);
00178 cp1=pw;
00179 cp2=PASSWORD_SCRAMBLE_PREFIX;
00180 for (i=0;i<len;i++) {
00181 if (*cp1++ != *cp2++) {
00182 return 0;
00183 }
00184 }
00185 strncpy(pw2, cp1, MAX_PASSWORD_LEN);
00186 cp3 = getenv(PASSWORD_KEY_ENV_VAR);
00187 if (cp3==NULL) {
00188 cp3 = PASSWORD_DEFAULT_KEY;
00189 }
00190 obfDecodeByKey(pw2, cp3, unscrambled);
00191 strncpy(pw, unscrambled, MAX_PASSWORD_LEN);
00192
00193 return 0;
00194 }
00195
00196
00197
00198
00199
00200 static int
00201 icatScramble(char *pw) {
00202 char *cp1;
00203 char newPw[MAX_PASSWORD_LEN+10];
00204 char scrambled[MAX_PASSWORD_LEN+10];
00205
00206 cp1 = getenv(PASSWORD_KEY_ENV_VAR);
00207 if (cp1==NULL) {
00208 cp1 = PASSWORD_DEFAULT_KEY;
00209 }
00210 obfEncodeByKey(pw, cp1, scrambled);
00211 strncpy(newPw, PASSWORD_SCRAMBLE_PREFIX, MAX_PASSWORD_LEN);
00212 strncat(newPw, scrambled, MAX_PASSWORD_LEN);
00213 strncpy(pw, newPw, MAX_PASSWORD_LEN);
00214 return 0;
00215 }
00216
00217
00218
00219
00220
00221 int chlOpen(char *DBUser, char *DBpasswd) {
00222 int i;
00223 if (logSQL!=0) rodsLog(LOG_SQL, "chlOpen");
00224 strncpy(icss.databaseUsername, DBUser, DB_USERNAME_LEN);
00225 strncpy(icss.databasePassword, DBpasswd, DB_PASSWORD_LEN);
00226 i = cmlOpen(&icss);
00227 if (i != 0) {
00228 rodsLog(LOG_NOTICE, "chlOpen cmlOpen failure %d",i);
00229 }
00230 else {
00231 icss.status=1;
00232
00233
00234 eirods::catalog_properties::getInstance().capture();
00235 }
00236
00237 return(i);
00238 }
00239
00240
00241
00242
00243
00244 int chlClose() {
00245 int i;
00246
00247 i = cmlClose(&icss);
00248 if (i == 0) icss.status=0;
00249 return(i);
00250 }
00251
00252 int chlIsConnected() {
00253 if (logSQL!=0) rodsLog(LOG_SQL, "chlIsConnected");
00254 return(icss.status);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264 icatSessionStruct *
00265 chlGetRcs()
00266 {
00267 if (logSQL!=0) rodsLog(LOG_SQL, "chlGetRcs");
00268 if (icss.status != 1) {
00269 return(NULL);
00270 }
00271 return(&icss);
00272 }
00273
00274
00275
00276
00277 int
00278 _rollback(const char *functionName) {
00279 int status;
00280 #if ORA_ICAT
00281 status = 0;
00282 #else
00283
00284
00285 status = cmlExecuteNoAnswerSql("rollback", &icss);
00286 if (status == 0) {
00287 rodsLog(LOG_NOTICE,
00288 "%s cmlExecuteNoAnswerSql(rollback) succeeded", functionName);
00289 }
00290 else {
00291 rodsLog(LOG_NOTICE,
00292 "%s cmlExecuteNoAnswerSql(rollback) failure %d",
00293 functionName, status);
00294 }
00295 #endif
00296
00297 return(status);
00298 }
00299
00300
00301
00302
00303
00304
00305
00306 int
00307 getLocalZone()
00308 {
00309 std::string local_zone;
00310 eirods::error e = eirods::zone_info::get_instance()->get_local_zone(icss, logSQL, local_zone);
00311 strncpy(localZone, local_zone.c_str(), MAX_NAME_LEN);
00312 return e.code();
00313 }
00314
00315
00316
00317
00318
00319 char *
00320 chlGetLocalZone() {
00321 getLocalZone();
00322 return(localZone);
00323 }
00324
00325
00326
00327
00328 static int
00329 _updateRescObjCount(
00330 const std::string& _resc_name,
00331 const std::string& _zone,
00332 int _amount) {
00333
00334 int result = 0;
00335 int status;
00336 char resc_id[MAX_NAME_LEN];
00337 char myTime[50];
00338 eirods::sql_logger logger(__FUNCTION__, logSQL);
00339 eirods::hierarchy_parser hparse;
00340
00341 resc_id[0] = '\0';
00342
00343 std::stringstream ss;
00344 if((status = cmlGetStringValueFromSql("select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
00345 resc_id, MAX_NAME_LEN, _resc_name.c_str(), _zone.c_str(), 0,
00346 &icss)) != 0) {
00347 if(status == CAT_NO_ROWS_FOUND) {
00348 result = CAT_INVALID_RESOURCE;
00349 } else {
00350 _rollback(__FUNCTION__);
00351 result = status;
00352 }
00353 } else {
00354 std::stringstream ss;
00355 ss << "update R_RESC_MAIN set resc_objcount=resc_objcount+";
00356 ss << _amount;
00357 ss << ", modify_ts=? where resc_id=?";
00358 getNowStr(myTime);
00359 cllBindVarCount = 0;
00360 cllBindVars[cllBindVarCount++] = myTime;
00361 cllBindVars[cllBindVarCount++] = resc_id;
00362 if((status = cmlExecuteNoAnswerSql(ss.str().c_str(), &icss)) != 0) {
00363 std::stringstream ss;
00364 ss << __FUNCTION__ << " cmlExecuteNoAnswerSql update failure " << status;
00365 eirods::log(LOG_NOTICE, ss.str());
00366 _rollback(__FUNCTION__);
00367 result = status;
00368 }
00369 }
00370 return result;
00371 }
00372
00373
00374
00375
00376 static int
00377 _updateObjCountOfResources(
00378 const std::string _resc_hier,
00379 const std::string _zone,
00380 int _amount) {
00381 int result = 0;
00382 eirods::hierarchy_parser hparse;
00383
00384 hparse.set_string(_resc_hier);
00385 for(eirods::hierarchy_parser::const_iterator it = hparse.begin();
00386 result == 0 && it != hparse.end(); ++it) {
00387 result = _updateRescObjCount(*it, _zone, _amount);
00388 }
00389 return result;
00390 }
00391
00392
00393
00394
00395 int
00396 chlUpdateRescObjCount(
00397 const std::string& _resc,
00398 int _delta) {
00399
00400 int result = 0;
00401 int ret;
00402 if((ret = getLocalZone()) != 0) {
00403 std::stringstream msg;
00404 msg << __FUNCTION__ << " - Failed to set the local zone.";
00405 eirods::log(LOG_ERROR, msg.str());
00406 result = ret;
00407 } else if((ret = _updateRescObjCount(_resc, localZone, _delta)) != 0) {
00408 std::stringstream msg;
00409 msg << __FUNCTION__ << " - Failed to update the object count for resource \"" << _resc << "\"";
00410 eirods::log(LOG_ERROR, msg.str());
00411 result = ret;
00412 }
00413
00414 return result;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 int chlModDataObjMeta(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
00431 keyValPair_t *regParam) {
00432 int i, j, status, upCols;
00433 rodsLong_t iVal = 0;
00434 int status2;
00435
00436 int mode=0;
00437
00438 char logicalFileName[MAX_NAME_LEN];
00439 char logicalDirName[MAX_NAME_LEN];
00440 char *theVal;
00441 char replNum1[MAX_NAME_LEN];
00442
00443 char *whereColsAndConds[10];
00444 char *whereValues[10];
00445 char idVal[MAX_NAME_LEN];
00446 int numConditions;
00447 char oldCopy[NAME_LEN];
00448 char newCopy[NAME_LEN];
00449 int adminMode;
00450
00451 int maxCols=90;
00452 char *updateCols[90];
00453 char *updateVals[90];
00454
00455
00456
00457
00458 int dataTypeIndex=1;
00459
00460 char *regParamNames[]={
00461 REPL_NUM_KW, DATA_TYPE_KW, DATA_SIZE_KW,
00462 RESC_NAME_KW,FILE_PATH_KW, DATA_OWNER_KW, DATA_OWNER_ZONE_KW,
00463 REPL_STATUS_KW, CHKSUM_KW, DATA_EXPIRY_KW,
00464 DATA_COMMENTS_KW, DATA_CREATE_KW, DATA_MODIFY_KW, RESC_GROUP_NAME_KW,
00465 DATA_MODE_KW, RESC_HIER_STR_KW, "END"
00466 };
00467
00468
00469
00470 char *colNames[]={
00471 "data_repl_num", "data_type_name", "data_size",
00472 "resc_name", "data_path", "data_owner_name", "data_owner_zone",
00473 "data_is_dirty", "data_checksum", "data_expiry_ts",
00474 "r_comment", "create_ts", "modify_ts", "resc_group_name",
00475 "data_mode", "resc_hier"
00476 };
00477 int DATA_EXPIRY_TS_IX=9;
00478 int MODIFY_TS_IX=12;
00479
00480 char objIdString[MAX_NAME_LEN];
00481 char *neededAccess;
00482
00483 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta");
00484
00485 if (regParam == NULL || dataObjInfo == NULL) {
00486 return (CAT_INVALID_ARGUMENT);
00487 }
00488
00489 adminMode=0;
00490 theVal = getValByKey(regParam, IRODS_ADMIN_KW);
00491 if (theVal != NULL) {
00492 adminMode=1;
00493 }
00494
00495
00496 for (i=0, j=0; i<maxCols; i++) {
00497 if (strcmp(regParamNames[i],"END")==0) break;
00498 theVal = getValByKey(regParam, regParamNames[i]);
00499 if (theVal != NULL) {
00500 updateCols[j]=colNames[i];
00501 updateVals[j]=theVal;
00502 if (i==DATA_EXPIRY_TS_IX) {
00503
00504
00505 if (strcmp(colNames[i],"data_expiry_ts") == 0) {
00506 if (strlen(theVal) < 11) {
00507 static char theVal2[20];
00508 time_t myTimeValue;
00509 myTimeValue=atoll(theVal);
00510 snprintf(theVal2, sizeof theVal2, "%011d", (int)myTimeValue);
00511 updateVals[j]=theVal2;
00512 }
00513 }
00514 }
00515
00516 if (i==MODIFY_TS_IX) {
00517
00518
00519 if (strcmp(colNames[i],"modify_ts") == 0) {
00520 if (strlen(theVal) < 11) {
00521 static char theVal3[20];
00522 time_t myTimeValue;
00523 myTimeValue=atoll(theVal);
00524 snprintf(theVal3, sizeof theVal3, "%011d", (int)myTimeValue);
00525 updateVals[j]=theVal3;
00526 }
00527 }
00528 }
00529
00530 j++;
00531
00532
00533 if (i==dataTypeIndex) {
00534 status = cmlCheckNameToken("data_type",
00535 theVal, &icss);
00536 if (status !=0 ) {
00537 std::stringstream msg;
00538 msg << __FUNCTION__;
00539 msg << " - Invalid data type specified.";
00540 addRErrorMsg (&rsComm->rError, 0, msg.str().c_str());
00541 return(CAT_INVALID_DATA_TYPE);
00542 }
00543 }
00544 }
00545 }
00546 upCols=j;
00547
00548
00549
00550
00551
00552
00553
00554 neededAccess = ACCESS_MODIFY_METADATA;
00555 if (upCols==1 && strcmp(updateCols[0],"chksum")==0) {
00556 neededAccess = ACCESS_READ_OBJECT;
00557 }
00558
00559
00560
00561 theVal = getValByKey(regParam, DATA_EXPIRY_KW);
00562 if (theVal != NULL) {
00563 neededAccess = ACCESS_DELETE_OBJECT;
00564 }
00565
00566 if (dataObjInfo->dataId <= 0) {
00567 status = splitPathByKey(dataObjInfo->objPath,
00568 logicalDirName, logicalFileName, '/');
00569
00570 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta SQL 1 ");
00571 status = cmlGetIntegerValueFromSql(
00572 "select coll_id from R_COLL_MAIN where coll_name=?", &iVal,
00573 logicalDirName, 0, 0, 0, 0, &icss);
00574
00575 if (status != 0) {
00576 char errMsg[105];
00577 snprintf(errMsg, 100, "collection '%s' is unknown",
00578 logicalDirName);
00579 addRErrorMsg (&rsComm->rError, 0, errMsg);
00580 _rollback("chlModDataObjMeta");
00581 return(CAT_UNKNOWN_COLLECTION);
00582 }
00583 snprintf(objIdString, MAX_NAME_LEN, "%lld", iVal);
00584
00585 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta SQL 2");
00586 status = cmlGetIntegerValueFromSql(
00587 "select data_id from R_DATA_MAIN where coll_id=? and data_name=?",
00588 &iVal, objIdString, logicalFileName, 0, 0, 0, &icss);
00589 if (status != 0) {
00590 std::stringstream msg;
00591 msg << __FUNCTION__;
00592 msg << " - Failed to find file in database by its logical path.";
00593 addRErrorMsg (&rsComm->rError, 0, msg.str().c_str());
00594 _rollback("chlModDataObjMeta");
00595 return(CAT_UNKNOWN_FILE);
00596 }
00597
00598 dataObjInfo->dataId = iVal;
00599
00600 }
00601
00602 snprintf(objIdString, MAX_NAME_LEN, "%lld", dataObjInfo->dataId);
00603
00604 if (adminMode) {
00605 if (rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
00606 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00607 }
00608 }
00609 else {
00610 status = cmlCheckDataObjId(objIdString, rsComm->clientUser.userName,
00611 rsComm->clientUser.rodsZone, neededAccess, &icss);
00612 if (status != 0) {
00613 theVal = getValByKey(regParam, ACL_COLLECTION_KW);
00614 if (theVal != NULL && dataObjInfo->objPath != NULL &&
00615 upCols==1 && strcmp(updateCols[0],"data_path")==0) {
00616 int len, iVal = 0;
00617
00618
00619
00620
00621 len = strlen(theVal);
00622 if (strncmp(theVal, dataObjInfo->objPath, len) == 0) {
00623
00624 iVal = cmlCheckDir(theVal,
00625 rsComm->clientUser.userName,
00626 rsComm->clientUser.rodsZone,
00627 ACCESS_OWN,
00628 &icss);
00629 }
00630 if (iVal > 0) status=0;
00631
00632 }
00633 if (status) {
00634 _rollback("chlModDataObjMeta");
00635 return(CAT_NO_ACCESS_PERMISSION);
00636 }
00637 }
00638 }
00639
00640 whereColsAndConds[0]="data_id=";
00641 snprintf(idVal, MAX_NAME_LEN, "%lld", dataObjInfo->dataId);
00642 whereValues[0]=idVal;
00643 numConditions=1;
00644
00645
00646
00647
00648
00649
00650 if (getValByKey(regParam, ALL_KW) == NULL) {
00651 j = numConditions;
00652 whereColsAndConds[j]="data_repl_num=";
00653 snprintf(replNum1, MAX_NAME_LEN, "%d", dataObjInfo->replNum);
00654 whereValues[j]=replNum1;
00655 numConditions++;
00656 }
00657
00658 mode =0;
00659 if (getValByKey(regParam, ALL_REPL_STATUS_KW)) {
00660 mode=1;
00661
00662 }
00663
00664 status = getLocalZone();
00665 if( status < 0 ) {
00666 rodsLog( LOG_ERROR, "chlModObjMeta - failed in getLocalZone with status [%d]", status );
00667 return status;
00668 }
00669
00670
00671
00672 char* new_resc_hier = getValByKey(regParam, RESC_HIER_STR_KW);
00673 if(new_resc_hier != NULL) {
00674 std::stringstream id_stream;
00675 id_stream << dataObjInfo->dataId;
00676 std::stringstream repl_stream;
00677 repl_stream << dataObjInfo->replNum;
00678 char resc_hier[MAX_NAME_LEN];
00679 if((status = cmlGetStringValueFromSql("select resc_hier from R_DATA_MAIN where data_id=? and data_repl_num=?",
00680 resc_hier, MAX_NAME_LEN, id_stream.str().c_str(), repl_stream.str().c_str(),
00681 0, &icss)) != 0) {
00682 std::stringstream msg;
00683 msg << __FUNCTION__;
00684 msg << " - Failed to get the resc hierarchy from object with id: ";
00685 msg << id_stream.str();
00686 msg << " and replNum: ";
00687 msg << repl_stream.str();
00688 eirods::log(LOG_NOTICE, msg.str());
00689 return status;
00690 }
00691
00692 else if((status = _updateObjCountOfResources(resc_hier, localZone, -1)) != 0) {
00693 return status;
00694 } else if((status = _updateObjCountOfResources(new_resc_hier, localZone, +1)) != 0) {
00695 return status;
00696 }
00697 }
00698
00699 if (mode == 0) {
00700 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta SQL 4");
00701 status = cmlModifySingleTable("R_DATA_MAIN", updateCols, updateVals,
00702 whereColsAndConds, whereValues, upCols,
00703 numConditions, &icss);
00704 } else {
00705
00706 j = upCols;
00707 updateCols[j]="data_is_dirty";
00708 snprintf(newCopy, NAME_LEN, "%d", NEWLY_CREATED_COPY);
00709 updateVals[j]=newCopy;
00710 upCols++;
00711 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta SQL 5");
00712 status = cmlModifySingleTable("R_DATA_MAIN", updateCols, updateVals,
00713 whereColsAndConds, whereValues, upCols,
00714 numConditions, &icss);
00715 if (status == 0) {
00716 j = numConditions-1;
00717 whereColsAndConds[j]="data_repl_num!=";
00718 snprintf(replNum1, MAX_NAME_LEN, "%d", dataObjInfo->replNum);
00719 whereValues[j]=replNum1;
00720
00721 updateCols[0]="data_is_dirty";
00722 snprintf(oldCopy, NAME_LEN, "%d", OLD_COPY);
00723 updateVals[0]=oldCopy;
00724 if (logSQL!=0) rodsLog(LOG_SQL, "chlModDataObjMeta SQL 6");
00725 status2 = cmlModifySingleTable("R_DATA_MAIN", updateCols, updateVals,
00726 whereColsAndConds, whereValues, 1,
00727 numConditions, &icss);
00728
00729 if (status2 != 0 && status2 != CAT_SUCCESS_BUT_WITH_NO_INFO) {
00730
00731 rodsLog(LOG_NOTICE,
00732 "chlModDataObjMeta cmlModifySingleTable failure for other replicas %d",
00733 status2);
00734 _rollback("chlModDataObjMeta");
00735 return(status2);
00736 }
00737
00738 }
00739 }
00740 if (status != 0) {
00741 _rollback("chlModDataObjMeta");
00742 rodsLog(LOG_NOTICE,
00743 "chlModDataObjMeta cmlModifySingleTable failure %d",
00744 status);
00745 return(status);
00746 }
00747
00748 if ( !(dataObjInfo->flags & NO_COMMIT_FLAG) ) {
00749 status = cmlExecuteNoAnswerSql("commit", &icss);
00750 if (status != 0) {
00751 rodsLog(LOG_NOTICE,
00752 "chlModDataObjMeta cmlExecuteNoAnswerSql commit failure %d",
00753 status);
00754 return(status);
00755 }
00756 }
00757 return status;
00758 }
00759
00760
00761
00762
00763
00764
00765 int chlRegDataObj(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo) {
00766 char myTime[50];
00767 char logicalFileName[MAX_NAME_LEN];
00768 char logicalDirName[MAX_NAME_LEN];
00769 rodsLong_t seqNum;
00770 rodsLong_t iVal;
00771 char dataIdNum[MAX_NAME_LEN];
00772 char collIdNum[MAX_NAME_LEN];
00773 char dataReplNum[MAX_NAME_LEN];
00774 char dataSizeNum[MAX_NAME_LEN];
00775 char dataStatusNum[MAX_NAME_LEN];
00776 int status;
00777 int inheritFlag;
00778
00779 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj");
00780 if (!icss.status) {
00781 return(CATALOG_NOT_CONNECTED);
00782 }
00783
00784 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 1 ");
00785 seqNum = cmlGetNextSeqVal(&icss);
00786 if (seqNum < 0) {
00787 rodsLog(LOG_NOTICE, "chlRegDataObj cmlGetNextSeqVal failure %d",
00788 seqNum);
00789 _rollback("chlRegDataObj");
00790 return(seqNum);
00791 }
00792 snprintf(dataIdNum, MAX_NAME_LEN, "%lld", seqNum);
00793 dataObjInfo->dataId=seqNum;
00794
00795 status = splitPathByKey(dataObjInfo->objPath,
00796 logicalDirName, logicalFileName, '/');
00797
00798
00799
00800
00801 iVal = cmlCheckDirAndGetInheritFlag(logicalDirName,
00802 rsComm->clientUser.userName,
00803 rsComm->clientUser.rodsZone,
00804 ACCESS_MODIFY_OBJECT, &inheritFlag, &icss);
00805 if (iVal < 0) {
00806 char errMsg[105];
00807 if (iVal==CAT_UNKNOWN_COLLECTION) {
00808 snprintf(errMsg, 100, "collection '%s' is unknown",
00809 logicalDirName);
00810 addRErrorMsg (&rsComm->rError, 0, errMsg);
00811 }
00812 if (iVal==CAT_NO_ACCESS_PERMISSION) {
00813 snprintf(errMsg, 100, "no permission to update collection '%s'",
00814 logicalDirName);
00815 addRErrorMsg (&rsComm->rError, 0, errMsg);
00816 }
00817 return (iVal);
00818 }
00819 snprintf(collIdNum, MAX_NAME_LEN, "%lld", iVal);
00820
00821
00822 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 4");
00823 status = cmlGetIntegerValueFromSql(
00824 "select coll_id from R_COLL_MAIN where coll_name=?",
00825 &iVal,
00826 dataObjInfo->objPath, 0, 0, 0, 0, &icss);
00827 if (status == 0) {
00828 return(CAT_NAME_EXISTS_AS_COLLECTION);
00829 }
00830
00831 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 5");
00832 status = cmlCheckNameToken("data_type",
00833 dataObjInfo->dataType, &icss);
00834 if (status !=0 ) {
00835 return(CAT_INVALID_DATA_TYPE);
00836 }
00837
00838 snprintf(dataReplNum, MAX_NAME_LEN, "%d", dataObjInfo->replNum);
00839 snprintf(dataStatusNum, MAX_NAME_LEN, "%d", dataObjInfo->replStatus);
00840 snprintf(dataSizeNum, MAX_NAME_LEN, "%lld", dataObjInfo->dataSize);
00841 getNowStr(myTime);
00842 cllBindVars[0]=dataIdNum;
00843 cllBindVars[1]=collIdNum;
00844 cllBindVars[2]=logicalFileName;
00845 cllBindVars[3]=dataReplNum;
00846 cllBindVars[4]=dataObjInfo->version;
00847 cllBindVars[5]=dataObjInfo->dataType;
00848 cllBindVars[6]=dataSizeNum;
00849 cllBindVars[7]=dataObjInfo->rescGroupName;
00850 cllBindVars[8]=dataObjInfo->rescName;
00851 cllBindVars[9]=dataObjInfo->rescHier;
00852 cllBindVars[10]=dataObjInfo->filePath;
00853 cllBindVars[11]=rsComm->clientUser.userName;
00854 cllBindVars[12]=rsComm->clientUser.rodsZone;
00855 cllBindVars[13]=dataStatusNum;
00856 cllBindVars[14]=dataObjInfo->chksum;
00857 cllBindVars[15]=dataObjInfo->dataMode;
00858 cllBindVars[16]=myTime;
00859 cllBindVars[17]=myTime;
00860 cllBindVarCount=18;
00861 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 6");
00862 status = cmlExecuteNoAnswerSql(
00863 "insert into R_DATA_MAIN (data_id, coll_id, data_name, data_repl_num, data_version, data_type_name, data_size, resc_group_name, resc_name, resc_hier, data_path, data_owner_name, data_owner_zone, data_is_dirty, data_checksum, data_mode, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
00864 &icss);
00865 if (status != 0) {
00866 rodsLog(LOG_NOTICE,
00867 "chlRegDataObj cmlExecuteNoAnswerSql failure %d",status);
00868 _rollback("chlRegDataObj");
00869 return(status);
00870 }
00871
00872 status = getLocalZone();
00873 if( status < 0 ) {
00874 rodsLog( LOG_ERROR, "chlRegDataInfo - failed in getLocalZone with status [%d]", status );
00875 return status;
00876 }
00877
00878 if((status = _updateObjCountOfResources( dataObjInfo->rescHier, localZone, 1)) != 0) {
00879 return status;
00880 }
00881
00882 if (inheritFlag) {
00883
00884
00885 cllBindVars[0]=dataIdNum;
00886 cllBindVars[1]=myTime;
00887 cllBindVars[2]=myTime;
00888 cllBindVars[3]=collIdNum;
00889 cllBindVarCount=4;
00890 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 7");
00891 status = cmlExecuteNoAnswerSql(
00892 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select ?, user_id, access_type_id, ?, ? from R_OBJT_ACCESS where object_id = ?)",
00893 &icss);
00894 if (status != 0) {
00895 rodsLog(LOG_NOTICE,
00896 "chlRegDataObj cmlExecuteNoAnswerSql insert access failure %d",
00897 status);
00898 _rollback("chlRegDataObj");
00899 return(status);
00900 }
00901 }
00902 else {
00903 cllBindVars[0]=dataIdNum;
00904 cllBindVars[1]=rsComm->clientUser.userName;
00905 cllBindVars[2]=rsComm->clientUser.rodsZone;
00906 cllBindVars[3]=ACCESS_OWN;
00907 cllBindVars[4]=myTime;
00908 cllBindVars[5]=myTime;
00909 cllBindVarCount=6;
00910 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegDataObj SQL 8");
00911 status = cmlExecuteNoAnswerSql(
00912 "insert into R_OBJT_ACCESS values (?, (select user_id from R_USER_MAIN where user_name=? and zone_name=?), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
00913 &icss);
00914 if (status != 0) {
00915 rodsLog(LOG_NOTICE,
00916 "chlRegDataObj cmlExecuteNoAnswerSql insert access failure %d",
00917 status);
00918 _rollback("chlRegDataObj");
00919 return(status);
00920 }
00921 }
00922
00923 status = cmlAudit3(AU_REGISTER_DATA_OBJ, dataIdNum,
00924 rsComm->clientUser.userName,
00925 rsComm->clientUser.rodsZone, "", &icss);
00926 if (status != 0) {
00927 rodsLog(LOG_NOTICE,
00928 "chlRegDataObj cmlAudit3 failure %d",
00929 status);
00930 _rollback("chlRegDataObj");
00931 return(status);
00932 }
00933
00934
00935 if ( !(dataObjInfo->flags & NO_COMMIT_FLAG) ) {
00936 status = cmlExecuteNoAnswerSql("commit", &icss);
00937 if (status != 0) {
00938 rodsLog(LOG_NOTICE,
00939 "chlRegDataObj cmlExecuteNoAnswerSql commit failure %d",
00940 status);
00941 return(status);
00942 }
00943 }
00944
00945 return(0);
00946 }
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 int chlRegReplica(rsComm_t *rsComm, dataObjInfo_t *srcDataObjInfo,
00957 dataObjInfo_t *dstDataObjInfo, keyValPair_t *condInput) {
00958 char myTime[50];
00959 char logicalFileName[MAX_NAME_LEN];
00960 char logicalDirName[MAX_NAME_LEN];
00961 rodsLong_t iVal;
00962 rodsLong_t status;
00963 char tSQL[MAX_SQL_SIZE];
00964 char *cVal[30];
00965 int i;
00966 int statementNumber;
00967 int nextReplNum;
00968 char nextRepl[30];
00969 char theColls[]="data_id, coll_id, data_name, data_repl_num, data_version, data_type_name, data_size, resc_group_name, resc_name, resc_hier, data_path, data_owner_name, data_owner_zone, data_is_dirty, data_status, data_checksum, data_expiry_ts, data_map_id, data_mode, r_comment, create_ts, modify_ts";
00970 int IX_DATA_REPL_NUM=3;
00971 int IX_RESC_GROUP_NAME=7;
00972 int IX_RESC_NAME=8;
00973 int IX_RESC_HIER=9;
00974 int IX_DATA_PATH=10;
00975
00976 int IX_DATA_MODE=18;
00977 int IX_CREATE_TS=20;
00978 int IX_MODIFY_TS=21;
00979 int IX_RESC_NAME2=22;
00980 int IX_DATA_PATH2=23;
00981 int IX_DATA_ID2=24;
00982 int nColumns=25;
00983
00984 char objIdString[MAX_NAME_LEN];
00985 char replNumString[MAX_NAME_LEN];
00986 int adminMode;
00987 char *theVal;
00988
00989 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegReplica");
00990
00991 adminMode=0;
00992 if (condInput != NULL) {
00993 theVal = getValByKey(condInput, IRODS_ADMIN_KW);
00994 if (theVal != NULL) {
00995 adminMode=1;
00996 }
00997 }
00998
00999 if (!icss.status) {
01000 return(CATALOG_NOT_CONNECTED);
01001 }
01002
01003 status = splitPathByKey(srcDataObjInfo->objPath,
01004 logicalDirName, logicalFileName, '/');
01005
01006 if (adminMode) {
01007 if (rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
01008 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01009 }
01010 }
01011 else {
01012
01013 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegReplica SQL 1 ");
01014 status = cmlCheckDataObjOnly(logicalDirName, logicalFileName,
01015 rsComm->clientUser.userName,
01016 rsComm->clientUser.rodsZone,
01017 ACCESS_READ_OBJECT, &icss);
01018 if (status < 0) {
01019 _rollback("chlRegReplica");
01020 return(status);
01021 }
01022 }
01023
01024
01025 snprintf(objIdString, MAX_NAME_LEN, "%lld", srcDataObjInfo->dataId);
01026 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegReplica SQL 2");
01027 status = cmlGetIntegerValueFromSql(
01028 "select max(data_repl_num) from R_DATA_MAIN where data_id = ?",
01029 &iVal, objIdString, 0, 0, 0, 0, &icss);
01030
01031 if (status != 0) {
01032 _rollback("chlRegReplica");
01033 return(status);
01034 }
01035
01036 nextReplNum = iVal+1;
01037 snprintf(nextRepl, sizeof nextRepl, "%d", nextReplNum);
01038 dstDataObjInfo->replNum = nextReplNum;
01039 snprintf(replNumString, MAX_NAME_LEN, "%d", srcDataObjInfo->replNum);
01040 snprintf(tSQL, MAX_SQL_SIZE,
01041 "select %s from R_DATA_MAIN where data_id = ? and data_repl_num = ?",
01042 theColls);
01043 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegReplica SQL 3");
01044 status = cmlGetOneRowFromSqlV2(tSQL, cVal, nColumns,
01045 objIdString, replNumString, &icss);
01046 if (status < 0) {
01047 _rollback("chlRegReplica");
01048 return(status);
01049 }
01050 statementNumber = status;
01051
01052 cVal[IX_DATA_REPL_NUM]=nextRepl;
01053 cVal[IX_RESC_NAME]=dstDataObjInfo->rescName;
01054 cVal[IX_RESC_HIER]=dstDataObjInfo->rescHier;
01055 cVal[IX_RESC_GROUP_NAME]=dstDataObjInfo->rescGroupName;
01056 cVal[IX_DATA_PATH]=dstDataObjInfo->filePath;
01057 cVal[IX_DATA_MODE]=dstDataObjInfo->dataMode;
01058
01059
01060 getNowStr(myTime);
01061 cVal[IX_MODIFY_TS]=myTime;
01062 cVal[IX_CREATE_TS]=myTime;
01063
01064 cVal[IX_RESC_NAME2]=dstDataObjInfo->rescName;
01065 cVal[IX_DATA_PATH2]=dstDataObjInfo->filePath;
01066 cVal[IX_DATA_ID2]=objIdString;
01067
01068
01069 for (i=0;i<nColumns;i++) {
01070 cllBindVars[i]=cVal[i];
01071 }
01072 cllBindVarCount = nColumns;
01073 #if (defined ORA_ICAT || defined MY_ICAT) // JMC - backport 4685
01074
01075 snprintf(tSQL, MAX_SQL_SIZE, "insert into R_DATA_MAIN ( %s ) select ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? from DUAL where not exists (select data_id from R_DATA_MAIN where resc_name=? and data_path=? and data_id=?)",
01076 theColls);
01077 #else
01078
01079 snprintf(tSQL, MAX_SQL_SIZE, "insert into R_DATA_MAIN ( %s ) select ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? where not exists (select data_id from R_DATA_MAIN where resc_name=? and data_path=? and data_id=?)",
01080 theColls);
01081
01082 #endif
01083 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegReplica SQL 4");
01084 status = cmlExecuteNoAnswerSql(tSQL, &icss);
01085 if (status < 0) {
01086 rodsLog(LOG_NOTICE,
01087 "chlRegReplica cmlExecuteNoAnswerSql(insert) failure %d",
01088 status);
01089 _rollback("chlRegReplica");
01090 return(status);
01091 }
01092
01093 status = getLocalZone();
01094 if( status < 0 ) {
01095 rodsLog( LOG_ERROR, "chlRegReplica - failed in getLocalZone with status [%d]", status );
01096 return status;
01097 }
01098
01099 if((status = _updateObjCountOfResources(dstDataObjInfo->rescHier, localZone, +1)) != 0) {
01100 return status;
01101 }
01102
01103 cmlFreeStatement(statementNumber, &icss);
01104 if (status < 0) {
01105 rodsLog(LOG_NOTICE, "chlRegReplica cmlFreeStatement failure %d", status);
01106 return(status);
01107 }
01108
01109 status = cmlAudit3(AU_REGISTER_DATA_REPLICA, objIdString,
01110 rsComm->clientUser.userName,
01111 rsComm->clientUser.rodsZone, nextRepl, &icss);
01112 if (status != 0) {
01113 rodsLog(LOG_NOTICE,
01114 "chlRegDataReplica cmlAudit3 failure %d",
01115 status);
01116 _rollback("chlRegReplica");
01117 return(status);
01118 }
01119
01120 status = cmlExecuteNoAnswerSql("commit", &icss);
01121 if (status != 0) {
01122 rodsLog(LOG_NOTICE,
01123 "chlRegReplica cmlExecuteNoAnswerSql commit failure %d",
01124 status);
01125 return(status);
01126 }
01127
01128 return(0);
01129 }
01130
01131
01132
01133
01134
01135
01136
01137 void removeMetaMapAndAVU(char *dataObjNumber) {
01138 char tSQL[MAX_SQL_SIZE];
01139 int status;
01140 cllBindVars[0]=dataObjNumber;
01141 cllBindVarCount=1;
01142 if (logSQL!=0) rodsLog(LOG_SQL, "removeMetaMapAndAVU SQL 1 ");
01143 snprintf(tSQL, MAX_SQL_SIZE,
01144 "delete from R_OBJT_METAMAP where object_id=?");
01145 status = cmlExecuteNoAnswerSql(tSQL, &icss);
01146
01147
01148
01149
01150
01151 if (status == 0) {
01152 #ifdef METADATA_CLEANUP
01153 removeAVUs();
01154 #endif
01155 }
01156 return;
01157 }
01158
01159
01160
01161
01162 static int removeAVUs() {
01163 char tSQL[MAX_SQL_SIZE];
01164 int status;
01165
01166 if (logSQL!=0) rodsLog(LOG_SQL, "removeAVUs SQL 1 ");
01167 cllBindVarCount=0;
01168
01169 #if ORA_ICAT
01170 snprintf(tSQL, MAX_SQL_SIZE,
01171 "delete from R_META_MAIN where meta_id in (select meta_id from R_META_MAIN minus select meta_id from R_OBJT_METAMAP)");
01172 #elif MY_ICAT
01173
01174
01175 snprintf(tSQL, MAX_SQL_SIZE,
01176 "delete from R_META_MAIN where meta_id not in (select meta_id from R_OBJT_METAMAP)");
01177 #else
01178
01179 snprintf(tSQL, MAX_SQL_SIZE,
01180 "delete from R_META_MAIN where meta_id in (select meta_id from R_META_MAIN except select meta_id from R_OBJT_METAMAP)");
01181 #endif
01182 status = cmlExecuteNoAnswerSql(tSQL, &icss);
01183 rodsLog (LOG_NOTICE, "removeAVUs status=%d\n",status);
01184
01185 return status;
01186 }
01187
01188
01189
01190
01191 bool
01192 _dataIsLastRepl(
01193 dataObjInfo_t* _dataObjInfo) {
01194
01195 bool result = true;
01196 int status;
01197 eirods::sql_logger logger("_dataIsLastRepl", logSQL);
01198 static const unsigned int length = 30;
01199 char cVal[length];
01200
01201 logger.log();
01202 std::stringstream id_stream;
01203 id_stream << _dataObjInfo->dataId;
01204 std::string id_string = id_stream.str();
01205 std::stringstream repl_stream;
01206 repl_stream << _dataObjInfo->replNum;
01207 std::string repl_string = repl_stream.str();
01208 status = cmlGetStringValueFromSql("select data_repl_num from R_DATA_MAIN where data_id=? and data_repl_num!=?",
01209 cVal, length, id_string.c_str(), repl_string.c_str(), 0, &icss);
01210 if(status != 0) {
01211 result = false;
01212 }
01213 return result;
01214 }
01215
01216
01217
01218
01219
01220
01221
01222 int chlUnregDataObj (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
01223 keyValPair_t *condInput) {
01224 char logicalFileName[MAX_NAME_LEN];
01225 char logicalDirName[MAX_NAME_LEN];
01226 rodsLong_t status;
01227 char tSQL[MAX_SQL_SIZE];
01228 char replNumber[30];
01229 char dataObjNumber[30];
01230 char cVal[MAX_NAME_LEN];
01231 int adminMode;
01232 int trashMode;
01233 char *theVal;
01234 char checkPath[MAX_NAME_LEN];
01235
01236 dataObjNumber[0]='\0';
01237 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj");
01238
01239 if (!icss.status) {
01240 return(CATALOG_NOT_CONNECTED);
01241 }
01242
01243 adminMode=0;
01244 trashMode=0;
01245 if (condInput != NULL) {
01246 theVal = getValByKey(condInput, IRODS_ADMIN_KW);
01247 if (theVal != NULL) {
01248 adminMode=1;
01249 }
01250 theVal = getValByKey(condInput, IRODS_ADMIN_RMTRASH_KW);
01251 if (theVal != NULL) {
01252 adminMode=1;
01253 trashMode=1;
01254 }
01255 }
01256
01257 status = splitPathByKey(dataObjInfo->objPath,
01258 logicalDirName, logicalFileName, '/');
01259
01260
01261 if (adminMode==0) {
01262
01263 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj SQL 1 ");
01264 status = cmlCheckDataObjOnly(logicalDirName, logicalFileName,
01265 rsComm->clientUser.userName,
01266 rsComm->clientUser.rodsZone,
01267 ACCESS_DELETE_OBJECT, &icss);
01268 if (status < 0) {
01269 _rollback("chlUnregDataObj");
01270 return(status);
01271 }
01272 snprintf(dataObjNumber, sizeof dataObjNumber, "%lld", status);
01273 }
01274 else {
01275 if (rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
01276 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01277 }
01278 if (trashMode) {
01279 int len;
01280 status = getLocalZone();
01281 if (status != 0) return(status);
01282 snprintf(checkPath, MAX_NAME_LEN, "/%s/trash", localZone);
01283 len = strlen(checkPath);
01284 if (strncmp(checkPath, logicalDirName, len) != 0) {
01285 addRErrorMsg (&rsComm->rError, 0,
01286 "TRASH_KW but not zone/trash path");
01287 return(CAT_INVALID_ARGUMENT);
01288 }
01289 if (dataObjInfo->dataId > 0) {
01290 snprintf(dataObjNumber, sizeof dataObjNumber, "%lld",
01291 dataObjInfo->dataId);
01292 }
01293 }
01294 else {
01295 if (dataObjInfo->replNum >= 0 && dataObjInfo->dataId >= 0) {
01296
01297 snprintf(dataObjNumber, sizeof dataObjNumber, "%lld",
01298 dataObjInfo->dataId);
01299 snprintf(replNumber, sizeof replNumber, "%d", dataObjInfo->replNum);
01300 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj SQL 2");
01301 status = cmlGetStringValueFromSql(
01302 "select data_repl_num from R_DATA_MAIN where data_id=? and data_repl_num!=?",
01303 cVal,
01304 sizeof cVal,
01305 dataObjNumber,
01306 replNumber,
01307 0,
01308 &icss);
01309 if (status != 0) {
01310 addRErrorMsg (&rsComm->rError, 0,
01311 "This is the last replica, removal by admin not allowed");
01312 return(CAT_LAST_REPLICA);
01313 }
01314 }
01315 else {
01316 addRErrorMsg (&rsComm->rError, 0,
01317 "dataId and replNum required");
01318 _rollback("chlUnregDataObj");
01319 return (CAT_INVALID_ARGUMENT);
01320 }
01321 }
01322 }
01323
01324
01325 std::string resc_hier;
01326 if(!dataObjInfo->rescHier || strlen(dataObjInfo->rescHier) == 0) {
01327 if(dataObjInfo->replNum >= 0) {
01328 snprintf(replNumber, sizeof replNumber, "%d", dataObjInfo->replNum);
01329 if((status = cmlGetStringValueFromSql("select resc_hier from R_DATA_MAIN where data_id=? and data_repl_num=?",
01330 cVal, sizeof cVal, dataObjNumber, replNumber, 0, &icss)) != 0) {
01331 return status;
01332 }
01333 } else {
01334 if((status = cmlGetStringValueFromSql("select resc_hier from R_DATA_MAIN where data_id=?",
01335 cVal, sizeof cVal, dataObjNumber, 0, 0, &icss)) != 0) {
01336 return status;
01337 }
01338 }
01339 resc_hier = std::string(cVal);
01340 } else {
01341 resc_hier = std::string(dataObjInfo->rescHier);
01342 }
01343
01344 cllBindVars[0]=logicalDirName;
01345 cllBindVars[1]=logicalFileName;
01346 if (dataObjInfo->replNum >= 0) {
01347 snprintf(replNumber, sizeof replNumber, "%d", dataObjInfo->replNum);
01348 cllBindVars[2]=replNumber;
01349 cllBindVarCount=3;
01350 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj SQL 4");
01351 snprintf(tSQL, MAX_SQL_SIZE,
01352 "delete from R_DATA_MAIN where coll_id=(select coll_id from R_COLL_MAIN where coll_name=?) and data_name=? and data_repl_num=?");
01353 }
01354 else {
01355 cllBindVarCount=2;
01356 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj SQL 5");
01357 snprintf(tSQL, MAX_SQL_SIZE,
01358 "delete from R_DATA_MAIN where coll_id=(select coll_id from R_COLL_MAIN where coll_name=?) and data_name=?");
01359 }
01360 status = cmlExecuteNoAnswerSql(tSQL, &icss);
01361 if (status != 0) {
01362 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) {
01363 char errMsg[105];
01364 status = CAT_UNKNOWN_FILE;
01365 snprintf(errMsg, 100, "data object '%s' is unknown",
01366 logicalFileName);
01367 addRErrorMsg (&rsComm->rError, 0, errMsg);
01368 return(status);
01369 }
01370 _rollback("chlUnregDataObj");
01371 return(status);
01372 }
01373
01374 status = getLocalZone();
01375 if( status < 0 ) {
01376 rodsLog( LOG_ERROR, "chlUnRegDataObj - failed in getLocalZone with status [%d]", status );
01377 return status;
01378 }
01379
01380
01381 if((status = _updateObjCountOfResources(resc_hier, localZone, -1)) != 0) {
01382 return status;
01383 }
01384
01385
01386 if (dataObjNumber[0]!='\0') {
01387 cllBindVars[0]=dataObjNumber;
01388 cllBindVars[1]=dataObjNumber;
01389 cllBindVarCount=2;
01390 if (logSQL!=0) rodsLog(LOG_SQL, "chlUnregDataObj SQL 3");
01391 status = cmlExecuteNoAnswerSql(
01392 "delete from R_OBJT_ACCESS where object_id=? and not exists (select * from R_DATA_MAIN where data_id=?)", &icss);
01393 if (status == 0) {
01394 removeMetaMapAndAVU(dataObjNumber);
01395 }
01396 }
01397
01398
01399 if (dataObjNumber[0]!='\0') {
01400 status = cmlAudit3(AU_UNREGISTER_DATA_OBJ, dataObjNumber,
01401 rsComm->clientUser.userName,
01402 rsComm->clientUser.rodsZone, "", &icss);
01403 }
01404 else {
01405 status = cmlAudit3(AU_UNREGISTER_DATA_OBJ, "0",
01406 rsComm->clientUser.userName,
01407 rsComm->clientUser.rodsZone,
01408 dataObjInfo->objPath, &icss);
01409 }
01410 if (status != 0) {
01411 rodsLog(LOG_NOTICE,
01412 "chlUnregDataObj cmlAudit3 failure %d",
01413 status);
01414 _rollback("chlUnregDataObj");
01415 return(status);
01416 }
01417
01418
01419 status = cmlExecuteNoAnswerSql("commit", &icss);
01420 if (status != 0) {
01421 rodsLog(LOG_NOTICE,
01422 "chlUnregDataObj cmlExecuteNoAnswerSql commit failure %d",
01423 status);
01424 return(status);
01425 }
01426
01427 return(status);
01428
01429 }
01430
01431
01432
01433
01434
01435
01436
01437 int chlRegRuleExec(rsComm_t *rsComm,
01438 ruleExecSubmitInp_t *ruleExecSubmitInp) {
01439 char myTime[50];
01440 rodsLong_t seqNum;
01441 char ruleExecIdNum[MAX_NAME_LEN];
01442 int status;
01443
01444 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegRuleExec");
01445 if (!icss.status) {
01446 return(CATALOG_NOT_CONNECTED);
01447 }
01448
01449 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegRuleExec SQL 1 ");
01450 seqNum = cmlGetNextSeqVal(&icss);
01451 if (seqNum < 0) {
01452 rodsLog(LOG_NOTICE, "chlRegRuleExec cmlGetNextSeqVal failure %d",
01453 seqNum);
01454 _rollback("chlRegRuleExec");
01455 return(seqNum);
01456 }
01457 snprintf(ruleExecIdNum, MAX_NAME_LEN, "%lld", seqNum);
01458
01459
01460 strncpy(ruleExecSubmitInp->ruleExecId,ruleExecIdNum, NAME_LEN);
01461
01462 getNowStr(myTime);
01463
01464 cllBindVars[0]=ruleExecIdNum;
01465 cllBindVars[1]=ruleExecSubmitInp->ruleName;
01466 cllBindVars[2]=ruleExecSubmitInp->reiFilePath;
01467 cllBindVars[3]=ruleExecSubmitInp->userName;
01468 cllBindVars[4]=ruleExecSubmitInp->exeAddress;
01469 cllBindVars[5]=ruleExecSubmitInp->exeTime;
01470 cllBindVars[6]=ruleExecSubmitInp->exeFrequency;
01471 cllBindVars[7]=ruleExecSubmitInp->priority;
01472 cllBindVars[8]=ruleExecSubmitInp->estimateExeTime;
01473 cllBindVars[9]=ruleExecSubmitInp->notificationAddr;
01474 cllBindVars[10]=myTime;
01475 cllBindVars[11]=myTime;
01476
01477 cllBindVarCount=12;
01478 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegRuleExec SQL 2");
01479 status = cmlExecuteNoAnswerSql(
01480 "insert into R_RULE_EXEC (rule_exec_id, rule_name, rei_file_path, user_name, exe_address, exe_time, exe_frequency, priority, estimated_exe_time, notification_addr, create_ts, modify_ts) values (?,?,?,?,?,?,?,?,?,?,?,?)",
01481 &icss);
01482 if (status != 0) {
01483 rodsLog(LOG_NOTICE,
01484 "chlRegRuleExec cmlExecuteNoAnswerSql(insert) failure %d",status);
01485 _rollback("chlRegRuleExec");
01486 return(status);
01487
01488 }
01489
01490
01491 status = cmlAudit3(AU_REGISTER_DELAYED_RULE, ruleExecIdNum,
01492 rsComm->clientUser.userName,
01493 rsComm->clientUser.rodsZone,
01494 ruleExecSubmitInp->ruleName, &icss);
01495 if (status != 0) {
01496 rodsLog(LOG_NOTICE,
01497 "chlRegRuleExec cmlAudit3 failure %d",
01498 status);
01499 _rollback("chlRegRuleExec");
01500 return(status);
01501 }
01502
01503 status = cmlExecuteNoAnswerSql("commit", &icss);
01504 if (status != 0) {
01505 rodsLog(LOG_NOTICE,
01506 "chlRegRuleExec cmlExecuteNoAnswerSql commit failure %d",
01507 status);
01508 return(status);
01509 }
01510
01511 return(0);
01512 }
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522 int chlModRuleExec(rsComm_t *rsComm, char *ruleExecId,
01523 keyValPair_t *regParam) {
01524 int i, j, status;
01525
01526 char tSQL[MAX_SQL_SIZE];
01527 char *theVal;
01528
01529 int maxCols=90;
01530
01531
01532
01533
01534 char *regParamNames[]={
01535 RULE_NAME_KW, RULE_REI_FILE_PATH_KW, RULE_USER_NAME_KW,
01536 RULE_EXE_ADDRESS_KW, RULE_EXE_TIME_KW,
01537 RULE_EXE_FREQUENCY_KW, RULE_PRIORITY_KW, RULE_ESTIMATE_EXE_TIME_KW,
01538 RULE_NOTIFICATION_ADDR_KW, RULE_LAST_EXE_TIME_KW,
01539 RULE_EXE_STATUS_KW,
01540 "END"
01541 };
01542 char *colNames[]={
01543 "rule_name", "rei_file_path", "user_name",
01544 "exe_address", "exe_time", "exe_frequency", "priority",
01545 "estimated_exe_time", "notification_addr",
01546 "last_exe_time", "exe_status",
01547 "create_ts", "modify_ts",
01548 };
01549
01550 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRuleExec");
01551
01552 if (regParam == NULL || ruleExecId == NULL) {
01553 return (CAT_INVALID_ARGUMENT);
01554 }
01555
01556 snprintf(tSQL, MAX_SQL_SIZE, "update R_RULE_EXEC set ");
01557
01558 for (i=0, j=0; i<maxCols; i++) {
01559 if (strcmp(regParamNames[i],"END")==0) break;
01560 theVal = getValByKey(regParam, regParamNames[i]);
01561 if (theVal != NULL) {
01562 if (j>0) rstrcat(tSQL, "," , MAX_SQL_SIZE);
01563 rstrcat(tSQL, colNames[i] , MAX_SQL_SIZE);
01564 rstrcat(tSQL, "=?", MAX_SQL_SIZE);
01565 cllBindVars[j++]=theVal;
01566 }
01567 }
01568
01569 if (j == 0) {
01570 return (CAT_INVALID_ARGUMENT);
01571 }
01572
01573 rstrcat(tSQL, "where rule_exec_id=?", MAX_SQL_SIZE);
01574 cllBindVars[j++]=ruleExecId;
01575 cllBindVarCount=j;
01576
01577 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRuleExec SQL 1 ");
01578 status = cmlExecuteNoAnswerSql(tSQL, &icss);
01579
01580 if (status != 0) {
01581 _rollback("chlModRuleExec");
01582 rodsLog(LOG_NOTICE,
01583 "chlModRuleExec cmlExecuteNoAnswer(update) failure %d",
01584 status);
01585 return(status);
01586 }
01587
01588
01589 status = cmlAudit3(AU_MODIFY_DELAYED_RULE, ruleExecId,
01590 rsComm->clientUser.userName,
01591 rsComm->clientUser.rodsZone,
01592 "", &icss);
01593 if (status != 0) {
01594 rodsLog(LOG_NOTICE,
01595 "chlModRuleExec cmlAudit3 failure %d",
01596 status);
01597 _rollback("chlModRuleExec");
01598 return(status);
01599 }
01600
01601
01602 status = cmlExecuteNoAnswerSql("commit", &icss);
01603 if (status != 0) {
01604 rodsLog(LOG_NOTICE,
01605 "chlModRuleExecMeta cmlExecuteNoAnswerSql commit failure %d",
01606 status);
01607 return(status);
01608 }
01609 return status;
01610 }
01611
01612
01613 int chlDelRuleExec(rsComm_t *rsComm,
01614 char *ruleExecId) {
01615 int status;
01616 char userName[MAX_NAME_LEN+2];
01617
01618 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelRuleExec");
01619
01620 if (!icss.status) {
01621 return(CATALOG_NOT_CONNECTED);
01622 }
01623
01624 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
01625 if (rsComm->proxyUser.authInfo.authFlag == LOCAL_USER_AUTH) {
01626 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelRuleExec SQL 1 ");
01627 status = cmlGetStringValueFromSql(
01628 "select user_name from R_RULE_EXEC where rule_exec_id=?",
01629 userName, MAX_NAME_LEN, ruleExecId, 0, 0, &icss);
01630 if (strncmp(userName, rsComm->clientUser.userName, MAX_NAME_LEN)
01631 != 0) {
01632 return(CAT_NO_ACCESS_PERMISSION);
01633 }
01634 }
01635 else {
01636 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01637 }
01638 }
01639
01640 cllBindVars[cllBindVarCount++]=ruleExecId;
01641 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelRuleExec SQL 2 ");
01642 status = cmlExecuteNoAnswerSql(
01643 "delete from R_RULE_EXEC where rule_exec_id=?",
01644 &icss);
01645 if (status != 0) {
01646 rodsLog(LOG_NOTICE,
01647 "chlDelRuleExec delete failure %d",
01648 status);
01649 _rollback("chlDelRuleExec");
01650 return(status);
01651 }
01652
01653
01654 status = cmlAudit3(AU_DELETE_DELAYED_RULE, ruleExecId,
01655 rsComm->clientUser.userName,
01656 rsComm->clientUser.rodsZone,
01657 "", &icss);
01658 if (status != 0) {
01659 rodsLog(LOG_NOTICE,
01660 "chlDelRuleExec cmlAudit3 failure %d",
01661 status);
01662 _rollback("chlDelRuleExec");
01663 return(status);
01664 }
01665
01666 status = cmlExecuteNoAnswerSql("commit", &icss);
01667 if (status != 0) {
01668 rodsLog(LOG_NOTICE,
01669 "chlDelRuleExec cmlExecuteNoAnswerSql commit failure %d",
01670 status);
01671 return(status);
01672 }
01673 return(status);
01674 }
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688 int chlTest(rsComm_t *rsComm, char *name) {
01689 dataObjInfo_t dataObjInfo;
01690
01691 strcpy(dataObjInfo.objPath, name);
01692 dataObjInfo.replNum=1;
01693 strcpy(dataObjInfo.version, "12");
01694 strcpy(dataObjInfo.dataType, "URL");
01695 dataObjInfo.dataSize=42;
01696
01697 strcpy(dataObjInfo.rescName, "resc A");
01698
01699 strcpy(dataObjInfo.filePath, "/scratch/slocal/test1");
01700
01701 dataObjInfo.replStatus=5;
01702
01703 return (chlRegDataObj(rsComm, &dataObjInfo));
01704 }
01705
01706 int
01707 _canConnectToCatalog(
01708 rsComm_t* _rsComm)
01709 {
01710 int result = 0;
01711 if (!icss.status) {
01712 result = CATALOG_NOT_CONNECTED;
01713 } else if (_rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
01714 result = CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
01715 } else if (_rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
01716 result = CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
01717 }
01718 return result;
01719 }
01720
01721 int
01722 _resolveHostName(
01723 rsComm_t* _rsComm,
01724 rescInfo_t* _rescInfo)
01725 {
01726 int result = 0;
01727 struct hostent *myHostEnt;
01728
01729 myHostEnt = gethostbyname(_rescInfo->rescLoc);
01730 if (myHostEnt <= 0) {
01731 char errMsg[155];
01732 snprintf(errMsg, 150,
01733 "Warning, resource host address '%s' is not a valid DNS entry, gethostbyname failed.",
01734 _rescInfo->rescLoc);
01735 addRErrorMsg (&_rsComm->rError, 0, errMsg);
01736 }
01737 if (strcmp(_rescInfo->rescLoc, "localhost") == 0) {
01738 addRErrorMsg( &_rsComm->rError, 0,
01739 "Warning, resource host address 'localhost' will not work properly as it maps to the local host from each client.");
01740 }
01741
01742 return result;
01743 }
01744
01745 int
01746 _childIsValid(
01747 const std::string& _new_child) {
01748
01749
01750 int result = 0;
01751 char parent[MAX_NAME_LEN];
01752 int status;
01753
01754
01755 std::string resc_name;
01756 eirods::children_parser parser;
01757 parser.set_string(_new_child);
01758 parser.first_child(resc_name);
01759
01760
01761 eirods::sql_logger logger("_childIsValid", logSQL);
01762 logger.log();
01763 parent[0] = '\0';
01764 if((status = cmlGetStringValueFromSql("select resc_parent from R_RESC_MAIN where resc_name=? and zone_name=?",
01765 parent, MAX_NAME_LEN, resc_name.c_str(), localZone, 0, &icss)) != 0) {
01766 if(status == CAT_NO_ROWS_FOUND) {
01767 std::stringstream ss;
01768 ss << "Child resource \"" << resc_name << "\" not found";
01769 eirods::log(LOG_NOTICE, ss.str());
01770 } else {
01771 _rollback("_childIsValid");
01772 }
01773 result = status;
01774
01775 } else if(strlen(parent) != 0) {
01776
01777 std::stringstream ss;
01778 ss << "Child resource \"" << resc_name << "\" already has a parent \"" << parent << "\"";
01779 eirods::log(LOG_NOTICE, ss.str());
01780 result = EIRODS_CHILD_HAS_PARENT;
01781 }
01782 return result;
01783 }
01784
01785 int
01786 _updateRescChildren(
01787 char* _resc_id,
01788 const std::string& _new_child_string) {
01789
01790 int result = 0;
01791 int status;
01792 char children[MAX_PATH_ALLOWED];
01793 char myTime[50];
01794 eirods::sql_logger logger("_updateRescChildren", logSQL);
01795
01796 if((status = cmlGetStringValueFromSql("select resc_children from R_RESC_MAIN where resc_id=?",
01797 children, MAX_PATH_ALLOWED, _resc_id, 0, 0, &icss)) != 0) {
01798 _rollback("_updateRescChildren");
01799 result = status;
01800 } else {
01801 std::string children_string(children);
01802 std::stringstream ss;
01803 if(children_string.empty()) {
01804 ss << _new_child_string;
01805 } else {
01806 ss << children_string << ";" << _new_child_string;
01807 }
01808 std::string combined_children = ss.str();
01809
01810
01811 eirods::tmp_string ts(combined_children.c_str());
01812 getNowStr(myTime);
01813 cllBindVarCount = 0;
01814 cllBindVars[cllBindVarCount++] = ts.str();
01815 cllBindVars[cllBindVarCount++] = myTime;
01816 cllBindVars[cllBindVarCount++] = _resc_id;
01817 logger.log();
01818 if((status = cmlExecuteNoAnswerSql("update R_RESC_MAIN set resc_children=?, modify_ts=? "
01819 "where resc_id=?", &icss)) != 0) {
01820 std::stringstream ss;
01821 ss << "_updateRescChildren cmlExecuteNoAnswerSql update failure " << status;
01822 eirods::log(LOG_NOTICE, ss.str());
01823 _rollback("_updateRescChildren");
01824 result = status;
01825 }
01826 }
01827 return result;
01828 }
01829
01830 int
01831 _updateChildParent(
01832 const std::string& _new_child,
01833 const std::string& _parent) {
01834
01835 int result = 0;
01836 char resc_id[MAX_NAME_LEN];
01837 char myTime[50];
01838 eirods::sql_logger logger("_updateChildParent", logSQL);
01839 int status;
01840
01841
01842 eirods::children_parser parser;
01843 std::string child;
01844 parser.set_string(_new_child);
01845 parser.first_child(child);
01846
01847
01848 resc_id[0] = '\0';
01849 if((status = cmlGetStringValueFromSql("select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
01850 resc_id, MAX_NAME_LEN, child.c_str(), localZone, 0,
01851 &icss)) != 0) {
01852 if(status == CAT_NO_ROWS_FOUND) {
01853 result = CAT_INVALID_RESOURCE;
01854 } else {
01855 _rollback("_updateChildParent");
01856 result = status;
01857 }
01858 } else {
01859
01860
01861
01862 eirods::tmp_string ts(_parent.c_str());
01863 getNowStr(myTime);
01864 cllBindVarCount = 0;
01865 cllBindVars[cllBindVarCount++] = ts.str();
01866 cllBindVars[cllBindVarCount++] = myTime;
01867 cllBindVars[cllBindVarCount++] = resc_id;
01868 logger.log();
01869 if((status = cmlExecuteNoAnswerSql("update R_RESC_MAIN set resc_parent=?, modify_ts=? "
01870 "where resc_id=?", &icss)) != 0) {
01871 std::stringstream ss;
01872 ss << "_updateChildParent cmlExecuteNoAnswerSql update failure " << status;
01873 eirods::log(LOG_NOTICE, ss.str());
01874 _rollback("_updateChildParent");
01875 result = status;
01876 }
01877 }
01878
01879 return result;
01880 }
01881
01882 eirods::error chlRescObjCount(
01883 const std::string& _resc_name,
01884 rodsLong_t & _rtn_obj_count)
01885 {
01886 eirods::error result = SUCCESS();
01887 rodsLong_t obj_count = 0;
01888 int status;
01889
01890 if((status = cmlGetIntegerValueFromSql("select resc_objcount from R_RESC_MAIN where resc_name=?",
01891 &obj_count, _resc_name.c_str(), 0, 0, 0, 0, &icss)) != 0) {
01892 _rollback(__FUNCTION__);
01893 std::stringstream msg;
01894 msg << __FUNCTION__ << " - Failed to get object count for resource: \"" << _resc_name << "\"";
01895 result = ERROR(status, msg.str());
01896 } else {
01897 _rtn_obj_count = obj_count;
01898 }
01899
01900 return result;
01901 }
01902
01903
01904
01905
01906 bool
01907 _rescHasData(
01908 const std::string& _resc_name) {
01909
01910 bool result = false;
01911 eirods::sql_logger logger("_rescHasData", logSQL);
01912 int status;
01913 static const char* func_name = "_rescHasData";
01914 rodsLong_t obj_count;
01915
01916 logger.log();
01917 if((status = cmlGetIntegerValueFromSql("select resc_objcount from R_RESC_MAIN where resc_name=?",
01918 &obj_count, _resc_name.c_str(), 0, 0, 0, 0, &icss)) != 0) {
01919 _rollback(func_name);
01920 } else {
01921 if(obj_count > 0) {
01922 result = true;
01923 }
01924 }
01925 return result;
01926 }
01927
01928
01929
01930
01931 bool
01932 _childHasData(
01933 const std::string& _child) {
01934
01935 bool result = true;
01936 eirods::children_parser parser;
01937 parser.set_string(_child);
01938 std::string child;
01939 parser.first_child(child);
01940 result = _rescHasData(child);
01941 return result;
01942 }
01943
01944
01945
01946
01947 int
01948 chlAddChildResc(
01949 rsComm_t* rsComm,
01950 rescInfo_t* rescInfo)
01951 {
01952 int result = 0;
01953
01954 int status;
01955 static const char* func_name = "chlAddChildResc";
01956 eirods::sql_logger logger(func_name, logSQL);
01957 std::string new_child_string(rescInfo->rescChildren);
01958 std::string hierarchy, child_resc, root_resc;
01959 eirods::children_parser parser;
01960 eirods::hierarchy_parser hier_parser;
01961 rodsLong_t obj_count;
01962 char resc_id[MAX_NAME_LEN];
01963
01964
01965 logger.log();
01966
01967 if(!(result = _canConnectToCatalog(rsComm))) {
01968
01969 if((status = getLocalZone())) {
01970 result = status;
01971
01972 } else if (rescInfo->zoneName != NULL && strlen(rescInfo->zoneName) > 0 && strcmp(rescInfo->zoneName, localZone) !=0) {
01973 addRErrorMsg (&rsComm->rError, 0,
01974 "Currently, resources must be in the local zone");
01975 result = CAT_INVALID_ZONE;
01976
01977 } else {
01978
01979 logger.log();
01980
01981 resc_id[0] = '\0';
01982 if((status = cmlGetStringValueFromSql("select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
01983 resc_id, MAX_NAME_LEN, rescInfo->rescName, localZone, 0,
01984 &icss)) != 0) {
01985 if(status == CAT_NO_ROWS_FOUND) {
01986 result = CAT_INVALID_RESOURCE;
01987 } else {
01988 _rollback(func_name);
01989 result = status;
01990 }
01991 } else if((status =_childIsValid(new_child_string)) == 0) {
01992 if((status = _updateRescChildren(resc_id, new_child_string)) != 0) {
01993 result = status;
01994 } else if((status = _updateChildParent(new_child_string, rescInfo->rescName)) != 0) {
01995 result = status;
01996 } else {
01997
01998
01999 if(_childHasData(new_child_string)) {
02000
02001
02002
02003
02004 status = chlGetHierarchyForResc(rescInfo->rescName, localZone, hierarchy);
02005 if (status < 0) {
02006 std::stringstream ss;
02007 ss << func_name << ": chlGetHierarchyForResc failed, status = " << status;
02008 eirods::log(LOG_NOTICE, ss.str());
02009 _rollback(func_name);
02010 return status;
02011 }
02012
02013
02014
02015
02016
02017
02018 parser.set_string(new_child_string);
02019 parser.first_child(child_resc);
02020
02021 if (chlRescObjCount(child_resc, obj_count).ok()) {
02022 status = _updateObjCountOfResources(hierarchy, localZone, obj_count);
02023 } else {
02024 status = CAT_INVALID_OBJ_COUNT;
02025 }
02026
02027 if (status < 0) {
02028
02029 std::stringstream ss;
02030 ss << func_name << " aborted. Object count update error, status = " << status;
02031 eirods::log(LOG_NOTICE, ss.str());
02032 _rollback(func_name);
02033 return status;
02034 }
02035
02036
02037
02038
02039
02040
02041 hierarchy += eirods::hierarchy_parser::delimiter() + child_resc;
02042
02043
02044 status = chlSubstituteResourceHierarchies(rsComm, child_resc.c_str(), hierarchy.c_str());
02045
02046
02047
02048
02049
02050
02051
02052 hier_parser.set_string(hierarchy);
02053 hier_parser.first_resc(root_resc);
02054
02055 cllBindVars[cllBindVarCount++]=(char*)root_resc.c_str();
02056 cllBindVars[cllBindVarCount++]=(char*)root_resc.c_str();
02057 cllBindVars[cllBindVarCount++]=(char*)child_resc.c_str();
02058 status = cmlExecuteNoAnswerSql("update R_DATA_MAIN set resc_name = ?, resc_group_name = ? where resc_name = ?", &icss);
02059
02060 if (status < 0) {
02061
02062 std::stringstream ss;
02063 ss << func_name << " aborted. Resource update error, status = " << status;
02064 eirods::log(LOG_NOTICE, ss.str());
02065 _rollback(func_name);
02066 return status;
02067 }
02068
02069 }
02070
02071
02072
02073 char commentStr[1024];
02074 snprintf(commentStr, sizeof commentStr, "%s %s", rescInfo->rescName, new_child_string.c_str());
02075 if((status = cmlAudit3(AU_ADD_CHILD_RESOURCE, resc_id, rsComm->clientUser.userName, rsComm->clientUser.rodsZone,
02076 commentStr, &icss)) != 0) {
02077 std::stringstream ss;
02078 ss << func_name << " cmlAudit3 failure " << status;
02079 eirods::log(LOG_NOTICE, ss.str());
02080 _rollback(func_name);
02081 result = status;
02082 } else if((status = cmlExecuteNoAnswerSql("commit", &icss)) != 0) {
02083 std::stringstream ss;
02084 ss << func_name<< " cmlExecuteNoAnswerSql commit failure " << status;
02085 eirods::log(LOG_NOTICE, ss.str());
02086 result = status;
02087 }
02088 }
02089 } else {
02090 std::string resc_name;
02091 eirods::children_parser parser;
02092 parser.set_string(new_child_string);
02093 parser.first_child(resc_name);
02094
02095 std::stringstream msg;
02096 msg << __FUNCTION__;
02097 msg << " - Resource '" << resc_name << "' already has a parent.";
02098 addRErrorMsg(&rsComm->rError, 0, msg.str().c_str());
02099 result = status;
02100 }
02101 }
02102 }
02103 return result;
02104 }
02105
02106
02107
02108 eirods::error validate_resource_name(std::string _resc_name) {
02109
02110
02111
02112
02113 boost::regex re("^(?=.{1,63}$)\\w(\\w*(-\\w+)?)*$");
02114
02115 if (!boost::regex_match(_resc_name, re)) {
02116 std::stringstream msg;
02117 msg << "validate_resource_name failed for resource [";
02118 msg << _resc_name;
02119 msg << "]";
02120 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
02121 }
02122
02123 return SUCCESS();
02124
02125 }
02126
02127
02128
02129 int chlRegResc(rsComm_t *rsComm,
02130 rescInfo_t *rescInfo) {
02131 rodsLong_t seqNum;
02132 char idNum[MAX_SQL_SIZE];
02133 int status;
02134 char myTime[50];
02135 struct hostent *myHostEnt;
02136
02137 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegResc");
02138
02139
02140
02141 if( strlen( rescInfo->rescName ) < 1 ) {
02142 addRErrorMsg( &rsComm->rError, 0, "resource name is empty" );
02143 return CAT_INVALID_RESOURCE_NAME;
02144 }
02145
02146
02147
02148 if( strlen( rescInfo->rescType ) < 1 ) {
02149 addRErrorMsg( &rsComm->rError, 0, "resource type is empty" );
02150 return CAT_INVALID_RESOURCE_TYPE;
02151 }
02152
02153 if (!icss.status) {
02154 return(CATALOG_NOT_CONNECTED);
02155 }
02156
02157 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02158 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02159 }
02160 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02161 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02162 }
02163
02164
02165
02166
02167 eirods::error ret = validate_resource_name(rescInfo->rescName);
02168 if(!ret.ok()) {
02169 eirods::log(ret);
02170 return SYS_INVALID_INPUT_PARAM;
02171 }
02172
02173
02174
02175 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegResc SQL 1 ");
02176 seqNum = cmlGetNextSeqVal(&icss);
02177 if (seqNum < 0) {
02178 rodsLog(LOG_NOTICE, "chlRegResc cmlGetNextSeqVal failure %d",
02179 seqNum);
02180 _rollback("chlRegResc");
02181 return(seqNum);
02182 }
02183 snprintf(idNum, MAX_SQL_SIZE, "%lld", seqNum);
02184
02185 status = getLocalZone();
02186 if (status != 0) return(status);
02187
02188 if (rescInfo->zoneName != NULL && strlen(rescInfo->zoneName) > 0) {
02189 if (strcmp(rescInfo->zoneName, localZone) !=0) {
02190 addRErrorMsg (&rsComm->rError, 0,
02191 "Currently, resources must be in the local zone");
02192 return(CAT_INVALID_ZONE);
02193 }
02194 }
02195
02196 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegResc SQL 2");
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206 if( eirods::EMPTY_RESC_HOST != rescInfo->rescLoc ) {
02207
02208
02209 myHostEnt = gethostbyname(rescInfo->rescLoc);
02210 if (myHostEnt <= 0) {
02211 char errMsg[155];
02212 snprintf(errMsg, 150,
02213 "Warning, resource host address '%s' is not a valid DNS entry, gethostbyname failed.",
02214 rescInfo->rescLoc);
02215 addRErrorMsg (&rsComm->rError, 0, errMsg);
02216 }
02217 if (strcmp(rescInfo->rescLoc, "localhost") == 0) {
02218 addRErrorMsg( &rsComm->rError, 0,
02219 "Warning, resource host address 'localhost' will not work properly as it maps to the local host from each client.");
02220 }
02221
02222 }
02223 #if 0
02224 if (false &&
02225 (strcmp(rescInfo->rescType, "database") !=0) &&
02226 (strcmp(rescInfo->rescType, "mso") !=0) ) {
02227 if (strlen(rescInfo->rescVaultPath)<1) {
02228 return(CAT_INVALID_RESOURCE_VAULT_PATH);
02229 }
02230 }
02231 #endif
02232
02233 status = getLocalZone();
02234 if (status != 0) return(status);
02235
02236 getNowStr(myTime);
02237
02238 cllBindVars[0]=idNum;
02239 cllBindVars[1]=rescInfo->rescName;
02240 cllBindVars[2]=localZone;
02241 cllBindVars[3]=rescInfo->rescType;
02242 cllBindVars[4]=rescInfo->rescClass;
02243 cllBindVars[5]=rescInfo->rescLoc;
02244 cllBindVars[6]=rescInfo->rescVaultPath;
02245 cllBindVars[7]=myTime;
02246 cllBindVars[8]=myTime;
02247 cllBindVars[9]=rescInfo->rescChildren;
02248 cllBindVars[10]=rescInfo->rescContext;
02249 cllBindVars[11]=rescInfo->rescParent;
02250 cllBindVars[12]="0";
02251 cllBindVarCount=13;
02252
02253 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegResc SQL 4");
02254 status = cmlExecuteNoAnswerSql(
02255 "insert into R_RESC_MAIN (resc_id, resc_name, zone_name, resc_type_name, resc_class_name, resc_net, resc_def_path, create_ts, modify_ts, resc_children, resc_context, resc_parent, resc_objcount) values (?,?,?,?,?,?,?,?,?,?,?,?,?)",
02256 &icss);
02257
02258 if (status != 0) {
02259 rodsLog(LOG_NOTICE,
02260 "chlRegResc cmlExectuteNoAnswerSql(insert) failure %d",
02261 status);
02262 _rollback("chlRegResc");
02263 return(status);
02264 }
02265
02266
02267 status = cmlAudit3(AU_REGISTER_RESOURCE, idNum,
02268 rsComm->clientUser.userName,
02269 rsComm->clientUser.rodsZone,
02270 rescInfo->rescName, &icss);
02271 if (status != 0) {
02272 rodsLog(LOG_NOTICE,
02273 "chlRegResc cmlAudit3 failure %d",
02274 status);
02275 _rollback("chlRegResc");
02276 return(status);
02277 }
02278
02279 status = cmlExecuteNoAnswerSql("commit", &icss);
02280 if (status != 0) {
02281 rodsLog(LOG_NOTICE,
02282 "chlRegResc cmlExecuteNoAnswerSql commit failure %d",status);
02283 return(status);
02284 }
02285 return(status);
02286 }
02287
02288 int
02289 _removeRescChild(
02290 char* _resc_id,
02291 const std::string& _child_string) {
02292
02293 int result = 0;
02294 int status;
02295 char children[MAX_PATH_ALLOWED];
02296 char myTime[50];
02297 eirods::sql_logger logger("_removeRescChild", logSQL);
02298
02299
02300 if((status = cmlGetStringValueFromSql("select resc_children from R_RESC_MAIN where resc_id=?",
02301 children, MAX_PATH_ALLOWED, _resc_id, 0, 0, &icss)) != 0) {
02302 _rollback("_updateRescChildren");
02303 result = status;
02304 } else {
02305
02306
02307 eirods::children_parser parser;
02308 eirods::error ret = parser.set_string(children);
02309 if(!ret.ok()) {
02310 std::stringstream ss;
02311 ss << "_removeChildFromResource resource has invalid children string \"" << children << "\'";
02312 ss << ret.result();
02313 eirods::log(LOG_NOTICE, ss.str());
02314 result = CAT_INVALID_CHILD;
02315 } else {
02316
02317
02318 ret = parser.remove_child(_child_string);
02319 if(!ret.ok()) {
02320 std::stringstream ss;
02321 ss << "_removeChildFromResource parent has no child \"" << _child_string << "\'";
02322 ss << ret.result();
02323 eirods::log(LOG_NOTICE, ss.str());
02324 result = CAT_INVALID_CHILD;
02325 } else {
02326
02327
02328
02329 std::string children_string;
02330 parser.str(children_string);
02331 eirods::tmp_string tmp_children(children_string.c_str());
02332 getNowStr(myTime);
02333 cllBindVarCount = 0;
02334 cllBindVars[cllBindVarCount++] = tmp_children.str();
02335 cllBindVars[cllBindVarCount++] = myTime;
02336 cllBindVars[cllBindVarCount++] = _resc_id;
02337 logger.log();
02338 if((status = cmlExecuteNoAnswerSql("update R_RESC_MAIN set resc_children=?, modify_ts=? "
02339 "where resc_id=?", &icss)) != 0) {
02340 std::stringstream ss;
02341 ss << "_removeRescChild cmlExecuteNoAnswerSql update failure " << status;
02342 eirods::log(LOG_NOTICE, ss.str());
02343 _rollback("_removeRescChild");
02344 result = status;
02345 }
02346 }
02347 }
02348 }
02349 return result;
02350 }
02351
02352
02353
02354
02355 #if 0 // currently unused
02356 static bool
02357 _rescHasChildren(
02358 const std::string _resc_name) {
02359
02360 bool result = false;
02361 int status;
02362 char children[MAX_NAME_LEN];
02363 eirods::sql_logger logger("_rescHasChildren", logSQL);
02364
02365 logger.log();
02366 if((status = cmlGetStringValueFromSql("select resc_children from R_RESC_MAIN where resc_name=?",
02367 children, MAX_NAME_LEN, _resc_name.c_str(), 0, 0, &icss)) !=0) {
02368 if(status != CAT_NO_ROWS_FOUND) {
02369 _rollback("_rescHasChildren");
02370 }
02371 result = false;
02372 } else if(strlen(children) != 0) {
02373 result = true;
02374 }
02375 return result;
02376 }
02377 #endif
02378
02379
02380
02381
02382 int
02383 chlDelChildResc(
02384 rsComm_t* rsComm,
02385 rescInfo_t* rescInfo) {
02386
02387 eirods::sql_logger logger("chlDelChildResc", logSQL);
02388 int result = 0;
02389 int status;
02390 rodsLong_t obj_count;
02391 char resc_id[MAX_NAME_LEN];
02392 std::string child_string(rescInfo->rescChildren);
02393 std::string child, hierarchy, partial_hier;
02394 eirods::children_parser parser;
02395
02396 parser.set_string(child_string);
02397 parser.first_child(child);
02398
02399 if(!(result = _canConnectToCatalog(rsComm))) {
02400 if((status = getLocalZone())) {
02401 result = status;
02402 } else {
02403 logger.log();
02404
02405 resc_id[0] = '\0';
02406 if((status = cmlGetStringValueFromSql("select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
02407 resc_id, MAX_NAME_LEN, rescInfo->rescName, localZone, 0,
02408 &icss)) != 0) {
02409 if(status == CAT_NO_ROWS_FOUND) {
02410 result = CAT_INVALID_RESOURCE;
02411 } else {
02412 _rollback("chlDelChildResc");
02413 result = status;
02414 }
02415
02416 } else if((status = _updateChildParent(child, std::string(""))) != 0) {
02417 result = status;
02418 } else if((status = _removeRescChild(resc_id, child)) != 0) {
02419 result = status;
02420 } else {
02421
02422
02423 if(_childHasData(child_string)) {
02424
02425
02426
02427
02428 status = chlGetHierarchyForResc(rescInfo->rescName, localZone, hierarchy);
02429 if (status < 0) {
02430 std::stringstream ss;
02431 ss << "chlDelChildResc: chlGetHierarchyForResc failed, status = " << status;
02432 eirods::log(LOG_NOTICE, ss.str());
02433 _rollback("chlDelChildResc");
02434 return status;
02435 }
02436
02437
02438
02439
02440 if (chlRescObjCount(child, obj_count).ok()) {
02441 status = _updateObjCountOfResources(hierarchy, localZone, -obj_count);
02442 } else {
02443 status = CAT_INVALID_OBJ_COUNT;
02444 }
02445
02446 if (status < 0) {
02447
02448 std::stringstream ss;
02449 ss << "chlDelChildResc aborted. Object count update error, status = " << status;
02450 eirods::log(LOG_NOTICE, ss.str());
02451 _rollback("chlDelChildResc");
02452 return status;
02453 }
02454
02455
02456
02457
02458
02459
02460 hierarchy += eirods::hierarchy_parser::delimiter() + child;
02461
02462
02463 status = chlSubstituteResourceHierarchies(rsComm, hierarchy.c_str(), child.c_str());
02464
02465
02466
02467
02468 partial_hier = child + eirods::hierarchy_parser::delimiter() + "%";
02469
02470 cllBindVars[cllBindVarCount++]=(char*)child.c_str();
02471 cllBindVars[cllBindVarCount++]=(char*)child.c_str();
02472 cllBindVars[cllBindVarCount++]=(char*)child.c_str();
02473 cllBindVars[cllBindVarCount++]=(char*)partial_hier.c_str();
02474 status = cmlExecuteNoAnswerSql("update R_DATA_MAIN set resc_name = ?, resc_group_name = ? where resc_hier = ? or resc_hier like ?", &icss);
02475
02476 if (status < 0) {
02477
02478 std::stringstream ss;
02479 ss << "chlDelChildResc" << " aborted. Resource update error, status = " << status;
02480 eirods::log(LOG_NOTICE, ss.str());
02481 _rollback("chlDelChildResc");
02482 return status;
02483 }
02484
02485 }
02486
02487
02488
02489
02490
02491 char commentStr[1024];
02492 snprintf(commentStr, sizeof commentStr, "%s %s", rescInfo->rescName, child_string.c_str());
02493 if((status = cmlAudit3(AU_DEL_CHILD_RESOURCE, resc_id, rsComm->clientUser.userName, rsComm->clientUser.rodsZone,
02494 commentStr, &icss)) != 0) {
02495 std::stringstream ss;
02496 ss << "chlDelChildResc cmlAudit3 failure " << status;
02497 eirods::log(LOG_NOTICE, ss.str());
02498 _rollback("chlDelChildResc");
02499 result = status;
02500 } else if((status = cmlExecuteNoAnswerSql("commit", &icss)) != 0) {
02501 std::stringstream ss;
02502 ss << "chlDelChildResc cmlExecuteNoAnswerSql commit failure " << status;
02503 eirods::log(LOG_NOTICE, ss.str());
02504 result = status;
02505 }
02506 }
02507 }
02508 }
02509 return result;
02510 }
02511
02512 bool
02513 _rescHasParentOrChild(
02514 char* rescId) {
02515
02516 bool result = false;
02517 char parent[MAX_NAME_LEN];
02518 char children[MAX_NAME_LEN];
02519 int status;
02520 eirods::sql_logger logger("_rescHasParentOrChild", logSQL);
02521
02522 logger.log();
02523 parent[0] = '\0';
02524 children[0] = '\0';
02525 if((status = cmlGetStringValueFromSql("select resc_parent from R_RESC_MAIN where resc_id=?",
02526 parent, MAX_NAME_LEN, rescId, 0, 0, &icss)) != 0) {
02527 if(status == CAT_NO_ROWS_FOUND) {
02528 std::stringstream ss;
02529 ss << "Resource \"" << rescId << "\" not found";
02530 eirods::log(LOG_NOTICE, ss.str());
02531 } else {
02532 _rollback("_rescHasParentOrChild");
02533 }
02534 result = false;
02535 } else if(strlen(parent) != 0) {
02536 result = true;
02537 } else if((status = cmlGetStringValueFromSql("select resc_children from R_RESC_MAIN where resc_id=?",
02538 children, MAX_NAME_LEN, rescId, 0, 0, &icss)) !=0) {
02539 if(status != CAT_NO_ROWS_FOUND) {
02540 _rollback("_rescHasParentOrChild");
02541 }
02542 result = false;
02543 } else if(strlen(children) != 0) {
02544 result = true;
02545 }
02546 return result;
02547
02548 }
02549
02550
02551 int chlDelResc(rsComm_t *rsComm, rescInfo_t *rescInfo, int _dryrun ) {
02552
02553 int status;
02554 char rescId[MAX_NAME_LEN];
02555
02556 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelResc");
02557
02558 if (!icss.status) {
02559 return(CATALOG_NOT_CONNECTED);
02560 }
02561
02562 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02563 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02564 }
02565 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02566 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02567 }
02568
02569
02570
02571 if (strncmp(rescInfo->rescName, BUNDLE_RESC, strlen(BUNDLE_RESC))==0) {
02572 char errMsg[155];
02573 snprintf(errMsg, 150,
02574 "%s is a built-in resource needed for bundle operations.",
02575 BUNDLE_RESC);
02576 addRErrorMsg (&rsComm->rError, 0, errMsg);
02577 return(CAT_PSEUDO_RESC_MODIFY_DISALLOWED);
02578 }
02579
02580
02581 if (_rescHasData(rescInfo->rescName)) {
02582 char errMsg[105];
02583 snprintf(errMsg, 100,
02584 "resource '%s' contains one or more dataObjects",
02585 rescInfo->rescName);
02586 addRErrorMsg (&rsComm->rError, 0, errMsg);
02587 return(CAT_RESOURCE_NOT_EMPTY);
02588 }
02589
02590 status = getLocalZone();
02591 if (status != 0) return(status);
02592
02593
02594 rescId[0]='\0';
02595 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelResc SQL 2 ");
02596 status = cmlGetStringValueFromSql(
02597 "select resc_id from R_RESC_MAIN where resc_name=?",
02598 rescId, MAX_NAME_LEN, rescInfo->rescName, 0, 0, &icss);
02599 if (status != 0) {
02600 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) {
02601 char errMsg[105];
02602 snprintf(errMsg, 100,
02603 "resource '%s' does not exist",
02604 rescInfo->rescName);
02605 addRErrorMsg (&rsComm->rError, 0, errMsg);
02606 return(status);
02607 }
02608 _rollback("chlDelResc");
02609 return(status);
02610 }
02611
02612 if(_rescHasParentOrChild(rescId)) {
02613 char errMsg[105];
02614 snprintf(errMsg, 100,
02615 "resource '%s' has a parent or child",
02616 rescInfo->rescName);
02617 addRErrorMsg (&rsComm->rError, 0, errMsg);
02618 return(CAT_RESOURCE_NOT_EMPTY);
02619 }
02620
02621 cllBindVars[cllBindVarCount++]=rescInfo->rescName;
02622 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelResc SQL 3");
02623 status = cmlExecuteNoAnswerSql(
02624 "delete from R_RESC_MAIN where resc_name=?",
02625 &icss);
02626 if (status != 0) {
02627 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) {
02628 char errMsg[105];
02629 snprintf(errMsg, 100,
02630 "resource '%s' does not exist",
02631 rescInfo->rescName);
02632 addRErrorMsg (&rsComm->rError, 0, errMsg);
02633 return(status);
02634 }
02635 _rollback("chlDelResc");
02636 return(status);
02637 }
02638
02639
02640 cllBindVars[cllBindVarCount++]=rescId;
02641 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelResc SQL 4");
02642 status = cmlExecuteNoAnswerSql(
02643 "delete from R_RESC_GROUP where resc_id=?",
02644 &icss);
02645 if (status != 0 &&
02646 status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
02647 rodsLog(LOG_NOTICE,
02648 "chlDelResc delete from R_RESC_GROUP failure %d",
02649 status);
02650 _rollback("chlDelResc");
02651 return(status);
02652 }
02653
02654
02655
02656 removeMetaMapAndAVU(rescId);
02657
02658
02659
02660 status = cmlAudit3(AU_DELETE_RESOURCE,
02661 rescId,
02662 rsComm->clientUser.userName,
02663 rsComm->clientUser.rodsZone,
02664 rescInfo->rescName,
02665 &icss);
02666 if (status != 0) {
02667 rodsLog(LOG_NOTICE,
02668 "chlDelResc cmlAudit3 failure %d",
02669 status);
02670 _rollback("chlDelResc");
02671 return(status);
02672 }
02673
02674 if( _dryrun ) {
02675 _rollback( "chlDelResc" );
02676 return status;
02677 }
02678
02679 status = cmlExecuteNoAnswerSql("commit", &icss);
02680 if (status != 0) {
02681 rodsLog(LOG_NOTICE,
02682 "chlDelResc cmlExecuteNoAnswerSql commit failure %d",
02683 status);
02684 return(status);
02685 }
02686 return(status);
02687 }
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702 int chlRollback(rsComm_t *rsComm) {
02703 int status;
02704 if (logSQL!=0) rodsLog(LOG_SQL, "chlRollback - SQL 1 ");
02705 status = cmlExecuteNoAnswerSql("rollback", &icss);
02706 if (status != 0) {
02707 rodsLog(LOG_NOTICE,
02708 "chlRollback cmlExecuteNoAnswerSql failure %d",
02709 status);
02710 }
02711 return(status);
02712 }
02713
02714
02715
02716
02717
02718
02719
02720
02721 int chlCommit(rsComm_t *rsComm) {
02722 int status;
02723 if (logSQL!=0) rodsLog(LOG_SQL, "chlCommit - SQL 1 ");
02724 status = cmlExecuteNoAnswerSql("commit", &icss);
02725 if (status != 0) {
02726 rodsLog(LOG_NOTICE,
02727 "chlCommit cmlExecuteNoAnswerSql failure %d",
02728 status);
02729 }
02730 return(status);
02731 }
02732
02733
02734 int chlDelUserRE(rsComm_t *rsComm, userInfo_t *userInfo) {
02735 int status;
02736 char iValStr[200];
02737 char zoneToUse[MAX_NAME_LEN];
02738 char userStr[200];
02739 char userName2[NAME_LEN];
02740 char zoneName[NAME_LEN];
02741
02742 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE");
02743
02744 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02745 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02746 }
02747 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02748 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02749 }
02750
02751 status = getLocalZone();
02752 if (status != 0) return(status);
02753
02754 strncpy(zoneToUse, localZone, MAX_NAME_LEN);
02755 if (strlen(userInfo->rodsZone)>0) {
02756 strncpy(zoneToUse, userInfo->rodsZone, MAX_NAME_LEN);
02757 }
02758
02759 status = parseUserName(userInfo->userName, userName2, zoneName);
02760 if (zoneName[0]!='\0') {
02761 rstrcpy(zoneToUse, zoneName, NAME_LEN);
02762 }
02763
02764 if (strncmp(rsComm->clientUser.userName, userName2, sizeof(userName2))==0 &&
02765 strncmp(rsComm->clientUser.rodsZone, zoneToUse, sizeof(zoneToUse))==0) {
02766 addRErrorMsg (&rsComm->rError, 0, "Cannot remove your own admin account, probably unintended");
02767 return(CAT_INVALID_USER);
02768 }
02769
02770
02771 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE SQL 1 ");
02772 status = cmlGetStringValueFromSql(
02773 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
02774 iValStr, 200, userName2, zoneToUse, 0, &icss);
02775 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO ||
02776 status==CAT_NO_ROWS_FOUND) {
02777 addRErrorMsg (&rsComm->rError, 0, "Invalid user");
02778 return(CAT_INVALID_USER);
02779 }
02780 if (status != 0) {
02781 _rollback("chlDelUserRE");
02782 return(status);
02783 }
02784
02785 cllBindVars[cllBindVarCount++]=userName2;
02786 cllBindVars[cllBindVarCount++]=zoneToUse;
02787 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE SQL 2");
02788 status = cmlExecuteNoAnswerSql(
02789 "delete from R_USER_MAIN where user_name=? and zone_name=?",
02790 &icss);
02791 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) return(CAT_INVALID_USER);
02792 if (status != 0) {
02793 _rollback("chlDelUserRE");
02794 return(status);
02795 }
02796
02797 cllBindVars[cllBindVarCount++]=iValStr;
02798 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE SQL 3");
02799 status = cmlExecuteNoAnswerSql(
02800 "delete from R_USER_PASSWORD where user_id=?",
02801 &icss);
02802 if (status!=0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
02803 char errMsg[MAX_NAME_LEN+40];
02804 rodsLog(LOG_NOTICE,
02805 "chlDelUserRE delete password failure %d",
02806 status);
02807 snprintf(errMsg, sizeof errMsg, "Error removing password entry");
02808 addRErrorMsg (&rsComm->rError, 0, errMsg);
02809 _rollback("chlDelUserRE");
02810 return(status);
02811 }
02812
02813
02814
02815 cllBindVars[cllBindVarCount++]=iValStr;
02816 cllBindVars[cllBindVarCount++]=iValStr;
02817 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE SQL 4");
02818 status = cmlExecuteNoAnswerSql(
02819 "delete from R_USER_GROUP where user_id=? or group_user_id=?",
02820 &icss);
02821 if (status!=0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
02822 char errMsg[MAX_NAME_LEN+40];
02823 rodsLog(LOG_NOTICE,
02824 "chlDelUserRE delete user_group entry failure %d",
02825 status);
02826 snprintf(errMsg, sizeof errMsg, "Error removing user_group entry");
02827 addRErrorMsg (&rsComm->rError, 0, errMsg);
02828 _rollback("chlDelUserRE");
02829 return(status);
02830 }
02831
02832
02833 cllBindVars[cllBindVarCount++]=iValStr;
02834 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelUserRE SQL 4");
02835 status = cmlExecuteNoAnswerSql(
02836 "delete from R_USER_AUTH where user_id=?",
02837 &icss);
02838 if (status!=0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
02839 char errMsg[MAX_NAME_LEN+40];
02840 rodsLog(LOG_NOTICE,
02841 "chlDelUserRE delete user_auth entries failure %d",
02842 status);
02843 snprintf(errMsg, sizeof errMsg, "Error removing user_auth entries");
02844 addRErrorMsg (&rsComm->rError, 0, errMsg);
02845 _rollback("chlDelUserRE");
02846 return(status);
02847 }
02848
02849
02850 removeMetaMapAndAVU(iValStr);
02851
02852
02853 snprintf(userStr, sizeof userStr, "%s#%s",
02854 userName2, zoneToUse);
02855 status = cmlAudit3(AU_DELETE_USER_RE,
02856 iValStr,
02857 rsComm->clientUser.userName,
02858 rsComm->clientUser.rodsZone,
02859 userStr,
02860 &icss);
02861 if (status != 0) {
02862 rodsLog(LOG_NOTICE,
02863 "chlDelUserRE cmlAudit3 failure %d",
02864 status);
02865 _rollback("chlDelUserRE");
02866 return(status);
02867 }
02868
02869 return(0);
02870 }
02871
02872
02873
02874
02875
02876
02877
02878 int chlRegCollByAdmin(rsComm_t *rsComm, collInfo_t *collInfo)
02879 {
02880 char myTime[50];
02881 char logicalEndName[MAX_NAME_LEN];
02882 char logicalParentDirName[MAX_NAME_LEN];
02883 rodsLong_t iVal;
02884 char collIdNum[MAX_NAME_LEN];
02885 char nextStr[MAX_NAME_LEN];
02886 char currStr[MAX_NAME_LEN];
02887 char currStr2[MAX_SQL_SIZE];
02888 int status;
02889 char tSQL[MAX_SQL_SIZE];
02890 char userName2[NAME_LEN];
02891 char zoneName[NAME_LEN];
02892
02893 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegCollByAdmin");
02894
02895 if (!icss.status) {
02896 return(CATALOG_NOT_CONNECTED);
02897 }
02898
02899
02900
02901 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ||
02902 rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
02903 int status2;
02904 status2 = cmlCheckGroupAdminAccess(
02905 rsComm->clientUser.userName,
02906 rsComm->clientUser.rodsZone,
02907 "", &icss);
02908 if (status2 != 0) return(status2);
02909 if (creatingUserByGroupAdmin==0) {
02910 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
02911 }
02912
02913 }
02914
02915 if (collInfo==0) {
02916 return(CAT_INVALID_ARGUMENT);
02917 }
02918
02919 status = splitPathByKey(collInfo->collName,
02920 logicalParentDirName, logicalEndName, '/');
02921
02922 if (strlen(logicalParentDirName)==0) {
02923 strcpy(logicalParentDirName, "/");
02924 strcpy(logicalEndName, collInfo->collName+1);
02925 }
02926
02927
02928 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegCollByAdmin SQL 1 ");
02929 status = cmlGetIntegerValueFromSql(
02930 "select coll_id from R_COLL_MAIN where coll_name=?",
02931 &iVal, logicalParentDirName, 0, 0, 0, 0, &icss);
02932 if (status < 0) {
02933 char errMsg[MAX_NAME_LEN+40];
02934 if (status == CAT_NO_ROWS_FOUND) {
02935 snprintf(errMsg, sizeof errMsg,
02936 "collection '%s' is unknown, cannot create %s under it",
02937 logicalParentDirName, logicalEndName);
02938 addRErrorMsg (&rsComm->rError, 0, errMsg);
02939 return(status);
02940 }
02941 _rollback("chlRegCollByAdmin");
02942 return(status);
02943 }
02944
02945 snprintf(collIdNum, MAX_NAME_LEN, "%d", status);
02946
02947
02948 cllNextValueString("R_ObjectID", nextStr, MAX_NAME_LEN);
02949
02950 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegCollByAdmin SQL 2");
02951 snprintf(tSQL, MAX_SQL_SIZE,
02952 "insert into R_COLL_MAIN (coll_id, parent_coll_name, coll_name, coll_owner_name, coll_owner_zone, coll_type, coll_info1, coll_info2, create_ts, modify_ts) values (%s, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
02953 nextStr);
02954
02955 getNowStr(myTime);
02956
02957 status = getLocalZone();
02958 if (status != 0) return(status);
02959
02960
02961 status = parseUserName(collInfo->collOwnerName, userName2, zoneName);
02962 if (zoneName[0]=='\0') {
02963 rstrcpy(zoneName, localZone, NAME_LEN);
02964 }
02965
02966 cllBindVars[cllBindVarCount++]=logicalParentDirName;
02967 cllBindVars[cllBindVarCount++]=collInfo->collName;
02968 cllBindVars[cllBindVarCount++]=userName2;
02969 if (strlen(collInfo->collOwnerZone)>0) {
02970 cllBindVars[cllBindVarCount++]=collInfo->collOwnerZone;
02971 }
02972 else {
02973 cllBindVars[cllBindVarCount++]=zoneName;
02974 }
02975 if (collInfo->collType != NULL) {
02976 cllBindVars[cllBindVarCount++]=collInfo->collType;
02977 }
02978 else {
02979 cllBindVars[cllBindVarCount++]="";
02980 }
02981 if (collInfo->collInfo1 != NULL) {
02982 cllBindVars[cllBindVarCount++]=collInfo->collInfo1;
02983 }
02984 else {
02985 cllBindVars[cllBindVarCount++]="";
02986 }
02987 if (collInfo->collInfo2 != NULL) {
02988 cllBindVars[cllBindVarCount++]=collInfo->collInfo2;
02989 }
02990 else {
02991 cllBindVars[cllBindVarCount++]="";
02992 }
02993 cllBindVars[cllBindVarCount++]=myTime;
02994 cllBindVars[cllBindVarCount++]=myTime;
02995 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegCollByAdmin SQL 3");
02996 status = cmlExecuteNoAnswerSql(tSQL,
02997 &icss);
02998 if (status != 0) {
02999 char errMsg[105];
03000 if (status == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
03001 snprintf(errMsg, 100, "Error %d %s",
03002 status,
03003 "CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME"
03004 );
03005 addRErrorMsg (&rsComm->rError, 0, errMsg);
03006 }
03007
03008 rodsLog(LOG_NOTICE,
03009 "chlRegCollByAdmin cmlExecuteNoAnswerSQL(insert) failure %d"
03010 ,status);
03011 _rollback("chlRegCollByAdmin");
03012 return(status);
03013 }
03014
03015
03016 cllCurrentValueString("R_ObjectID", currStr, MAX_NAME_LEN);
03017 snprintf(currStr2, MAX_SQL_SIZE, " %s ", currStr);
03018
03019 cllBindVars[cllBindVarCount++]=userName2;
03020 cllBindVars[cllBindVarCount++]=zoneName;
03021 cllBindVars[cllBindVarCount++]=ACCESS_OWN;
03022 cllBindVars[cllBindVarCount++]=myTime;
03023 cllBindVars[cllBindVarCount++]=myTime;
03024
03025 snprintf(tSQL, MAX_SQL_SIZE,
03026 "insert into R_OBJT_ACCESS values (%s, (select user_id from R_USER_MAIN where user_name=? and zone_name=?), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
03027 currStr2);
03028 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegCollByAdmin SQL 4");
03029 status = cmlExecuteNoAnswerSql(tSQL, &icss);
03030 if (status != 0) {
03031 rodsLog(LOG_NOTICE,
03032 "chlRegCollByAdmin cmlExecuteNoAnswerSql(insert access) failure %d",
03033 status);
03034 _rollback("chlRegCollByAdmin");
03035 return(status);
03036 }
03037
03038
03039 status = cmlAudit4(AU_REGISTER_COLL_BY_ADMIN,
03040 currStr2,
03041 "",
03042 userName2,
03043 zoneName,
03044 rsComm->clientUser.userName,
03045 &icss);
03046 if (status != 0) {
03047 rodsLog(LOG_NOTICE,
03048 "chlRegCollByAdmin cmlAudit4 failure %d",
03049 status);
03050 _rollback("chlRegCollByAdmin");
03051 return(status);
03052 }
03053
03054 return(0);
03055 }
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066 int chlRegColl(rsComm_t *rsComm, collInfo_t *collInfo) {
03067 char myTime[50];
03068 char logicalEndName[MAX_NAME_LEN];
03069 char logicalParentDirName[MAX_NAME_LEN];
03070 rodsLong_t iVal;
03071 char collIdNum[MAX_NAME_LEN];
03072 char nextStr[MAX_NAME_LEN];
03073 char currStr[MAX_NAME_LEN];
03074 char currStr2[MAX_SQL_SIZE];
03075 rodsLong_t status;
03076 char tSQL[MAX_SQL_SIZE];
03077 int inheritFlag;
03078
03079 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl");
03080
03081 if (!icss.status) {
03082 return(CATALOG_NOT_CONNECTED);
03083 }
03084
03085 status = splitPathByKey(collInfo->collName,
03086 logicalParentDirName, logicalEndName, '/');
03087
03088 if (strlen(logicalParentDirName)==0) {
03089 strcpy(logicalParentDirName, "/");
03090 strcpy(logicalEndName, collInfo->collName+1);
03091 }
03092
03093
03094
03095 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 1 ");
03096 status = cmlCheckDirAndGetInheritFlag(logicalParentDirName,
03097 rsComm->clientUser.userName,
03098 rsComm->clientUser.rodsZone,
03099 ACCESS_MODIFY_OBJECT, &inheritFlag, &icss);
03100 if (status < 0) {
03101 char errMsg[105];
03102 if (status == CAT_UNKNOWN_COLLECTION) {
03103 snprintf(errMsg, 100, "collection '%s' is unknown",
03104 logicalParentDirName);
03105 addRErrorMsg (&rsComm->rError, 0, errMsg);
03106 return(status);
03107 }
03108 _rollback("chlRegColl");
03109 return(status);
03110 }
03111 snprintf(collIdNum, MAX_NAME_LEN, "%lld", status);
03112
03113
03114 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 2");
03115 status = cmlGetIntegerValueFromSql(
03116 "select data_id from R_DATA_MAIN where data_name=? and coll_id=?",
03117 &iVal, logicalEndName, collIdNum, 0, 0, 0, &icss);
03118
03119 if (status == 0) {
03120 return(CAT_NAME_EXISTS_AS_DATAOBJ);
03121 }
03122
03123
03124
03125 cllNextValueString("R_ObjectID", nextStr, MAX_NAME_LEN);
03126
03127 getNowStr(myTime);
03128
03129 cllBindVars[cllBindVarCount++]=logicalParentDirName;
03130 cllBindVars[cllBindVarCount++]=collInfo->collName;
03131 cllBindVars[cllBindVarCount++]=rsComm->clientUser.userName;
03132 cllBindVars[cllBindVarCount++]=rsComm->clientUser.rodsZone;
03133 if (collInfo->collType != NULL) {
03134 cllBindVars[cllBindVarCount++]=collInfo->collType;
03135 }
03136 else {
03137 cllBindVars[cllBindVarCount++]="";
03138 }
03139 if (collInfo->collInfo1 != NULL) {
03140 cllBindVars[cllBindVarCount++]=collInfo->collInfo1;
03141 }
03142 else {
03143 cllBindVars[cllBindVarCount++]="";
03144 }
03145 if (collInfo->collInfo2 != NULL) {
03146 cllBindVars[cllBindVarCount++]=collInfo->collInfo2;
03147 }
03148 else {
03149 cllBindVars[cllBindVarCount++]="";
03150 }
03151 cllBindVars[cllBindVarCount++]=myTime;
03152 cllBindVars[cllBindVarCount++]=myTime;
03153 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 3");
03154 snprintf(tSQL, MAX_SQL_SIZE,
03155 "insert into R_COLL_MAIN (coll_id, parent_coll_name, coll_name, coll_owner_name, coll_owner_zone, coll_type, coll_info1, coll_info2, create_ts, modify_ts) values (%s, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
03156 nextStr);
03157 status = cmlExecuteNoAnswerSql(tSQL,
03158 &icss);
03159 if (status != 0) {
03160 rodsLog(LOG_NOTICE,
03161 "chlRegColl cmlExecuteNoAnswerSql(insert) failure %d",status);
03162 _rollback("chlRegColl");
03163 return(status);
03164 }
03165
03166
03167 cllCurrentValueString("R_ObjectID", currStr, MAX_NAME_LEN);
03168 snprintf(currStr2, MAX_SQL_SIZE, " %s ", currStr);
03169
03170 if (inheritFlag) {
03171
03172
03173 cllBindVars[0]=myTime;
03174 cllBindVars[1]=myTime;
03175 cllBindVars[2]=collIdNum;
03176 cllBindVarCount=3;
03177 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 4");
03178 snprintf(tSQL, MAX_SQL_SIZE,
03179 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select %s, user_id, access_type_id, ?, ? from R_OBJT_ACCESS where object_id = ?)",
03180 currStr2);
03181 status = cmlExecuteNoAnswerSql(tSQL, &icss);
03182
03183 if (status == 0) {
03184 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 5");
03185 #if ORA_ICAT
03186 char newCollectionID[MAX_NAME_LEN];
03187
03188
03189
03190
03191 status = cmlGetCurrentSeqVal(&icss);
03192
03193 if (status > 0) {
03194
03195 snprintf(newCollectionID, MAX_NAME_LEN, "%lld", status);
03196 cllBindVars[cllBindVarCount++]="1";
03197 cllBindVars[cllBindVarCount++]=myTime;
03198 cllBindVars[cllBindVarCount++]=newCollectionID;
03199 status = cmlExecuteNoAnswerSql(
03200 "update R_COLL_MAIN set coll_inheritance=?, modify_ts=? where coll_id=?",
03201 &icss);
03202 }
03203 #else
03204
03205
03206
03207
03208 cllBindVars[cllBindVarCount++]="1";
03209 cllBindVars[cllBindVarCount++]=myTime;
03210 snprintf(tSQL, MAX_SQL_SIZE,
03211 "update R_COLL_MAIN set coll_inheritance=?, modify_ts=? where coll_id=%s",
03212 currStr2);
03213 status = cmlExecuteNoAnswerSql(tSQL, &icss);
03214 #endif
03215 }
03216 }
03217 else {
03218 cllBindVars[cllBindVarCount++]=rsComm->clientUser.userName;
03219 cllBindVars[cllBindVarCount++]=rsComm->clientUser.rodsZone;
03220 cllBindVars[cllBindVarCount++]=ACCESS_OWN;
03221 cllBindVars[cllBindVarCount++]=myTime;
03222 cllBindVars[cllBindVarCount++]=myTime;
03223 snprintf(tSQL, MAX_SQL_SIZE,
03224 "insert into R_OBJT_ACCESS values (%s, (select user_id from R_USER_MAIN where user_name=? and zone_name=?), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
03225 currStr2);
03226 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegColl SQL 6");
03227 status = cmlExecuteNoAnswerSql(tSQL, &icss);
03228 }
03229 if (status != 0) {
03230 rodsLog(LOG_NOTICE,
03231 "chlRegColl cmlExecuteNoAnswerSql(insert access) failure %d",
03232 status);
03233 _rollback("chlRegColl");
03234 return(status);
03235 }
03236
03237
03238 status = cmlAudit4(AU_REGISTER_COLL,
03239 currStr2,
03240 "",
03241 rsComm->clientUser.userName,
03242 rsComm->clientUser.rodsZone,
03243 collInfo->collName,
03244 &icss);
03245 if (status != 0) {
03246 rodsLog(LOG_NOTICE,
03247 "chlRegColl cmlAudit4 failure %d",
03248 status);
03249 _rollback("chlRegColl");
03250 return(status);
03251 }
03252
03253 status = cmlExecuteNoAnswerSql("commit", &icss);
03254 if (status != 0) {
03255 rodsLog(LOG_NOTICE,
03256 "chlRegColl cmlExecuteNoAnswerSql commit failure %d",
03257 status);
03258 return(status);
03259 }
03260
03261 return(status);
03262 }
03263
03264
03265
03266
03267
03268
03269
03270
03271
03272
03273 int chlModColl(rsComm_t *rsComm, collInfo_t *collInfo) {
03274 char myTime[50];
03275 rodsLong_t status;
03276 char tSQL[MAX_SQL_SIZE];
03277 int count;
03278 rodsLong_t iVal;
03279 char iValStr[60];
03280
03281 if (logSQL!=0) rodsLog(LOG_SQL, "chlModColl");
03282
03283 if( NULL == collInfo ) {
03284 rodsLog( LOG_ERROR, "chlModColl :: null input parameter collInfo" );
03285 return -1;
03286 }
03287
03288 if (!icss.status) {
03289 return(CATALOG_NOT_CONNECTED);
03290 }
03291
03292
03293 iVal = cmlCheckDir(collInfo->collName, rsComm->clientUser.userName,
03294 rsComm->clientUser.rodsZone,
03295 ACCESS_MODIFY_OBJECT, &icss);
03296
03297 if (iVal < 0) {
03298 char errMsg[105];
03299 if (iVal==CAT_UNKNOWN_COLLECTION) {
03300 snprintf(errMsg, 100, "collection '%s' is unknown",
03301 collInfo->collName);
03302 addRErrorMsg (&rsComm->rError, 0, errMsg);
03303 return(CAT_UNKNOWN_COLLECTION);
03304 }
03305 if (iVal==CAT_NO_ACCESS_PERMISSION) {
03306 snprintf(errMsg, 100, "no permission to update collection '%s'",
03307 collInfo->collName);
03308 addRErrorMsg (&rsComm->rError, 0, errMsg);
03309 return (CAT_NO_ACCESS_PERMISSION);
03310 }
03311 return(iVal);
03312 }
03313
03314
03315
03316
03317
03318 strncpy(tSQL, "update R_COLL_MAIN set ", MAX_SQL_SIZE);
03319 count=0;
03320 if (collInfo->collType != NULL && strlen(collInfo->collType)>0) {
03321 if (strcmp(collInfo->collType,"NULL_SPECIAL_VALUE")==0) {
03322
03323 cllBindVars[cllBindVarCount++]="";
03324 }
03325 else {
03326 cllBindVars[cllBindVarCount++]=collInfo->collType;
03327 }
03328 strncat(tSQL, "coll_type=? ", MAX_SQL_SIZE);
03329 count++;
03330 }
03331 if (collInfo->collInfo1 != NULL && strlen(collInfo->collInfo1)>0) {
03332 if (strcmp(collInfo->collInfo1,"NULL_SPECIAL_VALUE")==0) {
03333
03334 cllBindVars[cllBindVarCount++]="";
03335 } else {
03336 cllBindVars[cllBindVarCount++]=collInfo->collInfo1;
03337 }
03338 if (count>0) strncat(tSQL, ",", MAX_SQL_SIZE);
03339 strncat(tSQL, "coll_info1=? ", MAX_SQL_SIZE);
03340 count++;
03341 }
03342 if (collInfo->collInfo2 != NULL && strlen(collInfo->collInfo2)>0) {
03343 if (strcmp(collInfo->collInfo2,"NULL_SPECIAL_VALUE")==0) {
03344
03345 cllBindVars[cllBindVarCount++]="";
03346 } else {
03347 cllBindVars[cllBindVarCount++]=collInfo->collInfo2;
03348 }
03349 if (count>0) strncat(tSQL, ",", MAX_SQL_SIZE);
03350 strncat(tSQL, "coll_info2=? ", MAX_SQL_SIZE);
03351 count++;
03352 }
03353 if (count==0) return(CAT_INVALID_ARGUMENT);
03354 getNowStr(myTime);
03355 cllBindVars[cllBindVarCount++]=myTime;
03356 cllBindVars[cllBindVarCount++]=collInfo->collName;
03357 strncat(tSQL, ", modify_ts=? where coll_name=?", MAX_SQL_SIZE);
03358
03359 if (logSQL!=0) rodsLog(LOG_SQL, "chlModColl SQL 1");
03360 status = cmlExecuteNoAnswerSql(tSQL,
03361 &icss);
03362
03363
03364 snprintf(iValStr, sizeof iValStr, "%lld", iVal);
03365 status = cmlAudit3(AU_REGISTER_COLL,
03366 iValStr,
03367 rsComm->clientUser.userName,
03368 rsComm->clientUser.rodsZone,
03369 collInfo->collName,
03370 &icss);
03371 if (status != 0) {
03372 rodsLog(LOG_NOTICE,
03373 "chlModColl cmlAudit3 failure %d",
03374 status);
03375 return(status);
03376 }
03377
03378
03379 if (status != 0) {
03380 rodsLog(LOG_NOTICE,
03381 "chlModColl cmlExecuteNoAnswerSQL(update) failure %d", status);
03382 return(status);
03383 }
03384 return(0);
03385 }
03386
03387
03388
03389 static bool allowed_zone_char( const char _c ) {
03390 return ( !std::isalnum( _c ) &&
03391 !( '_' == _c ) &&
03392 !( '-' == _c ) );
03393 }
03394
03395
03396
03397 eirods::error validate_zone_name(
03398 std::string _zone_name ) {
03399 std::string::iterator itr = std::find_if( _zone_name.begin(),
03400 _zone_name.end(),
03401 allowed_zone_char );
03402 if( itr != _zone_name.end() ) {
03403 std::stringstream msg;
03404 msg << "validate_zone_name failed for zone [";
03405 msg << _zone_name;
03406 msg << "]";
03407 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
03408 }
03409
03410 return SUCCESS();
03411
03412 }
03413
03414
03415 int chlRegZone(rsComm_t *rsComm,
03416 char *zoneName, char *zoneType, char *zoneConnInfo,
03417 char *zoneComment) {
03418 char nextStr[MAX_NAME_LEN];
03419 char tSQL[MAX_SQL_SIZE];
03420 int status;
03421 char myTime[50];
03422
03423 if( !rsComm || !zoneName || !zoneType || !zoneConnInfo || !zoneComment ) {
03424 return SYS_INVALID_INPUT_PARAM;
03425 }
03426
03427 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegZone");
03428
03429 if (!icss.status) {
03430 return(CATALOG_NOT_CONNECTED);
03431 }
03432
03433 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03434 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03435 }
03436 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03437 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03438 }
03439
03440 if (strncmp(zoneType, "remote", 6) != 0) {
03441 addRErrorMsg (&rsComm->rError, 0,
03442 "Currently, only zones of type 'remote' are allowed");
03443 return(CAT_INVALID_ARGUMENT);
03444 }
03445
03446
03447
03448 eirods::error ret = validate_zone_name( zoneName );
03449 if( !ret.ok() ) {
03450 eirods::log( ret );
03451 return SYS_INVALID_INPUT_PARAM;
03452 }
03453
03454
03455 cllNextValueString("R_ObjectID", nextStr, MAX_NAME_LEN);
03456
03457 getNowStr(myTime);
03458
03459 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegZone SQL 1 ");
03460 cllBindVars[cllBindVarCount++]=zoneName;
03461 cllBindVars[cllBindVarCount++]=zoneConnInfo;
03462 cllBindVars[cllBindVarCount++]=zoneComment;
03463 cllBindVars[cllBindVarCount++]=myTime;
03464 cllBindVars[cllBindVarCount++]=myTime;
03465
03466 snprintf(tSQL, MAX_SQL_SIZE,
03467 "insert into R_ZONE_MAIN (zone_id, zone_name, zone_type_name, zone_conn_string, r_comment, create_ts, modify_ts) values (%s, ?, 'remote', ?, ?, ?, ?)",
03468 nextStr);
03469 status = cmlExecuteNoAnswerSql(tSQL,
03470 &icss);
03471 if (status != 0) {
03472 rodsLog(LOG_NOTICE,
03473 "chlRegZone cmlExecuteNoAnswerSql(insert) failure %d",status);
03474 _rollback("chlRegZone");
03475 return(status);
03476 }
03477
03478
03479 status = cmlAudit3(AU_REGISTER_ZONE, "0",
03480 rsComm->clientUser.userName,
03481 rsComm->clientUser.rodsZone,
03482 "", &icss);
03483 if (status != 0) {
03484 rodsLog(LOG_NOTICE,
03485 "chlRegResc cmlAudit3 failure %d",
03486 status);
03487 return(status);
03488 }
03489
03490
03491 status = cmlExecuteNoAnswerSql("commit", &icss);
03492 if (status != 0) {
03493 rodsLog(LOG_NOTICE,
03494 "chlRegZone cmlExecuteNoAnswerSql commit failure %d",
03495 status);
03496 return(status);
03497 }
03498
03499 return(0);
03500 }
03501
03502
03503
03504 int chlModZone(rsComm_t *rsComm, char *zoneName, char *option,
03505 char *optionValue) {
03506 int status, OK;
03507 char myTime[50];
03508 char zoneId[MAX_NAME_LEN];
03509 char commentStr[200];
03510
03511 if (logSQL!=0) rodsLog(LOG_SQL, "chlModZone");
03512
03513 if (zoneName == NULL || option==NULL || optionValue==NULL) {
03514 return (CAT_INVALID_ARGUMENT);
03515 }
03516
03517 if (*zoneName == '\0' || *option == '\0' || *optionValue=='\0') {
03518 return (CAT_INVALID_ARGUMENT);
03519 }
03520
03521 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03522 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03523 }
03524 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03525 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03526 }
03527
03528 status = getLocalZone();
03529 if (status != 0) return(status);
03530
03531 zoneId[0]='\0';
03532 if (logSQL!=0) rodsLog(LOG_SQL, "chlModZone SQL 1 ");
03533 status = cmlGetStringValueFromSql(
03534 "select zone_id from R_ZONE_MAIN where zone_name=?",
03535 zoneId, MAX_NAME_LEN, zoneName, "", 0, &icss);
03536 if (status != 0) {
03537 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_ZONE);
03538 return(status);
03539 }
03540
03541 getNowStr(myTime);
03542 OK=0;
03543 if (strcmp(option, "comment")==0) {
03544 cllBindVars[cllBindVarCount++]=optionValue;
03545 cllBindVars[cllBindVarCount++]=myTime;
03546 cllBindVars[cllBindVarCount++]=zoneId;
03547 if (logSQL!=0) rodsLog(LOG_SQL, "chlModZone SQL 3");
03548 status = cmlExecuteNoAnswerSql(
03549 "update R_ZONE_MAIN set r_comment = ?, modify_ts=? where zone_id=?",
03550 &icss);
03551 if (status != 0) {
03552 rodsLog(LOG_NOTICE,
03553 "chlModZone cmlExecuteNoAnswerSql update failure %d",
03554 status);
03555 return(status);
03556 }
03557 OK=1;
03558 }
03559 if (strcmp(option, "conn")==0) {
03560 cllBindVars[cllBindVarCount++]=optionValue;
03561 cllBindVars[cllBindVarCount++]=myTime;
03562 cllBindVars[cllBindVarCount++]=zoneId;
03563 if (logSQL!=0) rodsLog(LOG_SQL, "chlModZone SQL 5");
03564 status = cmlExecuteNoAnswerSql(
03565 "update R_ZONE_MAIN set zone_conn_string = ?, modify_ts=? where zone_id=?",
03566 &icss);
03567 if (status != 0) {
03568 rodsLog(LOG_NOTICE,
03569 "chlModZone cmlExecuteNoAnswerSql update failure %d",
03570 status);
03571 return(status);
03572 }
03573 OK=1;
03574 }
03575 if (strcmp(option, "name")==0) {
03576 if (strcmp(zoneName,localZone)==0) {
03577 addRErrorMsg (&rsComm->rError, 0,
03578 "It is not valid to rename the local zone via chlModZone; iadmin should use acRenameLocalZone");
03579 return (CAT_INVALID_ARGUMENT);
03580 }
03581 cllBindVars[cllBindVarCount++]=optionValue;
03582 cllBindVars[cllBindVarCount++]=myTime;
03583 cllBindVars[cllBindVarCount++]=zoneId;
03584 if (logSQL!=0) rodsLog(LOG_SQL, "chlModZone SQL 5");
03585 status = cmlExecuteNoAnswerSql(
03586 "update R_ZONE_MAIN set zone_name = ?, modify_ts=? where zone_id=?",
03587 &icss);
03588 if (status != 0) {
03589 rodsLog(LOG_NOTICE,
03590 "chlModZone cmlExecuteNoAnswerSql update failure %d",
03591 status);
03592 return(status);
03593 }
03594 OK=1;
03595 }
03596 if (OK==0) {
03597 return (CAT_INVALID_ARGUMENT);
03598 }
03599
03600
03601 snprintf(commentStr, sizeof commentStr, "%s %s", option, optionValue);
03602 status = cmlAudit3(AU_MOD_ZONE,
03603 zoneId,
03604 rsComm->clientUser.userName,
03605 rsComm->clientUser.rodsZone,
03606 commentStr,
03607 &icss);
03608 if (status != 0) {
03609 rodsLog(LOG_NOTICE,
03610 "chlModZone cmlAudit3 failure %d",
03611 status);
03612 return(status);
03613 }
03614
03615 status = cmlExecuteNoAnswerSql("commit", &icss);
03616 if (status != 0) {
03617 rodsLog(LOG_NOTICE,
03618 "chlModZone cmlExecuteNoAnswerSql commit failure %d",
03619 status);
03620 return(status);
03621 }
03622 return(0);
03623 }
03624
03625
03626 int chlRenameColl(rsComm_t *rsComm, char *oldCollName, char *newCollName) {
03627 int status;
03628 rodsLong_t status1;
03629
03630
03631
03632 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameColl SQL 1 ");
03633
03634 status1 = cmlCheckDir(oldCollName,
03635 rsComm->clientUser.userName,
03636 rsComm->clientUser.rodsZone,
03637 ACCESS_OWN,
03638 &icss);
03639
03640 if (status1 < 0) {
03641 return(status1);
03642 }
03643
03644
03645 status = chlRenameObject(rsComm, status1, newCollName);
03646 return(status);
03647 }
03648
03649
03650
03651 int chlRenameLocalZone(rsComm_t *rsComm, char *oldZoneName, char *newZoneName) {
03652 int status;
03653 char zoneId[MAX_NAME_LEN];
03654 char myTime[50];
03655 char commentStr[200];
03656
03657 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone");
03658
03659 if (!icss.status) {
03660 return(CATALOG_NOT_CONNECTED);
03661 }
03662
03663 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03664 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03665 }
03666 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03667 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03668 }
03669
03670 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 1 ");
03671 getLocalZone();
03672
03673 if (strcmp(localZone, oldZoneName) != 0) {
03674 return(CAT_INVALID_ARGUMENT);
03675 }
03676
03677
03678 zoneId[0]='\0';
03679 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 2 ");
03680 status = cmlGetStringValueFromSql(
03681 "select zone_id from R_ZONE_MAIN where zone_name=?",
03682 zoneId, MAX_NAME_LEN, newZoneName, "", 0, &icss);
03683 if (status != CAT_NO_ROWS_FOUND) return(CAT_INVALID_ZONE);
03684
03685 getNowStr(myTime);
03686
03687
03688
03689
03690
03691 snprintf(commentStr, sizeof commentStr, "renamed local zone %s to %s",
03692 oldZoneName, newZoneName);
03693 status = cmlAudit3(AU_MOD_ZONE,
03694 "0",
03695 rsComm->clientUser.userName,
03696 rsComm->clientUser.rodsZone,
03697 commentStr,
03698 &icss);
03699 if (status != 0) {
03700 rodsLog(LOG_NOTICE,
03701 "chlRenameLocalZone cmlAudit3 failure %d",
03702 status);
03703 return(status);
03704 }
03705
03706
03707 cllBindVars[cllBindVarCount++]=newZoneName;
03708 cllBindVars[cllBindVarCount++]=myTime;
03709 cllBindVars[cllBindVarCount++]=oldZoneName;
03710 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 3 ");
03711 status = cmlExecuteNoAnswerSql(
03712 "update R_COLL_MAIN set coll_owner_zone = ?, modify_ts=? where coll_owner_zone=?",
03713 &icss);
03714 if (status != 0) {
03715 rodsLog(LOG_NOTICE,
03716 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03717 status);
03718 return(status);
03719 }
03720
03721
03722 cllBindVars[cllBindVarCount++]=newZoneName;
03723 cllBindVars[cllBindVarCount++]=myTime;
03724 cllBindVars[cllBindVarCount++]=oldZoneName;
03725 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 4 ");
03726 status = cmlExecuteNoAnswerSql(
03727 "update R_DATA_MAIN set data_owner_zone = ?, modify_ts=? where data_owner_zone=?",
03728 &icss);
03729 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
03730 rodsLog(LOG_NOTICE,
03731 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03732 status);
03733 return(status);
03734 }
03735
03736
03737 cllBindVars[cllBindVarCount++]=newZoneName;
03738 cllBindVars[cllBindVarCount++]=myTime;
03739 cllBindVars[cllBindVarCount++]=oldZoneName;
03740 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 5 ");
03741 status = cmlExecuteNoAnswerSql(
03742 "update R_RESC_MAIN set zone_name = ?, modify_ts=? where zone_name=?",
03743 &icss);
03744 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
03745 rodsLog(LOG_NOTICE,
03746 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03747 status);
03748 return(status);
03749 }
03750
03751
03752 cllBindVars[cllBindVarCount++]=newZoneName;
03753 cllBindVars[cllBindVarCount++]=myTime;
03754 cllBindVars[cllBindVarCount++]=oldZoneName;
03755 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 6 ");
03756 status = cmlExecuteNoAnswerSql(
03757 "update R_RULE_MAIN set rule_owner_zone=?, modify_ts=? where rule_owner_zone=?",
03758 &icss);
03759 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
03760 rodsLog(LOG_NOTICE,
03761 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03762 status);
03763 return(status);
03764 }
03765
03766
03767 cllBindVars[cllBindVarCount++]=newZoneName;
03768 cllBindVars[cllBindVarCount++]=myTime;
03769 cllBindVars[cllBindVarCount++]=oldZoneName;
03770 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 7 ");
03771 status = cmlExecuteNoAnswerSql(
03772 "update R_USER_MAIN set zone_name=?, modify_ts=? where zone_name=?",
03773 &icss);
03774 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
03775 rodsLog(LOG_NOTICE,
03776 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03777 status);
03778 return(status);
03779 }
03780
03781
03782 cllBindVars[cllBindVarCount++]=newZoneName;
03783 cllBindVars[cllBindVarCount++]=myTime;
03784 cllBindVars[cllBindVarCount++]=oldZoneName;
03785 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameLocalZone SQL 8 ");
03786 status = cmlExecuteNoAnswerSql(
03787 "update R_ZONE_MAIN set zone_name=?, modify_ts=? where zone_name=?",
03788 &icss);
03789 if (status != 0) {
03790 rodsLog(LOG_NOTICE,
03791 "chlRenameLocalZone cmlExecuteNoAnswerSql update failure %d",
03792 status);
03793 return(status);
03794 }
03795
03796 return(0);
03797 }
03798
03799
03800 int chlDelZone(rsComm_t *rsComm, char *zoneName) {
03801 int status;
03802 char zoneType[MAX_NAME_LEN];
03803
03804 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelZone");
03805
03806 if (!icss.status) {
03807 return(CATALOG_NOT_CONNECTED);
03808 }
03809
03810 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03811 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03812 }
03813 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03814 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03815 }
03816
03817 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelZone SQL 1 ");
03818
03819 status = cmlGetStringValueFromSql(
03820 "select zone_type_name from R_ZONE_MAIN where zone_name=?",
03821 zoneType, MAX_NAME_LEN, zoneName, 0, 0, &icss);
03822 if (status != 0) {
03823 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_ZONE);
03824 return(status);
03825 }
03826
03827 if (strcmp(zoneType, "remote") != 0) {
03828 addRErrorMsg (&rsComm->rError, 0,
03829 "It is not permitted to remove the local zone");
03830 return(CAT_INVALID_ARGUMENT);
03831 }
03832
03833 cllBindVars[cllBindVarCount++]=zoneName;
03834 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelZone 2");
03835 status = cmlExecuteNoAnswerSql(
03836 "delete from R_ZONE_MAIN where zone_name = ?",
03837 &icss);
03838 if (status != 0) {
03839 rodsLog(LOG_NOTICE,
03840 "chlDelZone cmlExecuteNoAnswerSql delete failure %d",
03841 status);
03842 return(status);
03843 }
03844
03845
03846 status = cmlAudit3(AU_DELETE_ZONE,
03847 "0",
03848 rsComm->clientUser.userName,
03849 rsComm->clientUser.rodsZone,
03850 zoneName,
03851 &icss);
03852 if (status != 0) {
03853 rodsLog(LOG_NOTICE,
03854 "chlDelZone cmlAudit3 failure %d",
03855 status);
03856 _rollback("chlDelZone");
03857 return(status);
03858 }
03859
03860 status = cmlExecuteNoAnswerSql("commit", &icss);
03861 if (status != 0) {
03862 rodsLog(LOG_NOTICE,
03863 "chlDelZone cmlExecuteNoAnswerSql commit failure %d",
03864 status);
03865 return(status);
03866 }
03867
03868 return(0);
03869 }
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881
03882
03883
03884
03885
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895 int chlSimpleQuery(rsComm_t *rsComm, char *sql,
03896 char *arg1, char *arg2, char *arg3, char *arg4,
03897 int format, int *control,
03898 char *outBuf, int maxOutBuf) {
03899 int stmtNum, status, nCols, i, needToGet, didGet;
03900 int rowSize;
03901 int rows;
03902 int OK;
03903
03904 char *allowedSQL[]={
03905 "select token_name from R_TOKN_MAIN where token_namespace = 'token_namespace'",
03906 "select token_name from R_TOKN_MAIN where token_namespace = ?",
03907 "select * from R_TOKN_MAIN where token_namespace = ? and token_name like ?",
03908 "select resc_name from R_RESC_MAIN",
03909 "select * from R_RESC_MAIN where resc_name=?",
03910 "select zone_name from R_ZONE_MAIN",
03911 "select * from R_ZONE_MAIN where zone_name=?",
03912 "select user_name from R_USER_MAIN where user_type_name='rodsgroup'",
03913 "select user_name||'#'||zone_name from R_USER_MAIN, R_USER_GROUP where R_USER_GROUP.user_id=R_USER_MAIN.user_id and R_USER_GROUP.group_user_id=(select user_id from R_USER_MAIN where user_name=?)",
03914 "select * from R_DATA_MAIN where data_id=?",
03915 "select data_name, data_id, data_repl_num from R_DATA_MAIN where coll_id =(select coll_id from R_COLL_MAIN where coll_name=?)",
03916 "select coll_name from R_COLL_MAIN where parent_coll_name=?",
03917 "select * from R_USER_MAIN where user_name=?",
03918 "select user_name||'#'||zone_name from R_USER_MAIN where user_type_name != 'rodsgroup'",
03919 "select R_RESC_GROUP.resc_group_name, R_RESC_GROUP.resc_id, resc_name, R_RESC_GROUP.create_ts, R_RESC_GROUP.modify_ts from R_RESC_MAIN, R_RESC_GROUP where R_RESC_MAIN.resc_id = R_RESC_GROUP.resc_id and resc_group_name=?",
03920 "select distinct resc_group_name from R_RESC_GROUP",
03921 "select coll_id from R_COLL_MAIN where coll_name = ?",
03922 "select * from R_USER_MAIN where user_name=? and zone_name=?",
03923 "select user_name from R_USER_MAIN where zone_name=? and user_type_name != 'rodsgroup'",
03924 "select zone_name from R_ZONE_MAIN where zone_type_name=?",
03925 "select user_name, user_auth_name from R_USER_AUTH, R_USER_MAIN where R_USER_AUTH.user_id = R_USER_MAIN.user_id and R_USER_MAIN.user_name=?",
03926 "select user_name, user_auth_name from R_USER_AUTH, R_USER_MAIN where R_USER_AUTH.user_id = R_USER_MAIN.user_id and R_USER_MAIN.user_name=? and R_USER_MAIN.zone_name=?",
03927 "select user_name, user_auth_name from R_USER_AUTH, R_USER_MAIN where R_USER_AUTH.user_id = R_USER_MAIN.user_id",
03928 "select user_name, user_auth_name from R_USER_AUTH, R_USER_MAIN where R_USER_AUTH.user_id = R_USER_MAIN.user_id and R_USER_AUTH.user_auth_name=?",
03929 "select user_name, R_USER_MAIN.zone_name, resc_name, quota_limit, quota_over, R_QUOTA_MAIN.modify_ts from R_QUOTA_MAIN, R_USER_MAIN, R_RESC_MAIN where R_USER_MAIN.user_id = R_QUOTA_MAIN.user_id and R_RESC_MAIN.resc_id = R_QUOTA_MAIN.resc_id",
03930 "select user_name, R_USER_MAIN.zone_name, resc_name, quota_limit, quota_over, R_QUOTA_MAIN.modify_ts from R_QUOTA_MAIN, R_USER_MAIN, R_RESC_MAIN where R_USER_MAIN.user_id = R_QUOTA_MAIN.user_id and R_RESC_MAIN.resc_id = R_QUOTA_MAIN.resc_id and user_name=? and R_USER_MAIN.zone_name=?",
03931 "select user_name, R_USER_MAIN.zone_name, quota_limit, quota_over, R_QUOTA_MAIN.modify_ts from R_QUOTA_MAIN, R_USER_MAIN where R_USER_MAIN.user_id = R_QUOTA_MAIN.user_id and R_QUOTA_MAIN.resc_id = 0",
03932 "select user_name, R_USER_MAIN.zone_name, quota_limit, quota_over, R_QUOTA_MAIN.modify_ts from R_QUOTA_MAIN, R_USER_MAIN where R_USER_MAIN.user_id = R_QUOTA_MAIN.user_id and R_QUOTA_MAIN.resc_id = 0 and user_name=? and R_USER_MAIN.zone_name=?",
03933 ""
03934 };
03935
03936 if (logSQL!=0) rodsLog(LOG_SQL, "chlSimpleQuery");
03937
03938 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03939 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03940 }
03941 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
03942 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
03943 }
03944
03945
03946 OK=0;
03947 for (i=0;;i++) {
03948 if (strlen(allowedSQL[i]) < 1) break;
03949 if (strcasecmp(allowedSQL[i], sql)==0) {
03950 OK=1;
03951 break;
03952 }
03953 }
03954
03955 if (OK == 0) {
03956 return(CAT_INVALID_ARGUMENT);
03957 }
03958
03959
03960
03961 if (i==0 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 1 ");
03962 if (i==1 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 2");
03963 if (i==2 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 3");
03964 if (i==3 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 4");
03965 if (i==4 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 5");
03966 if (i==5 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 6");
03967 if (i==6 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 7");
03968 if (i==7 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 8");
03969 if (i==8 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 9");
03970 if (i==9 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 10");
03971 if (i==10 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 11");
03972 if (i==11 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 12");
03973 if (i==12 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 13");
03974 if (i==13 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 14");
03975
03976
03977
03978 if (i==17 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 18");
03979 if (i==18 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 19");
03980 if (i==19 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 20");
03981 if (i==20 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 21");
03982 if (i==21 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 22");
03983 if (i==22 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 23");
03984 if (i==23 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 24");
03985 if (i==24 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 25");
03986 if (i==25 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 26");
03987 if (i==26 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 27");
03988 if (i==27 && logSQL) rodsLog(LOG_SQL, "chlSimpleQuery SQL 28");
03989
03990 outBuf[0]='\0';
03991 needToGet=1;
03992 didGet=0;
03993 rowSize=0;
03994 rows=0;
03995 if (*control==0) {
03996 status = cmlGetFirstRowFromSqlBV(sql, arg1, arg2, arg3, arg4,
03997 &stmtNum, &icss);
03998 if (status < 0) {
03999 if (status != CAT_NO_ROWS_FOUND) {
04000 rodsLog(LOG_NOTICE,
04001 "chlSimpleQuery cmlGetFirstRowFromSqlBV failure %d",
04002 status);
04003 }
04004 return(status);
04005 }
04006 didGet=1;
04007 needToGet=0;
04008 *control = stmtNum+1;
04009 }
04010 else {
04011 stmtNum = *control - 1;
04012 }
04013
04014 for (;;) {
04015 if (needToGet) {
04016 status = cmlGetNextRowFromStatement(stmtNum, &icss);
04017 if (status == CAT_NO_ROWS_FOUND) {
04018 *control = 0;
04019 if (didGet) {
04020 if (format == 2) {
04021 i = strlen(outBuf);
04022 outBuf[i-1]='\0';
04023 }
04024 return(0);
04025 }
04026 return(status);
04027 }
04028 if (status < 0) {
04029 rodsLog(LOG_NOTICE,
04030 "chlSimpleQuery cmlGetNextRowFromStatement failure %d",
04031 status);
04032 return(status);
04033 }
04034 *control = stmtNum+1;
04035 didGet=1;
04036 }
04037 needToGet=1;
04038 nCols = icss.stmtPtr[stmtNum]->numOfCols;
04039 if (rows==0 && format==3) {
04040 for (i = 0; i < nCols ; i++ ) {
04041 rstrcat(outBuf, icss.stmtPtr[stmtNum]->resultColName[i],maxOutBuf);
04042 rstrcat(outBuf, " ", maxOutBuf);
04043 }
04044 if (i != nCols-1) {
04045
04046 rstrcat(outBuf, " ", maxOutBuf);
04047 }
04048
04049 }
04050 rows++;
04051 for (i = 0; i < nCols ; i++ ) {
04052 if (format==1 || format==3) {
04053 if (strlen(icss.stmtPtr[stmtNum]->resultValue[i])==0) {
04054 rstrcat(outBuf, "- ", maxOutBuf);
04055 }
04056 else {
04057 rstrcat(outBuf, icss.stmtPtr[stmtNum]->resultValue[i],
04058 maxOutBuf);
04059 rstrcat(outBuf, " ", maxOutBuf);
04060 }
04061 }
04062 if (format == 2) {
04063 rstrcat(outBuf, icss.stmtPtr[stmtNum]->resultColName[i],maxOutBuf);
04064 rstrcat(outBuf, ": ", maxOutBuf);
04065 rstrcat(outBuf, icss.stmtPtr[stmtNum]->resultValue[i], maxOutBuf);
04066 rstrcat(outBuf, "\n", maxOutBuf);
04067 }
04068 }
04069 rstrcat(outBuf, "\n", maxOutBuf);
04070 if (rowSize==0) rowSize=strlen(outBuf);
04071 if ((int) strlen(outBuf)+rowSize+20 > maxOutBuf) {
04072 return(0);
04073 }
04074 }
04075 return 0;
04076 }
04077
04078
04079
04080 int chlDelCollByAdmin(rsComm_t *rsComm, collInfo_t *collInfo) {
04081 rodsLong_t iVal;
04082 char logicalEndName[MAX_NAME_LEN];
04083 char logicalParentDirName[MAX_NAME_LEN];
04084 char collIdNum[MAX_NAME_LEN];
04085 int status;
04086
04087 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelCollByAdmin");
04088
04089 if (!icss.status) {
04090 return(CATALOG_NOT_CONNECTED);
04091 }
04092
04093 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
04094 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
04095 }
04096 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
04097 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
04098 }
04099
04100 if (collInfo==0) {
04101 return(CAT_INVALID_ARGUMENT);
04102 }
04103
04104 status = splitPathByKey(collInfo->collName,
04105 logicalParentDirName, logicalEndName, '/');
04106
04107 if (strlen(logicalParentDirName)==0) {
04108 strcpy(logicalParentDirName, "/");
04109 strcpy(logicalEndName, collInfo->collName+1);
04110 }
04111
04112
04113 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelCollByAdmin SQL 1 ");
04114 status = cmlGetIntegerValueFromSql(
04115 "select coll_id from R_COLL_MAIN where parent_coll_name=? union select coll_id from R_DATA_MAIN where coll_id=(select coll_id from R_COLL_MAIN where coll_name=?)",
04116 &iVal, collInfo->collName, collInfo->collName, 0, 0, 0, &icss);
04117
04118 if (status != CAT_NO_ROWS_FOUND) {
04119 if (status == 0) {
04120 char errMsg[105];
04121 snprintf(errMsg, 100, "collection '%s' is not empty",
04122 collInfo->collName);
04123 addRErrorMsg (&rsComm->rError, 0, errMsg);
04124 return(CAT_COLLECTION_NOT_EMPTY);
04125 }
04126 _rollback("chlDelCollByAdmin");
04127 return(status);
04128 }
04129
04130
04131 cllBindVars[cllBindVarCount++]=collInfo->collName;
04132 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelCollByAdmin SQL 2");
04133 status = cmlExecuteNoAnswerSql(
04134 "delete from R_OBJT_ACCESS where object_id=(select coll_id from R_COLL_MAIN where coll_name=?)",
04135 &icss);
04136 if (status != 0) {
04137
04138 rodsLog(LOG_NOTICE,
04139 "chlDelCollByAdmin delete access failure %d",
04140 status);
04141 _rollback("chlDelCollByAdmin");
04142 }
04143
04144
04145 snprintf(collIdNum, MAX_NAME_LEN, "%lld", iVal);
04146 removeMetaMapAndAVU(collIdNum);
04147
04148
04149 status = cmlAudit4(AU_DELETE_COLL_BY_ADMIN,
04150 "select coll_id from R_COLL_MAIN where coll_name=?",
04151 collInfo->collName,
04152 rsComm->clientUser.userName,
04153 rsComm->clientUser.rodsZone,
04154 collInfo->collName,
04155 &icss);
04156 if (status != 0) {
04157 rodsLog(LOG_NOTICE,
04158 "chlDelCollByAdmin cmlAudit4 failure %d",
04159 status);
04160 _rollback("chlDelCollByAdmin");
04161 return(status);
04162 }
04163
04164
04165
04166 cllBindVars[cllBindVarCount++]=collInfo->collName;
04167 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelCollByAdmin SQL 3");
04168 status = cmlExecuteNoAnswerSql("delete from R_COLL_MAIN where coll_name=?",
04169 &icss);
04170
04171 if (status != 0) {
04172 char errMsg[105];
04173 snprintf(errMsg, 100, "collection '%s' is unknown",
04174 collInfo->collName);
04175 addRErrorMsg (&rsComm->rError, 0, errMsg);
04176 _rollback("chlDelCollByAdmin");
04177 return(CAT_UNKNOWN_COLLECTION);
04178 }
04179
04180 return(0);
04181 }
04182
04183
04184
04185 int chlDelColl(rsComm_t *rsComm, collInfo_t *collInfo) {
04186
04187 int status;
04188
04189 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelColl");
04190
04191 status = _delColl(rsComm, collInfo);
04192 if (status != 0) return(status);
04193
04194 status = cmlExecuteNoAnswerSql("commit", &icss);
04195 if (status != 0) {
04196 rodsLog(LOG_NOTICE,
04197 "chlDelColl cmlExecuteNoAnswerSql commit failure %d",
04198 status);
04199 _rollback("chlDelColl");
04200 return(status);
04201 }
04202 return(0);
04203 }
04204
04205
04206
04207
04208 static int _delColl(rsComm_t *rsComm, collInfo_t *collInfo) {
04209 rodsLong_t iVal;
04210 char logicalEndName[MAX_NAME_LEN];
04211 char logicalParentDirName[MAX_NAME_LEN];
04212 char collIdNum[MAX_NAME_LEN];
04213 char parentCollIdNum[MAX_NAME_LEN];
04214 rodsLong_t status;
04215
04216 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl");
04217
04218 if (!icss.status) {
04219 return(CATALOG_NOT_CONNECTED);
04220 }
04221
04222 status = splitPathByKey(collInfo->collName,
04223 logicalParentDirName, logicalEndName, '/');
04224
04225 if (strlen(logicalParentDirName)==0) {
04226 strcpy(logicalParentDirName, "/");
04227 strcpy(logicalEndName, collInfo->collName+1);
04228 }
04229
04230
04231
04232 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl SQL 1 ");
04233 status = cmlCheckDir(logicalParentDirName,
04234 rsComm->clientUser.userName,
04235 rsComm->clientUser.rodsZone,
04236 ACCESS_MODIFY_OBJECT,
04237 &icss);
04238 if (status < 0) {
04239 char errMsg[105];
04240 if (status == CAT_UNKNOWN_COLLECTION) {
04241 snprintf(errMsg, 100, "collection '%s' is unknown",
04242 logicalParentDirName);
04243 addRErrorMsg (&rsComm->rError, 0, errMsg);
04244 return(status);
04245 }
04246 _rollback("_delColl");
04247 return(status);
04248 }
04249 snprintf(parentCollIdNum, MAX_NAME_LEN, "%lld", status);
04250
04251
04252
04253 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl SQL 2");
04254 status = cmlCheckDir(collInfo->collName,
04255 rsComm->clientUser.userName,
04256 rsComm->clientUser.rodsZone,
04257 ACCESS_DELETE_OBJECT,
04258 &icss);
04259 if (status < 0) return(status);
04260 snprintf(collIdNum, MAX_NAME_LEN, "%lld", status);
04261
04262
04263 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl SQL 3");
04264 status = cmlGetIntegerValueFromSql(
04265 "select coll_id from R_COLL_MAIN where parent_coll_name=? union select coll_id from R_DATA_MAIN where coll_id=(select coll_id from R_COLL_MAIN where coll_name=?)",
04266 &iVal, collInfo->collName, collInfo->collName, 0, 0, 0, &icss);
04267 if (status != CAT_NO_ROWS_FOUND) {
04268 return(CAT_COLLECTION_NOT_EMPTY);
04269 }
04270
04271
04272
04273
04274
04275 cllBindVars[cllBindVarCount++]=collInfo->collName;
04276 cllBindVars[cllBindVarCount++]=collIdNum;
04277 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl SQL 4");
04278 status = cmlExecuteNoAnswerSql(
04279 "delete from R_COLL_MAIN where coll_name=? and coll_id=?",
04280 &icss);
04281 if (status != 0) {
04282 rodsLog(LOG_NOTICE,
04283 "_delColl cmlExecuteNoAnswerSql delete failure %d",
04284 status);
04285 _rollback("_delColl");
04286 return(status);
04287 }
04288
04289
04290 cllBindVars[cllBindVarCount++]=collIdNum;
04291 if (logSQL!=0) rodsLog(LOG_SQL, "_delColl SQL 5");
04292 status = cmlExecuteNoAnswerSql(
04293 "delete from R_OBJT_ACCESS where object_id=?",
04294 &icss);
04295 if (status != 0) {
04296 rodsLog(LOG_NOTICE,
04297 "_delColl cmlExecuteNoAnswerSql delete access failure %d",
04298 status);
04299 _rollback("_delColl");
04300 }
04301
04302
04303 removeMetaMapAndAVU(collIdNum);
04304
04305
04306 status = cmlAudit3(AU_DELETE_COLL,
04307 collIdNum,
04308 rsComm->clientUser.userName,
04309 rsComm->clientUser.rodsZone,
04310 collInfo->collName,
04311 &icss);
04312 if (status != 0) {
04313 rodsLog(LOG_NOTICE,
04314 "chlModColl cmlAudit3 failure %d",
04315 status);
04316 _rollback("_delColl");
04317 return(status);
04318 }
04319
04320 return(status);
04321 }
04322
04323
04324
04325
04326 static int _modRescInHierarchies(const std::string& old_resc, const std::string& new_resc) {
04327 char update_sql[MAX_SQL_SIZE];
04328 int status;
04329 const char *sep = eirods::hierarchy_parser::delimiter().c_str();
04330 std::string std_conf_str;
04331
04332 #if ORA_ICAT
04333
04334 return SYS_NOT_IMPLEMENTED;
04335 #elif MY_ICAT
04336 return SYS_NOT_IMPLEMENTED;
04337 #endif
04338
04339
04340
04341 eirods::catalog_properties::getInstance().get_property<std::string>(eirods::STANDARD_CONFORMING_STRINGS, std_conf_str);
04342
04343
04344
04345
04346
04347
04348
04349
04350 if (std_conf_str == "on") {
04351
04352 snprintf(update_sql, MAX_SQL_SIZE,
04353 "update r_data_main set resc_hier = regexp_replace(resc_hier, '(^|(.+%s))%s($|(%s.+))', '\\1%s\\3');",
04354 sep, old_resc.c_str(), sep, new_resc.c_str());
04355 } else {
04356
04357 snprintf(update_sql, MAX_SQL_SIZE,
04358 "update r_data_main set resc_hier = regexp_replace(resc_hier, '(^|(.+%s))%s($|(%s.+))', '\\\\1%s\\\\3');",
04359 sep, old_resc.c_str(), sep, new_resc.c_str());
04360 }
04361
04362
04363
04364 status = cmlExecuteNoAnswerSql(update_sql, &icss);
04365
04366
04367
04368 if (status < 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
04369 std::stringstream ss;
04370 ss << "_modRescInHierarchies: cmlExecuteNoAnswerSql update failure, status = " << status;
04371 eirods::log(LOG_NOTICE, ss.str());
04372
04373 }
04374
04375 return status;
04376 }
04377
04378
04379
04380
04381 static int _modRescInChildren(const std::string& old_resc, const std::string& new_resc) {
04382 char update_sql[MAX_SQL_SIZE];
04383 int status;
04384 char sep[] = ";";
04385 std::string std_conf_str;
04386
04387 #if ORA_ICAT
04388
04389 return SYS_NOT_IMPLEMENTED;
04390 #elif MY_ICAT
04391 return SYS_NOT_IMPLEMENTED;
04392 #endif
04393
04394
04395
04396 eirods::catalog_properties::getInstance().get_property<std::string>(eirods::STANDARD_CONFORMING_STRINGS, std_conf_str);
04397
04398
04399
04400
04401
04402
04403
04404
04405
04406 if (std_conf_str == "on") {
04407
04408 snprintf(update_sql, MAX_SQL_SIZE,
04409 "update r_resc_main set resc_children = regexp_replace(resc_children, '(^|(.+%s))%s{}(.*)', '\\1%s{}\\3');",
04410 sep, old_resc.c_str(), new_resc.c_str());
04411 } else {
04412
04413 snprintf(update_sql, MAX_SQL_SIZE,
04414 "update r_resc_main set resc_children = regexp_replace(resc_children, '(^|(.+%s))%s{}(.*)', '\\\\1%s{}\\\\3');",
04415 sep, old_resc.c_str(), new_resc.c_str());
04416 }
04417
04418
04419
04420 status = cmlExecuteNoAnswerSql(update_sql, &icss);
04421
04422
04423
04424 if (status < 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
04425 std::stringstream ss;
04426 ss << "_modRescInChildren: cmlExecuteNoAnswerSql update failure, status = " << status;
04427 eirods::log(LOG_NOTICE, ss.str());
04428
04429 }
04430
04431 return status;
04432 }
04433
04434
04435
04436
04437 static
04438 eirods::error verify_auth_response(
04439 const char* _scheme,
04440 const char* _challenge,
04441 const char* _user_name,
04442 const char* _response ) {
04443
04444
04445 if( !_scheme ) {
04446 return ERROR(
04447 SYS_INVALID_INPUT_PARAM,
04448 "null _scheme ptr" );
04449 } else if( !_challenge ) {
04450 return ERROR(
04451 SYS_INVALID_INPUT_PARAM,
04452 "null _challenge ptr" );
04453 } else if( !_user_name ) {
04454 return ERROR(
04455 SYS_INVALID_INPUT_PARAM,
04456 "null _user_name ptr" );
04457 } else if( !_response ) {
04458 return ERROR(
04459 SYS_INVALID_INPUT_PARAM,
04460 "null _response ptr" );
04461 }
04462
04463
04464
04465 eirods::auth_object_ptr auth_obj;
04466 eirods::error ret = eirods::auth_factory(
04467 _scheme,
04468 0,
04469 auth_obj );
04470 if( !ret.ok() ){
04471 return ret;
04472 }
04473
04474
04475
04476 eirods::plugin_ptr ptr;
04477 ret = auth_obj->resolve(
04478 eirods::AUTH_INTERFACE,
04479 ptr );
04480 if( !ret.ok() ){
04481 return ret;
04482 }
04483 eirods::auth_ptr auth_plugin = boost::dynamic_pointer_cast< eirods::auth >( ptr );
04484
04485
04486
04487 ret = auth_plugin->call<
04488 const char*,
04489 const char*,
04490 const char* >(
04491 eirods::AUTH_AGENT_AUTH_VERIFY,
04492 auth_obj,
04493 _challenge,
04494 _user_name,
04495 _response );
04496 if( !ret.ok() ){
04497 eirods::log( PASS( ret ) );
04498 return ret;
04499 }
04500
04501 return SUCCESS();
04502
04503 }
04504
04505
04506
04507
04508
04509
04510
04511
04512
04513
04514
04515
04516
04517 int chlCheckAuth(
04518 rsComm_t* rsComm,
04519 const char* scheme,
04520 char* challenge,
04521 char* response,
04522 char* username,
04523 int* userPrivLevel,
04524 int* clientPrivLevel ) {
04525
04526
04527 int status;
04528 char md5Buf[CHALLENGE_LEN+MAX_PASSWORD_LEN+2];
04529 char digest[RESPONSE_LEN+2];
04530 MD5_CTX context;
04531 char *cp;
04532 int i, OK, k;
04533 char userType[MAX_NAME_LEN];
04534 static int prevFailure=0;
04535 char pwInfoArray[MAX_PASSWORD_LEN*MAX_PASSWORDS*3];
04536 char goodPw[MAX_PASSWORD_LEN+10];
04537 char lastPw[MAX_PASSWORD_LEN+10];
04538 char goodPwExpiry[MAX_PASSWORD_LEN+10];
04539 char goodPwTs[MAX_PASSWORD_LEN+10];
04540 char goodPwModTs[MAX_PASSWORD_LEN+10];
04541 rodsLong_t expireTime;
04542 char *cpw;
04543 int nPasswords;
04544 char myTime[50];
04545 time_t nowTime;
04546 time_t pwExpireMaxCreateTime;
04547 char expireStr[50];
04548 char expireStrCreate[50];
04549 char myUserZone[MAX_NAME_LEN];
04550 char userName2[NAME_LEN+2];
04551 char userZone[NAME_LEN+2];
04552 rodsLong_t pamMinTime;
04553 rodsLong_t pamMaxTime;
04554
04555 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth");
04556
04557 if (prevFailure > 1) {
04558
04559 if (prevFailure > 5) sleep(20);
04560 sleep(2);
04561 }
04562 *userPrivLevel = NO_USER_AUTH;
04563 *clientPrivLevel = NO_USER_AUTH;
04564
04565 memset(md5Buf, 0, sizeof(md5Buf));
04566 strncpy(md5Buf, challenge, CHALLENGE_LEN);
04567 snprintf(prevChalSig,sizeof prevChalSig,
04568 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
04569 (unsigned char)md5Buf[0], (unsigned char)md5Buf[1],
04570 (unsigned char)md5Buf[2], (unsigned char)md5Buf[3],
04571 (unsigned char)md5Buf[4], (unsigned char)md5Buf[5],
04572 (unsigned char)md5Buf[6], (unsigned char)md5Buf[7],
04573 (unsigned char)md5Buf[8], (unsigned char)md5Buf[9],
04574 (unsigned char)md5Buf[10],(unsigned char)md5Buf[11],
04575 (unsigned char)md5Buf[12],(unsigned char)md5Buf[13],
04576 (unsigned char)md5Buf[14],(unsigned char)md5Buf[15]);
04577
04578 status = parseUserName(username, userName2, userZone);
04579 if (userZone[0]=='\0') {
04580 status = getLocalZone();
04581 if (status != 0) return(status);
04582 strncpy(myUserZone, localZone, MAX_NAME_LEN);
04583 }
04584 else {
04585 strncpy(myUserZone, userZone, MAX_NAME_LEN);
04586 }
04587
04588
04589 if( scheme && strlen( scheme ) > 0 ) {
04590 eirods::error ret = verify_auth_response(
04591 scheme,
04592 challenge,
04593 userName2,
04594 response );
04595 if( !ret.ok() ) {
04596 eirods::log( PASS( ret ) );
04597 return ret.code();
04598 }
04599 goto checkLevel;
04600 }
04601
04602
04603 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 1 ");
04604
04605 status = cmlGetMultiRowStringValuesFromSql(
04606 "select rcat_password, pass_expiry_ts, R_USER_PASSWORD.create_ts, R_USER_PASSWORD.modify_ts from R_USER_PASSWORD, R_USER_MAIN where user_name=? and zone_name=? and R_USER_MAIN.user_id = R_USER_PASSWORD.user_id",
04607 pwInfoArray, MAX_PASSWORD_LEN,
04608 MAX_PASSWORDS*4,
04609 userName2, myUserZone, &icss);
04610
04611 if (status < 4) {
04612 if (status == CAT_NO_ROWS_FOUND) {
04613 status = CAT_INVALID_USER;
04614 if (strncmp(ANONYMOUS_USER, userName2, NAME_LEN)==0) {
04615
04616 goto checkLevel;
04617 }
04618 }
04619 return(status);
04620 }
04621
04622 nPasswords=status/4;
04623 goodPwExpiry[0]='\0';
04624 goodPwTs[0]='\0';
04625 goodPwModTs[0]='\0';
04626
04627 cpw=pwInfoArray;
04628 for (k=0;k<MAX_PASSWORDS && k<nPasswords;k++) {
04629 memset(md5Buf, 0, sizeof(md5Buf));
04630 strncpy(md5Buf, challenge, CHALLENGE_LEN);
04631 icatDescramble(cpw);
04632 strncpy(md5Buf+CHALLENGE_LEN, cpw, MAX_PASSWORD_LEN);
04633
04634 MD5Init (&context);
04635 MD5Update (&context, (unsigned char *) md5Buf, CHALLENGE_LEN+MAX_PASSWORD_LEN);
04636 MD5Final ((unsigned char *) digest, &context);
04637
04638 for (i=0;i<RESPONSE_LEN;i++) {
04639 if (digest[i]=='\0') digest[i]++;
04640
04641 }
04642
04643 cp = response;
04644 OK=1;
04645 for (i=0;i<RESPONSE_LEN;i++) {
04646 if (*cp++ != digest[i]) OK=0;
04647 }
04648
04649 memset(md5Buf, 0, sizeof(md5Buf));
04650 if (OK==1) {
04651 rstrcpy(goodPw, cpw, MAX_PASSWORD_LEN);
04652 cpw+=MAX_PASSWORD_LEN;
04653 rstrcpy(goodPwExpiry, cpw, MAX_PASSWORD_LEN);
04654 cpw+=MAX_PASSWORD_LEN;
04655 rstrcpy(goodPwTs, cpw, MAX_PASSWORD_LEN);
04656 cpw+=MAX_PASSWORD_LEN;
04657 rstrcpy(goodPwModTs, cpw, MAX_PASSWORD_LEN);
04658 break;
04659 }
04660 cpw+=MAX_PASSWORD_LEN*4;
04661 }
04662 memset(pwInfoArray, 0, sizeof(pwInfoArray));
04663
04664 if (OK==0) {
04665 prevFailure++;
04666 return(CAT_INVALID_AUTHENTICATION);
04667 }
04668
04669 expireTime=atoll(goodPwExpiry);
04670 getNowStr(myTime);
04671 nowTime=atoll(myTime);
04672
04673
04674 pamMaxTime=atoll(IRODS_PAM_PASSWORD_MAX_TIME);
04675 pamMinTime=atoll(IRODS_PAM_PASSWORD_MIN_TIME);
04676
04677 if( ( strncmp(goodPwExpiry, "9999",4)!=0) &&
04678 expireTime >= pamMinTime &&
04679 expireTime <= pamMaxTime) {
04680 time_t modTime;
04681
04682 getNowStr(myTime);
04683 nowTime=atoll(myTime);
04684 modTime=atoll(goodPwModTs);
04685
04686 if (modTime+expireTime < nowTime) {
04687
04688 cllBindVars[cllBindVarCount++]=lastPw;
04689 cllBindVars[cllBindVarCount++]=goodPwTs;
04690 cllBindVars[cllBindVarCount++]=userName2;
04691 cllBindVars[cllBindVarCount++]=myUserZone;
04692 if (logSQL!=0)
04693 rodsLog(LOG_SQL, "chlCheckAuth SQL 2");
04694 status = cmlExecuteNoAnswerSql("delete from R_USER_PASSWORD where rcat_password=? and create_ts=? and user_id = (select user_id from R_USER_MAIN where user_name=? and zone_name=?)", &icss);
04695 memset(goodPw, 0, sizeof(goodPw));
04696 memset(lastPw, 0, sizeof(lastPw));
04697 if (status != 0) {
04698 rodsLog(LOG_NOTICE,
04699 "chlCheckAuth cmlExecuteNoAnswerSql delete expired password failure %d",
04700 status);
04701 return(status);
04702 }
04703 status = cmlExecuteNoAnswerSql("commit", &icss);
04704 if (status != 0) {
04705 rodsLog(LOG_NOTICE,
04706 "chlCheckAuth cmlExecuteNoAnswerSql commit failure %d",
04707 status);
04708 return(status);
04709 }
04710 return(CAT_PASSWORD_EXPIRED);
04711 }
04712 }
04713
04714
04715 if (expireTime < TEMP_PASSWORD_MAX_TIME) {
04716
04717
04718
04719 time_t createTime;
04720 int returnExpired;
04721
04722
04723
04724 returnExpired=0;
04725 getNowStr(myTime);
04726 nowTime=atoll(myTime);
04727 createTime=atoll(goodPwTs);
04728 if (createTime==0 || nowTime==0 ) returnExpired=1;
04729 if (createTime+expireTime < nowTime) returnExpired=1;
04730
04731
04732
04733
04734 cllBindVars[cllBindVarCount++]=goodPw;
04735 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 2");
04736 status = cmlExecuteNoAnswerSql(
04737 "delete from R_USER_PASSWORD where rcat_password=?",
04738 &icss);
04739 if (status !=0) {
04740 rodsLog(LOG_NOTICE,
04741 "chlCheckAuth cmlExecuteNoAnswerSql delete failure %d",
04742 status);
04743 _rollback("chlCheckAuth");
04744 return(status);
04745 }
04746
04747
04748
04749 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 3");
04750 snprintf(expireStr, sizeof expireStr, "%d", TEMP_PASSWORD_TIME);
04751 cllBindVars[cllBindVarCount++]=expireStr;
04752
04753 pwExpireMaxCreateTime = nowTime-TEMP_PASSWORD_TIME;
04754
04755 snprintf(expireStrCreate, sizeof expireStrCreate, "%011d",
04756 (int)pwExpireMaxCreateTime);
04757 cllBindVars[cllBindVarCount++]=expireStrCreate;
04758
04759 status = cmlExecuteNoAnswerSql(
04760 "delete from R_USER_PASSWORD where pass_expiry_ts = ? and create_ts < ?",
04761 &icss);
04762 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
04763 rodsLog(LOG_NOTICE,
04764 "chlCheckAuth cmlExecuteNoAnswerSql delete2 failure %d",
04765 status);
04766 _rollback("chlCheckAuth");
04767 return(status);
04768 }
04769
04770 memset(goodPw, 0, MAX_PASSWORD_LEN);
04771 if (returnExpired) return(CAT_PASSWORD_EXPIRED);
04772
04773 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 4");
04774 status = cmlExecuteNoAnswerSql("commit", &icss);
04775 if (status != 0) {
04776 rodsLog(LOG_NOTICE,
04777 "chlCheckAuth cmlExecuteNoAnswerSql commit failure %d",
04778 status);
04779 return(status);
04780 }
04781 memset(goodPw, 0, MAX_PASSWORD_LEN);
04782 if (returnExpired) return(CAT_PASSWORD_EXPIRED);
04783 }
04784
04785
04786 checkLevel:
04787
04788 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 5");
04789 status = cmlGetStringValueFromSql(
04790 "select user_type_name from R_USER_MAIN where user_name=? and zone_name=?",
04791 userType, MAX_NAME_LEN, userName2, myUserZone, 0, &icss);
04792 if (status !=0) {
04793 if (status == CAT_NO_ROWS_FOUND) {
04794 status = CAT_INVALID_USER;
04795 }
04796 else {
04797 _rollback("chlCheckAuth");
04798 }
04799 return(status);
04800 }
04801 *userPrivLevel = LOCAL_USER_AUTH;
04802 if (strcmp(userType, "rodsadmin") == 0) {
04803 *userPrivLevel = LOCAL_PRIV_USER_AUTH;
04804
04805
04806 if (strcmp( rsComm->clientUser.userName, userName2)==0 &&
04807 strcmp( rsComm->clientUser.rodsZone, userZone)==0) {
04808 *clientPrivLevel = LOCAL_PRIV_USER_AUTH;
04809 }
04810 else {
04811 if (rsComm->clientUser.userName[0]=='\0') {
04812
04813
04814
04815
04816
04817
04818
04819
04820
04821
04822
04823
04824 *clientPrivLevel = REMOTE_USER_AUTH;
04825 prevFailure=0;
04826 return(0);
04827 }
04828 else {
04829 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckAuth SQL 6");
04830 status = cmlGetStringValueFromSql(
04831 "select user_type_name from R_USER_MAIN where user_name=? and zone_name=?",
04832 userType, MAX_NAME_LEN, rsComm->clientUser.userName,
04833 rsComm->clientUser.rodsZone, 0, &icss);
04834 if (status !=0) {
04835 if (status == CAT_NO_ROWS_FOUND) {
04836 status = CAT_INVALID_CLIENT_USER;
04837 }
04838 else {
04839 _rollback("chlCheckAuth");
04840 }
04841 return(status);
04842 }
04843 *clientPrivLevel = LOCAL_USER_AUTH;
04844 if (strcmp(userType, "rodsadmin") == 0) {
04845 *clientPrivLevel = LOCAL_PRIV_USER_AUTH;
04846 }
04847 }
04848 }
04849 }
04850
04851 prevFailure=0;
04852 return(0);
04853 }
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863 int chlMakeTempPw(rsComm_t *rsComm, char *pwValueToHash) {
04864 int status;
04865 char md5Buf[100];
04866 unsigned char digest[RESPONSE_LEN+2];
04867 MD5_CTX context;
04868 int i;
04869 char password[MAX_PASSWORD_LEN+10];
04870 char newPw[MAX_PASSWORD_LEN+10];
04871 char myTime[50];
04872 char myTimeExp[50];
04873 char rBuf[200];
04874 char hashValue[50];
04875 int j=0;
04876 char tSQL[MAX_SQL_SIZE];
04877
04878 if (logSQL!=0) rodsLog(LOG_SQL, "chlMakeTempPw");
04879
04880 if (logSQL!=0) rodsLog(LOG_SQL, "chlMakeTempPw SQL 1 ");
04881
04882 snprintf(tSQL, MAX_SQL_SIZE,
04883 "select rcat_password from R_USER_PASSWORD, R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=? and R_USER_MAIN.user_id = R_USER_PASSWORD.user_id and pass_expiry_ts != '%d'",
04884 TEMP_PASSWORD_TIME);
04885
04886 status = cmlGetStringValueFromSql(tSQL,
04887 password, MAX_PASSWORD_LEN,
04888 rsComm->clientUser.userName,
04889 rsComm->clientUser.rodsZone, 0, &icss);
04890 if (status !=0) {
04891 if (status == CAT_NO_ROWS_FOUND) {
04892 status = CAT_INVALID_USER;
04893 }
04894 else {
04895 _rollback("chlMakeTempPw");
04896 }
04897 return(status);
04898 }
04899
04900 icatDescramble(password);
04901
04902 j=0;
04903 get64RandomBytes(rBuf);
04904 for (i=0;i<50 && j<MAX_PASSWORD_LEN-1;i++) {
04905 char c;
04906 c = rBuf[i] &0x7f;
04907 if (c < '0') c+='0';
04908 if ( (c > 'a' && c < 'z') || (c > 'A' && c < 'Z') ||
04909 (c > '0' && c < '9') ){
04910 hashValue[j++]=c;
04911 }
04912 }
04913 hashValue[j]='\0';
04914
04915
04916
04917
04918 memset(md5Buf, 0, sizeof(md5Buf));
04919 strncpy(md5Buf, hashValue, 100);
04920 strncat(md5Buf, password, 100);
04921
04922 MD5Init (&context);
04923 MD5Update (&context, (unsigned char *) md5Buf, 100);
04924 MD5Final ((unsigned char *) digest, &context);
04925
04926 md5ToStr(digest, newPw);
04927
04928
04929 rstrcpy(pwValueToHash, hashValue, MAX_PASSWORD_LEN);
04930
04931
04932
04933
04934 getNowStr(myTime);
04935 sprintf(myTimeExp, "%d", TEMP_PASSWORD_TIME);
04936
04937 cllBindVars[cllBindVarCount++]=rsComm->clientUser.userName;
04938 cllBindVars[cllBindVarCount++]=rsComm->clientUser.rodsZone,
04939 cllBindVars[cllBindVarCount++]=newPw;
04940 cllBindVars[cllBindVarCount++]=myTimeExp;
04941 cllBindVars[cllBindVarCount++]=myTime;
04942 cllBindVars[cllBindVarCount++]=myTime;
04943 if (logSQL!=0) rodsLog(LOG_SQL, "chlMakeTempPw SQL 2");
04944 status = cmlExecuteNoAnswerSql(
04945 "insert into R_USER_PASSWORD (user_id, rcat_password, pass_expiry_ts, create_ts, modify_ts) values ((select user_id from R_USER_MAIN where user_name=? and zone_name=?), ?, ?, ?, ?)",
04946 &icss);
04947 if (status !=0) {
04948 rodsLog(LOG_NOTICE,
04949 "chlMakeTempPw cmlExecuteNoAnswerSql insert failure %d",
04950 status);
04951 _rollback("chlMakeTempPw");
04952 return(status);
04953 }
04954
04955 status = cmlExecuteNoAnswerSql("commit", &icss);
04956 if (status != 0) {
04957 rodsLog(LOG_NOTICE,
04958 "chlMakeTempPw cmlExecuteNoAnswerSql commit failure %d",
04959 status);
04960 return(status);
04961 }
04962
04963 memset(newPw, 0, MAX_PASSWORD_LEN);
04964 return(0);
04965 }
04966
04967
04968
04969
04970
04971
04972 int decodePw(rsComm_t *rsComm, char *in, char *out) {
04973 int status;
04974 char *cp;
04975 char password[MAX_PASSWORD_LEN];
04976 char upassword[MAX_PASSWORD_LEN+10];
04977 char rand[]=
04978 "1gCBizHWbwIYyWLo";
04979 int pwLen1, pwLen2;
04980
04981 if (logSQL!=0) rodsLog(LOG_SQL, "decodePw - SQL 1 ");
04982 status = cmlGetStringValueFromSql(
04983 "select rcat_password from R_USER_PASSWORD, R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=? and R_USER_MAIN.user_id = R_USER_PASSWORD.user_id",
04984 password, MAX_PASSWORD_LEN,
04985 rsComm->clientUser.userName,
04986 rsComm->clientUser.rodsZone,
04987 0, &icss);
04988 if (status !=0) {
04989 if (status == CAT_NO_ROWS_FOUND) {
04990 status = CAT_INVALID_USER;
04991 }
04992 else {
04993 _rollback("decodePw");
04994 }
04995 return(status);
04996 }
04997
04998 icatDescramble(password);
04999
05000 obfDecodeByKeyV2(in, password, prevChalSig, upassword);
05001
05002 pwLen1=strlen(upassword);
05003
05004 memset(password, 0, MAX_PASSWORD_LEN);
05005
05006 cp = strstr(upassword, rand);
05007 if (cp !=NULL) *cp='\0';
05008
05009 pwLen2 = strlen(upassword);
05010
05011 if (pwLen2 > MAX_PASSWORD_LEN-5 && pwLen2==pwLen1) {
05012
05013 char errMsg[160];
05014 snprintf(errMsg, 150,
05015 "Error with password encoding.\nPlease try connecting directly to the ICAT host (setenv irodsHost)");
05016 addRErrorMsg (&rsComm->rError, 0, errMsg);
05017 return(CAT_PASSWORD_ENCODING_ERROR);
05018 }
05019 strcpy(out, upassword);
05020 memset(upassword, 0, MAX_PASSWORD_LEN);
05021
05022 return(0);
05023 }
05024
05025
05026
05027
05028
05029
05030
05031
05032
05033
05034 int chlUpdateIrodsPamPassword(rsComm_t *rsComm,
05035 char *username, int timeToLive,
05036 char *testTime,
05037 char **irodsPassword) {
05038 char myTime[50];
05039 char rBuf[200];
05040 int i, j;
05041 char randomPw[50];
05042 char randomPwEncoded[50];
05043 int status;
05044 char passwordInIcat[MAX_PASSWORD_LEN+2];
05045 char passwordModifyTime[50];
05046 char *cVal[3];
05047 int iVal[3];
05048 char selUserId[MAX_NAME_LEN];
05049 char expTime[50];
05050
05051 status = getLocalZone();
05052 if (status != 0) return(status);
05053
05054 getNowStr(myTime);
05055
05056
05057 if (timeToLive == 0) {
05058 rstrcpy(expTime, IRODS_PAM_PASSWORD_DEFAULT_TIME, sizeof expTime);
05059 }
05060 else {
05061
05062 rodsLong_t pamMinTime, pamMaxTime;
05063 pamMinTime=atoll(IRODS_PAM_PASSWORD_MIN_TIME);
05064 pamMaxTime=atoll(IRODS_PAM_PASSWORD_MAX_TIME);
05065 timeToLive = timeToLive * 3600;
05066 if (timeToLive < pamMinTime ||
05067 timeToLive > pamMaxTime) {
05068 return PAM_AUTH_PASSWORD_INVALID_TTL;
05069 }
05070 snprintf(expTime, sizeof expTime, "%d", timeToLive);
05071 }
05072
05073
05074 if (logSQL!=0) rodsLog(LOG_SQL, "chlUpdateIrodsPamPassword SQL 1");
05075 status = cmlGetStringValueFromSql(
05076 "select user_id from R_USER_MAIN where user_name=? and zone_name=? and user_type_name!='rodsgroup'",
05077 selUserId, MAX_NAME_LEN, username, localZone, 0, &icss);
05078 if (status==CAT_NO_ROWS_FOUND) return (CAT_INVALID_USER);
05079 if (status) return(status);
05080
05081
05082 if (logSQL!=0) rodsLog(LOG_SQL, "chlUpdateIrodsPamPassword SQL 2");
05083 cllBindVars[cllBindVarCount++]=IRODS_PAM_PASSWORD_MIN_TIME;
05084 cllBindVars[cllBindVarCount++]=IRODS_PAM_PASSWORD_MAX_TIME;
05085 cllBindVars[cllBindVarCount++]=myTime;
05086 #if MY_ICAT
05087 status = cmlExecuteNoAnswerSql("delete from R_USER_PASSWORD where pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as signed integer)>=? and cast(pass_expiry_ts as signed integer)<=? and (cast(pass_expiry_ts as signed integer) + cast(modify_ts as signed integer) < ?)",
05088 #else
05089 status = cmlExecuteNoAnswerSql("delete from R_USER_PASSWORD where pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as integer)>=? and cast(pass_expiry_ts as integer)<=? and (cast(pass_expiry_ts as integer) + cast(modify_ts as integer) < ?)",
05090 #endif
05091 &icss);
05092 if (logSQL!=0) rodsLog(LOG_SQL, "chlUpdateIrodsPamPassword SQL 3");
05093 cVal[0]=passwordInIcat;
05094 iVal[0]=MAX_PASSWORD_LEN;
05095 cVal[1]=passwordModifyTime;
05096 iVal[1]=sizeof(passwordModifyTime);
05097 status = cmlGetStringValuesFromSql(
05098 #if MY_ICAT
05099 "select rcat_password, modify_ts from R_USER_PASSWORD where user_id=? and pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as signed integer) >= ? and cast (pass_expiry_ts as signed integer) <= ?",
05100 #else
05101 "select rcat_password, modify_ts from R_USER_PASSWORD where user_id=? and pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as integer) >= ? and cast (pass_expiry_ts as integer) <= ?",
05102 #endif
05103 cVal, iVal, 2,
05104 selUserId,
05105 IRODS_PAM_PASSWORD_MIN_TIME,
05106 IRODS_PAM_PASSWORD_MAX_TIME, &icss);
05107
05108 if (status==0) {
05109 #ifndef PAM_AUTH_NO_EXTEND
05110 if (logSQL!=0) rodsLog(LOG_SQL, "chlUpdateIrodsPamPassword SQL 4");
05111 cllBindVars[cllBindVarCount++]=myTime;
05112 cllBindVars[cllBindVarCount++]=expTime;
05113 cllBindVars[cllBindVarCount++]=selUserId;
05114 cllBindVars[cllBindVarCount++]=passwordInIcat;
05115 status = cmlExecuteNoAnswerSql("update R_USER_PASSWORD set modify_ts=?, pass_expiry_ts=? where user_id = ? and rcat_password = ?",
05116 &icss);
05117 if (status) return(status);
05118
05119 status = cmlExecuteNoAnswerSql("commit", &icss);
05120 if (status != 0) {
05121 rodsLog(LOG_NOTICE,
05122 "chlUpdateIrodsPamPassword cmlExecuteNoAnswerSql commit failure %d",
05123 status);
05124 return(status);
05125 }
05126 #endif
05127 icatDescramble(passwordInIcat);
05128 strncpy(*irodsPassword, passwordInIcat, IRODS_PAM_PASSWORD_LEN);
05129 return(0);
05130 }
05131
05132
05133
05134
05135
05136
05137
05138 bool pw_good = false;
05139 while( !pw_good ) {
05140
05141 j=0;
05142 get64RandomBytes(rBuf);
05143 for (i=0;i<50 && j<IRODS_PAM_PASSWORD_LEN-1;i++) {
05144 char c;
05145 c = rBuf[i] & 0x7f;
05146 if (c < '0') c+='0';
05147 if ( (c > 'a' && c < 'z') || (c > 'A' && c < 'Z') ||
05148 (c > '0' && c < '9') ){
05149 randomPw[j++]=c;
05150 }
05151 }
05152 randomPw[j]='\0';
05153
05154 strncpy(randomPwEncoded, randomPw, 50);
05155 icatScramble(randomPwEncoded);
05156 if( !strstr( randomPwEncoded, "\'" ) ) {
05157 pw_good = true;
05158
05159 } else {
05160 rodsLog( LOG_STATUS, "chlUpdateIrodsPamPassword :: getting a new password [%s] has a single quote", randomPwEncoded );
05161
05162 }
05163
05164 }
05165
05166 if (testTime!=NULL && strlen(testTime)>0) {
05167 strncpy(myTime, testTime, sizeof(myTime));
05168 }
05169
05170 if (logSQL!=0) rodsLog(LOG_SQL, "chlUpdateIrodsPamPassword SQL 5");
05171 cllBindVars[cllBindVarCount++]=selUserId;
05172 cllBindVars[cllBindVarCount++]=randomPwEncoded;
05173 cllBindVars[cllBindVarCount++]=expTime;
05174 cllBindVars[cllBindVarCount++]=myTime;
05175 cllBindVars[cllBindVarCount++]=myTime;
05176 status = cmlExecuteNoAnswerSql("insert into R_USER_PASSWORD (user_id, rcat_password, pass_expiry_ts, create_ts, modify_ts) values (?, ?, ?, ?, ?)",
05177 &icss);
05178 if (status) return(status);
05179
05180 status = cmlExecuteNoAnswerSql("commit", &icss);
05181 if (status != 0) {
05182 rodsLog(LOG_NOTICE,
05183 "chlUpdateIrodsPamPassword cmlExecuteNoAnswerSql commit failure %d",
05184 status);
05185 return(status);
05186 }
05187
05188 strncpy(*irodsPassword, randomPw, IRODS_PAM_PASSWORD_LEN);
05189 return(0);
05190 }
05191
05192
05193
05194
05195 int chlModUser(rsComm_t *rsComm, char *userName, char *option,
05196 char *newValue) {
05197 int status;
05198 int opType;
05199 char decoded[MAX_PASSWORD_LEN+20];
05200 char tSQL[MAX_SQL_SIZE];
05201 char form1[]="update R_USER_MAIN set %s=?, modify_ts=? where user_name=? and zone_name=?";
05202 char form2[]="update R_USER_MAIN set %s=%s, modify_ts=? where user_name=? and zone_name=?";
05203 char form3[]="update R_USER_PASSWORD set rcat_password=?, modify_ts=? where user_id=?";
05204 char form4[]="insert into R_USER_PASSWORD (user_id, rcat_password, pass_expiry_ts, create_ts, modify_ts) values ((select user_id from R_USER_MAIN where user_name=? and zone_name=?), ?, ?, ?, ?)";
05205 char form5[]="insert into R_USER_AUTH (user_id, user_auth_name, create_ts) values ((select user_id from R_USER_MAIN where user_name=? and zone_name=?), ?, ?)";
05206 char form6[]="delete from R_USER_AUTH where user_id = (select user_id from R_USER_MAIN where user_name=? and zone_name=?) and user_auth_name = ?";
05207 #if MY_ICAT
05208 char form7[]="delete from R_USER_PASSWORD where pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as signed integer)>=? and cast(pass_expiry_ts as signed integer)<=? and user_id = (select user_id from R_USER_MAIN where user_name=? and zone_name=?)";
05209 #else
05210 char form7[]="delete from R_USER_PASSWORD where pass_expiry_ts not like '9999%' and cast(pass_expiry_ts as integer)>=? and cast(pass_expiry_ts as integer)<=? and user_id = (select user_id from R_USER_MAIN where user_name=? and zone_name=?)";
05211 #endif
05212
05213 char myTime[50];
05214 rodsLong_t iVal;
05215
05216 int auditId;
05217 char auditComment[110];
05218 char auditUserName[110];
05219 int userSettingOwnPassword;
05220 int groupAdminSettingPassword;
05221
05222 char userName2[NAME_LEN];
05223 char zoneName[NAME_LEN];
05224
05225 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser");
05226
05227 if (userName == NULL || option == NULL || newValue==NULL) {
05228 return (CAT_INVALID_ARGUMENT);
05229 }
05230
05231 if (*userName == '\0' || *option == '\0' || newValue=='\0') {
05232 return (CAT_INVALID_ARGUMENT);
05233 }
05234
05235 userSettingOwnPassword=0;
05236
05237
05238 groupAdminSettingPassword=0;
05239 if (rsComm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH &&
05240 rsComm->proxyUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
05241
05242 }
05243 else {
05244
05245 if ( strcmp(option,"password")!=0) {
05246
05247 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
05248 }
05249 if ( strcmp(userName, rsComm->clientUser.userName)==0) {
05250 userSettingOwnPassword=1;
05251 }
05252 else {
05253 int status2;
05254 status2 = cmlCheckGroupAdminAccess(
05255 rsComm->clientUser.userName,
05256 rsComm->clientUser.rodsZone,
05257 "", &icss);
05258 if (status2 != 0) return(status2);
05259 groupAdminSettingPassword=1;
05260 }
05261
05262 if (userSettingOwnPassword==0 && groupAdminSettingPassword==0) {
05263 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
05264 }
05265 }
05266
05267 status = getLocalZone();
05268 if (status != 0) return(status);
05269
05270 tSQL[0]='\0';
05271 opType=0;
05272
05273 getNowStr(myTime);
05274
05275 auditComment[0]='\0';
05276 strncpy(auditUserName,userName,100);
05277
05278 status = parseUserName(userName, userName2, zoneName);
05279 if (zoneName[0]=='\0') {
05280 rstrcpy(zoneName, localZone, NAME_LEN);
05281 }
05282 if (status != 0) {
05283 return (CAT_INVALID_ARGUMENT);
05284 }
05285
05286 #if 0
05287
05288
05289 if (strcmp(option,"name" )==0 ||
05290 strcmp(option,"user_name" )==0) {
05291 snprintf(tSQL, MAX_SQL_SIZE, form1,
05292 "user_name");
05293 cllBindVars[cllBindVarCount++]=newValue;
05294 cllBindVars[cllBindVarCount++]=myTime;
05295 cllBindVars[cllBindVarCount++]=userName2;
05296 cllBindVars[cllBindVarCount++]=zoneName;
05297 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUserSQLxx1x");
05298 auditId = AU_MOD_USER_NAME;
05299 strncpy(auditComment, userName, 100);
05300 strncpy(auditUserName,newValue,100);
05301 }
05302 #endif
05303 if (strcmp(option,"type")==0 ||
05304 strcmp(option,"user_type_name")==0) {
05305 char tsubSQL[MAX_SQL_SIZE];
05306 snprintf(tsubSQL, MAX_SQL_SIZE, "(select token_name from R_TOKN_MAIN where token_namespace='user_type' and token_name=?)");
05307 cllBindVars[cllBindVarCount++]=newValue;
05308 snprintf(tSQL, MAX_SQL_SIZE, form2,
05309 "user_type_name", tsubSQL);
05310 cllBindVars[cllBindVarCount++]=myTime;
05311 cllBindVars[cllBindVarCount++]=userName2;
05312 cllBindVars[cllBindVarCount++]=zoneName;
05313 opType=1;
05314 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 2");
05315 auditId = AU_MOD_USER_TYPE;
05316 strncpy(auditComment, newValue, 100);
05317 }
05318 if (strcmp(option,"zone")==0 ||
05319 strcmp(option,"zone_name")==0) {
05320 snprintf(tSQL, MAX_SQL_SIZE, form1, "zone_name");
05321 cllBindVars[cllBindVarCount++]=newValue;
05322 cllBindVars[cllBindVarCount++]=myTime;
05323 cllBindVars[cllBindVarCount++]=userName2;
05324 cllBindVars[cllBindVarCount++]=zoneName;
05325 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 3");
05326 auditId = AU_MOD_USER_ZONE;
05327 strncpy(auditComment, newValue, 100);
05328 strncpy(auditUserName,userName,100);
05329 }
05330 if (strcmp(option,"addAuth")==0) {
05331 opType=4;
05332 rstrcpy(tSQL, form5, MAX_SQL_SIZE);
05333 cllBindVars[cllBindVarCount++]=userName2;
05334 cllBindVars[cllBindVarCount++]=zoneName;
05335 cllBindVars[cllBindVarCount++]=newValue;
05336 cllBindVars[cllBindVarCount++]=myTime;
05337 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 4");
05338 auditId = AU_ADD_USER_AUTH_NAME;
05339 strncpy(auditComment, newValue, 100);
05340 }
05341 if (strcmp(option,"rmAuth")==0) {
05342 rstrcpy(tSQL, form6, MAX_SQL_SIZE);
05343 cllBindVars[cllBindVarCount++]=userName2;
05344 cllBindVars[cllBindVarCount++]=zoneName;
05345 cllBindVars[cllBindVarCount++]=newValue;
05346 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 5");
05347 auditId = AU_DELETE_USER_AUTH_NAME;
05348 strncpy(auditComment, newValue, 100);
05349
05350 }
05351
05352 if (strncmp(option, "rmPamPw", 9)==0) {
05353 rstrcpy(tSQL, form7, MAX_SQL_SIZE);
05354 cllBindVars[cllBindVarCount++]=IRODS_PAM_PASSWORD_MIN_TIME;
05355 cllBindVars[cllBindVarCount++]=IRODS_PAM_PASSWORD_MAX_TIME;
05356 cllBindVars[cllBindVarCount++]=userName2;
05357 cllBindVars[cllBindVarCount++]=zoneName;
05358 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 6");
05359 auditId = AU_MOD_USER_PASSWORD;
05360 strncpy(auditComment, "Deleted user iRODS-PAM password (if any)", 100);
05361 }
05362
05363 if (strcmp(option,"info")==0 ||
05364 strcmp(option,"user_info")==0) {
05365 snprintf(tSQL, MAX_SQL_SIZE, form1,
05366 "user_info");
05367 cllBindVars[cllBindVarCount++]=newValue;
05368 cllBindVars[cllBindVarCount++]=myTime;
05369 cllBindVars[cllBindVarCount++]=userName2;
05370 cllBindVars[cllBindVarCount++]=zoneName;
05371 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 6");
05372 auditId = AU_MOD_USER_INFO;
05373 strncpy(auditComment, newValue, 100);
05374 }
05375 if (strcmp(option,"comment")==0 ||
05376 strcmp(option,"r_comment")==0) {
05377 snprintf(tSQL, MAX_SQL_SIZE, form1,
05378 "r_comment");
05379 cllBindVars[cllBindVarCount++]=newValue;
05380 cllBindVars[cllBindVarCount++]=myTime;
05381 cllBindVars[cllBindVarCount++]=userName2;
05382 cllBindVars[cllBindVarCount++]=zoneName;
05383 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 7");
05384 auditId = AU_MOD_USER_COMMENT;
05385 strncpy(auditComment, newValue, 100);
05386 }
05387 if (strcmp(option,"password")==0) {
05388 int i;
05389 char userIdStr[MAX_NAME_LEN];
05390 i = decodePw(rsComm, newValue, decoded);
05391
05392 icatScramble(decoded);
05393
05394 if (i) return(i);
05395 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 8");
05396 i = cmlGetStringValueFromSql(
05397 "select R_USER_PASSWORD.user_id from R_USER_PASSWORD, R_USER_MAIN where R_USER_MAIN.user_name=? and R_USER_MAIN.zone_name=? and R_USER_MAIN.user_id = R_USER_PASSWORD.user_id",
05398 userIdStr, MAX_NAME_LEN, userName2, zoneName, 0, &icss);
05399 if (i != 0 && i !=CAT_NO_ROWS_FOUND) return(i);
05400 if (i == 0) {
05401 if (groupAdminSettingPassword == 1) {
05402
05403 return( CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
05404 }
05405 rstrcpy(tSQL, form3, MAX_SQL_SIZE);
05406 cllBindVars[cllBindVarCount++]=decoded;
05407 cllBindVars[cllBindVarCount++]=myTime;
05408 cllBindVars[cllBindVarCount++]=userIdStr;
05409 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 9");
05410 }
05411 else {
05412 opType=4;
05413 rstrcpy(tSQL, form4, MAX_SQL_SIZE);
05414 cllBindVars[cllBindVarCount++]=userName2;
05415 cllBindVars[cllBindVarCount++]=zoneName;
05416 cllBindVars[cllBindVarCount++]=decoded;
05417 cllBindVars[cllBindVarCount++]="9999-12-31-23.59.01";
05418 cllBindVars[cllBindVarCount++]=myTime;
05419 cllBindVars[cllBindVarCount++]=myTime;
05420 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 10");
05421 }
05422 auditId = AU_MOD_USER_PASSWORD;
05423 }
05424
05425 if (tSQL[0]=='\0') {
05426 return (CAT_INVALID_ARGUMENT);
05427 }
05428
05429 status = cmlExecuteNoAnswerSql(tSQL, &icss);
05430 memset(decoded, 0, MAX_PASSWORD_LEN);
05431
05432 if (status != 0 ) {
05433 if (opType==1) {
05434 int status2;
05435 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 11");
05436 status2 = cmlGetIntegerValueFromSql(
05437 "select token_name from R_TOKN_MAIN where token_namespace='user_type' and token_name=?",
05438 &iVal, newValue, 0, 0, 0, 0, &icss);
05439 if (status2 != 0) {
05440 char errMsg[105];
05441 snprintf(errMsg, 100, "user_type '%s' is not valid",
05442 newValue);
05443 addRErrorMsg (&rsComm->rError, 0, errMsg);
05444
05445 rodsLog(LOG_NOTICE,
05446 "chlModUser invalid user_type");
05447 return(CAT_INVALID_USER_TYPE);
05448 }
05449 }
05450 if (opType==4) {
05451
05452 int status2;
05453 _rollback("chlModUser");
05454 if (logSQL!=0) rodsLog(LOG_SQL, "chlModUser SQL 12");
05455 status2 = cmlGetIntegerValueFromSql(
05456 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
05457 &iVal, userName2, zoneName, 0, 0, 0, &icss);
05458 if (status2 != 0) {
05459 rodsLog(LOG_NOTICE,
05460 "chlModUser invalid user %s zone %s", userName2, zoneName);
05461 return(CAT_INVALID_USER);
05462 }
05463 }
05464 rodsLog(LOG_NOTICE,
05465 "chlModUser cmlExecuteNoAnswerSql failure %d",
05466 status);
05467 return(status);
05468 }
05469
05470 status = cmlAudit1(auditId, rsComm->clientUser.userName,
05471 localZone, auditUserName, auditComment, &icss);
05472 if (status != 0) {
05473 rodsLog(LOG_NOTICE,
05474 "chlModUser cmlAudit1 failure %d",
05475 status);
05476 _rollback("chlModUser");
05477 return(status);
05478 }
05479
05480 status = cmlExecuteNoAnswerSql("commit", &icss);
05481 if (status != 0) {
05482 rodsLog(LOG_NOTICE,
05483 "chlModUser cmlExecuteNoAnswerSql commit failure %d",
05484 status);
05485 return(status);
05486 }
05487 return(0);
05488 }
05489
05490
05491
05492
05493 int chlModGroup(rsComm_t *rsComm, char *groupName, char *option,
05494 char *userName, char *userZone) {
05495 int status, OK;
05496 char myTime[50];
05497 char userId[MAX_NAME_LEN];
05498 char groupId[MAX_NAME_LEN];
05499 char commentStr[100];
05500 char zoneToUse[MAX_NAME_LEN];
05501
05502 char userName2[NAME_LEN];
05503 char zoneName[NAME_LEN];
05504
05505
05506 if (logSQL!=0) rodsLog(LOG_SQL, "chlModGroup");
05507
05508 if (groupName == NULL || option == NULL || userName==NULL) {
05509 return (CAT_INVALID_ARGUMENT);
05510 }
05511
05512 if (*groupName == '\0' || *option == '\0' || userName=='\0') {
05513 return (CAT_INVALID_ARGUMENT);
05514 }
05515
05516 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ||
05517 rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
05518 int status2;
05519 status2 = cmlCheckGroupAdminAccess(
05520 rsComm->clientUser.userName,
05521 rsComm->clientUser.rodsZone, groupName, &icss);
05522 if (status2 != 0) return(status2);
05523 }
05524
05525 status = getLocalZone();
05526 if (status != 0) return(status);
05527
05528 strncpy(zoneToUse, localZone, MAX_NAME_LEN);
05529 if (userZone != NULL && *userZone != '\0') {
05530 strncpy(zoneToUse, userZone, MAX_NAME_LEN);
05531 }
05532
05533 status = parseUserName(userName, userName2, zoneName);
05534 if (zoneName[0]!='\0') {
05535 rstrcpy(zoneToUse, zoneName, NAME_LEN);
05536 }
05537
05538 userId[0]='\0';
05539 if (logSQL!=0) rodsLog(LOG_SQL, "chlModGroup SQL 1 ");
05540 status = cmlGetStringValueFromSql(
05541 "select user_id from R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=? and user_type_name !='rodsgroup'",
05542 userId, MAX_NAME_LEN, userName2, zoneToUse, 0, &icss);
05543 if (status != 0) {
05544 if (status==CAT_NO_ROWS_FOUND) {
05545 return(CAT_INVALID_USER);
05546 }
05547 _rollback("chlModGroup");
05548 return(status);
05549 }
05550
05551 groupId[0]='\0';
05552 if (logSQL!=0) rodsLog(LOG_SQL, "chlModGroup SQL 2");
05553 status = cmlGetStringValueFromSql(
05554 "select user_id from R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=? and user_type_name='rodsgroup'",
05555 groupId, MAX_NAME_LEN, groupName, localZone, 0, &icss);
05556 if (status != 0) {
05557 if (status==CAT_NO_ROWS_FOUND) {
05558 return(CAT_INVALID_GROUP);
05559 }
05560 _rollback("chlModGroup");
05561 return(status);
05562 }
05563 OK=0;
05564 if (strcmp(option, "remove")==0) {
05565 if (logSQL!=0) rodsLog(LOG_SQL, "chlModGroup SQL 3");
05566 cllBindVars[cllBindVarCount++]=groupId;
05567 cllBindVars[cllBindVarCount++]=userId;
05568 status = cmlExecuteNoAnswerSql(
05569 "delete from R_USER_GROUP where group_user_id = ? and user_id = ?",
05570 &icss);
05571 if (status != 0) {
05572 rodsLog(LOG_NOTICE,
05573 "chlModGroup cmlExecuteNoAnswerSql delete failure %d",
05574 status);
05575 _rollback("chlModGroup");
05576 return(status);
05577 }
05578 OK=1;
05579 }
05580
05581 if (strcmp(option, "add")==0) {
05582 getNowStr(myTime);
05583 cllBindVars[cllBindVarCount++]=groupId;
05584 cllBindVars[cllBindVarCount++]=userId;
05585 cllBindVars[cllBindVarCount++]=myTime;
05586 cllBindVars[cllBindVarCount++]=myTime;
05587 if (logSQL!=0) rodsLog(LOG_SQL, "chlModGroup SQL 4");
05588 status = cmlExecuteNoAnswerSql(
05589 "insert into R_USER_GROUP (group_user_id, user_id , create_ts, modify_ts) values (?, ?, ?, ?)",
05590 &icss);
05591 if (status != 0) {
05592 rodsLog(LOG_NOTICE,
05593 "chlModGroup cmlExecuteNoAnswerSql delete failure %d",
05594 status);
05595 _rollback("chlModGroup");
05596 return(status);
05597 }
05598 OK=1;
05599 }
05600
05601 if (OK==0) {
05602 return (CAT_INVALID_ARGUMENT);
05603 }
05604
05605
05606 snprintf(commentStr, sizeof commentStr, "%s %s", option, userId);
05607 status = cmlAudit3(AU_MOD_GROUP,
05608 groupId,
05609 rsComm->clientUser.userName,
05610 rsComm->clientUser.rodsZone,
05611 commentStr,
05612 &icss);
05613 if (status != 0) {
05614 rodsLog(LOG_NOTICE,
05615 "chlModGroup cmlAudit3 failure %d",
05616 status);
05617 _rollback("chlModGroup");
05618 return(status);
05619 }
05620
05621 status = cmlExecuteNoAnswerSql("commit", &icss);
05622 if (status != 0) {
05623 rodsLog(LOG_NOTICE,
05624 "chlModGroup cmlExecuteNoAnswerSql commit failure %d",
05625 status);
05626 return(status);
05627 }
05628 return(0);
05629 }
05630
05631
05632 int chlModResc(
05633 rsComm_t* rsComm,
05634 char* rescName,
05635 char* option,
05636 char* optionValue ) {
05637 int status, OK;
05638 char myTime[50];
05639 char rescId[MAX_NAME_LEN];
05640 char rescPath[MAX_NAME_LEN]="";
05641 char rescPathMsg[MAX_NAME_LEN+100];
05642 char commentStr[200];
05643 struct hostent *myHostEnt;
05644
05645 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc");
05646
05647 if (rescName == NULL || option==NULL || optionValue==NULL) {
05648 return (CAT_INVALID_ARGUMENT);
05649 }
05650
05651 if (*rescName == '\0' || *option == '\0' || *optionValue=='\0') {
05652 return (CAT_INVALID_ARGUMENT);
05653 }
05654
05655 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
05656 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
05657 }
05658 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
05659 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
05660 }
05661
05662
05663
05664 if (strncmp(rescName, BUNDLE_RESC, strlen(BUNDLE_RESC))==0) {
05665 char errMsg[155];
05666 snprintf(errMsg, 150,
05667 "%s is a built-in resource needed for bundle operations.",
05668 BUNDLE_RESC);
05669 addRErrorMsg (&rsComm->rError, 0, errMsg);
05670 return(CAT_PSEUDO_RESC_MODIFY_DISALLOWED);
05671 }
05672
05673 status = getLocalZone();
05674 if (status != 0) return(status);
05675
05676 rescId[0]='\0';
05677 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 1 ");
05678 status = cmlGetStringValueFromSql(
05679 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
05680 rescId, MAX_NAME_LEN, rescName, localZone, 0, &icss);
05681 if (status != 0) {
05682 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
05683 _rollback("chlModResc");
05684 return(status);
05685 }
05686
05687 getNowStr(myTime);
05688 OK=0;
05689 if (strcmp(option, "info")==0) {
05690 cllBindVars[cllBindVarCount++]=optionValue;
05691 cllBindVars[cllBindVarCount++]=myTime;
05692 cllBindVars[cllBindVarCount++]=rescId;
05693 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 2");
05694 status = cmlExecuteNoAnswerSql(
05695 "update R_RESC_MAIN set resc_info=?, modify_ts=? where resc_id=?",
05696 &icss);
05697 if (status != 0) {
05698 rodsLog(LOG_NOTICE,
05699 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05700 status);
05701 _rollback("chlModResc");
05702 return(status);
05703 }
05704 OK=1;
05705 }
05706 if (strcmp(option, "comment")==0) {
05707 cllBindVars[cllBindVarCount++]=optionValue;
05708 cllBindVars[cllBindVarCount++]=myTime;
05709 cllBindVars[cllBindVarCount++]=rescId;
05710 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 3");
05711 status = cmlExecuteNoAnswerSql(
05712 "update R_RESC_MAIN set r_comment = ?, modify_ts=? where resc_id=?",
05713 &icss);
05714 if (status != 0) {
05715 rodsLog(LOG_NOTICE,
05716 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05717 status);
05718 _rollback("chlModResc");
05719 return(status);
05720 }
05721 OK=1;
05722 }
05723 if (strcmp(option, "freespace")==0) {
05724 int inType=0;
05725 if (*optionValue=='+') {
05726 inType=1;
05727 optionValue++;
05728 }
05729 if (*optionValue=='-') {
05730 inType=2;
05731 optionValue++;
05732 }
05733 cllBindVars[cllBindVarCount++]=optionValue;
05734 cllBindVars[cllBindVarCount++]=myTime;
05735 cllBindVars[cllBindVarCount++]=myTime;
05736 cllBindVars[cllBindVarCount++]=rescId;
05737 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 4");
05738 if (inType==0) {
05739 status = cmlExecuteNoAnswerSql(
05740 "update R_RESC_MAIN set free_space = ?, free_space_ts = ?, modify_ts=? where resc_id=?",
05741 &icss);
05742 }
05743 if (inType==1) {
05744 #if ORA_ICAT
05745
05746 status = cmlExecuteNoAnswerSql(
05747 "update R_RESC_MAIN set free_space = cast(free_space as integer) + cast(? as integer), free_space_ts = ?, modify_ts=? where resc_id=?",
05748 &icss);
05749 #elif MY_ICAT
05750 status = cmlExecuteNoAnswerSql(
05751 "update R_RESC_MAIN set free_space = free_space + ?, free_space_ts = ?, modify_ts=? where resc_id=?",
05752 &icss);
05753 #else
05754 status = cmlExecuteNoAnswerSql(
05755 "update R_RESC_MAIN set free_space = cast(free_space as bigint) + cast(? as bigint), free_space_ts = ?, modify_ts=? where resc_id=?",
05756 &icss);
05757 #endif
05758 }
05759 if (inType==2) {
05760 #if ORA_ICAT
05761
05762 status = cmlExecuteNoAnswerSql(
05763 "update R_RESC_MAIN set free_space = cast(free_space as integer) - cast(? as integer), free_space_ts = ?, modify_ts=? where resc_id=?",
05764 &icss);
05765 #elif MY_ICAT
05766 status = cmlExecuteNoAnswerSql(
05767 "update R_RESC_MAIN set free_space = free_space - ?, free_space_ts = ?, modify_ts=? where resc_id=?",
05768 &icss);
05769 #else
05770 status = cmlExecuteNoAnswerSql(
05771 "update R_RESC_MAIN set free_space = cast(free_space as bigint) - cast(? as bigint), free_space_ts = ?, modify_ts=? where resc_id=?",
05772 &icss);
05773 #endif
05774 }
05775 if (status != 0) {
05776 rodsLog(LOG_NOTICE,
05777 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05778 status);
05779 _rollback("chlModResc");
05780 return(status);
05781 }
05782 OK=1;
05783 }
05784 if (strcmp(option, "host")==0) {
05785
05786
05787 myHostEnt = gethostbyname(optionValue);
05788 if (myHostEnt <= 0) {
05789 char errMsg[155];
05790 snprintf(errMsg, 150,
05791 "Warning, resource host address '%s' is not a valid DNS entry, gethostbyname failed.",
05792 optionValue);
05793 addRErrorMsg (&rsComm->rError, 0, errMsg);
05794 }
05795 if (strcmp(optionValue, "localhost") == 0) {
05796 addRErrorMsg (&rsComm->rError, 0,
05797 "Warning, resource host address 'localhost' will not work properly as it maps to the local host from each client.");
05798 }
05799
05800
05801 cllBindVars[cllBindVarCount++]=optionValue;
05802 cllBindVars[cllBindVarCount++]=myTime;
05803 cllBindVars[cllBindVarCount++]=rescId;
05804 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 5");
05805 status = cmlExecuteNoAnswerSql(
05806 "update R_RESC_MAIN set resc_net = ?, modify_ts=? where resc_id=?",
05807 &icss);
05808 if (status != 0) {
05809 rodsLog(LOG_NOTICE,
05810 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05811 status);
05812 _rollback("chlModResc");
05813 return(status);
05814 }
05815 OK=1;
05816 }
05817 if (strcmp(option, "type")==0) {
05818 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 6");
05819 #if 0 // JMC :: resource type is now dynamic
05820 status = cmlCheckNameToken("resc_type", optionValue, &icss);
05821 if (status !=0 ) {
05822 char errMsg[105];
05823 snprintf(errMsg, 100, "resource_type '%s' is not valid",
05824 optionValue);
05825 addRErrorMsg (&rsComm->rError, 0, errMsg);
05826 return(CAT_INVALID_RESOURCE_TYPE);
05827 }
05828 #endif
05829 cllBindVars[cllBindVarCount++]=optionValue;
05830 cllBindVars[cllBindVarCount++]=myTime;
05831 cllBindVars[cllBindVarCount++]=rescId;
05832 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 7");
05833 status = cmlExecuteNoAnswerSql(
05834 "update R_RESC_MAIN set resc_type_name = ?, modify_ts=? where resc_id=?",
05835 &icss);
05836 if (status != 0) {
05837 rodsLog(LOG_NOTICE,
05838 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05839 status);
05840 _rollback("chlModResc");
05841 return(status);
05842 }
05843 OK=1;
05844 }
05845
05846 #if 0 // JMC - no longer support resource classes
05847 if (strcmp(option, "class")==0) {
05848 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc S---Q---L 8");
05849 status = cmlCheckNameToken("resc_class", optionValue, &icss);
05850 if (status !=0 ) {
05851 char errMsg[105];
05852 snprintf(errMsg, 100, "resource_class '%s' is not valid",
05853 optionValue);
05854 addRErrorMsg (&rsComm->rError, 0, errMsg);
05855 return(CAT_INVALID_RESOURCE_CLASS);
05856 }
05857
05858 cllBindVars[cllBindVarCount++]=optionValue;
05859 cllBindVars[cllBindVarCount++]=myTime;
05860 cllBindVars[cllBindVarCount++]=rescId;
05861 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc S---Q---L 9");
05862 status = cmlExecuteNoAnswerSql(
05863 "update R_RESC_MAIN set resc_class_name = ?, modify_ts=? where resc_id=?",
05864 &icss);
05865 if (status != 0) {
05866 rodsLog(LOG_NOTICE,
05867 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05868 status);
05869 _rollback("chlModResc");
05870 return(status);
05871 }
05872 OK=1;
05873 }
05874 #endif
05875 if (strcmp(option, "path")==0) {
05876 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 10");
05877 status = cmlGetStringValueFromSql(
05878 "select resc_def_path from R_RESC_MAIN where resc_id=?",
05879 rescPath, MAX_NAME_LEN, rescId, 0, 0, &icss);
05880 if (status != 0) {
05881 rodsLog(LOG_NOTICE,
05882 "chlModResc cmlGetStringValueFromSql query failure %d",
05883 status);
05884 _rollback("chlModResc");
05885 return(status);
05886 }
05887
05888 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 11");
05889
05890 cllBindVars[cllBindVarCount++]=optionValue;
05891 cllBindVars[cllBindVarCount++]=myTime;
05892 cllBindVars[cllBindVarCount++]=rescId;
05893 status = cmlExecuteNoAnswerSql(
05894 "update R_RESC_MAIN set resc_def_path=?, modify_ts=? where resc_id=?",
05895 &icss);
05896 if (status != 0) {
05897 rodsLog(LOG_NOTICE,
05898 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05899 status);
05900 _rollback("chlModResc");
05901 return(status);
05902 }
05903 OK=1;
05904 }
05905
05906 if (strcmp(option, "status")==0) {
05907 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 12");
05908 cllBindVars[cllBindVarCount++]=optionValue;
05909 cllBindVars[cllBindVarCount++]=myTime;
05910 cllBindVars[cllBindVarCount++]=rescId;
05911 status = cmlExecuteNoAnswerSql(
05912 "update R_RESC_MAIN set resc_status=?, modify_ts=? where resc_id=?",
05913 &icss);
05914 if (status != 0) {
05915 rodsLog(LOG_NOTICE,
05916 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05917 status);
05918 _rollback("chlModResc");
05919 return(status);
05920 }
05921 OK=1;
05922 }
05923
05924 if (strcmp(option, "name")==0) {
05925 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 13");
05926 cllBindVars[cllBindVarCount++]=optionValue;
05927 cllBindVars[cllBindVarCount++]=myTime;
05928 cllBindVars[cllBindVarCount++]=rescId;
05929
05930 status = cmlExecuteNoAnswerSql(
05931 "update R_RESC_MAIN set resc_name=?, modify_ts=? where resc_id=?",
05932 &icss);
05933 if (status != 0) {
05934 rodsLog(LOG_NOTICE,
05935 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05936 status);
05937 _rollback("chlModResc");
05938 return(status);
05939 }
05940
05941 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 14");
05942 cllBindVars[cllBindVarCount++]=optionValue;
05943 cllBindVars[cllBindVarCount++]=rescName;
05944 status = cmlExecuteNoAnswerSql(
05945 "update R_DATA_MAIN set resc_name=? where resc_name=?",
05946 &icss);
05947 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
05948 if (status != 0) {
05949 rodsLog(LOG_NOTICE,
05950 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05951 status);
05952 _rollback("chlModResc");
05953 return(status);
05954 }
05955
05956 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 15");
05957 cllBindVars[cllBindVarCount++]=optionValue;
05958 cllBindVars[cllBindVarCount++]=rescName;
05959 status = cmlExecuteNoAnswerSql(
05960 "update R_SERVER_LOAD set resc_name=? where resc_name=?",
05961 &icss);
05962 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
05963 if (status != 0) {
05964 rodsLog(LOG_NOTICE,
05965 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05966 status);
05967 _rollback("chlModResc");
05968 return(status);
05969 }
05970
05971 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 16");
05972 cllBindVars[cllBindVarCount++]=optionValue;
05973 cllBindVars[cllBindVarCount++]=rescName;
05974 status = cmlExecuteNoAnswerSql(
05975 "update R_SERVER_LOAD_DIGEST set resc_name=? where resc_name=?",
05976 &icss);
05977 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
05978 if (status != 0) {
05979 rodsLog(LOG_NOTICE,
05980 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05981 status);
05982 _rollback("chlModResc");
05983 return(status);
05984 }
05985
05986
05987 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 17");
05988 cllBindVars[cllBindVarCount++]=optionValue;
05989 cllBindVars[cllBindVarCount++]=rescName;
05990 status = cmlExecuteNoAnswerSql(
05991 "update R_RESC_MAIN set resc_parent=? where resc_parent=?",
05992 &icss);
05993 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
05994 if (status != 0) {
05995 rodsLog(LOG_NOTICE,
05996 "chlModResc cmlExecuteNoAnswerSql update failure %d",
05997 status);
05998 _rollback("chlModResc");
05999 return(status);
06000 }
06001
06002
06003 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 18");
06004 status = _modRescInHierarchies(rescName, optionValue);
06005 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
06006 if (status != 0) {
06007 rodsLog(LOG_NOTICE,
06008 "chlModResc: _modRescInHierarchies error, status = %d",
06009 status);
06010 _rollback("chlModResc");
06011 return(status);
06012 }
06013
06014
06015 if (logSQL!=0) rodsLog(LOG_SQL, "chlModResc SQL 19");
06016 status = _modRescInChildren(rescName, optionValue);
06017 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
06018 if (status != 0) {
06019 rodsLog(LOG_NOTICE,
06020 "chlModResc: _modRescInChildren error, status = %d",
06021 status);
06022 _rollback("chlModResc");
06023 return(status);
06024 }
06025
06026 OK=1;
06027 }
06028
06029 if (strcmp(option, "context")==0) {
06030 cllBindVars[cllBindVarCount++]=optionValue;
06031 cllBindVars[cllBindVarCount++]=myTime;
06032 cllBindVars[cllBindVarCount++]=rescId;
06033 status = cmlExecuteNoAnswerSql(
06034 "update R_RESC_MAIN set resc_context=?, modify_ts=? where resc_id=?",
06035 &icss);
06036 if (status != 0) {
06037 rodsLog(LOG_NOTICE,
06038 "chlModResc cmlExecuteNoAnswerSql update failure for resc context %d",
06039 status);
06040 _rollback("chlModResc");
06041 return(status);
06042 }
06043 OK=1;
06044 }
06045
06046 if (OK==0) {
06047 return (CAT_INVALID_ARGUMENT);
06048 }
06049
06050
06051 snprintf(commentStr, sizeof commentStr, "%s %s", option, optionValue);
06052 status = cmlAudit3(AU_MOD_RESC,
06053 rescId,
06054 rsComm->clientUser.userName,
06055 rsComm->clientUser.rodsZone,
06056 commentStr,
06057 &icss);
06058 if (status != 0) {
06059 rodsLog(LOG_NOTICE,
06060 "chlModResc cmlAudit3 failure %d",
06061 status);
06062 _rollback("chlModResc");
06063 return(status);
06064 }
06065
06066 status = cmlExecuteNoAnswerSql("commit", &icss);
06067 if (status != 0) {
06068 rodsLog(LOG_NOTICE,
06069 "chlModResc cmlExecuteNoAnswerSql commit failure %d",
06070 status);
06071 return(status);
06072 }
06073
06074 if (rescPath[0]!='\0') {
06075
06076
06077 snprintf(rescPathMsg, sizeof(rescPathMsg), "Previous resource path: %s",
06078 rescPath);
06079 addRErrorMsg (&rsComm->rError, 0, rescPathMsg);
06080 }
06081
06082 return(0);
06083 }
06084
06085
06086 int chlModRescDataPaths(rsComm_t *rsComm, char *rescName, char *oldPath,
06087 char *newPath, char *userName) {
06088 char rescId[MAX_NAME_LEN];
06089 int status, len, rows;
06090 char *cptr;
06091
06092 char userZone[NAME_LEN];
06093 char zoneToUse[NAME_LEN];
06094 char userName2[NAME_LEN];
06095
06096 char oldPath2[MAX_NAME_LEN];
06097
06098 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescDataPaths");
06099
06100 if (rescName == NULL || oldPath==NULL || newPath==NULL) {
06101 return (CAT_INVALID_ARGUMENT);
06102 }
06103
06104 if (*rescName == '\0' || *oldPath == '\0' || *newPath=='\0') {
06105 return (CAT_INVALID_ARGUMENT);
06106 }
06107
06108
06109 if (*oldPath != '/' or *newPath != '/') {
06110 return (CAT_INVALID_ARGUMENT);
06111 }
06112 len = strlen(oldPath);
06113 cptr = oldPath+len-1;
06114 if (*cptr != '/') return (CAT_INVALID_ARGUMENT);
06115 len = strlen(newPath);
06116 cptr = newPath+len-1;
06117 if (*cptr != '/') return (CAT_INVALID_ARGUMENT);
06118
06119 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06120 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06121 }
06122 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06123 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06124 }
06125
06126 status = getLocalZone();
06127 if (status != 0) return(status);
06128
06129 rescId[0]='\0';
06130 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescDataPaths SQL 1 ");
06131 status = cmlGetStringValueFromSql(
06132 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
06133 rescId, MAX_NAME_LEN, rescName, localZone, 0, &icss);
06134 if (status != 0) {
06135 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
06136 _rollback("chlModRescDataPaths");
06137 return(status);
06138 }
06139
06140
06141
06142
06143 strncpy(oldPath2, oldPath, sizeof(oldPath2));
06144 strncat(oldPath2, "%", sizeof(oldPath2));
06145
06146 if (userName != NULL && *userName != '\0') {
06147 strncpy(zoneToUse, localZone, NAME_LEN);
06148 status = parseUserName(userName, userName2, userZone);
06149 if (userZone[0]!='\0') {
06150 rstrcpy(zoneToUse, userZone, NAME_LEN);
06151 }
06152
06153 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescDataPaths SQL 2");
06154 cllBindVars[cllBindVarCount++]=oldPath;
06155 cllBindVars[cllBindVarCount++]=newPath;
06156 cllBindVars[cllBindVarCount++]=rescName;
06157 cllBindVars[cllBindVarCount++]=oldPath2;
06158 cllBindVars[cllBindVarCount++]=userName2;
06159 cllBindVars[cllBindVarCount++]=zoneToUse;
06160 status = cmlExecuteNoAnswerSql(
06161 "update R_DATA_MAIN set data_path = replace (R_DATA_MAIN.data_path, ?, ?) where resc_name=? and data_path like ? and data_owner_name=? and data_owner_zone=?",
06162 &icss);
06163 }
06164 else {
06165 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescDataPaths SQL 3");
06166 cllBindVars[cllBindVarCount++]=oldPath;
06167 cllBindVars[cllBindVarCount++]=newPath;
06168 cllBindVars[cllBindVarCount++]=rescName;
06169 cllBindVars[cllBindVarCount++]=oldPath2;
06170 status = cmlExecuteNoAnswerSql(
06171 "update R_DATA_MAIN set data_path = replace (R_DATA_MAIN.data_path, ?, ?) where resc_name=? and data_path like ?",
06172 &icss);
06173 }
06174 if (status != 0) {
06175 rodsLog(LOG_NOTICE,
06176 "chlModRescDataPaths cmlExecuteNoAnswerSql update failure %d",
06177 status);
06178 _rollback("chlModResc");
06179 return(status);
06180 }
06181
06182 rows = cllGetRowCount(&icss,-1);
06183
06184 status = cmlExecuteNoAnswerSql("commit", &icss);
06185 if (status != 0) {
06186 rodsLog(LOG_NOTICE,
06187 "chlModResc cmlExecuteNoAnswerSql commit failure %d",
06188 status);
06189 return(status);
06190 }
06191
06192 if (rows > 0) {
06193 char rowsMsg[100];
06194 snprintf(rowsMsg, 100, "%d rows updated",
06195 rows);
06196 status = addRErrorMsg (&rsComm->rError, 0, rowsMsg);
06197 }
06198
06199 return(0);
06200 }
06201
06202
06203
06204
06205
06206
06207 int chlModRescFreeSpace(rsComm_t *rsComm, char *rescName, int updateValue) {
06208 int status;
06209 char myTime[50];
06210 char updateValueStr[MAX_NAME_LEN];
06211
06212 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescFreeSpace");
06213
06214 if (rescName == NULL) {
06215 return (CAT_INVALID_ARGUMENT);
06216 }
06217
06218 if (*rescName == '\0') {
06219 return (CAT_INVALID_ARGUMENT);
06220 }
06221
06222
06223
06224
06225
06226 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06227 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06228 }
06229 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06230 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06231 }
06232
06233 status = getLocalZone();
06234 if (status != 0) return(status);
06235
06236 getNowStr(myTime);
06237
06238 snprintf(updateValueStr,MAX_NAME_LEN, "%d", updateValue);
06239
06240 cllBindVars[cllBindVarCount++]=updateValueStr;
06241 cllBindVars[cllBindVarCount++]=myTime;
06242 cllBindVars[cllBindVarCount++]=rescName;
06243
06244 if (logSQL!=0) rodsLog(LOG_SQL, "chlModRescFreeSpace SQL 1 ");
06245 status = cmlExecuteNoAnswerSql(
06246 "update R_RESC_MAIN set free_space = ?, free_space_ts=? where resc_name=?",
06247 &icss);
06248 if (status != 0) {
06249 rodsLog(LOG_NOTICE,
06250 "chlModRescFreeSpace cmlExecuteNoAnswerSql update failure %d",
06251 status);
06252 _rollback("chlModRescFreeSpace");
06253 return(status);
06254 }
06255
06256
06257 status = cmlAudit4(AU_MOD_RESC_FREE_SPACE,
06258 "select resc_id from R_RESC_MAIN where resc_name=?",
06259 rescName,
06260 rsComm->clientUser.userName,
06261 rsComm->clientUser.rodsZone,
06262 updateValueStr,
06263 &icss);
06264 if (status != 0) {
06265 rodsLog(LOG_NOTICE,
06266 "chlModRescFreeSpace cmlAudit4 failure %d",
06267 status);
06268 _rollback("chlModRescFreeSpace");
06269 return(status);
06270 }
06271
06272 return(0);
06273 }
06274
06275
06276 int chlModRescGroup(rsComm_t *rsComm, char *rescGroupName, char *option,
06277 char *rescName) {
06278 int status, OK;
06279 char myTime[50];
06280 char rescId[MAX_NAME_LEN];
06281 rodsLong_t seqNum;
06282 char rescGroupId[MAX_NAME_LEN];
06283 char dataObjNumber[MAX_NAME_LEN];
06284 char commentStr[200];
06285
06286 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group");
06287
06288 if (rescGroupName == NULL || option==NULL || rescName==NULL) {
06289 return (CAT_INVALID_ARGUMENT);
06290 }
06291
06292 if (*rescGroupName == '\0' || *option == '\0' || *rescName=='\0') {
06293 return (CAT_INVALID_ARGUMENT);
06294 }
06295
06296 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06297 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06298 }
06299 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06300 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06301 }
06302
06303 status = getLocalZone();
06304 if (status != 0) return(status);
06305
06306 rescId[0]='\0';
06307 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 1 ");
06308 status = cmlGetStringValueFromSql(
06309 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
06310 rescId, MAX_NAME_LEN, rescName, localZone, 0, &icss);
06311 if (status != 0) {
06312 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
06313 _rollback("chlModRescGroup");
06314 return(status);
06315 }
06316
06317 getNowStr(myTime);
06318 OK=0;
06319 if (strcmp(option, "add")==0) {
06320
06321 rescGroupId[0]='\0';
06322 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 2a ");
06323 status = cmlGetStringValueFromSql(
06324 "select distinct resc_group_id from R_RESC_GROUP where resc_group_name=?",
06325 rescGroupId, MAX_NAME_LEN, rescGroupName, 0, 0, &icss);
06326 if (status != 0) {
06327 if (status==CAT_NO_ROWS_FOUND) {
06328
06329 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 2b ");
06330 seqNum = cmlGetNextSeqVal(&icss);
06331 if (seqNum < 0) {
06332 rodsLog(LOG_NOTICE, "chlModRescGroup cmlGetNextSeqVal failure %d",
06333 seqNum);
06334 _rollback("chlModRescGroup");
06335 return(seqNum);
06336 }
06337 snprintf(rescGroupId, MAX_NAME_LEN, "%lld", seqNum);
06338 } else {
06339 _rollback("chlModRescGroup");
06340 return(status);
06341 }
06342 }
06343
06344 cllBindVars[cllBindVarCount++]=rescGroupName;
06345 cllBindVars[cllBindVarCount++]=rescGroupId;
06346 cllBindVars[cllBindVarCount++]=rescId;
06347 cllBindVars[cllBindVarCount++]=myTime;
06348 cllBindVars[cllBindVarCount++]=myTime;
06349 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 2");
06350 status = cmlExecuteNoAnswerSql(
06351 "insert into R_RESC_GROUP (resc_group_name, resc_group_id, resc_id , create_ts, modify_ts) values (?, ?, ?, ?, ?)",
06352 &icss);
06353 if (status != 0) {
06354 rodsLog(LOG_NOTICE,
06355 "chlModRescGroup cmlExecuteNoAnswerSql insert failure %d",
06356 status);
06357 _rollback("chlModRescGroup");
06358 return(status);
06359 }
06360 OK=1;
06361 }
06362
06363 if (strcmp(option, "remove")==0) {
06364
06365 dataObjNumber[0]='\0';
06366 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 3a ");
06367 status = cmlGetStringValueFromSql(
06368 "select distinct resc_group_id from R_RESC_GROUP where resc_id=? and resc_group_name=?",
06369 dataObjNumber, MAX_NAME_LEN, rescId, rescGroupName, 0, &icss);
06370 if (status != 0) {
06371 _rollback("chlModRescGroup");
06372 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
06373 return(status);
06374 }
06375
06376
06377 cllBindVars[cllBindVarCount++]=rescGroupName;
06378 cllBindVars[cllBindVarCount++]=rescId;
06379 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 3b");
06380 status = cmlExecuteNoAnswerSql(
06381 "delete from R_RESC_GROUP where resc_group_name=? and resc_id=?",
06382 &icss);
06383 if (status != 0) {
06384 rodsLog(LOG_NOTICE,
06385 "chlModRescGroup cmlExecuteNoAnswerSql delete failure %d",
06386 status);
06387 _rollback("chlModRescGroup");
06388 return(status);
06389 }
06390
06391
06392 rescGroupId[0]='\0';
06393 if (logSQL!=0) rodsLog(LOG_SQL, "chl-Mod-Resc-Group S Q L 3c ");
06394 status = cmlGetStringValueFromSql(
06395 "select distinct resc_group_id from R_RESC_GROUP where resc_group_name=?",
06396 rescGroupId, MAX_NAME_LEN, rescGroupName, 0, 0, &icss);
06397 if (status != 0) {
06398 if (status==CAT_NO_ROWS_FOUND) {
06399
06400 removeMetaMapAndAVU(dataObjNumber);
06401 }
06402 }
06403 OK=1;
06404 }
06405
06406 if (OK==0) {
06407 return (CAT_INVALID_ARGUMENT);
06408 }
06409
06410
06411 snprintf(commentStr, sizeof commentStr, "%s %s", option, rescGroupName);
06412 status = cmlAudit3(AU_MOD_RESC_GROUP,
06413 rescId,
06414 rsComm->clientUser.userName,
06415 rsComm->clientUser.rodsZone,
06416 commentStr,
06417 &icss);
06418 if (status != 0) {
06419 rodsLog(LOG_NOTICE,
06420 "chlModRescGroup cmlAudit3 failure %d",
06421 status);
06422 _rollback("chlModRescGroup");
06423 return(status);
06424 }
06425
06426 status = cmlExecuteNoAnswerSql("commit", &icss);
06427 if (status != 0) {
06428 rodsLog(LOG_NOTICE,
06429 "chlModRescGroup cmlExecuteNoAnswerSql commit failure %d",
06430 status);
06431 return(status);
06432 }
06433 return(0);
06434 }
06435
06436
06437
06438 eirods::error validate_user_name(std::string _user_name) {
06439
06440
06441
06442
06443 boost::regex re("^(?=.{3,63}$)\\w(\\w*([.-]\\w+)?)*$");
06444
06445
06446
06447
06448 if (!boost::regex_match(_user_name, re)) {
06449 std::stringstream msg;
06450 msg << "validate_user_name failed for user [";
06451 msg << _user_name;
06452 msg << "]";
06453 return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
06454 }
06455
06456 return SUCCESS();
06457
06458 }
06459
06460
06461
06462 int chlRegUserRE(rsComm_t *rsComm, userInfo_t *userInfo) {
06463 char myTime[50];
06464 int status;
06465 char seqStr[MAX_NAME_LEN];
06466 char auditSQL[MAX_SQL_SIZE];
06467 char userZone[MAX_NAME_LEN];
06468 char zoneId[MAX_NAME_LEN];
06469
06470 int zoneForm;
06471 char userName2[NAME_LEN];
06472 char zoneName[NAME_LEN];
06473
06474 static char lastValidUserType[MAX_NAME_LEN]="";
06475 static char userTypeTokenName[MAX_NAME_LEN]="";
06476
06477 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE");
06478
06479 if (!icss.status) {
06480 return(CATALOG_NOT_CONNECTED);
06481 }
06482
06483 if (!userInfo) {
06484 return(SYS_INTERNAL_NULL_INPUT_ERR);
06485 }
06486
06487
06488
06489
06490 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ||
06491 rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06492 int status2;
06493 status2 = cmlCheckGroupAdminAccess(
06494 rsComm->clientUser.userName,
06495 rsComm->clientUser.rodsZone,
06496 "",
06497 &icss);
06498 if (status2 != 0) return(status2);
06499 creatingUserByGroupAdmin=1;
06500 }
06501
06502
06503
06504
06505
06506
06507 if ( *userInfo->userType=='\0' ||
06508 strcmp(userInfo->userType, lastValidUserType)!=0 ) {
06509 char errMsg[105];
06510 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE SQL 1 ");
06511 status = cmlGetStringValueFromSql(
06512 "select token_name from R_TOKN_MAIN where token_namespace='user_type' and token_name=?",
06513 userTypeTokenName, MAX_NAME_LEN, userInfo->userType, 0, 0, &icss);
06514 if (status==0) {
06515 strncpy(lastValidUserType, userInfo->userType, MAX_NAME_LEN);
06516 }
06517 else {
06518 snprintf(errMsg, 100, "user_type '%s' is not valid",
06519 userInfo->userType);
06520 addRErrorMsg (&rsComm->rError, 0, errMsg);
06521 return(CAT_INVALID_USER_TYPE);
06522 }
06523 }
06524
06525 status = getLocalZone();
06526 if (status != 0) return(status);
06527
06528 if (strlen(userInfo->rodsZone)>0) {
06529 zoneForm=1;
06530 strncpy(userZone, userInfo->rodsZone, MAX_NAME_LEN);
06531 }
06532 else {
06533 zoneForm=0;
06534 strncpy(userZone, localZone, MAX_NAME_LEN);
06535 }
06536
06537 status = parseUserName(userInfo->userName, userName2, zoneName);
06538 if (zoneName[0]!='\0') {
06539 rstrcpy(userZone, zoneName, NAME_LEN);
06540 zoneForm=2;
06541 }
06542 if (status != 0) {
06543 return (CAT_INVALID_ARGUMENT);
06544 }
06545
06546
06547
06548
06549 eirods::error ret = validate_user_name(userName2);
06550 if(!ret.ok()) {
06551 eirods::log(ret);
06552 return SYS_INVALID_INPUT_PARAM;
06553 }
06554
06555
06556
06557 if (zoneForm) {
06558
06559 zoneId[0]='\0';
06560 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE SQL 5 ");
06561 status = cmlGetStringValueFromSql(
06562 "select zone_id from R_ZONE_MAIN where zone_name=?",
06563 zoneId, MAX_NAME_LEN, userZone, "", 0, &icss);
06564 if (status != 0) {
06565 if (status==CAT_NO_ROWS_FOUND) {
06566 char errMsg[105];
06567 snprintf(errMsg, 100,
06568 "zone '%s' does not exist",
06569 userZone);
06570 addRErrorMsg (&rsComm->rError, 0, errMsg);
06571 return(CAT_INVALID_ZONE);
06572 }
06573 return(status);
06574 }
06575 }
06576
06577 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE SQL 2");
06578 status = cmlGetNextSeqStr(seqStr, MAX_NAME_LEN, &icss);
06579 if (status != 0) {
06580 rodsLog(LOG_NOTICE, "chlRegUserRE cmlGetNextSeqStr failure %d",
06581 status);
06582 return(status);
06583 }
06584
06585 getNowStr(myTime);
06586
06587 cllBindVars[cllBindVarCount++]=seqStr;
06588 cllBindVars[cllBindVarCount++]=userName2;
06589 cllBindVars[cllBindVarCount++]=userTypeTokenName;
06590 cllBindVars[cllBindVarCount++]=userZone;
06591 cllBindVars[cllBindVarCount++]=myTime;
06592 cllBindVars[cllBindVarCount++]=myTime;
06593
06594 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE SQL 3");
06595 status = cmlExecuteNoAnswerSql(
06596 "insert into R_USER_MAIN (user_id, user_name, user_type_name, zone_name, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?)",
06597 &icss);
06598
06599 if (status != 0) {
06600 if (status == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
06601 char errMsg[105];
06602 snprintf(errMsg, 100, "Error %d %s",
06603 status,
06604 "CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME"
06605 );
06606 addRErrorMsg (&rsComm->rError, 0, errMsg);
06607 }
06608 _rollback("chlRegUserRE");
06609 rodsLog(LOG_NOTICE,
06610 "chlRegUserRE insert failure %d",status);
06611 return(status);
06612 }
06613
06614
06615 cllBindVars[cllBindVarCount++]=seqStr;
06616 cllBindVars[cllBindVarCount++]=seqStr;
06617 cllBindVars[cllBindVarCount++]=myTime;
06618 cllBindVars[cllBindVarCount++]=myTime;
06619
06620 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegUserRE SQL 4");
06621 status = cmlExecuteNoAnswerSql(
06622 "insert into R_USER_GROUP (group_user_id, user_id, create_ts, modify_ts) values (?, ?, ?, ?)",
06623 &icss);
06624 if (status != 0) {
06625 rodsLog(LOG_NOTICE,
06626 "chlRegUserRE insert into R_USER_GROUP failure %d",status);
06627 _rollback("chlRegUserRE");
06628 return(status);
06629 }
06630
06631
06632
06633
06634
06635
06636
06637 if (strlen(userInfo->authInfo.authStr) > 0) {
06638 status = chlModUser(rsComm, userInfo->userName, "addAuth",
06639 userInfo->authInfo.authStr);
06640 if (status != 0) {
06641 rodsLog(LOG_NOTICE,
06642 "chlRegUserRE chlModUser insert auth failure %d",status);
06643 _rollback("chlRegUserRE");
06644 return(status);
06645 }
06646 }
06647
06648
06649 snprintf(auditSQL, MAX_SQL_SIZE-1,
06650 "select user_id from R_USER_MAIN where user_name=? and zone_name='%s'",
06651 userZone);
06652 status = cmlAudit4(AU_REGISTER_USER_RE,
06653 auditSQL,
06654 userName2,
06655 rsComm->clientUser.userName,
06656 rsComm->clientUser.rodsZone,
06657 userZone,
06658 &icss);
06659 if (status != 0) {
06660 rodsLog(LOG_NOTICE,
06661 "chlRegUserRE cmlAudit4 failure %d",
06662 status);
06663 _rollback("chlRegUserRE");
06664 return(status);
06665 }
06666
06667
06668 return(status);
06669 }
06670
06671 int
06672 convertTypeOption(char *typeStr) {
06673 if (strcmp(typeStr, "-d") == 0) return(1);
06674 if (strcmp(typeStr, "-D") == 0) return(1);
06675 if (strcmp(typeStr, "-c") == 0) return(2);
06676 if (strcmp(typeStr, "-C") == 0) return(2);
06677 if (strcmp(typeStr, "-r") == 0) return(3);
06678 if (strcmp(typeStr, "-R") == 0) return(3);
06679 if (strcmp(typeStr, "-u") == 0) return(4);
06680 if (strcmp(typeStr, "-U") == 0) return(4);
06681 if (strcmp(typeStr, "-g") == 0) return(5);
06682 if (strcmp(typeStr, "-G") == 0) return(5);
06683 return (0);
06684 }
06685
06686
06687
06688
06689
06690 rodsLong_t checkAndGetObjectId(rsComm_t *rsComm, char *type,
06691 char *name, char *access) {
06692 int itype;
06693 char logicalEndName[MAX_NAME_LEN];
06694 char logicalParentDirName[MAX_NAME_LEN];
06695 rodsLong_t status;
06696 rodsLong_t objId;
06697 char userName[NAME_LEN];
06698 char userZone[NAME_LEN];
06699
06700
06701 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId");
06702
06703 if (!icss.status) {
06704 return(CATALOG_NOT_CONNECTED);
06705 }
06706
06707 if (type == NULL || *type=='\0') {
06708 return (CAT_INVALID_ARGUMENT);
06709 }
06710
06711 if (name == NULL || *name=='\0') {
06712 return (CAT_INVALID_ARGUMENT);
06713 }
06714
06715 itype = convertTypeOption(type);
06716 if (itype==0) return(CAT_INVALID_ARGUMENT);
06717
06718 if (itype==1) {
06719 status = splitPathByKey(name,
06720 logicalParentDirName, logicalEndName, '/');
06721 if (strlen(logicalParentDirName)==0) {
06722 strcpy(logicalParentDirName, "/");
06723 strcpy(logicalEndName, name);
06724 }
06725 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId SQL 1 ");
06726 status = cmlCheckDataObjOnly(logicalParentDirName, logicalEndName,
06727 rsComm->clientUser.userName,
06728 rsComm->clientUser.rodsZone,
06729 access, &icss);
06730 if (status < 0) {
06731 _rollback("checkAndGetObjectId");
06732 return(status);
06733 }
06734 objId=status;
06735 }
06736
06737 if (itype==2) {
06738
06739
06740 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId SQL 2");
06741 status = cmlCheckDir(name,
06742 rsComm->clientUser.userName,
06743 rsComm->clientUser.rodsZone,
06744 access, &icss);
06745 if (status < 0) {
06746 char errMsg[105];
06747 if (status == CAT_UNKNOWN_COLLECTION) {
06748 snprintf(errMsg, 100, "collection '%s' is unknown",
06749 name);
06750 addRErrorMsg (&rsComm->rError, 0, errMsg);
06751 }
06752 return(status);
06753 }
06754 objId=status;
06755 }
06756
06757 if (itype==3) {
06758 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06759 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06760 }
06761
06762 status = getLocalZone();
06763 if (status != 0) return(status);
06764
06765 objId=0;
06766 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId SQL 3");
06767 status = cmlGetIntegerValueFromSql(
06768 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
06769 &objId, name, localZone, 0, 0, 0, &icss);
06770 if (status != 0) {
06771 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
06772 _rollback("checkAndGetObjectId");
06773 return(status);
06774 }
06775 }
06776
06777 if (itype==4) {
06778 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06779 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06780 }
06781
06782 status = parseUserName(name, userName, userZone);
06783 if (userZone[0]=='\0') {
06784 status = getLocalZone();
06785 if (status != 0) return(status);
06786 strncpy(userZone, localZone, NAME_LEN);
06787 }
06788
06789 objId=0;
06790 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId SQL 4");
06791 status = cmlGetIntegerValueFromSql(
06792 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
06793 &objId, userName, userZone, 0, 0, 0, &icss);
06794 if (status != 0) {
06795 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
06796 _rollback("checkAndGetObjectId");
06797 return(status);
06798 }
06799 }
06800
06801 if (itype==5) {
06802 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
06803 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
06804 }
06805
06806 status = getLocalZone();
06807 if (status != 0) return(status);
06808
06809 objId=0;
06810 if (logSQL!=0) rodsLog(LOG_SQL, "checkAndGetObjectId S Q L 5");
06811 status = cmlGetIntegerValueFromSql(
06812 "select distinct resc_group_id from R_RESC_GROUP where resc_group_name=?",
06813 &objId, name, 0, 0, 0, 0, &icss);
06814 if (status != 0) {
06815 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
06816 _rollback("checkAndGetObjectId");
06817 return(status);
06818 }
06819 }
06820
06821 return(objId);
06822 }
06823
06824
06825
06826
06827
06828
06829 rodsLong_t
06830 findAVU(char *attribute, char *value, char *units) {
06831 rodsLong_t status;
06832
06833
06834 rodsLong_t iVal;
06835 iVal=0;
06836 if (*units!='\0') {
06837 if (logSQL!=0) rodsLog(LOG_SQL, "findAVU SQL 1");
06838 status = cmlGetIntegerValueFromSql(
06839 "select meta_id from R_META_MAIN where meta_attr_name=? and meta_attr_value=? and meta_attr_unit=?",
06840 &iVal, attribute, value, units, 0, 0, &icss);
06841 }
06842 else {
06843 if (logSQL!=0) rodsLog(LOG_SQL, "findAVU SQL 2");
06844 status = cmlGetIntegerValueFromSql(
06845 "select meta_id from R_META_MAIN where meta_attr_name=? and meta_attr_value=? and (meta_attr_unit='' or meta_attr_unit IS NULL)",
06846 &iVal, attribute, value, 0, 0, 0, &icss);
06847 }
06848 if (status == 0) {
06849 status = iVal;
06850 return(status);
06851 }
06852
06853
06854 return(status);
06855 }
06856
06857
06858
06859
06860
06861 int
06862 findOrInsertAVU(char *attribute, char *value, char *units) {
06863 char nextStr[MAX_NAME_LEN];
06864 char myTime[50];
06865 rodsLong_t status, seqNum;
06866 rodsLong_t iVal;
06867 iVal = findAVU(attribute, value, units);
06868 if (iVal > 0) {
06869 return iVal;
06870 }
06871 if (logSQL!=0) rodsLog(LOG_SQL, "findOrInsertAVU SQL 1");
06872
06873 status = cmlGetNextSeqVal(&icss);
06874 if (status < 0) {
06875 rodsLog(LOG_NOTICE, "findAVU cmlGetNextSeqVal failure %d",
06876 status);
06877 return(status);
06878 }
06879 seqNum = status;
06880
06881 snprintf(nextStr, sizeof nextStr, "%lld", seqNum);
06882
06883 getNowStr(myTime);
06884
06885 cllBindVars[cllBindVarCount++]=nextStr;
06886 cllBindVars[cllBindVarCount++]=attribute;
06887 cllBindVars[cllBindVarCount++]=value;
06888 cllBindVars[cllBindVarCount++]=units;
06889 cllBindVars[cllBindVarCount++]=myTime;
06890 cllBindVars[cllBindVarCount++]=myTime;
06891
06892 if (logSQL!=0) rodsLog(LOG_SQL, "findOrInsertAVU SQL 2");
06893 status = cmlExecuteNoAnswerSql(
06894 "insert into R_META_MAIN (meta_id, meta_attr_name, meta_attr_value, meta_attr_unit, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?)",
06895 &icss);
06896 if (status < 0) {
06897 rodsLog(LOG_NOTICE, "findOrInsertAVU insert failure %d", status);
06898 return(status);
06899 }
06900 return(seqNum);
06901 }
06902
06903
06904
06905
06906 int chlSetAVUMetadata(rsComm_t *rsComm, char *type,
06907 char *name, char *attribute, char *newValue,
06908 char *newUnit) {
06909 int status;
06910 char myTime[50];
06911 rodsLong_t objId;
06912 char metaIdStr[MAX_NAME_LEN*2];
06913 char objIdStr[MAX_NAME_LEN];
06914
06915 memset(metaIdStr, 0, sizeof(metaIdStr));
06916 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata");
06917
06918 if (!icss.status) {
06919 return(CATALOG_NOT_CONNECTED);
06920 }
06921
06922 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata SQL 1 ");
06923 objId = checkAndGetObjectId(rsComm, type, name, ACCESS_CREATE_METADATA);
06924 if (objId < 0) return objId;
06925 snprintf(objIdStr, MAX_NAME_LEN, "%lld", objId);
06926
06927 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata SQL 2");
06928
06929 status = cmlGetMultiRowStringValuesFromSql("select meta_id from R_OBJT_METAMAP where meta_id in (select meta_id from R_META_MAIN where meta_attr_name=? AND meta_id in (select meta_id from R_OBJT_METAMAP where object_id=?))",
06930 metaIdStr, MAX_NAME_LEN, 2, attribute, objIdStr, &icss);
06931
06932 if (status <= 0) {
06933 if (status == CAT_NO_ROWS_FOUND) {
06934
06935 status = chlAddAVUMetadata(rsComm, 0, type, name, attribute,
06936 newValue, newUnit);
06937 } else {
06938 rodsLog(LOG_NOTICE,
06939 "chlSetAVUMetadata cmlGetMultiRowStringValuesFromSql failure %d",
06940 status);
06941 }
06942 return status;
06943 }
06944
06945 if (status > 1) {
06946
06947 status = chlDeleteAVUMetadata(rsComm, 1, type, name, attribute, "%",
06948 "%", 1);
06949 if (status != 0) {
06950 _rollback("chlSetAVUMetadata");
06951 return(status);
06952 }
06953 status = chlAddAVUMetadata(rsComm, 0, type, name, attribute,
06954 newValue, newUnit);
06955 return status;
06956 }
06957
06958
06959
06960 rodsLog(LOG_NOTICE, "chlSetAVUMetadata found metaId %s", metaIdStr);
06961
06962 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata SQL 4");
06963 status = cmlGetMultiRowStringValuesFromSql("select meta_id from R_META_MAIN where meta_attr_name=?",
06964 metaIdStr, MAX_NAME_LEN, 2, attribute, objIdStr, &icss);
06965 if (status <= 0) {
06966 rodsLog(LOG_NOTICE,
06967 "chlSetAVUMetadata cmlGetMultiRowStringValueFromSql failure %d",
06968 status);
06969 return(status);
06970 }
06971 if (status > 1) {
06972
06973
06974
06975 status = chlDeleteAVUMetadata(rsComm, 1, type, name, attribute,
06976 "%", "%", 1);
06977 if (status != 0) {
06978 _rollback("chlSetAVUMetadata");
06979 return(status);
06980 }
06981 status = chlAddAVUMetadata(rsComm, 0, type, name, attribute,
06982 newValue, newUnit);
06983 }
06984 else {
06985 getNowStr(myTime);
06986 cllBindVarCount = 0;
06987 cllBindVars[cllBindVarCount++] = newValue;
06988 if (newUnit != NULL && *newUnit!='\0') {
06989 cllBindVars[cllBindVarCount++] = newUnit;
06990 }
06991 cllBindVars[cllBindVarCount++] = myTime;
06992 cllBindVars[cllBindVarCount++] = attribute;
06993 cllBindVars[cllBindVarCount++] = metaIdStr;
06994 if (newUnit != NULL && *newUnit!='\0') {
06995 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata SQL 5");
06996 status = cmlExecuteNoAnswerSql(
06997 "update R_META_MAIN set meta_attr_value=?,meta_attr_unit=?,modify_ts=? where meta_attr_name=? and meta_id=?",
06998 &icss);
06999 }
07000 else {
07001 if (logSQL != 0) rodsLog(LOG_SQL, "chlSetAVUMetadata SQL 6");
07002 status = cmlExecuteNoAnswerSql(
07003 "update R_META_MAIN set meta_attr_value=?,modify_ts=? where meta_attr_name=? and meta_id=?",
07004 &icss);
07005 }
07006 if (status != 0) {
07007 rodsLog(LOG_NOTICE,
07008 "chlSetAVUMetadata cmlExecuteNoAnswerSql update failure %d",
07009 status);
07010 _rollback("chlSetAVUMetadata");
07011 return(status);
07012 }
07013 }
07014
07015
07016 status = cmlAudit3(AU_ADD_AVU_METADATA,
07017 objIdStr,
07018 rsComm->clientUser.userName,
07019 rsComm->clientUser.rodsZone,
07020 type,
07021 &icss);
07022 if (status != 0) {
07023 rodsLog(LOG_NOTICE,
07024 "chlSetAVUMetadata cmlAudit3 failure %d",
07025 status);
07026 _rollback("chlSetAVUMetadata");
07027 return(status);
07028 }
07029
07030 status = cmlExecuteNoAnswerSql("commit", &icss);
07031 if (status != 0) {
07032 rodsLog(LOG_NOTICE,
07033 "chlSetAVUMetadata cmlExecuteNoAnswerSql commit failure %d",
07034 status);
07035 return(status);
07036 }
07037
07038 return(status);
07039 }
07040
07041
07042
07043
07044
07045
07046
07047
07048
07049 #define ACCESS_MAX 999999
07050
07051
07052 int
07053 chlAddAVUMetadataWild(rsComm_t *rsComm, int adminMode, char *type,
07054 char *name, char *attribute, char *value, char *units) {
07055 rodsLong_t status, status2;
07056 rodsLong_t seqNum;
07057 int numObjects;
07058 int nAccess=0;
07059 static int accessNeeded=ACCESS_MAX;
07060 rodsLong_t iVal;
07061 char collection[MAX_NAME_LEN];
07062 char objectName[MAX_NAME_LEN];
07063 char myTime[50];
07064 char seqNumStr[MAX_NAME_LEN];
07065 int itype;
07066
07067 itype = convertTypeOption(type);
07068 if (itype!=1) return(CAT_INVALID_ARGUMENT);
07069
07070 status = splitPathByKey(name, collection, objectName, '/');
07071 if (strlen(collection)==0) {
07072 strcpy(collection, "/");
07073 strcpy(objectName, name);
07074 }
07075
07076
07077
07078
07079
07080
07081
07082
07083
07084
07085 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 1");
07086 status = cmlGetIntegerValueFromSql(
07087 "select count(DISTINCT DM.data_id) from R_DATA_MAIN DM, R_COLL_MAIN CM where DM.data_name like ? and DM.coll_id=CM.coll_id and CM.coll_name like ?",
07088 &iVal, objectName, collection, 0, 0, 0, &icss);
07089 if (status != 0) {
07090 rodsLog(LOG_NOTICE,
07091 "chlAddAVUMetadataWild get count failure %d",
07092 status);
07093 _rollback("chlAddAVUMetadataWild");
07094 return(status);
07095 }
07096 numObjects = iVal;
07097 if (numObjects == 0) {
07098 return(CAT_NO_ROWS_FOUND);
07099 }
07100
07101
07102
07103
07104
07105 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 2");
07106 #if ORA_ICAT
07107
07108
07109 status = cmlExecuteNoAnswerSql("purge recyclebin",
07110 &icss);
07111 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07112 if (status != 0) {
07113 rodsLog(LOG_NOTICE,
07114 "chlAddAVUMetadata cmlExecuteNoAnswerSql (drop table ACCESS_VIEW_ONE) failure %d",
07115 status);
07116 }
07117 status = cmlExecuteNoAnswerSql("drop table ACCESS_VIEW_ONE",
07118 &icss);
07119 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07120 if (status != 0) {
07121 rodsLog(LOG_NOTICE,
07122 "chlAddAVUMetadata cmlExecuteNoAnswerSql (drop table ACCESS_VIEW_ONE) failure %d",
07123 status);
07124 }
07125
07126 status = cmlExecuteNoAnswerSql("create table ACCESS_VIEW_ONE (access_type_id integer, data_id integer)",
07127 &icss);
07128 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07129 if (status != 0) {
07130 rodsLog(LOG_NOTICE,
07131 "chlAddAVUMetadata cmlExecuteNoAnswerSql (create table ACCESS_VIEW_ONE) failure %d",
07132 status);
07133 _rollback("chlAddAVUMetadataWild");
07134 return(status);
07135 }
07136
07137 cllBindVars[cllBindVarCount++]=objectName;
07138 cllBindVars[cllBindVarCount++]=collection;
07139 cllBindVars[cllBindVarCount++]=rsComm->clientUser.userName;
07140 cllBindVars[cllBindVarCount++]=rsComm->clientUser.rodsZone;
07141 status = cmlExecuteNoAnswerSql(
07142 "insert into ACCESS_VIEW_ONE (access_type_id, data_id) (select access_type_id, DM.data_id from R_DATA_MAIN DM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_COLL_MAIN CM where DM.data_name like ? and DM.coll_id=CM.coll_id and CM.coll_name like ? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = DM.data_id and UG.group_user_id = OA.user_id)",
07143 &icss);
07144 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07145 if (status==CAT_NO_ROWS_FOUND) status=CAT_NO_ACCESS_PERMISSION;
07146 if (status != 0) {
07147 rodsLog(LOG_NOTICE,
07148 "chlAddAVUMetadata cmlExecuteNoAnswerSql (create view) failure %d",
07149 status);
07150 _rollback("chlAddAVUMetadataWild");
07151 return(status);
07152 }
07153 #else
07154 cllBindVars[cllBindVarCount++]=objectName;
07155 cllBindVars[cllBindVarCount++]=collection;
07156 cllBindVars[cllBindVarCount++]=rsComm->clientUser.userName;
07157 cllBindVars[cllBindVarCount++]=rsComm->clientUser.rodsZone;
07158 status = cmlExecuteNoAnswerSql(
07159 "create view ACCESS_VIEW_ONE as select access_type_id, DM.data_id from R_DATA_MAIN DM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_COLL_MAIN CM where DM.data_name like ? and DM.coll_id=CM.coll_id and CM.coll_name like ? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = DM.data_id and UG.group_user_id = OA.user_id",
07160 &icss);
07161 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07162 if (status==CAT_NO_ROWS_FOUND) status=CAT_NO_ACCESS_PERMISSION;
07163 if (status != 0) {
07164 rodsLog(LOG_NOTICE,
07165 "chlAddAVUMetadata cmlExecuteNoAnswerSql (create view) failure %d",
07166 status);
07167 _rollback("chlAddAVUMetadataWild");
07168 return(status);
07169 }
07170 #endif
07171
07172
07173
07174
07175
07176
07177 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 3");
07178 #if (defined ORA_ICAT || defined MY_ICAT)
07179 status = cmlExecuteNoAnswerSql(
07180 "create or replace view ACCESS_VIEW_TWO as select max(access_type_id) max from ACCESS_VIEW_ONE group by data_id",
07181 &icss);
07182 #else
07183 status = cmlExecuteNoAnswerSql(
07184 "create or replace view ACCESS_VIEW_TWO as select max(access_type_id) from ACCESS_VIEW_ONE group by data_id",
07185 &icss);
07186 #endif
07187 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
07188 if (status==CAT_NO_ROWS_FOUND) status=CAT_NO_ACCESS_PERMISSION;
07189 if (status != 0) {
07190 rodsLog(LOG_NOTICE,
07191 "chlAddAVUMetadata cmlExecuteNoAnswerSql (create view) failure %d",
07192 status);
07193 _rollback("chlAddAVUMetadataWild");
07194 return(status);
07195 }
07196
07197 if (accessNeeded>=ACCESS_MAX) {
07198 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 4");
07199 status = cmlGetIntegerValueFromSql(
07200 "select token_id from R_TOKN_MAIN where token_name = 'modify metadata' and token_namespace = 'access_type'",
07201 &iVal, 0, 0, 0, 0, 0, &icss);
07202 if (status==0) accessNeeded = iVal;
07203 }
07204
07205
07206
07207 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 5");
07208 iVal=-1;
07209 status = cmlGetIntegerValueFromSql(
07210 "select min(max) from ACCESS_VIEW_TWO",
07211 &iVal, 0, 0, 0, 0, 0, &icss);
07212
07213 if (status==CAT_NO_ROWS_FOUND) status=CAT_NO_ACCESS_PERMISSION;
07214
07215 if (status==0) {
07216 if (iVal < accessNeeded) {
07217 status = CAT_NO_ACCESS_PERMISSION;
07218 }
07219 }
07220
07221
07222
07223
07224 if (status==0) {
07225 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 6");
07226 status = cmlGetIntegerValueFromSql(
07227 "select count(*) from ACCESS_VIEW_TWO",
07228 &iVal, 0, 0, 0, 0, 0, &icss);
07229 if (status==0) {
07230 nAccess = iVal;
07231
07232 if (numObjects > nAccess) {
07233 status=CAT_NO_ACCESS_PERMISSION;
07234 }
07235 }
07236 }
07237
07238 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 7");
07239 #if ORA_ICAT
07240 status2 = cmlExecuteNoAnswerSql(
07241 "drop table ACCESS_VIEW_ONE",
07242 &icss);
07243 if (status2==CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
07244 if (status2==0) {
07245 status2 = cmlExecuteNoAnswerSql(
07246 "drop view ACCESS_VIEW_TWO",
07247 &icss);
07248 if (status2==CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
07249 }
07250 #else
07251 status2 = cmlExecuteNoAnswerSql(
07252 "drop view ACCESS_VIEW_TWO, ACCESS_VIEW_ONE",
07253 &icss);
07254 if (status2==CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
07255 #endif
07256
07257 if (status2 != 0) {
07258 rodsLog(LOG_NOTICE,
07259 "chlAddAVUMetadataWild cmlExecuteNoAnswerSql (drop view (or table)) failure %d",
07260 status2);
07261 }
07262
07263 if (status != 0) return(status);
07264
07265
07266
07267
07268 status = findOrInsertAVU(attribute, value, units);
07269 if (status<0) {
07270 rodsLog(LOG_NOTICE,
07271 "chlAddAVUMetadataWild findOrInsertAVU failure %d",
07272 status);
07273 _rollback("chlAddAVUMetadata");
07274 return(status);
07275 }
07276 seqNum = status;
07277
07278 getNowStr(myTime);
07279 snprintf(seqNumStr, sizeof seqNumStr, "%lld", seqNum);
07280 cllBindVars[cllBindVarCount++]=seqNumStr;
07281 cllBindVars[cllBindVarCount++]=myTime;
07282 cllBindVars[cllBindVarCount++]=myTime;
07283 cllBindVars[cllBindVarCount++]=objectName;
07284 cllBindVars[cllBindVarCount++]=collection;
07285 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadataWild SQL 8");
07286 status = cmlExecuteNoAnswerSql(
07287 "insert into R_OBJT_METAMAP (object_id, meta_id, create_ts, modify_ts) select DM.data_id, ?, ?, ? from R_DATA_MAIN DM, R_COLL_MAIN CM where DM.data_name like ? and DM.coll_id=CM.coll_id and CM.coll_name like ? group by DM.data_id",
07288 &icss);
07289 if (status != 0) {
07290 rodsLog(LOG_NOTICE,
07291 "chlAddAVUMetadataWild cmlExecuteNoAnswerSql insert failure %d",
07292 status);
07293 _rollback("chlAddAVUMetadataWild");
07294 return(status);
07295 }
07296
07297
07298 status = cmlAudit3(AU_ADD_AVU_WILD_METADATA,
07299 seqNumStr,
07300 rsComm->clientUser.userName,
07301 rsComm->clientUser.rodsZone,
07302 name,
07303 &icss);
07304 if (status != 0) {
07305 rodsLog(LOG_NOTICE,
07306 "chlAddAVUMetadataWild cmlAudit3 failure %d",
07307 status);
07308 _rollback("chlAddAVUMetadataWild");
07309 return(status);
07310 }
07311
07312
07313
07314 status = cmlExecuteNoAnswerSql("commit", &icss);
07315 if (status != 0) {
07316 rodsLog(LOG_NOTICE,
07317 "chlAddAVUMetadataWild cmlExecuteNoAnswerSql commit failure %d",
07318 status);
07319 return(status);
07320 }
07321
07322 if (status != 0) return(status);
07323 return(numObjects);
07324 }
07325
07326
07327
07328 int chlAddAVUMetadata(rsComm_t *rsComm, int adminMode, char *type,
07329 char *name, char *attribute, char *value, char *units) {
07330 int itype;
07331 char myTime[50];
07332 char logicalEndName[MAX_NAME_LEN];
07333 char logicalParentDirName[MAX_NAME_LEN];
07334 rodsLong_t seqNum, iVal;
07335 rodsLong_t objId, status;
07336 char objIdStr[MAX_NAME_LEN];
07337 char seqNumStr[MAX_NAME_LEN];
07338 char userName[NAME_LEN];
07339 char userZone[NAME_LEN];
07340
07341 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata");
07342
07343 if (!icss.status) {
07344 return(CATALOG_NOT_CONNECTED);
07345 }
07346
07347 if (type == NULL || *type=='\0') {
07348 return (CAT_INVALID_ARGUMENT);
07349 }
07350
07351 if (name == NULL || *name=='\0') {
07352 return (CAT_INVALID_ARGUMENT);
07353 }
07354
07355 if (attribute == NULL || *attribute=='\0') {
07356 return (CAT_INVALID_ARGUMENT);
07357 }
07358
07359 if (value == NULL || *value=='\0') {
07360 return (CAT_INVALID_ARGUMENT);
07361 }
07362
07363 if (adminMode==1) {
07364 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07365 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07366 }
07367 }
07368
07369 if (units == NULL) units="";
07370
07371 itype = convertTypeOption(type);
07372 if (itype==0) return(CAT_INVALID_ARGUMENT);
07373
07374 if (itype==1) {
07375 status = splitPathByKey(name,
07376 logicalParentDirName, logicalEndName, '/');
07377 if (strlen(logicalParentDirName)==0) {
07378 strcpy(logicalParentDirName, "/");
07379 strcpy(logicalEndName, name);
07380 }
07381 if (adminMode==1) {
07382 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 1 ");
07383 status = cmlGetIntegerValueFromSql(
07384 "select data_id from R_DATA_MAIN DM, R_COLL_MAIN CM where DM.data_name=? and DM.coll_id=CM.coll_id and CM.coll_name=?",
07385 &iVal, logicalEndName, logicalParentDirName, 0, 0, 0, &icss);
07386 if (status==0) status=iVal;
07387 }
07388 else {
07389 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 2");
07390 status = cmlCheckDataObjOnly(logicalParentDirName, logicalEndName,
07391 rsComm->clientUser.userName,
07392 rsComm->clientUser.rodsZone,
07393 ACCESS_CREATE_METADATA, &icss);
07394 }
07395 if (status < 0) {
07396 _rollback("chlAddAVUMetadata");
07397 return(status);
07398 }
07399 objId=status;
07400 }
07401
07402 if (itype==2) {
07403 if (adminMode==1) {
07404 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 3");
07405 status = cmlGetIntegerValueFromSql(
07406 "select coll_id from R_COLL_MAIN where coll_name=?",
07407 &iVal, name, 0, 0, 0, 0, &icss);
07408 if (status==0) status=iVal;
07409 }
07410 else {
07411
07412
07413 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 4");
07414 status = cmlCheckDir(name,
07415 rsComm->clientUser.userName,
07416 rsComm->clientUser.rodsZone,
07417 ACCESS_CREATE_METADATA, &icss);
07418 }
07419 if (status < 0) {
07420 char errMsg[105];
07421 _rollback("chlAddAVUMetadata");
07422 if (status == CAT_UNKNOWN_COLLECTION) {
07423 snprintf(errMsg, 100, "collection '%s' is unknown",
07424 name);
07425 addRErrorMsg (&rsComm->rError, 0, errMsg);
07426 } else {
07427 _rollback("chlAddAVUMetadata");
07428 }
07429 return(status);
07430 }
07431 objId=status;
07432 }
07433
07434 if (itype==3) {
07435 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07436 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07437 }
07438
07439 status = getLocalZone();
07440 if (status != 0) return(status);
07441
07442 objId=0;
07443 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 5");
07444 status = cmlGetIntegerValueFromSql(
07445 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
07446 &objId, name, localZone, 0, 0, 0, &icss);
07447 if (status != 0) {
07448 _rollback("chlAddAVUMetadata");
07449 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
07450 return(status);
07451 }
07452 }
07453
07454 if (itype==4) {
07455 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07456 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07457 }
07458
07459 status = parseUserName(name, userName, userZone);
07460 if (userZone[0]=='\0') {
07461 status = getLocalZone();
07462 if (status != 0) return(status);
07463 strncpy(userZone, localZone, NAME_LEN);
07464 }
07465
07466 objId=0;
07467 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 6");
07468 status = cmlGetIntegerValueFromSql(
07469 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
07470 &objId, userName, userZone, 0, 0, 0, &icss);
07471 if (status != 0) {
07472 _rollback("chlAddAVUMetadata");
07473 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
07474 return(status);
07475 }
07476 }
07477
07478 if (itype==5) {
07479 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07480 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07481 }
07482
07483 status = getLocalZone();
07484 if (status != 0) return(status);
07485
07486 objId=0;
07487 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 7");
07488 status = cmlGetIntegerValueFromSql(
07489 "select distinct resc_group_id from R_RESC_GROUP where resc_group_name=?",
07490 &objId, name, 0, 0, 0, 0, &icss);
07491 if (status != 0) {
07492 _rollback("chlAddAVUMetadata");
07493 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
07494 return(status);
07495 }
07496 }
07497
07498 status = findOrInsertAVU(attribute, value, units);
07499 if (status<0) {
07500 rodsLog(LOG_NOTICE,
07501 "chlAddAVUMetadata findOrInsertAVU failure %d",
07502 status);
07503 _rollback("chlAddAVUMetadata");
07504 return(status);
07505 }
07506 seqNum = status;
07507
07508 getNowStr(myTime);
07509 snprintf(objIdStr, sizeof objIdStr, "%lld", objId);
07510 snprintf(seqNumStr, sizeof seqNumStr, "%lld", seqNum);
07511 cllBindVars[cllBindVarCount++]=objIdStr;
07512 cllBindVars[cllBindVarCount++]=seqNumStr;
07513 cllBindVars[cllBindVarCount++]=myTime;
07514 cllBindVars[cllBindVarCount++]=myTime;
07515 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddAVUMetadata SQL 7");
07516 status = cmlExecuteNoAnswerSql(
07517 "insert into R_OBJT_METAMAP (object_id, meta_id, create_ts, modify_ts) values (?, ?, ?, ?)",
07518 &icss);
07519 if (status != 0) {
07520 rodsLog(LOG_NOTICE,
07521 "chlAddAVUMetadata cmlExecuteNoAnswerSql insert failure %d",
07522 status);
07523 _rollback("chlAddAVUMetadata");
07524 return(status);
07525 }
07526
07527
07528 status = cmlAudit3(AU_ADD_AVU_METADATA,
07529 objIdStr,
07530 rsComm->clientUser.userName,
07531 rsComm->clientUser.rodsZone,
07532 type,
07533 &icss);
07534 if (status != 0) {
07535 rodsLog(LOG_NOTICE,
07536 "chlAddAVUMetadata cmlAudit3 failure %d",
07537 status);
07538 _rollback("chlAddAVUMetadata");
07539 return(status);
07540 }
07541
07542 status = cmlExecuteNoAnswerSql("commit", &icss);
07543 if (status != 0) {
07544 rodsLog(LOG_NOTICE,
07545 "chlAddAVUMetadata cmlExecuteNoAnswerSql commit failure %d",
07546 status);
07547 return(status);
07548 }
07549
07550 return(status);
07551 }
07552
07553
07554
07555
07556 int
07557 checkModArgType(char *arg) {
07558 if (arg == NULL || *arg=='\0')
07559 return(CAT_INVALID_ARGUMENT);
07560 if (*(arg+1)!=':') return(0);
07561 if (*arg=='n') return(1);
07562 if (*arg=='v') return(2);
07563 if (*arg=='u') return(3);
07564 return(0);
07565 }
07566
07567
07568 int chlModAVUMetadata(rsComm_t *rsComm, char *type,
07569 char *name, char *attribute, char *value,
07570 char *unitsOrArg0, char *arg1, char *arg2, char *arg3) {
07571 int status, atype;
07572 char myUnits[MAX_NAME_LEN]="";
07573 char *addAttr="", *addValue="", *addUnits="";
07574 int newUnits=0;
07575 if (unitsOrArg0 == NULL || *unitsOrArg0=='\0')
07576 return(CAT_INVALID_ARGUMENT);
07577 atype = checkModArgType(unitsOrArg0);
07578 if (atype==0) strncpy(myUnits, unitsOrArg0, MAX_NAME_LEN);
07579
07580 status = chlDeleteAVUMetadata(rsComm, 0, type, name, attribute, value,
07581 myUnits, 1);
07582 if (status != 0) {
07583 _rollback("chlModAVUMetadata");
07584 return(status);
07585 }
07586
07587 if (atype==1) {
07588 addAttr=unitsOrArg0+2;
07589 }
07590 if (atype==2) {
07591 addValue=unitsOrArg0+2;
07592 }
07593 if (atype==3) {
07594 addUnits=unitsOrArg0+2;
07595 }
07596
07597 atype = checkModArgType(arg1);
07598 if (atype==1) {
07599 addAttr=arg1+2;
07600 }
07601 if (atype==2) {
07602 addValue=arg1+2;
07603 }
07604 if (atype==3) {
07605 addUnits=arg1+2;
07606 }
07607
07608 atype = checkModArgType(arg2);
07609 if (atype==1) {
07610 addAttr=arg2+2;
07611 }
07612 if (atype==2) {
07613 addValue=arg2+2;
07614 }
07615 if (atype==3) {
07616 addUnits=arg2+2;
07617 }
07618
07619 atype = checkModArgType(arg3);
07620 if (atype==1) {
07621 addAttr=arg3+2;
07622 }
07623 if (atype==2) {
07624 addValue=arg3+2;
07625 }
07626 if (atype==3) {
07627 addUnits=arg3+2;
07628 newUnits=1;
07629 }
07630
07631 if (*addAttr=='\0' &&
07632 *addValue=='\0' &&
07633 *addUnits=='\0') {
07634 _rollback("chlModAVUMetadata");
07635 return (CAT_INVALID_ARGUMENT);
07636 }
07637
07638 if (*addAttr=='\0') addAttr=attribute;
07639 if (*addValue=='\0') addValue=value;
07640 if (*addUnits=='\0' && newUnits==0) addUnits=myUnits;
07641
07642 status = chlAddAVUMetadata(rsComm, 0, type, name, addAttr, addValue,
07643 addUnits);
07644 return(status);
07645
07646 }
07647
07648
07649
07650
07651 int chlDeleteAVUMetadata(rsComm_t *rsComm, int option, char *type,
07652 char *name, char *attribute, char *value,
07653 char *units, int noCommit ) {
07654 int itype;
07655 char logicalEndName[MAX_NAME_LEN];
07656 char logicalParentDirName[MAX_NAME_LEN];
07657 rodsLong_t status;
07658 rodsLong_t objId;
07659 char objIdStr[MAX_NAME_LEN];
07660 int allowNullUnits;
07661 char userName[NAME_LEN];
07662 char userZone[NAME_LEN];
07663
07664 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata");
07665
07666 if (!icss.status) {
07667 return(CATALOG_NOT_CONNECTED);
07668 }
07669
07670 if (type == NULL || *type=='\0') {
07671 return (CAT_INVALID_ARGUMENT);
07672 }
07673
07674 if (name == NULL || *name=='\0') {
07675 return (CAT_INVALID_ARGUMENT);
07676 }
07677
07678 if (option != 2) {
07679 if (attribute == NULL || *attribute=='\0') {
07680 return (CAT_INVALID_ARGUMENT);
07681 }
07682
07683 if (value == NULL || *value=='\0') {
07684 return (CAT_INVALID_ARGUMENT);
07685 }
07686 }
07687
07688 if (units == NULL) units="";
07689
07690 itype = convertTypeOption(type);
07691 if (itype==0) return(CAT_INVALID_ARGUMENT);
07692
07693 if (itype==1) {
07694 status = splitPathByKey(name,
07695 logicalParentDirName, logicalEndName, '/');
07696 if (strlen(logicalParentDirName)==0) {
07697 strcpy(logicalParentDirName, "/");
07698 strcpy(logicalEndName, name);
07699 }
07700 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 1 ");
07701 status = cmlCheckDataObjOnly(logicalParentDirName, logicalEndName,
07702 rsComm->clientUser.userName,
07703 rsComm->clientUser.rodsZone,
07704 ACCESS_DELETE_METADATA, &icss);
07705 if (status < 0) {
07706 _rollback("chlDeleteAVUMetadata");
07707 return(status);
07708 }
07709 objId=status;
07710 }
07711
07712 if (itype==2) {
07713
07714
07715 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 2");
07716 status = cmlCheckDir(name,
07717 rsComm->clientUser.userName,
07718 rsComm->clientUser.rodsZone,
07719 ACCESS_DELETE_METADATA, &icss);
07720 if (status < 0) {
07721 char errMsg[105];
07722 if (status == CAT_UNKNOWN_COLLECTION) {
07723 snprintf(errMsg, 100, "collection '%s' is unknown",
07724 name);
07725 addRErrorMsg (&rsComm->rError, 0, errMsg);
07726 }
07727 return(status);
07728 }
07729 objId=status;
07730 }
07731
07732 if (itype==3) {
07733 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07734 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07735 }
07736
07737 status = getLocalZone();
07738 if (status != 0) return(status);
07739
07740 objId=0;
07741 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 3");
07742 status = cmlGetIntegerValueFromSql(
07743 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
07744 &objId, name, localZone, 0, 0, 0, &icss);
07745 if (status != 0) {
07746 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
07747 _rollback("chlDeleteAVUMetadata");
07748 return(status);
07749 }
07750 }
07751
07752 if (itype==4) {
07753 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07754 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07755 }
07756
07757 status = parseUserName(name, userName, userZone);
07758 if (userZone[0]=='\0') {
07759 status = getLocalZone();
07760 if (status != 0) return(status);
07761 strncpy(userZone, localZone, NAME_LEN);
07762 }
07763
07764 objId=0;
07765 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 4");
07766 status = cmlGetIntegerValueFromSql(
07767 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
07768 &objId, userName, userZone, 0, 0, 0, &icss);
07769 if (status != 0) {
07770 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
07771 _rollback("chlDeleteAVUMetadata");
07772 return(status);
07773 }
07774 }
07775
07776 if (itype==5) {
07777 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
07778 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
07779 }
07780
07781 status = getLocalZone();
07782 if (status != 0) return(status);
07783
07784 objId=0;
07785 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 5");
07786 status = cmlGetIntegerValueFromSql(
07787 "select resc_group_id from R_RESC_GROUP where resc_group_name=?",
07788 &objId, name, 0, 0, 0, 0, &icss);
07789 if (status != 0) {
07790 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
07791 _rollback("chlDeleteAVUMetadata");
07792 return(status);
07793 }
07794 }
07795
07796
07797 snprintf(objIdStr, MAX_NAME_LEN, "%lld", objId);
07798
07799 if (option==2) {
07800 cllBindVars[cllBindVarCount++]=objIdStr;
07801 cllBindVars[cllBindVarCount++]=attribute;
07802
07803 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 9");
07804 status = cmlExecuteNoAnswerSql(
07805 "delete from R_OBJT_METAMAP where object_id=? and meta_id =?",
07806 &icss);
07807 if (status != 0) {
07808 rodsLog(LOG_NOTICE,
07809 "chlDeleteAVUMetadata cmlExecuteNoAnswerSql delete failure %d",
07810 status);
07811 _rollback("chlDeleteAVUMetadata");
07812 return(status);
07813 }
07814
07815
07816 #ifdef METADATA_CLEANUP
07817 removeAVUs();
07818 #endif
07819
07820
07821 status = cmlAudit3(AU_DELETE_AVU_METADATA,
07822 objIdStr,
07823 rsComm->clientUser.userName,
07824 rsComm->clientUser.rodsZone,
07825 type,
07826 &icss);
07827 if (status != 0) {
07828 rodsLog(LOG_NOTICE,
07829 "chlDeleteAVUMetadata cmlAudit3 failure %d",
07830 status);
07831 _rollback("chlDeleteAVUMetadata");
07832 return(status);
07833 }
07834
07835 if (noCommit != 1) {
07836 status = cmlExecuteNoAnswerSql("commit", &icss);
07837 if (status != 0) {
07838 rodsLog(LOG_NOTICE,
07839 "chlDeleteAVUMetadata cmlExecuteNoAnswerSql commit failure %d",
07840 status);
07841 return(status);
07842 }
07843 }
07844 return(status);
07845 }
07846
07847 cllBindVars[cllBindVarCount++]=objIdStr;
07848 cllBindVars[cllBindVarCount++]=attribute;
07849 cllBindVars[cllBindVarCount++]=value;
07850 cllBindVars[cllBindVarCount++]=units;
07851
07852 allowNullUnits=0;
07853 if (*units=='\0') {
07854 allowNullUnits=1;
07855 }
07856 if (option==1 && *units=='%' && *(units+1)=='\0') {
07857 allowNullUnits=1;
07858 }
07859
07860 if (allowNullUnits) {
07861 if (option==1) {
07862 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 5");
07863 status = cmlExecuteNoAnswerSql(
07864 "delete from R_OBJT_METAMAP where object_id=? and meta_id IN (select meta_id from R_META_MAIN where meta_attr_name like ? and meta_attr_value like ? and (meta_attr_unit like ? or meta_attr_unit IS NULL) )",
07865 &icss);
07866 }
07867 else {
07868 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 6");
07869 status = cmlExecuteNoAnswerSql(
07870 "delete from R_OBJT_METAMAP where object_id=? and meta_id IN (select meta_id from R_META_MAIN where meta_attr_name = ? and meta_attr_value = ? and (meta_attr_unit = ? or meta_attr_unit IS NULL) )",
07871 &icss);
07872 }
07873 }
07874 else {
07875 if (option==1) {
07876 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 7");
07877 status = cmlExecuteNoAnswerSql(
07878 "delete from R_OBJT_METAMAP where object_id=? and meta_id IN (select meta_id from R_META_MAIN where meta_attr_name like ? and meta_attr_value like ? and meta_attr_unit like ?)",
07879 &icss);
07880 }
07881 else {
07882 if (logSQL!=0) rodsLog(LOG_SQL, "chlDeleteAVUMetadata SQL 8");
07883 status = cmlExecuteNoAnswerSql(
07884 "delete from R_OBJT_METAMAP where object_id=? and meta_id IN (select meta_id from R_META_MAIN where meta_attr_name = ? and meta_attr_value = ? and meta_attr_unit = ?)",
07885 &icss);
07886 }
07887 }
07888 if (status != 0) {
07889 rodsLog(LOG_NOTICE,
07890 "chlDeleteAVUMetadata cmlExecuteNoAnswerSql delete failure %d",
07891 status);
07892 _rollback("chlDeleteAVUMetadata");
07893 return(status);
07894 }
07895
07896
07897 #ifdef METADATA_CLEANUP
07898 removeAVUs();
07899 #endif
07900
07901
07902 status = cmlAudit3(AU_DELETE_AVU_METADATA,
07903 objIdStr,
07904 rsComm->clientUser.userName,
07905 rsComm->clientUser.rodsZone,
07906 type,
07907 &icss);
07908 if (status != 0) {
07909 rodsLog(LOG_NOTICE,
07910 "chlDeleteAVUMetadata cmlAudit3 failure %d",
07911 status);
07912 _rollback("chlDeleteAVUMetadata");
07913 return(status);
07914 }
07915
07916 if (noCommit != 1) {
07917 status = cmlExecuteNoAnswerSql("commit", &icss);
07918 if (status != 0) {
07919 rodsLog(LOG_NOTICE,
07920 "chlDeleteAVUMetadata cmlExecuteNoAnswerSql commit failure %d",
07921 status);
07922 return(status);
07923 }
07924 }
07925
07926 return(status);
07927 }
07928
07929
07930
07931 int chlCopyAVUMetadata(rsComm_t *rsComm, char *type1, char *type2,
07932 char *name1, char *name2) {
07933 char myTime[50];
07934 int status;
07935 rodsLong_t objId1, objId2;
07936 char objIdStr1[MAX_NAME_LEN];
07937 char objIdStr2[MAX_NAME_LEN];
07938
07939 if (logSQL!=0) rodsLog(LOG_SQL, "chlCopyAVUMetadata");
07940
07941 if (!icss.status) {
07942 return(CATALOG_NOT_CONNECTED);
07943 }
07944
07945 if (logSQL!=0) rodsLog(LOG_SQL, "chlCopyAVUMetadata SQL 1 ");
07946 objId1 = checkAndGetObjectId(rsComm, type1, name1, ACCESS_READ_METADATA);
07947 if (objId1 < 0) return(objId1);
07948
07949 if (logSQL!=0) rodsLog(LOG_SQL, "chlCopyAVUMetadata SQL 2");
07950 objId2 = checkAndGetObjectId(rsComm, type2, name2, ACCESS_CREATE_METADATA);
07951
07952 if (objId2 < 0) return(objId2);
07953
07954 snprintf(objIdStr1, MAX_NAME_LEN, "%lld", objId1);
07955 snprintf(objIdStr2, MAX_NAME_LEN, "%lld", objId2);
07956
07957 getNowStr(myTime);
07958 cllBindVars[cllBindVarCount++]=objIdStr2;
07959 cllBindVars[cllBindVarCount++]=myTime;
07960 cllBindVars[cllBindVarCount++]=myTime;
07961 cllBindVars[cllBindVarCount++]=objIdStr1;
07962 if (logSQL!=0) rodsLog(LOG_SQL, "chlCopyAVUMetadata SQL 3");
07963 status = cmlExecuteNoAnswerSql(
07964 "insert into R_OBJT_METAMAP (object_id, meta_id, create_ts, modify_ts) select ?, meta_id, ?, ? from R_OBJT_METAMAP where object_id=?",
07965 &icss);
07966 if (status != 0) {
07967 rodsLog(LOG_NOTICE,
07968 "chlCopyAVUMetadata cmlExecuteNoAnswerSql insert failure %d",
07969 status);
07970 _rollback("chlCopyAVUMetadata");
07971 return(status);
07972 }
07973
07974
07975 status = cmlAudit3(AU_COPY_AVU_METADATA,
07976 objIdStr1,
07977 rsComm->clientUser.userName,
07978 rsComm->clientUser.rodsZone,
07979 objIdStr2,
07980 &icss);
07981 if (status != 0) {
07982 rodsLog(LOG_NOTICE,
07983 "chlCopyAVUMetadata cmlAudit3 failure %d",
07984 status);
07985 _rollback("chlCopyAVUMetadata");
07986 return(status);
07987 }
07988
07989 status = cmlExecuteNoAnswerSql("commit", &icss);
07990 if (status != 0) {
07991 rodsLog(LOG_NOTICE,
07992 "chlCopyAVUMetadata cmlExecuteNoAnswerSql commit failure %d",
07993 status);
07994 return(status);
07995 }
07996
07997 return(status);
07998 }
07999
08000
08001 void
08002 makeEscapedPath(char *inPath, char *outPath, int size) {
08003 int i;
08004 for (i=0;i<size-1;i++) {
08005 if (*inPath=='%' || *inPath=='_') {
08006 *outPath++='\\';
08007 }
08008 if (*inPath=='\0') {
08009 *outPath++=*inPath++;
08010 break;
08011 }
08012 *outPath++=*inPath++;
08013 }
08014 return;
08015 }
08016
08017
08018
08019 int _modInheritance(int inheritFlag, int recursiveFlag, char *collIdStr, char *pathName) {
08020 rodsLong_t status;
08021 char myTime[50];
08022 char newValue[10];
08023 char pathStart[MAX_NAME_LEN*2];
08024 char auditStr[30];
08025
08026 if (recursiveFlag==0) {
08027 strcpy(auditStr, "inheritance non-recursive ");
08028 }
08029 else {
08030 strcpy(auditStr, "inheritance recursive ");
08031 }
08032
08033 if (inheritFlag==1) {
08034 newValue[0]='1';
08035 newValue[1]='\0';
08036 }
08037 else {
08038 newValue[0]='0';
08039 newValue[1]='\0';
08040 }
08041 strcat(auditStr, newValue);
08042
08043 getNowStr(myTime);
08044
08045
08046 if (recursiveFlag==0) {
08047
08048 if (logSQL!=0) rodsLog(LOG_SQL, "_modInheritance SQL 1");
08049
08050 cllBindVars[cllBindVarCount++]=newValue;
08051 cllBindVars[cllBindVarCount++]=myTime;
08052 cllBindVars[cllBindVarCount++]=collIdStr;
08053 status = cmlExecuteNoAnswerSql(
08054 "update R_COLL_MAIN set coll_inheritance=?, modify_ts=? where coll_id=?",
08055 &icss);
08056 }
08057 else {
08058
08059 makeEscapedPath(pathName, pathStart, sizeof(pathStart));
08060 strncat(pathStart, "/%", sizeof(pathStart));
08061
08062 cllBindVars[cllBindVarCount++]=newValue;
08063 cllBindVars[cllBindVarCount++]=myTime;
08064 cllBindVars[cllBindVarCount++]=pathName;
08065 cllBindVars[cllBindVarCount++]=pathStart;
08066 if (logSQL!=0) rodsLog(LOG_SQL, "_modInheritance SQL 2");
08067 status = cmlExecuteNoAnswerSql(
08068 "update R_COLL_MAIN set coll_inheritance=?, modify_ts=? where coll_name = ? or coll_name like ?",
08069 &icss);
08070 }
08071 if (status != 0) {
08072 _rollback("_modInheritance");
08073 return(status);
08074 }
08075
08076
08077 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_COLL,
08078 collIdStr,
08079 "0",
08080 auditStr,
08081 &icss);
08082 if (status != 0) {
08083 rodsLog(LOG_NOTICE,
08084 "_modInheritance cmlAudit5 failure %d",
08085 status);
08086 _rollback("_modInheritance");
08087 return(status);
08088 }
08089
08090 status = cmlExecuteNoAnswerSql("commit", &icss);
08091 return(status);
08092 }
08093
08094 int chlModAccessControlResc(rsComm_t *rsComm, int recursiveFlag,
08095 char* accessLevel, char *userName, char *zone,
08096 char* rescName) {
08097 char myAccessStr[LONG_NAME_LEN];
08098 char rescIdStr[MAX_NAME_LEN];
08099 char *myAccessLev=NULL;
08100 int rmFlag=0;
08101 rodsLong_t status;
08102 char *myZone;
08103 rodsLong_t userId;
08104 char userIdStr[MAX_NAME_LEN];
08105 char myTime[50];
08106 rodsLong_t iVal;
08107 int debug=0;
08108
08109 strncpy(myAccessStr,accessLevel+strlen(MOD_RESC_PREFIX),LONG_NAME_LEN);
08110 myAccessStr[ LONG_NAME_LEN-1 ]='\0';
08111 if (debug>0) {
08112 printf("accessLevel: %s\n", accessLevel);
08113 printf("rescName: %s\n", rescName);
08114 }
08115
08116 if (strcmp(myAccessStr, AP_NULL)==0) {myAccessLev=ACCESS_NULL; rmFlag=1;}
08117 else if (strcmp(myAccessStr,AP_READ)==0) {myAccessLev=ACCESS_READ_OBJECT;}
08118 else if (strcmp(myAccessStr,AP_WRITE)==0){myAccessLev=ACCESS_MODIFY_OBJECT;}
08119 else if (strcmp(myAccessStr,AP_OWN)==0) {myAccessLev=ACCESS_OWN;}
08120 else {
08121 char errMsg[105];
08122 snprintf(errMsg, 100, "access level '%s' is invalid for a resource",
08123 myAccessStr);
08124 addRErrorMsg (&rsComm->rError, 0, errMsg);
08125 return(CAT_INVALID_ARGUMENT);
08126 }
08127
08128 if (rsComm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
08129
08130 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControlResc SQL 1");
08131 status = cmlGetIntegerValueFromSql(
08132 "select resc_id from R_RESC_MAIN where resc_name=?",
08133 &iVal, rescName, 0, 0, 0, 0, &icss);
08134 if (status==CAT_NO_ROWS_FOUND) return(CAT_UNKNOWN_RESOURCE);
08135 if (status<0) return(status);
08136 status = iVal;
08137 }
08138 else {
08139 status = cmlCheckResc(rescName,
08140 rsComm->clientUser.userName,
08141 rsComm->clientUser.rodsZone,
08142 ACCESS_OWN,
08143 &icss);
08144 if (status<0) return(status);
08145 }
08146 snprintf(rescIdStr, MAX_NAME_LEN, "%lld", status);
08147
08148
08149 status = getLocalZone();
08150 if (status != 0) return(status);
08151
08152 myZone=zone;
08153 if (zone == NULL || strlen(zone)==0) {
08154 myZone=localZone;
08155 }
08156
08157 userId=0;
08158 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControlResc SQL 2");
08159 status = cmlGetIntegerValueFromSql(
08160 "select user_id from R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=?",
08161 &userId, userName, myZone, 0, 0, 0, &icss);
08162 if (status != 0) {
08163 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
08164 return(status);
08165 }
08166
08167 snprintf(userIdStr, MAX_NAME_LEN, "%lld", userId);
08168
08169
08170 cllBindVars[cllBindVarCount++]=userIdStr;
08171 cllBindVars[cllBindVarCount++]=rescIdStr;
08172 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControlResc SQL 3");
08173 status = cmlExecuteNoAnswerSql(
08174 "delete from R_OBJT_ACCESS where user_id=? and object_id=?",
08175 &icss);
08176 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08177 return(status);
08178 }
08179
08180
08181 if (rmFlag==0) {
08182 getNowStr(myTime);
08183 cllBindVars[cllBindVarCount++]=rescIdStr;
08184 cllBindVars[cllBindVarCount++]=userIdStr;
08185 cllBindVars[cllBindVarCount++]=myAccessLev;
08186 cllBindVars[cllBindVarCount++]=myTime;
08187 cllBindVars[cllBindVarCount++]=myTime;
08188 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControlResc SQL 4");
08189 status = cmlExecuteNoAnswerSql(
08190 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) values (?, ?, (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
08191 &icss);
08192 if (status != 0) {
08193 _rollback("chlModAccessControlResc");
08194 return(status);
08195 }
08196 }
08197
08198
08199 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_RESOURCE,
08200 rescIdStr,
08201 userIdStr,
08202 myAccessLev,
08203 &icss);
08204 if (status != 0) {
08205 rodsLog(LOG_NOTICE,
08206 "chlModAccessControlResc cmlAudit5 failure %d",
08207 status);
08208 _rollback("chlModAccessControlResc");
08209 return(status);
08210 }
08211
08212 status = cmlExecuteNoAnswerSql("commit", &icss);
08213 return(status);
08214 }
08215
08216
08217
08218
08219
08220
08221 int chlModAccessControl(rsComm_t *rsComm, int recursiveFlag,
08222 char* accessLevel, char *userName, char *zone,
08223 char* pathName) {
08224 char *myAccessLev=NULL;
08225 char logicalEndName[MAX_NAME_LEN];
08226 char logicalParentDirName[MAX_NAME_LEN];
08227 char collIdStr[MAX_NAME_LEN];
08228 rodsLong_t objId=0;
08229 rodsLong_t status, status1, status2, status3;
08230 int rmFlag=0;
08231 rodsLong_t userId;
08232 char myTime[50];
08233 char *myZone;
08234 char userIdStr[MAX_NAME_LEN];
08235 char objIdStr[MAX_NAME_LEN];
08236 char pathStart[MAX_NAME_LEN*2];
08237 int inheritFlag=0;
08238 char myAccessStr[LONG_NAME_LEN];
08239 int adminMode=0;
08240 rodsLong_t iVal;
08241
08242 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl");
08243
08244 if (strncmp(accessLevel, MOD_RESC_PREFIX, strlen(MOD_RESC_PREFIX))==0) {
08245 return(chlModAccessControlResc(rsComm, recursiveFlag,
08246 accessLevel, userName, zone, pathName));
08247 }
08248
08249 adminMode=0;
08250 if (strncmp(accessLevel, MOD_ADMIN_MODE_PREFIX,
08251 strlen(MOD_ADMIN_MODE_PREFIX))==0) {
08252 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
08253 addRErrorMsg (&rsComm->rError, 0,
08254 "You must be the admin to use the -M admin mode");
08255 return(CAT_NO_ACCESS_PERMISSION);
08256 }
08257 strncpy(myAccessStr,accessLevel+strlen(MOD_ADMIN_MODE_PREFIX),
08258 LONG_NAME_LEN);
08259 accessLevel = myAccessStr;
08260 adminMode=1;
08261 }
08262
08263 if (strcmp(accessLevel, AP_NULL)==0) {myAccessLev=ACCESS_NULL; rmFlag=1;}
08264 else if (strcmp(accessLevel,AP_READ)==0) {myAccessLev=ACCESS_READ_OBJECT;}
08265 else if (strcmp(accessLevel,AP_WRITE)==0){myAccessLev=ACCESS_MODIFY_OBJECT;}
08266 else if (strcmp(accessLevel,AP_OWN)==0) {myAccessLev=ACCESS_OWN;}
08267 else if (strcmp(accessLevel,ACCESS_INHERIT)==0) {
08268 inheritFlag=1;
08269 }
08270 else if (strcmp(accessLevel,ACCESS_NO_INHERIT)==0) {
08271 inheritFlag=2;
08272 }
08273 else {
08274 char errMsg[105];
08275 snprintf(errMsg, 100, "access level '%s' is invalid",
08276 accessLevel);
08277 addRErrorMsg (&rsComm->rError, 0, errMsg);
08278 return(CAT_INVALID_ARGUMENT);
08279 }
08280
08281 if (!icss.status) {
08282 return(CATALOG_NOT_CONNECTED);
08283 }
08284
08285 if (adminMode) {
08286
08287
08288 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 14");
08289 status1 = cmlGetIntegerValueFromSql(
08290 "select coll_id from R_COLL_MAIN where coll_name=?",
08291 &iVal, pathName, 0, 0, 0, 0, &icss);
08292 if (status1==CAT_NO_ROWS_FOUND) {
08293 status1=CAT_UNKNOWN_COLLECTION;
08294 }
08295 if (status1==0) status1=iVal;
08296 }
08297 else {
08298
08299
08300 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 1 ");
08301 status1 = cmlCheckDir(pathName,
08302 rsComm->clientUser.userName,
08303 rsComm->clientUser.rodsZone,
08304 ACCESS_OWN,
08305 &icss);
08306 }
08307 if (status1 >= 0) {
08308 snprintf(collIdStr, MAX_NAME_LEN, "%lld", status1);
08309 }
08310
08311 if (status1 < 0 && inheritFlag!=0) {
08312 char errMsg[105];
08313 snprintf(errMsg, 100, "access level '%s' is valid only for collections",
08314 accessLevel);
08315 addRErrorMsg (&rsComm->rError, 0, errMsg);
08316 return(CAT_INVALID_ARGUMENT);
08317 }
08318
08319
08320 if (status1 < 0) {
08321 status2 = splitPathByKey(pathName,
08322 logicalParentDirName, logicalEndName, '/');
08323 if (strlen(logicalParentDirName)==0) {
08324 strcpy(logicalParentDirName, "/");
08325 strcpy(logicalEndName, pathName+1);
08326 }
08327 if (adminMode) {
08328 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 15");
08329 status2 = cmlGetIntegerValueFromSql(
08330 "select data_id from R_DATA_MAIN DM, R_COLL_MAIN CM where DM.data_name=? and DM.coll_id=CM.coll_id and CM.coll_name=?",
08331 &iVal, logicalEndName, logicalParentDirName, 0, 0, 0, &icss);
08332 if (status2==CAT_NO_ROWS_FOUND) status2=CAT_UNKNOWN_FILE;
08333 if (status2==0) status2=iVal;
08334 }
08335 else {
08336
08337
08338 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 2");
08339 status2 = cmlCheckDataObjOnly(logicalParentDirName, logicalEndName,
08340 rsComm->clientUser.userName,
08341 rsComm->clientUser.rodsZone,
08342 ACCESS_OWN, &icss);
08343 }
08344 if (status2 > 0) objId=status2;
08345 }
08346
08347
08348 if (status1 < 0 && status2 < 0) {
08349 char errMsg[205];
08350
08351 if (status1 == CAT_UNKNOWN_COLLECTION && status2 == CAT_UNKNOWN_FILE) {
08352 snprintf(errMsg, 200,
08353 "Input path is not a collection and not a dataObj: %s",
08354 pathName);
08355 addRErrorMsg (&rsComm->rError, 0, errMsg);
08356 return(CAT_INVALID_ARGUMENT);
08357 }
08358 if (status1 != CAT_UNKNOWN_COLLECTION) {
08359 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 12");
08360 status3 = cmlCheckDirOwn(pathName,
08361 rsComm->clientUser.userName,
08362 rsComm->clientUser.rodsZone,
08363 &icss);
08364 if (status3 < 0) return(status1);
08365 snprintf(collIdStr, MAX_NAME_LEN, "%lld", status3);
08366 }
08367 else {
08368 if (status2 == CAT_NO_ACCESS_PERMISSION) {
08369
08370
08371 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 13");
08372 status3 = cmlCheckDataObjOwn(logicalParentDirName, logicalEndName,
08373 rsComm->clientUser.userName,
08374 rsComm->clientUser.rodsZone,
08375 &icss);
08376 if (status3 < 0) {
08377 _rollback("chlModAccessControl");
08378 return(status2);
08379 }
08380 objId = status3;
08381 } else {
08382 return(status2);
08383 }
08384 }
08385 }
08386
08387
08388 if (inheritFlag!=0) {
08389 status = _modInheritance(inheritFlag, recursiveFlag, collIdStr, pathName);
08390 return(status);
08391 }
08392
08393
08394 status = getLocalZone();
08395 if (status != 0) return(status);
08396
08397 myZone=zone;
08398 if (zone == NULL || strlen(zone)==0) {
08399 myZone=localZone;
08400 }
08401
08402 userId=0;
08403 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 3");
08404 status = cmlGetIntegerValueFromSql(
08405 "select user_id from R_USER_MAIN where user_name=? and R_USER_MAIN.zone_name=?",
08406 &userId, userName, myZone, 0, 0, 0, &icss);
08407 if (status != 0) {
08408 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
08409 return(status);
08410 }
08411
08412 snprintf(userIdStr, MAX_NAME_LEN, "%lld", userId);
08413 snprintf(objIdStr, MAX_NAME_LEN, "%lld", objId);
08414
08415 rodsLog(LOG_NOTICE, "recursiveFlag %d",recursiveFlag);
08416
08417
08418 if (recursiveFlag==0) {
08419
08420
08421 if (objId) {
08422 cllBindVars[cllBindVarCount++]=userIdStr;
08423 cllBindVars[cllBindVarCount++]=objIdStr;
08424 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 4");
08425 status = cmlExecuteNoAnswerSql(
08426 "delete from R_OBJT_ACCESS where user_id=? and object_id=?",
08427 &icss);
08428 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08429 return(status);
08430 }
08431 if (rmFlag==0) {
08432 getNowStr(myTime);
08433 cllBindVars[cllBindVarCount++]=objIdStr;
08434 cllBindVars[cllBindVarCount++]=userIdStr;
08435 cllBindVars[cllBindVarCount++]=myAccessLev;
08436 cllBindVars[cllBindVarCount++]=myTime;
08437 cllBindVars[cllBindVarCount++]=myTime;
08438 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 5");
08439 status = cmlExecuteNoAnswerSql(
08440 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) values (?, ?, (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
08441 &icss);
08442 if (status != 0) {
08443 _rollback("chlModAccessControl");
08444 return(status);
08445 }
08446 }
08447
08448
08449 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_OBJ,
08450 objIdStr,
08451 userIdStr,
08452 myAccessLev,
08453 &icss);
08454 if (status != 0) {
08455 rodsLog(LOG_NOTICE,
08456 "chlModAccessControl cmlAudit5 failure %d",
08457 status);
08458 _rollback("chlModAccessControl");
08459 return(status);
08460 }
08461
08462 status = cmlExecuteNoAnswerSql("commit", &icss);
08463 return(status);
08464 }
08465
08466
08467 cllBindVars[cllBindVarCount++]=userIdStr;
08468 cllBindVars[cllBindVarCount++]=collIdStr;
08469 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 6");
08470 status = cmlExecuteNoAnswerSql(
08471 "delete from R_OBJT_ACCESS where user_id=? and object_id=?",
08472 &icss);
08473 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08474 _rollback("chlModAccessControl");
08475 return(status);
08476 }
08477 if (rmFlag) {
08478
08479 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_COLL,
08480 collIdStr,
08481 userIdStr,
08482 myAccessLev,
08483 &icss);
08484 if (status != 0) {
08485 rodsLog(LOG_NOTICE,
08486 "chlModAccessControl cmlAudit5 failure %d",
08487 status);
08488 _rollback("chlModAccessControl");
08489 return(status);
08490 }
08491 status = cmlExecuteNoAnswerSql("commit", &icss);
08492 return(status);
08493 }
08494
08495 getNowStr(myTime);
08496 cllBindVars[cllBindVarCount++]=collIdStr;
08497 cllBindVars[cllBindVarCount++]=userIdStr;
08498 cllBindVars[cllBindVarCount++]=myAccessLev;
08499 cllBindVars[cllBindVarCount++]=myTime;
08500 cllBindVars[cllBindVarCount++]=myTime;
08501 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 7");
08502 status = cmlExecuteNoAnswerSql(
08503 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) values (?, ?, (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ?)",
08504 &icss);
08505
08506 if (status != 0) {
08507 _rollback("chlModAccessControl");
08508 return(status);
08509 }
08510
08511 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_COLL,
08512 collIdStr,
08513 userIdStr,
08514 myAccessLev,
08515 &icss);
08516 if (status != 0) {
08517 rodsLog(LOG_NOTICE,
08518 "chlModAccessControl cmlAudit5 failure %d",
08519 status);
08520 _rollback("chlModAccessControl");
08521 return(status);
08522 }
08523
08524 status = cmlExecuteNoAnswerSql("commit", &icss);
08525 return(status);
08526 }
08527
08528
08529
08530 if (objId) {
08531 char errMsg[205];
08532
08533 snprintf(errMsg, 200,
08534 "Input path is not a collection and recursion was requested: %s",
08535 pathName);
08536 addRErrorMsg (&rsComm->rError, 0, errMsg);
08537 return(CAT_INVALID_ARGUMENT);
08538 }
08539
08540
08541 makeEscapedPath(pathName, pathStart, sizeof(pathStart));
08542 strncat(pathStart, "/%", sizeof(pathStart));
08543
08544 cllBindVars[cllBindVarCount++]=userIdStr;
08545 cllBindVars[cllBindVarCount++]=pathName;
08546 cllBindVars[cllBindVarCount++]=pathStart;
08547
08548 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 8");
08549 status = cmlExecuteNoAnswerSql(
08550 "delete from R_OBJT_ACCESS where user_id=? and object_id in (select data_id from R_DATA_MAIN where coll_id in (select coll_id from R_COLL_MAIN where coll_name = ? or coll_name like ?))",
08551 &icss);
08552
08553 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08554 _rollback("chlModAccessControl");
08555 return(status);
08556 }
08557
08558 cllBindVars[cllBindVarCount++]=userIdStr;
08559 cllBindVars[cllBindVarCount++]=pathName;
08560 cllBindVars[cllBindVarCount++]=pathStart;
08561
08562 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 9");
08563 status = cmlExecuteNoAnswerSql(
08564 "delete from R_OBJT_ACCESS where user_id=? and object_id in (select coll_id from R_COLL_MAIN where coll_name = ? or coll_name like ?)",
08565 &icss);
08566 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08567 _rollback("chlModAccessControl");
08568 return(status);
08569 }
08570 if (rmFlag) {
08571
08572
08573 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_COLL_RECURSIVE,
08574 collIdStr,
08575 userIdStr,
08576 myAccessLev,
08577 &icss);
08578 if (status != 0) {
08579 rodsLog(LOG_NOTICE,
08580 "chlModAccessControl cmlAudit5 failure %d",
08581 status);
08582 _rollback("chlModAccessControl");
08583 return(status);
08584 }
08585
08586 status = cmlExecuteNoAnswerSql("commit", &icss);
08587 return(status);
08588 }
08589
08590 getNowStr(myTime);
08591 makeEscapedPath(pathName, pathStart, sizeof(pathStart));
08592 strncat(pathStart, "/%", sizeof(pathStart));
08593 cllBindVars[cllBindVarCount++]=userIdStr;
08594 cllBindVars[cllBindVarCount++]=myAccessLev;
08595 cllBindVars[cllBindVarCount++]=myTime;
08596 cllBindVars[cllBindVarCount++]=myTime;
08597 cllBindVars[cllBindVarCount++]=pathName;
08598 cllBindVars[cllBindVarCount++]=pathStart;
08599 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 10");
08600 #if ORA_ICAT
08601
08602 status = cmlExecuteNoAnswerSql(
08603 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct data_id, cast(? as integer), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_DATA_MAIN where coll_id in (select coll_id from R_COLL_MAIN where coll_name = ? or coll_name like ?))",
08604 &icss);
08605 #elif MY_ICAT
08606 status = cmlExecuteNoAnswerSql(
08607 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct data_id, ?, (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_DATA_MAIN where coll_id in (select coll_id from R_COLL_MAIN where coll_name = ? or coll_name like ?))",
08608 &icss);
08609 #else
08610 status = cmlExecuteNoAnswerSql(
08611 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct data_id, cast(? as bigint), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_DATA_MAIN where coll_id in (select coll_id from R_COLL_MAIN where coll_name = ? or coll_name like ?))",
08612 &icss);
08613 #endif
08614 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
08615 if (status != 0) {
08616 _rollback("chlModAccessControl");
08617 return(status);
08618 }
08619
08620
08621
08622 cllBindVars[cllBindVarCount++]=userIdStr;
08623 cllBindVars[cllBindVarCount++]=myAccessLev;
08624 cllBindVars[cllBindVarCount++]=myTime;
08625 cllBindVars[cllBindVarCount++]=myTime;
08626 cllBindVars[cllBindVarCount++]=pathName;
08627 cllBindVars[cllBindVarCount++]=pathStart;
08628 if (logSQL!=0) rodsLog(LOG_SQL, "chlModAccessControl SQL 11");
08629 #if ORA_ICAT
08630
08631 status = cmlExecuteNoAnswerSql(
08632 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct coll_id, cast(? as integer), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_COLL_MAIN where coll_name = ? or coll_name like ?)",
08633 &icss);
08634 #elif MY_ICAT
08635 status = cmlExecuteNoAnswerSql(
08636 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct coll_id, ?, (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_COLL_MAIN where coll_name = ? or coll_name like ?)",
08637 &icss);
08638 #else
08639 status = cmlExecuteNoAnswerSql(
08640 "insert into R_OBJT_ACCESS (object_id, user_id, access_type_id, create_ts, modify_ts) (select distinct coll_id, cast(? as bigint), (select token_id from R_TOKN_MAIN where token_namespace = 'access_type' and token_name = ?), ?, ? from R_COLL_MAIN where coll_name = ? or coll_name like ?)",
08641 &icss);
08642 #endif
08643 if (status != 0) {
08644 _rollback("chlModAccessControl");
08645 return(status);
08646 }
08647
08648
08649 status = cmlAudit5(AU_MOD_ACCESS_CONTROL_COLL_RECURSIVE,
08650 collIdStr,
08651 userIdStr,
08652 myAccessLev,
08653 &icss);
08654 if (status != 0) {
08655 rodsLog(LOG_NOTICE,
08656 "chlModAccessControl cmlAudit5 failure %d",
08657 status);
08658 _rollback("chlModAccessControl");
08659 return(status);
08660 }
08661
08662 status = cmlExecuteNoAnswerSql("commit", &icss);
08663 return(status);
08664 }
08665
08666
08667
08668
08669 int chlRenameObject(rsComm_t *rsComm, rodsLong_t objId,
08670 char* newName) {
08671 int status;
08672 rodsLong_t collId;
08673 rodsLong_t otherDataId;
08674 rodsLong_t otherCollId;
08675 char myTime[50];
08676
08677 char parentCollName[MAX_NAME_LEN]="";
08678 char collName[MAX_NAME_LEN]="";
08679 char *cVal[3];
08680 int iVal[3];
08681 int pLen, cLen, len;
08682 int isRootDir=0;
08683 char objIdString[MAX_NAME_LEN];
08684 char collIdString[MAX_NAME_LEN];
08685 char collNameTmp[MAX_NAME_LEN];
08686
08687 char pLenStr[MAX_NAME_LEN];
08688 char cLenStr[MAX_NAME_LEN];
08689 char collNameSlash[MAX_NAME_LEN];
08690 char collNameSlashLen[20];
08691 char slashNewName[MAX_NAME_LEN];
08692
08693 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject");
08694
08695 if (strstr(newName, "/")) {
08696 return(CAT_INVALID_ARGUMENT);
08697 }
08698
08699
08700
08701 collId=0;
08702
08703 snprintf(objIdString, MAX_NAME_LEN, "%lld", objId);
08704 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 1 ");
08705
08706 status = cmlGetIntegerValueFromSql(
08707 "select coll_id from R_DATA_MAIN DM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_TOKN_MAIN TM where DM.data_id=? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = DM.data_id and UG.group_user_id = OA.user_id and OA.access_type_id >= TM.token_id and TM.token_namespace ='access_type' and TM.token_name = 'own'",
08708 &collId, objIdString, rsComm->clientUser.userName, rsComm->clientUser.rodsZone,
08709 0, 0, &icss);
08710
08711 if (status == 0) {
08712
08713
08714 snprintf(collIdString, MAX_NAME_LEN, "%lld", collId);
08715 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 2");
08716 status = cmlGetIntegerValueFromSql(
08717 "select data_id from R_DATA_MAIN where data_name=? and coll_id=?",
08718 &otherDataId,
08719 newName, collIdString, 0, 0, 0, &icss);
08720 if (status!=CAT_NO_ROWS_FOUND) {
08721 return( CAT_NAME_EXISTS_AS_DATAOBJ);
08722 }
08723
08724
08725
08726 snprintf(collNameTmp, MAX_NAME_LEN, "/%s", newName);
08727 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 3");
08728 status = cmlGetIntegerValueFromSql(
08729 "select coll_id from R_COLL_MAIN where coll_name = ( select coll_name from R_COLL_MAIN where coll_id=? ) || ?",
08730 &otherCollId, collIdString, collNameTmp, 0, 0, 0, &icss);
08731 if (status!=CAT_NO_ROWS_FOUND) {
08732 return( CAT_NAME_EXISTS_AS_COLLECTION);
08733 }
08734
08735
08736 getNowStr(myTime);
08737 cllBindVars[cllBindVarCount++]=newName;
08738 cllBindVars[cllBindVarCount++]=objIdString;
08739 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 4");
08740 status = cmlExecuteNoAnswerSql(
08741 "update R_DATA_MAIN set data_name = ? where data_id=?",
08742 &icss);
08743 if (status != 0) {
08744 rodsLog(LOG_NOTICE,
08745 "chlRenameObject cmlExecuteNoAnswerSql update1 failure %d",
08746 status);
08747 _rollback("chlRenameObject");
08748 return(status);
08749 }
08750
08751 cllBindVars[cllBindVarCount++]=myTime;
08752 cllBindVars[cllBindVarCount++]=collIdString;
08753 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 5");
08754 status = cmlExecuteNoAnswerSql(
08755 "update R_COLL_MAIN set modify_ts=? where coll_id=?",
08756 &icss);
08757 if (status != 0) {
08758 rodsLog(LOG_NOTICE,
08759 "chlRenameObject cmlExecuteNoAnswerSql update2 failure %d",
08760 status);
08761 _rollback("chlRenameObject");
08762 return(status);
08763 }
08764
08765
08766 status = cmlAudit3(AU_RENAME_DATA_OBJ,
08767 objIdString,
08768 rsComm->clientUser.userName,
08769 rsComm->clientUser.rodsZone,
08770 newName,
08771 &icss);
08772 if (status != 0) {
08773 rodsLog(LOG_NOTICE,
08774 "chlRenameObject cmlAudit3 failure %d",
08775 status);
08776 _rollback("chlRenameObject");
08777 return(status);
08778 }
08779
08780 return(status);
08781 }
08782
08783
08784
08785
08786 cVal[0]=parentCollName;
08787 iVal[0]=MAX_NAME_LEN;
08788 cVal[1]=collName;
08789 iVal[1]=MAX_NAME_LEN;
08790
08791 snprintf(objIdString, MAX_NAME_LEN, "%lld", objId);
08792 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 6");
08793
08794 status = cmlGetStringValuesFromSql(
08795 "select parent_coll_name, coll_name from R_COLL_MAIN CM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_TOKN_MAIN TM where CM.coll_id=? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = CM.coll_id and UG.group_user_id = OA.user_id and OA.access_type_id >= TM.token_id and TM.token_namespace ='access_type' and TM.token_name = 'own'",
08796 cVal, iVal, 2, objIdString,
08797 rsComm->clientUser.userName, rsComm->clientUser.rodsZone, &icss);
08798 if (status == 0) {
08799
08800
08801
08802 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 7");
08803 status = cmlGetIntegerValueFromSql(
08804 "select data_id from R_DATA_MAIN where data_name=? and coll_id= (select coll_id from R_COLL_MAIN where coll_name = ?)",
08805 &otherDataId, newName, parentCollName, 0, 0, 0, &icss);
08806 if (status!=CAT_NO_ROWS_FOUND) {
08807 return( CAT_NAME_EXISTS_AS_DATAOBJ);
08808 }
08809
08810
08811
08812 snprintf(collNameTmp, MAX_NAME_LEN, "%s/%s", parentCollName, newName);
08813 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 8");
08814 status = cmlGetIntegerValueFromSql(
08815 "select coll_id from R_COLL_MAIN where coll_name = ?",
08816 &otherCollId, collNameTmp, 0, 0, 0, 0, &icss);
08817 if (status!=CAT_NO_ROWS_FOUND) {
08818 return( CAT_NAME_EXISTS_AS_COLLECTION);
08819 }
08820
08821
08822 pLen = strlen(parentCollName);
08823 cLen=strlen(collName);
08824 if (pLen<=0 || cLen <=0) return(CAT_INVALID_ARGUMENT);
08825
08826
08827 if (pLen==1) {
08828 if (strncmp(parentCollName, "/", 20) == 0) {
08829 isRootDir=1;
08830 }
08831 }
08832
08833
08834
08835
08836
08837
08838 snprintf(pLenStr,MAX_NAME_LEN, "%d", pLen);
08839
08840
08841 snprintf(cLenStr,MAX_NAME_LEN, "%d", cLen+1);
08842 snprintf(collNameSlash, MAX_NAME_LEN, "%s/", collName);
08843 len = strlen(collNameSlash);
08844 snprintf(collNameSlashLen, 10, "%d", len);
08845 snprintf(slashNewName, MAX_NAME_LEN, "/%s", newName);
08846 if (isRootDir) {
08847 snprintf(slashNewName, MAX_NAME_LEN, "%s", newName);
08848 }
08849 cllBindVars[cllBindVarCount++]=pLenStr;
08850 cllBindVars[cllBindVarCount++]=slashNewName;
08851 cllBindVars[cllBindVarCount++]=cLenStr;
08852 cllBindVars[cllBindVarCount++]=collNameSlashLen;
08853 cllBindVars[cllBindVarCount++]=collNameSlash;
08854 cllBindVars[cllBindVarCount++]=collName;
08855 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 9");
08856 status = cmlExecuteNoAnswerSql(
08857 "update R_COLL_MAIN set coll_name = substr(coll_name,1,?) || ? || substr(coll_name, ?) where substr(parent_coll_name,1,?) = ? or parent_coll_name = ?",
08858 &icss);
08859 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08860 rodsLog(LOG_NOTICE,
08861 "chlRenameObject cmlExecuteNoAnswerSql update failure %d",
08862 status);
08863 _rollback("chlRenameObject");
08864 return(status);
08865 }
08866
08867
08868 cllBindVars[cllBindVarCount++]=pLenStr;
08869 cllBindVars[cllBindVarCount++]=slashNewName;
08870 cllBindVars[cllBindVarCount++]=cLenStr;
08871 cllBindVars[cllBindVarCount++]=collNameSlashLen;
08872 cllBindVars[cllBindVarCount++]=collNameSlash;
08873 cllBindVars[cllBindVarCount++]=collName;
08874 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 10");
08875 status = cmlExecuteNoAnswerSql(
08876 "update R_COLL_MAIN set parent_coll_name = substr(parent_coll_name,1,?) || ? || substr(parent_coll_name, ?) where substr(parent_coll_name,1,?) = ? or parent_coll_name = ?",
08877 &icss);
08878 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
08879 rodsLog(LOG_NOTICE,
08880 "chlRenameObject cmlExecuteNoAnswerSql update failure %d",
08881 status);
08882 _rollback("chlRenameObject");
08883 return(status);
08884 }
08885
08886
08887 getNowStr(myTime);
08888 snprintf(collNameTmp, MAX_NAME_LEN, "%s/%s", parentCollName, newName);
08889 if (isRootDir) {
08890 snprintf(collNameTmp, MAX_NAME_LEN, "%s%s", parentCollName, newName);
08891 }
08892 cllBindVars[cllBindVarCount++]=collNameTmp;
08893 cllBindVars[cllBindVarCount++]=myTime;
08894 cllBindVars[cllBindVarCount++]=objIdString;
08895 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 11");
08896 status = cmlExecuteNoAnswerSql(
08897 "update R_COLL_MAIN set coll_name=?, modify_ts=? where coll_id=?",
08898 &icss);
08899 if (status != 0) {
08900 rodsLog(LOG_NOTICE,
08901 "chlRenameObject cmlExecuteNoAnswerSql update failure %d",
08902 status);
08903 _rollback("chlRenameObject");
08904 return(status);
08905 }
08906
08907
08908 status = cmlAudit3(AU_RENAME_COLLECTION,
08909 objIdString,
08910 rsComm->clientUser.userName,
08911 rsComm->clientUser.rodsZone,
08912 newName,
08913 &icss);
08914 if (status != 0) {
08915 rodsLog(LOG_NOTICE,
08916 "chlRenameObject cmlAudit3 failure %d",
08917 status);
08918 _rollback("chlRenameObject");
08919 return(status);
08920 }
08921
08922 return(status);
08923
08924 }
08925
08926
08927
08928
08929
08930 snprintf(objIdString, MAX_NAME_LEN, "%lld", objId);
08931 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 12");
08932 status = cmlGetIntegerValueFromSql(
08933 "select coll_id from R_DATA_MAIN where data_id=?",
08934 &otherDataId, objIdString, 0, 0, 0, 0, &icss);
08935 if (status == 0) {
08936
08937 return (CAT_NO_ACCESS_PERMISSION);
08938 }
08939
08940 snprintf(collIdString, MAX_NAME_LEN, "%lld", objId);
08941 if (logSQL!=0) rodsLog(LOG_SQL, "chlRenameObject SQL 12");
08942 status = cmlGetIntegerValueFromSql(
08943 "select coll_id from R_COLL_MAIN where coll_id=?",
08944 &otherDataId, collIdString, 0, 0, 0, 0, &icss);
08945 if (status == 0) {
08946
08947 return (CAT_NO_ACCESS_PERMISSION);
08948 }
08949
08950 return(CAT_NOT_A_DATAOBJ_AND_NOT_A_COLLECTION);
08951 }
08952
08953
08954
08955
08956
08957 int chlMoveObject(rsComm_t *rsComm, rodsLong_t objId,
08958 rodsLong_t targetCollId) {
08959 int status;
08960 rodsLong_t collId;
08961 rodsLong_t otherDataId;
08962 rodsLong_t otherCollId;
08963 char myTime[50];
08964
08965 char dataObjName[MAX_NAME_LEN]="";
08966 char *cVal[3];
08967 int iVal[3];
08968
08969 char parentCollName[MAX_NAME_LEN]="";
08970 char oldCollName[MAX_NAME_LEN]="";
08971 char endCollName[MAX_NAME_LEN]="";
08972
08973
08974 char targetCollName[MAX_NAME_LEN]="";
08975 char parentTargetCollName[MAX_NAME_LEN]="";
08976 char newCollName[MAX_NAME_LEN]="";
08977 int pLen, ocLen;
08978 int i, OK, len;
08979 char *cp;
08980 char objIdString[MAX_NAME_LEN];
08981 char collIdString[MAX_NAME_LEN];
08982 char nameTmp[MAX_NAME_LEN];
08983 char ocLenStr[MAX_NAME_LEN];
08984 char collNameSlash[MAX_NAME_LEN];
08985 char collNameSlashLen[20];
08986
08987 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject");
08988
08989
08990
08991 cVal[0]=parentTargetCollName;
08992 iVal[0]=MAX_NAME_LEN;
08993 cVal[1]=targetCollName;
08994 iVal[1]=MAX_NAME_LEN;
08995 snprintf(objIdString, MAX_NAME_LEN, "%lld", targetCollId);
08996 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 1 ");
08997 status = cmlGetStringValuesFromSql(
08998 "select parent_coll_name, coll_name from R_COLL_MAIN CM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_TOKN_MAIN TM where CM.coll_id=? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = CM.coll_id and UG.group_user_id = OA.user_id and OA.access_type_id >= TM.token_id and TM.token_namespace ='access_type' and TM.token_name = 'own'",
08999 cVal, iVal, 2, objIdString,
09000 rsComm->clientUser.userName,
09001 rsComm->clientUser.rodsZone, &icss);
09002
09003 snprintf(collIdString, MAX_NAME_LEN, "%lld", targetCollId);
09004 if (status != 0) {
09005 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 2");
09006 status = cmlGetIntegerValueFromSql(
09007 "select coll_id from R_COLL_MAIN where coll_id=?",
09008 &collId, collIdString, 0, 0, 0, 0, &icss);
09009 if (status==0) {
09010 return (CAT_NO_ACCESS_PERMISSION);
09011
09012 }
09013 return(CAT_UNKNOWN_COLLECTION);
09014 }
09015
09016
09017
09018
09019 snprintf(objIdString, MAX_NAME_LEN, "%lld", objId);
09020 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 3");
09021 status = cmlGetStringValueFromSql(
09022 "select data_name from R_DATA_MAIN DM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_TOKN_MAIN TM where DM.data_id=? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = DM.data_id and UG.group_user_id = OA.user_id and OA.access_type_id >= TM.token_id and TM.token_namespace ='access_type' and TM.token_name = 'own'",
09023 dataObjName, MAX_NAME_LEN, objIdString,
09024 rsComm->clientUser.userName,
09025 rsComm->clientUser.rodsZone, &icss);
09026 snprintf(collIdString, MAX_NAME_LEN, "%lld", targetCollId);
09027 if (status == 0) {
09028
09029
09030
09031 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 4");
09032 status = cmlGetIntegerValueFromSql(
09033 "select data_id from R_DATA_MAIN where data_name=? and coll_id=?",
09034 &otherDataId, dataObjName, collIdString, 0, 0, 0, &icss);
09035 if (status!=CAT_NO_ROWS_FOUND) {
09036 return( CAT_NAME_EXISTS_AS_DATAOBJ);
09037 }
09038
09039
09040
09041
09042 snprintf(nameTmp, MAX_NAME_LEN, "/%s", dataObjName);
09043 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 5");
09044 status = cmlGetIntegerValueFromSql(
09045 "select coll_id from R_COLL_MAIN where coll_name = ( select coll_name from R_COLL_MAIN where coll_id=? ) || ?",
09046 &otherCollId, collIdString, nameTmp, 0, 0, 0, &icss);
09047 if (status!=CAT_NO_ROWS_FOUND) {
09048 return( CAT_NAME_EXISTS_AS_COLLECTION);
09049 }
09050
09051
09052 getNowStr(myTime);
09053 cllBindVars[cllBindVarCount++]=collIdString;
09054 cllBindVars[cllBindVarCount++]=myTime;
09055 cllBindVars[cllBindVarCount++]=objIdString;
09056 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 6");
09057 status = cmlExecuteNoAnswerSql(
09058 "update R_DATA_MAIN set coll_id=?, modify_ts=? where data_id=?",
09059 &icss);
09060 if (status != 0) {
09061 rodsLog(LOG_NOTICE,
09062 "chlMoveObject cmlExecuteNoAnswerSql update1 failure %d",
09063 status);
09064 _rollback("chlMoveObject");
09065 return(status);
09066 }
09067
09068
09069 cllBindVars[cllBindVarCount++]=myTime;
09070 cllBindVars[cllBindVarCount++]=collIdString;
09071 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 7");
09072 status = cmlExecuteNoAnswerSql(
09073 "update R_COLL_MAIN set modify_ts=? where coll_id=?",
09074 &icss);
09075 if (status != 0) {
09076 rodsLog(LOG_NOTICE,
09077 "chlMoveObject cmlExecuteNoAnswerSql update2 failure %d",
09078 status);
09079 _rollback("chlMoveObject");
09080 return(status);
09081 }
09082
09083
09084 status = cmlAudit3(AU_MOVE_DATA_OBJ,
09085 objIdString,
09086 rsComm->clientUser.userName,
09087 rsComm->clientUser.rodsZone,
09088 collIdString,
09089 &icss);
09090 if (status != 0) {
09091 rodsLog(LOG_NOTICE,
09092 "chlMoveObject cmlAudit3 failure %d",
09093 status);
09094 _rollback("chlMoveObject");
09095 return(status);
09096 }
09097
09098 return(status);
09099 }
09100
09101
09102
09103 cVal[0]=parentCollName;
09104 iVal[0]=MAX_NAME_LEN;
09105 cVal[1]=oldCollName;
09106 iVal[1]=MAX_NAME_LEN;
09107
09108 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 8");
09109 status = cmlGetStringValuesFromSql(
09110 "select parent_coll_name, coll_name from R_COLL_MAIN CM, R_OBJT_ACCESS OA, R_USER_GROUP UG, R_USER_MAIN UM, R_TOKN_MAIN TM where CM.coll_id=? and UM.user_name=? and UM.zone_name=? and UM.user_type_name!='rodsgroup' and UM.user_id = UG.user_id and OA.object_id = CM.coll_id and UG.group_user_id = OA.user_id and OA.access_type_id >= TM.token_id and TM.token_namespace ='access_type' and TM.token_name = 'own'",
09111 cVal, iVal, 2, objIdString, rsComm->clientUser.userName,
09112 rsComm->clientUser.rodsZone, &icss);
09113 if (status == 0) {
09114
09115
09116 pLen = strlen(parentCollName);
09117
09118 ocLen=strlen(oldCollName);
09119 if (pLen<=0 || ocLen <=0) return(CAT_INVALID_ARGUMENT);
09120
09121
09122 OK=0;
09123 for (i=ocLen;i>0;i--) {
09124 if (oldCollName[i]=='/') {
09125 OK=1;
09126 strncpy(endCollName, (char*)&oldCollName[i+1], MAX_NAME_LEN);
09127 break;
09128 }
09129 }
09130 if (OK==0) return (CAT_INVALID_ARGUMENT);
09131
09132
09133
09134 snprintf(collIdString, MAX_NAME_LEN, "%lld", targetCollId);
09135 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 9");
09136 status = cmlGetIntegerValueFromSql(
09137 "select data_id from R_DATA_MAIN where data_name=? and coll_id=?",
09138 &otherDataId, endCollName, collIdString, 0, 0, 0, &icss);
09139 if (status!=CAT_NO_ROWS_FOUND) {
09140 return( CAT_NAME_EXISTS_AS_DATAOBJ);
09141 }
09142
09143
09144
09145 strncpy(newCollName, targetCollName, MAX_NAME_LEN);
09146 strncat(newCollName, "/", MAX_NAME_LEN);
09147 strncat(newCollName, endCollName, MAX_NAME_LEN);
09148
09149 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 10");
09150 status = cmlGetIntegerValueFromSql(
09151 "select coll_id from R_COLL_MAIN where coll_name = ?",
09152 &otherCollId, newCollName, 0, 0, 0, 0, &icss);
09153 if (status!=CAT_NO_ROWS_FOUND) {
09154 return( CAT_NAME_EXISTS_AS_COLLECTION);
09155 }
09156
09157
09158
09159
09160 cp = strstr(targetCollName, oldCollName);
09161 if (cp == targetCollName &&
09162 (targetCollName[strlen(oldCollName)] == '/' ||
09163 targetCollName[strlen(oldCollName)] == '\0')) {
09164 return(CAT_RECURSIVE_MOVE);
09165 }
09166
09167
09168
09169
09170
09171
09172 getNowStr(myTime);
09173 cllBindVars[cllBindVarCount++]=newCollName;
09174 cllBindVars[cllBindVarCount++]=targetCollName;
09175 cllBindVars[cllBindVarCount++]=myTime;
09176 cllBindVars[cllBindVarCount++]=objIdString;
09177 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 11");
09178 status = cmlExecuteNoAnswerSql(
09179 "update R_COLL_MAIN set coll_name = ?, parent_coll_name=?, modify_ts=? where coll_id = ?",
09180 &icss);
09181 if (status != 0) {
09182 rodsLog(LOG_NOTICE,
09183 "chlMoveObject cmlExecuteNoAnswerSql update failure %d",
09184 status);
09185 _rollback("chlMoveObject");
09186 return(status);
09187 }
09188
09189
09190
09191
09192
09193
09194 snprintf(ocLenStr, MAX_NAME_LEN, "%d", ocLen+1);
09195 snprintf(collNameSlash, MAX_NAME_LEN, "%s/", oldCollName);
09196 len = strlen(collNameSlash);
09197 snprintf(collNameSlashLen, 10, "%d", len);
09198 cllBindVars[cllBindVarCount++]=newCollName;
09199 cllBindVars[cllBindVarCount++]=ocLenStr;
09200 cllBindVars[cllBindVarCount++]=newCollName;
09201 cllBindVars[cllBindVarCount++]=ocLenStr;
09202 cllBindVars[cllBindVarCount++]=collNameSlashLen;
09203 cllBindVars[cllBindVarCount++]=collNameSlash;
09204 cllBindVars[cllBindVarCount++]=oldCollName;
09205 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 12");
09206 status = cmlExecuteNoAnswerSql(
09207 "update R_COLL_MAIN set parent_coll_name = ? || substr(parent_coll_name, ?), coll_name = ? || substr(coll_name, ?) where substr(parent_coll_name,1,?) = ? or parent_coll_name = ?",
09208 &icss);
09209 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) status = 0;
09210 if (status != 0) {
09211 rodsLog(LOG_NOTICE,
09212 "chlMoveObject cmlExecuteNoAnswerSql update failure %d",
09213 status);
09214 _rollback("chlMoveObject");
09215 return(status);
09216 }
09217
09218
09219 status = cmlAudit3(AU_MOVE_COLL,
09220 objIdString,
09221 rsComm->clientUser.userName,
09222 rsComm->clientUser.rodsZone,
09223 targetCollName,
09224 &icss);
09225 if (status != 0) {
09226 rodsLog(LOG_NOTICE,
09227 "chlMoveObject cmlAudit3 failure %d",
09228 status);
09229 _rollback("chlMoveObject");
09230 return(status);
09231 }
09232
09233 return(status);
09234 }
09235
09236
09237
09238
09239 snprintf(objIdString, MAX_NAME_LEN, "%lld", objId);
09240 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 13");
09241 status = cmlGetIntegerValueFromSql(
09242 "select coll_id from R_DATA_MAIN where data_id=?",
09243 &otherDataId, objIdString, 0, 0, 0, 0, &icss);
09244 if (status == 0) {
09245
09246 return (CAT_NO_ACCESS_PERMISSION);
09247 }
09248
09249 if (logSQL!=0) rodsLog(LOG_SQL, "chlMoveObject SQL 14");
09250 status = cmlGetIntegerValueFromSql(
09251 "select coll_id from R_COLL_MAIN where coll_id=?",
09252 &otherDataId, objIdString, 0, 0, 0, 0, &icss);
09253 if (status == 0) {
09254
09255 return (CAT_NO_ACCESS_PERMISSION);
09256 }
09257
09258 return(CAT_NOT_A_DATAOBJ_AND_NOT_A_COLLECTION);
09259 }
09260
09261
09262
09263
09264 int chlRegToken(rsComm_t *rsComm, char *nameSpace, char *name, char *value,
09265 char *value2, char *value3, char *comment)
09266 {
09267 int status;
09268 rodsLong_t objId;
09269 char *myValue1, *myValue2, *myValue3, *myComment;
09270 char myTime[50];
09271 rodsLong_t seqNum;
09272 char errMsg[205];
09273 char seqNumStr[MAX_NAME_LEN];
09274
09275 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegToken");
09276
09277 if (nameSpace==NULL || strlen(nameSpace)==0) return (CAT_INVALID_ARGUMENT);
09278 if (name==NULL || strlen(name)==0) return (CAT_INVALID_ARGUMENT);
09279
09280 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegToken SQL 1 ");
09281 status = cmlGetIntegerValueFromSql(
09282 "select token_id from R_TOKN_MAIN where token_namespace=? and token_name=?",
09283 &objId, "token_namespace", nameSpace, 0, 0, 0, &icss);
09284 if (status != 0) {
09285 snprintf(errMsg, 200,
09286 "Token namespace '%s' does not exist",
09287 nameSpace);
09288 addRErrorMsg (&rsComm->rError, 0, errMsg);
09289 return (CAT_INVALID_ARGUMENT);
09290 }
09291
09292 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegToken SQL 2");
09293 status = cmlGetIntegerValueFromSql(
09294 "select token_id from R_TOKN_MAIN where token_namespace=? and token_name=?",
09295 &objId, nameSpace, name, 0, 0, 0, &icss);
09296 if (status == 0) {
09297 snprintf(errMsg, 200,
09298 "Token '%s' already exists in namespace '%s'",
09299 name, nameSpace);
09300 addRErrorMsg (&rsComm->rError, 0, errMsg);
09301 return (CAT_INVALID_ARGUMENT);
09302 }
09303
09304 myValue1=value;
09305 if (myValue1==NULL) myValue1="";
09306 myValue2=value2;
09307 if (myValue2==NULL) myValue2="";
09308 myValue3=value3;
09309 if (myValue3==NULL) myValue3="";
09310 myComment=comment;
09311 if (myComment==NULL) myComment="";
09312
09313 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegToken SQL 3");
09314 seqNum = cmlGetNextSeqVal(&icss);
09315 if (seqNum < 0) {
09316 rodsLog(LOG_NOTICE, "chlRegToken cmlGetNextSeqVal failure %d",
09317 seqNum);
09318 return(seqNum);
09319 }
09320
09321 getNowStr(myTime);
09322 snprintf(seqNumStr, sizeof seqNumStr, "%lld", seqNum);
09323 cllBindVars[cllBindVarCount++]=nameSpace;
09324 cllBindVars[cllBindVarCount++]=seqNumStr;
09325 cllBindVars[cllBindVarCount++]=name;
09326 cllBindVars[cllBindVarCount++]=myValue1;
09327 cllBindVars[cllBindVarCount++]=myValue2;
09328 cllBindVars[cllBindVarCount++]=myValue3;
09329 cllBindVars[cllBindVarCount++]=myComment;
09330 cllBindVars[cllBindVarCount++]=myTime;
09331 cllBindVars[cllBindVarCount++]=myTime;
09332 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegToken SQL 4");
09333 status = cmlExecuteNoAnswerSql(
09334 "insert into R_TOKN_MAIN values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
09335 &icss);
09336 if (status != 0) {
09337 _rollback("chlRegToken");
09338 return(status);
09339 }
09340
09341
09342 status = cmlAudit3(AU_REG_TOKEN,
09343 seqNumStr,
09344 rsComm->clientUser.userName,
09345 rsComm->clientUser.rodsZone,
09346 name,
09347 &icss);
09348 if (status != 0) {
09349 rodsLog(LOG_NOTICE,
09350 "chlRegToken cmlAudit3 failure %d",
09351 status);
09352 _rollback("chlRegToken");
09353 return(status);
09354 }
09355
09356 status = cmlExecuteNoAnswerSql("commit", &icss);
09357 return(status);
09358 }
09359
09360
09361
09362
09363
09364 int chlDelToken(rsComm_t *rsComm, char *nameSpace, char *name)
09365 {
09366 int status;
09367 rodsLong_t objId;
09368 char errMsg[205];
09369 char objIdStr[60];
09370
09371 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelToken");
09372
09373 if (nameSpace==NULL || strlen(nameSpace)==0) return (CAT_INVALID_ARGUMENT);
09374 if (name==NULL || strlen(name)==0) return (CAT_INVALID_ARGUMENT);
09375
09376 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelToken SQL 1 ");
09377 status = cmlGetIntegerValueFromSql(
09378 "select token_id from R_TOKN_MAIN where token_namespace=? and token_name=?",
09379 &objId, nameSpace, name, 0, 0, 0, &icss);
09380 if (status != 0) {
09381 snprintf(errMsg, 200,
09382 "Token '%s' does not exist in namespace '%s'",
09383 name, nameSpace);
09384 addRErrorMsg (&rsComm->rError, 0, errMsg);
09385 return (CAT_INVALID_ARGUMENT);
09386 }
09387
09388 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelToken SQL 2");
09389 cllBindVars[cllBindVarCount++]=nameSpace;
09390 cllBindVars[cllBindVarCount++]=name;
09391 status = cmlExecuteNoAnswerSql(
09392 "delete from R_TOKN_MAIN where token_namespace=? and token_name=?",
09393 &icss);
09394 if (status != 0) {
09395 _rollback("chlDelToken");
09396 return(status);
09397 }
09398
09399
09400 snprintf(objIdStr, sizeof objIdStr, "%lld", objId);
09401 status = cmlAudit3(AU_DEL_TOKEN,
09402 objIdStr,
09403 rsComm->clientUser.userName,
09404 rsComm->clientUser.rodsZone,
09405 name,
09406 &icss);
09407 if (status != 0) {
09408 rodsLog(LOG_NOTICE,
09409 "chlDelToken cmlAudit3 failure %d",
09410 status);
09411 _rollback("chlDelToken");
09412 return(status);
09413 }
09414
09415 status = cmlExecuteNoAnswerSql("commit", &icss);
09416 return(status);
09417 }
09418
09419
09420
09421
09422
09423
09424
09425 int chlRegServerLoad(rsComm_t *rsComm,
09426 char *hostName, char *rescName,
09427 char *cpuUsed, char *memUsed, char *swapUsed,
09428 char *runqLoad, char *diskSpace, char *netInput,
09429 char *netOutput) {
09430 char myTime[50];
09431 int status;
09432 int i;
09433
09434 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegServerLoad");
09435
09436 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
09437 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
09438 }
09439
09440 if (!icss.status) {
09441 return(CATALOG_NOT_CONNECTED);
09442 }
09443
09444 getNowStr(myTime);
09445
09446 i=0;
09447 cllBindVars[i++]=hostName;
09448 cllBindVars[i++]=rescName;
09449 cllBindVars[i++]=cpuUsed;
09450 cllBindVars[i++]=memUsed;
09451 cllBindVars[i++]=swapUsed;
09452 cllBindVars[i++]=runqLoad;
09453 cllBindVars[i++]=diskSpace;
09454 cllBindVars[i++]=netInput;
09455 cllBindVars[i++]=netOutput;
09456 cllBindVars[i++]=myTime;
09457 cllBindVarCount=i;
09458 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegServerLoad SQL 1");
09459 status = cmlExecuteNoAnswerSql(
09460 "insert into R_SERVER_LOAD (host_name, resc_name, cpu_used, mem_used, swap_used, runq_load, disk_space, net_input, net_output, create_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
09461 &icss);
09462 if (status != 0) {
09463 rodsLog(LOG_NOTICE,
09464 "chlRegServerLoad cmlExecuteNoAnswerSql failure %d",status);
09465 _rollback("chlRegServerLoad");
09466 return(status);
09467 }
09468
09469 status = cmlExecuteNoAnswerSql("commit", &icss);
09470 if (status != 0) {
09471 rodsLog(LOG_NOTICE,
09472 "chlRegServerLoad cmlExecuteNoAnswerSql commit failure %d",
09473 status);
09474 return(status);
09475 }
09476
09477 return(0);
09478 }
09479
09480
09481
09482
09483
09484
09485
09486 int chlPurgeServerLoad(rsComm_t *rsComm, char *secondsAgo) {
09487
09488
09489 int status;
09490 char nowStr[50];
09491 static char thenStr[50];
09492 time_t nowTime;
09493 time_t thenTime;
09494 time_t secondsAgoTime;
09495
09496 if (logSQL!=0) rodsLog(LOG_SQL, "chlPurgeServerLoad");
09497
09498 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
09499 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
09500 }
09501
09502 getNowStr(nowStr);
09503 nowTime=atoll(nowStr);
09504 secondsAgoTime=atoll(secondsAgo);
09505 thenTime = nowTime - secondsAgoTime;
09506 snprintf(thenStr, sizeof thenStr, "%011d", (uint) thenTime);
09507
09508 if (logSQL!=0) rodsLog(LOG_SQL, "chlPurgeServerLoad SQL 1");
09509
09510 cllBindVars[cllBindVarCount++]=thenStr;
09511 status = cmlExecuteNoAnswerSql(
09512 "delete from R_SERVER_LOAD where create_ts <?",
09513 &icss);
09514 if (status != 0) {
09515 _rollback("chlPurgeServerLoad");
09516 return(status);
09517 }
09518
09519 status = cmlExecuteNoAnswerSql("commit", &icss);
09520 return(status);
09521 }
09522
09523
09524
09525
09526
09527
09528 int chlRegServerLoadDigest(rsComm_t *rsComm,
09529 char *rescName, char *loadFactor) {
09530 char myTime[50];
09531 int status;
09532 int i;
09533
09534 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegServerLoadDigest");
09535
09536 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
09537 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
09538 }
09539
09540 if (!icss.status) {
09541 return(CATALOG_NOT_CONNECTED);
09542 }
09543
09544 getNowStr(myTime);
09545
09546 i=0;
09547 cllBindVars[i++]=rescName;
09548 cllBindVars[i++]=loadFactor;
09549 cllBindVars[i++]=myTime;
09550 cllBindVarCount=i;
09551
09552 if (logSQL!=0) rodsLog(LOG_SQL, "chlRegServerLoadDigest SQL 1");
09553 status = cmlExecuteNoAnswerSql(
09554 "insert into R_SERVER_LOAD_DIGEST (resc_name, load_factor, create_ts) values (?, ?, ?)",
09555 &icss);
09556 if (status != 0) {
09557 rodsLog(LOG_NOTICE,
09558 "chlRegServerLoadDigest cmlExecuteNoAnswerSql failure %d", status);
09559 _rollback("chlRegServerLoadDigest");
09560 return(status);
09561 }
09562
09563 status = cmlExecuteNoAnswerSql("commit", &icss);
09564 if (status != 0) {
09565 rodsLog(LOG_NOTICE,
09566 "chlRegServerLoadDigest cmlExecuteNoAnswerSql commit failure %d",
09567 status);
09568 return(status);
09569 }
09570
09571 return(0);
09572 }
09573
09574
09575
09576
09577
09578
09579
09580 int chlPurgeServerLoadDigest(rsComm_t *rsComm, char *secondsAgo) {
09581
09582 int status;
09583 char nowStr[50];
09584 static char thenStr[50];
09585 time_t nowTime;
09586 time_t thenTime;
09587 time_t secondsAgoTime;
09588
09589 if (logSQL!=0) rodsLog(LOG_SQL, "chlPurgeServerLoadDigest");
09590
09591 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
09592 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
09593 }
09594
09595 getNowStr(nowStr);
09596 nowTime=atoll(nowStr);
09597 secondsAgoTime=atoll(secondsAgo);
09598 thenTime = nowTime - secondsAgoTime;
09599 snprintf(thenStr, sizeof thenStr, "%011d", (uint) thenTime);
09600
09601 if (logSQL!=0) rodsLog(LOG_SQL, "chlPurgeServerLoadDigest SQL 1");
09602
09603 cllBindVars[cllBindVarCount++]=thenStr;
09604 status = cmlExecuteNoAnswerSql(
09605 "delete from R_SERVER_LOAD_DIGEST where create_ts <?",
09606 &icss);
09607 if (status != 0) {
09608 _rollback("chlPurgeServerLoadDigest");
09609 return(status);
09610 }
09611
09612 status = cmlExecuteNoAnswerSql("commit", &icss);
09613 return(status);
09614 }
09615
09616
09617
09618
09619
09620
09621
09622
09623
09624 int setOverQuota(rsComm_t *rsComm) {
09625 int status;
09626 int rowsFound;
09627 int statementNum;
09628 char myTime[50];
09629
09630
09631
09632 char mySQL1[]="select sum(quota_usage), UM1.user_id, R_QUOTA_USAGE.resc_id from R_QUOTA_USAGE, R_QUOTA_MAIN, R_USER_MAIN UM1, R_USER_GROUP, R_USER_MAIN UM2 where R_QUOTA_MAIN.user_id = UM1.user_id and UM1.user_type_name = 'rodsgroup' and R_USER_GROUP.group_user_id = UM1.user_id and UM2.user_id = R_USER_GROUP.user_id and R_QUOTA_USAGE.user_id = UM2.user_id and R_QUOTA_MAIN.resc_id = R_QUOTA_USAGE.resc_id group by UM1.user_id, R_QUOTA_USAGE.resc_id";
09633
09634
09635
09636 char mySQL2a[]="select sum(quota_usage), R_QUOTA_MAIN.quota_limit, UM1.user_id from R_QUOTA_USAGE, R_QUOTA_MAIN, R_USER_MAIN UM1, R_USER_GROUP, R_USER_MAIN UM2 where R_QUOTA_MAIN.user_id = UM1.user_id and UM1.user_type_name = 'rodsgroup' and R_USER_GROUP.group_user_id = UM1.user_id and UM2.user_id = R_USER_GROUP.user_id and R_QUOTA_USAGE.user_id = UM2.user_id and R_QUOTA_USAGE.resc_id != %s and R_QUOTA_MAIN.resc_id = %s group by UM1.user_id, R_QUOTA_MAIN.quota_limit";
09637 char mySQL2b[MAX_SQL_SIZE];
09638
09639 char mySQL3a[]="update R_QUOTA_MAIN set quota_over= %s - ?, modify_ts=? where user_id=? and %s - ? > quota_over";
09640 char mySQL3b[MAX_SQL_SIZE];
09641
09642
09643
09644
09645 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 1");
09646 status = cmlExecuteNoAnswerSql(
09647 "update R_QUOTA_MAIN set quota_over = -quota_limit", &icss);
09648 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) return(0);
09649 if (status != 0) return(status);
09650
09651
09652 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 2");
09653 status = cmlExecuteNoAnswerSql(
09654 #if ORA_ICAT
09655 "update R_QUOTA_MAIN set quota_over = (select R_QUOTA_USAGE.quota_usage - R_QUOTA_MAIN.quota_limit from R_QUOTA_USAGE, R_QUOTA_MAIN where R_QUOTA_MAIN.user_id = R_QUOTA_USAGE.user_id and R_QUOTA_MAIN.resc_id = R_QUOTA_USAGE.resc_id) where exists (select 1 from R_QUOTA_USAGE, R_QUOTA_MAIN where R_QUOTA_MAIN.user_id = R_QUOTA_USAGE.user_id and R_QUOTA_MAIN.resc_id = R_QUOTA_USAGE.resc_id)",
09656 #elif MY_ICAT
09657 "update R_QUOTA_MAIN, R_QUOTA_USAGE set R_QUOTA_MAIN.quota_over = R_QUOTA_USAGE.quota_usage - R_QUOTA_MAIN.quota_limit where R_QUOTA_MAIN.user_id = R_QUOTA_USAGE.user_id and R_QUOTA_MAIN.resc_id = R_QUOTA_USAGE.resc_id",
09658 #else
09659 "update R_QUOTA_MAIN set quota_over = quota_usage - quota_limit from R_QUOTA_USAGE where R_QUOTA_MAIN.user_id = R_QUOTA_USAGE.user_id and R_QUOTA_MAIN.resc_id = R_QUOTA_USAGE.resc_id",
09660 #endif
09661 &icss);
09662 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
09663 if (status != 0) return(status);
09664
09665
09666
09667
09668
09669 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 3");
09670 getNowStr(myTime);
09671 for (rowsFound=0;;rowsFound++) {
09672 int status2;
09673 if (rowsFound==0) {
09674 status = cmlGetFirstRowFromSql("select sum(quota_usage), R_QUOTA_MAIN.user_id from R_QUOTA_USAGE, R_QUOTA_MAIN where R_QUOTA_MAIN.user_id = R_QUOTA_USAGE.user_id and R_QUOTA_MAIN.resc_id = '0' group by R_QUOTA_MAIN.user_id",
09675 &statementNum, 0, &icss);
09676 }
09677 else {
09678 status = cmlGetNextRowFromStatement(statementNum, &icss);
09679 }
09680 if (status != 0) break;
09681 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09682 cllBindVars[cllBindVarCount++]=myTime;
09683 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[1];
09684 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09685 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 4");
09686 status2 = cmlExecuteNoAnswerSql("update R_QUOTA_MAIN set quota_over=?-quota_limit, modify_ts=? where user_id=? and ?-quota_limit > quota_over and resc_id='0'",
09687 &icss);
09688 if (status2 == CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
09689 if (status2 != 0) return(status2);
09690 }
09691
09692
09693 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 5");
09694 for (rowsFound=0;;rowsFound++) {
09695 int status2;
09696 if (rowsFound==0) {
09697 status = cmlGetFirstRowFromSql(mySQL1, &statementNum,
09698 0, &icss);
09699 }
09700 else {
09701 status = cmlGetNextRowFromStatement(statementNum, &icss);
09702 }
09703 if (status != 0) break;
09704 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09705 cllBindVars[cllBindVarCount++]=myTime;
09706 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[1];
09707 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09708 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[2];
09709 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 6");
09710 status2 = cmlExecuteNoAnswerSql("update R_QUOTA_MAIN set quota_over=?-quota_limit, modify_ts=? where user_id=? and ?-quota_limit > quota_over and R_QUOTA_MAIN.resc_id=?",
09711 &icss);
09712 if (status2 == CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
09713 if (status2 != 0) return(status2);
09714 }
09715 if (status==CAT_NO_ROWS_FOUND) status=0;
09716 if (status != 0) return(status);
09717
09718
09719 #if ORA_ICAT
09720
09721 snprintf(mySQL2b, sizeof mySQL2b, mySQL2a,
09722 "cast('0' as integer)", "cast('0' as integer)");
09723 snprintf(mySQL3b, sizeof mySQL3b, mySQL3a,
09724 "cast(? as integer)", "cast(? as integer)");
09725 #elif MY_ICAT
09726 snprintf(mySQL2b, sizeof mySQL2b, mySQL2a, "'0'", "'0'");
09727 snprintf(mySQL3b, sizeof mySQL3b, mySQL3a, "?", "?");
09728 #else
09729 snprintf(mySQL2b, sizeof mySQL2b, mySQL2a,
09730 "cast('0' as bigint)", "cast('0' as bigint)");
09731 snprintf(mySQL3b, sizeof mySQL3b, mySQL3a,
09732 "cast(? as bigint)", "cast(? as bigint)");
09733 #endif
09734 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 7");
09735 getNowStr(myTime);
09736 for (rowsFound=0;;rowsFound++) {
09737 int status2;
09738 if (rowsFound==0) {
09739 status = cmlGetFirstRowFromSql(mySQL2b, &statementNum,
09740 0, &icss);
09741 }
09742 else {
09743 status = cmlGetNextRowFromStatement(statementNum, &icss);
09744 }
09745 if (status != 0) break;
09746 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09747 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[1];
09748 cllBindVars[cllBindVarCount++]=myTime;
09749 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[2];
09750 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[0];
09751 cllBindVars[cllBindVarCount++]=icss.stmtPtr[statementNum]->resultValue[1];
09752 if (logSQL!=0) rodsLog(LOG_SQL, "setOverQuota SQL 8");
09753 status2 = cmlExecuteNoAnswerSql(mySQL3b,
09754 &icss);
09755 if (status2 == CAT_SUCCESS_BUT_WITH_NO_INFO) status2=0;
09756 if (status2 != 0) return(status2);
09757 }
09758 if (status==CAT_NO_ROWS_FOUND) status=0;
09759 if (status != 0) return(status);
09760
09761
09762
09763
09764
09765
09766 return(status);
09767 }
09768
09769
09770 int chlCalcUsageAndQuota(rsComm_t *rsComm) {
09771 int status;
09772 char myTime[50];
09773
09774 status = 0;
09775 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
09776 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
09777 }
09778
09779 rodsLog(LOG_NOTICE,
09780 "chlCalcUsageAndQuota called");
09781
09782
09783 getNowStr(myTime);
09784
09785
09786 if (logSQL!=0) rodsLog(LOG_SQL, "chlCalcUsageAndQuota SQL 1");
09787 cllBindVars[cllBindVarCount++]=myTime;
09788 status = cmlExecuteNoAnswerSql(
09789 "delete from R_QUOTA_USAGE where modify_ts < ?", &icss);
09790 if (status !=0 && status !=CAT_SUCCESS_BUT_WITH_NO_INFO) {
09791 _rollback("chlCalcUsageAndQuota");
09792 return(status);
09793 }
09794
09795
09796 if (logSQL!=0) rodsLog(LOG_SQL, "chlCalcUsageAndQuota SQL 2");
09797 cllBindVars[cllBindVarCount++]=myTime;
09798 status = cmlExecuteNoAnswerSql(
09799 "insert into R_QUOTA_USAGE (quota_usage, resc_id, user_id, modify_ts) (select sum(R_DATA_MAIN.data_size), R_RESC_MAIN.resc_id, R_USER_MAIN.user_id, ? from R_DATA_MAIN, R_USER_MAIN, R_RESC_MAIN where R_USER_MAIN.user_name = R_DATA_MAIN.data_owner_name and R_USER_MAIN.zone_name = R_DATA_MAIN.data_owner_zone and R_RESC_MAIN.resc_name = R_DATA_MAIN.resc_name group by R_RESC_MAIN.resc_id, user_id)",
09800 &icss);
09801 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) status=0;
09802 if (status != 0) {
09803 _rollback("chlCalcUsageAndQuota");
09804 return(status);
09805 }
09806
09807
09808 status = setOverQuota(rsComm);
09809 if (status != 0) {
09810 _rollback("chlCalcUsageAndQuota");
09811 return(status);
09812 }
09813
09814 status = cmlExecuteNoAnswerSql("commit", &icss);
09815 return(status);
09816 }
09817
09818 int chlSetQuota(rsComm_t *rsComm, char *type, char *name,
09819 char *rescName, char* limit) {
09820 int status;
09821 rodsLong_t rescId;
09822 rodsLong_t userId;
09823 char userZone[NAME_LEN];
09824 char userName[NAME_LEN];
09825 char rescIdStr[60];
09826 char userIdStr[60];
09827 char myTime[50];
09828 int itype=0;
09829
09830 if (strncmp(type, "user",4)==0) itype=1;
09831 if (strncmp(type, "group",5)==0) itype=2;
09832 if (itype==0) return (CAT_INVALID_ARGUMENT);
09833
09834 status = getLocalZone();
09835 if (status != 0) return(status);
09836
09837
09838 rescId=0;
09839 if (strncmp(rescName,"total",5)!=0) {
09840 if (logSQL!=0) rodsLog(LOG_SQL, "chlSetQuota SQL 1");
09841 status = cmlGetIntegerValueFromSql(
09842 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
09843 &rescId, rescName, localZone, 0, 0, 0, &icss);
09844 if (status != 0) {
09845 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
09846 _rollback("chlSetQuota");
09847 return(status);
09848 }
09849 }
09850
09851
09852 status = parseUserName(name, userName, userZone);
09853 if (userZone[0]=='\0') {
09854 strncpy(userZone, localZone, NAME_LEN);
09855 }
09856
09857 if (itype==1) {
09858 userId=0;
09859 if (logSQL!=0) rodsLog(LOG_SQL, "chlSetQuota SQL 2");
09860 status = cmlGetIntegerValueFromSql(
09861 "select user_id from R_USER_MAIN where user_name=? and zone_name=?",
09862 &userId, userName, userZone, 0, 0, 0, &icss);
09863 if (status != 0) {
09864 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_USER);
09865 _rollback("chlSetQuota");
09866 return(status);
09867 }
09868 }
09869 else {
09870 userId=0;
09871 if (logSQL!=0) rodsLog(LOG_SQL, "chlSetQuota SQL 3");
09872 status = cmlGetIntegerValueFromSql(
09873 "select user_id from R_USER_MAIN where user_name=? and zone_name=? and user_type_name='rodsgroup'",
09874 &userId, userName, userZone, 0, 0, 0, &icss);
09875 if (status != 0) {
09876 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_GROUP);
09877 _rollback("chlSetQuota");
09878 return(status);
09879 }
09880 }
09881
09882 snprintf(userIdStr, sizeof userIdStr, "%lld", userId);
09883 snprintf(rescIdStr, sizeof rescIdStr, "%lld", rescId);
09884
09885
09886 cllBindVars[cllBindVarCount++]=userIdStr;
09887 cllBindVars[cllBindVarCount++]=rescIdStr;
09888 if (logSQL!=0) rodsLog(LOG_SQL, "chlSetQuota SQL 4");
09889 status = cmlExecuteNoAnswerSql(
09890 "delete from R_QUOTA_MAIN where user_id=? and resc_id=?",
09891 &icss);
09892 if (status != 0) {
09893 rodsLog(LOG_DEBUG,
09894 "chlSetQuota cmlExecuteNoAnswerSql delete failure %d",
09895 status);
09896 }
09897 if (atol(limit)>0) {
09898 getNowStr(myTime);
09899 cllBindVars[cllBindVarCount++]=userIdStr;
09900 cllBindVars[cllBindVarCount++]=rescIdStr;
09901 cllBindVars[cllBindVarCount++]=limit;
09902 cllBindVars[cllBindVarCount++]=myTime;
09903 if (logSQL!=0) rodsLog(LOG_SQL, "chlSetQuota SQL 5");
09904 status = cmlExecuteNoAnswerSql(
09905 "insert into R_QUOTA_MAIN (user_id, resc_id, quota_limit, modify_ts) values (?, ?, ?, ?)",
09906 &icss);
09907 if (status != 0) {
09908 rodsLog(LOG_NOTICE,
09909 "chlSetQuota cmlExecuteNoAnswerSql insert failure %d",
09910 status);
09911 _rollback("chlSetQuota");
09912 return(status);
09913 }
09914 }
09915
09916
09917
09918
09919 status = setOverQuota(rsComm);
09920 if (status != 0) {
09921 _rollback("chlSetQuota");
09922 return(status);
09923 }
09924
09925 status = cmlExecuteNoAnswerSql("commit", &icss);
09926 return(status);
09927 }
09928
09929
09930 int
09931 chlCheckQuota(rsComm_t *rsComm, char *userName, char *rescName,
09932 rodsLong_t *userQuota, int *quotaStatus) {
09933
09934
09935
09936
09937
09938
09939
09940
09941
09942 int status;
09943 int statementNum;
09944
09945 char mySQL[]="select distinct QM.user_id, QM.resc_id, QM.quota_limit, QM.quota_over from R_QUOTA_MAIN QM, R_USER_MAIN UM, R_RESC_MAIN RM, R_USER_GROUP UG, R_USER_MAIN UM2 where ( (QM.user_id = UM.user_id and UM.user_name = ?) or (QM.user_id = UG.group_user_id and UM2.user_name = ? and UG.user_id = UM2.user_id) ) and ((QM.resc_id = RM.resc_id and RM.resc_name = ?) or QM.resc_id = '0') order by quota_over desc";
09946
09947 *userQuota = 0;
09948 if (logSQL!=0) rodsLog(LOG_SQL, "chlCheckQuota SQL 1");
09949 cllBindVars[cllBindVarCount++]=userName;
09950 cllBindVars[cllBindVarCount++]=userName;
09951 cllBindVars[cllBindVarCount++]=rescName;
09952
09953 status = cmlGetFirstRowFromSql(mySQL, &statementNum,
09954 0, &icss);
09955
09956 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) {
09957 rodsLog(LOG_NOTICE,
09958 "chlCheckQuota - CAT_SUCCESS_BUT_WITH_NO_INFO");
09959 *quotaStatus = QUOTA_UNRESTRICTED;
09960 return(0);
09961 }
09962
09963 if (status == CAT_NO_ROWS_FOUND) {
09964 rodsLog(LOG_NOTICE,
09965 "chlCheckQuota - CAT_NO_ROWS_FOUND");
09966 *quotaStatus = QUOTA_UNRESTRICTED;
09967 return(0);
09968 }
09969
09970 if (status != 0) return(status);
09971
09972 #if 0
09973 for (i=0;i<4;i++) {
09974 rodsLog(LOG_NOTICE, "checkvalue: %s",
09975 icss.stmtPtr[statementNum]->resultValue[i]);
09976 }
09977 #endif
09978
09979
09980 rodsLog(LOG_NOTICE, "checkQuota: inUser:%s inResc:%s RescId:%s Quota:%s",
09981 userName, rescName,
09982 icss.stmtPtr[statementNum]->resultValue[1],
09983 icss.stmtPtr[statementNum]->resultValue[3]);
09984
09985 *userQuota = atoll(icss.stmtPtr[statementNum]->resultValue[3]);
09986 if (atoi(icss.stmtPtr[statementNum]->resultValue[1])==0) {
09987 *quotaStatus=QUOTA_GLOBAL;
09988 }
09989 else {
09990 *quotaStatus=QUOTA_RESOURCE;
09991 }
09992 cmlFreeStatement(statementNum, &icss);
09993
09994 return(status);
09995 }
09996
09997 int
09998 chlDelUnusedAVUs(rsComm_t *rsComm) {
09999
10000
10001
10002
10003
10004 int status;
10005 status = removeAVUs();
10006
10007 if (status == 0) {
10008 status = cmlExecuteNoAnswerSql("commit", &icss);
10009 }
10010 return(status);
10011
10012 }
10013
10014
10015
10016
10017
10018
10019
10020 int
10021 chlInsRuleTable(rsComm_t *rsComm,
10022 char *baseName, char *mapPriorityStr, char *ruleName,
10023 char *ruleHead, char *ruleCondition, char *ruleAction,
10024 char *ruleRecovery, char *ruleIdStr, char *myTime) {
10025 int status;
10026 int i;
10027 rodsLong_t seqNum = -1;
10028
10029 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsRuleTable");
10030
10031 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10032 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10033 }
10034
10035 if (!icss.status) {
10036 return(CATALOG_NOT_CONNECTED);
10037 }
10038
10039
10040 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsRuleTable SQL 1");
10041 i=0;
10042 cllBindVars[i++]=baseName;
10043 cllBindVars[i++]=ruleName;
10044 cllBindVars[i++]=ruleHead;
10045 cllBindVars[i++]=ruleCondition;
10046 cllBindVars[i++]=ruleAction;
10047 cllBindVars[i++]=ruleRecovery;
10048 cllBindVarCount=i;
10049 status = cmlGetIntegerValueFromSqlV3(
10050 "select rule_id from R_RULE_MAIN where rule_base_name = ? and rule_name = ? and rule_event = ? and rule_condition = ? and rule_body = ? and rule_recovery = ?",
10051 &seqNum,
10052 &icss);
10053 if (status != 0 && status != CAT_NO_ROWS_FOUND) {
10054 rodsLog(LOG_NOTICE,
10055 "chlInsRuleTable cmlGetIntegerValueFromSqlV3 find rule if any failure %d",status);
10056 return(status);
10057 }
10058 if (seqNum < 0) {
10059 seqNum = cmlGetNextSeqVal(&icss);
10060 if (seqNum < 0) {
10061 rodsLog(LOG_NOTICE, "chlInsRuleTable cmlGetNextSeqVal failure %d",
10062 seqNum);
10063 _rollback("chlInsRuleTable");
10064 return(seqNum);
10065 }
10066 snprintf(ruleIdStr, MAX_NAME_LEN, "%lld", seqNum);
10067
10068 i=0;
10069 cllBindVars[i++]=ruleIdStr;
10070 cllBindVars[i++]=baseName;
10071 cllBindVars[i++]=ruleName;
10072 cllBindVars[i++]=ruleHead;
10073 cllBindVars[i++]=ruleCondition;
10074 cllBindVars[i++]=ruleAction;
10075 cllBindVars[i++]=ruleRecovery;
10076 cllBindVars[i++]=rsComm->clientUser.userName;
10077 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10078 cllBindVars[i++]=myTime;
10079 cllBindVars[i++]=myTime;
10080 cllBindVarCount=i;
10081 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsRuleTable SQL 2");
10082 status = cmlExecuteNoAnswerSql(
10083 "insert into R_RULE_MAIN(rule_id, rule_base_name, rule_name, rule_event, rule_condition, rule_body, rule_recovery, rule_owner_name, rule_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
10084 &icss);
10085 if (status != 0) {
10086 rodsLog(LOG_NOTICE,
10087 "chlInsRuleTable cmlExecuteNoAnswerSql Rule Main Insert failure %d",status);
10088 return(status);
10089 }
10090 }
10091 else {
10092 snprintf(ruleIdStr, MAX_NAME_LEN, "%lld", seqNum);
10093 }
10094 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsRuleTable SQL 3");
10095 i = 0;
10096 cllBindVars[i++]=baseName;
10097 cllBindVars[i++]=mapPriorityStr;
10098 cllBindVars[i++]=ruleIdStr;
10099 cllBindVars[i++]=rsComm->clientUser.userName;
10100 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10101 cllBindVars[i++]=myTime;
10102 cllBindVars[i++]=myTime;
10103 cllBindVarCount=i;
10104 status = cmlExecuteNoAnswerSql(
10105 "insert into R_RULE_BASE_MAP (map_base_name, map_priority, rule_id, map_owner_name,map_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?)",
10106 &icss);
10107 if (status != 0) {
10108 rodsLog(LOG_NOTICE,
10109 "chlInsRuleTable cmlExecuteNoAnswerSql Rule Map insert failure %d" , status);
10110
10111 return(status);
10112 }
10113
10114 return(0);
10115 }
10116
10117
10118
10119
10120
10121
10122 int
10123 chlInsDvmTable(rsComm_t *rsComm,
10124 char *baseName, char *varName, char *action,
10125 char *var2CMap, char *myTime) {
10126 int status;
10127 int i;
10128 rodsLong_t seqNum = -1;
10129 char dvmIdStr[MAX_NAME_LEN];
10130 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsDvmTable");
10131
10132 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10133 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10134 }
10135
10136 if (!icss.status) {
10137 return(CATALOG_NOT_CONNECTED);
10138 }
10139
10140
10141 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsDvmTable SQL 1");
10142 i=0;
10143 cllBindVars[i++]=baseName;
10144 cllBindVars[i++]=varName;
10145 cllBindVars[i++]=action;
10146 cllBindVars[i++]=var2CMap;
10147 cllBindVarCount=i;
10148 status = cmlGetIntegerValueFromSqlV3(
10149 "select dvm_id from R_RULE_DVM where dvm_base_name = ? and dvm_ext_var_name = ? and dvm_condition = ? and dvm_int_map_path = ? ",
10150 &seqNum,
10151 &icss);
10152 if (status != 0 && status != CAT_NO_ROWS_FOUND) {
10153 rodsLog(LOG_NOTICE,
10154 "chlInsDvmTable cmlGetIntegerValueFromSqlV3 find DVM if any failure %d",status);
10155 return(status);
10156 }
10157 if (seqNum < 0) {
10158 seqNum = cmlGetNextSeqVal(&icss);
10159 if (seqNum < 0) {
10160 rodsLog(LOG_NOTICE, "chlInsDvmTable cmlGetNextSeqVal failure %d",
10161 seqNum);
10162 _rollback("chlInsDvmTable");
10163 return(seqNum);
10164 }
10165 snprintf(dvmIdStr, MAX_NAME_LEN, "%lld", seqNum);
10166
10167 i=0;
10168 cllBindVars[i++]=dvmIdStr;
10169 cllBindVars[i++]=baseName;
10170 cllBindVars[i++]=varName;
10171 cllBindVars[i++]=action;
10172 cllBindVars[i++]=var2CMap;
10173 cllBindVars[i++]=rsComm->clientUser.userName;
10174 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10175 cllBindVars[i++]=myTime;
10176 cllBindVars[i++]=myTime;
10177 cllBindVarCount=i;
10178 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsDvmTable SQL 2");
10179 status = cmlExecuteNoAnswerSql(
10180 "insert into R_RULE_DVM(dvm_id, dvm_base_name, dvm_ext_var_name, dvm_condition, dvm_int_map_path, dvm_owner_name, dvm_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
10181 &icss);
10182 if (status != 0) {
10183 rodsLog(LOG_NOTICE,
10184 "chlInsDvmTable cmlExecuteNoAnswerSql DVM Main Insert failure %d",status);
10185 return(status);
10186 }
10187 }
10188 else {
10189 snprintf(dvmIdStr, MAX_NAME_LEN, "%lld", seqNum);
10190 }
10191 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsDvmTable SQL 3");
10192 i = 0;
10193 cllBindVars[i++]=baseName;
10194 cllBindVars[i++]=dvmIdStr;
10195 cllBindVars[i++]=rsComm->clientUser.userName;
10196 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10197 cllBindVars[i++]=myTime;
10198 cllBindVars[i++]=myTime;
10199 cllBindVarCount=i;
10200 status = cmlExecuteNoAnswerSql(
10201 "insert into R_RULE_DVM_MAP (map_dvm_base_name, dvm_id, map_owner_name,map_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?)",
10202 &icss);
10203 if (status != 0) {
10204 rodsLog(LOG_NOTICE,
10205 "chlInsDvmTable cmlExecuteNoAnswerSql DVM Map insert failure %d" , status);
10206
10207 return(status);
10208 }
10209
10210 return(0);
10211 }
10212
10213
10214
10215
10216
10217
10218
10219
10220 int
10221 chlInsFnmTable(rsComm_t *rsComm,
10222 char *baseName, char *funcName,
10223 char *func2CMap, char *myTime) {
10224 int status;
10225 int i;
10226 rodsLong_t seqNum = -1;
10227 char fnmIdStr[MAX_NAME_LEN];
10228 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsFnmTable");
10229
10230 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10231 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10232 }
10233
10234 if (!icss.status) {
10235 return(CATALOG_NOT_CONNECTED);
10236 }
10237
10238
10239 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsFnmTable SQL 1");
10240 i=0;
10241 cllBindVars[i++]=baseName;
10242 cllBindVars[i++]=funcName;
10243 cllBindVars[i++]=func2CMap;
10244 cllBindVarCount=i;
10245 status = cmlGetIntegerValueFromSqlV3(
10246 "select fnm_id from R_RULE_FNM where fnm_base_name = ? and fnm_ext_func_name = ? and fnm_int_func_name = ? ",
10247 &seqNum,
10248 &icss);
10249 if (status != 0 && status != CAT_NO_ROWS_FOUND) {
10250 rodsLog(LOG_NOTICE,
10251 "chlInsFnmTable cmlGetIntegerValueFromSqlV3 find FNM if any failure %d",status);
10252 return(status);
10253 }
10254 if (seqNum < 0) {
10255 seqNum = cmlGetNextSeqVal(&icss);
10256 if (seqNum < 0) {
10257 rodsLog(LOG_NOTICE, "chlInsFnmTable cmlGetNextSeqVal failure %d",
10258 seqNum);
10259 _rollback("chlInsFnmTable");
10260 return(seqNum);
10261 }
10262 snprintf(fnmIdStr, MAX_NAME_LEN, "%lld", seqNum);
10263
10264 i=0;
10265 cllBindVars[i++]=fnmIdStr;
10266 cllBindVars[i++]=baseName;
10267 cllBindVars[i++]=funcName;
10268 cllBindVars[i++]=func2CMap;
10269 cllBindVars[i++]=rsComm->clientUser.userName;
10270 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10271 cllBindVars[i++]=myTime;
10272 cllBindVars[i++]=myTime;
10273 cllBindVarCount=i;
10274 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsFnmTable SQL 2");
10275 status = cmlExecuteNoAnswerSql(
10276 "insert into R_RULE_FNM(fnm_id, fnm_base_name, fnm_ext_func_name, fnm_int_func_name, fnm_owner_name, fnm_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?)",
10277 &icss);
10278 if (status != 0) {
10279 rodsLog(LOG_NOTICE,
10280 "chlInsFnmTable cmlExecuteNoAnswerSql FNM Main Insert failure %d",status);
10281 return(status);
10282 }
10283 }
10284 else {
10285 snprintf(fnmIdStr, MAX_NAME_LEN, "%lld", seqNum);
10286 }
10287 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsFnmTable SQL 3");
10288 i = 0;
10289 cllBindVars[i++]=baseName;
10290 cllBindVars[i++]=fnmIdStr;
10291 cllBindVars[i++]=rsComm->clientUser.userName;
10292 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10293 cllBindVars[i++]=myTime;
10294 cllBindVars[i++]=myTime;
10295 cllBindVarCount=i;
10296 status = cmlExecuteNoAnswerSql(
10297 "insert into R_RULE_FNM_MAP (map_fnm_base_name, fnm_id, map_owner_name,map_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?)",
10298 &icss);
10299 if (status != 0) {
10300 rodsLog(LOG_NOTICE,
10301 "chlInsFnmTable cmlExecuteNoAnswerSql FNM Map insert failure %d" , status);
10302
10303 return(status);
10304 }
10305
10306 return(0);
10307 }
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318 int chlInsMsrvcTable(rsComm_t *rsComm,
10319 char *moduleName, char *msrvcName,
10320 char *msrvcSignature, char *msrvcVersion,
10321 char *msrvcHost, char *msrvcLocation,
10322 char *msrvcLanguage, char *msrvcTypeName, char *msrvcStatus,
10323 char *myTime)
10324 {
10325 int status;
10326 int i;
10327 rodsLong_t seqNum = -1;
10328 char msrvcIdStr[MAX_NAME_LEN];
10329 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable");
10330
10331 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10332 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10333 }
10334
10335 if (!icss.status) {
10336 return(CATALOG_NOT_CONNECTED);
10337 }
10338
10339
10340 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable SQL 1");
10341 i=0;
10342 cllBindVars[i++]=moduleName;
10343 cllBindVars[i++]=msrvcName;
10344 cllBindVarCount=i;
10345 status = cmlGetIntegerValueFromSqlV3(
10346 "select msrvc_id from R_MICROSRVC_MAIN where msrvc_module_name = ? and msrvc_name = ? ",
10347 &seqNum,
10348 &icss);
10349 if (status != 0 && status != CAT_NO_ROWS_FOUND) {
10350 rodsLog(LOG_NOTICE,
10351 "chlInsMsrvcTable cmlGetIntegerValueFromSqlV3 find MSRVC if any failure %d",status);
10352 return(status);
10353 }
10354 if (seqNum < 0) {
10355 seqNum = cmlGetNextSeqVal(&icss);
10356 if (seqNum < 0) {
10357 rodsLog(LOG_NOTICE, "chlInsMsrvcTable cmlGetNextSeqVal failure %d",
10358 seqNum);
10359 _rollback("chlInsMsrvcTable");
10360 return(seqNum);
10361 }
10362 snprintf(msrvcIdStr, MAX_NAME_LEN, "%lld", seqNum);
10363
10364 i=0;
10365 cllBindVars[i++]=msrvcIdStr;
10366 cllBindVars[i++]=msrvcName;
10367 cllBindVars[i++]=moduleName;
10368 cllBindVars[i++]=msrvcSignature;
10369 cllBindVars[i++]=rsComm->clientUser.userName;
10370 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10371 cllBindVars[i++]=myTime;
10372 cllBindVars[i++]=myTime;
10373 cllBindVarCount=i;
10374 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable SQL 2");
10375 status = cmlExecuteNoAnswerSql(
10376 "insert into R_MICROSRVC_MAIN(msrvc_id, msrvc_name, msrvc_module_name, msrvc_signature, msrvc_doxygen, msrvc_variations, msrvc_owner_name, msrvc_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, 'NONE', 'NONE', ?, ?, ?, ?)",
10377 &icss);
10378 if (status != 0) {
10379 rodsLog(LOG_NOTICE,
10380 "chlInsMsrvcTable cmlExecuteNoAnswerSql R_MICROSRVC_MAIN Insert failure %d",status);
10381 return(status);
10382 }
10383
10384 i=0;
10385 cllBindVars[i++]=msrvcIdStr;
10386 cllBindVars[i++]=msrvcVersion;
10387 cllBindVars[i++]=msrvcHost;
10388 cllBindVars[i++]=msrvcLocation;
10389 cllBindVars[i++]=msrvcLanguage;
10390 cllBindVars[i++]=msrvcTypeName;
10391 cllBindVars[i++]=msrvcStatus;
10392 cllBindVars[i++]=rsComm->clientUser.userName;
10393 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10394 cllBindVars[i++]=myTime;
10395 cllBindVars[i++]=myTime;
10396 cllBindVarCount=i;
10397 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable SQL 3");
10398 status = cmlExecuteNoAnswerSql(
10399 "insert into R_MICROSRVC_VER(msrvc_id, msrvc_version, msrvc_host, msrvc_location, msrvc_language, msrvc_type_name, msrvc_status, msrvc_owner_name, msrvc_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
10400 &icss);
10401 if (status != 0) {
10402 rodsLog(LOG_NOTICE,
10403 "chlInsMsrvcTable cmlExecuteNoAnswerSql R_MICROSRVC_VER Insert failure %d",status);
10404 return(status);
10405 }
10406 }
10407 else {
10408 snprintf(msrvcIdStr, MAX_NAME_LEN, "%lld", seqNum);
10409
10410 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable SQL 4");
10411 i=0;
10412 cllBindVars[i++]=msrvcIdStr;
10413 cllBindVars[i++]=msrvcHost;
10414 cllBindVars[i++]=msrvcLocation;
10415 cllBindVarCount=i;
10416 status = cmlGetIntegerValueFromSqlV3(
10417 "select msrvc_id from R_MICROSRVC_VER where msrvc_id = ? and msrvc_host = ? and msrvc_location = ? ",
10418 &seqNum, &icss);
10419 if (status != 0 && status != CAT_NO_ROWS_FOUND) {
10420 rodsLog(LOG_NOTICE,
10421 "chlInsMsrvcTable cmlGetIntegerValueFromSqlV4 find MSRVC_HOST if any failure %d",status);
10422 return(status);
10423 }
10424
10425 i=0;
10426 cllBindVars[i++]=msrvcIdStr;
10427 cllBindVars[i++]=msrvcVersion;
10428 cllBindVars[i++]=msrvcHost;
10429 cllBindVars[i++]=msrvcLocation;
10430 cllBindVars[i++]=msrvcLanguage;
10431 cllBindVars[i++]=msrvcTypeName;
10432 cllBindVars[i++]=rsComm->clientUser.userName;
10433 cllBindVars[i++]=rsComm->clientUser.rodsZone;
10434 cllBindVars[i++]=myTime;
10435 cllBindVars[i++]=myTime;
10436 cllBindVarCount=i;
10437 if (logSQL!=0) rodsLog(LOG_SQL, "chlInsMsrvcTable SQL 3");
10438 status = cmlExecuteNoAnswerSql(
10439 "insert into R_MICROSRVC_VER(msrvc_id, msrvc_version, msrvc_host, msrvc_location, msrvc_language, msrvc_type_name, msrvc_owner_name, msrvc_owner_zone, create_ts, modify_ts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
10440 &icss);
10441 if (status != 0) {
10442 rodsLog(LOG_NOTICE,
10443 "chlInsMsrvcTable cmlExecuteNoAnswerSql R_MICROSRVC_VER Insert failure %d",status);
10444 return(status);
10445 }
10446 }
10447
10448 return(0);
10449 }
10450
10451
10452
10453
10454
10455
10456
10457 int
10458 chlVersionRuleBase(rsComm_t *rsComm,
10459 char *baseName, char *myTime) {
10460
10461 int i, status;
10462
10463 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionRuleBase");
10464
10465 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10466 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10467 }
10468
10469 if (!icss.status) {
10470 return(CATALOG_NOT_CONNECTED);
10471 }
10472
10473 i=0;
10474 cllBindVars[i++]=myTime;
10475 cllBindVars[i++]=myTime;
10476 cllBindVars[i++]=baseName;
10477 cllBindVarCount=i;
10478 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionRuleBase SQL 1");
10479
10480 status = cmlExecuteNoAnswerSql(
10481 "update R_RULE_BASE_MAP set map_version = ?, modify_ts = ? where map_base_name = ? and map_version = '0'",&icss);
10482 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
10483 rodsLog(LOG_NOTICE,
10484 "chlVersionRuleBase cmlExecuteNoAnswerSql Rule Map version update failure %d" , status);
10485 return(status);
10486
10487 }
10488
10489 return(0);
10490 }
10491
10492
10493
10494
10495
10496
10497
10498 int
10499 chlVersionDvmBase(rsComm_t *rsComm,
10500 char *baseName, char *myTime) {
10501 int i, status;
10502
10503 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionDvmBase");
10504
10505 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10506 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10507 }
10508
10509 if (!icss.status) {
10510 return(CATALOG_NOT_CONNECTED);
10511 }
10512
10513 i=0;
10514 cllBindVars[i++]=myTime;
10515 cllBindVars[i++]=myTime;
10516 cllBindVars[i++]=baseName;
10517 cllBindVarCount=i;
10518 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionDvmBase SQL 1");
10519
10520 status = cmlExecuteNoAnswerSql(
10521 "update R_RULE_DVM_MAP set map_dvm_version = ?, modify_ts = ? where map_dvm_base_name = ? and map_dvm_version = '0'",&icss);
10522 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
10523 rodsLog(LOG_NOTICE,
10524 "chlVersionDvmBase cmlExecuteNoAnswerSql DVM Map version update failure %d" , status);
10525 return(status);
10526
10527 }
10528
10529 return(0);
10530 }
10531
10532
10533
10534
10535
10536
10537
10538 int
10539 chlVersionFnmBase(rsComm_t *rsComm,
10540 char *baseName, char *myTime) {
10541
10542 int i, status;
10543
10544 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionFnmBase");
10545
10546 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10547 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10548 }
10549
10550 if (!icss.status) {
10551 return(CATALOG_NOT_CONNECTED);
10552 }
10553
10554 i=0;
10555 cllBindVars[i++]=myTime;
10556 cllBindVars[i++]=myTime;
10557 cllBindVars[i++]=baseName;
10558 cllBindVarCount=i;
10559 if (logSQL!=0) rodsLog(LOG_SQL, "chlVersionFnmBase SQL 1");
10560
10561 status = cmlExecuteNoAnswerSql(
10562 "update R_RULE_FNM_MAP set map_fnm_version = ?, modify_ts = ? where map_fnm_base_name = ? and map_fnm_version = '0'",&icss);
10563 if (status != 0 && status != CAT_SUCCESS_BUT_WITH_NO_INFO) {
10564 rodsLog(LOG_NOTICE,
10565 "chlVersionFnmBase cmlExecuteNoAnswerSql FNM Map version update failure %d" , status);
10566 return(status);
10567
10568 }
10569
10570 return(0);
10571 }
10572
10573
10574
10575
10576
10577
10578
10579 int
10580 icatCheckResc(char *rescName) {
10581 int status;
10582 rodsLong_t rescId;
10583 status = getLocalZone();
10584 if (status != 0) return(status);
10585
10586 rescId=0;
10587 if (logSQL!=0) rodsLog(LOG_SQL, "icatCheckResc SQxL 1");
10588 status = cmlGetIntegerValueFromSql(
10589 "select resc_id from R_RESC_MAIN where resc_name=? and zone_name=?",
10590 &rescId, rescName, localZone, 0, 0, 0, &icss);
10591 if (status != 0) {
10592 if (status==CAT_NO_ROWS_FOUND) return(CAT_INVALID_RESOURCE);
10593 _rollback("icatCheckResc");
10594 }
10595 return(status);
10596 }
10597
10598 int
10599 chlAddSpecificQuery(rsComm_t *rsComm, char *sql, char *alias) {
10600 int status, i;
10601 char myTime[50];
10602 char tsCreateTime[50];
10603 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddSpecificQuery");
10604
10605 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10606 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10607 }
10608
10609 if (strlen(sql) < 5) {
10610 return(CAT_INVALID_ARGUMENT);
10611 }
10612
10613 if (!icss.status) {
10614 return(CATALOG_NOT_CONNECTED);
10615 }
10616
10617 getNowStr(myTime);
10618
10619 if (alias != NULL && strlen(alias)>0) {
10620 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddSpecificQuery SQL 1");
10621 status = cmlGetStringValueFromSql(
10622 "select create_ts from R_SPECIFIC_QUERY where alias=?",
10623 tsCreateTime, 50,
10624 alias, "" , "", &icss);
10625 if (status==0) {
10626 i = addRErrorMsg (&rsComm->rError, 0, "Alias is not unique");
10627 return(CAT_INVALID_ARGUMENT);
10628 }
10629 i=0;
10630 cllBindVars[i++]=sql;
10631 cllBindVars[i++]=alias;
10632 cllBindVars[i++]=myTime;
10633 cllBindVarCount=i;
10634 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddSpecificQuery SQL 2");
10635 status = cmlExecuteNoAnswerSql(
10636 "insert into R_SPECIFIC_QUERY (sqlStr, alias, create_ts) values (?, ?, ?)",
10637 &icss);
10638 }
10639 else {
10640 i=0;
10641 cllBindVars[i++]=sql;
10642 cllBindVars[i++]=myTime;
10643 cllBindVarCount=i;
10644 if (logSQL!=0) rodsLog(LOG_SQL, "chlAddSpecificQuery SQL 3");
10645 status = cmlExecuteNoAnswerSql(
10646 "insert into R_SPECIFIC_QUERY (sqlStr, create_ts) values (?, ?)",
10647 &icss);
10648 }
10649
10650 if (status != 0) {
10651 rodsLog(LOG_NOTICE,
10652 "chlAddSpecificQuery cmlExecuteNoAnswerSql insert failure %d",
10653 status);
10654 return(status);
10655 }
10656
10657 status = cmlExecuteNoAnswerSql("commit", &icss);
10658 return(status);
10659 }
10660
10661 int
10662 chlDelSpecificQuery(rsComm_t *rsComm, char *sqlOrAlias) {
10663 int status, i;
10664 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelSpecificQuery");
10665
10666 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10667 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10668 }
10669
10670 if (!icss.status) {
10671 return(CATALOG_NOT_CONNECTED);
10672 }
10673
10674 i=0;
10675 cllBindVars[i++]=sqlOrAlias;
10676 cllBindVarCount=i;
10677 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelSpecificQuery SQL 1");
10678 status = cmlExecuteNoAnswerSql(
10679 "delete from R_SPECIFIC_QUERY where sqlStr = ?",
10680 &icss);
10681
10682 if (status==CAT_SUCCESS_BUT_WITH_NO_INFO) {
10683 if (logSQL!=0) rodsLog(LOG_SQL, "chlDelSpecificQuery SQL 2");
10684 i=0;
10685 cllBindVars[i++]=sqlOrAlias;
10686 cllBindVarCount=i;
10687 status = cmlExecuteNoAnswerSql(
10688 "delete from R_SPECIFIC_QUERY where alias = ?",
10689 &icss);
10690 }
10691
10692 if (status != 0) {
10693 rodsLog(LOG_NOTICE,
10694 "chlDelSpecificQuery cmlExecuteNoAnswerSql delete failure %d",
10695 status);
10696 return(status);
10697 }
10698
10699 status = cmlExecuteNoAnswerSql("commit", &icss);
10700 return(status);
10701 }
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711 #define MINIMUM_COL_SIZE 50
10712
10713 int
10714 chlSpecificQuery(specificQueryInp_t specificQueryInp, genQueryOut_t *result) {
10715 int i, j, k;
10716 int needToGetNextRow;
10717
10718 char combinedSQL[MAX_SQL_SIZE];
10719
10720 int status, statementNum;
10721 int numOfCols;
10722 int attriTextLen;
10723 int totalLen;
10724 int maxColSize;
10725 int currentMaxColSize;
10726 char *tResult, *tResult2;
10727 char tsCreateTime[50];
10728
10729 int debug=0;
10730
10731 icatSessionStruct *icss;
10732
10733 if (logSQL!=0) rodsLog(LOG_SQL, "chlSpecificQuery");
10734
10735 result->attriCnt=0;
10736 result->rowCnt=0;
10737 result->totalRowCount = 0;
10738
10739 currentMaxColSize=0;
10740
10741 icss = chlGetRcs();
10742 if (icss==NULL) return(CAT_NOT_OPEN);
10743 #ifdef ADDR_64BITS
10744 if (debug) printf("icss=%ld\n",(long int)icss);
10745 #else
10746 if (debug) printf("icss=%d\n",(int)icss);
10747 #endif
10748
10749 if (specificQueryInp.continueInx == 0) {
10750 if (specificQueryInp.sql == NULL) {
10751 return(CAT_INVALID_ARGUMENT);
10752 }
10753
10754
10755
10756 if (logSQL!=0) rodsLog(LOG_SQL, "chlSpecificQuery SQL 1");
10757 status = cmlGetStringValueFromSql(
10758 "select create_ts from R_SPECIFIC_QUERY where sqlStr=?",
10759 tsCreateTime, 50,
10760 specificQueryInp.sql, "" , "", icss);
10761 if (status == CAT_NO_ROWS_FOUND) {
10762 int status2;
10763 if (logSQL!=0) rodsLog(LOG_SQL, "chlSpecificQuery SQL 2");
10764 status2 = cmlGetStringValueFromSql(
10765 "select sqlStr from R_SPECIFIC_QUERY where alias=?",
10766 combinedSQL, sizeof(combinedSQL),
10767 specificQueryInp.sql, "" , "", icss);
10768 if (status2 == CAT_NO_ROWS_FOUND) return(CAT_UNKNOWN_SPECIFIC_QUERY);
10769 if (status2 != 0) return(status2);
10770 }
10771 else {
10772 if (status != 0) return(status);
10773 strncpy(combinedSQL, specificQueryInp.sql, sizeof(combinedSQL));
10774 }
10775
10776 i=0;
10777 while (specificQueryInp.args[i]!=NULL && strlen(specificQueryInp.args[i])>0) {
10778 cllBindVars[cllBindVarCount++]=specificQueryInp.args[i++];
10779 }
10780
10781 if (logSQL!=0) rodsLog(LOG_SQL, "chlSpecificQuery SQL 3");
10782 status = cmlGetFirstRowFromSql(combinedSQL, &statementNum,
10783 specificQueryInp.rowOffset, icss);
10784 if (status < 0) {
10785 if (status != CAT_NO_ROWS_FOUND) {
10786 rodsLog(LOG_NOTICE,
10787 "chlSpecificQuery cmlGetFirstRowFromSql failure %d",
10788 status);
10789 }
10790 return(status);
10791 }
10792
10793 result->continueInx = statementNum+1;
10794 if (debug) printf("statement number =%d\n", statementNum);
10795 needToGetNextRow = 0;
10796 }
10797 else {
10798 statementNum = specificQueryInp.continueInx-1;
10799 needToGetNextRow = 1;
10800 if (specificQueryInp.maxRows<=0) {
10801 status = cmlFreeStatement(statementNum, icss);
10802 return(status);
10803 }
10804 }
10805 for (i=0;i<specificQueryInp.maxRows;i++) {
10806 if (needToGetNextRow) {
10807 status = cmlGetNextRowFromStatement(statementNum, icss);
10808 if (status == CAT_NO_ROWS_FOUND) {
10809 cmlFreeStatement(statementNum, icss);
10810 result->continueInx=0;
10811 if (result->rowCnt==0) return(status);
10812
10813 return(0);
10814 }
10815 if (status < 0) return(status);
10816 }
10817 needToGetNextRow = 1;
10818
10819 result->rowCnt++;
10820 if (debug) printf("result->rowCnt=%d\n", result->rowCnt);
10821 numOfCols = icss->stmtPtr[statementNum]->numOfCols;
10822 if (debug) printf("numOfCols=%d\n",numOfCols);
10823 result->attriCnt=numOfCols;
10824 result->continueInx = statementNum+1;
10825
10826 maxColSize=0;
10827
10828 for (k=0;k<numOfCols;k++) {
10829 j = strlen(icss->stmtPtr[statementNum]->resultValue[k]);
10830 if (maxColSize <= j) maxColSize=j;
10831 }
10832 maxColSize++;
10833 if (maxColSize < MINIMUM_COL_SIZE) {
10834 maxColSize=MINIMUM_COL_SIZE;
10835 }
10836 if (debug) printf("maxColSize=%d\n",maxColSize);
10837
10838 if (i==0) {
10839 attriTextLen= numOfCols * maxColSize;
10840 if (debug) printf("attriTextLen=%d\n",attriTextLen);
10841 totalLen = attriTextLen * specificQueryInp.maxRows;
10842 for (j=0;j<numOfCols;j++) {
10843 tResult = (char *) malloc(totalLen);
10844 if (tResult==NULL) return(SYS_MALLOC_ERR);
10845 memset(tResult, 0, totalLen);
10846 result->sqlResult[j].attriInx = 0;
10847
10848
10849 result->sqlResult[j].len = maxColSize;
10850 result->sqlResult[j].value = tResult;
10851 }
10852 currentMaxColSize = maxColSize;
10853 }
10854
10855
10856
10857
10858
10859
10860 if (maxColSize > currentMaxColSize) {
10861 maxColSize += MINIMUM_COL_SIZE;
10862
10863 if (debug) printf("Bumping %d to %d\n",
10864 currentMaxColSize, maxColSize);
10865 attriTextLen= numOfCols * maxColSize;
10866 if (debug) printf("attriTextLen=%d\n",attriTextLen);
10867 totalLen = attriTextLen * specificQueryInp.maxRows;
10868 for (j=0;j<numOfCols;j++) {
10869 char *cp1, *cp2;
10870 int k;
10871 tResult = (char *) malloc(totalLen);
10872 if (tResult==NULL) return(SYS_MALLOC_ERR);
10873 memset(tResult, 0, totalLen);
10874 cp1 = result->sqlResult[j].value;
10875 cp2 = tResult;
10876 for (k=0;k<result->rowCnt;k++) {
10877 strncpy(cp2, cp1, result->sqlResult[j].len);
10878 cp1 += result->sqlResult[j].len;
10879 cp2 += maxColSize;
10880 }
10881 free(result->sqlResult[j].value);
10882 result->sqlResult[j].len = maxColSize;
10883 result->sqlResult[j].value = tResult;
10884 }
10885 currentMaxColSize = maxColSize;
10886 }
10887
10888
10889
10890 for (j=0;j<numOfCols;j++) {
10891 tResult2 = result->sqlResult[j].value;
10892 tResult2 += currentMaxColSize*(result->rowCnt-1);
10893
10894 strncpy(tResult2, icss->stmtPtr[statementNum]->resultValue[j],
10895 currentMaxColSize);
10896 }
10897
10898 }
10899
10900 result->continueInx=statementNum+1;
10901
10902 return(0);
10903
10904 }
10905
10906
10907
10908
10909
10910
10911
10912 int chlSubstituteResourceHierarchies(rsComm_t *rsComm, const char *old_hier, const char *new_hier) {
10913 int status = 0;
10914 char old_hier_partial[MAX_NAME_LEN];
10915 eirods::sql_logger logger("chlSubstituteResourceHierarchies", logSQL);
10916
10917 logger.log();
10918
10919
10920
10921 if (!icss.status) {
10922 return(CATALOG_NOT_CONNECTED);
10923 }
10924 if (!rsComm || !old_hier || !new_hier) {
10925 return(SYS_INTERNAL_NULL_INPUT_ERR);
10926 }
10927 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH || rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
10928 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
10929 }
10930
10931
10932
10933 snprintf(old_hier_partial, MAX_NAME_LEN, "%s%s%%", old_hier, eirods::hierarchy_parser::delimiter().c_str());
10934
10935
10936
10937 cllBindVars[cllBindVarCount++]=(char*)new_hier;
10938 cllBindVars[cllBindVarCount++]=(char*)old_hier;
10939 cllBindVars[cllBindVarCount++]=(char*)old_hier;
10940 cllBindVars[cllBindVarCount++]=old_hier_partial;
10941 #if ORA_ICAT // Oracle
10942 status = cmlExecuteNoAnswerSql("update R_DATA_MAIN set resc_hier = ? || substr(resc_hier, (length(?)+1)) where resc_hier = ? or resc_hier like ?", &icss);
10943 #else // Postgres and MySQL
10944 status = cmlExecuteNoAnswerSql("update R_DATA_MAIN set resc_hier = ? || substring(resc_hier from (char_length(?)+1)) where resc_hier = ? or resc_hier like ?", &icss);
10945 #endif
10946
10947
10948 if (status == CAT_SUCCESS_BUT_WITH_NO_INFO) {
10949 return 0;
10950 }
10951
10952
10953
10954 if (status < 0) {
10955 std::stringstream ss;
10956 ss << "chlSubstituteResourceHierarchies: cmlExecuteNoAnswerSql update failure " << status;
10957 eirods::log(LOG_NOTICE, ss.str());
10958 _rollback("chlSubstituteResourceHierarchies");
10959 }
10960
10961 return status;
10962 }
10963
10964
10965
10966
10967 int chlGetDistinctDataObjCountOnResource(
10968 const std::string& _resc_name,
10969 long long& _count ) {
10970
10971
10972 char query[ MAX_NAME_LEN ];
10973 std::string base_query = "select count(distinct data_id) from r_data_main where resc_hier like '%s;%s' or resc_hier like '%s;%s;%s' or resc_hier like '%s;%s';";
10974 sprintf(
10975 query,
10976 base_query.c_str(),
10977 _resc_name.c_str(), "%",
10978 "%", _resc_name.c_str(), "%",
10979 "%", _resc_name.c_str() );
10980
10981
10982
10983 int statement_num = 0;
10984 int status = cmlGetFirstRowFromSql(
10985 query,
10986 &statement_num,
10987 0, &icss );
10988 if( status != 0 ) {
10989 return status;
10990 }
10991
10992 _count = atol( icss.stmtPtr[ statement_num ]->resultValue[0] );
10993
10994 return 0;
10995
10996 }
10997
10998
10999
11000
11001
11002 int chlGetDistinctDataObjsMissingFromChildGivenParent(
11003 const std::string& _parent,
11004 const std::string& _child,
11005 int _limit,
11006 dist_child_result_t& _results ) {
11007
11008
11009 char query[ MAX_NAME_LEN ];
11010 std::string base_query = "select distinct data_id from r_data_main where resc_hier like '%s;%s' or resc_hier like '%s;%s;%s' or resc_hier like '%s;%s' except ( select distinct data_id from r_data_main where resc_hier like '%s;%s' or resc_hier like '%s;%s;%s' or resc_hier like '%s;%s' ) limit %d;";
11011 sprintf(
11012 query,
11013 base_query.c_str(),
11014 _parent.c_str(), "%",
11015 "%", _parent.c_str(), "%",
11016 "%", _parent.c_str(),
11017 _child.c_str(), "%",
11018 "%", _child.c_str(), "%",
11019 "%", _child.c_str(),
11020 _limit );
11021
11022
11023
11024 int statement_num = 0;
11025
11026
11027
11028 for( int i = 0; ; i++ ) {
11029
11030
11031 int status = 0;
11032 if( 0 == i ) {
11033 status = cmlGetFirstRowFromSql(
11034 query,
11035 &statement_num,
11036 0, &icss );
11037 } else {
11038 status = cmlGetNextRowFromStatement( statement_num, &icss );
11039 }
11040
11041 if ( status != 0 ) {
11042 return status;
11043 }
11044
11045 _results.push_back( atoi( icss.stmtPtr[ statement_num ]->resultValue[0] ) );
11046
11047 }
11048
11049 cmlFreeStatement( statement_num, &icss );
11050
11051 return 0;
11052
11053 }
11054
11055
11056
11057
11058 int chlGetHierarchyForResc(const std::string& resc_name, const std::string& zone_name, std::string& hierarchy) {
11059 char *current_node;
11060 char parent[MAX_NAME_LEN];
11061 int status;
11062
11063
11064 eirods::sql_logger logger("chlGetHierarchyForResc", logSQL);
11065 logger.log();
11066
11067 if (!icss.status) {
11068 return(CATALOG_NOT_CONNECTED);
11069 }
11070
11071 hierarchy = resc_name;
11072
11073 current_node = (char *)resc_name.c_str();
11074 while (current_node) {
11075
11076 status = cmlGetStringValueFromSql("select resc_parent from R_RESC_MAIN where resc_name=? and zone_name=?",
11077 parent, MAX_NAME_LEN, current_node, zone_name.c_str(), NULL, &icss);
11078
11079 if (status == CAT_NO_ROWS_FOUND) {
11080 return CAT_UNKNOWN_RESOURCE;
11081 }
11082
11083 if (status < 0) {
11084 return status;
11085 }
11086
11087 if (strlen(parent)) {
11088 hierarchy = parent + eirods::hierarchy_parser::delimiter() + hierarchy;
11089 current_node = parent;
11090 }
11091 else {
11092 current_node = NULL;
11093 }
11094 }
11095
11096 return 0;
11097 }
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114