Exemple #1
0
/*
 Modify (add or remove) AVUs
 */
int
modAVUMetadata(char *arg0, char *arg1, char *arg2, char *arg3, 
	       char *arg4, char *arg5, char *arg6, char *arg7, char *arg8) {
   modAVUMetadataInp_t modAVUMetadataInp;
   int status;
   char *mySubName;
   char *myName;
   char fullName[MAX_NAME_LEN];

   strncpy(fullName, cwd, MAX_NAME_LEN);
   if (strcmp(arg1,"-R")==0 || strcmp(arg1,"-r")==0 || 
       strcmp(arg1,"-G")==0 || strcmp(arg1,"-g")==0 || 
       strcmp(arg1,"-u")==0) {
      strncpy(fullName, arg2, MAX_NAME_LEN);
   }
   else {
      if (strlen(arg2)>0) {
	 if (*arg2=='/') {
	    strncpy(fullName, arg2, MAX_NAME_LEN);
	 }
	 else {
	    rstrcat(fullName, "/", MAX_NAME_LEN);
	    rstrcat(fullName, arg2, MAX_NAME_LEN);
	 }
      }
   }

   modAVUMetadataInp.arg0 = arg0;
   modAVUMetadataInp.arg1 = arg1;
   modAVUMetadataInp.arg2 = fullName;
   modAVUMetadataInp.arg3 = arg3;
   modAVUMetadataInp.arg4 = arg4;
   modAVUMetadataInp.arg5 = arg5;
   modAVUMetadataInp.arg6 = arg6;
   modAVUMetadataInp.arg7 = arg7;
   modAVUMetadataInp.arg8 = arg8;
   modAVUMetadataInp.arg9 ="";

   status = rcModAVUMetadata(Conn, &modAVUMetadataInp);
   lastCommandStatus = status;

   if (status < 0 ) {
      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);
	 }
      }
      myName = rodsErrorName(status, &mySubName);
      rodsLog (LOG_ERROR, "rcModAVUMetadata failed with error %d %s %s",
	       status, myName, mySubName);
   }
   return(status);
}
Exemple #2
0
/**
 * Wrap tag data in simple header xml markup.
 * @param td		tag data container
 * @return		formatted string
 */
static char * xmlFormat(rpmtd td)
{
    const char *xtag = NULL;
    char *val = NULL;
    char *s = NULL;
    rpmtdFormats fmt = RPMTD_FORMAT_STRING;

    switch (rpmtdClass(td)) {
    case RPM_STRING_CLASS:
	xtag = "string";
	break;
    case RPM_BINARY_CLASS:
	fmt = RPMTD_FORMAT_BASE64;
	xtag = "base64";
	break;
    case RPM_NUMERIC_CLASS:
	xtag = "integer";
	break;
    case RPM_NULL_TYPE:
    default:
	return xstrdup(_("(invalid xml type)"));
	break;
    }

    /* XXX TODO: handle errors */
    s = rpmtdFormat(td, fmt, NULL);

    if (s[0] == '\0') {
	val = rstrscat(NULL, "\t<", xtag, "/>", NULL);
    } else {
	char *new_s = NULL;
	size_t i, s_size = strlen(s);
	
	for (i=0; i<s_size; i++) {
	    switch (s[i]) {
		case '<':	rstrcat(&new_s, "&lt;");	break;
		case '>':	rstrcat(&new_s, "&gt;");	break;
		case '&':	rstrcat(&new_s, "&amp;");	break;
		default: {
		    char c[2] = " ";
		    *c = s[i];
		    rstrcat(&new_s, c);
		    break;
		}
	    }
	}

	val = rstrscat(NULL, "\t<", xtag, ">", new_s, "</", xtag, ">", NULL);
	free(new_s);
    }
    free(s);

    return val;
}
Exemple #3
0
/**
 * Check file info from header against what's actually installed.
 * @param ts		transaction set
 * @param h		header to verify
 * @param omitMask	bits to disable verify checks
 * @param ghosts	should ghosts be verified?
 * @return		0 no problems, 1 problems found
 */
static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts)
{
    rpmVerifyAttrs verifyResult = 0;
    int ec = 0;		/* assume no problems */
    rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_FLAGS_VERIFY);

    rpmfiInit(fi, 0);
    while (rpmfiNext(fi) >= 0) {
	rpmfileAttrs fileAttrs = rpmfiFFlags(fi);
	char *buf = NULL, *attrFormat;
	char ac;
	int rc;

	/* If not verifying %ghost, skip ghost files. */
	if ((fileAttrs & RPMFILE_GHOST) && !ghosts)
	    continue;

	rc = rpmVerifyFile(ts, fi, &verifyResult, omitMask);

	/* Filter out timestamp differences of shared files */
	if (rc == 0 && (verifyResult & RPMVERIFY_MTIME)) {
	    rpmdbMatchIterator mi;
	    mi = rpmtsInitIterator(ts, RPMDBI_BASENAMES, rpmfiFN(fi), 0);
	    if (rpmdbGetIteratorCount(mi) > 1) 
		verifyResult &= ~RPMVERIFY_MTIME;
	    rpmdbFreeIterator(mi);
	}

	attrFormat = rpmFFlagsString(fileAttrs, "");
	ac = rstreq(attrFormat, "") ? ' ' : attrFormat[0];
	if (rc) {
	    if (!(fileAttrs & (RPMFILE_MISSINGOK|RPMFILE_GHOST)) || rpmIsVerbose()) {
		rasprintf(&buf, _("missing   %c %s"), ac, rpmfiFN(fi));
		if ((verifyResult & RPMVERIFY_LSTATFAIL) != 0 &&
		    errno != ENOENT) {
		    char *app;
		    rasprintf(&app, " (%s)", strerror(errno));
		    rstrcat(&buf, app);
		    free(app);
		}
		ec = rc;
	    }
	} else if (verifyResult || rpmIsVerbose()) {
	    char *verifyFormat = rpmVerifyString(verifyResult, ".");
	    rasprintf(&buf, "%s  %c %s", verifyFormat, ac, rpmfiFN(fi));
	    free(verifyFormat);

	    if (verifyResult) ec = 1;
	}
	free(attrFormat);

	if (buf) {
	    rpmlog(RPMLOG_NOTICE, "%s\n", buf);
	    buf = _free(buf);
	}
    }
    rpmfiFree(fi);
	
    return ec;
}
Exemple #4
0
void
makeFullPath( char *inName, char **outName ) {
    static char fullName[LONG_NAME_LEN];
    strcpy( fullName, "" );
    if ( strlen( inName ) > 0 ) {
        strncpy( fullName, cwd, LONG_NAME_LEN );
        if ( *inName == '/' ) {
            strncpy( fullName, inName, LONG_NAME_LEN );
        }
        else {
            rstrcat( fullName, "/", LONG_NAME_LEN );
            rstrcat( fullName, inName, LONG_NAME_LEN );
        }
    }
    *outName = fullName;
}
Exemple #5
0
static void queryArgCallback(poptContext con,
		enum poptCallbackReason reason,
		const struct poptOption * opt, const char * arg, 
		const void * data)
{
    QVA_t qva = &rpmQVKArgs;

    switch (opt->val) {
    case 'c': qva->qva_flags |= QUERY_FOR_CONFIG | QUERY_FOR_LIST; break;
    case 'd': qva->qva_flags |= QUERY_FOR_DOCS | QUERY_FOR_LIST; break;
    case 'L': qva->qva_flags |= QUERY_FOR_LICENSE | QUERY_FOR_LIST; break;
    case 'l': qva->qva_flags |= QUERY_FOR_LIST; break;
    case 's': qva->qva_flags |= QUERY_FOR_STATE | QUERY_FOR_LIST;
	break;
    case POPT_DUMP: qva->qva_flags |= QUERY_FOR_DUMPFILES | QUERY_FOR_LIST;
	break;

    case POPT_QUERYFORMAT:
	rstrcat(&qva->qva_queryFormat, arg);
	break;

    case 'i':
	if (qva->qva_mode == 'q') {
	    const char * infoCommand[] = { "--info", NULL };
	    (void) poptStuffArgs(con, infoCommand);
	}
	break;

    case RPMCLI_POPT_NODEPS:
	qva->qva_flags |= VERIFY_DEPS;
	break;

    case RPMCLI_POPT_NOFILEDIGEST:
	qva->qva_flags |= VERIFY_FILEDIGEST;
	break;

    case RPMCLI_POPT_NOCONTEXTS:
	qva->qva_flags |= VERIFY_CONTEXTS;
	break;

#ifdef	NOTYET
    case RPMCLI_POPT_FORCE:
	ia->probFilter |=
		( RPMPROB_FILTER_REPLACEPKG
		| RPMPROB_FILTER_REPLACEOLDFILES
		| RPMPROB_FILTER_REPLACENEWFILES
		| RPMPROB_FILTER_OLDPACKAGE );
	break;
#endif

    case RPMCLI_POPT_NOSCRIPTS:
	qva->qva_flags |= VERIFY_SCRIPT;
	break;

    }
}
Exemple #6
0
int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
{
    char *d, *de;
    int rc;

    if (path == NULL || *path == '\0')
	return -1;
    d = rstrcat(NULL, path);
    if (d[strlen(d)-1] != '/') {
	rstrcat(&d,"/");
    }
    de = d;
    for (;(de=strchr(de+1,'/'));) {
	struct stat st;
	*de = '\0';
	rc = stat(d, &st);
	if (rc) {
	    if (errno != ENOENT)
		goto exit;
	    rc = mkdir(d, mode);
	    if (rc)
		goto exit;
	    rpmlog(RPMLOG_DEBUG, "created directory(s) %s mode 0%o\n", path, mode);
	    if (!(uid == (uid_t) -1 && gid == (gid_t) -1)) {
		rc = chown(d, uid, gid);
		if (rc)
		    goto exit;
	    }
	} else if (!S_ISDIR(st.st_mode)) {
	    rc = ENOTDIR;
	    goto exit;
	}
	*de = '/';
    }
    rc = 0;
exit:
    free(d);
    return rc;
}
Exemple #7
0
int rpmtsSetRootDir(rpmts ts, const char * rootDir)
{
    if (ts == NULL || (rootDir && rootDir[0] != '/')) {
	return -1;
    }

    ts->rootDir = _free(ts->rootDir);
    /* Ensure clean path with a trailing slash */
    ts->rootDir = rootDir ? rpmGetPath(rootDir, NULL) : xstrdup("/");
    if (!rstreq(ts->rootDir, "/")) {
	rstrcat(&ts->rootDir, "/");
    }
    return 0;
}
Exemple #8
0
char * rpmGenPath(const char * urlroot, const char * urlmdir,
		const char *urlfile)
{
    char * xroot = rpmGetPath(urlroot, NULL);
    const char * root = xroot;
    char * xmdir = rpmGetPath(urlmdir, NULL);
    const char * mdir = xmdir;
    char * xfile = rpmGetPath(urlfile, NULL);
    const char * file = xfile;
    char * result;
    char * url = NULL;
    int nurl = 0;
    int ut;

    ut = urlPath(xroot, &root);
    if (url == NULL && ut > URL_IS_DASH) {
	url = xroot;
	nurl = root - xroot;
    }
    if (root == NULL || *root == '\0') root = "/";

    ut = urlPath(xmdir, &mdir);
    if (url == NULL && ut > URL_IS_DASH) {
	url = xmdir;
	nurl = mdir - xmdir;
    }
    if (mdir == NULL || *mdir == '\0') mdir = "/";

    ut = urlPath(xfile, &file);
    if (url == NULL && ut > URL_IS_DASH) {
	url = xfile;
	nurl = file - xfile;
    }

    if (url && nurl > 0) {
	char *t = rstrcat(NULL, url);
	t[nurl] = '\0';
	url = t;
    } else
	url = xstrdup("");

    result = rpmGetPath(url, root, "/", mdir, "/", file, NULL);

    free(xroot);
    free(xmdir);
    free(xfile);
    free(url);
    return result;
}
Exemple #9
0
/*
   Try a specific-query for the a particular Data-object in collection
   query first, for performance improvements, before going back to a
   general-query.  This is called from rsQueryDataObjInCollReCur below.
   See the svn commit log (r5682) for the specific query definition.
 */
