socsvn commit: r256878 - in soc2013/dpl/head/lib/libzcap: . test zlibworker
dpl at FreeBSD.org
dpl at FreeBSD.org
Tue Sep 3 18:41:30 UTC 2013
Author: dpl
Date: Tue Sep 3 18:41:30 2013
New Revision: 256878
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256878
Log:
Savepoint before an architectural change. Last commit working with a single child process.
Added:
soc2013/dpl/head/lib/libzcap/test/testlib.sh (contents, props changed)
soc2013/dpl/head/lib/libzcap/zlibworker/data.h
Modified:
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/deflate.c
soc2013/dpl/head/lib/libzcap/gzlib.c
soc2013/dpl/head/lib/libzcap/inflate.c
soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c
soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -12,8 +12,6 @@
#include <stdio.h>
#include <err.h>
-#define SUM 0
-
pid_t pid = 0;
int sv[2];
@@ -29,22 +27,20 @@
perror("zcaplib: socketpair()");
if( (pid = fork()) == 0 ){
- cap_rights_limit(STDIN_FILENO, CAP_READ);
- cap_rights_limit(STDOUT_FILENO, CAP_WRITE|CAP_FSTAT|CAP_IOCTL);
- cap_rights_limit(STDERR_FILENO, CAP_WRITE);
+ 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);
- cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_POLL_EVENT);
+ if (cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_POLL_EVENT) < 0)
+ err(1, "Couldn't limit rights");
closefrom(4);
- /* open and execl() listener */
- if (access("/usr/libexec/zlibworker", X_OK) < 0) {
- perror("zcaplib: access():");
- exit (-1);
- }
-
+ /* execl() zlibworker */
if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) < 0) {
- perror("zcaplib: execl:");
- exit (-1);
+ err(1, "Couldn't find zlibworker.");
}
exit(0);
} else {
Modified: soc2013/dpl/head/lib/libzcap/capsicum.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.h Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/capsicum.h Tue Sep 3 18:41:30 2013 (r256878)
@@ -2,16 +2,20 @@
* With Capsicum, we get a compartmentalized, and securer lib.
*/
#define CAPSICUM
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
#include <sys/capability.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
+
+#include <dnv.h>
+#include <stdlib.h>
+#include <signal.h>
#include <nv.h>
+#include <unistd.h>
+
#include "commands.h"
+
#define MAXLEN (5*1024)
extern int pid;
Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/commands.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -10,9 +10,8 @@
#include <err.h>
-void checkChild(void);
-void initializeCommand(void);
-void destroy(void);
+static void initializeCommand(void);
+static void destroy(void);
/* Basic functions */
@@ -61,7 +60,7 @@
uLong zcapcmd_compressBound(uLong sourceLen);
/* gzip file functions */
-gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode);
+gzFile zcapcmd_gzopen(int fd, const char *mode);
int zcapcmd_gzbuffer(gzFile file, unsigned size);
int zcapcmd_gzsetparams(gzFile file, int level, int strategy);
int zcapcmd_gzread(gzFile file, voidp buf, unsigned len);
@@ -74,7 +73,7 @@
int zcapcmd_gzflush(gzFile file, int flush);
z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence);
int zcapcmd_simplecommand(gzFile file, int command);
-char * zcapcmd_gzerror(gzFile file, int *errnum);
+const char * zcapcmd_gzerror(gzFile file, int *errnum);
/* Checksum functions */
uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len);
@@ -88,26 +87,21 @@
extern void *data;
nvlist_t *nvl, *args, *result;
-size_t gzfilesize = sizeof(struct gzFile_s);
+size_t gzfilesize = sizeof(gzFile);
size_t gzheadersize = sizeof(struct gz_header_s);
size_t zstreamsize = sizeof(z_stream);
-void
-checkChild(void) {
+static void
+initializeCommand() {
if (pid == 0)
startChild();
-}
-
-void
-initializeCommand() {
- checkChild();
if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL )
err(1, "zcaplib: nvlist_create");
}
-void
+static void
destroy(void) {
nvlist_destroy(args);
nvlist_destroy(nvl);
@@ -119,6 +113,7 @@
int memLevel, int strategy, const char * version, int stream_size)
{
uLong ret;
+ const z_stream *newstrm;
initializeCommand();
@@ -135,18 +130,19 @@
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
-
- ret = nvlist_take_number(result, "result");
- /* We take the "good" struct from the worker.
- Here we have the good internal_state.
- When we work on the data now, we have to pass it in
- buffers, and sync: next_in, avail_in, total_in, next_out,
- avail_out, total_out. */
- /* Supposing there's already space reserved for z_stream */
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
- memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
- memcpy(strm->msg, msg, strlen(msg)+1);
+ ret = dnvlist_get_number(result, "result", NULL);
+ /*
+ * We get the "good" struct from the worker.
+ * Here we have the good internal_state.
+ * When we work on the data now, we have to pass
+ * it in buffers, and sync next_in, avail_in, total_in,
+ * next_out, avail_out and total_out.
+ */
+ newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
+ memcpy(strm, newstrm, zstreamsize);
+ const char *msg = dnvlist_get_string(result, "msg", NULL);
+ if (msg != NULL)
+ memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
}
@@ -155,7 +151,8 @@
zcapcmd_deflate(z_streamp strm, int flush)
{
uLong ret;
-
+ const z_stream *newstrm;
+
initializeCommand();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -164,8 +161,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
/* Supposing there's already space reserved for z_stream */
memcpy(strm, newstrm, zstreamsize);
destroy();
@@ -177,7 +174,8 @@
zcapcmd_deflateEnd(z_streamp strm)
{
uLong ret;
-
+ const z_stream *newstrm;
+
initializeCommand();
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEEND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
@@ -185,9 +183,12 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
- memcpy(strm, newstrm, zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
+ if (newstrm != NULL)
+ memcpy(strm, newstrm, zstreamsize);
+ else
+ err(1, "libzcap: deflateEnd() destroyed z_stream\n");
destroy();
return(ret);
}
@@ -197,11 +198,12 @@
const char *version, int stream_size)
{
uLong ret;
-
+ const z_stream *newstrm;
+ const char *msg;
+
initializeCommand();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEINIT);
- /* No worries here */
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_number(args, "windowBits", windowBits);
nvlist_add_string(args, "version", version);
@@ -210,11 +212,13 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
- memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
- memcpy(strm->msg, msg, strlen(msg)+1);
+ ret = dnvlist_get_number(result, "result", NULL);
+ newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
+ if (newstrm != NULL)
+ memcpy(strm, newstrm, zstreamsize);
+ msg = dnvlist_get_string(result, "msg", NULL);
+ if (msg != NULL)
+ memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
}
@@ -226,14 +230,14 @@
initializeCommand();
- nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATE);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
/* Supposing there's already space reserved for z_stream */
memcpy(strm, newstrm, zstreamsize);
destroy();
@@ -244,18 +248,20 @@
zcapcmd_inflateEnd(z_streamp strm)
{
uLong ret;
-
+ const z_stream *newstrm;
+
initializeCommand();
- nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEEND);
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
- memcpy(strm, newstrm, zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
+ if (newstrm != NULL)
+ memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
}
@@ -277,8 +283,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -299,8 +305,8 @@
/* The two z_streamp are now copied at the worker. */
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(dest, newstrm, zstreamsize);
destroy();
return(ret);
@@ -319,11 +325,11 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
/* Save the reseted strm. */
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
+ const char *msg = dnvlist_get_string(result, "msg", NULL);
memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
@@ -344,9 +350,9 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
/* Overwrite the old streamp */
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -370,8 +376,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -391,8 +397,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -414,8 +420,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -436,8 +442,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -461,8 +467,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -482,8 +488,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -503,8 +509,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -523,8 +529,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -545,8 +551,8 @@
/* The two z_streamp are now copied at the worker. */
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(dest, newstrm, zstreamsize);
destroy();
return(ret);
@@ -565,10 +571,10 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
+ const char *msg = dnvlist_get_string(result, "msg", NULL);
memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
@@ -588,10 +594,10 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
+ const char *msg = dnvlist_get_string(result, "msg", NULL);
memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
@@ -612,8 +618,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -632,8 +638,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -654,10 +660,10 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
- gz_headerp newhead = nvlist_take_binary(result, "newhead", gzheadersize);
+ gz_headerp newhead = (gz_headerp)dnvlist_get_binary(result, "newhead", gzheadersize, NULL, sizeof(NULL));
head->done = newhead->done;
destroy();
return(ret);
@@ -673,17 +679,16 @@
initializeCommand();
nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKINIT);
- /* No worries here */
nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
nvlist_add_number(args, "windowBits", windowBits);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
- char *msg = nvlist_take_string(result, "msg");
+ const char *msg = dnvlist_get_string(result, "msg", NULL);
memcpy(strm->msg, msg, strlen(msg)+1);
destroy();
return(ret);
@@ -703,8 +708,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -723,8 +728,8 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
- z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+ ret = dnvlist_get_number(result, "result", NULL);
+ const z_stream *newstrm = dnvlist_get_binary(result, "newstrm", &zstreamsize, NULL, sizeof(NULL));
memcpy(strm, newstrm, zstreamsize);
destroy();
return(ret);
@@ -742,7 +747,7 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -760,32 +765,32 @@
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
/* gzip file functions */
gzFile
-zcapcmd_gzopen(const char *path, int fd, const char *mode)
+zcapcmd_gzopen(int fd, const char *mode)
{
-
+ gzFile *fileptr;
+ gzFile file;
initializeCommand();
nvlist_add_number(nvl, "command", ZCAPCMD_GZOPEN);
- nvlist_add_string(args, "path", path);
nvlist_move_descriptor(args, "fd", fd);
nvlist_add_string(args, "mode", mode);
nvlist_add_nvlist(nvl, "args", args);
-
+
result = sendCommand(nvl);
- void *mem = malloc(gzfilesize);
- memcpy(mem,
- nvlist_take_binary(result, "result", &gzfilesize),
- gzfilesize);
+ fileptr = (gzFile *)dnvlist_get_binary(result, "result", &gzfilesize, NULL, sizeof(NULL));
+ file = *fileptr;
destroy();
- return((gzFile)mem);
+ fprintf(stderr, "zcaplib: after zcapcmd_gzopen: fileptr: %p *fileprt: %p\n", fileptr, *fileptr);
+ fprintf(stderr, "zcaplib: after zcapcmd_gzopen: file: %p\n", file);
+ return((gzFile)file);
}
int
@@ -801,7 +806,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -820,7 +825,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -828,7 +833,7 @@
int
zcapcmd_gzread(gzFile file, voidp buf, unsigned len)
{
- void * data;
+ const void * data;
initializeCommand();
@@ -839,8 +844,8 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
- data = nvlist_take_binary(result, "data", len);
+ int ret = dnvlist_get_number(result, "result", NULL);
+ data = dnvlist_get_binary(result, "data", len, NULL, sizeof(NULL));
memcpy(buf, data, (size_t)len);
destroy();
return(ret);
@@ -859,7 +864,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -876,7 +881,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -894,7 +899,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -912,7 +917,7 @@
result = sendCommand(nvl);
- char *ret = nvlist_take_string(result, "result");
+ const char *ret = dnvlist_get_string(result, "result", NULL);
if (ret == NULL)
return NULL;
else
@@ -934,7 +939,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -952,7 +957,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -970,7 +975,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -989,7 +994,7 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return ((z_off_t)ret);
}
@@ -1011,12 +1016,12 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ int ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
-char *
+const char *
zcapcmd_gzerror(gzFile file, int *errnum)
{
@@ -1029,8 +1034,8 @@
result = sendCommand(nvl);
/* XXX: Should I malloc space for this? */
- char * ret = nvlist_take_string(result, "result");
- *errnum = nvlist_take_number(result, "zerrno");
+ const char * ret = dnvlist_get_string(result, "result", NULL);
+ *errnum = dnvlist_get_number(result, "zerrno", NULL);
destroy();
return(ret);
}
@@ -1051,7 +1056,7 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -1071,7 +1076,7 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -1081,12 +1086,8 @@
{
uLong ret;
- checkChild();
- if( (args = nvlist_create(0)) == NULL ||
- (nvl = nvlist_create(0)) == NULL ) {
- perror("zcaplib: nvlist_create");
- return(0);
- }
+ initializeCommand();
+
nvlist_add_number(nvl, "command", ZCAPCMD_CRC32);
nvlist_add_number(args, "crc", crc);
nvlist_add_binary(args, "buf", buf, len);
@@ -1095,7 +1096,7 @@
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
@@ -1114,7 +1115,7 @@
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ ret = dnvlist_get_number(result, "result", NULL);
destroy();
return(ret);
}
\ No newline at end of file
Modified: soc2013/dpl/head/lib/libzcap/commands.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.h Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/commands.h Tue Sep 3 18:41:30 2013 (r256878)
@@ -13,6 +13,7 @@
*/
+#define SOCKETFILENO 3
#define ZCAPCMD_DEFLATEINIT 0
#define ZCAPCMD_DEFLATE 1
Modified: soc2013/dpl/head/lib/libzcap/deflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/deflate.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/deflate.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -174,9 +174,6 @@
int ZEXPORT deflateEnd (strm)
z_streamp strm;
{
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
return zcapcmd_deflateEnd(strm);
}
Modified: soc2013/dpl/head/lib/libzcap/gzlib.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzlib.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/gzlib.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -27,52 +27,55 @@
{
int oflag = 0;
int fd;
+ char *loopmode;
- while(*mode) {
+ strncpy(loopmode, mode, strlen(mode)+1);
+ while(*loopmode) {
switch (*mode){
#ifndef NO_GZCOMPRESS
- case('w'):
- oflag |= O_WRONLY|O_CREAT|O_TRUNC;
- break;
- case('a'):
- oflag |= O_WRONLY|O_CREAT|O_APPEND;
- break;
-#endif
- case('r'):
- oflag |= O_RDONLY;
- break;
+ case('w'):
+ oflag |= O_WRONLY|O_CREAT|O_TRUNC;
+ break;
+ case('a'):
+ oflag |= O_WRONLY|O_CREAT|O_APPEND;
+ break;
+#endif
+ case('r'):
+ oflag |= O_RDONLY;
+ break;
#ifdef O_CLOEXEC
- case('e'):
- oflag |= O_CLOEXEC;
- break;
+ case('e'):
+ oflag |= O_CLOEXEC;
+ break;
#endif
#ifdef O_EXCL
- case('x'):
- oflag |= O_EXCL;
- break;
-#endif
- case('+'):
- /* Not accepted by gzopen */
- oflag |= O_RDONLY;
- break;
- default:
- ;
+ case('x'):
+ oflag |= O_EXCL;
+ break;
+#endif
+ case('+'):
+ /* Not accepted by gzopen */
+ oflag |= O_RDONLY;
+ break;
+ default:
+ ;
}
- ++mode;
+ ++loopmode;
}
-#ifdef O_LARGEFILE
- oflag |= O_LARGEFILE;
-#endif
-#ifdef O_BINARY
- oflag |= O_BINARY;
-#endif
if ((fd = open(path, oflag)) < 0) {
- perror("zcaplib: Couldn't open");
+ perror("zcaplib: Couldn't create gzip file");
+ abort();
+ }
+
+ if (cap_rights_limit(fd, CAP_READ|CAP_SEEK|CAP_WRITE|CAP_FSTAT|CAP_FCNTL) < 0) {
+ perror("zcaplib: Couldn't limit fd");
+ abort();
+ }
+ if (cap_fcntls_limit(fd, CAP_FCNTL_GETFL) < 0) {
+ perror("zcaplib: Couldn't limit fd");
abort();
}
-
- cap_rights_limit(fd, CAP_READ|CAP_SEEK|CAP_WRITE|CAP_FSTAT);
return gzdopen(fd, mode);
}
@@ -94,16 +97,6 @@
}
/* -- see zlib.h -- */
-#ifdef _WIN32
-gzFile ZEXPORT gzopen_w(path, mode)
- const wchar_t *path;
- const char *mode;
-{
- return gz_open(path, -2, mode);
-}
-#endif
-
-/* -- see zlib.h -- */
extern gzFile zcapcmd_gzbuffer();
int ZEXPORT gzbuffer(file, size)
gzFile file;
Modified: soc2013/dpl/head/lib/libzcap/inflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/inflate.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/inflate.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -37,9 +37,6 @@
int ZEXPORT inflateEnd(strm)
z_streamp strm;
{
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
return zcapcmd_inflateEnd(strm);
}
Added: soc2013/dpl/head/lib/libzcap/test/testlib.sh
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/dpl/head/lib/libzcap/test/testlib.sh Tue Sep 3 18:41:30 2013 (r256878)
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+cd /usr/home/athos/gsoc/head/lib/libzcap/
+sudo make clean all install
+cd /usr/home/athos/gsoc/head/lib/libzcap/test
+cc -o zcaplibtest -g -Wall -fno-color-diagnostics -lnv -lzcap zcaplibtest.c
+echo; echo
+echo 'Done compiling library and tester.'
+echo
+
+if [ $1 = "-k" ]
+then
+ ktrace -i ./zcaplibtest
+else
+ ./zcaplibtest
+fi
Modified: soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Tue Sep 3 17:33:29 2013 (r256877)
+++ soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Tue Sep 3 18:41:30 2013 (r256878)
@@ -1,61 +1,64 @@
-#include <zlib.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
+#include <zlib.h>
/* Basic functions */
-void testzlibVersion(void);
-void testdeflateInit(z_streamp strm);
-void testdeflate(z_streamp strm);
-void testdeflateEnd(z_streamp strm);
-void testinflateInit(z_streamp strm);
-void testinflate(z_streamp strm);
-void testinflateEnd(z_streamp strm);
+static void testzlibVersion(void);
+static void testdeflateInit(z_streamp strm);
+static void testdeflate(z_streamp strm);
+static void testdeflateEnd(z_streamp strm);
+static void testinflateInit(z_streamp strm);
+static void testinflate(z_streamp strm);
+static void testinflateEnd(z_streamp strm);
/* gzip functions */
/* Test non-IO and saves a compressed file */
-gzFile testgzbasic(void);
+static gzFile testgzbasic(void);
/* returns a gzFile of the written file */
-gzFile testgzio(gzFile file);
+static gzFile testgzio(gzFile file);
/* Test error related functions */
-void testgzerr(gzFile file);
+static void testgzerr(gzFile file);
/* Advanced functions */
-void testzlibCompileFlags(void);
+static void testzlibCompileFlags(void);
/* Utility functions */
-void testCompressBound(void);
+static void testCompressBound(void);
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-soc-all
mailing list