socsvn commit: r255419 - soc2013/dpl/head/lib/libzcap
dpl at FreeBSD.org
dpl at FreeBSD.org
Thu Aug 1 14:58:28 UTC 2013
Author: dpl
Date: Thu Aug 1 14:58:27 2013
New Revision: 255419
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255419
Log:
Everything's ready to change most of the functions!
Added:
soc2013/dpl/head/lib/libzcap/commands.h
Modified:
soc2013/dpl/head/lib/libzcap/capsicum.c
soc2013/dpl/head/lib/libzcap/capsicum.h
Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c Thu Aug 1 13:18:47 2013 (r255418)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c Thu Aug 1 14:58:27 2013 (r255419)
@@ -9,10 +9,11 @@
int sv[2];
int startChild(void);
-void waitCommand(void);
void killChild(void);
+nvlist_t * command(int command, int args, ... );
-int startChild()
+int
+startChild()
{
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 )
perror("socketpair");
@@ -22,14 +23,18 @@
close(STDIN_FILENO);
close(STDERR_FILENO);
cap_enter();
- waitCommand();
+ /* Exec listener */
+ exit(0);
} else
atexit(killChild);
return pid;
}
-/* Wait for commands, and execute them */
+/*
+ * Wait for commands, and execute them
+ * This code really pertains to the listener program
+
void
waitCommand()
{
@@ -38,27 +43,23 @@
while(1) {
while(1){
if ((nvl = nvlist_recv(sv[1])) != NULL)
- if (nvlist_exists(nvl, "com"))
+ if (nvlist_exists(nvl, "command"))
if (nvlist_exists(nvl, "args"))
break;
;
}
- /* Switch for "command" */
- /* Get args, and call the real lib */
- switch( nvlist_take_number(nvl, "com")){
- case SUM:
+ // Switch for "command"
+ // Get args, and call the real lib.
+ int com = nvlist_take_number(nvl, "command");
+ if (com == SUM) {
if ((args = nvlist_take_nvlist(nvl, "args")) == NULL) {
perror("CHILD: nvlist_take_nvlist(nvl, 'args')");
break;
}
- nvlist_add_number(nvl, "result", 0 /* sum_(nvlist_take_number(args, "a")) */);
- break;
- default:
- break;
+ nvlist_add_number(nvl, "result", 0 );
}
-
while(1){
if( nvlist_send(sv[1], nvl) == 0 )
break;
@@ -68,6 +69,112 @@
}
}
+*/
+
+nvlist_t *
+command( int command, int args, ... )
+{
+ nvlist_t *nvl, *nvlargs;
+ va_list ap;
+
+ /* If the child is not executing, do it. */
+ /* It _should_ only be tested once.
+ if (pid == 0)
+ startChild();
+
+ if( (nvlargs = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return (NULL);
+ }
+ nvlist_add_number(nvl, "command", command);
+
+ va_start(ap, args);
+ // Set up args, and add it to nvl.
+ if (command == DEFLATEINIT){
+ } else if (command == DEFLATE ) {
+ } else if (command == DEFLATEEND ) {
+ } else if (command == INFLATEINIT ) {
+ } else if (command == INFLATE ) {
+ } else if (command == INFLATEEND ) {
+ } else if (command == DEFLATEINIT2 ) {
+ } else if (command == DEFLATESETDICTIONARY ) {
+ } else if (command == DEFLATECOPY ) {
+ } else if (command == DEFLATERESET ) {
+ } else if (command == DEFLATEPARAMS ) {
+ } else if (command == DEFLATETUNE ) {
+ } else if (command == DEFLATEBOUND ) {
+ } else if (command == DEFLATEPENDING ) {
+ } else if (command == DEFLATEPRIME ) {
+ } else if (command == DEFLATESETHEADER ) {
+ } else if (command == INFLATEINIT2 ) {
+ } else if (command == INFLATESETDICTIONARY ) {
+ } else if (command == INFLATEGETDICTIONARY ) {
+ } else if (command == INFLATESYNC ) {
+ } else if (command == INFLATECOPY ) {
+ } else if (command == INFLATERESET ) {
+ } else if (command == INFLATERESET2 ) {
+ } else if (command == INFLATEPRIME ) {
+ } else if (command == INFLATEMARK ) {
+ } else if (command == INFLATEGETHEADER ) {
+ } else if (command == INFLATEBACKINIT ) {
+ } else if (command == INFLATEBACK ) {
+ } else if (command == INFLATEBACKEND ) {
+ } else if (command == ZLIBCOMPILEFLAGS ) {
+ } else if (command == COMPRESS ) {
+ } else if (command == COMPRESS2 ) {
+ } else if (command == COMPRESSBOUND ) {
+ } else if (command == UNCOMPRESS ) {
+ } else if (command == GZOPEN ) {
+ } else if (command == GZDOPEN ) {
+ } else if (command == GZBUFFER ) {
+ } else if (command == GZSETPARAMS ) {
+ } else if (command == GZREAD ) {
+ } else if (command == GZWRITE ) {
+ } else if (command == GZPRINTF ) {
+ } else if (command == GZPUTS ) {
+ } else if (command == GZGETS ) {
+ } else if (command == GZPUTC ) {
+ } else if (command == GZGETC ) {
+ } else if (command == GZUNGETC ) {
+ } else if (command == GZFLUSH ) {
+ } else if (command == GZSEEK ) {
+ } else if (command == GZREWIND ) {
+ } else if (command == GZTELL ) {
+ } else if (command == GZOFFSET ) {
+ } else if (command == GZEOF ) {
+ } else if (command == GZDIRECT ) {
+ } else if (command == GZCLOSE ) {
+ } else if (command == GZCLOSE_R ) {
+ } else if (command == GZCLOSE_W ) {
+ } else if (command == GZERROR ) {
+ } else if (command == GZCLEARERR ) {
+ } else if (command == ADLER32 ) {
+ } else if (command == ADLER32_COMBINE ) {
+ } else if (command == CRC32 ) {
+ } else if (command == CRC32_COMBINE ) {
+ } else { return NULL; }
+
+ va_end(ap);
+
+ /* send nvlist*/
+ /* What about the whiles? */
+ while(1){
+ if( nvlist_send(sv[0], nvl) == 0 )
+ break;
+ ;
+ }
+
+ /* recv results */
+ while(1){
+ if ((nvl = nvlist_recv(sv[0])) != NULL)
+ if (nvlist_exists(nvl, "result"))
+ break;
+ ;
+ }
+ return (nvl);
+}
+
void killChild(){
kill(pid, SIGKILL);
}
Modified: soc2013/dpl/head/lib/libzcap/capsicum.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.h Thu Aug 1 13:18:47 2013 (r255418)
+++ soc2013/dpl/head/lib/libzcap/capsicum.h Thu Aug 1 14:58:27 2013 (r255419)
@@ -1,17 +1,15 @@
/*
* With Capsicum, we get a compartmentalized, and securer lib.
*/
-#if defined(__FreeBSD__)
-# include <osreldate.h>
-# if __FreeBSD_version >= 900041
-# 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 <nv.h>
-# endif
+#if __FreeBSD_version >= 900041
+# 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 <nv.h>
+# include "commands.h"
#endif
Added: soc2013/dpl/head/lib/libzcap/commands.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/dpl/head/lib/libzcap/commands.h Thu Aug 1 14:58:27 2013 (r255419)
@@ -0,0 +1,155 @@
+/*
+ This is a list of all the capsizumized zlib interfaces.
+ Every one of the capsicumized functions will have a define.
+ 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.
+ Also, the defines have been checked for not being duplicates.
+
+ // basic functions
+ zlibVersion // Not capsicumized
+ deflateInit
+ deflate
+ deflateEnd
+ inflateInit
+ inflate
+ inflateEnd
+
+ // Advanced functions
+ deflateInit2
+ deflateSetDictionary
+ deflateCopy
+ deflateReset
+ deflateParams
+ deflateTune
+ deflateBound
+ deflatePending
+ deflatePrime
+ deflateSetHeader
+ inflateInit2
+ inflateSetDictionary
+ inflateGetDictionary
+ inflateSync
+ inflateCopy
+ inflateReset
+ inflateReset2
+ inflatePrime
+ inflateMark
+ inflateGetHeader
+ inflateBackInit
+ inflateBack
+ inflateBackEnd
+ zlibCompileFlags
+
+ // utility functions
+ compress
+ compress2
+ compressBound
+ uncompress
+
+ // gzip file access functions
+ gzopen
+ gzdopen
+ gzbuffer
+ gzsetparams
+ gzread
+ gzwrite
+ gzprintf
+ gzputs
+ gzgets
+ gzputc
+ gzgetc
+ gzungetc
+ gzflush
+ gzseek
+ gzrewind
+ gztell
+ gzoffset
+ gzeof
+ gzdirect
+ gzclose
+ gzclose_r
+ gzclose_w
+ gzerror
+ gzclearerr
+
+ // checksum functions
+ adler32
+ adler32_combine
+ crc32
+ crc32_combine
+*/
+
+
+/* basic functions */
+#define DEFLATEINIT 0
+#define DEFLATE 1
+#define DEFLATEEND 2
+#define INFLATEINIT 3
+#define INFLATE 4
+#define INFLATEEND 5
+
+/* Advanced functions */
+#define DEFLATEINIT2
+#define DEFLATESETDICTIONARY 6
+#define DEFLATECOPY 7
+#define DEFLATERESET 8
+#define DEFLATEPARAMS 9
+#define DEFLATETUNE 10
+#define DEFLATEBOUND 11
+#define DEFLATEPENDING 12
+#define DEFLATEPRIME 13
+#define DEFLATESETHEADER 14
+#define INFLATEINIT2 15
+#define INFLATESETDICTIONARY 16
+#define INFLATEGETDICTIONARY 17
+#define INFLATESYNC 18
+#define INFLATECOPY 19
+#define INFLATERESET 20
+#define INFLATERESET2 21
+#define INFLATEPRIME 22
+#define INFLATEMARK 23
+#define INFLATEGETHEADER 24
+#define INFLATEBACKINIT 25
+#define INFLATEBACK 26
+#define INFLATEBACKEND 27
+#define ZLIBCOMPILEFLAGS 28
+
+/* utility functions */
+#define COMPRESS 29
+#define COMPRESS2 30
+#define COMPRESSBOUND 31
+#define UNCOMPRESS 32
+
+/* gzip file access functions */
+#define GZOPEN 33
+#define GZDOPEN 34
+#define GZBUFFER 35
+#define GZSETPARAMS 36
+#define GZREAD 37
+#define GZWRITE 38
+#define GZPRINTF 39
+#define GZPUTS 40
+#define GZGETS 50
+#define GZPUTC 51
+#define GZGETC 52
+#define GZUNGETC 53
+#define GZFLUSH 54
+#define GZSEEK 55
+#define GZREWIND 56
+#define GZTELL 57
+#define GZOFFSET 58
+#define GZEOF 59
+#define GZDIRECT 60
+#define GZCLOSE 61
+#define GZCLOSE_R 62
+#define GZCLOSE_W 63
+#define GZERROR 64
+#define GZCLEARERR 65
+
+/* checksum functions */
+#define ADLER32 66
+#define ADLER32_COMBINE 67
+#define CRC32 68
+#define CRC32_COMBINE 69
More information about the svn-soc-all
mailing list