From owner-p4-projects@FreeBSD.ORG Thu Jan 28 13:41:32 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7762D1065676; Thu, 28 Jan 2010 13:41:32 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 217AE1065692 for ; Thu, 28 Jan 2010 13:41:32 +0000 (UTC) (envelope-from jona@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 0E0088FC0A for ; Thu, 28 Jan 2010 13:41:32 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o0SDfVJ8055511 for ; Thu, 28 Jan 2010 13:41:31 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o0SDfVw8055509 for perforce@freebsd.org; Thu, 28 Jan 2010 13:41:31 GMT (envelope-from jona@FreeBSD.org) Date: Thu, 28 Jan 2010 13:41:31 GMT Message-Id: <201001281341.o0SDfVw8055509@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jona@FreeBSD.org using -f From: Jonathan Anderson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 173834 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2010 13:41:32 -0000 http://p4web.freebsd.org/chv.cgi?CH=173834 Change 173834 by jona@jona-belle-freebsd8 on 2010/01/28 13:41:06 Initial lc_fdlist work. No mmap'ing yet. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/lib/libcapability/Makefile#18 edit .. //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability.h#27 edit .. //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_fdlist.c#1 add .. //depot/projects/trustedbsd/capabilities/src/tools/cap/fdlist/Makefile#1 add .. //depot/projects/trustedbsd/capabilities/src/tools/cap/fdlist/fdlist.c#1 add Differences ... ==== //depot/projects/trustedbsd/capabilities/src/lib/libcapability/Makefile#18 (text+ko) ==== @@ -10,7 +10,7 @@ libcapability_sandbox_io.c \ libcapability_host.c \ libcapability_host_io.c \ - libcapability_registry.c + libcapability_fdlist.c INCS= libcapability.h ==== //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability.h#27 (text+ko) ==== @@ -30,13 +30,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability.h#26 $ + * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability.h#27 $ */ #ifndef _LIBCAPABILITY_H_ #define _LIBCAPABILITY_H_ #include +#include __BEGIN_DECLS @@ -52,29 +53,53 @@ int lcl_fd; }; + +/* A list of file descriptors, which can be passed around in shared memory */ +struct lc_fdlist; + + +struct lc_fdlist* lc_fdlist_new(void); +struct lc_fdlist* lc_fdlist_dup(struct lc_fdlist *orig); +void lc_fdlist_free(struct lc_fdlist *l); + +/* Size of an FD list in bytes, including all associated string data */ +int lc_fdlist_size(struct lc_fdlist *l); + + /* - * A file descriptor "registry" + * Add a file descriptor to the list. + * + * l the list to add to + * subsystem a software component name, e.g. "org.freebsd.rtld-elf" + * classname a class name, e.g. "libdir" or "library" + * name an instance name, e.g. "system library dir" or "libc.so.6" + * fd the file descriptor */ -struct lc_fdregistry_entry; -struct lc_fdregistry { - struct lc_fdregistry_entry *entries; /* registry entries */ +int lc_fdlist_add(struct lc_fdlist **l, + const char *subsystem, const char *classname, + const char *name, int fd); - unsigned int count; /* number of entries */ - unsigned int capacity; /* entries that we can hold */ -}; +/* + * Like lc_fdlist_add(), but allows capability rights to be specified. The file + * descriptor will be wrapped in a capability with the given rights (so if the + * descriptor *is* a capability, its rights will be constrained according to this + * rights mask) + */ +int lc_fdlist_addcap(struct lc_fdlist **l, + const char *subsystem, const char *classname, + const char *name, int fd, cap_rights_t rights); /* - * Registry operations + * Look up a file descriptor. + * + * Multiple entries with the same classname are allowed, so iterating through + * all instances of a class is done by supplying an integer 'pos' which is used + * internally to skip entries which have already been seen. If 'pos' is 0 or NULL, + * the first matching entry will be returned. */ -struct lc_fdregistry* lc_fdregistry_new(void); -struct lc_fdregistry* lc_fdregistry_dup(const struct lc_fdregistry *orig); -void lc_fdregistry_free(struct lc_fdregistry *registry); - -int lc_fdregistry_add(const struct lc_fdregistry *reg, - const char *id, const char *name, int fd); - -int lc_fdregistry_lookup(const struct lc_fdregistry *reg, - const char *id, char **name, int *fdp); +int lc_fdlist_lookup(struct lc_fdlist *l, + const char *subsystem, const char *classname, + char **name, int *fdp, int *pos); /* * Capability interfaces.