uint32_t
DataObject::addHandshake(unsigned int def_hs )
{

	unsigned int handshake = def_hs;
	unsigned int ret = 0;

	/*
	 *  If we pass a value in ( other than 0 ), we set the handshake to that value
	 *  otherwise we generate a random one
	 */
	if ( handshake == 0 )
	{
		handshake = rand();
	}

	// set expiry in data structure, if it exists already it is updated
	VLOG(9) << "  from_iso_string: " << getNowStr();
	m_handshakeQueue[handshake]["expiry"] = getNowStr();

	// if we find said element again, return handshake, otherwise 0
	if ( m_handshakeQueue[handshake].find("expiry") != m_handshakeQueue[handshake].end() )
	{
		ret = handshake;
	}

	return ret;

}
Beispiel #2
0
/**
 * \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 );
}
Beispiel #3
0
/**
 * \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;
}
uint32_t
DataObject::createServerSessionListresp(std::string ip)
{
	std::list<std::string> ip_list;
	std::vector<std::string> ip_vec;

	/*
	 * zero out list
	 */
	ip_list.clear();
	ip_vec.clear();

	VLOG(9) << "createServerSessionListresp(" << ip << ")";
    VLOG(9) << "m_serverData(" << m_serverData.size() << ")";
	/*
	 * Check if cache exists ... if so erase it
	 */
	if ( m_serverListreq.find(ip) != m_serverListreq.end() )
	{
		VLOG(9) << "  m_serverListreq[" << ip << "] exists, erasing";
		m_serverListreq.erase(ip);
//		m_serverListreq[ip].clear();
	}

	/*
	 * TODO: this is where we can apply custom per-client sorting and
	 * filtering.  Perhaps maybe create a sort lambda ?
	 */
	for( auto& foo : m_serverData )
	{
		VLOG(9) << "    Temp Cache[" << ip << "] = " << foo.first;
		ip_list.push_back(foo.first);
	}

	/*
	 * Just put in the list to make preventing duplicates easier
	 */
	ip_list.unique();

	for( auto& bar: ip_list )
	{
		VLOG(9) << "    Packing vector (" << bar << ")";
		ip_vec.push_back(bar);
	}

	/*
	 *  Place list into cache
	 */
	m_serverListreq[ip] = ip_vec;
	m_listreqExpiry[ip] = getNowStr();

	return ip_vec.size();
}
bool DataObject::addClientSession( const std::string& sessionid )
{
	bool ret = false;
	/*
	 *  If the client session does not exist, create it, and add+uniq the listresp
	 */
	if ( ! keyExists<std::string>( m_clientData, sessionid ) )
	{
		addClientAttribute(sessionid,"ip",sessionid);
		ret = true;
	}

	/*
	 *  If a new structure, this will create the expiry, if existing it will just
	 *  refresh the timeout
	 */
	addClientAttribute(sessionid,"expiry", getNowStr() );

	return ret;
}
Beispiel #6
0
int 
cmlAudit2(int actionId, char *dataId, char *userName, char *zoneName, 
          char *accessLevel, icatSessionStruct *icss) 
{
   char myTime[50];
   char actionIdStr[50];
   int status;

   if (auditEnabled==0) return(0);

   if (logSQL_CML!=0) rodsLog(LOG_SQL, "cmlAudit2 SQL 1 ");

   getNowStr(myTime);

   snprintf(actionIdStr, sizeof actionIdStr, "%d", actionId);

   cllBindVars[0]=dataId;
   cllBindVars[1]=userName;
   cllBindVars[2]=zoneName;
   cllBindVars[3]=actionIdStr;
   cllBindVars[4]=accessLevel;
   cllBindVars[5]=myTime;
   cllBindVars[6]=myTime;
   cllBindVarCount=7;

   status = cmlExecuteNoAnswerSql(
				  "insert into R_OBJT_AUDIT (object_id, user_id, action_id, r_comment, create_ts, modify_ts) values (?, (select user_id from R_USER_MAIN where user_name=? and zone_name=?), ?, ?, ?, ?)", icss);
   if (status != 0) {
      rodsLog(LOG_NOTICE, "cmlAudit2 insert failure %d", status);
   }
#ifdef ORA_ICAT
#else
   else {
      cllCheckPending("",2,  icss->databaseType);
      /* Indicate that this was an audit SQL and so should be
	 committed on disconnect if still pending. */
   }
#endif

   return(status);
}
Beispiel #7
0
/* 
 Audit - record auditing information
 */
