Esempio n. 1
0
/// =-=-=-=-=-=-=-
/// @brief function which determines if a client/server negotiation is needed
///        on the client side
    bool do_client_server_negotiation_for_client( ) {
        // =-=-=-=-=-=-=-
        // get the irods environment so we can compare the
        // flag for negotiation of policy
        rodsEnv rods_env;
        int status = getRodsEnv( &rods_env );
        if ( status < 0 ) {
            return false;
        }

        // =-=-=-=-=-=-=-
        // if it is not set then move on
        std::string neg_policy( rods_env.rodsClientServerNegotiation );
        if ( neg_policy.empty() ) {
            return false;
        }

        // =-=-=-=-=-=-=-
        // if it is set then check for our magic token which requests
        // the negotiation, if its not there then return success
        if ( std::string::npos == neg_policy.find( REQ_SVR_NEG ) ) {
            return false;
        }

        // =-=-=-=-=-=-=-
        // otherwise, its a failure.
        return true;

    } // do_client_server_negotiation_for_client
Esempio n. 2
0
int
isioSetup() {
   int status;
   rErrMsg_t errMsg;
   char *mySubName;
   char *myName;

   if (debug) printf("isioSetup\n");

   status = getRodsEnv (&myRodsEnv);
   if (status < 0) {
      rodsLogError(LOG_ERROR, status, "isioSetup: getRodsEnv error.");
   }
   Comm = rcConnect (myRodsEnv.rodsHost, myRodsEnv.rodsPort, 
		     myRodsEnv.rodsUserName,
                     myRodsEnv.rodsZone, 0, &errMsg);

   if (Comm == NULL) {
      myName = rodsErrorName(errMsg.status, &mySubName);
      rodsLog(LOG_ERROR, "rcConnect failure %s (%s) (%d) %s",
	      myName,
	      mySubName,
	      errMsg.status,
	      errMsg.msg);
      status = errMsg.status;
      return(status);
   }

   status = clientLogin(Comm);
   if (status==0) {
      setupFlag=1;
   }
   return(status);
}
int RodsConnection::connect()
{
    int status = 0;

    // if we are already connected, nothing to be done
    if (this->rodsCommPtr)
        return (status);

    this->mutexLock();

    // get user iRODS environment
    if ((status = getRodsEnv(&this->rodsUserEnv)) < 0)
        return (status);

    // rods api connect
    if ((rodsCommPtr = rcConnect(this->rodsUserEnv.rodsHost, this->rodsUserEnv.rodsPort,
                                this->rodsUserEnv.rodsUserName, this->rodsUserEnv.rodsZone,
                                 0, &this->lastErrMsg)) == NULL)
    {
        this->mutexUnlock();
        return(-1);
    }

    this->mutexUnlock();
    return (status);
}
Esempio n. 4
0
File: test.c Progetto: 0x414A/irods
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;
}
Esempio n. 5
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;

    status = parseCmdLineOpt( argc, argv, "vVh", 0, &myRodsArgs );
    if ( status ) {
        printf( "Use -h for help\n" );
        exit( 1 );
    }

    if ( myRodsArgs.help == True ) {
        usage( argv[0] );
        exit( 0 );
    }

    status = getRodsEnv( &myEnv );
    if ( status != 0 ) {
        printf( "Failed with error %d\n", status );
        exit( 2 );
    }

    printf( "%s\n", myEnv.rodsCwd );

    exit( 0 );
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
int
main( int argc, char **argv ) {
    int status, ix;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;
    char *envFile;

    status = parseCmdLineOpt( argc, argv, "Vvh", 0, &myRodsArgs );
    if ( status ) {
        printf( "Use -h for help\n" );
        exit( 1 );
    }
    if ( myRodsArgs.help == True ) {
        usage( argv[0] );
        exit( 0 );
    }
    ix = myRodsArgs.optind;

    status = getRodsEnv( &myEnv );

    envFile = getRodsEnvFileName();
    status = unlink( envFile );
    if ( myRodsArgs.verbose == True ) {
        printf( "Deleting (if it exists) session envFile:%s\n", envFile );
        printf( "unlink status = %d\n", status );
    }

    if ( ix < argc ) {
        if ( strcmp( argv[ix], "full" ) == 0 ) {
            if ( myRodsArgs.verbose == True ) {
                obfRmPw( 0 );
            }
            else {
                obfRmPw( 1 );
            }
        }
        else {
            printf( "option %s is unrecognized\n", argv[ix] );
        }
    }

    exit( 0 );
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
File: idbug.cpp Progetto: bpow/irods
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;
}
Esempio n. 10
0
	int icommands::irm(int argc, char **argv) {
		int status;
		rodsEnv myEnv;
		rErrMsg_t errMsg;
		rcComm_t *conn;
		rodsArguments_t myRodsArgs;
		char *optStr;
		rodsPathInp_t rodsPathInp;


		optStr = "hfruUvVfn:";

		status = parseCmdLineOpt (argc, argv, optStr, 0, &myRodsArgs);
		if (status < 0) {
			printf("Use -h for help.\n");
			exit (1);
		}
		if (myRodsArgs.help==True) {
//		   usage();
		   exit(0);
		}

		if (argc - optind <= 0) {
			rodsLog (LOG_ERROR, "irm: no input");
			printf("Use -h for help.\n");
			exit (2);
		}

		status = getRodsEnv (&myEnv);

		if (status < 0) {
			rodsLogError (LOG_ERROR, status, "main: getRodsEnv error. ");
			exit (1);
		}

		status = parseCmdLinePath (argc, argv, optind, &myEnv,
		  UNKNOWN_OBJ_T, NO_INPUT_T, 0, &rodsPathInp);

		if (status < 0) {
			rodsLogError (LOG_ERROR, status, "main: parseCmdLinePath error. ");
			printf("Use -h for help.\n");
			exit (1);
		}

		conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
		  myEnv.rodsZone, 1, &errMsg);

		if (conn == NULL) {
			exit (2);
		}

		status = clientLogin(conn);
		if (status != 0) {
			rcDisconnect(conn);
			exit (7);
		}

		status = rmUtil (conn, &myEnv, &myRodsArgs, &rodsPathInp);

		rcDisconnect(conn);

		if (status < 0) {
		exit (3);
		}
		else {
//			exit(0);
			return 0;
		}

	}
