Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
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 );
}
Beispiel #4
0
/* #define SERVER_DEBUG 1   */
int
main( int, char ** ) {

    int status;
    rsComm_t rsComm;
    char *tmpStr;

    ProcessType = AGENT_PT;

    // capture server properties
    irods::server_properties& props = irods::server_properties::getInstance();
    irods::error result = props.capture_if_needed();
    if ( !result.ok() ) {
        irods::log( PASSMSG( "failed to read server configuration", result ) );
    }

#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, SIG_IGN );

    // register irods signal handlers
    register_handlers();
#endif

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

    memset( &rsComm, 0, sizeof( rsComm ) );
    rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) );

    status = initRsCommWithStartupPack( &rsComm, NULL );

    // =-=-=-=-=-=-=-
    // manufacture a network object for comms
    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( &rsComm, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    if ( status < 0 ) {
        sendVersion( net_obj, status, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    /* Handle option to log sql commands */
    tmpStr = getenv( SP_LOG_SQL );
    if ( tmpStr != NULL ) {
#ifdef 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 SYSLOG
    /* Open a connection to syslog */
    openlog( "rodsAgent", LOG_ODELAY | LOG_PID, LOG_DAEMON );
#endif
    status = getRodsEnv( &rsComm.myEnv );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    ret = setRECacheSaltFromEnv();
    if ( !ret.ok() ) {
        rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() );
        exit( 1 );
    }

    // =-=-=-=-=-=-=-
    // load server side pluggable api entries
    irods::api_entry_table&  RsApiTable   = irods::get_server_api_table();
    irods::pack_entry_table& ApiPackTable = irods::get_pack_table();
    ret = irods::init_api_table(
              RsApiTable,
              ApiPackTable,
              false );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }

    // =-=-=-=-=-=-=-
    // load client side pluggable api entries
    irods::api_entry_table&  RcApiTable = irods::get_client_api_table();
    ret = irods::init_api_table(
              RcApiTable,
              ApiPackTable,
              true );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }




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

    status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status );
        sendVersion( net_obj, 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( net_obj, status, 0, NULL, 0 );
            cleanupAndExit( status );
        }
    }

    // =-=-=-=-=-=-=-
    // handle negotiations with the client regarding TLS if requested
    // this scope block makes valgrind happy
    {
        std::string neg_results;
        ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
        if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
            irods::log( PASS( ret ) );
            // =-=-=-=-=-=-=-
            // send a 'we failed to negotiate' message here??
            // or use the error stack rule engine thingie
            irods::log( PASS( ret ) );
            sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
            cleanupAndExit( ret.code() );

        }
        else {
            // =-=-=-=-=-=-=-
            // copy negotiation results to comm for action by network objects
            snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() );
            //rsComm.ssl_do_accept = 1;

        }
    }

    /* send the server version and atatus as part of the protocol. Put
     * rsComm.reconnPort as the status */
    ret = sendVersion( net_obj, status, rsComm.reconnPort,
                       rsComm.reconnAddr, rsComm.cookie );

    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    logAgentProc( &rsComm );

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

    ret = sockAgentStart( new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_server( &rsComm );
    status = agentMain( &rsComm );

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

    new_net_obj->to_server( &rsComm );
    cleanup();
    free( rsComm.thread_ctx );
    free( rsComm.auth_scheme );
    rodsLog( LOG_NOTICE, "Agent exiting with status = %d", status );
    return status;
}
Beispiel #5
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;
    }
}
Beispiel #6
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);
}
Beispiel #7
0
    int
    getRodsEnvFromEnv( 
        rodsEnv* _env ) {
        if( !_env ) {
            printf( "ERROR - getRodsEnvFromEnv :: null rodsEnv\n" );
            fflush( stdout );
            return SYS_INVALID_INPUT_PARAM;
        }

        std::string env_var = irods::CFG_IRODS_USER_NAME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsUserName );

        env_var = irods::CFG_IRODS_HOST_KW;
        capture_string_env_var(
            env_var,
            _env->rodsHost );

        env_var = irods::CFG_IRODS_XMSG_HOST_KW;
        capture_string_env_var(
            env_var,
            _env->xmsgHost );

        env_var = irods::CFG_IRODS_PORT_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsPort );

        env_var = irods::CFG_IRODS_XMSG_PORT_KW;
        capture_integer_env_var(
            env_var,
            _env->xmsgPort );

        env_var = irods::CFG_IRODS_HOME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsHome );

        env_var = irods::CFG_IRODS_CWD_KW;
        capture_string_env_var(
            env_var,
            _env->rodsCwd );

        env_var = irods::CFG_IRODS_AUTHENTICATION_SCHEME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsAuthScheme );

        env_var = irods::CFG_IRODS_DEFAULT_RESOURCE_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDefResource );

        env_var = irods::CFG_IRODS_ZONE_KW;
        capture_string_env_var(
            env_var,
            _env->rodsZone );

        env_var = irods::CFG_IRODS_CLIENT_SERVER_POLICY_KW;
        capture_string_env_var(
            env_var,
            _env->rodsClientServerPolicy );

        env_var = irods::CFG_IRODS_CLIENT_SERVER_NEGOTIATION_KW;
        capture_string_env_var(
            env_var,
            _env->rodsClientServerNegotiation );

        env_var = irods::CFG_IRODS_ENCRYPTION_KEY_SIZE_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionKeySize );
        
        env_var = irods::CFG_IRODS_ENCRYPTION_SALT_SIZE_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionSaltSize );

        env_var = irods::CFG_IRODS_ENCRYPTION_NUM_HASH_ROUNDS_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionNumHashRounds );

        env_var = irods::CFG_IRODS_ENCRYPTION_ALGORITHM_KW;
        capture_string_env_var(
            env_var,
            _env->rodsEncryptionAlgorithm );

        env_var = irods::CFG_IRODS_DEFAULT_HASH_SCHEME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDefaultHashScheme );

        env_var = irods::CFG_IRODS_MATCH_HASH_POLICY_KW;
        capture_string_env_var(
            env_var,
            _env->rodsMatchHashPolicy );

        env_var = irods::CFG_IRODS_GSI_SERVER_DN_KW;
        capture_string_env_var(
            env_var,
            _env->rodsServerDn );

        _env->rodsLogLevel = 0;
        env_var = irods::CFG_IRODS_LOG_LEVEL_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsLogLevel );
        if ( _env->rodsLogLevel ) {
            rodsLogLevel( _env->rodsLogLevel ); /* go ahead and process it */
        }

        memset( _env->rodsAuthFileName, 0, sizeof( _env->rodsAuthFileName ) );
        env_var = irods::CFG_IRODS_AUTHENTICATION_FILE_NAME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsAuthFileName );
        if( strlen( _env->rodsAuthFileName ) > 0 ) {
            rstrcpy( authFileName, _env->rodsAuthFileName, LONG_NAME_LEN );

        }

        env_var = irods::CFG_IRODS_DEBUG_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDebug );

        return 0;
    }
