Пример #1
0
int _ikrbRcvTokenBody( int fd, gss_buffer_t tok, int length ) {
    unsigned int ret;
    int status;
    int i;

    i = tok->length;
    if ( i < length ) {
        status = KRB_ERROR_TOKEN_TOO_LARGE;
        rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                            "_ikrbRcvTokenBody error, token is too large for buffer, %d bytes in token, buffer is %d bytes",
                            length, tok->length );
        return status;
    }

    if ( tok->value == NULL ) {
        return KRB_ERROR_BAD_TOKEN_RCVED;
    }

    tok->length = length;

    ret = _ikrbReadAll( fd, ( char * ) tok->value, tok->length );
    if ( ret < 0 ) {
        return ret;
    }
    else if ( ret != tok->length ) {
        status = KRB_PARTIAL_TOKEN_READ;
        rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                            "reading token data: %d of %d bytes read\n",
                            ret, tok->length );
        return status;
    }

    return tok->length;
}
Пример #2
0
int
rsGsiAuthRequest( rsComm_t *rsComm, gsiAuthRequestOut_t **gsiAuthRequestOut ) {
    int status;

    if ( gsiAuthReqStatus == 1 ) {
        gsiAuthReqStatus = 0;
        if ( gsiAuthReqError != 0 ) {
            rodsLogAndErrorMsg( LOG_NOTICE, &rsComm->rError, gsiAuthReqError,
                                gsiAuthReqErrorMsg );
        }
        return gsiAuthReqError;
    }

    *gsiAuthRequestOut = ( gsiAuthRequestOut_t * )malloc( sizeof( gsiAuthRequestOut_t ) );
    memset( ( char * )*gsiAuthRequestOut, 0, sizeof( gsiAuthRequestOut_t ) );

#if defined(GSI_AUTH)
    status = igsiSetupCreds( NULL, rsComm, NULL, &( *gsiAuthRequestOut )->serverDN );
    if ( status == 0 ) {
        rsComm->gsiRequest = 1;
        if ( rsComm->auth_scheme != NULL ) {
            free( rsComm->auth_scheme );
        }
        rsComm->auth_scheme = strdup( "gsi" );
    }
    return status;
#else
    status = GSI_NOT_BUILT_INTO_SERVER;
    rodsLog( LOG_ERROR,
             "rsGsiAuthRequest failed GSI_NOT_BUILT_INTO_SERVER, status = %d",
             status );
    return status;
#endif

}
Пример #3
0
static void _ikrbLogError_1( char *callerMsg, OM_uint32 code, int type ) {
    OM_uint32 majorStatus, minorStatus;
    gss_buffer_desc msg;
    OM_uint32 msg_ctx;
    int status;
    char *whichSide;

    if ( ProcessType == CLIENT_PT ) {
        whichSide = "Client side:";
    }
    else {
        whichSide = "On iRODS-Server side:";
    }

    msg_ctx = 0;
    status = KRB_ERROR_FROM_KRB_LIBRARY;
    while ( 1 ) {
        majorStatus =    GSS_DISPLAY_STATUS( &minorStatus, code,
                                             type, GSS_C_NULL_OID,
                                             &msg_ctx, &msg );
        rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                            "%sGSS-API error %s: %s", whichSide, callerMsg,
                            ( char * ) msg.value );
        ( void )    GSS_RELEASE_BUFFER( &minorStatus, &msg );

        if ( !msg_ctx ) {
            break;
        }
    }
}
Пример #4
0
/*
 read the token hdr
 */