Esempio n. 11
0
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;
    }
}
Esempio n. 12
0
int
sendStartupPack( rcComm_t *conn, int connectCnt, int reconnFlag ) {
    startupPack_t startupPack;
    int status;
    char *tmpStr;
    bytesBuf_t *startupPackBBuf = NULL;


    /* setup the startup pack */

    startupPack.irodsProt  = conn->irodsProt;
    startupPack.connectCnt = connectCnt;
    startupPack.reconnFlag = reconnFlag;

    rstrcpy( startupPack.proxyUser,      conn->proxyUser.userName,  NAME_LEN );
    rstrcpy( startupPack.proxyRodsZone,  conn->proxyUser.rodsZone,  NAME_LEN );
    rstrcpy( startupPack.clientUser,     conn->clientUser.userName, NAME_LEN );
    rstrcpy( startupPack.clientRodsZone, conn->clientUser.rodsZone, NAME_LEN );

    rstrcpy( startupPack.relVersion, RODS_REL_VERSION,  NAME_LEN );
    rstrcpy( startupPack.apiVersion, RODS_API_VERSION,  NAME_LEN );

    if ( ( tmpStr = getenv( SP_OPTION ) ) != NULL ) {
        rstrcpy( startupPack.option, tmpStr, NAME_LEN );
    }
    else {
        startupPack.option[0] = '\0';
    }

    // =-=-=-=-=-=-=-
    // if the advanced negotiation is requested from the irodsEnv,
    // tack those results onto the startup pack option string
    rodsEnv rods_env;
    status = getRodsEnv( &rods_env );

    if ( status >= 0 && strlen( rods_env.rodsClientServerNegotiation ) > 0 ) {
        strncat( startupPack.option,
                 rods_env.rodsClientServerNegotiation,
                 strlen( rods_env.rodsClientServerNegotiation ) );
    }

    /* always use XML_PROT for the startupPack */
    status = packStruct( ( void * ) &startupPack, &startupPackBBuf,
                         "StartupPack_PI", RodsPackTable, 0, XML_PROT );
    if ( status < 0 ) {
        rodsLogError( LOG_NOTICE, status,
                      "sendStartupPack: packStruct error, status = %d", status );
        return status;
    }

    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( conn, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        freeBBuf( startupPackBBuf );
        return ret.code();
    }

    ret = sendRodsMsg(
              net_obj,
              RODS_CONNECT_T,
              startupPackBBuf,
              NULL, NULL, 0,
              XML_PROT );
    freeBBuf( startupPackBBuf );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    return ret.code();

} // sendStartupPack
Esempio n. 13
0
int
connectToRhost( rcComm_t *conn, int connectCnt, int reconnFlag ) {
    int status;
    conn->sock = connectToRhostWithRaddr( &conn->remoteAddr,
                                          conn->windowSize, 1 );
    if ( conn->sock < 0 ) {
        rodsLogError( LOG_NOTICE, conn->sock,
                      "connectToRhost: connect to host %s on port %d failed, status = %d",
                      conn->host, conn->portNum, conn->sock );
        return conn->sock;
    }

    setConnAddr( conn );
    status = sendStartupPack( conn, connectCnt, reconnFlag );

    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status,
                      "connectToRhost: sendStartupPack to %s failed, status = %d",
                      conn->host, status );
        close( conn->sock );
        return status;
    }

    // =-=-=-=-=-=-=-
    // create a network object
    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( conn, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    // =-=-=-=-=-=-=-
    // if the client requests the connection negotiation then wait for a
    // response here from the Agent
    if ( irods::do_client_server_negotiation_for_client() ) {
        // =-=-=-=-=-=-=-
        // politely do the negotiation
        std::string results;
        ret = irods::client_server_negotiation_for_client(
                  net_obj,
                  results );
        if ( !ret.ok() ) {
            irods::log( PASS( ret ) );
            return ret.code();
        }


        // =-=-=-=-=-=-=-
        // enable SSL if requested
        // NOTE:: this is disabled in rcDisconnect if the conn->ssl_on flag is set
        if ( irods::CS_NEG_USE_SSL == irods::CS_NEG_FAILURE ) {
            printf( "connectToRhost - failed in client-server negotiations\n" );
        }

        // =-=-=-=-=-=-=-
        // copy results to connection for network object factory
        snprintf( conn->negotiation_results, MAX_NAME_LEN, "%s", results.c_str() );
    }

    ret = readVersion( net_obj, &conn->svrVersion );
    if ( !ret.ok() ) {
        rodsLogError( LOG_ERROR, ret.code(),
                      "connectToRhost: readVersion to %s failed, status = %d",
                      conn->host, ret.code() );
        close( conn->sock );
        return ret.code();
    }

    if ( conn->svrVersion->status < 0 ) {
        rodsLogError( LOG_ERROR, conn->svrVersion->status,
                      "connectToRhost: error returned from host %s status = %d",
                      conn->host, conn->svrVersion->status );
        if ( conn->svrVersion->status == SYS_EXCEED_CONNECT_CNT )
            rodsLog( LOG_ERROR,
                     "It is likely %s is a localhost but not recognized by this server. A line can be added to the server/config/irodsHost file to fix the problem", conn->host );
        close( conn->sock );
        return conn->svrVersion->status;
    }

    // =-=-=-=-=-=-=-
    // call initialization for network plugin as negotiated
    irods::network_object_ptr new_net_obj;
    ret = irods::network_factory( conn, new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    // =-=-=-=-=-=-=-
    // get rods env to pass to client start for policy decisions
    rodsEnv rods_env;
    status = getRodsEnv( &rods_env );

    ret = sockClientStart( new_net_obj, &rods_env );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_client( conn );

    return 0;

} // connectToRhost
Esempio n. 14
0
int
main(int argc, char **argv) {
   int status, status2;
   rErrMsg_t errMsg;

   rodsArguments_t myRodsArgs;

   char *mySubName;
   char *myName;

   rodsEnv myEnv;


   rodsLogLevel(LOG_ERROR);

   status = parseCmdLineOpt (argc, argv, "AhvVlz:", 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);
   }

   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }

   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) {
      exit (3);
   }

   status2=0;
   if (myRodsArgs.optind == argc) {  /* no resource name specified */
      status = showResc(argv[myRodsArgs.optind], myRodsArgs.longOption);
      status2 = showRescGroups(myRodsArgs.longOption);
   }
   else {
      if (myRodsArgs.accessControl == True) {
	 showRescAcl(argv[myRodsArgs.optind]);
      }
      else {
	 status = showOneRescGroup(argv[myRodsArgs.optind], 
				   myRodsArgs.longOption);
	 if (status==0) {
	    status2 = showResc(argv[myRodsArgs.optind], myRodsArgs.longOption);
	    if (status2==0) {
	       /* Only print this if both fail */
	       printf("Resource-group %s does not exist.\n",
		      argv[myRodsArgs.optind]); 
	    }
	 }
      }
   }

   printErrorStack(Conn->rError);

   rcDisconnect(Conn);

   /* Exit 0 if one or more items were displayed */
   if (status > 0) exit(0);
   if (status2 > 0) exit(0);
   exit(4);
}
Esempio n. 15
0
int main(int argc, char **argv) {
  int status;

  /* 
   * seed random number generator
   * TODO: what uses this?
   */ 
  srandom((unsigned int) time(0) % getpid());

  /*
   * iquest_fuse data that will be passed in to FUSE operations
   */
  static iquest_fuse_t iquest_fuse;
  memset(&iquest_fuse, 0, sizeof(iquest_fuse));

  static iquest_fuse_conf_t iquest_fuse_conf;
  memset(&iquest_fuse_conf, 0, sizeof(iquest_fuse_conf));
  iquest_fuse.conf = &iquest_fuse_conf;

  static rodsEnv myRodsEnv;
  iquest_fuse.rods_env = &myRodsEnv;

  iquest_fuse_t *iqf = &iquest_fuse;
  
  /*
   * Use FUSE option processing to process argc/argv
   */
  struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

  /*
   * Set defaults for dynamically allocated conf fields that have not been set by options
   */
  if(iqf->conf->indicator == NULL) {
    int bufsize = strlen(IQF_DEFAULT_INDICATOR)+1;
    iqf->conf->indicator = malloc(bufsize);
    if(iqf->conf->indicator == NULL) {
      fprintf(stderr, "main: malloc(%d) setting default for iqf->conf->indicator\n", bufsize);
      exit(2);
    }
    strncpy(iqf->conf->indicator, IQF_DEFAULT_INDICATOR, bufsize);
  }
  
  if(iqf->conf->slash_remap == NULL) {
    int bufsize = strlen(IQF_DEFAULT_SLASH_REMAP)+1;
    iqf->conf->slash_remap = malloc(bufsize);
    if(iqf->conf->slash_remap == NULL) {
      fprintf(stderr, "main: malloc(%d) setting default for iqf->conf->slash_remap\n", bufsize);
      exit(2);
    }
    strncpy(iqf->conf->slash_remap, IQF_DEFAULT_SLASH_REMAP, bufsize);
  }
  
  /*
   * Set configuration in iquest_fuse_conf from command-line options and 
   * call iquest_fuse_opt_proc for other options
   */
  fuse_opt_parse(&args, &iquest_fuse_conf, iquest_fuse_opts, iquest_fuse_opt_proc);

  
  if(iqf->conf->irods_cwd != NULL) {
    rodsLog(LOG_NOTICE, "using iRODS cwd %s", iqf->conf->irods_cwd);
    status = setenv("irodsCwd", iqf->conf->irods_cwd, 1);
    if( status < 0) {
      rodsLog(LOG_ERROR, "main: could not set irodsCwd environment variable");
    }
  }
  
  if(iqf->conf->base_query != NULL) {
    rodsLog(LOG_NOTICE, "using base query %s", iqf->conf->base_query);
  }
  
  if(iqf->conf->indicator != NULL) {
    rodsLog(LOG_NOTICE, "using indicator %s", iqf->conf->indicator);
  }
  
  if(iqf->conf->slash_remap != NULL) {
    rodsLog(LOG_NOTICE, "remapping slashes [/] in metadata to [%s]", iqf->conf->slash_remap);
  }

  if(iqf->conf->show_indicator > 0) {
    rodsLog(LOG_SYS_WARNING, "showing query indicator (%s) in directory listings -- you must not attempt to recursively list directories (e.g. don't use find, du, ls -R, etc)", iqf->conf->indicator);
  }
  

#ifdef CACHE_FILE_FOR_READ
  if (setAndMkFileCacheDir () < 0) exit(3);
#endif
  
  /*
   * get iRODS configuration from environment and conf file (~/.irods/.irodsEnv)
   */
  status = getRodsEnv(iqf->rods_env);
  if( status < 0 ) {
    rodsLogError(LOG_ERROR, status, "main: getRodsEnv error. ");
    exit(1);
  }


  /* 
   * override irodsLogLevel if debug_level is greater
   */
  if(iqf->conf->debug_level > iqf->rods_env->rodsLogLevel) {
    fprintf(stderr, "overriding rodsLogLevel to debug_level=%d\n", iqf->conf->debug_level);
    rodsLogLevel(iqf->conf->debug_level);
    iqf->rods_env->rodsLogLevel = iqf->conf->debug_level;
  }
  
  initPathCache ();
  initIFuseDesc ();
  

  /*
   * Pass control to FUSE (which will call iquest_fuse_init and then start event loop 
   */
  rodsLog(LOG_DEBUG, "calling fuse_main");
  status = fuse_main (args.argc, args.argv, &iquest_fuse_operations, &iquest_fuse);
  rodsLog(LOG_DEBUG, "back from fuse_main");
  
  disconnect_all(iqf);
  
  if (status < 0) {
    rodsLogError(LOG_ERROR, status, "fuse_main");
    exit(5);
  } else {
    exit(0);
  }
}
Esempio n. 16
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 );
}
Esempio n. 17
0
int
bulkPutFileUtil( rcComm_t *conn, char *srcPath, char *targPath,
                 rodsLong_t srcSize, int createMode,
                 rodsArguments_t *rodsArgs, bulkOprInp_t *bulkOprInp,
                 bulkOprInfo_t *bulkOprInfo ) {
    int status;
    int in_fd;
    int bytesRead = 0;
    /*#ifndef windows_platform
      char *bufPtr = bulkOprInfo->bytesBuf.buf + bulkOprInfo->size;
    #else*/  /* make change for Windows only */
    char *bufPtr = ( char * )( bulkOprInfo->bytesBuf.buf ) + bulkOprInfo->size;
    /*#endif*/

#ifdef windows_platform
    in_fd = iRODSNt_bopen( srcPath, O_RDONLY, 0 );
#else
    in_fd = open( srcPath, O_RDONLY, 0 );
#endif
    if ( in_fd < 0 ) { /* error */
        status = USER_FILE_DOES_NOT_EXIST - errno;
        rodsLog( LOG_ERROR,
                 "bulkPutFileUtilcannot open file %s, status = %d", srcPath, status );
        return status;
    }

    status = myRead( in_fd, bufPtr, srcSize, &bytesRead, NULL );
    if ( status != srcSize ) {
        if ( status >= 0 ) {
            status = SYS_COPY_LEN_ERR - errno;
            rodsLogError( LOG_ERROR, status, "bulkPutFileUtil: bytesRead %ju does not match srcSize %ju for %s",
                          ( uintmax_t )bytesRead, ( uintmax_t )srcSize, srcPath );
        }
        else {
            status = USER_INPUT_PATH_ERR - errno;
        }
        return status;
    }
    close( in_fd );
    rstrcpy( bulkOprInfo->cachedTargPath, targPath, MAX_NAME_LEN );
    bulkOprInfo->count++;
    bulkOprInfo->size += srcSize;
    bulkOprInfo->bytesBuf.len = bulkOprInfo->size;

    if ( getValByKey( &bulkOprInp->condInput, REG_CHKSUM_KW ) != NULL ||
            getValByKey( &bulkOprInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) {
        char chksumStr[NAME_LEN];

        rodsEnv env;
        int ret = getRodsEnv( &env );
        if ( ret < 0 ) {
            rodsLog(
                LOG_ERROR,
                "bulkPutFileUtil: error getting rods env %d",
                ret );
            return ret;
        }
        status = chksumLocFile( srcPath, chksumStr, env.rodsDefaultHashScheme );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "bulkPutFileUtil: chksumLocFile error for %s ", srcPath );
            return status;
        }
        status = fillAttriArrayOfBulkOprInp( targPath, createMode, chksumStr,
                                             bulkOprInfo->size, bulkOprInp );
    }
    else {
        status = fillAttriArrayOfBulkOprInp( targPath, createMode, NULL,
                                             bulkOprInfo->size, bulkOprInp );
    }
    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status,
                      "bulkPutFileUtil: fillAttriArrayOfBulkOprInp error for %s",
                      srcPath );
        return status;
    }
    if ( bulkOprInfo->count >= MAX_NUM_BULK_OPR_FILES ||
            bulkOprInfo->size >= BULK_OPR_BUF_SIZE -
            MAX_BULK_OPR_FILE_SIZE ) {
        /* tar send it */
        status = sendBulkPut( conn, bulkOprInp, bulkOprInfo, rodsArgs );
        if ( status >= 0 ) {
            /* return the count */
            status = bulkOprInfo->count;
        }
        else {
            rodsLogError( LOG_ERROR, status,
                          "bulkPutFileUtil: tarAndBulkPut error for %s", srcPath );
        }
        clearBulkOprInfo( bulkOprInfo );
    }
    return status;
}
Esempio n. 18
0
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 );
}
Esempio n. 19
0
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 );
}
Esempio n. 20
0
static struct irods_server * connect_to_host( const char *hostport )
{
	struct irods_server *server;
	rcComm_t *conn;
	rErrMsg_t errmsg;
	char host[PFS_PATH_MAX];
	int port;

