RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: [email protected] Module: rpm Date: 12-Jul-2009 21:21:11 Branch: HEAD Handle: 2009071219211000 Modified files: rpm CHANGES rpm/rpmio librpmio.vers rpmio.c rpmsx.c rpmsx.h Log: - rpmsx: wrap getfilecon/lgetfilecon. - rpmsx: add persistent/lazy matchpathcon_{init,free}. Summary: Revision Changes Path 1.3050 +2 -0 rpm/CHANGES 2.132 +2 -0 rpm/rpmio/librpmio.vers 1.203 +6 -2 rpm/rpmio/rpmio.c 2.3 +62 -12 rpm/rpmio/rpmsx.c 2.3 +15 -0 rpm/rpmio/rpmsx.h ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3049 -r1.3050 CHANGES --- rpm/CHANGES 11 Jul 2009 21:32:33 -0000 1.3049 +++ rpm/CHANGES 12 Jul 2009 19:21:10 -0000 1.3050 @@ -1,5 +1,7 @@ 5.2b1 -> 5.3a1 + - jbj: rpmsx: wrap getfilecon/lgetfilecon. + - jbj: rpmsx: add persistent/lazy matchpathcon_{init,free}. - jbj: rpmsx: refactor the existing SELinux implementation. - jbj: python: fix: missing changelog in repo-md can segfault (David Smid). - jbj: rpmdav: oops, WebDAV is different code path, revert some changes. @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.131 -r2.132 librpmio.vers --- rpm/rpmio/librpmio.vers 11 Jul 2009 21:32:36 -0000 2.131 +++ rpm/rpmio/librpmio.vers 12 Jul 2009 19:21:10 -0000 2.132 @@ -478,6 +478,8 @@ _rpmsx_debug; rpmsxEnabled; rpmsxExec; + rpmsxGetfilecon; + rpmsxLgetfilecon; rpmsxLsetfilecon; rpmsxMatch; rpmsxNew; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.c ============================================================================ $ cvs diff -u -r1.202 -r1.203 rpmio.c --- rpm/rpmio/rpmio.c 11 Jul 2009 17:14:03 -0000 1.202 +++ rpm/rpmio/rpmio.c 12 Jul 2009 19:21:10 -0000 1.203 @@ -75,6 +75,8 @@ #include <rpmsquirrel.h> #include <rpmtcl.h> +#include <rpmsx.h> + #if defined(HAVE_LIBIO_H) && defined(_G_IO_IO_FILE_VERSION) #define _USE_LIBIO 1 #endif @@ -3138,7 +3140,7 @@ extern rpmioPool _htmlPool; extern rpmioPool _htPool; extern rpmioPool _ctxPool; - extern rpmioPool _rpmsexPool; + extern rpmioPool _rpmsxPool; extern rpmioPool _rpmsyckPool; /*...@=shadow@*/ extern rpmioPool _rpmaugPool; @@ -3187,13 +3189,15 @@ _rpmluavPool = rpmioFreePool(_rpmluavPool); _rpmluaPool = rpmioFreePool(_rpmluaPool); + _rpmsxI = rpmsxFree(_rpmsxI); + _rpmsxPool = rpmioFreePool(_rpmsxPool); + _htmlPool = rpmioFreePool(_htmlPool); _mirePool = rpmioFreePool(_mirePool); _rpmmgPool = rpmioFreePool(_rpmmgPool); _rpmbfPool = rpmioFreePool(_rpmbfPool); _htPool = rpmioFreePool(_htPool); _ctxPool = rpmioFreePool(_ctxPool); - _rpmsexPool = rpmioFreePool(_rpmsexPool); _rpmsyckPool = rpmioFreePool(_rpmsyckPool); _rpmiobPool = rpmioFreePool(_rpmiobPool); _digPool = rpmioFreePool(_digPool); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmsx.c ============================================================================ $ cvs diff -u -r2.2 -r2.3 rpmsx.c --- rpm/rpmio/rpmsx.c 11 Jul 2009 21:32:36 -0000 2.2 +++ rpm/rpmio/rpmsx.c 12 Jul 2009 19:21:10 -0000 2.3 @@ -160,6 +160,31 @@ return scon; } +const char * rpmsxGetfilecon(rpmsx sx, const char *fn) +{ + const char * scon = NULL; + + if (sx == NULL) sx = rpmsxI(); + +if (_rpmsx_debug) +fprintf(stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn); + +#if defined(WITH_SELINUX) + if (sx->fn && fn) { + security_context_t _con = NULL; + int rc = getfilecon(fn, &_con); + if (rc > 0 && _con != NULL) + scon = (const char *) _con; + else + freecon(_con); + } +#endif + +if (_rpmsx_debug) +fprintf(stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon); + return scon; +} + int rpmsxSetfilecon(rpmsx sx, const char *fn, mode_t mode, const char * scon) { @@ -168,16 +193,16 @@ if (sx == NULL) sx = rpmsxI(); if (_rpmsx_debug) -fprintf(stderr, "--> %s(%p,%s,0%o,%s)\n", __FUNCTION__, sx, fn, mode, scon); +fprintf(stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, mode, scon, sx->fn); #if defined(WITH_SELINUX) if (sx->fn) { - security_context_t _scon = (security_context_t) + security_context_t _con = (security_context_t) (scon ? scon : rpmsxMatch(sx, fn, mode)); - rc = setfilecon(fn, _scon); - if (scon == NULL) { - freecon(_scon); - _scon = NULL; + rc = setfilecon(fn, _con); + if (scon == NULL) { /* XXX free lazy rpmsxMatch() string */ + freecon(_con); + _con = NULL; } } #endif @@ -187,6 +212,31 @@ return rc; } +const char * rpmsxLgetfilecon(rpmsx sx, const char *fn) +{ + const char * scon = NULL; + + if (sx == NULL) sx = rpmsxI(); + +if (_rpmsx_debug) +fprintf(stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn); + +#if defined(WITH_SELINUX) + if (sx->fn && fn) { + security_context_t _con = NULL; + int rc = lgetfilecon(fn, &_con); + if (rc > 0 && _con != NULL) + scon = (const char *) _con; + else + freecon(_con); + } +#endif + +if (_rpmsx_debug) +fprintf(stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon); + return scon; +} + int rpmsxLsetfilecon(rpmsx sx, const char *fn, mode_t mode, const char * scon) { @@ -195,16 +245,16 @@ if (sx == NULL) sx = rpmsxI(); if (_rpmsx_debug) -fprintf(stderr, "--> %s(%p,%s,0%o,%s)\n", __FUNCTION__, sx, fn, mode, scon); +fprintf(stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, mode, scon, sx->fn); #if defined(WITH_SELINUX) if (sx->fn) { - security_context_t _scon = (security_context_t) + security_context_t _con = (security_context_t) (scon ? scon : rpmsxMatch(sx, fn, mode)); - rc = lsetfilecon(fn, _scon); - if (scon == NULL) { - freecon(_scon); - _scon = NULL; + rc = lsetfilecon(fn, _con); + if (scon == NULL) { /* XXX free lazy rpmsxMatch() string */ + freecon(_con); + _con = NULL; } } #endif @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmsx.h ============================================================================ $ cvs diff -u -r2.2 -r2.3 rpmsx.h --- rpm/rpmio/rpmsx.h 11 Jul 2009 21:32:36 -0000 2.2 +++ rpm/rpmio/rpmsx.h 12 Jul 2009 19:21:10 -0000 2.3 @@ -100,6 +100,21 @@ /*...@modifies sx, fileSystem, internalState @*/; /** + * Get security context for a file. + * @param sx SELinux wrapper (NULL uses active context) + * @param fn file path + * @return file security context (NULL on error/disabled) + */ +/*...@null@*/ +const char * rpmsxGetfilecon(/*...@null@*/ rpmsx sx, const char *fn) + /*...@globals fileSystem, internalState @*/ + /*...@modifies fileSystem, internalState @*/; +/*...@null@*/ +const char * rpmsxLgetfilecon(/*...@null@*/ rpmsx sx, const char *fn) + /*...@globals fileSystem, internalState @*/ + /*...@modifies fileSystem, internalState @*/; + +/** * Set security context for a file. * @param sx SELinux wrapper (NULL uses active context) * @param fn file path @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository [email protected]
