Ejemplo n.º 1
0
int
lsDataObjUtilLong( rcComm_t *conn, char *srcPath,
                   rodsArguments_t *rodsArgs, genQueryInp_t *genQueryInp ) {
    int status;
    genQueryOut_t *genQueryOut = NULL;
    char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN];
    char condStr[MAX_NAME_LEN];
    int queryFlags;

    queryFlags = setQueryFlag( rodsArgs );
    setQueryInpForData( queryFlags, genQueryInp );
    genQueryInp->maxRows = MAX_SQL_ROWS;

    memset( myColl, 0, MAX_NAME_LEN );
    memset( myData, 0, MAX_NAME_LEN );

    if ( ( status = splitPathByKey(
                        srcPath, myColl, MAX_NAME_LEN, myData, MAX_NAME_LEN, '/' ) ) < 0 ) {
        rodsLogError( LOG_ERROR, status,
                      "setQueryInpForLong: splitPathByKey for %s error, status = %d",
                      srcPath, status );
        return status;
    }

    snprintf( condStr, MAX_NAME_LEN, "='%s'", myColl );
    addInxVal( &genQueryInp->sqlCondInp, COL_COLL_NAME, condStr );
    snprintf( condStr, MAX_NAME_LEN, "='%s'", myData );
    addInxVal( &genQueryInp->sqlCondInp, COL_DATA_NAME, condStr );

    status =  rcGenQuery( conn, genQueryInp, &genQueryOut );

    if ( status < 0 ) {
        if ( status == CAT_NO_ROWS_FOUND ) {
            rodsLog( LOG_ERROR, "%s does not exist or user lacks access permission",
                     srcPath );
        }
        else {
            rodsLogError( LOG_ERROR, status,
                          "lsDataObjUtilLong: rcGenQuery error for %s", srcPath );
        }
        return status;
    }
    printLsLong( conn, rodsArgs, genQueryOut );

    return 0;
}
Ejemplo n.º 2
0
int
doTest11( char *userName, char *rodsZone, char *accessPerm, char *collection,
          char *dataObj ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    char condStr[MAX_NAME_LEN];
    int status;
    char accStr[LONG_NAME_LEN];

    printf( "dotest11\n" );
    rodsLogSqlReq( 1 );

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

    snprintf( accStr, LONG_NAME_LEN, "%s", userName );
    addKeyVal( &genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr );

    snprintf( accStr, LONG_NAME_LEN, "%s", rodsZone );
    addKeyVal( &genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr );

    snprintf( accStr, LONG_NAME_LEN, "%s", accessPerm );
    addKeyVal( &genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr );

    snprintf( condStr, MAX_NAME_LEN, "='%s'", collection );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );

    snprintf( condStr, MAX_NAME_LEN, "='%s'", dataObj );
    addInxVal( &genQueryInp.sqlCondInp, COL_DATA_NAME, condStr );

    addInxIval( &genQueryInp.selectInp,  COL_D_DATA_ID, 1 );

    genQueryInp.maxRows = 10;

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );

    printf( "genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount );

    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }

    return 0;
}
Ejemplo n.º 3
0
/* checkDupReplica - Check if a given object with a given rescName
 * and physical path already exist. If it does, returns the replNum.
 * JMC - backport 4497 */