	if(!hostport[0]) {
		errno = EACCES;
		return 0;
	}

	if(!connect_cache) connect_cache = hash_table_create(0,0);

	time_t current = time(0);

	server = (struct irods_server*) hash_table_lookup(connect_cache,hostport);
	if(server) {
		if((current-server->lastused)>DISCONNECT_TIMEOUT) {
			debug(D_IRODS,"discarding stale connection to %s",hostport);
			rcDisconnect(server->conn);
			free(server);
			server = 0;
		} else {
			server->lastused = current;
			return server;
		}
	}

	if(!got_irods_env) {
		rodsLogLevel(pfs_irods_debug_level);
		if(getRodsEnv(&irods_env)<0) {
			debug(D_IRODS,"couldn't load irods environment!");
			return 0;
		}
		got_irods_env = 1;
	}

	debug(D_IRODS,"connecting to %s",hostport);

	sscanf(hostport,"%[^:]:%d",host,&port);

	conn = rcConnect(host,port,irods_env.rodsUserName,irods_env.rodsZone,1,&errmsg);
	if(!conn) {
		if(errno==EINPROGRESS) {
			errno = ECONNREFUSED;
		}
		debug(D_IRODS,"couldn't connect: %s\n",strerror(errno));
		return 0;
	}

	debug(D_IRODS,"logging in...");

	if(clientLogin(conn)!=0) {
		debug(D_IRODS,"unable to login as %s",irods_env.rodsUserName);
		rcDisconnect(conn);
		return 0;
	}

	server = malloc(sizeof(*server));
	server->conn = conn;
	server->lastused = current;
	server->serial = irods_serial++;

	hash_table_insert(connect_cache,hostport,server);

