PERFORCE change 166812 for review

Robert Watson rwatson at FreeBSD.org
Thu Jul 30 17:45:46 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=166812

Change 166812 by rwatson at 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) {


More information about the p4-projects mailing list