int msiobjget_z3950( msParam_t* inRequestPath, msParam_t* inFileMode, msParam_t* inFileFlags, msParam_t* inCacheFilename, ruleExecInfo_t* rei ) { char *reqStr; int mode; char *cacheFilename; char *str; int status, bytesWritten, objLen; int destFd; char *locStr, *queryStr, *syntaxStr; char *myMSICall; int i; ruleExecInfo_t rei2; msParamArray_t msParamArray; msParam_t *mP; RE_TEST_MACRO( " Calling msiobjget_z3950" ); /* check for input parameters */ if ( inRequestPath == NULL || strcmp( inRequestPath->type , STR_MS_T ) != 0 || inRequestPath->inOutStruct == NULL ) { return( USER_PARAM_TYPE_ERR ); } if ( inFileMode == NULL || strcmp( inFileMode->type , STR_MS_T ) != 0 || inFileMode->inOutStruct == NULL ) { return( USER_PARAM_TYPE_ERR ); } if ( inFileFlags == NULL || strcmp( inFileFlags->type , STR_MS_T ) != 0 || inFileFlags->inOutStruct == NULL ) { return( USER_PARAM_TYPE_ERR ); } if ( inCacheFilename == NULL || strcmp( inCacheFilename->type , STR_MS_T ) != 0 || inCacheFilename->inOutStruct == NULL ) { return( USER_PARAM_TYPE_ERR ); } /* coerce input to local variables */ reqStr = ( char * ) inRequestPath->inOutStruct; cacheFilename = ( char * ) inCacheFilename->inOutStruct; mode = atoi( ( char * ) inFileMode->inOutStruct ); /* Do the processing */ /* first skipping the mso-name */ if ( ( str = strstr( reqStr, ":" ) ) == NULL ) { str = reqStr; } else { str++; } /* getting parameters for the calls */ i = getz3950Params( str, &locStr, &queryStr, &syntaxStr ); if ( i != 0 ) { printf( "msiobjget_z3950: Error in request format for %s:%i\n", str, i ); return( USER_INPUT_FORMAT_ERR ); } myMSICall = ( char * ) malloc( strlen( reqStr ) + 200 ); sprintf( myMSICall, "msiz3950Submit(\"%s\",\"%s\",\"%s\",*OutBuffer)", locStr, queryStr, syntaxStr ); /* sprintf(myMSICall, "msiz3950Submit(\"z3950.loc.gov:7090/Voyager\",\"@attr 1=1003 Marx\",\"USMARC\",*OutBuffer)" ); printf("MM:%s***\n",myMSICall); */ free( locStr ); free( queryStr ); free( syntaxStr ); memset( ( char* )&rei2, 0, sizeof( ruleExecInfo_t ) ); memset( ( char* )&msParamArray, 0, sizeof( msParamArray_t ) ); rei2.rsComm = rei->rsComm; if ( rei2.rsComm != NULL ) { rei2.uoic = &rei2.rsComm->clientUser; rei2.uoip = &rei2.rsComm->proxyUser; } #ifdef RULE_ENGINE_N i = applyRuleUpdateParams( myMSICall, &msParamArray, &rei2, NO_SAVE_REI ); #else i = applyRule( myMSICall, &msParamArray, &rei2, NO_SAVE_REI ); #endif if ( i != 0 ) { printf( "msiobjget_z3950: Error in calling %s: %i\n", myMSICall, i ); free( myMSICall ); return( i ); } free( myMSICall ); mP = getMsParamByLabel( &msParamArray, "*OutBuffer" ); if ( mP == NULL ) { printf( "msiobjget_z3950: Error in Getting Parameter after call for *OutBuffer\n" ); return( UNKNOWN_PARAM_IN_RULE_ERR ); } str = ( char * ) mP->inOutStruct; objLen = strlen( str ); /* write the resulting buffer in cache file */ destFd = open( cacheFilename, O_WRONLY | O_CREAT | O_TRUNC, mode ); if ( destFd < 0 ) { status = UNIX_FILE_OPEN_ERR - errno; printf( "msigetobj_z3950: open error for cacheFilename %s, status = %d", cacheFilename, status ); clearMsParamArray( &msParamArray, 0 ); return status; } bytesWritten = write( destFd, str, objLen ); close( destFd ); clearMsParamArray( &msParamArray, 0 ); if ( bytesWritten != objLen ) { printf( "msigetobj_z3950: In Cache File %s bytesWritten %d != returned objLen %i\n", cacheFilename, bytesWritten, objLen ); return SYS_COPY_LEN_ERR; } /* clean up */ /*return */ return( 0 ); }
/// =-=-=-=-=-=-=- /// @brief function which manages the TLS and Auth negotiations with the client error client_server_negotiation_for_server( irods::network_object_ptr _ptr, std::string& _result ) { // =-=-=-=-=-=-=- // manufacture an rei for the applyRule ruleExecInfo_t rei; memset( ( char* )&rei, 0, sizeof( ruleExecInfo_t ) ); // =-=-=-=-=-=-=- // if it is, then call the pre PEP and get the result msParamArray_t params; memset( ¶ms, 0, sizeof( params ) ); int status = applyRuleUpdateParams( "acPreConnect(*OUT)", ¶ms, &rei, NO_SAVE_REI ); if ( 0 != status ) { return ERROR( status, "failed in call to applyRuleUpdateParams" ); } // =-=-=-=-=-=-=- // extract the value from the outgoing param to pass out to the operation char* rule_result_ptr = 0; msParam_t* out_ms_param = getMsParamByLabel( ¶ms, "*OUT" ); if ( out_ms_param ) { rule_result_ptr = reinterpret_cast< char* >( out_ms_param->inOutStruct ); } else { return ERROR( SYS_INVALID_INPUT_PARAM, "null out parameter" ); } if ( !rule_result_ptr ) { return ERROR( SYS_INVALID_INPUT_PARAM, "rule_result is null" ); } std::string rule_result( rule_result_ptr ); clearMsParamArray( ¶ms, 0 ); // =-=-=-=-=-=-=- // check to see if a negoation was requested if ( !do_client_server_negotiation_for_server() ) { // =-=-=-=-=-=-=- // if it was not but we require SSL then error out if ( CS_NEG_REQUIRE == rule_result ) { std::stringstream msg; msg << "SSL is required by the server but not requested by the client"; return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); } else { // =-=-=-=-=-=-=- // a negotiation was not requested, bail return SUCCESS(); } } // =-=-=-=-=-=-=- // pass the PEP result to the client, send CS_NEG_SVR_1_MSG irods::cs_neg_t cs_neg; cs_neg.status_ = CS_NEG_STATUS_SUCCESS; snprintf( cs_neg.result_, sizeof( cs_neg.result_ ), "%s", rule_result.c_str() ); error err = send_client_server_negotiation_message( _ptr, cs_neg ); if ( !err.ok() ) { std::stringstream msg; msg << "failed with PEP value of [" << rule_result << "]"; return PASSMSG( msg.str(), err ); } // =-=-=-=-=-=-=- // get the response from CS_NEG_CLI_1_MSG boost::shared_ptr< cs_neg_t > read_cs_neg; err = read_client_server_negotiation_message( _ptr, read_cs_neg ); if ( !err.ok() ) { return PASS( err ); } // =-=-=-=-=-=-=- // get the result from the key val pair if ( strlen( read_cs_neg->result_ ) != 0 ) { irods::kvp_map_t kvp; err = irods::parse_kvp_string( read_cs_neg->result_, kvp ); if ( err.ok() ) { // =-=-=-=-=-=-=- // extract the signed SID if ( kvp.find( CS_NEG_SID_KW ) != kvp.end() ) { std::string svr_sid = kvp[ CS_NEG_SID_KW ]; if ( !svr_sid.empty() ) { // =-=-=-=-=-=-=- // get our SID to compare server_properties& props = server_properties::getInstance(); err = props.capture_if_needed(); if ( !err.ok() ) { return PASS( err ); } // =-=-=-=-=-=-=- // check SID against our SIDs err = check_sent_sid( props, svr_sid ); if ( !err.ok() ) { rodsLog( LOG_DEBUG, "[%s]", PASS( err ).status() ); } else { // =-=-=-=-=-=-=- // store property that states this is an // Agent-Agent connection props.set_property < std::string > ( AGENT_CONN_KW, svr_sid ); } } // if sid is not empty else { rodsLog( LOG_DEBUG, "%s - sent SID is empty", __FUNCTION__ ); } } // =-=-=-=-=-=-=- // check to see if the result string has the SSL negotiation results _result = kvp[ CS_NEG_RESULT_KW ]; if ( _result.empty() ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "SSL result string missing from response" ); } } else { // =-=-=-=-=-=-=- // support 4.0 client-server negotiation which did not // use key-val pairs _result = read_cs_neg->result_; } } // if result strlen > 0 // =-=-=-=-=-=-=- // if the response is favorable, return success if ( CS_NEG_STATUS_SUCCESS == read_cs_neg->status_ ) { return SUCCESS(); } // =-=-=-=-=-=-=- // else, return a failure return ERROR( -1, "failure detected from client" ); } // client_server_negotiation_for_server
// =-=-=-=-=-=-=- // private - execute rule for pre operation error operation_rule_execution_manager::exec_op( rsComm_t* _comm, keyValPair_t& _kvp, const std::string& _name, std::string& _res ) { // =-=-=-=-=-=-=- // determine if rule exists RuleIndexListNode* re_node = 0; if ( findNextRule2( const_cast<char*>( _name.c_str() ), 0, &re_node ) < 0 ) { return ERROR( SYS_RULE_NOT_FOUND, "no rule found" ); } // =-=-=-=-=-=-=- // debug message for creating dynPEP rules rodsLog( LOG_DEBUG, "operation_rule_execution_manager exec_op [%s]", _name.c_str() ); // =-=-=-=-=-=-=- // add additional global re params error err = add_global_re_params_to_kvp_for_dynpep( _kvp ); if ( !err.ok() ) { return PASS( err ); } // =-=-=-=-=-=-=- // manufacture an rei for the applyRule ruleExecInfo_t rei; memset( ( char* )&rei, 0, sizeof( ruleExecInfo_t ) ); rei.rsComm = _comm; rei.condInputData = &_kvp; // give rule scope to our key value pairs rstrcpy( rei.pluginInstanceName, instance_.c_str(), MAX_NAME_LEN ); // =-=-=-=-=-=-=- // add the output parameter msParamArray_t params; memset( ¶ms, 0, sizeof( msParamArray_t ) ); char out_param[ MAX_NAME_LEN ] = {"EMPTY_PARAM"}; if ( _res.empty() ) { addMsParamToArray( ¶ms, "*OUT", STR_MS_T, out_param, NULL, 0 ); } else { addMsParamToArray( ¶ms, "*OUT", STR_MS_T, const_cast<char*>( _res.c_str() ), NULL, 0 ); } // =-=-=-=-=-=-=- // rule exists, param array is build. call the rule. std::string arg_name = _name + "(*OUT)"; int ret = applyRuleUpdateParams( const_cast<char*>( arg_name.c_str() ), ¶ms, &rei, NO_SAVE_REI ); if ( 0 != ret ) { return ERROR( ret, "failed in call to applyRuleUpdateParams" ); } // =-=-=-=-=-=-=- // extract the value from the outgoing param to pass out to the operation msParam_t* out_ms_param = getMsParamByLabel( ¶ms, "*OUT" ); if ( out_ms_param ) { _res = reinterpret_cast< char* >( out_ms_param->inOutStruct ); } else { return ERROR( SYS_INVALID_INPUT_PARAM, "null out parameter" ); } return SUCCESS(); } // exec_op