	return server;
}
Esempio n. 21
0
int
main( int argc, char **argv ) {
    int i1 = 0, i2 = 0, i3 = 0, i = 0;
    genQueryInp_t genQueryInp;
    int i1a[10];
    int i2a[10];
    int done = 0;
    int mode = 0;
    char *condVal[2];
    char v1[20];

    /* remove this call or change to LOG_NOTICE for more verbosity */
    rodsLogLevel( LOG_ERROR );

    /* this will cause the sql to be printed, comment this out to skip it  */
    rodsLogSqlReq( 1 );

    i1 = 7;
    i2 = 5;

    done = 0;
    mode = 0;
    if ( argc >= 2 ) {
        if ( strcmp( argv[1], "gen" ) == 0 ) {
            mode = 1;
        }
        if ( strcmp( argv[1], "ls" ) == 0 ) {
            mode = 2;
        }
        if ( strcmp( argv[1], "gen2" ) == 0 ) {
            mode = 3;
        }
        if ( strcmp( argv[1], "gen3" ) == 0 ) {
            mode = 4;
        }
        if ( strcmp( argv[1], "gen4" ) == 0 ) {
            mode = 5;
        }
        if ( strcmp( argv[1], "gen5" ) == 0 ) {
            mode = 6;
        }
        if ( strcmp( argv[1], "gen6" ) == 0 ) {
            mode = 7;
        }
        if ( strcmp( argv[1], "gen7" ) == 0 ) {
            mode = 8;
        }
        if ( strcmp( argv[1], "gen8" ) == 0 ) {
            mode = 9;
        }
        if ( strcmp( argv[1], "gen9" ) == 0 ) {
            mode = 10;
        }
        if ( strcmp( argv[1], "gen10" ) == 0 ) {
            mode = 11;
        }
        if ( strcmp( argv[1], "gen11" ) == 0 ) {
            mode = 12;
        }
        if ( strcmp( argv[1], "gen12" ) == 0 ) {
            mode = 13;
        }
        if ( strcmp( argv[1], "gen13" ) == 0 ) {
            mode = 14;
        }
        if ( strcmp( argv[1], "lsr" ) == 0 ) {
            mode = 15;
        }
        if ( strcmp( argv[1], "gen15" ) == 0 ) {
            mode = 16;
        }
    }

    if ( argc == 3 && mode == 0 ) {
        i1 = atoi( argv[1] );
        i2 = atoi( argv[2] );
        sTest( i1, i2 );
        done++;
    }

    if ( argc == 4 && mode == 0 ) {
        i1 = atoi( argv[1] );
        i2 = atoi( argv[2] );
        i3 = atoi( argv[3] );
        sTest2( i1, i2, i3 );
        done++;
    }

    if ( argc == 2 && mode == 0 ) {
        int j;
        j = atoi( argv[1] );
        if ( j >= 0 ) {
            printf( "finding cycles starting with table %d\n", j );
            i = findCycles( j );
            printf( "status = %d\n", i );
        }
        else {
            printf( "finding cycles for all tables\n" );
            printf( "last test should be -816000 if last table finished\n" );
            i = 0;
            for ( j = 0; i == 0; j++ ) {
                i = findCycles( j );
                printf( "starting with table %d status = %d\n", j, i );
            }
            if ( j > 70 && i == CAT_INVALID_ARGUMENT ) {
                printf(
                    "Success: Searched all tables (0 to %d) and no cycles found\n",
                    j - 1 );
                exit( 0 );
            }
            else {
                exit( 5 );
            }
        }
        done++;
    }

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

    genQueryInp.maxRows = 10;
    genQueryInp.continueInx = 0;
    /*
      (another test case that could be used)
    i1a[0]=COL_R_RESC_NAME;
    i1a[1]=COL_R_ZONE_NAME;
    i1a[2]=COL_R_TYPE_NAME;
    i1a[3]=COL_R_CLASS_NAME;
    */
    /*   i1a[0]=COL_COLL_INHERITANCE; */
    i1a[0] = COL_COLL_NAME;

    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.len = 1;

    i2a[0] = COL_D_DATA_PATH;
    genQueryInp.sqlCondInp.inx = i2a;
    strcpy( v1, "='b'" );
    condVal[0] = v1;
    genQueryInp.sqlCondInp.value = condVal;
    genQueryInp.sqlCondInp.len = 1;

    if ( mode == 1 ) {
        if ( argc == 3 ) {
            i1a[0] = atoi( argv[2] );
        }
    }
    if ( done == 0 ) {
        int status;
        genQueryOut_t result;
        rodsEnv myEnv;

        memset( ( char * )&result, 0, sizeof( result ) );
        memset( ( char * )&myEnv, 0, sizeof( myEnv ) );
        status = getRodsEnv( &myEnv );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR, "main: getRodsEnv error. status = %d",
                     status );
            exit( 1 );
        }

        // capture server properties
        irods::server_properties::getInstance().capture();

        if ( ( status = chlOpen() ) != 0 ) {

            rodsLog( LOG_SYS_FATAL,
                     "chlopen Error. Status = %d",
                     status );
            return status;
        }


        /* This is no longer ifdef'ed GEN_QUERY_AC (since msiAclPolicy
        now used), so just do it.   */
        chlGenQueryAccessControlSetup( myEnv.rodsUserName,
                                       myEnv.rodsZone,
                                       "",
                                       LOCAL_PRIV_USER_AUTH, 1 );

        if ( strstr( myEnv.rodsDebug, "CAT" ) != NULL ) {
            chlDebug( myEnv.rodsDebug );
        }

        if ( mode == 2 ) {
            /*	 doLs(); */
            doLs2();
            exit( 0 );
        }
        if ( mode == 3 ) {
            doTest2();
            exit( 0 );
        }
        if ( mode == 4 ) {
            doTest3();
            exit( 0 );
        }
        if ( mode == 5 ) {
            doTest4();
            exit( 0 );
        }
        if ( mode == 6 ) {
            doTest5();
            exit( 0 );
        }
        if ( mode == 7 ) {
            doTest6( argv[2] );
            exit( 0 );
        }

        if ( mode == 8 ) {
            status = doTest7( argv[2], argv[3], argv[4], argv[5] );
            if ( status < 0 ) {
                exit( 1 );
            }
            exit( 0 );
        }

        if ( mode == 9 ) {
            status = doTest8( argv[2], argv[3], argv[4] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }

        if ( mode == 10 ) {
            status = doTest9( argv[2], argv[3] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }

        if ( mode == 11 ) {
            status = doTest10( argv[2], argv[3], argv[4], argv[5] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }

        if ( mode == 12 ) {
            status = doTest11( argv[2], argv[3], argv[4], argv[5], argv[6] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }
        if ( mode == 13 ) {
            status = doTest12( argv[2], argv[3], argv[4], argv[5] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }
        if ( mode == 14 ) {
            status = doTest13( argv[2], argv[3], argv[4], argv[5], argv[6] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }
        if ( mode == 15 ) {
            try {
                int reps = boost::lexical_cast<int>( argv[2] );
                reps = reps > 0 && reps <= std::numeric_limits<int>::max() ? reps : 0;
                status = doLs3( reps );
            } catch ( boost::bad_lexical_cast e ) {
                exit( 2 );
            }
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }
        if ( mode == 16 ) {
            status = doTest15( argv[2], argv[3], argv[4] );
            if ( status < 0 ) {
                exit( 2 );
            }
            exit( 0 );
        }

        genQueryInp.maxRows = 2;
        i = chlGenQuery( genQueryInp, &result );
        printf( "chlGenQuery status=%d\n", i );
        printf( "result.rowCnt=%d\n", result.rowCnt );
        if ( result.rowCnt > 0 ) {
            int i;
            for ( i = 0; i < result.rowCnt; i++ ) {
                printf( "result.SqlResult[%d].value=%s\n", i,
                        result.sqlResult[i].value );
            }
        }
    }
    exit( 0 );
}
Esempio n. 22
0
// Read LEGACY_SERVER_CONFIG_FILE and fill server_properties::properties
    void server_properties::capture_legacy() {
        error result = SUCCESS();
        std::string property; // property setting

        FILE *fptr;
        char buf[BUF_LEN];
        char *fchar;
        int len;
        char *key;

        char DBKey[MAX_PASSWORD_LEN], DBPassword[MAX_PASSWORD_LEN];
        memset( &DBKey, '\0', MAX_PASSWORD_LEN );
        memset( &DBPassword, '\0', MAX_PASSWORD_LEN );

        std::string cfg_file;
        error ret = irods::get_full_path_for_config_file(
                        LEGACY_SERVER_CONFIG_FILE,
                        cfg_file );
        if ( !ret.ok() ) {
            THROW( ret.code(), ret.result() );
        }

        if ( !fs::exists( cfg_file ) ) {
            return;
        }

        rodsLog(
            LOG_ERROR,
            "server_properties::capture_legacy - use of legacy configuration is deprecated" );

        fptr = fopen( cfg_file.c_str(), "r" );

        if ( fptr == NULL ) {
            rodsLog( LOG_DEBUG,
                     "Cannot open LEGACY_SERVER_CONFIG_FILE file %s. errno = %d\n",
                     cfg_file.c_str(), errno );
            std::stringstream msg;
            msg << LEGACY_SERVER_CONFIG_FILE << " file error";
            THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() );
        }

        // =-=-=-=-=-=-=-
        // PAM configuration - init PAM values
        result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false );
        result = config_props_.set<size_t>( PAM_PW_LEN_KW, 20 );

        property.assign( "121" );
        result = config_props_.set<std::string>( PAM_PW_MIN_TIME_KW, property );

        property.assign( "1209600" );
        result = config_props_.set<std::string>( PAM_PW_MAX_TIME_KW, property );
        // init PAM values

        std::string initializer[] = {
            ICAT_HOST_KW,
            RE_RULESET_KW,
            RE_FUNCMAPSET_KW,
            RE_VARIABLEMAPSET_KW,
            DB_USERNAME_KW,
            PAM_PW_MIN_TIME_KW,
            PAM_PW_MAX_TIME_KW,
            CATALOG_DATABASE_TYPE_KW,
            KERBEROS_NAME_KW,
            LOCAL_ZONE_SID_KW };
        std::vector<std::string> keys( initializer, initializer + sizeof( initializer ) / sizeof( std::string ) );

        buf[BUF_LEN - 1] = '\0';
        fchar = fgets( buf, BUF_LEN - 1, fptr );
        while ( fchar ) {
            if ( buf[0] == '#' || buf[0] == '/' ) {
                buf[0] = '\0'; /* Comment line, ignore */
            }

            /**
             * Parsing of server configuration settings
             */
            key = strstr( buf, DB_PASSWORD_KW );
            if ( key != NULL ) {
                len = strlen( DB_PASSWORD_KW );

                // Store password in temporary string
                snprintf( DBPassword, sizeof( DBPassword ), "%s", findNextTokenAndTerm( key + len ) );

            } // DB_PASSWORD_KW

            key = strstr( buf, DB_KEY_KW );
            if ( key != NULL ) {
                len = strlen( DB_KEY_KW );

                // Store key in temporary string
                snprintf( DBKey, sizeof( DBKey ), "%s", findNextTokenAndTerm( key + len ) );

            } // DB_KEY_KW

            for ( std::vector<std::string>::iterator it = keys.begin(); it != keys.end(); it++ ) {
                char * pos = strstr( buf, it->c_str() );
                if ( pos != NULL ) {

                    // Set property
                    property.assign( findNextTokenAndTerm( pos + it->size() ) );

                    // Update properties table
                    result = config_props_.set<std::string>( *it, property );
                    rodsLog( LOG_DEBUG1, "%s=%s", it->c_str(), property.c_str() );
                }
            }

            key = strstr( buf, PAM_PW_LEN_KW );
            if ( key != NULL ) {
                len = strlen( PAM_PW_LEN_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                // Update properties table
                result = config_props_.set<size_t>( PAM_PW_LEN_KW, atoi( property.c_str() ) );

                rodsLog( LOG_DEBUG, "%s=%s", PAM_PW_LEN_KW, property.c_str() );
            } // PAM_PW_LEN_KW

            key = strstr( buf, PAM_NO_EXTEND_KW );
            if ( key != NULL ) {
                len = strlen( PAM_NO_EXTEND_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                std::transform( property.begin(), property.end(), property.begin(), ::tolower );
                if ( property == "true" ) {
                    result = config_props_.set<bool>( PAM_NO_EXTEND_KW, true );
                }
                else {
                    result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false );
                }

                rodsLog( LOG_DEBUG, "%s=%s", PAM_NO_EXTEND_KW, property.c_str() );
            } // PAM_NO_EXTEND_KW

            key = strstr( buf, DEF_DIR_MODE_KW );
            if ( key != NULL ) {
                len = strlen( DEF_DIR_MODE_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                // Update properties table
                result = config_props_.set<int>( DEF_DIR_MODE_KW, strtol( property.c_str(), 0, 0 ) );

                rodsLog( LOG_DEBUG, "%s=%s", DEF_DIR_MODE_KW, property.c_str() );
            } // DEF_DIR_MODE_KW


            key = strstr( buf, DEF_FILE_MODE_KW );
            if ( key != NULL ) {
                len = strlen( DEF_FILE_MODE_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                // Update properties table
                result = config_props_.set<int>( DEF_FILE_MODE_KW, strtol( property.c_str(), 0, 0 ) );

                rodsLog( LOG_DEBUG, "%s=%s", DEF_FILE_MODE_KW, property.c_str() );
            } // DEF_FILE_MODE_KW

            key = strstr( buf, KERBEROS_KEYTAB_KW );
            if ( key != NULL ) {
                len = strlen( KERBEROS_KEYTAB_KW );
                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );
                // Update properties table
                result = config_props_.set<std::string>( KERBEROS_KEYTAB_KW, property );
                rodsLog( LOG_DEBUG, "%s=%s", KERBEROS_KEYTAB_KW, property.c_str() );

                // Now set the appropriate kerberos environment variable
                setenv( "KRB5_KTNAME", property.c_str(), 1 );

            } // KERBEROS_KEYTAB_KW

            key = strstr( buf, DEFAULT_HASH_SCHEME_KW );
            if ( key != NULL ) {
                len = strlen( DEFAULT_HASH_SCHEME_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );
                std::transform(
                    property.begin(),
                    property.end(),
                    property.begin(),
                    ::tolower );

                // Update properties table
                result = config_props_.set<std::string>( DEFAULT_HASH_SCHEME_KW, property );

                rodsLog( LOG_DEBUG, "%s=%s", DEFAULT_HASH_SCHEME_KW, property.c_str() );
            } // DEFAULT_HASH_SCHEME_KW

            key = strstr( buf, MATCH_HASH_POLICY_KW );
            if ( key != NULL ) {
                len = strlen( MATCH_HASH_POLICY_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );
                std::transform(
                    property.begin(),
                    property.end(),
                    property.begin(),
                    ::tolower );

                // Update properties table
                result = config_props_.set<std::string>( MATCH_HASH_POLICY_KW, property );

                rodsLog( LOG_DEBUG, "%s=%s", MATCH_HASH_POLICY_KW, property.c_str() );
            } // MATCH_HASH_POLICY_KW

            key = strstr( buf, REMOTE_ZONE_SID_KW );
            if ( key != NULL ) {
                len = strlen( REMOTE_ZONE_SID_KW );

                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                // Update properties table
                std::vector<std::string>           rem_sids;
                std::vector<std::string>::iterator sid_itr;
                if ( config_props_.has_entry( REMOTE_ZONE_SID_KW ) ) {
                    result = config_props_.get< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids );

                    // do not want duplicate entries
                    sid_itr = std::find(
                                  rem_sids.begin(),
                                  rem_sids.end(),
                                  property );

                }

                if ( sid_itr == rem_sids.end() ) {
                    rem_sids.push_back( property );
                    result = config_props_.set< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids );
                }

                rodsLog( LOG_DEBUG, "%s=%s", REMOTE_ZONE_SID_KW, property.c_str() );

            } // REMOTE_ZONE_SID_KW

            key = strstr( buf, AGENT_KEY_KW.c_str() );
            if ( key != NULL ) {
                len = strlen( AGENT_KEY_KW.c_str() );
                // Set property
                property.assign( findNextTokenAndTerm( key + len ) );

                if ( 32 != property.size() ) {
                    rodsLog( LOG_ERROR,
                             "%s field in %s must be 32 characters in length (currently %d characters in length).",
                             AGENT_KEY_KW.c_str(), LEGACY_SERVER_CONFIG_FILE, property.size() );
                    fclose( fptr );
                    std::stringstream msg;
                    msg << LEGACY_SERVER_CONFIG_FILE << " file error";
                    THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() );
                }

                // Update properties table
                result = config_props_.set<std::string>( AGENT_KEY_KW, property );

            } // AGENT_KEY_KW

            fchar = fgets( buf, BUF_LEN - 1, fptr );

        } // for ( ; fchar != '\0'; )

        fclose( fptr );

        // unscramble password
        if ( strlen( DBKey ) > 0 && strlen( DBPassword ) > 0 ) {
            char sPassword[MAX_PASSWORD_LEN + 10];
            strncpy( sPassword, DBPassword, MAX_PASSWORD_LEN );
            obfDecodeByKey( sPassword, DBKey, DBPassword );
            memset( sPassword, 0, MAX_PASSWORD_LEN );
        }

        // store password and key in server properties
        property.assign( DBPassword );
        result = config_props_.set<std::string>( DB_PASSWORD_KW, property );
        rodsLog( LOG_DEBUG1, "%s=%s", DB_PASSWORD_KW, property.c_str() );

        property.assign( DBKey );
        result = config_props_.set<std::string>( DB_KEY_KW, property );
        rodsLog( LOG_DEBUG1, "%s=%s", DB_KEY_KW, property.c_str() );

        // add expected zone_name, zone_user, zone_port, zone_auth_scheme
        // as these are now read from server_properties
        rodsEnv env;
        int status = getRodsEnv( &env );
        if ( status < 0 ) {
            THROW( status, "failure in getRodsEnv" );
        }
        result = config_props_.set<std::string>(
                     irods::CFG_ZONE_NAME_KW,
                     env.rodsZone );
        if ( !result.ok() ) {
            irods::log( PASS( result ) );

        }

        result = config_props_.set<std::string>(
                     irods::CFG_ZONE_USER,
                     env.rodsUserName );
        if ( !result.ok() ) {
            irods::log( PASS( result ) );

        }

        result = config_props_.set<std::string>(
                     irods::CFG_ZONE_AUTH_SCHEME,
                     env.rodsAuthScheme );
        if ( !result.ok() ) {
            irods::log( PASS( result ) );

        }

        result = config_props_.set<int>(
                     irods::CFG_ZONE_PORT,
                     env.rodsPort );
        if ( !result.ok() ) {
            irods::log( PASS( result ) );

        }

        if ( 0 != env.xmsgPort ) {
            result = config_props_.set<int>(
                         irods::CFG_XMSG_PORT,
                         env.xmsgPort );
            if ( !result.ok() ) {
                irods::log( PASS( result ) );

            }
        }

    } // server_properties::capture()
Esempio n. 23
0
int
main(int argc, char **argv) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;
    int nArgv;
    

    optStr = "bD:hR:cxD:fZ";
   
    status = parseCmdLineOpt (argc, argv, optStr, 1, &myRodsArgs);

    if (status < 0) {
	printf("use -h for help.\n");
        exit (1);
    }

    if (myRodsArgs.help==True) {
       usage();
       exit(0);
    }

    nArgv = argc - optind;

    if (nArgv != 2) {      /* must have 2 inputs */
        usage ();
        exit (1);
    }

    status = getRodsEnv (&myEnv);
    if (status < 0) {
        rodsLogError (LOG_ERROR, status, "main: getRodsEnv error. ");
        exit (1);
    }

    status = parseCmdLinePath (argc, argv, optind, &myEnv,
      UNKNOWN_OBJ_T, UNKNOWN_OBJ_T, 0, &rodsPathInp);

    if (status < 0) {
        rodsLogError (LOG_ERROR, status, "main: parseCmdLinePath error. "); 
	printf("use -h for help.\n");
        exit (1);
    }

    conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
      myEnv.rodsZone, 1, &errMsg);

    if (conn == NULL) {
        exit (2);
    }
   
    status = clientLogin(conn);
    if (status != 0) {
       rcDisconnect(conn);
        exit (7);
    }

    status = bunUtil (conn, &myEnv, &myRodsArgs, &rodsPathInp);

    printErrorStack(conn->rError);

    rcDisconnect(conn);

    if (status < 0) {
	exit (3);
    } else {
        exit(0);
    }

}
Esempio n. 24
0
int
main(int argc, char **argv)
{
   int status;
   rodsArguments_t myRodsArgs;
   rodsEnv myEnv;
   int i, j, didOne;
   char objPath[MAX_NAME_LEN];
   int maxCmdTokens=20;
   char *cmdToken[20];
   int argOffset;
   rcComm_t *Conn;
   rErrMsg_t errMsg;
   char *mySubName;
   char *myName;

   status = parseCmdLineOpt(argc, argv, "lvVh", 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(objPath,myEnv.rodsCwd,MAX_NAME_LEN);

   for (i=0;i<maxCmdTokens;i++) {
      cmdToken[i]="";
   }
   j=0;
   for (i=argOffset;i<argc;i++) {
      cmdToken[j++]=argv[i];
   }

   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);
   }

   if (strcmp(cmdToken[0],"ldt")==0) {
      if (*cmdToken[1]=='\0') {
	 cmdToken[1]=" ";  /* just for subsequent checks below */
      }
   }

   if (*cmdToken[1]=='\0') {
      usage("");
      exit(1);
   }

   if (*cmdToken[1]=='/') {
      rstrcpy(objPath, cmdToken[1], MAX_NAME_LEN);
   }
   else {
      rstrcat(objPath, "/", MAX_NAME_LEN);
      rstrcat(objPath, cmdToken[1], MAX_NAME_LEN);
   }

   didOne=0;
   if (strcmp(cmdToken[0],"ls")==0) {
      int longOption;
      if (myRodsArgs.longOption) longOption=1;
      if (myRodsArgs.verbose) longOption=1;
      doLs(Conn, objPath, longOption);
      didOne=1;
   }
   if (strcmp(cmdToken[0],"ldt")==0) {
      doListDataTypes(Conn);
      didOne=1;
   }

   if (strcmp(cmdToken[0],"mod")==0) {
      char theTime[TIME_LEN+20];

      if (*cmdToken[2]=='\0') {
	 usage("");
	 exit(1);
      }
      if (strcmp(cmdToken[2],"datatype")==0) {
	 if (*cmdToken[3]=='\0') {
	    usage("");
	    exit(1);
	 }	    
	 status = doModDatatype(Conn, objPath, cmdToken[3]);
	 didOne=1;
      }
      else if (strcmp(cmdToken[2],"comment")==0) {
	 if (*cmdToken[3]=='\0') {
	    usage("");
	    exit(1);
	 }
	 if (*cmdToken[4]=='\0') {
             status = doModComment(Conn, objPath, -1, cmdToken[3]);
         }
         else {
             status = doModComment(Conn, objPath, atoi(cmdToken[3]), cmdToken[4]);
         }
	 
	 didOne=1;
      }
      else {
	 rstrcpy(theTime, cmdToken[2], TIME_LEN);
	 status=0;
	 if (*cmdToken[2]=='+') {
	    rstrcpy(theTime, cmdToken[2]+1, TIME_LEN); /* skip the + */
	    status = checkDateFormat(theTime);      /* check and convert the time value */
	    getOffsetTimeStr(theTime, theTime);     /* convert delta format to now + this*/
	 } else {
	    status = checkDateFormat(theTime);      /* check and convert the time value */
	 }
	 if (status==0) {
	    status = doMod(Conn, objPath, theTime);
	    didOne=1;
	 }
	 else {
	    printf("Invalid time format input\n");
	 }
      }
   }

   printErrorStack(Conn->rError);

   rcDisconnect(Conn);

   if (didOne==0) {
      usage("");
      exit(1);
   }

   exit(0);
}
Esempio n. 25
0
int
main( int argc, char **argv ) {
    int status;
    rErrMsg_t errMsg;

    rodsArguments_t myRodsArgs;
    int argOffset;

    rodsLogLevel( LOG_ERROR );

    status = parseCmdLineOpt( argc, argv, "hvV", 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 );
    }

    if ( argOffset != argc - 3 ) {
        usage();
        exit( -1 );
    }

    // =-=-=-=-=-=-=-
    // 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 ) {
        exit( 2 );
    }

    status = clientLogin( Conn );
    if ( status != 0 ) {
        printError( Conn, status, "clientLogin" );
        if ( !debug ) {
            exit( 3 );
        }
    }

    status = modDelayedRule( argv[argOffset], argv[argOffset + 1],
                             argv[argOffset + 2] );

    printErrorStack( Conn->rError );
    rcDisconnect( Conn );

    if ( status != 0 ) {
        exit( 4 );
    }
    exit( 0 );
}
Esempio n. 26
0
int
main(int argc, char **argv) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    execCmd_t execCmd;
    execCmdOut_t *execCmdOut = NULL;
    int nArg;
    char *tmpPtr;

    optStr = "hvH:p:P:";

    status = parseCmdLineOpt (argc, argv, optStr, 1, &myRodsArgs);

    if (status < 0) {
        printf("Use -h for help.\n");
        exit (1);
    }
    if (myRodsArgs.help==True) {
        usage();
        exit(0);
    }

    nArg = argc - optind;

    if (nArg <= 0 || nArg > 1) {
        rodsLog (LOG_ERROR, "iexecmd: no input or too many input");
        printf("Use -h for help.\n");
        exit (2);
    }

    if (myRodsArgs.physicalPath == True && myRodsArgs.logicalPath == True) {
        rodsLog (LOG_ERROR,
                 "iexecmd: -p and -P options cannot be used together");
        exit (3);
    }

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

    if ((tmpPtr = strchr (argv[optind], ' ')) != NULL &&
            tmpPtr != argv[optind]) {
        /* have argv in the command */
        *tmpPtr = '\0';
        rstrcpy (execCmd.cmd, argv[optind], LONG_NAME_LEN);
        tmpPtr ++;
        rstrcpy (execCmd.cmdArgv, tmpPtr, HUGE_NAME_LEN);
    } else {
        rstrcpy (execCmd.cmd, argv[optind], LONG_NAME_LEN);
    }

    if (myRodsArgs.hostAddr == True) {
        rstrcpy (execCmd.execAddr, myRodsArgs.hostAddrString, LONG_NAME_LEN);
    }

    if (myRodsArgs.physicalPath == True) {
        rstrcpy (execCmd.hintPath, myRodsArgs.physicalPathString,
                 LONG_NAME_LEN);
        execCmd.addPathToArgv = 0;
    } else if (myRodsArgs.logicalPath == True) {
        rstrcpy (execCmd.hintPath, myRodsArgs.logicalPathString,
                 LONG_NAME_LEN);
        execCmd.addPathToArgv = 1;
    }
    addKeyVal (&execCmd.condInput, STREAM_STDOUT_KW, "");

    status = getRodsEnv (&myEnv);

    if (status < 0) {
        rodsLogError (LOG_ERROR, status, "main: getRodsEnv error. ");
        exit (1);
    }

    conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
                      myEnv.rodsZone, 0, &errMsg);

    if (conn == NULL) {
        exit (2);
    }

    status = clientLogin(conn);
    if (status != 0) {
        rcDisconnect(conn);
        exit (7);
    }

    status = rcExecCmd (conn, &execCmd, &execCmdOut);

    if (status == SYS_UNMATCHED_API_NUM) {
        /* try older version */
        execCmd241_t execCmd241Inp;

        rstrcpy (execCmd241Inp.cmd, execCmd.cmd, LONG_NAME_LEN);
        rstrcpy (execCmd241Inp.cmdArgv, execCmd.cmdArgv, HUGE_NAME_LEN);
        rstrcpy (execCmd241Inp.execAddr, execCmd.execAddr, LONG_NAME_LEN);
        rstrcpy (execCmd241Inp.hintPath, execCmd.hintPath, LONG_NAME_LEN);
        execCmd241Inp.addPathToArgv = execCmd.addPathToArgv;
        bzero (&execCmd241Inp.condInput, sizeof (keyValPair_t));

        status = rcExecCmd241 (conn, &execCmd241Inp, &execCmdOut);
    }

    if (status < 0) {
        rodsLogError (LOG_ERROR, status, "rcExecCmd error. ");
        printErrorStack (conn->rError);
        if (execCmdOut != NULL && execCmdOut->stderrBuf.buf != NULL) {
            fprintf (stderr, "%s", (char *) execCmdOut->stderrBuf.buf);
        }

        rcDisconnect(conn);
        exit (4);
    }


    if (myRodsArgs.verbose == True) {
        printf ("rcExecCmd completed successfully.    Output \n\n");
    }

    if (execCmdOut != NULL) {
        int i;
        char *tmpPtr;
        fileReadInp_t streamReadInp;
        fileCloseInp_t streamCloseInp;
        bytesBuf_t *streamReadOutBBuf;
        int bytesRead;

        if (execCmdOut->stdoutBuf.buf != NULL) {
            tmpPtr = (char*)execCmdOut->stdoutBuf.buf;
            for (i = 0; i < execCmdOut->stdoutBuf.len; i++) {
                fputc ((int)(*tmpPtr), stdout);
                tmpPtr++;
            }
        }
        if (execCmdOut->stderrBuf.buf != NULL) {
            tmpPtr = (char*)execCmdOut->stderrBuf.buf;
            for (i = 0; i < execCmdOut->stderrBuf.len; i++) {
                fputc ((int)(*tmpPtr), stderr);
                tmpPtr++;
            }
        }
        if (execCmdOut->status > 0) {
            /* (execCmdOut->status is a stream descriptor */
            bzero (&streamReadInp, sizeof (streamReadInp));
            streamReadOutBBuf = &execCmdOut->stdoutBuf;
            if (streamReadOutBBuf->len < MAX_SZ_FOR_EXECMD_BUF) {
                if (streamReadOutBBuf->buf != NULL) {
                    free (streamReadOutBBuf->buf);
                }
                streamReadOutBBuf->buf = malloc (MAX_SZ_FOR_EXECMD_BUF);
            }
            streamReadOutBBuf->len = streamReadInp.len = MAX_SZ_FOR_EXECMD_BUF;
            streamReadInp.fileInx = execCmdOut->status;
            while ((bytesRead = rcStreamRead (conn, &streamReadInp,
                                              streamReadOutBBuf)) > 0) {
                tmpPtr = (char*)streamReadOutBBuf->buf;
                for (i = 0; i < bytesRead; i++) {
                    fputc ((int)(*tmpPtr), stdout);
                    tmpPtr++;
                }
            }
            streamCloseInp.fileInx = execCmdOut->status;
            rcStreamClose (conn, &streamCloseInp);
        }
    }
    rcDisconnect(conn);

    exit(0);
}
Esempio n. 27
0
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);
}
Esempio n. 28
0
int
putFileUtil( rcComm_t *conn, char *srcPath, char *targPath, rodsLong_t srcSize,
             rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp ) {
    int status;
    struct timeval startTime, endTime;

    if ( srcPath == NULL || targPath == NULL ) {
        rodsLog( LOG_ERROR,
                 "putFileUtil: NULL srcPath or targPath input" );
        return USER__NULL_INPUT_ERR;
    }

    if ( conn->fileRestart.info.status == FILE_RESTARTED &&
            strcmp( conn->fileRestart.info.objPath, targPath ) == 0 ) {
        /* it was restarted */
        conn->fileRestart.info.status = FILE_NOT_RESTART;
        return 0;
    }

    if ( rodsArgs->verbose == True ) {
        ( void ) gettimeofday( &startTime, ( struct timezone * )0 );
    }

    if ( gGuiProgressCB != NULL ) {
        rstrcpy( conn->operProgress.curFileName, srcPath, MAX_NAME_LEN );
        conn->operProgress.curFileSize = srcSize;
        conn->operProgress.curFileSizeDone = 0;
        conn->operProgress.flag = 0;
        gGuiProgressCB( &conn->operProgress );
    }

    /* have to take care of checksum here since it needs to be recalculated */
    if ( rodsArgs->checksum == True ) {
        // set the expected flag to indicate that we want a server-side
        // checksum computed and stored in the catalog
        addKeyVal( &dataObjOprInp->condInput, REG_CHKSUM_KW, "" );

    }
    else if ( rodsArgs->verifyChecksum == True ) {
        rodsEnv env;
        int ret = getRodsEnv( &env );
        if ( ret < 0 ) {
            rodsLog(
                LOG_ERROR,
                "putFileUtil - failed to capture rods env %d",
                ret );
            return ret;
        }

        status = rcChksumLocFile( srcPath,
                                  VERIFY_CHKSUM_KW,
                                  &dataObjOprInp->condInput,
                                  env.rodsDefaultHashScheme );
        if ( status < 0 ) {
            rodsLogError( LOG_ERROR, status,
                          "putFileUtil: rcChksumLocFile error for %s, status = %d",
                          srcPath, status );
            return status;
        }
    }
    if ( strlen( targPath ) >= MAX_PATH_ALLOWED - 1 ) {
        return USER_PATH_EXCEEDS_MAX;
    }
    rstrcpy( dataObjOprInp->objPath, targPath, MAX_NAME_LEN );
    dataObjOprInp->dataSize = srcSize;
    status = rcDataObjPut( conn, dataObjOprInp, srcPath );

    if ( status >= 0 ) {
        if ( rodsArgs->verbose == True ) {
            ( void ) gettimeofday( &endTime, ( struct timezone * )0 );
            printTiming( conn, dataObjOprInp->objPath, srcSize, srcPath,
                         &startTime, &endTime );
        }
        if ( gGuiProgressCB != NULL ) {
            conn->operProgress.totalNumFilesDone++;
            conn->operProgress.totalFileSizeDone += srcSize;
        }
    }

    return status;
}
Esempio n. 29
0
/* #define SERVER_DEBUG 1   */
int
main(int argc, char *argv[])
{
    int status;
    rsComm_t rsComm;
    char *tmpStr;

    ProcessType = AGENT_PT;

#ifdef RUN_SERVER_AS_ROOT
#ifndef windows_platform
    if (initServiceUser() < 0) {
        exit (1);
    }
#endif
#endif

#ifdef windows_platform
	iRODSNtAgentInit(argc, argv);
#endif

#ifndef windows_platform
    signal(SIGINT, signalExit);
    signal(SIGHUP, signalExit);
    signal(SIGTERM, signalExit);
    /* set to SIG_DFL as recommended by andy.salnikov so that system()
     * call returns real values instead of 1 */
    signal(SIGCHLD, SIG_DFL);
    signal(SIGUSR1, signalExit);
    signal(SIGPIPE, rsPipSigalHandler);
#endif

#ifndef windows_platform
#ifdef SERVER_DEBUG
    if (isPath ("/tmp/rodsdebug"))
        sleep (20);
#endif
#endif

#ifdef SYS_TIMING
    rodsLogLevel(LOG_NOTICE);
    printSysTiming ("irodsAgent", "exec", 1);
#endif

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

    status = initRsCommWithStartupPack (&rsComm, NULL);

    if (status < 0) {
	sendVersion (rsComm.sock, status, 0, NULL, 0);
        cleanupAndExit (status);
    }

    /* Handle option to log sql commands */
    tmpStr = getenv (SP_LOG_SQL);
    if (tmpStr != NULL) {
#ifdef IRODS_SYSLOG
       int j = atoi(tmpStr);
       rodsLogSqlReq(j);
#else
       rodsLogSqlReq(1);
#endif
    }

    /* Set the logging level */
    tmpStr = getenv (SP_LOG_LEVEL);
    if (tmpStr != NULL) {
       int i;
       i = atoi(tmpStr);
       rodsLogLevel(i);
    } else {
       rodsLogLevel(LOG_NOTICE); /* default */
    }

#ifdef IRODS_SYSLOG
/* Open a connection to syslog */
#ifdef SYSLOG_FACILITY_CODE
    openlog("rodsAgent",LOG_ODELAY|LOG_PID,SYSLOG_FACILITY_CODE);
#else
    openlog("rodsAgent",LOG_ODELAY|LOG_PID,LOG_DAEMON);
#endif
#endif

    status = getRodsEnv (&rsComm.myEnv);

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }

