From owner-p4-projects@FreeBSD.ORG Fri Jun 12 18:12:59 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 98A661065751; Fri, 12 Jun 2009 18:12:59 +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 493D3106574E for ; Fri, 12 Jun 2009 18:12:59 +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 365F38FC16 for ; Fri, 12 Jun 2009 18:12:59 +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 n5CICxkX013301 for ; Fri, 12 Jun 2009 18:12:59 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5CICxZb013299 for perforce@freebsd.org; Fri, 12 Jun 2009 18:12:59 GMT (envelope-from jona@FreeBSD.org) Date: Fri, 12 Jun 2009 18:12:59 GMT Message-Id: <200906121812.n5CICxZb013299@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 164193 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, 12 Jun 2009 18:13:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=164193 Change 164193 by jona@jona-trustedbsd-kentvm on 2009/06/12 18:12:34 Some more testing of user_angel IPC Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/fdtest.c#3 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#7 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#6 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/fdtest.c#3 (text+ko) ==== @@ -84,7 +84,7 @@ - struct cap_wire_datum *d = cap_marshall_string(message, 7); + struct cap_wire_datum *d = cap_marshall_string(message, strlen(message)); if(cap_send_fd(sock, "message and FDs", d, fds, fdlen) < 0) err(EX_IOERR, "Error sending data/FD"); @@ -98,6 +98,51 @@ if(cap_recv_fd(sock, &name, &d, fd_array, &fdlen) < 0) err(EX_IOERR, "Error receiving data/FD"); + printf("Received datum:\n"); + printf(" type: %i\n", d->type); + printf(" length: %i\n", d->length); + printf(" value: "); + + int len = 50; + char tmp[len + 1]; + + switch(d->type & TYPE_PRIMITIVE_MASK) + { + case INTEGER: + // TODO: long, short, etc. + ; + int value; + if(cap_unmarshall_int(d, &value) < 0) + err(EX_SOFTWARE, "Error unmarshalling int"); + + printf("%i ", value); + break; + +/* + case FLOAT: + if(d->type & LONG) printf("%g ", *((double*) value)); + else printf("%f ", *((float*) value)); + break; +*/ + case STRING: + ; + if(cap_unmarshall_string(d, tmp, &len) < 0) + err(EX_SOFTWARE, "Error unmarshalling string"); + + tmp[len] = '\0'; + printf("'%s' ", tmp); + break; + + case CAPBOX_OPTIONS: + printf("capbox_options (TODO) "); + break; + + default: + printf("unknown type 0x%x ", d->type); + } + printf("\n"); + + free(d); printf("Received FDs: "); for(int i = 0; i < fdlen; i++) printf("%i ", fd_array[i]); ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#7 (text+ko) ==== @@ -58,6 +58,21 @@ } + +int cap_unmarshall_int(struct cap_wire_datum *datum, int32_t *value) +{ + if(datum->length != 4) + { + fprintf(stderr, "Error unmarshalling int: should be 4B long, not %i\n", + datum->length); + return -1; + } + + memcpy(value, ((void*) datum) + sizeof(struct cap_wire_datum), 4); + return datum->length; +} + + struct cap_wire_datum* cap_marshall_string(char *value, int len) { int size = sizeof(struct cap_wire_datum) + len; @@ -65,10 +80,25 @@ d->type = STRING; d->length = len; - memcpy(d + sizeof(struct cap_wire_datum), value, len); + memcpy(((char*) d) + sizeof(struct cap_wire_datum), value, len); return d; } + + +int cap_unmarshall_string(struct cap_wire_datum *datum, char *value, int *len) +{ + *len = datum->length; + if(datum->length < 0) + { + fprintf(stderr, "Error unmarshalling int: should be positive, not %i\n", + datum->length); + return -1; + } + + memcpy(value, ((void*) datum) + sizeof(struct cap_wire_datum), datum->length); + return datum->length; +} /* int cap_send(int sock, struct cap_wire_datum* datum); */ @@ -140,7 +170,7 @@ // make room for it *d = (struct cap_wire_datum*) malloc(to_receive); struct iovec iov; - iov.iov_base = d; + iov.iov_base = *d; iov.iov_len = to_receive; ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#6 (text+ko) ==== @@ -38,11 +38,16 @@ struct cap_wire_datum { uint32_t type; - #define INTEGER 0x00000001 - #define FLOAT 0x00000002 - #define STRING 0x00000004 - #define LONG 0x00000100 - #define SHORT 0x00000200 + #define TYPE_PRIMITIVE_MASK 0x000000ff + #define INTEGER 0x00000001 + #define FLOAT 0x00000002 + #define STRING 0x00000004 + #define CAPBOX_OPTIONS 0x00000008 + + #define TYPE_MODIFIER_MASK 0x0000ff00 + #define LONG 0x00000100 + #define SHORT 0x00000200 + #define UNSIGNED 0x00000400 uint32_t length; @@ -60,16 +65,23 @@ +/* Unmarshalling functions; calling programs should free the result */ struct cap_wire_datum* cap_marshall_int(int32_t value); struct cap_wire_datum* cap_marshall_string(char *value, int len); +/* Unmarshalling functions; return the number of bytes unmarshalled (or -1) */ +int cap_unmarshall_int(struct cap_wire_datum *datum, int32_t *value); +int cap_unmarshall_string(struct cap_wire_datum *datum, char* value, int *len); + +/* Sending, with or without file descriptors */ int cap_send(int sock, char *name, struct cap_wire_datum *d); int cap_send_fd(int sock, const char *name, struct cap_wire_datum *d, int32_t fd_array[], int32_t fdlen); +/* Receiving, with or without file descriptors */ int cap_recv(int sock, char **name, struct cap_wire_datum **d); -/** You supply the FD array and say how big it is; I'll tell you how many FDs you actually received. */ +/* You supply the FD array and say how big it is; I'll tell you how many FDs you actually received. */ int cap_recv_fd(int sock, char **name, struct cap_wire_datum **d, int32_t fd_array[], int32_t *fdlen);