int
cmlAudit5(int actionId, char *objId, char *userId, char *comment, 
	    icatSessionStruct *icss)
{
   char myTime[50];
   char actionIdStr[50];
   int status;

   if (auditEnabled==0) return(0);

   getNowStr(myTime);

   snprintf(actionIdStr, sizeof actionIdStr, "%d", actionId);

   cllBindVars[0]=objId;
   cllBindVars[1]=userId;
   cllBindVars[2]=actionIdStr;
   cllBindVars[3]=comment;
   cllBindVars[4]=myTime;
   cllBindVars[5]=myTime;
   cllBindVarCount=6;

   status = cmlExecuteNoAnswerSql(
	  "insert into R_OBJT_AUDIT (object_id, user_id, action_id, r_comment, create_ts, modify_ts) values (?,?,?,?,?,?)",
	  icss);
   if (status != 0) {
      rodsLog(LOG_NOTICE, "cmlAudit5 insert failure %d", status);
   }
#ifdef ORA_ICAT
#else
   else {
      cllCheckPending("",2,  icss->databaseType);
      /* Indicate that this was an audit SQL and so should be
	 committed on disconnect if still pending. */
   }
#endif
   return(status);
}
bool
DataObject::addServerSession( const std::string& sessionid )
{

	bool ret = false;
	/*
	 *  If the server session does not exist, create it
	 */
	if ( ! keyExists<std::string>(m_serverData, sessionid) )
	{
		addServerAttribute(sessionid,"ip",sessionid);
		ret = true;
	}

	/*
	 *  If a new structure, this will create the expiry, if existing it will just
	 *  refresh the timeout
	 */
	addServerAttribute(sessionid,"expiry", getNowStr() );


	return ret;

}
Beispiel #9
0
/**
 * \fn msiGetFormattedSystemTime(msParam_t* outParam, msParam_t* inpParam,
 *          msParam_t* inpFormatParam, ruleExecInfo_t *rei)
 *
 * \brief Returns the local system time, formatted
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author  Romain Guinot
 * \date    2008
 *
 * \note Default output format is system time in seconds. Use 'human' as input
 *       parameter 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 (human)
 * \param[in] inpFormatParam - Optional - a STR_MS_T containing printf formatting (if inpParam was human)
 * \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
msiGetFormattedSystemTime( msParam_t* outParam, msParam_t* inpParam,
                           msParam_t* inpFormatParam, ruleExecInfo_t *rei ) {
    char *format;
    char *dateFormat;
    char tStr[TIME_LEN];
    time_t myTime;
    struct tm *mytm;
    int status;

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


    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR,
                 "msiGetFormattedSystemTime: input rei or rsComm is NULL" );
        return ( SYS_INTERNAL_NULL_INPUT_ERR );
    }
    format = ( char* )inpParam->inOutStruct;
    dateFormat = ( char* )inpFormatParam->inOutStruct;

    if ( !format || strcmp( format, "human" ) ) {
        getNowStr( tStr );
    }
    else {
        myTime = time( NULL );
        mytm = localtime( &myTime );

        snprintf( tStr, TIME_LEN, dateFormat,
                  mytm->tm_year + 1900, mytm->tm_mon + 1, mytm->tm_mday,
                  mytm->tm_hour, mytm->tm_min, mytm->tm_sec );
    }
    status = fillStrInMsParam( outParam, tStr );
    return( status );
}
Beispiel #10
0
int 
cmlAudit4(int actionId, char *sql, char *sqlParm, char *userName, 
	  char *zoneName, char *comment, icatSessionStruct *icss) 
{
   char myTime[50];
   char actionIdStr[50];
   char myComment[AUDIT_COMMENT_MAX_SIZE+10];
   char mySQL[MAX_SQL_SIZE];
   int status;
   int i;

   if (auditEnabled==0) return(0);

   getNowStr(myTime);

   snprintf(actionIdStr, sizeof actionIdStr, "%d", actionId);

   /* Truncate the comment if necessary (or else SQL will fail)*/
   myComment[AUDIT_COMMENT_MAX_SIZE-1]='\0';
   strncpy(myComment, comment, AUDIT_COMMENT_MAX_SIZE-1);

   if (zoneName[0]=='\0') {
      /* This no longer seems to occur.  I'm leaving the code in place
         (just in case) but I'm removing the rodsLog call so the ICAT
         test suite does not require it to be tested.
      */
      /*   
      if (logSQL_CML!=0) rodsLog(LOG_SQL, "cmlA---udit4 S--QL 1 ");
      */
      snprintf(mySQL, MAX_SQL_SIZE, 
	       "insert into R_OBJT_AUDIT (object_id, user_id, action_id, r_comment, create_ts, modify_ts) values ((%s), (select user_id from R_USER_MAIN where user_name=? and zone_name=(select zone_name from R_ZONE_MAIN where zone_type_name='local')), ?, ?, ?, ?)",
	       sql);
      i=0;
      if (sqlParm[0]!='\0') {
	 cllBindVars[i++]=sqlParm;
      }
      cllBindVars[i++]=userName;
      cllBindVars[i++]=actionIdStr;
      cllBindVars[i++]=myComment;
      cllBindVars[i++]=myTime;
      cllBindVars[i++]=myTime;
      cllBindVarCount=i;
      status = cmlExecuteNoAnswerSql(mySQL,icss);
   }
   else {
      if (logSQL_CML!=0) rodsLog(LOG_SQL, "cmlAudit4 SQL 2 ");
      snprintf(mySQL, MAX_SQL_SIZE, 
	       "insert into R_OBJT_AUDIT (object_id, user_id, action_id, r_comment, create_ts, modify_ts) values ((%s), (select user_id from R_USER_MAIN where user_name=? and zone_name=?), ?, ?, ?, ?)",
	       sql);
      i=0;
      if (sqlParm[0]!='\0') {
	 cllBindVars[i++]=sqlParm;
      }
      cllBindVars[i++]=userName;
      cllBindVars[i++]=zoneName;
      cllBindVars[i++]=actionIdStr;
      cllBindVars[i++]=myComment;
      cllBindVars[i++]=myTime;
      cllBindVars[i++]=myTime;
      cllBindVarCount=i;
      status = cmlExecuteNoAnswerSql(mySQL,icss);
   }

   if (status != 0) {
      rodsLog(LOG_NOTICE, "cmlAudit4 insert failure %d", status);
   }