#if RODS_CAT
    if (strstr(rsComm.myEnv.rodsDebug, "CAT") != NULL) {
       chlDebug(rsComm.myEnv.rodsDebug);
    }
#endif

#ifdef RULE_ENGINE_N
    status = initAgent (RULE_ENGINE_TRY_CACHE, &rsComm);
#else
    status = initAgent (&rsComm);
#endif
#ifdef SYS_TIMING
    printSysTiming ("irodsAgent", "initAgent", 0);
#endif

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }

    /* move configConnectControl behind initAgent for now. need zoneName if
     * the user does not specify one in the input */
    initConnectControl ();

    if (rsComm.clientUser.userName[0] != '\0') {
        status = chkAllowedUser (rsComm.clientUser.userName,
         rsComm.clientUser.rodsZone);

        if (status < 0) {
            sendVersion (rsComm.sock, status, 0, NULL, 0);
            cleanupAndExit (status);
	}
    }

    /* send the server version and atatus as part of the protocol. Put
     * rsComm.reconnPort as the status */

    status = sendVersion (rsComm.sock, status, rsComm.reconnPort,
      rsComm.reconnAddr, rsComm.cookie);

    if (status < 0) {
	sendVersion (rsComm.sock, SYS_AGENT_INIT_ERR, 0, NULL, 0);
        cleanupAndExit (status);
    }
