/** * \fn msiGetSystemTime(msParam_t* outParam, msParam_t* inpParam, ruleExecInfo_t *rei) * * \brief This microservice returns the local system time * * \module framework * * \since pre-2.1 * * \author Antoine de Torcy * \date 2007-09-19 * * \note Default output format is system time in seconds, use 'human' as input param for human readable format. * * \usage See clients/icommands/test/rules3.0/ * * \param[out] outParam - a STR_MS_T containing the time * \param[in] inpParam - Optional - a STR_MS_T containing the desired output format * \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 msiGetSystemTime( msParam_t* outParam, msParam_t* inpParam, ruleExecInfo_t *rei ) { char *format; char tStr0[TIME_LEN], tStr[TIME_LEN]; int status; /* For testing mode when used with irule --test */ RE_TEST_MACRO( " Calling msiGetSystemTime" ) if ( rei == NULL || rei->rsComm == NULL ) { rodsLog( LOG_ERROR, "msiGetSystemTime: input rei or rsComm is NULL" ); return ( SYS_INTERNAL_NULL_INPUT_ERR ); } format = ( char * ) inpParam->inOutStruct; if ( !format || strcmp( format, "human" ) ) { getNowStr( tStr ); } else { getNowStr( tStr0 ); getLocalTimeFromRodsTime( tStr0, tStr ); } status = fillStrInMsParam( outParam, tStr ); return( status ); }
int printDataCollEntLong (collEnt_t *collEnt, int flags) { char *tmpReplStatus; char localTimeModify[20]; char typeStr[NAME_LEN]; if (collEnt->replStatus == OLD_COPY) { tmpReplStatus = " "; } else { tmpReplStatus = "&"; } getLocalTimeFromRodsTime (collEnt->modifyTime, localTimeModify); if (collEnt->specColl.collClass == NO_SPEC_COLL || collEnt->specColl.collClass == LINKED_COLL) { printf (" %-12.12s %6d %-20.20s %12lld %16.16s %s %s\n", collEnt->ownerName, collEnt->replNum, collEnt->resource, collEnt->dataSize, localTimeModify, tmpReplStatus, collEnt->dataName); } else { getSpecCollTypeStr (&collEnt->specColl, typeStr); printf (" %-12.12s %6.6s %-20.20s %12lld %16.16s %s %s\n", collEnt->ownerName, typeStr, collEnt->resource, collEnt->dataSize, localTimeModify, tmpReplStatus, collEnt->dataName); } if ((flags & VERY_LONG_METADATA_FG) != 0) { printf (" %s %s %s %s\n", collEnt->chksum, collEnt->rescGrp, collEnt->dataType, collEnt->phyPath); } return 0; }
bool print_general_info(const userinfo_t& _info) { // Construct query object for listing info for specified user const std::string select{ "USER_NAME, USER_ID, USER_TYPE, USER_ZONE, USER_INFO, USER_COMMENT, USER_CREATE_TIME, USER_MODIFY_TIME"}; irods::query<rcComm_t> qobj{Conn, construct_userinfo_query_string(_info, select)}; // Ensure that user exists if (qobj.begin() == qobj.end()) { return false; } // Print information concerning found users const std::vector<std::string> general_info_labels{ "name", "id", "type", "zone", "info", "comment", "create time", "modify time"}; int i{}; for (const auto& selections: *qobj.begin()) { if (std::string::npos != (general_info_labels[i].find("time"))) { char local_time[TIME_LEN]{}; getLocalTimeFromRodsTime(selections.c_str(), local_time); printf("%s: %s: %s\n", general_info_labels[i].c_str(), selections.c_str(), local_time); } else { printf("%s: %s\n", general_info_labels[i].c_str(), selections.c_str()); } i++; } return true; }
/* print the results of a general query. */ void printResultsAndSubQuery( rcComm_t *Conn, int status, genQueryOut_t *genQueryOut, char *descriptions[], int subColumn, int dashOpt ) { int i, j; lastCommandStatus = status; if ( status == CAT_NO_ROWS_FOUND ) { lastCommandStatus = 0; } if ( status != 0 && status != CAT_NO_ROWS_FOUND ) { printError( Conn, status, "rcGenQuery" ); } else { if ( status == CAT_NO_ROWS_FOUND ) { if ( printCount == 0 ) { printf( "No rows found\n" ); } } else { for ( i = 0; i < genQueryOut->rowCnt; i++ ) { printedRows++; char *subCol = ""; if ( i > 0 && dashOpt > 0 ) { printf( "----\n" ); } for ( j = 0; j < genQueryOut->attriCnt; j++ ) { char *tResult; tResult = genQueryOut->sqlResult[j].value; tResult += i * genQueryOut->sqlResult[j].len; if ( subColumn == j ) { subCol = tResult; } if ( *descriptions[j] != '\0' ) { if ( strstr( descriptions[j], "time" ) != 0 ) { char localTime[TIME_LEN]; getLocalTimeFromRodsTime( tResult, localTime ); if ( strcmp( tResult, "0" ) == 0 || *tResult == '\0' ) { strcpy( localTime, "none" ); } printf( "%s: %s\n", descriptions[j], localTime ); } else { printf( "%s: %s\n", descriptions[j], tResult ); printCount++; } } } if ( subColumn >= 0 ) { showRestrictions( subCol ); } } } } }
/** * \fn msiGetIcatTime (msParam_t *timeOutParam, msParam_t *typeInParam, ruleExecInfo_t *) * * \brief This function returns the system time for the iCAT server * * \module core * * \since pre-2.1 * * * \usage See clients/icommands/test/rules/ * * \param[out] timeOutParam - a msParam of type STR_MS_T * \param[in] typeInParam - a msParam of type STR_MS_T * \li "icat" or "unix" will return seconds since epoch * \li otherwise, human friendly * \param[in,out] - 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 msiGetIcatTime( msParam_t* timeOutParam, msParam_t* typeInParam, ruleExecInfo_t* ) { char *type; char tStr0[TIME_LEN], tStr[TIME_LEN]; int i; type = ( char* )typeInParam->inOutStruct; if ( !strcmp( type, "icat" ) || !strcmp( type, "unix" ) ) { getNowStr( tStr ); } else { /* !strcmp(type,"human") */ getNowStr( tStr0 ); getLocalTimeFromRodsTime( tStr0, tStr ); } i = fillStrInMsParam( timeOutParam, tStr ); return i; }
/* print the results of a general query. */ int printGenQueryResults( rcComm_t *Conn, int status, genQueryOut_t *genQueryOut, char *descriptions[], int doDashes ) { int printCount; int i, j; char localTime[TIME_LEN]; printCount = 0; if ( status != 0 ) { printError( Conn, status, "rcGenQuery" ); } else { if ( status != CAT_NO_ROWS_FOUND ) { for ( i = 0; i < genQueryOut->rowCnt; i++ ) { if ( i > 0 && doDashes ) { printf( "----\n" ); } for ( j = 0; j < genQueryOut->attriCnt; j++ ) { char *tResult; tResult = genQueryOut->sqlResult[j].value; tResult += i * genQueryOut->sqlResult[j].len; if ( *descriptions[j] != '\0' ) { if ( strstr( descriptions[j], "time" ) != 0 ) { getLocalTimeFromRodsTime( tResult, localTime ); printf( "%s: %s: %s\n", descriptions[j], tResult, localTime ); } else { printf( "%s: %s\n", descriptions[j], tResult ); } } else { printf( "%s\n", tResult ); } printCount++; } } } } return printCount; }
/* print the results of a general query. */ void printGenQueryResults(rcComm_t *Conn, int status, genQueryOut_t *genQueryOut, char *descriptions[]) { int i, j; char localTime[20]; lastCommandStatus = status; if (status == CAT_NO_ROWS_FOUND) lastCommandStatus = 0; if (status!=0 && status != CAT_NO_ROWS_FOUND) { printError(Conn, status, "rcGenQuery"); } else { if (status == CAT_NO_ROWS_FOUND) { if (printCount==0) printf("No rows found\n"); } else { for (i=0;i<genQueryOut->rowCnt;i++) { if (i>0) printf("----\n"); for (j=0;j<genQueryOut->attriCnt;j++) { char *tResult; tResult = genQueryOut->sqlResult[j].value; tResult += i*genQueryOut->sqlResult[j].len; if (*descriptions[j]!='\0') { if (strstr(descriptions[j],"time")!=0) { getLocalTimeFromRodsTime(tResult, localTime); printf("%s: %s\n", descriptions[j], localTime); } else { printf("%s: %s\n", descriptions[j], tResult); printCount++; } } } } } } }
/** * \fn msiServerBackup(msParam_t *options, msParam_t *keyValOut, ruleExecInfo_t *rei) * * \brief Copies iRODS server files to the local resource * * \module core * * \since 3.0.x * * \author Antoine de Torcy * \date 2011-05-25 * * \note Copies server files to the local vault and registers them. * Object (.o) files and binaries are not included. * * \note Files are stored in the Vault under a directory of the format: hostname_timestamp * * \usage See clients/icommands/test/rules3.0/ * * \param[in] options - Optional - a STR_MS_T that contains one of more options in * the format keyWd1=value1++++keyWd2=value2++++keyWd3=value3... * A placeholder for now. * \param[out] keyValOut - a KeyValPair_MS_T with the number of files and bytes written. * \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 Some * \sideeffect None * * \return integer * \retval 0 on success * \pre None * \post None * \sa None **/ int msiServerBackup(msParam_t *options, msParam_t *keyValOut, ruleExecInfo_t *rei) { keyValPair_t *myKeyVal; /* for storing results */ collInp_t collInp; /* for creating and opening collections */ dataObjInp_t dataObjInp; /* for collection registration */ char tStr0[TIME_LEN], tStr[TIME_LEN]; /* for timestamp */ char newDirPath[MAX_NAME_LEN]; /* physical path of new directory on resource */ rescInfo_t *rescInfo; /* for local resource info */ char *dbPath; /* local iCAT home dir */ char *rodsDirPath, *subPath; size_t offset; int fileCount, status; /* counters, status, etc... */ char fileCountStr[21]; /* For testing mode when used with irule --test */ RE_TEST_MACRO (" Calling msiServerBackup") /* Sanity checks */ if (rei == NULL || rei->rsComm == NULL) { rodsLog (LOG_ERROR, "msiServerBackup: input rei or rsComm is NULL."); return (SYS_INTERNAL_NULL_INPUT_ERR); } /* Must be called from an admin account */ if (rei->uoic->authInfo.authFlag < LOCAL_PRIV_USER_AUTH) { status = CAT_INSUFFICIENT_PRIVILEGE_LEVEL; rodsLog (LOG_ERROR, "msiServerBackup: User %s is not local admin. Status = %d", rei->uoic->userName, status); return(status); } /* Get icat home dir, if applicable */ dbPath = getDBHomeDir(); /* Get local resource info */ status = getDefaultLocalRescInfo(&rescInfo); if (status < 0) { rodsLog (LOG_ERROR, "msiServerBackup: Could not resolve local resource, status = %d", status); if (dbPath) { free(dbPath); } return (status); } /* Get path of iRODS home directory */ if ((rodsDirPath = getenv("irodsHomeDir")) == NULL) { rodsLog (LOG_ERROR, "msiServerBackup: Cannot find directory to back up."); if (dbPath) { free(dbPath); } return (USER_INPUT_PATH_ERR); } /***** Create target directory for copy, whose name is made ****** of the hostname and timestamp ********************/ /* get timestamp */ getNowStr (tStr0); getLocalTimeFromRodsTime (tStr0,tStr); /**********************************/ /* Prepare myKeyVal so that we can dump * data in it throughout the microservice */ myKeyVal = (keyValPair_t*) malloc (sizeof(keyValPair_t)); memset (myKeyVal, 0, sizeof(keyValPair_t)); keyValOut->type = strdup(KeyValPair_MS_T); /* Store local and target directories in myKeyVal, along with other useful stuff */ /* Calculate offset */ offset = strrchr(rodsDirPath,'/') - rodsDirPath + 1; /*******************************************/ /************ invoke loadDirToLocalResc ***************************/ fileCount = loadDirToLocalResc(rei, rodsDirPath, offset, rescInfo->rescVaultPath, tStr, dbPath); /* get some cleanup out of the way */ if (dbPath) { free(dbPath); } if (rei->status < 0) { rodsLog (LOG_ERROR, "msiServerBackup: loadDirToLocalResc() error, status = %d", rei->status); free(myKeyVal); return rei->status; } /******************************************************/ /* We need to create a parent collection prior to registering our directory */ /* set up collection creation input */ memset (&collInp, 0, sizeof(collInp_t)); addKeyVal (&collInp.condInput, RECURSIVE_OPR__KW, ""); /* build path of target collection */ snprintf(collInp.collName, MAX_NAME_LEN, "%s/%s/%s_%s", rei->rsComm->myEnv.rodsHome, BCKP_COLL_NAME, rei->rsComm->myEnv.rodsHost, tStr); /* make target collection */ rei->status = rsCollCreate (rei->rsComm, &collInp); if (rei->status < 0) { rodsLog (LOG_ERROR, "msiServerBackup: rsCollCreate failed for %s, status = %d", collInp.collName, rei->status); free(myKeyVal); return (rei->status); } /* Register our new directory in the vault */ /* Input setup */ memset(&dataObjInp, 0, sizeof(dataObjInp_t)); addKeyVal (&dataObjInp.condInput, COLLECTION_KW, ""); addKeyVal (&dataObjInp.condInput, DEST_RESC_NAME_KW, rescInfo->rescName); /* Separated for clarity. Typically this chunk is 'home/$username' */ subPath = rei->rsComm->myEnv.rodsHome + strlen(rei->rsComm->myEnv.rodsZone) + 2; /* Reconstruct path of new dir on resource */ snprintf(newDirPath, MAX_NAME_LEN, "%s/%s/%s/%s_%s/%s", rescInfo->rescVaultPath, subPath, BCKP_COLL_NAME, rei->rsComm->myEnv.rodsHost, tStr, rodsDirPath + offset); addKeyVal (&dataObjInp.condInput, FILE_PATH_KW, newDirPath); /* Similarly, reconstruct iRODS path of (target) new collection */ snprintf(dataObjInp.objPath, MAX_NAME_LEN, "%s/%s/%s_%s/%s", rei->rsComm->myEnv.rodsHome, BCKP_COLL_NAME, rei->rsComm->myEnv.rodsHost, tStr, rodsDirPath + offset); /* Registration happens here */ rei->status = rsPhyPathReg (rei->rsComm, &dataObjInp); if (rei->status < 0) { rodsLog (LOG_ERROR, "msiServerBackup: rsPhyPathReg() failed with status %d", rei->status); free(myKeyVal); return rei->status; } /* Add file count to myKeyVal */ snprintf(fileCountStr, 21, "%d", fileCount); addKeyVal(myKeyVal, "object_count", fileCountStr); // stub /* Return myKeyVal through keyValOut */ keyValOut->inOutStruct = (void*) myKeyVal; /* Done! */ return 0; }
/* Show user quota information */ int showUserUsage( char *userName, char *usersZone ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut; int inputInx[20]; int inputVal[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int inputCond[20]; char *condVal[10]; char v1[BIG_STR]; int i, j, k, status; int printCount; char header[] = "Resource User Data-stored (bytes)"; char *pad[14] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "" }; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); printCount = 0; i = 0; inputInx[i++] = COL_QUOTA_USAGE_MODIFY_TIME; inputInx[i++] = COL_QUOTA_RESC_NAME; inputInx[i++] = COL_QUOTA_USER_NAME; inputInx[i++] = COL_QUOTA_USER_ZONE; inputInx[i++] = COL_QUOTA_USAGE; genQueryInp.selectInp.inx = inputInx; genQueryInp.selectInp.value = inputVal; genQueryInp.selectInp.len = i; genQueryInp.sqlCondInp.len = 0; if ( userName[0] != '\0' ) { inputCond[0] = COL_QUOTA_USER_NAME; sprintf( v1, "='%s'", userName ); condVal[0] = v1; genQueryInp.sqlCondInp.inx = inputCond; genQueryInp.sqlCondInp.value = condVal; genQueryInp.sqlCondInp.len++; } genQueryInp.condInput.len = 0; genQueryInp.maxRows = MAX_SQL_ROWS; genQueryInp.continueInx = 0; status = rcGenQuery( Conn, &genQueryInp, &genQueryOut ); if ( status == CAT_NO_ROWS_FOUND ) { printf( "No records found, run 'iadmin cu' to calculate usage\n" ); return 0; } if ( status != 0 ) { printError( Conn, status, "rcGenQuery" ); return status; } printf( "%s\n", header ); printCount = 0; k = 0; for ( i = 0; i < genQueryOut->rowCnt; i++ ) { for ( j = 1; j < genQueryOut->attriCnt; j++ ) { char *tResult; char *tResult2; tResult = genQueryOut->sqlResult[j].value; tResult += i * genQueryOut->sqlResult[j].len; if ( j == 1 ) { printf( "%s ", tResult ); k = strlen( tResult ); } if ( j == 2 ) { j++; tResult2 = genQueryOut->sqlResult[j].value; tResult2 += i * genQueryOut->sqlResult[j].len; if ( strncmp( tResult2, usersZone, NAME_LEN ) == 0 ) { printf( "%s", tResult ); k = strlen( tResult ); } else { printf( "%s#%s", tResult, tResult2 ); k = strlen( tResult ) + 1 + strlen( tResult2 ); } } if ( j == 4 ) { printNice( tResult, 14, "" ); k = strlen( tResult ); } if ( k < 14 ) { printf( "%s", pad[k] ); } printCount++; } printf( "\n" ); } const sqlResult_t *quota_usage_modify_time_result = getSqlResultByInx( genQueryOut, COL_QUOTA_USAGE_MODIFY_TIME ); if ( quota_usage_modify_time_result == NULL ) { printf( "Error getting quota usage modify times.\n" ); return SYS_NULL_INPUT; } long long localiTime = 0; for ( i = 0; i < genQueryOut->rowCnt; i++ ) { const char *tResult = quota_usage_modify_time_result->value + i * quota_usage_modify_time_result->len; const long long itime = atoll( tResult ); if ( itime > localiTime ) { localiTime = itime; getLocalTimeFromRodsTime( tResult, quotaTime ); } } return 0; }
/* Show user quota information */ int showQuotas( char *userName, int userOrGroup, int rescOrGlobal ) { genQueryInp_t genQueryInp; genQueryOut_t *genQueryOut; int inputInx[20]; int inputVal[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int inputCond[20]; char *condVal[10]; char v1[BIG_STR]; char v1b[BIG_STR]; char v2[BIG_STR]; char v3[BIG_STR]; int i, j, status; int localiTime = 0; int printCount; static int printedTime = 0; char *colName[10]; memset( &genQueryInp, 0, sizeof( genQueryInp_t ) ); printCount = 0; i = 0; if ( rescOrGlobal == 0 ) { colName[i] = "Resource: "; inputInx[i++] = COL_QUOTA_RESC_NAME; } else { colName[i] = "Resource: "; inputInx[i++] = COL_QUOTA_RESC_ID; } if ( userOrGroup == 0 ) { colName[i] = "User: "******"Group: "; } inputInx[i++] = COL_QUOTA_USER_NAME; colName[i] = "Zone: "; inputInx[i++] = COL_QUOTA_USER_ZONE; colName[i] = "Quota: "; inputInx[i++] = COL_QUOTA_LIMIT; colName[i] = "Over: "; inputInx[i++] = COL_QUOTA_OVER; colName[i] = "Time"; inputInx[i++] = COL_QUOTA_MODIFY_TIME; genQueryInp.selectInp.inx = inputInx; genQueryInp.selectInp.value = inputVal; genQueryInp.selectInp.len = i; char userName2[NAME_LEN]; char userZone[NAME_LEN]; genQueryInp.sqlCondInp.len = 0; if ( userName[0] != '\0' ) { status = parseUserName( userName, userName2, userZone ); if ( status < 0 ) { rodsLog( LOG_ERROR, "parseUserName error in showQuotas with status %d", status ); return status; } if ( userZone[0] == '\0' ) { inputCond[0] = COL_QUOTA_USER_NAME; sprintf( v1, "='%s'", userName ); condVal[0] = v1; genQueryInp.sqlCondInp.len++; } else { inputCond[0] = COL_QUOTA_USER_NAME; sprintf( v1, "='%s'", userName2 ); condVal[0] = v1; genQueryInp.sqlCondInp.len++; inputCond[1] = COL_QUOTA_USER_ZONE; sprintf( v1b, "='%s'", userZone ); condVal[1] = v1b; genQueryInp.sqlCondInp.len++; } } inputCond[genQueryInp.sqlCondInp.len] = COL_QUOTA_USER_TYPE; if ( userOrGroup == 0 ) { sprintf( v2, "!='%s'", "rodsgroup" ); } else { sprintf( v2, "='%s'", "rodsgroup" ); } condVal[genQueryInp.sqlCondInp.len] = v2; genQueryInp.sqlCondInp.len++; if ( rescOrGlobal == 1 ) { inputCond[genQueryInp.sqlCondInp.len] = COL_QUOTA_RESC_ID; sprintf( v3, "='%s'", "0" ); condVal[genQueryInp.sqlCondInp.len] = v3; genQueryInp.sqlCondInp.len++; } genQueryInp.sqlCondInp.inx = inputCond; genQueryInp.sqlCondInp.value = condVal; genQueryInp.condInput.len = 0; genQueryInp.maxRows = MAX_SQL_ROWS; genQueryInp.continueInx = 0; status = rcGenQuery( Conn, &genQueryInp, &genQueryOut ); if ( status == CAT_NO_ROWS_FOUND ) { printf( "None\n\n" ); return 0; } if ( status != 0 ) { printError( Conn, status, "rcGenQuery" ); return status; } if ( genQueryOut->rowCnt > 0 && printedTime == 0 ) { for ( i = 0; i < 1; i++ ) { for ( j = 0; j < genQueryOut->attriCnt; j++ ) { char *tResult; long itime; tResult = genQueryOut->sqlResult[j].value; tResult += i * genQueryOut->sqlResult[j].len; if ( j == 5 ) { itime = atoll( tResult ); if ( itime > localiTime ) { localiTime = itime; getLocalTimeFromRodsTime( tResult, quotaTime ); } } } } } printCount = 0; for ( i = 0; i < genQueryOut->rowCnt; i++ ) { for ( j = 0; j < genQueryOut->attriCnt; j++ ) { char *tResult; long itime; tResult = genQueryOut->sqlResult[j].value; tResult += i * genQueryOut->sqlResult[j].len; if ( j == 5 ) { itime = atoll( tResult ); if ( itime > localiTime ) { localiTime = itime; getLocalTimeFromRodsTime( tResult, quotaTime ); } } else { printf( " %s", colName[j] ); if ( rescOrGlobal == 1 && j == 0 ) { tResult = "All"; } if ( j == 4 || j == 3 ) { printNice( tResult, 0, "bytes" ); if ( strncmp( colName[j], "Over:", 5 ) == 0 ) { rodsLong_t ival; ival = atoll( tResult ); if ( ival > 0 ) { printf( " OVER QUOTA" ); } else { if ( ival > QUOTA_APPROACH_WARNING_SIZE ) { printf( " (Nearing quota)" ); } else { printf( " (under quota)" ); } } } printf( "\n" ); } else { printf( "%s\n", tResult ); } printCount++; } } printf( "\n" ); } return 0; }