Example #1
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;

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

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

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

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

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

    signal( SIGPIPE, SIG_IGN );


    const char * optStr = "ah";
    rodsArguments_t myRodsArgs;
    int status = parseCmdLineOpt( argc, argv, optStr, 0, &myRodsArgs );

    if ( status < 0 ) {
        printf( "Use -h for help\n" );
        return 1;
    }

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

    if ( myRodsArgs.all == True ) {
        for ( unsigned int i = 0; i < sizeof( icmds ) / sizeof( icmds[0] ); ++i ) {
            std::string myExe( icmds[i] );
            myExe += " -h";
            status = system( myExe.c_str() );
            if ( status ) {
                printf( "error %d running %s\n", status, myExe.c_str() );
            }
        }
        return 0;
    }

    if ( argc == 1 ) {
        printMainHelp();
    }
    else if ( argc == 2 ) {
        for ( unsigned int i = 0; i < sizeof( icmds ) / sizeof( icmds[0] ); ++i ) {
            if ( strcmp( argv[1], icmds[i] ) == 0 ) {
                std::string myExe( icmds[i] );
                myExe += " -h";
                status = system( myExe.c_str() );
                if ( status ) {
                    printf( "error %d running %s\n", status, myExe.c_str() );
                }
                return 0;
            }
        }
        printf( "%s is not an iCommand\n", argv[1] );
    }

    return 0;
}
Example #3
0
int
main( int argc, char **argv ) {
    int status, ix;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;
    char *envFile;

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

    status = getRodsEnv( &myEnv );

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

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

    exit( 0 );
}
Example #4
0
int
main( int argc, char **argv ) {
    rcComm_t *conn;
    rodsEnv myEnv;
    char *optStr;
    rErrMsg_t errMsg;
    int status;
    rodsArguments_t rodsArgs;
    int flag = 0;
    int nativeAPI = 0;

    optStr = "alL";

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

    if ( status < 0 ) {
        printf( "parseCmdLineOpt error, status = %d.\n", status );
        exit( 1 );
    }

    if ( argc - optind <= 0 ) {
        rodsLog( LOG_ERROR, "no input" );
        exit( 2 );
    }

    memset( &errMsg, 0, sizeof( rErrMsg_t ) );

    status = getRodsEnv( &myEnv );

    if ( status < 0 ) {
        fprintf( stderr, "getRodsEnv error, status = %d\n", status );
        exit( 1 );
    }


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

    if ( conn == NULL ) {
        fprintf( stderr, "rcConnect error\n" );
        exit( 1 );
    }

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

    flag = setQueryFlag( &rodsArgs );

    if ( rodsArgs.all == True ) {
        nativeAPI = 1;
    }

    if ( nativeAPI == 1 ) {
        status = printCollectionNat( conn, argv[optind], flag );
    }
    else {
        status = printCollection( conn, argv[optind], flag );
    }

    rcDisconnect( conn );

    exit( 0 );
}
Example #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;
    }
}
Example #6
0
int
main(int argc, char **argv) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    execCmd_t execCmd;
    execCmdOut_t *execCmdOut = NULL;
    int nArg;
    char *tmpPtr;

    optStr = "hvH:p:P:";

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

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

    nArg = argc - optind;

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

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

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

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

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

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

    status = getRodsEnv (&myEnv);

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

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

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

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

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

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

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

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

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

        rcDisconnect(conn);
        exit (4);
    }


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

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

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

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

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

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

   argOffset = myRodsArgs.optind;
 
   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }
   strncpy(objPath,myEnv.rodsCwd,MAX_NAME_LEN);

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

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

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

   status = clientLogin(Conn);
   if (status != 0) {
      rcDisconnect(Conn);
      exit (3);
   }

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

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

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

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

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

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

   printErrorStack(Conn->rError);

   rcDisconnect(Conn);

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

   exit(0);
}
Example #8
0
	int icommands::irm(int argc, char **argv) {
		int status;
		rodsEnv myEnv;
		rErrMsg_t errMsg;
		rcComm_t *conn;
		rodsArguments_t myRodsArgs;
		char *optStr;
		rodsPathInp_t rodsPathInp;


		optStr = "hfruUvVfn:";

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

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

		status = getRodsEnv (&myEnv);

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

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

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

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

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

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

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

		rcDisconnect(conn);

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

	}