int
checkDupReplica( rsComm_t *rsComm, rodsLong_t dataId, char *rescName,
                 char *filePath ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char tmpStr[MAX_NAME_LEN];
    int status;

    if ( rsComm == NULL || rescName == NULL || filePath == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    bzero( &genQueryInp, sizeof( genQueryInp_t ) );

    snprintf( tmpStr, MAX_NAME_LEN, "='%s'", rescName );
    addInxVal( &genQueryInp.sqlCondInp, COL_D_RESC_NAME, tmpStr );
    snprintf( tmpStr, MAX_NAME_LEN, "='%s'", filePath );
    addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr );
    snprintf( tmpStr, MAX_NAME_LEN, "='%lld'", dataId );
    addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr );

    addInxIval( &genQueryInp.selectInp, COL_DATA_REPL_NUM, 1 );
    genQueryInp.maxRows = 2;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    clearGenQueryInp( &genQueryInp );
    if ( status >= 0 ) {
        int intReplNum;
        sqlResult_t *replNum;
        if ( ( replNum = getSqlResultByInx( genQueryOut, COL_DATA_REPL_NUM ) ) ==
                NULL ) {
            rodsLog( LOG_ERROR,
                     "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        intReplNum = atoi( replNum->value );
        freeGenQueryOut( &genQueryOut );
        return intReplNum;
    }
    else {
        return status;
    }
}
Ejemplo n.º 4
0
/* querySpecColl - The query can produce multiple answer and only one
 * is correct. e.g., objPath = /x/yabc can produce answers:
 * /x/y, /x/ya, /x/yabc, etc. The calling subroutine need to screen
 * /x/y, /x/ya out
 * check queueSpecCollCache () for screening.
 */
int
querySpecColl( rsComm_t *rsComm, char *objPath, genQueryOut_t **genQueryOut ) {
    genQueryInp_t genQueryInp;
    int status;
    char condStr[MAX_NAME_LEN];

    if ( HaveFailedSpecCollPath && strcmp( objPath, FailedSpecCollPath ) == 0 ) {
        return CAT_NO_ROWS_FOUND;
    }

    /* see if objPath is in the path of a spec collection */
    memset( &genQueryInp, 0, sizeof( genQueryInp ) );

    snprintf( condStr, MAX_NAME_LEN, "parent_of '%s'", objPath );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );
    rstrcpy( condStr, "like '_%'", MAX_NAME_LEN );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_TYPE, condStr );

    addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 );

    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, &genQueryInp, genQueryOut );

    clearGenQueryInp( &genQueryInp );

    if ( status < 0 ) {
        rstrcpy( FailedSpecCollPath, objPath, MAX_NAME_LEN );
        HaveFailedSpecCollPath = 1;
        return status;
    }

    return 0;
}
Ejemplo n.º 5
0
// =-=-=-=-=-=-=-
// JMC - backport 4552
int
getNumSubfilesInBunfileObj( rsComm_t *rsComm, char *objPath ) {
    int status;
    genQueryOut_t *genQueryOut = NULL;
    genQueryInp_t genQueryInp;
    int totalRowCount;
    char condStr[MAX_NAME_LEN];

    bzero( &genQueryInp, sizeof( genQueryInp ) );
    genQueryInp.maxRows = 1;
    genQueryInp.options = RETURN_TOTAL_ROW_COUNT;

    snprintf( condStr, MAX_NAME_LEN, "='%s'", objPath );
    addInxVal( &genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr );
    snprintf( condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr );
    addKeyVal( &genQueryInp.condInput, ZONE_KW, objPath );

    addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_DATA_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, 1 );

    status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( genQueryOut == NULL || status < 0 ) {
        freeGenQueryOut( &genQueryOut );
        clearGenQueryInp( &genQueryInp );
        if ( status == CAT_NO_ROWS_FOUND ) {
            return 0;
        }
        else {
            return status;
        }
    }
    totalRowCount = genQueryOut->totalRowCount;
    freeGenQueryOut( &genQueryOut );
    /* clear result */
    genQueryInp.maxRows = 0;
    rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    clearGenQueryInp( &genQueryInp );

    return totalRowCount;
}
Ejemplo n.º 6
0
int
doTest2(char *arg1, char *arg2, char *arg3, char *arg4) {
    generalUpdateInp_t generalUpdateInp;
    int status;

    printf("dotest2\n");
    rodsLogSqlReq(1);

    memset (&generalUpdateInp, 0, sizeof (generalUpdateInp));

    addInxVal (&generalUpdateInp.values, COL_TOKEN_NAMESPACE, arg1);
    addInxVal (&generalUpdateInp.values, COL_TOKEN_ID, arg2);
    addInxVal (&generalUpdateInp.values, COL_TOKEN_NAME, arg3);

    generalUpdateInp.type = GENERAL_UPDATE_DELETE;

    status  = chlGeneralUpdate(generalUpdateInp);
    printf("chlGenUpdate status=%d\n",status);

    return(status);
}
Ejemplo n.º 7
0
/* Based on doTest7, but tests AUTO_CLOSE */
int
doTest15( char *testString, char *testString2, char *testString3 ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    char condStr1[MAX_NAME_LEN];
    char condStr2[MAX_NAME_LEN];
    int status;

    printf( "dotest15\n" );
    rodsLogSqlReq( 1 );

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

    addInxIval( &genQueryInp.selectInp, COL_TOKEN_NAME, 1 );

    snprintf( condStr1, MAX_NAME_LEN, "= 'data_type'" );
    addInxVal( &genQueryInp.sqlCondInp,  COL_TOKEN_NAMESPACE, condStr1 );

    snprintf( condStr2, MAX_NAME_LEN, "like '%s%s%s'", "%",
              testString, "%" );
    addInxVal( &genQueryInp.sqlCondInp,  COL_TOKEN_VALUE2, condStr2 );

    genQueryInp.options = AUTO_CLOSE;
    genQueryInp.maxRows = 1;
    if ( testString3 != NULL && *testString3 != '\0' ) {
        genQueryInp.maxRows = atoi( testString3 );
    }

    if ( testString2 != NULL && *testString2 != '\0' ) {
        genQueryInp.rowOffset = atoi( testString2 );
    }

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );

    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }
    return status;
}
Ejemplo n.º 8
0
int
isData (rsComm_t *rsComm, char *objName, rodsLong_t *dataId)
{
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char tmpStr[MAX_NAME_LEN];
    char logicalEndName[MAX_NAME_LEN];
    char logicalParentDirName[MAX_NAME_LEN];
    int status;

    status = splitPathByKey(objName,
			    logicalParentDirName, logicalEndName, '/');
    memset (&genQueryInp, 0, sizeof (genQueryInp_t));
    snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName);
    addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr);
    addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
    snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName);
    addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
    addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
    genQueryInp.maxRows = 2;
    status =  rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
    if (status >= 0) {
        sqlResult_t *dataIdRes;

        if ((dataIdRes = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) ==
          NULL) {
            rodsLog (LOG_ERROR,
              "isData: getSqlResultByInx for COL_D_DATA_ID failed");
            return (UNMATCHED_KEY_OR_INDEX);
        }
	if (dataId != NULL) {
            *dataId = strtoll (dataIdRes->value, 0, 0);
	}
	freeGenQueryOut (&genQueryOut);
    }

    clearGenQueryInp (&genQueryInp);
    return(status);
}
Ejemplo n.º 9
0
int
doTest8( char *testString, char *testString2, char *testString3 ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    /*    char condStr1[MAX_NAME_LEN]; */
    char condStr2[MAX_NAME_LEN];
    int status, status2;

    printf( "dotest8\n" );
    rodsLogSqlReq( 1 );

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

    /* for : test_genq gen8 / 0 10          (should find 1)
       or :  test_genq gen8 /tempZone 0 10  (should find 2)
       or :  test_genq gen8 abc 0 10        (should find 0)  */
    addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 );

    snprintf( condStr2, MAX_NAME_LEN, "begin_of '%s'", testString );
    addInxVal( &genQueryInp.sqlCondInp,  COL_COLL_NAME, condStr2 );

    genQueryInp.options = RETURN_TOTAL_ROW_COUNT;
    genQueryInp.maxRows = 5;
    if ( testString3 != NULL && *testString3 != '\0' ) {
        genQueryInp.maxRows = atoi( testString3 );
    }

    if ( testString2 != NULL && *testString2 != '\0' ) {
        genQueryInp.rowOffset = atoi( testString2 );
    }

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );

    printf( "genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount );

    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }

    if ( genQueryOut.continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut.continueInx;
        printf( "Second call to chlGenQuery\n" );
        status2  = chlGenQuery( genQueryInp, &genQueryOut );
        printf( "chlGenQuery status=%d\n", status2 );
        if ( status2 == 0 ) {
            printGenQOut( &genQueryOut );
        }
    }
    return status;
}
Ejemplo n.º 10
0
int
checkPermitForDataObject( rsComm_t *rsComm, char *objName, int userId, int operId ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char t1[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds
    char t11[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds
    char t2[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds
    char t3[MAX_NAME_LEN]; // JMC cppcheck - snprintf out of bounds
    char logicalEndName[MAX_NAME_LEN];
    char logicalParentDirName[MAX_NAME_LEN];
    int status;

    status = splitPathByKey( objName,
                             logicalParentDirName, MAX_NAME_LEN, logicalEndName, MAX_NAME_LEN, '/' );
    snprintf( t1, MAX_NAME_LEN, " = '%s'", logicalEndName );
    snprintf( t11, MAX_NAME_LEN, " = '%s'", logicalParentDirName );
    snprintf( t2, MAX_NAME_LEN, " = '%i'", userId );
    snprintf( t3, MAX_NAME_LEN, " >= '%i' ", operId );

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    addInxIval( &genQueryInp.selectInp, COL_D_DATA_ID, 1 );
    addInxVal( &genQueryInp.sqlCondInp, COL_DATA_NAME, t1 );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, t11 );
    addInxVal( &genQueryInp.sqlCondInp, COL_DATA_ACCESS_USER_ID, t2 );
    addInxVal( &genQueryInp.sqlCondInp, COL_DATA_ACCESS_TYPE, t3 );
    genQueryInp.maxRows = 2;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    clearGenQueryInp( &genQueryInp );
    if ( status >= 0 ) {
        freeGenQueryOut( &genQueryOut );
        return 1;
    }
    else {
        return 0;
    }
}
Ejemplo n.º 11
0
int
getPhyPath (rsComm_t *rsComm, char *objName,  char *resource, char *phyPath)
{
   genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char tmpStr[MAX_NAME_LEN];
    char logicalEndName[MAX_NAME_LEN];
    char logicalParentDirName[MAX_NAME_LEN];
    int status;

    status = splitPathByKey(objName,
                            logicalParentDirName, logicalEndName, '/');
    memset (&genQueryInp, 0, sizeof (genQueryInp_t));
    snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName);
    addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr);
    snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName);
    addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
    addInxIval (&genQueryInp.selectInp, COL_D_DATA_PATH, 1);
    genQueryInp.maxRows = 2;
    status =  rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
    if (status >= 0) {
        sqlResult_t *phyPathRes = NULL;
        if ((phyPathRes = getSqlResultByInx (genQueryOut, COL_D_DATA_PATH)) ==
          NULL) {
            rodsLog (LOG_ERROR,
              "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed");
            return (UNMATCHED_KEY_OR_INDEX);
        }
        if (phyPath != NULL) {
            rstrcpy (phyPath, phyPathRes->value, MAX_NAME_LEN);
        }
        freeGenQueryOut (&genQueryOut);
    }
    clearGenQueryInp (&genQueryInp);
    return(status);
}
Ejemplo n.º 12
0
int
doTest6(char *arg1, char *arg2, char *arg3, char *arg4) {
    generalUpdateInp_t generalUpdateInp;
    int status;

    printf("dotest2\n");
    rodsLogSqlReq(1);

    memset (&generalUpdateInp, 0, sizeof (generalUpdateInp));

    addInxVal (&generalUpdateInp.values, atoi(arg1), arg2);

    if (arg3 !=0 && *arg3 !='\0' &&
	arg4 !=0 && *arg4 !='\0' ) { 
       addInxVal (&generalUpdateInp.values, atoi(arg3), arg4);
    }

    generalUpdateInp.type = GENERAL_UPDATE_DELETE;
    
    status  = chlGeneralUpdate(generalUpdateInp);
    printf("chlGenUpdate status=%d\n",status);

    return(status);
}
Ejemplo n.º 13
0
/**
 * \fn msiCheckHostAccessControl (ruleExecInfo_t *rei)
 *
 * \brief  This microservice sets the access control policy. It checks the
 *  access control by host and user based on the the policy given in the
 *  HostAccessControl file.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2007-09
 *
 * \note  This microservice controls access to the iRODS service
 *  based on the information in the host based access configuration file:
 *  HOST_ACCESS_CONTROL_FILE
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa N/A
 **/