int _ikrbRcvTokenHeader( int fd ) {
    int length;
    char *cp;
    int ret;
    int status;

    length = 0;
    cp = ( char * ) &length;
    if ( sizeof( length ) > 4 ) {
        cp += sizeof( length ) - 4;
    }
    ret = _ikrbReadAll( fd, cp, 4 );
    if ( ret < 0 ) {
        return  KRB_ERROR_READING_TOKEN_LENGTH;
    }
    else if ( ret != 4 ) {
        if ( ret == 0 ) {
            return 0;
        }
        status = KRB_ERROR_READING_TOKEN_LENGTH;
        rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                            "reading token length: %d of %d bytes written",
                            ret, 4 );
        return status;
    }

    length = ntohl( length );

    if ( ikrbDebugFlag > 0 ) {
        fprintf( stderr, "token length = %d\n", length );
    }

    return length;
}
Пример #5
0
int _krbSendToken( int fd, gss_buffer_t tok ) {
    unsigned int len, ret;
    char *cp;
    int status;

    if ( ikrbDebugFlag > 0 ) {
        fprintf( stderr, "sending tok->length=%d\n", tok->length );
    }

    if ( ikrbTokenHeaderMode ) {
        len = htonl( tok->length );

        cp = ( char * ) &len;
        if ( sizeof( len ) > 4 ) {
            cp += sizeof( len ) - 4;
        }
        ret = _ikrbWriteAll( fd, cp, 4 );
        if ( ret < 0 ) {
            return KRB_ERROR_SENDING_TOKEN_LENGTH;
        }
        else if ( ret != 4 ) {
            status = KRB_ERROR_SENDING_TOKEN_LENGTH;
            rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                                "sending token data: %d of %d bytes written",
                                ret, tok->length );
            return status;
        }
    }

    ret = _ikrbWriteAll( fd, ( char * )tok->value, tok->length );
    if ( ret < 0 ) {
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    else if ( ret != tok->length ) {
        status = KRB_ERROR_SENDING_TOKEN_LENGTH;
        rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                            "sending token data2: %d of %d bytes written",
                            ret, tok->length );
        return status;
    }

    return 0;
}
Пример #6
0
/**
 * \fn msiWriteRodsLog (msParam_t *inpParam1,  msParam_t *outParam, ruleExecInfo_t *rei)
 *
 * \brief Writes a message into the server rodsLog.
 *
 * \module core
 *
 * \since 2.3
 *
 * \author  Jean-Yves Nief
 * \date    2009-06-15
 *
 * \note  This call should only be used through the rcExecMyRule (irule) call
 *        i.e., rule execution initiated by clients and should not be called
 *        internally by the server since it interacts with the client through
 *        the normal client/server socket connection.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] inpParam1 - A STR_MS_T which specifies the message to log.
 * \param[out] outParam - An INT_MS_T containing the status.
 * \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
msiWriteRodsLog (msParam_t *inpParam1,  msParam_t *outParam, ruleExecInfo_t *rei)
{
    rsComm_t *rsComm;

    RE_TEST_MACRO (" Calling msiWriteRodsLog")

    if (rei == NULL || rei->rsComm == NULL) {
        rodsLog (LOG_ERROR,
        "msiWriteRodsLog: input rei or rsComm is NULL");
        return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    rsComm = rei->rsComm;

    if ( inpParam1 == NULL ) {
        rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
        "msiWriteRodsLog: input Param1 is NULL");
        rei->status = USER__NULL_INPUT_ERR;
        return (rei->status);
    }

    if (strcmp (inpParam1->type, STR_MS_T) == 0) {
        rodsLog(LOG_NOTICE,
          "msiWriteRodsLog message: %s", inpParam1->inOutStruct);
    } else {
        rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
        "msiWriteRodsLog: Unsupported input Param1 types %s",
        inpParam1->type);
        rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
        return (rei->status);
    }

    rei->status = 0;

    fillIntInMsParam (outParam, rei->status);

    return (rei->status);
}
Пример #7
0
void logErrMsg(rError_t *errmsg, rError_t *system) {
    char errbuf[ERR_MSG_LEN * 16];
    errMsgToString(errmsg, errbuf, ERR_MSG_LEN * 16);
#ifdef DEBUG
    writeToTmp("err.log", "begin errlog\n");
    writeToTmp("err.log", errbuf);
    writeToTmp("err.log", "end errlog\n");
#endif
    if(system!=NULL) {
    	rodsLogAndErrorMsg(LOG_ERROR, system,RE_UNKNOWN_ERROR, "%s", errbuf);
    } else {
    	rodsLog (LOG_ERROR, "%s", errbuf);
    }
}
Пример #8
0
    /**
    * \fn msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    * \brief Open a fully qualified group name and get the group id.  nc_inq_grp_full_ncid is called to get the grpncid
    * \module core
    *
    * \since 3.2
    *
    * \author  Mike Wan
    * \date    2012
    *
    * \usage See clients/icommands/test/rules3.0/netcdfTest1.r, netcdfTest2.r and netcdfTest3.r.
    * \param[in] rootNcidParam - An INT_MS_T containing the rootNcid.
    * \param[in] fullGrpNameParam - A STR_MS_T containing the full group name
    * \param[out] outParam - An INT_MS_T containing the group ncid
    *
    **/
    int
    msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    {
        rsComm_t *rsComm;
        ncOpenInp_t ncOpenInp;
        int *grpNcid = NULL;

        RE_TEST_MACRO ("    Calling msiNcOpenGroup")

        if (rei == NULL || rei->rsComm == NULL) {
          rodsLog (LOG_ERROR,
            "msiNcOpenGroup: input rei or rsComm is NULL");
          return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        rsComm = rei->rsComm;

        bzero (&ncOpenInp, sizeof (ncOpenInp));
        if (rootNcidParam == NULL) {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: input rootNcidParam is NULL");
            return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        ncOpenInp.rootNcid = parseMspForPosInt (rootNcidParam);
        if (strcmp (fullGrpNameParam->type, STR_MS_T) == 0) {
            rstrcpy (ncOpenInp.objPath, (char*)fullGrpNameParam->inOutStruct,
              MAX_NAME_LEN);
        } else {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: Unsupported input fullGrpNameParam type %s",
              fullGrpNameParam->type);
            return (USER_PARAM_TYPE_ERR);
        }
        rei->status = irods::server_api_call ( NC_OPEN_GROUP_AN, rsComm, &ncOpenInp, &grpNcid);

        clearKeyVal (&ncOpenInp.condInput);
        if (rei->status >= 0) {
            fillIntInMsParam (outParam, *grpNcid);
            free (grpNcid);
        } else {
          rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
            "msiNcOpenGroup: api call to ncOpenGroup failed for rootNcid %d, status = %d",
            ncOpenInp.rootNcid, rei->status);
        }
        return (rei->status);
    }
Пример #9
0
/**
 * \fn msiDbrRollback(msParam_t *dbrName, ruleExecInfo_t *rei)
 *
 * \brief This microservice does a rollback on a Database Resource (DBR)
 *
 * \module core
 *
 * \since 2.5
 *
 * \author Wayne Schroeder
 * \date   2010-11-23
 *
 * \usage See clients/icommands/test/rules3.0/ and https://www.irods.org/index.php/DBR
 *
 * \param[in] dbrName - a STR_MS_T, name of the DBR being used
 * \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
msiDbrRollback(msParam_t *dbrName, ruleExecInfo_t *rei)
{
    rsComm_t *rsComm; 
    int status;

    databaseObjControlInp_t databaseObjControlInp;
    databaseObjControlOut_t *databaseObjControlOut;

    char *myDbrName;

    RE_TEST_MACRO ("    Calling msiDboRollback")

    if (rei == NULL || rei->rsComm == NULL) {
	rodsLog (LOG_ERROR,
	  "msiDbrRollback rei or rsComm is NULL");
	return (SYS_INTERNAL_NULL_INPUT_ERR);
    }
    rsComm = rei->rsComm;

    memset((void *)&databaseObjControlInp, 0, sizeof(databaseObjControlInp));

    myDbrName = parseMspForStr(dbrName);
    if (myDbrName == NULL) {
       rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
			   "msiDbrRollback: input dbrName is NULL");
       return(USER__NULL_INPUT_ERR);
    }

   databaseObjControlInp.dbrName = myDbrName;

   databaseObjControlInp.option =  DBR_ROLLBACK;

   status = rsDatabaseObjControl(rsComm, &databaseObjControlInp, 
				 &databaseObjControlOut);
   return(status);

}
Пример #10
0
int
rsRsyncFileToData (rsComm_t *rsComm, dataObjInp_t *dataObjInp)
{
    int status;
    char *fileChksumStr = NULL;
     char *dataObjChksumStr = NULL;
    dataObjInfo_t *dataObjInfoHead = NULL;

    fileChksumStr = getValByKey (&dataObjInp->condInput, RSYNC_CHKSUM_KW);

    if (fileChksumStr == NULL) {
        rodsLog (LOG_ERROR,
          "rsRsyncFileToData: RSYNC_CHKSUM_KW input is missing");
        return (CHKSUM_EMPTY_IN_STRUCT_ERR);
    }

    status = _rsDataObjChksum (rsComm, dataObjInp, &dataObjChksumStr,
      &dataObjInfoHead);

    if (status < 0 && status != CAT_NO_ACCESS_PERMISSION && 
      status != CAT_NO_ROWS_FOUND) {
        /* XXXXX CAT_NO_ACCESS_PERMISSION mean the chksum was calculated but
         * cannot be registered. But the chksum value is OK.
         */
        rodsLog (LOG_ERROR,
          "rsRsyncFileToData: _rsDataObjChksum of %s error. status = %d",
          dataObjInp->objPath, status);
    }

    freeAllDataObjInfo (dataObjInfoHead);

    if (dataObjChksumStr != NULL &&
      strcmp (dataObjChksumStr, fileChksumStr) == 0) {
	free (dataObjChksumStr);
	return (0);
    }
    return SYS_SVR_TO_CLI_PUT_ACTION;
