int rcReconnect( rcComm_t **conn, char *newHost, rodsEnv *myEnv, int reconnFlag ) { int status; rcComm_t *newConn = NULL; rErrMsg_t errMsg; bzero( &errMsg, sizeof( errMsg ) ); newConn = rcConnect( newHost, myEnv->rodsPort, myEnv->rodsUserName, myEnv->rodsZone, reconnFlag, &errMsg ); if ( newConn != NULL ) { status = clientLogin( newConn ); if ( status != 0 ) { rcDisconnect( newConn ); return status; } rcDisconnect( *conn ); *conn = newConn; return 0; } else { return errMsg.status; } }
void choose_server(rcComm_t **cn, char *host, rodsEnv *env, int verb) { if (verb) { fprintf(stderr, "Chosen server is: %s\n", host); } if (host && strcmp(host, THIS_ADDRESS)) { int stat; rErrMsg_t err_msg; rcComm_t *new_cn = NULL; new_cn = rcConnect(host, env->rodsPort, env->rodsUserName, env->rodsZone, 0, &err_msg); if (!new_cn) { fprintf(stderr, "Error: rcReconnect failed with status %d. Continuing with original server.\n", err_msg.status); return; } #if IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4001008 stat = clientLogin(new_cn, "", ""); #else stat = clientLogin(new_cn); #endif if (stat < 0) { rcDisconnect(new_cn); error_and_exit(*cn, "Error: clientLogin failed with status %d:%s\n", stat, get_irods_error_name(stat, verb)); } else { rcDisconnect(*cn); *cn = new_cn; } } }
int main () { rodsEnv myEnv; int status = getRodsEnv( &myEnv ); if ( status != 0 ) { printf( "getRodsEnv failed.\n" ); return -1; } rErrMsg_t errMsg; rcComm_t* conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 1, &errMsg ); /* Test that irods errors are compile time constants in c */ switch (0) { case SYS_NO_HANDLER_REPLY_MSG: break; default: break; } if ( ! conn ) { printf( "rcConnect failed\n"); return -1; } else { printf( "Success!\n"); rcDisconnect( conn ); } return 0; }
int cleanUpAndExit() { sendXmsgInp_t sendXmsgInp; xmsgTicketInfo_t xmsgTicketInfo; int status; char buf[] = "QUIT"; memset( &xmsgTicketInfo, 0, sizeof( xmsgTicketInfo ) ); memset( &sendXmsgInp, 0, sizeof( sendXmsgInp ) ); xmsgTicketInfo.sendTicket = 4; xmsgTicketInfo.rcvTicket = 4; xmsgTicketInfo.flag = 1; sendXmsgInp.ticket = xmsgTicketInfo; snprintf( sendXmsgInp.sendAddr, NAME_LEN, "%s:%i", myHostName, getpid() ); sendXmsgInp.sendXmsgInfo.numRcv = 1; strcpy( sendXmsgInp.sendXmsgInfo.msgType, "QUIT" ); sendXmsgInp.sendXmsgInfo.msg = buf; sendXmsgInp.sendXmsgInfo.msgNumber = myMNum; sendXmsgInp.sendXmsgInfo.miscInfo = strdup( "ERASE_MESSAGE" ); status = rcSendXmsg( conn, &sendXmsgInp ); if ( status < 0 ) { fprintf( stderr, "rsSendXmsg error for 4. status = %d\n", status ); } sendIDebugCommand( "quit", "CMSG:QUIT" ); rcDisconnect( conn ); exit( 0 ); }
int ifuseConnect( iFuseConn_t *iFuseConn, rodsEnv *myRodsEnv ) { int status = 0; LOCK_STRUCT( *iFuseConn ); if ( iFuseConn->conn == NULL ) { rErrMsg_t errMsg; iFuseConn->conn = rcConnect( myRodsEnv->rodsHost, myRodsEnv->rodsPort, myRodsEnv->rodsUserName, myRodsEnv->rodsZone, NO_RECONN, &errMsg ); if ( iFuseConn->conn == NULL ) { /* try one more */ iFuseConn->conn = rcConnect( myRodsEnv->rodsHost, myRodsEnv->rodsPort, myRodsEnv->rodsUserName, myRodsEnv->rodsZone, NO_RECONN, &errMsg ); if ( iFuseConn->conn == NULL ) { rodsLogError( LOG_ERROR, errMsg.status, "ifuseConnect: rcConnect failure %s", errMsg.msg ); UNLOCK_STRUCT( *iFuseConn ); if ( errMsg.status < 0 ) { return errMsg.status; } else { return -1; } } } status = clientLogin( iFuseConn->conn ); if ( status != 0 ) { rcDisconnect( iFuseConn->conn ); iFuseConn->conn = NULL; } } UNLOCK_STRUCT( *iFuseConn ); return status; }
int RodsConnection::login() { int status = 0; // first of all, we must be connected if (!this->rodsCommPtr) return (status); // login only if not already logged in if (!this->isReady()) { this->mutexLock(); // try to authenticate client to the iRODS server if ((status = clientLogin (this->rodsCommPtr)) != 0) { rcDisconnect(this->rodsCommPtr); this->rodsCommPtr = NULL; } this->mutexUnlock(); } return (status); }
int disconnRcatHost( int rcatType, const char *rcatZoneHint ) { int status; rodsServerHost_t *rodsServerHost = NULL; status = getRcatHost( rcatType, rcatZoneHint, &rodsServerHost ); if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr return status; } if ( ( rodsServerHost )->localFlag == LOCAL_HOST ) { return LOCAL_HOST; } if ( rodsServerHost->conn != NULL ) { /* a connection exists */ status = rcDisconnect( rodsServerHost->conn ); rodsServerHost->conn = NULL; } if ( status >= 0 ) { return REMOTE_HOST; } else { return status; } }
int testLogin(rsComm_t *rsComm, char *User, char *pw, char *pw1) { int status, stat2; rcComm_t *Conn; rErrMsg_t errMsg; Conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 0, &errMsg); if (Conn == NULL) { printf("rcConnect failure"); return -1; } #if 0 Conn->clientUser.authInfo.authFlag = 0; Conn->proxyUser.authInfo.authFlag = LOCAL_PRIV_USER_AUTH; rstrcpy (Conn->clientUser.userName, privUser, NAME_LEN); #endif status = clientLoginWithPassword(Conn, pw1); /* first login as self */ if (status ==0) { rstrcpy (Conn->clientUser.userName, User, sizeof Conn->clientUser.userName); rstrcpy (Conn->clientUser.rodsZone, myEnv.rodsZone, sizeof Conn->clientUser.rodsZone); /* default to our zone */ status = clientLoginWithPassword(Conn, pw); /* then try other user */ } stat2 = rcDisconnect(Conn); return(status); }
int irodsexit(int exitValue) { int status; if (debug) printf("irodsexit: %d\n", exitValue); if (setupFlag>0) { status = rcDisconnect(Comm); } exit(exitValue); }
int irods_disconnect_() { int status; if ( debug ) { printf( "irods_disconnect_" ); } status = 0; if ( setupFlag > 0 ) { status = rcDisconnect( Comm ); } return status; }
void error_and_exit(rcComm_t *c, const char *msg, ...) { va_list argp; va_start(argp, msg); vfprintf(stderr, msg, argp); va_end(argp); if (c) { rcDisconnect(c); } exit(EXIT_FAILURE); }
static int connectToRemoteiRODS( char* inStr, rcComm_t** rcComm ) { rErrMsg_t errMsg; /*inStr of form: //irods:host[:port][:user[@zone][:pass]]/remotePath if port is not given default port 1247 is used if user@zone is not given ANONYMOUS_USER is used if pass is not given ANONYMOUS_USER is used */ const std::string input( inStr ); boost::smatch matches; boost::regex expression( "irods:([^:/]+)(:([0-9]+))?" // irods:host[:port] "(:([^:/@]+)(@([^:/]+))?(:([^/]+))?)?" // [:user[@zone][:pass]] "/(.*)" ); // /remotePath try { const bool matched = boost::regex_match( input, matches, expression ); if ( !matched ) { return USER_INPUT_FORMAT_ERR; } std::string host = matches.str( 1 ); int port = 1247; if ( !matches.str( 3 ).empty() ) { port = boost::lexical_cast<int>( matches.str( 3 ) ); } std::string user( ANONYMOUS_USER ); if ( !matches.str( 5 ).empty() ) { user = matches.str( 5 ); } std::string zone = matches.str( 7 ); printf( "MM: host=%s,port=%i,user=%s\n", host.c_str(), port, user.c_str() ); *rcComm = rcConnect( host.c_str(), port, user.c_str(), zone.c_str(), 0, &errMsg ); if ( *rcComm == NULL ) { return REMOTE_IRODS_CONNECT_ERR; } int status = clientLogin( *rcComm ); if ( status != 0 ) { rcDisconnect( *rcComm ); } return status; } catch ( const boost::bad_lexical_cast& ) { return INVALID_LEXICAL_CAST; } catch ( const boost::exception& ) { return SYS_INTERNAL_ERR; } }
int rsPamAuthRequest (rsComm_t *rsComm, pamAuthRequestInp_t *pamAuthRequestInp, pamAuthRequestOut_t **pamAuthRequestOut) { rodsServerHost_t *rodsServerHost; int status; status = getAndConnRcatHost(rsComm, MASTER_RCAT, rsComm->clientUser.rodsZone, &rodsServerHost); if (status < 0) { return(status); } if (rodsServerHost->localFlag == LOCAL_HOST) { #ifdef RODS_CAT status = _rsPamAuthRequest(rsComm, pamAuthRequestInp, pamAuthRequestOut); #else status = SYS_NO_RCAT_SERVER_ERR; #endif } else { #ifdef USE_SSL /* protect the PAM plain text password by using an SSL connection to the remote ICAT */ status = sslStart(rodsServerHost->conn); if (status) { rodsLog(LOG_NOTICE, "rsPamAuthRequest: could not establish SSL connection, status %d", status); return(status); } #else rodsLog(LOG_ERROR, "iRODS doesn't include SSL support, required for PAM authentication."); return SSL_NOT_BUILT_INTO_SERVER; #endif /* USE_SSL */ status = rcPamAuthRequest(rodsServerHost->conn, pamAuthRequestInp, pamAuthRequestOut); #ifdef USE_SSL sslEnd(rodsServerHost->conn); #endif rcDisconnect(rodsServerHost->conn); rodsServerHost->conn = NULL; if (status < 0) { rodsLog(LOG_NOTICE, "rsPamAuthRequest: rcPamAuthRequest to remote server failed, status %d", status); } } return (status); }
static int irods_init() { kstring_t useragent = { 0, 0, NULL }; struct sigaction pipehandler; rErrMsg_t err; int ret, pipehandler_ret; if (hts_verbose >= 5) rodsLogLevel(hts_verbose); ret = getRodsEnv(&irods.env); if (ret < 0) goto error; // Set iRODS User-Agent, if our caller hasn't already done so. kputs("htslib/", &useragent); kputs(hts_version(), &useragent); (void) setenv(SP_OPTION, useragent.s, 0); free(useragent.s); // Prior to iRODS 4.1, rcConnect() (even if it fails) installs its own // SIGPIPE handler, which just prints a message and otherwise ignores the // signal. Most actual SIGPIPEs encountered will pertain to e.g. stdout // rather than iRODS's connection, so we save and restore the existing // state (by default, termination; or as already set by our caller). pipehandler_ret = sigaction(SIGPIPE, NULL, &pipehandler); irods.conn = rcConnect(irods.env.rodsHost, irods.env.rodsPort, irods.env.rodsUserName, irods.env.rodsZone, NO_RECONN, &err); if (pipehandler_ret == 0) sigaction(SIGPIPE, &pipehandler, NULL); if (irods.conn == NULL) { ret = err.status; goto error; } if (strcmp(irods.env.rodsUserName, PUBLIC_USER_NAME) != 0) { #if defined IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4000000 ret = clientLogin(irods.conn, NULL, NULL); #else ret = clientLogin(irods.conn); #endif if (ret != 0) goto error; } return 0; error: if (irods.conn) { (void) rcDisconnect(irods.conn); } irods.conn = NULL; set_errno(ret); return -1; }
int disconnectAllSvrToSvrConn() { rodsServerHost_t *tmpRodsServerHost; /* check if host exist */ tmpRodsServerHost = ServerHostHead; while ( tmpRodsServerHost != NULL ) { if ( tmpRodsServerHost->conn != NULL ) { rcDisconnect( tmpRodsServerHost->conn ); tmpRodsServerHost->conn = NULL; } tmpRodsServerHost = tmpRodsServerHost->next; } return 0; }
/* Check if there is a connected ICAT host, and if there is, disconnect */ int getAndDisconnRcatHost( int rcatType, char *rcatZoneHint, rodsServerHost_t **rodsServerHost ) { int status; status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost ); if ( status < 0 ) { return status; } if ( ( *rodsServerHost )->conn != NULL ) { /* a connection exists */ status = rcDisconnect( ( *rodsServerHost )->conn ); return status; } return 0; }
int rsPamAuthRequest( rsComm_t *rsComm, pamAuthRequestInp_t *pamAuthRequestInp, pamAuthRequestOut_t **pamAuthRequestOut ) { rodsServerHost_t *rodsServerHost; int status; status = getAndConnRcatHost( rsComm, MASTER_RCAT, (const char*)rsComm->clientUser.rodsZone, &rodsServerHost ); if ( status < 0 ) { return status; } if ( rodsServerHost->localFlag == LOCAL_HOST ) { #ifdef RODS_CAT status = _rsPamAuthRequest( rsComm, pamAuthRequestInp, pamAuthRequestOut ); #else status = SYS_NO_RCAT_SERVER_ERR; #endif } else { /* protect the PAM plain text password by using an SSL connection to the remote ICAT */ status = sslStart( rodsServerHost->conn ); if ( status ) { rodsLog( LOG_NOTICE, "rsPamAuthRequest: could not establish SSL connection, status %d", status ); return status; } status = rcPamAuthRequest( rodsServerHost->conn, pamAuthRequestInp, pamAuthRequestOut ); sslEnd( rodsServerHost->conn ); rcDisconnect( rodsServerHost->conn ); rodsServerHost->conn = NULL; if ( status < 0 ) { rodsLog( LOG_NOTICE, "rsPamAuthRequest: rcPamAuthRequest to remote server failed, status %d", status ); } } return status; }
int RodsConnection::disconnect() { int status = 0; // only if there is a connection (conn pointer set) if (this->rodsCommPtr) { this->mutexLock(); // do rods api disconnect and set comm ptr to null status = rcDisconnect(this->rodsCommPtr); this->rodsCommPtr = NULL; this->mutexUnlock(); } // return rods api status return (status); }
int main () { rodsEnv myEnv; int status = getRodsEnv( &myEnv ); if ( status != 0 ) { printf( "getRodsEnv failed.\n" ); return -1; } rErrMsg_t errMsg; rcComm_t* conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 1, &errMsg ); if ( ! conn ) { printf( "rcConnect failed\n"); return -1; } else { printf( "Success!\n"); rcDisconnect( conn ); } return 0; }
int connectToX() { int status; int sleepSec = 1; if ( conn != NULL ) { return 0; } status = getRodsEnv( &myRodsEnv ); if ( status < 0 ) { fprintf( stderr, "getRodsEnv error, status = %d\n", status ); exit( 1 ); } while ( conn == NULL ) { conn = rcConnectXmsg( &myRodsEnv, &errMsg ); if ( conn == NULL ) { fprintf( stderr, "rcConnectXmsg error...Will try again\n" ); sleep( sleepSec ); sleepSec = 2 * sleepSec; if ( sleepSec > 10 ) { sleepSec = 10; } continue; } status = clientLogin( conn ); if ( status != 0 ) { rcDisconnect( conn ); conn = NULL; fprintf( stderr, "clientLogin error...Will try again\n" ); sleep( sleepSec ); sleepSec = 2 * sleepSec; if ( sleepSec > 10 ) { sleepSec = 10; } continue; } } return 0; }
int sendIxmsg( rcComm_t **inconn, sendXmsgInp_t *sendXmsgInp){ int status; int sleepSec = 1; rcComm_t *conn; conn = *inconn; while (connectFlag == 0) { conn = rcConnectXmsg (&myRodsEnv, &errMsg); if (conn == NULL) { sleep(sleepSec); sleepSec = 2 * sleepSec; if (sleepSec > 10) sleepSec = 10; continue; } status = clientLogin(conn); if (status != 0) { rcDisconnect(conn); fprintf (stderr, "clientLogin error...Will try again\n"); sleep(sleepSec); sleepSec = 2 * sleepSec; if (sleepSec > 10) sleepSec = 10; continue; } *inconn = conn; connectFlag = 1; } status = rcSendXmsg (conn, sendXmsgInp); /* rcDisconnect(conn); **/ if (status < 0) { fprintf (stderr, "rsSendXmsg error. status = %d\n", status); exit (9); } return(status); }
int main( int, char** ) { signal( SIGPIPE, SIG_IGN ); rodsEnv myEnv; int status = getRodsEnv( &myEnv ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "main: getRodsEnv error. " ); exit( 1 ); } rErrMsg_t errMsg; rcComm_t *conn; conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 0, &errMsg ); if ( conn == NULL ) { exit( 2 ); } // =-=-=-=-=-=-=- // initialize pluggable api table irods::pack_entry_table& pk_tbl = irods::get_pack_table(); irods::api_entry_table& api_tbl = irods::get_client_api_table(); init_api_table( api_tbl, pk_tbl ); if ( strcmp( myEnv.rodsUserName, PUBLIC_USER_NAME ) != 0 ) { status = clientLogin( conn ); if ( status != 0 ) { rcDisconnect( conn ); exit( 7 ); } } helloInp_t inp; memset( &inp, 0, sizeof( inp ) ); inp._this = 42; strncpy( inp._that, "hello, world.", 64 ); void *tmp_out = NULL; status = procApiRequest( conn, 1300, &inp, NULL, &tmp_out, NULL ); if ( status < 0 ) { printf( "\n\nERROR - failed to call our api\n\n\n" ); return 0; } else { helloOut_t* out = static_cast<helloOut_t*>( tmp_out ); if ( out != NULL ) { printf( "\n\nthis [%d] that [%s] other [%f]\n", out->_this, out->_that, out->_other._value ); } else { printf( "ERROR: the 'out' variable is null\n" ); } } rcDisconnect( conn ); }
int main(int argc, char **argv) { int status, i, j; rErrMsg_t errMsg; rodsEnv myEnv; rodsArguments_t myRodsArgs; char *mySubName; char *myName; int argOffset; int maxCmdTokens=20; char *cmdToken[20]; int keepGoing; int firstTime; rodsLogLevel(LOG_ERROR); status = parseCmdLineOpt (argc, argv, "vVh", 0, &myRodsArgs); if (status) { printf("Use -h for help.\n"); exit(1); } if (myRodsArgs.help==True) { usage(""); exit(0); } argOffset = myRodsArgs.optind; status = getRodsEnv (&myEnv); if (status < 0) { rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d", status); exit (1); } strncpy(myZone, myEnv.rodsZone, sizeof(myZone)); for (i=0;i<maxCmdTokens;i++) { cmdToken[i]=""; } j=0; for (i=argOffset;i<argc;i++) { cmdToken[j++]=argv[i]; } if (strcmp(cmdToken[0],"help")==0 || strcmp(cmdToken[0],"h") == 0) { usage(cmdToken[1]); exit(0); } if (strcmp(cmdToken[0],"spass") ==0) { char scrambled[MAX_PASSWORD_LEN+100]; if (strlen(cmdToken[1])>MAX_PASSWORD_LEN-2) { printf("Password exceeds maximum length\n"); } else { obfEncodeByKey(cmdToken[1], cmdToken[2], scrambled); printf("Scrambled form is:%s\n", scrambled); } exit(0); } Conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 0, &errMsg); if (Conn == NULL) { myName = rodsErrorName(errMsg.status, &mySubName); rodsLog(LOG_ERROR, "rcConnect failure %s (%s) (%d) %s", myName, mySubName, errMsg.status, errMsg.msg); exit (2); } status = clientLogin(Conn); if (status != 0) { rcDisconnect(Conn); exit (3); } keepGoing=1; firstTime=1; while (keepGoing) { int status; status=doCommand(cmdToken); if (status==-1) keepGoing=0; if (firstTime) { if (status==0) keepGoing=0; if (status==-2) { keepGoing=0; lastCommandStatus=-1; } firstTime=0; } if (keepGoing) { getInput(cmdToken, maxCmdTokens); } } printErrorStack(Conn->rError); rcDisconnect(Conn); if (lastCommandStatus != 0) exit(4); exit(0); }
/* Prompt for input and parse into tokens */ void getInput(char *cmdToken[], int maxTokens) { int lenstr, i; static char ttybuf[500]; int nTokens; int tokenFlag; /* 1: start reg, 2: start ", 3: start ' */ char *cpTokenStart; char *stat; memset(ttybuf, 0, sizeof(ttybuf)); fputs("groupadmin>",stdout); stat = fgets(ttybuf, sizeof(ttybuf), stdin); if (stat==0) { printf("\n"); rcDisconnect(Conn); if (lastCommandStatus != 0) exit(4); exit(0); } lenstr=strlen(ttybuf); for (i=0;i<maxTokens;i++) { cmdToken[i]=""; } cpTokenStart = ttybuf; nTokens=0; tokenFlag=0; for (i=0;i<lenstr;i++) { if (ttybuf[i]=='\n') { ttybuf[i]='\0'; cmdToken[nTokens++]=cpTokenStart; return; } if (tokenFlag==0) { if (ttybuf[i]=='\'') { tokenFlag=3; cpTokenStart++; } else if (ttybuf[i]=='"') { tokenFlag=2; cpTokenStart++; } else if (ttybuf[i]==' ') { cpTokenStart++; } else { tokenFlag=1; } } else if (tokenFlag == 1) { if (ttybuf[i]==' ') { ttybuf[i]='\0'; cmdToken[nTokens++]=cpTokenStart; cpTokenStart = &ttybuf[i+1]; tokenFlag=0; } } else if (tokenFlag == 2) { if (ttybuf[i]=='"') { ttybuf[i]='\0'; cmdToken[nTokens++]=cpTokenStart; cpTokenStart = &ttybuf[i+1]; tokenFlag=0; } } else if (tokenFlag == 3) { if (ttybuf[i]=='\'') { ttybuf[i]='\0'; cmdToken[nTokens++]=cpTokenStart; cpTokenStart = &ttybuf[i+1]; tokenFlag=0; } } } }
int main( int argc, char **argv ) { rcComm_t *conn; rodsEnv myEnv; char *optStr; rErrMsg_t errMsg; int status; rodsArguments_t rodsArgs; int flag = 0; int nativeAPI = 0; optStr = "alL"; status = parseCmdLineOpt( argc, argv, optStr, 1, &rodsArgs ); if ( status < 0 ) { printf( "parseCmdLineOpt error, status = %d.\n", status ); exit( 1 ); } if ( argc - optind <= 0 ) { rodsLog( LOG_ERROR, "no input" ); exit( 2 ); } memset( &errMsg, 0, sizeof( rErrMsg_t ) ); status = getRodsEnv( &myEnv ); if ( status < 0 ) { fprintf( stderr, "getRodsEnv error, status = %d\n", status ); exit( 1 ); } conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 1, &errMsg ); if ( conn == NULL ) { fprintf( stderr, "rcConnect error\n" ); exit( 1 ); } status = clientLogin( conn ); if ( status != 0 ) { rcDisconnect( conn ); exit( 7 ); } flag = setQueryFlag( &rodsArgs ); if ( rodsArgs.all == True ) { nativeAPI = 1; } if ( nativeAPI == 1 ) { status = printCollectionNat( conn, argv[optind], flag ); } else { status = printCollection( conn, argv[optind], flag ); } rcDisconnect( conn ); exit( 0 ); }
static int _download(const char *path, struct stat *stbufIn) { int status; rcComm_t *conn; rodsPathInp_t rodsPathInp; rErrMsg_t errMsg; char preloadCachePath[MAX_NAME_LEN]; char preloadCacheWorkPath[MAX_NAME_LEN]; // set path for getUtil status = _getCachePath(path, preloadCachePath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _getCachePath error."); rodsLog (LOG_ERROR, "_download: failed to get cache path - %s", path); return status; } status = _getCacheWorkPath(path, preloadCacheWorkPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _getCacheWorkPath error."); rodsLog (LOG_ERROR, "_download: failed to get cache work path - %s", path); return status; } rodsLog (LOG_DEBUG, "_download: download %s to %s", path, preloadCachePath); // set src path memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) ); addSrcInPath( &rodsPathInp, (char*)path ); status = parseRodsPath (&rodsPathInp.srcPath[0], PreloadRodsEnv); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: parseRodsPath error."); return status; } // set dest path rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) ); rstrcpy( rodsPathInp.destPath->inPath, preloadCacheWorkPath, MAX_NAME_LEN ); status = parseLocalPath (rodsPathInp.destPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: parseLocalPath error."); return status; } // Connect conn = rcConnect (PreloadRodsEnv->rodsHost, PreloadRodsEnv->rodsPort, PreloadRodsEnv->rodsUserName, PreloadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg); if (conn == NULL) { rodsLog (LOG_ERROR, "_download: error occurred while connecting to irods"); return -EPIPE; } // Login if (strcmp (PreloadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { status = clientLogin(conn); if (status != 0) { rodsLogError(LOG_ERROR, status, "_download: ClientLogin error."); rcDisconnect(conn); return status; } } // make dir prepareDir(preloadCachePath); // Preload rodsLog (LOG_DEBUG, "_download: download %s", path); status = getUtil (&conn, PreloadRodsEnv, PreloadRodsArgs, &rodsPathInp); rodsLog (LOG_DEBUG, "_download: complete downloading %s", path); // Disconnect rcDisconnect(conn); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: getUtil error."); return status; } // be careful when using Lock LOCK(PreloadLock); status = _completeDownload(preloadCacheWorkPath, preloadCachePath, stbufIn); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _completeDownload error."); UNLOCK(PreloadLock); return status; } UNLOCK(PreloadLock); return 0; }
int do_modify_permissions(FILE *input, recursive_op recurse, option_flags oflags) { int item_count = 0; int error_count = 0; rodsEnv env; rcComm_t *conn = rods_login(&env); if (!conn) goto error; while (!feof(input)) { size_t flags = JSON_DISABLE_EOF_CHECK | JSON_REJECT_DUPLICATES; json_error_t load_error; json_t *target = json_loadf(input, flags, &load_error); if (!target) { if (!feof(input)) { logmsg(ERROR, "JSON error at line %d, column %d: %s", load_error.line, load_error.column, load_error.text); } continue; } item_count++; if (!json_is_object(target)) { logmsg(ERROR, "Item %d in stream was not a JSON object; skipping", item_count); error_count++; json_decref(target); continue; } baton_error_t path_error; char *path = json_to_path(target, &path_error); if (add_error_report(target, &path_error)) { error_count++; } else { json_t *perms = json_object_get(target, JSON_ACCESS_KEY); if (!json_is_array(perms)) { error_count++; set_baton_error(&path_error, -1, "Permissions data for %s is not in " "a JSON array", path); add_error_report(target, &path_error); } else { rodsPath_t rods_path; resolve_rods_path(conn, &env, &rods_path, path, oflags, &path_error); if (add_error_report(target, &path_error)) { error_count++; } else { for (size_t i = 0; i < json_array_size(perms); i++) { json_t *perm = json_array_get(perms, i); baton_error_t mod_error; modify_json_permissions(conn, &rods_path, recurse, perm, &mod_error); if (add_error_report(target, &mod_error)) { error_count++; } } if (rods_path.rodsObjStat) free(rods_path.rodsObjStat); } } } print_json(target); if (unbuffered_flag) fflush(stdout); json_decref(target); if (path) free(path); } // while rcDisconnect(conn); if (error_count > 0) { logmsg(WARN, "Processed %d items with %d errors", item_count, error_count); } else { logmsg(DEBUG, "Processed %d items with %d errors", item_count, error_count); } return error_count; error: if (conn) rcDisconnect(conn); logmsg(ERROR, "Processed %d items with %d errors", item_count, error_count); return 1; }
void _ifuseDisconnect( iFuseConn_t *tmpIFuseConn ) { if ( tmpIFuseConn->conn != NULL ) { rcDisconnect( tmpIFuseConn->conn ); tmpIFuseConn->conn = NULL; } }
int main( int argc, char **argv ) { signal( SIGPIPE, SIG_IGN ); int status; rErrMsg_t errMsg; rodsArguments_t myRodsArgs; rodsEnv myEnv; rodsLogLevel( LOG_ERROR ); status = parseCmdLineOpt( argc, argv, "hvVlz:Z", 1, &myRodsArgs ); if ( status ) { printf( "Use -h for help.\n" ); exit( 1 ); } if ( myRodsArgs.help == True ) { usage(); exit( 0 ); } if ( myRodsArgs.zone == True ) { strncpy( zoneArgument, myRodsArgs.zoneName, MAX_NAME_LEN ); } status = getRodsEnv( &myEnv ); if ( status < 0 ) { rodsLog( LOG_ERROR, "main: getRodsEnv error. status = %d", status ); exit( 1 ); } // =-=-=-=-=-=-=- // initialize pluggable api table irods::pack_entry_table& pk_tbl = irods::get_pack_table(); irods::api_entry_table& api_tbl = irods::get_client_api_table(); init_api_table( api_tbl, pk_tbl ); Conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 0, &errMsg ); if ( Conn == NULL ) { char *mySubName = NULL; const char *myName = rodsErrorName( errMsg.status, &mySubName ); rodsLog( LOG_ERROR, "rcConnect failure %s (%s) (%d) %s", myName, mySubName, errMsg.status, errMsg.msg ); free( mySubName ); exit( 2 ); } status = clientLogin( Conn ); if ( status != 0 ) { exit( 3 ); } // tree view if ( myRodsArgs.longOption != True ) { if ( myRodsArgs.ascii == True ) { // character set for printing tree gfx_mode = 0; } status = showRescTree( argv[myRodsArgs.optind] ); } else { // regular view status = showResc( argv[myRodsArgs.optind], myRodsArgs.longOption ); } printErrorStack( Conn->rError ); rcDisconnect( Conn ); /* Exit 0 if one or more items were displayed */ if ( status >= 0 ) { return 0; } else { return status; } }
int main( int argc, char **argv ) { int status, i, j; rErrMsg_t errMsg; rodsArguments_t myRodsArgs; char *mySubName; char *myName; int argOffset; int maxCmdTokens = 20; char *cmdToken[20]; int keepGoing; int firstTime; rodsLogLevel( LOG_ERROR ); status = parseCmdLineOpt( argc, argv, "vVhgrcGRCdulz:", 0, &myRodsArgs ); if ( status ) { printf( "Use -h for help.\n" ); exit( 1 ); } if ( myRodsArgs.help == True ) { usage( "" ); exit( 0 ); } if ( myRodsArgs.zone == True ) { strncpy( zoneArgument, myRodsArgs.zoneName, MAX_NAME_LEN ); } if ( myRodsArgs.longOption ) { longMode = 1; } argOffset = myRodsArgs.optind; if ( argOffset > 1 ) { if ( argOffset > 2 ) { if ( *argv[1] == '-' && *( argv[1] + 1 ) == 'z' ) { if ( *( argv[1] + 2 ) == '\0' ) { argOffset = 3; /* skip -z zone */ } else { argOffset = 2; /* skip -zzone */ } } else { argOffset = 1; /* Ignore the parseCmdLineOpt parsing as -d etc handled below*/ } } else { argOffset = 1; /* Ignore the parseCmdLineOpt parsing as -d etc handled below*/ } } status = getRodsEnv( &myEnv ); if ( status < 0 ) { rodsLog( LOG_ERROR, "main: getRodsEnv error. status = %d", status ); exit( 1 ); } strncpy( cwd, myEnv.rodsCwd, BIG_STR ); if ( strlen( cwd ) == 0 ) { strcpy( cwd, "/" ); } for ( i = 0; i < maxCmdTokens; i++ ) { cmdToken[i] = ""; } j = 0; for ( i = argOffset; i < argc; i++ ) { cmdToken[j++] = argv[i]; } #if defined(linux_platform) /* imeta cp -d TestFile1 -d TestFile3 comes in as: -d -d cp TestFile1 TestFile3 so switch it to: cp -d -d TestFile1 TestFile3 */ if ( cmdToken[0] != NULL && *cmdToken[0] == '-' ) { /* args were toggled, switch them back */ if ( cmdToken[1] != NULL && *cmdToken[1] == '-' ) { cmdToken[0] = argv[argOffset + 2]; cmdToken[1] = argv[argOffset]; cmdToken[2] = argv[argOffset + 1]; } else { cmdToken[0] = argv[argOffset + 1]; cmdToken[1] = argv[argOffset]; } } #else /* tested on Solaris, not sure other than Linux/Solaris */ /* imeta cp -d TestFile1 -d TestFile3 comes in as: cp -d TestFile1 -d TestFile3 so switch it to: cp -d -d TestFile1 TestFile3 */ if ( cmdToken[0] != NULL && cmdToken[1] != NULL && *cmdToken[1] == '-' && cmdToken[2] != NULL && cmdToken[3] != NULL && *cmdToken[3] == '-' ) { /* two args */ cmdToken[2] = argv[argOffset + 3]; cmdToken[3] = argv[argOffset + 2]; } #endif if ( strcmp( cmdToken[0], "help" ) == 0 || strcmp( cmdToken[0], "h" ) == 0 ) { usage( cmdToken[1] ); exit( 0 ); } if ( strcmp( cmdToken[0], "spass" ) == 0 ) { char scrambled[MAX_PASSWORD_LEN + 100]; if ( strlen( cmdToken[1] ) > MAX_PASSWORD_LEN - 2 ) { printf( "Password exceeds maximum length\n" ); } else { obfEncodeByKey( cmdToken[1], cmdToken[2], scrambled ); printf( "Scrambled form is:%s\n", scrambled ); } exit( 0 ); } // =-=-=-=-=-=-=- // initialize pluggable api table irods::api_entry_table& api_tbl = irods::get_client_api_table(); irods::pack_entry_table& pk_tbl = irods::get_pack_table(); init_api_table( api_tbl, pk_tbl ); Conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName, myEnv.rodsZone, 0, &errMsg ); if ( Conn == NULL ) { myName = rodsErrorName( errMsg.status, &mySubName ); rodsLog( LOG_ERROR, "rcConnect failure %s (%s) (%d) %s", myName, mySubName, errMsg.status, errMsg.msg ); exit( 2 ); } status = clientLogin( Conn ); if ( status != 0 ) { if ( !debug ) { exit( 3 ); } } keepGoing = 1; firstTime = 1; while ( keepGoing ) { int status; status = doCommand( cmdToken ); if ( status == -1 ) { keepGoing = 0; } if ( firstTime ) { if ( status == 0 ) { keepGoing = 0; } if ( status == -2 ) { keepGoing = 0; lastCommandStatus = -1; } firstTime = 0; } if ( keepGoing ) { getInput( cmdToken, maxCmdTokens ); } } printErrorStack( Conn->rError ); rcDisconnect( Conn ); if ( lastCommandStatus != 0 ) { exit( 4 ); } exit( 0 ); }