int msiCheckHostAccessControl( ruleExecInfo_t *rei ) {
    char group[MAX_NAME_LEN], *hostclient, *result, *username;
    char condstr[MAX_NAME_LEN];
    int i, rc, status;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    rsComm_t *rsComm;

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

    group[0] = '\0';
    rsComm = rei->rsComm;

    /* retrieve user name */
    username = rsComm->clientUser.userName;
    /* retrieve client IP address */
    hostclient = inet_ntoa( rsComm->remoteAddr.sin_addr );
    /* retrieve groups to which the user belong */
    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    snprintf( condstr, MAX_NAME_LEN, "= '%s'", username );
    addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condstr );
    addInxIval( &genQueryInp.selectInp, COL_USER_GROUP_NAME, 1 );
    genQueryInp.maxRows = MAX_SQL_ROWS;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( status >= 0 ) {
        for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
            result = genQueryOut->sqlResult[0].value;
            result += i * genQueryOut->sqlResult[0].len;
            strcat( group, result );
            strcat( group, " " );
        }
    }
    else {
        rstrcpy( group, "all", MAX_NAME_LEN );
    }
    clearGenQueryInp( &genQueryInp );
    freeGenQueryOut( &genQueryOut );

    rc = checkHostAccessControl( username, hostclient, group );
    if ( rc < 0 ) {
        rodsLog( LOG_NOTICE, "Access to user %s from host %s has been refused.\n", username, hostclient );
        rei->status = rc;
    }

    return rei->status;

}
Ejemplo n.º 14
0
int
isResc( rsComm_t *rsComm, char *objName ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char tmpStr[NAME_LEN];
    int status;

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    snprintf( tmpStr, NAME_LEN, "='%s'", objName );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, tmpStr );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 );
    genQueryInp.maxRows = 2;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    freeGenQueryOut( &genQueryOut );
    clearGenQueryInp( &genQueryInp );
    return status;
}
Ejemplo n.º 15
0
int
checkCollAccessPerm( rsComm_t *rsComm, char *collection, char *accessPerm ) {
    char accStr[LONG_NAME_LEN];
    char condStr[MAX_NAME_LEN];
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int status;

    if ( collection == NULL || accessPerm == NULL ) {
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

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

    snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName );
    addKeyVal( &genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr );

    snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone );
    addKeyVal( &genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr );

    snprintf( accStr, LONG_NAME_LEN, "%s", accessPerm );
    addKeyVal( &genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr );

    snprintf( condStr, MAX_NAME_LEN, "='%s'", collection );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );

    addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 );

    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );

    clearGenQueryInp( &genQueryInp );
    if ( status >= 0 ) {
        freeGenQueryOut( &genQueryOut );
    }

    return status;
}
Ejemplo n.º 16
0
int
rsQueryCollInColl( rsComm_t *rsComm, char *collection,
                   genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut ) {
    char collQCond[MAX_NAME_LEN];
    int status;

    if ( collection == NULL || genQueryOut == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

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

    snprintf( collQCond, MAX_NAME_LEN, "='%s'", collection );

    addInxVal( &genQueryInp->sqlCondInp, COL_COLL_PARENT_NAME, collQCond );

    addInxIval( &genQueryInp->selectInp, COL_COLL_NAME, 1 );

    genQueryInp->maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, genQueryInp, genQueryOut );

    return status;
}
Ejemplo n.º 17
0
int
doTest5() {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    char condStr[MAX_NAME_LEN];
    int status;

    printf( "dotest5\n" );
    rodsLogSqlReq( 1 );

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

    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ID, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_REI_FILE_PATH, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_USER_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ADDRESS, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_FREQUENCY, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_PRIORITY, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ESTIMATED_EXE_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_NOTIFICATION_ADDR, 1 );

    /* compound condition test: */
    snprintf( condStr, MAX_NAME_LEN, "= 'Wayne'" );
    addInxVal( &genQueryInp.sqlCondInp,  COL_RULE_EXEC_USER_NAME, condStr );

    genQueryInp.maxRows = 2;

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );
    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }
    return status;
}
Ejemplo n.º 18
0
int
rsQueryDataObjInCollReCur( rsComm_t *rsComm, char *collection,
                           genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut, char *accessPerm,
                           int singleFlag ) {
    char collQCond[MAX_NAME_LEN * 2];
    int status = 0;
    char accStr[LONG_NAME_LEN];

    if ( genQueryInp == NULL ||
            collection  == NULL ||
            genQueryOut == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

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

    genAllInCollQCond( collection, collQCond );

    addInxVal( &genQueryInp->sqlCondInp, COL_COLL_NAME, collQCond );

    addInxIval( &genQueryInp->selectInp, COL_D_DATA_ID, 1 );
    addInxIval( &genQueryInp->selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp->selectInp, COL_DATA_NAME, 1 );

    if ( singleFlag == 0 ) {
        addInxIval( &genQueryInp->selectInp, COL_DATA_REPL_NUM, 1 );
        addInxIval( &genQueryInp->selectInp, COL_D_RESC_NAME, 1 );
        addInxIval( &genQueryInp->selectInp, COL_D_DATA_PATH, 1 );
    }

    addInxIval( &genQueryInp->selectInp, COL_D_RESC_HIER, 1 );

    if ( accessPerm != NULL ) {
        snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName );
        addKeyVal( &genQueryInp->condInput, USER_NAME_CLIENT_KW, accStr );

        snprintf( accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone );
        addKeyVal( &genQueryInp->condInput, RODS_ZONE_CLIENT_KW, accStr );

        snprintf( accStr, LONG_NAME_LEN, "%s", accessPerm );
        addKeyVal( &genQueryInp->condInput, ACCESS_PERMISSION_KW, accStr );
        /* have to set it to 1 because it only check the first one */
        genQueryInp->maxRows = 1;
        status =  rsGenQuery( rsComm, genQueryInp, genQueryOut );
        rmKeyVal( &genQueryInp->condInput, USER_NAME_CLIENT_KW );
        rmKeyVal( &genQueryInp->condInput, RODS_ZONE_CLIENT_KW );
        rmKeyVal( &genQueryInp->condInput, ACCESS_PERMISSION_KW );
    }
    else {
        genQueryInp->maxRows = MAX_SQL_ROWS;
        status = trySpecificQueryDataObjInCollReCur(
                     rsComm,
                     collection,
                     genQueryOut );
        if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
            rodsLog(
                LOG_NOTICE,
                "Note: DataObjInCollReCur specific-Query failed (not defined?), running standard query, status=%d",
                status );
            /* remove the level 0 error msg added by the specific-query failure */
            status = freeRErrorContent( &rsComm->rError );
            /* fall back to the general-query call which used before this
               specific-query was added (post 3.3.1) */
            genQueryInp->maxRows = MAX_SQL_ROWS;
            status =  rsGenQuery( rsComm, genQueryInp, genQueryOut );
        }

    }

    return status;

}
Ejemplo n.º 19
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" );
            }
        }