int trySpecificQueryDataObjInCollReCur(
    rsComm_t *rsComm,
    char *collection,
    genQueryOut_t **genQueryOut ) {

    int status = 0;
    char collNamePercent[MAX_NAME_LEN + 2];

    specificQueryInp_t specificQueryInp;

    rstrcpy( collNamePercent, collection, MAX_NAME_LEN );
    rstrcat( collNamePercent, "/%", MAX_NAME_LEN );

    memset( &specificQueryInp, 0, sizeof( specificQueryInp_t ) );

    specificQueryInp.maxRows = MAX_SQL_ROWS;
    specificQueryInp.continueInx = 0;

    specificQueryInp.sql = "DataObjInCollReCur";
    specificQueryInp.args[0] = collection;
    specificQueryInp.args[1] = collNamePercent;

    status = rsSpecificQuery( rsComm, &specificQueryInp, genQueryOut );

    if ( status == 0 ) {
        /*
           Set the attriInx values so the server-side code can locate
           the fields (avoid a UNMATCHED_KEY_OR_INDEX error) the way
           general-query is handled.  The specific-query can't set these
           because the columns being returned are not known (unlike for
           general-query).  So this code assumes the DataObjInCollReCur
           is defined correctly and is returning the following columns.
           The result->attriCnt == 6 test is a sanity check.
         */
        genQueryOut_t *result;
        result = *genQueryOut;
        if ( result->attriCnt == 7 ) {

            result->sqlResult[0].attriInx = COL_D_DATA_ID;
            result->sqlResult[1].attriInx = COL_COLL_NAME;
            result->sqlResult[2].attriInx = COL_DATA_NAME;
            result->sqlResult[3].attriInx = COL_DATA_REPL_NUM;
            result->sqlResult[4].attriInx = COL_D_RESC_NAME;
            result->sqlResult[5].attriInx = COL_D_DATA_PATH;
            result->sqlResult[6].attriInx = COL_D_RESC_HIER;
        }
    }
    return status;
}
Exemple #10
0
char * rpmGetPath(const char *path, ...)
{
    va_list ap;
    char *dest = NULL, *res;
    const char *s;

    if (path == NULL)
	return xstrdup("");

    va_start(ap, path);
    for (s = path; s; s = va_arg(ap, const char *)) {
	rstrcat(&dest, s);
    }
    va_end(ap);

    res = rpmExpand(dest, NULL);
    free(dest);

    return rpmCleanPath(res);
}
Exemple #11
0
/* 
 Attempt to make the ~/.irods directory in case it doesn't exist (may
 be needed to write the .irodsA file and perhaps the .irodsEnv file).
 */
int
mkrodsdir() {
   char dirName[NAME_LEN];
   int status, mode;
   char *getVar;
#ifdef windows_platform
   getVar = iRODSNt_gethome();
#else
   getVar = getenv("HOME");
#endif
   rstrcpy(dirName, getVar, NAME_LEN);
   rstrcat(dirName, "/.irods", NAME_LEN);
   mode = 0700;
#ifdef _WIN32
   status = iRODSNt_mkdir (dirName, mode);
#else
   status = mkdir (dirName, mode);
#endif
   return(0); /* no error messages as it normally fails */
}
Exemple #12
0
static char * canonDir(rpmstrPool pool, rpmsid dirNameId)
{
    const char * dirName = rpmstrPoolStr(pool, dirNameId);
    size_t cdnl = rpmstrPoolStrlen(pool, dirNameId);;
    char *cdnbuf = NULL;

    if (*dirName == '/') {
	cdnbuf = xstrdup(dirName);
	cdnbuf = rpmCleanPath(cdnbuf);
	/* leave my trailing slashes along you b**** */
	if (cdnl > 1)
	    cdnbuf = rstrcat(&cdnbuf, "/");
    } else {
	/* Using realpath on the arg isn't correct if the arg is a symlink,
	 * especially if the symlink is a dangling link.  What we 
	 * do instead is use realpath() on `.' and then append arg to
	 * the result.
	 */

	/* if the current directory doesn't exist, we might fail. 
	   oh well. likewise if it's too long.  */

	/* XXX we should let realpath() allocate if it can */
	cdnbuf = xmalloc(PATH_MAX);
	cdnbuf[0] = '\0';
	if (realpath(".", cdnbuf) != NULL) {
	    char *end = cdnbuf + strlen(cdnbuf);
	    if (end[-1] != '/')	*end++ = '/';
	    end = stpncpy(end, dirName, PATH_MAX - (end - cdnbuf));
	    *end = '\0';
	    (void)rpmCleanPath(cdnbuf); /* XXX possible /../ from concatenation */
	    end = cdnbuf + strlen(cdnbuf);
	    if (end[-1] != '/')	*end++ = '/';
	    *end = '\0';
	} else {
	    cdnbuf = _free(cdnbuf);
	}
    }
    return cdnbuf;
}
Exemple #13
0
/* 
 * Format sigcheck result for output, appending the message spew to buf and
 * bad/missing keyids to keyprob.
 *
 * In verbose mode, just dump it all. Otherwise ok signatures
 * are dumped lowercase, bad sigs uppercase and for PGP/GPG
 * if misssing/untrusted key it's uppercase in parenthesis
 * and stash the key id as <SIGTYPE>#<keyid>. Pfft.
 */
