From edec2a4bdd688a3c009aeaadbb2fc49db9464949 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 6 Aug 2019 15:15:16 -0700 Subject: [PATCH] Build & link successfully with a cross compiler targeting VxWorks, though I can't actually test it yet; clean up & extend platform & file type detection a bit --- config.h.in | 77 ++++++++++++++++ configure | 106 ++++++++++++++++++--- configure.ac | 44 +++++++-- src/core/Makefile.am | 2 +- src/core/Makefile.in | 2 +- src/core/crc32.cpp | 2 +- src/core/file_unix.cpp | 11 ++- src/core/fixups.h | 69 ++++++++++++++ src/core/fsservices.h | 5 +- src/core/msystem.cpp | 13 ++- src/core/msystem.h | 10 ++ src/core/platform.h | 109 +++++++++++++++------- src/core/timeconvert.cpp | 12 ++- src/core/twlocale.cpp | 9 +- src/core/unixfsservices.cpp | 147 +++++++++++++++++++----------- src/fco/signature.cpp | 6 ++ src/fs/fsdatasourceiter.cpp | 9 ++ src/fs/fspropcalc.cpp | 13 +++ src/fs/fspropset.cpp | 5 +- src/fs/fspropset.h | 3 + src/fs/fsstrings.cpp | 17 +++- src/fs/fsstrings.h | 5 +- src/siggen/siggenmain.cpp | 8 ++ src/tripwire/pipedmailmessage.cpp | 8 +- src/tripwire/smtpmailmessage.cpp | 31 ++++--- src/tripwire/syslog_trip.cpp | 11 ++- src/tripwire/tripwiremain.cpp | 9 ++ src/twadmin/keygeneration.cpp | 6 +- src/twadmin/twadminmain.cpp | 9 ++ src/twcrypto/crypto.cpp | 6 +- src/twcrypto/crypto.h | 6 +- src/twprint/twprintmain.cpp | 9 ++ src/twtest/crypto_t.cpp | 30 +++--- src/twtest/fspropcalc_t.cpp | 5 + src/twtest/twutil_t.cpp | 7 +- src/util/fileutil.cpp | 6 +- 36 files changed, 650 insertions(+), 177 deletions(-) create mode 100644 src/core/fixups.h diff --git a/config.h.in b/config.h.in index c189842..6d143fa 100644 --- a/config.h.in +++ b/config.h.in @@ -15,6 +15,18 @@ /* Define to 1 if you have the header file. */ #undef HAVE_BITS_SIGNUM_H +/* Define to 1 if you have the `break' function. */ +#undef HAVE_BREAK + +/* Define to 1 if you have the `broken_ac_check_func' function. */ +#undef HAVE_BROKEN_AC_CHECK_FUNC + +/* Define to 1 if you have the `chmod' function. */ +#undef HAVE_CHMOD + +/* Define to 1 if you have the `chown' function. */ +#undef HAVE_CHOWN + /* Uses the Clang compiler */ #undef HAVE_CLANG @@ -24,6 +36,9 @@ /* Define to 1 if you have the `closedir' function. */ #undef HAVE_CLOSEDIR +/* Define to 1 if you have the `closelog' function. */ +#undef HAVE_CLOSELOG + /* Define to 1 if you have the header file. */ #undef HAVE_COMMONCRYPTO_COMMONDIGEST_H @@ -33,6 +48,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DOOR_H +/* Define to 1 if you have the `exec' function. */ +#undef HAVE_EXEC + /* Define to 1 if you have the `fclose' function. */ #undef HAVE_FCLOSE @@ -42,6 +60,9 @@ /* Define to 1 if you have the `fopen' function. */ #undef HAVE_FOPEN +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + /* Define to 1 if you have the `fread' function. */ #undef HAVE_FREAD @@ -54,12 +75,21 @@ /* Uses the GNU gcc compiler */ #undef HAVE_GCC +/* Define to 1 if you have the `gethostbyname' function. */ +#undef HAVE_GETHOSTBYNAME + /* Define to 1 if you have the `gethostid' function. */ #undef HAVE_GETHOSTID /* Define to 1 if you have the `gethostname' function. */ #undef HAVE_GETHOSTNAME +/* Define to 1 if you have the `getuid' function. */ +#undef HAVE_GETUID + +/* Define to 1 if you have the header file. */ +#undef HAVE_GRP_H + /* Uses the aCC compiler */ #undef HAVE_HP_ACC @@ -81,6 +111,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LIMITS +/* Define to 1 if you have the `link' function. */ +#undef HAVE_LINK + /* Define to 1 if you have the header file. */ #undef HAVE_LOCALE @@ -108,6 +141,9 @@ /* Define to 1 if you have the `opendir' function. */ #undef HAVE_OPENDIR +/* Define to 1 if you have the `openlog' function. */ +#undef HAVE_OPENLOG + /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_MD5_H @@ -117,6 +153,9 @@ /* Uses the sunCC compiler */ #undef HAVE_ORACLE_SUNCC +/* Define to 1 if you have the `popen' function. */ +#undef HAVE_POPEN + /* Define to 1 if you have the `port_create' function. */ #undef HAVE_PORT_CREATE @@ -126,6 +165,9 @@ /* Define to 1 if you have the `posix_fadvise' function. */ #undef HAVE_POSIX_FADVISE +/* Define to 1 if you have the header file. */ +#undef HAVE_PWD_H + /* Define to 1 if you have the `read' function. */ #undef HAVE_READ @@ -141,6 +183,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SIGNUM_H +/* Define to 1 if you have the `socket' function. */ +#undef HAVE_SOCKET + /* Define to 1 if you have the `stat' function. */ #undef HAVE_STAT @@ -168,9 +213,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H +/* Define to 1 if `st_attrib' is a member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_ATTRIB + /* Define to 1 if `st_blocks' is a member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_BLOCKS +/* Define to 1 if `st_flag' is a member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_FLAG + /* Define to 1 if `st_flags' is a member of `struct stat'. */ #undef HAVE_STRUCT_STAT_ST_FLAGS @@ -183,9 +234,18 @@ /* Define to 1 if you have the `swab' function. */ #undef HAVE_SWAB +/* Define to 1 if you have the `symlink' function. */ +#undef HAVE_SYMLINK + +/* Define to 1 if you have the `syslog' function. */ +#undef HAVE_SYSLOG + /* Define to 1 if you have the header file. */ #undef HAVE_SYSLOG_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_FILE_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_FS_VX_IOCTL_H @@ -213,6 +273,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SYSMACROS_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H @@ -225,6 +288,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_UTSNAME_H +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define to 1 if you have the `tmpnam' function. */ +#undef HAVE_TMPNAM + +/* Define to 1 if you have the `tzset' function. */ +#undef HAVE_TZSET + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H @@ -243,6 +315,9 @@ /* Define to 1 if you have the file `/dev/urandom'. */ #undef HAVE__DEV_URANDOM +/* Define to 1 if you have the `_exit' function. */ +#undef HAVE__EXIT + /* Is byte aligned */ #undef IS_BYTE_ALIGNED @@ -340,3 +415,5 @@ /* Define to `unsigned int' if does not define. */ #undef size_t + +#include "core/fixups.h" diff --git a/configure b/configure index 7aac708..724272e 100755 --- a/configure +++ b/configure @@ -3284,6 +3284,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu CXXFLAGS=${tmp_cxxflags} + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -5543,7 +5545,7 @@ fi done -for ac_header in unistd.h sys/unistd.h +for ac_header in unistd.h sys/unistd.h pwd.h grp.h termios.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_cxx_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -5556,7 +5558,7 @@ fi done -for ac_header in syslog.h langinfo.h sys/statfs.h sys/select.h +for ac_header in syslog.h langinfo.h sys/statfs.h sys/select.h sys/time.h sys/file.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_cxx_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -6178,6 +6180,24 @@ cat >>confdefs.h <<_ACEOF _ACEOF +fi +ac_fn_cxx_check_member "$LINENO" "struct stat" "st_flag" "ac_cv_member_struct_stat_st_flag" "$ac_includes_default" +if test "x$ac_cv_member_struct_stat_st_flag" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_STAT_ST_FLAG 1 +_ACEOF + + +fi +ac_fn_cxx_check_member "$LINENO" "struct stat" "st_attrib" "ac_cv_member_struct_stat_st_attrib" "$ac_includes_default" +if test "x$ac_cv_member_struct_stat_st_attrib" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_STAT_ST_ATTRIB 1 +_ACEOF + + fi @@ -6382,7 +6402,30 @@ rm -rf conftest* fi -for ac_func in strftime gethostname gethostid +for ac_func in broken_ac_check_func +do : + ac_fn_cxx_check_func "$LINENO" "broken_ac_check_func" "ac_cv_func_broken_ac_check_func" +if test "x$ac_cv_func_broken_ac_check_func" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_BROKEN_AC_CHECK_FUNC 1 +_ACEOF + +fi +done + + +for ac_func in strftime +do : + ac_fn_cxx_check_func "$LINENO" "strftime" "ac_cv_func_strftime" +if test "x$ac_cv_func_strftime" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRFTIME 1 +_ACEOF + +fi +done + +for ac_func in gethostname gethostbyname gethostid getuid do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -6394,7 +6437,7 @@ _ACEOF fi done -for ac_func in mkstemp mktemp +for ac_func in mkstemp mktemp tmpnam break do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -6402,16 +6445,17 @@ if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF - break + fi done -for ac_func in swab +for ac_func in swab tzset _exit popen do : - ac_fn_cxx_check_func "$LINENO" "swab" "ac_cv_func_swab" -if test "x$ac_cv_func_swab" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_SWAB 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi @@ -6479,6 +6523,43 @@ fi done +for ac_func in chown chmod link symlink +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + +for ac_func in openlog syslog closelog +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + +for ac_func in fork exec socket +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + for ac_header in fcntl.h do : ac_fn_cxx_check_header_mongrel "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" @@ -6648,7 +6729,8 @@ case $host_os in aros*) ;; *) - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/random" >&5 + if test "$cross_compiling" != yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/random" >&5 $as_echo_n "checking for /dev/random... " >&6; } if ${ac_cv_file__dev_random+:} false; then : $as_echo_n "(cached) " >&6 @@ -6715,6 +6797,7 @@ _ACEOF fi + fi ;; esac @@ -7386,6 +7469,7 @@ if test "${enable_openssl+set}" = set; then : fi + # Check whether --with-ssl-dir was given. if test "${with_ssl_dir+set}" = set; then : withval=$with_ssl_dir; @@ -7446,7 +7530,7 @@ else # Basic test to check for compatible library and # correct linking - if test "$cross_compiling" = yes; then + if test "x$cross_compiling" = "xyes"; then found_crypto=1 else if test "$cross_compiling" = yes; then : diff --git a/configure.ac b/configure.ac index 15f3e77..9394a69 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,13 @@ tmp_cxxflags=${CXXFLAGS} AC_LANG_CPLUSPLUS CXXFLAGS=${tmp_cxxflags} +dnl ******************************************************* +dnl Append an include to config.h for a handcrafted header +dnl that sets things back to (hopefully) correct values +dnl for known cases where autoconf does the Wrong Thing +dnl ******************************************************* +AH_BOTTOM([#include "core/fixups.h"]) + dnl ################### dnl Checks for programs dnl ################### @@ -178,8 +185,8 @@ AC_CHECK_HEADERS(sys/mount.h,,, #endif ]]) AC_CHECK_HEADERS(sys/ustat.h sys/sysmacros.h sys/syslog.h sys/socket.h) -AC_CHECK_HEADERS(unistd.h sys/unistd.h) -AC_CHECK_HEADERS(syslog.h langinfo.h sys/statfs.h sys/select.h) +AC_CHECK_HEADERS(unistd.h sys/unistd.h pwd.h grp.h termios.h) +AC_CHECK_HEADERS(syslog.h langinfo.h sys/statfs.h sys/select.h sys/time.h sys/file.h) AC_CHECK_HEADERS(signum.h bits/signum.h, break ) AC_CHECK_HEADERS(stdarg.h varargs.h, break ) AC_CHECK_HEADERS(sys/utsname.h memory.h) @@ -219,18 +226,27 @@ AC_DEFINE(IS_UNIX, 1, [Is a unix type platform]) dnl whether or not to generate debuging code? dnl this gets defined elsewhere based on config args AC_DEFINE(NDEBUG, 1, [don't generate debuging code]) -dnl look for struct stat members that aren't always there -AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blocks, struct stat.st_flags, struct stat.st_gen]) +dnl look for struct stat members that aren't always there: +dnl st_rdev & st_blocks are standard but a few platforms don't have them. +dnl st_flags & st_gen are BSD-isms & are mostly seen there, including macOS +dnl st_flag (singular) is AIX-only, while st_attrib holds DOS attribute bits on VxWorks +AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blocks, struct stat.st_flags, struct stat.st_gen, struct stat.st_flag, struct stat.st_attrib]) dnl detect large file support & use it where available AC_SYS_LARGEFILE +dnl ****************************************** +dnl Check whether AC_CHECK_FUNC(S) lies to us +dnl ****************************************** +AC_CHECK_FUNCS(broken_ac_check_func) + dnl ############################# dnl Checks for standard functions dnl ############################# -AC_CHECK_FUNCS(strftime gethostname gethostid) -AC_CHECK_FUNCS(mkstemp mktemp, break) -AC_CHECK_FUNCS(swab) +AC_CHECK_FUNCS(strftime) +AC_CHECK_FUNCS(gethostname gethostbyname gethostid getuid) +AC_CHECK_FUNCS(mkstemp mktemp tmpnam break) +AC_CHECK_FUNCS(swab tzset _exit popen) dnl posix way to read files AC_CHECK_FUNCS(openat open read close) @@ -243,6 +259,13 @@ AC_CHECK_FUNCS(statx fstatat lstat stat) dnl posix way to get symlink contents AC_CHECK_FUNCS(readlinkat readlink) +dnl posix fns that make filesystem changes +AC_CHECK_FUNCS(chown chmod link symlink) +dnl posix syslog fns +AC_CHECK_FUNCS(openlog syslog closelog) +dnl assorted other posix fns +AC_CHECK_FUNCS(fork exec socket) + dnl check for posix_fadvise AC_CHECK_HEADERS(fcntl.h, [AC_CHECK_FUNCS(posix_fadvise)]) @@ -281,7 +304,9 @@ case $host_os in aros*) ;; *) - AC_CHECK_FILES(/dev/random /dev/urandom /dev/arandom) + if test "$cross_compiling" != yes; then + AC_CHECK_FILES(/dev/random /dev/urandom /dev/arandom) + fi ;; esac @@ -487,6 +512,7 @@ if you are trying to compile a static binary. dnl Check for OpenSSL, now that we have a working compiler AC_ARG_ENABLE(openssl, [ --disable-openssl Don't link against OpenSSL libraries]) + AC_ARG_WITH(ssl-dir, [ --with-ssl-dir=PATH Specify path to OpenSSL installation ], [ @@ -543,7 +569,7 @@ then # Basic test to check for compatible library and # correct linking - if test "$cross_compiling" = yes; then + if test "x$cross_compiling" = "xyes"; then found_crypto=1 else AC_TRY_RUN( diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2b48224..05c706e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -23,7 +23,7 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ core.h coreerrors.h corestrings.h crc32.h debug.h displayencoder.h \ displayutil.h epoch.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ - fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ + fixups.h fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ diff --git a/src/core/Makefile.in b/src/core/Makefile.in index 13de53b..367af30 100644 --- a/src/core/Makefile.in +++ b/src/core/Makefile.in @@ -347,7 +347,7 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ core.h coreerrors.h corestrings.h crc32.h debug.h displayencoder.h \ displayutil.h epoch.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \ errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \ - fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ + fixups.h fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \ ntmbs.h package.h platform.h refcountobj.h resources.h \ serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \ sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \ diff --git a/src/core/crc32.cpp b/src/core/crc32.cpp index b29b20e..441e408 100644 --- a/src/core/crc32.cpp +++ b/src/core/crc32.cpp @@ -82,7 +82,7 @@ #include "archive.h" #endif -#define BUFSIZE 4096 +#define BUFFER_SIZE 4096 static uint32_t crctab[] = { 0x0, diff --git a/src/core/file_unix.cpp b/src/core/file_unix.cpp index 0a83703..fc0e989 100644 --- a/src/core/file_unix.cpp +++ b/src/core/file_unix.cpp @@ -244,8 +244,13 @@ void cFile::Open(const TSTRING& sFileNameC, uint32_t flags) #if HAVE_POSIX_FADVISE if (flags & OPEN_SCANNING && !(flags & OPEN_DIRECT)) { +#ifdef POSIX_FADV_SEQUENTIAL posix_fadvise(fh, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + +#ifdef POSIX_FADV_NOREUSE posix_fadvise(fh, 0, 0, POSIX_FADV_NOREUSE); +#endif } #elif HAVE_SYS_FS_VX_IOCTL_H @@ -267,7 +272,7 @@ void cFile::Close() //throw(eFile) { if (mpData->mpCurrStream != NULL) { -#ifdef HAVE_POSIX_FADVISE +#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED) posix_fadvise(fileno(mpData->mpCurrStream), 0, 0, POSIX_FADV_DONTNEED); #endif @@ -362,7 +367,11 @@ cFile::File_t cFile::Read(void* buffer, File_t nBytes) const //throw(eFile) if (mpData->mFlags & OPEN_DIRECT) { +#if READ_TAKES_CHAR_PTR + iBytesRead = read(mpData->m_fd, (char*)buffer, nBytes); +#else iBytesRead = read(mpData->m_fd, buffer, nBytes); +#endif if (iBytesRead < 0) { throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString()); diff --git a/src/core/fixups.h b/src/core/fixups.h new file mode 100644 index 0000000..317853c --- /dev/null +++ b/src/core/fixups.h @@ -0,0 +1,69 @@ +// +// The developer of the original code and/or files is Tripwire, Inc. +// Portions created by Tripwire, Inc. are copyright (C) 2000-2019 Tripwire, +// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights +// reserved. +// +// This program is free software. The contents of this file are subject +// to the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2 of the License, or (at your +// option) any later version. You may redistribute it and/or modify it +// only in compliance with the GNU General Public License. +// +// This program is distributed in the hope that it will be useful. +// However, this program is distributed AS-IS WITHOUT ANY +// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS +// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. +// +// Nothing in the GNU General Public License or any other license to use +// the code or files shall permit you to use Tripwire's trademarks, +// service marks, or other intellectual property without Tripwire's +// prior written consent. +// +// If you have any questions, please contact Tripwire, Inc. at either +// info@tripwire.org or www.tripwire.org. + + +// ==================================================================== +// fixups.h : +// This file is included at the end of the generated config.h, for repairing things +// the configure script got wrong. Because this does happen now and then. +// +// This header is intentionally not wrapped with the usual #ifndef/#define/#endif +// since config.h itself doesn't do that, and we need to be inclded right after +// it each time it's included. + + +// ===================================================================== +// Cross compiling to powerpc-wrs-vxworks from linux amd64, observed that +// AC_CHECK_FUNC defines HAVE_xxx for every checked function, including +// ones that don't and can't exist like fork() & symlink(), and others that +// could at least optionally exist, but don't in my cross compiler, like socket(). +// + +#if HAVE_BROKEN_AC_CHECK_FUNC + #if defined(__VXWORKS__) || defined(__vxworks) + #undef HAVE__EXIT + #undef HAVE_CHOWN + #undef HAVE_EXEC + #undef HAVE_FORK + #undef HAVE_GETHOSTID + #undef HAVE_GETUID + #undef HAVE_LSTAT + #undef HAVE_MKSTEMP + #undef HAVE_MKTEMP + #undef HAVE_POPEN + #undef HAVE_SOCKET + #undef HAVE_SYMLINK + #undef HAVE_SYSLOG + #undef HAVE_READLINK + #undef HAVE_TZSET + #endif +#endif + diff --git a/src/core/fsservices.h b/src/core/fsservices.h index c42bbe7..811a046 100644 --- a/src/core/fsservices.h +++ b/src/core/fsservices.h @@ -136,7 +136,10 @@ struct cFSStatArgs TY_SOCK, TY_DOOR, TY_PORT, - TY_NAMED + TY_NAMED, + TY_MESSAGE_QUEUE, + TY_SEMAPHORE, + TY_SHARED_MEMORY }; // attr is fs dependent? diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index ebb5cc1..f03e9a2 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -72,7 +72,7 @@ #include "config.h" #include #include -#if !IS_SORTIX +#if !IS_SORTIX && HAVE_SYS_FILE_H # include #endif #include @@ -98,9 +98,8 @@ #define setuid(x) sleep(0) #define setgid(x) sleep(0) #endif - - +#if SUPPORTS_POSIX_FORK_EXEC /* * signal type */ @@ -620,6 +619,8 @@ static const char *shellenv() return(shptr); } + +#if USES_MSYSTEM /* * like system but A LOT safer */ @@ -661,6 +662,7 @@ char *cmd; return(127); return(echild(i)); } +#endif // USES_MSYSTEM /* * this structure holds the information associating @@ -672,6 +674,7 @@ static struct popenfunc { /* association of pid, file pointer */ FILE *fp; /* the file pointer */ } pfunc[MAX_MPOPEN]; +#if USES_MPOPEN /* * like popen but A LOT safer */ @@ -722,6 +725,7 @@ char *mode; return(NULL); return(pfunc[indx].fp = ((*mode == 'w') ? fpa[0] : fpa[1])); } +#endif /* * close the pipe @@ -1028,7 +1032,6 @@ int echild(pid) int pid; #endif { - int r; /* PID of process just exited */ int status; /* status of wait call */ @@ -1050,3 +1053,5 @@ int pid; */ return(status); } + +#endif // SUPPORTS_POSIX_FORK_EXEC diff --git a/src/core/msystem.h b/src/core/msystem.h index f354dd0..db11b2b 100644 --- a/src/core/msystem.h +++ b/src/core/msystem.h @@ -57,6 +57,8 @@ #include "platform.h" +#if SUPPORTS_POSIX_FORK_EXEC + #ifdef __STDC__ void le_clobber(void); int le_set(const char*); @@ -66,8 +68,15 @@ int le_openfd(int); int le_closefd(int); int le_euid(int); int le_egid(int); + +#if USES_MSYSTEM int msystem(const char*); +#endif + +#if USES_MPOPEN FILE *mpopen(const char*, const char*); +#endif + int mpclose(FILE *); int mfpopen(const char*, FILE *[]); int mfpclose(int, FILE *[]); @@ -136,3 +145,4 @@ int echild(); # define NOSHELL "/bin/sh" /* use this if no shell */ #endif +#endif // SUPPORTS_POSIX_FORK_EXEC diff --git a/src/core/platform.h b/src/core/platform.h index ef08730..b0e1690 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -55,43 +55,53 @@ # define OS_CYGWIN 0x0102 # define OS_DOS_DJGPP 0x0103 -# define OS_LINUX 0x0201 +# define OS_LINUX 0x0201 # define OS_ANDROID 0x0202 -# define OS_FREEBSD 0x0301 -# define OS_NETBSD 0x0302 -# define OS_OPENBSD 0x0303 -# define OS_DARWIN 0x0304 +# define OS_FREEBSD 0x0301 +# define OS_NETBSD 0x0302 +# define OS_OPENBSD 0x0303 +# define OS_DARWIN 0x0304 # define OS_DRAGONFLYBSD 0x0305 -# define OS_MIDNIGHTBSD 0x0306 -# define OS_MIRBSD 0x0307 -# define OS_BITRIG 0x0308 -# define OS_LIBERTYBSD 0x0309 +# define OS_MIDNIGHTBSD 0x0306 +# define OS_MIRBSD 0x0307 +# define OS_BITRIG 0x0308 +# define OS_LIBERTYBSD 0x0309 +# define OS_BSDI 0x030A # define OS_SOLARIS 0x0400 -# define OS_AIX 0x0401 -# define OS_HPUX 0x0402 -# define OS_IRIX 0x0403 -# define OS_OSF1 0x0404 +# define OS_AIX 0x0401 +# define OS_HPUX 0x0402 +# define OS_IRIX 0x0403 +# define OS_OSF1 0x0404 +# define OS_OS400 0x0405 -# define OS_MINIX 0x0501 -# define OS_HURD 0x0502 -# define OS_HAIKU 0x0503 +# define OS_MINIX 0x0501 +# define OS_HURD 0x0502 +# define OS_HAIKU 0x0503 # define OS_SYLLABLE 0x0504 -# define OS_SKYOS 0x0505 -# define OS_SORTIX 0x0506 -# define OS_MINT 0x0507 -# define OS_AROS 0x0508 -# define OS_RTEMS 0x0509 -# define OS_RISCOS 0x050A -# define OS_REDOX 0x050B -# define OS_QNX 0x050C +# define OS_SKYOS 0x0505 +# define OS_SORTIX 0x0506 +# define OS_MINT 0x0507 +# define OS_AROS 0x0508 +# define OS_RTEMS 0x0509 +# define OS_RISCOS 0x050A +# define OS_REDOX 0x050B +# define OS_QNX 0x050C +# define OS_VXWORKS 0x50D +# define OS_LYNXOS 0x50E +# define OS_OS9 0x50F // For Microware's OS-9, not the Apple one. +# define OS_PLAN9 0x510 # define COMP_UNKNOWN 0 # define COMP_GCC 0x0001 # define COMP_CLANG 0x0002 # define COMP_MSVC 0x0101 + +// Definitions for the old KAI C++ compiler. +// KCC was EOL'd ages ago, but I'm leaving these definitions here for now +// on the off chance someone's still using it. # define COMP_KAI_GCC 0x0201 # define COMP_KAI_SUNPRO 0x0202 # define COMP_KAI_GLIBC 0x0203 @@ -99,7 +109,10 @@ # define COMP_KAI_HPANSIC 0x0205 # define COMP_KAI_IRIX 0x0206 # define COMP_KAI_OSF1ALPHA 0x0207 + # define COMP_SUNPRO 0x0301 +# define COMP_XL_C 0x0302 +# define COMP_ACC 0x0303 //============================================================================= // Platform detection @@ -128,7 +141,7 @@ # define OS OS_DOS_DJGPP # define IS_DOS_DJGPP 1 - +// Detect Android first, since Linux macros are also defined there # elif defined(__ANDROID__) # define OS OS_ANDROID # define IS_ANDROID 1 @@ -164,6 +177,9 @@ # define OS OS_BITRIG # define IS_BITRIG 1 +// Detect LibertyBSD first since OpenBSD macros are also defined. +// Autotools can tell them apart by target triplet, so we define +// 'TW_LibertybSD' there and pass it in. # elif defined(TW_LibertyBSD) # define OS OS_LIBERTYBSD # define IS_LIBERTYBSD 1 @@ -197,6 +213,9 @@ # define OS OS_OSF1 # define IS_OSF1 1 +# elif defined(__OS400__) +# define OS OS_OS400 +# define IS_OS400 1 # elif defined(__minix__) # define OS OS_MINIX @@ -242,10 +261,26 @@ # define OS OS_REDOX # define IS_REDOX 1 -# elif defined(__QNX__) +# elif defined(__QNX__) || defined(__QNXNTO__) # define OS OS_QNX # define IS_QNX 1 +# elif defined(__VXWORKS__) +# define OS OS_VXWORKS +# define IS_VXWORKS 1 + +# elif defined(__Lynx__) +# define OS OS_LYNXOS +# define IS_LYNXOS 1 + +# elif defined(__OS9000) +# define OS OS_OS9 +# define IS_OS9 1 + +# elif defined(EPLAN9) +# define OS OS_PLAN9 +# define IS_PLAN9 1 + # endif @@ -271,6 +306,10 @@ // These macros are the "worker bees" of platform.h. Programmers should use // these macros rather than comparing PLATFORM to the unique IDs by hand. // +// NOTE: Wherever possible, let autotools figure this out & define it in config.h +// rather than hardcoding it here. If autotools misdefines something, use +// core/fixups.h, which is guaranteed to be (re)included right after config.h +// // NB: Programmers are STRONGLY ENCOURAGED not to use the OS detection macros // or compiler detection marcros directly. Instead they should create // macros specific to the task at hand. For example Win32 and Solaris support @@ -288,6 +327,8 @@ // int network_order = swap(machine_order); // #endif + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -328,26 +369,32 @@ # define WCHAR_IS_16_BITS IS_WIN32 # define WCHAR_IS_32_BITS IS_UNIX # define WCHAR_REP_IS_UCS2 IS_WIN32 + +# define SUPPORTS_POSIX_FORK_EXEC (HAVE_FORK && HAVE_EXEC) // msystem+mpopen fail on Syllable, so use the libc equivalents until we figure out why. // TODO: Figure out why. -# define USES_MPOPEN (IS_UNIX && !IS_SYLLABLE) -# define USES_MSYSTEM (IS_UNIX && !IS_SYLLABLE) +# define USES_MPOPEN (SUPPORTS_POSIX_FORK_EXEC && !IS_SYLLABLE) +# define USES_MSYSTEM (SUPPORTS_POSIX_FORK_EXEC && !IS_SYLLABLE) # define SUPPORTS_WCHART IS_WIN32 // TODO: Remove after getting new ver of KAI # define USES_GLIBC ((COMP == COMP_KAI_GLIBC) || HAVE_GCC) # define SUPPORTS_MEMBER_TEMPLATES (!IS_SUNPRO) # define SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST (!IS_SUNPRO) # define SUPPORTS_POSIX_SIGNALS (!IS_DOS_DJGPP) -# define SUPPORTS_NETWORKING (!IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX) -# define SUPPORTS_SYSLOG (HAVE_SYSLOG_H && !IS_SKYOS && !IS_RISCOS) +# define SUPPORTS_NETWORKING (HAVE_SOCKET && !IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX) +# define SUPPORTS_SYSLOG (HAVE_SYSLOG && !IS_SKYOS && !IS_RISCOS) # define NEEDS_SWAB_IMPL (IS_CYGWIN || IS_SYLLABLE || IS_ANDROID || IS_SORTIX) # define USES_MBLEN (!IS_ANDROID && !IS_AROS) # define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP || IS_RISCOS || IS_REDOX) # define ICONV_CONST_SOURCE (IS_MINIX) # define SUPPORTS_DIRECT_IO (IS_LINUX) + +# define READ_TAKES_CHAR_PTR (IS_VXWORKS) +# define BCOPY_TAKES_CHAR_PTR (IS_VXWORKS) + // Linux is the only platform where direct i/o hashing has been tested & works properly so far. -# define SUPPORTS_TERMIOS (!IS_RTEMS && !IS_REDOX) +# define SUPPORTS_TERMIOS (HAVE_TERMIOS_H && (!IS_RTEMS && !IS_REDOX)) // RTEMS errors are probably just a buildsys issue & this will change or go away. // Redox will probably implement this in the future. diff --git a/src/core/timeconvert.cpp b/src/core/timeconvert.cpp index 3c53a74..a75c558 100644 --- a/src/core/timeconvert.cpp +++ b/src/core/timeconvert.cpp @@ -48,16 +48,16 @@ #include +#if IS_AROS +# undef HAVE_TZSET +#endif + //========================================================================= // METHOD CODE //========================================================================= #define TIME_MAX 2147483647L // largest signed 32 bit number -#if IS_AROS -# define tzset() -#endif - struct tm* cTimeUtil::TimeToDateGMT(const int64_t& seconds) { ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes! @@ -69,13 +69,17 @@ struct tm* cTimeUtil::TimeToDateLocal(const int64_t& seconds) { ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes! time_t t = static_cast(seconds); +#if HAVE_TZSET tzset(); +#endif return localtime(&t); } int64_t cTimeUtil::DateToTime(struct tm* ptm) { +#if HAVE_TZSET tzset(); +#endif return mktime(ptm); } diff --git a/src/core/twlocale.cpp b/src/core/twlocale.cpp index 206ca4a..ec0e456 100644 --- a/src/core/twlocale.cpp +++ b/src/core/twlocale.cpp @@ -48,6 +48,9 @@ #include #endif //HAVE_GCC +#if IS_AROS +# undef HAVE_TZSET +#endif //========================================================================= // STANDARD LIBRARY INCLUDES @@ -68,10 +71,6 @@ static TSTRING& util_FormatTimeCPlusPlus(struct tm* ptm, TSTRING& strBuf); // PUBLIC METHOD CODE //========================================================================= -#if IS_AROS -# define tzset() -#endif - void cTWLocale::InitGlobalLocale() { cDebug d("cTWLocale::InitGlobalLocale"); @@ -239,7 +238,9 @@ TSTRING& cTWLocale::FormatTime(int64_t t, TSTRING& strBuf) { // clear return string strBuf.erase(); +#if HAVE_TZSET tzset(); +#endif time_t tmpTime = t; struct tm* ptm = localtime(&tmpTime); if (ptm) diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 21a5ea5..509b4e3 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -54,20 +54,28 @@ #include #include #include + +#if HAVE_SYS_TIME_H #include -#ifdef HAVE_SYS_PARAM_H +#endif + +#if HAVE_SYS_PARAM_H #include #endif -#ifdef HAVE_SYS_MOUNT_H + +#if HAVE_SYS_MOUNT_H #include #endif -#ifdef HAVE_SYS_USTAT_H + +#if HAVE_SYS_USTAT_H #include #endif -#ifdef HAVE_WCHAR_H + +#if HAVE_WCHAR_H #include #endif -#ifdef HAVE_SYS_SYSMACROS_H + +#if HAVE_SYS_SYSMACROS_H #include #endif @@ -75,7 +83,9 @@ #include #endif +#if HAVE_PWD_H #include +#endif #if IS_REDOX # define restrict __restrict__ @@ -87,7 +97,10 @@ #include #endif +#if HAVE_GRP_H #include +#endif + #include #include @@ -173,7 +186,7 @@ void cUnixFSServices::GetHostID(TSTRING& name) const TOSTRINGSTREAM ret; ret.setf(ios_base::hex, ios_base::basefield); -#ifdef HAVE_GETHOSTID +#if HAVE_GETHOSTID ret << gethostid(); #else ret << 999999; @@ -264,38 +277,41 @@ void cUnixFSServices::GetCurrentDir(TSTRING& strCurDir) const TSTRING& cUnixFSServices::MakeTempFilename(TSTRING& strName) const { - char* pchTempFileName; char szTemplate[iFSServices::TW_MAX_PATH]; - int fd; strncpy(szTemplate, strName.c_str(), iFSServices::TW_MAX_PATH); -#ifdef HAVE_MKSTEMP +#if HAVE_MKSTEMP // create temp filename and check to see if mkstemp failed - if ((fd = mkstemp(szTemplate)) == -1) - { + int fd = mkstemp(szTemplate); + if (fd < 0) throw eFSServicesGeneric(strName); - } - else - { - close(fd); - } - pchTempFileName = szTemplate; -#else - fd = 0; + + close(fd); + char* pchTempFileName = szTemplate; + +#elif HAVE_MKTEMP + // create temp filename - pchTempFileName = mktemp(szTemplate); + char* pchTempFileName = mktemp(szTemplate); //check to see if mktemp failed if (pchTempFileName == NULL || strlen(pchTempFileName) == 0) { throw eFSServicesGeneric(strName); } + +#elif HAVE_TMPNAM + char* pchTempFileName = tmpnam(szTemplate); +#else + // none of the standard temp fns exist? should this be an error? + #error "No standard tempfile naming functions are available" #endif // change name so that it has the XXXXXX part filled in strName = pchTempFileName; + // TODO: below is a very old comment, is it still accurate? // Linux creates the file!! Doh! // So I'll always attempt to delete it -bam FileDelete(strName.c_str()); @@ -310,16 +326,15 @@ void cUnixFSServices::GetTempDirName(TSTRING& strName) const void cUnixFSServices::SetTempDirName(TSTRING& tmpPath) { - mTempPath = tmpPath; } #if !USES_DEVICE_PATH -void cUnixFSServices::Stat(const TSTRING& strName, cFSStatArgs& stat) const +void cUnixFSServices::Stat(const TSTRING& strName, cFSStatArgs& statArgs) const { #else -void cUnixFSServices::Stat(const TSTRING& strNameC, cFSStatArgs& stat) const +void cUnixFSServices::Stat(const TSTRING& strNameC, cFSStatArgs& statArgs) const { TSTRING strName = cDevicePath::AsNative(strNameC); #endif @@ -327,7 +342,11 @@ void cUnixFSServices::Stat(const TSTRING& strNameC, cFSStatArgs& stat) const struct stat statbuf; int ret; +#if HAVE_LSTAT ret = lstat(strName.c_str(), &statbuf); +#elif HAVE_STAT + ret = stat(strName.c_str(), &statbuf); +#endif cDebug d("cUnixFSServices::Stat"); d.TraceDetail("Executing on file %s (result=%d)\n", strName.c_str(), ret); @@ -348,66 +367,81 @@ void cUnixFSServices::Stat(const TSTRING& strNameC, cFSStatArgs& stat) const #endif //copy information returned by lstat call into the structure passed in - stat.gid = statbuf.st_gid; - stat.atime = statbuf.st_atime; - stat.ctime = statbuf.st_ctime; - stat.mtime = statbuf.st_mtime; - stat.dev = statbuf.st_dev; + statArgs.gid = statbuf.st_gid; + statArgs.atime = statbuf.st_atime; + statArgs.ctime = statbuf.st_ctime; + statArgs.mtime = statbuf.st_mtime; + statArgs.dev = statbuf.st_dev; #if HAVE_STRUCT_STAT_ST_RDEV - stat.rdev = statbuf.st_rdev; + statArgs.rdev = statbuf.st_rdev; #else - stat.rdev = 0; + statArgs.rdev = 0; #endif - stat.ino = statbuf.st_ino; - stat.mode = statbuf.st_mode; - stat.nlink = statbuf.st_nlink; - stat.size = statbuf.st_size; - stat.uid = statbuf.st_uid; - stat.blksize = statbuf.st_blksize; + statArgs.ino = statbuf.st_ino; + statArgs.mode = statbuf.st_mode; + statArgs.nlink = statbuf.st_nlink; + statArgs.size = statbuf.st_size; + statArgs.uid = statbuf.st_uid; + statArgs.blksize = statbuf.st_blksize; #if HAVE_STRUCT_STAT_ST_BLOCKS - stat.blocks = statbuf.st_blocks; + statArgs.blocks = statbuf.st_blocks; #else - stat.blocks = 0; + statArgs.blocks = 0; #endif // set the file type if (S_ISREG(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_FILE; + statArgs.mFileType = cFSStatArgs::TY_FILE; else if (S_ISDIR(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_DIR; + statArgs.mFileType = cFSStatArgs::TY_DIR; else if (S_ISLNK(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_SYMLINK; + statArgs.mFileType = cFSStatArgs::TY_SYMLINK; else if (S_ISBLK(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_BLOCKDEV; + statArgs.mFileType = cFSStatArgs::TY_BLOCKDEV; else if (S_ISCHR(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_CHARDEV; + statArgs.mFileType = cFSStatArgs::TY_CHARDEV; else if (S_ISFIFO(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_FIFO; + statArgs.mFileType = cFSStatArgs::TY_FIFO; #ifdef S_ISSOCK else if (S_ISSOCK(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_SOCK; + statArgs.mFileType = cFSStatArgs::TY_SOCK; #endif #if HAVE_DOOR_CREATE else if (S_ISDOOR(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_DOOR; + statArgs.mFileType = cFSStatArgs::TY_DOOR; #endif #if HAVE_PORT_CREATE else if (S_ISPORT(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_PORT; + statArgs.mFileType = cFSStatArgs::TY_PORT; #endif #ifdef S_ISNAM else if (S_ISNAM(statbuf.st_mode)) - stat.mFileType = cFSStatArgs::TY_NAMED; + statArgs.mFileType = cFSStatArgs::TY_NAMED; +#endif + +#ifdef S_TYPEISMQ + else if (S_TYPEISMQ(&statbuf)) + statArgs.mFileType = cFSStatArgs::TY_MESSAGE_QUEUE; +#endif + +#ifdef S_TYPEISSEM + else if (S_TYPEISSEM(&statbuf)) + statArgs.mFileType = cFSStatArgs::TY_SEMAPHORE; +#endif + +#ifdef S_TYPEISSHM + else if (S_TYPEISSHM(&statbuf)) + statArgs.mFileType = cFSStatArgs::TY_SHARED_MEMORY; #endif else - stat.mFileType = cFSStatArgs::TY_INVALID; + statArgs.mFileType = cFSStatArgs::TY_INVALID; } void cUnixFSServices::GetMachineName(TSTRING& strName) const @@ -461,8 +495,8 @@ bool cUnixFSServices::FileDelete(const TSTRING& strName) const bool cUnixFSServices::GetCurrentUserName(TSTRING& strName) const { +#if HAVE_PWD_H bool fSuccess = false; - uid_t uid = getuid(); struct passwd* pp = getpwuid(uid); @@ -475,6 +509,10 @@ bool cUnixFSServices::GetCurrentUserName(TSTRING& strName) const strName = _T(""); return (fSuccess); +#else + strName = _T(""); + return true; +#endif } @@ -537,6 +575,7 @@ bool cUnixFSServices::GetUserName(uid_t user_id, TSTRING& tstrUser) const { bool fSuccess = true; +#if HAVE_PWD_H if (mResolveNames) { struct passwd* pp = getpwuid(user_id); @@ -550,11 +589,13 @@ bool cUnixFSServices::GetUserName(uid_t user_id, TSTRING& tstrUser) const } else { +#endif std::stringstream sstr; sstr << user_id; tstrUser = sstr.str(); +#if HAVE_PWD_H } - +#endif return (fSuccess); } @@ -563,7 +604,7 @@ bool cUnixFSServices::GetGroupName(gid_t group_id, TSTRING& tstrGroup) const { bool fSuccess = true; -#if !IS_REDOX +#if !IS_REDOX && HAVE_GRP_H if (mResolveNames) { struct group* pg = getgrgid(group_id); @@ -581,7 +622,7 @@ bool cUnixFSServices::GetGroupName(gid_t group_id, TSTRING& tstrGroup) const std::stringstream sstr; sstr << group_id; tstrGroup = sstr.str(); -#if !IS_REDOX +#if !IS_REDOX && HAVE_GRP_H } #endif diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index 02836a8..bb960d9 100644 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -520,8 +520,14 @@ void cMD5Signature::Finit() MD5_Final(md5_digest, &mMD5Info); #else MD5Final(&mMD5Info); + +#if BCOPY_TAKES_CHAR_PTR + bcopy((char*)mMD5Info.digest, (char*)md5_digest, MD5_DIGEST_LENGTH); +#else bcopy(mMD5Info.digest, md5_digest, MD5_DIGEST_LENGTH); #endif + +#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/fs/fsdatasourceiter.cpp b/src/fs/fsdatasourceiter.cpp index f3c12e4..089726a 100644 --- a/src/fs/fsdatasourceiter.cpp +++ b/src/fs/fsdatasourceiter.cpp @@ -274,6 +274,15 @@ bool cFSDataSourceIter::InitializeTypeInfo(iFCO* pFCO) case cFSStatArgs::TY_NAMED: propSet.SetFileType(cFSPropSet::FT_NAMED); break; + case cFSStatArgs::TY_MESSAGE_QUEUE: + propSet.SetFileType(cFSPropSet::FT_MESSAGE_QUEUE); + break; + case cFSStatArgs::TY_SEMAPHORE: + propSet.SetFileType(cFSPropSet::FT_SEMAPHORE); + break; + case cFSStatArgs::TY_SHARED_MEMORY: + propSet.SetFileType(cFSPropSet::FT_SHARED_MEMORY); + break; default: // set it to invalid propSet.SetFileType(cFSPropSet::FT_INVALID); diff --git a/src/fs/fspropcalc.cpp b/src/fs/fspropcalc.cpp index bb48542..ec3bded 100644 --- a/src/fs/fspropcalc.cpp +++ b/src/fs/fspropcalc.cpp @@ -78,6 +78,9 @@ static bool NeedsStat(const cFCOPropVector& v) bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t size) { +#if !HAVE_READLINK + return false; +#else std::vector data(size + 1); char* buf = &data[0]; @@ -118,6 +121,7 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s arch.WriteBlob(buf, rtn); return true; +#endif } void cFSPropCalc::AddPropCalcError(const eError& e) @@ -298,6 +302,15 @@ void cFSPropCalc::HandleStatProperties(const cFCOPropVector& propsToCheck, const case cFSStatArgs::TY_NAMED: propSet.SetFileType(cFSPropSet::FT_NAMED); break; + case cFSStatArgs::TY_MESSAGE_QUEUE: + propSet.SetFileType(cFSPropSet::FT_MESSAGE_QUEUE); + break; + case cFSStatArgs::TY_SEMAPHORE: + propSet.SetFileType(cFSPropSet::FT_SEMAPHORE); + break; + case cFSStatArgs::TY_SHARED_MEMORY: + propSet.SetFileType(cFSPropSet::FT_SHARED_MEMORY); + break; default: // set it to invalid propSet.SetFileType(cFSPropSet::FT_INVALID); diff --git a/src/fs/fspropset.cpp b/src/fs/fspropset.cpp index 1457302..0bb7e02 100644 --- a/src/fs/fspropset.cpp +++ b/src/fs/fspropset.cpp @@ -59,7 +59,10 @@ TSTRING cFCOPropFileType::AsString() const fs::STR_FT_SOCK, fs::STR_FT_DOOR, fs::STR_FT_PORT, - fs::STR_FT_NAMED}; + fs::STR_FT_NAMED, + fs::STR_FT_MESSAGE_QUEUE, + fs::STR_FT_SEMAPHORE, + fs::STR_FT_SHARED_MEMORY}; int32_t fileType = GetValue(); if ((fileType > cFSPropSet::FT_INVALID) && (fileType < cFSPropSet::FT_NUMITEMS)) diff --git a/src/fs/fspropset.h b/src/fs/fspropset.h index 3a1606a..f716728 100644 --- a/src/fs/fspropset.h +++ b/src/fs/fspropset.h @@ -112,6 +112,9 @@ public: FT_DOOR, FT_PORT, FT_NAMED, + FT_MESSAGE_QUEUE, + FT_SEMAPHORE, + FT_SHARED_MEMORY, FT_NUMITEMS }; diff --git a/src/fs/fsstrings.cpp b/src/fs/fsstrings.cpp index 92a57d8..36cc3dd 100644 --- a/src/fs/fsstrings.cpp +++ b/src/fs/fsstrings.cpp @@ -42,13 +42,20 @@ TSS_BeginStringtable(cFS) TSS_StringEntry(fs::STR_FT_INVALID, _T("Invalid")), - TSS_StringEntry(fs::STR_FT_FILE, _T("Regular File")), TSS_StringEntry(fs::STR_FT_DIR, _T("Directory")), + TSS_StringEntry(fs::STR_FT_FILE, _T("Regular File")), + TSS_StringEntry(fs::STR_FT_DIR, _T("Directory")), TSS_StringEntry(fs::STR_FT_BLOCKDEV, _T("Block Device")), TSS_StringEntry(fs::STR_FT_CHARDEV, _T("Character Device")), - TSS_StringEntry(fs::STR_FT_SYMLINK, _T("Symbolic Link")), TSS_StringEntry(fs::STR_FT_FIFO, _T("FIFO")), - TSS_StringEntry(fs::STR_FT_SOCK, _T("Socket")), TSS_StringEntry(fs::STR_FT_DOOR, _T("Door")), - TSS_StringEntry(fs::STR_FT_PORT, _T("Event Port")), TSS_StringEntry(fs::STR_FT_NAMED, _T("Named Special File")), - + TSS_StringEntry(fs::STR_FT_SYMLINK, _T("Symbolic Link")), + TSS_StringEntry(fs::STR_FT_FIFO, _T("FIFO")), + TSS_StringEntry(fs::STR_FT_SOCK, _T("Socket")), + TSS_StringEntry(fs::STR_FT_DOOR, _T("Door")), + TSS_StringEntry(fs::STR_FT_PORT, _T("Event Port")), + TSS_StringEntry(fs::STR_FT_NAMED, _T("Named Special File")), + TSS_StringEntry(fs::STR_FT_MESSAGE_QUEUE, _T("Message Queue")), + TSS_StringEntry(fs::STR_FT_SEMAPHORE, _T("Semaphore")), + TSS_StringEntry(fs::STR_FT_SHARED_MEMORY, _T("Shared Memory")), + // property names TSS_StringEntry(fs::STR_PROP_DEV, _T("Device Number")), TSS_StringEntry(fs::STR_PROP_RDEV, _T("File Device Number")), diff --git a/src/fs/fsstrings.h b/src/fs/fsstrings.h index d8e5733..dc7f279 100644 --- a/src/fs/fsstrings.h +++ b/src/fs/fsstrings.h @@ -46,9 +46,8 @@ TSS_BeginStringIds(fs) // file types STR_FT_INVALID, - STR_FT_FILE, STR_FT_DIR, STR_FT_BLOCKDEV, STR_FT_CHARDEV, STR_FT_SYMLINK, STR_FT_FIFO, STR_FT_SOCK, STR_FT_DOOR, - STR_FT_PORT, STR_FT_NAMED, - + STR_FT_FILE, STR_FT_DIR, STR_FT_BLOCKDEV, STR_FT_CHARDEV, STR_FT_SYMLINK, STR_FT_FIFO, STR_FT_SOCK, STR_FT_DOOR, STR_FT_PORT, STR_FT_NAMED, + STR_FT_MESSAGE_QUEUE, STR_FT_SEMAPHORE, STR_FT_SHARED_MEMORY, // property names STR_PROP_DEV, STR_PROP_RDEV, STR_PROP_INODE, STR_PROP_MODE, STR_PROP_NLINK, STR_PROP_UID, STR_PROP_GID, STR_PROP_SIZE, STR_PROP_ATIME, STR_PROP_MTIME, STR_PROP_CTIME, STR_PROP_BLOCK_SIZE, STR_PROP_BLOCKS, STR_PROP_CRC32, diff --git a/src/siggen/siggenmain.cpp b/src/siggen/siggenmain.cpp index 85291b7..e309329 100644 --- a/src/siggen/siggenmain.cpp +++ b/src/siggen/siggenmain.cpp @@ -64,14 +64,22 @@ void tw_terminate_handler() { fputs("### Internal Error.\n### Terminate Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } #if __cplusplus < 201703L void tw_unexpected_handler() { fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } #endif diff --git a/src/tripwire/pipedmailmessage.cpp b/src/tripwire/pipedmailmessage.cpp index 5c7ce81..7793e1a 100644 --- a/src/tripwire/pipedmailmessage.cpp +++ b/src/tripwire/pipedmailmessage.cpp @@ -153,11 +153,13 @@ void cPipedMailMessage::SendInit() // throw( eMailMessageError ) TSTRING strHeader; strHeader += cStringUtil::StrToTstr(cMailMessage::Create822Header()); -#if !USES_MPOPEN +#if USES_MPOPEN + // call mpopen, our safe version popen + mpFile = mpopen((char*)mstrSendMailExePath.c_str(), _T("w")); +#elif HAVE_POPEN mpFile = popen(mstrSendMailExePath.c_str(), _T("w")); #else - // call mpopen, our safe version popen - mpFile = mpopen((char*)mstrSendMailExePath.c_str(), _T("w")); + // No pipes for you, sorry. #endif if (!mpFile) { diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 3550491..bed64f5 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -45,22 +45,27 @@ //All the spleck that it takes to run sockets in Unix... #include -# if HAVE_SYS_SOCKET_H -# include -# include -# include -# include -# endif + +#if HAVE_SYS_SOCKET_H +# include +# include +# include +# include +#endif + #include -#include -# if HAVE_SYS_UTSNAME_H -# include -# endif +#if HAVE_SYS_TIME_H +# include +#endif -# if HAVE_SYS_SELECT_H -# include -# endif +#if HAVE_SYS_UTSNAME_H +# include +#endif + +#if HAVE_SYS_SELECT_H +# include +#endif /* Some systems like Solaris and AIX don't define * INADDR_NONE, but it's pretty standard. If not, diff --git a/src/tripwire/syslog_trip.cpp b/src/tripwire/syslog_trip.cpp index 49c3429..b3a82b1 100644 --- a/src/tripwire/syslog_trip.cpp +++ b/src/tripwire/syslog_trip.cpp @@ -37,11 +37,11 @@ #include "syslog_trip.h" #if HAVE_SYSLOG_H -#include +# include #endif #if HAVE_SYS_SYSLOG_H -#include +# include #endif // next three includes are for error reporting @@ -49,10 +49,11 @@ #include "tw/twerrors.h" #include "tw/twstrings.h" +// TODO: Handle this in a proper autoconf way #if IS_AROS -#include -# define openlog(a, b, c) -# define closelog() +# include +# define openlog(a, b, c) +# define closelog() #endif /////////////////////////////////////////////////////////////////////////////// diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index 052a109..4decfc8 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -92,14 +92,23 @@ void operator delete(void* addr) void tw_terminate_handler() { fputs("### Internal Error.\n### Terminate Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(8); +#else + exit(8); +#endif } #if __cplusplus < 201703L void tw_unexpected_handler() { fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr); + +#if HAVE__EXIT _exit(8); +#else + exit(8); +#endif } #endif diff --git a/src/twadmin/keygeneration.cpp b/src/twadmin/keygeneration.cpp index d50c602..f27f6d0 100644 --- a/src/twadmin/keygeneration.cpp +++ b/src/twadmin/keygeneration.cpp @@ -52,7 +52,7 @@ struct tGK enum ReturnValue { - OK = 0, + OKAY = 0, INVALIDPARAM = 1, GENERATION_ERROR = 2, FILE_WRITE_ERROR = 3, @@ -123,7 +123,7 @@ static void GeneratePublicPrivateKeys(void* pParams, const cElGamalSig::KeySize return; } - pGK->retValue = tGK::OK; + pGK->retValue = tGK::OKAY; pGK->doneFlag = true; return; } @@ -152,7 +152,7 @@ bool GenerateKey(const TCHAR* keyPath, wc16_string passphrase, const cElGamalSig GeneratePublicPrivateKeys(&gk, key_size); - if (gk.retValue != tGK::OK) + if (gk.retValue != tGK::OKAY) { switch (gk.retValue) { diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index a337f94..7045b55 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -51,6 +51,7 @@ #include #include + /////////////////////////////////////////////////////////////////////////////// // terminate and unexpected handlers // TODO: move these to a common library @@ -58,14 +59,22 @@ void tw_terminate_handler() { fputs("### Internal Error.\n### Terminate Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } #if __cplusplus < 201703L void tw_unexpected_handler() { fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } #endif diff --git a/src/twcrypto/crypto.cpp b/src/twcrypto/crypto.cpp index 1f852ed..91acab4 100644 --- a/src/twcrypto/crypto.cpp +++ b/src/twcrypto/crypto.cpp @@ -1197,12 +1197,12 @@ cHashedKey128::cHashedKey128(const TSTRING& data) sha.CalculateDigest((uint8_t*)mKey, (uint8_t*)data.data(), data.length() * sizeof(TCHAR)); } -cHashedKey128::cHashedKey128(void* pData, int dataLen) +cHashedKey128::cHashedKey128(void* pData, int32_t dataLen) { SHA sha; ASSERT(SHA::DIGESTSIZE >= KEYLEN); - ASSERT(SHA::DIGESTSIZE <= BUFSIZE); + ASSERT(SHA::DIGESTSIZE <= BUFFER_SIZE); sha.CalculateDigest((uint8_t*)mKey, (uint8_t*)pData, dataLen); } @@ -1227,7 +1227,7 @@ cHashedKey192::cHashedKey192(const TSTRING& data) memcpy(mKey, localKey, KEYLEN); } -cHashedKey192::cHashedKey192(void* pData, int dataLen) +cHashedKey192::cHashedKey192(void* pData, int32_t dataLen) { SHA sha; diff --git a/src/twcrypto/crypto.h b/src/twcrypto/crypto.h index 3f8d83a..cd1b4f5 100644 --- a/src/twcrypto/crypto.h +++ b/src/twcrypto/crypto.h @@ -350,7 +350,7 @@ class cHashedKey128 { public: explicit cHashedKey128(const TSTRING& data); - cHashedKey128(void* pData, int dataLen); + cHashedKey128(void* pData, int32_t dataLen); ~cHashedKey128(); const int8_t* GetKey() const; @@ -362,10 +362,10 @@ protected: enum { KEYLEN = 16, - BUFSIZE = 20 + BUFFER_SIZE = 20 }; - int8_t mKey[BUFSIZE]; + int8_t mKey[BUFFER_SIZE]; }; inline const int8_t* cHashedKey128::GetKey() const diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index f0d9d55..351a10a 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -67,7 +67,11 @@ void tw_terminate_handler() { fputs("### Internal Error.\n### Terminate Handler called.\n### Exiting...\n", stderr); +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } // Exception specifications removed as a misfeature in C++17 @@ -75,7 +79,12 @@ void tw_terminate_handler() void tw_unexpected_handler() { fputs("### Internal Error.\n### Unexpected Exception Handler called.\n### Exiting...\n", stderr); + +#if HAVE__EXIT _exit(1); +#else + exit(1); +#endif } #endif diff --git a/src/twtest/crypto_t.cpp b/src/twtest/crypto_t.cpp index b02adf2..3eae107 100644 --- a/src/twtest/crypto_t.cpp +++ b/src/twtest/crypto_t.cpp @@ -42,10 +42,10 @@ void TestCrypto() { const int COUNT = 4000; - const int BUFSIZE = 9000; + const int BUFFER_SIZE = 9000; - std::vector source_buf(BUFSIZE); - std::vector crypt_buf(COUNT + BUFSIZE); // needs to be able to hold even number of blocks + std::vector source_buf(BUFFER_SIZE); + std::vector crypt_buf(COUNT + BUFFER_SIZE); // needs to be able to hold even number of blocks std::vector dest_buf(COUNT); char* source = &source_buf[0]; @@ -119,9 +119,9 @@ void TestCrypto() // we use buf for when the end of the source doesn't fall on a // blocksize boundry. - TEST(crypter.GetBlockSizePlain() < BUFSIZE); - TEST(crypter.GetBlockSizeCipher() < BUFSIZE); - char buf[BUFSIZE]; + TEST(crypter.GetBlockSizePlain() < BUFFER_SIZE); + TEST(crypter.GetBlockSizeCipher() < BUFFER_SIZE); + char buf[BUFFER_SIZE]; cRSAPublicKey* pPublic; cRSAPrivateKey* pPrivate; @@ -132,16 +132,16 @@ void TestCrypto() cRSAPublicKey* pPublic2; cRSAPrivateKey* pPrivate2; - TEST(pPublic->GetWriteLen() < BUFSIZE); + TEST(pPublic->GetWriteLen() < BUFFER_SIZE); pPublic->Write(buf); pPublic2 = new cRSAPublicKey(buf); - TEST(pPrivate->GetWriteLen() < BUFSIZE); + TEST(pPrivate->GetWriteLen() < BUFFER_SIZE); pPrivate->Write(buf); pPrivate2 = new cRSAPrivateKey(buf); // we will try encrypting to a second pair of buffers and see if all goes well - char crypt2[COUNT + BUFSIZE]; + char crypt2[COUNT + BUFFER_SIZE]; char dest2[COUNT]; // encrypt the phrase @@ -289,9 +289,9 @@ void TestCrypto() // we use buf for when the end of the source doesn't fall on a // blocksize boundry. - TEST(crypter.GetBlockSizePlain() < BUFSIZE); - TEST(crypter.GetBlockSizeCipher() < BUFSIZE); - char buf[BUFSIZE]; + TEST(crypter.GetBlockSizePlain() < BUFFER_SIZE); + TEST(crypter.GetBlockSizeCipher() < BUFFER_SIZE); + char buf[BUFFER_SIZE]; cElGamalSigPublicKey* pPublic; cElGamalSigPrivateKey* pPrivate; @@ -302,16 +302,16 @@ void TestCrypto() cElGamalSigPublicKey* pPublic2; cElGamalSigPrivateKey* pPrivate2; - TEST(pPublic->GetWriteLen() < BUFSIZE); + TEST(pPublic->GetWriteLen() < BUFFER_SIZE); pPublic->Write(buf); pPublic2 = new cElGamalSigPublicKey(buf); - TEST(pPrivate->GetWriteLen() < BUFSIZE); + TEST(pPrivate->GetWriteLen() < BUFFER_SIZE); pPrivate->Write(buf); pPrivate2 = new cElGamalSigPrivateKey(buf); // we will try encrypting to a second pair of buffers and see if all goes well - //char crypt2[COUNT + BUFSIZE]; + //char crypt2[COUNT + BUFFER_SIZE]; //char dest2[COUNT]; // zero out things and try signing and verifying diff --git a/src/twtest/fspropcalc_t.cpp b/src/twtest/fspropcalc_t.cpp index 6dd3262..d120879 100644 --- a/src/twtest/fspropcalc_t.cpp +++ b/src/twtest/fspropcalc_t.cpp @@ -46,6 +46,7 @@ #include #include + /////////////////////////////////////////////////////////////////////////////// // PrintProps -- prints out all the valid property names and values as pairs... /////////////////////////////////////////////////////////////////////////////// @@ -140,6 +141,7 @@ void TestFSPropCalc() return; } +#if HAVE_SYMLINK void TestGetSymLinkStr() { std::string file = TwTestPath("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); @@ -156,9 +158,12 @@ void TestGetSymLinkStr() TEST(cFSPropCalc::GetSymLinkStr(link, arch, 8)); TEST(arch.Length() == (int64_t)file.size()); } +#endif void RegisterSuite_FSPropCalc() { RegisterTest("FSPropCalc", "Basic", TestFSPropCalc); +#if HAVE_SYMLINK RegisterTest("FSPropCalc", "GetSymLinkStr", TestGetSymLinkStr); +#endif } diff --git a/src/twtest/twutil_t.cpp b/src/twtest/twutil_t.cpp index 5c2d78f..aaa4ebc 100644 --- a/src/twtest/twutil_t.cpp +++ b/src/twtest/twutil_t.cpp @@ -75,12 +75,17 @@ void TestTWUtil() TEST(cFileUtil::FileWritable(tmpFN) == true) TEST(cFileUtil::FileExists(tmpFN) == false); +#if !HAVE_GETUID + bool is_root = true; +#else + #if IS_AROS bool is_root = (65534 == getuid()); //AROS doesn't really have users, & posixy fns use this pseudo value. #else bool is_root = (0 == getuid()); #endif - + +#endif // make the dir read only and make sure write tests false // windows fails this test, perhaps because I am an administrator? // chmod(tmpDir.c_str(), 0500); diff --git a/src/util/fileutil.cpp b/src/util/fileutil.cpp index 5ebf3e0..48027b2 100644 --- a/src/util/fileutil.cpp +++ b/src/util/fileutil.cpp @@ -52,7 +52,6 @@ #include #include - /////////////////////////////////////////////////////////////////////////////// // TestFileExists /////////////////////////////////////////////////////////////////////////////// @@ -264,8 +263,13 @@ bool cFileUtil::Copy(const TSTRING& src_path, const TSTRING& dest_path) // restore permissions and ownership // don't worry if it fails. it's not mission-critical. +#if HAVE_CHMOD chmod(dest_path.c_str(), srcStat.st_mode); +#endif + +#if HAVE_CHOWN chown(dest_path.c_str(), srcStat.st_uid, srcStat.st_gid); +#endif srcFile.Close(); destFile.Close();