#if 0
    msParamArray_t *myMsParamArray;
    dataObjInp_t *myDataObjInp;

    myMsParamArray = malloc (sizeof (msParamArray_t));
    memset (myMsParamArray, 0, sizeof (msParamArray_t));
    /* have to get its own dataObjInp_t */
    myDataObjInp = malloc (sizeof (dataObjInp_t));
    replDataObjInp (dataObjInp, myDataObjInp);
    addKeyVal (&myDataObjInp->condInput, REG_CHKSUM_KW, fileChksumStr);

    status = addMsParam (myMsParamArray, CL_PUT_ACTION, DataObjInp_MS_T,
      (void *) myDataObjInp, NULL);

    if (status < 0) {
        rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
          "rsRsyncDataToFile: addMsParam error. status = %d", status);
        return (status);
    }

    /* tell the client to do the put */
    status = sendAndRecvBranchMsg (rsComm, rsComm->apiInx,
     SYS_SVR_TO_CLI_MSI_REQUEST, (void *) myMsParamArray, NULL);

    return (status);
#endif
}
Пример #11
0
/**
 * \fn msiDigestMonStat(msParam_t *cpu_wght, msParam_t *mem_wght, msParam_t *swap_wght,
 *       msParam_t *runq_wght, msParam_t *disk_wght, msParam_t *netin_wght,
 *       msParam_t *netout_wght, ruleExecInfo_t *rei)
 *
 * \brief  This microservice calculates and stores a load factor for each connected
 *    resource based on the weighting values passed in as parameters.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2009-06
 *
 * \note  The following values are loaded from R_LOAD_SERVER:
 *    \li cpu_used
 *    \li mem_used
 *    \li swap_used
 *    \li runq_load
 *    \li disk_space
 *    \li net_input
 *    \li net_output
 *
 * \note  The stored load factor is calculated as such:
 *    \li load_factor = cpu_wght*cpu_used + mem_wght*mem_used + swap_wght*swap_used +
 *        runq_wght*runq_load + disk_wght*disk_space + netin_wght*net_input +
 *        netout_wght*net_output
 *
 * \usage See clients/icommands/test/rules3.0/ and https://wiki.irods.org/index.php/Resource_Monitoring_System
 *
 * \param[in] cpu_wght - Required - a msParam of type STR_MS_T defining relative CPU weighting.
 * \param[in] mem_wght - Required - a msParam of type STR_MS_T defining relative memory weighting
 * \param[in] swap_wght - Required - a msParam of type STR_MS_T defining relative swap weighting
 * \param[in] runq_wght - Required - a msParam of type STR_MS_T defining relative run queue weighting
 * \param[in] disk_wght - Required - a msParam of type STR_MS_T defining relative disk space weighting
 * \param[in] netin_wght - Required - a msParam of type STR_MS_T defining relative inbound network weighting
 * \param[in] netout_wght - Required - a msParam of type STR_MS_T defining relative outbound network weighting
 * \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 R_SERVER_LOAD table content
 * \iCatAttrModified R_SERVER_LOAD_DIGEST table content
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa  N/A
 **/
int msiDigestMonStat( msParam_t *cpu_wght, msParam_t *mem_wght, msParam_t *swap_wght, msParam_t *runq_wght,
                      msParam_t *disk_wght, msParam_t *netin_wght, msParam_t *netout_wght,
                      ruleExecInfo_t *rei ) {
    char rescList[MAX_NSERVERS][MAX_NAME_LEN], *tResult,
         timeList[MAX_NSERVERS][MAX_NAME_LEN];
    char condStr1[MAX_NAME_LEN], condStr2[MAX_NAME_LEN], loadStr[MAX_NAME_LEN];
    int i, j, loadFactor, nresc, rc, status, totalWeight, weight[NRESULT];
    rsComm_t *rsComm;
    generalRowInsertInp_t generalRowInsertInp;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;

    RE_TEST_MACRO( "    Calling msiDigestMonStat" );

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR,
                 "msiDigestMonStat: input rei or rsComm is NULL" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    rsComm = rei->rsComm;

    if ( cpu_wght == NULL || mem_wght == NULL || swap_wght == NULL || runq_wght == NULL
            || disk_wght == NULL || netin_wght == NULL || netout_wght == NULL ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: at least one of the input param is NULL" );
        return rei->status;
    }

    if ( strcmp( cpu_wght->type, STR_MS_T ) == 0 ) {
        weight[0] = atoi( ( const char* )cpu_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input cpu_wght type %s",
                            cpu_wght->type );
        return rei->status;
    }

    if ( strcmp( mem_wght->type, STR_MS_T ) == 0 ) {
        weight[1] = atoi( ( const char* )mem_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input mem_wght type %s",
                            mem_wght->type );
        return rei->status;
    }

    if ( strcmp( swap_wght->type, STR_MS_T ) == 0 ) {
        weight[2] = atoi( ( const char* )swap_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input swap_wght type %s",
                            swap_wght->type );
        return rei->status;
    }

    if ( strcmp( runq_wght->type, STR_MS_T ) == 0 ) {
        weight[3] = atoi( ( const char* )runq_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input runq_wght type %s",
                            runq_wght->type );
        return rei->status;
    }

    if ( strcmp( disk_wght->type, STR_MS_T ) == 0 ) {
        weight[4] = atoi( ( const char* )disk_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input disk_wght type %s",
                            disk_wght->type );
        return rei->status;
    }

    if ( strcmp( netin_wght->type, STR_MS_T ) == 0 ) {
        weight[5] = atoi( ( const char* )netin_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input netin_wght type %s",
                            netin_wght->type );
        return rei->status;
    }

    if ( strcmp( netout_wght->type, STR_MS_T ) == 0 ) {
        weight[6] = atoi( ( const char* )netout_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input netout_wght type %s",
                            netout_wght->type );
        return rei->status;
    }

    totalWeight = 0;
    for ( i = 0; i < NRESULT; i++ ) {
        totalWeight += weight[i];
    }

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_SL_RESC_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_CREATE_TIME, SELECT_MAX );
    genQueryInp.maxRows = MAX_SQL_ROWS;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( NULL == genQueryOut ) { // JMC cppcheck - nullptr
        rodsLog( LOG_ERROR, "msiDigestMonStat :: &genQueryOut is NULL" );
        return rei->status;
    }
    if ( status == 0 ) {
        nresc = genQueryOut->rowCnt;
        for ( i = 0; i < genQueryOut->attriCnt; i++ ) {
            for ( j = 0; j < nresc; j++ ) {
                tResult = genQueryOut->sqlResult[i].value;
                tResult += j * genQueryOut->sqlResult[i].len;
                if ( i == 0 ) {
                    rstrcpy( rescList[j], tResult, genQueryOut->sqlResult[i].len );
                }
                if ( i == 1 ) {
                    rstrcpy( timeList[j], tResult, genQueryOut->sqlResult[i].len );
                }
            }
        }
    }
    else {
        rodsLog( LOG_ERROR, "msiDigestMonStat: Unable to retrieve information \
                        from R_SERVER_LOAD" );
        return rei->status;
    }

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_SL_CPU_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_MEM_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_SWAP_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_RUNQ_LOAD, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_DISK_SPACE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_NET_INPUT, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_NET_OUTPUT, 1 );
    genQueryInp.maxRows = 1;
    generalRowInsertInp.tableName = "serverloaddigest";
    for ( i = 0; i < nresc; i++ ) {
        memset( &genQueryInp.sqlCondInp, 0, sizeof( genQueryInp.sqlCondInp ) );
        snprintf( condStr1, MAX_NAME_LEN, "= '%s'", rescList[i] );
        addInxVal( &genQueryInp.sqlCondInp, COL_SL_RESC_NAME, condStr1 );
        snprintf( condStr2, MAX_NAME_LEN, "= '%s'", timeList[i] );
        addInxVal( &genQueryInp.sqlCondInp, COL_SL_CREATE_TIME, condStr2 );
        status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            loadFactor = 0;
            for ( j = 0; j < genQueryOut->attriCnt; j++ ) {
                tResult = genQueryOut->sqlResult[j].value;
                loadFactor += atoi( tResult ) * weight[j];
            }
            loadFactor = loadFactor / totalWeight;
            generalRowInsertInp.arg1 = rescList[i];
            snprintf( loadStr, MAX_NAME_LEN, "%i", loadFactor );
            generalRowInsertInp.arg2 = loadStr;
            rc = rsGeneralRowInsert( rsComm, &generalRowInsertInp );
            if ( rc != 0 ) {
                rodsLog( LOG_ERROR, "msiDigestMonStat: Unable to ingest\
        information into from R_SERVER_LOAD_DIGEST table" );
            }
        }
