From owner-p4-projects@FreeBSD.ORG Fri Aug 28 22:19:26 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5946C1065675; Fri, 28 Aug 2009 22:19:26 +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 1DC071065673 for ; Fri, 28 Aug 2009 22:19:26 +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 0BCA68FC15 for ; Fri, 28 Aug 2009 22:19:26 +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 n7SMJPht087138 for ; Fri, 28 Aug 2009 22:19:25 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7SMJP2q087136 for perforce@freebsd.org; Fri, 28 Aug 2009 22:19:25 GMT (envelope-from jona@FreeBSD.org) Date: Fri, 28 Aug 2009 22:19:25 GMT Message-Id: <200908282219.n7SMJP2q087136@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 167933 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: Fri, 28 Aug 2009 22:19:26 -0000 http://perforce.freebsd.org/chv.cgi?CH=167933 Change 167933 by jona@jona-trustedbsd-belle-vmware on 2009/08/28 22:18:41 Better passing of rights, including 64b type handling Affected files ... .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#14 edit .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#13 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#14 (text+ko) ==== @@ -232,10 +232,9 @@ data[0] = ua_marshall_int(UA_OPEN_PATH); data[1] = ua_marshall_string(path, strlen(path)); data[2] = ua_marshall_int(flags); - data[3] = ua_marshall_int(rights); + data[3] = ua_marshall_long(rights); data[4] = ua_marshall_int(mask); - for(int i = 0; i <= 4; i++) { if(ua_send(angel, data[i], NULL, 0) < 0) return -1; @@ -277,40 +276,40 @@ if(angel < 0) return NULL; int flags = 0; - cap_rights_t rights = CAP_SEEK | CAP_FSYNC; + cap_rights_t rights = CAP_SEEK | CAP_FSYNC | CAP_FCNTL | CAP_FCHFLAGS | CAP_MASK_VALID; - if(strstr(mode, "r+")) + if(strnstr(mode, "r+", 3)) { flags |= O_RDWR; rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; } - else if(strstr(mode, "r")) + else if(strnstr(mode, "r", 2)) { flags |= O_RDONLY; rights |= CAP_READ; } - else if(strstr(mode, "w+")) + else if(strnstr(mode, "w+", 3)) { flags |= O_RDWR | O_CREAT | O_TRUNC; rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; } - else if(strstr(mode, "w")) + else if(strnstr(mode, "w", 2)) { flags |= O_WRONLY | O_CREAT | O_TRUNC; rights |= CAP_WRITE | CAP_FTRUNCATE; } - else if(strstr(mode, "a+")) + else if(strnstr(mode, "a+", 3)) { flags |= O_RDWR | O_CREAT | O_APPEND; rights |= CAP_READ | CAP_WRITE | CAP_FTRUNCATE; } - else if(strstr(mode, "a")) + else if(strnstr(mode, "a", 2)) { flags |= O_WRONLY | O_CREAT | O_APPEND; rights |= CAP_WRITE | CAP_FTRUNCATE; } - int fd = ua_open(path, flags); + int fd = ua_ropen(path, flags, rights, 0); if(flags & O_APPEND) if(lseek(fd, 0, SEEK_END) < 0) { @@ -320,6 +319,10 @@ return NULL; } + char buf[80]; + bzero(buf, 80); + if(read(fd, buf, 35) < 0) perror("Error reading file"); + return fdopen(fd, mode); } @@ -542,6 +545,52 @@ +datum* ua_marshall_long(int64_t value) +{ + int size = sizeof(datum) + sizeof(value); + datum *d = (datum*) malloc(size); + + d->type = LONG | INTEGER; + d->length = sizeof(value); + + void *address = ((char*) d) + sizeof(datum); + ((int64_t*) address)[0] = value; + + return d; +} + + + +int ua_unmarshall_long(const datum *d, int64_t *value) +{ + if(d == NULL) + { + errno = EINVAL; + return -1; + } + + if(!(d->type & (LONG | INTEGER))) + { + if(d->type & ERROR) handle_error(d); + else errno = EINVAL; + return -1; + } + + if(d->length > sizeof(int64_t)) + { + errno = EOVERFLOW; + return -1; + } + else bzero(value, sizeof(int32_t)); + + memcpy(value, ((const char*) d) + sizeof(datum), sizeof(*value)); + + return d->length; +} + + + + datum* ua_marshall_string(const char *value, unsigned int len) { int size = sizeof(datum) + len; @@ -655,7 +704,7 @@ data[4] = ua_marshall_int(options->mult); data[5] = ua_marshall_string(options->filter, options->filterlen); data[6] = ua_marshall_int(options->flags); - data[7] = ua_marshall_int(options->rights); + data[7] = ua_marshall_long(options->rights); data[8] = ua_marshall_int(options->umask); int total_size = 0; @@ -743,8 +792,9 @@ options->flags = tmp_int; head = (const datum*) (((const char*) head) + sizeof(datum) + head->length); - if(ua_unmarshall_int(head, &tmp_int) < 0) return -1; - options->rights = tmp_int; + int64_t tmp_long; + if(ua_unmarshall_long(head, &tmp_long) < 0) return -1; + options->rights = tmp_long; head = (const datum*) (((const char*) head) + sizeof(datum) + head->length); if(ua_unmarshall_int(head, &tmp_int) < 0) return -1; @@ -757,13 +807,14 @@ void handle_error(const datum *d) { - int32_t errnum; + int32_t errnum = 0; char msg[200]; int msglen = 200; - if(ua_unmarshall_error(d, &errnum, msg, &msglen) < 0) return; + ua_unmarshall_error(d, &errnum, msg, &msglen); errno = errnum; + printf("libuserangel error: %s\n", msg); /* TODO: do something! fprintf(stderr, "user_angel error: %s (%i: %s)\n", ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#13 (text+ko) ==== @@ -122,6 +122,7 @@ /* Unmarshalling functions; calling programs should free the result */ struct ua_datum* ua_marshall_int(int32_t value); +struct ua_datum* ua_marshall_long(int64_t value); struct ua_datum* ua_marshall_string(const char *value, unsigned int len); struct ua_datum* ua_marshall_error(int errnum, const char *msg, unsigned int msglen); struct ua_datum* ua_marshall_powerbox(const struct ua_powerbox_options *options); @@ -129,6 +130,7 @@ /* Unmarshalling functions; return the number of bytes unmarshalled (or -1) */ int ua_unmarshall_int(const struct ua_datum *d, int32_t *value); +int ua_unmarshall_long(const struct ua_datum *d, int64_t *value); int ua_unmarshall_bytes(const struct ua_datum *d, char *value, unsigned int *len); int ua_unmarshall_string(const struct ua_datum *d, char *value, unsigned int *len); int ua_unmarshall_error(const struct ua_datum *d, int *errnum, char *msg, int *msglen);