Skip to content

Commit

Permalink
msi_dir_list: check if the hostname and resource location are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed May 8, 2024
1 parent 557b1d5 commit 6cde738
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/msi_dir_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int get_resource_attribute_by_name(rsComm_t* rsComm,
else {
if ((resource_data = getSqlResultByInx(genQueryOut, column_number)) == NULL) {
rodsLog(LOG_ERROR,
"msi_file_checksum: getSqlResultByInx for column %d failed on lookup of %s",
"msi_dir_list: getSqlResultByInx for column %d failed on lookup of %s",
column_number,
resource_name);
out_status = UNMATCHED_KEY_OR_INDEX;
Expand Down Expand Up @@ -105,6 +105,14 @@ static int get_resource_vault_path(rsComm_t* rsComm, char* resource_name, char*
return get_resource_attribute_by_name(rsComm, resource_name, resource_vault_path_out, COL_R_VAULT_PATH);
}

/** This function retrieves the location of a resource based on its name
* to resource_loc_out
*/
static int get_resource_loc(rsComm_t* rsComm, char* resource_name, char* resource_loc_out)
{
return get_resource_attribute_by_name(rsComm, resource_name, resource_loc_out, COL_R_LOC);
}

int msiDirList(msParam_t* _path, msParam_t* _rescName, msParam_t* _list, ruleExecInfo_t* _rei)
{
// Convert parameter values to C strings.
Expand Down Expand Up @@ -182,6 +190,24 @@ int msiDirList(msParam_t* _path, msParam_t* _rescName, msParam_t* _list, ruleExe
return SYS_INVALID_FILE_PATH;
}

// Retrieve resource location
char resource_loc[MAX_NAME_LEN + 1];
memset(&resource_loc, '\0', MAX_NAME_LEN + 1);
int status_resource_loc = get_resource_loc(_rei->rsComm, rescName, resource_loc);
if (status_resource_loc < 0) {
rodsLog(LOG_ERROR,
"msi_dir_list: error while looking up resource vault path of resource [%s]: %d",
rescName,
status_resource_loc);
return status_resource_loc;
}

// Check if the hostname and resource location are the same.
if (strcmp(_rei->rsComm->myEnv.rodsHost, resource_loc) != 0) {
rodsLog(LOG_ERROR, "msi_dir_list: hostname differs from resource location");
return USER_INVALID_RESC_INPUT;
}

try {
pt::ptree jsonResult;
fs::directory_iterator endIter;
Expand Down

0 comments on commit 6cde738

Please sign in to comment.