Пример #12
0
/**
 * \fn msiFlushMonStat (msParam_t *inpParam1, msParam_t *inpParam2, ruleExecInfo_t *rei)
 *
 * \brief  This microservice flushes the servers' monitoring statistics.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2009-06
 *
 * \note  This microservice removes the servers' metrics older than the
 *    number of hours in "timespan".
 *
 * \usage See clients/icommands/test/rules3.0/ and https://wiki.irods.org/index.php/Resource_Monitoring_System
 *
 * \param[in] inpParam1 - Required - a msParam of type STR_MS_T defining the timespan in hours.
 *    "default" is equal to 24 hours.
 * \param[in] inpParam2 - Required - a msParam of type STR_MS_T defining the tablename to be
 *    flushed.  Currently must be either "serverload" or "serverloaddigest".
 * \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 table R_SERVER_LOAD content
 * \iCatAttrModified table R_SERVER_LOAD content
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa  N/A
 **/
int msiFlushMonStat( msParam_t *inpParam1, msParam_t *inpParam2, ruleExecInfo_t *rei ) {
    int elapseTime, defaultTimespan, rc;
    char secAgo[MAXLEN], *tablename, *timespan;
    generalRowPurgeInp_t generalRowPurgeInp;
    rsComm_t *rsComm;

    RE_TEST_MACRO( "    Calling msiFlushMonStat" );

    defaultTimespan = 24;  /* in hours */

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR, "msiFlushMonStat: input rei or rsComm is NULL" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    rsComm = rei->rsComm;

    if ( inpParam1 == NULL ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiFlushMonStat: input Param1 is NULL" );
        return rei->status;
    }

    if ( strcmp( inpParam1->type, STR_MS_T ) == 0 ) {
        timespan = ( char * ) inpParam1->inOutStruct;
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiFlushMonStat: Unsupported input Param1 type %s",
                            inpParam1->type );
        return rei->status;
    }

    if ( inpParam2 == NULL ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiFlushMonStat: input Param2 is NULL" );
        return rei->status;
    }

    if ( strcmp( inpParam2->type, STR_MS_T ) == 0 ) {
        tablename = ( char * ) inpParam2->inOutStruct;
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiFlushMonStat: Unsupported input Param2 type %s",
                            inpParam2->type );
        return rei->status;
    }

    if ( atoi( timespan ) > 0 ) {
        elapseTime = atoi( timespan ) * 3600;
    }
    else {
        elapseTime = defaultTimespan * 3600; /* default timespan in seconds */
    }

    if ( strcmp( tablename, "serverload" ) != 0 &&
            strcmp( tablename, "serverloaddigest" ) != 0 ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiFlushMonStat: table %s does not exist", tablename );
        return rei->status;
    }

    generalRowPurgeInp.tableName = tablename;
    snprintf( secAgo, MAXLEN, "%i", elapseTime );
    generalRowPurgeInp.secondsAgo = secAgo;
    rc = rsGeneralRowPurge( rsComm, &generalRowPurgeInp );

    if ( rc != 0 && rc != CAT_SUCCESS_BUT_WITH_NO_INFO ) {
        rodsLog( LOG_ERROR, "msiFlushMonStat failed, error %i", rc );
    }

    return rei->status;
}
Пример #13
0
/*
 Set up an session between this server and a connected new client.

 Establishses a GSS-API context (as the service specified in
 ikrbSetupCreds) with an incoming client, and returns the
 authenticated client name (the id on the other side of the socket).
 The other side (the client) must call ikrbEstablishContextClientside at
 about the same time for the exchanges across the network to work
 (each side will block waiting for the other).

 If successful, the context handle is set in the global context array.
 If unsuccessful, an error message is displayed and -1 is returned.

 */