Ejemplo n.º 20
0
int rodsMonPerfLog( char *serverName, char *resc, char *output, ruleExecInfo_t *rei ) {

    char condstr[MAX_NAME_LEN], fname[MAX_NAME_LEN], msg[MAX_MESSAGE_SIZE],
         monStatus[MAX_NAME_LEN], suffix[MAX_VALUE], *result;
    const char *delim1 = "#";
    const char *delim2 = ",";
    int index, timestamp, rc1 = 0, rc2 = 0, rc3 = 0, rc4 = 0;
    FILE *foutput;
    time_t tps;
    generalRowInsertInp_t generalRowInsertInp;
    generalAdminInp_t generalAdminInp1, generalAdminInp2;
    genQueryInp_t genQueryInp;
    struct tm *now;

    genQueryOut_t *genQueryOut = NULL;
    tps = time( NULL );
    now = localtime( &tps );

    /* a quick test in order to see if the resource is up or down (needed to update the "status" metadata) */
    if ( strcmp( output, MON_OUTPUT_NO_ANSWER ) == 0 ) {
        strncpy( monStatus, RESC_AUTO_DOWN, MAX_NAME_LEN );
    }
    else {
        strncpy( monStatus, RESC_AUTO_UP, MAX_NAME_LEN );
    }

    std::vector<std::string> output_tokens;
    boost::algorithm::split( output_tokens, output, boost::is_any_of( delim1 ) );
    std::vector<std::string> resc_tokens;
    boost::algorithm::split( resc_tokens, resc, boost::is_any_of( delim2 ) );
    std::vector<std::string> disk_tokens;
    boost::algorithm::split( disk_tokens, output_tokens[4], boost::is_any_of( delim2 ) );
    std::vector<std::string> value_tokens;
    boost::algorithm::split( value_tokens, output_tokens[7], boost::is_any_of( delim2 ) );
    index = 0;
    while ( !resc_tokens[index].empty() ) {
        if ( strcmp( monStatus, RESC_AUTO_DOWN ) == 0 ) {
            disk_tokens[index] = "-1";
            value_tokens[index] = "-1";
        }
        sprintf( msg, "server=%s resource=%s cpu=%s, mem=%s, swp=%s, rql=%s, dsk=%s, nin=%s, nout=%s, dskAv(MB)=%s\n",
                 serverName, resc_tokens[index].c_str(), output_tokens[0].c_str(), output_tokens[1].c_str(), output_tokens[2].c_str(),
                 output_tokens[3].c_str(), disk_tokens[index].c_str(), output_tokens[5].c_str(), output_tokens[6].c_str(), value_tokens[index].c_str() );
        sprintf( suffix, "%d.%d.%d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday );
        sprintf( fname, "%s.%s", OUTPUT_MON_PERF, suffix );
        /* retrieve the system time */
        timestamp = time( &tps );

        /* log the result into the database as well */
        generalRowInsertInp.tableName = "serverload";
        generalRowInsertInp.arg1 = serverName;
        generalRowInsertInp.arg2 = resc_tokens[index].c_str();
        generalRowInsertInp.arg3 = output_tokens[0].c_str();
        generalRowInsertInp.arg4 = output_tokens[1].c_str();
        generalRowInsertInp.arg5 = output_tokens[2].c_str();
        generalRowInsertInp.arg6 = output_tokens[3].c_str();
        generalRowInsertInp.arg7 = disk_tokens[index].c_str();
        generalRowInsertInp.arg8 = output_tokens[5].c_str();
        generalRowInsertInp.arg9 = output_tokens[6].c_str();
        /* prepare DB request to modify resource metadata: freespace and status */
        generalAdminInp1.arg0 = "modify";
        generalAdminInp1.arg1 = "resource";
        generalAdminInp1.arg2 = resc_tokens[index].c_str();
        generalAdminInp1.arg3 = "freespace";
        generalAdminInp1.arg4 = value_tokens[index].c_str();
        generalAdminInp2.arg0 = "modify";
        generalAdminInp2.arg1 = "resource";
        generalAdminInp2.arg2 = resc_tokens[index].c_str();
        generalAdminInp2.arg3 = "status";
        generalAdminInp2.arg4 = monStatus;
        memset( &genQueryInp, 0, sizeof( genQueryInp ) );
        addInxIval( &genQueryInp.selectInp, COL_R_RESC_STATUS, 1 );
        snprintf( condstr, MAX_NAME_LEN, "= '%s'", resc_tokens[index].c_str() );
        addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condstr );
        genQueryInp.maxRows = MAX_SQL_ROWS;
#ifndef windows_platform
        pthread_mutex_lock( &my_mutex );
#endif
        /* append to the output log file */
        foutput = fopen( fname, "a" );
        if ( foutput != NULL ) {
            fprintf( foutput, "time=%i %s", timestamp, msg );
            // fclose(foutput); // JMC cppcheck - nullptr // cannot close it here. it is used later - hcj
        }

        rc1 = rsGeneralRowInsert( rei->rsComm, &generalRowInsertInp );
        rc2 = rsGeneralAdmin( rei->rsComm, &generalAdminInp1 );
        rc3 = rsGenQuery( rei->rsComm, &genQueryInp, &genQueryOut );
        if ( rc3 >= 0 ) {
            result = genQueryOut->sqlResult[0].value;
            if ( strcmp( result, "\0" ) == 0 || ( strncmp( result, "auto-", 5 ) == 0 && strcmp( result, monStatus ) != 0 ) ) {
                rc4 = rsGeneralAdmin( rei->rsComm, &generalAdminInp2 );
            }
        }
        else {
            rodsLog( LOG_ERROR, "msiServerMonPerf: unable to retrieve the status metadata for the resource %s", resc_tokens[index].c_str() );
        }
#ifndef windows_platform
        pthread_mutex_unlock( &my_mutex );
#endif
        if ( foutput != NULL && rc1 != 0 ) {
            fprintf( foutput, "time=%i : unable to insert the entries for server %s into the iCAT\n",
                     timestamp, serverName );
            fclose( foutput );
        }
        if ( rc2 != 0 ) {
            rodsLog( LOG_ERROR, "msiServerMonPerf: unable to register the free space metadata for the resource %s", resc_tokens[index].c_str() );
        }
        if ( rc4 != 0 ) {
            rodsLog( LOG_ERROR, "msiServerMonPerf: unable to register the status metadata for the resource %s", resc_tokens[index].c_str() );
        }
        index += 1;
    }

    clearGenQueryInp( &genQueryInp );
    freeGenQueryOut( &genQueryOut );

    return 0;
}
Ejemplo n.º 21
0
int getListOfResc( rsComm_t *rsComm, char serverList[MAX_VALUE][MAX_NAME_LEN], int nservers,
                   monInfo_t monList[MAX_NSERVERS], int *nlist ) {
    /**********************************************************
     * search in the database, the list of resources with      *
     * their associated server. If config file exist, restrict *
     * the list to serverList                                  *
     ***********************************************************/
    int i, j, k, index[MAX_NSERVERS], l, status;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char condStr[MAX_NAME_LEN];

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    memset( &index, -1, MAX_NSERVERS * sizeof( int ) );
    genQueryInp.maxRows = MAX_SQL_ROWS;

    //clearGenQueryInp( &genQueryInp );
    addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_LOC, "!='EMPTY_RESC_HOST'" );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_VAULT_PATH, "!='EMPTY_RESC_PATH'" );
    snprintf( condStr, MAX_NAME_LEN, "!='%s'", BUNDLE_RESC );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condStr );

    status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( status < 0 ) {
        irods::log( ERROR( status, "rsGenQuery failed." ) );
    }
    if ( genQueryOut->rowCnt > 0 ) {
        l = 0;
        for ( i = 0; i < genQueryOut->attriCnt; i++ ) {
            for ( j = 0; j < genQueryOut->rowCnt; j++ ) {
                char *tResult;
                tResult = genQueryOut->sqlResult[i].value;
                tResult += j * genQueryOut->sqlResult[i].len;
                switch ( i ) {
                case 0:
                    if ( nservers >= 0 ) {
                        for ( k = 0; k < nservers; k++ ) {
                            if ( strcmp( serverList[k], tResult ) == 0 ) {
                                index[j] = l;
                                l++;
                            }
                        }
                    }
                    else {
                        index[j] = l;
                        l++;
                    }
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].serverName, tResult, LONG_NAME_LEN );
                    }
                    break;
                case 1:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].rescName, tResult, MAX_NAME_LEN );
                    }
                    break;
                case 2:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].rescType, tResult, LONG_NAME_LEN );
                    }
                    break;
                case 3:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].vaultPath, tResult, LONG_NAME_LEN );
                    }
                    break;
                }
            }
        }
        ( *nlist ) = l;
        clearGenQueryInp( &genQueryInp );
        freeGenQueryOut( &genQueryOut );
        return 0;
    }
    return -1;
}
Ejemplo n.º 22
0
int showRescTree( char *name ) {
    int status;
    int offset = 0; // when getting more rows

    // genQuery input and output (camelCase for tradition)
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    char collQCond[MAX_NAME_LEN];


    // start clean
    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );

    // set up query columns
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, ORDER_BY );
    addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_CHILDREN, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_PARENT, 1 );

    if ( zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
    }

    // set up query condition (resc_name != 'bundleResc')
    snprintf( collQCond, MAX_NAME_LEN, "!='%s'", BUNDLE_RESC );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, collQCond );

    // query for resources
    genQueryInp.maxRows = MAX_SQL_ROWS;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );

    // query fail?
    if ( status < 0 ) {
        printError( Conn, status, "rcGenQuery" );
        return status;
    }


    // parse results
    status = parseGenQueryOut( offset, genQueryOut );



    // More rows in the pipeline?
    while ( !status && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;

        // update offset
        offset += genQueryOut->rowCnt;

        // get next batch of rows
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );

        // parse results
        status = parseGenQueryOut( offset, genQueryOut );
    }



    // If target resource was specified print tree for that resource
    if ( name && strlen( name ) ) {
        std::string target_resc_name( name );

        // check for invalid resource name
        if ( std::find( resc_names.begin(), resc_names.end(), target_resc_name ) == resc_names.end() ) {
            std::cout << "Resource " << target_resc_name << " does not exist." << std::endl;
            return USER_INVALID_RESC_INPUT;
        }

        // print tree
        printRescTree( target_resc_name, "" );
    }
    else {
        // Otherwise print tree for each root node
        for ( std::vector<std::string>::const_iterator it = roots.begin(); it != roots.end(); ++it ) {
            printRescTree( *it, "" );
        }
    }

    return status;
}
Ejemplo n.º 23
0
int igsiServersideAuth() {
    int status;
#if defined(GSI_AUTH)
    char clientName[500];
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    char condition1[MAX_NAME_LEN];
    char condition2[MAX_NAME_LEN];
    char *tResult;
    int privLevel;
    int clientPrivLevel;
    int noNameMode;
    int statusRule;
#ifdef GSI_DEBUG
    char *getVar;
    getVar = getenv( "X509_CERT_DIR" );
    if ( getVar != NULL ) {
        printf( "X509_CERT_DIR:%s\n", getVar );
    }
#endif

    gsiAuthReqStatus = 1;

    status = igsiEstablishContextServerside( rsComm, clientName, 500 );
#ifdef GSI_DEBUG
    if ( status == 0 ) {
        printf( "clientName:%s\n", clientName );
    }
#endif

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

    noNameMode = 0;
    if ( strlen( rsComm->clientUser.userName ) > 0 ) {
        /* regular mode */

        snprintf( condition1, MAX_NAME_LEN, "='%s'", clientName );
        addInxVal( &genQueryInp.sqlCondInp, COL_USER_DN, condition1 );

        snprintf( condition2, MAX_NAME_LEN, "='%s'",
                  rsComm->clientUser.userName );
        addInxVal( &genQueryInp.sqlCondInp, COL_USER_NAME, condition2 );

        addInxIval( &genQueryInp.selectInp, COL_USER_ID, 1 );
        addInxIval( &genQueryInp.selectInp, COL_USER_TYPE, 1 );
        addInxIval( &genQueryInp.selectInp, COL_USER_ZONE, 1 );

        genQueryInp.maxRows = 2;

        status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    }
    else {
        /*
        The client isn't providing the rodsUserName so query on just
               the DN.  If it returns just one row, set the clientUser to
               the returned irods user name.
            */
        noNameMode = 1;
        memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );

        snprintf( condition1, MAX_NAME_LEN, "='%s'", clientName );
        addInxVal( &genQueryInp.sqlCondInp, COL_USER_DN, condition1 );

        addInxIval( &genQueryInp.selectInp, COL_USER_ID, 1 );
        addInxIval( &genQueryInp.selectInp, COL_USER_TYPE, 1 );
        addInxIval( &genQueryInp.selectInp, COL_USER_NAME, 1 );
        addInxIval( &genQueryInp.selectInp, COL_USER_ZONE, 1 );

        genQueryInp.maxRows = 2;

        status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );

        if ( status == CAT_NO_ROWS_FOUND ) { /* not found */
            /* execute the rule acGetUserByDN.  By default this
                   is a no-op but at some sites can be configured to
                   run a process to determine a user by DN (for VO support)
                   or possibly create the user.
               The stdout of the process is the irodsUserName to use.

               The corresponding rule would be something like this:
               acGetUserByDN(*arg,*OUT)||msiExecCmd(t,"*arg",null,null,null,*OUT)|nop
            */
            ruleExecInfo_t rei;
            char *args[2];
            msParamArray_t *myMsParamArray;
            msParamArray_t myInOutParamArray;

            memset( ( char* )&rei, 0, sizeof( rei ) );
            rei.rsComm = rsComm;
            rei.uoic = &rsComm->clientUser;
            rei.uoip = &rsComm->proxyUser;
            args[0] = clientName;
            char out[200] = "*cmdOutput";
            args[1] = out;

            rei.inOutMsParamArray = myInOutParamArray;

            myMsParamArray = ( msParamArray_t * ) malloc( sizeof( msParamArray_t ) );
            memset( myMsParamArray, 0, sizeof( msParamArray_t ) );

            statusRule = applyRuleArgPA( "acGetUserByDN", args, 2,
                                         myMsParamArray, &rei, NO_SAVE_REI );

#ifdef GSI_DEBUG
            printf( "acGetUserByDN status=%d\n", statusRule );

            int i;
            for ( i = 0; i < myMsParamArray->len; i++ ) {
                char *r;
                msParam_t *myP;
                myP = myMsParamArray->msParam[i];
                r = myP->label;
                printf( "l1=%s\n", r );
            }
#endif
            /* Try the query again, whether or not the rule succeeded, to see
                   if the user has been added. */
            memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );

            snprintf( condition1, MAX_NAME_LEN, "='%s'", clientName );
            addInxVal( &genQueryInp.sqlCondInp, COL_USER_DN, condition1 );

            addInxIval( &genQueryInp.selectInp, COL_USER_ID, 1 );
            addInxIval( &genQueryInp.selectInp, COL_USER_TYPE, 1 );
            addInxIval( &genQueryInp.selectInp, COL_USER_NAME, 1 );
            addInxIval( &genQueryInp.selectInp, COL_USER_ZONE, 1 );

            genQueryInp.maxRows = 2;

            status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
        }
        if ( status == 0 ) {
            char *myBuf;
            strncpy( rsComm->clientUser.userName, genQueryOut->sqlResult[2].value,
                     NAME_LEN );
            strncpy( rsComm->proxyUser.userName, genQueryOut->sqlResult[2].value,
                     NAME_LEN );
            strncpy( rsComm->clientUser.rodsZone, genQueryOut->sqlResult[3].value,
                     NAME_LEN );
            strncpy( rsComm->proxyUser.rodsZone, genQueryOut->sqlResult[3].value,
                     NAME_LEN );
            myBuf = ( char * )malloc( NAME_LEN * 2 );
            snprintf( myBuf, NAME_LEN * 2, "%s=%s", SP_CLIENT_USER,
                      rsComm->clientUser.userName );
            putenv( myBuf );
            free( myBuf ); // JMC cppcheck - leak
        }
    }
    if ( status == CAT_NO_ROWS_FOUND || genQueryOut == NULL ) {
        status = GSI_DN_DOES_NOT_MATCH_USER;
        rodsLog( LOG_NOTICE,
                 "igsiServersideAuth: DN mismatch, user=%s, Certificate DN=%s, status=%d",
                 rsComm->clientUser.userName,
                 clientName,
                 status );
        snprintf( gsiAuthReqErrorMsg, sizeof gsiAuthReqErrorMsg,
                  "igsiServersideAuth: DN mismatch, user=%s, Certificate DN=%s, status=%d",
                  rsComm->clientUser.userName,
                  clientName,
                  status );
        gsiAuthReqError = status;
        return status;
    }

    if ( status < 0 ) {
        rodsLog( LOG_NOTICE,
                 "igsiServersideAuth: rsGenQuery failed, status = %d", status );
        snprintf( gsiAuthReqErrorMsg, sizeof gsiAuthReqErrorMsg,
                  "igsiServersideAuth: rsGenQuery failed, status = %d", status );
        gsiAuthReqError = status;
        return status;
    }

    if ( noNameMode == 0 ) {
        if ( genQueryOut == NULL || genQueryOut->rowCnt < 1 ) {
            gsiAuthReqError = GSI_NO_MATCHING_DN_FOUND;
            return GSI_NO_MATCHING_DN_FOUND;
        }
        if ( genQueryOut->rowCnt > 1 ) {
            gsiAuthReqError = GSI_MULTIPLE_MATCHING_DN_FOUND;
            return GSI_MULTIPLE_MATCHING_DN_FOUND;
        }
        if ( genQueryOut->attriCnt != 3 ) {
            gsiAuthReqError = GSI_QUERY_INTERNAL_ERROR;
            return GSI_QUERY_INTERNAL_ERROR;
        }
    }
    else {
        if ( genQueryOut == NULL || genQueryOut->rowCnt < 1 ) {
            gsiAuthReqError = GSI_NO_MATCHING_DN_FOUND;
            return GSI_NO_MATCHING_DN_FOUND;
        }
        if ( genQueryOut->rowCnt > 1 ) {
            gsiAuthReqError = GSI_MULTIPLE_MATCHING_DN_FOUND;
            return GSI_MULTIPLE_MATCHING_DN_FOUND;
        }
        if ( genQueryOut->attriCnt != 4 ) {
            gsiAuthReqError = GSI_QUERY_INTERNAL_ERROR;
            return GSI_QUERY_INTERNAL_ERROR;
        }
    }

