/** * \fn rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) * * \brief Execute my rule. * * \user client * * \ingroup rules * * \since 1.0 * * * \remark none * * \note none * * \param[in] conn - A rcComm_t connection handle to the server. * \param[in] execMyRuleInp * \param[out] outParamArray * * \return integer * \retval 0 on success. * \sideeffect none * \pre none * \post none * \sa none **/ int rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) { int status = procApiRequest( conn, EXEC_MY_RULE_AN, execMyRuleInp, NULL, ( void ** )outParamArray, NULL ); while ( status == SYS_SVR_TO_CLI_MSI_REQUEST ) { /* it is a server request */ msParam_t *myParam = NULL, *putParam = NULL; if ( ( myParam = putParam = getMsParamByLabel( *outParamArray, CL_PUT_ACTION ) ) || ( myParam = getMsParamByLabel( *outParamArray, CL_GET_ACTION ) ) ) { //putParam is non-null if it's a put, null if it's a get dataObjInp_t * dataObjInp = ( dataObjInp_t * ) myParam->inOutStruct; char * locFilePath; char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN]; // locFilePath should be the return of getValByKey if it exists, // otherwise use the filename from splitPathByKey if ( ( locFilePath = getValByKey( &dataObjInp->condInput, LOCAL_PATH_KW ) ) || ( ( status = splitPathByKey( dataObjInp->objPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) >= 0 && ( locFilePath = ( char * ) myFile ) ) ) { status = putParam ? rcDataObjPut( conn, dataObjInp, locFilePath ) : rcDataObjGet( conn, dataObjInp, locFilePath ); rcOprComplete( conn, status ); } else { rodsLogError( LOG_ERROR, status, "rcExecMyRule: splitPathByKey for %s error", dataObjInp->objPath ); rcOprComplete( conn, USER_FILE_DOES_NOT_EXIST ); } clearKeyVal( &dataObjInp->condInput ); } else { rcOprComplete( conn, SYS_SVR_TO_CLI_MSI_NO_EXIST ); } /* free outParamArray */ clearMsParamArray( *outParamArray, 1 ); free( *outParamArray ); *outParamArray = NULL; /* read the reply from the earlier call */ status = branchReadAndProcApiReply( conn, EXEC_MY_RULE_AN, ( void ** )outParamArray, NULL ); if ( status < 0 ) { rodsLogError( LOG_DEBUG, status, "rcExecMyRule: readAndProcApiReply failed. status = %d", status ); } } return status; }
/** * \fn msiSendStdoutAsEmail(msParam_t* xtoAddr, msParam_t* xsubjectLine, ruleExecInfo_t *rei) * * \brief Sends the current buffer content in rei->ruleExecOut->stdoutBuf.buf as email. * * \module core * * \since pre-2.1 * * \author Arcot Rajasekar * \date 2008-05 * * \note This microservice sends contents of the buffer rei->ruleExecOut->stdoutBuf.buf as email. * * \usage See clients/icommands/test/rules3.0/ * * \param[in] xtoAddr - a msParam of type STR_MS_T which is the address of the receiver. * \param[in] xsubjectLine - a msParam of type STR_MS_T which is the subject of the message. * \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 on success * \pre none * \post none * \sa writeLine, writeString **/ int msiSendStdoutAsEmail( msParam_t* xtoAddr, msParam_t* xsubjectLine, ruleExecInfo_t *rei ) { int i; msParam_t *mP; char tmpVarName[MAX_ACTION_SIZE]; execCmdOut_t *myExecCmdOut; if ( ( mP = getMsParamByLabel( rei->msParamArray, "ruleExecOut" ) ) == NULL ) { return NO_VALUES_FOUND; } myExecCmdOut = ( execCmdOut_t* )mP->inOutStruct; getNewVarName( tmpVarName, rei->msParamArray ); addMsParam( rei->msParamArray, tmpVarName, STR_MS_T, myExecCmdOut->stdoutBuf.buf , NULL ); mP = getMsParamByLabel( rei->msParamArray, tmpVarName ); i = msiSendMail( xtoAddr, xsubjectLine, mP, rei ); rmMsParamByLabel( rei->msParamArray, tmpVarName, 1 ); return i; }
/** * \fn msiSendStdoutAsEmail(msParam_t* xtoAddr, msParam_t* xsubjectLine, ruleExecInfo_t *rei) * * \brief Sends the current buffer content in rei->ruleExecOut->stdoutBuf.buf as email. * * \module core * * \since pre-2.1 * * * \note This microservice sends contents of the buffer rei->ruleExecOut->stdoutBuf.buf as email. * * \usage See clients/icommands/test/rules3.0/ * * \param[in] xtoAddr - a msParam of type STR_MS_T which is the address of the receiver. * \param[in] xsubjectLine - a msParam of type STR_MS_T which is the subject of the message. * \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 on success * \pre none * \post none * \sa writeLine, writeString **/ int msiSendStdoutAsEmail( msParam_t* xtoAddr, msParam_t* xsubjectLine, ruleExecInfo_t *rei ) { msParam_t *mP; if ( ( mP = getMsParamByLabel( rei->msParamArray, "ruleExecOut" ) ) == NULL ) { return NO_VALUES_FOUND; } execCmdOut_t *myExecCmdOut = ( execCmdOut_t* )mP->inOutStruct; char tmpVarName[MAX_ACTION_SIZE]; getNewVarName( tmpVarName, rei->msParamArray ); addMsParam( rei->msParamArray, tmpVarName, STR_MS_T, myExecCmdOut->stdoutBuf.buf , NULL ); mP = getMsParamByLabel( rei->msParamArray, tmpVarName ); int status; if ( NULL != mP ) { status = msiSendMail( xtoAddr, xsubjectLine, mP, rei ); } else { status = SYS_INTERNAL_NULL_INPUT_ERR; } rmMsParamByLabel( rei->msParamArray, tmpVarName, 1 ); return status; }
int getNewVarName(char *v, msParamArray_t *msParamArray) { /* msParam_t *mP;*/ sprintf(v,"*RNDVAR%i",staticVarNumber); staticVarNumber++; while (getMsParamByLabel (msParamArray, v) != NULL) { sprintf(v,"*RNDVAR%i",staticVarNumber); staticVarNumber++; } return(0); }
/** * \fn msiFreeBuffer(msParam_t* memoryParam, ruleExecInfo_t *rei) * * \brief This microservice frees a named buffer, including stdout and stderr * * \module core * * \since pre-2.1 * * \author Arcot Rajasekar * \date 2006 * * \usage See clients/icommands/test/rules3.0/ * * \param[in] memoryParam - the buffer to free * \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 on success * \pre none * \post none * \sa none **/ int msiFreeBuffer( msParam_t* memoryParam, ruleExecInfo_t *rei ) { msParamArray_t *inMsParamArray; msParam_t *mP; execCmdOut_t *myExecCmdOut; RE_TEST_MACRO( "Loopback on msiFreeBuffer" ); if ( !strcmp( memoryParam->type, "STR_PI" ) && ( !strcmp( ( char* )memoryParam->inOutStruct, "stdout" ) || !strcmp( ( char* )memoryParam->inOutStruct, "stderr" ) ) ) { mP = NULL; inMsParamArray = rei->msParamArray; if ( ( ( mP = getMsParamByLabel( inMsParamArray, "ruleExecOut" ) ) != NULL ) && ( mP->inOutStruct != NULL ) ) { myExecCmdOut = ( execCmdOut_t * ) mP->inOutStruct; if ( !strcmp( ( char* )memoryParam->inOutStruct, "stdout" ) ) { if ( myExecCmdOut->stdoutBuf.buf != NULL ) { free( myExecCmdOut->stdoutBuf.buf ); myExecCmdOut->stdoutBuf.buf = NULL; myExecCmdOut->stdoutBuf.len = 0; } } if ( !strcmp( ( char* )memoryParam->inOutStruct, "stderr" ) ) { if ( myExecCmdOut->stderrBuf.buf != NULL ) { free( myExecCmdOut->stderrBuf.buf ); myExecCmdOut->stderrBuf.buf = NULL; myExecCmdOut->stderrBuf.len = 0; } } } return( 0 ); } if ( memoryParam->inpOutBuf != NULL ) { free( memoryParam->inpOutBuf ); } memoryParam->inpOutBuf = NULL; return( 0 ); }
int _rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut) { int status; static int ruleExecuted=0; ruleExecInfo_t rei; static int ruleResult=0; static int PrePostProcForGenQueryFlag = -2; int i, argc; ruleExecInfo_t rei2; char *args[MAX_NUM_OF_ARGS_IN_ACTION]; if (PrePostProcForGenQueryFlag < 0) { if (getenv("PREPOSTPROCFORGENQUERYFLAG") != NULL) PrePostProcForGenQueryFlag = 1; else PrePostProcForGenQueryFlag = 0; } memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t)); rei2.rsComm = rsComm; if (rsComm != NULL) { rei2.uoic = &rsComm->clientUser; rei2.uoip = &rsComm->proxyUser; } /* printGenQI(genQueryInp); for debug */ *genQueryOut = (genQueryOut_t*)malloc(sizeof(genQueryOut_t)); memset((char *)*genQueryOut, 0, sizeof(genQueryOut_t)); if (ruleExecuted==0) { #if 0 msParam_t *outMsParam; #endif memset((char*)&rei,0,sizeof(rei)); rei.rsComm = rsComm; if (rsComm != NULL) { /* Include the user info for possible use by the rule. Note that when this is called (as the agent is initializing), this user info is not confirmed yet. For password authentication though, the agent will soon exit if this is not valid. But tor GSI, the user information may not be present and/or may be changed when the authentication completes, so it may not be safe to use this in a GSI enabled environment. This addition of user information was requested by ARCS/IVEC (Sean Fleming) to avoid a local patch. */ rei.uoic = &rsComm->clientUser; rei.uoip = &rsComm->proxyUser; } #ifdef RULE_ENGINE_N if (getRuleEngineStatus() == UNINITIALIZED) { /* Skip the call to run acAclPolicy if the Rule Engine hasn't been initialized yet, which happens for a couple initial queries made by the agent when starting up. The new RE logs these types of errors and so this avoids that. */ status = -1; } else #endif { status = applyRule ("acAclPolicy", NULL, &rei, NO_SAVE_REI); ruleResult = rei.status; } if (status==0) { ruleExecuted=1; /* No need to retry next time since it succeeded. Since this is called at startup, the Rule Engine may not be initialized yet, in which case the default setting is fine and we should retry next time. */ #if 0 /* No longer need this as msiAclPolicy calls chlGenQueryAccessControlSetup to set the flag. Leaving it in the code for now in case needed later. */ outMsParam = getMsParamByLabel(&rei.inOutMsParamArray, "STRICT"); printf("outMsParam=%x\n",(int)outMsParam); if (outMsParam != NULL) { ruleResult=1; } #endif } #if 0 printf("rsGenQuery rule status=%d ruleResult=%d\n",status,ruleResult); #endif } chlGenQueryAccessControlSetup(rsComm->clientUser.userName, rsComm->clientUser.rodsZone, rsComm->clientAddr, rsComm->clientUser.authInfo.authFlag, -1); #if 0 rodsLog (LOG_NOTICE, "_rsGenQuery debug: client %s %d proxy %s %d", rsComm->clientUser.userName, rsComm->clientUser.authInfo.authFlag, rsComm->proxyUser.userName, rsComm->proxyUser.authInfo.authFlag); #endif /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/ if (PrePostProcForGenQueryFlag == 1) { args[0] = (char *) malloc(300); sprintf(args[0],"%ld",(long) genQueryInp); argc = 1; i = applyRuleArg("acPreProcForGenQuery",args,argc, &rei2, NO_SAVE_REI); free(args[0]); if (i < 0) { rodsLog (LOG_ERROR, "rsGenQuery:acPreProcForGenQuery error,stat=%d", i); if (i != NO_MICROSERVICE_FOUND_ERR) return i; } } /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/ status = chlGenQuery(*genQueryInp, *genQueryOut); /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/ if (PrePostProcForGenQueryFlag == 1) { args[0] = (char *) malloc(300); args[1] = (char *) malloc(300); args[2] = (char *) malloc(300); sprintf(args[0],"%ld",(long) genQueryInp); sprintf(args[1],"%ld",(long) *genQueryOut); sprintf(args[2],"%d",status); argc = 3; i = applyRuleArg("acPostProcForGenQuery",args,argc, &rei2, NO_SAVE_REI); free(args[0]); free(args[1]); free(args[2]); if (i < 0) { rodsLog (LOG_ERROR, "rsGenQuery:acPostProcForGenQuery error,stat=%d", i); if (i != NO_MICROSERVICE_FOUND_ERR) return i; } } /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/ if (status < 0) { clearGenQueryOut (*genQueryOut); free (*genQueryOut); *genQueryOut = NULL; if (status != CAT_NO_ROWS_FOUND) { rodsLog (LOG_NOTICE, "_rsGenQuery: genQuery status = %d", status); } return (status); } return (status); }
/// =-=-=-=-=-=-=- /// @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
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 ); }
int rcDataObjRsync (rcComm_t *conn, dataObjInp_t *dataObjInp) { int status; msParamArray_t *outParamArray = NULL; char *locFilePath; status = _rcDataObjRsync (conn, dataObjInp, &outParamArray); if (status == SYS_SVR_TO_CLI_PUT_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } else if (status == SYS_SVR_TO_CLI_GET_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } /* below is for backward compatibility */ while (status == SYS_SVR_TO_CLI_MSI_REQUEST) { /* it is a server request */ msParam_t *myMsParam; dataObjInp_t *dataObjInp = NULL; int l1descInx; myMsParam = getMsParamByLabel (outParamArray, CL_ZONE_OPR_INX); if (myMsParam == NULL) { l1descInx = -1; } else { l1descInx = *(int*) myMsParam->inOutStruct; } if ((myMsParam = getMsParamByLabel (outParamArray, CL_PUT_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else if ((myMsParam = getMsParamByLabel (outParamArray, CL_GET_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, SYS_SVR_TO_CLI_MSI_NO_EXIST); } } /* free outParamArray */ if (dataObjInp != NULL) { clearKeyVal (&dataObjInp->condInput); } clearMsParamArray (outParamArray, 1); free (outParamArray); /* read the reply from the eariler call */ status = branchReadAndProcApiReply (conn, DATA_OBJ_RSYNC_AN, (void **)&outParamArray, NULL); if (status < 0) { rodsLogError (LOG_DEBUG, status, "rcDataObjRsync: readAndProcApiReply failed. status = %d", status); } } return (status); }
// =-=-=-=-=-=-=- // 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
int _writeString( char *writeId, char *writeStr, ruleExecInfo_t *rei ) { // =-=-=-=-=-=-=- // JMC - backport 4619 dataObjInp_t dataObjInp; openedDataObjInp_t openedDataObjInp; bytesBuf_t tmpBBuf; int fd, i; // =-=-=-=-=-=-=- if ( writeId != NULL && strcmp( writeId, "serverLog" ) == 0 ) { rodsLog( LOG_NOTICE, "writeString: inString = %s", writeStr ); return 0; } // =-=-=-=-=-=-=- // JMC - backport 4619 if ( writeId != NULL && writeId[0] == '/' ) { /* writing to an existing iRODS file */ if ( rei == NULL || rei->rsComm == NULL ) { rodsLog( LOG_ERROR, "_writeString: input rei or rsComm is NULL" ); return SYS_INTERNAL_NULL_INPUT_ERR; } bzero( &dataObjInp, sizeof( dataObjInp ) ); dataObjInp.openFlags = O_RDWR; snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s", writeId ); fd = rsDataObjOpen( rei->rsComm, &dataObjInp ); if ( fd < 0 ) { rodsLog( LOG_ERROR, "_writeString: rsDataObjOpen failed. status = %d", fd ); return fd; } bzero( &openedDataObjInp, sizeof( openedDataObjInp ) ); openedDataObjInp.l1descInx = fd; openedDataObjInp.offset = 0; openedDataObjInp.whence = SEEK_END; fileLseekOut_t *dataObjLseekOut = NULL; i = rsDataObjLseek( rei->rsComm, &openedDataObjInp, &dataObjLseekOut ); free( dataObjLseekOut ); if ( i < 0 ) { rodsLog( LOG_ERROR, "_writeString: rsDataObjLseek failed. status = %d", i ); return i; } bzero( &openedDataObjInp, sizeof( openedDataObjInp ) ); openedDataObjInp.l1descInx = fd; tmpBBuf.len = openedDataObjInp.len = strlen( writeStr ) + 1; tmpBBuf.buf = writeStr; i = rsDataObjWrite( rei->rsComm, &openedDataObjInp, &tmpBBuf ); if ( i < 0 ) { rodsLog( LOG_ERROR, "_writeString: rsDataObjWrite failed. status = %d", i ); return i; } bzero( &openedDataObjInp, sizeof( openedDataObjInp ) ); openedDataObjInp.l1descInx = fd; i = rsDataObjClose( rei->rsComm, &openedDataObjInp ); return i; } // =-=-=-=-=-=-=- msParam_t * mP = NULL; msParamArray_t * inMsParamArray = rei->msParamArray; execCmdOut_t *myExecCmdOut; if ( ( ( mP = getMsParamByLabel( inMsParamArray, "ruleExecOut" ) ) != NULL ) && ( mP->inOutStruct != NULL ) ) { if ( !strcmp( mP->type, STR_MS_T ) ) { myExecCmdOut = ( execCmdOut_t* )malloc( sizeof( execCmdOut_t ) ); memset( myExecCmdOut, 0, sizeof( execCmdOut_t ) ); mP->inOutStruct = myExecCmdOut; mP->type = strdup( ExecCmdOut_MS_T ); } else { myExecCmdOut = ( execCmdOut_t* )mP->inOutStruct; } } else { myExecCmdOut = ( execCmdOut_t* )malloc( sizeof( execCmdOut_t ) ); memset( myExecCmdOut, 0, sizeof( execCmdOut_t ) ); if ( mP == NULL ) { addMsParam( inMsParamArray, "ruleExecOut", ExecCmdOut_MS_T, myExecCmdOut, NULL ); } else { mP->inOutStruct = myExecCmdOut; mP->type = strdup( ExecCmdOut_MS_T ); } } /***** Jun 27, 2007 i = replaceVariablesAndMsParams("",writeStr, rei->msParamArray, rei); if (i < 0) return i; ****/ if ( writeId != NULL ) { if ( !strcmp( writeId, "stdout" ) ) { appendToByteBuf( &( myExecCmdOut->stdoutBuf ), ( char * ) writeStr ); } else if ( !strcmp( writeId, "stderr" ) ) { appendToByteBuf( &( myExecCmdOut->stderrBuf ), ( char * ) writeStr ); } } return 0; }
int carryOverMsParam(msParamArray_t *sourceMsParamArray,msParamArray_t *targetMsParamArray) { int i; msParam_t *mP, *mPt; char *a, *b; if (sourceMsParamArray == NULL) return(0); /**** for (i = 0; i < sourceMsParamArray->len ; i++) { mPt = sourceMsParamArray->msParam[i]; if ((mP = getMsParamByLabel (targetMsParamArray, mPt->label)) != NULL) rmMsParamByLabel (targetMsParamArray, mPt->label, 1); addMsParam(targetMsParamArray, mPt->label, mPt->type, NULL,NULL); j = targetMsParamArray->len - 1; free(targetMsParamArray->msParam[j]->label); free(targetMsParamArray->msParam[j]->type); replMsParam(mPt,targetMsParamArray->msParam[j]); } ****/ /**** for (i = 0; i < sourceMsParamArray->len ; i++) { mPt = sourceMsParamArray->msParam[i]; if ((mP = getMsParamByLabel (targetMsParamArray, mPt->label)) != NULL) rmMsParamByLabel (targetMsParamArray, mPt->label, 1); addMsParamToArray(targetMsParamArray, mPt->label, mPt->type, mPt->inOutStruct, mPt->inpOutBuf, 1); } ****/ for (i = 0; i < sourceMsParamArray->len ; i++) { mPt = sourceMsParamArray->msParam[i]; if ((mP = getMsParamByLabel (targetMsParamArray, mPt->label)) != NULL) { a = mP->label; b = mP->type; mP->label = NULL; mP->type = NULL; /** free(mP->inOutStruct);**/ free(mP->inpOutBuf); replMsParam(mPt,mP); free(mP->label); mP->label = a; free(mP->type); mP->type = b; } else addMsParamToArray(targetMsParamArray, mPt->label, mPt->type, mPt->inOutStruct, mPt->inpOutBuf, 1); } /**** for (i = 0; i < sourceMsParamArray->len ; i++) { mPt = sourceMsParamArray->msParam[i]; if ((mP = getMsParamByLabel (targetMsParamArray, mPt->label)) != NULL) { if (mP->inOutStruct == mP->inOutStruct) { if (mP->type != mPt->type) { free(mP->type ); mP->type = mPt->type; } if (mP->label != mPt->label) { free(mP->label); mP->label= mPt->label; } } else { if (mP->type == mPt->type) a = mP->type; else { free(mP->type ); a = NULL; } if (mP->label == mPt->label) b = mP->label; else { free(mP->label ); b = NULL; } b = mP->label; free(mP->inOutStruct); free(mPt->inpOutBuf); replMsParam(mPt,mP); if (a != NULL) { free(mP->type); mP->type = a; } if (b != NULL) { free(mP->label); mP->label = b; } } } else { addMsParamToArray(targetMsParamArray, mPt->label, mPt->type, mPt->inOutStruct, mPt->inpOutBuf, 1); } } ***/ return(0); }