int ikrbEstablishContextServerside( rsComm_t *rsComm, char *clientName,
                                    int maxLen_clientName ) {
#if defined(KRB_AUTH)
    int fd;
    int status;

    fd = rsComm->sock;
    ikrb_rErrorPtr = &rsComm->rError;

    gss_buffer_desc send_buffer, recv_buffer;
    gss_buffer_desc client_name;
    gss_name_t client;
    gss_OID doid;
    OM_uint32 majorStatus, minorStatus;

    int i, j;

#if defined(IKRB_TIMING)
    struct timeval startTimeFunc, endTimeFunc, sTimeDiff;
    float fSec;
    /* Starting timer for function */
    ( void ) gettimeofday( &startTimeFunc, ( struct timezone * ) 0 );

#endif

    context[fd] = GSS_C_NO_CONTEXT;

    recv_buffer.value = &ikrbScratchBuffer;

    do {
        recv_buffer.length = SCRATCH_BUFFER_SIZE;
        status =  _ikrbRcvToken( fd, &recv_buffer );
        if ( status <= 0 ) {
            rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                                "ikrbEstablishContextServerside" );
            return status;
        }
        if ( ikrbDebugFlag > 0 ) {
            fprintf( stderr, "Received token (size=%d): \n",
                     recv_buffer.length );
            _ikrbPrintToken( &recv_buffer );
        }

        majorStatus =    GSS_ACCEPT_SEC_CONTEXT( &minorStatus,
                         &context[fd], myCreds, &recv_buffer,
                         GSS_C_NO_CHANNEL_BINDINGS, &client, &doid,
                         &send_buffer, &context_flags,
                         NULL,     /* ignore time_rec */
                         NULL );   /* ignore del_cred_handle */

        if ( majorStatus != GSS_S_COMPLETE
                && majorStatus != GSS_S_CONTINUE_NEEDED ) {
            _ikrbLogError( "accepting context", majorStatus, minorStatus );
            memset( ikrbScratchBuffer, 0, SCRATCH_BUFFER_SIZE );
            return KRB_ACCEPT_SEC_CONTEXT_ERROR;
        }

        /* since buffer is not malloc'ed, don't need to call
           gss_release_buffer, instead clear it. */
        memset( ikrbScratchBuffer, 0, SCRATCH_BUFFER_SIZE );

        if ( send_buffer.length != 0 ) {
            if ( ikrbDebugFlag > 0 ) {
                fprintf( stderr,
                         "Sending accept_sec_context token (size=%d):\n",
                         send_buffer.length );
                _ikrbPrintToken( &send_buffer );
            }
            status = _krbSendToken( fd, &send_buffer );
            if ( status < 0 ) {
                return status;
            }
        }
        if ( ikrbDebugFlag > 0 ) {
            if ( majorStatus == GSS_S_CONTINUE_NEEDED ) {
                fprintf( stderr, "continue needed...\n" );
            }
        }
    }
    while ( majorStatus == GSS_S_CONTINUE_NEEDED );

    /* convert name (internally represented) to a string */
    majorStatus =
        GSS_DISPLAY_NAME( &minorStatus, client, &client_name, &doid );
    if ( majorStatus != GSS_S_COMPLETE ) {
        _ikrbLogError( "displaying name", majorStatus, minorStatus );
        return KRB_ERROR_DISPLAYING_NAME;
    }

    i = client_name.length;
    if ( maxLen_clientName < i ) {
        i = maxLen_clientName;
    }

    strncpy( clientName, ( char * )client_name.value, i );
    j = client_name.length;
    if ( maxLen_clientName > j ) {
        clientName[client_name.length] = '\0';
    }

    /* release the name structure */
    majorStatus =    GSS_RELEASE_NAME( &minorStatus, &client );

    if ( majorStatus != GSS_S_COMPLETE ) {
        _ikrbLogError( "releasing name", majorStatus, minorStatus );
        return KRB_ERROR_RELEASING_NAME;
    }

    ( void )    GSS_RELEASE_BUFFER( &minorStatus, &client_name );

#if defined(IKRB_TIMING)
    ( void ) gettimeofday( &endTimeFunc, ( struct timezone * ) 0 );
    ( void ) _ikrbTime( &sTimeDiff, &endTimeFunc, &startTimeFunc );
    fSec =
        ( float ) sTimeDiff.tv_sec + ( ( float ) sTimeDiff.tv_usec / 1000000.0 );

    /* for IKRB_TIMING  print time */
    fprintf( stdout, " ---  %.5f sec time taken for executing "
             "ikrbEstablishContextServerside() ---  \n", fSec );
#endif

    return 0;

#else
    if ( ProcessType == CLIENT_PT ) {
        return KRB_NOT_BUILT_INTO_CLIENT;
    }
    else {
        return KRB_NOT_BUILT_INTO_SERVER;
    }