#ifdef SYS_TIMING
    printSysTiming ("irodsAgent", "sendVersion", 0);
#endif

    logAgentProc (&rsComm);

    status = agentMain (&rsComm);

    cleanupAndExit (status);

    return (status);
}
Esempio n. 30
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr, buffer[HUGE_NAME_LEN];
    rodsPathInp_t rodsPathInp;
    objType_t srcType, destType;
    int nArgv;
    int i;


    optStr = "ahKlN:rR:svVZ";

    status = parseCmdLineOpt( argc, argv, optStr, 1, &myRodsArgs );

    if ( status < 0 ) {
        printf( "use -h for help.\n" );
        exit( 1 );
    }

    if ( myRodsArgs.help == True ) {
        usage();
        exit( 0 );
    }

    status = getRodsEnv( &myEnv );
    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status, "main: getRodsEnv error. " );
        exit( 1 );
    }

    nArgv = argc - optind;

    if ( nArgv < 2 ) {    /* must have at least 2 input */
        usage();
        exit( 1 );
    }

    for ( i = 2; i <= nArgv; i++ ) {
        if ( strcmp( argv[argc - i], "i:" ) == 0 ) {
            srcType = UNKNOWN_OBJ_T;
            strcpy( argv[argc - i], "." );
        }
        else if ( strncmp( argv[argc - i], "i:", 2 ) == 0 ) {
            srcType = UNKNOWN_OBJ_T;
            snprintf( buffer, HUGE_NAME_LEN, "%s", argv[argc - i] + 2 );
            argv[argc - i] = strdup( buffer );
        }
        else {
            srcType = UNKNOWN_FILE_T;
        }
    }

    if ( strcmp( argv[argc - 1], "i:" ) == 0 ) {
        destType = UNKNOWN_OBJ_T;
        strcpy( argv[argc - 1], "." );
    }
    else if ( strncmp( argv[argc - 1], "i:", 2 ) == 0 ) {
        destType = UNKNOWN_OBJ_T;
        snprintf( buffer, HUGE_NAME_LEN, "%s", argv[argc - 1] + 2 );
        argv[argc - 1] = strdup( argv[argc - 1] + 2 );
    }
    else {
        destType = UNKNOWN_FILE_T;
    }

    if ( srcType == UNKNOWN_FILE_T && destType == UNKNOWN_FILE_T ) {
        rodsLog( LOG_ERROR,
                 "Both source and destination cannot be local file type" );
        exit( 1 );
    }

    status = parseCmdLinePath( argc, argv, optind, &myEnv,
                               srcType, destType, 0, &rodsPathInp );

    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status, "main: parseCmdLinePath error. " );
        printf( "use -h for help.\n" );
        exit( 1 );
    }

    // =-=-=-=-=-=-=-
    // 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, 1, &errMsg );

    if ( conn == NULL ) {
        exit( 2 );
    }

    status = clientLogin( conn );
    if ( status != 0 ) {
        rcDisconnect( conn );
        exit( 7 );
    }

    status = rsyncUtil( conn, &myEnv, &myRodsArgs, &rodsPathInp );

    printErrorStack( conn->rError );
    rcDisconnect( conn );

    if ( status < 0 ) {
        exit( 3 );
    }
    else {
        exit( 0 );
    }

}