int isData(rsComm_t *rsComm, char *objName, rodsLong_t *dataId) { char logicalEndName[MAX_NAME_LEN]{}; char logicalParentDirName[MAX_NAME_LEN]{}; auto status{splitPathByKey(objName, logicalParentDirName, MAX_NAME_LEN, logicalEndName, MAX_NAME_LEN, '/')}; if (status < 0) { const auto err{ERROR(status, (boost::format("splitPathByKey failed for [%s]") % objName).str().c_str())}; irods::log(err); return err.code(); } genQueryInp_t genQueryInp{}; genQueryOut_t *genQueryOut{}; char tmpStr[MAX_NAME_LEN]{}; memset(&genQueryInp, 0, sizeof(genQueryInp_t)); snprintf(tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal(&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); addInxIval(&genQueryInp.selectInp, COL_D_DATA_ID, 1); snprintf(tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal(&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval(&genQueryInp.selectInp, COL_COLL_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut); if (status < 0) { freeGenQueryOut(&genQueryOut); clearGenQueryInp(&genQueryInp); return status; } sqlResult_t *dataIdRes{getSqlResultByInx(genQueryOut, COL_D_DATA_ID)}; if (NULL == dataIdRes) { const auto err{ERROR(UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_D_DATA_ID failed")}; irods::log(err); return err.code(); } if (NULL != dataId) { *dataId = strtoll(dataIdRes->value, 0, 0); } freeGenQueryOut(&genQueryOut); clearGenQueryInp(&genQueryInp); return status; }
int readICatUserInfo( char *userName, char *attr, char userInfo[MAX_NAME_LEN], rsComm_t *rsComm ) { int status; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char condstr[MAX_NAME_LEN]; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); genQueryInp.maxRows = MAX_SQL_ROWS; snprintf( condstr, MAX_NAME_LEN, "= '%s'", userName ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condstr ); snprintf( condstr, MAX_NAME_LEN, "= '%s'", attr ); addInxVal( &genQueryInp.sqlCondInp, COL_META_USER_ATTR_NAME, condstr ); addInxIval( &genQueryInp.selectInp, COL_META_USER_ATTR_VALUE, 1 ); status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); userInfo[0] = '\0'; if ( status >= 0 && genQueryOut->rowCnt > 0 ) { if ( sqlResult_t *r = getSqlResultByInx( genQueryOut, COL_META_USER_ATTR_VALUE ) ) { rstrcpy( userInfo, &r->value[0], MAX_NAME_LEN ); } genQueryInp.continueInx = genQueryOut->continueInx; } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return status; }
int checkPermitForResource( rsComm_t *rsComm, char *objName, int userId, int operId ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char t1[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char t2[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char t4[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds int status; snprintf( t1, MAX_NAME_LEN, " = '%s'", objName ); snprintf( t2, MAX_NAME_LEN, " = '%i'", userId ); snprintf( t4, MAX_NAME_LEN, " >= '%i' ", operId ); memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 ); addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, t1 ); addInxVal( &genQueryInp.sqlCondInp, COL_RESC_ACCESS_USER_ID, t2 ); addInxVal( &genQueryInp.sqlCondInp, COL_RESC_ACCESS_TYPE, t4 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { freeGenQueryOut( &genQueryOut ); return 1; } else { return 0; } }
int getQuotaByResc( rsComm_t *rsComm, char *userName, char *rescName, genQueryOut_t **genQueryOut ) { int status; genQueryInp_t genQueryInp; char condition1[MAX_NAME_LEN]; char condition2[MAX_NAME_LEN]; if ( genQueryOut == NULL ) { return USER__NULL_INPUT_ERR; } *genQueryOut = NULL; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); genQueryInp.options = QUOTA_QUERY; snprintf( condition1, MAX_NAME_LEN, "%s", userName ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condition1 ); if ( rescName != NULL && strlen( rescName ) > 0 ) { snprintf( condition2, MAX_NAME_LEN, "%s", rescName ); addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condition2 ); } genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, genQueryOut ); clearGenQueryInp( &genQueryInp ); return status; }
int isColl( rsComm_t *rsComm, char *objName, rodsLong_t *collId ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", objName ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { sqlResult_t *collIdRes; if ( ( collIdRes = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "isColl: getSqlResultByInx for COL_D_DATA_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( collId != NULL ) { *collId = strtoll( collIdRes->value, 0, 0 ); } freeGenQueryOut( &genQueryOut ); } clearGenQueryInp( &genQueryInp ); return status; }
int getTokenId(rsComm_t *rsComm, char *tokenNameSpace, char *tokenName) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char tmpStr2[MAX_NAME_LEN]; int status; memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, NAME_LEN, "='%s'", tokenNameSpace); snprintf (tmpStr2, NAME_LEN, "='%s'", tokenName); addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, tmpStr); addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAME, tmpStr2); addInxIval (&genQueryInp.selectInp, COL_TOKEN_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); clearGenQueryInp (&genQueryInp); if (status >= 0) { sqlResult_t *tokenIdRes; if ((tokenIdRes = getSqlResultByInx (genQueryOut, COL_TOKEN_ID)) == NULL) { rodsLog (LOG_ERROR, "getTokenId: getSqlResultByInx for COL_TOKEN_ID failed"); freeGenQueryOut (&genQueryOut); return (UNMATCHED_KEY_OR_INDEX); } status = atoi(tokenIdRes->value); freeGenQueryOut (&genQueryOut); } return(status); }
int checkCollExists( rcComm_t *conn, rodsArguments_t *myRodsArgs, const char *collPath ) { int status; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char condStr[MAX_NAME_LEN]; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); genQueryInp.maxRows = 0; genQueryInp.options = AUTO_CLOSE; snprintf( condStr, MAX_NAME_LEN, "='%s'", collPath ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); status = rcGenQuery( conn, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); if ( status == CAT_NO_ROWS_FOUND ) { return 0; } else { return 1; } }
int getReInfoById( rsComm_t *rsComm, char *ruleExecId, genQueryOut_t **genQueryOut ) { genQueryInp_t genQueryInp; char tmpStr[NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ID, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_REI_FILE_PATH, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_USER_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ADDRESS, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_FREQUENCY, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_PRIORITY, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ESTIMATED_EXE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_NOTIFICATION_ADDR, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_LAST_EXE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_STATUS, 1 ); snprintf( tmpStr, NAME_LEN, "='%s'", ruleExecId ); addInxVal( &genQueryInp.sqlCondInp, COL_RULE_EXEC_ID, tmpStr ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, genQueryOut ); clearGenQueryInp( &genQueryInp ); return status; }
int getUserId( rsComm_t *rsComm, char *userName, char *zoneName ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char tmpStr2[MAX_NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); snprintf( tmpStr, NAME_LEN, "='%s'", userName ); snprintf( tmpStr2, NAME_LEN, "='%s'", zoneName ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_ZONE, tmpStr2 ); addInxIval( &genQueryInp.selectInp, COL_USER_ID, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { sqlResult_t *userIdRes; if ( ( userIdRes = getSqlResultByInx( genQueryOut, COL_USER_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "getUserId: getSqlResultByInx for COL_USER_ID failed" ); freeGenQueryOut( &genQueryOut ); return UNMATCHED_KEY_OR_INDEX; } status = atoi( userIdRes->value ); freeGenQueryOut( &genQueryOut ); } return status; }
int checkPermitForDataObject( rsComm_t *rsComm, char *objName, int userId, int operId ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char t1[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char t11[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char t2[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char t3[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds char logicalEndName[MAX_NAME_LEN]; char logicalParentDirName[MAX_NAME_LEN]; int status; splitPathByKey( objName, logicalParentDirName, MAX_NAME_LEN, logicalEndName, MAX_NAME_LEN, '/' ); snprintf( t1, MAX_NAME_LEN, " = '%s'", logicalEndName ); snprintf( t11, MAX_NAME_LEN, " = '%s'", logicalParentDirName ); snprintf( t2, MAX_NAME_LEN, " = '%i'", userId ); snprintf( t3, MAX_NAME_LEN, " >= '%i' ", operId ); memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); addInxIval( &genQueryInp.selectInp, COL_D_DATA_ID, 1 ); addInxVal( &genQueryInp.sqlCondInp, COL_DATA_NAME, t1 ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, t11 ); addInxVal( &genQueryInp.sqlCondInp, COL_DATA_ACCESS_USER_ID, t2 ); addInxVal( &genQueryInp.sqlCondInp, COL_DATA_ACCESS_TYPE, t3 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); freeGenQueryOut( &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { return 1; } else { return 0; } }
int qdelUtil( rcComm_t *conn, char *userName, int allFlag, rodsArguments_t *myRodsArgs ) { genQueryInp_t genQueryInp; int status, i, continueInx; char tmpStr[MAX_NAME_LEN]; sqlResult_t *execId; char *execIdStr; genQueryOut_t *genQueryOut = NULL; int savedStatus = 0; if ( allFlag == 1 && userName != NULL ) { rodsLog( LOG_ERROR, "qdelUtil: all(-a) and user(-u) cannot be used together" ); return USER_INPUT_OPTION_ERR; } memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); if ( userName != NULL ) { snprintf( tmpStr, MAX_NAME_LEN, " = '%s'", userName ); addInxVal( &genQueryInp.sqlCondInp, COL_RULE_EXEC_USER_NAME, tmpStr ); } addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ID, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; continueInx = 1; /* a fake one so it will do the first query */ while ( continueInx > 0 ) { status = rcGenQuery( conn, &genQueryInp, &genQueryOut ); if ( status < 0 ) { if ( status != CAT_NO_ROWS_FOUND ) { savedStatus = status; } break; } if ( ( execId = getSqlResultByInx( genQueryOut, COL_RULE_EXEC_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "qdelUtil: getSqlResultByInx for COL_RULE_EXEC_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { execIdStr = &execId->value[execId->len * i]; if ( myRodsArgs->verbose ) { printf( "Deleting %s\n", execIdStr ); } status = rmDelayedRule( execIdStr ); if ( status < 0 ) { rodsLog( LOG_ERROR, "qdelUtil: rmDelayedRule %s error. status = %d", execIdStr, status ); savedStatus = status; } } continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut( &genQueryOut ); } clearGenQueryInp( &genQueryInp ); return savedStatus; }
// =-=-=-=-=-=-=- // JMC - backport 4552 int getNumSubfilesInBunfileObj( rsComm_t *rsComm, char *objPath ) { int status; genQueryOut_t *genQueryOut = NULL; genQueryInp_t genQueryInp; int totalRowCount; char condStr[MAX_NAME_LEN]; bzero( &genQueryInp, sizeof( genQueryInp ) ); genQueryInp.maxRows = 1; genQueryInp.options = RETURN_TOTAL_ROW_COUNT; snprintf( condStr, MAX_NAME_LEN, "='%s'", objPath ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr ); snprintf( condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS ); addInxVal( &genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr ); addKeyVal( &genQueryInp.condInput, ZONE_KW, objPath ); addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_DATA_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, 1 ); status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( genQueryOut == NULL || status < 0 ) { freeGenQueryOut( &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status == CAT_NO_ROWS_FOUND ) { return 0; } else { return status; } } totalRowCount = genQueryOut->totalRowCount; freeGenQueryOut( &genQueryOut ); /* clear result */ genQueryInp.maxRows = 0; rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); return totalRowCount; }
/* checkDupReplica - Check if a given object with a given rescName * and physical path already exist. If it does, returns the replNum. * JMC - backport 4497 */ int checkDupReplica( rsComm_t *rsComm, rodsLong_t dataId, char *rescName, char *filePath ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; if ( rsComm == NULL || rescName == NULL || filePath == NULL ) { return USER__NULL_INPUT_ERR; } bzero( &genQueryInp, sizeof( genQueryInp_t ) ); rodsLong_t resc_id; irods::error ret = resc_mgr.hier_to_leaf_id(rescName,resc_id); if(!ret.ok()) { irods::log(PASS(ret)); return ret.code(); } std::string resc_id_str = boost::lexical_cast<std::string>(resc_id); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", resc_id_str.c_str() ); addInxVal( &genQueryInp.sqlCondInp, COL_D_RESC_ID, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", filePath ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%lld'", dataId ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_DATA_REPL_NUM, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { int intReplNum; sqlResult_t *replNum; if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) == NULL ) { freeGenQueryOut( &genQueryOut ); rodsLog( LOG_ERROR, "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed" ); return UNMATCHED_KEY_OR_INDEX; } intReplNum = atoi( replNum->value ); freeGenQueryOut( &genQueryOut ); return intReplNum; } else { freeGenQueryOut( &genQueryOut ); return status; } }
int checkCollIsEmpty( rcComm_t *conn, rodsArguments_t *myRodsArgs, const char *collPath ) { int status; genQueryInp_t genQueryInp1, genQueryInp2; genQueryOut_t *genQueryOut1 = NULL, *genQueryOut2 = NULL; int noDataFound = 0; int noCollFound = 0; char condStr[MAX_NAME_LEN]; memset( &genQueryInp1, 0, sizeof( genQueryInp1 ) ); memset( &genQueryInp2, 0, sizeof( genQueryInp2 ) ); snprintf( condStr, MAX_NAME_LEN, "select COLL_ID where COLL_NAME like '%s/%%'", collPath ); fillGenQueryInpFromStrCond( condStr, &genQueryInp1 ); status = rcGenQuery( conn, &genQueryInp1, &genQueryOut1 ); clearGenQueryInp( &genQueryInp1 ); freeGenQueryOut( &genQueryOut1 ); if ( status == CAT_NO_ROWS_FOUND ) { noCollFound = 1; } snprintf( condStr, MAX_NAME_LEN, "select DATA_ID where COLL_NAME like '%s%%'", collPath ); fillGenQueryInpFromStrCond( condStr, &genQueryInp2 ); status = rcGenQuery( conn, &genQueryInp2, &genQueryOut2 ); clearGenQueryInp( &genQueryInp2 ); freeGenQueryOut( &genQueryOut2 ); if ( status == CAT_NO_ROWS_FOUND ) { noDataFound = 1; } return ( noDataFound && noCollFound ); }
/** * \fn msiCheckHostAccessControl (ruleExecInfo_t *rei) * * \brief This microservice sets the access control policy. It checks the * access control by host and user based on the the policy given in the * HostAccessControl file. * * \module core * * \since pre-2.1 * * \author Jean-Yves Nief * \date 2007-09 * * \note This microservice controls access to the iRODS service * based on the information in the host based access configuration file: * HOST_ACCESS_CONTROL_FILE * * \usage See clients/icommands/test/rules3.0/ * * \param[in,out] rei - The RuleExecInfo structure that is automatically * handled by the rule engine. The user does not include rei as a * parameter in the rule invocation. * * \DolVarDependence none * \DolVarModified none * \iCatAttrDependence none * \iCatAttrModified none * \sideeffect none * * \return integer * \retval 0 upon success * \pre N/A * \post N/A * \sa N/A **/ int msiCheckHostAccessControl( ruleExecInfo_t *rei ) { char group[MAX_NAME_LEN], *hostclient, *result, *username; char condstr[MAX_NAME_LEN]; int i, rc, status; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; rsComm_t *rsComm; RE_TEST_MACRO( " Calling msiCheckHostAccessControl" ) /* the above line is needed for loop back testing using irule -i option */ group[0] = '\0'; rsComm = rei->rsComm; /* retrieve user name */ username = rsComm->clientUser.userName; /* retrieve client IP address */ hostclient = inet_ntoa( rsComm->remoteAddr.sin_addr ); /* retrieve groups to which the user belong */ memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( condstr, MAX_NAME_LEN, "= '%s'", username ); addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condstr ); addInxIval( &genQueryInp.selectInp, COL_USER_GROUP_NAME, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { for ( i = 0; i < genQueryOut->rowCnt; i++ ) { result = genQueryOut->sqlResult[0].value; result += i * genQueryOut->sqlResult[0].len; strcat( group, result ); strcat( group, " " ); } } else { rstrcpy( group, "all", MAX_NAME_LEN ); } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); rc = checkHostAccessControl( username, hostclient, group ); if ( rc < 0 ) { rodsLog( LOG_NOTICE, "Access to user %s from host %s has been refused.\n", username, hostclient ); rei->status = rc; } return rei->status; }
int isResc( rsComm_t *rsComm, char *objName ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[NAME_LEN]; int status; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); snprintf( tmpStr, NAME_LEN, "='%s'", objName ); addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); freeGenQueryOut( &genQueryOut ); clearGenQueryInp( &genQueryInp ); return status; }
/* checkDupReplica - Check if a given object with a given rescName * and physical path already exist. If it does, returns the replNum. * JMC - backport 4497 */ int checkDupReplica( rsComm_t *rsComm, rodsLong_t dataId, char *rescName, char *filePath ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; int status; if ( rsComm == NULL || rescName == NULL || filePath == NULL ) { return USER__NULL_INPUT_ERR; } bzero( &genQueryInp, sizeof( genQueryInp_t ) ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", rescName ); addInxVal( &genQueryInp.sqlCondInp, COL_D_RESC_NAME, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%s'", filePath ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr ); snprintf( tmpStr, MAX_NAME_LEN, "='%lld'", dataId ); addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr ); addInxIval( &genQueryInp.selectInp, COL_DATA_REPL_NUM, 1 ); genQueryInp.maxRows = 2; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { int intReplNum; sqlResult_t *replNum; if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) == NULL ) { rodsLog( LOG_ERROR, "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed" ); return UNMATCHED_KEY_OR_INDEX; } intReplNum = atoi( replNum->value ); freeGenQueryOut( &genQueryOut ); return intReplNum; } else { return status; } }
/* querySpecColl - The query can produce multiple answer and only one * is correct. e.g., objPath = /x/yabc can produce answers: * /x/y, /x/ya, /x/yabc, etc. The calling subroutine need to screen * /x/y, /x/ya out * check queueSpecCollCache () for screening. */ int querySpecColl( rsComm_t *rsComm, char *objPath, genQueryOut_t **genQueryOut ) { genQueryInp_t genQueryInp; int status; char condStr[MAX_NAME_LEN]; if ( HaveFailedSpecCollPath && strcmp( objPath, FailedSpecCollPath ) == 0 ) { return CAT_NO_ROWS_FOUND; } /* see if objPath is in the path of a spec collection */ memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( condStr, MAX_NAME_LEN, "parent_of '%s'", objPath ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); rstrcpy( condStr, "like '_%'", MAX_NAME_LEN ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_TYPE, condStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status < 0 ) { rstrcpy( FailedSpecCollPath, objPath, MAX_NAME_LEN ); HaveFailedSpecCollPath = 1; return status; } return 0; }
int isData (rsComm_t *rsComm, char *objName, rodsLong_t *dataId) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char logicalEndName[MAX_NAME_LEN]; char logicalParentDirName[MAX_NAME_LEN]; int status; status = splitPathByKey(objName, logicalParentDirName, logicalEndName, '/'); memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); if (status >= 0) { sqlResult_t *dataIdRes; if ((dataIdRes = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "isData: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } if (dataId != NULL) { *dataId = strtoll (dataIdRes->value, 0, 0); } freeGenQueryOut (&genQueryOut); } clearGenQueryInp (&genQueryInp); return(status); }
int checkCollAccessPerm( rsComm_t *rsComm, char *collection, char *accessPerm ) { char accStr[LONG_NAME_LEN]; char condStr[MAX_NAME_LEN]; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; if ( collection == NULL || accessPerm == NULL ) { return SYS_INTERNAL_NULL_INPUT_ERR; } memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName ); addKeyVal( &genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr ); snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone ); addKeyVal( &genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr ); snprintf( accStr, LONG_NAME_LEN, "%s", accessPerm ); addKeyVal( &genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr ); snprintf( condStr, MAX_NAME_LEN, "='%s'", collection ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status >= 0 ) { freeGenQueryOut( &genQueryOut ); } return status; }
int getPhyPath (rsComm_t *rsComm, char *objName, char *resource, char *phyPath) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char tmpStr[MAX_NAME_LEN]; char logicalEndName[MAX_NAME_LEN]; char logicalParentDirName[MAX_NAME_LEN]; int status; status = splitPathByKey(objName, logicalParentDirName, logicalEndName, '/'); memset (&genQueryInp, 0, sizeof (genQueryInp_t)); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr); snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_PATH, 1); genQueryInp.maxRows = 2; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); if (status >= 0) { sqlResult_t *phyPathRes = NULL; if ((phyPathRes = getSqlResultByInx (genQueryOut, COL_D_DATA_PATH)) == NULL) { rodsLog (LOG_ERROR, "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed"); return (UNMATCHED_KEY_OR_INDEX); } if (phyPath != NULL) { rstrcpy (phyPath, phyPathRes->value, MAX_NAME_LEN); } freeGenQueryOut (&genQueryOut); } clearGenQueryInp (&genQueryInp); return(status); }
int rodsMonPerfLog( char *serverName, char *resc, char *output, ruleExecInfo_t *rei ) { char condstr[MAX_NAME_LEN], fname[MAX_NAME_LEN], msg[MAX_MESSAGE_SIZE], monStatus[MAX_NAME_LEN], suffix[MAX_VALUE], *result; const char *delim1 = "#"; const char *delim2 = ","; int index, timestamp, rc1 = 0, rc2 = 0, rc3 = 0, rc4 = 0; FILE *foutput; time_t tps; generalRowInsertInp_t generalRowInsertInp; generalAdminInp_t generalAdminInp1, generalAdminInp2; genQueryInp_t genQueryInp; struct tm *now; genQueryOut_t *genQueryOut = NULL; tps = time( NULL ); now = localtime( &tps ); /* a quick test in order to see if the resource is up or down (needed to update the "status" metadata) */ if ( strcmp( output, MON_OUTPUT_NO_ANSWER ) == 0 ) { strncpy( monStatus, RESC_AUTO_DOWN, MAX_NAME_LEN ); } else { strncpy( monStatus, RESC_AUTO_UP, MAX_NAME_LEN ); } std::vector<std::string> output_tokens; boost::algorithm::split( output_tokens, output, boost::is_any_of( delim1 ) ); std::vector<std::string> resc_tokens; boost::algorithm::split( resc_tokens, resc, boost::is_any_of( delim2 ) ); std::vector<std::string> disk_tokens; boost::algorithm::split( disk_tokens, output_tokens[4], boost::is_any_of( delim2 ) ); std::vector<std::string> value_tokens; boost::algorithm::split( value_tokens, output_tokens[7], boost::is_any_of( delim2 ) ); index = 0; while ( !resc_tokens[index].empty() ) { if ( strcmp( monStatus, RESC_AUTO_DOWN ) == 0 ) { disk_tokens[index] = "-1"; value_tokens[index] = "-1"; } sprintf( msg, "server=%s resource=%s cpu=%s, mem=%s, swp=%s, rql=%s, dsk=%s, nin=%s, nout=%s, dskAv(MB)=%s\n", serverName, resc_tokens[index].c_str(), output_tokens[0].c_str(), output_tokens[1].c_str(), output_tokens[2].c_str(), output_tokens[3].c_str(), disk_tokens[index].c_str(), output_tokens[5].c_str(), output_tokens[6].c_str(), value_tokens[index].c_str() ); sprintf( suffix, "%d.%d.%d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday ); sprintf( fname, "%s.%s", OUTPUT_MON_PERF, suffix ); /* retrieve the system time */ timestamp = time( &tps ); /* log the result into the database as well */ generalRowInsertInp.tableName = "serverload"; generalRowInsertInp.arg1 = serverName; generalRowInsertInp.arg2 = resc_tokens[index].c_str(); generalRowInsertInp.arg3 = output_tokens[0].c_str(); generalRowInsertInp.arg4 = output_tokens[1].c_str(); generalRowInsertInp.arg5 = output_tokens[2].c_str(); generalRowInsertInp.arg6 = output_tokens[3].c_str(); generalRowInsertInp.arg7 = disk_tokens[index].c_str(); generalRowInsertInp.arg8 = output_tokens[5].c_str(); generalRowInsertInp.arg9 = output_tokens[6].c_str(); /* prepare DB request to modify resource metadata: freespace and status */ generalAdminInp1.arg0 = "modify"; generalAdminInp1.arg1 = "resource"; generalAdminInp1.arg2 = resc_tokens[index].c_str(); generalAdminInp1.arg3 = "freespace"; generalAdminInp1.arg4 = value_tokens[index].c_str(); generalAdminInp2.arg0 = "modify"; generalAdminInp2.arg1 = "resource"; generalAdminInp2.arg2 = resc_tokens[index].c_str(); generalAdminInp2.arg3 = "status"; generalAdminInp2.arg4 = monStatus; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_STATUS, 1 ); snprintf( condstr, MAX_NAME_LEN, "= '%s'", resc_tokens[index].c_str() ); addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condstr ); genQueryInp.maxRows = MAX_SQL_ROWS; #ifndef windows_platform pthread_mutex_lock( &my_mutex ); #endif /* append to the output log file */ foutput = fopen( fname, "a" ); if ( foutput != NULL ) { fprintf( foutput, "time=%i %s", timestamp, msg ); // fclose(foutput); // JMC cppcheck - nullptr // cannot close it here. it is used later - hcj } rc1 = rsGeneralRowInsert( rei->rsComm, &generalRowInsertInp ); rc2 = rsGeneralAdmin( rei->rsComm, &generalAdminInp1 ); rc3 = rsGenQuery( rei->rsComm, &genQueryInp, &genQueryOut ); if ( rc3 >= 0 ) { result = genQueryOut->sqlResult[0].value; if ( strcmp( result, "\0" ) == 0 || ( strncmp( result, "auto-", 5 ) == 0 && strcmp( result, monStatus ) != 0 ) ) { rc4 = rsGeneralAdmin( rei->rsComm, &generalAdminInp2 ); } } else { rodsLog( LOG_ERROR, "msiServerMonPerf: unable to retrieve the status metadata for the resource %s", resc_tokens[index].c_str() ); } #ifndef windows_platform pthread_mutex_unlock( &my_mutex ); #endif if ( foutput != NULL && rc1 != 0 ) { fprintf( foutput, "time=%i : unable to insert the entries for server %s into the iCAT\n", timestamp, serverName ); fclose( foutput ); } if ( rc2 != 0 ) { rodsLog( LOG_ERROR, "msiServerMonPerf: unable to register the free space metadata for the resource %s", resc_tokens[index].c_str() ); } if ( rc4 != 0 ) { rodsLog( LOG_ERROR, "msiServerMonPerf: unable to register the status metadata for the resource %s", resc_tokens[index].c_str() ); } index += 1; } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return 0; }
int getListOfResc( rsComm_t *rsComm, char serverList[MAX_VALUE][MAX_NAME_LEN], int nservers, monInfo_t monList[MAX_NSERVERS], int *nlist ) { /********************************************************** * search in the database, the list of resources with * * their associated server. If config file exist, restrict * * the list to serverList * ***********************************************************/ int i, j, k, index[MAX_NSERVERS], l, status; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; char condStr[MAX_NAME_LEN]; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); memset( &index, -1, MAX_NSERVERS * sizeof( int ) ); genQueryInp.maxRows = MAX_SQL_ROWS; //clearGenQueryInp( &genQueryInp ); addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 ); addInxVal( &genQueryInp.sqlCondInp, COL_R_LOC, "!='EMPTY_RESC_HOST'" ); addInxVal( &genQueryInp.sqlCondInp, COL_R_VAULT_PATH, "!='EMPTY_RESC_PATH'" ); snprintf( condStr, MAX_NAME_LEN, "!='%s'", BUNDLE_RESC ); addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condStr ); status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status < 0 ) { irods::log( ERROR( status, "rsGenQuery failed." ) ); } if ( genQueryOut->rowCnt > 0 ) { l = 0; for ( i = 0; i < genQueryOut->attriCnt; i++ ) { for ( j = 0; j < genQueryOut->rowCnt; j++ ) { char *tResult; tResult = genQueryOut->sqlResult[i].value; tResult += j * genQueryOut->sqlResult[i].len; switch ( i ) { case 0: if ( nservers >= 0 ) { for ( k = 0; k < nservers; k++ ) { if ( strcmp( serverList[k], tResult ) == 0 ) { index[j] = l; l++; } } } else { index[j] = l; l++; } if ( index[j] != -1 ) { rstrcpy( monList[index[j]].serverName, tResult, LONG_NAME_LEN ); } break; case 1: if ( index[j] != -1 ) { rstrcpy( monList[index[j]].rescName, tResult, MAX_NAME_LEN ); } break; case 2: if ( index[j] != -1 ) { rstrcpy( monList[index[j]].rescType, tResult, LONG_NAME_LEN ); } break; case 3: if ( index[j] != -1 ) { rstrcpy( monList[index[j]].vaultPath, tResult, LONG_NAME_LEN ); } break; } } } ( *nlist ) = l; clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return 0; } return -1; }
// =-=-=-=-=-=-=- // public - connect to the catalog and query for all the // attached resources and instantiate them error resource_manager::init_from_catalog( rsComm_t* _comm ) { // =-=-=-=-=-=-=- // clear existing resource map and initialize resources_.clear(); // =-=-=-=-=-=-=- // set up data structures for a gen query genQueryInp_t genQueryInp; genQueryOut_t* genQueryOut = NULL; error proc_ret; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_ZONE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_CLASS_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_FREE_SPACE, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_INFO, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_COMMENT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_CREATE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_MODIFY_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_STATUS, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_CHILDREN, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_CONTEXT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_PARENT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_OBJCOUNT, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; // =-=-=-=-=-=-=- // init continueInx to pass for first loop int continueInx = 1; // =-=-=-=-=-=-=- // loop until continuation is not requested while ( continueInx > 0 ) { // =-=-=-=-=-=-=- // perform the general query int status = rsGenQuery( _comm, &genQueryInp, &genQueryOut ); // =-=-=-=-=-=-=- // perform the general query if ( status < 0 ) { if ( status != CAT_NO_ROWS_FOUND ) { rodsLog( LOG_NOTICE, "initResc: rsGenQuery error, status = %d", status ); } clearGenQueryInp( &genQueryInp ); return ERROR( status, "genQuery failed." ); } // if // =-=-=-=-=-=-=- // given a series of rows, each being a resource, create a resource and add it to the table proc_ret = process_init_results( genQueryOut ); // =-=-=-=-=-=-=- // if error is not valid, clear query and bail if ( !proc_ret.ok() ) { irods::error log_err = PASSMSG( "init_from_catalog - process_init_results failed", proc_ret ); irods::log( log_err ); freeGenQueryOut( &genQueryOut ); break; } else { if ( genQueryOut != NULL ) { continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut( &genQueryOut ); } else { continueInx = 0; } } // else } // while clearGenQueryInp( &genQueryInp ); // =-=-=-=-=-=-=- // pass along the error if we are in an error state if ( !proc_ret.ok() ) { return PASSMSG( "process_init_results failed.", proc_ret ); } // =-=-=-=-=-=-=- // Update child resource maps proc_ret = init_child_map(); if ( !proc_ret.ok() ) { return PASSMSG( "init_child_map failed.", proc_ret ); } // =-=-=-=-=-=-=- // gather the post disconnect maintenance operations error op_ret = gather_operations(); if ( !op_ret.ok() ) { return PASSMSG( "gather_operations failed.", op_ret ); } // =-=-=-=-=-=-=- // initialize the special local file system resource // JMC :: no longer needed //error spec_ret = init_local_file_system_resource(); //if ( !spec_ret.ok() ) { // return PASSMSG( "init_local_file_system_resource failed.", op_ret ); //} // =-=-=-=-=-=-=- // call start for plugins error start_err = start_resource_plugins(); if ( !start_err.ok() ) { return PASSMSG( "start_resource_plugins failed.", start_err ); } // =-=-=-=-=-=-=- // win! return SUCCESS(); } // init_from_catalog
int initZone( rsComm_t *rsComm ) { rodsServerHost_t *tmpRodsServerHost; rodsServerHost_t *masterServerHost = NULL; rodsServerHost_t *slaveServerHost = NULL; genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status, i; sqlResult_t *zoneName, *zoneType, *zoneConn, *zoneComment; char *tmpZoneName, *tmpZoneType, *tmpZoneConn;//, *tmpZoneComment; irods::server_properties& props = irods::server_properties::getInstance(); irods::error ret = props.capture_if_needed(); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } std::string zone_name; ret = props.get_property < std::string > ( irods::CFG_ZONE_NAME, zone_name ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return ret.code(); } /* configure the local zone first or rsGenQuery would not work */ tmpRodsServerHost = ServerHostHead; while ( tmpRodsServerHost != NULL ) { if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) { tmpRodsServerHost->zoneInfo = ZoneInfoHead; masterServerHost = tmpRodsServerHost; } else if ( tmpRodsServerHost->rcatEnabled == LOCAL_SLAVE_ICAT ) { tmpRodsServerHost->zoneInfo = ZoneInfoHead; slaveServerHost = tmpRodsServerHost; } tmpRodsServerHost = tmpRodsServerHost->next; } ZoneInfoHead->masterServerHost = masterServerHost; ZoneInfoHead->slaveServerHost = slaveServerHost; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_ZONE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_TYPE, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_CONNECTION, 1 ); addInxIval( &genQueryInp.selectInp, COL_ZONE_COMMENT, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); clearGenQueryInp( &genQueryInp ); if ( status < 0 ) { freeGenQueryOut( &genQueryOut ); rodsLog( LOG_NOTICE, "initZone: rsGenQuery error, status = %d", status ); return status; } if ( genQueryOut == NULL ) { rodsLog( LOG_NOTICE, "initZone: NULL genQueryOut" ); return CAT_NO_ROWS_FOUND; } if ( ( zoneName = getSqlResultByInx( genQueryOut, COL_ZONE_NAME ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneType = getSqlResultByInx( genQueryOut, COL_ZONE_TYPE ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_TYPE failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneConn = getSqlResultByInx( genQueryOut, COL_ZONE_CONNECTION ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_CONNECTION failed" ); return UNMATCHED_KEY_OR_INDEX; } if ( ( zoneComment = getSqlResultByInx( genQueryOut, COL_ZONE_COMMENT ) ) == NULL ) { rodsLog( LOG_NOTICE, "initZone: getSqlResultByInx for COL_ZONE_COMMENT failed" ); return UNMATCHED_KEY_OR_INDEX; } for ( i = 0; i < genQueryOut->rowCnt; i++ ) { rodsHostAddr_t addr; tmpZoneName = &zoneName->value[zoneName->len * i]; tmpZoneType = &zoneType->value[zoneType->len * i]; tmpZoneConn = &zoneConn->value[zoneConn->len * i]; //tmpZoneComment = &zoneComment->value[zoneComment->len * i]; if ( strcmp( tmpZoneType, "local" ) == 0 ) { if ( strcmp( zone_name.c_str(), tmpZoneName ) != 0 ) { rodsLog( LOG_ERROR, "initZone: zoneName in env %s does not match %s in icat ", zone_name.c_str(), tmpZoneName ); } /* fillin rodsZone if it is not defined */ if ( strlen( rsComm->proxyUser.rodsZone ) == 0 ) { rstrcpy( rsComm->proxyUser.rodsZone, tmpZoneName, NAME_LEN ); } if ( strlen( rsComm->clientUser.rodsZone ) == 0 ) { rstrcpy( rsComm->clientUser.rodsZone, tmpZoneName, NAME_LEN ); } continue; } else if ( strlen( tmpZoneConn ) <= 0 ) { rodsLog( LOG_ERROR, "initZone: connection info for zone %s not configured", tmpZoneName ); continue; } memset( &addr, 0, sizeof( addr ) ); /* assume address:port */ parseHostAddrStr( tmpZoneConn, &addr ); if ( addr.portNum == 0 ) { addr.portNum = ZoneInfoHead->portNum; } rstrcpy( addr.zoneName, tmpZoneName, NAME_LEN ); // JMC - bacport 4562 status = resolveHost( &addr, &tmpRodsServerHost ); if ( status < 0 ) { rodsLog( LOG_ERROR, "initZone: resolveHost error for %s for zone %s. status = %d", addr.hostAddr, tmpZoneName, status ); continue; } if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) { rodsLog( LOG_ERROR, "initZone: address %s for remote zone %s already in use", tmpZoneConn, tmpZoneName ); continue; } tmpRodsServerHost->rcatEnabled = REMOTE_ICAT; /* REMOTE_ICAT is always on a remote host even if it is one the same * host, but will be on different port */ tmpRodsServerHost->localFlag = REMOTE_HOST; // JMC - bacport 4562 queZone( tmpZoneName, addr.portNum, tmpRodsServerHost, NULL ); } freeGenQueryOut( &genQueryOut ); return 0; }
int dataObjStat (rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN]; char condStr[MAX_NAME_LEN]; sqlResult_t *dataSize; sqlResult_t *dataMode; sqlResult_t *replStatus; sqlResult_t *dataId; sqlResult_t *chksum; sqlResult_t *ownerName; sqlResult_t *ownerZone; sqlResult_t *createTime; sqlResult_t *modifyTime; /* see if objPath is a dataObj */ memset (myColl, 0, MAX_NAME_LEN); memset (myData, 0, MAX_NAME_LEN); if ((status = splitPathByKey ( dataObjInp->objPath, myColl, myData, '/')) < 0) { return (OBJ_PATH_DOES_NOT_EXIST); } memset (&genQueryInp, 0, sizeof (genQueryInp)); snprintf (condStr, MAX_NAME_LEN, "='%s'", myColl); addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr); snprintf (condStr, MAX_NAME_LEN, "='%s'", myData); addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, condStr); addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_MODE, 1); addInxIval (&genQueryInp.selectInp, COL_D_REPL_STATUS, 1); addInxIval (&genQueryInp.selectInp, COL_D_DATA_CHECKSUM, 1); addInxIval (&genQueryInp.selectInp, COL_D_OWNER_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_D_OWNER_ZONE, 1); addInxIval (&genQueryInp.selectInp, COL_D_CREATE_TIME, 1); addInxIval (&genQueryInp.selectInp, COL_D_MODIFY_TIME, 1); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut); clearGenQueryInp (&genQueryInp); if (status >= 0) { if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_DATA_SIZE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((dataMode = getSqlResultByInx (genQueryOut, COL_DATA_MODE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_DATA_MODE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((replStatus = getSqlResultByInx (genQueryOut, COL_D_REPL_STATUS)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_D_REPL_STATUS failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((dataId = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_D_DATA_ID failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((chksum = getSqlResultByInx (genQueryOut, COL_D_DATA_CHECKSUM)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_DATA_CHECKSUM failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((ownerName = getSqlResultByInx (genQueryOut, COL_D_OWNER_NAME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_OWNER_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((ownerZone = getSqlResultByInx (genQueryOut, COL_D_OWNER_ZONE)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_OWNER_ZONE failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((createTime = getSqlResultByInx (genQueryOut, COL_D_CREATE_TIME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_CREATE_TIME failed"); return (UNMATCHED_KEY_OR_INDEX); } else if ((modifyTime = getSqlResultByInx (genQueryOut, COL_D_MODIFY_TIME)) == NULL) { rodsLog (LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_D_MODIFY_TIME failed"); return (UNMATCHED_KEY_OR_INDEX); } else { int i; *rodsObjStatOut = (rodsObjStat_t *) malloc (sizeof (rodsObjStat_t)); memset (*rodsObjStatOut, 0, sizeof (rodsObjStat_t)); (*rodsObjStatOut)->objType = DATA_OBJ_T; status = (int)DATA_OBJ_T; /* XXXXXX . dont have numCopies anymore. Replaced by dataMode * (*rodsObjStatOut)->numCopies = genQueryOut->rowCnt; */ for (i = 0;i < genQueryOut->rowCnt; i++) { if (atoi (&replStatus->value[replStatus->len * i]) > 0) { rstrcpy ((*rodsObjStatOut)->dataId, &dataId->value[dataId->len * i], NAME_LEN); (*rodsObjStatOut)->objSize = strtoll (&dataSize->value[dataSize->len * i], 0, 0); (*rodsObjStatOut)->dataMode = atoi (&dataMode->value[dataMode->len * i]); rstrcpy ((*rodsObjStatOut)->chksum, &chksum->value[chksum->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerName, &ownerName->value[ownerName->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerZone, &ownerZone->value[ownerZone->len * i], NAME_LEN); rstrcpy ((*rodsObjStatOut)->createTime, &createTime->value[createTime->len * i], TIME_LEN); rstrcpy ((*rodsObjStatOut)->modifyTime, &modifyTime->value[modifyTime->len * i], TIME_LEN); break; } } if (strlen ((*rodsObjStatOut)->dataId) == 0) { /* just use the first one */ rstrcpy ((*rodsObjStatOut)->dataId, dataId->value, NAME_LEN); (*rodsObjStatOut)->objSize = strtoll (dataSize->value, 0, 0); rstrcpy ((*rodsObjStatOut)->chksum, chksum->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerName, ownerName->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->ownerZone, ownerZone->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->createTime, createTime->value, NAME_LEN); rstrcpy ((*rodsObjStatOut)->modifyTime, modifyTime->value, NAME_LEN); } } freeGenQueryOut (&genQueryOut); } return (status); }
/// =-=-=-=-=-=-=- /// @brief get the loads, times and names from the resource monitoring table irods::error get_load_lists( irods::resource_plugin_context& _ctx, std::vector< std::string >& _resc_names, std::vector< int >& _resc_loads, std::vector< int >& _resc_times ) { // =-=-=-=-=-=-=- // int i = 0, j = 0, nresc = 0, status = 0; char* tResult = 0; genQueryInp_t genQueryInp; genQueryOut_t* genQueryOut = NULL; // =-=-=-=-=-=-=- // query the database in order to retrieve the information on the // resources' load memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_SLD_RESC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_SLD_LOAD_FACTOR, 1 ); addInxIval( &genQueryInp.selectInp, COL_SLD_CREATE_TIME, SELECT_MAX ); // =-=-=-=-=-=-=- // a tmp fix to increase no. of resource to 256 genQueryInp.maxRows = MAX_SQL_ROWS * 10; status = rsGenQuery( _ctx.comm(), &genQueryInp, &genQueryOut ); if ( status == 0 ) { nresc = genQueryOut->rowCnt; // =-=-=-=-=-=-=- // vectors should be sized to number of resources // these vectors will be indexed directly, not built _resc_names.resize( nresc ); _resc_loads.resize( nresc ); _resc_times.resize( nresc ); for ( i = 0; i < genQueryOut->attriCnt; i++ ) { for ( j = 0; j < nresc; j++ ) { tResult = genQueryOut->sqlResult[i].value; tResult += j * genQueryOut->sqlResult[i].len; switch ( i ) { case 0: _resc_names[j] = tResult; break; case 1: _resc_loads[j] = atoi( tResult ); break; case 2: _resc_times[j] = atoi( tResult ); break; } } } } else { clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return ERROR( status, "genquery failed" ); } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return SUCCESS(); } // get_load_lists
int lsSubfilesInBundle (rcComm_t *conn, char *srcPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs) { int i, status; genQueryOut_t *genQueryOut = NULL; genQueryInp_t genQueryInp; char condStr[MAX_NAME_LEN]; sqlResult_t *dataName, *collection, *dataSize; char *dataNameStr, *collectionStr, *dataSizeStr; int continueInx = 1; fprintf (stdout, "Bundle file: %s\n", srcPath); fprintf (stdout, "Subfiles:\n"); bzero (&genQueryInp, sizeof (genQueryInp)); genQueryInp.maxRows = MAX_SQL_ROWS; snprintf (condStr, MAX_NAME_LEN, "='%s'", srcPath); addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr); snprintf (condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS); addInxVal (&genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr); addKeyVal (&genQueryInp.condInput, ZONE_KW, srcPath); addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1); addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1); while (continueInx > 0) { status = rcGenQuery (conn, &genQueryInp, &genQueryOut); if (status < 0) { if (status != CAT_NO_ROWS_FOUND) { rodsLogError (LOG_ERROR, status, "lsSubfilesInBundle: rsGenQuery error for %s", srcPath); } clearGenQueryInp (&genQueryInp); return (status); } if ((collection = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_COLL_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_NAME failed"); return (UNMATCHED_KEY_OR_INDEX); } if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == NULL) { rodsLog (LOG_ERROR, "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_SIZE failed"); return (UNMATCHED_KEY_OR_INDEX); } for (i = 0;i < genQueryOut->rowCnt; i++) { collectionStr = &collection->value[collection->len * i]; dataNameStr = &dataName->value[dataName->len * i]; dataSizeStr = &dataSize->value[dataSize->len * i]; fprintf (stdout, " %s/%s %s\n", collectionStr, dataNameStr, dataSizeStr); } if (genQueryOut != NULL) { continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut (&genQueryOut); } else { continueInx = 0; } } clearGenQueryInp (&genQueryInp); return (status); }
int collStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut = NULL; int status; char condStr[MAX_NAME_LEN]; sqlResult_t *dataId; sqlResult_t *ownerName; sqlResult_t *ownerZone; sqlResult_t *createTime; sqlResult_t *modifyTime; sqlResult_t *collType; sqlResult_t *collInfo1; sqlResult_t *collInfo2; /* see if objPath is a collection */ memset( &genQueryInp, 0, sizeof( genQueryInp ) ); snprintf( condStr, MAX_NAME_LEN, "='%s'", dataObjInp->objPath ); addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr ); addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 ); /* XXXX COL_COLL_NAME added for queueSpecColl */ addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 ); /* XXXX may want to do this if spec coll is supported */ addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 ); addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut ); if ( status >= 0 ) { *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) ); memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) ); ( *rodsObjStatOut )->objType = COLL_OBJ_T; status = ( int )COLL_OBJ_T; if ( ( dataId = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat: getSqlResultByInx for COL_COLL_ID failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerName = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_NAME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_NAME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( ownerZone = getSqlResultByInx( genQueryOut, COL_COLL_OWNER_ZONE ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( createTime = getSqlResultByInx( genQueryOut, COL_COLL_CREATE_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_CREATE_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( modifyTime = getSqlResultByInx( genQueryOut, COL_COLL_MODIFY_TIME ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collType = getSqlResultByInx( genQueryOut, COL_COLL_TYPE ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_TYPE failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo1 = getSqlResultByInx( genQueryOut, COL_COLL_INFO1 ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_INFO1 failed" ); return UNMATCHED_KEY_OR_INDEX; } else if ( ( collInfo2 = getSqlResultByInx( genQueryOut, COL_COLL_INFO2 ) ) == NULL ) { rodsLog( LOG_ERROR, "_rsObjStat:getSqlResultByInx for COL_COLL_INFO2 failed" ); return UNMATCHED_KEY_OR_INDEX; } else { rstrcpy( ( *rodsObjStatOut )->dataId, dataId->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->ownerName, ownerName->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->ownerZone, ownerZone->value, NAME_LEN ); rstrcpy( ( *rodsObjStatOut )->createTime, createTime->value, TIME_LEN ); rstrcpy( ( *rodsObjStatOut )->modifyTime, modifyTime->value, TIME_LEN ); if ( strlen( collType->value ) > 0 ) { specCollCache_t *specCollCache = 0; if ( ( specCollCache = matchSpecCollCache( dataObjInp->objPath ) ) != NULL ) { replSpecColl( &specCollCache->specColl, &( *rodsObjStatOut )->specColl ); } else { status = queueSpecCollCache( rsComm, genQueryOut, // JMC - backport 4680? dataObjInp->objPath ); if ( status < 0 ) { return status; } replSpecColl( &SpecCollCacheHead->specColl, &( *rodsObjStatOut )->specColl ); } } } } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return status; }
int // JMC - backport 4680 getPhyPath( rsComm_t* _comm, char* _obj_name, char* _resource, char* _phy_path, char* _resc_hier ) { // =-=-=-=-=-=-=- // if no resc hier is specified, call resolve on the object to // ask the resource composition to pick a valid hier for open std::string resc_hier; if ( 0 == strlen( _resc_hier ) ) { dataObjInp_t data_inp; memset( &data_inp, 0, sizeof( data_inp ) ); strncpy( data_inp.objPath, _obj_name, MAX_NAME_LEN ); irods::error ret = irods::resolve_resource_hierarchy( irods::OPEN_OPERATION, _comm, &data_inp, resc_hier ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); return SYS_INVALID_INPUT_PARAM; } } else { resc_hier = _resc_hier; } std::string root_resc; irods::hierarchy_parser parser; parser.set_string( resc_hier ); parser.first_resc( root_resc ); // =-=-=-=-=-=-=- // perform a genquery to get the physical path of the data object // as the hier reolve does not do that for us genQueryOut_t* gen_out = NULL; char tmp_str [ MAX_NAME_LEN ]; char logical_end_name [ MAX_NAME_LEN ]; char logical_parent_dir_name[ MAX_NAME_LEN ]; // =-=-=-=-=-=-=- // split the object path by the last delimiter / int status = splitPathByKey( _obj_name, logical_parent_dir_name, MAX_NAME_LEN, logical_end_name, MAX_NAME_LEN, '/' ); genQueryInp_t gen_inp; memset( &gen_inp, 0, sizeof( genQueryInp_t ) ); // =-=-=-=-=-=-=- // add query to the struct for the data object name snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_end_name ); addInxVal( &gen_inp.sqlCondInp, COL_DATA_NAME, tmp_str ); // =-=-=-=-=-=-=- // add query to the struct for the collection name snprintf( tmp_str, MAX_NAME_LEN, "='%s'", logical_parent_dir_name ); addInxVal( &gen_inp.sqlCondInp, COL_COLL_NAME, tmp_str ); // =-=-=-=-=-=-=- // add query to the struct for the resource hierarchy snprintf( tmp_str, MAX_NAME_LEN, "='%s'", resc_hier.c_str() ); addInxVal( &gen_inp.sqlCondInp, COL_D_RESC_HIER, tmp_str ); // =-=-=-=-=-=-=- // include request for data path and resource hierarchy addInxIval( &gen_inp.selectInp, COL_D_DATA_PATH, 1 ); // =-=-=-=-=-=-=- // request only 2 results in the set gen_inp.maxRows = 2; status = rsGenQuery( _comm, &gen_inp, &gen_out ); if ( status >= 0 ) { // =-=-=-=-=-=-=- // extract the physical path from the query sqlResult_t* phy_path_res = getSqlResultByInx( gen_out, COL_D_DATA_PATH ); if ( !phy_path_res ) { rodsLog( LOG_ERROR, "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed" ); return UNMATCHED_KEY_OR_INDEX; } // =-=-=-=-=-=-=- // copy the results to the out variables strncpy( _phy_path, phy_path_res->value, MAX_NAME_LEN ); strncpy( _resource, root_resc.c_str(), root_resc.size() ); strncpy( _resc_hier, resc_hier.c_str(), resc_hier.size() ); freeGenQueryOut( &gen_out ); } clearGenQueryInp( &gen_inp ); return status; }