From owner-p4-projects@FreeBSD.ORG Thu Jun 18 11:11:35 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 20B331065672; Thu, 18 Jun 2009 11:11:35 +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 D531F106566C for ; Thu, 18 Jun 2009 11:11:34 +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 B8B418FC08 for ; Thu, 18 Jun 2009 11:11:34 +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 n5IBBY2Q000822 for ; Thu, 18 Jun 2009 11:11:34 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5IBBVD6000819 for perforce@freebsd.org; Thu, 18 Jun 2009 11:11:31 GMT (envelope-from jona@FreeBSD.org) Date: Thu, 18 Jun 2009 11:11:31 GMT Message-Id: <200906181111.n5IBBVD6000819@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 164658 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: Thu, 18 Jun 2009 11:11:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=164658 Change 164658 by jona@jona-trustedbsd-kentvm on 2009/06/18 11:11:15 Provided the code for marshalling and unmarshalling errors Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#10 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#9 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#10 (text+ko) ==== @@ -162,6 +162,86 @@ } + +wire_datum* cap_marshall_error(int errno, const char *msg, int msglen) +{ + wire_datum *data[2]; + data[0] = cap_marshall_int(errno); + data[1] = cap_marshall_string(msg, msglen); + + int total_size = 0; + for(int i = 0; i < 2; i++) + if(data[i] == NULL) + { + sprintf(errmsg, "Error datum %i is NULL", i); + return NULL; + } + else total_size += (sizeof(wire_datum) + data[i]->length); + + wire_datum *d = (wire_datum*) malloc(sizeof(wire_datum) + total_size); + d->type = ERROR; + d->length = total_size; + + char *buffer = ((char*) d) + sizeof(wire_datum); + char *head = buffer; + for(int i = 0; i < 2; i++) + { + memcpy(head, data[i], sizeof(wire_datum) + data[i]->length); + head += sizeof(wire_datum) + data[i]->length; + + free(data[i]); + } + + return d; +} + + +int cap_unmarshall_error(const wire_datum *d, int *errno, const char *msg, int *msglen) +{ + if(datum == NULL) + { + sprintf(errmsg, "NULL datum"); + return -1; + } + else if(datum->type != ERROR) + { + sprintf(errmsg, "Datum's type is %i, not ERROR (%i)", + datum->type, ERROR); + } + else if(datum->length < 0) + { + sprintf(errmsg, "Datum length should be positive, not %i", + datum->length); + return -1; + } + + int32_t tmp_int; + wire_datum *d = (wire_datum*) (((char*) datum) + sizeof(wire_datum)); + + if(cap_unmarshall_int(d, &tmp_int) < 0) + { + char error[128]; + sprintf(error, "Error unmarshalling errno: %s", cap_error()); + strcpy(errmsg, error); + return -1; + } + *errno = tmp_int; + d = (wire_datum*) (((char*) d) + sizeof(wire_datum) + d->length); + + + if(cap_unmarshall_string(d, msg, msglen) < 0) + { + char error[128]; + sprintf(error, "Error unmarshalling path: %s", cap_error()); + strcpy(errmsg, error); + return -1; + } + + return sizeof(wire_datum) + datum->length; +} + + + wire_datum* cap_marshall_capbox(const struct capbox_options *options) { wire_datum *data[8]; ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#9 (text+ko) ==== @@ -82,8 +82,8 @@ /* Unmarshalling functions; return the number of bytes unmarshalled (or -1) */ int cap_unmarshall_int(const struct cap_wire_datum *d, int32_t *value); -int cap_unmarshall_string(const struct cap_wire_datum *d, char* value, int *len); -int cap_unmarshall_error(const struct cap_wire_datum *d, int errno, const char *msg, int msglen); +int cap_unmarshall_string(const struct cap_wire_datum *d, char *value, int *len); +int cap_unmarshall_error(const struct cap_wire_datum *d, int *errno, const char *msg, int *msglen); int cap_unmarshall_capbox(const struct cap_wire_datum *d, struct capbox_options *options);