#ifdef GSI_DEBUG
    printf( "Results=%d\n", genQueryOut->rowCnt );
#endif

    tResult = genQueryOut->sqlResult[0].value;
#ifdef GSI_DEBUG
    printf( "0:%s\n", tResult );
#endif
    tResult = genQueryOut->sqlResult[1].value;
#ifdef GSI_DEBUG
    printf( "1:%s\n", tResult );
#endif
    privLevel = LOCAL_USER_AUTH;
    clientPrivLevel = LOCAL_USER_AUTH;

    if ( strcmp( tResult, "rodsadmin" ) == 0 ) {
        privLevel = LOCAL_PRIV_USER_AUTH;
        clientPrivLevel = LOCAL_PRIV_USER_AUTH;
    }

    status = chkProxyUserPriv( rsComm, privLevel );

    if ( status < 0 ) {
        return status;
    }

    rsComm->proxyUser.authInfo.authFlag = privLevel;
    rsComm->clientUser.authInfo.authFlag = clientPrivLevel;

    if ( noNameMode ) { /* We didn't before, but now have an irodsUserName */
        int status2, status3;
        rodsServerHost_t *rodsServerHost = NULL;
        status2 = getAndConnRcatHost( rsComm, MASTER_RCAT,
                                      rsComm->myEnv.rodsZone, &rodsServerHost );
        if ( status2 >= 0 &&
                rodsServerHost->localFlag == REMOTE_HOST &&
                rodsServerHost->conn != NULL ) {  /* If the IES is remote */

            status3 = rcDisconnect( rodsServerHost->conn ); /* disconnect*/

            /* And clear out the connection information so
               getAndConnRcatHost will reconnect.  This may leak some
               memory but only happens at most once in an agent:  */
            rodsServerHost->conn = NULL;

            /* And reconnect (with irodsUserName here and in the IES): */
            status3 = getAndConnRcatHost( rsComm, MASTER_RCAT,
                                          rsComm->myEnv.rodsZone,
                                          &rodsServerHost );
            if ( status3 ) {
                rodsLog( LOG_ERROR,
                         "igsiServersideAuth failed in getAndConnRcatHost, status = %d",
                         status3 );
                return status3;
            }
        }
    }
    return status;
#else
    status = GSI_NOT_BUILT_INTO_SERVER;
    rodsLog( LOG_ERROR,
             "igsiServersideAuth failed GSI_NOT_BUILT_INTO_SERVER, status = %d",
             status );
    return status;
