From owner-p4-projects@FreeBSD.ORG Thu Jul 30 17:45:45 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AE97D1065678; Thu, 30 Jul 2009 17:45:45 +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 66E7A1065670 for ; Thu, 30 Jul 2009 17:45:45 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 393DA8FC16 for ; Thu, 30 Jul 2009 17:45:45 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6UHjjRj099280 for ; Thu, 30 Jul 2009 17:45:45 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6UHjjxR099278 for perforce@freebsd.org; Thu, 30 Jul 2009 17:45:45 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Thu, 30 Jul 2009 17:45:45 GMT Message-Id: <200907301745.n6UHjjxR099278@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 166812 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, 30 Jul 2009 17:45:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=166812 Change 166812 by rwatson@rwatson_freebsd_capabilities on 2009/07/30 17:45:41 Recomment. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_world/sandbox_world.c#4 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_world/sandbox_world.c#4 (text+ko) ==== @@ -53,6 +53,9 @@ #define MYNAME "sandbox_world" /* Binary to run in sandbox. */ +/* + * Unsandboxed host process with full user rights. + */ int main(int argc, char *argv[]) { @@ -65,6 +68,9 @@ if (argc != 1) errx(-1, "usage: sandbox_world"); + /* + * Create a sandbox, do permit access to stdout and stderr. + */ if (lch_start(MYNAME, sandbox_argv, LCH_PERMIT_STDERR | LCH_PERMIT_STDOUT, &lcsp) < 0) err(-1, "lch_start %s", argv[1]); @@ -79,14 +85,19 @@ if (lch_rpc(lcsp, 0, &iov, 1, &iov, 1, &len) < 0) err(-1, "lch_rpc"); if (len != sizeof(ch)) - errx(-1, "lch_rpc returned size %d not %d", len, - sizeof(ch)); + errx(-1, "lch_rpc returned size %d not %d", len, sizeof(ch)); if (ch != 'X') errx(-1, "lch_recv: expected %d and got %d", 'X', ch); + /* + * Terminate the sandbox when done. + */ lch_stop(lcsp); } +/* + * Sandboxed process implementing a 'printf hello world' RPC. + */ int cap_main(int argc, char *argv[]) { @@ -99,7 +110,13 @@ if (lcs_get(&lchp) < 0) err(-1, "lcs_get"); + /* + * Serve RPCs from the host until the sandbox is killed. + */ while (1) { + /* + * Receive a one-byte RPC from the host. + */ if (lcs_recvrpc(lchp, &opno, &seqno, &buffer, &len) < 0) { if (errno != EPIPE) err(-6, "lcs_recvrpc"); @@ -110,6 +127,11 @@ errx(-7, "lcs_recvrpc len"); printf("Hello world!\n"); fflush(stdout); + + /* + * Reply with the same message. Remember to free the message + * when done. + */ iov.iov_base = buffer; iov.iov_len = 1; if (lcs_sendrpc(lchp, opno, seqno, &iov, 1) < 0) {