diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac index 3c058135a..25249726f 100644 --- a/open-vm-tools/configure.ac +++ b/open-vm-tools/configure.ac @@ -129,6 +129,9 @@ case "$host_os" in [solaris*]) os="solaris" ;; + [netbsd*]) + os="netbsd" + ;; [*]) AC_MSG_WARN([This is an untested and unsupported Operating System. Proceed at your own peril.]) ;; @@ -615,6 +618,18 @@ if test "$with_fuse" = "fuse" || AC_DEFINE([FUSE_USE_VERSION], 29, [FUSE API version to use.])], [have_fuse=no]) + if test "$have_fuse" = "no" -a "$os" = "netbsd"; then + AC_CHECK_LIB( + [refuse], + [fuse_loop], + [have_fuse=yes; + FUSE_CPPFLAGS="-D_NETBSD_SOURCE -D_KERNTYPES"; + FUSE_LIBS=-lrefuse; + AC_DEFINE([HAVE_FUSE], 1, [Define to 1 if using FUSE.]) + AC_DEFINE([FUSE_USE_VERSION], 29, [FUSE API version to use.])], + [have_fuse=no]) + fi + if test "$have_fuse" = "no"; then if test "$with_fuse" = "auto" || test "$with_fuse" = "yes"; then AC_MSG_NOTICE([Fuse is missing, vmblock-fuse/vmhgfs-fuse will be disabled.]) @@ -1689,6 +1704,8 @@ fi AM_CONDITIONAL(LINUX, test "$os" = "linux") AM_CONDITIONAL(SOLARIS, test "$os" = "solaris") AM_CONDITIONAL(FREEBSD, test "$os" = "freebsd" -o "$os" = "kfreebsd-gnu") +AM_CONDITIONAL(NETBSD, test "$os" = "netbsd") +AM_CONDITIONAL(BSD, test "$os" = "freebsd" -o "$os" = "kfreebsd-gnu" -o "$os" = "netbsd") AM_CONDITIONAL(FREEBSD_CUSTOM_SYSDIR, test \( "$os" = "freebsd" -o "$os" = "kfreebsd-gnu" \) -a -n "$SYSDIR") AM_CONDITIONAL(ARCH_X32, test "$arch" = "x32") diff --git a/open-vm-tools/lib/dynxdr/dynxdr.c b/open-vm-tools/lib/dynxdr/dynxdr.c index bd42c7513..3a4f37db5 100644 --- a/open-vm-tools/lib/dynxdr/dynxdr.c +++ b/open-vm-tools/lib/dynxdr/dynxdr.c @@ -55,7 +55,8 @@ typedef struct DynXdrData { * Mac OS X, FreeBSD and Solaris don't take a const parameter to the * "x_getpostn" function. */ -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(sun) || defined(USE_TIRPC) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(sun) || defined(USE_TIRPC) # define DYNXDR_GETPOS_CONST #else # define DYNXDR_GETPOS_CONST const diff --git a/open-vm-tools/lib/dynxdr/xdrutil.c b/open-vm-tools/lib/dynxdr/xdrutil.c index a2d1a250e..b73f8a2be 100644 --- a/open-vm-tools/lib/dynxdr/xdrutil.c +++ b/open-vm-tools/lib/dynxdr/xdrutil.c @@ -102,7 +102,11 @@ XdrUtil_Deserialize(const void *data, // IN ASSERT(dest != NULL); xdrmem_create(&xdrs, (char *) data, dataLen, XDR_DECODE); +#if defined(__NetBSD__) + ret = (Bool) proc(&xdrs, dest); +#else ret = (Bool) proc(&xdrs, dest, 0); +#endif xdr_destroy(&xdrs); if (!ret) { diff --git a/open-vm-tools/lib/file/fileIOPosix.c b/open-vm-tools/lib/file/fileIOPosix.c index 492a4bf4a..a13a2a54e 100644 --- a/open-vm-tools/lib/file/fileIOPosix.c +++ b/open-vm-tools/lib/file/fileIOPosix.c @@ -66,7 +66,7 @@ #include #include #else -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) #include #include #else @@ -1493,7 +1493,7 @@ FileIO_Writev(FileIODescriptor *fd, // IN: #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||\ - defined(__sun__) + defined(__sun__) || defined(__NetBSD__) /* *---------------------------------------------------------------------- @@ -1679,7 +1679,7 @@ FileIOPwritevCoalesced( } #endif /* defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || - defined(__sun__) */ + defined(__sun__) || defined(__NetBSD__) */ #if defined(__linux__) && !defined(__ANDROID__) @@ -1952,7 +1952,7 @@ FileIOPwritevInternal( #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||\ - defined(__sun__) + defined(__sun__) || defined(__NetBSD__) /* *---------------------------------------------------------------------- @@ -2046,7 +2046,7 @@ FileIO_Pwritev(FileIODescriptor *fd, // IN: File descriptor } #endif /* defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || - defined(__sun__) */ + defined(__sun__) || defined(__NetBSD__) */ /* diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index ee36700ea..1ecd7669a 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -24,7 +24,7 @@ #include /* Needed before sys/vfs.h with glibc 2.0 --hpreg */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) # include # include #else @@ -57,6 +57,10 @@ #include #endif +#if defined(__NetBSD__) +#define statfs statvfs +#endif + #include "vmware.h" #include "posix.h" #include "codeset.h" @@ -115,9 +119,9 @@ struct WalkDirContextImpl { #define FS_VSAND_ON_ESX "vsanD" #define FS_VSAN_URI_PREFIX "vsan:" -#if defined __ANDROID__ +#if defined __ANDROID__ || defined __NetBSD__ /* - * Android doesn't support setmntent(), endmntent() or MOUNTED. + * Android and NetBSD doesn't support setmntent(), endmntent() or MOUNTED. */ #define NO_SETMNTENT #define NO_ENDMNTENT @@ -370,7 +374,7 @@ FileAttributes(const char *pathName, // IN: *---------------------------------------------------------------------- */ -#if !defined(__FreeBSD__) && !defined(sun) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(sun) Bool File_IsRemote(const char *pathName) // IN: Path name { @@ -409,7 +413,7 @@ File_IsRemote(const char *pathName) // IN: Path name #endif } } -#endif /* !FreeBSD && !sun */ +#endif /* !FreeBSD && !NetBSD && !sun */ /* @@ -581,8 +585,8 @@ File_StripFwdSlashes(const char *pathName) // IN: * directory and so on. If the path is NULL or "", this routine * returns the current working directory. * - * On FreeBSD and Sun platforms, this routine will only work if - * the path exists, or when we are about to create a child in an + * On BSD and Sun platforms, this routine will only work if the + * path exists, or when we are about to create a child in an * existing parent directory. This is because on these platforms, * we cannot rely on finding existing ancestor and such because * those functions are not compiled. @@ -626,7 +630,7 @@ File_FullPath(const char *pathName) // IN: if (ret == NULL) { char *dir; char *file; -#if defined(__FreeBSD__) || defined(sun) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sun) char *realDir; #else char *ancestorPath; @@ -634,7 +638,7 @@ File_FullPath(const char *pathName) // IN: #endif File_GetPathName(path, &dir, &file); -#if defined(__FreeBSD__) || defined(sun) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sun) realDir = Posix_RealPath(dir); if (realDir == NULL) { realDir = File_StripFwdSlashes(dir); @@ -2186,6 +2190,10 @@ File_IsSameFile(const char *path1, // IN: if ((stfs1.f_flags & MNT_LOCAL) && (stfs2.f_flags & MNT_LOCAL)) { return TRUE; } +#elif defined(__NetBSD__) + if ((stfs1.f_flag & MNT_LOCAL) && (stfs2.f_flag & MNT_LOCAL)) { + return TRUE; + } #else if ((stfs1.f_type != NFS_SUPER_MAGIC) && (stfs2.f_type != NFS_SUPER_MAGIC)) { diff --git a/open-vm-tools/lib/hgfsHelper/hgfsHelperPosix.c b/open-vm-tools/lib/hgfsHelper/hgfsHelperPosix.c index d35dbe7c1..ca521fc2b 100644 --- a/open-vm-tools/lib/hgfsHelper/hgfsHelperPosix.c +++ b/open-vm-tools/lib/hgfsHelper/hgfsHelperPosix.c @@ -24,7 +24,8 @@ * */ -#if !defined __linux__ && !defined __FreeBSD__ && !defined sun && !defined __APPLE__ +#if !defined __linux__ && !defined __FreeBSD__ && !defined __NetBSD__ && \ + !defined sun && !defined __APPLE__ # error This file should not be compiled #endif @@ -65,7 +66,7 @@ Bool HgfsHlpr_QuerySharesDefaultRootPath(char **hgfsRootPath) { -#if defined __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ return FALSE; #else ASSERT(hgfsRootPath != NULL); diff --git a/open-vm-tools/lib/hgfsUri/hgfsUriPosix.c b/open-vm-tools/lib/hgfsUri/hgfsUriPosix.c index 2d296da5f..91b8b7f49 100644 --- a/open-vm-tools/lib/hgfsUri/hgfsUriPosix.c +++ b/open-vm-tools/lib/hgfsUri/hgfsUriPosix.c @@ -23,7 +23,8 @@ * x-vmware-share:// style URIs */ -#if !defined __linux__ && !defined __APPLE__ && !defined __FreeBSD__ +#if !defined __linux__ && !defined __APPLE__ && !defined __FreeBSD__ && \ + !defined __NetBSD__ # error This file should not be compiled #endif diff --git a/open-vm-tools/lib/include/codeset.h b/open-vm-tools/lib/include/codeset.h index 4e1482f2f..d3165358b 100644 --- a/open-vm-tools/lib/include/codeset.h +++ b/open-vm-tools/lib/include/codeset.h @@ -65,6 +65,7 @@ extern "C" { */ #if defined(__FreeBSD__) || \ + defined(__NetBSD__) || \ defined(VMX86_SERVER) || \ defined(__APPLE__) || \ defined __ANDROID__ diff --git a/open-vm-tools/lib/include/guest_os.h b/open-vm-tools/lib/include/guest_os.h index 5825cfa85..72f16f605 100644 --- a/open-vm-tools/lib/include/guest_os.h +++ b/open-vm-tools/lib/include/guest_os.h @@ -634,6 +634,9 @@ Bool Gos_InSetArray(uint32 gos, const uint32 *set); /* FreeBSD */ #define STR_OS_FREEBSD "freeBSD" +/* NetBSD */ +#define STR_OS_NETBSD "netbsd" + /* Solaris */ #define STR_OS_SOLARIS "solaris" diff --git a/open-vm-tools/lib/include/hgfsUtil.h b/open-vm-tools/lib/include/hgfsUtil.h index 609f4c000..27aeccc95 100644 --- a/open-vm-tools/lib/include/hgfsUtil.h +++ b/open-vm-tools/lib/include/hgfsUtil.h @@ -58,6 +58,7 @@ !defined __timespec_defined && \ !defined sun && \ !defined __FreeBSD__ && \ + !defined __NetBSD__ && \ !__APPLE__ && \ !defined _WIN32 struct timespec { @@ -73,7 +74,8 @@ struct timespec { # if defined __KERNEL__ || defined _KERNEL || defined KERNEL # if defined __linux__ # include -# elif defined sun || defined __FreeBSD__ || defined __APPLE__ +# elif defined sun || defined __FreeBSD__ || defined __NetBSD__ || \ + defined __APPLE__ # include # endif # else diff --git a/open-vm-tools/lib/include/iovector.h b/open-vm-tools/lib/include/iovector.h index 2354d5b4e..eedcedfa2 100644 --- a/open-vm-tools/lib/include/iovector.h +++ b/open-vm-tools/lib/include/iovector.h @@ -36,7 +36,8 @@ extern "C" { /* * Ugly definition of struct iovec. */ -#if defined(__linux__) || defined(sun) || defined(__APPLE__) || defined(__FreeBSD__) +#if defined(__linux__) || defined(sun) || defined(__APPLE__) || \ + defined(__FreeBSD__) || defined(__NetBSD__) #include // for struct iovec #else diff --git a/open-vm-tools/lib/include/mntinfo.h b/open-vm-tools/lib/include/mntinfo.h index d1c978c85..1acd09426 100644 --- a/open-vm-tools/lib/include/mntinfo.h +++ b/open-vm-tools/lib/include/mntinfo.h @@ -34,7 +34,7 @@ # include #elif defined(__linux__) # include -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) # include #endif #include "posix.h" @@ -106,7 +106,10 @@ # define MNTINFO_FSTYPE(mnt) mnt->mnt_type # define MNTINFO_MNTPT(mnt) mnt->mnt_dir # define MNTINFO_MNT_IS_RO(mnt) (hasmntopt((mnt), "rw") == NULL) -#elif defined(__FreeBSD__) || defined(__APPLE__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#if defined(__NetBSD__) +#define statfs statvfs +#endif struct mntHandle { struct statfs *mountPoints; // array of mountpoints per getmntinfo(3) int numMountPoints; // number of elements in mntArray @@ -155,7 +158,11 @@ struct mntHandle { # define MNTINFO_NAME(mnt) mnt->f_mntfromname # define MNTINFO_FSTYPE(mnt) mnt->f_fstypename # define MNTINFO_MNTPT(mnt) mnt->f_mntonname -# define MNTINFO_MNT_IS_RO(mnt) ((mnt)->f_flags & MNT_RDONLY) +# if defined __NetBSD__ +# define MNTINFO_MNT_IS_RO(mnt) ((mnt)->f_flag & MNT_RDONLY) +# else +# define MNTINFO_MNT_IS_RO(mnt) ((mnt)->f_flags & MNT_RDONLY) +# endif #else # error "Define mount information macros for your OS type" #endif diff --git a/open-vm-tools/lib/include/posix.h b/open-vm-tools/lib/include/posix.h index c2a38673f..b3b0dfc09 100644 --- a/open-vm-tools/lib/include/posix.h +++ b/open-vm-tools/lib/include/posix.h @@ -134,7 +134,7 @@ char *Posix_MkTemp(const char *pathName); * Make them NULL wrappers for all other platforms. */ #define Posix_GetHostName gethostname -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__NetBSD__) #define Posix_GetHostByName gethostbyname #endif #define Posix_GetAddrInfo getaddrinfo @@ -209,7 +209,7 @@ struct mntent *Posix_Getmntent_r(FILE *fp, struct mntent *m, int Posix_Getmntent(FILE *fp, struct mnttab *mp); #endif // !defined(sun) -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__NetBSD__) /* @@ -280,7 +280,7 @@ Posix_GetHostByName(const char *name) // IN /* There has been an error */ return NULL; } -#endif // !define(__APPLE__) +#endif // !define(__APPLE__) && !defined(__NetBSD__) /* @@ -303,7 +303,7 @@ Posix_GetHostByName(const char *name) // IN static INLINE void Posix_FreeHostent(struct hostent *he) { -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__NetBSD__) char **p; if (he) { diff --git a/open-vm-tools/lib/include/procMgr.h b/open-vm-tools/lib/include/procMgr.h index 218b7ba6e..f7e8aa2b4 100644 --- a/open-vm-tools/lib/include/procMgr.h +++ b/open-vm-tools/lib/include/procMgr.h @@ -56,7 +56,7 @@ typedef struct ProcMgr_AsyncProc ProcMgr_AsyncProc; typedef struct ProcMgrProcInfo { ProcMgr_Pid procId; char *procCmdName; // UTF-8 -#if defined(__linux__) || defined(_WIN32) +#if defined(__linux__) || defined(__NetBSD__) || defined(_WIN32) char *procCmdAbsPath; // UTF-8 #endif char *procCmdLine; // UTF-8 diff --git a/open-vm-tools/lib/include/sigPosixRegs.h b/open-vm-tools/lib/include/sigPosixRegs.h index 17301ae29..553e13d44 100644 --- a/open-vm-tools/lib/include/sigPosixRegs.h +++ b/open-vm-tools/lib/include/sigPosixRegs.h @@ -203,6 +203,38 @@ extern "C" { #define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.mc_esp) #define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.mc_eip) #endif +#elif defined (__NetBSD__) +#ifdef __x86_64__ +#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RAX]) +#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RBX]) +#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RCX]) +#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RDX]) +#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RDI]) +#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RSI]) +#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RBP]) +#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RSP]) +#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_RIP]) +#define SC_R8(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R8]) +#define SC_R9(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R9]) +#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R10]) +#define SC_R11(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R11]) +#define SC_R12(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R12]) +#define SC_R13(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R13]) +#define SC_R14(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R14]) +#define SC_R15(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_R15]) +#elif defined(__aarch64__) +#define SC_X(uc,n) ((unsigned long) (uc)->uc_mcontext.__gregs[n]) +#else +#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EAX]) +#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EBX]) +#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_ECX]) +#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EDX]) +#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EDI]) +#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_ESI]) +#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EBP]) +#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_ESP]) +#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.__gregs[_REG_EIP]) +#endif #elif defined (sun) #ifdef __x86_64__ #define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RAX]) diff --git a/open-vm-tools/lib/include/su.h b/open-vm-tools/lib/include/su.h index 67e88ae9e..eb07628fc 100644 --- a/open-vm-tools/lib/include/su.h +++ b/open-vm-tools/lib/include/su.h @@ -55,7 +55,8 @@ Bool Id_AuthCheck(char const *right, char const *localizedDescription, Bool showDialogIfNeeded); -#elif (defined(__linux__) || defined(sun) || defined(__FreeBSD__)) +#elif (defined(__linux__) || defined(sun) || defined(__FreeBSD__) || \ + defined(__NetBSD__)) #include #include diff --git a/open-vm-tools/lib/include/vm_ctype.h b/open-vm-tools/lib/include/vm_ctype.h index 2e48786ff..3fa05eb5b 100644 --- a/open-vm-tools/lib/include/vm_ctype.h +++ b/open-vm-tools/lib/include/vm_ctype.h @@ -40,7 +40,7 @@ extern "C" { * Attack the parameter with 0xFF to cast away the signedness. */ -#ifdef _WIN32 +#if defined _WIN32 || defined __NetBSD__ #define CType_IsAlnum(c) isalnum((c) & 0xFF) #define CType_IsAlpha(c) isalpha((c) & 0xFF) diff --git a/open-vm-tools/lib/include/vm_product.h b/open-vm-tools/lib/include/vm_product.h index dc037c4e8..cf7c646e2 100644 --- a/open-vm-tools/lib/include/vm_product.h +++ b/open-vm-tools/lib/include/vm_product.h @@ -448,6 +448,8 @@ # define PRODUCT_NAME_PLATFORM PRODUCT_NAME " for Windows" #elif defined(__FreeBSD__) # define PRODUCT_NAME_PLATFORM PRODUCT_NAME " for FreeBSD" +#elif defined(__NetBSD__) +# define PRODUCT_NAME_PLATFORM PRODUCT_NAME " for NetBSD" #elif defined(sun) # define PRODUCT_NAME_PLATFORM PRODUCT_NAME " for Solaris" #elif defined(__APPLE__) diff --git a/open-vm-tools/lib/include/vmblock.h b/open-vm-tools/lib/include/vmblock.h index 6a03e40ca..4920a6b2a 100644 --- a/open-vm-tools/lib/include/vmblock.h +++ b/open-vm-tools/lib/include/vmblock.h @@ -83,11 +83,11 @@ #ifndef _VMBLOCK_H_ #define _VMBLOCK_H_ -#if defined(sun) || defined(__FreeBSD__) +#if defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) # include #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) # include #endif @@ -169,7 +169,7 @@ extern "C" { "/" VMBLOCK_CONTROL_DEVNAME # define VMBLOCK_DEVICE_MODE O_WRONLY -#elif defined(sun) || defined(__FreeBSD__) +#elif defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) # define VMBLOCK_FS_NAME "vmblock" # define VMBLOCK_MOUNT_POINT "/var/run/" VMBLOCK_FS_NAME # define VMBLOCK_FS_ROOT VMBLOCK_MOUNT_POINT @@ -187,7 +187,8 @@ extern "C" { # define VMBLOCK_LIST_FILEBLOCKS _IO('v', 3) # endif -# elif defined(__FreeBSD__) /* } else if (FreeBSD) { */ +# elif defined(__FreeBSD__) || defined(__NetBSD__) + /* } else if (FreeBSD || NetBSD) { */ /* * Similar to Solaris, construct ioctl(2) commands for block operations. * Since the FreeBSD implementation does not change the user's passed-in diff --git a/open-vm-tools/lib/include/vmblock_user.h b/open-vm-tools/lib/include/vmblock_user.h index 8c76d3750..d0a482f93 100644 --- a/open-vm-tools/lib/include/vmblock_user.h +++ b/open-vm-tools/lib/include/vmblock_user.h @@ -129,7 +129,7 @@ VMBLOCK_CONTROL(int fd, int op, const char *path) return write(fd, path, op); } -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) static INLINE int VMBLOCK_CONTROL(int fd, int cmd, const char *path) diff --git a/open-vm-tools/lib/misc/codesetOld.c b/open-vm-tools/lib/misc/codesetOld.c index 00d55a2d1..8cb2f4314 100644 --- a/open-vm-tools/lib/misc/codesetOld.c +++ b/open-vm-tools/lib/misc/codesetOld.c @@ -70,7 +70,7 @@ #endif -#if defined(__FreeBSD__) || defined(sun) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sun) static const char nul[] = {'\0', '\0'}; #else static const wchar_t nul = L'\0'; diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index f525236f3..f7ad81125 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -41,7 +41,7 @@ #include #endif #include -#if defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include #endif #if !defined(__APPLE__) @@ -87,7 +87,7 @@ #endif #endif -#if defined(__APPLE__) || defined(__FreeBSD__) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) #include #endif @@ -114,6 +114,7 @@ #include "vmstdio.h" #include "su.h" #include "vm_atomic.h" +#include "vm_ctype.h" #if defined(__i386__) || defined(__x86_64__) #include "x86cpuid.h" @@ -340,7 +341,7 @@ HostinfoOSVersionInit(void) */ p = extra; - while (*p && !isdigit(*p)) { + while (*p && !CType_IsDigit(*p)) { p++; } sscanf(p, "%d", &version->hostinfoOSVersion[3]); @@ -477,8 +478,12 @@ Hostinfo_GetSystemBitness(void) } #else char buf[SYSTEM_BITNESS_MAXLEN] = { '\0', }; -# if defined __FreeBSD__ || defined __APPLE__ +# if defined __FreeBSD__ || defined __NetBSD__ || defined __APPLE__ +# if defined __NetBSD__ + static int mib[2] = { CTL_HW, HW_MACHINE_ARCH, }; +# else static int mib[2] = { CTL_HW, HW_MACHINE, }; +# endif size_t len = sizeof buf; if (sysctl(mib, ARRAYSIZE(mib), buf, &len, NULL, 0) == -1) { @@ -622,7 +627,7 @@ HostinfoOSDetailedData(void) escapedString[i] = '\0'; /* No trailing spaces */ - while (--i >= 0 && isspace(escapedString[i])) { + while (--i >= 0 && CType_IsSpace(escapedString[i])) { escapedString[i] = '\0'; } @@ -1335,7 +1340,7 @@ HostinfoGetOSShortName(const char *distro, // IN: full distro name /* The first digit in the distro string is the version */ while (*p != '\0') { - if (isdigit(*p)) { + if (CType_IsDigit(*p)) { versionStr = p; break; } @@ -2073,7 +2078,7 @@ HostinfoLinux(struct utsname *buf) // IN: * * HostinfoBSD -- * - * Determine the specifics concerning BSD. + * Determine the specifics concerning FreeBSD. * * Return value: * TRUE Success @@ -2134,6 +2139,55 @@ HostinfoBSD(struct utsname *buf) // IN: } +/* + *----------------------------------------------------------------------------- + * + * HostinfoNetBSD -- + * + * Determine the specifics concerning NetBSD. + * + * Return value: + * TRUE Success + * FALSE Failure + * + * Side effects: + * Cache values are set when returning TRUE + * + *----------------------------------------------------------------------------- + */ + +static Bool +HostinfoNetBSD(struct utsname *buf) // IN: +{ + int len; + int majorVersion; + char distroShort[DISTRO_BUF_SIZE]; + char osName[MAX_OS_NAME_LEN]; + char osNameFull[MAX_OS_FULLNAME_LEN]; + + majorVersion = Hostinfo_OSVersion(0); + + Str_Sprintf(distroShort, sizeof distroShort, "%s%s%d", + HostinfoArchString(), STR_OS_NETBSD, majorVersion); + len = Str_Snprintf(osNameFull, sizeof osNameFull, "%s %s", buf->sysname, + buf->release); + if (len != -1) { + if (Hostinfo_GetSystemBitness() == 64) { + len = Str_Snprintf(osName, sizeof osName, "%s%s", distroShort, + STR_OS_64BIT_SUFFIX); + } else { + len = Str_Snprintf(osName, sizeof osName, "%s", distroShort); + } + } + + if (len != -1) { + HostinfoPostData(osName, osNameFull); + } + + return len != -1; +} + + /* *----------------------------------------------------------------------------- * @@ -2252,6 +2306,8 @@ HostinfoOSData(void) success = HostinfoLinux(&buf); } else if (strstr(buf.sysname, "FreeBSD")) { success = HostinfoBSD(&buf); + } else if (strstr(buf.sysname, "NetBSD")) { + success = HostinfoNetBSD(&buf); } else if (strstr(buf.sysname, "SunOS")) { success = HostinfoSun(&buf); } else { @@ -3357,8 +3413,8 @@ HostinfoGetCpuInfo(int nCpu, // IN: e = s + strlen(s); /* Skip leading and trailing while spaces */ - for (; s < e && isspace(*s); s++); - for (; s < e && isspace(e[-1]); e--); + for (; s < e && CType_IsSpace(*s); s++); + for (; s < e && CType_IsSpace(e[-1]); e--); *e = 0; /* Free previous value */ @@ -4071,7 +4127,8 @@ HostinfoSysinfo(uint64 *totalRam, // OUT: Total RAM in bytes #endif // ifndef __APPLE__ -#if defined(__linux__) || defined(__FreeBSD__) || defined(sun) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(sun) /* *----------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c index 1bb86f483..4a89339c8 100644 --- a/open-vm-tools/lib/misc/idLinux.c +++ b/open-vm-tools/lib/misc/idLinux.c @@ -119,7 +119,7 @@ static AuthorizationRef IdAuthCreateWithFork(void); int Id_SetUid(uid_t euid) // IN: new euid { -#if defined(__FreeBSD__) || defined(sun) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sun) return setuid(euid); #elif defined(__linux__) || defined __ANDROID__ if (uid32) { @@ -162,7 +162,7 @@ Id_SetGid(gid_t egid) // IN: new egid Warning("XXXMACOS: implement %s\n", __func__); return -1; -#elif defined(sun) || defined(__FreeBSD__) +#elif defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) return setgid(egid); #else if (uid32) { @@ -365,7 +365,7 @@ Id_SetREUid(uid_t uid, // IN: new uid #if defined(__APPLE__) Warning("XXXMACOS: implement %s\n", __func__); return -1; -#elif defined(sun) || defined(__FreeBSD__) +#elif defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) return setreuid(uid, euid); #else if (uid32) { @@ -406,7 +406,7 @@ int Id_SetREGid(gid_t gid, // IN: new gid gid_t egid) // IN: new effective gid { -#if defined(sun) || defined(__FreeBSD__) +#if defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) return setregid(gid, egid); #else if (uid32) { diff --git a/open-vm-tools/lib/misc/posixPosix.c b/open-vm-tools/lib/misc/posixPosix.c index 236c18dbc..f4018a5ef 100644 --- a/open-vm-tools/lib/misc/posixPosix.c +++ b/open-vm-tools/lib/misc/posixPosix.c @@ -52,7 +52,7 @@ #include extern char **environ; #endif -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) #include #include #elif defined(sun) @@ -76,6 +76,10 @@ extern char **environ; # include // PATH_MAX # endif +#if defined(__NetBSD__) +#define statfs statvfs +#endif + #include "vmware.h" #include "posixInt.h" #if defined(sun) @@ -1806,7 +1810,8 @@ Posix_Unsetenv(const char *name) // IN: #if !defined(sun) // { -#if !defined(__APPLE__) && !defined(__FreeBSD__) // { +#if !defined(__APPLE__) && !defined(__FreeBSD__) && \ + !defined(__NetBSD__) // { /* *---------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index acecee504..d8da14079 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -1405,7 +1405,7 @@ StrUtil_TrimWhitespace(const char *str) // IN size_t len; /* Skip leading whitespace. */ - while (*cur && isspace(*cur)) { + while (*cur && CType_IsSpace(*cur)) { cur++; } @@ -1419,7 +1419,7 @@ StrUtil_TrimWhitespace(const char *str) // IN } cur = res + len - 1; - while (cur > res && isspace(*cur)) { + while (cur > res && CType_IsSpace(*cur)) { cur--; } diff --git a/open-vm-tools/lib/misc/util_misc.c b/open-vm-tools/lib/misc/util_misc.c index 9e57c3898..ba219b03b 100644 --- a/open-vm-tools/lib/misc/util_misc.c +++ b/open-vm-tools/lib/misc/util_misc.c @@ -331,7 +331,8 @@ Util_CanonicalPathsIdentical(const char *path1, // IN: Bool Util_IsAbsolutePath(const char *path) // IN: path to check { -#if defined __linux__ || defined __APPLE__ || defined __FreeBSD__ || defined sun +#if defined __linux__ || defined __APPLE__ || defined __FreeBSD__ || \ + defined __NetBSD__ || defined sun // path[0] is valid even for the empty string. return path && path[0] == DIRSEPC; #elif defined _WIN32 diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index b4a7b1362..09def0aca 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -64,6 +64,9 @@ # if defined __linux__ # include // for gettid(2) # endif +# if defined __NetBSD__ + #include +# endif # include #endif #include @@ -352,6 +355,8 @@ VThreadBase_GetKernelID(void) # endif // Best effort until FreeBSD header update return (uint64)(uintptr_t)(void *)pthread_self(); +#elif defined __NetBSD__ + return (uint64)_lwp_self(); #else # error "Unknown platform" #endif diff --git a/open-vm-tools/lib/netUtil/netUtilLinux.c b/open-vm-tools/lib/netUtil/netUtilLinux.c index 7a1c9f847..b41f23ef4 100644 --- a/open-vm-tools/lib/netUtil/netUtilLinux.c +++ b/open-vm-tools/lib/netUtil/netUtilLinux.c @@ -31,7 +31,8 @@ #endif -#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(sun) && !defined(__APPLE__) # error This file should not be compiled #endif @@ -59,7 +60,7 @@ #include #include // for ARPHRD_ETHER -#if defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) #include "ifaddrs.h" #endif @@ -150,7 +151,8 @@ ValidateConvertAddress(const char *ifaceName, // IN: interface name *---------------------------------------------------------------------- */ -#if !defined(__FreeBSD__) && !defined(__APPLE__) /* { */ +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(__APPLE__) /* { */ char * NetUtil_GetPrimaryIP(void) { diff --git a/open-vm-tools/lib/nicInfo/nicInfoInt.h b/open-vm-tools/lib/nicInfo/nicInfoInt.h index 47b484bfd..3d2b21d20 100644 --- a/open-vm-tools/lib/nicInfo/nicInfoInt.h +++ b/open-vm-tools/lib/nicInfo/nicInfoInt.h @@ -29,7 +29,8 @@ #include "nicInfo.h" -#if defined __FreeBSD__ || defined __sun__ || defined __APPLE__ +#if defined __FreeBSD__ || defined __NetBSD__ || defined __sun__ || \ + defined __APPLE__ # include // struct sockaddr #endif diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c index de57a4a90..22091fdd7 100644 --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c @@ -35,7 +35,7 @@ #include #include #include -#if defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include # include # include @@ -144,7 +144,8 @@ static Bool RecordRoutingInfo(unsigned int maxIPv4Routes, unsigned int maxIPv6Routes, NicInfoV3 *nicInfo); -#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(USERWORLD) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && \ + !defined(USERWORLD) typedef struct GuestInfoIpPriority { char *ipstr; NicInfoPriority priority; @@ -500,6 +501,7 @@ GuestInfoGetNicInfo(unsigned int maxIPv4Routes, ****************************************************************************** */ #if defined(__FreeBSD__) || \ + defined(__NetBSD__) || \ defined(__APPLE__) || \ defined(USERWORLD) || \ (defined(__linux__) && defined(NO_DNET)) @@ -1583,7 +1585,8 @@ RecordRoutingInfo(unsigned int maxIPv4Routes, #ifndef NO_DNET -#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(USERWORLD) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && \ + !defined(USERWORLD) /* ****************************************************************************** * GuestInfoGetIntf -- */ /** diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index b45cccb0a..f0644719c 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -27,7 +27,8 @@ // pull in setresuid()/setresgid() if possible #define _GNU_SOURCE #include -#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(sun) && \ + !defined(__APPLE__) #include #endif #if !defined(sun) && !defined(__APPLE__) @@ -53,7 +54,7 @@ // Pull in PAGE_SIZE/PAGE_SHIFT defines ahead of vm_basic_defs.h # include #endif -#if defined (__FreeBSD__) +#if defined (__FreeBSD__) || defined(__NetBSD__) #include #include #include @@ -170,7 +171,7 @@ Bool ProcMgr_PromoteEffectiveToReal(void); *---------------------------------------------------------------------- */ -#if defined(__linux__) +#if defined(__linux__) || defined(__NetBSD__) int ProcMgr_ReadProcFile(int fd, // IN char **contents) // OUT @@ -664,7 +665,7 @@ ProcMgr_ListProcesses(void) return procList; } -#endif // defined(__linux__) +#endif // defined(__linux__) || defined(__NetBSD__) /* @@ -2228,7 +2229,8 @@ ProcMgr_Free(ProcMgr_AsyncProc *asyncProc) // IN free(asyncProc); } -#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(__APPLE__) /* *---------------------------------------------------------------------- @@ -2308,7 +2310,7 @@ ProcMgr_ImpersonateUserStart(const char *user, // IN: UTF-8 encoded user name // first change group #if defined(USERWORLD) ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__NetBSD__) ret = setegid(ppw->pw_gid); #else ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid); @@ -2329,7 +2331,7 @@ ProcMgr_ImpersonateUserStart(const char *user, // IN: UTF-8 encoded user name // now user #if defined(USERWORLD) ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__NetBSD__) ret = seteuid(ppw->pw_uid); #else ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); @@ -2391,7 +2393,7 @@ ProcMgr_ImpersonateUserStop(void) // first change back user #if defined(USERWORLD) ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__NetBSD__) ret = seteuid(ppw->pw_uid); #else ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); @@ -2404,7 +2406,7 @@ ProcMgr_ImpersonateUserStop(void) // now group #if defined(USERWORLD) ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__NetBSD__) ret = setegid(ppw->pw_gid); #else ret = setresgid(ppw->pw_gid, ppw->pw_gid, ppw->pw_gid); diff --git a/open-vm-tools/lib/rpcChannel/rpcChannel.c b/open-vm-tools/lib/rpcChannel/rpcChannel.c index 453c675a3..38240075c 100644 --- a/open-vm-tools/lib/rpcChannel/rpcChannel.c +++ b/open-vm-tools/lib/rpcChannel/rpcChannel.c @@ -308,7 +308,11 @@ RpcChannelXdrWrapper(RpcInData *data, goto exit; } +#if defined __NetBSD__ + if (!xdrProc(&xdrs, copy.result)) { +#else if (!xdrProc(&xdrs, copy.result, 0)) { +#endif ret = RPCIN_SETRETVALS(data, "XDR serialization failed.", FALSE); /* @@ -378,7 +382,11 @@ RpcChannel_BuildXdrCommand(const char *cmd, goto exit; } +#if defined __NetBSD__ + if (!proc(&xdrs, xdrData)) { +#else if (!proc(&xdrs, xdrData, 0)) { +#endif goto exit; } diff --git a/open-vm-tools/lib/system/systemLinux.c b/open-vm-tools/lib/system/systemLinux.c index a688ab250..9d58744fc 100644 --- a/open-vm-tools/lib/system/systemLinux.c +++ b/open-vm-tools/lib/system/systemLinux.c @@ -26,7 +26,8 @@ * */ -#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(sun) && !defined(__APPLE__) # error This file should not be compiled #endif @@ -59,7 +60,7 @@ # include #endif -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ #include "ifaddrs.h" #endif @@ -315,7 +316,7 @@ System_Shutdown(Bool reboot) // IN: "reboot or shutdown" flag cmd = "/sbin/shutdown -r now"; #endif } else { -#if __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ cmd = "/sbin/shutdown -p now"; #elif defined(sun) cmd = "/usr/sbin/shutdown -g 0 -i 5 -y"; diff --git a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c index 3fa635c98..9e55b0ca0 100644 --- a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c +++ b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c @@ -2439,7 +2439,7 @@ UnicodeNormalizeEncodingName(const char *encodingName) // IN for (currentResult = result; *encodingName != '\0'; encodingName++) { // The explicit cast from char to int is necessary for Netware builds. if (isalnum((int) *encodingName)) { - *currentResult = tolower(*encodingName); + *currentResult = tolower(*encodingName & 0xff); currentResult++; } } diff --git a/open-vm-tools/lib/wiper/wiperPosix.c b/open-vm-tools/lib/wiper/wiperPosix.c index a34d86759..6f3af7d65 100644 --- a/open-vm-tools/lib/wiper/wiperPosix.c +++ b/open-vm-tools/lib/wiper/wiperPosix.c @@ -23,7 +23,8 @@ * */ -#if !defined(__linux__) && !defined(sun) && !defined(__FreeBSD__) && !defined(__APPLE__) +#if !defined(__linux__) && !defined(sun) && !defined(__FreeBSD__) && \ + !defined(__NetBSD__) && !defined(__APPLE__) #error This file should not be compiled on this platform. #endif @@ -34,14 +35,15 @@ # include # endif # include -#elif defined(__FreeBSD__) || defined(__APPLE__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include # include # include # include -# if defined(__FreeBSD_version) && __FreeBSD_version >= 500000 +# if (defined(__FreeBSD_version) && __FreeBSD_version >= 500000) || \ + defined(__NetBSD__) # include -# endif /* __FreeBSD_version >= 500000 */ +# endif /* __FreeBSD_version >= 500000 || __NetBSD__ */ #endif #include @@ -74,7 +76,7 @@ #if defined(sun) || defined(__linux__) # define PROCFS "proc" -#elif defined(__FreeBSD__) || defined(__APPLE__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) # define PROCFS "procfs" #endif @@ -387,6 +389,35 @@ WiperIsDiskDevice(MNTINFO *mnt, // IN: file system being considered return retval; } +#elif defined(__NetBSD__) /* } { */ + +static Bool +WiperIsDiskDevice(MNTINFO *mnt, // IN: file system being considered + struct stat *s) // IN: stat(2) info of fs source +{ + Bool retval = FALSE; + +#define MASK_WEDGE_DISK "dk" +#define MASK_WD_DISK "wd" +#define MASK_SD_DISK "sd" +#define MASK_LD_DISK "ld" + if (S_ISCHR(s->st_mode)) { + char *name = basename(MNTINFO_NAME(mnt)); + if ((strncmp(name, MASK_WEDGE_DISK, sizeof MASK_WEDGE_DISK - 1) == 0) || + (strncmp(name, MASK_WD_DISK, sizeof MASK_WD_DISK - 1) == 0) || + (strncmp(name, MASK_SD_DISK, sizeof MASK_SD_DISK - 1) == 0) || + (strncmp(name, MASK_LD_DISK, sizeof MASK_LD_DISK - 1) == 0)) { + retval = TRUE; + } + } +#undef MASK_WEDGE_DISK +#undef MASK_WD_DISK +#undef MASK_SD_DISK +#undef MASK_LD_DISK + + return retval; +} + #elif defined(__APPLE__) /* } { */ static Bool @@ -626,7 +657,7 @@ WiperSinglePartition_GetSpace(const WiperPartition *p, // IN uint64 *free, // OUT/OPT uint64 *total) // OUT { -#ifdef sun +#if defined sun || defined __NetBSD__ struct statvfs statfsbuf; #else struct statfs statfsbuf; @@ -635,7 +666,7 @@ WiperSinglePartition_GetSpace(const WiperPartition *p, // IN ASSERT(p); -#ifdef sun +#if defined sun || defined __NetBSD__ if (statvfs(p->mountPoint, &statfsbuf) < 0) { #else if (Posix_Statfs(p->mountPoint, &statfsbuf) < 0) { diff --git a/open-vm-tools/lib/xdg/xdg.c b/open-vm-tools/lib/xdg/xdg.c index 7f93becf3..2b14ae21e 100644 --- a/open-vm-tools/lib/xdg/xdg.c +++ b/open-vm-tools/lib/xdg/xdg.c @@ -33,6 +33,7 @@ #include "vmware.h" #include "vmstdio.h" +#include "vm_ctype.h" #include "xdg.h" @@ -91,7 +92,7 @@ Xdg_DetectDesktopEnv(void) int i; for (i = 0; i < outLen; i++) { - if (!isalnum(outbuf[i])) { + if (!CType_IsAlnum(outbuf[i])) { g_debug("%s: received malformed input\n", __func__); free(outbuf); outbuf = NULL; diff --git a/open-vm-tools/libguestlib/Makefile.am b/open-vm-tools/libguestlib/Makefile.am index d2cfb80a5..b57bf1aa6 100644 --- a/open-vm-tools/libguestlib/Makefile.am +++ b/open-vm-tools/libguestlib/Makefile.am @@ -51,8 +51,10 @@ libguestlib_la_SOURCES += $(libguestlib_rpcchanneldir)/simpleSocket.c endif libguestlib_la_LDFLAGS = +if !NETBSD libguestlib_la_LDFLAGS += -Wl,-ldl libguestlib_la_LDFLAGS += -Wl,-lrt +endif # We require GCC, so we're fine passing compiler-specific flags. # Needed for OS's that don't link shared libraries against libc by default, e.g. FreeBSD libguestlib_la_LDFLAGS += -Wl,-lc diff --git a/open-vm-tools/scripts/netbsd/network b/open-vm-tools/scripts/netbsd/network new file mode 100644 index 000000000..bd1d7c661 --- /dev/null +++ b/open-vm-tools/scripts/netbsd/network @@ -0,0 +1,89 @@ +#!/bin/sh +########################################################## +# Copyright (C) 2010-2017 VMware, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation version 2.1 and no later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +########################################################## + +########################################################################## +# DO NOT modify this file directly as it will be overwritten the next +# time the VMware Tools are installed. +########################################################################## + +# +# network (NetBSD) +# +# This script uses NetBSD's rc(8) scripts to stop and restart networking +# services in response to suspend and resume events, respectively. +# + + +echo `date` ": Executing '$0'" +echo + +. `dirname "$0"`/../../statechange.subr + + +# +# ToggleNetwork -- +# +# Sources native configuration files in a subshell and executes native +# scripts to either start or stop networking services associated with +# a single interface. +# +# Results: +# See description above. +# +# Side effects: +# All side effects implied by NetBSD's rc.d scripts. +# + +ToggleNetwork() { + ( + /etc/rc.d/dhcpcd $1 + ) +} + + +# +# main -- +# +# Main entry point. Perform some sanity checking, then map state change +# events to relevant networking operations. +# +# Results: +# See comment at top of file. +# + +main() { + exitCode=0 + + [ -x /etc/rc.d/dhcpcd ] || \ + Panic "Cannot find an executable /etc/rc.d/dhcpcd" + + case "$1" in + suspend-vm) + ToggleNetwork stop + ;; + resume-vm) + ToggleNetwork start + ;; + *) ;; + esac + + return $exitCode +} + +main "$@" diff --git a/open-vm-tools/scripts/netbsd/network.orig b/open-vm-tools/scripts/netbsd/network.orig new file mode 100644 index 000000000..e69de29bb diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c b/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c index 219065f74..a8816d35a 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c @@ -28,6 +28,9 @@ #include #include #include +#if defined(__NetBSD__) +#include +#endif #include "vmware.h" #include "dndInt.h" @@ -40,7 +43,8 @@ #include "util.h" #include "escape.h" #include "su.h" -#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) +#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) || \ + defined(__NetBSD__) #include "vmblock_user.h" #include "mntinfo.h" #endif @@ -278,7 +282,8 @@ DnD_UriIsNonFileSchemes(const char *uri) /* We need to make this suck less. */ -#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) +#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) || \ + defined(__NetBSD__) /* *---------------------------------------------------------------------------- @@ -736,7 +741,7 @@ DnD_CompleteBlockInitialization(int fd, // IN return TRUE; } -#endif /* linux || sun || FreeBSD */ +#endif /* linux || sun || FreeBSD || NetBSD */ /* diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c b/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c index da54ee585..bc1a3af57 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c @@ -29,7 +29,7 @@ #include #include -#if defined __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ #include #endif diff --git a/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c b/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c index 3f7372a49..bf32244f7 100644 --- a/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c +++ b/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c @@ -1540,8 +1540,10 @@ Bool GuestInfoTakeSample(DynBuf *statBuf) // IN/OUT: inited, ready to fill { GuestInfoCollector *temp; +#if !defined __NetBSD__ locale_t newLoc; locale_t prevLoc; +#endif ASSERT(statBuf && DynBuf_GetSize(statBuf) == 0); @@ -1568,6 +1570,7 @@ GuestInfoTakeSample(DynBuf *statBuf) // IN/OUT: inited, ready to fill return FALSE; } +#if !defined __NetBSD__ /* * Switch the current thread to "C" locale to parse /proc files. * @@ -1591,6 +1594,7 @@ GuestInfoTakeSample(DynBuf *statBuf) // IN/OUT: inited, ready to fill } else { g_warning("%s: newlocale failed, error=%d.\n", __FUNCTION__, errno); } +#endif /* Collect the current data */ GuestInfoCollect(gCurrentCollector); @@ -1598,11 +1602,13 @@ GuestInfoTakeSample(DynBuf *statBuf) // IN/OUT: inited, ready to fill /* Encode the captured data */ GuestInfoEncodeStats(gCurrentCollector, gPreviousCollector, statBuf); +#if !defined __NetBSD__ if (newLoc != (locale_t)0) { /* Restore thread previous locale */ uselocale(prevLoc); freelocale(newLoc); } +#endif /* Switch the collections for next time. */ temp = gCurrentCollector; diff --git a/open-vm-tools/services/plugins/timeSync/Makefile.am b/open-vm-tools/services/plugins/timeSync/Makefile.am index d05028516..1b541d6d9 100644 --- a/open-vm-tools/services/plugins/timeSync/Makefile.am +++ b/open-vm-tools/services/plugins/timeSync/Makefile.am @@ -39,6 +39,10 @@ if FREEBSD libtimeSync_la_SOURCES += slewAdjtime.c libtimeSync_la_SOURCES += pllNone.c endif +if NETBSD +libtimeSync_la_SOURCES += slewAdjtime.c +libtimeSync_la_SOURCES += pllNone.c +endif if LINUX libtimeSync_la_SOURCES += slewLinux.c libtimeSync_la_SOURCES += pllLinux.c diff --git a/open-vm-tools/services/plugins/vix/vixTools.c b/open-vm-tools/services/plugins/vix/vixTools.c index 34f3125d2..6df99a284 100644 --- a/open-vm-tools/services/plugins/vix/vixTools.c +++ b/open-vm-tools/services/plugins/vix/vixTools.c @@ -66,7 +66,8 @@ #include #endif -#if defined(sun) || defined(__FreeBSD__) || defined(__APPLE__) +#if defined(sun) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(__APPLE__) #include #endif @@ -1592,7 +1593,7 @@ VixToolsRunProgramImpl(char *requestName, // IN si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = (VIX_RUNPROGRAM_ACTIVATE_WINDOW & runProgramOptions) ? SW_SHOWNORMAL : SW_MINIMIZE; -#elif !defined(__FreeBSD__) +#elif !defined(__FreeBSD__) && !defined(__NetBSD__) procArgs.envp = VixToolsEnvironmentTableToEnvp(userEnvironmentTable); #endif @@ -1761,7 +1762,8 @@ VixToolsStartProgramImpl(const char *requestName, // IN * For non-Windows, we use the user's $HOME if workingDir isn't supplied. */ if (NULL == workingDir) { -#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined(__APPLE__) char *username = NULL; if (!ProcMgr_GetImpersonatedUserInfo(&username, &workingDirectory)) { @@ -2671,7 +2673,7 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef, // IN VixPropertyListImpl propList; char *serializedBuffer = NULL; size_t serializedBufferLength = 0; -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) char *guestName; int osFamily; char *packageList = NULL; @@ -2885,7 +2887,7 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef, // IN free(powerOffScript); #else /* - * FreeBSD. We do not require all the properties above. + * FreeBSD/NetBSD. We do not require all the properties above. * We only Support VMODL Guest Ops for now (Bug 228398). */ @@ -2930,7 +2932,7 @@ VixTools_GetToolsPropertiesImpl(GKeyFile *confDictRef, // IN quit: VixPropertyList_RemoveAllWithoutHandles(&propList); free(serializedBuffer); -#endif // __FreeBSD__ +#endif // __FreeBSD__ || __NetBSD__ return err; } // VixTools_GetToolsPropertiesImpl @@ -4366,7 +4368,7 @@ VixToolsGetMultipleEnvVarsForUser(void *userToken, // IN char *resultLocal = Util_SafeStrdup(""); // makes the loop cleaner. VixToolsUserEnvironment *env; -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ if (NULL == userEnvironmentTable) { err = VIX_E_FAIL; free(resultLocal); @@ -4383,7 +4385,7 @@ VixToolsGetMultipleEnvVarsForUser(void *userToken, // IN for (i = 0; i < numNames; i++) { char *value; -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ /* * We should check the original envp for all vars except * a few allowlisted ones that we set/unset on impersonate @@ -4482,7 +4484,7 @@ VixToolsGetAllEnvVarsForUser(void *userToken, // IN char *resultLocal; VixToolsEnvIterator *itr; char *envVar; -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ char **envp; if (NULL == userEnvironmentTable) { err = VIX_E_FAIL; @@ -4498,7 +4500,7 @@ VixToolsGetAllEnvVarsForUser(void *userToken, // IN resultLocal = Util_SafeStrdup(""); // makes the loop cleaner. -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ err = VixToolsNewEnvIterator(userToken, envp, &itr); #else err = VixToolsNewEnvIterator(userToken, &itr); @@ -4510,7 +4512,7 @@ VixToolsGetAllEnvVarsForUser(void *userToken, // IN while ((envVar = VixToolsGetNextEnvVar(itr)) != NULL) { char *tmp = resultLocal; char *tmpVal; -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ /* * For variables we change during Impersonatation of user, * we need to fetch from getenv() system call, all else @@ -4566,7 +4568,7 @@ VixToolsGetAllEnvVarsForUser(void *userToken, // IN quit: VixToolsDestroyEnvIterator(itr); -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ VixToolsFreeEnvp(envp); #endif *result = resultLocal; @@ -4783,7 +4785,7 @@ VixToolsMoveObject(VixCommandRequestHeader *requestMsg) // IN * Be careful. Renaming a file to itself can cause it to be deleted. * This should be a no-op anyway. */ -#if !defined(sun) && !defined(__FreeBSD__) +#if !defined(sun) && !defined(__FreeBSD__) && !defined(__NetBSD__) if (File_IsSameFile(srcFilePathName, destFilePathName)) { err = VIX_OK; goto quit; @@ -6871,7 +6873,8 @@ VixToolsGetFileExtendedInfoLength(const char *filePathName, // IN fileExtendedInfoBufferSize += 10 * 3; // uid, gid, perms #endif -#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) +#if defined(__linux__) || defined(sun) || defined(__FreeBSD__) || \ + defined(__NetBSD__) if (File_IsSymLink(filePathName)) { char *symlinkTarget; symlinkTarget = Posix_ReadLink(filePathName); diff --git a/open-vm-tools/services/plugins/vix/vixToolsEnvVars.c b/open-vm-tools/services/plugins/vix/vixToolsEnvVars.c index e0d4efc5a..7e493aa8b 100644 --- a/open-vm-tools/services/plugins/vix/vixToolsEnvVars.c +++ b/open-vm-tools/services/plugins/vix/vixToolsEnvVars.c @@ -94,7 +94,7 @@ struct VixToolsUserEnvironment { VixError VixToolsNewEnvIterator(void *userToken, // IN -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ char **envp, // IN #endif VixToolsEnvIterator **envItr) // OUT @@ -134,7 +134,7 @@ VixToolsNewEnvIterator(void *userToken, // IN } #elif defined(__APPLE__) it->environ = *_NSGetEnviron(); -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) it->environ = envp; #else it->environ = environ; diff --git a/open-vm-tools/services/plugins/vix/vixToolsInt.h b/open-vm-tools/services/plugins/vix/vixToolsInt.h index 03a6847f2..9611c8dc1 100644 --- a/open-vm-tools/services/plugins/vix/vixToolsInt.h +++ b/open-vm-tools/services/plugins/vix/vixToolsInt.h @@ -123,7 +123,7 @@ void VixToolsUnimpersonateUser(void *userToken); void VixToolsLogoutUser(void *userToken); VixError VixToolsNewEnvIterator(void *userToken, -#ifdef __FreeBSD__ +#if defined __FreeBSD__ || defined __NetBSD__ char **envp, #endif VixToolsEnvIterator **envItr); diff --git a/open-vm-tools/services/vmtoolsd/toolsRpc.c b/open-vm-tools/services/vmtoolsd/toolsRpc.c index d5a115b91..ef8c9b65d 100644 --- a/open-vm-tools/services/vmtoolsd/toolsRpc.c +++ b/open-vm-tools/services/vmtoolsd/toolsRpc.c @@ -129,7 +129,8 @@ ToolsCoreAppChannelFail(UNUSED_PARAM(gpointer _state)) #if !defined(__APPLE__) ToolsServiceState *state = _state; #endif -#if defined(__linux__) || defined(__FreeBSD__) || defined(sun) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(sun) static const char *vmusrGrepExpr = "'vmtoolsd.*vmusr'"; #if defined(sun) static const char *psCmd = "ps -aef"; diff --git a/open-vm-tools/vmblockmounter/Makefile.am b/open-vm-tools/vmblockmounter/Makefile.am index effb430a6..ffc8e2344 100644 --- a/open-vm-tools/vmblockmounter/Makefile.am +++ b/open-vm-tools/vmblockmounter/Makefile.am @@ -23,7 +23,7 @@ mount_vmblock_LDADD += ../lib/stubs/libStubs.la mount_vmblock_SOURCES = mount_vmblock_SOURCES += vmblockmounter.c -if FREEBSD +if BSD install-exec-hook: mv $(DESTDIR)$(sbindir)/mount.vmblock \ $(DESTDIR)$(sbindir)/mount_vmblock @@ -39,4 +39,4 @@ install-exec-hook: $(DESTDIR)/sbin/mount.vmblock &> /dev/null uninstall-hook: rm -f $(DESTDIR)/sbin/mount.vmblock -endif !FREEBSD +endif !BSD diff --git a/open-vm-tools/vmblockmounter/vmblockmounter.c b/open-vm-tools/vmblockmounter/vmblockmounter.c index 2735fd334..0c9fe91b7 100644 --- a/open-vm-tools/vmblockmounter/vmblockmounter.c +++ b/open-vm-tools/vmblockmounter/vmblockmounter.c @@ -29,7 +29,7 @@ #include #include #include -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) # include # include #endif @@ -235,6 +235,9 @@ main(int argc, // IN }; mntRes = nmount(iov, ARRAYSIZE(iov), MNT_NOSUID); } +#elif defined(__NetBSD__) + mntRes = mount(VMBLOCK_FS_NAME, mountPoint, 0, mountPoint, + strlen(mountPoint) + 1); #else #error "Unsupported OS" #endif diff --git a/open-vm-tools/vmhgfs-fuse/fsutil.h b/open-vm-tools/vmhgfs-fuse/fsutil.h index 34b6d489a..20882b645 100644 --- a/open-vm-tools/vmhgfs-fuse/fsutil.h +++ b/open-vm-tools/vmhgfs-fuse/fsutil.h @@ -32,7 +32,8 @@ #include "hgfsProto.h" #include -#if defined(__FreeBSD__) || defined(__SOLARIS__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SOLARIS__) || \ + defined(__APPLE__) typedef long long loff_t; #endif diff --git a/open-vm-tools/vmware-user-suid-wrapper/main.c b/open-vm-tools/vmware-user-suid-wrapper/main.c index e9d7e5084..78375b9e9 100644 --- a/open-vm-tools/vmware-user-suid-wrapper/main.c +++ b/open-vm-tools/vmware-user-suid-wrapper/main.c @@ -30,7 +30,8 @@ * vmware-user. */ -#if !defined(sun) && !defined(__FreeBSD__) && !defined(__linux__) +#if !defined(sun) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(__linux__) # error This program is not supported on your platform. #endif diff --git a/open-vm-tools/vmware-user-suid-wrapper/wrapper-netbsd.c b/open-vm-tools/vmware-user-suid-wrapper/wrapper-netbsd.c new file mode 100644 index 000000000..6dfc69dec --- /dev/null +++ b/open-vm-tools/vmware-user-suid-wrapper/wrapper-netbsd.c @@ -0,0 +1,136 @@ +/********************************************************* + * Copyright (C) 2007-2016 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation version 2.1 and no later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *********************************************************/ + +/* + * wrapper.c -- + * + * Platform specific code for the VMware User Agent setuid wrapper. + */ + + +#include +#include +#include +#include +#include + +#include "vmware.h" +#include "wrapper.h" + + +/* + * Global functions + */ + + +#ifdef USES_LOCATIONS_DB +/* + *----------------------------------------------------------------------------- + * + * BuildExecPath -- + * + * Determine & return path of vmware-user for use by execve(2). + * + * Results: + * TRUE on success, FALSE otherwise + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +Bool +BuildExecPath(char *execPath, // OUT: Buffer to store executable's path + size_t execPathSize) // IN : size of execPath buffer +{ + char tmpPath[MAXPATHLEN]; + int execLen; + + /* + * The locations database is the only path that's fixed, and it contains the + * paths to all the other paths selected during Tools configuration. The + * locations database file is only writable by root, so we can trust it. + */ + if (!QueryLocationsDB(LOCATIONS_PATH, QUERY_BINDIR, tmpPath, sizeof tmpPath)) { + Error("could not obtain BINDIR\n"); + return FALSE; + } + + if (strlcat(tmpPath, + "/vmware-user-wrapper", sizeof tmpPath) >= sizeof tmpPath) { + Error("could not construct program filename\n"); + return FALSE; + } + + /* + * From readlink(2), "The readlink() system call does not append a NUL + * character to buf." (NB: This breaks if user ever replaces the symlink + * with the target.) + */ + if ((execLen = readlink(tmpPath, execPath, execPathSize - 1)) == -1) { + Error("could not resolve symlink: %s\n", strerror(errno)); + return FALSE; + } + + execPath[execLen] = '\0'; + + /* + * Now make sure that the target is actually part of our "trusted" + * directory. (Check that execPath has LIBDIR as a prefix and does + * not contain "..".) + */ + if (!QueryLocationsDB(LOCATIONS_PATH, QUERY_LIBDIR, tmpPath, + sizeof tmpPath)) { + Error("could not obtain LIBDIR\n"); + return FALSE; + } + + if ((strncmp(execPath, tmpPath, strlen(tmpPath)) != 0) || + (strstr(execPath, "..") != NULL)) { + Error("vmware-user path untrusted\n"); + return FALSE; + } + + return TRUE; +} +#endif // ifdef USES_LOCATIONS_DB + + +/* + *---------------------------------------------------------------------------- + * + * CompatExec -- + * + * Simple platform-dependent execve() wrapper. + * + * Results: + * False. + * + * Side effects: + * This function may not return. + * + *---------------------------------------------------------------------------- + */ + +Bool +CompatExec(const char *path, char * const argv[], char * const envp[]) +{ + execve(path, argv, envp); + return FALSE; +}