diff --git a/README b/README index dfa71c20..adf2d684 100644 --- a/README +++ b/README @@ -265,6 +265,23 @@ Then to build libsmb2, run The process will copy the resulting libsmb2.a and the include/smb2 headers to your OpenOrbis SDK include folder. +Amiga (AmigaOS) +---------------------- +AmigaOS is Operating system which the main processor is a Microprocessor PowerPC. +There are 3 versions: +AmigaOS4(Makefile.AMIGA) +AmigaOS3(Makefile.AMIGA_OS3) +AmigaAROS(Makefile.AMIGA_AROS) +To compile libsmb2 for the AmigaOS, you need to set newlib.library V53.40 or newer (or V53.30 as included in 4.1 FE) and +filesysbox.library 54.4 or newer to set it up. + +Then to build libsmb2, choose the makefile acording your AmigaOS system and hit + $ cd lib + $ make -f Makefile.YOUR_AMIGA_OS_USED clean install + +The process will copy the resulting libsmb2.a and the include/smb2 headers in the bin folder inside of the lib folder +NOTE: Amiga AROS is a Open Source version of AmigaOS, So do not build this version unless you are using the AmigaAROS. + Dreamcast (KallistiOS) ---------------------- Hitachi SH4 in little-endian mode is the main CPU for the Dreamcast. diff --git a/Xbox 360/libsmb2.vcxproj b/Xbox 360/libsmb2.vcxproj index b9e7f77a..939df932 100644 --- a/Xbox 360/libsmb2.vcxproj +++ b/Xbox 360/libsmb2.vcxproj @@ -108,7 +108,7 @@ false $(OutDir)$(ProjectName).pch MultiThreadedDebug - _DEBUG;_XBOX;_LIB;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;XBOX_360_PLATFORM;HAVE_CONFIG_H + _DEBUG;_XBOX;_LIB;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;NEED_GETADDRINFO;NEED_FREEADDRINFO;XBOX_360_PLATFORM;HAVE_CONFIG_H Callcap CompileAsC ..\include\;..\include\smb2;..\include\msvc;..\include\msvc\sys;..\include\xbox 360 @@ -195,7 +195,7 @@ false $(OutDir)$(ProjectName).pch MultiThreaded - NDEBUG;_XBOX;_LIB;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;XBOX_360_PLATFORM;HAVE_CONFIG_H + NDEBUG;_XBOX;_LIB;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;NEED_GETADDRINFO;NEED_FREEADDRINFO;XBOX_360_PLATFORM;HAVE_CONFIG_H ..\include\;..\include\smb2;..\include\msvc;..\include\msvc\sys;..\include\xbox 360 CompileAsC AnySuitable diff --git a/Xbox/libsmb2.vcproj b/Xbox/libsmb2.vcproj index a1f7e998..dddd49bb 100644 --- a/Xbox/libsmb2.vcproj +++ b/Xbox/libsmb2.vcproj @@ -22,7 +22,7 @@ InlineFunctionExpansion="2" OptimizeForProcessor="2" AdditionalIncludeDirectories="..\include\;..\include\msvc;..\include\xbox;..\include\smb2" - PreprocessorDefinitions="_DEBUG;_XBOX;_LIB;XBOX_PLATFORM;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;HAVE_CONFIG_H" + PreprocessorDefinitions="_DEBUG;_XBOX;_LIB;XBOX_PLATFORM;NEED_POLL;NEED_GETADDRINFO;NEED_FREEADDRINFO;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;HAVE_CONFIG_H" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -126,7 +126,7 @@ OmitFramePointers="TRUE" OptimizeForProcessor="2" AdditionalIncludeDirectories="..\include\;..\include\msvc;..\include\xbox;..\include\smb2" - PreprocessorDefinitions="NDEBUG;_XBOX;_LIB;XBOX_PLATFORM;NEED_POLL;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;HAVE_CONFIG_H" + PreprocessorDefinitions="NDEBUG;_XBOX;_LIB;XBOX_PLATFORM;NEED_POLL;NEED_GETADDRINFO;NEED_FREEADDRINFO;NEED_GETPID;NEED_GETLOGIN_R;NEED_RANDOM;NEED_SRANDOM;HAVE_CONFIG_H" StringPooling="TRUE" RuntimeLibrary="0" BufferSecurityCheck="TRUE" diff --git a/examples/smb2-cat-async.c b/examples/smb2-cat-async.c index 0ee8477b..9464abd7 100644 --- a/examples/smb2-cat-async.c +++ b/examples/smb2-cat-async.c @@ -14,7 +14,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define _GNU_SOURCE #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -27,6 +29,16 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "libsmb2.h" #include "libsmb2-raw.h" +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +struct pollfd { + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, unsigned int nfds, int timo); +#endif + int is_finished; uint8_t buf[256 * 1024]; uint32_t pos; @@ -137,7 +149,6 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - if (smb2_connect_share_async(smb2, url->server, url->share, url->user, cf_cb, (void *)url->path) != 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); diff --git a/examples/smb2-cat-sync.c b/examples/smb2-cat-sync.c index 81e5b5db..3d7c6a4a 100644 --- a/examples/smb2-cat-sync.c +++ b/examples/smb2-cat-sync.c @@ -15,7 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -66,7 +68,6 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); exit(10); diff --git a/examples/smb2-ls-async.c b/examples/smb2-ls-async.c index 57f6af40..3c65784f 100644 --- a/examples/smb2-ls-async.c +++ b/examples/smb2-ls-async.c @@ -14,7 +14,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define _GNU_SOURCE #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -25,6 +27,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "libsmb2.h" #include "libsmb2-raw.h" +#ifdef __AROS__ +#include "asprintf.h" +#endif + +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +struct pollfd { + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, unsigned int nfds, int timo); +#endif + int is_finished; int usage(void) @@ -32,7 +48,7 @@ int usage(void) fprintf(stderr, "Usage:\n" "smb2-ls-async \n\n" "URL format: " - "smb://[@]>[:]//\n"); + "smb://[@]>[:]//\n"); exit(1); } @@ -73,7 +89,7 @@ void od_cb(struct smb2_context *smb2, int status, break; } t = (time_t)ent->st.smb2_mtime; - printf("%-20s %-9s %15"PRIu64" %s\n", ent->name, type, ent->st.smb2_size, asctime(localtime(&t))); + printf("%-20s %-9s %15"PRIu64" %s\n", ent->name, type, ent->st.smb2_size, asctime(localtime(&t))); } smb2_closedir(smb2, dir); @@ -139,9 +155,7 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - - if (smb2_connect_share_async(smb2, url->server, url->share, url->user, - cf_cb, (void *)url->path) != 0) { + if (smb2_connect_share_async(smb2, url->server, url->share, url->user, cf_cb, (void *)url->path) != 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); exit(10); } diff --git a/examples/smb2-ls-sync.c b/examples/smb2-ls-sync.c index 00bd8f58..22b17c45 100644 --- a/examples/smb2-ls-sync.c +++ b/examples/smb2-ls-sync.c @@ -14,7 +14,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define _GNU_SOURCE #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -25,6 +27,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "libsmb2.h" #include "libsmb2-raw.h" +#ifdef __AROS__ +#include "asprintf.h" +#endif + int usage(void) { fprintf(stderr, "Usage:\n" @@ -60,7 +66,6 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - if (smb2_connect_share(smb2, url->server, url->share, url->user) < 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); exit(10); diff --git a/examples/smb2-put-async.c b/examples/smb2-put-async.c index e108e327..017c5916 100644 --- a/examples/smb2-put-async.c +++ b/examples/smb2-put-async.c @@ -15,7 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -28,6 +30,16 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "libsmb2.h" #include "libsmb2-raw.h" +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +struct pollfd { + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, unsigned int nfds, int timo); +#endif + uint8_t buf[256 * 1024]; int usage(void) @@ -114,7 +126,6 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); exit(10); diff --git a/examples/smb2-put-sync.c b/examples/smb2-put-sync.c index 70e4a7ee..1dc25462 100644 --- a/examples/smb2-put-sync.c +++ b/examples/smb2-put-sync.c @@ -15,7 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -73,7 +75,6 @@ int main(int argc, char *argv[]) } smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED); - if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) { printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2)); exit(10); diff --git a/examples/smb2-share-enum.c b/examples/smb2-share-enum.c index 4c489036..42113945 100644 --- a/examples/smb2-share-enum.c +++ b/examples/smb2-share-enum.c @@ -14,7 +14,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define _GNU_SOURCE #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -25,6 +27,16 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "libsmb2.h" #include "libsmb2-raw.h" +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +struct pollfd { + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, unsigned int nfds, int timo); +#endif + int is_finished; int usage(void) diff --git a/examples/smb2-statvfs-sync.c b/examples/smb2-statvfs-sync.c index aa804dc2..81076a3b 100644 --- a/examples/smb2-statvfs-sync.c +++ b/examples/smb2-statvfs-sync.c @@ -15,7 +15,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include #include +#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) #include +#endif #include #include #include @@ -32,7 +34,7 @@ int usage(void) { fprintf(stderr, "Usage:\n" "smb2-statvfs-sync \n\n" - "URL format: " + "URL format: " "smb://[@][:]//\n"); exit(1); } diff --git a/include/amiga_os/config.h b/include/amiga_os/config.h new file mode 100644 index 00000000..aec590d4 --- /dev/null +++ b/include/amiga_os/config.h @@ -0,0 +1,118 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Whether or not TCP sockets should be allowed to linger after closure */ +#define CONFIGURE_OPTION_TCP_LINGER 1 + +/* Define to 1 if you have the header file. */ +/* #define HAVE_ARPA_INET_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +/* #define HAVE_GSSAPI_GSSAPI_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Whether we use gssapi_krb5 or not */ +/* #define HAVE_LIBKRB5 1 */ + +/* Define to 1 if you have the `nsl' library (-lnsl). */ +/* #undef HAVE_LIBNSL */ + +/* Define to 1 if you have the `socket' library (-lsocket). */ +/* #undef HAVE_LIBSOCKET */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_POLL_H */ + +/* Whether sockaddr struct has sa_len */ +#define HAVE_SOCKADDR_LEN 1 + +/* Whether we have sockaddr_Storage */ +/* #undef HAVE_SOCKADDR_STORAGE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_IOCTL_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_STAT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 +#ifdef __AROS__ +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 +#endif +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libsmb2" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libsmb2" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libsmb2 4.0.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libsmb2" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "4.0.0" + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "4.0.0" diff --git a/include/asprintf.h b/include/asprintf.h index e020b18d..2cac4bdb 100644 --- a/include/asprintf.h +++ b/include/asprintf.h @@ -2,7 +2,9 @@ #ifndef _ASPRINTF_H_ #define _ASPRINTF_H_ +#ifndef __AROS__ #include +#endif #include #include #include diff --git a/include/portable-endian.h b/include/portable-endian.h index 967b25d9..c9388b4c 100644 --- a/include/portable-endian.h +++ b/include/portable-endian.h @@ -209,6 +209,112 @@ # error platform not supported # endif +#elif defined(__amigaos4__) || defined(__AMIGA__) + +# if defined(__NEWLIB__) +# include + +# define htobe16(x) (x) +# define htole16(x) __bswap16(x) +# define be16toh(x) (x) +# define le16toh(x) __bswap16(x) + +# define htobe32(x) (x) +# define htole32(x) __bswap32(x) +# define be32toh(x) (x) +# define le32toh(x) __bswap32(x) + +# define htobe64(x) (x) +# define htole64(x) __bswap64(x) +# define be64toh(x) (x) +# define le64toh(x) __bswap64(x) + +# elif defined(__GNUC__) + +# define htobe16(x) (x) +# define htole16(x) __builtin_bswap16(x) +# define be16toh(x) (x) +# define le16toh(x) __builtin_bswap16(x) + +# define htobe32(x) (x) +# define htole32(x) __builtin_bswap32(x) +# define be32toh(x) (x) +# define le32toh(x) __builtin_bswap32(x) + +# define htobe64(x) (x) +# define htole64(x) __builtin_bswap64(x) +# define be64toh(x) (x) +# define le64toh(x) __builtin_bswap64(x) + +# else +# error platform not supported +# endif + +#elif defined(__AROS__) + +# include + +# if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 8)) + +# define __bswap16(x) __builtin_bswap16(x) +# define __bswap32(x) __builtin_bswap32(x) +# define __bswap64(x) __builtin_bswap64(x) + +# else + +# define __bswap16(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \ + (((uint16_t)(x) & 0x00FF) << 8)) +# define __bswap32(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \ + (((uint32_t)(x) & 0x00FF0000) >> 8) | \ + (((uint32_t)(x) & 0x0000FF00) << 8) | \ + (((uint32_t)(x) & 0x000000FF) << 24)) +# define __bswap64(x) ((((uint64_t)(x) & 0xFF00000000000000) >> 56) | \ + (((uint64_t)(x) & 0x00FF000000000000) >> 40) | \ + (((uint64_t)(x) & 0x0000FF0000000000) >> 24) | \ + (((uint64_t)(x) & 0x000000FF00000000) >> 8) | \ + (((uint64_t)(x) & 0x00000000FF000000) << 8) | \ + (((uint64_t)(x) & 0x0000000000FF0000) << 24) | \ + (((uint64_t)(x) & 0x000000000000FF00) << 40) | \ + (((uint64_t)(x) & 0x00000000000000FF) << 56)) + +# endif + +# if _BYTE_ORDER == _LITTLE_ENDIAN + +# define htobe16(x) __bswap16(x) +# define htole16(x) (x) +# define be16toh(x) __bswap16(x) +# define le16toh(x) (x) + +# define htobe32(x) __bswap32(x) +# define htole32(x) (x) +# define be32toh(x) __bswap32(x) +# define le32toh(x) (x) + +# define htobe64(x) __bswap64(x) +# define htole64(x) (x) +# define be64toh(x) __bswap64(x) +# define le64toh(x) (x) + +# else + +# define htobe16(x) (x) +# define htole16(x) __bswap16(x) +# define be16toh(x) (x) +# define le16toh(x) __bswap16(x) + +# define htobe32(x) (x) +# define htole32(x) __bswap32(x) +# define be32toh(x) (x) +# define le32toh(x) __bswap32(x) + +# define htobe64(x) (x) +# define htole64(x) __bswap64(x) +# define be64toh(x) (x) +# define le64toh(x) __bswap64(x) + +# endif + #elif defined(XBOX_360_PLATFORM) # include @@ -234,7 +340,7 @@ # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN -# elif defined(XBOX_PLATFORM) +#elif defined(XBOX_PLATFORM) # include # include diff --git a/lib/Makefile.AMIGA b/lib/Makefile.AMIGA new file mode 100644 index 00000000..955a2067 --- /dev/null +++ b/lib/Makefile.AMIGA @@ -0,0 +1,46 @@ +CC = ppc-amigaos-gcc +AR = ppc-amigaos-ar +RANLIB = ppc-amigaos-ranlib +STRIP = ppc-amigaos-strip + +OPTIMIZE = -O2 +DEBUG = -gstabs +WARNINGS = -Wall -Werror -Wwrite-strings +INCLUDES = -I. -I../include -I../include/smb2 -I../include/amiga_os +DEFINES = -DHAVE_CONFIG_H "-D_U_=__attribute__((unused))" -DNEED_POLL -DNEED_GETADDRINFO -DNEED_FREEADDRINFO -DNEED_GETLOGIN_R -DNEED_RANDOM -DNEED_SRANDOM + +CFLAGS = $(OPTIMIZE) $(DEBUG) $(WARNINGS) $(INCLUDES) $(DEFINES) + +STRIPFLAGS = -R.comment --strip-unneeded-rel-relocs + +SRCS = aes.c aes128ccm.c alloc.c dcerpc.c dcerpc-lsa.c dcerpc-srvsvc.c \ + errors.c init.c hmac.c hmac-md5.c krb5-wrapper.c libsmb2.c md4c.c \ + md5.c ntlmssp.c pdu.c sha1.c sha224-256.c sha384-512.c \ + smb2-cmd-close.c smb2-cmd-create.c smb2-cmd-echo.c smb2-cmd-error.c \ + smb2-cmd-flush.c smb2-cmd-ioctl.c smb2-cmd-logoff.c \ + smb2-cmd-negotiate.c smb2-cmd-query-directory.c smb2-cmd-query-info.c \ + smb2-cmd-read.c smb2-cmd-session-setup.c smb2-cmd-set-info.c \ + smb2-cmd-tree-connect.c smb2-cmd-tree-disconnect.c smb2-cmd-write.c \ + smb2-data-file-info.c smb2-data-filesystem-info.c \ + smb2-data-security-descriptor.c smb2-data-reparse-point.c \ + smb2-share-enum.c smb3-seal.c smb2-signing.c socket.c sync.c \ + timestamps.c unicode.c usha.c compat.c + +OBJS = $(addprefix obj/,$(SRCS:.c=.o)) + +.PHONY: all +all: bin/libsmb2.a + +obj/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c -o $@ $< + +bin/libsmb2.a: $(OBJS) + @mkdir -p $(dir $@) + $(AR) -crv $@ $^ + $(RANLIB) $@ + +.PHONY: clean +clean: + rm -rf bin obj + diff --git a/lib/Makefile.AMIGA_AROS b/lib/Makefile.AMIGA_AROS new file mode 100644 index 00000000..1290859c --- /dev/null +++ b/lib/Makefile.AMIGA_AROS @@ -0,0 +1,59 @@ +CPU ?= i386 + +CC = $(CPU)-aros-gcc +AR = $(CPU)-aros-ar +RANLIB = $(CPU)-aros-ranlib +STRIP = $(CPU)-aros-strip + +OPTIMIZE = -O2 -fno-common -fomit-frame-pointer +DEBUG = -g +WARNINGS = -Wall -Werror +INCLUDES = -I. -I../include -I../include/smb2 -I../include/amiga_os +DEFINES = -DHAVE_CONFIG_H "-D_U_=__attribute__((unused))" -DNEED_POLL -DNEED_GETADDRINFO -DNEED_FREEADDRINFO -DNEED_GETLOGIN_R + +ifeq (x86_64,$(CPU)) + # Fixes duplicate member th_off/th_x2 errors in + # on x86_64 ABIv11 target. + DEFINES += -D__BSD_VISIBLE +endif + +CFLAGS = -std=gnu99 $(OPTIMIZE) $(DEBUG) $(WARNINGS) $(INCLUDES) $(DEFINES) + +LIBS = -lnet + +ifneq (,$(SYSROOT)) + CFLAGS := --sysroot=$(SYSROOT) $(CFLAGS) + LDFLAGS := --sysroot=$(SYSROOT) $(LDFLAGS) +endif + +SRCS = aes.c aes128ccm.c alloc.c dcerpc.c dcerpc-lsa.c dcerpc-srvsvc.c \ + errors.c init.c hmac.c hmac-md5.c krb5-wrapper.c libsmb2.c md4c.c \ + md5.c ntlmssp.c pdu.c sha1.c sha224-256.c sha384-512.c \ + smb2-cmd-close.c smb2-cmd-create.c smb2-cmd-echo.c smb2-cmd-error.c \ + smb2-cmd-flush.c smb2-cmd-ioctl.c smb2-cmd-logoff.c \ + smb2-cmd-negotiate.c smb2-cmd-query-directory.c smb2-cmd-query-info.c \ + smb2-cmd-read.c smb2-cmd-session-setup.c smb2-cmd-set-info.c \ + smb2-cmd-tree-connect.c smb2-cmd-tree-disconnect.c smb2-cmd-write.c \ + smb2-data-file-info.c smb2-data-filesystem-info.c \ + smb2-data-security-descriptor.c smb2-data-reparse-point.c \ + smb2-share-enum.c smb3-seal.c smb2-signing.c socket.c sync.c \ + timestamps.c unicode.c usha.c compat.c + +OBJS = $(addprefix obj/$(CPU)/,$(SRCS:.c=.o)) + +.PHONY: all +all: bin/libsmb2.a.$(CPU) + +obj/$(CPU)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c -o $@ $< + +bin/libsmb2.a.$(CPU): $(OBJS) + @mkdir -p $(dir $@) + $(AR) -crv $@ $^ + $(RANLIB) $@ + +.PHONY: clean +clean: + rm -rf bin obj + diff --git a/lib/Makefile.AMIGA_OS3 b/lib/Makefile.AMIGA_OS3 new file mode 100644 index 00000000..bb00f727 --- /dev/null +++ b/lib/Makefile.AMIGA_OS3 @@ -0,0 +1,59 @@ +CC = m68k-amigaos-gcc +AR = m68k-amigaos-ar +RANLIB = m68k-amigaos-ranlib +STRIP = m68k-amigaos-strip + +OPTIMIZE = -O2 -noixemul -fno-common -fomit-frame-pointer +DEBUG = -g +WARNINGS = -Wall -Wno-pointer-sign -Wno-discarded-qualifiers -Werror +INCLUDES = -I. -I../include -I../include/smb2 -I../include/amiga_os +DEFINES = -DHAVE_CONFIG_H "-D_U_=__attribute__((unused))" -DNEED_POLL -DNEED_GETADDRINFO -DNEED_FREEADDRINFO -DNEED_GETLOGIN_R -DNEED_RANDOM -DNEED_SRANDOM + +CFLAGS = $(OPTIMIZE) $(DEBUG) $(WARNINGS) $(INCLUDES) $(DEFINES) + +STRIPFLAGS = -R.comment + +SRCS = aes.c aes128ccm.c alloc.c dcerpc.c dcerpc-lsa.c dcerpc-srvsvc.c \ + errors.c init.c hmac.c hmac-md5.c krb5-wrapper.c libsmb2.c md4c.c \ + md5.c ntlmssp.c pdu.c sha1.c sha224-256.c sha384-512.c \ + smb2-cmd-close.c smb2-cmd-create.c smb2-cmd-echo.c smb2-cmd-error.c \ + smb2-cmd-flush.c smb2-cmd-ioctl.c smb2-cmd-logoff.c \ + smb2-cmd-negotiate.c smb2-cmd-query-directory.c smb2-cmd-query-info.c \ + smb2-cmd-read.c smb2-cmd-session-setup.c smb2-cmd-set-info.c \ + smb2-cmd-tree-connect.c smb2-cmd-tree-disconnect.c smb2-cmd-write.c \ + smb2-data-file-info.c smb2-data-filesystem-info.c \ + smb2-data-security-descriptor.c smb2-data-reparse-point.c \ + smb2-share-enum.c smb3-seal.c smb2-signing.c socket.c sync.c \ + timestamps.c unicode.c usha.c compat.c + +ARCH_000 = -mcpu=68000 -mtune=68000 +OBJS_000 = $(addprefix obj/68000/,$(SRCS:.c=.o)) + +ARCH_020 = -mcpu=68020 -mtune=68020-60 +OBJS_020 = $(addprefix obj/68020/,$(SRCS:.c=.o)) + +.PHONY: all +all: bin/libsmb2.a.000 bin/libsmb2.a.020 + +obj/68000/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(ARCH_000) $(CFLAGS) -c -o $@ $< + +obj/68020/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(ARCH_020) $(CFLAGS) -c -o $@ $< + +bin/libsmb2.a.000: $(OBJS_000) + @mkdir -p $(dir $@) + $(AR) -crv $@ $^ + $(RANLIB) $@ + +bin/libsmb2.a.020: $(OBJS_020) + @mkdir -p $(dir $@) + $(AR) -crv $@ $^ + $(RANLIB) $@ + +.PHONY: clean +clean: + rm -rf bin obj + diff --git a/lib/Makefile.PS3_PPU b/lib/Makefile.PS3_PPU index 39c00d93..787413be 100644 --- a/lib/Makefile.PS3_PPU +++ b/lib/Makefile.PS3_PPU @@ -37,7 +37,7 @@ INCLUDE := ../include ../include/ps3 ../include/smb2 DATA := data LIBS := -MACHDEP := -DPS3_PPU_PLATFORM -DHAVE_CONFIG_H -DNEED_READV -DNEED_WRITEV -DNEED_GETLOGIN_R -DNEED_RANDOM -DNEED_SRANDOM -D_U_=/**/ +MACHDEP := -DPS3_PPU_PLATFORM -DHAVE_CONFIG_H -DNEED_READV -DNEED_WRITEV -DNEED_GETLOGIN_R -DNEED_RANDOM -DNEED_SRANDOM -DNEED_GETADDRINFO -DNEED_FREEADDRINFO -D_U_=/**/ CFLAGS += -O2 -Wall -mcpu=cell $(MACHDEP) -fno-strict-aliasing $(INCLUDES) diff --git a/lib/compat.c b/lib/compat.c index b3a291b5..78b3b5d8 100644 --- a/lib/compat.c +++ b/lib/compat.c @@ -57,6 +57,32 @@ #endif +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +#define login_num ENXIO +#ifndef __amigaos4__ +#define NEED_READV +#define NEED_WRITEV +#include +#define read(fd, buf, count) recv(fd, buf, count, 0) +#define write(fd, buf, count) send(fd, buf, count, 0) +#ifndef __AROS__ +#define select(nfds, readfds, writefds, exceptfds, timeout) WaitSelect(nfds, readfds, writefds, exceptfds, timeout, NULL) +#define smb2_random rand +#define smb2_srandom srand +#endif +#ifdef libnix +StdFileDes *_lx_fhfromfd(int d) { return NULL; } +struct MinList __filelist = { (struct MinNode *) &__filelist.mlh_Tail, NULL, (struct MinNode *) &__filelist.mlh_Head }; +#endif +#endif + +#include +#include +#include +#include + +#endif + #ifdef PICO_PLATFORM #define NEED_BE64TOH @@ -71,42 +97,6 @@ #endif /* PICO_PLATFORM */ -#ifdef _XBOX - -int smb2_getaddrinfo(const char *node, const char*service, - const struct addrinfo *hints, - struct addrinfo **res) -{ - struct sockaddr_in *sin; - - sin = malloc(sizeof(struct sockaddr_in)); - sin->sin_family=AF_INET; - - /* Some error checking would be nice */ - sin->sin_addr.s_addr = inet_addr(node); - - sin->sin_port=0; - if (service) { - sin->sin_port=htons(atoi(service)); - } - - *res = malloc(sizeof(struct addrinfo)); - - (*res)->ai_family = AF_INET; - (*res)->ai_addrlen = sizeof(struct sockaddr_in); - (*res)->ai_addr = (struct sockaddr *)sin; - - return 0; -} - -void smb2_freeaddrinfo(struct addrinfo *res) -{ - free(res->ai_addr); - free(res); -} - -#endif - #ifdef PS2_EE_PLATFORM #include @@ -214,16 +204,53 @@ int iop_connect(int sockfd, struct sockaddr *addr, socklen_t addrlen) #define smb2_random rand #define smb2_srandom srand +#endif /* PS3_PPU_PLATFORM */ + +#ifdef NEED_GETADDRINFO int smb2_getaddrinfo(const char *node, const char*service, const struct addrinfo *hints, struct addrinfo **res) { struct sockaddr_in *sin; +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + struct hostent *host; + int i, ip[4]; +#endif +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + sin = calloc(1, sizeof(struct sockaddr_in)); +#else sin = malloc(sizeof(struct sockaddr_in)); +#endif +#ifndef _XBOX sin->sin_len = sizeof(struct sockaddr_in); - sin->sin_family=AF_INET; +#endif + sin->sin_family=AF_INET; + +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + /* Some error checking would be nice */ + if (sscanf(node, "%d.%d.%d.%d", ip, ip+1, ip+2, ip+3) == 4) { + for (i = 0; i < 4; i++) { + ((char *)&sin->sin_addr.s_addr)[i] = ip[i]; + } + } else { + host = gethostbyname(node); + if (host == NULL) { + return -1; + } + if (host->h_addrtype != AF_INET) { + return -2; + } + memcpy(&sin->sin_addr.s_addr, host->h_addr, 4); + } + + sin->sin_port=0; + if (service) { + sin->sin_port=htons(atoi(service)); + } + *res = calloc(1, sizeof(struct addrinfo)); +#else /* Some error checking would be nice */ sin->sin_addr.s_addr = inet_addr(node); @@ -233,21 +260,22 @@ int smb2_getaddrinfo(const char *node, const char*service, } *res = malloc(sizeof(struct addrinfo)); - +#endif (*res)->ai_family = AF_INET; (*res)->ai_addrlen = sizeof(struct sockaddr_in); (*res)->ai_addr = (struct sockaddr *)sin; return 0; } +#endif +#ifdef NEED_FREEADDRINFO void smb2_freeaddrinfo(struct addrinfo *res) { free(res->ai_addr); free(res); } - -#endif /* PS3_PPU_PLATFORM */ +#endif #ifdef NEED_RANDOM int random(void) @@ -394,6 +422,27 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) FD_ZERO(&ifds); FD_ZERO(&ofds); FD_ZERO(&efds); +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + op = ip = 0; + for (i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + fds[i].revents = 0; + if (fd < 0) + continue; + if(fds[i].events & (POLLIN|POLLPRI)) { + ip = &ifds; + FD_SET(fd, ip); + } + if(fds[i].events & POLLOUT) { + op = &ofds; + FD_SET(fd, op); + } + FD_SET(fd, &efds); + if (fd > maxfd) { + maxfd = fd; + } + } +#else for (i = 0, op = ip = 0; i < nfds; ++i) { fds[i].revents = 0; if(fds[i].events & (POLLIN|POLLPRI)) { @@ -409,7 +458,16 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) maxfd = fds[i].fd; } } +#endif + +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + if(timo >= 0) { + toptr = &timeout; + timeout.tv_sec = (unsigned)timo / 1000; + timeout.tv_usec = ((unsigned)timo % 1000) * 1000; + } +#else if(timo < 0) { toptr = NULL; } else { @@ -426,6 +484,7 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) timeout.tv_sec = timo / 1000; timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; #endif +#endif } rc = select(maxfd + 1, ip, op, &efds, toptr); @@ -433,6 +492,26 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) if(rc <= 0) return rc; +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + rc = 0; + for (i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + short events = fds[i].events; + short revents = 0; + if (fd < 0) + continue; + if(events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + revents |= POLLIN; + if(events & POLLOUT && FD_ISSET(fd, &ofds)) + revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) + revents |= POLLHUP; + if (revents) { + fds[i].revents = revents; + rc++; + } + } +#else if(rc > 0) { for (i = 0; i < nfds; ++i) { int fd = fds[i].fd; @@ -444,6 +523,7 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) fds[i].revents |= POLLHUP; } } +#endif return rc; } #endif diff --git a/lib/compat.h b/lib/compat.h index 3710a39e..9791103f 100644 --- a/lib/compat.h +++ b/lib/compat.h @@ -233,6 +233,72 @@ long long int be64toh(long long int x); #endif /* PS2_EE_PLATFORM */ +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) +#include +#include +#include +#include +#include +#if defined(__amigaos4__) || defined(__AROS__) +#include +#endif +int getlogin_r(char *buf, size_t size); +#ifndef __AROS__ +int random(void); +void srandom(unsigned int seed); +#endif +#if !defined(__amigaos4__) && (defined(__AMIGA__) || defined(__AROS__)) +#include +#undef HAVE_UNISTD_H +#define close CloseSocket +#undef getaddrinfo +#undef freeaddrinfo +#endif +#define strncpy(a,b,c) strcpy(a,b) +#define getaddrinfo smb2_getaddrinfo +#define freeaddrinfo smb2_freeaddrinfo +#define POLLIN 0x0001 /* There is data to read */ +#define POLLPRI 0x0002 /* There is urgent data to read */ +#define POLLOUT 0x0004 /* Writing now will not block */ +#define POLLERR 0x0008 /* Error condition */ +#define POLLHUP 0x0010 /* Hung up */ +struct pollfd { + int fd; + short events; + short revents; +}; +int poll(struct pollfd *fds, unsigned int nfds, int timo); +int smb2_getaddrinfo(const char *node, const char*service, + const struct addrinfo *hints, + struct addrinfo **res); +void smb2_freeaddrinfo(struct addrinfo *res); +#ifndef __amigaos4__ +ssize_t writev(int fd, const struct iovec *iov, int iovcnt); +ssize_t readv(int fd, const struct iovec *iov, int iovcnt); +#endif +#if !defined(HAVE_SOCKADDR_STORAGE) +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128 +#define _SS_ALIGNSIZE (sizeof(double)) +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) * 2) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) * 2 - \ + _SS_PAD1SIZE - _SS_ALIGNSIZE) +struct sockaddr_storage { +#ifdef HAVE_SOCKADDR_LEN + unsigned char ss_len; /* address length */ + unsigned char ss_family; /* address family */ +#else + unsigned short ss_family; +#endif + char __ss_pad1[_SS_PAD1SIZE]; + double __ss_align; /* force desired structure storage alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; +#endif +#endif + #ifdef PS2_IOP_PLATFORM #include diff --git a/lib/errors.c b/lib/errors.c index b30b8381..7860a673 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -1104,6 +1104,7 @@ int nterror_to_errno(uint32_t status) { case SMB2_STATUS_FILE_RENAMED: case SMB2_STATUS_PROCESS_IS_TERMINATING: case SMB2_STATUS_DIRECTORY_NOT_EMPTY: + return ENOTEMPTY; case SMB2_STATUS_CANNOT_DELETE: case SMB2_STATUS_FILE_DELETED: return EPERM; diff --git a/lib/init.c b/lib/init.c index 04f0eeee..84f10c32 100644 --- a/lib/init.c +++ b/lib/init.c @@ -82,8 +82,6 @@ #include "compat.h" - - static int smb2_parse_args(struct smb2_context *smb2, const char *args) { @@ -192,8 +190,8 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) smb2_set_error(smb2, "URL is too long"); return NULL; } + strncpy(str, url + 6, MAX_URL_SIZE); - args = strchr(str, '?'); if (args) { *(args++) = '\0'; @@ -225,7 +223,7 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) } /* user */ if ((tmp = strchr(ptr, '@')) != NULL && strlen(tmp) > len_shared_folder) { - *(tmp++) = '\0'; + *(tmp++) = '\0'; u->user = strdup(ptr); ptr = tmp; } @@ -470,7 +468,7 @@ void smb2_set_security_mode(struct smb2_context *smb2, uint16_t security_mode) smb2->security_mode = security_mode; } -#if !defined(_XBOX) && !defined(PS2_IOP_PLATFORM) +#if !defined(_XBOX) && !defined(PS2_IOP_PLATFORM) && !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) static void smb2_set_password_from_file(struct smb2_context *smb2) { char *name = NULL; @@ -558,7 +556,7 @@ void smb2_set_user(struct smb2_context *smb2, const char *user) return; } smb2->user = strdup(user); -#if !defined(_XBOX) && !defined(PS2_IOP_PLATFORM) +#if !defined(_XBOX) && !defined(PS2_IOP_PLATFORM) && !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__) smb2_set_password_from_file(smb2); #endif } diff --git a/lib/libsmb2.c b/lib/libsmb2.c index ce8271e1..391e6926 100644 --- a/lib/libsmb2.c +++ b/lib/libsmb2.c @@ -84,7 +84,7 @@ #include #endif -#if defined(_WIN32) || defined(_XBOX) +#if defined(_WIN32) || defined(_XBOX) || defined(__AROS__) #include "asprintf.h" #endif @@ -1028,7 +1028,7 @@ connect_cb(struct smb2_context *smb2, int status, int smb2_connect_share_async(struct smb2_context *smb2, const char *server, - const char *share, const char *user, + const char *share, const char *user, smb2_command_cb cb, void *cb_data) { struct connect_data *c_data; @@ -1056,7 +1056,6 @@ smb2_connect_share_async(struct smb2_context *smb2, if (user) { smb2_set_user(smb2, user); } - c_data = calloc(1, sizeof(struct connect_data)); if (c_data == NULL) { smb2_set_error(smb2, "Failed to allocate connect_data"); diff --git a/lib/socket.c b/lib/socket.c index 6ed760c0..f99f065b 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -845,6 +845,9 @@ set_nonblocking(t_socket fd) #if defined(WIN32) || defined(_XBOX) || defined(PS2_EE_PLATFORM) && defined(PS2IPS) unsigned long opt = 1; ioctlsocket(fd, FIONBIO, &opt); +#elif (defined(__AMIGA__) || defined(__AROS__)) && !defined(__amigaos4__) + unsigned long opt = 0; + IoctlSocket(fd, FIONBIO, (char *)&opt); #else unsigned v; v = fcntl(fd, F_GETFL, 0); @@ -893,7 +896,7 @@ connect_async_ai(struct smb2_context *smb2, const struct addrinfo *ai, int *fd_o ((struct sockaddr_in *)&ss)->sin_len = socksize; #endif break; -#ifndef _XBOX +#ifdef AF_INET6 case AF_INET6: #if !defined(PICO_PLATFORM) || defined(LWIP_INETV6) socksize = sizeof(struct sockaddr_in6); @@ -901,9 +904,9 @@ connect_async_ai(struct smb2_context *smb2, const struct addrinfo *ai, int *fd_o #ifdef HAVE_SOCK_SIN_LEN ((struct sockaddr_in6 *)&ss)->sin6_len = socksize; #endif -#endif #endif break; +#endif default: smb2_set_error(smb2, "Unknown address family :%d. " "Only IPv4/IPv6 supported so far.", diff --git a/lib/sync.c b/lib/sync.c index 01db3445..b0dc1b08 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -133,7 +133,7 @@ static void connect_cb(struct smb2_context *smb2, int status, */ int smb2_connect_share(struct smb2_context *smb2, const char *server, - const char *share, + const char *share, const char *user) { struct sync_cb_data *cb_data; @@ -145,8 +145,8 @@ int smb2_connect_share(struct smb2_context *smb2, return -ENOMEM; } - rc = smb2_connect_share_async(smb2, server, share, user, - connect_cb, cb_data); + rc = smb2_connect_share_async(smb2, server, share, user, connect_cb, cb_data); + if (rc < 0) { goto out; }