aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-06 00:19:03 -0800
committerDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-06 00:19:03 -0800
commit46dceafbffc63599faf6a0c8cc9966083bee44ff (patch)
tree31e5c26b0b75a60e5d53e221e4696fe600a31bac
parent1bd7e4d1e1d13b4136838b88446454b34325505f (diff)
downloadsecurecoreutils-46dceafbffc63599faf6a0c8cc9966083bee44ff.tar.gz
securecoreutils-46dceafbffc63599faf6a0c8cc9966083bee44ff.tar.bz2
securecoreutils-46dceafbffc63599faf6a0c8cc9966083bee44ff.tar.xz
securecoreutils-46dceafbffc63599faf6a0c8cc9966083bee44ff.zip
Adding 'zcat' widget
-rw-r--r--Makefile.am5
-rw-r--r--acinclude.m439
-rw-r--r--configure.ac36
-rw-r--r--securecoreutilities.xcodeproj/project.pbxproj38
-rw-r--r--src/securecoreutils.c7
-rw-r--r--src/widget-zcat.c337
-rw-r--r--src/widget-zcat.h70
7 files changed, 527 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index cb9aa5c..5b49f13 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -105,7 +105,9 @@ src_securecoreutils_SOURCES = $(include_HEADERS) \
105 src/widget-rmdir.c \ 105 src/widget-rmdir.c \
106 src/widget-rmdir.h \ 106 src/widget-rmdir.h \
107 src/widget-tail.c \ 107 src/widget-tail.c \
108 src/widget-tail.h 108 src/widget-tail.h \
109 src/widget-zcat.c \
110 src/widget-zcat.h
109 111
110 112
111# Makefile includes 113# Makefile includes
@@ -127,6 +129,7 @@ install-exec-local:
127 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils secrm; ) 129 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils secrm; )
128 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils secrmdir; ) 130 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils secrmdir; )
129 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils sectail; ) 131 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils sectail; )
132 ( cd $(DESTDIR)$(bindir); ln -sf securecoreutils seczcat; )
130 133
131 134
132install-data-local: 135install-data-local:
diff --git a/acinclude.m4 b/acinclude.m4
index b87030d..2a27829 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -34,4 +34,43 @@
34# acinclude.m4 - custom m4 macros used by configure.ac 34# acinclude.m4 - custom m4 macros used by configure.ac
35# 35#
36 36
37# AC_OPENVPN_LDAPCMD_COMPONENTS
38# ______________________________________________________________________________
39AC_DEFUN([AC_SCU_ZCAT_DEPS],[dnl
40
41 # check zlib
42 USE_ZLIB=yes;
43 AC_CHECK_HEADERS([zlib.h], [], [USE_ZLIB=no])
44 AC_SEARCH_LIBS([gzclose], [z], [], [USE_ZLIB=no])
45 AC_SEARCH_LIBS([gzerror], [z], [], [USE_ZLIB=no])
46 AC_SEARCH_LIBS([gzopen], [z], [], [USE_ZLIB=no])
47 AC_SEARCH_LIBS([gzread], [z], [], [USE_ZLIB=no])
48 if test "x${USE_ZLIB}" = "xyes";then
49 AC_DEFINE_UNQUOTED(USE_ZLIB, 1, [Use zlib])
50 fi
51
52 # check bzip2
53 USE_BZIP2=yes;
54 AC_CHECK_HEADERS([bzlib.h], [], [USE_BZIP2=no])
55 AC_SEARCH_LIBS([BZ2_bzRead], [bz2], [], [USE_BZIP2=no])
56 AC_SEARCH_LIBS([BZ2_bzReadClose], [bz2], [], [USE_BZIP2=no])
57 AC_SEARCH_LIBS([BZ2_bzReadGetUnused], [bz2], [], [USE_BZIP2=no])
58 AC_SEARCH_LIBS([BZ2_bzReadOpen], [bz2], [], [USE_BZIP2=no])
59 if test "x${USE_BZIP2}" = "xyes";then
60 AC_DEFINE_UNQUOTED(USE_BZIP2, 1, [Use bzip2])
61 fi
62
63 AC_CHECK_PROG([USE_XZ], [xz], [yes], [no])
64 if test "x${USE_XZ}" = "xyes";then
65 AC_DEFINE_UNQUOTED(USE_XZ, 1, [Use xz])
66 fi
67
68 AC_CHECK_PROG([USE_Z], [uncompress], [yes], [no])
69 if test "x${USE_Z}" = "xyes";then
70 AC_DEFINE_UNQUOTED(USE_Z, 1, [Use uncompress])
71 fi
72
73])dnl
74
75
37# end of m4 file 76# end of m4 file
diff --git a/configure.ac b/configure.ac
index b8f64bb..6429221 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,6 +102,38 @@ AM_PROG_LEX
102AC_PROG_LN_S 102AC_PROG_LN_S
103 103
104 104
105# check for common functions
106AC_FUNC_FORK
107AC_FUNC_MALLOC
108AC_FUNC_REALLOC
109AC_FUNC_STRERROR_R
110
111# Type checks
112AC_TYPE_INT8_T
113AC_TYPE_INT16_T
114AC_TYPE_INT32_T
115AC_TYPE_INT64_T
116AC_TYPE_OFF_T
117AC_TYPE_SIZE_T
118AC_TYPE_SSIZE_T
119AC_TYPE_UID_T
120AC_TYPE_UINT8_T
121AC_TYPE_UINT16_T
122AC_TYPE_UINT32_T
123AC_TYPE_UINT64_T
124
125# check for required functions
126AC_CHECK_FUNCS([bzero], [], [AC_MSG_ERROR([missing required functions])])
127AC_CHECK_FUNCS([memset], [], [AC_MSG_ERROR([missing required functions])])
128AC_CHECK_FUNCS([rmdir], [], [AC_MSG_ERROR([missing required functions])])
129AC_CHECK_FUNCS([strcasecmp], [], [AC_MSG_ERROR([missing required functions])])
130AC_CHECK_FUNCS([strdup], [], [AC_MSG_ERROR([missing required functions])])
131AC_CHECK_FUNCS([strerror], [], [AC_MSG_ERROR([missing required functions])])
132
133# check for headers
134AC_CHECK_HEADERS([fcntl.h], [], [AC_MSG_ERROR([missing required headers])])
135AC_CHECK_HEADERS([limits.h], [], [AC_MSG_ERROR([missing required headers])])
136
105# GNU Libtool Support 137# GNU Libtool Support
106LT_INIT(dlopen disable-fast-install win32-dll) 138LT_INIT(dlopen disable-fast-install win32-dll)
107 139
@@ -116,6 +148,7 @@ AC_BINDLE_GIT_PACKAGE_VERSION([contrib/bindletools/build-aux/git-package-version
116 148
117# custom configure options 149# custom configure options
118AC_BINDLE_ENABLE_WARNINGS 150AC_BINDLE_ENABLE_WARNINGS
151AC_SCU_ZCAT_DEPS
119 152
120 153
121# enables getopt_long if header and functions were found 154# enables getopt_long if header and functions were found
@@ -132,6 +165,9 @@ AC_MSG_NOTICE([ ])
132AC_MSG_NOTICE([ Secure Core Utilities $GIT_PACKAGE_VERSION ($GIT_PACKAGE_BUILD)]) 165AC_MSG_NOTICE([ Secure Core Utilities $GIT_PACKAGE_VERSION ($GIT_PACKAGE_BUILD)])
133AC_MSG_NOTICE([ ]) 166AC_MSG_NOTICE([ ])
134AC_MSG_NOTICE([ Features:]) 167AC_MSG_NOTICE([ Features:])
168AC_MSG_NOTICE([ zlib support: $USE_ZLIB])
169AC_MSG_NOTICE([ bzip2 support: $USE_BZIP2])
170AC_MSG_NOTICE([ xz support: $USE_XZ])
135AC_MSG_NOTICE([ ]) 171AC_MSG_NOTICE([ ])
136AC_MSG_NOTICE([ Please send suggestions to: $PACKAGE_BUGREPORT]) 172AC_MSG_NOTICE([ Please send suggestions to: $PACKAGE_BUGREPORT])
137AC_MSG_NOTICE([ ]) 173AC_MSG_NOTICE([ ])
diff --git a/securecoreutilities.xcodeproj/project.pbxproj b/securecoreutilities.xcodeproj/project.pbxproj
index 3ea0cf7..7d78de9 100644
--- a/securecoreutilities.xcodeproj/project.pbxproj
+++ b/securecoreutilities.xcodeproj/project.pbxproj
@@ -24,6 +24,9 @@
24 A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */ = {isa = PBXBuildFile; fileRef = A005C1811EC8BDAF00A08403 /* widget-tail.c */; }; 24 A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */ = {isa = PBXBuildFile; fileRef = A005C1811EC8BDAF00A08403 /* widget-tail.c */; };
25 A0446A211F0DABB4000085C7 /* widget-rm.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A1F1F0DA0F3000085C7 /* widget-rm.c */; }; 25 A0446A211F0DABB4000085C7 /* widget-rm.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A1F1F0DA0F3000085C7 /* widget-rm.c */; };
26 A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A221F0DC7D2000085C7 /* widget-rmdir.c */; }; 26 A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A221F0DC7D2000085C7 /* widget-rmdir.c */; };
27 A0446A271F0DDF83000085C7 /* widget-zcat.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A251F0DDF78000085C7 /* widget-zcat.c */; };
28 A0446A2F1F0DFAEB000085C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A2E1F0DFAEB000085C7 /* libz.tbd */; };
29 A0446A311F0E1EAA000085C7 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A301F0E1EAA000085C7 /* libbz2.tbd */; };
27 A054C3DD1B0292930036591C /* securecoreutils.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D71B0292930036591C /* securecoreutils.c */; }; 30 A054C3DD1B0292930036591C /* securecoreutils.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D71B0292930036591C /* securecoreutils.c */; };
28 A054C3DE1B0292930036591C /* widget-cat.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D91B0292930036591C /* widget-cat.c */; }; 31 A054C3DE1B0292930036591C /* widget-cat.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D91B0292930036591C /* widget-cat.c */; };
29 A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3DB1B0292930036591C /* widget-pathcheck.c */; }; 32 A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3DB1B0292930036591C /* widget-pathcheck.c */; };
@@ -58,6 +61,12 @@
58 A0446A201F0DA0F3000085C7 /* widget-rm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "widget-rm.h"; sourceTree = "<group>"; }; 61 A0446A201F0DA0F3000085C7 /* widget-rm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "widget-rm.h"; sourceTree = "<group>"; };
59 A0446A221F0DC7D2000085C7 /* widget-rmdir.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "widget-rmdir.c"; sourceTree = "<group>"; }; 62 A0446A221F0DC7D2000085C7 /* widget-rmdir.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "widget-rmdir.c"; sourceTree = "<group>"; };
60 A0446A231F0DC7D2000085C7 /* widget-rmdir.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "widget-rmdir.h"; sourceTree = "<group>"; }; 63 A0446A231F0DC7D2000085C7 /* widget-rmdir.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "widget-rmdir.h"; sourceTree = "<group>"; };
64 A0446A251F0DDF78000085C7 /* widget-zcat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "widget-zcat.c"; sourceTree = "<group>"; };
65 A0446A261F0DDF78000085C7 /* widget-zcat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "widget-zcat.h"; sourceTree = "<group>"; };
66 A0446A2A1F0DF1D5000085C7 /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
67 A0446A2B1F0DF1D5000085C7 /* TODO */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TODO; sourceTree = "<group>"; };
68 A0446A2E1F0DFAEB000085C7 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
69 A0446A301F0E1EAA000085C7 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
61 A054C3A51B0292600036591C /* securecoreutilities */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = securecoreutilities; sourceTree = BUILT_PRODUCTS_DIR; }; 70 A054C3A51B0292600036591C /* securecoreutilities */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = securecoreutilities; sourceTree = BUILT_PRODUCTS_DIR; };
62 A054C3AD1B0292930036591C /* acinclude.m4 */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = acinclude.m4; sourceTree = "<group>"; }; 71 A054C3AD1B0292930036591C /* acinclude.m4 */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = acinclude.m4; sourceTree = "<group>"; };
63 A054C3AE1B0292930036591C /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; }; 72 A054C3AE1B0292930036591C /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; };
@@ -84,12 +93,23 @@
84 isa = PBXFrameworksBuildPhase; 93 isa = PBXFrameworksBuildPhase;
85 buildActionMask = 2147483647; 94 buildActionMask = 2147483647;
86 files = ( 95 files = (
96 A0446A311F0E1EAA000085C7 /* libbz2.tbd in Frameworks */,
97 A0446A2F1F0DFAEB000085C7 /* libz.tbd in Frameworks */,
87 ); 98 );
88 runOnlyForDeploymentPostprocessing = 0; 99 runOnlyForDeploymentPostprocessing = 0;
89 }; 100 };
90/* End PBXFrameworksBuildPhase section */ 101/* End PBXFrameworksBuildPhase section */
91 102
92/* Begin PBXGroup section */ 103/* Begin PBXGroup section */
104 A0446A2D1F0DFAEB000085C7 /* Frameworks */ = {
105 isa = PBXGroup;
106 children = (
107 A0446A301F0E1EAA000085C7 /* libbz2.tbd */,
108 A0446A2E1F0DFAEB000085C7 /* libz.tbd */,
109 );
110 name = Frameworks;
111 sourceTree = "<group>";
112 };
93 A054C3951B0291F50036591C = { 113 A054C3951B0291F50036591C = {
94 isa = PBXGroup; 114 isa = PBXGroup;
95 children = ( 115 children = (
@@ -97,15 +117,18 @@
97 A054C3AE1B0292930036591C /* AUTHORS */, 117 A054C3AE1B0292930036591C /* AUTHORS */,
98 A054C3AF1B0292930036591C /* autogen.sh */, 118 A054C3AF1B0292930036591C /* autogen.sh */,
99 A054C3BC1B0292930036591C /* ChangeLog */, 119 A054C3BC1B0292930036591C /* ChangeLog */,
120 A0446A2A1F0DF1D5000085C7 /* configure.ac */,
100 A054C3BD1B0292930036591C /* COPYING */, 121 A054C3BD1B0292930036591C /* COPYING */,
101 A054C3D31B0292930036591C /* Makefile.am */, 122 A054C3D31B0292930036591C /* Makefile.am */,
102 A054C3D41B0292930036591C /* NEWS */, 123 A054C3D41B0292930036591C /* NEWS */,
103 A054C3D51B0292930036591C /* README */, 124 A054C3D51B0292930036591C /* README */,
125 A0446A2B1F0DF1D5000085C7 /* TODO */,
104 A054C3B01B0292930036591C /* build-aux */, 126 A054C3B01B0292930036591C /* build-aux */,
105 A054C3BE1B0292930036591C /* include */, 127 A054C3BE1B0292930036591C /* include */,
106 A054C3C31B0292930036591C /* m4 */, 128 A054C3C31B0292930036591C /* m4 */,
107 A054C3D61B0292930036591C /* src */, 129 A054C3D61B0292930036591C /* src */,
108 A054C3A61B0292600036591C /* Products */, 130 A054C3A61B0292600036591C /* Products */,
131 A0446A2D1F0DFAEB000085C7 /* Frameworks */,
109 ); 132 );
110 sourceTree = "<group>"; 133 sourceTree = "<group>";
111 }; 134 };
@@ -157,6 +180,8 @@
157 A0446A231F0DC7D2000085C7 /* widget-rmdir.h */, 180 A0446A231F0DC7D2000085C7 /* widget-rmdir.h */,
158 A005C1811EC8BDAF00A08403 /* widget-tail.c */, 181 A005C1811EC8BDAF00A08403 /* widget-tail.c */,
159 A005C1821EC8BDAF00A08403 /* widget-tail.h */, 182 A005C1821EC8BDAF00A08403 /* widget-tail.h */,
183 A0446A251F0DDF78000085C7 /* widget-zcat.c */,
184 A0446A261F0DDF78000085C7 /* widget-zcat.h */,
160 ); 185 );
161 path = src; 186 path = src;
162 sourceTree = "<group>"; 187 sourceTree = "<group>";
@@ -241,6 +266,7 @@
241 A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */, 266 A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */,
242 A054C3DE1B0292930036591C /* widget-cat.c in Sources */, 267 A054C3DE1B0292930036591C /* widget-cat.c in Sources */,
243 A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */, 268 A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */,
269 A0446A271F0DDF83000085C7 /* widget-zcat.c in Sources */,
244 A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */, 270 A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */,
245 A054C3DD1B0292930036591C /* securecoreutils.c in Sources */, 271 A054C3DD1B0292930036591C /* securecoreutils.c in Sources */,
246 A0446A211F0DABB4000085C7 /* widget-rm.c in Sources */, 272 A0446A211F0DABB4000085C7 /* widget-rm.c in Sources */,
@@ -273,6 +299,10 @@
273 ENABLE_STRICT_OBJC_MSGSEND = YES; 299 ENABLE_STRICT_OBJC_MSGSEND = YES;
274 ENABLE_TESTABILITY = YES; 300 ENABLE_TESTABILITY = YES;
275 GCC_NO_COMMON_BLOCKS = YES; 301 GCC_NO_COMMON_BLOCKS = YES;
302 GCC_PREPROCESSOR_DEFINITIONS = (
303 "USE_ZLIB=1",
304 "USE_BZIP2=1",
305 );
276 GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
277 GCC_WARN_ABOUT_RETURN_TYPE = YES; 307 GCC_WARN_ABOUT_RETURN_TYPE = YES;
278 GCC_WARN_UNDECLARED_SELECTOR = YES; 308 GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -302,6 +332,10 @@
302 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
303 ENABLE_STRICT_OBJC_MSGSEND = YES; 333 ENABLE_STRICT_OBJC_MSGSEND = YES;
304 GCC_NO_COMMON_BLOCKS = YES; 334 GCC_NO_COMMON_BLOCKS = YES;
335 GCC_PREPROCESSOR_DEFINITIONS = (
336 "USE_ZLIB=1",
337 "USE_BZIP2=1",
338 );
305 GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 339 GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
306 GCC_WARN_ABOUT_RETURN_TYPE = YES; 340 GCC_WARN_ABOUT_RETURN_TYPE = YES;
307 GCC_WARN_UNDECLARED_SELECTOR = YES; 341 GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -354,10 +388,6 @@
354 GCC_DYNAMIC_NO_PIC = NO; 388 GCC_DYNAMIC_NO_PIC = NO;
355 GCC_NO_COMMON_BLOCKS = YES; 389 GCC_NO_COMMON_BLOCKS = YES;
356 GCC_OPTIMIZATION_LEVEL = 0; 390 GCC_OPTIMIZATION_LEVEL = 0;
357 GCC_PREPROCESSOR_DEFINITIONS = (
358 "DEBUG=1",
359 "$(inherited)",
360 );
361 GCC_SYMBOLS_PRIVATE_EXTERN = NO; 391 GCC_SYMBOLS_PRIVATE_EXTERN = NO;
362 GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 392 GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
363 GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 393 GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
diff --git a/src/securecoreutils.c b/src/securecoreutils.c
index 9576027..19504b9 100644
--- a/src/securecoreutils.c
+++ b/src/securecoreutils.c
@@ -57,6 +57,7 @@
57#include "widget-rm.h" 57#include "widget-rm.h"
58#include "widget-rmdir.h" 58#include "widget-rmdir.h"
59#include "widget-tail.h" 59#include "widget-tail.h"
60#include "widget-zcat.h"
60 61
61 62
62////////////////// 63//////////////////
@@ -114,6 +115,12 @@ const scu_widget scu_widget_map[] =
114 "sectail", // widget alias 115 "sectail", // widget alias
115 scu_widget_tail, // widget function 116 scu_widget_tail, // widget function
116 }, 117 },
118 {
119 "zcat", // widget name
120 "Writes contents of file to standard out.", // widget description
121 "seczcat", // widget alias
122 scu_widget_zcat, // widget function
123 },
117 { NULL, NULL, NULL, NULL } 124 { NULL, NULL, NULL, NULL }
118}; 125};
119 126
diff --git a/src/widget-zcat.c b/src/widget-zcat.c
new file mode 100644
index 0000000..6ae394d
--- /dev/null
+++ b/src/widget-zcat.c
@@ -0,0 +1,337 @@
1/*
2 * Secure Core Utilities
3 * Copyright (C) 2015 Bindle Binaries <syzdek@bindlebinaries.com>.
4 *
5 * @BINDLE_BINARIES_BSD_LICENSE_START@
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Bindle Binaries nor the
17 * names of its contributors may be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BINDLE BINARIES BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @BINDLE_BINARIES_BSD_LICENSE_END@
33 */
34#include "widget-zcat.h"
35
36///////////////
37// //
38// Headers //
39// //
40///////////////
41#ifdef __SECURECOREUTILS_PMARK
42#pragma mark - Headers
43#endif
44
45#include <assert.h>
46#include <inttypes.h>
47#include <errno.h>
48#include <stdio.h>
49#include <string.h>
50#include <strings.h>
51#include <sys/types.h>
52#include <sys/uio.h>
53#include <sys/stat.h>
54#include <unistd.h>
55#include <fcntl.h>
56#include <stdlib.h>
57
58#ifdef USE_ZLIB
59#include <zlib.h>
60#endif
61
62#ifdef USE_BZIP2
63#include <bzlib.h>
64#endif
65
66
67/////////////////
68// //
69// Variables //
70// //
71/////////////////
72
73const uint8_t scm_magic_bz2[3] = { 0x42, 0x5a, 0x68 }; // tar.bz2
74const uint8_t scm_magic_gz[2] = { 0x1f, 0x8b }; // tar.gz
75const uint8_t scm_magic_lz4[4] = { 0x04, 0x22, 0x4d, 0x18 }; // tar.lz4
76const uint8_t scm_magic_z_lzw[2] = { 0x1f, 0x9d }; // tar.Z
77const uint8_t scm_magic_z_lzh[2] = { 0x1f, 0xa0 }; // tar.Z
78const uint8_t scm_magic_xz[6] = { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00 }; // tar.xz
79
80
81/////////////////
82// //
83// Functions //
84// //
85/////////////////
86#ifdef __SECURECOREUTILS_PMARK
87#pragma mark - Functions
88#endif
89
90int scu_widget_zcat(scu_config * cnf)
91{
92 int fd;
93 int c;
94 int opt_index;
95 int rc;
96 int type;
97 uint8_t magic[16];
98 ssize_t len;
99
100 // getopt options
101 static char short_opt[] = "+hqVv";
102 static struct option long_opt[] =
103 {
104 {"help", no_argument, NULL, 'h' },
105 {"quiet", no_argument, NULL, 'q' },
106 {"silent", no_argument, NULL, 'q' },
107 {"version", no_argument, NULL, 'V' },
108 {"verbose", no_argument, NULL, 'v' },
109 { NULL, 0, NULL, 0 }
110 };
111
112 assert(cnf != NULL);
113
114 type = 0;
115 bzero(magic, sizeof(magic));
116
117 while((c = getopt_long(cnf->argc, cnf->argv, short_opt, long_opt, &opt_index)) != -1)
118 {
119 switch(c)
120 {
121 case -1: /* no more arguments */
122 case 0: /* long options toggles */
123 break;
124
125 case 'h':
126 scu_widget_zcat_usage();
127 return(0);
128
129 case 's':
130 cnf->quiet = 1;
131 if ((cnf->verbose))
132 {
133 fprintf(stderr, "%s: %s: incompatible options\n", PROGRAM_NAME, cnf->widget->name);
134 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
135 return(1);
136 };
137 break;
138
139 case 'V':
140 printf("%s widget\n", cnf->widget->name);
141 scu_version();
142 return(0);
143
144 case 'v':
145 cnf->verbose++;
146 if ((cnf->quiet))
147 {
148 fprintf(stderr, "%s: %s: incompatible options\n", PROGRAM_NAME, cnf->widget->name);
149 fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget->name);
150 return(1);
151 };
152 break;
153
154 case '?':
155 fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget->name);
156 return(1);
157
158 default:
159 fprintf(stderr, "%s: %s: unrecognized option `--%c'\n", PROGRAM_NAME, cnf->widget->name, c);
160 fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget->name);
161 return(1);
162 };
163 };
164
165 if ((cnf->argc - optind) < 1)
166 {
167 fprintf(stderr, "%s: %s: missing required argument\n", PROGRAM_NAME, cnf->widget->name);
168 fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget->name);
169 return(1);
170 };
171 if ((cnf->argc - optind) > 1)
172 {
173 fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]);
174 fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget->name);
175 return(1);
176 };
177
178 // checks file for restriction validations
179 if ((rc = scu_pathcheck(cnf->argv[optind], 0)) != 0)
180 {
181 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, scu_strerror(rc));
182 return(1);
183 };
184
185 // read magic number
186 if ((fd = open(cnf->argv[optind], O_RDONLY)) == -1)
187 {
188 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, strerror(errno));
189 return(1);
190 };
191 if ((len = read(fd, magic, sizeof(magic))) == -1)
192 {
193 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, strerror(errno));
194 close(fd);
195 return(1);
196 };
197 close(fd);
198
199
200 // processes gzip file
201#ifdef USE_ZLIB
202 if (!( memcmp(magic, scm_magic_gz, sizeof(scm_magic_gz)) ))
203 return(scu_widget_zcat_gz(cnf));
204#endif
205
206#ifdef USE_BZIP2
207 if (!( memcmp(magic, scm_magic_bz2, sizeof(scm_magic_bz2)) ))
208 return(scu_widget_zcat_bz2(cnf));
209#endif
210
211#ifdef USE_XZ
212 if (!( memcmp(magic, scm_magic_xz, sizeof(scm_magic_xz)) ))
213 return(scu_widget_zcat_prog(cnf, "xz -cd"));
214#endif
215
216#ifdef USE_Z
217 if (!( memcmp(magic, scm_magic_z_lzw, sizeof(scm_magic_z_lzw)) ))
218 return(scu_widget_zcat_prog(cnf, "/usr/bin/uncompress -c"));
219 if (!( memcmp(magic, scm_magic_z_lzh, sizeof(scm_magic_z_lzh)) ))
220 return(scu_widget_zcat_prog(cnf, "/usr/bin/uncompress -c"));
221#endif
222
223 fprintf(stderr, "%s: %s: unable to determine compression algorithms\n", PROGRAM_NAME, cnf->widget->name);
224 return(1);
225}
226
227
228#ifdef USE_BZIP2
229int scu_widget_zcat_bz2(scu_config * cnf)
230{
231 int bzerror;
232 char buff[16384];
233 ssize_t len;
234 FILE * fs;
235 BZFILE * bz2;
236
237 if ((fs = fopen(cnf->argv[optind], "r")) == NULL)
238 {
239 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, strerror(errno));
240 return(1);
241 };
242
243 bz2 = BZ2_bzReadOpen(&bzerror, fs, 0, 1, NULL, 0);
244 if (bzerror != BZ_OK)
245 {
246 fprintf(stderr, "%s: %s: error with decompression\n", PROGRAM_NAME, cnf->widget->name);
247 BZ2_bzReadClose(&bzerror, bz2);
248 fclose(fs);
249 return(1);
250 };
251
252 while ((len = BZ2_bzRead(&bzerror, bz2, buff, sizeof(buff))) > 0)
253 {
254 if ((len = write(STDOUT_FILENO, buff, len)) == -1)
255 {
256 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, strerror(errno));
257 BZ2_bzReadClose(&bzerror, bz2);
258 fclose(fs);
259 return(1);
260 };
261 };
262
263 BZ2_bzReadClose(&bzerror, bz2);
264 fclose(fs);
265
266 return(0);
267}
268#endif
269
270
271#ifdef USE_ZLIB
272int scu_widget_zcat_gz(scu_config * cnf)
273{
274 gzFile gz;
275 char buff[4096];
276 int gzlen;
277 ssize_t len;
278
279 errno = 0;
280
281 if ((gz = gzopen(cnf->argv[optind], "rb")) == NULL)
282 {
283 if (errno == 0)
284 {
285 fprintf(stderr, "%s: %s: insufficient memory\n", PROGRAM_NAME, cnf->widget->name);
286 return(1);
287 };
288 };
289
290 while((gzlen = gzread(gz, buff, sizeof(buff))) > 0)
291 {
292 if ((len = write(STDOUT_FILENO, buff, gzlen)) == -1)
293 {
294 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, strerror(errno));
295 gzclose(gz);
296 return(1);
297 };
298 };
299 if (gzlen == -1)
300 {
301 fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, cnf->widget->name, gzerror(gz, NULL));
302 gzclose(gz);
303 return(1);
304 };
305
306 gzclose(gz);
307
308 return(0);
309}
310#endif
311
312
313int scu_widget_zcat_prog(scu_config * cnf, const char * prog)
314{
315 char buff[2048];
316
317 bzero(buff, sizeof(buff));
318 snprintf(buff, sizeof(buff), "%s %s", prog, cnf->argv[optind]);
319
320 return(system(buff));
321}
322
323
324void scu_widget_zcat_usage(void)
325{
326 printf("Usage: %s zcat [OPTIONS] file\n", PROGRAM_NAME);
327 printf(" zcat [OPTIONS] file\n");
328 printf(" seczcat [OPTIONS] file\n");
329 printf("\n");
330 scu_usage_options();
331 printf("\n");
332 scu_usage_restrictions();
333 printf("\n");
334 return;
335}
336
337/* end of source */
diff --git a/src/widget-zcat.h b/src/widget-zcat.h
new file mode 100644
index 0000000..277cca9
--- /dev/null
+++ b/src/widget-zcat.h
@@ -0,0 +1,70 @@
1/*
2 * Secure Core Utilities
3 * Copyright (C) 2015 Bindle Binaries <syzdek@bindlebinaries.com>.
4 *
5 * @BINDLE_BINARIES_BSD_LICENSE_START@
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Bindle Binaries nor the
17 * names of its contributors may be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BINDLE BINARIES BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @BINDLE_BINARIES_BSD_LICENSE_END@
33 */
34/**
35 * @file securecoreutils.c
36 * Secure Core Utils widget wrapper
37 */
38#ifndef __SRC_WIDGET_ZCAT_H
39#define __SRC_WIDGET_ZCAT_H 1
40
41
42///////////////
43// //
44// Headers //
45// //
46///////////////
47#ifdef __SECURECOREUTILS_PMARK
48#pragma mark - Headers
49#endif
50
51#include "securecoreutils.h"
52
53
54//////////////////
55// //
56// Prototypes //
57// //
58//////////////////
59#ifdef __TALLYMARK_PMARK
60#pragma mark -
61#endif
62
63int scu_widget_zcat(scu_config * cnf);
64int scu_widget_zcat_bz2(scu_config * cnf);
65int scu_widget_zcat_gz(scu_config * cnf);
66int scu_widget_zcat_prog(scu_config * cnf, const char * prog);
67
68void scu_widget_zcat_usage(void);
69
70#endif /* end of header */