Date: Mon, 8 Jul 2013 12:06:18 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254411 - in soc2013/dpl/head/contrib: bzip2 xz/src/xz Message-ID: <201307081206.r68C6IXv095157@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Mon Jul 8 12:06:17 2013 New Revision: 254411 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254411 Log: Added code to be able to compress anywhere. (Not working) Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c soc2013/dpl/head/contrib/xz/src/xz/coder.c soc2013/dpl/head/contrib/xz/src/xz/file_io.c soc2013/dpl/head/contrib/xz/src/xz/file_io.h soc2013/dpl/head/contrib/xz/src/xz/private.h Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jul 8 11:29:59 2013 (r254410) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jul 8 12:06:17 2013 (r254411) @@ -91,9 +91,8 @@ # ifdef __FreeBSD__ # include <osreldate.h> # if __FreeBSD_version >= 900041 -# define CAPSICUM 1 +# define CAPSICUM # include <sys/capability.h> -# include <sys/socket.h> # include <sys/wait.h> # include <sys/un.h> # endif @@ -222,13 +221,14 @@ FILE *outputHandleJustInCase; Int32 workFactor; -#if CAPSICUM +#ifdef CAPSICUM #define IN_FILENO fileno(inStr) #define OUT_FILENO fileno(outStr) void limitfd(int); +const Char * getdir(Char* file); FILE *inStr; FILE *outStr; -int cwd; +int cwd; /* Where is the file (fd) */ #endif static void panic ( const Char* ) NORETURN; @@ -663,7 +663,7 @@ if (v > exitValue) exitValue = v; } -#if CAPSICUM +#ifdef CAPSICUM /*---------------------------------------------*/ void limitfd(int fd) @@ -686,6 +686,22 @@ exit(exitValue); } } + + +/*---------------------------------------------*/ +const Char * +getdir(Char *file) +{ + Char * slashPos; + Char * ret; + + slashPos = strrchr(file, (int)'/'); + if ( slashPos == 0 ) + return( "." ); + ret = strndup( file, (slashPos - file + 1) ); + return(ret); + +} #endif /*---------------------------------------------*/ @@ -1168,7 +1184,7 @@ static void compress ( Char *name ) { -#if CAPSICUM +#ifdef CAPSICUM pid_t forkpid; #elif FILE *inStr; @@ -1329,7 +1345,7 @@ break; } -# if CAPSICUM +# ifdef CAPSICUM /* Fork and compress in sandbox. */ if ( (forkpid = fork()) == -1 ){ fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) ); @@ -1362,6 +1378,7 @@ applySavedTimeInfoToOutputFile ( OUT_FILENO ); deleteOutputOnInterrupt = False; if ( !keepInputFiles ) { + printf("unlinkat( %d, %s, 0);\n", cwd, inName); IntNative retVal = unlinkat ( cwd, inName, 0 ); ERROR_IF_NOT_ZERO ( retVal ); } @@ -1371,7 +1388,7 @@ fclose(inStr); fclose(outStr); close(cwd); -# if CAPSICUM +# ifdef CAPSICUM exit(0); } # endif @@ -1381,7 +1398,7 @@ static void uncompress ( Char *name ) { -#if CAPSICUM +#ifdef CAPSICUM pid_t forkpid; #elif FILE *inStr; @@ -1540,7 +1557,7 @@ } -# if CAPSICUM +# ifdef CAPSICUM /* Fork and compress in sandbox. */ if ( (forkpid = fork()) == -1 ){ fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) ); @@ -1603,7 +1620,7 @@ fclose(inStr); fclose(outStr); close(cwd); -# if CAPSICUM +# ifdef CAPSICUM exit(0); } # endif @@ -2061,8 +2078,6 @@ # endif } - cwd = open ( ".", 0 ); - if (opMode == OM_Z) { if (srcMode == SM_I2O) { compress ( NULL ); @@ -2072,6 +2087,9 @@ if (ISFLAG("--")) { decode = False; continue; } if (aa->name[0] == '-' && decode) continue; numFilesProcessed++; +# ifdef CAPSICUM + cwd = open ( getdir(aa->name) , O_DIRECTORY ); +# endif compress ( aa->name ); } } @@ -2088,6 +2106,9 @@ if (ISFLAG("--")) { decode = False; continue; } if (aa->name[0] == '-' && decode) continue; numFilesProcessed++; +# ifdef CAPSICUM + cwd = open ( getdir(aa->name) , 0 ); +# endif uncompress ( aa->name ); } } Modified: soc2013/dpl/head/contrib/xz/src/xz/coder.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/coder.c Mon Jul 8 11:29:59 2013 (r254410) +++ soc2013/dpl/head/contrib/xz/src/xz/coder.c Mon Jul 8 12:06:17 2013 (r254411) @@ -641,6 +641,9 @@ // Don't open the destination file when --test // is used. if (opt_mode == MODE_TEST || !io_open_dest(pair)) { +# ifdef CAPSICUM + limitfd(pair); +# endif // Initialize the progress indicator. const uint64_t in_size = pair->src_st.st_size <= 0 Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.c Mon Jul 8 11:29:59 2013 (r254410) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.c Mon Jul 8 12:06:17 2013 (r254411) @@ -955,3 +955,15 @@ return io_write_buf(pair, buf->u8, size); } + +#if CAPSICUM +extern void +limitfd(struct file_pair *pair) +{ + cap_rights_t rights = 0; + + + + return; +} +#endif \ No newline at end of file Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.h ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.h Mon Jul 8 11:29:59 2013 (r254410) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.h Mon Jul 8 12:06:17 2013 (r254411) @@ -127,3 +127,11 @@ /// \return On success, zero is returned. On error, -1 is returned /// and error message printed. extern bool io_write(file_pair *pair, const io_buf *buf, size_t size); + + +#ifdef CAPSICUM +/// \brief Limits fd using FreeBSD's Capsicum framework. +/// +/// \param fd File descriptor to limit. +extern void limitfd(struct file_pair* pair); +#endif \ No newline at end of file Modified: soc2013/dpl/head/contrib/xz/src/xz/private.h ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/private.h Mon Jul 8 11:29:59 2013 (r254410) +++ soc2013/dpl/head/contrib/xz/src/xz/private.h Mon Jul 8 12:06:17 2013 (r254411) @@ -27,6 +27,14 @@ #include "tuklib_exit.h" #include "tuklib_mbstr.h" +#ifdef __FreeBSD__ +# include <osreldate.h> +# if __FreeBSD_version >= 900041 +# define CAPSICUM +# include <sys/capability.h> +# endif +#endif + #if defined(_WIN32) && !defined(__CYGWIN__) # define WIN32_LEAN_AND_MEAN # include <windows.h>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307081206.r68C6IXv095157>