RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   04-May-2017 22:55:39
  Branch: rpm-5_4                          Handle: 2017050420553801

  Added files:              (Branch: rpm-5_4)
    rpm/rpmio               rpmcap.c rpmcap.h
  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES
    rpm/rpmio               Makefile.am

  Log:
    - cap: wrap libcap routines.

  Summary:
    Revision    Changes     Path
    1.3501.2.541+1  -0      rpm/CHANGES
    1.293.2.78  +2  -1      rpm/rpmio/Makefile.am
    1.1.2.1     +186 -0     rpm/rpmio/rpmcap.c
    1.1.2.1     +74 -0      rpm/rpmio/rpmcap.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.540 -r1.3501.2.541 CHANGES
  --- rpm/CHANGES       3 May 2017 15:01:16 -0000       1.3501.2.540
  +++ rpm/CHANGES       4 May 2017 20:55:38 -0000       1.3501.2.541
  @@ -1,4 +1,5 @@
   5.4.17 -> 5.4.18:
  +    - jbj: cap: wrap libcap routines.
       - jbj: rpmku: stub in syscall wrappers.
       - jbj: repackage: fix: memory leak recreating lead.
       - jbj: rpmio: support for O_DIRECT through Fopen.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.293.2.77 -r1.293.2.78 Makefile.am
  --- rpm/rpmio/Makefile.am     23 Dec 2016 17:00:02 -0000      1.293.2.77
  +++ rpm/rpmio/Makefile.am     4 May 2017 20:55:39 -0000       1.293.2.78
  @@ -153,7 +153,7 @@
        groestl.h hamsi.h jh.h jsmn.h keccak.h lane.h luffa.h md2.h md6.h \
        duktape.h mongoc.h radiogatun.h \
        salsa10.h salsa20.h shabal.h shavite3.h simd.h skein.h tib3.h tiger.h \
  -     pcrs.h rpmacl.h rpmasn.h rpmaug.h rpmbag.h rpmbc.h rpmbz.h \
  +     pcrs.h rpmacl.h rpmasn.h rpmaug.h rpmbag.h rpmbc.h rpmbz.h rpmcap.h \
        rpmcdsa.h rpmct.h rpmcudf.h rpmcvs.h rpmdate.h rpmdav.h rpmdir.h \
        rpmficl.h rpmgc.h rpmgfs.h rpmgit.h rpmhash.h \
        rpmhkp.h rpmhook.h rpmio_internal.h rpmjni.h rpmjs.h rpmjsio.h \
  @@ -202,6 +202,7 @@
        rpmbag.c \
        rpmbc.c \
        rpmbf.c \
  +     rpmcap.c \
        rpmcdsa.c \
        rpmct.c \
        rpmcudf.c \
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmcap.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1.2.1 rpmcap.c
  --- /dev/null 2017-05-04 22:55:00.000000000 +0200
  +++ rpmcap.c  2017-05-04 22:55:39.357356446 +0200
  @@ -0,0 +1,186 @@
  +/** \ingroup rpmio
  + * \file rpmio/rpmcap.c
  + */
  +
  +#include "system.h"
  +
  +/* XXX permit building --without-cap */
  +#if !defined(WITH_CAP)
  +#undef       HAVE_SYS_CAPABILITY_H
  +#endif
  +
  +#if defined(HAVE_SYS_CAPABILITY_H)
  +#include <sys/capability.h>
  +#endif
  +#include <rpmcap.h>
  +
  +#include "debug.h"
  +
  +int _rpmcap_debug = 0;
  +
  +/* Retrofit cap_compare() if not available. */
  +#if defined(WITH_CAP) && !defined(HAVE_CAP_COMPARE)
  +static int cap_compare(cap_t acap, cap_t bcap)
  +{
  +    int rc = 0;
  +    size_t asize = cap_size(acap);
  +    size_t bsize = cap_size(bcap);
  +
  +    if (asize != bsize) {
  +     rc = 1;
  +    } else {
  +     char *abuf = xcalloc(asize, sizeof(*abuf));
  +     char *bbuf = xcalloc(bsize, sizeof(*bbuf));
  +     cap_copy_ext(abuf, acap, asize);
  +     cap_copy_ext(bbuf, bcap, bsize);
  +     rc = memcmp(abuf, bbuf, asize);
  +     free(abuf);
  +     free(bbuf);
  +    }
  +    return rc;
  +}
  +#endif
  +
  +char * rpmcapValidate(const char *s)
  +{
  +    char * text = NULL;
  +#if defined(WITH_CAP)
  +    cap_t fcaps = cap_from_text(s);
  +    if (fcaps) {
  +     char *t = cap_to_text(fcaps, NULL);
  +     text = xstrdup(t);
  +     cap_free(t);
  +     cap_free(fcaps);
  +    } else
  +     text = xstrdup("");
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%s) text %s\n", __FUNCTION__, s, text);
  +    return text;
  +}
  +
  +char * rpmcapGetFD(int fdno)
  +{
  +    char * text = NULL;
  +#if defined(WITH_CAP)
  +    cap_t fcaps = cap_get_fd(fdno);
  +    if (fcaps) {
  +     char *t = cap_to_text(fcaps, NULL);
  +     text = xstrdup(t);
  +     cap_free(t);
  +     cap_free(fcaps);
  +    }
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%d) text %s\n", __FUNCTION__, fdno, text);
  +    return text;
  +}
  +
  +char * rpmcapGetFN(const char *fn)
  +{
  +    char * text = NULL;
  +#if defined(WITH_CAP)
  +    cap_t fcaps = cap_get_file(fn);
  +    if (fcaps) {
  +     char *t = cap_to_text(fcaps, NULL);
  +     text = xstrdup(t);
  +     cap_free(t);
  +     cap_free(fcaps);
  +    }
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%s) text %s\n", __FUNCTION__, fn, text);
  +    return text;
  +}
  +
  +int rpmcapSetFD(int fdno, const char *s)
  +{
  +    int rc = -1;             /* assume failure */
  +#if defined(WITH_CAP)
  +    cap_t fcaps = NULL;
  +    if (s && *s != '\0') {
  +        fcaps = cap_from_text(s);
  +     if (fcaps == NULL
  +         || cap_set_fd(fdno, fcaps) != 0)
  +         goto exit;
  +    }
  +    rc = 0;
  +exit:
  +    if (fcaps)
  +        cap_free(fcaps);
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%d,%s) rc %d\n", __FUNCTION__, fdno, s, rc);
  +    return rc;
  +}
  +
  +int rpmcapSetFN(const char *fn, const char *s)
  +{
  +    int rc = -1;             /* assume failure */
  +#if defined(WITH_CAP)
  +    cap_t fcaps = NULL;
  +    if (s && *s != '\0') {
  +        fcaps = cap_from_text(s);
  +     if (fcaps == NULL
  +         || cap_set_file(fn, fcaps) != 0)
  +         goto exit;
  +    }
  +    rc = 0;
  +exit:
  +    if (fcaps)
  +        cap_free(fcaps);
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%s,%s) rc %d\n", __FUNCTION__, fn, s, rc);
  +    return rc;
  +}
  +
  +int rpmcapVerifyFD(int fdno, const char *s)
  +{
  +    int rc = -1;             /* assume failure */
  +#if defined(WITH_CAP)
  +    cap_t fcap = cap_get_fd(fdno);
  +    cap_t cap = cap_from_text(s);
  +    /*
  +     * Empty capability set ("=") is not exactly the same as no
  +     * capabilities at all but suffices for now... 
  +     */
  +    if (cap == NULL)
  +     cap = cap_from_text("=");
  +    if (fcap == NULL)
  +     fcap = cap_from_text("=");
  +     
  +    rc = (cap_compare(cap, fcap) != 0);
  +
  +    cap_free(fcap);
  +    cap_free(cap);
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%d,%s) rc %d\n", __FUNCTION__, fdno, s, rc);
  +    return rc;
  +}
  +
  +int rpmcapVerifyFN(const char *fn, const char *s)
  +{
  +    int rc = -1;             /* assume failure */
  +#if defined(WITH_CAP)
  +    cap_t fcap = cap_get_file(fn);
  +    cap_t cap = cap_from_text(s);
  +    /*
  +     * Empty capability set ("=") is not exactly the same as no
  +     * capabilities at all but suffices for now... 
  +     */
  +    if (cap == NULL)
  +     cap = cap_from_text("=");
  +    if (fcap == NULL)
  +     fcap = cap_from_text("=");
  +     
  +    rc = (cap_compare(cap, fcap) != 0);
  +
  +    cap_free(fcap);
  +    cap_free(cap);
  +#endif
  +if (_rpmcap_debug)
  +fprintf(stderr, "<-- %s(%s,%s) rc %d\n", __FUNCTION__, fn, s, rc);
  +    return rc;
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmcap.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1.2.1 rpmcap.h
  --- /dev/null 2017-05-04 22:55:00.000000000 +0200
  +++ rpmcap.h  2017-05-04 22:55:39.367356489 +0200
  @@ -0,0 +1,74 @@
  +#ifndef      H_RPMCAP
  +#define      H_RPMCAP
  +
  +/** \ingroup rpmio
  + * \file rpmio/rpmcap.h
  + */
  +
  +#include <rpmiotypes.h>
  +#include <rpmio.h>
  +
  +extern int _rpmcap_debug;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +/**
  + * Return validated capability string.
  + * @param s  capability string
  + * @return   validated capability string (malloc'd)
  + */
  +char * rpmcapValidate(const char *s);
  +
  +/**
  + * Get file capabity from fdno.
  + * @param fdno       file descriptor
  + * @return   capability string (malloc'd)
  + */
  +char * rpmcapGetFD(int fdno);
  +
  +/**
  + * Get file capabity from path.
  + * @param fn file name
  + * @return   capability string (malloc'd)
  + */
  +char * rpmcapGetFN(const char *fn);
  +
  +/**
  + * Set file capabity on fdno.
  + * @param fdno       file descriptor
  + * @param s  capability string
  + * @return   0 on success
  + */
  +int rpmcapSetFD(int fdno, const char *s);
  +
  +/**
  + * Set file capabity on path.
  + * @param fn file name
  + * @param s  capability string
  + * @return   0 on success
  + */
  +int rpmcapSetFN(const char *fn, const char *s);
  +
  +/**
  + * Verify file capabity on fdno.
  + * @param fdno       file descriptor
  + * @param s  capability string
  + * @return   0 on success
  + */
  +int rpmcapVerifyFD(int fdno, const char *s);
  +
  +/**
  + * Verify file capabity on path.
  + * @param fn file name
  + * @param s  capability string
  + * @return   0 on success
  + */
  +int rpmcapVerifyFN(const char *fn, const char *s);
  +
  +#ifdef __cplusplus
  +}
  +#endif
  +
  +#endif       /* H_RPMCAP */
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to