Beispiel #1
0
static rpmfcAttr rpmfcAttrNew(const char *name)
{
    rpmfcAttr attr = xcalloc(1, sizeof(*attr));
    struct matchRule *rules[] = { &attr->incl, &attr->excl, NULL };

    attr->name = xstrdup(name);
    for (struct matchRule **rule = rules; rule && *rule; rule++) {
	const char *prefix = (*rule == &attr->incl) ? NULL : "exclude";
	char *flags = rpmfcAttrMacro(name, prefix, "flags");

	(*rule)->path = rpmfcAttrReg(name, prefix, "path");
	(*rule)->magic = rpmfcAttrReg(name, prefix, "magic");
	(*rule)->flags = argvSplitString(flags, ",", ARGV_SKIPEMPTY);
	argvSort((*rule)->flags, NULL);

	free(flags);
    }

    return attr;
}
Beispiel #2
0
static sepol *sepolNew(rpmte te)
{
    sepol *head = NULL;
    sepol *ret = NULL;
    sepolAction action;
    Header h;
    struct rpmtd_s policies, names, types, typesidx, flags;
    int i, j;
    int count;

    rpmtdReset(&policies);
    rpmtdReset(&names);
    rpmtdReset(&types);
    rpmtdReset(&typesidx);
    rpmtdReset(&flags);

    h = rpmteHeader(te);
    if (!h) {
	goto exit;
    }

    if (!headerIsEntry(h, RPMTAG_POLICIES)) {
	goto exit;
    }

    if (!headerGet(h, RPMTAG_POLICIES, &policies, HEADERGET_MINMEM)) {
	goto exit;
    }

    count = rpmtdCount(&policies);
    if (count <= 0) {
	goto exit;
    }

    if (!headerGet(h, RPMTAG_POLICYNAMES, &names, HEADERGET_MINMEM)
	|| rpmtdCount(&names) != count) {
	goto exit;
    }

    if (!headerGet(h, RPMTAG_POLICYFLAGS, &flags, HEADERGET_MINMEM)
	|| rpmtdCount(&flags) != count) {
	goto exit;
    }

    if (!headerGet(h, RPMTAG_POLICYTYPES, &types, HEADERGET_MINMEM)) {
	goto exit;
    }

    if (!headerGet(h, RPMTAG_POLICYTYPESINDEXES, &typesidx, HEADERGET_MINMEM)
	|| rpmtdCount(&types) != rpmtdCount(&typesidx)) {
	goto exit;
    }

    action = (rpmteType(te) == TR_ADDED) ? SEPOL_ACTION_INSTALL : SEPOL_ACTION_REMOVE;

    for (i = 0; i < count; i++) {
	sepol *pol = xcalloc(1, sizeof(*pol));
	pol->next = head;
	head = pol;

	pol->data = xstrdup(rpmtdNextString(&policies));
	pol->name = xstrdup(rpmtdNextString(&names));
	pol->flags = *rpmtdNextUint32(&flags);
	pol->action = action;

	for (j = 0; j < rpmtdCount(&types); j++) {
	    uint32_t index = ((uint32_t *) typesidx.data)[j];
	    if (index < 0 || index >= count) {
		goto exit;
	    }
	    if (index != i) {
		continue;
	    }
	    argvAdd(&pol->types, rpmtdNextString(&types));
	}
	argvSort(pol->types, NULL);
    }

    ret = head;

  exit:
    headerFree(h);

    rpmtdFreeData(&policies);
    rpmtdFreeData(&names);
    rpmtdFreeData(&types);
    rpmtdFreeData(&typesidx);
    rpmtdFreeData(&flags);

    if (!ret) {
	sepolFree(head);
    }

    return ret;
}
Beispiel #3
0
static ModuleRec newModule(const char *path, const char *name,
			   const char *types, uint32_t flags)
{
    ModuleRec mod;
    uint8_t *raw = NULL;
    ssize_t rawlen = 0;
    const char *buildDir = "%{_builddir}/%{?buildsubdir}/";

    if (!path) {
	rpmlog(RPMLOG_ERR, _("%%semodule requires a file path\n"));
	return NULL;
    }

    mod = xcalloc(1, sizeof(*mod));

    mod->path = rpmGenPath(buildDir, NULL, path);

    if ((rpmioSlurp(mod->path, &raw, &rawlen)) != 0 || raw == NULL) {
	rpmlog(RPMLOG_ERR, _("Failed to read  policy file: %s\n"),
	       mod->path);
	goto err;
    }

    mod->data = b64encode(raw, rawlen, -1);
    if (!mod->data) {
	rpmlog(RPMLOG_ERR, _("Failed to encode policy file: %s\n"),
	       mod->path);
	goto err;
    }

    if (name) {
	mod->name = xstrdup(name);
    } else {
	/* assume base name (minus extension) if name is not given */
	char *tmp = xstrdup(mod->path);
	char *bname = basename(tmp);
	char *end = strchr(bname, '.');
	if (end)
	    *end = '\0';
	if (strlen(bname) > 0) {
	    mod->name = xstrdup(bname);
	} else {
	    rpmlog(RPMLOG_ERR, _("Failed to determine a policy name: %s\n"),
		   mod->path);
	    _free(tmp);
	    goto err;
	}
	_free(tmp);
    }

    if (types) {
	mod->types = argvSplitString(types, ",", ARGV_SKIPEMPTY);
	argvSort(mod->types, NULL);
	if (argvSearch(mod->types, RPMPOL_TYPE_DEFAULT, NULL) && argvCount(mod->types) > 1) {
	    rpmlog(RPMLOG_WARNING, _("'%s' type given with other types in %%semodule %s. Compacting types to '%s'.\n"),
		   RPMPOL_TYPE_DEFAULT, mod->path, RPMPOL_TYPE_DEFAULT);
	    mod->types = argvFree(mod->types);
	    argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT);
	}
    } else {
	argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT);
    }

    mod->flags = flags;

    return mod;

  err:
    freeModule(mod);
    return NULL;
}
Beispiel #4
0
int
main(int argc, char *argv[])
{
    poptContext optCon = NULL;
    ARGV_t av = NULL;
    rpmfc fc = NULL;
    int ec = 1;
    char buf[BUFSIZ];

    xsetprogname(argv[0]); /* Portability call -- see system.h */

    optCon = rpmcliInit(argc, argv, optionsTable);
    if (optCon == NULL)
	goto exit;

    /* normally files get passed through stdin but also accept files as args */
    if (poptPeekArg(optCon)) {
	const char *arg;
	while ((arg = poptGetArg(optCon)) != NULL) {
	    argvAdd(&av, arg);
	}
    } else {
	while (fgets(buf, sizeof(buf), stdin) != NULL) {
	    char *be = buf + strlen(buf) - 1;
	    while (strchr("\r\n", *be) != NULL)
		*be-- = '\0';
	    argvAdd(&av, buf);
	}
    }
    /* Make sure file names are sorted. */
    argvSort(av, NULL);

    /* Build file/package class and dependency dictionaries. */
    fc = rpmfcCreate(getenv("RPM_BUILD_ROOT"), 0);
    if (rpmfcClassify(fc, av, NULL) || rpmfcApply(fc))
	goto exit;

    if (_rpmfc_debug)
	rpmfcPrint(buf, fc, NULL);

    if (print_provides)
	rpmdsPrint(NULL, rpmfcProvides(fc), stdout);
    if (print_requires)
	rpmdsPrint(NULL, rpmfcRequires(fc), stdout);
    if (print_recommends)
	rpmdsPrint(NULL, rpmfcRecommends(fc), stdout);
    if (print_suggests)
	rpmdsPrint(NULL, rpmfcSuggests(fc), stdout);
    if (print_supplements)
	rpmdsPrint(NULL, rpmfcSupplements(fc), stdout);
    if (print_enhances)
	rpmdsPrint(NULL, rpmfcEnhances(fc), stdout);
    if (print_conflicts)
	rpmdsPrint(NULL, rpmfcConflicts(fc), stdout);
    if (print_obsoletes)
	rpmdsPrint(NULL, rpmfcObsoletes(fc), stdout);

    ec = 0;

exit:
    argvFree(av);
    rpmfcFree(fc);
    rpmcliFini(optCon);
    return ec;
}
Beispiel #5
0
int
main(int argc, char *const argv[])
{
    poptContext optCon = rpmioInit(argc, argv, optionsTable);
    ARGV_t av;
    int ac;
    rpmdict dict;
    EVR_t evr = (EVR_t) xcalloc(1, sizeof(*evr));
    const char * arg;
    int rc = 0;
    int xx;
    int i;

    if ((progname = strrchr(argv[0], '/')) != NULL)
	progname++;
    else
	progname = argv[0];

    av = NULL;
    (void) argvAppend(&av, poptGetArgs(optCon));
    ac = argvCount(av);

    if (ac == 0 || !strcmp(*av, "-")) {
	av = NULL;
	xx = argvFgets(&av, NULL);
	ac = argvCount(av);
    }
    
    dict = rpmdictCreate();

    if (av != NULL)
    for (i = 0; (arg = av[i]) != NULL; i++) {
	if (*arg == '\0')	/* Skip cruft */
	    continue;
	s.total++;

	if (nofiles && *arg == '/') {		/* Skip file paths. */
	    s.files++;
	    continue;
	}
	if (noKdigests && isKdigest(arg)) {	/* Skip kernel MD5/SHA1. */
	    s.Kdigest++;
	    continue;
	}
	if (noOdigests && isOdigest(arg)) {	/* Skip OCAML EVR strings. */
	    s.Odigest++;
	    continue;
	}

	/* Split E:V-R into components. */
	xx = rpmEVRparse(arg, evr);
	if (evr->F[RPMEVR_E] == NULL) {
	    evr->F[RPMEVR_E] = "0";
	    s.Emiss++;
	}
	if (evr->F[RPMEVR_R] == NULL) {
	    evr->F[RPMEVR_R] = "";
	    s.Rmiss++;
	}
	rpmdictAdd(dict, evr->F[RPMEVR_E]);
	rpmdictAdd(dict, evr->F[RPMEVR_V]);
	rpmdictAdd(dict, evr->F[RPMEVR_R]);

if (__debug)
fprintf(stderr, "%5d: %s => %s:%s-%s\n", s.total, arg, evr->F[RPMEVR_E], evr->F[RPMEVR_V], evr->F[RPMEVR_R]);

	evr->str = _free(evr->str);
    }

    (void) argvSort(dict->av,(int (*)(const char **, const char **))rpmdictCmp);

    /* Compute size of string & uuid store. */
    if (av != NULL)
    for (i = 0; av[i] != NULL; i++) {
	s.strnb += sizeof(*av) + strlen(av[i]) + 1;
	s.uuidnb += 64/8;
    }
    s.strnb += sizeof(*av) + 1;

    /* Compute size of dictionary store. */
    for (i = 0; dict->av[i] != NULL; i++) {
	s.dictnb += sizeof(*dict->av) + strlen(dict->av[i]) + 1;
    }
    s.dictnb += sizeof(*dict->av) + 1;

fprintf(stderr, "total:%u files:%u Kdigest:%u Odigest:%u Emiss:%u Rmiss:%u dictlen:%u strnb:%u dictnb:%u uuidnb:%u\n",
s.total, s.files, s.Kdigest, s.Odigest, s.Emiss, s.Rmiss, argvCount(dict->av), (unsigned)s.strnb, (unsigned)s.dictnb, (unsigned)s.uuidnb);

if (__debug)
    argvPrint("E:V-R dictionary", dict->av, NULL);

    evr = _free(evr);
    dict = rpmdictFree(dict);

    av = argvFree(av);
    optCon = rpmioFini(optCon);

    return rc;
}