Example #9
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 );
}
Example #10
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);
}
Example #11
0
File: icd.cpp Project: bpow/irods
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status, ix, i, fd, len;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;
    char *envFile;
    char buffer[MAX_NAME_LEN];
    rodsPath_t rodsPath;
    rcComm_t *Conn;
    rErrMsg_t errMsg;

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

    status = getRodsEnv( &myEnv );
    envFile = getRodsEnvFileName();

    /* Just "icd", so cd to home, so just remove the session file */
    /* (can do this for now, since session has only the cwd). */
    if ( ix >= argc ) {
        status = unlink( envFile );
        if ( myRodsArgs.verbose == True ) {
            printf( "Deleting (if it exists) session envFile:%s\n", envFile );
            printf( "unlink status = %d\n", status );
        }
        exit( 0 );
    }

    memset( ( char* )&rodsPath, 0, sizeof( rodsPath ) );
    rstrcpy( rodsPath.inPath, argv[ix], MAX_NAME_LEN );
    parseRodsPath( &rodsPath, &myEnv );

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

    /* Connect and check that the path exists */
    Conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
                      myEnv.rodsZone, 0, &errMsg );
    if ( Conn == NULL ) {
        exit( 2 );
    }

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

    status = getRodsObjType( Conn, &rodsPath );
    printErrorStack( Conn->rError );
    rcDisconnect( Conn );

    if ( status < 0 ) {
        fprintf( stderr, "error %d getting type", status );
        exit( 4 );
    }

    if ( rodsPath.objType != COLL_OBJ_T || rodsPath.objState != EXIST_ST ) {
        printf( "No such directory (collection): %s\n", rodsPath.outPath );
        exit( 3 );
    }


    /* open the sessionfile and write or update it */
    if ( ( fd = open( envFile, O_CREAT | O_RDWR | O_TRUNC, 0644 ) ) < 0 ) {
        fprintf( stderr, "Unable to open envFile %s\n", envFile );
        exit( 5 );
    }

    snprintf( buffer, sizeof( buffer ), "{\n\"irods_cwd\": \"%s\"\n}\n", rodsPath.outPath );
    len = strlen( buffer );
    i = write( fd, buffer, len );
    close( fd );
    if ( i != len ) {
        fprintf( stderr, "Unable to write envFile %s\n", envFile );
        exit( 6 );
    }

    return 0;
}
Example #12
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;
    int reconnFlag;


    optStr = "hfIKN:n:PQrt:vVX:R:TZ";

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

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

    status = getRodsEnv( &myEnv );

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

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

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

    if ( myRodsArgs.reconnect == True ) {
        reconnFlag = RECONN_TIMEOUT;
    }
    else {
        reconnFlag = NO_RECONN;
    }

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

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

    if ( strcmp( myEnv.rodsUserName, PUBLIC_USER_NAME ) != 0 ) {
        status = clientLogin( conn );
        if ( status != 0 ) {
            rcDisconnect( conn );
            exit( 7 );
        }
    }

    if ( myRodsArgs.progressFlag == True ) {
        gGuiProgressCB = ( guiProgressCallback ) iCommandProgStat;
    }

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

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

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

}
Example #13
0
int
main( int argc, char **argv ) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;
    int reconnFlag;


    optStr = "aBG:QMhrvVn:PR:S:TX:UZ"; // JMC - backport 4549

    status = parseCmdLineOpt( argc, argv, optStr, 1, &myRodsArgs ); // JMC - backport 4549

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

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

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

    status = getRodsEnv( &myEnv );

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

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

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

    if ( myRodsArgs.reconnect == True ) {
        reconnFlag = RECONN_TIMEOUT;
    }
    else {
        reconnFlag = NO_RECONN;
    }

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

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

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

    if ( myRodsArgs.progressFlag == True ) {
        gGuiProgressCB = ( irodsGuiProgressCallbak ) iCommandProgStat;
    }

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

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

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

}
Example #14
0
int
main( int argc, char **argv ) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    execMyRuleInp_t execMyRuleInp;
    msParamArray_t *outParamArray = NULL;
    msParamArray_t msParamArray;
    int rulegen;

    int connFlag = 0;
    char saveFile[MAX_NAME_LEN];

    optStr = "ZhlvF:s";

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

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

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

    /* init data structures */
    memset( &execMyRuleInp, 0, sizeof( execMyRuleInp ) );
    memset( &msParamArray, 0, sizeof( msParamArray ) );
    execMyRuleInp.inpParamArray = &msParamArray;
    execMyRuleInp.condInput.len = 0;

    /* add key val for test mode */
    if ( myRodsArgs.test == True ) {
        addKeyVal( &execMyRuleInp.condInput, "looptest", "true" );
    }

    /* read rules from the input file */
    if ( myRodsArgs.file == True ) {
        FILE *fptr;
        int len;
        int gotRule = 0;
        char buf[META_STR_LEN];
        char *inpParamNames[1024];
        char *outParamNames[1024];

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

        /* if the input file name starts with "i:", the get the file from iRODS server */
        if ( !strncmp( myRodsArgs.fileString, "i:", 2 ) ) {
            status = getRodsEnv( &myEnv );

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

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

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

            status = clientLogin( conn );
            if ( status != 0 ) {
                rcDisconnect( conn );
                exit( 7 );
            }
            if ( status == 0 ) {
                char *myargv[3];
                int myargc, myoptind;
                rodsPathInp_t rodsPathInp;
                connFlag = 1;

                myargv[0] = strdup( myRodsArgs.fileString + 2 );
                myargv[1] = saveFile;
                myargc = 2;
                myoptind = 0;
                char *fileType = strrchr( myRodsArgs.fileString, '.' );
                if ( fileType == NULL ) {
                    printf( "Unsupported input file type\n" );
                    exit( 10 );
                }
                if ( strcmp( fileType, ".r" ) == 0 ) {
                    rulegen = 1;
                }
                else if ( strcmp( fileType, ".ir" ) == 0 || strcmp( fileType, ".irb" ) == 0 ) {
                    rulegen = 0;
                }
                else {
                    rodsLog( LOG_ERROR,
                             "Unsupported input file type %s\n", fileType );
                    exit( 10 );
                }
                snprintf( saveFile, MAX_NAME_LEN, "/tmp/tmpiruleFile.%i.%i.%s",
                          ( unsigned int ) time( 0 ), getpid(), rulegen ? "r" : "ir" );
                status = parseCmdLinePath( myargc, myargv, myoptind, &myEnv,
                                           UNKNOWN_OBJ_T, UNKNOWN_FILE_T, 0, &rodsPathInp );
                status = getUtil( &conn, &myEnv, &myRodsArgs, &rodsPathInp );
                if ( status < 0 ) {
                    rcDisconnect( conn );
                    exit( 3 );
                }
                myRodsArgs.fileString = saveFile;
                connFlag = 1;
            }
        }

        fptr = fopen( myRodsArgs.fileString, "r" );

        /* test if the file can be opened */
        if ( fptr == NULL ) {
            rodsLog( LOG_ERROR, "Cannot open input file %s. errno = %d\n",
                     myRodsArgs.fileString, errno );
            exit( 1 );
        }

        /* test if the file extension is supported */
        char *fileType = strrchr( myRodsArgs.fileString, '.' );
        if ( fileType == NULL ) {
            printf( "Unsupported input file type\n" );
            exit( 10 );

        }
        else if ( strcmp( fileType, ".r" ) == 0 ) {
            rulegen = 1;
        }
        else if ( strcmp( fileType, ".ir" ) == 0 || strcmp( fileType, ".irb" ) == 0 ) {
            rulegen = 0;
        }
        else {
            rodsLog( LOG_ERROR,
                     "Unsupported input file type %s\n", fileType );
            exit( 10 );
        }

        /* add the @external directive in the rule if the input file is in the new rule engine syntax */
        if ( rulegen ) {
            rstrcpy( execMyRuleInp.myRule, "@external\n", META_STR_LEN );
        }

        while ( ( len = getLine( fptr, buf, META_STR_LEN ) ) > 0 ) {
            if ( myRodsArgs.longOption == True ) {
                puts( buf );
            }

            /* skip comments if the input file is in the old rule engine syntax */
            if ( !rulegen && buf[0] == '#' ) {
                continue;
            }

            if ( rulegen ) {
                if ( startsWith( buf, "INPUT" ) || startsWith( buf, "input" ) ) {
                    gotRule = 1;
                    trimSpaces( trimPrefix( buf ) );
                }
                else if ( startsWith( buf, "OUTPUT" ) || startsWith( buf, "output" ) ) {
                    gotRule = 2;
                    trimSpaces( trimPrefix( buf ) );
                }
            }

            if ( gotRule == 0 ) {
                if ( !rulegen ) {
                    /* the input is a rule */
                    snprintf( execMyRuleInp.myRule + strlen( execMyRuleInp.myRule ), META_STR_LEN - strlen( execMyRuleInp.myRule ), "%s\n", buf );
                }
                else {
                    snprintf( execMyRuleInp.myRule + strlen( execMyRuleInp.myRule ), META_STR_LEN - strlen( execMyRuleInp.myRule ), "%s\n", buf );
                }
            }
            else if ( gotRule == 1 ) {
                if ( rulegen ) {
                    if ( convertListToMultiString( buf, 1 ) != 0 ) {
                        rodsLog( LOG_ERROR,
                                 "Input parameter list format error for %s\n", myRodsArgs.fileString );
                        exit( 10 );
                    }
                }
                extractVarNames( inpParamNames, buf );
                parseMsInputParam( argc, argv, optind, rulegen, myRodsArgs.string, &execMyRuleInp, buf );
            }
            else if ( gotRule == 2 ) {
                if ( rulegen ) {
                    if ( convertListToMultiString( buf, 0 ) != 0 ) {
                        rodsLog( LOG_ERROR,
                                 "Output parameter list format error for %s\n", myRodsArgs.fileString );
                        exit( 10 );
                    }
                }
                extractVarNames( outParamNames, buf );
                if ( strcmp( buf, "null" ) != 0 ) {
                    rstrcpy( execMyRuleInp.outParamDesc, buf, LONG_NAME_LEN );
                }
                break;
            }
            else {
                break;
            }
            if ( !rulegen ) {
                gotRule++;
            }
        }

        if ( myRodsArgs.longOption == True ) {
            puts( "-----------------------------------------------------------------" );
        }

        if ( gotRule != 2 ) {
            rodsLog( LOG_ERROR, "Incomplete rule input for %s",
                     myRodsArgs.fileString );
            exit( 2 );
        }
        if ( connFlag == 1 ) {
            fclose( fptr );
            unlink( saveFile );
        }
    }
    else {	/* command line input */
        rulegen = 1;
        int nArg = argc - optind; /* number of rule arguments */
        if ( nArg < 3 ) {
            rodsLog( LOG_ERROR, "no input" );
            printf( "Use -h for help.\n" );
            exit( 3 );
        }

        snprintf( execMyRuleInp.myRule, META_STR_LEN, "@external rule { %s }", argv[optind] );
        parseMsInputParam( 0, NULL, 0, 1, myRodsArgs.string, &execMyRuleInp, argv[optind + 1] );
        if ( strcmp( argv[optind + 2], "null" ) != 0 ) {
            rstrcpy( execMyRuleInp.outParamDesc, argv[optind + 2],
                     LONG_NAME_LEN );
        }
    }


    if ( connFlag == 0 ) {
        status = getRodsEnv( &myEnv );

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

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

        if ( conn == NULL ) {
            rodsLogError( LOG_ERROR, errMsg.status, "rcConnect failure %s",
                          errMsg.msg );
            exit( 2 );
        }

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

    if ( myRodsArgs.verbose == True ) {
        printf( "rcExecMyRule: %s\n", rulegen ? execMyRuleInp.myRule + 10 : execMyRuleInp.myRule );
        printf( "outParamDesc: %s\n", execMyRuleInp.outParamDesc );
    }

    status = rcExecMyRule( conn, &execMyRuleInp, &outParamArray );

    if ( myRodsArgs.test == True ) {
        printErrorStack( conn->rError );
    }

    if ( status < 0 ) {
        msParam_t *mP;
        execCmdOut_t *execCmdOut;

        if ( !rulegen ) {
            rodsLogError( LOG_ERROR, status, "rcExecMyRule error. The rule engine is running under backward compatible mode. To run the rule(s) under normal mode, try renaming the file extension to \".r\". " );

        }
        else {
            rodsLogError( LOG_ERROR, status, "rcExecMyRule error. " );

        }
        printErrorStack( conn->rError );
        if ( ( mP = getMsParamByType( outParamArray, ExecCmdOut_MS_T ) ) != NULL ) {
            execCmdOut = ( execCmdOut_t * ) mP->inOutStruct;
            if ( execCmdOut->stdoutBuf.buf != NULL ) {
                fprintf( stdout, "%s", ( char * ) execCmdOut->stdoutBuf.buf );
            }
            if ( execCmdOut->stderrBuf.buf != NULL ) {
                fprintf( stderr, "%s", ( char * ) execCmdOut->stderrBuf.buf );
            }
        }
        rcDisconnect( conn );
        exit( 4 );
    }

    if ( myRodsArgs.verbose == True ) {
        printf( "ExecMyRule completed successfully.    Output \n\n" );
        printMsParamNew( outParamArray, 1 );
    }
    else {
        printMsParamNew( outParamArray, 0 );
        msParam_t *mP;
        execCmdOut_t *execCmdOut;
        if ( ( mP = getMsParamByType( outParamArray, ExecCmdOut_MS_T ) ) != NULL ) {
            execCmdOut = ( execCmdOut_t * ) mP->inOutStruct;
            if ( execCmdOut->stdoutBuf.buf != NULL ) {
                fprintf( stdout, "%s", ( char * ) execCmdOut->stdoutBuf.buf );
            }
            if ( execCmdOut->stderrBuf.buf != NULL ) {
                fprintf( stderr, "%s", ( char * ) execCmdOut->stderrBuf.buf );
            }
        }
    }
    if ( myRodsArgs.verbose == True && conn->rError != NULL ) {
        int i, len;
        rErrMsg_t *errMsg;
        len = conn->rError->len;
        for ( i = 0; i < len; i++ ) {
            errMsg = conn->rError->errMsg[i];
            printf( "%s\n", errMsg->msg );
        }
    }

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

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

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    int noDistinctFlag = 0;
    int upperCaseFlag = 0;

    optStr = "hz:Z";

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

    if ( myRodsArgs.optind < argc ) {
        if ( !strcmp( argv[myRodsArgs.optind], "no-distinct" ) ) {
            noDistinctFlag = 1;
            myRodsArgs.optind++;
        }
    }
    if ( myRodsArgs.optind < argc ) {
        if ( strncmp( argv[myRodsArgs.optind], "upper", 5 ) == 0 ) {
            upperCaseFlag = 1;
            myRodsArgs.optind++;
        }
    }


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

    if ( myRodsArgs.optind == argc ) {
        printf( "StringCondition needed\n" );
        usage();
        exit( 0 );
    }


    status = getRodsEnv( &myEnv );

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

    if ( myRodsArgs.optind == 1 ) {
        if ( !strncmp( argv[argc - 1], "attrs", 5 ) ) {
            showAttrNames();
            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 ) {
        exit( 2 );
    }

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

    if ( myRodsArgs.sql ) {
        status = execAndShowSpecificQuery( conn, argv[myRodsArgs.optind],
                                           argv,
                                           myRodsArgs.optind + 1,
                                           myRodsArgs.noPage,
                                           myRodsArgs.zoneName );
        rcDisconnect( conn );
        if ( status < 0 ) {
            rodsLogError( LOG_ERROR, status, "iquest Error: specificQuery (sql-query) failed" );
            exit( 4 );
        }
        else {
            exit( 0 );
        }
    }

    if ( myRodsArgs.optind == ( argc - 3 ) ) {
        status = queryAndShowStrCond( conn, argv[argc - 3],
                                      argv[argc - 2], argv[argc - 1],
                                      noDistinctFlag, upperCaseFlag,
                                      myRodsArgs.zoneName,
                                      myRodsArgs.noPage );
    }
    else if ( myRodsArgs.optind == ( argc - 2 ) ) {
        status = queryAndShowStrCond( conn, NULL, argv[argc - 2], argv[argc - 1],
                                      noDistinctFlag, upperCaseFlag,
                                      myRodsArgs.zoneName,
                                      myRodsArgs.noPage );
    }
    else {
        status = queryAndShowStrCond( conn, NULL, NULL, argv[argc - 1],
                                      noDistinctFlag, upperCaseFlag,
                                      myRodsArgs.zoneName,
                                      myRodsArgs.noPage );
    }
    rcDisconnect( conn );

    if ( status < 0 ) {
        if ( status == CAT_NO_ROWS_FOUND ) {
            printf( "CAT_NO_ROWS_FOUND: Nothing was found matching your query\n" );
            exit( 0 );
        }
        else {
            rodsLogError( LOG_ERROR, status, "iquest Error: queryAndShowStrCond failed" );
            exit( 4 );
        }
    }
    else {
        exit( 0 );
    }

}
Example #17
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 );
}
Example #18
0
File: iscan.cpp Project: nesi/irods
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    rodsArguments_t myRodsArgs;
    int status = parseCmdLineOpt( argc, argv, "dhr", 0, &myRodsArgs );

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

    rodsEnv myEnv;
    status = getRodsEnv( &myEnv );

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

    objType_t srcType;
    if ( myRodsArgs.dataObjects ) {
        srcType = UNKNOWN_OBJ_T;
    }
    else {
        srcType = UNKNOWN_FILE_T;
    }

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

    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status, "main: parseCmdLinePath error. " );
        usage();
        return 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 );

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

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

    if ( strcmp( myEnv.rodsUserName, PUBLIC_USER_NAME ) != 0 ) {
        status = clientLogin( conn );
        if ( status != 0 ) {
            rcDisconnect( conn );
            return 7;
        }
    }

    char hostname[LONG_NAME_LEN];
    status = gethostname( hostname, LONG_NAME_LEN );
    if ( status < 0 ) {
        printf( "cannot resolve server name, aborting!\n" );
        return 4;
    }

    status = scanObj( conn, &myRodsArgs, &rodsPathInp, hostname );

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

    return status;

}
Example #19
0
int
main(int argc, char **argv) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr, buffer[HUGE_NAME_LEN], hostname[LONG_NAME_LEN];
    objType_t srcType;
    rodsPathInp_t rodsPathInp;

    optStr = "hr";
   
    status = parseCmdLineOpt (argc, argv, optStr, 0, &myRodsArgs);

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

    status = getRodsEnv (&myEnv);

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

	if (strcmp (argv[argc-1], "i:") == 0) {
		srcType = UNKNOWN_OBJ_T;
		strcpy (argv[argc-1], ".");
	} else if (strncmp (argv[argc-1], "i:", 2) == 0) {
		srcType = UNKNOWN_OBJ_T;
		strcpy (buffer, argv[argc-1] + 2);
		argv[argc-1] = buffer;
    } else {
		srcType = UNKNOWN_FILE_T;
    }
	
    status = parseCmdLinePath (argc, argv, optind, &myEnv,
      srcType, NO_INPUT_T, 0, &rodsPathInp);

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

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

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

    if (strcmp (myEnv.rodsUserName, PUBLIC_USER_NAME) != 0) { 
        status = clientLogin(conn);
        if (status != 0) {
           rcDisconnect(conn);
           exit (7);
		}
    }
   
	status = gethostname(hostname, LONG_NAME_LEN);
	if ( status < 0 ) {
		printf ("cannot resolve server name, aborting!\n");
		exit(4);
	}
	
	status = scanObj (conn, &myRodsArgs, &rodsPathInp, hostname);

    printErrorStack(conn->rError);

    rcDisconnect(conn);

    exit(status);

}
Example #20
0
int
main( int argc, char **argv ) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;


    optStr = "hru:vVz:MZ";

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

    status = getRodsEnv( &myEnv );

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

    /* use the trash home as cwd */
    snprintf( myEnv.rodsCwd, LONG_NAME_LEN, "/%s/trash/home/%s",
              myEnv.rodsZone, myEnv.rodsUserName );
    rstrcpy( myEnv.rodsHome, myEnv.rodsCwd, LONG_NAME_LEN );
    status = parseCmdLinePath( argc, argv, optind, &myEnv,
                               UNKNOWN_OBJ_T, NO_INPUT_T, 0, &rodsPathInp );

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

    // =-=-=-=-=-=-=-
    // initialize pluggable api table
    irods::api_entry_table&  api_tbl = irods::get_client_api_table();
    irods::pack_entry_table& pk_tbl  = irods::get_pack_table();
    init_api_table( api_tbl, pk_tbl );

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

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

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

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

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

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

}
Example #21
0
int
main(int argc, char **argv) {
    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;
    int nArgv;
    

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

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

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

    nArgv = argc - optind;

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

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

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

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

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

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

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

    printErrorStack(conn->rError);

    rcDisconnect(conn);

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

}
Example #22
0
int
main (int argc, char **argv)
{

    irodsOper.getattr = irodsGetattr;
    irodsOper.readlink = irodsReadlink;
    irodsOper.readdir = irodsReaddir;
    irodsOper.mknod = irodsMknod;
    irodsOper.mkdir = irodsMkdir;
    irodsOper.symlink = irodsSymlink;
    irodsOper.unlink = irodsUnlink;
    irodsOper.rmdir = irodsRmdir;
    irodsOper.rename = irodsRename;
    irodsOper.link = irodsLink;
    irodsOper.chmod = irodsChmod;
    irodsOper.chown = irodsChown;
    irodsOper.truncate = irodsTruncate;
    irodsOper.utimens = irodsUtimens;
    irodsOper.open = irodsOpen;
    irodsOper.read = irodsRead;
    irodsOper.write = irodsWrite;
    irodsOper.statfs = irodsStatfs;
    irodsOper.release = irodsRelease;
    irodsOper.fsync = irodsFsync;
    irodsOper.flush = irodsFlush;


    int status;
    rodsArguments_t myRodsArgs;
    char *optStr;

#ifdef  __cplusplus
    bzero (&irodsOper, sizeof (irodsOper));
    irodsOper.getattr = irodsGetattr;
    irodsOper.readlink = irodsReadlink;
    irodsOper.readdir = irodsReaddir;
    irodsOper.mknod = irodsMknod;
    irodsOper.mkdir = irodsMkdir;
    irodsOper.symlink = irodsSymlink;
    irodsOper.unlink = irodsUnlink;
    irodsOper.rmdir = irodsRmdir;
    irodsOper.rename = irodsRename;
    irodsOper.link = irodsLink;
    irodsOper.chmod = irodsChmod;
    irodsOper.chown = irodsChown;
    irodsOper.truncate = irodsTruncate;
    irodsOper.utimens = irodsUtimens;
    irodsOper.open = irodsOpen;
    irodsOper.read = irodsRead;
    irodsOper.write = irodsWrite;
    irodsOper.statfs = irodsStatfs;
    irodsOper.release = irodsRelease;
    irodsOper.fsync = irodsFsync;
    irodsOper.flush = irodsFlush;
#endif
    optStr = "hdo:";

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

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

    status = getRodsEnv (&MyRodsEnv);

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

    srandom((unsigned int) time(0) % getpid());

#ifdef CACHE_FILE_FOR_READ
    if (setAndMkFileCacheDir () < 0) exit (1);
#endif

    initPathCache ();
    initIFuseDesc ();
    initConn();
    initFileCache();

    status = fuse_main (argc, argv, &irodsOper, NULL);

    disconnectAll ();

    if (status < 0) {
        exit (3);
    } else {
        exit(0);
    }
}
Example #23
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

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


    optStr = "ahKlN:rR:svVZ";

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

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

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

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

    nArgv = argc - optind;

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

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

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

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

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

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

    // =-=-=-=-=-=-=-
    // initialize pluggable api table
    irods::api_entry_table&  api_tbl = irods::get_client_api_table();
    irods::pack_entry_table& pk_tbl  = irods::get_pack_table();
    init_api_table( api_tbl, pk_tbl );

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

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

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

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

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

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

}
Example #24
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);
}
Example #25
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);
}
Example #26
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 );
}
Example #27
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 );
}
Example #28
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;


    optStr = "hKfarR:vVn:Z";

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

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

    status = getRodsEnv( &myEnv );

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

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

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

    // =-=-=-=-=-=-=-
    // initialize pluggable api table
    irods::api_entry_table& api_tbl = irods::get_client_api_table();
    irods::pack_entry_table& pk_tbl  = irods::get_pack_table();
    init_api_table( api_tbl, pk_tbl );

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

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

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

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

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

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

}
Example #29
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);
}
Example #30
0
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    rodsEnv myEnv;
    rErrMsg_t errMsg;
    rcComm_t *conn;
    rodsArguments_t myRodsArgs;
    char *optStr;
    rodsPathInp_t rodsPathInp;
    int i, nArgs;
    modAccessControlInp_t modAccessControl;
    char userName[NAME_LEN];
    char zoneName[NAME_LEN];
    int doingInherit;
    char rescAccessLevel[LONG_NAME_LEN];
    char adminModeAccessLevel[LONG_NAME_LEN];

    optStr = "RrhvVM";

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

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

    nArgs = argc - myRodsArgs.optind;

    if ( nArgs < 2 ) {
        usage();
        exit( 3 );
    }

    status = getRodsEnv( &myEnv );

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

    optind = myRodsArgs.optind + 2;
    doingInherit = 0;
    if ( strcmp( argv[myRodsArgs.optind], ACCESS_INHERIT ) == 0 ||
            strcmp( argv[myRodsArgs.optind], ACCESS_NO_INHERIT ) == 0 ) {
        doingInherit = 1;
        optind = myRodsArgs.optind + 1;
    }

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

    if ( status < 0 ) {
        rodsLogError( LOG_ERROR, status, "main: parseCmdLinePath error. " );
        usage();
        exit( 4 );
    }

    // =-=-=-=-=-=-=-
    // 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( 5 );
    }

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

    modAccessControl.recursiveFlag = myRodsArgs.recursive;
    modAccessControl.accessLevel = argv[myRodsArgs.optind];

    if ( doingInherit ) {
        modAccessControl.userName = "";
        modAccessControl.zone = "";
    }
    else {
        status = parseUserName( argv[myRodsArgs.optind + 1], userName, zoneName );
        if ( status != 0 ) {
            printf( "Invalid iRODS user name format: %s\n",
                    argv[myRodsArgs.optind + 1] );
            exit( 7 );
        }
    }
    modAccessControl.userName = userName;
    modAccessControl.zone = zoneName;
    for ( i = 0; i < rodsPathInp.numSrc && status == 0; i++ ) {
        if ( rodsPathInp.numSrc > 1 && myRodsArgs.verbose != 0 ) {
            printf( "path %s\n", rodsPathInp.srcPath[i].outPath );
        }
        modAccessControl.path = rodsPathInp.srcPath[i].outPath;

        if ( myRodsArgs.resource ) {
            strncpy( rescAccessLevel, MOD_RESC_PREFIX, LONG_NAME_LEN );
            strncat( rescAccessLevel, argv[myRodsArgs.optind], LONG_NAME_LEN - strlen( rescAccessLevel ) );
            modAccessControl.accessLevel = rescAccessLevel; /* indicate resource*/
            modAccessControl.path = argv[optind]; /* just use the plain name */
        }
        if ( myRodsArgs.admin && i == 0 ) {  /* admin mode, add indicator */
            strncpy( adminModeAccessLevel, MOD_ADMIN_MODE_PREFIX, LONG_NAME_LEN );
            strncat( adminModeAccessLevel, modAccessControl.accessLevel,
                     LONG_NAME_LEN - strlen( adminModeAccessLevel ) );
            modAccessControl.accessLevel = adminModeAccessLevel;
        }
        status = rcModAccessControl( conn, &modAccessControl );
        if ( status < 0 ) {
            rodsLogError( LOG_ERROR, status, "rcModAccessControl failure %s",
                          errMsg.msg );
            if ( conn->rError ) {
                rError_t *Err;
                rErrMsg_t *ErrMsg;
                int i, len;
                Err = conn->rError;
                len = Err->len;
                for ( i = 0; i < len; i++ ) {
                    ErrMsg = Err->errMsg[i];
                    rodsLog( LOG_ERROR, "Level %d: %s", i, ErrMsg->msg );
                }
            }
        }
    }

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

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

}