static void formatResult(rpmTagVal sigtag, rpmRC sigres, const char *result,
			 char **keyprob, char **buf)
{
    char *msg = NULL;
    if (rpmIsVerbose()) {
	rasprintf(&msg, "    %s\n", result);
    } else { 
	/* Check for missing / untrusted keys in result. */
	const char *signame = sigtagname(sigtag, (sigres != RPMRC_OK));
	
	if (sigres == RPMRC_NOKEY || sigres == RPMRC_NOTTRUSTED) {
	    const char *tempKey = strstr(result, "ey ID");
	    if (tempKey) {
		char keyid[sizeof(pgpKeyID_t) + 1];
		rstrlcpy(keyid, tempKey + 6, sizeof(keyid));
		rstrscat(keyprob, " ", signame, "#", keyid, NULL);
	    }
	}
	rasprintf(&msg, (*keyprob ? "(%s) " : "%s "), signame);
    }
    rstrcat(buf, msg);
    free(msg);
}
Exemple #14
0
static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag)
{
    struct Source *p;
    int flag = 0;
    const char *name = NULL;
    char *nump;
    char *fieldp = NULL;
    char *buf = NULL;
    uint32_t num = 0;

    switch (tag) {
      case RPMTAG_SOURCE:
	flag = RPMBUILD_ISSOURCE;
	name = "source";
	fieldp = spec->line + 6;
	break;
      case RPMTAG_PATCH:
	flag = RPMBUILD_ISPATCH;
	name = "patch";
	fieldp = spec->line + 5;
	break;
      case RPMTAG_ICON:
	flag = RPMBUILD_ISICON;
	fieldp = NULL;
	break;
      default:
	return -1;
	break;
    }

    /* Get the number */
    if (tag != RPMTAG_ICON) {
	/* We already know that a ':' exists, and that there */
	/* are no spaces before it.                          */
	/* This also now allows for spaces and tabs between  */
	/* the number and the ':'                            */
	char ch;
	char *fieldp_backup = fieldp;

	while ((*fieldp != ':') && (*fieldp != ' ') && (*fieldp != '\t')) {
	    fieldp++;
	}
	ch = *fieldp;
	*fieldp = '\0';

	nump = fieldp_backup;
	SKIPSPACE(nump);
	if (nump == NULL || *nump == '\0') {
	    num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX;
	} else {
	    if (parseUnsignedNum(fieldp_backup, &num)) {
		rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"),
			 spec->lineNum, name, spec->line);
		*fieldp = ch;
		return RPMRC_FAIL;
	    }
	}
	*fieldp = ch;
    }

    /* Check whether tags of the same number haven't already been defined */
    for (p = spec->sources; p != NULL; p = p->next) {
	if ( p->num != num ) continue;
	if ((tag == RPMTAG_SOURCE && p->flags == RPMBUILD_ISSOURCE) ||
	    (tag == RPMTAG_PATCH  && p->flags == RPMBUILD_ISPATCH)) {
		rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num);
		return RPMRC_FAIL;
	    }
    }

    /* Create the entry and link it in */
    p = xmalloc(sizeof(*p));
    p->num = num;
    p->fullSource = xstrdup(field);
    p->flags = flag;
    p->source = strrchr(p->fullSource, '/');
    if (p->source) {
	if ((buf = strrchr(p->source,'='))) p->source = buf;
	p->source++;
    } else {
	p->source = p->fullSource;
    }

    if (tag != RPMTAG_ICON) {
	p->next = spec->sources;
	spec->sources = p;
    } else {
	p->next = pkg->icon;
	pkg->icon = p;
    }

    spec->numSources++;

    if (tag != RPMTAG_ICON) {
	char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL);
	struct stat st;
	int nofetch = (spec->flags & RPMSPEC_FORCE) ||
		      rpmExpandNumeric("%{_disable_source_fetch}");

	/* try to download source/patch if it's missing */
	if (lstat(body, &st) != 0 && errno == ENOENT && !nofetch) {
	    char *url = NULL;
	    if (urlIsURL(p->fullSource) != URL_IS_UNKNOWN) {
		url = rstrdup(p->fullSource);
	    } else {
		url = rpmExpand("%{_default_source_url}", NULL);
		rstrcat(&url, p->source);
		if (*url == '%') url = _free(url);
	    }
	    if (url) {
		rpmlog(RPMLOG_WARNING, _("Downloading %s to %s\n"), url, body);
		if (urlGetFile(url, body) != 0) {
		    free(url);
		    rpmlog(RPMLOG_ERR, _("Couldn't download %s\n"), p->fullSource);
		    return RPMRC_FAIL;
		}
		free(url);
	    }
	}

	rasprintf(&buf, "%s%d",
		(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
	rpmPushMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
	free(buf);
	rasprintf(&buf, "%sURL%d",
		(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
	rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
	free(buf);
#ifdef WITH_LUA
	{
	    rpmlua lua = NULL; /* global state */
	    const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources";
	    rpmluaPushTable(lua, what);
	    rpmluav var = rpmluavNew();
	    rpmluavSetListMode(var, 1);
	    rpmluavSetValue(var, RPMLUAV_STRING, body);
	    rpmluaSetVar(lua, var);
	    rpmluavFree(var);
	    rpmluaPop(lua);
	}
#endif
	free(body);
    }
    
    return 0;
}
Exemple #15
0
int
performAction( inStruct Sentries ) {
    int status;
    int c, i, j;
    int uFlag = 0;;
    char tmpStr[100];
    ruleExecInfo_t rei;
    char action[100];
    char *t1;
    char *args[MAX_NUM_OF_ARGS_IN_ACTION];
    char configDirEV[200];
    char retestflagEV[200];
    char reloopbackflagEV[200];

    char ruleSet[RULE_SET_DEF_LENGTH];
    hrtime_t ht1, ht2, ht3;

    bzero( &rei, sizeof( ruleExecInfo_t ) ); /*  June 17. 2009 */
    /*
     sprintf(configDirEV,"irodsConfigDir=/scratch/s1/sekar/irods/RODS/server/config");
     sprintf(configDirEV,"irodsConfigDir=/misc/www/projects/srb-secure/cgi-bin");
     putenv(configDirEV);
    */
    sprintf( retestflagEV, "RETESTFLAG=%i", HTML_TEST_1 );
    putenv( retestflagEV );
    sprintf( reloopbackflagEV, "RELOOPBACKFLAG=%i", LOOP_BACK_1 );
    putenv( reloopbackflagEV );

    fprintf( stdout, "Content-type: text/html%c%c", 10, 10 );
    fflush( stdout );
    fprintf( stdout, "<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n" );
    fprintf( stdout, "<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Application</FONT></B></CENTER>\n" );
    fflush( stdout );

    rei.doi = mallocAndZero( sizeof( dataObjInfo_t ) );
    rei.uoip = mallocAndZero( sizeof( userInfo_t ) );
    rei.uoic = mallocAndZero( sizeof( userInfo_t ) );
    rei.coi = mallocAndZero( sizeof( collInfo_t ) );
    rei.uoio = mallocAndZero( sizeof( userInfo_t ) );
    rei.next = NULL;

    strcpy( rei.doi->objPath, "" );
    strcpy( rei.doi->rescName, "" );
    strcpy( rei.doi->dataType, "" );
    strcpy( rei.uoic->authInfo.host, "" );
    rei.doi->dataSize = 100;


    rei.condInputData = NULL;

    rei.rsComm = NULL;
    strcpy( ruleSet, "" );

    for ( i = 0; i <= Sentries->m; i++ ) {

        if ( !strcmp( Sentries->entries[i].name, "action" ) ) {
            strcpy( action, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>Action:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "objPath" ) ) {
            strcpy( rei.doi->objPath, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$objPath:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "rescName" ) ) {
            strcpy( rei.doi->rescName, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$rescName:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "dataSize" ) ) {
            rei.doi->dataSize = atol( Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$dataSize:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "dataType" ) ) {
            strcpy( rei.doi->dataType, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$dataType:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "dataOwner" ) ) {
            strcpy( rei.doi->dataOwnerName, Sentries->entries[i].val );
            if ( ( t1 = strstr( rei.doi->dataOwnerName, "|" ) ) != NULL ) {
                *t1 = '\0';
                strcpy( rei.doi->dataOwnerZone, ( char * )( t1 + 1 ) );
            }
            else {
                strcpy( rei.doi->dataOwnerZone, "" );
            }
            fprintf( stdout, "<FONT COLOR=#0000FF>$dataOwner:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "dataUser" ) ) {
            strcpy( rei.uoic->userName, Sentries->entries[i].val );
            if ( ( t1 = strstr( rei.uoic->userName, "|" ) ) != NULL ) {
                *t1 = '\0';
                strcpy( rei.uoic->rodsZone, ( char * )( t1 + 1 ) );
            }
            else {
                strcpy( rei.uoic->rodsZone, "" );
            }
            fprintf( stdout, "<FONT COLOR=#0000FF>$dataUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "dataAccess" ) ) {
            strcpy( rei.doi->dataAccess, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$dataAccess:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "hostClient" ) ) {
            strcpy( rei.uoic->authInfo.host, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$hostClient:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "proxyUser" ) ) {
            strcpy( rei.uoip->userName, Sentries->entries[i].val );
            if ( ( t1 = strstr( rei.uoip->userName, "|" ) ) != NULL ) {
                *t1 = '\0';
                strcpy( rei.uoip->rodsZone, ( char * )( t1 + 1 ) );
            }
            else {
                strcpy( rei.uoio->rodsZone, "" );
            }
            fprintf( stdout, "<FONT COLOR=#0000FF>$otherUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "otherUser" ) ) {
            strcpy( rei.uoic->userName, Sentries->entries[i].val );
            if ( ( t1 = strstr( rei.uoio->userName, "|" ) ) != NULL ) {
                *t1 = '\0';
                strcpy( rei.uoio->rodsZone, ( char * )( t1 + 1 ) );
            }
            else {
                strcpy( rei.uoio->rodsZone, "" );
            }
            fprintf( stdout, "<FONT COLOR=#0000FF>$otherUser:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "otherUserType" ) ) {
            strcpy( rei.uoio->userType, Sentries->entries[i].val );
            fprintf( stdout, "<FONT COLOR=#0000FF>$otherUserType:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "ruleSet" ) ) {
            if ( strlen( Sentries->entries[i].val ) > 0 ) {
                if ( ruleSet[0] != '\0' ) {
                    strcat( ruleSet, "," );
                }
                rstrcat( ruleSet, Sentries->entries[i].val, 999 );
            }
        }
        else if ( !strcmp( Sentries->entries[i].name, "retestflag" ) ) {
            sprintf( retestflagEV, "RETESTFLAG=%s", Sentries->entries[i].val );
            putenv( retestflagEV );
            fprintf( stdout, "<FONT COLOR=#0000FF>Trace Status</FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
                     Sentries->entries[i].val );
        }
        else if ( !strcmp( Sentries->entries[i].name, "configDir" ) ) {
            if ( strlen( Sentries->entries[i].val ) > 0 ) {
                snprintf( configDirEV, 199, "irodsConfigDir=%s", Sentries->entries[i].val );
            }
            else {
                sprintf( configDirEV, "irodsConfigDir=%s", MY_SERVER_CONFIG_DIR );
            }
            putenv( configDirEV );
        }

        /*
        else if (!strcmp(Sentries->entries[i].name,"")){
        strcpy(,Sentries->entries[i].val);
        fprintf(stdout,"<FONT COLOR=#0000FF></FONT> <FONT COLOR=#FF0000>%s</FONT><BR>\n",
        	Sentries->entries[i].val);
             }
             */
    }
    fprintf( stdout, "<FONT COLOR=#0000FF>Rule Set:</FONT> <FONT COLOR=#FF0000>%s</FONT><BR><HR>\n", ruleSet );
    strcpy( rei.ruleSet, ruleSet );
    /*    fprintf(stdout,"<PRE>\n");fflush(stdout);*/
    ht1 = gethrtime();
    initRuleStruct( NULL, ruleSet, "core", "core" );
    ht2 = gethrtime();
    /***    i = applyRule(action, args, 0, &rei, SAVE_REI); ***/
    i = applyRuleArgPA( action, args, 0, NULL, &rei, SAVE_REI );
    ht3 = gethrtime();

    if ( reTestFlag == COMMAND_TEST_1 ||  reTestFlag == COMMAND_TEST_MSI ) {
        fprintf( stdout, "Rule Initialization Time = %.2f millisecs\n", ( float )( ht2 - ht1 ) / 1000000 );
        fprintf( stdout, "Rule Execution     Time = %.2f millisecs\n", ( float )( ht3 - ht1 ) / 1000000 );
    }
    if ( reTestFlag == HTML_TEST_1 || reTestFlag ==  HTML_TEST_MSI ) {
        fprintf( stdout, "<BR>Rule Initialization Time = %.2f millisecs<BR>\n", ( float )( ht2 - ht1 ) / 1000000 );
        fprintf( stdout, "Rule Execution     Time = %.2f millisecs<BR>\n", ( float )( ht3 - ht1 ) / 1000000 );
    }

    if ( i != 0 ) {
        rodsLogError( LOG_ERROR, i, "<BR>Rule Application Failed:" );
        /*    fprintf(stdout,"</PRE>\n</body>\n</HTML>\n");*/
        return -1;
    }
    /*    fprintf(stdout,"</PRE>\n</body>\n</HTML>\n");*/

    return 0;
}
Exemple #16
0
int
showRules( inStruct Sentries ) {
    int n, i, j;
    char ruleCondition[MAX_RULE_LENGTH];
    char ruleAction[MAX_RULE_LENGTH];
    char ruleRecovery[MAX_RULE_LENGTH];
    char ruleHead[MAX_ACTION_SIZE];
    char ruleBase[MAX_ACTION_SIZE];
    char *actionArray[MAX_ACTION_IN_RULE];
    char *recoveryArray[MAX_ACTION_IN_RULE];
    char configDirEV[200];
    char ruleSet[RULE_SET_DEF_LENGTH];
    char oldRuleBase[MAX_ACTION_SIZE];
    strcpy( ruleSet, "" );
    strcpy( oldRuleBase, "" );
    fprintf( stdout, "Content-type: text/html%c%c", 10, 10 );
    fflush( stdout );
    fprintf( stdout, "<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n" );
    fprintf( stdout, "<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Base</FONT></B></CENTER>\n" );
    fflush( stdout );

    /*    sprintf(configDirEV,"irodsConfigDir=/scratch/s1/sekar/irods/RODS/server/config");
      sprintf(configDirEV,"irodsConfigDir=/misc/www/projects/srb-secure/cgi-bin");
      putenv(configDirEV);
    */


    for ( i = 0; i <= Sentries->m; i++ ) {
        if ( !strcmp( Sentries->entries[i].name, "ruleSet" ) ) {
            if ( strlen( Sentries->entries[i].val ) > 0 ) {
                if ( ruleSet[0] != '\0' ) {
                    strcat( ruleSet, "," );
                }
                rstrcat( ruleSet, Sentries->entries[i].val, 999 );
            }
        }
        else if ( !strcmp( Sentries->entries[i].name, "configDir" ) ) {
            if ( strlen( Sentries->entries[i].val ) > 0 ) {
                snprintf( configDirEV, 199, "irodsConfigDir=%s", Sentries->entries[i].val );
            }
            else {
                sprintf( configDirEV, "irodsConfigDir=%s", MY_SERVER_CONFIG_DIR );
            }
            putenv( configDirEV );
        }
    }
    if ( ruleSet[0] == '\0' ) {
        strcpy( ruleSet, "core" );
    }
    fprintf( stdout, "<CENTER> <B><FONT COLOR=#0000FF>[%s]</FONT></B></CENTER>\n", ruleSet );
    fflush( stdout );

    initRuleStruct( NULL, ruleSet, "core", "core" );
    fprintf( stdout, "<TABLE>\n" );
    for ( j = 0 ; j < coreRuleStrct.MaxNumOfRules; j++ ) {
        getRule( j + 1000 , ruleBase, ruleHead, ruleCondition, ruleAction, ruleRecovery, MAX_RULE_LENGTH );
        if ( strcmp( oldRuleBase, ruleBase ) ) {
            if ( strlen( oldRuleBase ) > 0 ) {
                fprintf( stdout, "<TR><TD COLSPAN=6><HR NOSHADE COLOR=#00FF00 SIZE=4></TD></TR>" );
            }
            strcpy( oldRuleBase, ruleBase );
        }
        n = getActionRecoveryList( ruleAction, ruleRecovery, actionArray, recoveryArray );
        fprintf( stdout, "<TR><TD><BR>&nbsp;%i</TD><TD><BR>&nbsp;<FONT COLOR=#0000FF>ON</FONT></TD><TD COLSPAN=3><BR>&nbsp;<FONT COLOR=#FF0000>%s.</FONT><FONT COLOR=#0000FF>%s</FONT></TD></TR>\n", j, ruleBase, ruleHead );
        if ( strlen( ruleCondition ) != 0 ) {
            fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>IF &nbsp;</TD><TD  COLSPAN=3 VALIGN=TOP><FONT COLOR=#FF0000>%s</FONT></TD></TR>\n", ruleCondition );
        }
        for ( i = 0; i < n; i++ ) {
            if ( i == 0 )
                fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>DO &nbsp;</TD><TD VALIGN=TOP>%s</TD><TD NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD><TD VALIGN=TOP>[%s]</TD></TR>\n",
                         actionArray[i], recoveryArray[i] );
            else
                fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>AND &nbsp;</TD><TD VALIGN=TOP>%s</TD><TD NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD><TD VALIGN=TOP>[%s]</TD></TR>\n",
                         actionArray[i], recoveryArray[i] );
        }
    }
    fprintf( stdout, "</TABLE>\n" );
    fprintf( stdout, "</BODY>\n</HTML>\n" );
    return 0;
}
Exemple #17
0
void rpmRelocateFileList(rpmRelocation *relocations, int numRelocations, 
			 rpmfs fs, Header h)
{
    char ** baseNames;
    char ** dirNames;
    uint32_t * dirIndexes;
    rpm_count_t fileCount, dirCount;
    int nrelocated = 0;
    int fileAlloced = 0;
    char * fn = NULL;
    int haveRelocatedBase = 0;
    size_t maxlen = 0;
    int i, j;
    struct rpmtd_s bnames, dnames, dindexes, fmodes;

    if (!addPrefixes(h, relocations, numRelocations))
	return;

    if (rpmIsDebug()) {
	rpmlog(RPMLOG_DEBUG, "========== relocations\n");
	for (i = 0; i < numRelocations; i++) {
	    if (relocations[i].oldPath == NULL) continue; /* XXX can't happen */
	    if (relocations[i].newPath == NULL)
		rpmlog(RPMLOG_DEBUG, "%5d exclude  %s\n",
			i, relocations[i].oldPath);
	    else
		rpmlog(RPMLOG_DEBUG, "%5d relocate %s -> %s\n",
			i, relocations[i].oldPath, relocations[i].newPath);
	}
    }

    for (i = 0; i < numRelocations; i++) {
	if (relocations[i].newPath == NULL) continue;
	size_t len = strlen(relocations[i].newPath);
	if (len > maxlen) maxlen = len;
    }

    headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
    headerGet(h, RPMTAG_DIRINDEXES, &dindexes, HEADERGET_ALLOC);
    headerGet(h, RPMTAG_DIRNAMES, &dnames, HEADERGET_MINMEM);
    headerGet(h, RPMTAG_FILEMODES, &fmodes, HEADERGET_MINMEM);
    /* TODO XXX ugh.. use rpmtd iterators & friends instead */
    baseNames = bnames.data;
    dirIndexes = dindexes.data;
    fileCount = rpmtdCount(&bnames);
    dirCount = rpmtdCount(&dnames);
    /* XXX TODO: use rpmtdDup() instead */
    dirNames = dnames.data = duparray(dnames.data, dirCount);
    dnames.flags |= RPMTD_PTR_ALLOCED;

    /*
     * For all relocations, we go through sorted file/relocation lists 
     * backwards so that /usr/local relocations take precedence over /usr 
     * ones.
     */

    /* Relocate individual paths. */

    for (i = fileCount - 1; i >= 0; i--) {
	rpmFileTypes ft;
	int fnlen;

	size_t len = maxlen +
		strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
	if (len >= fileAlloced) {
	    fileAlloced = len * 2;
	    fn = xrealloc(fn, fileAlloced);
	}

assert(fn != NULL);		/* XXX can't happen */
	*fn = '\0';
	fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;

	/*
	 * See if this file path needs relocating.
	 */
	/*
	 * XXX FIXME: Would a bsearch of the (already sorted) 
	 * relocation list be a good idea?
	 */
	for (j = numRelocations - 1; j >= 0; j--) {
	    if (relocations[j].oldPath == NULL) /* XXX can't happen */
		continue;
	    len = !rstreq(relocations[j].oldPath, "/")
		? strlen(relocations[j].oldPath)
		: 0;

	    if (fnlen < len)
		continue;
	    /*
	     * Only subdirectories or complete file paths may be relocated. We
	     * don't check for '\0' as our directory names all end in '/'.
	     */
	    if (!(fn[len] == '/' || fnlen == len))
		continue;

	    if (!rstreqn(relocations[j].oldPath, fn, len))
		continue;
	    break;
	}
	if (j < 0) continue;

	rpmtdSetIndex(&fmodes, i);
	ft = rpmfiWhatis(rpmtdGetNumber(&fmodes));

	/* On install, a relocate to NULL means skip the path. */
	if (relocations[j].newPath == NULL) {
	    if (ft == XDIR) {
		/* Start with the parent, looking for directory to exclude. */
		for (j = dirIndexes[i]; j < dirCount; j++) {
		    len = strlen(dirNames[j]) - 1;
		    while (len > 0 && dirNames[j][len-1] == '/') len--;
		    if (fnlen != len)
			continue;
		    if (!rstreqn(fn, dirNames[j], fnlen))
			continue;
		    break;
		}
	    }
	    rpmfsSetAction(fs, i, FA_SKIPNSTATE);
	    rpmlog(RPMLOG_DEBUG, "excluding %s %s\n",
		   ftstring(ft), fn);
	    continue;
	}

	/* Relocation on full paths only, please. */
	if (fnlen != len) continue;

	rpmlog(RPMLOG_DEBUG, "relocating %s to %s\n",
	       fn, relocations[j].newPath);
	nrelocated++;

	strcpy(fn, relocations[j].newPath);
	{   char * te = strrchr(fn, '/');
	    if (te) {
		if (te > fn) te++;	/* root is special */
		fnlen = te - fn;
	    } else
		te = fn + strlen(fn);
	    if (!rstreq(baseNames[i], te)) { /* basename changed too? */
		if (!haveRelocatedBase) {
		    /* XXX TODO: use rpmtdDup() instead */
		    bnames.data = baseNames = duparray(baseNames, fileCount);
		    bnames.flags |= RPMTD_PTR_ALLOCED;
		    haveRelocatedBase = 1;
		}
		free(baseNames[i]);
		baseNames[i] = xstrdup(te);
	    }
	    *te = '\0';			/* terminate new directory name */
	}

	/* Does this directory already exist in the directory list? */
	for (j = 0; j < dirCount; j++) {
	    if (fnlen != strlen(dirNames[j]))
		continue;
	    if (!rstreqn(fn, dirNames[j], fnlen))
		continue;
	    break;
	}
	
	if (j < dirCount) {
	    dirIndexes[i] = j;
	    continue;
	}

	/* Creating new paths is a pita */
	dirNames = dnames.data = xrealloc(dnames.data, 
			       sizeof(*dirNames) * (dirCount + 1));

	dirNames[dirCount] = xstrdup(fn);
	dirIndexes[i] = dirCount;
	dirCount++;
	dnames.count++;
    }

    /* Finish off by relocating directories. */
    for (i = dirCount - 1; i >= 0; i--) {
	for (j = numRelocations - 1; j >= 0; j--) {

	    if (relocations[j].oldPath == NULL) /* XXX can't happen */
		continue;
	    size_t len = !rstreq(relocations[j].oldPath, "/")
		? strlen(relocations[j].oldPath)
		: 0;

	    if (len && !rstreqn(relocations[j].oldPath, dirNames[i], len))
		continue;

	    /*
	     * Only subdirectories or complete file paths may be relocated. We
	     * don't check for '\0' as our directory names all end in '/'.
	     */
	    if (dirNames[i][len] != '/')
		continue;

	    if (relocations[j].newPath) { /* Relocate the path */
		char *t = NULL;
		rstrscat(&t, relocations[j].newPath, (dirNames[i] + len), NULL);
		/* Unfortunately rpmCleanPath strips the trailing slash.. */
		(void) rpmCleanPath(t);
		rstrcat(&t, "/");

		rpmlog(RPMLOG_DEBUG,
		       "relocating directory %s to %s\n", dirNames[i], t);
		free(dirNames[i]);
		dirNames[i] = t;
		nrelocated++;
	    }
	}
    }

    /* Save original filenames in header and replace (relocated) filenames. */
    if (nrelocated) {
	saveOrig(h);
	headerMod(h, &bnames);
	headerMod(h, &dnames);
	headerMod(h, &dindexes);
    }

    rpmtdFreeData(&bnames);
    rpmtdFreeData(&dnames);
    rpmtdFreeData(&dindexes);
    rpmtdFreeData(&fmodes);
    free(fn);
}
Exemple #18
0
/**
 * \fn msiServerMonPerf (msParam_t *verb, msParam_t *ptime, ruleExecInfo_t *rei)
 *
 * \brief  This microservice monitors the servers' activity and performance.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2009-06
 *
 * \note  This microservice monitors the servers' activity and performance
 *    for CPU, network, memory and more.  It retrieves the list of servers
 *    to monitor from the MON_CFG_FILE if it exists, or the iCAT if the
 *    configuration file does not exist.
 *
 * \note The MON_PERF_SCRIPT is executed on each host. The result is put
 *    in the OUTPUT_MON_PERF file and will also be put in the iCAT in the
 *    near future.
 *
 * \usage See clients/icommands/test/rules3.0/ and https://wiki.irods.org/index.php/Resource_Monitoring_System
 *
 * \param[in] verb - a msParam of type STR_MS_T defining verbose mode:
 *    \li "default" - not verbose
 *    \li "verbose" - verbose mode
 * \param[in] ptime - a msParam of type STR_MS_T defining probe time
 *    in seconds. "default" is equal to 10 seconds.
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified resource status flag, resource free space available,
 table R_SERVER_LOAD
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa N/A
 **/
int msiServerMonPerf( msParam_t *verb, msParam_t *ptime, ruleExecInfo_t *rei ) {
    char line[MAX_VALUE], *verbosity;
    char serverList[MAX_VALUE][MAX_NAME_LEN];
    char cmd[MAX_NAME_LEN]; /* cmd => name of the Perl script */
    char probtime[LEN_SECONDS], measTime[LEN_SECONDS];
    FILE *filein; /* file pointers */
    const char *delim = " \n";
    char valinit[MAX_NAME_LEN] = "";
    char val[MAX_NAME_LEN] = ""; /* val => arguments for the script */
    int check, i, indx, j, looptime, maxtime, nresc, nservers, thrCount, threadsNotfinished;
    const char *probtimeDef = "10"; /* default value used by the monitoring script for the amount
                                       of time for this measurement (in s) */
    rsComm_t *rsComm;
    monInfo_t rescList[MAX_NSERVERS];
    thrInp_t *thrInput;
    int addPathToArgv = 0;
    char *hintPath = "";

    RE_TEST_MACRO( "    Calling msiServerMonPerf" )

    /* the above line is needed for loop back testing using irule -i option */

    rsComm = rei->rsComm;

    if ( verb->inOutStruct != NULL ) {
        verbosity = ( char * ) verb->inOutStruct;
        if ( strcmp( verbosity, "verbose" ) == 0 ) {
            strcat( valinit, "-v " );
        }
    }

    strcat( valinit, " -t " );

    strncpy( probtime, ( char * ) ptime->inOutStruct,  LEN_SECONDS );
    if ( atoi( probtime ) > 0 ) {
        strcat( valinit, probtime );
        strncpy( measTime, probtime, LEN_SECONDS );
    }
    else {
        strcat( valinit, probtimeDef );
        strncpy( measTime, probtimeDef, LEN_SECONDS );
    }

    rstrcpy( val, "", MAX_NAME_LEN );

    /* read the config file or the iCAT to know the servers list to monitor */
    nresc = 0;

    nservers = -1;  /* nservers = -1, no config file available, consider all ressources for the monitoring */
    /* nservers >= 0, config file available, consider all resources hosted on the list of servers */
    if ( ( filein = fopen( MON_CFG_FILE, "r" ) ) != NULL ) {
        i = 0;
        while ( fgets( line, sizeof line, filein ) != NULL ) { /* for each line of the file */
            /* if begin of line = # => ignore */
            if ( line[0] != '#' ) {
                std::vector<std::string> tokens;
                boost::algorithm::split( tokens, line, boost::is_any_of( delim ) );
                snprintf( serverList[i], MAX_NAME_LEN, "%s", tokens[0].c_str() );
                i++;
            }
        }
        /* number of servers... useful for the threads */
        nservers = i;
        /* close the configuration file */
        fclose( filein );
    }
    getListOfResc( rsComm, serverList, nservers, rescList, &nresc );

    strcpy( cmd, MON_PERF_SCRIPT );
#ifndef windows_platform
    pthread_t *threads = ( pthread_t* )malloc( sizeof( pthread_t ) * nresc );
    pthread_mutex_init( &my_mutex, NULL );
#endif
    thrInput = ( thrInp_t* )malloc( sizeof( thrInp_t ) * nresc );
    thrCount = 0;

    for ( i = 0; i < nresc; i++ ) {
        /* for each server, build the proxy command to be executed.
           it will be put in a thrInp structure to be given to the thread.
           then start one thread for each server to be monitored */
        check = 0;
        indx = 0;
        for ( j = 0; j < thrCount; j++ ) {
            if ( strcmp( thrInput[j].execAddr, rescList[i].serverName ) == 0 ) {
                indx = j;
                check = 1;
            }
        }
        if ( check == 0 ) {
            strcpy( thrInput[thrCount].cmdArgv, valinit );
            strcat( thrInput[thrCount].cmdArgv, " -fs " );
            if ( strcmp( rescList[thrCount].rescType, "unixfilesystem" ) == 0 ) {
                strcat( thrInput[thrCount].cmdArgv, rescList[i].vaultPath );
            }
            else {
                strcat( thrInput[thrCount].cmdArgv, "none" );
            }
            rstrcpy( thrInput[thrCount].cmd, cmd, LONG_NAME_LEN );
            rstrcpy( thrInput[thrCount].execAddr, rescList[i].serverName, LONG_NAME_LEN );
            rstrcpy( thrInput[thrCount].hintPath, hintPath, MAX_NAME_LEN );
            thrInput[thrCount].addPathToArgv = addPathToArgv;
            thrInput[thrCount].threadId = thrCount;
            rstrcpy( thrInput[thrCount].rescName, rescList[i].rescName, MAX_NAME_LEN );
            memcpy( &( thrInput[thrCount].rei ), rei, sizeof( ruleExecInfo_t ) );
            thrCount += 1;
        }
        else {
            rstrcat( thrInput[indx].rescName, ",", MAX_NAME_LEN );
            rstrcat( thrInput[indx].rescName, rescList[i].rescName, MAX_NAME_LEN );
            if ( strcmp( rescList[i].rescType, "unixfilesystem" ) == 0 ) {
                strcat( thrInput[indx].cmdArgv, "," );
                strcat( thrInput[indx].cmdArgv, rescList[i].vaultPath );
            }
            else {
                strcat( thrInput[indx].cmdArgv, ",none" );
            }
        }
        rstrcpy( val, "", MAX_NAME_LEN );
    }

    for ( i = 0; i < thrCount; i++ ) {
#ifndef windows_platform
        if ( pthread_create( &threads[i], NULL, *startMonScript, ( void * ) &thrInput[i] ) < 0 ) {
            rodsLog( LOG_ERROR, "msiServerMonPerf: pthread_create error\n" );
            exit( 1 );
        }
#endif
    }

    maxtime = atoi( measTime ) + TIMEOUT;
    looptime = 0;
    while ( 1 ) {
        sleep( 1 );
        looptime += 1;
        if ( looptime >= maxtime ) {
            for ( i = 0; i < thrCount; i++ ) {
                if ( !threadIsAlive[i] ) {
#ifndef windows_platform
                    int rc = pthread_cancel( threads[i] );
                    if ( rc == 0 ) {
                        char noanswer[MAXSTR] = MON_OUTPUT_NO_ANSWER;
                        threadIsAlive[i] = 1;
                        rodsMonPerfLog( thrInput[i].execAddr,
                                        thrInput[i].rescName,
                                        noanswer,
                                        &( thrInput[i].rei ) );
                    }
#endif
                }
            }
        }
        threadsNotfinished = 1;
        for ( i = 0; i < thrCount; i++ ) {
            if ( threadIsAlive[i] == 0 ) {
                threadsNotfinished = 0;
            }
        }
        if ( threadsNotfinished ) {
            break;
        }
    }

#ifndef windows_platform
    free( threads );
#endif
    free( thrInput );

    return rei->status;

}
Exemple #19
0
rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
{
    struct cpioSourceArchive_s csabuf;
    CSA_t csa = &csabuf;
    rpmRC rc;
    const char *errorString;
    Package pkg;
    char *pkglist = NULL;

    trimChangelog(spec->packages->header);
    for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
	char *fn;

	if (pkg->fileList == NULL)
	    continue;

	if ((rc = processScriptFiles(spec, pkg)))
	    return rc;
	
	if (cookie) {
	    headerPutString(pkg->header, RPMTAG_COOKIE, cookie);
	}

	/* Copy changelog from src rpm */
	headerCopyTags(spec->packages->header, pkg->header, copyTags);
	
	headerPutString(pkg->header, RPMTAG_RPMVERSION, VERSION);
	headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost());
	headerPutUint32(pkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1);

	addPackageProvides(pkg->header);

    {	char * optflags = rpmExpand("%{optflags}", NULL);
	headerPutString(pkg->header, RPMTAG_OPTFLAGS, optflags);
	optflags = _free(optflags);
    }

	if (spec->sourcePkgId != NULL) {
	    headerPutBin(pkg->header, RPMTAG_SOURCEPKGID, spec->sourcePkgId,16);
	}

	if (cheating) {
	    (void) rpmlibNeedsFeature(pkg->header, "ShortCircuited", "4.9.0-1");
	}
	
	{   char *binFormat = rpmGetPath("%{_rpmfilename}", NULL);
	    char *binRpm, *binDir;
	    binRpm = headerFormat(pkg->header, binFormat, &errorString);
	    binFormat = _free(binFormat);
	    if (binRpm == NULL) {
		rpmlog(RPMLOG_ERR, _("Could not generate output "
		     "filename for package %s: %s\n"), 
		     headerGetString(pkg->header, RPMTAG_NAME), errorString);
		return RPMRC_FAIL;
	    }
	    fn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
	    if ((binDir = strchr(binRpm, '/')) != NULL) {
		struct stat st;
		char *dn;
		*binDir = '\0';
		dn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
		if (stat(dn, &st) < 0) {
		    switch(errno) {
		    case  ENOENT:
			if (mkdir(dn, 0755) == 0)
			    break;
		    default:
			rpmlog(RPMLOG_ERR,_("cannot create %s: %s\n"),
			    dn, strerror(errno));
			break;
		    }
		}
		dn = _free(dn);
	    }
	    binRpm = _free(binRpm);
	}

	memset(csa, 0, sizeof(*csa));
	csa->cpioArchiveSize = 0;
	csa->cpioFdIn = fdNew();
	csa->cpioList = rpmfiLink(pkg->cpioList);

	rc = writeRPM(&pkg->header, NULL, fn, csa, NULL);
	csa->cpioList = rpmfiFree(csa->cpioList);
	csa->cpioFdIn = fdFree(csa->cpioFdIn);
	if (rc == RPMRC_OK) {
	    /* Do check each written package if enabled */
	    char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", fn, NULL);
	    if (pkgcheck[0] != ' ') {
		rc = checkPackages(pkgcheck);
	    }
	    pkgcheck = _free(pkgcheck);
	    rstrcat(&pkglist, fn);
	    rstrcat(&pkglist, " ");
	}
	fn = _free(fn);
	if (rc != RPMRC_OK) {
	    pkglist = _free(pkglist);
	    return rc;
	}
    }

    /* Now check the package set if enabled */
    if (pkglist != NULL) {
	char *pkgcheck_set = rpmExpand("%{?_build_pkgcheck_set} ", pkglist,  NULL);
	if (pkgcheck_set[0] != ' ') {	/* run only if _build_pkgcheck_set is defined */
	    checkPackages(pkgcheck_set);
	}
	pkgcheck_set = _free(pkgcheck_set);
	pkglist = _free(pkglist);
    }
    
    return RPMRC_OK;
}
Exemple #20
0
Fichier : verify.c Projet : xrg/RPM
/**
 * Check file info from header against what's actually installed.
 * @param qva		parsed query/verify options
 * @param ts		transaction set
 * @param h		header to verify
 * @return		0 no problems, 1 problems found
 */
static int verifyHeader(QVA_t qva, const rpmts ts, Header h)
{
    rpmVerifyAttrs verifyResult = 0;
    /* FIX: union? */
    rpmVerifyAttrs omitMask = ((qva->qva_flags & VERIFY_ATTRS) ^ VERIFY_ATTRS);
    int ec = 0;		/* assume no problems */
    char *buf = NULL;
    int i;

    rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_FLAGS_VERIFY);
    rpmfiInit(fi, 0);
    while ((i = rpmfiNext(fi)) >= 0) {
	rpmfileAttrs fileAttrs;
	int rc;

	fileAttrs = rpmfiFFlags(fi);

	/* If not verifying %ghost, skip ghost files. */
	if (!(qva->qva_fflags & RPMFILE_GHOST)
	&& (fileAttrs & RPMFILE_GHOST))
	    continue;

	rc = rpmVerifyFile(ts, fi, &verifyResult, omitMask);
	if (rc) {
	    if (!(fileAttrs & (RPMFILE_MISSINGOK|RPMFILE_GHOST)) || rpmIsVerbose()) {
		rasprintf(&buf, _("missing   %c %s"),
			((fileAttrs & RPMFILE_CONFIG)	? 'c' :
			 (fileAttrs & RPMFILE_DOC)	? 'd' :
			 (fileAttrs & RPMFILE_GHOST)	? 'g' :
			 (fileAttrs & RPMFILE_LICENSE)	? 'l' :
			 (fileAttrs & RPMFILE_PUBKEY)	? 'P' :
			 (fileAttrs & RPMFILE_README)	? 'r' : ' '), 
			rpmfiFN(fi));
		if ((verifyResult & RPMVERIFY_LSTATFAIL) != 0 &&
		    errno != ENOENT) {
		    char *app;
		    rasprintf(&app, " (%s)", strerror(errno));
		    rstrcat(&buf, app);
		    free(app);
		}
		ec = rc;
	    }
	} else if (verifyResult || rpmIsVerbose()) {
	    const char * size, * MD5, * link, * mtime, * mode;
	    const char * group, * user, * rdev, *caps;
	    static const char *const aok = ".";
	    static const char *const unknown = "?";

	    ec = 1;

#define	_verify(_RPMVERIFY_F, _C)	\
	((verifyResult & _RPMVERIFY_F) ? _C : aok)
#define	_verifylink(_RPMVERIFY_F, _C)	\
	((verifyResult & RPMVERIFY_READLINKFAIL) ? unknown : \
	 (verifyResult & _RPMVERIFY_F) ? _C : aok)
#define	_verifyfile(_RPMVERIFY_F, _C)	\
	((verifyResult & RPMVERIFY_READFAIL) ? unknown : \
	 (verifyResult & _RPMVERIFY_F) ? _C : aok)
	
	    MD5 = _verifyfile(RPMVERIFY_MD5, "5");
	    size = _verify(RPMVERIFY_FILESIZE, "S");
	    link = _verifylink(RPMVERIFY_LINKTO, "L");
	    mtime = _verify(RPMVERIFY_MTIME, "T");
	    rdev = _verify(RPMVERIFY_RDEV, "D");
	    user = _verify(RPMVERIFY_USER, "U");
	    group = _verify(RPMVERIFY_GROUP, "G");
	    mode = _verify(RPMVERIFY_MODE, "M");
	    caps = _verify(RPMVERIFY_CAPS, "P");

#undef _verifyfile
#undef _verifylink
#undef _verify

	    rasprintf(&buf, "%s%s%s%s%s%s%s%s%s  %c %s",
			size, mode, MD5, rdev, link, user, group, mtime, caps,
			((fileAttrs & RPMFILE_CONFIG)	? 'c' :
			 (fileAttrs & RPMFILE_DOC)	? 'd' :
			 (fileAttrs & RPMFILE_GHOST)	? 'g' :
			 (fileAttrs & RPMFILE_LICENSE)	? 'l' :
			 (fileAttrs & RPMFILE_PUBKEY)	? 'P' :
			 (fileAttrs & RPMFILE_README)	? 'r' : ' '), 
			rpmfiFN(fi));
	}

	if (buf) {
	    rpmlog(RPMLOG_NOTICE, "%s\n", buf);
	    buf = _free(buf);
	}
    }
    rpmfiFree(fi);
	
    return ec;
}
Exemple #21
0
/*
Via a general query, show the AVUs for a collection
*/
int
showColl(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char fullName[MAX_NAME_LEN];
   int  status;
   char *columnNames[]={"attribute", "value", "units"};

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for collection %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_COLL_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_COLL_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_COLL_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   if (strlen(name)>0) {
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      else {
	 rstrcat(fullName, "/", MAX_NAME_LEN);
	 rstrcat(fullName, name, MAX_NAME_LEN);
      }
   }
   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",fullName);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   if (attrName != NULL && *attrName!='\0') {
      i2a[1]=COL_META_COLL_ATTR_NAME;
      if (wild) {
	 sprintf(v2,"like '%s'",attrName);
      }
      else {
	 sprintf(v2,"= '%s'",attrName);
      }
      condVal[1]=v2;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_COLL_COMMENTS;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Collection %s does not exist.\n", fullName);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #22
0
/**
 * Check file info from header against what's actually installed.
 * @param ts		transaction set
 * @param h		header to verify
 * @param omitMask	bits to disable verify checks
 * @param incAttr	skip files without these attrs (eg %ghost)
 * @param skipAttr	skip files with these attrs (eg %ghost)
 * @return		0 no problems, 1 problems found
 */
static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask,
			rpmfileAttrs incAttrs, rpmfileAttrs skipAttrs)
{
    rpmVerifyAttrs verifyResult = 0;
    rpmVerifyAttrs verifyAll = 0; /* assume no problems */
    rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_FLAGS_VERIFY);

    if (fi == NULL)
	return 1;

    rpmfiInit(fi, 0);
    while (rpmfiNext(fi) >= 0) {
	rpmfileAttrs fileAttrs = rpmfiFFlags(fi);
	char *buf = NULL, *attrFormat;
	const char *fstate = NULL;
	char ac;

	/* If filtering by inclusion, skip non-matching (eg --configfiles) */
	if (incAttrs && !(incAttrs & fileAttrs))
	    continue;

	/* Skip on attributes (eg from --noghost) */
	if (skipAttrs & fileAttrs)
	    continue;

	verifyResult = rpmfiVerify(fi, omitMask);

	/* Filter out timestamp differences of shared files */
	if (verifyResult & RPMVERIFY_MTIME) {
	    rpmdbMatchIterator mi;
	    mi = rpmtsInitIterator(ts, RPMDBI_BASENAMES, rpmfiFN(fi), 0);
	    if (rpmdbGetIteratorCount(mi) > 1) 
		verifyResult &= ~RPMVERIFY_MTIME;
	    rpmdbFreeIterator(mi);
	}

	/* State is only meaningful for installed packages */
	if (headerGetInstance(h))
	    fstate = stateStr(rpmfiFState(fi));

	attrFormat = rpmFFlagsString(fileAttrs, "");
	ac = rstreq(attrFormat, "") ? ' ' : attrFormat[0];
	if (verifyResult & RPMVERIFY_LSTATFAIL) {
	    if (!(fileAttrs & (RPMFILE_MISSINGOK|RPMFILE_GHOST)) || rpmIsVerbose()) {
		rasprintf(&buf, _("missing   %c %s"), ac, rpmfiFN(fi));
		if ((verifyResult & RPMVERIFY_LSTATFAIL) != 0 &&
		    errno != ENOENT) {
		    char *app;
		    rasprintf(&app, " (%s)", strerror(errno));
		    rstrcat(&buf, app);
		    free(app);
		}
	    }
	} else if (verifyResult || fstate || rpmIsVerbose()) {
	    char *verifyFormat = rpmVerifyString(verifyResult, ".");
	    rasprintf(&buf, "%s  %c %s", verifyFormat, ac, rpmfiFN(fi));
	    free(verifyFormat);
	}
	free(attrFormat);

	if (buf) {
	    if (fstate)
		buf = rstrscat(&buf, " (", fstate, ")", NULL);
	    rpmlog(RPMLOG_NOTICE, "%s\n", buf);
	    buf = _free(buf);
	}
	verifyAll |= verifyResult;
    }
    rpmfiFree(fi);
	
    return (verifyAll != 0) ? 1 : 0;
}
Exemple #23
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);
}
Exemple #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);
}
Exemple #25
0
/*
Do a query on AVUs for collections and show the results
 */
