diff options
author | Andrew Morgan <morgan@kernel.org> | 2007-07-10 20:50:21 -0700 |
---|---|---|
committer | Jorge Lucangeli Obes <jorgelo@google.com> | 2015-09-03 14:13:03 -0700 |
commit | 7baf3be8302d9a7ba63c8c57131ecbc3fbd6d3eb (patch) | |
tree | 0e850e1a45be8cb8452a5157bd4b6538eafdbebe /libcap/cap_alloc.c | |
parent | d45f2b5bdac50859bce5f723d83a584314ba5f7b (diff) | |
download | libcap-7baf3be8302d9a7ba63c8c57131ecbc3fbd6d3eb.tar.gz |
This is the source for libcap-1.0.tar.gz
http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.2/libcap-1.0.tar.gz
Diffstat (limited to 'libcap/cap_alloc.c')
-rw-r--r-- | libcap/cap_alloc.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/libcap/cap_alloc.c b/libcap/cap_alloc.c new file mode 100644 index 0000000..3d9e7ab --- /dev/null +++ b/libcap/cap_alloc.c @@ -0,0 +1,90 @@ +/* + * $Id: cap_alloc.c,v 1.3 1998/05/24 22:54:09 morgan Exp $ + * + * Copyright (c) 1997-8 Andrew G Morgan <morgan@linux.kernel.org> + * + * See end of file for Log. + * + * This file deals with allocation and deallocation of internal + * capability sets as specified by POSIX.1e (formerlly, POSIX 6). + */ + +#include "libcap.h" + +/* + * This function duplicates an internal capability set (x3) with + * malloc()'d memory. It is the responsibility of the user to call + * cap_free() to liberate it. + */ + +cap_t cap_dup(cap_t cap_d) +{ + cap_t result; + + if (!good_cap_t(cap_d)) { + _cap_debug("bad argument"); + errno = EINVAL; + return NULL; + } + + result = (cap_t) malloc( sizeof(*cap_d) ); + if (result == NULL) { + _cap_debug("out of memory"); + errno = ENOMEM; + return NULL; + } + + memcpy(result, cap_d, sizeof(*cap_d)); + + return result; +} + + +/* + * Scrub and then liberate an internal capability set. + */ + +int cap_free(cap_t *cap_d_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; + + 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; + } + return result; +} + +/* + * $Log: cap_alloc.c,v $ + * Revision 1.3 1998/05/24 22:54:09 morgan + * updated for 2.1.104 + * + * Revision 1.2 1997/04/28 00:57:11 morgan + * fixes and zefram's patches + * + * Revision 1.1 1997/04/21 04:32:52 morgan + * Initial revision + * + */ |