socsvn commit: r257164 - in soc2013/dpl/head/lib/libzcap: . zlibworker
dpl at FreeBSD.org
dpl at FreeBSD.org
Mon Sep 9 16:09:04 UTC 2013
Author: dpl
Date: Mon Sep 9 16:09:03 2013
New Revision: 257164
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257164
Log:
Code improved. Now we're not depending on capsicum.h as before.
Modified:
soc2013/dpl/head/lib/libzcap/adler32.c
soc2013/dpl/head/lib/libzcap/capsicum.c
soc2013/dpl/head/lib/libzcap/capsicum.h
soc2013/dpl/head/lib/libzcap/commands.c
soc2013/dpl/head/lib/libzcap/commands.h
soc2013/dpl/head/lib/libzcap/crc32.c
soc2013/dpl/head/lib/libzcap/deflate.c
soc2013/dpl/head/lib/libzcap/gzlib.c
soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
Modified: soc2013/dpl/head/lib/libzcap/adler32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/adler32.c Mon Sep 9 15:38:51 2013 (r257163)
+++ soc2013/dpl/head/lib/libzcap/adler32.c Mon Sep 9 16:09:03 2013 (r257164)
@@ -6,6 +6,7 @@
/* @(#) $Id$ */
#include "zutil.h"
+#include "commands.h"
#define local static
Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c Mon Sep 9 15:38:51 2013 (r257163)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c Mon Sep 9 16:09:03 2013 (r257164)
@@ -1,3 +1,4 @@
+#include "debug.h"
#include "capsicum.h"
#include "zlib.h"
@@ -8,38 +9,62 @@
#include <sys/socket.h>
#include <sys/types.h>
+#include <err.h>
+#include <errno.h>
#include <nv.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
-#include <err.h>
/*
* The only function allocating space
* for struct sandbox is startChild().
*/
-struct sandbox;
-struct slisthead sandboxes;
-struct sandbox * startSandbox(void *data);
-void stopSandbox(struct sandbox *sandbox);
+/* head of singly-linked list. */
+SLIST_HEAD(slisthead, sandbox) sandboxes = SLIST_HEAD_INITIALIZER(sandboxes);
+
+struct sandbox {
+ void * dataptr; /* Pointer to the data structure of the lib */
+ int pd; /* Process descriptor */
+ int socket; /* Socket we have to pass the data through */
+ SLIST_ENTRY(sandbox) next; /* Singly-linked list. */
+};
+
+void startSandbox(void *data);
+void stopSandbox(void *ptr);
void startNullSandbox(void);
struct sandbox * findSandbox(void *ptr);
struct sandbox *startChild(void *data);
void killChild(void);
void suicide(int signal);
-nvlist_t * sendCommand(nvlist_t *nvl, int socket);
+nvlist_t * sendCommand(nvlist_t *nvl, void *ptr);
bool slist_initiated = 0;
+/* At "debug.h" */
+extern int DEBUG_ZCAP;
+
+static void
+limitfd(int fd, unsigned long long cap)
+{
+ cap_rights_t rights;
+
+ cap_rights_init(&rights);
+ cap_rights_set(&rights, cap);
+
+ if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS)
+ err(1, "Couldn't limit fd: %d\n", fd);
+}
+
/*
* This function should be called only by:
* gzopen(), deflateInit(), inflateInit(),
* inflateBackInit().
*/
-struct sandbox *
+void
startSandbox(void *data)
{
struct sandbox *newsandbox;
@@ -50,8 +75,6 @@
/* Create and add the real sandbox */
newsandbox = startChild(data);
SLIST_INSERT_HEAD(&sandboxes, newsandbox, next);
-
- return (newsandbox);
}
/*
@@ -60,18 +83,17 @@
* deflateEnd, inflateEnd (inflateBackEnd).
*/
void
-stopSandbox(struct sandbox *sandboxToStop)
+stopSandbox(void *ptr)
{
- int pid;
-
- if (pdgetpid(sandboxToStop->pd, &pid) < 0)
- err(1, "Couldn't get child PID");
+ struct sandbox *box;
- if (kill(SIGKILL, pid) < 0)
- err(1, "Couldn't kill child");
+ box = findSandbox(ptr);
+ if (DEBUG_ZCAP)
+ printf("DEBUG: Stopping sandbox:%d\n",box->pd );
+ pdkill(box->pd, SIGKILL);
- SLIST_REMOVE(&sandboxes, sandboxToStop, sandbox, next);
- free(sandboxToStop);
+ SLIST_REMOVE(&sandboxes, box, sandbox, next);
+ free(box);
}
/* Starts the default sandbox. */
@@ -79,8 +101,12 @@
startNullSandbox(void)
{
struct sandbox *newsandbox;
+ if (DEBUG_ZCAP)
+ printf("DEBUG: Starting NULL sandbox\n");
+
if (!slist_initiated) {
SLIST_INIT(&sandboxes);
+
/* Here we add a sandbox used for non-structure related stuff */
/* This will be the first sandbox always */
if (SLIST_EMPTY(&sandboxes)) {
@@ -124,34 +150,47 @@
sv[0] = sv[1] = 0;
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 )
perror("zcaplib: socketpair()");
+ if (DEBUG_ZCAP)
+ printf("DEBUG: Called socketpair(): sv[0]: %d, sv[1]: %d\n", sv[0], sv[1]);
procd = pdfork(&procd, 0);
- if (procd == 0 ){
- if (cap_rights_limit(STDIN_FILENO, CAP_READ) < 0)
- err(1, "Couldn't limit rights");
- if (cap_rights_limit(STDOUT_FILENO, CAP_WRITE|CAP_FSTAT) < 0)
- err(1, "Couldn't limit rights");
- if (cap_rights_limit(STDERR_FILENO, CAP_WRITE) < 0)
- err(1, "Couldn't limit rights");
- dup2(sv[0], 3);
- if (cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_POLL_EVENT) < 0)
- err(1, "Couldn't limit rights");
+ if (procd == 0 ) {
+ /* Sandbox the process */
+ if (cap_enter() < 0)
+ err(1, "Couldn't enter capability mode");
+
+ if (DEBUG_ZCAP)
+ printf("DEBUG: STDIN_FILENO: %d\n", STDIN_FILENO);
+
+ limitfd(STDIN_FILENO, CAP_READ);
+ limitfd(STDOUT_FILENO, CAP_WRITE|CAP_FSTAT);
+ limitfd(STDERR_FILENO, CAP_WRITE);
+
+ if (dup2(sv[0], 3) != 3)
+ err(1, "Couldn't duplicate fd");
closefrom(4);
+ limitfd(3, CAP_WRITE|CAP_READ|CAP_POLL_EVENT);
+
/* execl() zlibworker */
- if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) < 0) {
+ if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) < 0)
err(1, "Couldn't find zlibworker.");
- }
+
exit(0);
} else if (procd == -1) {
err(1, "Couldn't fork");
} else {
- close(sv[1]);
+ if ( DEBUG_ZCAP )
+ printf("DEBUG: Done forking: %d\n", procd);
+
signal(SIGCHLD, suicide);
atexit(killChild);
newsandbox->dataptr = data;
newsandbox->pd = procd;
newsandbox->socket = sv[0];
+ if (DEBUG_ZCAP)
+ printf("DEBUG: We have started a new sandbox.\n");
+ printf("\tpd: %d, socket: %d\n", newsandbox->pd, newsandbox->socket);
}
return (newsandbox);
}
@@ -159,6 +198,8 @@
void killChild(void) {
int pid;
struct sandbox *box;
+
+ /* Kill all sandboxes. */
SLIST_FOREACH(box, &sandboxes, next)
if (pdgetpid(box->pd, &pid) > 0)
kill(SIGKILL, pid);
@@ -167,13 +208,20 @@
kill(getpid(), SIGKILL);
}
+/* Sends nvlist to the related sandbox. */
nvlist_t *
-sendCommand(nvlist_t *nvl, int socket)
+sendCommand(nvlist_t *nvl, void *ptr)
{
nvlist_t *new;
- if( nvlist_send(socket, nvl) != 0 )
+ struct sandbox *box;
+
+ box = findSandbox(ptr);
+ if (DEBUG_ZCAP)
+ printf("DEBUG: Sending command to %d sandbox\n", box->pd);
+
+ if( nvlist_send(box->socket, nvl) != 0 )
err(1, "zcaplib: nvlist_send() Went wrong");
- if ((new = nvlist_recv(socket)) == NULL)
+ if ((new = nvlist_recv(box->socket)) == NULL)
err(1, "nvlist_recv(): nvlist_t is NULL");
return (new);
}
Modified: soc2013/dpl/head/lib/libzcap/capsicum.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.h Mon Sep 9 15:38:51 2013 (r257163)
+++ soc2013/dpl/head/lib/libzcap/capsicum.h Mon Sep 9 16:09:03 2013 (r257164)
@@ -8,29 +8,12 @@
#include <nv.h>
-#define MAXLEN (5*1024)
-
-struct sandbox * startSandbox(void *data);
-void stopSandbox(struct sandbox *sandbox);
+void startSandbox(void *data);
+void stopSandbox(void *ptr);
void startNullSandbox(void);
struct sandbox * findSandbox(void *ptr);
struct sandbox *startChild(void *data);
void killChild(void);
void suicide(int signal);
-nvlist_t * sendCommand(nvlist_t *nvl, int socket);
-
-/* head of singly-linked list. */
-SLIST_HEAD(slisthead, sandbox) sandboxes = SLIST_HEAD_INITIALIZER(sandboxes);
-
-/*
- * This structure holds a relation of structs of data structs,
- * and its related process descriptor (pd).
- */
-struct sandbox {
- void * dataptr; /* Pointer to the data structure of the lib */
- int pd; /* Process descriptor */
- int socket; /* Socket we have to pass the data through */
- SLIST_ENTRY(sandbox) next; /* Singly-linked list. */
-};
-
-#endif /* CAPSICUM_H */
\ No newline at end of file
+nvlist_t * sendCommand(nvlist_t *nvl, void *ptr);
+#endif /* !CAPSICUM_H */
\ No newline at end of file
Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c Mon Sep 9 15:38:51 2013 (r257163)
+++ soc2013/dpl/head/lib/libzcap/commands.c Mon Sep 9 16:09:03 2013 (r257164)
@@ -8,9 +8,11 @@
#include <string.h>
#include <err.h>
+#include <nv.h>
+#include <dnv.h>
-static void initializeCommand(void);
+static void initNvl(void);
static void destroy(void);
@@ -82,24 +84,24 @@
uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2);
-extern nvlist_t *sendCommand(nvlist_t *);
-extern void *data;
+extern nvlist_t *sendCommand(nvlist_t *, void *ptr);
+extern void startSandbox(void *data);
+extern void startNullSandbox();
+extern bool slist_initiated;
nvlist_t *nvl, *args, *result;
size_t gzfilesize = sizeof(gzFile);
size_t gzheadersize = sizeof(struct gz_header_s);
size_t zstreamsize = sizeof(z_stream);
-static sandbox_s*
-initializeCommand(void *ptr) {
- sandbox_s *sanbox;
+void
+initNvl() {
+ if (!slist_initiated)
+ startNullSandbox();
- sandbox = findSandbox(ptr);
if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL )
err(1, "zcaplib: nvlist_create");
-
- return sandbox;
}
static void
@@ -116,7 +118,8 @@
uLong ret;
const z_stream *newstrm;
- initializeCommand();
+ initNvl();
+ startSandbox(strm);
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
/* No worries here, strm state will be saved on zlibworker */
@@ -130,7 +133,7 @@
nvlist_add_number(args, "stream_size", stream_size);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
/*
* We get the "good" struct from the worker.
@@ -154,13 +157,13 @@
uLong ret;
const z_stream *newstrm;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -177,12 +180,12 @@
uLong ret;
const z_stream *newstrm;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEEND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -191,6 +194,7 @@
else
err(1, "libzcap: deflateEnd() destroyed z_stream\n");
destroy();
+ stopSandbox(strm);
return(ret);
}
@@ -202,7 +206,8 @@
const z_stream *newstrm;
const char *msg;
- initializeCommand();
+ initNvl();
+ startSandbox(strm);
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEINIT);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -211,7 +216,7 @@
nvlist_add_number(args, "stream_size", stream_size);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -229,13 +234,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATE);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -251,13 +256,13 @@
uLong ret;
const z_stream *newstrm;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEEND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -275,14 +280,14 @@
/* XXX */
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETDICTIONARY);
nvlist_add_binary(args, "dictionary", *dictionary, dictLength);
nvlist_add_number(args, "dictLength", dictLength);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -296,15 +301,15 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY);
nvlist_add_binary(args, "dest", (void *)dest, zstreamsize);
nvlist_add_binary(args, "source", (void *)source, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- /* The two z_streamp are now copied at the worker. */
- result = sendCommand(nvl);
+ /* The dest z_streamp is copied at its sandbox. */
+ result = sendCommand(nvl, dest);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -318,13 +323,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATERESET);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
/* Save the reseted strm. */
@@ -341,7 +346,7 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPARAMS);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -349,7 +354,7 @@
nvlist_add_number(args, "strategy", strategy);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
/* Overwrite the old streamp */
@@ -365,7 +370,7 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATETUNE);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -375,7 +380,7 @@
nvlist_add_number(args, "max_chain", max_chain);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -389,14 +394,14 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEBOUND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_number(args, "sourceLen", sourceLen);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -410,7 +415,7 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPENDING);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -419,7 +424,7 @@
nvlist_add_number(args, "bits", *bits);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -433,7 +438,7 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -441,7 +446,7 @@
nvlist_add_number(args, "value", value);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -457,7 +462,7 @@
/* What happens with header->extra??? */
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -466,7 +471,7 @@
nvlist_add_string(nvl, "comment", head->comment);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -481,13 +486,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -502,13 +507,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETDICTIONARY);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -522,13 +527,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESYNC);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -542,15 +547,16 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATECOPY);
nvlist_add_binary(args, "dest", (void *)dest, zstreamsize);
nvlist_add_binary(args, "source", (void *)source, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- /* The two z_streamp are now copied at the worker. */
- result = sendCommand(nvl);
+ /* The dest z_streamp is copied at its sandbox. */
+ /* XXX - There's a problem with this, we can't copy internat_state */
+ result = sendCommand(nvl, dest);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -564,13 +570,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -586,14 +592,14 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET2);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_number(nvl, "windowBits", windowBits);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -609,7 +615,7 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEPRIME);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -617,7 +623,7 @@
nvlist_add_number(args, "value", value);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -631,13 +637,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEMARK);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -652,14 +658,14 @@
/* XXX: Beware of gz_headerp extra */
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETHEADER);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_binary(args, "head", (void *)head, gzheadersize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -677,14 +683,14 @@
/* window has to be a pointer to at least a 32kb buffer */
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKINIT);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_number(args, "windowBits", windowBits);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -701,13 +707,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACK);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -721,13 +727,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKEND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, strm);
ret = dnvlist_get_number(result, "result", NULL);
const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
@@ -741,12 +747,12 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_ZLIBCOMPILEFLAGS);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, NULL);
ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -759,13 +765,13 @@
{
uLong ret;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_COMPRESSBOUND);
nvlist_add_number(args, "sourceLen", sourceLen);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, NULL);
ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
@@ -777,14 +783,16 @@
{
gzFile *fileptr;
gzFile file;
- initializeCommand();
+
+ initNvl();
+ startSandbox(file);
nvlist_add_number(nvl, "command", ZCAPCMD_GZOPEN);
nvlist_move_descriptor(args, "fd", fd);
nvlist_add_string(args, "mode", mode);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
fileptr = (gzFile *)dnvlist_get_binary(result, "result", &gzfilesize, NULL, sizeof(NULL));
file = *fileptr;
@@ -798,14 +806,14 @@
zcapcmd_gzbuffer(gzFile file, unsigned size)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZBUFFER);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_number(args, "size", size);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -816,7 +824,7 @@
zcapcmd_gzsetparams(gzFile file, int level, int strategy)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZSETPARAMS);
nvlist_add_binary(args, "file", file, gzfilesize);
@@ -824,7 +832,7 @@
nvlist_add_number(args, "strategy", strategy);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -836,14 +844,14 @@
{
const void * data;
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZREAD);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
data = dnvlist_get_binary(result, "data", len, NULL, sizeof(NULL));
@@ -855,7 +863,7 @@
int
zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZWRITE);
nvlist_add_binary(args, "file", file, gzfilesize);
@@ -863,7 +871,7 @@
nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -873,14 +881,14 @@
int
zcapcmd_gzprintf(gzFile file, const char * str)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZPRINTF);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_string(args, "str", str);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -891,14 +899,14 @@
zcapcmd_gzputs(gzFile file, const char *s)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTS);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_string(args, "s", s);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -909,14 +917,14 @@
zcapcmd_gzgets(gzFile file, char *buf, int len)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZGETS);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
const char *ret = dnvlist_get_string(result, "result", NULL);
if (ret == NULL)
@@ -931,14 +939,14 @@
zcapcmd_gzputc(gzFile file, int c)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_number(args, "c", c);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -949,14 +957,14 @@
zcapcmd_gzungetc(int c, gzFile file)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZUNGETC);
nvlist_add_number(args, "c", c);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_nvlist(nvl, "args", args);
- result = sendCommand(nvl);
+ result = sendCommand(nvl, file);
int ret = dnvlist_get_number(result, "result", NULL);
destroy();
@@ -967,14 +975,14 @@
zcapcmd_gzflush(gzFile file, int flush)
{
- initializeCommand();
+ initNvl();
nvlist_add_number(nvl, "command", ZCAPCMD_GZFLUSH);
nvlist_add_binary(args, "file", file, gzfilesize);
nvlist_add_number(args, "flush", flush);
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-soc-all
mailing list