diff --git a/switch/libsmb2/.gitignore b/switch/libsmb2/.gitignore new file mode 100644 index 00000000..a96471be --- /dev/null +++ b/switch/libsmb2/.gitignore @@ -0,0 +1,2 @@ +*.tgz +switch-libsmb2 \ No newline at end of file diff --git a/switch/libsmb2/PKGBUILD b/switch/libsmb2/PKGBUILD new file mode 100644 index 00000000..524d323b --- /dev/null +++ b/switch/libsmb2/PKGBUILD @@ -0,0 +1,54 @@ +# Maintainer: Rhys Koedijk + +pkgname=switch-libsmb2 +pkgver=r307.aef1888 +pkgrel=1 +pkgdesc='SMB2/3 userspace client' +arch=('any') +url='https://github.com/sahlberg/libsmb2' +license=('(L)GPL') +options=(!strip libtool staticlibs) +source=(${pkgname}::"git+https://github.com/sahlberg/libsmb2.git#commit=aef1888f0f04bb41a38262d3388d7b673e48a1ed") +sha256sums=('SKIP') +makedepends=('git' 'switch-pkg-config' 'devkitpro-pkgbuild-helpers') +groups=('switch-portlibs') + +pkgver() { + cd "$srcdir/${pkgname}" + printf 'r%s.%s' "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +prepare() { + cd ${pkgname} + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-define_endian_macros.patch" + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-define_getlogin_r.patch" + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-define_net_readv_writev.patch" + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-fix_portable_endian_include.patch" + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-fix_getaddrinfo_hints.patch" + patch -Np1 -i "$srcdir/../libsmb2-91d6c8a-fix_makefile_libnx_include.patch" +} + +build() { + cd ${pkgname} + + source /opt/devkitpro/switchvars.sh + + libtoolize + aclocal + autoheader + automake --add-missing + autoconf + + ./configure --prefix="${PORTLIBS_PREFIX}" --host=aarch64-none-elf \ + --disable-shared --enable-static --without-libkrb5 + + make +} + +package() { + cd ${pkgname} + + make DESTDIR="$pkgdir" install + + install -Dm644 LICENCE-LGPL-2.1.txt "$pkgdir"/opt/devkitpro/portlibs/switch/licenses/$pkgname/LICENCE +} diff --git a/switch/libsmb2/libsmb2-91d6c8a-define_endian_macros.patch b/switch/libsmb2/libsmb2-91d6c8a-define_endian_macros.patch new file mode 100644 index 00000000..e2341d2f --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-define_endian_macros.patch @@ -0,0 +1,30 @@ +diff --git a/include/portable-endian.h b/include/portable-endian.h +index e0730b2..17e1b3f 100644 +--- a/include/portable-endian.h ++++ b/include/portable-endian.h +@@ -110,6 +110,25 @@ + # error platform not supported + # endif + ++#elif defined(__SWITCH__) ++ ++# include ++ ++# 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 + # error platform not supported + #endif \ No newline at end of file diff --git a/switch/libsmb2/libsmb2-91d6c8a-define_getlogin_r.patch b/switch/libsmb2/libsmb2-91d6c8a-define_getlogin_r.patch new file mode 100644 index 00000000..586d9545 --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-define_getlogin_r.patch @@ -0,0 +1,16 @@ +diff --git a/lib/init.c b/lib/init.c +index aeb1982..f349cd4 100644 +--- a/lib/init.c ++++ b/lib/init.c +@@ -74,6 +74,11 @@ + #endif + #endif // __ANDROID__ + ++#ifdef __SWITCH__ ++#include ++#define getlogin_r(a,b) ENXIO ++#endif // __SWITCH__ ++ + static int + smb2_parse_args(struct smb2_context *smb2, const char *args) + { \ No newline at end of file diff --git a/switch/libsmb2/libsmb2-91d6c8a-define_net_readv_writev.patch b/switch/libsmb2/libsmb2-91d6c8a-define_net_readv_writev.patch new file mode 100644 index 00000000..b4edf9c3 --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-define_net_readv_writev.patch @@ -0,0 +1,102 @@ +--- a/lib/socket.c ++++ b/lib/socket.c +@@ -80,6 +80,99 @@ + + #define MAX_URL_SIZE 256 + ++#ifdef __SWITCH__ ++ ++#include ++#include ++#include ++#include ++ ++ ++ssize_t writev(int fd, const struct iovec *vector, int count) ++{ ++ size_t bytes = 0; ++ ++ for (int i = 0; i < count; ++i) ++ { ++ bytes += vector[i].iov_len; ++ } ++ ++ char *buffer = (char *)malloc(bytes); ++ ++ if (buffer == NULL) ++ { ++ return -1; ++ } ++ ++ size_t to_copy = bytes; ++ char *bp = buffer; ++ ++ for (int i = 0; i < count; ++i) ++ { ++ size_t copy = MIN(vector[i].iov_len, to_copy); ++ bp = mempcpy((void *)bp, (void *)vector[i].iov_base, copy); ++ to_copy -= copy; ++ if (to_copy == 0) ++ { ++ break; ++ } ++ } ++ ++ ssize_t bytes_written = write(fd, buffer, bytes); ++ free(buffer); ++ return bytes_written; ++} ++ ++ssize_t readv(int fd, const struct iovec *iov, int iovcnt) ++{ ++ ssize_t total = 0, bytes_read = 0; ++ ++ for (int j = 0; j < iovcnt; j++) { ++ total += iov[j].iov_len; ++ } ++ ++ char *buffer = (char *)malloc(total); ++ char *bp = buffer; ++ ++ if(buffer == NULL) { ++ return -1; ++ } ++ ++ int bytes_left = read(fd, buffer, total); ++ ++ if (bytes_left == -1) { ++ free((void*)buffer); ++ return -1; ++ } ++ ++ if(bytes_left == 0) ++ { ++ return 0; ++ } ++ ++ for (int i = 0; i < iovcnt; i++) ++ { ++ int sz = MIN(iov[i].iov_len, bytes_left); ++ ++ memcpy(iov[i].iov_base, bp, sz); ++ ++ bp += sz; ++ bytes_read += sz; ++ bytes_left -= sz; ++ ++ if(bytes_left < 1) ++ { ++ break; ++ } ++ } ++ ++ free((void*)buffer); ++ return bytes_read; ++} ++ ++ ++#endif ++ + static int + smb2_get_credit_charge(struct smb2_context *smb2, struct smb2_pdu *pdu) + { diff --git a/switch/libsmb2/libsmb2-91d6c8a-fix_getaddrinfo_hints.patch b/switch/libsmb2/libsmb2-91d6c8a-fix_getaddrinfo_hints.patch new file mode 100644 index 00000000..e05168dc --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-fix_getaddrinfo_hints.patch @@ -0,0 +1,20 @@ +diff --git a/lib/socket.c b/lib/socket.c +index 978f06d..156fad5 100644 +--- a/lib/socket.c ++++ b/lib/socket.c +@@ -701,9 +747,14 @@ smb2_connect_async(struct smb2_context *smb2, const char *server, + } else { + port = "445"; + } ++ ++ struct addrinfo hints; ++ memset(&hints, 0, sizeof hints); ++ hints.ai_family = AF_INET; // AF_INET or AF_INET6 to force version ++ hints.ai_socktype = SOCK_STREAM; + + /* is it a hostname ? */ +- if (getaddrinfo(host, port, NULL, &ai) != 0) { ++ if (getaddrinfo(host, port, &hints, &ai) != 0) { + free(addr); + smb2_set_error(smb2, "Invalid address:%s " + "Can not resolv into IPv4/v6.", server); diff --git a/switch/libsmb2/libsmb2-91d6c8a-fix_makefile_libnx_include.patch b/switch/libsmb2/libsmb2-91d6c8a-fix_makefile_libnx_include.patch new file mode 100644 index 00000000..b406c752 --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-fix_makefile_libnx_include.patch @@ -0,0 +1,12 @@ +diff --git a/lib/Makefile.am b/lib/Makefile.am +index 72a86ec..fe133eb 100644 +--- a/lib/Makefile.am ++++ b/lib/Makefile.am +@@ -4,6 +4,7 @@ lib_LTLIBRARIES = libsmb2.la + + libsmb2_la_CPPFLAGS = -I$(abs_top_srcdir)/include \ + -I$(abs_top_srcdir)/include/smb2 \ ++ -I$(DEVKITPRO)/libnx/include \ + "-D_U_=__attribute__((unused))" + + libsmb2_la_SOURCES = \ \ No newline at end of file diff --git a/switch/libsmb2/libsmb2-91d6c8a-fix_portable_endian_include.patch b/switch/libsmb2/libsmb2-91d6c8a-fix_portable_endian_include.patch new file mode 100644 index 00000000..6998751f --- /dev/null +++ b/switch/libsmb2/libsmb2-91d6c8a-fix_portable_endian_include.patch @@ -0,0 +1,12 @@ +diff --git a/lib/aes128ccm.c b/lib/aes128ccm.c +index 10bd11d..bcc492d 100644 +--- a/lib/aes128ccm.c ++++ b/lib/aes128ccm.c +@@ -21,6 +21,7 @@ + #include + + #include "aes.h" ++#include "portable-endian.h" + + static void aes_ccm_generate_b0(unsigned char *nonce, int nlen, + int alen, int plen, int mlen, \ No newline at end of file