Beispiel #8
0
    int getRodsEnvFromFile(
        rodsEnv* _env ) {
        if ( !_env ) {
            printf( "ERROR - getRodsEnv :: null rodsEnv\n" );
            fflush( stdout );
            return SYS_INVALID_INPUT_PARAM;
        }

        irods::environment_properties& props =
            irods::environment_properties::getInstance();
        irods::error ret = props.capture_if_needed();
        if ( !ret.ok() ) {
            // irods::log( PASS( ret ) );
            // legacy code doesnt error out
            // return  ret.code();
        }

        int msg_lvl = LOG_DEBUG;
        if ( getenv( PRINT_RODS_ENV_STR ) &&
                atoi( getenv( PRINT_RODS_ENV_STR ) ) ) {
            msg_lvl = LOG_NOTICE;
            unsetenv( PRINT_RODS_ENV_STR );
        }

        // default auth scheme
        snprintf(
            _env->rodsAuthScheme,
            sizeof( _env->rodsAuthScheme ),
            "native" );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SESSION_ENVIRONMENT_FILE_KW,
            configFileName );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_USER_NAME_KW,
            _env->rodsUserName );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_HOST_KW,
            _env->rodsHost );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_XMSG_HOST_KW,
            _env->xmsgHost );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_HOME_KW,
            _env->rodsHome );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_CWD_KW,
            _env->rodsCwd );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_AUTHENTICATION_SCHEME_KW,
            _env->rodsAuthScheme );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_PORT_KW,
            _env->rodsPort );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_XMSG_PORT_KW,
            _env->xmsgPort );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_DEFAULT_RESOURCE_KW,
            _env->rodsDefResource );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_ZONE_KW,
            _env->rodsZone );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_CLIENT_SERVER_POLICY_KW,
            _env->rodsClientServerPolicy );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_CLIENT_SERVER_NEGOTIATION_KW,
            _env->rodsClientServerNegotiation );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_ENCRYPTION_KEY_SIZE_KW,
            _env->rodsEncryptionKeySize );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_ENCRYPTION_SALT_SIZE_KW,
            _env->rodsEncryptionSaltSize );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_ENCRYPTION_NUM_HASH_ROUNDS_KW,
            _env->rodsEncryptionNumHashRounds );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_ENCRYPTION_ALGORITHM_KW,
            _env->rodsEncryptionAlgorithm );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_DEFAULT_HASH_SCHEME_KW,
            _env->rodsDefaultHashScheme );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_MATCH_HASH_POLICY_KW,
            _env->rodsMatchHashPolicy );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_GSI_SERVER_DN_KW,
            _env->rodsServerDn );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_DEBUG_KW,
            _env->rodsDebug );

        _env->rodsLogLevel = 0;
        int status = capture_integer_property(
                         msg_lvl,
                         props,
                         irods::CFG_IRODS_LOG_LEVEL_KW,
                         _env->rodsLogLevel );
        if ( status == 0 ) {
            rodsLogLevel( _env->rodsLogLevel );

        }

        memset( _env->rodsAuthFileName, 0, sizeof( _env->rodsAuthFileName ) );
        status = capture_string_property(
                     msg_lvl,
                     props,
                     irods::CFG_IRODS_AUTHENTICATION_FILE_NAME_KW,
                     _env->rodsAuthFileName );
        if ( status == 0 ) {
            rstrcpy(
                authFileName,
                _env->rodsAuthFileName,
                LONG_NAME_LEN - 1 );
        }

        // legacy ssl environment variables
        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_CA_CERTIFICATE_PATH,
            _env->irodsSSLCACertificatePath );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_CA_CERTIFICATE_FILE,
            _env->irodsSSLCACertificateFile );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_VERIFY_SERVER,
            _env->irodsSSLVerifyServer );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_CERTIFICATE_CHAIN_FILE,
            _env->irodsSSLCertificateChainFile );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_CERTIFICATE_KEY_FILE,
            _env->irodsSSLCertificateKeyFile );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SSL_DH_PARAMS_FILE,
            _env->irodsSSLDHParamsFile );

        // control plane variables
        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SERVER_CONTROL_PLANE_KEY,
            _env->irodsCtrlPlaneKey );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SERVER_CONOTROL_PLANE_ENCRYPTION_NUM_HASH_ROUNDS_KW,
            _env->irodsCtrlPlaneEncryptionNumHashRounds );

        capture_string_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SERVER_CONOTROL_PLANE_ENCRYPTION_ALGORITHM_KW,
            _env->irodsCtrlPlaneEncryptionAlgorithm );

        capture_integer_property(
            msg_lvl,
            props,
            irods::CFG_IRODS_SERVER_CONTROL_PLANE_PORT,
            _env->irodsCtrlPlanePort );

        return 0;
    }
