From owner-p4-projects@FreeBSD.ORG Mon Jun 29 16:13:48 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AF8661065675; Mon, 29 Jun 2009 16:13:47 +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 6F545106564A for ; Mon, 29 Jun 2009 16:13:47 +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 42EB78FC08 for ; Mon, 29 Jun 2009 16:13:47 +0000 (UTC) (envelope-from jona@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5TGDl3M040535 for ; Mon, 29 Jun 2009 16:13:47 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5TGDl0Q040533 for perforce@freebsd.org; Mon, 29 Jun 2009 16:13:47 GMT (envelope-from jona@FreeBSD.org) Date: Mon, 29 Jun 2009 16:13:47 GMT Message-Id: <200906291613.n5TGDl0Q040533@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 Cc: Subject: PERFORCE change 165408 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2009 16:13:49 -0000 http://perforce.freebsd.org/chv.cgi?CH=165408 Change 165408 by jona@jona-trustedbsd-belle-vmware on 2009/06/29 16:12:49 ua_fopen(), a wrapper around fopen() Affected files ... .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#7 edit .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#7 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#7 (text+ko) ==== @@ -237,6 +237,60 @@ +FILE* ua_fopen(const char *path, const char *mode) +{ + if(angel < 0) angel = ua_find(); + if(angel < 0) return NULL; + + int flags = 0; + cap_rights_t rights = CAP_SEEK | CAP_FSYNC; + + if(strstr(mode, "r+")) + { + flags |= O_RDWR; + rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; + } + else if(strstr(mode, "r")) + { + flags |= O_RDONLY; + rights |= CAP_READ; + } + else if(strstr(mode, "w+")) + { + flags |= O_RDWR | O_CREAT | O_TRUNC; + rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; + } + else if(strstr(mode, "w")) + { + flags |= O_WRONLY | O_CREAT | O_TRUNC; + rights |= CAP_WRITE | CAP_FTRUNCATE; + } + else if(strstr(mode, "a+")) + { + flags |= O_RDWR | O_CREAT | O_APPEND; + rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; + } + else if(strstr(mode, "a")) + { + flags |= O_WRONLY | O_CREAT | O_APPEND; + rights |= CAP_WRITE | CAP_FTRUNCATE; + } + + int fd = ua_open(path, flags); + if(flags & O_APPEND) + if(lseek(fd, 0, SEEK_END) < 0) + { + sprintf(errmsg, "Error seeking to end of %s: %i (%s)", + path, errno, strerror(errno)); + close(fd); + return NULL; + } + + return fdopen(fd, mode); +} + + + int ua_send(int sock, datum *d, int32_t fds[], int32_t fdlen) { // the datum is the I/O vector ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#7 (text+ko) ==== @@ -35,6 +35,8 @@ #define _LIBUSERANGEL_H_ #include +#include + #include __BEGIN_DECLS @@ -57,6 +59,9 @@ /** Open a file via the User Angel */ int ua_open(const char *path, int flags); +/** Open a file stream via the User Angel */ +FILE* ua_fopen(const char *path, const char *mode); + /* Low-level API */