Date: Thu, 25 Jun 2009 08:22:02 GMT From: Jonathan Anderson <jona@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 165136 for review Message-ID: <200906250822.n5P8M2ax050452@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=165136 Change 165136 by jona@jona-trustedbsd-belle-vmware on 2009/06/25 08:22:00 Let ua_find() parse the server hello Affected files ... .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#4 edit .. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#3 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#9 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#12 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#12 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#4 (text+ko) ==== @@ -53,6 +53,9 @@ int angel = -1; +const char *VERSION = "UA/0.1"; +const char *ua_protocol_version() { return VERSION; } + char errmsg[256]; const char* ua_protocol_error(void) { return errmsg; } @@ -90,6 +93,59 @@ return -1; } + + // receive server 'hello' + struct ua_datum *hello_datum = ua_recv(angel, NULL, NULL); + if(!hello_datum) + { + sprintf(errmsg, "Error receiving server 'hello': %i (%s)", + errno, strerror(errno)); + close(angel); + angel = -1; + return -1; + } + + unsigned int hellolen = 120; + char hello[hellolen]; + if(ua_unmarshall_string(hello_datum, hello, &hellolen) < 0) + { + sprintf(errmsg, "Error unmarshalling server 'hello': %i (%s)", + errno, strerror(errno)); + + close(angel); + angel = -1; + return -1; + } + + free(hello_datum); + printf("Got server hello: \"%s\"\n", hello); + + // validate server 'hello' message + if(strncmp(hello, "user_angel", 10)) + { + sprintf(errmsg, "Server handshake didn't start with user_angel: %s", + hello); + + close(angel); + angel = -1; + return -1; + } + + char *version = hello; + while(*version != ' ') version++; + version++; + + unsigned int len = strlen(version); + if((len != strlen(VERSION)) || strncmp(version, VERSION, len)) + { + sprintf(errmsg, "Invalid UA protocol version: %s (expected %s)", + version, VERSION); + + close(angel); + angel = -1; + return -1; + } + return angel; } ==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#3 (text+ko) ==== @@ -39,6 +39,9 @@ /* High-level API */ +/** Version of the User Angel protocol */ +const char* ua_protocol_version(void); + /** The last angel/sandbox protocol error */ const char* ua_protocol_error(void); ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#9 (text+ko) ==== @@ -1,12 +1,11 @@ -VERSION=dev-pre1 DEBUG=-g -ggdb WARNINGS=-Wall -Werror -pedantic-errors QDBUS_INCLUDE=-I/usr/local/include/qt4 QDBUS_LIBS=-L /usr/local/lib/qt4 -lQtDBus -CFLAGS=--std=c99 ${DEBUG} ${WARNINGS} ${INCLUDE} -DVERSION='"${VERSION}"' -CXXFLAGS=${DEBUG} -Wall ${QDBUS_INCLUDE} -DVERSION='"${VERSION}"' +CFLAGS=--std=c99 ${DEBUG} ${WARNINGS} ${INCLUDE} +CXXFLAGS=${DEBUG} -Wall ${QDBUS_INCLUDE} LIBS=-lcapability -luserangel -lsbuf BIN=user_angel test_client ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#12 (text+ko) ==== @@ -190,7 +190,7 @@ if(client > highest_fd) highest_fd = client; char hello[80]; - sprintf(hello, "user_angel v%s", VERSION); + sprintf(hello, "user_angel %s", ua_protocol_version()); struct ua_datum *d = ua_marshall_string(hello, strlen(hello)); ua_send(client, d, NULL, 0); ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#12 (text+ko) ==== @@ -22,8 +22,13 @@ int main(int argc, char *argv[]) { int fd_angel = ua_find(); - if(fd_angel < 0) err(EX_SOFTWARE, "Error finding user angel"); - printf("Conntected to user angel via FD %i\n", fd_angel); + if(fd_angel < 0) + { + fprintf(stderr, "Error finding user angel: %s\n", + ua_protocol_error()); + return -1; + } + printf("Connected to user angel via FD %i\n", fd_angel); int proc; pid_t pid = pdfork(&proc); @@ -44,18 +49,6 @@ - // receive server 'hello' - struct ua_datum *hello_datum = ua_recv(fd_angel, NULL, NULL); - if(!hello_datum) err(EX_IOERR, "Error receiving server 'hello'"); - - unsigned int hellolen = 80; - char hello[hellolen]; - if(ua_unmarshall_string(hello_datum, hello, &hellolen) < 0) - err(EX_SOFTWARE, "Error unmarshalling server 'hello'"); - - free(hello_datum); - printf("Got server hello: \"%s\"\n", hello); - open_file(fd_angel, "/etc/group", O_RDONLY, CAP_FSTAT | CAP_READ | CAP_SEEK);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906250822.n5P8M2ax050452>