#ifdef ORA_ICAT
#else
   else {
      cllCheckPending("",2,  icss->databaseType);
      /* Indicate that this was an audit SQL and so should be
	 committed on disconnect if still pending. */
   }
#endif

   return(status);
}
Beispiel #11
0
/* Check access via a Ticket to a data-object or collection */
int checkObjIdByTicket(char *dataId, char *accessLevel, 
			       char *ticketStr, char *ticketHost,
			       char *userName, char *userZone,
			      icatSessionStruct *icss) {
   int status, i;
   char *cVal[10];
   int iVal[10];
   char ticketId[NAME_LEN]="";
   char usesCount[NAME_LEN]="";
   char usesLimit[NAME_LEN]="";
   char ticketExpiry[NAME_LEN]="";
   char restrictions[NAME_LEN]="";
   char writeFileCount[NAME_LEN]="";
   char writeFileLimit[NAME_LEN]="";
   char writeByteCount[NAME_LEN]="";
   char writeByteLimit[NAME_LEN]="";
   int iUsesCount=0;
   int iUsesLimit=0;
   int iWriteFileCount=0;
   int iWriteFileLimit=0;
   int iWriteByteCount=0;
   int iWriteByteLimit=0;
   char myUsesCount[NAME_LEN];
   char myWriteFileCount[NAME_LEN];
   rodsLong_t intDataId;
   static rodsLong_t previousDataId1=0;
   static rodsLong_t previousDataId2=0;

   static char prevTicketId[50]="";

#if 0
   rodsLog(LOG_NOTICE, "checkObjIdByTicket debug dataId=%s accessLevel=%s", dataId, 
	   accessLevel);
#endif

   for (i=0;i<10;i++) { iVal[i]=NAME_LEN; }

   cVal[0]=ticketId;
   cVal[1]=usesLimit;
   cVal[2]=usesCount;
   cVal[3]=ticketExpiry;
   cVal[4]=restrictions;
   if (strncmp(accessLevel, "modify", 6) == 0) {
      if (logSQL_CML!=0) rodsLog(LOG_SQL, "checkObjIdByTicket SQL 1 ");
      /* ticket must also be of type 'write', and get the
          writeFileCount and writeFileLimit  */
      cVal[5]=writeFileCount;
      cVal[6]=writeFileLimit;
      cVal[7]=writeByteCount;
      cVal[8]=writeByteLimit;
      status = cmlGetStringValuesFromSql(
	    "select ticket_id, uses_limit, uses_count, ticket_expiry_ts, restrictions, write_file_count, write_file_limit, write_byte_count, write_byte_limit from R_TICKET_MAIN TM, R_DATA_MAIN DM where TM.ticket_type = 'write' and TM.ticket_string = ? and (TM.object_id=? or (TM.object_id=DM.coll_id and DM.data_id=?))",
	    cVal, iVal, 9, 
	    ticketStr, dataId, dataId, icss);

   }
   else {
      /* don't check ticket type, 'read' or 'write' is fine */
      if (logSQL_CML!=0) rodsLog(LOG_SQL, "checkObjIdByTicket SQL 2 ");
      status = cmlGetStringValuesFromSql(
	    "select ticket_id, uses_limit, uses_count, ticket_expiry_ts, restrictions from R_TICKET_MAIN TM, R_DATA_MAIN DM where TM.ticket_string = ? and (TM.object_id=? or (TM.object_id=DM.coll_id and DM.data_id=?))",
	    cVal, iVal, 5, 
	    ticketStr, dataId, dataId, icss);
   }

   if (status != 0) return (CAT_TICKET_INVALID);

   if (strncmp(ticketId, prevTicketId, sizeof(prevTicketId)) != 0) {
      strncpy(prevTicketId, ticketId, sizeof(prevTicketId));
      status = cmlAudit3(AU_USE_TICKET, ticketId, userName, userZone, 
			ticketStr, icss);
      if (status != 0) return(status);
   }

   if (ticketExpiry[0]!='\0') {
      rodsLong_t ticketExp, now;
      char myTime[50];

      ticketExp = atoll(ticketExpiry);
      if (ticketExp > 0) {
	 getNowStr(myTime);
	 now = atoll(myTime);
	 if (now > ticketExp) {
	    return(CAT_TICKET_EXPIRED);
	 }
      }
   }

   status = cmlCheckTicketRestrictions(ticketId, ticketHost, 
				       userName, userZone, icss);
   if (status != 0) return(status);

   if (strncmp(accessLevel, "modify", 6) == 0) {
      iWriteByteLimit = atoi(writeByteLimit);
      if (iWriteByteLimit > 0) {
	 iWriteByteCount = atoi(writeByteCount);
	 if (iWriteByteCount > iWriteByteLimit) {
	    return(CAT_TICKET_WRITE_BYTES_EXCEEDED);
	 }
      }

      iWriteFileLimit = atoi(writeFileLimit);
      if (iWriteFileLimit > 0) {
	 iWriteFileCount = atoi(writeFileCount);
	 if (iWriteFileCount >= iWriteFileLimit) {
	    return(CAT_TICKET_WRITE_USES_EXCEEDED);
	 }
         intDataId = atoll(dataId);
         /* Don't update a second time if this id matches the last one */
	 if (previousDataId1!=intDataId) {  
	    iWriteFileCount++;
	    snprintf(myWriteFileCount, sizeof myWriteFileCount, "%d", 
		     iWriteFileCount);
	    cllBindVars[cllBindVarCount++]=myWriteFileCount;
	    cllBindVars[cllBindVarCount++]=ticketId;
	    if (logSQL_CML!=0) rodsLog(LOG_SQL, "checkObjIdByTicket SQL 3 ");
	    status =  cmlExecuteNoAnswerSql(
	       "update R_TICKET_MAIN set write_file_count=? where ticket_id=?",
	       icss);
	    if (status != 0) return(status);
#ifndef ORA_ICAT
            /* as with auditing, do a commit on disconnect if needed */
	    cllCheckPending("",2, icss->databaseType); 
#endif
	 }
	 previousDataId1=intDataId;
      }
   }

   iUsesLimit = atoi(usesLimit);
   if (iUsesLimit > 0) {
      iUsesCount = atoi(usesCount);
      if (iUsesCount >= iUsesLimit) {
	 return(CAT_TICKET_USES_EXCEEDED);
      }
      intDataId = atoll(dataId);
      /* Don't update a second time if this id matches the last one */
      if (previousDataId2!=intDataId) {
	 iUsesCount++;
	 snprintf(myUsesCount, sizeof myUsesCount, "%d", iUsesCount);
	 cllBindVars[cllBindVarCount++]=myUsesCount;
	 cllBindVars[cllBindVarCount++]=ticketId;
	 if (logSQL_CML!=0) rodsLog(LOG_SQL, "checkObjIdByTicket SQL 4 ");
	 status =  cmlExecuteNoAnswerSql(
	    "update R_TICKET_MAIN set uses_count=? where ticket_id=?", icss);
	 if (status != 0) return(status);
#ifndef ORA_ICAT
	 /* as with auditing, do a commit on disconnect if needed*/
	 cllCheckPending("",2, icss->databaseType); 
#endif
      }
      previousDataId2=intDataId;
   }
   return(0);
}
Beispiel #12
0
/**
 * \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;
}
Beispiel #13
0
void
setNowTime() {
    getNowStr( nowTime );
    printf( "Current time as iRODS integer time: %s\n", nowTime );
}
std::string
DataObject::getServerExpiryIso(std::string& sessionid)
{

	const std::string etdef = "20000101T010000.000000";
	std::string et;
	if( m_serverData.find(sessionid) == m_serverData.end() )
	{
		/*
		 * We don't have a session
		 * Option 1: some list somewhere is iterating over the list and it's
		 *           removed ... very bad
		 * Option 2: expiry sub-map is empty ... which is not allowed
		 */
		VLOG(3) << "session(" << sessionid << ") does not exist for expiry request";
		et = getNowStr();
	}
	else
	{
		/*
		 * found session, check expiry
		 *
		 */
		if ( m_serverData[sessionid].find("expiry") != m_serverData[sessionid].end() )
		{
			et = m_serverData[sessionid]["expiry"];
		}
		else
		{
			VLOG(3) << "session(" << sessionid << ") does not contain expiry attribute";
			et = getNowStr();
		}
	}

	/*
	 * And just in case because we know for sure we can't have anything that
	 * is empty
	 */
	if ( et.length() == 0 || et == "" )
	{
		VLOG(3) << "session(" << sessionid << ") expiry time empty, defaulting:" << etdef;
		et = etdef;
	}

	/*
	 * Since it's so important to get the time, we can do a from_iso_string and
	 * if there is an issue here, there will definitely be an issue elsewhere,
	 * thus we can override that.
	 */
	try
	{
		boost::posix_time::ptime p = boost::posix_time::from_iso_string(et);
	}
	catch(const boost::exception& bex )
	{
		/*
		 * Whoops, date is malformed, we want to reset, unless
		 * the session is maybe on the way out in which case just
		 * let it be as it will disappear itself
		 */
		LOG(WARNING) << "expiry time for session(" << sessionid << ") seems bad, resetting: " << etdef;
		if ( m_serverData.find(sessionid) != m_serverData.end() )
		{
			/*
			 * TODO: rethink this
			 */
			m_serverData[sessionid]["expiry"] = etdef;
		}

	}

	return et;
}