#endif
}
Пример #14
0
int ikrbEstablishContextClientside( rcComm_t *Comm, char *serviceName,
                                    int delegFlag ) {
#if defined(KRB_AUTH)
    int fd;
    int status;

    fd = Comm->sock;

    ikrb_rErrorPtr = Comm->rError;

    gss_OID oid = GSS_C_NULL_OID;
    gss_buffer_desc send_tok, recv_tok, *tokenPtr, name_buffer;
    gss_name_t target_name;
    OM_uint32 majorStatus, minorStatus;
    OM_uint32 flags = 0;

#if defined(IKRB_TIMING)
    struct timeval startTimeFunc, endTimeFunc, sTimeDiff;
    float fSec;
    /* Starting timer for function */
    ( void ) gettimeofday( &startTimeFunc, ( struct timezone * ) 0 );
#endif

    if ( serviceName != 0 && strlen( serviceName ) > 0 ) {
        /*
        * Import the name into target_name.
        */
        name_buffer.value = serviceName;
        name_buffer.length = strlen( serviceName ) + 1;

        majorStatus =    GSS_IMPORT_NAME( &minorStatus, &name_buffer,
                                          ( gss_OID ) gss_nt_service_name_krb,
                                          &target_name );

        if ( majorStatus != GSS_S_COMPLETE ) {
            /* could use "if (GSS_ERROR(majorStatus))" but I believe it should
               always be GSS_S_COMPLETE if successful  */
            _ikrbLogError
            ( "importing name (ikrbEstablishContextClientside)", majorStatus,
              minorStatus );
            return KRB_ERROR_IMPORT_NAME;
        }
    }
    /*
     * Perform the context-establishment loop.
     *
     * On each pass through the loop, tokenPtr points to the token
     * to send to the server (or GSS_C_NO_BUFFER on the first pass).
     * Every generated token is stored in send_tok which is then
     * transmitted to the server; every received token is stored in
     * recv_tok, which tokenPtr is then set to, to be processed by
     * the next call to gss_init_sec_context.
     *
     * GSS-API guarantees that send_tok's length will be non-zero
     * if and only if the server is expecting another token from us,
     * and that gss_init_sec_context returns GSS_S_CONTINUE_NEEDED if
     * and only if the server has another token to send us.
     */

    tokenPtr = GSS_C_NO_BUFFER;
    context[fd] = GSS_C_NO_CONTEXT;
    flags = GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG;
    if ( delegFlag ) {
        flags |= GSS_C_DELEG_FLAG;
    }

    do {
        if ( ikrbDebugFlag > 0 ) {
            fprintf( stderr, "--> calling gss_init_sec_context\n" );
        }

        if ( serviceName != 0 && strlen( serviceName ) > 0 ) {
            majorStatus =    GSS_INIT_SEC_CONTEXT( &minorStatus,
                                                   myCreds, &context[fd], target_name, oid,
                                                   flags, 0,
                                                   NULL,   /* no channel bindings */
                                                   tokenPtr, NULL,    /* ignore mech type */
                                                   &send_tok, &context_flags,
                                                   NULL );  /* ignore time_rec */
        }
        else {
            majorStatus =    GSS_INIT_SEC_CONTEXT( &minorStatus,
                                                   myCreds, &context[fd], GSS_C_NO_NAME, oid,
                                                   flags, 0,
                                                   NULL,   /* no channel bindings */
                                                   tokenPtr, NULL,    /* ignore mech type */
                                                   &send_tok, &context_flags,
                                                   NULL );  /* ignore time_rec */
        }

        /* since recv_tok is not malloc'ed, don't need to call
           gss_release_buffer, instead clear it. */
        memset( ikrbScratchBuffer, 0, SCRATCH_BUFFER_SIZE );

        if ( majorStatus != GSS_S_COMPLETE
                && majorStatus != GSS_S_CONTINUE_NEEDED ) {
            _ikrbLogError( "initializing context",
                           majorStatus, minorStatus );
            ( void )    GSS_RELEASE_NAME( &minorStatus, &target_name );
            return KRB_ERROR_INIT_SECURITY_CONTEXT;
        }

        if ( send_tok.length != 0 ) {
            status = _krbSendToken( fd, &send_tok );
            if ( status < 0 ) {
                rodsLogAndErrorMsg( LOG_ERROR, ikrb_rErrorPtr, status,
                                    "Sending init_sec_context token (size=%d)\n",
                                    send_tok.length );
                ( void )    GSS_RELEASE_BUFFER( &minorStatus, &send_tok );
                ( void )    GSS_RELEASE_NAME( &minorStatus, &target_name );
                return status; /* KRB_SOCKET_WRITE_ERROR */
            }
        }

        ( void )    GSS_RELEASE_BUFFER( &minorStatus, &send_tok );

        if ( majorStatus == GSS_S_CONTINUE_NEEDED ) {
            if ( ikrbDebugFlag > 0 ) {
                fprintf( stderr, "continue needed...\n" );
            }
            recv_tok.value = &ikrbScratchBuffer;
            recv_tok.length = SCRATCH_BUFFER_SIZE;
            if ( _ikrbRcvToken( fd, &recv_tok ) <= 0 ) {
                ( void )    GSS_RELEASE_NAME( &minorStatus, &target_name );
                return KRB_ERROR_RELEASING_NAME;
            }
            tokenPtr = &recv_tok;
        }
    }
    while ( majorStatus == GSS_S_CONTINUE_NEEDED );

    if ( serviceName != 0 && strlen( serviceName ) > 0 ) {
        ( void )    GSS_RELEASE_NAME( &minorStatus, &target_name );
    }

    if ( ikrbDebugFlag > 0 ) {
        _ikrbDisplayCtxFlags();
    }

#if defined(IKRB_TIMING)
    ( void ) gettimeofday( &endTimeFunc, ( struct timezone * ) 0 );
    ( void ) _ikrbTime( &sTimeDiff, &endTimeFunc, &startTimeFunc );
    fSec =
        ( float ) sTimeDiff.tv_sec + ( ( float ) sTimeDiff.tv_usec / 1000000.0 );

    /* for IKRB_TIMING  print time */
    fprintf( stdout, " ---  %.5f sec time taken for executing "
             "ikrbEstablishContextClientside() ---  \n", fSec );
#endif
    return 0;

#else
    if ( ProcessType == CLIENT_PT ) {
        return KRB_NOT_BUILT_INTO_CLIENT;
    }
    else {
        return KRB_NOT_BUILT_INTO_SERVER;
    }
#endif

}
Пример #15
0
/*
 * Gets pipe separated metadata AVUs for a collection. - from eraUtil.c
 * 
 */
int
getCollectionPSmeta(char *objPath, bytesBuf_t *mybuf, rsComm_t *rsComm)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[MAX_NAME_LEN];
   int printCount=0;
   int status;



   if (rsComm == NULL) {
	rodsLog (LOG_ERROR,
	  "getCollectionPSmeta: input rsComm is NULL");
	return (SYS_INTERNAL_NULL_INPUT_ERR);
   }


   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   i1a[0]=COL_META_COLL_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_COLL_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_COLL_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'", objPath);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;


   /* Actual query happens here */
   status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);

   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_COLL_COMMENTS;
      genQueryInp.selectInp.len = 1;
      status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
      if (status==0) {
	    printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {

	rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
          "getCollectionPSmeta: Collection %s not found. status = %d", objPath, status);
	return (status);
      }
   }

   printCount+=extractPSQueryResults(status, genQueryOut, mybuf, objPath);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
      printCount+= extractPSQueryResults(status, genQueryOut, mybuf, objPath);
   }

  return (status);

}
Пример #16
0
/*
 * Gets pipe separated metadata AVUs for a data object. - from eraUtil.c
 * 
 */