int queryCollection(char *cmdToken[]) {
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20];
   int i2a[20];
   char *condVal[20];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   int status;
   char *columnNames[]={"collection"};
   int cmdIx;
   int condIx;
   char vstr[20] [BIG_STR];

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printCount=0;
   i1a[0]=COL_COLL_NAME;
   i1b[0]=0;  /* (unused) */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 1;

   i2a[0]=COL_META_COLL_ATTR_NAME;
   sprintf(v1,"='%s'", cmdToken[2]);
   condVal[0]=v1;

   i2a[1]=COL_META_COLL_ATTR_VALUE;
   sprintf(v2, "%s '%s'", cmdToken[3], cmdToken[4]);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (strcmp(cmdToken[5], "or")==0) {
      sprintf(v3, "|| %s '%s'", cmdToken[6], cmdToken[7]);
      rstrcat(v2, v3, BIG_STR);
   }

   cmdIx = 5;
   condIx = 2;
   while (strcmp(cmdToken[cmdIx], "and")==0) {
      i2a[condIx]=COL_META_COLL_ATTR_NAME;
      cmdIx++;
      sprintf(vstr[condIx],"='%s'", cmdToken[cmdIx]);
      condVal[condIx]=vstr[condIx];
      condIx++;

      i2a[condIx]=COL_META_COLL_ATTR_VALUE;
      sprintf(vstr[condIx], "%s '%s'", cmdToken[cmdIx+1], cmdToken[cmdIx+2]);
      cmdIx+=3;
      condVal[condIx]=vstr[condIx];
      condIx++;
      genQueryInp.sqlCondInp.len+=2;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #26
0
/*
 Via a general query and show the AVUs for a dataobject.
 */
int
showDataObj(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   char fullName[MAX_NAME_LEN];
   char myDirName[MAX_NAME_LEN];
   char myFileName[MAX_NAME_LEN];
   int status;
   /* "id" only used in testMode, in longMode id is reset to be 'time set' :*/
   char *columnNames[]={"attribute", "value", "units", "id"};

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for dataObj %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_DATA_ATTR_NAME;
   i1b[0]=0;
   i1a[1]=COL_META_DATA_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_DATA_ATTR_UNITS;
   i1b[2]=0;
   if (testMode) {
      i1a[3]=COL_META_DATA_ATTR_ID;
      i1b[3]=0;
   }
   if (longMode) {
      i1a[3]=COL_META_DATA_MODIFY_TIME;
      i1b[3]=0;
      columnNames[3]="time set";
   }
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;
   if (testMode) {
      genQueryInp.selectInp.len = 4;
   }
   if (longMode) {
      genQueryInp.selectInp.len = 4;
   }

   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",cwd);
   condVal[0]=v1;

   i2a[1]=COL_DATA_NAME;
   sprintf(v2,"='%s'",name);
   condVal[1]=v2;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   rstrcat(fullName, "/", MAX_NAME_LEN);
   rstrcat(fullName, name, MAX_NAME_LEN);
   if (strstr(name, "/") != NULL) {
      /* reset v1 and v2 for when full path or relative path entered */
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      status = splitPathByKey(fullName, 
			      myDirName, myFileName, '/');
      sprintf(v1,"='%s'",myDirName);
      sprintf(v2,"='%s'",myFileName);
   }

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (attrName != NULL && *attrName!='\0') {
      i2a[2]=COL_META_DATA_ATTR_NAME;
      if (wild) {
	 sprintf(v3,"like '%s'",attrName);
      }
      else {
	 sprintf(v3,"= '%s'",attrName);
      }
      condVal[2]=v3;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_D_DATA_PATH;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Dataobject %s does not exist.\n", fullName);
	 return(0);
      }
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }
   else {
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #27
0
/*
 Modify (copy) AVUs
 */
int
modCopyAVUMetadata(char *arg0, char *arg1, char *arg2, char *arg3, 
	     char *arg4, char *arg5, char *arg6, char *arg7) {
   modAVUMetadataInp_t modAVUMetadataInp;
   int status;
   char *mySubName;
   char *myName;
   char fullName1[MAX_NAME_LEN];
   char fullName2[MAX_NAME_LEN];

   strncpy(fullName1, cwd, MAX_NAME_LEN);
   if (strcmp(arg1,"-R")==0 || strcmp(arg1,"-r")==0 || 
       strcmp(arg1,"-G")==0 || strcmp(arg1,"-g")==0 || 
       strcmp(arg1,"-u")==0) {
      strncpy(fullName1, arg3, MAX_NAME_LEN);
   }
   else {
      if (strlen(arg3)>0) {
	 if (*arg3=='/') {
	    strncpy(fullName1, arg3, MAX_NAME_LEN);
	 }
	 else {
	    rstrcat(fullName1, "/", MAX_NAME_LEN);
	    rstrcat(fullName1, arg3, MAX_NAME_LEN);
	 }
      }
   }

   strncpy(fullName2, cwd, MAX_NAME_LEN);
   if (strcmp(arg2,"-R")==0 || strcmp(arg2,"-r")==0 || 
       strcmp(arg2,"-G")==0 || strcmp(arg2,"-g")==0 || 
       strcmp(arg2,"-u")==0) {
      strncpy(fullName2, arg4, MAX_NAME_LEN);
   }
   else {
      if (strlen(arg4)>0) {
	 if (*arg4=='/') {
	    strncpy(fullName2, arg4, MAX_NAME_LEN);
	 }
	 else {
	    rstrcat(fullName2, "/", MAX_NAME_LEN);
	    rstrcat(fullName2, arg4, MAX_NAME_LEN);
	 }
      }
   }

   modAVUMetadataInp.arg0 = arg0;
   modAVUMetadataInp.arg1 = arg1;
   modAVUMetadataInp.arg2 = arg2;
   modAVUMetadataInp.arg3 = fullName1;
   modAVUMetadataInp.arg4 = fullName2;
   modAVUMetadataInp.arg5 = arg5;
   modAVUMetadataInp.arg6 = arg6;
   modAVUMetadataInp.arg7 = arg7;
   modAVUMetadataInp.arg8 ="";
   modAVUMetadataInp.arg9 ="";

   status = rcModAVUMetadata(Conn, &modAVUMetadataInp);
   lastCommandStatus = status;

   if (status < 0 ) {
      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);
	 }
      }
      myName = rodsErrorName(status, &mySubName);
      rodsLog (LOG_ERROR, "rcModAVUMetadata failed with error %d %s %s",
	       status, myName, mySubName);
   }

   if (status == CAT_UNKNOWN_FILE) {
      char tempName[MAX_NAME_LEN]="/";
      int len;
      int isRemote=0;
      strncat(tempName, myEnv.rodsZone, MAX_NAME_LEN);
      len = strlen(tempName);
      if (strncmp(tempName, fullName1, len) != 0) {
	 printf("Cannot copy metadata from a remote zone.\n");
	 isRemote=1;
      }
      if (strncmp(tempName, fullName2, len) != 0) {
	 printf("Cannot copy metadata to a remote zone.\n");
	 isRemote=1;
      }
      if (isRemote) {
	 printf("Copying of metadata is done via SQL within each ICAT\n");
	 printf("for efficiency.  Copying metadata between zones is\n");
	 printf("not implemented.\n");
      }
   }
   return(status);
}