Rip out unnecessary selinux babbage.

- rpm doesn't manage selinux contexts so it doesn't need to know about them
  other than when creating files
- implement --fscontext as popt alias since it's easy to do so...
This commit is contained in:
Panu Matilainen 2007-09-03 15:15:50 +03:00
parent 97cea31a8a
commit c0bd72b026
4 changed files with 6 additions and 307 deletions

View File

@ -858,54 +858,6 @@ static int fileclassTag(Header h, /*@out@*/ rpmTagType * type,
return 0;
}
/**
* Retrieve file contexts from file system.
* @param h header
* @retval *type tag type
* @retval *data tag value
* @retval *count no. of data items
* @retval *freeData data-was-malloc'ed indicator
* @return 0 on success
*/
static int fscontextsTag(Header h, /*@out@*/ rpmTagType * type,
/*@out@*/ const void ** data, /*@out@*/ int_32 * count,
/*@out@*/ int * freeData)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *type, *data, *count, *freeData,
rpmGlobalMacroContext, fileSystem @*/
/*@requires maxSet(type) >= 0 /\ maxSet(data) >= 0
/\ maxSet(count) >= 0 /\ maxSet(freeData) >= 0 @*/
{
*type = RPM_STRING_ARRAY_TYPE;
rpmfiBuildFSContexts(h, (const char ***) data, count);
*freeData = 1;
return 0;
}
/**
* Retrieve file contexts from policy RE's.
* @param h header
* @retval *type tag type
* @retval *data tag value
* @retval *count no. of data items
* @retval *freeData data-was-malloc'ed indicator
* @return 0 on success
*/
static int recontextsTag(Header h, /*@out@*/ rpmTagType * type,
/*@out@*/ const void ** data, /*@out@*/ int_32 * count,
/*@out@*/ int * freeData)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *type, *data, *count, *freeData,
rpmGlobalMacroContext, fileSystem @*/
/*@requires maxSet(type) >= 0 /\ maxSet(data) >= 0
/\ maxSet(count) >= 0 /\ maxSet(freeData) >= 0 @*/
{
*type = RPM_STRING_ARRAY_TYPE;
rpmfiBuildREContexts(h, (const char ***) data, count);
*freeData = 1;
return 0;
}
/**
* Retrieve file provides.
* @param h header
@ -1136,11 +1088,9 @@ const struct headerSprintfExtension_s rpmHeaderFormats[] = {
{ HEADER_EXT_TAG, "RPMTAG_FILENAMES", { filenamesTag } },
{ HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE", { fileprovideTag } },
{ HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE", { filerequireTag } },
{ HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS", { fscontextsTag } },
{ HEADER_EXT_TAG, "RPMTAG_FSNAMES", { fsnamesTag } },
{ HEADER_EXT_TAG, "RPMTAG_FSSIZES", { fssizesTag } },
{ HEADER_EXT_TAG, "RPMTAG_INSTALLPREFIX", { instprefixTag } },
{ HEADER_EXT_TAG, "RPMTAG_RECONTEXTS", { recontextsTag } },
{ HEADER_EXT_TAG, "RPMTAG_TRIGGERCONDS", { triggercondsTag } },
{ HEADER_EXT_TAG, "RPMTAG_TRIGGERTYPE", { triggertypeTag } },
{ HEADER_EXT_FORMAT, "armor", { armorFormat } },

View File

@ -1560,209 +1560,6 @@ exit:
if (fcp) *fcp = ac;
}
void rpmfiBuildFContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
{
int scareMem = 0;
rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
const char * fcontext;
const char ** av;
int ac;
size_t nb;
char * t;
if ((ac = rpmfiFC(fi)) <= 0) {
av = NULL;
ac = 0;
goto exit;
}
/* Compute size of argv array blob. */
nb = (ac + 1) * sizeof(*av);
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
fcontext = rpmfiFContext(fi);
if (fcontext && *fcontext != '\0')
nb += strlen(fcontext);
nb += 1;
}
/* Create and load argv array. */
av = xmalloc(nb);
t = ((char *) av) + ((ac + 1) * sizeof(*av));
ac = 0;
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
fcontext = rpmfiFContext(fi);
av[ac++] = t;
if (fcontext && *fcontext != '\0')
t = stpcpy(t, fcontext);
*t++ = '\0';
}
av[ac] = NULL; /* XXX tag arrays are not NULL terminated. */
/*@=branchstate@*/
exit:
fi = rpmfiFree(fi);
/*@-branchstate@*/
if (fcontextp)
*fcontextp = av;
else
av = _free(av);
/*@=branchstate@*/
if (fcp) *fcp = ac;
}
void rpmfiBuildFSContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
{
int scareMem = 0;
rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
const char ** av;
int ac;
size_t nb;
char * t;
char * fctxt = NULL;
size_t fctxtlen = 0;
int * fcnb;
if ((ac = rpmfiFC(fi)) <= 0) {
av = NULL;
ac = 0;
goto exit;
}
/* Compute size of argv array blob, concatenating file contexts. */
nb = ac * sizeof(*fcnb);
fcnb = memset(alloca(nb), 0, nb);
ac = 0;
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
const char * fn = rpmfiFN(fi);
security_context_t scon;
fcnb[ac] = lgetfilecon(fn, &scon);
/*@-branchstate@*/
if (fcnb[ac] > 0) {
fctxt = xrealloc(fctxt, fctxtlen + fcnb[ac]);
memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
fctxtlen += fcnb[ac];
freecon(scon);
}
/*@=branchstate@*/
ac++;
}
/* Create and load argv array from concatenated file contexts. */
nb = (ac + 1) * sizeof(*av) + fctxtlen;
av = xmalloc(nb);
t = ((char *) av) + ((ac + 1) * sizeof(*av));
if (fctxt != NULL && fctxtlen > 0)
(void) memcpy(t, fctxt, fctxtlen);
ac = 0;
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
av[ac] = "";
if (fcnb[ac] > 0) {
av[ac] = t;
t += fcnb[ac];
}
ac++;
}
av[ac] = NULL; /* XXX tag arrays are not NULL terminated. */
exit:
fi = rpmfiFree(fi);
/*@-branchstate@*/
if (fcontextp)
*fcontextp = av;
else
av = _free(av);
/*@=branchstate@*/
if (fcp) *fcp = ac;
}
void rpmfiBuildREContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
{
int scareMem = 0;
rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
rpmsx sx = NULL;
const char ** av = NULL;
int ac;
size_t nb;
char * t;
char * fctxt = NULL;
size_t fctxtlen = 0;
int * fcnb;
if ((ac = rpmfiFC(fi)) <= 0) {
ac = 0;
goto exit;
}
/* Read security context patterns. */
sx = rpmsxNew(NULL);
/* Compute size of argv array blob, concatenating file contexts. */
nb = ac * sizeof(*fcnb);
fcnb = memset(alloca(nb), 0, nb);
ac = 0;
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
const char * fn = rpmfiFN(fi);
mode_t fmode = rpmfiFMode(fi);
const char * scon;
scon = rpmsxFContext(sx, fn, fmode);
if (scon != NULL) {
fcnb[ac] = strlen(scon) + 1;
/*@-branchstate@*/
if (fcnb[ac] > 0) {
fctxt = xrealloc(fctxt, fctxtlen + fcnb[ac]);
memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
fctxtlen += fcnb[ac];
}
/*@=branchstate@*/
}
ac++;
}
/* Create and load argv array from concatenated file contexts. */
nb = (ac + 1) * sizeof(*av) + fctxtlen;
av = xmalloc(nb);
t = ((char *) av) + ((ac + 1) * sizeof(*av));
(void) memcpy(t, fctxt, fctxtlen);
ac = 0;
fi = rpmfiInit(fi, 0);
if (fi != NULL)
while (rpmfiNext(fi) >= 0) {
av[ac] = "";
if (fcnb[ac] > 0) {
av[ac] = t;
t += fcnb[ac];
}
ac++;
}
av[ac] = NULL; /* XXX tag arrays are not NULL terminated. */
exit:
fi = rpmfiFree(fi);
sx = rpmsxFree(sx);
/*@-branchstate@*/
if (fcontextp)
*fcontextp = av;
else
av = _free(av);
/*@=branchstate@*/
if (fcp) *fcp = ac;
}
void rpmfiBuildFDeps(Header h, rpmTag tagN,
/*@out@*/ const char *** fdepsp, /*@out@*/ int * fcp)
{

View File

@ -533,47 +533,6 @@ void rpmfiBuildFClasses(Header h,
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *fclassp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
/**
* Retrieve file security contexts from header.
*
* This function is used to retrieve file contexts from the header.
*
* @param h header
* @retval *fcontextp array of file contexts
* @retval *fcp number of files
*/
void rpmfiBuildFContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
/**
* Retrieve file security contexts from file system.
*
* This function is used to retrieve file contexts from the file system.
*
* @param h header
* @retval *fcontextp array of file contexts
* @retval *fcp number of files
*/
void rpmfiBuildFSContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
/**
* Retrieve file security contexts from policy RE's.
*
* This function is used to retrieve file contexts from policy RE's.
*
* @param h header
* @retval *fcontextp array of file contexts
* @retval *fcp number of files
*/
void rpmfiBuildREContexts(Header h,
/*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
/**
* Retrieve per-file dependencies from header.

View File

@ -109,12 +109,10 @@ rpm alias --fileclass --qf '[%{FILENAMES}\t%{FILECLASS}\n]' \
rpm alias --filecolor --qf '[%{FILENAMES}\t%{FILECOLORS}\n]' \
--POPTdesc=$"list file names with colors"
rpm alias --fscontext --qf '[%{FILENAMES}\t%{FSCONTEXTS}\n]' \
rpm alias --fscontext --qf '[%{FILENAMES}\n]' \
--pipe "xargs ls --scontext | awk '{printf(\"%s %s\n\", $2, $1)}'" \
--POPTdesc=$"list file names with security context from file system"
rpm alias --recontext --qf '[%{FILENAMES}\t%{RECONTEXTS}\n]' \
--POPTdesc=$"list file names with security context from policy RE"
rpm alias --fileprovide --qf '[%{FILENAMES}\t%{FILEPROVIDE}\n]' \
--POPTdesc=$"list file names with provides"
@ -486,15 +484,10 @@ rpmquery alias --fileclass --qf '[%{FILENAMES}\t%{FILECLASS}\n]' \
rpmquery alias --filecolor --qf '[%{FILENAMES}\t%{FILECOLORS}\n]' \
--POPTdesc=$"list file names with colors"
rpmquery alias --filecontext --qf '[%{FILENAMES}\t%{FILECONTEXTS}\n]' \
--POPTdesc=$"list file names with security context"
rpmquery alias --fscontext --qf '[%{FILENAMES}\t%{FSCONTEXTS}\n]' \
rpmquery alias --fscontext --qf '[%{FILENAMES}\n]' \
--pipe "xargs ls --scontext | awk '{printf(\"%s %s\n\", $2, $1)}'" \
--POPTdesc=$"list file names with security context from file system"
rpmquery alias --recontext --qf '[%{FILENAMES}\t%{RECONTEXTS}\n]' \
--POPTdesc=$"list file names with security context from policy RE"
rpmquery alias --fileprovide --qf '[%{FILENAMES}\t%{FILEPROVIDE}\n]' \
--POPTdesc=$"list file names with provides"