This is libcap-1.10
http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/libcap-1.10.tar.gz
diff --git a/CHANGELOG b/CHANGELOG
index 157c926..d1d3cd9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,14 @@
+libcap 1.10
+
+* fixed cap_free to abide by correct documention - use it to free
+ strings returned by cap_to_text().
+
+libcap 1.03
+
+* Fix from Chris Evans relating to not seeing all of the capabilities
+ in the automatically generated cap_names.h file (fix in
+ _makenames.c)
+
libcap 1.02
* fixed kernel version matching to always fail when attempting to
diff --git a/Make.Rules b/Make.Rules
index 4b2e142..b36f76a 100644
--- a/Make.Rules
+++ b/Make.Rules
@@ -1,5 +1,5 @@
#
-# $Id: Make.Rules,v 1.4 1999/05/14 04:36:47 morgan Exp $
+# $Id: Make.Rules,v 1.5 1999/11/18 06:06:02 morgan Exp $
#
#
@@ -36,7 +36,7 @@
# common defines for libcap (suitable for 2.2.1+ Linux kernels)
VERSION=1
-MINOR=03
+MINOR=10
#
# Compilation specifics
diff --git a/libcap/cap_alloc.c b/libcap/cap_alloc.c
index 58cdb81..3d3168e 100644
--- a/libcap/cap_alloc.c
+++ b/libcap/cap_alloc.c
@@ -1,5 +1,5 @@
/*
- * $Id: cap_alloc.c,v 1.1.1.1 1999/04/17 22:16:31 morgan Exp $
+ * $Id: cap_alloc.c,v 1.3 1999/11/18 07:23:24 morgan Exp $
*
* Copyright (c) 1997-8 Andrew G Morgan <morgan@linux.kernel.org>
*
@@ -12,7 +12,59 @@
#include "libcap.h"
/*
- * This function duplicates an internal capability set (x3) with
+ * Obtain a blank set of capabilities
+ */
+
+cap_t cap_init(void)
+{
+ __u32 *raw_data;
+ cap_t result;
+
+ raw_data = malloc( sizeof(__u32) + sizeof(*result) );
+
+ if (raw_data == NULL) {
+ _cap_debug("out of memory");
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ *raw_data = CAP_T_MAGIC;
+ result = (cap_t) (raw_data + 1);
+ memset(result, 0, sizeof(*result));
+
+ result->head.version = _LINUX_CAPABILITY_VERSION;
+
+ return result;
+}
+
+/*
+ * This is an internal library function to duplicate a string and
+ * tag the result as something cap_free can handle.
+ */
+
+char *_libcap_strdup(const char *old)
+{
+ __u32 *raw_data;
+
+ if (old == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ raw_data = malloc( sizeof(__u32) + strlen(old) + 1 );
+ if (raw_data == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ *(raw_data++) = CAP_S_MAGIC;
+ strcpy((char *) raw_data, old);
+
+ return ((char *) raw_data);
+}
+
+/*
+ * This function duplicates an internal capability set with
* malloc()'d memory. It is the responsibility of the user to call
* cap_free() to liberate it.
*/
@@ -27,10 +79,9 @@
return NULL;
}
- result = (cap_t) malloc( sizeof(*cap_d) );
+ result = cap_init();
if (result == NULL) {
_cap_debug("out of memory");
- errno = ENOMEM;
return NULL;
}
@@ -44,40 +95,39 @@
* Scrub and then liberate an internal capability set.
*/
-int cap_free(cap_t *cap_d_p)
+int cap_free(void *data_p)
{
- if ( cap_d_p && good_cap_t(*cap_d_p) ) {
- memset(*cap_d_p, 0, sizeof(**cap_d_p));
- free(*cap_d_p);
- *cap_d_p = NULL;
+ if ( good_cap_t(data_p) ) {
+ data_p = -1 + (__u32 *) data_p;
+ memset(data_p, 0, sizeof(__u32) + sizeof(struct _cap_struct));
+ free(data_p);
+ data_p = NULL;
return 0;
- } else {
- _cap_debug("no capability to liberate");
- errno = EINVAL;
- return -1;
}
-}
-/*
- * Obtain a blank set of capabilities
- */
-
-cap_t cap_init(void)
-{
- cap_t result = (cap_t) calloc( 1, sizeof(*result) );
-
- if (result) {
- result->magic = CAP_T_MAGIC;
- result->head.version = _LINUX_CAPABILITY_VERSION;
- } else {
- errno = ENOMEM;
+ if ( good_cap_string(data_p) ) {
+ int length = strlen(data_p) + sizeof(__u32);
+ data_p = -1 + (__u32 *) data_p;
+ memset(data_p, 0, length);
+ free(data_p);
+ data_p = NULL;
+ return 0;
}
- return result;
+
+ _cap_debug("don't recognize what we're supposed to liberate");
+ errno = EINVAL;
+ return -1;
}
/*
* $Log: cap_alloc.c,v $
+ * Revision 1.3 1999/11/18 07:23:24 morgan
+ * final fixes tested on a RH6.0 system for release-1.10
+ *
+ * Revision 1.2 1999/11/18 06:03:26 morgan
+ * fixed cap_free to work as indicated in manuals
+ *
* Revision 1.1.1.1 1999/04/17 22:16:31 morgan
* release 1.0 of libcap
*
diff --git a/libcap/cap_text.c b/libcap/cap_text.c
index c17f89f..c69e89b 100644
--- a/libcap/cap_text.c
+++ b/libcap/cap_text.c
@@ -1,5 +1,5 @@
/*
- * $Id: cap_text.c,v 1.2 1999/04/17 23:25:09 morgan Exp $
+ * $Id: cap_text.c,v 1.3 1999/11/18 06:03:26 morgan Exp $
*
* Copyright (c) 1997-8 Andrew G Morgan <morgan@linux.kernel.org>
* Copyright (c) 1997 Andrew Main <zefram@dcs.warwick.ac.uk>
@@ -16,8 +16,6 @@
#include <ctype.h>
#include <stdio.h>
-char *strdup(const char *s);
-
/* Maximum output text length (16 per cap) */
#define CAP_TEXT_SIZE (16*__CAP_BITS)
@@ -306,11 +304,14 @@
*length_p = p - buf;
}
- return (strdup(buf));
+ return (_libcap_strdup(buf));
}
/*
* $Log: cap_text.c,v $
+ * Revision 1.3 1999/11/18 06:03:26 morgan
+ * fixed cap_free to work as indicated in manuals
+ *
* Revision 1.2 1999/04/17 23:25:09 morgan
* fixes from peeterj
*
diff --git a/libcap/include/sys/capability.h b/libcap/include/sys/capability.h
index 219ad2a..5afd3b0 100644
--- a/libcap/include/sys/capability.h
+++ b/libcap/include/sys/capability.h
@@ -20,6 +20,7 @@
* information for the user library.
*/
+#include <sys/types.h>
#include <linux/capability.h>
/*
@@ -63,7 +64,7 @@
/* libcap/cap_alloc.c */
cap_t cap_dup(cap_t);
-int cap_free(cap_t *);
+int cap_free(void *);
cap_t cap_init(void);
/* libcap/cap_flag.c */
diff --git a/libcap/libcap.h b/libcap/libcap.h
index f206090..eff5f8b 100644
--- a/libcap/libcap.h
+++ b/libcap/libcap.h
@@ -1,5 +1,5 @@
/*
- * $Id: libcap.h,v 1.2 1999/04/17 23:25:10 morgan Exp $
+ * $Id: libcap.h,v 1.5 1999/11/18 07:23:24 morgan Exp $
*
* Copyright (c) 1997 Andrew G Morgan <morgan@linux.kernel.org>
*
@@ -12,7 +12,6 @@
#ifndef LIBCAP_H
#define LIBCAP_H
-#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -41,11 +40,13 @@
#define CAP_T_MAGIC 0xCA90D0
struct _cap_struct {
- int magic;
struct __user_cap_header_struct head;
struct __user_cap_data_struct set;
};
+/* string magic for cap_free */
+#define CAP_S_MAGIC 0xCA95D0
+
/*
* Do we match the local kernel?
*/
@@ -76,7 +77,9 @@
* Private definitions for internal use by the library.
*/
-#define good_cap_t(c) ((c) && (c)->magic == CAP_T_MAGIC)
+#define __libcap_check_magic(c,magic) ((c) && *(-1+(__u32 *)(c)) == (magic))
+#define good_cap_t(c) __libcap_check_magic(c, CAP_T_MAGIC)
+#define good_cap_string(c) __libcap_check_magic(c, CAP_S_MAGIC)
/*
* library debugging
@@ -91,7 +94,7 @@
}
# define _cap_debugcap(s, c) \
fprintf(stderr, __FUNCTION__ "(" __FILE__ ":%d): " s \
- "%08x\n", __LINE__, c)
+ "%08x\n", __LINE__, *(c))
#else /* !DEBUG */
@@ -100,6 +103,8 @@
#endif /* DEBUG */
+extern char *_libcap_strdup(const char *text);
+
/*
* These are semi-public prototypes, they will only be defined in
* <sys/capability.h> if _POSIX_SOURCE is not #define'd, so we
@@ -115,6 +120,15 @@
/*
* $Log: libcap.h,v $
+ * Revision 1.5 1999/11/18 07:23:24 morgan
+ * final fixes tested on a RH6.0 system for release-1.10
+ *
+ * Revision 1.4 1999/11/18 06:25:02 morgan
+ * added prototype for _libcap_strdup
+ *
+ * Revision 1.3 1999/11/18 06:03:26 morgan
+ * fixed cap_free to work as indicated in manuals
+ *
* Revision 1.2 1999/04/17 23:25:10 morgan
* fixes from peeterj
*
diff --git a/progs/getpcaps.c b/progs/getpcaps.c
index a831547..cb3c9d7 100644
--- a/progs/getpcaps.c
+++ b/progs/getpcaps.c
@@ -1,5 +1,5 @@
/*
- * $Id: getpcaps.c,v 1.1.1.1 1999/04/17 22:16:31 morgan Exp $
+ * $Id: getpcaps.c,v 1.2 1999/11/18 06:04:25 morgan Exp $
*
* Copyright (c) 1997 Andrew G. Morgan <morgan@linux.kernel.org>
*
@@ -53,7 +53,7 @@
} else {
char *result = cap_to_text(cap_d, &length);
fprintf(stderr, "Capabilities for `%s': %s\n", *argv, result);
- free(result);
+ cap_free(result);
result = NULL;
}
}
@@ -63,6 +63,9 @@
/*
* $Log: getpcaps.c,v $
+ * Revision 1.2 1999/11/18 06:04:25 morgan
+ * use cap_free and not free for string from cap_to_text()
+ *
* Revision 1.1.1.1 1999/04/17 22:16:31 morgan
* release 1.0 of libcap
*
diff --git a/progs/setpcaps.c b/progs/setpcaps.c
index 9ec3d5f..7441420 100644
--- a/progs/setpcaps.c
+++ b/progs/setpcaps.c
@@ -1,5 +1,5 @@
/*
- * $Id: setpcaps.c,v 1.1.1.1 1999/04/17 22:16:31 morgan Exp $
+ * $Id: setpcaps.c,v 1.2 1999/11/18 06:04:26 morgan Exp $
*
* Copyright (c) 1997-8 Andrew G. Morgan <morgan@linux.kernel.org>
*
@@ -101,7 +101,7 @@
result = cap_to_text(cap_d, &length);
fprintf(stderr, "[caps set to:\n%s\n]\n", result);
- free(result);
+ cap_free(result);
result = NULL;
}
#endif
@@ -127,6 +127,9 @@
/*
* $Log: setpcaps.c,v $
+ * Revision 1.2 1999/11/18 06:04:26 morgan
+ * use cap_free and not free for string from cap_to_text()
+ *
* Revision 1.1.1.1 1999/04/17 22:16:31 morgan
* release 1.0 of libcap
*