From owner-p4-projects@FreeBSD.ORG Thu Jul 23 13:59:51 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 306CF1065672; Thu, 23 Jul 2009 13:59:51 +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 CB7341065670 for ; Thu, 23 Jul 2009 13:59:50 +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 B8EED8FC12 for ; Thu, 23 Jul 2009 13:59:50 +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 n6NDxowg028548 for ; Thu, 23 Jul 2009 13:59:50 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6NDxoU1028546 for perforce@freebsd.org; Thu, 23 Jul 2009 13:59:50 GMT (envelope-from jona@FreeBSD.org) Date: Thu, 23 Jul 2009 13:59:50 GMT Message-Id: <200907231359.n6NDxoU1028546@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 166443 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, 23 Jul 2009 13:59:51 -0000 http://perforce.freebsd.org/chv.cgi?CH=166443 Change 166443 by jona@jona-trustedbsd-belle-vmware on 2009/07/23 13:59:40 Handle ua_access() and ua_stat() requests in the user_angel Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#16 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#16 (text+ko) ==== @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -80,6 +81,8 @@ void accept_client(int fd_server); int service_client(struct client*); int handle_request(struct client*, enum ua_request_t); +int handle_stat_request(struct client *client, struct ua_datum *d); +int handle_check_access(struct client *client, struct ua_datum *d); int handle_path_request(struct client*, struct ua_datum*); int handle_powerbox_request(struct client*, struct ua_datum*); void client_error(struct client*, const char *message, int errnum, @@ -207,9 +210,9 @@ for(struct client *c = clients; ; c = c->next) if(c->next == NULL) { - c->next = client; client->prev = c; client->next = NULL; + c->next = client; break; } @@ -246,21 +249,27 @@ if(FD_ISSET(fd_server, &selected)) { + printf("server socket selected\n"); /* TODO: tmp */ accept_client(fd_server); FD_CLR(fd_server, &selected); ready--; } - for(struct client *c = clients; c && ready; c = c->next) + for(struct client *c = clients; c && ready; ) if(FD_ISSET(c->socket, &selected)) { int sock = c->socket; + struct client *next = c->next; + service_client(c); FD_CLR(sock, &selected); ready--; + + c = next; } + else c = c->next; } @@ -327,12 +336,23 @@ int retval; switch(req) { + case UA_CHECK_ACCESS: + printf("%20s", "UA_CHECK_ACCESS"); + retval = handle_check_access(client, datum); + break; + + case UA_STAT: + printf("%20s", "UA_STAT"); + retval = handle_stat_request(client, datum); + break; + case UA_OPEN_PATH: + printf("%20s", "UA_OPEN_PATH"); retval = handle_path_request(client, datum); break; case UA_POWERBOX: - puts("UA_POWERBOX"); + printf("%20s", "UA_POWERBOX"); retval = handle_powerbox_request(client, datum); break; @@ -346,14 +366,65 @@ } +int handle_check_access(struct client *client, struct ua_datum *d) +{ + char path[256] = ""; + unsigned int pathlen = 256; + + int sock = client->socket; + + if(ua_unmarshall_string(d, path, &pathlen) < 0) return -1; + + printf(": %s\n", path); + + int32_t mode; + if(ua_unmarshall_int(ua_recv(sock, NULL, NULL), &mode) < 0) return -1; + + + int retval = access(path, mode); + d = ua_marshall_int(retval); + if(!d) return -1; + + if(ua_send(sock, d, NULL, 0) < 0) return -1; + free(d); + + + return 0; +} + + +int handle_stat_request(struct client *client, struct ua_datum *d) +{ + char path[256] = ""; + unsigned int pathlen = 256; + + int sock = client->socket; + + if(ua_unmarshall_string(d, path, &pathlen) < 0) return -1; + printf(": %s\n", path); + + struct stat s; + if(stat(path, &s)) return 1; + + + d = ua_marshall_string((char*) &s, sizeof(s)); + if(!d) return -1; + + if(ua_send(sock, d, NULL, 0) < 0) return -1; + free(d); + + + return 0; +} + + + int handle_path_request(struct client *client, struct ua_datum *d) { // unsigned int fdlen = 0; char path[256] = ""; unsigned int pathlen = 256; - printf("UA_OPEN_PATH"); - int sock = client->socket; // struct ua_datum *d = ua_recv(sock, NULL, &fdlen);