#endif
}
Ejemplo n.º 24
0
int
main(int argc, char **argv)
{
    int status;
    packItem_t *packItemHead = NULL;
    startupPack_t myStartupPack, *outStartupPack;
    rError_t myError, *outError;
    bytesBuf_t *packedResult;
    genQueryOut_t myQueryOut, *outQueryOut;
    char *tmpValue;
    int i;
    modDataObjMeta_t modDataObjMetaInp, *outModDataObjMeta;
    dataObjInfo_t dataObjInfo;
    keyValPair_t regParam;
    authCheckInp_t authCheckInp, *outAuthCheckInp;
    genQueryInp_t genQueryInp, *outGenQueryInp;
    irodsProt_t irodsProt = XML_PROT;

    memset (&genQueryInp, 0, sizeof (genQueryInp));
    addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, "=xyz");
    addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
    genQueryInp.maxRows = 1234567890;
    status = packStruct (&genQueryInp, &packedResult, "GenQueryInp_PI",
      NULL, 0, irodsProt);

    printf ("packStruct GenQueryInp_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "queryInp.out");

    status = unpackStruct (packedResult->buf, (void **) &outGenQueryInp,
      "GenQueryInp_PI", NULL, irodsProt);

    printf ("unpackStruct of empty GenQueryInp_PI, status = %d\n", status);


    memset (&authCheckInp, 0, sizeof (authCheckInp));
    status = packStruct (&authCheckInp, &packedResult, "authCheckInp_PI",
      NULL, 0, irodsProt);

    printf ("packStruct of empty authCheckInp_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "auth.out");

    status = unpackStruct (packedResult->buf, (void **) &outAuthCheckInp,
      "authCheckInp_PI", NULL, irodsProt);

    printf ("unpackStruct of empty authCheckInp_PI, status = %d\n", status);

    memset (&dataObjInfo, 0, sizeof (dataObjInfo_t));
    memset (&regParam, 0, sizeof (keyValPair_t));

    strcpy (dataObjInfo.objPath, "/tmp/thisIsATest");
    modDataObjMetaInp.dataObjInfo = &dataObjInfo;
    modDataObjMetaInp.regParam = &regParam;

    status = packStruct (&modDataObjMetaInp, &packedResult, "ModDataObjMeta_PI",
      NULL, 0, irodsProt);

    printf ("packStruct of ModDataObjMeta_PI, status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "modeData.out");

    status = unpackStruct (packedResult->buf, (void **) &outModDataObjMeta, 
      "ModDataObjMeta_PI", NULL, irodsProt);

    printf ("unpackStruct of ModDataObjMeta_PI, status = %d\n", status);
    
    memset (&myQueryOut, 0, sizeof (myQueryOut));
    /* pack and unpack empty struct */

    status = packStruct (&myQueryOut, &packedResult, "GenQueryOut_PI",
      NULL, 0, irodsProt);
    printf ("packStruct empty myQueryOut status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "genq.out");

    status = unpackStruct (packedResult->buf, (void **) &outQueryOut,
      "GenQueryOut_PI", NULL, irodsProt);

    printf ("unpackStruct empty myQueryOut status = %d\n", status);

    memset (&myQueryOut, 0, sizeof (myQueryOut));
    myQueryOut.rowCnt = 2;
    myQueryOut.attriCnt = 4;

    myQueryOut.sqlResult[0].attriInx = 10;
    myQueryOut.sqlResult[0].len = 20;
    myQueryOut.sqlResult[0].value = tmpValue = (char *) malloc (20*2);
    sprintf (tmpValue, "value 0,1");
    tmpValue += 20;
    sprintf (tmpValue, "value 0,2");

    myQueryOut.sqlResult[1].attriInx = 20;
    myQueryOut.sqlResult[1].len = 30;
    myQueryOut.sqlResult[1].value = tmpValue = (char *) malloc (30*2);
    sprintf (tmpValue, "value 1,1");
    tmpValue += 30;
    sprintf (tmpValue, "value 1,2");

    myQueryOut.sqlResult[2].attriInx = 30;
    myQueryOut.sqlResult[2].len = 40;
    myQueryOut.sqlResult[2].value = tmpValue = (char *) malloc (40*2);
    sprintf (tmpValue, "value 2,1");
    tmpValue += 40;
    sprintf (tmpValue, "value 2,2");

    myQueryOut.sqlResult[3].attriInx = 40;
    myQueryOut.sqlResult[3].len = 50;
    myQueryOut.sqlResult[3].value = tmpValue = (char *) malloc (50*2);
    memset (tmpValue, 0, 50*2);

    status = packStruct (&myQueryOut, &packedResult, "GenQueryOut_PI",
      NULL, 0, irodsProt);
    printf ("packStruct status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "genq.out"); 

    status = unpackStruct (packedResult->buf, (void **) &outQueryOut,
      "GenQueryOut_PI", NULL, irodsProt);

    printf ("unpackStruct status = %d\n", status);

    status = parsePackInstruct (TEST_PI, &packItemHead);

    printf ("parsePackInstruct status = %d\n", status);

    myStartupPack.connectCnt = 11;
    myStartupPack.irodsProt = XML_PROT;
    strcpy (myStartupPack.proxyUser, "proxyUser"); 
    strcpy (myStartupPack.proxyRodsZone, "proxyRodsZone"); 
    strcpy (myStartupPack.clientUser, "myclientUser"); 
    strcpy (myStartupPack.clientRodsZone, "clientRodsZone"); 
    strcpy (myStartupPack.relVersion, "relVersion"); 
    strcpy (myStartupPack.apiVersion, "apiVersion"); 
    strcpy (myStartupPack.option, "option"); 
    status = packStruct (&myStartupPack, &packedResult, "StartupPack_PI",
      NULL, 0, XML_PROT);
    printf ("packStruct of StartupPack_PI status = %d\n", status);

    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "startup.out"); 
    status = unpackStruct (packedResult->buf, (void **) &outStartupPack, 
      "StartupPack_PI", NULL, irodsProt);
    printf ("unpackStruct of StartupPack_PI status = %d\n", status);

    myError.len = 3;

    myError.errMsg = (rErrMsg_t **) malloc (sizeof (void *) * 3);
    for (i = 0; i < 3; i++) {
	myError.errMsg[i] = (rErrMsg_t *) malloc (sizeof (rErrMsg_t));  
	sprintf (myError.errMsg[i]->msg, "error %d\n", i);
	myError.errMsg[i]->status = i;
    }

    status = packStruct (&myError, &packedResult, "RError_PI",
      NULL, 0, irodsProt);
    printf ("packStruct of RErrMsg_PI status = %d\n", status);
    if (irodsProt == XML_PROT)
        writePackedRes (packedResult, "error.out");

    status = unpackStruct (packedResult->buf, (void **) &outError, "RError_PI",
      NULL, irodsProt);
    printf ("unpackStruct of RErrMsg_PI status = %d\n", status);
    
} 
int
lsSubfilesInBundle (rcComm_t *conn, char *srcPath, rodsEnv *myRodsEnv,
rodsArguments_t *rodsArgs)
{
    int i, status;
    genQueryOut_t *genQueryOut = NULL;
    genQueryInp_t genQueryInp;
    char condStr[MAX_NAME_LEN];
    sqlResult_t *dataName, *collection, *dataSize;
    char *dataNameStr, *collectionStr, *dataSizeStr;
    int continueInx = 1;


    fprintf (stdout, "Bundle file: %s\n", srcPath);
    fprintf (stdout, "Subfiles:\n");
    bzero (&genQueryInp, sizeof (genQueryInp));
    genQueryInp.maxRows = MAX_SQL_ROWS;

    snprintf (condStr, MAX_NAME_LEN, "='%s'", srcPath);
    addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr);
    snprintf (condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS);
    addInxVal (&genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr);
    addKeyVal (&genQueryInp.condInput, ZONE_KW, srcPath);

    addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
    addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
    addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1);

    while (continueInx > 0) {
        status =  rcGenQuery (conn, &genQueryInp, &genQueryOut);

        if (status < 0) {
            if (status != CAT_NO_ROWS_FOUND) {
                rodsLogError (LOG_ERROR, status,
                  "lsSubfilesInBundle: rsGenQuery error for %s",
                  srcPath);
            }
            clearGenQueryInp (&genQueryInp);
            return (status);
        }

        if ((collection = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == 
	  NULL) {
            rodsLog (LOG_ERROR,
              "lsSubfilesInBundle: getSqlResultByInx for COL_COLL_NAME failed");
            return (UNMATCHED_KEY_OR_INDEX);
        }
        if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == 
          NULL) {
            rodsLog (LOG_ERROR,
              "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_NAME failed");
            return (UNMATCHED_KEY_OR_INDEX);
        }
        if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE)) == 
          NULL) {
            rodsLog (LOG_ERROR,
              "lsSubfilesInBundle: getSqlResultByInx for COL_DATA_SIZE failed");
            return (UNMATCHED_KEY_OR_INDEX);
        }

        for (i = 0;i < genQueryOut->rowCnt; i++) {
            collectionStr = &collection->value[collection->len * i];
            dataNameStr = &dataName->value[dataName->len * i];
            dataSizeStr = &dataSize->value[dataSize->len * i];
            fprintf (stdout, "    %s/%s    %s\n", 
	      collectionStr, dataNameStr, dataSizeStr);
        }

        if (genQueryOut != NULL) {
            continueInx = genQueryInp.continueInx =
            genQueryOut->continueInx;
            freeGenQueryOut (&genQueryOut);
        } else {
            continueInx = 0;
        }
    }
    clearGenQueryInp (&genQueryInp);
    return (status);
}
Ejemplo n.º 26
0
/**
 * \fn msiAddConditionToGenQuery(msParam_t *attribute, msParam_t *opr, msParam_t *value, msParam_t *queryInput, ruleExecInfo_t *rei)
 *
 * \brief Adds a condition to a genQueryInp_t
 *
 * \module core
 *
 * \author  Antoine de Torcy
 * \date    2009-12-07
 *
 * \note This microservice adds a condition to an existing genQueryInp_t, from three parameters.
 *       One is an iCAT attribute index given without its 'COL_' prefix.
 *       The second one is the SQL operator. The third one is the value and may contain wildcards.
 *       To be used with #msiAddSelectFieldToGenQuery and #msiExecGenQuery to build queries from the
 *       results of other microservices or actions within an iRODS rule.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] attribute - Required - A STR_MS_T with the iCAT attribute name (see wiki.irods.org/index.php/icatAttributes).
 * \param[in] opr - Required - A STR_MS_T with the operator.
 * \param[in] value - Required - A STR_MS_T with the value.
 * \param[in,out] queryInput - Required - A GenQueryInp_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 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiAddConditionToGenQuery( msParam_t *attribute, msParam_t *opr, msParam_t *value, msParam_t *queryInput, ruleExecInfo_t *rei ) {
    genQueryInp_t *genQueryInp;
    char condStr[MAX_NAME_LEN];
    char *att_str, *op_str, *val_str;
    int att_inx;

    /*************************************  INIT **********************************/

    /* For testing mode when used with irule --test */
    RE_TEST_MACRO( "    Calling msiAddConditionToGenQuery" )

    /* Sanity checks */
    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input rei or rsComm is NULL." );
        return ( SYS_INTERNAL_NULL_INPUT_ERR );
    }


    /********************************** PARAM PARSING  *********************************/

    /* Parse attribute */
    if ( ( att_str = parseMspForStr( attribute ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input attribute is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }

    /* Parse operator */
    if ( ( op_str = parseMspForStr( opr ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input opr is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }

    /* Parse value */
    if ( ( val_str = parseMspForStr( value ) ) == NULL ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input value is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }

    /* Check for proper parameter type for queryInput */
    if ( queryInput->type && strcmp( queryInput->type, GenQueryInp_MS_T ) ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: queryInput is not of type GenQueryInp_MS_T." );
        return ( USER_PARAM_TYPE_ERR );
    }

    /* Parse queryInput. Must not be empty. */
    if ( !queryInput->inOutStruct ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: input queryInput is NULL." );
        return ( USER__NULL_INPUT_ERR );
    }
    else {
        genQueryInp = ( genQueryInp_t* )queryInput->inOutStruct;
    }


    /***************************** ADD CONDITION TO QUERY INPUT  *****************************/

    /* Get attribute index */
    att_inx = getAttrIdFromAttrName( att_str );

    /* Error? */
    if ( att_inx < 0 ) {
        rodsLog( LOG_ERROR, "msiAddConditionToGenQuery: Unable to get valid ICAT column index." );
        return( att_inx );
    }

    /* Make the condition */
    snprintf( condStr, MAX_NAME_LEN, " %s '%s'", op_str, val_str );

    /* Add condition to genQueryInput */
    addInxVal( &genQueryInp->sqlCondInp, att_inx, condStr );  /* condStr gets strdup'ed */


    /*********************************** DONE *********************************************/
    return 0;
}
Ejemplo n.º 27
0
int
dataObjStat (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
rodsObjStat_t **rodsObjStatOut)
{
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int status;
    char myColl[MAX_NAME_LEN], myData[MAX_NAME_LEN];
    char condStr[MAX_NAME_LEN];
    sqlResult_t *dataSize;
    sqlResult_t *dataMode;
    sqlResult_t *replStatus;
    sqlResult_t *dataId;
    sqlResult_t *chksum;
    sqlResult_t *ownerName;
    sqlResult_t *ownerZone;
    sqlResult_t *createTime;
    sqlResult_t *modifyTime;

    /* see if objPath is a dataObj */

    memset (myColl, 0, MAX_NAME_LEN);
    memset (myData, 0, MAX_NAME_LEN);

    if ((status = splitPathByKey (
      dataObjInp->objPath, myColl, myData, '/')) < 0) {
        return (OBJ_PATH_DOES_NOT_EXIST);
    }

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

    snprintf (condStr, MAX_NAME_LEN, "='%s'", myColl);
    addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
    snprintf (condStr, MAX_NAME_LEN, "='%s'", myData);
    addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, condStr);

    addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
    addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1);
    addInxIval (&genQueryInp.selectInp, COL_DATA_MODE, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_REPL_STATUS, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_DATA_CHECKSUM, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_OWNER_NAME, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_OWNER_ZONE, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_CREATE_TIME, 1);
    addInxIval (&genQueryInp.selectInp, COL_D_MODIFY_TIME, 1);

    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery (rsComm, &genQueryInp, &genQueryOut);

    clearGenQueryInp (&genQueryInp);

    if (status >= 0) {
        if ((dataSize = getSqlResultByInx (genQueryOut, COL_DATA_SIZE))
          == NULL) {
            rodsLog (LOG_ERROR,
              "_rsObjStat: getSqlResultByInx for COL_DATA_SIZE failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((dataMode = getSqlResultByInx (genQueryOut,
          COL_DATA_MODE)) == NULL) {
            rodsLog (LOG_ERROR,
              "_rsObjStat: getSqlResultByInx for COL_DATA_MODE failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((replStatus = getSqlResultByInx (genQueryOut,
          COL_D_REPL_STATUS)) == NULL) {
            rodsLog (LOG_ERROR,
              "_rsObjStat: getSqlResultByInx for COL_D_REPL_STATUS failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((dataId = getSqlResultByInx (genQueryOut,
          COL_D_DATA_ID)) == NULL) {
            rodsLog (LOG_ERROR,
              "_rsObjStat: getSqlResultByInx for COL_D_DATA_ID failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((chksum = getSqlResultByInx (genQueryOut,
          COL_D_DATA_CHECKSUM)) == NULL) {
            rodsLog (LOG_ERROR,
             "_rsObjStat:getSqlResultByInx for COL_D_DATA_CHECKSUM failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((ownerName = getSqlResultByInx (genQueryOut,
          COL_D_OWNER_NAME)) == NULL) {
            rodsLog (LOG_ERROR,
             "_rsObjStat:getSqlResultByInx for COL_D_OWNER_NAME failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((ownerZone = getSqlResultByInx (genQueryOut,
          COL_D_OWNER_ZONE)) == NULL) {
            rodsLog (LOG_ERROR,
             "_rsObjStat:getSqlResultByInx for COL_D_OWNER_ZONE failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((createTime = getSqlResultByInx (genQueryOut,
          COL_D_CREATE_TIME)) == NULL) {
            rodsLog (LOG_ERROR,
             "_rsObjStat:getSqlResultByInx for COL_D_CREATE_TIME failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else if ((modifyTime = getSqlResultByInx (genQueryOut,
          COL_D_MODIFY_TIME)) == NULL) {
            rodsLog (LOG_ERROR,
             "_rsObjStat:getSqlResultByInx for COL_D_MODIFY_TIME failed");
            return (UNMATCHED_KEY_OR_INDEX);
        } else {
            int i;

            *rodsObjStatOut = (rodsObjStat_t *) malloc (sizeof (rodsObjStat_t));
            memset (*rodsObjStatOut, 0, sizeof (rodsObjStat_t));
            (*rodsObjStatOut)->objType = DATA_OBJ_T; status = (int)DATA_OBJ_T;
            /* XXXXXX . dont have numCopies anymore. Replaced by dataMode 
	     * (*rodsObjStatOut)->numCopies = genQueryOut->rowCnt; */

            for (i = 0;i < genQueryOut->rowCnt; i++) {
                if (atoi (&replStatus->value[replStatus->len * i]) > 0) {
                    rstrcpy ((*rodsObjStatOut)->dataId, 
		      &dataId->value[dataId->len * i], NAME_LEN);
                    (*rodsObjStatOut)->objSize =
                      strtoll (&dataSize->value[dataSize->len * i], 0, 0);
                    (*rodsObjStatOut)->dataMode =
                      atoi (&dataMode->value[dataMode->len * i]);
                    rstrcpy ((*rodsObjStatOut)->chksum,
                      &chksum->value[chksum->len * i], NAME_LEN);
		    rstrcpy ((*rodsObjStatOut)->ownerName,
                      &ownerName->value[ownerName->len * i], NAME_LEN);
                    rstrcpy ((*rodsObjStatOut)->ownerZone,
                      &ownerZone->value[ownerZone->len * i], NAME_LEN);
                    rstrcpy ((*rodsObjStatOut)->createTime,
                      &createTime->value[createTime->len * i], TIME_LEN);
                    rstrcpy ((*rodsObjStatOut)->modifyTime,
                      &modifyTime->value[modifyTime->len * i], TIME_LEN);
                    break;
                }
            }

            if (strlen ((*rodsObjStatOut)->dataId) == 0) {
                /* just use the first one */
                rstrcpy ((*rodsObjStatOut)->dataId, dataId->value, NAME_LEN);
                (*rodsObjStatOut)->objSize = strtoll (dataSize->value, 0, 0);
                rstrcpy ((*rodsObjStatOut)->chksum, chksum->value, NAME_LEN);
                rstrcpy ((*rodsObjStatOut)->ownerName, ownerName->value, 
		  NAME_LEN);
                rstrcpy ((*rodsObjStatOut)->ownerZone, ownerZone->value, 
		  NAME_LEN);
                rstrcpy ((*rodsObjStatOut)->createTime, createTime->value, 
		  NAME_LEN);
                rstrcpy ((*rodsObjStatOut)->modifyTime, modifyTime->value, 
		  NAME_LEN);
            }
        }
        freeGenQueryOut (&genQueryOut);
    }

    return (status);
}
Ejemplo n.º 28
0
int
doTest7( char *testString, char *testString2, char *testString3,
         char *minTotalRows ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    char condStr1[MAX_NAME_LEN];
    char condStr2[MAX_NAME_LEN];
    int status, status2;

    printf( "dotest7\n" );
    rodsLogSqlReq( 1 );

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

    addInxIval( &genQueryInp.selectInp, COL_TOKEN_NAME, 1 );

    snprintf( condStr1, MAX_NAME_LEN, "= 'data_type'" );
    addInxVal( &genQueryInp.sqlCondInp,  COL_TOKEN_NAMESPACE, condStr1 );

    snprintf( condStr2, MAX_NAME_LEN, "like '%s%s%s'", "%",
              testString, "%" );
    addInxVal( &genQueryInp.sqlCondInp,  COL_TOKEN_VALUE2, condStr2 );

    genQueryInp.options = RETURN_TOTAL_ROW_COUNT;
    genQueryInp.maxRows = 5;
    if ( testString3 != NULL && *testString3 != '\0' ) {
        genQueryInp.maxRows = atoi( testString3 );
    }

    if ( testString2 != NULL && *testString2 != '\0' ) {
        genQueryInp.rowOffset = atoi( testString2 );
    }

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );

    printf( "genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount );

    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }

    if ( minTotalRows != NULL && *minTotalRows != '\0' ) {
        int minTotalRowsInt;
        minTotalRowsInt  = atoi( minTotalRows );
        if ( genQueryOut.totalRowCount < minTotalRowsInt ) {
            rodsLog( LOG_ERROR, "doTest7 chlGenQuery totalRowCount(%d) is less than minimum expected (%d)\n",
                     genQueryOut.totalRowCount, minTotalRowsInt );
            return -1;
        }
    }

    if ( genQueryOut.continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut.continueInx;
        printf( "Second call to chlGenQuery\n" );
        status2  = chlGenQuery( genQueryInp, &genQueryOut );
        printf( "chlGenQuery status=%d\n", status2 );
        if ( status2 == 0 ) {
            printGenQOut( &genQueryOut );
        }
    }
    return status;
}
Ejemplo n.º 29
0
int
collStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
          rodsObjStat_t **rodsObjStatOut ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int status;
    char condStr[MAX_NAME_LEN];
    sqlResult_t *dataId;
    sqlResult_t *ownerName;
    sqlResult_t *ownerZone;
    sqlResult_t *createTime;
    sqlResult_t *modifyTime;
    sqlResult_t *collType;
    sqlResult_t *collInfo1;
    sqlResult_t *collInfo2;

    /* see if objPath is a collection */
    memset( &genQueryInp, 0, sizeof( genQueryInp ) );

    snprintf( condStr, MAX_NAME_LEN, "='%s'", dataObjInp->objPath );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );

    addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 );
    /* XXXX COL_COLL_NAME added for queueSpecColl */
    addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 );
    /* XXXX may want to do this if spec coll is supported */
    addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 );

    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( status >= 0 ) {
        *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) );
        memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) );
        ( *rodsObjStatOut )->objType = COLL_OBJ_T;
        status = ( int )COLL_OBJ_T;
        if ( ( dataId = getSqlResultByInx( genQueryOut,
                                           COL_COLL_ID ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat: getSqlResultByInx for COL_COLL_ID failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( ownerName = getSqlResultByInx( genQueryOut,
                                COL_COLL_OWNER_NAME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_NAME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( ownerZone = getSqlResultByInx( genQueryOut,
                                COL_COLL_OWNER_ZONE ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( createTime = getSqlResultByInx( genQueryOut,
                                 COL_COLL_CREATE_TIME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_CREATE_TIME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( modifyTime = getSqlResultByInx( genQueryOut,
                                 COL_COLL_MODIFY_TIME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collType = getSqlResultByInx( genQueryOut,
                               COL_COLL_TYPE ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_TYPE failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collInfo1 = getSqlResultByInx( genQueryOut,
                                COL_COLL_INFO1 ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_INFO1 failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collInfo2 = getSqlResultByInx( genQueryOut,
                                COL_COLL_INFO2 ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_INFO2 failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else {
            rstrcpy( ( *rodsObjStatOut )->dataId, dataId->value, NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->ownerName, ownerName->value,
                     NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->ownerZone, ownerZone->value,
                     NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->createTime, createTime->value,
                     TIME_LEN );
            rstrcpy( ( *rodsObjStatOut )->modifyTime, modifyTime->value,
                     TIME_LEN );

            if ( strlen( collType->value ) > 0 ) {
                specCollCache_t *specCollCache = 0;

                if ( ( specCollCache =
                            matchSpecCollCache( dataObjInp->objPath ) ) != NULL ) {
                    replSpecColl( &specCollCache->specColl,
                                  &( *rodsObjStatOut )->specColl );
                }
                else {
                    status = queueSpecCollCache( rsComm, genQueryOut, // JMC - backport 4680?
                                                 dataObjInp->objPath );
                    if ( status < 0 ) {
                        return status;
                    }
                    replSpecColl( &SpecCollCacheHead->specColl,
                                  &( *rodsObjStatOut )->specColl );
                }


            }
        }
    }

    clearGenQueryInp( &genQueryInp );
    freeGenQueryOut( &genQueryOut );

    return status;
}
Ejemplo n.º 30
0
int
doTest9( char *testString, char *testString2 ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t genQueryOut;
    char condStr1[MAX_NAME_LEN];
    int status, status2;
    int type;

    printf( "dotest9\n" );
    rodsLogSqlReq( 1 );

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

    type = 0;
    if ( testString2 != NULL ) {
        if ( strcmp( testString2, "min" ) == 0 ) {
            type = 1;
        }
        if ( strcmp( testString2, "max" ) == 0 ) {
            type = 2;
        }
        if ( strcmp( testString2, "sum" ) == 0 ) {
            type = 3;
        }
        if ( strcmp( testString2, "avg" ) == 0 ) {
            type = 4;
        }
        if ( strcmp( testString2, "count" ) == 0 ) {
            type = 5;
        }
    }

    if ( type == 0 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, 0 );
    }
    if ( type == 1 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, SELECT_MIN );
    }
    if ( type == 2 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, SELECT_MAX );
    }
    if ( type == 3 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, SELECT_SUM );
    }
    if ( type == 4 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, SELECT_AVG );
    }
    if ( type == 5 ) {
        addInxIval( &genQueryInp.selectInp, COL_DATA_SIZE, SELECT_COUNT );
    }

    snprintf( condStr1, MAX_NAME_LEN, "= '%s'", testString );

    addInxVal( &genQueryInp.sqlCondInp,  COL_R_RESC_NAME, condStr1 );

    genQueryInp.maxRows = 5;

    status  = chlGenQuery( genQueryInp, &genQueryOut );
    printf( "chlGenQuery status=%d\n", status );

    printf( "genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount );

    if ( status == 0 ) {
        printGenQOut( &genQueryOut );
    }

    if ( genQueryOut.continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut.continueInx;
        printf( "Second call to chlGenQuery\n" );
        status2  = chlGenQuery( genQueryInp, &genQueryOut );
        printf( "chlGenQuery status=%d\n", status2 );
        if ( status2 == 0 ) {
            printGenQOut( &genQueryOut );
        }
    }
    return status;
}