Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Sep 2013 19:44:22 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r257542 - in soc2013/dpl/head/lib/libzcap: . zlibworker
Message-ID:  <201309201944.r8KJiMIP076703@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Fri Sep 20 19:44:22 2013
New Revision: 257542
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257542

Log:
  Update to zlibworker to handle better gzfileparams().
  

Modified:
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/commands.h
  soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Fri Sep 20 19:42:47 2013	(r257541)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Fri Sep 20 19:44:22 2013	(r257542)
@@ -92,7 +92,7 @@
 
 extern bool slist_initiated;
 nvlist_t *nvl, *args, *result;
-size_t gzsize = sizeof(gzFile);
+size_t gzsize = sizeof(struct gzFile_s *);
 size_t gzheadersize = sizeof(gz_state);
 size_t zstreamsize = sizeof(z_stream);
 
@@ -799,6 +799,7 @@
 	result = sendCommand(nvl, file);
 	ptr = nvlist_get_binary(result, "result", &gzsize);
 	memcpy(file, ptr, gzsize);
+	fprintf(stderr, "ZCAPLIB: gzopen(): %p\n", ptr);
 	destroy();
 	return(file);
 }
@@ -806,7 +807,6 @@
 int
 zcapcmd_gzbuffer(gzFile file, unsigned size)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZBUFFER);
@@ -824,7 +824,6 @@
 int
 zcapcmd_gzsetparams(gzFile file, int level, int strategy)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZSETPARAMS);
@@ -899,7 +898,6 @@
 int
 zcapcmd_gzputs(gzFile file, const char *s)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTS);
@@ -917,7 +915,6 @@
 char *
 zcapcmd_gzgets(gzFile file, char *buf, int len)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZGETS);
@@ -939,7 +936,6 @@
 int
 zcapcmd_gzputc(gzFile file, int c)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
@@ -957,7 +953,6 @@
 int
 zcapcmd_gzungetc(int c, gzFile file)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZUNGETC);
@@ -975,7 +970,6 @@
 int
 zcapcmd_gzflush(gzFile file, int flush)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZFLUSH);
@@ -993,7 +987,6 @@
 z_off_t
 zcapcmd_gzseek(gzFile file, z_off_t offset, int whence)
 {
-	
 	initNvl();
 
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZSEEK);

Modified: soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/commands.c	Fri Sep 20 19:42:47 2013	(r257541)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/commands.c	Fri Sep 20 19:44:22 2013	(r257542)
@@ -11,7 +11,7 @@
 extern int zero;
 extern void *data;
 
-size_t gzsize = sizeof(gz_state);
+size_t gzsize = sizeof(struct gzFile_s *);
 size_t zstreamsize = sizeof(z_stream);
 
 /*
@@ -254,6 +254,8 @@
 	mode = nvlist_get_string(args, "mode");
 
 	ret = gzdopen(fd, mode);
+
+	fprintf(stderr, "ZLIBWORKER: gzopen(): %p\n", ret);
 	nvlist_add_binary(result, "result", ret, gzsize);
 }
 
@@ -275,12 +277,20 @@
 zcapcmd_gzsetparams(nvlist_t *args, nvlist_t *result)
 {
 	int ret = -1;
+	gzFile file;
+	int level, strat;
 
-	ret = gzsetparams(
-		(gzFile)nvlist_get_binary(args, "file", &gzsize),
-		nvlist_get_number(args, "level"),
-		nvlist_get_number(args, "strategy")
-	);
+	fprintf(stderr, "We get about to get zcapcmd_gzsetparams() args\n");
+	file = (gzFile)nvlist_get_binary(args, "file", &gzsize);
+	fprintf(stderr, "We got file\n");
+	level = nvlist_get_number(args, "level");
+	fprintf(stderr, "We got level\n");
+	strat = nvlist_get_number(args, "strategy");
+	fprintf(stderr, "We got strat\n");
+
+	fprintf(stderr, "We get to gzsetparams(%p, %d, %d)\n", file, level, strat);
+	ret = gzsetparams(file, level, strat);
+	fprintf(stderr, "We finished with zcapcmd_gzsetparams()\n");
 
 	nvlist_add_number(result, "result", ret);
 }

Modified: soc2013/dpl/head/lib/libzcap/zlibworker/commands.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/commands.h	Fri Sep 20 19:42:47 2013	(r257541)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/commands.h	Fri Sep 20 19:44:22 2013	(r257542)
@@ -4,13 +4,9 @@
 	This list is taken from zlib.h, in this same directory.
 
 	All this defines represent the commands passed to the real
-	zlib listening through a program, and it will recognize them.
+	zlib listening through zlibworker, and it will recognize them.
 	Also, the defines have been checked for not being duplicates.
 
-	Since the only things that we can Capsicumize are: deflate()
-	and inflate(), we only have to care about sending those to 
-	commands (related to the basic functions, and utility functions.
-
 */
 
 #define SOCKETFILENO					3

Modified: soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c	Fri Sep 20 19:42:47 2013	(r257541)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c	Fri Sep 20 19:44:22 2013	(r257542)
@@ -1,13 +1,17 @@
 #include <sys/capability.h>
+#include <sys/types.h>
 
 #include <err.h>
 #include <nv.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "commands.h"
 #include "data.h"
+#include "debug.h"
 
 int main(int argc, char *argv[]);
 static void destroy(nvlist_t *nvl, nvlist_t *args, nvlist_t *results);
@@ -75,6 +79,20 @@
 /* Zero is set when we need to zero out data */
 int zero = 0;
 
+/* At "debug.h" */
+extern int DEBUG_ZCAP;
+
+static void
+debug(const char *msg, ...)
+{
+	va_list ap;
+
+	va_start(ap, msg);
+	if (DEBUG_ZCAP == 1)
+		vfprintf(stderr, msg, ap);
+	va_end(ap);
+}
+
 /* Deletes nvlists */
 static void
 destroy(nvlist_t *nvl, nvlist_t *args, nvlist_t *results)
@@ -106,6 +124,8 @@
 	/* Sandbox the process */
 	if (cap_enter() < 0)
 		err(1, "Couldn't enter capability mode");
+
+	debug("DEBUG: zlibworker(%d) entered capability mode\n", getpid());
 	
 	if ((data = calloc(5*1024, 1)) == NULL)
 		err(1, "malloc\n");
@@ -114,6 +134,7 @@
 		if ((result = nvlist_create(0)) == NULL)
 			err(1, "Can't create result.\n");
 
+		debug("DEBUG: zlibworker(%d) Awaiting command\n", getpid());
 		if  ((nvl = nvlist_recv(SOCKETFILENO)) == NULL)
 			err(1, "Received nvlist is NULL\n");
 
@@ -294,6 +315,7 @@
 				break;
 		}
 
+		debug("DEBUG: zlibworker(%d) About to send result\n", getpid());
 		if (nvlist_send(SOCKETFILENO, result) != 0)
 			err(1, "Couldn't send response\n");
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309201944.r8KJiMIP076703>