Beispiel #9
0
int
main(int argc, char **argv)
{
    int status;
    int c;
    rsComm_t rsComm;
    int runMode = IRODS_SERVER;
    int flagval = 0;
    char *logDir = NULL;
    char *tmpStr;
    int logFd;
    char *ruleExecId = NULL;
    int jobType = 0;

    ProcessType = RE_SERVER_PT;

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

#ifndef _WIN32
    signal(SIGINT, signalExit);
    signal(SIGHUP, signalExit);
    signal(SIGTERM, signalExit);
    signal(SIGUSR1, signalExit);
    signal(SIGPIPE, rsPipSigalHandler);
    /* XXXXX switched to SIG_DFL for embedded python. child process 
     * went away. But probably have to call waitpid. 
     * signal(SIGCHLD, SIG_IGN); */
    signal(SIGCHLD, SIG_DFL);
#endif

    /* 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 */
    openlog("rodsReServer",LOG_ODELAY|LOG_PID,LOG_DAEMON);
#endif

    while ((c=getopt(argc, argv,"sSvD:j:t:")) != EOF) {
        switch (c) {
	    case 's':
		runMode = SINGLE_PASS;
		break;
	    case 'S':
		runMode = STANDALONE_SERVER;
		break;
            case 'v':   /* verbose */
                flagval |= v_FLAG;
                break;
            case 'D':   /* user specified a log directory */
		logDir = strdup (optarg);
		break;
	    case 'j':
		runMode = SINGLE_PASS;
		ruleExecId = strdup (optarg);
		break;
            case 't':
                jobType = atoi (optarg);
                break;
            default:
                usage (argv[0]);
                exit (1);
        }
    }

    status = initRsComm (&rsComm);

    if (status < 0) {
        cleanupAndExit (status);
    }

    if ((logFd = logFileOpen (runMode, logDir, RULE_EXEC_LOGFILE)) < 0) {
        exit (1);
    }

    daemonize (runMode, logFd);

#ifdef RULE_ENGINE_N
    status = initAgent (RULE_ENGINE_INIT_CACHE, &rsComm);
#else
    status = initAgent (&rsComm);
#endif
    if (status < 0) {
        cleanupAndExit (status);
    }

    if (ruleExecId != NULL) {
	status = reServerSingleExec (&rsComm, ruleExecId, jobType);
	if (status >= 0) {
            exit (0);
        } else {
             exit (1);
        }
    } else {
        reServerMain (&rsComm);
    }
    cleanupAndExit (status);

    exit (0);
}
Beispiel #10
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status, nArgs;
    rErrMsg_t errMsg;
    char userName[NAME_LEN];

    rodsArguments_t myRodsArgs;

    rodsLogLevel( LOG_ERROR );

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

    status = getRodsEnv( &myEnv );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "main: getRodsEnv error. status = %d",
                 status );
        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 ) {
        if ( !debug ) {
            exit( 3 );
        }
    }

    if ( myRodsArgs.user ) {
        snprintf( userName, sizeof( userName ), "%s", myRodsArgs.userString );
    }
    else {
        snprintf( userName, sizeof( userName ), "%s", myEnv.rodsUserName );
    }

    if ( myRodsArgs.all ) {
        userName[0] = '\0';
    }

    nArgs = argc - myRodsArgs.optind;

    if ( nArgs > 0 ) {
        if ( strncmp( argv[myRodsArgs.optind], "usage", 5 ) == 0 ) {
            status = showUserUsage( userName, myEnv.rodsZone );
        }
        else {
            usage();
        }
    }
    else {
        if ( userName[0] == '\0' ) {
            printf( "Resource quotas for users:\n" );
        }
        else {
            printf( "Resource quotas for user %s:\n", userName );
        }
        status = showQuotas( userName, 0, 0 ); /* users, resc */

        if ( userName[0] == '\0' ) {
            printf( "Global (total) quotas for users:\n" );
        }
        else {
            printf( "Global (total) quotas for user %s:\n", userName );
        }
        status = showQuotas( userName, 0, 1 ); /* users, global */

        printf( "Group quotas on resources:\n" );
        status = showQuotas( "", 1, 0 );     /* all groups, resc */

        printf( "Group global (total) quotas:\n" );
        status = showQuotas( "", 1, 1 );     /* all groups, global */

        if ( userName[0] != '\0' ) {
            status = showUserGroupMembership( userName, myEnv.rodsZone );
        }
    }
    if ( quotaTime[0] != '\0' ) {
        printf( "Information was set at %s\n", quotaTime );
    }

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

    exit( 0 );
}
Beispiel #11
0
int
main(int argc, char **argv) {
   int status;
   rsComm_t *Comm;
   /*   rErrMsg_t errMsg;*/
   rodsArguments_t myRodsArgs;
   char *mySubName;
   char *myName;
   int didOne;
   rodsServerConfig_t serverConfig;

   Comm = (rsComm_t*)malloc (sizeof (rsComm_t));
   memset (Comm, 0, sizeof (rsComm_t));

   parseCmdLineOpt(argc, argv, "", 0, &myRodsArgs);

   rodsLogLevel(LOG_NOTICE);

   rodsLogSqlReq(1);

   if (argc < 2) {
      printf("Usage: test_chl testName [args...]\n");
      exit(3);
   }

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

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

   memset(&serverConfig, 0, sizeof(serverConfig));
   status = readServerConfig(&serverConfig);

   strncpy(Comm->clientUser.userName, myEnv.rodsUserName, 
	   sizeof Comm->clientUser.userName);

   strncpy(Comm->clientUser.rodsZone, myEnv.rodsZone, 
	   sizeof Comm->clientUser.rodsZone);

   /*
   char rodsUserName[NAME_LEN];
   char rodsZone[NAME_LEN];

     userInfo_t clientUser;
    char userName[NAME_LEN];
    char rodsZone[NAME_LEN];
   */
   if ((status = chlOpen(serverConfig.DBUsername,
			 serverConfig.DBPassword)) != 0) {
        rodsLog (LOG_SYS_FATAL,
		 "initInfoWithRcat: chlopen Error. Status = %d",
		 status);
        free(Comm); // cppcheck - Memory leak: Comm
        return (status);
   }

   didOne=0;
   if (strcmp(argv[1],"reg")==0) {
      status = testRegDataObj(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }
   if (strcmp(argv[1],"regmulti")==0) {
      status = testRegDataMulti(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod")==0) {
      status = testModDataObjMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod2")==0) {
      status = testModDataObjMeta2(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modr")==0) {
      status = testModRuleMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modc")==0) {
      status = testModColl(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmrule")==0) {
      status = testDelRule(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"modrfs")==0) { 
      status = testModResourceFreeSpace(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rep")==0) {
      if (argc < 6) {
	 printf("too few arguments\n");
	 exit(1);
      }
      status = testRegReplica(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   /*
   if (strcmp(argv[1],"cml")==0) {
      status = testCml(Comm);
      didOne=1;
   }
   */

   if (strcmp(argv[1],"rmuser")==0) {
      status = testDelUser(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"mkdir")==0) {
      status = testRegColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmdir")==0) {
      status = testDelColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"sql")==0) {
      status = testSimpleQ(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rm")==0) {
      status = testDelFile(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmtrash")==0) {
      status = testDelFileTrash(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmpriv")==0) {
      status = testDelFilePriv(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"chmod")==0) {
      status = testChmod(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"regrule")==0) {
      status = testRegRule(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rename")==0) {
      status = testRename(Comm, argv[2], argv[3]);
      testCurrent(Comm);  /* exercise this as part of rename;
                             testCurrent needs a SQL context */
      didOne=1;
   }

   if (strcmp(argv[1],"login")==0) {
      status = testLogin(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"move")==0) {
      status = testMove(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkauth")==0) {
      status = testCheckAuth(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"temppw")==0) {
      status = testTempPw(Comm);
      didOne=1;
   }

   if (strcmp(argv[1],"tpc")==0) {
      status = testTempPwConvert(argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpw")==0) {
      status = testTempPwCombined(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpwforother")==0) {
      status = testTempPwForOther(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverload")==0) {
      status = testServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgeload")==0) {
      status = testPurgeServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverdigest")==0) {
      status = testServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgedigest")==0) {
      status = testPurgeServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkquota")==0) {
      if (argc < 5) {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 NULL, NULL);
      }
      else {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 argv[4], argv[5]);
      }
      didOne=1;
   }

   if (strcmp(argv[1],"open")==0) {
      int i;
      for (i=0;i<3;i++) {
	 status = chlClose();
	 if (status) {
	    printf ("close %d error", i);
	 }
      
	 if ((status = chlOpen(serverConfig.DBUsername,
			       serverConfig.DBPassword)) != 0) {
	    rodsLog (LOG_SYS_FATAL,
		     "initInfoWithRcat: chlopen %d Error. Status = %d",
		     i, status);
	    return (status);
	 }
      }
      didOne=1;
   }

   if (strcmp(argv[1],"addrule")==0) {
     status = testAddRule(Comm, argv[2], argv[3],
			     argv[4], argv[5],
			  argv[6], argv[7]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionrulebase")==0) {
     status = testVersionRuleBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versiondvmbase")==0) {
     status = testVersionDvmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionfnmbase")==0) {
     status = testVersionFnmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"insfnmtable")==0) {
      status = testInsFnmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insdvmtable")==0) {
      status = testInsDvmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insmsrvctable")==0) {
      status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			       argv[6], argv[7], argv[8], argv[9], argv[10]);
      if (status==0) {
	/* do it a second time to test another logic path and
           different SQL.  Since no commit is part of the chl
           function, and there is not corresponding Delete call, this
           is an easy way to do this. */
	status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			   argv[6], argv[7], argv[8], argv[9], argv[10]);
      }
     didOne=1;
   }
   if (strcmp(argv[1],"getlocalzone")==0) {
      status = testGetLocalZone(Comm, argv[2]);
      didOne=1;
   }
   if (strcmp(argv[1],"getpampw")==0) {
      status = testGetPamPw(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (status != 0) {
      /*
      if (Comm->rError) {
	 rError_t *Err;
         rErrMsg_t *ErrMsg;
	 int i, len;
	 Err = Comm->rError;
	 len = Err->len;
	 for (i=0;i<len;i++) {
	    ErrMsg = Err->errMsg[i];
	    rodsLog(LOG_ERROR, "Level %d: %s",i, ErrMsg->msg);
	 }
      }
      */
      myName = rodsErrorName(status, &mySubName);
      rodsLog (LOG_ERROR, "%s failed with error %d %s %s", argv[1],
	       status, myName, mySubName);
   }
   else {
      if (didOne) printf("Completed successfully\n");
   }

   if (didOne==0) {
      printf("Unknown test type: %s\n", argv[1]);
   }

   exit(status);
}
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status, nArgs;
    rErrMsg_t errMsg;

    rodsArguments_t myRodsArgs;

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

    status = getRodsEnv( &myEnv );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "main: getRodsEnv error. status = %d",
                 status );
        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 ) {
        if ( !debug ) {
            exit( 3 );
        }
    }

    nArgs = argc - myRodsArgs.optind;

    if ( nArgs == 1 ) {
        status = showUser(argv[myRodsArgs.optind]);
    }
    else {
        const auto user_name{(boost::format("%s#%s") %
                              myEnv.rodsUserName % myEnv.rodsZone).str().c_str()};
        status = showUser(user_name);
    }

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

    exit( status );
}
// currently only written to support iput.  needs to be expanded to
// support the full range of icommand options
static int parse_program_options(
    int              _argc,
    char**           _argv,
    rodsArguments_t& _rods_args,
    path_list_t&     _paths ) {
    namespace po = boost::program_options;

    po::options_description opt_desc( "options" );
    opt_desc.add_options()
    ( "help,h", "show command usage" )
    ( "all,a", "all - update all existing copies" )
    ( "bulk,b", "bulk upload to reduce overhead" )
    ( "force,f", "force - write data-object even it exists already; overwrite it" )
    ( "redirect,I", "redirect connection - redirect the connection to connect directly to the resource server." )
    ( "checksum,k", "checksum - calculate a checksum on the data server-side, and store it in the catalog" )
    ( "verify_checksum,K", "verify checksum - calculate and verify the checksum on the data, both client-side and server-side, without storing in the catalog." )
    ( "repl_num,n", po::value<std::string>(), "replNum  - the replica to be replaced, typically not needed" )
    ( "num_threads,N", po::value<int>(), "numThreads - the number of threads to use for the transfer. A value of 0 means no threading. By default (-N option not used) the server decides the number of threads to use.")
    ( "physical_path,p", po::value<std::string>(), "physicalPath - the absolute physical path of the uploaded file on the server" )
    ( "progress,P", "output the progress of the upload." )
    ( "rbudp,Q", "use RBUDP (datagram) protocol for the data transfer" )
    ( "recursive,r", "recursive - store the whole subdirectory" )
    ( "dest_resc,R", po::value<std::string>(), "resource - specifies the resource to store to. This can also be specified in your environment or via a rule set up by the administrator" )
    ( "ticket,t", po::value<std::string>(), "ticket - ticket (string) to use for ticket-based access" )
    ( "renew_socket,T", "renew socket connection after 10 minutes" )
    ( "verbose,v", "verbose" )
    ( "very_verbose,V", "very verbose" )
    ( "data_type,D", po::value<std::string>(), "dataType - the data type string" )
    ( "restart_file,X", po::value<std::string>(), "restartFile - specifies that the restart option is on and the restartFile input specifies a local file that contains the restart information." )
    ( "link", "ignore symlink." )
    ( "lfrestart", po::value<std::string>(), "lfRestartFile - specifies that the large file restart option is on and the lfRestartFile input specifies a local file that contains the restart information." )
    ( "retries", po::value<int>(), "count - Retry the iput in case of error. The 'count' input specifies the number of times to retry. It must be used with the -X option" )
    ( "wlock", "use advisory write (exclusive) lock for the upload" )
    ( "rlock", "use advisory read lock for the download" )
    ( "purgec", "Purge the staged cache copy after uploading an object to a" )
    ( "kv_pass", po::value<std::string>(), "pass key-value strings through to the plugin infrastructure" )
    ( "metadata", po::value<std::string>(), "atomically assign metadata after a data object is put" )
    ( "acl", po::value<std::string>(), "atomically apply an access control list after a data object is put" )
    ( "path_args", po::value<path_list_t>(&_paths)->composing(), "some files and stuffs" );

    po::positional_options_description pos_desc;
    pos_desc.add( "path_args", -1 );

    try {
        po::store(
            po::command_line_parser(
                _argc, _argv ).options(
                opt_desc ).positional(
                pos_desc ).run(), global_prog_ops_var_map );
        po::notify( global_prog_ops_var_map );
    }
    catch ( po::error& _e ) {
        std::cout << std::endl
                  << "Error: "
                  << _e.what()
                  << std::endl
                  << std::endl;
        usage();
        return -1;

    }

    // path args are passed out in a separate parameter
    //if( global_prog_ops_var_map.count( "path_args" ) ) {
    //}

    memset( &_rods_args, 0, sizeof( _rods_args ) );
    if( global_prog_ops_var_map.count( "help" ) ) {
        usage();
        return -1;
    }
    if( global_prog_ops_var_map.count( "all" ) ) {
        _rods_args.all = 1;
    }
    if( global_prog_ops_var_map.count( "bulk" ) ) {
        _rods_args.bulk = 1;
    }
    if( global_prog_ops_var_map.count( "force" ) ) {
        _rods_args.bulk = 1;
    }
    if( global_prog_ops_var_map.count( "force" ) ) {
        _rods_args.force = 1;
    }
    if( global_prog_ops_var_map.count( "redirect" ) ) {
        _rods_args.redirectConn = 1;
    }
    if( global_prog_ops_var_map.count( "checksum" ) ) {
        _rods_args.checksum = 1;
    }
    if( global_prog_ops_var_map.count( "verify_checksum" ) ) {
        _rods_args.verifyChecksum = 1;
    }
    if( global_prog_ops_var_map.count( "" ) ) {
        _rods_args.verifyChecksum = 1;
    }
    if( global_prog_ops_var_map.count( "repl_num" ) ) {
        _rods_args.replNum = 1;
        try {
            _rods_args.replNumValue = (char*)global_prog_ops_var_map[ "repl_num" ].as<std::string>().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "num_threads" ) ) {
        _rods_args.number = 1;
        try {
            _rods_args.numberValue = global_prog_ops_var_map[ "num_threads" ].as<int>();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "physical_path" ) ) {
        _rods_args.physicalPath = 1;
        try {
            _rods_args.physicalPathString = (char*)global_prog_ops_var_map[ "physical_path" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "progress" ) ) {
        _rods_args.progressFlag = 1;
    }
    if( global_prog_ops_var_map.count( "rbudp" ) ) {
        _rods_args.rbudp = 1;
    }
    if( global_prog_ops_var_map.count( "recursive" ) ) {
        _rods_args.recursive = 1;
    }
    if( global_prog_ops_var_map.count( "dest_resc" ) ) {
        _rods_args.resource = 1;
        try {
            _rods_args.resourceString = (char*)global_prog_ops_var_map[ "dest_resc" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "ticket" ) ) {
        _rods_args.ticket = 1;
        try {
            _rods_args.ticketString = (char*)global_prog_ops_var_map[ "ticket" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "renew_socket" ) ) {
        _rods_args.reconnect = 1;
    }
    if( global_prog_ops_var_map.count( "verbose" ) ) {
        _rods_args.verbose = 1;
    }
    if( global_prog_ops_var_map.count( "very_verbose" ) ) {
        _rods_args.verbose = 1;
        _rods_args.veryVerbose = 1;
        rodsLogLevel( LOG_NOTICE );
    }
    if( global_prog_ops_var_map.count( "data_type" ) ) {
        _rods_args.dataType = 1;
        try {
            _rods_args.dataTypeString = (char*)global_prog_ops_var_map[ "data_type" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "restart_file" ) ) {
        _rods_args.restart = 1;
        try {
            _rods_args.restartFileString = (char*)global_prog_ops_var_map[ "restart_file" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "link" ) ) {
        _rods_args.link = 1;
    }
    if( global_prog_ops_var_map.count( "lfrestart" ) ) {
        _rods_args.lfrestart = 1;
        try {
            _rods_args.lfrestartFileString = (char*)global_prog_ops_var_map[ "lfrestart" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "retries" ) ) {
        _rods_args.retries = 1;
        try {
            _rods_args.retriesValue = global_prog_ops_var_map[ "retries" ].as< int >();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "wlock" ) ) {
        _rods_args.wlock = 1;
    }
    if( global_prog_ops_var_map.count( "rlock" ) ) {
        _rods_args.rlock = 1;
    }
    if( global_prog_ops_var_map.count( "purgec" ) ) {
        _rods_args.purgeCache = 1;
    }
    if( global_prog_ops_var_map.count( "kv_pass" ) ) {
        _rods_args.kv_pass = 1;
        try {
            _rods_args.kv_pass_string = (char*)global_prog_ops_var_map[ "kv_pass" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "metadata" ) ) {
        try {
            _rods_args.metadata_string = (char*)global_prog_ops_var_map[ "metadata" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }
    if( global_prog_ops_var_map.count( "acl" ) ) {
        try {
            _rods_args.acl_string = (char*)global_prog_ops_var_map[ "acl" ].as< std::string >().c_str();
        }
        catch ( const boost::bad_any_cast& ) {
            return INVALID_ANY_CAST;
        }
    }

    return 0;

} // parse_program_options
Beispiel #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);
}
Beispiel #15
0
int
main(int argc, char **argv)
{
    int i, ix, status;
    int echoFlag=0;
    char *password;
    rodsEnv myEnv;
    rcComm_t *Conn;
    rErrMsg_t errMsg;
    rodsArguments_t myRodsArgs;
    int useGsi=0;
    int doPassword;
    int pamMode=0;
    char ttybuf[TTYBUF_LEN];
    int doingEnvFileUpdate=0;
    char updateText[UPDATE_TEXT_LEN]="";
    int ttl=0;

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

    if (myRodsArgs.echo==True) {
       echoFlag=1;
    }

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

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

    if (myRodsArgs.ttl==True) {
      ttl = myRodsArgs.ttlValue;
      if (ttl < 1) {
	printf("Time To Live value needs to be a positive integer\n");
	exit(1);
      }
    }

#ifdef TIME_TO_LIVE_REQUIRED 
    if (myRodsArgs.ttl!=True) {
#ifdef TIME_TO_LIVE_DEFAULT
       ttl=TIME_TO_LIVE_DEFAULT;
       printf("Notice: using default TTL (time to live) value of %d hours\n",
	      ttl);
#else
       printf("--ttl (Time To Live) is required, please try again\n");
       exit(2);
#endif /* TIME_TO_LIVE_DEFAULT */
    }
#endif /* TIME_TO_LIVE_REQUIRED */

    ix = myRodsArgs.optind;

    password="";
    if (ix < argc) {
       password = argv[ix];
    }

    if (myRodsArgs.longOption==True) {
	/* just list the env */
	exit (0);
    }

/*
 Create ~/.irods/ if it does not exist
 */
    mkrodsdir(); 

 /*
    Check on the key Environment values, prompt and save
    them if not already available.
  */
    if (myEnv.rodsHost == NULL || strlen(myEnv.rodsHost)==0) {
       int i;
       if (doingEnvFileUpdate==0) {
	  doingEnvFileUpdate=1;
	  printUpdateMsg();
       }
       printf("Enter the host name (DNS) of the server to connect to:");
       memset(ttybuf, 0, TTYBUF_LEN);
       fgets(ttybuf, TTYBUF_LEN, stdin);
       rstrcat(updateText,"irodsHost ", UPDATE_TEXT_LEN);
       rstrcat(updateText,ttybuf, UPDATE_TEXT_LEN);
       i = strlen(ttybuf);
       if (i>0) ttybuf[i-1]='\0'; /* chop off trailing \n */
       strncpy(myEnv.rodsHost, ttybuf, NAME_LEN);
    }
    if (myEnv.rodsPort == 0) {
       int i;
       if (doingEnvFileUpdate==0) {
	  doingEnvFileUpdate=1;
	  printUpdateMsg();
       }
       printf("Enter the port number:");
       memset(ttybuf, 0, TTYBUF_LEN);
       fgets(ttybuf, TTYBUF_LEN, stdin);
       rstrcat(updateText,"irodsPort ", UPDATE_TEXT_LEN);
       rstrcat(updateText,ttybuf, UPDATE_TEXT_LEN);
       i = strlen(ttybuf);
       if (i>0) ttybuf[i-1]='\0';
       myEnv.rodsPort = atoi(ttybuf);
    }
    if (myEnv.rodsUserName == NULL || strlen(myEnv.rodsUserName)==0) {
       int i;
       if (doingEnvFileUpdate==0) {
	  doingEnvFileUpdate=1;
	  printUpdateMsg();
       }
       printf("Enter your irods user name:");
       memset(ttybuf, 0, TTYBUF_LEN);
       fgets(ttybuf, TTYBUF_LEN, stdin);
       rstrcat(updateText,"irodsUserName ", UPDATE_TEXT_LEN);
       rstrcat(updateText,ttybuf, UPDATE_TEXT_LEN);
       i = strlen(ttybuf);
       if (i>0) ttybuf[i-1]='\0';
       strncpy(myEnv.rodsUserName, ttybuf, NAME_LEN);
    }
    if (myEnv.rodsZone == NULL || strlen(myEnv.rodsZone)==0) {
       int i;
       if (doingEnvFileUpdate==0) {
	  doingEnvFileUpdate=1;
	  printUpdateMsg();
       }
       printf("Enter your irods zone:");
       memset(ttybuf, 0, TTYBUF_LEN);
       fgets(ttybuf, TTYBUF_LEN, stdin);
       rstrcat(updateText,"irodsZone ", UPDATE_TEXT_LEN);
       rstrcat(updateText,ttybuf, UPDATE_TEXT_LEN);
       i = strlen(ttybuf);
       if (i>0) ttybuf[i-1]='\0';
       strncpy(myEnv.rodsZone, ttybuf, NAME_LEN);
    }
    #if defined(PAM_AUTH) || defined(GSI_AUTH)
    if (myEnv.rodsAuthScheme == NULL || strlen(myEnv.rodsAuthScheme)==0) {
       int authTypes=0,OK;
       if (doingEnvFileUpdate==1) { /* don't bother if authScheme is
                                       the only one missing; assume
                                       that password is what they want */
#if defined(PAM_AUTH)
       authTypes=1;    /* PAM */
#endif
#if defined(GSI_AUTH)
       if (authTypes==1) {
          authTypes=3; /* PAM and GSI */
       }
       else {
          authTypes=2; /* GSI */
       }
#endif
          if (authTypes==1) {
             printf("Enter your authentication method (password or PAM):");
          }
          if (authTypes==2) {
             printf("Enter your authentication method (password or GSI):");
          }
          if (authTypes==3) {
             printf("Enter your authentication method (password, GSI, or PAM):");
          }
          memset(ttybuf, 0, TTYBUF_LEN);
          fgets(ttybuf, TTYBUF_LEN, stdin);
          OK=-1;
          if (strncmp("GSI",ttybuf,3)==0) {OK=1; ttybuf[3]='\0';}
          if (strncmp("PAM",ttybuf,3)==0) {OK=2; ttybuf[3]='\0';}
          if (strncmp("password",ttybuf,8)==0) {OK=3; ttybuf[8]='\0';}
          if (OK < 0) {
             printf("Warning, invalid authentication type, ignoring\n");
          }
          if (OK > 0) {
             rstrcat(updateText,"irodsAuthScheme ", UPDATE_TEXT_LEN);
             rstrcat(updateText,ttybuf, UPDATE_TEXT_LEN);
             strncpy(myEnv.rodsAuthScheme, ttybuf, NAME_LEN);
          }
       }
    }
#endif
    if (doingEnvFileUpdate) {
       printf("Those values will be added to your environment file (for use by\n");
       printf("other i-commands) if the login succeeds.\n\n");
    }

    /*
      Now, get the password
     */
    doPassword=1;
#if defined(GSI_AUTH)
    if (strncmp("GSI",myEnv.rodsAuthScheme,3)==0) {
       useGsi=1;
       doPassword=0;
    }
#endif
    if (strncmp("PAM",myEnv.rodsAuthScheme,3)==0 ||
	strncmp("pam",myEnv.rodsAuthScheme,3)==0) {
#if defined(PAM_AUTH)
       doPassword=0;
#else 
       rodsLog (LOG_ERROR,
	    "PAM_AUTH_NOT_BUILT_INTO_CLIENT, will try iRODS password",
	     status);
#endif
    }

    if (strcmp(myEnv.rodsUserName, ANONYMOUS_USER)==0) {
       doPassword=0;
    }
    if (useGsi==1) {
       printf("Using GSI, attempting connection/authentication\n");
    }
    if (doPassword==1) {
       if (myRodsArgs.verbose==True) {
	  i = obfSavePw(echoFlag, 1, 1, password);
       }
       else {
	  i = obfSavePw(echoFlag, 0, 0, password);
       }

       if (i != 0) {
	  rodsLogError(LOG_ERROR, i, "Save Password failure");
	  exit(1);
       }
    }

    /* Connect... */ 
    Conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
      myEnv.rodsZone, 0, &errMsg);
    if (Conn == NULL) {
       rodsLog(LOG_ERROR, 
		    "Saved password, but failed to connect to server %s",
	       myEnv.rodsHost);
       exit(2);
    }

#ifdef PAM_AUTH
    if (strncmp("PAM",myEnv.rodsAuthScheme,3)==0 ||
	strncmp("pam",myEnv.rodsAuthScheme,3)==0) {
       status = clientLoginPam(Conn, password, ttl);
       if (status != 0) exit(8);
       /* if this succeeded, do the regular login below to check that the
	generated password works properly.  */
       pamMode=1;
    }
#endif
    /* and check that the user/password is OK */
    status = clientLogin(Conn);
    if (status != 0) {
       rcDisconnect(Conn);
       exit (7);
    }

    printErrorStack(Conn->rError);

    if (ttl>0 && pamMode==0) {
       /* if doing non-PAM TTL, now get the 
	short-term password (after initial login) */
       status = clientLoginTTL(Conn, ttl);
       if (status != 0) {
	  rcDisconnect(Conn);
	  exit(8);
       }

       /* And check that it works */
       status = clientLogin(Conn);
       if (status != 0) {
	  rcDisconnect(Conn);
	  exit (7);
       }
    }

    rcDisconnect(Conn);

    /* Save updates to .irodsEnv. */
    if (doingEnvFileUpdate==1) {
       appendRodsEnv(updateText);
    }

    exit (0);
}
Beispiel #16
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);
  }
}
Beispiel #17
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rErrMsg_t errMsg;
    rodsArguments_t myRodsArgs;
    int argOffset;
    int i;

    rodsLogLevel( LOG_ERROR ); /* This should be the default someday */

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

    if ( myRodsArgs.all || myRodsArgs.user ) {
        if ( argc > argOffset ) {
            /* should not have any input */
            usage();
            exit( -1 );
        }
    }
    else if ( argc <= argOffset ) {
        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 );
        }
    }

    if ( myRodsArgs.all ) {
        status = qdelUtil( Conn, NULL, myRodsArgs.all, &myRodsArgs );
    }
    else if ( myRodsArgs.user ) {
        status = qdelUtil( Conn, myRodsArgs.userString, myRodsArgs.all, &myRodsArgs );
    }
    else {
        for ( i = argOffset; i < argc; i++ ) {
            status = rmDelayedRule( argv[i] );
        }
    }

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

    if ( status ) {
        exit( 4 );
    }
    exit( 0 );
}
Beispiel #18
0
    int
    getRodsEnvFromEnv(
        rodsEnv* _env ) {
        if ( !_env ) {
            printf( "ERROR - getRodsEnvFromEnv :: null rodsEnv\n" );
            fflush( stdout );
            return SYS_INVALID_INPUT_PARAM;
        }

        int status = get_legacy_ssl_variables( _env );
        if ( status < 0 ) {
            return status;

        }

        std::string env_var = irods::CFG_IRODS_USER_NAME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsUserName );

        env_var = irods::CFG_IRODS_HOST_KW;
        capture_string_env_var(
            env_var,
            _env->rodsHost );

        env_var = irods::CFG_IRODS_XMSG_HOST_KW;
        capture_string_env_var(
            env_var,
            _env->xmsgHost );

        env_var = irods::CFG_IRODS_PORT_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsPort );

        env_var = irods::CFG_IRODS_XMSG_PORT_KW;
        capture_integer_env_var(
            env_var,
            _env->xmsgPort );

        env_var = irods::CFG_IRODS_HOME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsHome );

        env_var = irods::CFG_IRODS_CWD_KW;
        capture_string_env_var(
            env_var,
            _env->rodsCwd );

        env_var = irods::CFG_IRODS_AUTHENTICATION_SCHEME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsAuthScheme );

        env_var = irods::CFG_IRODS_DEFAULT_RESOURCE_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDefResource );

        env_var = irods::CFG_IRODS_ZONE_KW;
        capture_string_env_var(
            env_var,
            _env->rodsZone );

        env_var = irods::CFG_IRODS_CLIENT_SERVER_POLICY_KW;
        capture_string_env_var(
            env_var,
            _env->rodsClientServerPolicy );

        env_var = irods::CFG_IRODS_CLIENT_SERVER_NEGOTIATION_KW;
        capture_string_env_var(
            env_var,
            _env->rodsClientServerNegotiation );

        env_var = irods::CFG_IRODS_ENCRYPTION_KEY_SIZE_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionKeySize );

        env_var = irods::CFG_IRODS_ENCRYPTION_SALT_SIZE_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionSaltSize );

        env_var = irods::CFG_IRODS_ENCRYPTION_NUM_HASH_ROUNDS_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsEncryptionNumHashRounds );

        env_var = irods::CFG_IRODS_ENCRYPTION_ALGORITHM_KW;
        capture_string_env_var(
            env_var,
            _env->rodsEncryptionAlgorithm );

        env_var = irods::CFG_IRODS_DEFAULT_HASH_SCHEME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDefaultHashScheme );

        env_var = irods::CFG_IRODS_MATCH_HASH_POLICY_KW;
        capture_string_env_var(
            env_var,
            _env->rodsMatchHashPolicy );

        env_var = irods::CFG_IRODS_GSI_SERVER_DN_KW;
        capture_string_env_var(
            env_var,
            _env->rodsServerDn );

        _env->rodsLogLevel = 0;
        env_var = irods::CFG_IRODS_LOG_LEVEL_KW;
        capture_integer_env_var(
            env_var,
            _env->rodsLogLevel );
        if ( _env->rodsLogLevel ) {
            rodsLogLevel( _env->rodsLogLevel ); /* go ahead and process it */
        }

        memset( _env->rodsAuthFileName, 0, sizeof( _env->rodsAuthFileName ) );
        env_var = irods::CFG_IRODS_AUTHENTICATION_FILE_NAME_KW;
        capture_string_env_var(
            env_var,
            _env->rodsAuthFileName );
        if ( strlen( _env->rodsAuthFileName ) > 0 ) {
            rstrcpy( authFileName, _env->rodsAuthFileName, LONG_NAME_LEN );

        }

        env_var = irods::CFG_IRODS_DEBUG_KW;
        capture_string_env_var(
            env_var,
            _env->rodsDebug );

        // legacy ssl environment variables
        env_var = irods::CFG_IRODS_SSL_CA_CERTIFICATE_PATH;
        capture_string_env_var(
            env_var,
            _env->irodsSSLCACertificatePath );
        env_var = irods::CFG_IRODS_SSL_CA_CERTIFICATE_FILE;
        capture_string_env_var(
            env_var,
            _env->irodsSSLCACertificateFile );
        env_var = irods::CFG_IRODS_SSL_VERIFY_SERVER;
        capture_string_env_var(
            env_var,
            _env->irodsSSLVerifyServer );
        env_var = irods::CFG_IRODS_SSL_VERIFY_SERVER;
        capture_string_env_var(
            env_var,
            _env->irodsSSLVerifyServer );
        env_var = irods::CFG_IRODS_SSL_CERTIFICATE_CHAIN_FILE;
        capture_string_env_var(
            env_var,
            _env->irodsSSLCertificateChainFile );
        env_var = irods::CFG_IRODS_SSL_CERTIFICATE_KEY_FILE;
        capture_string_env_var(
            env_var,
            _env->irodsSSLCertificateKeyFile );
        env_var = irods::CFG_IRODS_SSL_DH_PARAMS_FILE;
        capture_string_env_var(
            env_var,
            _env->irodsSSLDHParamsFile );

        return 0;
    }
Beispiel #19
0
int
main( int argc, char **argv ) {
    int c;
    int runMode = SERVER;
    int flagval = 0;
    char *logDir = NULL;
    char *tmpStr;
    int logFd;

    ProcessType = XMSG_SERVER_PT;

    // capture server properties
    try {
        irods::server_properties::instance().capture_if_needed();
    }
    catch ( const irods::exception& e ) {
        rodsLog( LOG_ERROR, e.what() );
        return e.code();
    }

#ifndef _WIN32
    signal( SIGINT, signalExit );
    signal( SIGHUP, signalExit );
    signal( SIGTERM, signalExit );
    signal( SIGUSR1, signalExit );
    signal( SIGPIPE, rsPipeSignalHandler );
#endif

    /* Handle option to log sql commands */
    tmpStr = getenv( SP_LOG_SQL );
    if ( tmpStr != NULL ) {
        rodsLogSqlReq( 1 );
    }

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

    while ( ( c = getopt( argc, argv, "sSc:vD:" ) ) != EOF ) {
        switch ( c ) {
        case 's':
            runMode = SINGLE_PASS;
            break;
        case 'S':
            runMode = STANDALONE_SERVER;
            break;
        case 'v':   /* verbose */
            flagval |= v_FLAG;
            break;
        case 'c':
            loopCnt = atoi( optarg );
            break;
        case 'D':   /* user specified a log directory */
            logDir = strdup( optarg );
            break;
        default:
            usage( argv[0] );
            exit( 1 );
        }
    }

    if ( ( logFd = logFileOpen( runMode, logDir, XMSG_SVR_LOGFILE ) ) < 0 ) {
        exit( 1 );
    }

    irods::error ret = setRECacheSaltFromEnv();
    if ( !ret.ok() ) {
        rodsLog( LOG_ERROR, "irodsXmsgServer::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() );
        exit( 1 );
    }

    daemonize( runMode, logFd );

    xmsgServerMain();
    sleep( 5 );
    exit( 0 );
}
Beispiel #20
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 );
}
Beispiel #21
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 );
}
Beispiel #22
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);
}
Beispiel #23
0
int
main(int argc, char **argv) {
   int mode;
   rodsServerConfig_t serverConfig;
   int status;
   rodsEnv myEnv;

   /* 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);

   mode = 0;
   if (strcmp(argv[1],"1")==0) mode=1;
   if (strcmp(argv[1],"2")==0) mode=2;
   if (strcmp(argv[1],"3")==0) mode=3;
   if (strcmp(argv[1],"4")==0) mode=4;
   if (strcmp(argv[1],"5")==0) mode=5;
   if (strcmp(argv[1],"6")==0) mode=6;

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

   memset(&serverConfig, 0, sizeof(serverConfig));
   status = readServerConfig(&serverConfig);

   if ((status = chlOpen(serverConfig.DBUsername,
			 serverConfig.DBPassword)) != 0) {
      rodsLog (LOG_SYS_FATAL,
	       "chlopen Error. Status = %d",
	       status);
      return (status);
   }
   if (mode==1) {
      status = doTest1(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==2) {
      status = doTest2(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==3) {
      status = doTest3(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==4) {
      status = doTest4(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==5) {
      status = doTest5(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==6) {
      status = doTest6(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   exit(0);
}