int
getDataObjPSmeta(char *objPath, bytesBuf_t *mybuf, rsComm_t *rsComm)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[MAX_NAME_LEN];
   char v2[MAX_NAME_LEN];
   char fullName[MAX_NAME_LEN];
   char myDirName[MAX_NAME_LEN];
   char myFileName[MAX_NAME_LEN];
   int printCount=0;
   int status;


   if (rsComm == NULL) {
	rodsLog (LOG_ERROR,
	  "getDataObjPSmeta: input rsComm is NULL");
	return (SYS_INTERNAL_NULL_INPUT_ERR);
   }

   
   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   i1a[0]=COL_META_DATA_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_DATA_ATTR_VALUE;
   i1b[1]=0; /* currently unused */
   i1a[2]=COL_META_DATA_ATTR_UNITS;
   i1b[2]=0; /* currently unused */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   /* Extract cwd name and object name */
   strncpy(fullName, objPath, MAX_NAME_LEN);
   status = splitPathByKey(fullName, myDirName, myFileName, '/');

   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",myDirName);
   condVal[0]=v1;

   i2a[1]=COL_DATA_NAME;
   sprintf(v2,"='%s'",myFileName);
   condVal[1]=v2;


   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;


   /* Actual query happens here */
   status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);


   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_D_DATA_PATH;
      genQueryInp.selectInp.len = 1;
      status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
      if (status==0) {
	 /* printf("None\n"); */
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {

	rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
          "getDataObjPSmeta: DataObject %s not found. status = %d", fullName, status);
	return (status);
      }
      printCount+=extractPSQueryResults(status, genQueryOut, mybuf, fullName);
   }
   else {
      printCount+=extractPSQueryResults(status, genQueryOut, mybuf, fullName);
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
      printCount+= extractPSQueryResults(status, genQueryOut, mybuf, fullName);
   }

  return (status);
}
Пример #17
0
/**
 * \fn msiSetACL (msParam_t *recursiveFlag, msParam_t *accessLevel, msParam_t *userName, msParam_t *pathName, ruleExecInfo_t *rei)
 *
 * \brief   This microservice changes the ACL for a given pathname,
 *            either a collection or a data object.
 *
 * \module core
 *
 * \since 2.3
 *
 *
 * \note This microservice modifies the access rights on a given iRODS object or
 *    collection. For the collections, the modification can be recursive and the
 *    inheritence bit can be changed as well.
 *    For admin mode, add MOD_ADMIN_MODE_PREFIX to the access level string,
 *    e.g: msiSetACL("default", "admin:read", "rods", *path)
 *
 * \usage See clients/icommands/test/rules/
 *
 * \param[in] recursiveFlag - a STR_MS_T, either "default" or "recursive".  "recursive"
 *    is only relevant if set with accessLevel set to "inherit".
 * \param[in] accessLevel - a STR_MS_T containing one of the following:
 *    \li read
 *    \li write
 *    \li own
 *    \li inherit
 *    \li null
 * \param[in] userName - a STR_MS_T, the user name or group name who will have ACL changed.
 * \param[in] pathName - a STR_MS_T, the collection or data object that will have its ACL changed.
 * \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 $userName and/or $objPath and/or $collName
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 on success
 * \pre N/A
 * \post N/A
 * \sa N/A
**/
int msiSetACL( msParam_t *recursiveFlag, msParam_t *accessLevel, msParam_t *userName,
               msParam_t *pathName, ruleExecInfo_t *rei ) {
    char *acl, *path, *recursiveFlg, *user, uname[NAME_LEN], *zone;
    int recFlg, rc;
    modAccessControlInp_t modAccessControlInp;
    rsComm_t *rsComm = 0; // JMC cppcheck - uninit var

    RE_TEST_MACRO( "    Calling msiSetACL" )
    /* the above line is needed for loop back testing using irule -i option */

    if ( recursiveFlag == NULL || accessLevel == NULL || userName == NULL ||
            pathName == NULL ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiSetACL: one of the input parameter is NULL" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    recFlg = 0; /* non recursive mode */
    if ( strcmp( recursiveFlag->type, STR_MS_T ) == 0 ) {
        recursiveFlg = ( char * ) recursiveFlag->inOutStruct;
        if ( strcmp( recursiveFlg, "recursive" ) == 0 ) {
            /* recursive mode */
            recFlg = 1;
        }
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiSetACL: Unsupported input recursiveFlag type %i",
                            recursiveFlag->type );
        return USER_PARAM_TYPE_ERR;
    }

    if ( strcmp( accessLevel->type, STR_MS_T ) == 0 ) {
        acl = ( char * ) accessLevel->inOutStruct;
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiSetACL: Unsupported input accessLevel type %s",
                            accessLevel->type );
        return USER_PARAM_TYPE_ERR;
    }

    if ( strcmp( userName->type, STR_MS_T ) == 0 ) {
        user = ( char * ) userName->inOutStruct;
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiSetACL: Unsupported input userName type %s",
                            userName->type );
        return USER_PARAM_TYPE_ERR;
    }

    if ( strcmp( pathName->type, STR_MS_T ) == 0 ) {
        path = ( char * ) pathName->inOutStruct;
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiSetACL: Unsupported input pathName type %s",
                            pathName->type );
        return USER_PARAM_TYPE_ERR;
    }

    rsComm = rei->rsComm;
    modAccessControlInp.recursiveFlag = recFlg;
    modAccessControlInp.accessLevel = acl;
    if ( strchr( user, '#' ) == NULL ) {
        modAccessControlInp.userName = user;
        modAccessControlInp.zone = rei->uoic->rodsZone;
    }
    else {
        zone = strchr( user, '#' ) + 1;
        memset( uname, '\0', NAME_LEN );
        strncpy( uname, user, strlen( user ) - strlen( zone ) - 1 );
        modAccessControlInp.userName = uname;
        modAccessControlInp.zone = zone;
    }
    modAccessControlInp.path = path;
    rc = rsModAccessControl( rsComm, &modAccessControlInp );
    if ( rc < 0 ) {
        rodsLog( LOG_NOTICE, "msiSetACL: ACL modifications has failed for user %s on object %s, error = %i\n", user, path, rc );
    }

    return rc;
}
Пример #18
0
/**
 * \fn msiDboExec(msParam_t *dbrName, msParam_t *dboName, msParam_t *dborName,
 *      msParam_t *options,
 *      msParam_t *inpParam1, msParam_t *inpParam2, 
 *      msParam_t *inpParam3, msParam_t *inpParam4, 
 *      msParam_t *inpParam5, msParam_t *inpParam6, 
 *      ruleExecInfo_t *rei)
 *
 * \brief Execute a database object on a DBR
 *
 * \module core
 *
 * \since 2.5
 *
 * \author Wayne Schroeder
 * \date   2010-11-23
 *
 * \usage See clients/icommands/test/rules3.0/ and https://www.irods.org/index.php/DBR
 *
 * \param[in] dbrName - a STR_MS_T, name of the DBR being used
 * \param[in] dboName - a STR_MS_T, name of the DBO being used
 * \param[in] dborName - a STR_MS_T, name of the DBOR being used
 * \param[in] options - a STR_MS_T, currently 'force' or not
 * \param[in] inpParam1 - Optional - STR_MS_T parameters to the DBO SQL.
 * \param[in] inpParam2 - Optional - STR_MS_T parameters to the DBO SQL.
 * \param[in] inpParam3 - Optional - STR_MS_T parameters to the DBO SQL.
 * \param[in] inpParam4 - Optional - STR_MS_T parameters to the DBO SQL.
 * \param[in] inpParam5 - Optional - STR_MS_T parameters to the DBO SQL.
 * \param[in] inpParam6 - Optional - STR_MS_T parameters to the DBO SQL.
 * \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
msiDboExec(msParam_t *dbrName, msParam_t *dboName, msParam_t *dborName,
	   msParam_t *options,
	   msParam_t *inpParam1, msParam_t *inpParam2, 
	   msParam_t *inpParam3, msParam_t *inpParam4, 
	   msParam_t *inpParam5, msParam_t *inpParam6, 
	   ruleExecInfo_t *rei) {
    rsComm_t *rsComm; 
    char *myDbrName;
    char *myDboName;
    char *myDborName;
    char *myOptions;
    char *p1;
    char *p2;
    char *p3;
    char *p4;
    char *p5;
    char *p6;
    databaseObjControlInp_t databaseObjControlInp;
    databaseObjControlOut_t *databaseObjControlOut;
    int status;

    RE_TEST_MACRO ("    Calling msiDboExec")

    if (rei == NULL || rei->rsComm == NULL) {
	rodsLog (LOG_ERROR,
	  "msiDboExec rei or rsComm is NULL");
	return (SYS_INTERNAL_NULL_INPUT_ERR);
    }
    rsComm = rei->rsComm;

    myDbrName = parseMspForStr(dbrName);
    if (myDbrName == NULL) {
	rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
          "msiDboExec: input dbrName is NULL");
        return (USER__NULL_INPUT_ERR);
    }

    myDboName = parseMspForStr(dboName);
    if (myDboName == NULL) {
	rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
          "msiDboExec: input dboName is NULL");
        return (USER__NULL_INPUT_ERR);
    }


    myDborName = parseMspForStr(dborName);
    if (myDborName == NULL) {
	rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
          "msiDboExec: input dborName is NULL");
        return (USER__NULL_INPUT_ERR);
    }

    myOptions = parseMspForStr(options);

    p1 = parseMspForStr(inpParam1);
    p2 = parseMspForStr(inpParam2);
    p3 = parseMspForStr(inpParam3);
    p4 = parseMspForStr(inpParam4);
    p5 = parseMspForStr(inpParam5);
    p6 = parseMspForStr(inpParam6);

    if (rei->status < 0) {
        rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
          "msiDboExec: input inpParam error. status = %d", rei->status);
        return (rei->status);
    }

    memset((void *)&databaseObjControlInp, 0, sizeof(databaseObjControlInp));

    databaseObjControlInp.option = DBO_EXECUTE;

    databaseObjControlInp.dbrName = myDbrName;
    databaseObjControlInp.dboName = myDboName;
    databaseObjControlInp.dborName = myDborName;

    if (strcmp(myOptions, "force")==0) {
       databaseObjControlInp.subOption = 1;
    }

    databaseObjControlInp.args[0] = p1;
    databaseObjControlInp.args[1] = p2;
    databaseObjControlInp.args[2] = p3;
    databaseObjControlInp.args[3] = p4;
    databaseObjControlInp.args[4] = p5;
    databaseObjControlInp.args[5] = p6;

    status = rsDatabaseObjControl(rsComm, &databaseObjControlInp, 
				  &databaseObjControlOut);
    if (status) {
       return(status);
    }
    if (*databaseObjControlOut->outBuf != '\0') {
       int stat2;
       stat2 = _writeString("stdout",databaseObjControlOut->outBuf,rei);
    }

    return(status);
}
Пример #19
0
    /**
    * \fn msiH5Dataset_read (msParam_t *inpH5DatasetParam, msParam_t *outH5DatasetParam,
    * ruleExecInfo_t *rei)
    *
    * \brief This microservice is for reading a dataset from an opened HDF5 file.
    *
    * \module hdf5
    *
    * \since pre-2.1
    *
    * \author uiuc.edu Mike Wan
    * \date  2008
    *
    * \usage See clients/icommands/test/rules3.0/
    *
    * \param[in] inpH5DatasetParam - The input H5Dataset. Must be h5Dataset_MS_T.
    * \param[out] outH5DatasetParam - The output H5Dataset - Must be h5Dataset_MS_T.
    * \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 none
    * \post none
    * \sa none
    **/
    int
    msiH5Dataset_read (msParam_t *inpH5DatasetParam, msParam_t *outH5DatasetParam,
    ruleExecInfo_t *rei)
    {
        rsComm_t *rsComm;
        H5Dataset *ind;
        H5Dataset *outd;
        int l1descInx;
        dataObjInfo_t *dataObjInfo;
        int remoteFlag;
        rodsServerHost_t *rodsServerHost;

        RE_TEST_MACRO ( ( char * )"    Calling msiH5Dataset_read")

        if (rei == NULL || rei->rsComm == NULL) {
            rodsLog (LOG_ERROR,
              "msiH5Dataset_read: input rei or rsComm is NULL");
            return (SYS_INTERNAL_NULL_INPUT_ERR);
        }

        rsComm = rei->rsComm;

        if (inpH5DatasetParam == NULL || outH5DatasetParam == NULL) {
            rei->status = SYS_INTERNAL_NULL_INPUT_ERR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: NULL input/output Param");
            return (rei->status);
        }

        if (strcmp (inpH5DatasetParam->type, h5Dataset_MS_T) == 0) {
            ind = (H5Dataset*)inpH5DatasetParam->inOutStruct;
        } else {
            rei->status = USER_PARAM_TYPE_ERR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: wrong inpH5DatasetParam type %s",
              inpH5DatasetParam->type);
            return (rei->status);
        }

        l1descInx = getL1descInxByFid (ind->fid);
        if (l1descInx < 0) {
            rei->status = SYS_BAD_FILE_DESCRIPTOR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: bad fid %d", ind->fid);
            return (rei->status);
        }

        dataObjInfo = L1desc[l1descInx].dataObjInfo;

        remoteFlag = resolveHostByDataObjInfo (dataObjInfo,
          &rodsServerHost);

        if (remoteFlag == LOCAL_HOST) {
            outd = (H5Dataset*)malloc (sizeof (H5Dataset));
            rei->status = H5Dataset_read (ind, outd);
        } else {
            /* do the remote close */
            outd = NULL;
            if ((rei->status = svrToSvrConnect (rsComm, rodsServerHost)) >= 0) {
                rei->status = _clH5Dataset_read (rodsServerHost->conn, ind, &outd);
            }
        }

        /* prepare the output */

        fillMsParam (outH5DatasetParam, NULL, ( char * )h5Dataset_MS_T, outd, NULL);

        if (ind) H5Dataset_dtor(ind);

        return rei->status;

    }