diff --git a/.gitignore b/.gitignore index a3b3ad9..1dd892d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,12 @@ ref/* *.exe dsm *.so -*.a dsm_discover dsm_lookup dsm_inverse configure .*/ -build*/ -*.a +build/ *.deps *.la *.libs @@ -26,7 +24,12 @@ build*/ aclocal.m4 autom4te.cache config -config.* +config.rb +config.h.* +config.s* +config.log +config.guess +universal/*.a config.h.in configure libtool diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6b5d54d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libtasn1"] + path = libtasn1 + url = git@github.com:everappz/libtasn1.git diff --git a/NOTES.md b/NOTES.md deleted file mode 100644 index a29d8bf..0000000 --- a/NOTES.md +++ /dev/null @@ -1,36 +0,0 @@ -# SMB/NBT Notes. - -I will here throw various notes regarding SMB protocol implementation and -compatibility issues, with the hope it could be usefull to and reduce of pain -of somebody else. There are no particular order. - -Most (if not all) of these notes apply mostly to Win7 (the network i work on has -only Win7 boxes except my Linux one) - -## Discovering network hosts. - -Maybe this information is well known around the net, but it found it by randomly -experimenting with NBNS packets. There a special case of NetBIOS name which is -the wildcard `0x 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00` (before -Netbios encoding), that is a '*' followed by 15 zeros. I guess all the machines -on the network are supposed to reply when they see this broadcasted, but in -practice they don't. They don't reply, except if you remove the recursive and -broadcast flag from the NBNS packet, but still broadcast it. In that case, -they'll reply with an error. That's already something :) Now you've got their -IPs, you'll be able to issue a NBSTATE command to each one of them, so you'll -have thei're netbios name. Cool, you know everyone on the LAN. - -PS: I've no idea (yet) of how Samba, older versions of Windows and/or NAS are -behaving regarding this. - -## Windows 7 NTLM2 - -Although Win7 is supposed to support the old NTLM2 authentication, it seems -they actually doesn't handle it oustide of GSSAPI/SPNEGO, which i would like -to avoid, being unnecessarily complicated for my little goals. - -I've been unable to build a packet that would satisfy it, it answers with a BAD -PARAMETER (or something in that area). smbclient exhibits the same behavior. -But, it you just omit the UnicodePassword field with the NTLM2 response and just -provide the simpler LM2 response, it works nicely. Pay attention that in that -case, you MUST uppercase the user name. diff --git a/README.md b/README.md deleted file mode 100644 index 95968c4..0000000 --- a/README.md +++ /dev/null @@ -1,86 +0,0 @@ -# liBDSM - -lib Defective SMb (__libDSM__) is a [SMB protocol](https://en.wikipedia.org/wiki/Server_Message_Block) client implementation in pure old __C__, with -a _lot_ less features than [Samba](https://www.samba.org/) but is simpler, and -has with a more permissive license (currently __LGPL__ + __proprietary__). - -The initial goal of this project is to have a library that can access most SMB shares to -read files and that has with a license compatible with the iOS/Android/WinRT appstores in -order to integrate it into _VLC for iOS_ and _VLC for Android_. - -This library is also licensable under a proprietary license, if LGPL is not good enough -for you. - -The lib is provided as a static library or as a dynamically linked library. -A few useless (yet) utils are also provided, mostly for testing purpose. - -## Features - -Here's a list of the currently supported features: -* NETBIOS - * Basic bi-directionnal NETBIOS name resolution - * Hacky LAN SMB servers discovery (Listing all the smb servers on the LAN, no WINS, etc.) - * Basic NETBIOS Session transport layer -* SMB - * Support only required parts of 'NT LM 0.12' (aka CIFS?) dialect. - * User based authentication - * List Shares - * Browse folders - * Read file - * Write file - * Delete file - * Delete empty folder - * Move and rename file/folder - * Create new folder - * No copy, lock, RPCs, etc. [Hum... yet] - -## Support - -liBDSM has been tested/reported to work with the following devices/OSes: - -* Windows 7 -* Windows 8/8.1 -* Samba -* smbX (OSX new smb implementation) -* QNAP TS-212 -* A cheap NAS whose name i can't remember :) - -Feel free to contribute items to this list (or network trace of not working devices) - -## Building - -### Requirements - -* A Unix system with a bash-compatible shell -* C99 C compiler -* (GNU) Make -* Autotools -* libc with iconv -* getopt_long -* GNU tasn1 compiler/support library - -The build dependencies can be installed on Debian(-based) systems using - - sudo apt-get install build-essential autoconf libtool pkg-config libtasn1-3-dev libtasn1-3-bin libbsd-dev - -### HowTo - - $> ./bootstrap - $> ./configure --prefix=/your/prefix - $> make - $> make install # maybe - - -## TODO - -* HEAVILY refactor. Any help is welcome. -* Support more of the SMBv2 and v3 protocols. - -## Contributing - -* Fork videolabs/libdsm -* Make a feature branch -* Commits your work there -* Make a pull request -* ... -* Profit ! diff --git a/bin/discover.c b/bin/discover.c index c947d9b..d11d46a 100644 --- a/bin/discover.c +++ b/bin/discover.c @@ -90,6 +90,7 @@ int main() getchar(); netbios_ns_discover_stop(ns); + netbios_ns_destroy(ns); return 0; } diff --git a/bootstrap b/bootstrap deleted file mode 100755 index a16dbf9..0000000 --- a/bootstrap +++ /dev/null @@ -1,36 +0,0 @@ -#! /bin/sh -## --------------------------------------------------------------------------- -## __________________ _________ _____ _____ .__ ._. -## \______ \______ \ / _____/ / \ / _ \ |__| ____ | | -## | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | -## | | \| ` \/ / Y \ / | | \ ___/ \| -## |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ -## \/ \/ \/ \/ )/ \/ \/ \/ -## -## This file is part of libdsm. Copyright © 2014 VideoLabs SAS -## -## Author: Julien 'Lta' BALLET - -set -e - -cd "$(dirname "$0")" - -autoreconf --install --force --verbose ${ACLOCAL_ARGS} - -set +x - - -echo '#---------------------------------------------------------------------------#' -echo '# __________________ _________ _____ _____ .__ ._. #' -echo '# \______ \______ \ / _____/ / \ / _ \ |__| ____ | | #' -echo '# | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | #' -echo '# | | \| ` \/ / Y \ / | | \ ___/ \| #' -echo '# li|______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ #' -echo '# \/ \/ \/ \/ )/ \/ \/ \/ #' -echo '#---------------------------------------------------------------------------#' -echo "#-------------| You are now dead, please take your receipt ! |--------------#" -echo '#---------------------------------------------------------------------------#' -echo '' -echo 'See build options with `./configure --help`, make your choiches, then' -echo '$> ./configure [--prefix=/path] [...] && make && make install' - diff --git a/compat/clock_gettime.c b/compat/clock_gettime.c index 741a8d5..f3d8e68 100644 --- a/compat/clock_gettime.c +++ b/compat/clock_gettime.c @@ -38,7 +38,7 @@ #include #include "compat.h" -int clock_gettime(clockid_t clk_id, struct timespec *tp) { +int dsm_clock_gettime(clockid_t clk_id, struct timespec *tp) { kern_return_t ret; clock_serv_t clk; clock_id_t clk_serv_id; @@ -67,7 +67,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { #include #include "compat.h" -int clock_gettime(int clk_id, struct timespec *spec) { +int dsm_clock_gettime(int clk_id, struct timespec *spec) { (void)clk_id; FILETIME wintime; GetSystemTimeAsFileTime(&wintime); diff --git a/compat/compat.c b/compat/compat.c index c3c6f9e..d45a5ea 100644 --- a/compat/compat.c +++ b/compat/compat.c @@ -1,4 +1,4 @@ -#include "config.h" +#include "../xcode/config.h" #if !defined(HAVE_PIPE) && defined(HAVE__PIPE) diff --git a/compat/compat.h b/compat/compat.h index 1a2a897..73b4cc4 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -28,9 +28,14 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include + +#ifndef _WIN32 +#include +#endif + #if !defined HAVE_STRLCPY && !defined HAVE_LIBBSD size_t strlcpy(char *dst, const char *src, size_t siz); #endif @@ -47,7 +52,7 @@ enum { }; #endif #if !defined HAVE_CLOCK_GETTIME -int clock_gettime(clockid_t clk_id, struct timespec *tp); +int dsm_clock_gettime(clockid_t clk_id, struct timespec *tp); #endif #if !defined HAVE_STRNDUP diff --git a/config.h b/config.h new file mode 100644 index 0000000..c0ae56a --- /dev/null +++ b/config.h @@ -0,0 +1,163 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* ... */ +#define ASN1_ARRAY_TYPE asn1_static_node + +/* Define to 1 if you have the header file. */ +#define HAVE_ALLOCA_H 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. */ +/* #undef HAVE_BSD_STRING_H */ + +/* Define to 1 if the system has the type `clockid_t'. */ +#define HAVE_CLOCKID_T 1 + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if + you don't. */ +#define HAVE_DECL_CLOCK_MONOTONIC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `getifaddrs' function. */ +#define HAVE_GETIFADDRS 1 + +/* Define if you have the iconv() function and it works. */ +#define HAVE_ICONV 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_IFADDRS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LANGINFO_H 1 + +/* Does this system have libbsd strl*** functions implementation */ +#define HAVE_LIBBSD 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `pipe' function. */ +#define HAVE_PIPE 1 + +/* Define if you have POSIX threads libraries and header files. */ +#define HAVE_PTHREAD 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +#define HAVE_PTHREAD_PRIO_INHERIT 1 + +/* 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_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 `strlcpy' function. */ +#define HAVE_STRLCPY 1 + +/* Define to 1 if you have the `strndup' function. */ +#define HAVE_STRNDUP 1 + +/* Define to 1 if the system has the type `struct timespec'. */ +#define HAVE_STRUCT_TIMESPEC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* libtasn1 has v 3.0 downcase types */ +#define HAVE_TASN1_3PLUS 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `_pipe' function. */ +/* #undef HAVE__PIPE */ + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libdsm" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libdsm" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libdsm 0.2.7" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libdsm" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.2.7" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 for Unicode (Wide Chars) APIs. */ +/* #undef UNICODE */ + +/* Path of the random number generation device */ +#define URANDOM "/dev/urandom" + +/* Version number of package */ +#define VERSION "0.2.7" + +/* Define to 64 for large files support. */ +#define _FILE_OFFSET_BITS 64 + +/* Define to 2 to get glibc warnings. */ +#define _FORTIFY_SOURCE 2 + +/* Extensions to ISO C89 from ISO C99. */ +/* #undef _ISOC99_SOURCE */ + +/* IEEE Std 1003.1. */ +/* #undef _POSIX_C_SOURCE */ + +/* IEEE Std 1003.1. */ +/* #undef _POSIX_SOURCE */ + +/* Define to 1 for Unicode (Wide Chars) APIs. */ +/* #undef _UNICODE */ + +/* ... */ +/* #undef asn1_static_node */ diff --git a/contrib/mdx/md4.c b/contrib/mdx/md4.c index f153ea3..5c6fa23 100644 --- a/contrib/mdx/md4.c +++ b/contrib/mdx/md4.c @@ -35,6 +35,8 @@ * compile-time configuration. */ + + #ifndef HAVE_OPENSSL #include @@ -177,7 +179,7 @@ static const void *body(MD4_CTX *ctx, const void *data, unsigned long size) return ptr; } -void MD4_Init(MD4_CTX *ctx) +void MD4_CTX_Init(MD4_CTX *ctx) { ctx->a = 0x67452301; ctx->b = 0xefcdab89; @@ -188,7 +190,7 @@ void MD4_Init(MD4_CTX *ctx) ctx->hi = 0; } -void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size) +void MD4_CTX_Update(MD4_CTX *ctx, const void *data, unsigned long size) { MD4_u32plus saved_lo; unsigned long used, available; @@ -225,7 +227,7 @@ void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size) memcpy(ctx->buffer, data, size); } -void MD4_Final(unsigned char *result, MD4_CTX *ctx) +void MD4_CTX_Final(unsigned char *result, MD4_CTX *ctx) { unsigned long used, available; diff --git a/contrib/mdx/md4.h b/contrib/mdx/md4.h index 833b7e8..780bf1b 100644 --- a/contrib/mdx/md4.h +++ b/contrib/mdx/md4.h @@ -23,6 +23,7 @@ * See md4.c for more information. */ + #ifdef HAVE_OPENSSL #include #elif !defined(_MD4_H) @@ -39,8 +40,8 @@ typedef struct MD4_u32plus block[16]; } MD4_CTX; -extern void MD4_Init(MD4_CTX *ctx); -extern void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size); -extern void MD4_Final(unsigned char *result, MD4_CTX *ctx); +extern void MD4_CTX_Init(MD4_CTX *ctx); +extern void MD4_CTX_Update(MD4_CTX *ctx, const void *data, unsigned long size); +extern void MD4_CTX_Final(unsigned char *result, MD4_CTX *ctx); #endif diff --git a/contrib/mdx/md5.c b/contrib/mdx/md5.c index efa9c92..f8e5b9c 100644 --- a/contrib/mdx/md5.c +++ b/contrib/mdx/md5.c @@ -35,6 +35,7 @@ * compile-time configuration. */ + #ifndef HAVE_OPENSSL #include @@ -199,7 +200,7 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size) return ptr; } -void MD5_Init(MD5_CTX *ctx) +void MD5_CTX_Init(MD5_CTX *ctx) { ctx->a = 0x67452301; ctx->b = 0xefcdab89; @@ -210,7 +211,7 @@ void MD5_Init(MD5_CTX *ctx) ctx->hi = 0; } -void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size) +void MD5_CTX_Update(MD5_CTX *ctx, const void *data, unsigned long size) { MD5_u32plus saved_lo; unsigned long used, available; @@ -247,7 +248,7 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size) memcpy(ctx->buffer, data, size); } -void MD5_Final(unsigned char *result, MD5_CTX *ctx) +void MD5_CTX_Final(unsigned char *result, MD5_CTX *ctx) { unsigned long used, available; diff --git a/contrib/mdx/md5.h b/contrib/mdx/md5.h index ad4de9a..2156e3b 100644 --- a/contrib/mdx/md5.h +++ b/contrib/mdx/md5.h @@ -39,8 +39,8 @@ typedef struct MD5_u32plus block[16]; } MD5_CTX; -extern void MD5_Init(MD5_CTX *ctx); -extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); -extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); +extern void MD5_CTX_Init(MD5_CTX *ctx); +extern void MD5_CTX_Update(MD5_CTX *ctx, const void *data, unsigned long size); +extern void MD5_CTX_Final(unsigned char *result, MD5_CTX *ctx); #endif diff --git a/contrib/rc4/rc4.c b/contrib/rc4/rc4.c index 2e1fdda..7e99184 100644 --- a/contrib/rc4/rc4.c +++ b/contrib/rc4/rc4.c @@ -36,7 +36,7 @@ * $FreeBSD: src/sys/crypto/rc4/rc4.c,v 1.2.2.1 2000/04/18 04:48:31 archie Exp $ */ -#include "rc4/rc4.h" +#include "rc4.h" static __inline void swap_bytes(uint8_t *a, uint8_t *b) diff --git a/contrib/spnego/spnego_asn1.h b/contrib/spnego/spnego_asn1.h index 3534b99..144d1fc 100644 --- a/contrib/spnego/spnego_asn1.h +++ b/contrib/spnego/spnego_asn1.h @@ -2,9 +2,9 @@ #ifndef __SPNEGO_ASN1_CONF_H_ #define __SPNEGO_ASN1_CONF_H_ -#include "config.h" +#include "../../xcode/config.h" -#include +#include "libtasn1.h" extern const asn1_static_node spnego_asn1_conf[]; diff --git a/include/bdsm.h b/include/bdsm.h index efb975b..3062104 100644 --- a/include/bdsm.h +++ b/include/bdsm.h @@ -31,9 +31,9 @@ #ifndef __BDSM_H_ #define __BDSM_H_ -#define BDSM_VERSION_CURRENT 3 -#define BDSM_VERSION_REVISION 1 -#define BDSM_VERSION_AGE 0 +#define BDSM_VERSION_CURRENT 4 +#define BDSM_VERSION_REVISION 0 +#define BDSM_VERSION_AGE 1 #include "bdsm/netbios_ns.h" #include "bdsm/netbios_defs.h" diff --git a/include/bdsm/smb_defs.h b/include/bdsm/smb_defs.h index 38e9bc9..6435be4 100644 --- a/include/bdsm/smb_defs.h +++ b/include/bdsm/smb_defs.h @@ -78,6 +78,7 @@ enum enum smb_session_supports_what { SMB_SESSION_XSEC = 0, + SMB_SESSION_NTSMB = 1, }; //-----------------------------------------------------------------------------/ @@ -183,4 +184,8 @@ enum smb_session_supports_what #define DSM_ERROR_NETWORK (-3) #define DSM_ERROR_CHARSET (-4) +#define DSM_READ_TIMEOUT 15 +#define DSM_WRITE_TIMEOUT 15 +#define DSM_CONNECT_TIMEOUT 5 + #endif diff --git a/include/bdsm/smb_dir.h b/include/bdsm/smb_dir.h index 68c86ca..0634180 100644 --- a/include/bdsm/smb_dir.h +++ b/include/bdsm/smb_dir.h @@ -36,7 +36,7 @@ #ifndef __BDSM_SMB_DIR_H_ #define __BDSM_SMB_DIR_H_ -#include "bdsm/smb_session.h" +#include "smb_session.h" /** diff --git a/include/bdsm/smb_file.h b/include/bdsm/smb_file.h index b821075..5496e6d 100644 --- a/include/bdsm/smb_file.h +++ b/include/bdsm/smb_file.h @@ -36,7 +36,7 @@ #ifndef __BDSM_SMB_FILE_H_ #define __BDSM_SMB_FILE_H_ -#include "bdsm/smb_session.h" +#include "smb_session.h" /** diff --git a/include/bdsm/smb_session.h b/include/bdsm/smb_session.h index de5d33f..81b844c 100644 --- a/include/bdsm/smb_session.h +++ b/include/bdsm/smb_session.h @@ -32,8 +32,8 @@ #define __BDSM_SMB_SESSION_H_ -#include "bdsm/smb_defs.h" -#include "bdsm/smb_types.h" +#include "smb_defs.h" +#include "smb_types.h" /** * @file smb_session.h @@ -82,14 +82,13 @@ void smb_session_set_creds(smb_session *s, const char *domain, * @param s A session object. * @param hostname The ASCII netbios name, the name type will be coerced to <20> * since libdsm is about reading files - * @param ip The ip of the machine to connect to (in network byte order) + * @param ip The ip of the machine to connect to * @param transport The type of transport used, it could be SMB_TRANSPORT_TCP * or SMB_TRANSPORT_NBT (Netbios over TCP, ie legacy) * @return 0 on success or a DSM error code in case of error */ int smb_session_connect(smb_session *s, const char *hostname, - uint32_t ip, int transport); - + const char *ip,const char *user_port, int transport); /** * @brief Authenticate on the remote host with the provided credentials * @details Can be called if session state is SMB_STATE_DIALECT_OK. @@ -105,6 +104,9 @@ int smb_session_connect(smb_session *s, const char *hostname, */ int smb_session_login(smb_session *s); + +int smb_session_logoff(smb_session *s); + /** * @brief Am i logged in as Guest ? * @@ -142,5 +144,8 @@ int smb_session_supports(smb_session *s, int what); */ uint32_t smb_session_get_nt_status(smb_session *s); +uint64_t smb_session_server_time_stamp(smb_session *s); + +uint16_t smb_session_server_time_zone(smb_session *s); #endif diff --git a/include/bdsm/smb_share.h b/include/bdsm/smb_share.h index fd36e07..2c00f2e 100644 --- a/include/bdsm/smb_share.h +++ b/include/bdsm/smb_share.h @@ -31,8 +31,8 @@ #ifndef __BDSM_SMB_SHARE_H_ #define __BDSM_SMB_SHARE_H_ -#include "bdsm/smb_session.h" -#include "bdsm/smb_file.h" +#include "smb_session.h" +#include "smb_file.h" /** * @file smb_share.h diff --git a/include/bdsm/smb_stat.h b/include/bdsm/smb_stat.h index 622bcb0..85742cc 100644 --- a/include/bdsm/smb_stat.h +++ b/include/bdsm/smb_stat.h @@ -36,8 +36,8 @@ #ifndef __BDSM_SMB_STAT_H_ #define __BDSM_SMB_STAT_H_ -#include "bdsm/smb_defs.h" -#include "bdsm/smb_session.h" +#include "smb_defs.h" +#include "smb_session.h" /// smb_stat_get() OP: Get file size #define SMB_STAT_SIZE 0 @@ -53,7 +53,7 @@ #define SMB_STAT_WTIME 5 /// smb_stat_get() OP: Get file last moditification time #define SMB_STAT_MTIME 6 - +#define SMB_STAT_WTIME_DEP 7 /** * @brief Returns infos about files matching a pattern * @details This functions uses the FIND_FIRST2 SMB operations to list files @@ -79,8 +79,10 @@ smb_stat_list smb_find(smb_session *s, smb_tid tid, const char *pattern); * * @return An opaque smb_stat or NULL in case of error. You need to * destory this object with smb_stat_destroy after usage. + * FYI name is not returned */ -smb_stat smb_fstat(smb_session *s, smb_tid tid, const char *path); + +smb_file *smb_fstat(smb_session *s, smb_tid tid, const char *path); /** * @brief Get the status of an open file from it's file descriptor @@ -109,6 +111,7 @@ void smb_stat_destroy(smb_stat stat); */ size_t smb_stat_list_count(smb_stat_list list); +smb_stat smb_stat_list_next(smb_stat_list stat); /** * @brief Get the element at the given position. * diff --git a/include/bdsm/smb_types.h b/include/bdsm/smb_types.h index dabf8b9..5be3ea7 100644 --- a/include/bdsm/smb_types.h +++ b/include/bdsm/smb_types.h @@ -41,7 +41,7 @@ #define _FILE_OFFSET_BITS 64 -#include +#include "libtasn1.h" #if defined(__ANDROID__) # undef off_t diff --git a/libdsm-ios.sh b/libdsm-ios.sh new file mode 100755 index 0000000..33d1a38 --- /dev/null +++ b/libdsm-ios.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Global build settings +export SDKPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk +export SIMSDKPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk +export MIN_IOS_VERSION=8.0 +export HOST=arm-apple-darwin +export LDFLAGS_NATIVE="-isysroot $SDKPATH" +export LDFLAGS_SIMULATOR="-isysroot $SIMSDKPATH" +export TASN1_CFLAGS="-Ilibtasn1/include" +export TASN1_LIBS="-Llibtasn1 -ltasn1" +export ARCHES=(armv7 armv7s arm64 i386 x86_64) + + +###################################################################### +#Build libdsm + +rm -rf build + +build_files="" +for i in "${ARCHES[@]}" +do + build_files="$build_files build/$i/lib/libdsm.a" + export ARCH=$i + if [[ $i == *"arm"* ]] + then + export LDFLAGS=$LDFLAGS_NATIVE + else + export LDFLAGS=$LDFLAGS_SIMULATOR + fi + export CFLAGS="-arch $ARCH $LDFLAGS -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode -DNDEBUG" + ./bootstrap + ./configure --host=$HOST --prefix=$PWD/build/$ARCH && make && make install + make clean +done + +#Merge the compiled binaries into a single universal one +mkdir -p build/universal +lipo -create $build_files -output build/universal/libdsm.a + +#Copy headers across +mkdir build/universal/include +cp -R build/armv7/include build/universal + +#Move final product to parent directory +cp -R build/universal ../libdsm diff --git a/libdsm.podspec b/libdsm.podspec new file mode 100644 index 0000000..a61f778 --- /dev/null +++ b/libdsm.podspec @@ -0,0 +1,56 @@ +Pod::Spec.new do |s| + s.name = 'libdsm' + s.version = '0.4.0' + s.summary = 'SMB/CIFS client library built on top of libtasn1.' + s.description = <<-DESC + libdsm is a SMB/CIFS client library providing NetBIOS name service + discovery and SMB file sharing protocol support. It allows applications + to browse, read, and write files on SMB/CIFS network shares. + DESC + + s.homepage = 'https://github.com/everappz/libdsm' + s.license = { :type => 'LGPL-2.1', :file => 'COPYING' } + s.author = { 'everappz' => 'https://github.com/everappz' } + s.source = { :git => 'https://github.com/everappz/libdsm.git', :tag => s.version.to_s } + + s.ios.deployment_target = '12.0' + s.osx.deployment_target = '10.15' + s.tvos.deployment_target = '9.0' + s.watchos.deployment_target = '2.0' + + s.source_files = [ + 'src/*.{c,h}', + 'contrib/**/*.{c,h}', + 'compat/*.{c,h}', + 'include/**/*.h', + 'xcode/extra/*.{c,h}', + 'xcode/config.h', + 'config.h' + ] + + s.exclude_files = [ + 'compat/strlcpy.c' + ] + + s.public_header_files = [ + 'include/bdsm.h', + 'include/bdsm/*.h', + 'src/*.h' + ] + + s.header_mappings_dir = '.' + s.header_dir = 'libdsm' + + s.pod_target_xcconfig = { + 'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}/include" "${PODS_TARGET_SRCROOT}/src" "${PODS_TARGET_SRCROOT}/contrib/mdx" "${PODS_TARGET_SRCROOT}/contrib/rc4" "${PODS_TARGET_SRCROOT}/contrib/spnego" "${PODS_TARGET_SRCROOT}/compat" "${PODS_TARGET_SRCROOT}" "${PODS_ROOT}/Headers/Public/libtasn1"', + 'GCC_PREPROCESSOR_DEFINITIONS' => 'HAVE_CONFIG_H=1', + 'GCC_C_LANGUAGE_STANDARD' => 'gnu99' + } + + s.compiler_flags = '-DHAVE_CONFIG_H=1' + + s.libraries = 'iconv' + s.requires_arc = false + + s.dependency 'libtasn1', '~> 4.18' +end diff --git a/libtasn1 b/libtasn1 new file mode 160000 index 0000000..5baf4c8 --- /dev/null +++ b/libtasn1 @@ -0,0 +1 @@ +Subproject commit 5baf4c8d227032bb9851f2f2751d81c096c78a06 diff --git a/src/bdsm_debug.h b/src/bdsm_debug.h index 8abf498..ace7e97 100644 --- a/src/bdsm_debug.h +++ b/src/bdsm_debug.h @@ -31,7 +31,7 @@ #ifndef _BDSM_DEBUG_H_ # define _BDSM_DEBUG_H_ -# include "config.h" +# include "../xcode/config.h" # ifdef __ANDROID__ # define LOG_TAG "libdsm" diff --git a/src/hmac_md5.c b/src/hmac_md5.c index 7c05ecc..8282965 100644 --- a/src/hmac_md5.c +++ b/src/hmac_md5.c @@ -28,12 +28,11 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include #include #include +#include "../xcode/config.h" #include "hmac_md5.h" unsigned char *HMAC_MD5(const void *key, size_t key_len, const void *msg, @@ -45,48 +44,53 @@ unsigned char *HMAC_MD5(const void *key, size_t key_len, const void *msg, uint8_t *cat, *out; MD5_CTX ctx; - assert(key != NULL && msg != NULL); + bdsm_assert(key != NULL && msg != NULL); - // This is Microsoft variation of HMAC_MD5 for NTLMv2 - // It seems they truncate over-sized keys instead of rehashing - if (key_len > 64) - key_len = 64; + if(key != NULL && msg != NULL){ + + // This is Microsoft variation of HMAC_MD5 for NTLMv2 + // It seems they truncate over-sized keys instead of rehashing + if (key_len > 64) + key_len = 64; - memcpy(key_pad, key, key_len); - if (key_len < 64) - memset(key_pad + key_len, 0, 64 - key_len); + memcpy(key_pad, key, key_len); + if (key_len < 64) + memset(key_pad + key_len, 0, 64 - key_len); - // Compute the o/i XORed padded keys - for (unsigned i = 0; i < 64; i++) - { - o_key_pad[i] = 0x5c ^ key_pad[i]; - i_key_pad[i] = 0x36 ^ key_pad[i]; - } + // Compute the o/i XORed padded keys + for (unsigned i = 0; i < 64; i++) + { + o_key_pad[i] = 0x5c ^ key_pad[i]; + i_key_pad[i] = 0x36 ^ key_pad[i]; + } - // Concatenate inner padded key with message - cat = malloc(msg_len + 64); - if (!cat) - return NULL; - memcpy(cat, i_key_pad, 64); - memcpy(cat + 64, msg, msg_len); + // Concatenate inner padded key with message + cat = malloc(msg_len + 64); + if (!cat) + return NULL; + memcpy(cat, i_key_pad, 64); + memcpy(cat + 64, msg, msg_len); - // MD5 of the result - MD5_Init(&ctx); - MD5_Update(&ctx, cat, msg_len + 64); - MD5_Final(key_pad, &ctx); - free(cat); + // MD5 of the result + MD5_CTX_Init(&ctx); + MD5_CTX_Update(&ctx, cat, msg_len + 64); + MD5_CTX_Final(key_pad, &ctx); + free(cat); - memcpy(kcat, o_key_pad, 64); - memcpy(kcat + 64, key_pad, 16); + memcpy(kcat, o_key_pad, 64); + memcpy(kcat + 64, key_pad, 16); - if (hmac != NULL) - out = hmac; - else - out = hmac_static; + if (hmac != NULL) + out = hmac; + else + out = hmac_static; - MD5_Init(&ctx); - MD5_Update(&ctx, kcat, 80); - MD5_Final(out, &ctx); + MD5_CTX_Init(&ctx); + MD5_CTX_Update(&ctx, kcat, 80); + MD5_CTX_Final(out, &ctx); - return out; + return out; + } + + return NULL; } diff --git a/src/hmac_md5.h b/src/hmac_md5.h index 513ceb8..2b09c9b 100644 --- a/src/hmac_md5.h +++ b/src/hmac_md5.h @@ -32,7 +32,7 @@ #define _HMAC_MD5_H_ #include -#include +#include "../contrib/mdx/md5.h" // Pay attention that this is not HMAC_MD5 stricto sensus, this is a variation // to respect MS non-standard implementation in NTLMv2 auth. diff --git a/src/libdsm.sym b/src/libdsm.sym index e6f6348..6b2bff3 100644 --- a/src/libdsm.sym +++ b/src/libdsm.sym @@ -36,6 +36,7 @@ smb_stat_destroy smb_stat_fd smb_stat_get smb_stat_list_at +smb_stat_list_next smb_stat_list_count smb_stat_list_destroy smb_stat_name diff --git a/src/netbios_defs.h b/src/netbios_defs.h index e83fcaf..192d552 100644 --- a/src/netbios_defs.h +++ b/src/netbios_defs.h @@ -33,13 +33,13 @@ #include -#include "bdsm/netbios_defs.h" +#include "../include/bdsm/netbios_defs.h" #include "bdsm_common.h" -#define NETBIOS_PORT_NAME 137 // UDP -#define NETBIOS_PORT_SESSION 139 // TCP -#define NETBIOS_PORT_DIRECT 445 // TCP -#define NETBIOS_PORT_DIRECT_SECONDARY 139 // TCP +#define NETBIOS_PORT_NAME "137" // UDP +#define NETBIOS_PORT_SESSION "139" // TCP +#define NETBIOS_PORT_DIRECT "445" // TCP +#define NETBIOS_PORT_DIRECT_SECONDARY "139" // TCP #define NETBIOS_NAME_LENGTH 15 diff --git a/src/netbios_ns.c b/src/netbios_ns.c index e0d3796..27ecb04 100644 --- a/src/netbios_ns.c +++ b/src/netbios_ns.c @@ -29,7 +29,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include @@ -37,12 +37,10 @@ #include #include #include - #include #include #include #include - #ifdef HAVE_SYS_QUEUE_H # include #endif @@ -56,7 +54,6 @@ #ifdef HAVE_SYS_SOCKET_H # include #endif - #ifndef _WIN32 # include # ifdef HAVE_IFADDRS_H @@ -65,7 +62,7 @@ # include #endif -#include +#include "../include/bdsm/netbios_ns.h" #include "bdsm_debug.h" #include "netbios_query.h" @@ -138,28 +135,28 @@ struct netbios_ns_name_query static int ns_open_socket(netbios_ns *ns) { int sock_opt; - + if ((ns->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) goto error; - + sock_opt = 1; if (setsockopt(ns->socket, SOL_SOCKET, SO_BROADCAST, (void *)&sock_opt, sizeof(sock_opt)) < 0) goto error; - + sock_opt = 0; if (setsockopt(ns->socket, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&sock_opt, sizeof(sock_opt)) < 0) goto error; - + ns->addr.sin_family = AF_INET; ns->addr.sin_port = htons(0); ns->addr.sin_addr.s_addr = INADDR_ANY; if (bind(ns->socket, (struct sockaddr *)&ns->addr, sizeof(ns->addr)) < 0) goto error; - + return 1; - + error: BDSM_perror("netbios_ns_new, open_socket: "); return 0; @@ -170,18 +167,18 @@ static int ns_open_socket(netbios_ns *ns) static int ns_open_abort_pipe(netbios_ns *ns) { int flags; - + if (pipe(ns->abort_pipe) == -1) return -1; - + #ifndef _WIN32 if ((flags = fcntl(ns->abort_pipe[0], F_GETFL, 0)) == -1) return -1; - + if (fcntl(ns->abort_pipe[0], F_SETFL, flags | O_NONBLOCK) == -1) return -1; #endif - + return 0; } @@ -200,12 +197,12 @@ static bool netbios_ns_is_aborted(netbios_ns *ns) fd_set read_fds; int res; struct timeval timeout = {0, 0}; - + FD_ZERO(&read_fds); FD_SET(ns->abort_pipe[0], &read_fds); - + res = select(ns->abort_pipe[0] + 1, &read_fds, NULL, NULL, &timeout); - + return (res < 0 || FD_ISSET(ns->abort_pipe[0], &read_fds)); } @@ -251,11 +248,11 @@ static uint16_t query_class_in = 0x0100; static ssize_t netbios_ns_send_packet(netbios_ns* ns, netbios_query* q, uint32_t ip) { struct sockaddr_in addr; - + addr.sin_addr.s_addr = ip; addr.sin_family = AF_INET; addr.sin_port = htons(NETBIOS_PORT_NAME); - + BDSM_dbg("Sending netbios packet to %s\n", inet_ntoa(addr.sin_addr)); return sendto(ns->socket, (void *)q->packet, sizeof(netbios_query_packet) + q->cursor, 0, @@ -278,7 +275,10 @@ static void netbios_ns_broadcast_packet(netbios_ns* ns, netbios_query* q) if (a->ifa_addr->sa_family != PF_INET) continue; struct sockaddr_in* sin = (struct sockaddr_in*)a->ifa_broadaddr; - + + if (!sin) + continue; + uint32_t ip = sin->sin_addr.s_addr; if (netbios_ns_send_packet(ns, q, ip) == -1) BDSM_perror("Failed to broadcast"); @@ -304,7 +304,7 @@ static void netbios_ns_broadcast_packet(netbios_ns* ns, netbios_query* q) if (WSAIoctl(ns->socket, SIO_GET_INTERFACE_LIST, NULL, 0, (void*)infolist, sizeof(infolist), &dwBytesReturned, NULL, NULL) != 0) return; unsigned int dwNumInterfaces = dwBytesReturned / sizeof(INTERFACE_INFO); - + for (unsigned int index = 0; index < dwNumInterfaces; index++) { if (infolist[index].iiAddress.Address.sa_family == AF_INET) @@ -327,9 +327,9 @@ static int netbios_ns_send_name_query(netbios_ns *ns, { uint16_t query_type; netbios_query *q; - - assert(ns != NULL); - + + bdsm_assert(ns != NULL); + switch (type) { case NAME_QUERY_TYPE_NB: @@ -342,23 +342,23 @@ static int netbios_ns_send_name_query(netbios_ns *ns, BDSM_dbg("netbios_ns_send_name_query: unknow name_query_type"); return -1; } - + // Prepare packet q = netbios_query_new(34 + 4, 1, NETBIOS_OP_NAME_QUERY); if (query_flag) netbios_query_set_flag(q, query_flag, 1); - + // Append the queried name to the packet netbios_query_append(q, name, strlen(name) + 1); - + // Magic footer (i.e. Question type (Netbios) / class (IP) netbios_query_append(q, (const char *)&query_type, 2); netbios_query_append(q, (const char *)&query_class_in, 2); q->packet->queries = htons(1); - + // Increment transaction ID, not to reuse them q->packet->trn_id = htons(ns->last_trn_id + 1); - + if (ip != 0) { ssize_t sent = netbios_ns_send_packet(ns, q, ip); @@ -375,9 +375,9 @@ static int netbios_ns_send_name_query(netbios_ns *ns, { netbios_ns_broadcast_packet(ns, q); } - + netbios_query_destroy(q); - + ns->last_trn_id++; // Remember the last transaction id. return 0; } @@ -391,14 +391,14 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, uint16_t *p_type, type; uint16_t *p_data_length, data_length; char *p_data; - + // check for packet size if (size < sizeof(netbios_query_packet)) { BDSM_dbg("netbios_ns_handle_query, invalid size !\n"); return -1; } - + q = (netbios_query_packet *)ns->buffer; if (check_trn_id) { @@ -409,17 +409,17 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, return -1; } } - + if (!out_name_query) return 0; - + // get Name size, should be 0x20 if (size < sizeof(netbios_query_packet) + 1) return -1; name_size = q->payload[0]; if (name_size != 0x20) return -1; - + // get type and data_length if (size < sizeof(netbios_query_packet) + name_size + 11) return -1; @@ -427,11 +427,11 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, type = *p_type; p_data_length = (uint16_t *) (q->payload + name_size + 10); data_length = ntohs(*p_data_length); - + if (size < sizeof(netbios_query_packet) + name_size + 12 + data_length) return -1; p_data = q->payload + name_size + 12; - + if (type == query_type_nb) { out_name_query->type = NAME_QUERY_TYPE_NB; out_name_query->u.nb.ip = recv_ip; @@ -439,16 +439,16 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, uint8_t name_count; const char *names = NULL; const char *group = NULL, *name = NULL;; - + // get the number of names if (data_length < 1) return -1; name_count = *(p_data); names = p_data + 1; - + if (data_length < name_count * 18) return -1; - + // first search for a group in the name list for (uint8_t name_idx = 0; name_idx < name_count; name_idx++) { @@ -465,7 +465,7 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, const char *current_name = names + name_idx * 18; char current_type = current_name[15]; uint16_t current_flags = (current_name[16] << 8) | current_name[17]; - + if (current_flags & NETBIOS_NAME_FLAG_GROUP) continue; if (current_type == NETBIOS_FILESERVER) @@ -476,7 +476,7 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, break; } } - + if (name) { out_name_query->type = NAME_QUERY_TYPE_NBSTAT; @@ -485,7 +485,7 @@ static int netbios_ns_handle_query(netbios_ns *ns, size_t size, out_name_query->u.nbstat.type = NETBIOS_FILESERVER; } } - + return 0; } @@ -497,8 +497,12 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, netbios_ns_name_query *out_name_query) { int sock; - - assert(ns != NULL); + + bdsm_assert(ns != NULL); + + if(ns==NULL){ + return -1; + } sock = ns->socket; #ifdef HAVE_PIPE @@ -506,15 +510,15 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, #else int abort_fd = -1; #endif - + if (out_name_query) out_name_query->type = NAME_QUERY_TYPE_INVALID; - + while (true) { fd_set read_fds, error_fds; int res, nfds; - + FD_ZERO(&read_fds); FD_ZERO(&error_fds); FD_SET(sock, &read_fds); @@ -523,14 +527,14 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, #endif FD_SET(sock, &error_fds); nfds = (sock > abort_fd ? sock : abort_fd) + 1; - + res = select(nfds, &read_fds, 0, &error_fds, timeout); - + if (res < 0) goto error; if (FD_ISSET(sock, &error_fds)) goto error; - + #ifdef HAVE_PIPE if (FD_ISSET(abort_fd, &read_fds)) return -1; @@ -538,15 +542,15 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, if (netbios_ns_is_aborted(ns)) return -1; #endif - + else if (FD_ISSET(sock, &read_fds)) { struct sockaddr_in addr; socklen_t addr_len = sizeof(struct sockaddr_in); ssize_t size; - + size = recvfrom(sock, ns->buffer, RECV_BUFFER_SIZE, 0, - (struct sockaddr *)&addr, &addr_len); + (struct sockaddr *)&addr, &addr_len); if (size < 0) return -1; if (wait_ip != 0 && addr_len >= sizeof(struct sockaddr_in)) @@ -558,7 +562,7 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, continue; } } - + if (netbios_ns_handle_query(ns, (size_t)size, check_trn_id, addr.sin_addr.s_addr, out_name_query) == -1) @@ -566,7 +570,7 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, BDSM_dbg("netbios_ns_recv, invalid query\n"); continue; } - + if (out_addr) *out_addr = addr; return size; @@ -574,7 +578,7 @@ static ssize_t netbios_ns_recv(netbios_ns *ns, else return 0; } - + error: BDSM_perror("netbios_ns_recv: "); return -1; @@ -584,12 +588,12 @@ static void netbios_ns_copy_name(char *dest, const char *src) { memcpy(dest, src, NETBIOS_NAME_LENGTH); dest[NETBIOS_NAME_LENGTH] = 0; - + for (int i = 1; i < NETBIOS_NAME_LENGTH; i++ ) - if (dest[NETBIOS_NAME_LENGTH - i] == ' ') - dest[NETBIOS_NAME_LENGTH - i] = 0; - else - break; + if (dest[NETBIOS_NAME_LENGTH - i] == ' ') + dest[NETBIOS_NAME_LENGTH - i] = 0; + else + break; } static void netbios_ns_entry_set_name(netbios_ns_entry *entry, @@ -600,7 +604,7 @@ static void netbios_ns_entry_set_name(netbios_ns_entry *entry, netbios_ns_copy_name(entry->name, name); if (group != NULL) netbios_ns_copy_name(entry->group, group); - + entry->type = type; entry->flag |= NS_ENTRY_FLAG_VALID_NAME; } @@ -608,16 +612,16 @@ static void netbios_ns_entry_set_name(netbios_ns_entry *entry, static netbios_ns_entry *netbios_ns_entry_add(netbios_ns *ns, uint32_t ip) { netbios_ns_entry *entry; - + entry = calloc(1, sizeof(netbios_ns_entry)); if (!entry) return NULL; - + entry->address.s_addr = ip; entry->flag |= NS_ENTRY_FLAG_VALID_IP; - + TAILQ_INSERT_HEAD(&ns->entry_queue, entry, next); - + return entry; } @@ -627,9 +631,12 @@ static netbios_ns_entry *netbios_ns_entry_find(netbios_ns *ns, const char *by_na uint32_t ip) { netbios_ns_entry *iter; - - assert(ns != NULL); - + + bdsm_assert(ns != NULL); + if(ns==NULL){ + return NULL; + } + TAILQ_FOREACH(iter, &ns->entry_queue, next) { if (by_name != NULL) @@ -642,15 +649,19 @@ static netbios_ns_entry *netbios_ns_entry_find(netbios_ns *ns, const char *by_na && iter->address.s_addr == ip) return iter; } - + return NULL; } static void netbios_ns_entry_clear(netbios_ns *ns) { netbios_ns_entry *entry, *entry_next; - - assert(ns != NULL); + + bdsm_assert(ns != NULL); + + if(ns==NULL){ + return; + } for (entry = TAILQ_FIRST(&ns->entry_queue); entry != NULL; entry = entry_next) @@ -664,26 +675,26 @@ static void netbios_ns_entry_clear(netbios_ns *ns) netbios_ns *netbios_ns_new() { netbios_ns *ns; - + ns = calloc(1, sizeof(netbios_ns)); if (!ns) return NULL; - + #ifdef HAVE_PIPE // Don't initialize this in ns_open_abort_pipe, as it would lead to // fd 0 to be closed (twice) in case of ns_open_socket error ns->abort_pipe[0] = ns->abort_pipe[1] = -1; #endif - + if (!ns_open_socket(ns) || ns_open_abort_pipe(ns) == -1) { netbios_ns_destroy(ns); return NULL; } - + TAILQ_INIT(&ns->entry_queue); ns->last_trn_id = rand(); - + return ns; } @@ -691,14 +702,14 @@ void netbios_ns_destroy(netbios_ns *ns) { if (!ns) return; - + netbios_ns_entry_clear(ns); - + if (ns->socket != -1) closesocket(ns->socket); - + ns_close_abort_pipe(ns); - + free(ns); } @@ -709,33 +720,33 @@ int netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_ char *encoded_name; ssize_t recv; netbios_ns_name_query name_query; - - assert(ns != NULL && !ns->discover_started); - + + bdsm_assert(ns != NULL && !ns->discover_started); + if ((cached = netbios_ns_entry_find(ns, name, 0)) != NULL) { *addr = cached->address.s_addr; return 0; } - + if ((encoded_name = netbios_name_encode(name, 0, type)) == NULL) return -1; - + if (netbios_ns_send_name_query(ns, 0, NAME_QUERY_TYPE_NB, encoded_name, NETBIOS_FLAG_RECURSIVE | NETBIOS_FLAG_BROADCAST) == -1) { free(encoded_name); return -1; - + } free(encoded_name); - + // Now wait for a reply and pray timeout.tv_sec = 2; timeout.tv_usec = 420; recv = netbios_ns_recv(ns, &timeout, NULL, true, 0, &name_query); - + if (recv < 0) BDSM_perror("netbios_ns_resolve:"); else @@ -748,7 +759,7 @@ int netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_ } else BDSM_dbg("netbios_ns_resolve, wrong query type received\n"); } - + return -1; } @@ -761,22 +772,22 @@ static netbios_ns_entry *netbios_ns_inverse_internal(netbios_ns *ns, uint32_t ip ssize_t recv; netbios_ns_name_query name_query; netbios_ns_entry *entry; - + if ((cached = netbios_ns_entry_find(ns, NULL, ip)) != NULL) return cached; - + if (netbios_ns_send_name_query(ns, ip, NAME_QUERY_TYPE_NBSTAT, name_query_broadcast, 0) == -1) goto error; - + // Now wait for a reply and pray timeout.tv_sec = 1; timeout.tv_usec = 500; recv = netbios_ns_recv(ns, &timeout, NULL, true, ip, &name_query); - + if (recv <= 0) goto error; - + if (name_query.type != NAME_QUERY_TYPE_NBSTAT) { BDSM_dbg("netbios_ns_inverse, wrong query type received\n"); @@ -785,7 +796,7 @@ static netbios_ns_entry *netbios_ns_inverse_internal(netbios_ns *ns, uint32_t ip else BDSM_dbg("netbios_ns_inverse, received a reply for '%s' !\n", inet_ntoa(*(struct in_addr *)&ip)); - + entry = netbios_ns_entry_add(ns, ip); if (entry) netbios_ns_entry_set_name(entry, name_query.u.nbstat.name, @@ -799,9 +810,14 @@ static netbios_ns_entry *netbios_ns_inverse_internal(netbios_ns *ns, uint32_t ip const char *netbios_ns_inverse(netbios_ns *ns, uint32_t ip) { - assert(ns != NULL && ip != 0 && !ns->discover_started); - netbios_ns_entry *entry = netbios_ns_inverse_internal(ns, ip); - return entry ? entry->name : NULL; + bdsm_assert(ns != NULL && ip != 0 && !ns->discover_started); + + if(ns != NULL && ip != 0 && !ns->discover_started){ + netbios_ns_entry *entry = netbios_ns_inverse_internal(ns, ip); + return entry ? entry->name : NULL; + } + + return NULL; } const char *netbios_ns_entry_name(netbios_ns_entry *entry) @@ -829,48 +845,47 @@ static void *netbios_ns_discover_thread(void *opaque) netbios_ns *ns = (netbios_ns *) opaque; while (true) { - struct timespec tp; const int remove_timeout = 5 * ns->discover_broadcast_timeout; netbios_ns_entry *entry, *entry_next; - + if (netbios_ns_is_aborted(ns)) return NULL; - + // check if cached entries timeout, the timeout value is 5 times the // broadcast timeout. - clock_gettime(CLOCK_REALTIME, &tp); + time_t now = time(NULL); for (entry = TAILQ_FIRST(&ns->entry_queue); entry != NULL; entry = entry_next) { entry_next = TAILQ_NEXT(entry, next); - if (tp.tv_sec - entry->last_time_seen > remove_timeout) + if (now - entry->last_time_seen > remove_timeout) { if (entry->flag & NS_ENTRY_FLAG_VALID_NAME) { BDSM_dbg("Discover: on_entry_removed: %s\n", entry->name); ns->discover_callbacks.pf_on_entry_removed( - ns->discover_callbacks.p_opaque, entry); + ns->discover_callbacks.p_opaque, entry); } TAILQ_REMOVE(&ns->entry_queue, entry, next); free(entry); } } - + // send broadbast if (netbios_ns_send_name_query(ns, 0, NAME_QUERY_TYPE_NB, name_query_broadcast, 0) == -1) return NULL; - + while (true) { struct timeval timeout; struct sockaddr_in recv_addr; int res; netbios_ns_name_query name_query; - + timeout.tv_sec = ns->discover_broadcast_timeout; timeout.tv_usec = 0; - + // receive NB or NBSTAT answers res = netbios_ns_recv(ns, ns->discover_broadcast_timeout == 0 ? NULL : &timeout, @@ -879,57 +894,57 @@ static void *netbios_ns_discover_thread(void *opaque) // error or abort if (res == -1) return NULL; - + // timeout reached, broadcast again if (res == 0) break; - - clock_gettime(CLOCK_REALTIME, &tp); - + + time_t now = time(NULL); + if (name_query.type == NAME_QUERY_TYPE_NB) { uint32_t ip = name_query.u.nb.ip; entry = netbios_ns_entry_find(ns, NULL, ip); - + if (!entry) { entry = netbios_ns_entry_add(ns, ip); if (!entry) return NULL; } - entry->last_time_seen = tp.tv_sec; - + entry->last_time_seen = now; + // if entry is already valid, don't send NBSTAT query if (entry->flag & NS_ENTRY_FLAG_VALID_NAME) continue; - + // send NBSTAT query if (netbios_ns_send_name_query(ns, ip, NAME_QUERY_TYPE_NBSTAT, name_query_broadcast, 0) == -1) return NULL; - + } else if (name_query.type == NAME_QUERY_TYPE_NBSTAT) { bool send_callback; - + entry = netbios_ns_entry_find(ns, NULL, recv_addr.sin_addr.s_addr); - + // ignore NBSTAT answers that didn't answered to NB query first. if (!entry) continue; - - entry->last_time_seen = tp.tv_sec; - + + entry->last_time_seen = now; + send_callback = !(entry->flag & NS_ENTRY_FLAG_VALID_NAME); - + netbios_ns_entry_set_name(entry, name_query.u.nbstat.name, name_query.u.nbstat.group, name_query.u.nbstat.type); if (send_callback) ns->discover_callbacks.pf_on_entry_added( - ns->discover_callbacks.p_opaque, entry); + ns->discover_callbacks.p_opaque, entry); } } if (ns->discover_broadcast_timeout == 0) @@ -944,14 +959,14 @@ int netbios_ns_discover_start(netbios_ns *ns, { if (ns->discover_started || !callbacks) return -1; - + ns->discover_callbacks = *callbacks; ns->discover_broadcast_timeout = broadcast_timeout; if (pthread_create(&ns->discover_thread, NULL, netbios_ns_discover_thread, ns) != 0) return -1; ns->discover_started = true; - + return 0; } @@ -962,7 +977,7 @@ int netbios_ns_discover_stop(netbios_ns *ns) netbios_ns_abort(ns); pthread_join(ns->discover_thread, NULL); ns->discover_started = false; - + return 0; } else diff --git a/src/netbios_query.c b/src/netbios_query.c index 0f33b1f..734adb2 100644 --- a/src/netbios_query.c +++ b/src/netbios_query.c @@ -28,7 +28,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" + #include #include #include @@ -40,6 +41,7 @@ # include #endif + #include "netbios_query.h" netbios_query *netbios_query_new(size_t payload_size, @@ -67,56 +69,68 @@ netbios_query *netbios_query_new(size_t payload_size, void netbios_query_destroy(netbios_query *q) { - assert(q); - - free(q->packet); - free(q); + bdsm_assert(q); + if(q!=NULL){ + free(q->packet); + free(q); + } } void netbios_query_set_flag(netbios_query *q, uint16_t flag, int value) { - assert(q && q->packet); - - if (value) - q->packet->flags = htons(ntohs(q->packet->flags) | flag); - else - q->packet->flags = htons(ntohs(q->packet->flags) & ~flag); + bdsm_assert(q && q->packet); + + if(q && q->packet){ + if (value){ + q->packet->flags = htons(ntohs(q->packet->flags) | flag); + } + else{ + q->packet->flags = htons(ntohs(q->packet->flags) & ~flag); + } + } } void netbios_query_print(netbios_query *q) { - assert(q && q->packet); - - printf("--- netbios_query dump :\n"); - printf("payload = %zu, cursor = %zu.\n", q->payload_size, q->cursor); - printf("Transaction id = %u.\n", q->packet->trn_id); - - printf("-------------------------\n"); - for (unsigned i = 0; i < sizeof(netbios_query_packet) + q->cursor; i++) - { - char c; - if ((i % 8) == 0 && i != 0) - printf("\n"); - if ((i % 8) == 0) - printf("0x"); - - c = ((char *)q->packet)[i]; - printf("%.2hhX ", c); + bdsm_assert(q && q->packet); + + if(q && q->packet){ + + printf("--- netbios_query dump :\n"); + printf("payload = %zu, cursor = %zu.\n", q->payload_size, q->cursor); + printf("Transaction id = %u.\n", q->packet->trn_id); + + printf("-------------------------\n"); + for (unsigned i = 0; i < sizeof(netbios_query_packet) + q->cursor; i++) + { + char c; + if ((i % 8) == 0 && i != 0) + printf("\n"); + if ((i % 8) == 0) + printf("0x"); + + c = ((char *)q->packet)[i]; + printf("%.2hhX ", c); + } + printf("\n"); + printf("-------------------------\n"); } - printf("\n"); - printf("-------------------------\n"); } int netbios_query_append(netbios_query *q, const char *data, size_t data_size) { - assert(q && q->packet); - - if (q->payload_size - q->cursor < data_size) - return -1; - - memcpy(((char *)&q->packet->payload) + q->cursor, data, data_size); - q->cursor += data_size; - return 0; + bdsm_assert(q && q->packet); + + if(q && q->packet){ + if (q->payload_size - q->cursor < data_size){ + return -1; + } + memcpy(((char *)&q->packet->payload) + q->cursor, data, data_size); + q->cursor += data_size; + return 0; + } + + return -1; } diff --git a/src/netbios_session.c b/src/netbios_session.c index 9fd85bd..e544ce9 100644 --- a/src/netbios_session.c +++ b/src/netbios_session.c @@ -28,7 +28,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include @@ -36,6 +36,7 @@ #include #include #include +#import #ifdef HAVE_ARPA_INET_H #include @@ -44,6 +45,8 @@ #include #endif #include +#include +#include #include "smb_defs.h" #include "bdsm_debug.h" @@ -51,38 +54,100 @@ #include "netbios_session.h" #include "netbios_utils.h" +//Set blocking IO on the socket +static void set_blocking_io(netbios_session *s) +{ + int arg = fcntl(s->socket, F_GETFL, NULL); + arg &= (~O_NONBLOCK); + fcntl(s->socket, F_SETFL, arg); +} + static int open_socket_and_connect(netbios_session *s) { - if ((s->socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) + + bool restore_blocking_io = false; + + if ((s->socket = socket(s->remote_addr->ai_family, SOCK_STREAM, 0)) < 0){ goto error; - if (connect(s->socket, (struct sockaddr *)&s->remote_addr, sizeof(s->remote_addr)) <0) + } + + // Prevent SIGPIPE signals + int nosigpipe = 1; + setsockopt(s->socket, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe)); + + // Enable non-blocking IO on the socket + int result = fcntl(s->socket, F_SETFL, O_NONBLOCK); + + if (result == -1){ goto error; - + } + else{ + restore_blocking_io = true; + } + + connect(s->socket, s->remote_addr->ai_addr , s->remote_addr->ai_addrlen); + + fd_set fdset; + struct timeval tv; + FD_ZERO(&fdset); + FD_SET(s->socket, &fdset); + tv.tv_sec = DSM_CONNECT_TIMEOUT; + tv.tv_usec = 0; + + if (select((s->socket) + 1, NULL, &fdset, NULL, &tv) == 1){ + int so_error; + socklen_t len = sizeof so_error; + getsockopt(s->socket, SOL_SOCKET, SO_ERROR, &so_error, &len); + if (so_error == 0) { + ; + } + else{ + goto error; + } + } + else{ + goto error; + } + + set_blocking_io(s); + return DSM_SUCCESS; error: + + if(restore_blocking_io){ + set_blocking_io(s); + } + BDSM_perror("netbios_session_new, open_socket: "); return DSM_ERROR_NETWORK; } + + static int session_buffer_realloc(netbios_session *s, size_t new_size) { void *new_ptr; - assert(s != NULL); + bdsm_assert(s != NULL); + + if(s != NULL){ - /* BDSM_dbg("session_buffer_realloc: from %ld bytes to %ld bytes\n", */ - /* s->packet_payload_size, new_size); */ + /* BDSM_dbg("session_buffer_realloc: from %ld bytes to %ld bytes\n", */ + /* s->packet_payload_size, new_size); */ - new_ptr = realloc(s->packet, new_size); - if (new_ptr != NULL) - { - s->packet_payload_size = new_size; - s->packet = new_ptr; - return 1; + new_ptr = realloc(s->packet, new_size); + if (new_ptr != NULL) + { + s->packet_payload_size = new_size; + s->packet = new_ptr; + return 1; + } + free(s->packet); + s->packet = NULL; + return 0; + } - free(s->packet); - s->packet = NULL; return 0; } @@ -118,87 +183,123 @@ void netbios_session_destroy(netbios_session *s) free(s); } -int netbios_session_connect(uint32_t ip, netbios_session *s, +int netbios_session_connect(const char *ip, const char *user_port, netbios_session *s, const char *name, int direct_tcp) { ssize_t recv_size; char *encoded_name = NULL; - uint16_t ports[2]; + char *ports[3]; unsigned int nb_ports; bool opened = false; - assert(s != NULL && s->packet != NULL); + bdsm_assert(s != NULL && s->packet != NULL); - if (direct_tcp) - { - ports[0] = htons(NETBIOS_PORT_DIRECT); - ports[1] = htons(NETBIOS_PORT_DIRECT_SECONDARY); - nb_ports = 2; - } - else - { - ports[0] = htons(NETBIOS_PORT_SESSION); - nb_ports = 1; - } - for (unsigned int i = 0; i < nb_ports && !opened; ++i) - { - s->remote_addr.sin_port = ports[i]; - s->remote_addr.sin_family = AF_INET; - s->remote_addr.sin_addr.s_addr = ip; - opened = open_socket_and_connect(s) == DSM_SUCCESS; - } - if (!opened) - goto error; - - if (!direct_tcp) - { - // Send the Session Request message - netbios_session_packet_init(s); - s->packet->opcode = NETBIOS_OP_SESSION_REQ; - encoded_name = netbios_name_encode(name, 0, NETBIOS_FILESERVER); - if (!netbios_session_packet_append(s, encoded_name, strlen(encoded_name) + 1)) - goto error; - free(encoded_name); - encoded_name = netbios_name_encode("LIBDSM", 0, NETBIOS_WORKSTATION); - if (!netbios_session_packet_append(s, encoded_name, strlen(encoded_name) + 1)) - goto error; - free(encoded_name); - encoded_name = NULL; + if(s != NULL && s->packet != NULL){ + + if (direct_tcp) + { + ports[0] = NETBIOS_PORT_DIRECT; + ports[1] = NETBIOS_PORT_DIRECT_SECONDARY; + nb_ports = 2; + if(user_port!=NULL){ + ports[2] = (char *)user_port; + nb_ports++; + } + } + else + { + ports[0] = NETBIOS_PORT_SESSION; + nb_ports = 1; + if(user_port!=NULL){ + ports[1] = (char *)user_port; + nb_ports++; + } + } + + for (unsigned int i = 0; i < nb_ports && !opened; ++i) + { - s->state = NETBIOS_SESSION_CONNECTING; - if (!netbios_session_packet_send(s)) - goto error; + struct addrinfo hints; + struct addrinfo *rp, *result; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_ADDRCONFIG; + hints.ai_socktype = SOCK_STREAM; + + int getaddrinfoerror = getaddrinfo(ip, ports[i], &hints, &result); + if (getaddrinfoerror) { + goto error; + } + + for (rp = result; rp; rp = rp->ai_next) { + s->remote_addr = rp; + opened = (open_socket_and_connect(s) == DSM_SUCCESS); + if(opened){ + break; + } + } + + freeaddrinfo(result); + + } - // Now receiving the reply from the server. - recv_size = netbios_session_packet_recv(s, NULL); - if (recv_size < 0) + if (!opened) goto error; - // Reply was negative, we are not connected :( - if (s->packet->opcode != NETBIOS_OP_SESSION_REQ_OK) + if (!direct_tcp) { - s->state = NETBIOS_SESSION_REFUSED; - return 0; + // Send the Session Request message + netbios_session_packet_init(s); + s->packet->opcode = NETBIOS_OP_SESSION_REQ; + encoded_name = netbios_name_encode(name, 0, NETBIOS_FILESERVER); + if (!netbios_session_packet_append(s, encoded_name, strlen(encoded_name) + 1)) + goto error; + free(encoded_name); + encoded_name = netbios_name_encode("LIBDSM", 0, NETBIOS_WORKSTATION); + if (!netbios_session_packet_append(s, encoded_name, strlen(encoded_name) + 1)) + goto error; + free(encoded_name); + encoded_name = NULL; + + s->state = NETBIOS_SESSION_CONNECTING; + if (!netbios_session_packet_send(s)) + goto error; + + // Now receiving the reply from the server. + recv_size = netbios_session_packet_recv(s, NULL); + if (recv_size < 0) + goto error; + + // Reply was negative, we are not connected :( + if (s->packet->opcode != NETBIOS_OP_SESSION_REQ_OK) + { + s->state = NETBIOS_SESSION_REFUSED; + return 0; + } } - } - // Reply was OK or DirectTCP, a session has been established - s->state = NETBIOS_SESSION_CONNECTED; - return 1; + // Reply was OK or DirectTCP, a session has been established + s->state = NETBIOS_SESSION_CONNECTED; + return 1; -error: - free(encoded_name); - s->state = NETBIOS_SESSION_ERROR; + error: + free(encoded_name); + s->state = NETBIOS_SESSION_ERROR; + return 0; + } + return 0; } void netbios_session_packet_init(netbios_session *s) { - assert(s != NULL); + bdsm_assert(s != NULL); - s->packet_cursor = 0; - s->packet->flags = 0; - s->packet->opcode = NETBIOS_OP_SESSION_MSG; + if(s!=NULL){ + s->packet_cursor = 0; + s->packet->flags = 0; + s->packet->opcode = NETBIOS_OP_SESSION_MSG; + } } int netbios_session_packet_append(netbios_session *s, @@ -206,17 +307,21 @@ int netbios_session_packet_append(netbios_session *s, { char *start; - assert(s && s->packet); + bdsm_assert(s && s->packet); - if (s->packet_payload_size - s->packet_cursor < size) - if (!session_buffer_realloc(s, size + s->packet_cursor)) - return 0; + if(s && s->packet){ + + if (s->packet_payload_size - s->packet_cursor < size) + if (!session_buffer_realloc(s, size + s->packet_cursor)) + return 0; - start = ((char *)&s->packet->payload) + s->packet_cursor; - memcpy(start, data, size); - s->packet_cursor += size; + start = ((char *)&s->packet->payload) + s->packet_cursor; + memcpy(start, data, size); + s->packet_cursor += size; - return 1; + return 1; + } + return 0; } int netbios_session_packet_send(netbios_session *s) @@ -224,19 +329,72 @@ int netbios_session_packet_send(netbios_session *s) ssize_t to_send; ssize_t sent; - assert(s && s->packet && s->socket >= 0 && s->state > 0); + bdsm_assert(s && s->packet && s->socket >= 0 && s->state > 0); + + if(s && s->packet && s->socket >= 0 && s->state > 0){ + + s->packet->length = htons(s->packet_cursor); + to_send = sizeof(netbios_session_packet) + s->packet_cursor; + + // Set write timeout + struct timeval write_tv; + write_tv.tv_sec = DSM_WRITE_TIMEOUT; + write_tv.tv_usec = 0; + ; + + if(setsockopt(s->socket, SOL_SOCKET, SO_SNDTIMEO, (const char*)&write_tv, sizeof write_tv)<0) + { + BDSM_perror("netbios_session_packet_send: error setting send timeout"); + return 0; + } + + sent = send(s->socket, (void *)s->packet, to_send, 0); - s->packet->length = htons(s->packet_cursor); - to_send = sizeof(netbios_session_packet) + s->packet_cursor; - sent = send(s->socket, (void *)s->packet, to_send, 0); + if (sent != to_send) + { + BDSM_perror("netbios_session_packet_send: Unable to send (full?) packet"); + return 0; + } - if (sent != to_send) - { - BDSM_perror("netbios_session_packet_send: Unable to send (full?) packet"); - return 0; + return (int)sent; + } + return 0; +} - return sent; +int socket_set_recv_timeout(netbios_session *s) +{ + //set read timeout + struct timeval read_tv; + read_tv.tv_sec = DSM_READ_TIMEOUT; + read_tv.tv_usec = 0; + + if(setsockopt(s->socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&read_tv, sizeof read_tv)<0){ + return -1; + } + + int socketFD = s->socket; + int result = -1; + + struct pollfd pollfd[1]; + pollfd->fd = socketFD; + pollfd->events = POLLIN; + pollfd->revents = 0; + + //pool: wait for available data + result = poll(pollfd, 1, DSM_READ_TIMEOUT*1000); + + if(result < 0) { + BDSM_perror("netbios_session_packet_recv: error during poll()"); + return -1; + } + + if(result == 0) { + BDSM_perror("netbios_session_packet_recv: timeout during poll()"); + return -1; + } + + return 0; } static ssize_t netbios_session_get_next_packet(netbios_session *s) @@ -244,55 +402,65 @@ static ssize_t netbios_session_get_next_packet(netbios_session *s) ssize_t res; size_t total, sofar; - assert(s != NULL && s->packet != NULL && s->socket >= 0 && s->state > 0); + bdsm_assert(s != NULL && s->packet != NULL && s->socket >= 0 && s->state > 0); - // Only get packet header and analyze it to get only needed number of bytes - // needed for the packet. This will prevent losing a part of next packet - total = sizeof(netbios_session_packet); - sofar = 0; - while (sofar < total) - { - res = recv(s->socket, (uint8_t *)(s->packet) + sofar, total - sofar, 0); - if (res <= 0) - { - BDSM_perror("netbios_session_packet_recv: "); + if(s != NULL && s->packet != NULL && s->socket >= 0 && s->state > 0){ + + // Only get packet header and analyze it to get only needed number of bytes + // needed for the packet. This will prevent losing a part of next packet + total = sizeof(netbios_session_packet); + sofar = 0; + + if(socket_set_recv_timeout(s)==-1){ return -1; } - sofar += res; - } - - total = ntohs(s->packet->length); - total |= (s->packet->flags & 0x01) << 16; - sofar = 0; + + while (sofar < total) + { + res = recv(s->socket, (uint8_t *)(s->packet) + sofar, total - sofar, 0); + if (res <= 0) + { + BDSM_perror("netbios_session_packet_recv: "); + return -1; + } + sofar += res; + } - if (total + sizeof(netbios_session_packet) > s->packet_payload_size - && !session_buffer_realloc(s, total + sizeof(netbios_session_packet))) - return -1; + total = ntohs(s->packet->length); + total |= (s->packet->flags & 0x01) << 16; + sofar = 0; - //BDSM_dbg("Total = %ld, sofar = %ld\n", total, sofar); + if (total + sizeof(netbios_session_packet) > s->packet_payload_size + && !session_buffer_realloc(s, total + sizeof(netbios_session_packet))) + return -1; - while (sofar < total) - { - res = recv(s->socket, (uint8_t *)(s->packet) + sizeof(netbios_session_packet) - + sofar, total - sofar, 0); - //BDSM_dbg("Total = %ld, sofar = %ld, res = %ld\n", total, sofar, res); + //BDSM_dbg("Total = %ld, sofar = %ld\n", total, sofar); + + while (sofar < total) + { + res = recv(s->socket, (uint8_t *)(s->packet) + sizeof(netbios_session_packet) + + sofar, total - sofar, 0); + //BDSM_dbg("Total = %ld, sofar = %ld, res = %ld\n", total, sofar, res); + + if (res <= 0) + { + BDSM_perror("netbios_session_packet_recv: "); + return -1; + } + sofar += res; + } - if (res <= 0) + if (sofar > total) { - BDSM_perror("netbios_session_packet_recv: "); + BDSM_dbg("netbios_session_packet_recv: Packet size mismatch (%ld/%ld)\n", + sofar, total); return -1; } - sofar += res; - } - if (sofar > total) - { - BDSM_dbg("netbios_session_packet_recv: Packet size mismatch (%ld/%ld)\n", - sofar, total); - return -1; + return sofar; + } - - return sofar; + return -1; } ssize_t netbios_session_packet_recv(netbios_session *s, void **data) diff --git a/src/netbios_session.h b/src/netbios_session.h index abb89f6..9b570ac 100644 --- a/src/netbios_session.h +++ b/src/netbios_session.h @@ -51,7 +51,7 @@ typedef struct netbios_session_s { // The address of the remote peer; - struct sockaddr_in remote_addr; + struct addrinfo *remote_addr; // The socket of the TCP connection to the HOST' int socket; // The current sessions state; See macro before (eg. NETBIOS_SESSION_ERROR) @@ -68,7 +68,8 @@ typedef struct netbios_session_s // Return NULL if unable to open socket/connect netbios_session *netbios_session_new(size_t buf_size); void netbios_session_destroy(netbios_session *); -int netbios_session_connect(uint32_t ip, +int netbios_session_connect(const char *ip, + const char *user_port, netbios_session *s, const char *name, int direct_tcp); diff --git a/src/netbios_utils.c b/src/netbios_utils.c index b0f58b9..bbd8b99 100644 --- a/src/netbios_utils.c +++ b/src/netbios_utils.c @@ -28,7 +28,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include diff --git a/src/smb_buffer.c b/src/smb_buffer.c index 87ab60f..975a85d 100644 --- a/src/smb_buffer.c +++ b/src/smb_buffer.c @@ -28,11 +28,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include - #ifdef HAVE_ALLOCA_H # include #endif @@ -41,22 +40,29 @@ void smb_buffer_init(smb_buffer *buf, void *data, size_t size) { - assert(buf != NULL); - - buf->data = data; - buf->size = size; + bdsm_assert(buf != NULL); + + if(buf != NULL){ + buf->data = data; + buf->size = size; + } } int smb_buffer_alloc(smb_buffer *buf, size_t size) { - assert(buf != NULL); + bdsm_assert(buf != NULL); - buf->data = malloc(size); - if (buf->data) { - buf->size = size; - return 1; - } else - return 0; + if(buf != NULL){ + buf->data = malloc(size); + if (buf->data) { + buf->size = size; + return 1; + } else{ + return 0; + } + } + + return 0; } void smb_buffer_free(smb_buffer *buf) diff --git a/src/smb_defs.h b/src/smb_defs.h index 08af676..10baa25 100644 --- a/src/smb_defs.h +++ b/src/smb_defs.h @@ -36,13 +36,13 @@ #ifndef _SMB_DEFS_H_ #define _SMB_DEFS_H_ -#include "bdsm/smb_defs.h" +#include "../include/bdsm/smb_defs.h" //-----------------------------------------------------------------------------/ // Our own identity //-----------------------------------------------------------------------------/ -#define SMB_OS "Unix" -#define SMB_LANMAN "liBDSM" +#define SMB_OS "SMB_OS" +#define SMB_LANMAN "SMB_LANMAN" //-----------------------------------------------------------------------------/ @@ -68,6 +68,7 @@ #define SMB_CMD_TREE_DISCONNECT 0x71 #define SMB_CMD_NEGOTIATE 0x72 #define SMB_CMD_SETUP 0x73 // Session Setup AndX +#define SMB_CMD_LOGOFF 0x74 // Session Logoff AndX #define SMB_CMD_TREE_CONNECT 0x75 // Tree Connect AndX #define SMB_CMD_ECHO 0x2b #define SMB_CMD_READ 0x2e // Read AndX @@ -77,6 +78,7 @@ #define SMB_CMD_RMDIR 0x01 #define SMB_CMD_RMFILE 0x06 #define SMB_CMD_MOVE 0x07 // Move or rename +#define SMB_CMD_QUERY_INFO 0x08 // Query Information //-----------------------------------------------------------------------------/ // SMB FLAGS2 values diff --git a/src/smb_dir.c b/src/smb_dir.c index 40a0b03..2994d31 100644 --- a/src/smb_dir.c +++ b/src/smb_dir.c @@ -28,18 +28,19 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include #include #include #include #include +#include "../xcode/config.h" #include "smb_session_msg.h" #include "smb_fd.h" #include "smb_utils.h" #include "smb_dir.h" +#include "bdsm_debug.h" + int smb_directory_rm(smb_session *s, smb_tid tid, const char *path) { @@ -49,44 +50,55 @@ int smb_directory_rm(smb_session *s, smb_tid tid, const char *path) size_t utf_pattern_len; char *utf_pattern; - assert(s != NULL && path != NULL); + bdsm_assert(s != NULL && path != NULL); - utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); - if (utf_pattern_len == 0) - return DSM_ERROR_CHARSET; + if(s != NULL && path != NULL){ + + utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return DSM_ERROR_CHARSET; - req_msg = smb_message_new(SMB_CMD_RMDIR); - if (!req_msg) - { - free(utf_pattern); - return DSM_ERROR_GENERIC; - } + req_msg = smb_message_new(SMB_CMD_RMDIR); + if (!req_msg) + { + free(utf_pattern); + return DSM_ERROR_GENERIC; + } - req_msg->packet->header.tid = (uint16_t)tid; + req_msg->packet->header.tid = (uint16_t)tid; - SMB_MSG_INIT_PKT(req); - req.wct = 0x00; // Must be 0 - req.bct = (uint16_t)(utf_pattern_len + 1); - req.buffer_format = 0x04; // Must be 4 - SMB_MSG_PUT_PKT(req_msg, req); - smb_message_append(req_msg, utf_pattern, utf_pattern_len); + SMB_MSG_INIT_PKT(req); + req.wct = 0x00; // Must be 0 + req.bct = (uint16_t)(utf_pattern_len + 1); + req.buffer_format = 0x04; // Must be 4 + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_append(req_msg, utf_pattern, utf_pattern_len); - smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); + smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); - free(utf_pattern); + free(utf_pattern); - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; + + if (resp_msg.payload_size < sizeof(smb_directory_rm_resp)) + { + BDSM_dbg("[smb_directory_rm]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } - resp = (smb_directory_rm_resp *)resp_msg.packet->payload; - if ((resp->wct != 0) || (resp->bct != 0)) - return DSM_ERROR_NETWORK; + resp = (smb_directory_rm_resp *)resp_msg.packet->payload; + if ((resp->wct != 0) || (resp->bct != 0)) + return DSM_ERROR_NETWORK; - return 0; + return DSM_SUCCESS; + } + + return DSM_ERROR_GENERIC; } int smb_directory_create(smb_session *s, smb_tid tid, const char *path) @@ -97,42 +109,53 @@ int smb_directory_create(smb_session *s, smb_tid tid, const char *path) size_t utf_pattern_len; char *utf_pattern; - assert(s != NULL && path != NULL); + bdsm_assert(s != NULL && path != NULL); - utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); - if (utf_pattern_len == 0) - return DSM_ERROR_CHARSET; + if(s != NULL && path != NULL){ + + utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return DSM_ERROR_CHARSET; - req_msg = smb_message_new(SMB_CMD_MKDIR); - if (!req_msg) - { - free(utf_pattern); - return DSM_ERROR_GENERIC; - } + req_msg = smb_message_new(SMB_CMD_MKDIR); + if (!req_msg) + { + free(utf_pattern); + return DSM_ERROR_GENERIC; + } - req_msg->packet->header.tid = (uint16_t)tid; + req_msg->packet->header.tid = (uint16_t)tid; - SMB_MSG_INIT_PKT(req); - req.wct = 0x00; // Must be 0 - req.bct = (uint16_t)(utf_pattern_len + 1); - req.buffer_format = 0x04; // Must be 4 - SMB_MSG_PUT_PKT(req_msg, req); - smb_message_append(req_msg, utf_pattern, utf_pattern_len); + SMB_MSG_INIT_PKT(req); + req.wct = 0x00; // Must be 0 + req.bct = (uint16_t)(utf_pattern_len + 1); + req.buffer_format = 0x04; // Must be 4 + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_append(req_msg, utf_pattern, utf_pattern_len); - smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); + smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); - free(utf_pattern); + free(utf_pattern); - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; + + if (resp_msg.payload_size < sizeof(smb_directory_mk_resp)) + { + BDSM_dbg("[smb_directory_create]Malformed message %s\n", path); + return DSM_ERROR_NETWORK; + } - resp = (smb_directory_mk_resp *)resp_msg.packet->payload; - if ((resp->wct != 0) || (resp->bct != 0)) - return DSM_ERROR_NETWORK; + resp = (smb_directory_mk_resp *)resp_msg.packet->payload; + if ((resp->wct != 0) || (resp->bct != 0)) + return DSM_ERROR_NETWORK; - return 0; + return DSM_SUCCESS; + + } + return DSM_ERROR_GENERIC; } diff --git a/src/smb_dir.h b/src/smb_dir.h index 3c6dbf3..d35087c 100644 --- a/src/smb_dir.h +++ b/src/smb_dir.h @@ -36,6 +36,6 @@ #ifndef _SMB_DIR_H_ #define _SMB_DIR_H_ -#include "bdsm/smb_dir.h" +#include "../include/bdsm/smb_dir.h" #endif diff --git a/src/smb_fd.c b/src/smb_fd.c index 6745e1b..8a9a1ed 100644 --- a/src/smb_fd.c +++ b/src/smb_fd.c @@ -28,67 +28,78 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include +#include "../xcode/config.h" #include "smb_fd.h" void smb_session_share_add(smb_session *s, smb_share *share) { smb_share *iter; - assert(s != NULL && share != NULL); + bdsm_assert(s != NULL && share != NULL); - if (s->shares == NULL) - { - s->shares = share; - return; - } + if(s != NULL && share != NULL){ + + if (s->shares == NULL) + { + s->shares = share; + return; + } - iter = s->shares; - while (iter->next != NULL) - iter = iter->next; - iter->next = share; + iter = s->shares; + while (iter->next != NULL){ + iter = iter->next; + } + iter->next = share; + } + } smb_share *smb_session_share_get(smb_session *s, smb_tid tid) { smb_share *iter; - assert(s != NULL); + bdsm_assert(s != NULL); - iter = s->shares; - while (iter != NULL && iter->tid != tid) - iter = iter->next; + if(s != NULL){ + + iter = s->shares; + while (iter != NULL && iter->tid != tid) + iter = iter->next; - return iter; + return iter; + } + return NULL; } smb_share *smb_session_share_remove(smb_session *s, smb_tid tid) { smb_share *iter, *keep; - assert(s != NULL); + bdsm_assert(s != NULL); + + if(s != NULL){ - iter = s->shares; + iter = s->shares; - if (iter == NULL) - return NULL; - if (iter->tid == tid) - { - s->shares = s->shares->next; - return iter; - } + if (iter == NULL) + return NULL; + if (iter->tid == tid) + { + s->shares = s->shares->next; + return iter; + } - while (iter->next != NULL && iter->next->tid != tid) - iter = iter->next; + while (iter->next != NULL && iter->next->tid != tid) + iter = iter->next; - if (iter->next != NULL) // We found it - { - keep = iter->next; - iter->next = iter->next->next; - return keep; + if (iter->next != NULL) // We found it + { + keep = iter->next; + iter->next = iter->next->next; + return keep; + } } return NULL; } @@ -98,24 +109,27 @@ void smb_session_share_clear(smb_session *s) smb_share *iter, *tmp; smb_file *fiter, *ftmp; - assert(s != NULL); + bdsm_assert(s != NULL); - iter = s->shares; - while(iter != NULL) - { - fiter = iter->files; - while(fiter != NULL) - { - ftmp = fiter; - fiter = fiter->next; + if(s != NULL){ + + iter = s->shares; + while(iter != NULL) + { + fiter = iter->files; + while(fiter != NULL) + { + ftmp = fiter; + fiter = fiter->next; - free(ftmp->name); - free(ftmp); - } + free(ftmp->name); + free(ftmp); + } - tmp = iter; - iter = iter->next; - free(tmp); + tmp = iter; + iter = iter->next; + free(tmp); + } } } @@ -124,22 +138,27 @@ int smb_session_file_add(smb_session *s, smb_tid tid, smb_file *f) smb_share *share; smb_file *iter; - assert(s != NULL && f != NULL); + bdsm_assert(s != NULL && f != NULL); - if ((share = smb_session_share_get(s, tid)) == NULL) - return 0; + if(s != NULL && f != NULL){ + + if ((share = smb_session_share_get(s, tid)) == NULL) + return 0; - if (share->files == NULL) - share->files = f; - else - { - iter = share->files; - while (iter->next != NULL) - iter = iter->next; - iter->next = f; - } + if (share->files == NULL) + share->files = f; + else + { + iter = share->files; + while (iter->next != NULL) + iter = iter->next; + iter->next = f; + } - return 1; + return 1; + } + + return 0; } smb_file *smb_session_file_get(smb_session *s, smb_fd fd) @@ -147,16 +166,21 @@ smb_file *smb_session_file_get(smb_session *s, smb_fd fd) smb_share *share; smb_file *iter; - assert(s != NULL && fd); + bdsm_assert(s != NULL && fd); - if ((share = smb_session_share_get(s, SMB_FD_TID(fd))) == NULL) - return NULL; + if(s != NULL && fd){ + + if ((share = smb_session_share_get(s, SMB_FD_TID(fd))) == NULL) + return NULL; - iter = share->files; - while (iter != NULL && iter->fid != SMB_FD_FID(fd)) - iter = iter->next; + iter = share->files; + while (iter != NULL && iter->fid != SMB_FD_FID(fd)) + iter = iter->next; - return iter; + return iter; + + } + return NULL; } smb_file *smb_session_file_remove(smb_session *s, smb_fd fd) @@ -164,29 +188,34 @@ smb_file *smb_session_file_remove(smb_session *s, smb_fd fd) smb_share *share; smb_file *iter, *keep; - assert(s != NULL && fd); + bdsm_assert(s != NULL && fd); + + if(s != NULL && fd){ - if ((share = smb_session_share_get(s, SMB_FD_TID(fd))) == NULL) - return NULL; + if ((share = smb_session_share_get(s, SMB_FD_TID(fd))) == NULL) + return NULL; - iter = share->files; + iter = share->files; - if (iter == NULL) - return NULL; - if (iter->fid == SMB_FD_FID(fd)) - { - share->files = iter->next; - return iter; - } + if (iter == NULL) + return NULL; + if (iter->fid == SMB_FD_FID(fd)) + { + share->files = iter->next; + return iter; + } - while (iter->next != NULL && iter->next->fid != SMB_FD_TID(fd)) - iter = iter->next; - if (iter->next != NULL) - { - keep = iter->next; - iter->next = iter->next->next; - return keep; + while (iter->next != NULL && iter->next->fid != SMB_FD_TID(fd)) + iter = iter->next; + if (iter->next != NULL) + { + keep = iter->next; + iter->next = iter->next->next; + return keep; + } + else + return NULL; } - else - return NULL; + + return NULL; } diff --git a/src/smb_file.c b/src/smb_file.c index af42170..a56071b 100644 --- a/src/smb_file.c +++ b/src/smb_file.c @@ -28,18 +28,19 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include #include #include #include #include +#include "../xcode/config.h" #include "smb_session_msg.h" #include "smb_fd.h" #include "smb_utils.h" #include "smb_file.h" +#include "bdsm_debug.h" + int smb_fopen(smb_session *s, smb_tid tid, const char *path, uint32_t o_flags, smb_fd *fd) @@ -53,87 +54,98 @@ int smb_fopen(smb_session *s, smb_tid tid, const char *path, int res; char *utf_path; - assert(s != NULL && path != NULL && fd != NULL); - - if ((share = smb_session_share_get(s, tid)) == NULL) - return DSM_ERROR_GENERIC; - - path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); - if (path_len == 0) - return DSM_ERROR_CHARSET; - - req_msg = smb_message_new(SMB_CMD_CREATE); - if (!req_msg) { + bdsm_assert(s != NULL && path != NULL && fd != NULL); + + if(s != NULL && path != NULL && fd != NULL){ + + if ((share = smb_session_share_get(s, tid)) == NULL) + return DSM_ERROR_GENERIC; + + path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); + if (path_len == 0) + return DSM_ERROR_CHARSET; + + req_msg = smb_message_new(SMB_CMD_CREATE); + if (!req_msg) { + free(utf_path); + return DSM_ERROR_GENERIC; + } + + // Set SMB Headers + req_msg->packet->header.tid = tid; + + // Create AndX Params + SMB_MSG_INIT_PKT_ANDX(req); + req.wct = 24; + req.flags = 0; + req.root_fid = 0; + req.access_mask = o_flags; + req.alloc_size = 0; + req.file_attr = 0; + req.share_access = SMB_SHARE_READ | SMB_SHARE_WRITE; + if ((o_flags & SMB_MOD_RW) == SMB_MOD_RW) + { + req.disposition = SMB_DISPOSITION_FILE_SUPERSEDE; // Create if doesn't exist + req.create_opts = SMB_CREATEOPT_WRITE_THROUGH; + } + else + { + req.disposition = SMB_DISPOSITION_FILE_OPEN; // Open and fails if doesn't exist + req.create_opts = 0; // We dont't support create + } + req.impersonation = SMB_IMPERSONATION_SEC_IMPERSONATE; + req.security_flags = SMB_SECURITY_NO_TRACKING; + req.path_length = path_len; + req.bct = path_len + 1; + SMB_MSG_PUT_PKT(req_msg, req); + + // Create AndX 'Body' + smb_message_put8(req_msg, 0); // Align beginning of path + smb_message_append(req_msg, utf_path, path_len); free(utf_path); - return DSM_ERROR_GENERIC; - } - - // Set SMB Headers - req_msg->packet->header.tid = tid; - // Create AndX Params - SMB_MSG_INIT_PKT_ANDX(req); - req.wct = 24; - req.flags = 0; - req.root_fid = 0; - req.access_mask = o_flags; - req.alloc_size = 0; - req.file_attr = 0; - req.share_access = SMB_SHARE_READ | SMB_SHARE_WRITE; - if ((o_flags & SMB_MOD_RW) == SMB_MOD_RW) - { - req.disposition = SMB_DISPOSITION_FILE_SUPERSEDE; // Create if doesn't exist - req.create_opts = SMB_CREATEOPT_WRITE_THROUGH; - } - else - { - req.disposition = SMB_DISPOSITION_FILE_OPEN; // Open and fails if doesn't exist - req.create_opts = 0; // We dont't support create + // smb_message_put16(req_msg, 0); // ?? + + res = smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); + if (!res) + return DSM_ERROR_NETWORK; + + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; + + if (resp_msg.payload_size < sizeof(smb_create_resp)) + { + BDSM_dbg("[smb_fopen]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_create_resp *)resp_msg.packet->payload; + file = calloc(1, sizeof(smb_file)); + if (!file) + return DSM_ERROR_GENERIC; + + + file->fid = resp->fid; + file->tid = tid; + file->created = resp->created; + file->accessed = resp->accessed; + file->written = resp->written; + file->changed = resp->changed; + file->alloc_size = resp->alloc_size; + file->size = resp->size; + file->attr = resp->attr; + file->is_dir = resp->is_dir; + + smb_session_file_add(s, tid, file); // XXX Check return + + *fd = SMB_FD(tid, file->fid); + return DSM_SUCCESS; } - req.impersonation = SMB_IMPERSONATION_SEC_IMPERSONATE; - req.security_flags = SMB_SECURITY_NO_TRACKING; - req.path_length = path_len; - req.bct = path_len + 1; - SMB_MSG_PUT_PKT(req_msg, req); - - // Create AndX 'Body' - smb_message_put8(req_msg, 0); // Align beginning of path - smb_message_append(req_msg, utf_path, path_len); - free(utf_path); - - // smb_message_put16(req_msg, 0); // ?? - - res = smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); - if (!res) - return DSM_ERROR_NETWORK; - - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; - - resp = (smb_create_resp *)resp_msg.packet->payload; - file = calloc(1, sizeof(smb_file)); - if (!file) - return DSM_ERROR_GENERIC; - - - file->fid = resp->fid; - file->tid = tid; - file->created = resp->created; - file->accessed = resp->accessed; - file->written = resp->written; - file->changed = resp->changed; - file->alloc_size = resp->alloc_size; - file->size = resp->size; - file->attr = resp->attr; - file->is_dir = resp->is_dir; - - smb_session_file_add(s, tid, file); // XXX Check return - - *fd = SMB_FD(tid, file->fid); - return DSM_SUCCESS; + + return DSM_ERROR_GENERIC; } void smb_fclose(smb_session *s, smb_fd fd) @@ -142,9 +154,10 @@ void smb_fclose(smb_session *s, smb_fd fd) smb_message *msg; smb_close_req req; - assert(s != NULL); - if (!fd) - return; + bdsm_assert(s != NULL); + if (s==NULL || fd==0){ + return; + } // XXX Memory leak, destroy the file after removing it if ((file = smb_session_file_remove(s, fd)) == NULL) @@ -185,8 +198,11 @@ ssize_t smb_fread(smb_session *s, smb_fd fd, void *buf, size_t buf_size) size_t max_read; int res; - assert(s != NULL); - + bdsm_assert(s != NULL); + if (s==NULL || fd==0){ + return -1; + } + if ((file = smb_session_file_get(s, fd)) == NULL) return -1; @@ -219,8 +235,22 @@ ssize_t smb_fread(smb_session *s, smb_fd fd, void *buf, size_t buf_size) return -1; if (!smb_session_check_nt_status(s, &resp_msg)) return -1; + + if (resp_msg.payload_size < sizeof(smb_read_resp)) + { + BDSM_dbg("[smb_fread]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } resp = (smb_read_resp *)resp_msg.packet->payload; + + if (resp_msg.packet->payload + resp_msg.payload_size < + (uint8_t *)resp_msg.packet + resp->data_offset + resp->data_len) + { + BDSM_dbg("[smb_fread]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } + if (buf) memcpy(buf, (char *)resp_msg.packet + resp->data_offset, resp->data_len); smb_fseek(s, fd, resp->data_len, SEEK_CUR); @@ -237,68 +267,85 @@ ssize_t smb_fwrite(smb_session *s, smb_fd fd, void *buf, size_t buf_size) uint16_t max_write; int res; - assert(s != NULL && buf != NULL); - - file = smb_session_file_get(s, fd); - if (file == NULL) - return -1; - - req_msg = smb_message_new(SMB_CMD_WRITE); - if (!req_msg) - return -1; - req_msg->packet->header.tid = (uint16_t)file->tid; - - // total size of SMB message shall not exceed maximum size of netbios data payload - max_write = UINT16_MAX - sizeof(smb_packet) - sizeof(smb_write_req); - max_write = max_write < buf_size ? max_write : (uint16_t)buf_size; - - SMB_MSG_INIT_PKT_ANDX(req); - req.wct = 14; // Must be 14 - req.fid = file->fid; - req.offset = file->offset & 0xffffffff; - req.timeout = 0; - req.write_mode = SMB_WRITEMODE_WRITETHROUGH; - req.remaining = 0; - req.reserved = 0; - req.data_len = max_write; - req.data_offset = sizeof(smb_packet) + sizeof(smb_write_req); - req.offset_high = (file->offset >> 32) & 0xffffffff; - req.bct = max_write; - SMB_MSG_PUT_PKT(req_msg, req); - smb_message_append(req_msg, buf, max_write); - - res = smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); - if (!res) - return -1; - - if (!smb_session_recv_msg(s, &resp_msg)) - return -1; - if (!smb_session_check_nt_status(s, &resp_msg)) - return -1; - - resp = (smb_write_resp *)resp_msg.packet->payload; - - smb_fseek(s, fd, resp->data_len, SEEK_CUR); - - return resp->data_len; + bdsm_assert(s != NULL && buf != NULL); + + if (s != NULL && buf != NULL){ + + file = smb_session_file_get(s, fd); + if (file == NULL) + return -1; + + req_msg = smb_message_new(SMB_CMD_WRITE); + if (!req_msg) + return -1; + req_msg->packet->header.tid = (uint16_t)file->tid; + + // total size of SMB message shall not exceed maximum size of netbios data payload + max_write = UINT16_MAX - sizeof(smb_packet) - sizeof(smb_write_req); + max_write = max_write < buf_size ? max_write : (uint16_t)buf_size; + + SMB_MSG_INIT_PKT_ANDX(req); + req.wct = 14; // Must be 14 + req.fid = file->fid; + req.offset = file->offset & 0xffffffff; + req.timeout = 0; + req.write_mode = SMB_WRITEMODE_WRITETHROUGH; + req.remaining = 0; + req.reserved = 0; + req.data_len = max_write; + req.data_offset = sizeof(smb_packet) + sizeof(smb_write_req); + req.offset_high = (file->offset >> 32) & 0xffffffff; + req.bct = max_write; + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_append(req_msg, buf, max_write); + + res = smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); + if (!res) + return -1; + + if (!smb_session_recv_msg(s, &resp_msg)) + return -1; + if (!smb_session_check_nt_status(s, &resp_msg)) + return -1; + + if (resp_msg.payload_size < sizeof(smb_write_resp)) + { + BDSM_dbg("[smb_fwrite]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_write_resp *)resp_msg.packet->payload; + + smb_fseek(s, fd, resp->data_len, SEEK_CUR); + + return resp->data_len; + + } + + return -1; } ssize_t smb_fseek(smb_session *s, smb_fd fd, off_t offset, int whence) { smb_file *file; - assert(s != NULL); + bdsm_assert(s != NULL); + + if(s!=NULL){ - if ((file = smb_session_file_get(s, fd)) == NULL) - return -1; + if ((file = smb_session_file_get(s, fd)) == NULL) + return -1; - if (whence == SMB_SEEK_SET) - file->offset = offset; - else if (whence == SMB_SEEK_CUR) - file->offset += offset; + if (whence == SMB_SEEK_SET) + file->offset = offset; + else if (whence == SMB_SEEK_CUR) + file->offset += offset; - return file->offset; + return file->offset; + + } + return -1; } int smb_file_rm(smb_session *s, smb_tid tid, const char *path) @@ -309,45 +356,56 @@ int smb_file_rm(smb_session *s, smb_tid tid, const char *path) size_t utf_pattern_len; char *utf_pattern; - assert(s != NULL && path != NULL); + bdsm_assert(s != NULL && path != NULL); + + if(s != NULL && path != NULL){ - utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); - if (utf_pattern_len == 0) - return DSM_ERROR_CHARSET; + utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return DSM_ERROR_CHARSET; - req_msg = smb_message_new(SMB_CMD_RMFILE); - if (!req_msg) - { - free(utf_pattern); - return DSM_ERROR_GENERIC; - } - - req_msg->packet->header.tid = (uint16_t)tid; - req_msg->packet->header.flags2 = SMB_FLAGS2_LONG_NAMES; - - SMB_MSG_INIT_PKT(req); - req.wct = 0x01; // Must be 1 - req.search_attributes = SMB_ATTR_HIDDEN | SMB_ATTR_SYS; - req.bct = (uint16_t)(utf_pattern_len + 1); - req.buffer_format = 0x04; // Must be 4 - SMB_MSG_PUT_PKT(req_msg, req); - smb_message_append(req_msg, utf_pattern, utf_pattern_len); + req_msg = smb_message_new(SMB_CMD_RMFILE); + if (!req_msg) + { + free(utf_pattern); + return DSM_ERROR_GENERIC; + } - smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); + req_msg->packet->header.tid = (uint16_t)tid; + req_msg->packet->header.flags2 = SMB_FLAGS2_LONG_NAMES; - free(utf_pattern); + SMB_MSG_INIT_PKT(req); + req.wct = 0x01; // Must be 1 + req.search_attributes = SMB_ATTR_HIDDEN | SMB_ATTR_SYS; + req.bct = (uint16_t)(utf_pattern_len + 1); + req.buffer_format = 0x04; // Must be 4 + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_append(req_msg, utf_pattern, utf_pattern_len); - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; + smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); - resp = (smb_file_rm_resp *)resp_msg.packet->payload; - if ((resp->wct != 0) || (resp->bct != 0)) - return DSM_ERROR_NETWORK; + free(utf_pattern); - return 0; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; + + if (resp_msg.payload_size < sizeof(smb_file_rm_resp)) + { + BDSM_dbg("[smb_file_rm]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_file_rm_resp *)resp_msg.packet->payload; + if ((resp->wct != 0) || (resp->bct != 0)) + return DSM_ERROR_NETWORK; + + return 0; + } + + return DSM_ERROR_GENERIC; } int smb_file_mv(smb_session *s, smb_tid tid, const char *old_path, const char *new_path) @@ -358,56 +416,66 @@ int smb_file_mv(smb_session *s, smb_tid tid, const char *old_path, const c size_t utf_old_len,utf_new_len; char *utf_old_path,*utf_new_path; - assert(s != NULL && old_path != NULL && new_path != NULL); - - utf_old_len = smb_to_utf16(old_path, strlen(old_path) + 1, &utf_old_path); - if (utf_old_len == 0) - return DSM_ERROR_CHARSET; + bdsm_assert(s != NULL && old_path != NULL && new_path != NULL); + + if(s != NULL && old_path != NULL && new_path != NULL){ + + utf_old_len = smb_to_utf16(old_path, strlen(old_path) + 1, &utf_old_path); + if (utf_old_len == 0) + return DSM_ERROR_CHARSET; + + utf_new_len = smb_to_utf16(new_path, strlen(new_path) + 1, &utf_new_path); + if (utf_new_len == 0) + { + free(utf_old_path); + return DSM_ERROR_CHARSET; + } + + req_msg = smb_message_new(SMB_CMD_MOVE); + if (!req_msg) + { + free(utf_old_path); + free(utf_new_path); + return DSM_ERROR_GENERIC; + } + + req_msg->packet->header.tid = (uint16_t)tid; + req_msg->packet->header.flags2 = SMB_FLAGS2_LONG_NAMES; + + SMB_MSG_INIT_PKT(req); + req.wct = 0x01; // Must be 1 + req.search_attributes = SMB_ATTR_HIDDEN | SMB_ATTR_SYS; + req.bct = (uint16_t)(utf_old_len + utf_new_len + 3); // We have 2 bytes for buffer formats and 1 padding byte + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_put8(req_msg, 0x04); // Buffer format 1, must be 4 + smb_message_append(req_msg, utf_old_path, utf_old_len); + smb_message_put8(req_msg, 0x04); // Buffer format 2, must be 4 + smb_message_put8(req_msg, 0x00); // padding to have next byte 16 bits aligned + smb_message_append(req_msg, utf_new_path, utf_new_len); + + smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); - utf_new_len = smb_to_utf16(new_path, strlen(new_path) + 1, &utf_new_path); - if (utf_new_len == 0) - { - free(utf_old_path); - return DSM_ERROR_CHARSET; - } - - req_msg = smb_message_new(SMB_CMD_MOVE); - if (!req_msg) - { free(utf_old_path); free(utf_new_path); - return DSM_ERROR_GENERIC; - } - req_msg->packet->header.tid = (uint16_t)tid; - req_msg->packet->header.flags2 = SMB_FLAGS2_LONG_NAMES; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; - SMB_MSG_INIT_PKT(req); - req.wct = 0x01; // Must be 1 - req.search_attributes = SMB_ATTR_HIDDEN | SMB_ATTR_SYS; - req.bct = (uint16_t)(utf_old_len + utf_new_len + 3); // We have 2 bytes for buffer formats and 1 padding byte - SMB_MSG_PUT_PKT(req_msg, req); - smb_message_put8(req_msg, 0x04); // Buffer format 1, must be 4 - smb_message_append(req_msg, utf_old_path, utf_old_len); - smb_message_put8(req_msg, 0x00); // padding to have next byte 16 bits aligned - smb_message_put8(req_msg, 0x04); // Buffer format 2, must be 4 - smb_message_append(req_msg, utf_new_path, utf_new_len); + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; - smb_session_send_msg(s, req_msg); - smb_message_destroy(req_msg); + if (resp_msg.payload_size < sizeof(smb_file_mv_resp)) + { + BDSM_dbg("[smb_file_mv]Malformed message.\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_file_mv_resp *)resp_msg.packet->payload; + if ((resp->wct != 0) || (resp->bct != 0)) + return DSM_ERROR_NETWORK; - free(utf_old_path); - free(utf_new_path); - - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; - - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; - - resp = (smb_file_mv_resp *)resp_msg.packet->payload; - if ((resp->wct != 0) || (resp->bct != 0)) - return DSM_ERROR_NETWORK; - - return DSM_SUCCESS; + return DSM_SUCCESS; + } + return DSM_ERROR_GENERIC; } diff --git a/src/smb_file.h b/src/smb_file.h index b052fba..b794dfe 100644 --- a/src/smb_file.h +++ b/src/smb_file.h @@ -36,6 +36,6 @@ #ifndef _SMB_FILE_H_ #define _SMB_FILE_H_ -#include "bdsm/smb_file.h" +#include "../include/bdsm/smb_file.h" #endif diff --git a/src/smb_message.c b/src/smb_message.c index 43b64ac..e21c0c1 100644 --- a/src/smb_message.c +++ b/src/smb_message.c @@ -28,7 +28,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include diff --git a/src/smb_ntlm.c b/src/smb_ntlm.c index 8c2c867..600ddad 100644 --- a/src/smb_ntlm.c +++ b/src/smb_ntlm.c @@ -28,7 +28,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #ifdef _WIN32 # define _CRT_RAND_S @@ -49,8 +49,8 @@ #include "compat.h" #endif -#include "mdx/md4.h" -#include "rc4/rc4.h" +#include "../contrib/mdx/md4.h" +#include "../contrib/rc4/rc4.h" #include "bdsm_debug.h" #include "hmac_md5.h" #include "smb_utils.h" @@ -97,27 +97,34 @@ void smb_ntlm_hash(const char *password, smb_ntlmh hash) char *ucs2le_pass; size_t sz; - assert(password != NULL && hash != NULL); + bdsm_assert(password != NULL && hash != NULL); + + if(password != NULL && hash != NULL){ - sz = smb_to_utf16(password, strlen(password), &ucs2le_pass); - memset((void *)hash, 0, SMB_NTLM_HASH_SIZE); + sz = smb_to_utf16(password, strlen(password), &ucs2le_pass); + memset((void *)hash, 0, SMB_NTLM_HASH_SIZE); - MD4_Init(&ctx); - MD4_Update(&ctx, (uint8_t *)ucs2le_pass, sz); - MD4_Final((uint8_t *)hash, &ctx); + MD4_CTX_Init(&ctx); + MD4_CTX_Update(&ctx, (uint8_t *)ucs2le_pass, sz); + MD4_CTX_Final((uint8_t *)hash, &ctx); - free(ucs2le_pass); + free(ucs2le_pass); + } } static void _upcase(char *str) { - assert(str != NULL); - - while (*str) - { - if (isalpha(*str)) - *str = toupper(*str); - str++; + bdsm_assert(str != NULL); + + if(str != NULL){ + + while (*str) + { + if (isalpha(*str)) + *str = toupper(*str); + str++; + } + } } @@ -220,7 +227,7 @@ uint8_t *smb_lm2_response(smb_ntlmh hash_v2, uint64_t srv_challenge, // char *res; // size_t res_sz; -// assert(names != NULL && domain != NULL && host != NULL); +// bdsm_assert(names != NULL && domain != NULL && host != NULL); // wdomain_sz = smb_to_utf16(domain, strlen(domain) + 1, &wdomain); // wdomain_camel_sz = smb_to_utf16(domain, strlen(domain) + 1, &wdomain_camel); @@ -232,7 +239,7 @@ uint8_t *smb_lm2_response(smb_ntlmh hash_v2, uint64_t srv_challenge, // res_sz = (wdomain_sz - 2) * 2 + (whost_sz - 2) * 2 + 8 + 6 * 4; // *names = res = malloc(res_sz); -// assert(res != NULL); +// bdsm_assert(res != NULL); // memset(res, 0, res_sz); // __NAME_ENCODE_APPEND(2, wdomain) @@ -260,21 +267,26 @@ size_t smb_ntlm_make_blob(smb_ntlm_blob **out_blob, uint64_t ts, { smb_ntlm_blob *blob; - assert(out_blob != NULL && target != NULL); + bdsm_assert(out_blob != NULL && target != NULL); + + if(out_blob != NULL && target != NULL){ - blob = malloc(target->size + sizeof(smb_ntlm_blob)); - if (!blob) - return 0; + blob = malloc(target->size + sizeof(smb_ntlm_blob)); + if (!blob) + return 0; - memset((void *)blob, 0, sizeof(smb_ntlm_blob)); - blob->header = 0x101; - blob->timestamp = ts; - blob->challenge = user_challenge; + memset((void *)blob, 0, sizeof(smb_ntlm_blob)); + blob->header = 0x101; + blob->timestamp = ts; + blob->challenge = user_challenge; - memcpy(blob->target, target->data, target->size); + memcpy(blob->target, target->data, target->size); - *out_blob = blob; - return sizeof(smb_ntlm_blob) + target->size; + *out_blob = blob; + return sizeof(smb_ntlm_blob) + target->size; + } + + return 0; } void smb_ntlm2_session_key(smb_ntlmh hash_v2, void *ntlm2, @@ -295,28 +307,32 @@ void smb_ntlmssp_negotiate(const char *host, const char *domain, { smb_ntlmssp_nego *nego; - assert(host != NULL && domain != NULL && token != NULL); + bdsm_assert(host != NULL && domain != NULL && token != NULL); + + if(host != NULL && domain != NULL && token != NULL){ - token->size = sizeof(smb_ntlmssp_nego) + strlen(host) + strlen(domain); - if (token->size % 2) // Align on Word - token->size += 1; - if (smb_buffer_alloc(token, token->size) == 0) - return; - // BDSM_dbg("Token size if %ld\n", token->size); + token->size = sizeof(smb_ntlmssp_nego) + strlen(host) + strlen(domain); + if (token->size % 2) // Align on Word + token->size += 1; + if (smb_buffer_alloc(token, token->size) == 0) + return; + // BDSM_dbg("Token size if %ld\n", token->size); - nego = (smb_ntlmssp_nego *)token->data; + nego = (smb_ntlmssp_nego *)token->data; - nego->type = SMB_NTLMSSP_CMD_NEGO; - nego->flags = 0x60088215;//0x20080205; - nego->domain_len = nego->domain_maxlen = strlen(domain); - nego->domain_offset = 32; - nego->host_len = nego->host_maxlen = strlen(host); - nego->host_offset = 32 + strlen(domain); + nego->type = SMB_NTLMSSP_CMD_NEGO; + nego->flags = 0x60088215;//0x20080205; + nego->domain_len = nego->domain_maxlen = strlen(domain); + nego->domain_offset = 32; + nego->host_len = nego->host_maxlen = strlen(host); + nego->host_offset = 32 + strlen(domain); - memcpy(nego->id, "NTLMSSP", 8); - memcpy(nego->names, domain, strlen(domain)); - memcpy(nego->names + strlen(domain), domain, strlen(domain)); + memcpy(nego->id, "NTLMSSP", 8); + memcpy(nego->names, domain, strlen(domain)); + memcpy(nego->names + strlen(domain), domain, strlen(domain)); + } + } #define __AUTH_APPEND(FIELD, value, size, cursor) \ @@ -339,62 +355,74 @@ void smb_ntlmssp_response(uint64_t srv_challenge, uint64_t srv_ts, uint64_t user_challenge; char *utf; - assert(host != NULL && domain != NULL && user != NULL && password != NULL); - assert(token != NULL && target != NULL); - - //// We compute most of the data first to know the final token size - smb_ntlm2_hash(user, password, domain, hash_v2); - user_challenge = smb_ntlm_generate_challenge(); - smb_ntlm_generate_xkey(xkey); - blob_size = smb_ntlm_make_blob(&blob, srv_ts, user_challenge, target); - - lm2 = smb_lm2_response(hash_v2, srv_challenge, smb_ntlm_generate_challenge()); - smb_buffer_init(&buf, blob, blob_size); - ntlm2 = smb_ntlm2_response(hash_v2, srv_challenge, &buf); - smb_ntlm2_session_key(hash_v2, ntlm2, xkey, xkey_crypt); - - smb_buffer_init(&buf, NULL, 0); - free(blob); - - // Compute size of and allocate token - token->size = sizeof(smb_ntlmssp_auth) - + strlen(host) * 2 - + strlen(domain) * 2 - + strlen(user) * 2 - + blob_size + 16 // Blob + HMAC - + 8 + 16 // LM2 Response (miniblob=user_challenge + HMAC) - + 16; // Session Key - if (token->size % 2) // Align on Word - token->size += 1; - if (smb_buffer_alloc(token, token->size) == 0) { + bdsm_assert(host != NULL && domain != NULL && user != NULL && password != NULL); + bdsm_assert(token != NULL && target != NULL); + + if(host != NULL && domain != NULL && user != NULL && password != NULL + && token != NULL && target != NULL){ + + //// We compute most of the data first to know the final token size + smb_ntlm2_hash(user, password, domain, hash_v2); + user_challenge = smb_ntlm_generate_challenge(); + smb_ntlm_generate_xkey(xkey); + blob_size = smb_ntlm_make_blob(&blob, srv_ts, user_challenge, target); + + lm2 = smb_lm2_response(hash_v2, srv_challenge, smb_ntlm_generate_challenge()); + smb_buffer_init(&buf, blob, blob_size); + ntlm2 = smb_ntlm2_response(hash_v2, srv_challenge, &buf); + smb_ntlm2_session_key(hash_v2, ntlm2, xkey, xkey_crypt); + + smb_buffer_init(&buf, NULL, 0); + free(blob); + + // Compute size of and allocate token + token->size = sizeof(smb_ntlmssp_auth) + + strlen(host) * 2 + + strlen(domain) * 2 + + strlen(user) * 2 + + blob_size + 16 // Blob + HMAC + + 8 + 16 // LM2 Response (miniblob=user_challenge + HMAC) + + 16; // Session Key + if (token->size % 2) // Align on Word + token->size += 1; + if (smb_buffer_alloc(token, token->size) == 0) { + free(lm2); + free(ntlm2); + return; + } + + auth = (smb_ntlmssp_auth *)token->data; + memset(auth, 0, token->size); + + memcpy(auth->id, "NTLMSSP", 8); + auth->type = SMB_NTLMSSP_CMD_AUTH; + auth->flags = 0x60088215; + + + if (*domain || *user || *password) { + __AUTH_APPEND(lm, lm2, 24, cursor) + __AUTH_APPEND(ntlm, ntlm2, blob_size + 16, cursor) + } + + if (*domain) { + utf_sz = smb_to_utf16(domain, strlen(domain), &utf); + __AUTH_APPEND(domain, utf, utf_sz, cursor) + free(utf); + } + if (*user) { + utf_sz = smb_to_utf16(user, strlen(user), &utf); + __AUTH_APPEND(user, utf, utf_sz, cursor) + free(utf); + } + if (*host) { + utf_sz = smb_to_utf16(host, strlen(host), &utf); + __AUTH_APPEND(host, utf, utf_sz, cursor) + free(utf); + } + + __AUTH_APPEND(session_key, &xkey_crypt, 16, cursor) + free(lm2); free(ntlm2); - return; } - - auth = (smb_ntlmssp_auth *)token->data; - memset(auth, 0, token->size); - - memcpy(auth->id, "NTLMSSP", 8); - auth->type = SMB_NTLMSSP_CMD_AUTH; - auth->flags = 0x60088215; - - - __AUTH_APPEND(lm, lm2, 24, cursor) - __AUTH_APPEND(ntlm, ntlm2, blob_size + 16, cursor) - - utf_sz = smb_to_utf16(domain, strlen(domain), &utf); - __AUTH_APPEND(domain, utf, utf_sz, cursor) - free(utf); - utf_sz = smb_to_utf16(user, strlen(user), &utf); - __AUTH_APPEND(user, utf, utf_sz, cursor) - free(utf); - utf_sz = smb_to_utf16(host, strlen(host), &utf); - __AUTH_APPEND(host, utf, utf_sz, cursor) - free(utf); - - __AUTH_APPEND(session_key, &xkey_crypt, 16, cursor) - - free(lm2); - free(ntlm2); } diff --git a/src/smb_packets.h b/src/smb_packets.h index d0e3eda..bf42b39 100644 --- a/src/smb_packets.h +++ b/src/smb_packets.h @@ -97,8 +97,8 @@ SMB_PACKED_START typedef struct uint32_t max_rawbuffer; /* Max raw buffer size requested by serv. */ \ uint32_t session_key; /* 'MUST' be returned to server */ \ uint32_t caps; \ - uint64_t ts; /* I don't give a fuck (or do i?) */ \ - uint16_t tz; /* Even less fuck given */ \ + uint64_t ts; /* Server time */ \ + uint16_t tz; /* Server time zone */ \ uint8_t key_length; /* Size of challenge key // GSS blob */ \ uint16_t bct; @@ -394,9 +394,29 @@ SMB_PACKED_START typedef struct uint8_t payload[]; } SMB_PACKED_END smb_trans_req; - - - +//-> Fstat +SMB_PACKED_START typedef struct +{ + uint8_t wct; // 15 + uint16_t total_param_count; + uint16_t total_data_count; + uint16_t max_param_count; + uint16_t max_data_count; + uint8_t max_setup_count; + uint8_t reserved; + uint16_t flags; + uint32_t timeout; + uint16_t reserve2; + uint16_t param_count; + uint16_t param_offset; + uint16_t data_count; + uint16_t data_offset; + uint8_t setup_count; + uint8_t reserved3; + uint16_t cmd; + uint16_t bct; + uint8_t reserved4; +} SMB_PACKED_END smb_trans2_query_path_info_req; //-> Trans2 SMB_PACKED_START typedef struct @@ -535,6 +555,43 @@ SMB_PACKED_START typedef struct uint8_t name[]; } SMB_PACKED_END smb_tr2_path_info; +//// <- QueryBasicPathInfo +SMB_PACKED_START typedef struct +{ + uint64_t created; + uint64_t accessed; + uint64_t written; + uint64_t changed; + uint32_t attr; +} SMB_PACKED_END smb_tr2_basic_path_info; + +//// <- QueryStandardPathInfo +SMB_PACKED_START typedef struct +{ + uint64_t alloc_size; + uint64_t size; + uint32_t link_count; + uint8_t rm_pending; + uint8_t is_dir; +} SMB_PACKED_END smb_tr2_standard_path_info; + +//// <- QueryPathInfo Response +SMB_PACKED_START typedef struct +{ + uint8_t wct; + uint16_t attr; + uint32_t written; + uint32_t size; +} SMB_PACKED_END smb_query_path_info_resp; + +//// <- QueryPathInfo Request +SMB_PACKED_START typedef struct +{ + uint8_t wct; + uint16_t bct; + uint8_t buffer_format; +} SMB_PACKED_END smb_query_path_info_req; + //-> Example SMB_PACKED_START typedef struct { diff --git a/src/smb_session.c b/src/smb_session.c index b8fc2e9..51eaf71 100644 --- a/src/smb_session.c +++ b/src/smb_session.c @@ -28,15 +28,13 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - -#include "compat.h" - #include #include #include #include +#include "../xcode/config.h" +#include "../xcode/extra/spnego_asn1_mutex.h" #include "bdsm_debug.h" #include "smb_session.h" #include "smb_session_msg.h" @@ -44,6 +42,8 @@ #include "smb_ntlm.h" #include "smb_spnego.h" #include "smb_transport.h" +#include "compat.h" + static int smb_negotiate(smb_session *s); @@ -76,84 +76,97 @@ smb_session *smb_session_new() void smb_session_destroy(smb_session *s) { - assert(s != NULL); - - smb_session_share_clear(s); - - // FIXME Free smb_share and smb_file - if (s->transport.session != NULL) - { - s->transport.destroy(s->transport.session); - s->transport.session = NULL; + bdsm_assert(s != NULL); + + if(s!=NULL){ + + smb_session_share_clear(s); + + // FIXME Free smb_share and smb_file + if (s->transport.session != NULL) + { + s->transport.destroy(s->transport.session); + s->transport.session = NULL; + } + + if (s->spnego_asn1 != NULL){ + asn1_lock(); + asn1_delete_structure(&s->spnego_asn1); + asn1_unlock(); + } + + smb_buffer_free(&s->xsec_target); + + // Free stored credentials. + free(s->creds.domain); + free(s->creds.login); + free(s->creds.password); + free(s); } - - if (s->spnego_asn1 != NULL) - asn1_delete_structure(&s->spnego_asn1); - - smb_buffer_free(&s->xsec_target); - - // Free stored credentials. - free(s->creds.domain); - free(s->creds.login); - free(s->creds.password); - free(s); } void smb_session_set_creds(smb_session *s, const char *domain, const char *login, const char *password) { - assert(s != NULL); - - if (domain != NULL) - { - if (s->creds.domain != NULL) - free(s->creds.domain); - s->creds.domain = strndup(domain, SMB_CREDS_MAXLEN); - } - - if (login != NULL) - { - if (s->creds.login != NULL) - free(s->creds.login); - s->creds.login = strndup(login, SMB_CREDS_MAXLEN); - } - - if (password != NULL) - { - if (s->creds.password != NULL) - free(s->creds.password); - s->creds.password = strndup(password, SMB_CREDS_MAXLEN); + bdsm_assert(s != NULL); + + if(s!=NULL){ + + if (domain != NULL) + { + if (s->creds.domain != NULL) + free(s->creds.domain); + s->creds.domain = strndup(domain, SMB_CREDS_MAXLEN); + } + + if (login != NULL) + { + if (s->creds.login != NULL) + free(s->creds.login); + s->creds.login = strndup(login, SMB_CREDS_MAXLEN); + } + + if (password != NULL) + { + if (s->creds.password != NULL) + free(s->creds.password); + s->creds.password = strndup(password, SMB_CREDS_MAXLEN); + } } } int smb_session_connect(smb_session *s, const char *name, - uint32_t ip, int transport) + const char *ip,const char *user_port, int transport) { - assert(s != NULL && name != NULL); - - if (s->transport.session != NULL) - s->transport.destroy(s->transport.session); - - switch (transport) - { - case SMB_TRANSPORT_TCP: - smb_transport_tcp(&s->transport); - break; - case SMB_TRANSPORT_NBT: - smb_transport_nbt(&s->transport); - break; - default: + bdsm_assert(s != NULL && name != NULL); + + if(s != NULL && name != NULL){ + + if (s->transport.session != NULL) + s->transport.destroy(s->transport.session); + + switch (transport) + { + case SMB_TRANSPORT_TCP: + smb_transport_tcp(&s->transport); + break; + case SMB_TRANSPORT_NBT: + smb_transport_nbt(&s->transport); + break; + default: + return DSM_ERROR_GENERIC; + } + + if ((s->transport.session = s->transport.new(SMB_DEFAULT_BUFSIZE)) == NULL) return DSM_ERROR_GENERIC; - } - - if ((s->transport.session = s->transport.new(SMB_DEFAULT_BUFSIZE)) == NULL) - return DSM_ERROR_GENERIC; - if (!s->transport.connect(ip, s->transport.session, name)) - return DSM_ERROR_NETWORK; + if (!s->transport.connect(ip,user_port, s->transport.session, name)) + return DSM_ERROR_NETWORK; - memcpy(s->srv.name, name, strlen(name) + 1); + memcpy(s->srv.name, name, strlen(name) + 1); - return smb_negotiate(s); + return smb_negotiate(s); + } + return DSM_ERROR_GENERIC; } static int smb_negotiate(smb_session *s) @@ -162,51 +175,65 @@ static int smb_negotiate(smb_session *s) smb_message *msg = NULL; smb_message answer; smb_nego_resp *nego; - uint16_t *p_payload_size; + uint16_t payload_size; + - assert(s != NULL); + bdsm_assert(s != NULL); + + if(s!=NULL){ - msg = smb_message_new(SMB_CMD_NEGOTIATE); - if (!msg) - return DSM_ERROR_GENERIC; + msg = smb_message_new(SMB_CMD_NEGOTIATE); + if (!msg) + return DSM_ERROR_GENERIC; + + smb_message_put8(msg, 0); // wct + smb_message_put16(msg, 0); // bct, will be updated later - smb_message_put8(msg, 0); // wct - smb_message_put16(msg, 0); // bct, will be updated later + for (unsigned i = 0; dialects[i] != NULL; i++) + smb_message_append(msg, dialects[i], strlen(dialects[i]) + 1); + payload_size = msg->cursor - 3; + memcpy(msg->packet->payload + 1, &payload_size, sizeof(payload_size)); - for (unsigned i = 0; dialects[i] != NULL; i++) - smb_message_append(msg, dialects[i], strlen(dialects[i]) + 1); - p_payload_size = (uint16_t *)(msg->packet->payload + 1); - *p_payload_size = msg->cursor - 3; - if (!smb_session_send_msg(s, msg)) - { + if (!smb_session_send_msg(s, msg)) + { + smb_message_destroy(msg); + return DSM_ERROR_NETWORK; + } smb_message_destroy(msg); - return DSM_ERROR_NETWORK; + + if (!smb_session_recv_msg(s, &answer)) + return DSM_ERROR_NETWORK; + + if (answer.payload_size < sizeof(smb_nego_resp)) + { + BDSM_dbg("[smb_negotiate]Malformed message\n"); + return DSM_ERROR_NETWORK; + } + + nego = (smb_nego_resp *)answer.packet->payload; + if (!smb_session_check_nt_status(s, &answer)) + return DSM_ERROR_NT; + if (nego->wct != 0x11) + return DSM_ERROR_NETWORK; + + s->srv.dialect = nego->dialect_index; + s->srv.security_mode = nego->security_mode; + s->srv.caps = nego->caps; + s->srv.ts = nego->ts; + s->srv.tz = nego->tz; + s->srv.session_key = nego->session_key; + + // Copy SPNEGO supported mechanisms token for later usage (login_gss()) + if (smb_session_supports(s, SMB_SESSION_XSEC)) + BDSM_dbg("Server is supporting extended security\n"); + else + s->srv.challenge = nego->challenge; + + return DSM_SUCCESS; + } - smb_message_destroy(msg); - - if (!smb_session_recv_msg(s, &answer)) - return DSM_ERROR_NETWORK; - - nego = (smb_nego_resp *)answer.packet->payload; - if (!smb_session_check_nt_status(s, &answer)) - return DSM_ERROR_NT; - if (nego->wct != 0x11) - return DSM_ERROR_NETWORK; - - s->srv.dialect = nego->dialect_index; - s->srv.security_mode = nego->security_mode; - s->srv.caps = nego->caps; - s->srv.ts = nego->ts; - s->srv.session_key = nego->session_key; - - // Copy SPNEGO supported mechanisms token for later usage (login_gss()) - if (smb_session_supports(s, SMB_SESSION_XSEC)) - BDSM_dbg("Server is supporting extended security\n"); - else - s->srv.challenge = nego->challenge; - - return DSM_SUCCESS; + return DSM_ERROR_GENERIC; } @@ -220,146 +247,259 @@ static int smb_session_login_ntlm(smb_session *s, const char *domain, smb_ntlmh hash_v2; uint64_t user_challenge; - assert(s != NULL); - - msg = smb_message_new(SMB_CMD_SETUP); - if (!msg) - return DSM_ERROR_GENERIC; - - // this struct will be set at the end when we know the payload size - SMB_MSG_ADVANCE_PKT(msg, smb_session_req); - - user_challenge = smb_ntlm_generate_challenge(); - - // LM2 Response - smb_ntlm2_hash(user, password, domain, hash_v2); - ntlm2 = smb_lm2_response(hash_v2, s->srv.challenge, user_challenge); - smb_message_append(msg, ntlm2, 16 + 8); - free(ntlm2); - - if (msg->cursor / 2) // Padding ! - smb_message_put8(msg, 0); - - smb_message_put_utf16(msg, user, strlen(user)); - smb_message_put16(msg, 0); - smb_message_put_utf16(msg, domain, strlen(domain)); - smb_message_put16(msg, 0); - smb_message_put_utf16(msg, SMB_OS, strlen(SMB_OS)); - smb_message_put16(msg, 0); - smb_message_put_utf16(msg, SMB_LANMAN, strlen(SMB_LANMAN)); - smb_message_put16(msg, 0); - - SMB_MSG_INIT_PKT_ANDX(req); - req.wct = 13; - req.max_buffer = SMB_SESSION_MAX_BUFFER; - req.mpx_count = 16; // XXX ? - req.vc_count = 1; - //req.session_key = s->srv.session_key; // XXX Useless on the wire? - req.caps = s->srv.caps; // XXX caps & our_caps_mask - req.oem_pass_len = 16 + SMB_LM2_BLOB_SIZE; - req.uni_pass_len = 0; //16 + blob_size; //SMB_NTLM2_BLOB_SIZE; - req.payload_size = msg->cursor - sizeof(smb_session_req); - SMB_MSG_INSERT_PKT(msg, 0, req); - - if (!smb_session_send_msg(s, msg)) - { + bdsm_assert(s != NULL); + + if(s!=NULL){ + + msg = smb_message_new(SMB_CMD_SETUP); + if (!msg) + return DSM_ERROR_GENERIC; + + // this struct will be set at the end when we know the payload size + SMB_MSG_ADVANCE_PKT(msg, smb_session_req); + + user_challenge = smb_ntlm_generate_challenge(); + + // LM2 Response + smb_ntlm2_hash(user, password, domain, hash_v2); + ntlm2 = smb_lm2_response(hash_v2, s->srv.challenge, user_challenge); + smb_message_append(msg, ntlm2, 16 + 8); + free(ntlm2); + + if (msg->cursor / 2) // Padding ! + smb_message_put8(msg, 0); + + smb_message_put_utf16(msg, user, strlen(user)); + smb_message_put16(msg, 0); + smb_message_put_utf16(msg, domain, strlen(domain)); + smb_message_put16(msg, 0); + smb_message_put_utf16(msg, SMB_OS, strlen(SMB_OS)); + smb_message_put16(msg, 0); + smb_message_put_utf16(msg, SMB_LANMAN, strlen(SMB_LANMAN)); + smb_message_put16(msg, 0); + + SMB_MSG_INIT_PKT_ANDX(req); + req.wct = 13; + req.max_buffer = SMB_SESSION_MAX_BUFFER; + req.mpx_count = 16; // XXX ? + req.vc_count = 1; + //req.session_key = s->srv.session_key; // XXX Useless on the wire? + req.caps = s->srv.caps; // XXX caps & our_caps_mask + req.oem_pass_len = 16 + SMB_LM2_BLOB_SIZE; + req.uni_pass_len = 0; //16 + blob_size; //SMB_NTLM2_BLOB_SIZE; + req.payload_size = msg->cursor - sizeof(smb_session_req); + SMB_MSG_INSERT_PKT(msg, 0, req); + + if (!smb_session_send_msg(s, msg)) + { + smb_message_destroy(msg); + BDSM_dbg("Unable to send Session Setup AndX message\n"); + return DSM_ERROR_NETWORK; + } smb_message_destroy(msg); - BDSM_dbg("Unable to send Session Setup AndX message\n"); - return DSM_ERROR_NETWORK; - } - smb_message_destroy(msg); - if (smb_session_recv_msg(s, &answer) == 0) - { - BDSM_dbg("Unable to get Session Setup AndX reply\n"); - return DSM_ERROR_NETWORK; + if (smb_session_recv_msg(s, &answer) == 0) + { + BDSM_dbg("Unable to get Session Setup AndX reply\n"); + return DSM_ERROR_NETWORK; + } + + if (answer.payload_size < sizeof(smb_session_resp)) + { + BDSM_dbg("[smb_negotiate]Malformed message\n"); + return DSM_ERROR_NETWORK; + } + + smb_session_resp *r = (smb_session_resp *)answer.packet->payload; + if (!smb_session_check_nt_status(s, &answer)) + { + BDSM_dbg("Session Setup AndX : failure.\n"); + return DSM_ERROR_NT; + } + + if (r->action & 0x0001) + s->guest = true; + + s->srv.uid = answer.packet->header.uid; + s->logged = true; + + return DSM_SUCCESS; } + + return DSM_ERROR_GENERIC; +} - smb_session_resp *r = (smb_session_resp *)answer.packet->payload; - if (!smb_session_check_nt_status(s, &answer)) - { - BDSM_dbg("Session Setup AndX : failure.\n"); - return DSM_ERROR_NT; +int smb_session_login(smb_session *s) +{ + bdsm_assert(s != NULL); + + if(s!=NULL){ + + if (s->creds.domain == NULL + || s->creds.login == NULL + || s->creds.password == NULL) + return DSM_ERROR_GENERIC; + + if (smb_session_supports(s, SMB_SESSION_XSEC)) + return (smb_session_login_spnego(s, s->creds.domain, s->creds.login, + s->creds.password)); + else + return (smb_session_login_ntlm(s, s->creds.domain, s->creds.login, + s->creds.password)); } - - if (r->action & 0x0001) - s->guest = true; - - s->srv.uid = answer.packet->header.uid; - s->logged = true; - - return DSM_SUCCESS; + return DSM_ERROR_GENERIC; } -int smb_session_login(smb_session *s) +static int smb_session_logoff_andx(smb_session *s, const char *domain, + const char *user, const char *password) { - assert(s != NULL); - - if (s->creds.domain == NULL - || s->creds.login == NULL - || s->creds.password == NULL) - return DSM_ERROR_GENERIC; - - if (smb_session_supports(s, SMB_SESSION_XSEC)) - return (smb_session_login_spnego(s, s->creds.domain, s->creds.login, - s->creds.password)); - else - return (smb_session_login_ntlm(s, s->creds.domain, s->creds.login, - s->creds.password)); + + smb_message *msg = NULL; + + + bdsm_assert(s != NULL); + + if(s!=NULL){ + + msg = smb_message_new(SMB_CMD_LOGOFF); + if (!msg) + return DSM_ERROR_GENERIC; + + smb_message_put8(msg, 0x02); // wct=2 + smb_message_put8(msg, 0xff); //andx: no further commands + smb_message_put8(msg, 0); //reserved + smb_message_put16(msg, 0); // andx offset + smb_message_put16(msg, 0); // bct + + if (!smb_session_send_msg(s, msg)) + { + smb_message_destroy(msg); + BDSM_dbg("Unable to send Session Logoff AndX message\n"); + return DSM_ERROR_NETWORK; + } + smb_message_destroy(msg); + + s->srv.uid = 0; + s->logged = false; + s->guest = false; + + return DSM_SUCCESS; + } + + return DSM_ERROR_GENERIC; } +int smb_session_logoff(smb_session *s) +{ + bdsm_assert(s != NULL); + + if(s!=NULL){ + + if (s->creds.domain == NULL + || s->creds.login == NULL + || s->creds.password == NULL) + return DSM_ERROR_GENERIC; + + return (smb_session_logoff_andx(s, s->creds.domain, s->creds.login, + s->creds.password)); + } + + return DSM_ERROR_GENERIC; +} int smb_session_is_guest(smb_session *s) { - assert(s != NULL); + bdsm_assert(s != NULL); + + if(s!=NULL){ - // We're not logged in yet. - if (s->logged != true) - return -1; + // We're not logged in yet. + if (s->logged != true) + return -1; - // We're logged in as guest - if (s->guest) - return 1; + // We're logged in as guest + if (s->guest) + return 1; - // We're logged in as regular user - return 0; + // We're logged in as regular user + return 0; + + } + return -1; } const char *smb_session_server_name(smb_session *s) { - assert(s != NULL); + bdsm_assert(s != NULL); - return s->srv.name; + if(s!=NULL){ + return s->srv.name; + } + return NULL; +} + +uint64_t smb_session_server_time_stamp(smb_session *s) +{ + bdsm_assert(s != NULL); + + if(s!=NULL){ + return s->srv.ts; + } + return 0; +} + +uint16_t smb_session_server_time_zone(smb_session *s) +{ + bdsm_assert(s != NULL); + + if(s!=NULL){ + return s->srv.tz; + } + return 0; } int smb_session_supports(smb_session *s, int what) { - assert(s != NULL); - - switch (what) - { - case SMB_SESSION_XSEC: - return s->srv.caps & SMB_CAPS_XSEC; - default: - return 0; + bdsm_assert(s != NULL); + + if(s!=NULL){ + + switch (what) + { + case SMB_SESSION_XSEC: + return s->srv.caps & SMB_CAPS_XSEC; + case SMB_SESSION_NTSMB: + return s->srv.caps & SMB_CAPS_NTSMB; + default: + return 0; + } } + return 0; } uint32_t smb_session_get_nt_status(smb_session *s) { - assert(s != NULL); + bdsm_assert(s != NULL); - return s->nt_status; + if(s!=NULL){ + return s->nt_status; + } + return 0; } bool smb_session_check_nt_status(smb_session *s, smb_message *msg) { - assert(s != NULL && msg != NULL); - - if (msg->packet->header.status != NT_STATUS_SUCCESS) - { - s->nt_status = msg->packet->header.status; - return false; + bdsm_assert(s != NULL && msg != NULL); + + if(s != NULL && msg != NULL){ + + if (msg->packet->header.status != NT_STATUS_SUCCESS) + { + s->nt_status = msg->packet->header.status; + return false; + } + return true; + } - return true; + return false; } diff --git a/src/smb_session.h b/src/smb_session.h index 4c9e21a..03d5bc8 100644 --- a/src/smb_session.h +++ b/src/smb_session.h @@ -32,7 +32,7 @@ #define _SMB_SESSION_H_ #include "smb_types.h" -#include "bdsm/smb_session.h" +#include "../include/bdsm/smb_session.h" /** * @file smb_session.h diff --git a/src/smb_session_msg.c b/src/smb_session_msg.c index 7e01c0c..2023505 100644 --- a/src/smb_session_msg.c +++ b/src/smb_session_msg.c @@ -28,10 +28,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include - +#include "../xcode/config.h" #include "smb_session.h" #include "smb_message.h" @@ -39,24 +37,29 @@ int smb_session_send_msg(smb_session *s, smb_message *msg) { size_t pkt_sz; - assert(s != NULL); - assert(s->transport.session != NULL); - assert(msg != NULL && msg->packet != NULL); + bdsm_assert(s != NULL); + bdsm_assert(s->transport.session != NULL); + bdsm_assert(msg != NULL && msg->packet != NULL); - msg->packet->header.flags = 0x18; - msg->packet->header.flags2 = 0xc843; - // msg->packet->header.flags2 = 0xc043; // w/o extended security; - msg->packet->header.uid = s->srv.uid; + if( s != NULL && s->transport.session != NULL && msg != NULL && msg->packet != NULL){ + + msg->packet->header.flags = 0x18; + msg->packet->header.flags2 = 0xc843; + // msg->packet->header.flags2 = 0xc043; // w/o extended security; + msg->packet->header.uid = s->srv.uid; - s->transport.pkt_init(s->transport.session); + s->transport.pkt_init(s->transport.session); - pkt_sz = sizeof(smb_packet) + msg->cursor; - if (!s->transport.pkt_append(s->transport.session, (void *)msg->packet, pkt_sz)) - return 0; - if (!s->transport.send(s->transport.session)) - return 0; + pkt_sz = sizeof(smb_packet) + msg->cursor; + if (!s->transport.pkt_append(s->transport.session, (void *)msg->packet, pkt_sz)) + return 0; + if (!s->transport.send(s->transport.session)) + return 0; - return 1; + return 1; + + } + return 0; } size_t smb_session_recv_msg(smb_session *s, smb_message *msg) @@ -64,21 +67,26 @@ size_t smb_session_recv_msg(smb_session *s, smb_message *msg) void *data; ssize_t payload_size; - assert(s != NULL && s->transport.session != NULL); + bdsm_assert(s != NULL && s->transport.session != NULL); + + if( s != NULL && s->transport.session != NULL ){ - payload_size = s->transport.recv(s->transport.session, &data); - if (payload_size <= 0) - return 0; + payload_size = s->transport.recv(s->transport.session, &data); + if (payload_size <= 0) + return 0; - if ((size_t)payload_size < sizeof(smb_header)) - return 0; + if ((size_t)payload_size < sizeof(smb_header)) + return 0; - if (msg != NULL) - { - msg->packet = (smb_packet *)data; - msg->payload_size = payload_size - sizeof(smb_header); - msg->cursor = 0; - } + if (msg != NULL) + { + msg->packet = (smb_packet *)data; + msg->payload_size = payload_size - sizeof(smb_header); + msg->cursor = 0; + } - return payload_size - sizeof(smb_header); + return payload_size - sizeof(smb_header); + } + + return 0; } diff --git a/src/smb_share.c b/src/smb_share.c index 4d7a598..b549d08 100644 --- a/src/smb_share.c +++ b/src/smb_share.c @@ -28,14 +28,13 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include #include #include #include #include +#include "../xcode/config.h" #include "bdsm_debug.h" #include "smb_session_msg.h" #include "smb_utils.h" @@ -53,63 +52,74 @@ int smb_tree_connect(smb_session *s, const char *name, smb_tid *tid) size_t path_len, utf_path_len; char *path, *utf_path; - assert(s != NULL && name != NULL && tid != NULL); - - req_msg = smb_message_new(SMB_CMD_TREE_CONNECT); - if (!req_msg) - return DSM_ERROR_GENERIC; - - // Build \\SERVER\Share path from name - path_len = strlen(name) + strlen(s->srv.name) + 4; - path = alloca(path_len); - snprintf(path, path_len, "\\\\%s\\%s", s->srv.name, name); - utf_path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); - - // Packet headers - req_msg->packet->header.tid = 0xffff; // Behavior of libsmbclient - - smb_message_set_andx_members(req_msg); - - // Packet payload - SMB_MSG_INIT_PKT_ANDX(req); - req.wct = 4; - req.flags = 0x0c; // (??) - req.passwd_len = 1; // Null byte - req.bct = utf_path_len + 6 + 1; - SMB_MSG_PUT_PKT(req_msg, req); - - smb_message_put8(req_msg, 0); // Ze null byte password; - smb_message_append(req_msg, utf_path, utf_path_len); - free(utf_path); - smb_message_append(req_msg, "?????", strlen("?????") + 1); - - if (!smb_session_send_msg(s, req_msg)) - { + bdsm_assert(s != NULL && name != NULL && tid != NULL); + + if( s != NULL && name != NULL && tid != NULL ){ + + req_msg = smb_message_new(SMB_CMD_TREE_CONNECT); + if (!req_msg) + return DSM_ERROR_GENERIC; + + // Build \\SERVER\Share path from name + path_len = strlen(name) + strlen(s->srv.name) + 4; + path = alloca(path_len); + snprintf(path, path_len, "\\\\%s\\%s", s->srv.name, name); + utf_path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); + + // Packet headers + req_msg->packet->header.tid = 0xffff; // Behavior of libsmbclient + + smb_message_set_andx_members(req_msg); + + // Packet payload + SMB_MSG_INIT_PKT_ANDX(req); + req.wct = 4; + req.flags = 0x0c; // (??) + req.passwd_len = 1; // Null byte + req.bct = utf_path_len + 6 + 1; + SMB_MSG_PUT_PKT(req_msg, req); + + smb_message_put8(req_msg, 0); // Ze null byte password; + smb_message_append(req_msg, utf_path, utf_path_len); + free(utf_path); + smb_message_append(req_msg, "?????", strlen("?????") + 1); + + if (!smb_session_send_msg(s, req_msg)) + { + smb_message_destroy(req_msg); + return DSM_ERROR_NETWORK; + } smb_message_destroy(req_msg); - return DSM_ERROR_NETWORK; - } - smb_message_destroy(req_msg); - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; - resp = (smb_tree_connect_resp *)resp_msg.packet->payload; - share = calloc(1, sizeof(smb_share)); - if (!share) - return DSM_ERROR_GENERIC; + if (resp_msg.payload_size < sizeof(smb_tree_connect_resp)) + { + BDSM_dbg("[smb_tree_connect]Malformed message\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_tree_connect_resp *)resp_msg.packet->payload; + share = calloc(1, sizeof(smb_share)); + if (!share) + return DSM_ERROR_GENERIC; - share->tid = resp_msg.packet->header.tid; - share->opts = resp->opt_support; - share->rights = resp->max_rights; - share->guest_rights = resp->guest_rights; + share->tid = resp_msg.packet->header.tid; + share->opts = resp->opt_support; + share->rights = resp->max_rights; + share->guest_rights = resp->guest_rights; - smb_session_share_add(s, share); + smb_session_share_add(s, share); - *tid = share->tid; - return 0; + *tid = share->tid; + return 0; + } + + return DSM_ERROR_GENERIC; } int smb_tree_disconnect(smb_session *s, smb_tid tid) @@ -119,37 +129,48 @@ int smb_tree_disconnect(smb_session *s, smb_tid tid) smb_message *req_msg; smb_message resp_msg; - assert(s != NULL); + bdsm_assert(s != NULL); + + if( s != NULL){ - req_msg = smb_message_new(SMB_CMD_TREE_DISCONNECT); - if (!req_msg) - return DSM_ERROR_GENERIC; + req_msg = smb_message_new(SMB_CMD_TREE_DISCONNECT); + if (!req_msg) + return DSM_ERROR_GENERIC; - // Packet headers - req_msg->packet->header.tid = (uint16_t)tid; + // Packet headers + req_msg->packet->header.tid = (uint16_t)tid; - // Packet payload - req.wct = 0; // Must be 0 - req.bct = 0; // Must be 0 - SMB_MSG_PUT_PKT(req_msg, req); + // Packet payload + req.wct = 0; // Must be 0 + req.bct = 0; // Must be 0 + SMB_MSG_PUT_PKT(req_msg, req); - if (!smb_session_send_msg(s, req_msg)) - { + if (!smb_session_send_msg(s, req_msg)) + { + smb_message_destroy(req_msg); + return DSM_ERROR_NETWORK; + } smb_message_destroy(req_msg); - return DSM_ERROR_NETWORK; - } - smb_message_destroy(req_msg); - if (!smb_session_recv_msg(s, &resp_msg)) - return DSM_ERROR_NETWORK; - if (!smb_session_check_nt_status(s, &resp_msg)) - return DSM_ERROR_NT; - - resp = (smb_tree_disconnect_resp *)resp_msg.packet->payload; - if ((resp->wct != 0) || (resp->bct != 0)) - return DSM_ERROR_NETWORK; - - return DSM_SUCCESS; + if (!smb_session_recv_msg(s, &resp_msg)) + return DSM_ERROR_NETWORK; + if (!smb_session_check_nt_status(s, &resp_msg)) + return DSM_ERROR_NT; + + if (resp_msg.payload_size < sizeof(smb_tree_disconnect_resp)) + { + BDSM_dbg("[smb_tree_disconnect]Malformed message\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_tree_disconnect_resp *)resp_msg.packet->payload; + if ((resp->wct != 0) || (resp->bct != 0)) + return DSM_ERROR_NETWORK; + + return DSM_SUCCESS; + } + + return DSM_ERROR_GENERIC; } // Here we parse the NetShareEnumAll response packet payload to extract @@ -160,38 +181,56 @@ static ssize_t smb_share_parse_enum(smb_message *msg, char ***list) uint8_t *data, *eod; uint32_t *p_share_count; - assert(msg != NULL && list != NULL); - // Let's skip smb parameters and DCE/RPC stuff until we are at the begginning of - // NetShareCtrl - - p_share_count = (uint32_t *)(msg->packet->payload + 60); - share_count = *p_share_count; - data = msg->packet->payload + 72 + share_count * 12; - eod = msg->packet->payload + msg->payload_size; - - *list = calloc(share_count + 1, sizeof(char *)); - if (!(*list)) - return -1; - - for (i = 0; i < share_count && data < eod; i++) - { - uint32_t name_len, com_len; - - name_len = *((uint32_t *)data); // Read 'Max Count', make it a multiple of 2 - data += 3 * sizeof(uint32_t); // Move pointer to beginning of Name. - - smb_from_utf16((const char *)data, name_len * 2, (*list) + i); - - if (name_len % 2) name_len += 1; // Align next move - data += name_len * 2; // Move the pointer to Comment 'Max count' - - com_len = *((uint32_t *)data); - data += 3 * sizeof(uint32_t); // Move pointer to beginning of Comment. - if (com_len % 2) com_len += 1; // Align next move - data += com_len * 2; // Move the pointer to next item + bdsm_assert(msg != NULL && list != NULL); + + if( msg != NULL && list != NULL ){ + + // Let's skip smb parameters and DCE/RPC stuff until we are at the begginning of + // NetShareCtrl + + p_share_count = (uint32_t *)(msg->packet->payload + 60); + share_count = *p_share_count; + data = msg->packet->payload + 72 + share_count * 12; + eod = msg->packet->payload + msg->payload_size; + + *list = calloc(share_count + 1, sizeof(char *)); + if (!(*list)) + return -1; + + for (i = 0; i < share_count && data < eod; i++) + { + uint32_t name_len, com_len; + + if (data + sizeof(uint32_t) > eod) + { + BDSM_dbg("[smb_share_parse_enum]Malformed message\n"); + break; + } + + name_len = *((uint32_t *)data); // Read 'Max Count', make it a multiple of 2 + data += 3 * sizeof(uint32_t); // Move pointer to beginning of Name. + + if (data + sizeof(uint32_t) + name_len * 2 + sizeof(uint32_t) > eod) + { + BDSM_dbg("[smb_share_parse_enum]Malformed message\n"); + break; + } + + smb_from_utf16((const char *)data, name_len * 2, (*list) + i); + + if (name_len % 2) name_len += 1; // Align next move + data += name_len * 2; // Move the pointer to Comment 'Max count' + + com_len = *((uint32_t *)data); + data += 3 * sizeof(uint32_t); // Move pointer to beginning of Comment. + if (com_len % 2) com_len += 1; // Align next move + data += com_len * 2; // Move the pointer to next item + } + + return i; } - - return i; + + return -1; } size_t smb_share_list_count(smb_share_list list) @@ -209,18 +248,23 @@ size_t smb_share_list_count(smb_share_list list) const char *smb_share_list_at(smb_share_list list, size_t index) { - assert(list != NULL); - - return list[index]; + bdsm_assert(list != NULL); + + if(list!=NULL){ + return list[index]; + } + + return NULL; } void smb_share_list_destroy(smb_share_list list) { - assert(list != NULL); - - for (size_t i = 0; list[i] != NULL; i++) - free(list[i]); - free(list); + bdsm_assert(list != NULL); + if(list!=NULL){ + for (size_t i = 0; list[i] != NULL; i++) + free(list[i]); + free(list); + } } // We should normally implement SCERPC and SRVSVC to perform a share list. But @@ -237,197 +281,220 @@ int smb_share_get_list(smb_session *s, smb_share_list *list, size_t ssize_t count; int ret; - assert(s != NULL && list != NULL); - *list = NULL; - - if ((ret = smb_tree_connect(s, "IPC$", &ipc_tid)) != DSM_SUCCESS) - return ret; - - if ((ret = smb_fopen(s, ipc_tid, "\\srvsvc", SMB_MOD_READ | SMB_MOD_WRITE, - &srvscv_fd)) != DSM_SUCCESS) + bdsm_assert(s != NULL && list != NULL); + + if(s != NULL && list != NULL){ + + *list = NULL; + + if ((ret = smb_tree_connect(s, "IPC$", &ipc_tid)) != DSM_SUCCESS) + return ret; + + if ((ret = smb_fopen(s, ipc_tid, "\\srvsvc", SMB_MOD_READ | SMB_MOD_WRITE, + &srvscv_fd)) != DSM_SUCCESS) + return ret; + + //// Phase 1: + // We bind a context or whatever for DCE/RPC + + req = smb_message_new(SMD_CMD_TRANS); + if (!req) + { + ret = DSM_ERROR_GENERIC; + goto error; + } + req->packet->header.tid = ipc_tid; + + rpc_len = 0xffff; + SMB_MSG_INIT_PKT(trans); + trans.wct = 16; + trans.total_data_count = 72; + trans.max_data_count = rpc_len; + trans.param_offset = 84; + trans.data_count = 72; + trans.data_offset = 84; + trans.setup_count = 2; + trans.pipe_function = 0x26; + trans.fid = SMB_FD_FID(srvscv_fd); + trans.bct = 89; + SMB_MSG_PUT_PKT(req, trans); + + smb_message_put8(req, 0); // Padding + smb_message_put_utf16(req, "\\PIPE\\", strlen("\\PIPE\\") + 1); + smb_message_put16(req, 0); // Padding to be aligned with wtf boundary :-/ + + // Now we'll 'build' the DCE/RPC Packet. This basically a copycat + // from wireshark values. + smb_message_put8(req, 5); // version major + smb_message_put8(req, 0); // minor + smb_message_put8(req, 0x0b); // Packet type = 'bind' + smb_message_put8(req, 0x03); // Packet flags = ?? + smb_message_put32(req, 0x10); // Representation = little endian/ASCII. Damn + smb_message_put16(req, 72); // Data len again + smb_message_put16(req, 0); // Auth len ? + smb_message_put32(req, 19); // Call ID ? + smb_message_put16(req, rpc_len); // Max Xmit size + smb_message_put16(req, rpc_len); // Max Recv size + smb_message_put32(req, 0); // Assoc group ? + + smb_message_put32(req, 1); // Num Ctx Item + // Adding the CtxItem, whatever could that be + smb_message_put16(req, 0); // ContextID + smb_message_put16(req, 1); // Num Trans Item + // SRVSVC UUID + const uint8_t uuid_e[8] = {0x12, 0x78, 0x5a, 0x47, 0xbf, 0x6e, 0xe1, 0x88}; + smb_message_put_uuid(req, 0x4b324fc8, 0x1670, 0x01d3, uuid_e); + smb_message_put16(req, 3); // Version + smb_message_put16(req, 0); // Minor + // Another UUID + const uint8_t uuid_e2[8] = {0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60}; + smb_message_put_uuid(req, 0x8a885d04, 0x1ceb, 0x11c9, uuid_e2); + smb_message_put32(req, 2); // Another version + + // Let's send this ugly pile of shit over the network ! + res = smb_session_send_msg(s, req); + smb_message_destroy(req); + if (!res) + { + ret = DSM_ERROR_NETWORK; + goto error; + } + + // Is the server throwing pile of shit back at me ? + res = smb_session_recv_msg(s, &resp); + + if (resp.payload_size < 71) + { + BDSM_dbg("[smb_share_get_list]Malformed message\n"); + ret = DSM_ERROR_NETWORK; + goto error; + } + + if (!res || resp.packet->payload[68]) + { + BDSM_dbg("Bind call failed: 0x%hhx (reason = 0x%hhx)\n", + resp.packet->payload[68], resp.packet->payload[70]); + ret = DSM_ERROR_NETWORK; + goto error; + } + + + //// Phase 2: + // Now we have the 'bind' done (regarless of what it is), we'll call + // NetShareEnumAll + + req = smb_message_new(SMD_CMD_TRANS); + if (!req) + { + ret = DSM_ERROR_GENERIC; + goto error; + } + req->packet->header.tid = ipc_tid; + + // this struct will be set at the end when we know the data size + SMB_MSG_ADVANCE_PKT(req, smb_trans_req); + + smb_message_put8(req, 0); // Padding + smb_message_put_utf16(req, "\\PIPE\\", strlen("\\PIPE\\") + 1); + smb_message_put16(req, 0); // Padding + + // Now we'll 'build' the DCE/RPC Packet. This basically a copycat + // from wireshark values. + smb_message_put8(req, 5); // version major + smb_message_put8(req, 0); // minor + smb_message_put8(req, 0); // Packet type = 'request' + smb_message_put8(req, 0x03); // Packet flags = ?? + smb_message_put32(req, 0x10); // Representation = little endian/ASCII. Damn + // Let's save the cursor here to update that later + frag_len_cursor = req->cursor; + smb_message_put16(req, 0); // Data len again (frag length) + smb_message_put16(req, 0); // Auth len ? + smb_message_put32(req, 12); // Call ID ? + smb_message_put32(req, 64); // Alloc hint ? + smb_message_put16(req, 0); // Context ID ? + smb_message_put16(req, 15); // OpNum = NetShareEnumAll + + // Pointer to server UNC + smb_message_put32(req, 0x00020000); // Referent ID ? + smb_message_put32(req, strlen(s->srv.name) + 1); // Max count + smb_message_put32(req, 0); // Offset + smb_message_put32(req, strlen(s->srv.name) + 1); // Actual count + // The server name, supposed to be downcased + smb_message_put_utf16(req, s->srv.name, strlen(s->srv.name) + 1); + if ((strlen(s->srv.name) % 2) == 0) // It won't be aligned with the terminating byte + smb_message_put16(req, 0); + + smb_message_put32(req, 1); // Level 1 ? + smb_message_put32(req, 1); // Ctr ? + smb_message_put32(req, 0x00020004); // Referent ID ? + smb_message_put64(req, 0); // Count/Null Pointer to NetShareInfo1 + smb_message_put32(req, 0xffffffff); // Max Buffer (0xffffffff required by smbX) + + smb_message_put32(req, 0x00020008); // Referent ID ? + smb_message_put32(req, 0); // Resume ? + + // fill trans pkt at the end since we know the size at the end + SMB_MSG_INIT_PKT(trans); + trans.wct = 16; + trans.max_data_count = 4280; + trans.setup_count = 2; + trans.pipe_function = 0x26; // TransactNmPipe; + trans.fid = SMB_FD_FID(srvscv_fd); + trans.bct = req->cursor - sizeof(smb_trans_req); + trans.data_count = trans.bct - 17; // 17 -> padding + \PIPE\ + padding + trans.total_data_count = trans.data_count; + trans.data_offset = 84; + trans.param_offset = 84; + // but insert it at the begining + SMB_MSG_INSERT_PKT(req, 0, trans); + + req->packet->payload[frag_len_cursor] = trans.data_count; // (data_count SHOULD stay < 256) + + // Let's send this ugly pile of shit over the network ! + res = smb_session_send_msg(s, req); + smb_message_destroy(req); + if (!res) + { + ret = DSM_ERROR_NETWORK; + goto error; + } + + // Is the server throwing pile of shit back at me ? + res = smb_session_recv_msg(s, &resp); + if (resp.payload_size < 4) + { + BDSM_dbg("[smb_share_get_list]Malformed message\n"); + ret = DSM_ERROR_NETWORK; + goto error; + } + + if (!res && (uint32_t)resp.packet->payload[resp.payload_size - 4]) + { + BDSM_dbg("NetShareEnumAll call failed.\n"); + ret = DSM_ERROR_NETWORK; + goto error; + } + + + //// Phase 3 + // We parse the list of Share (finally !) and build function response + count = smb_share_parse_enum(&resp, list); + if (count == -1) + { + ret = DSM_ERROR_GENERIC; + goto error; + } + if (pcount != NULL) + *pcount = count; + ret = DSM_SUCCESS; + + error: + // Close the pipe + smb_fclose(s, srvscv_fd); return ret; - - //// Phase 1: - // We bind a context or whatever for DCE/RPC - - req = smb_message_new(SMD_CMD_TRANS); - if (!req) - { - ret = DSM_ERROR_GENERIC; - goto error; - } - req->packet->header.tid = ipc_tid; - - rpc_len = 0xffff; - SMB_MSG_INIT_PKT(trans); - trans.wct = 16; - trans.total_data_count = 72; - trans.max_data_count = rpc_len; - trans.param_offset = 84; - trans.data_count = 72; - trans.data_offset = 84; - trans.setup_count = 2; - trans.pipe_function = 0x26; - trans.fid = SMB_FD_FID(srvscv_fd); - trans.bct = 89; - SMB_MSG_PUT_PKT(req, trans); - - smb_message_put8(req, 0); // Padding - smb_message_put_utf16(req, "\\PIPE\\", strlen("\\PIPE\\") + 1); - smb_message_put16(req, 0); // Padding to be aligned with wtf boundary :-/ - - // Now we'll 'build' the DCE/RPC Packet. This basically a copycat - // from wireshark values. - smb_message_put8(req, 5); // version major - smb_message_put8(req, 0); // minor - smb_message_put8(req, 0x0b); // Packet type = 'bind' - smb_message_put8(req, 0x03); // Packet flags = ?? - smb_message_put32(req, 0x10); // Representation = little endian/ASCII. Damn - smb_message_put16(req, 72); // Data len again - smb_message_put16(req, 0); // Auth len ? - smb_message_put32(req, 19); // Call ID ? - smb_message_put16(req, rpc_len); // Max Xmit size - smb_message_put16(req, rpc_len); // Max Recv size - smb_message_put32(req, 0); // Assoc group ? - - smb_message_put32(req, 1); // Num Ctx Item - // Adding the CtxItem, whatever could that be - smb_message_put16(req, 0); // ContextID - smb_message_put16(req, 1); // Num Trans Item - // SRVSVC UUID - const uint8_t uuid_e[8] = {0x12, 0x78, 0x5a, 0x47, 0xbf, 0x6e, 0xe1, 0x88}; - smb_message_put_uuid(req, 0x4b324fc8, 0x1670, 0x01d3, uuid_e); - smb_message_put16(req, 3); // Version - smb_message_put16(req, 0); // Minor - // Another UUID - const uint8_t uuid_e2[8] = {0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60}; - smb_message_put_uuid(req, 0x8a885d04, 0x1ceb, 0x11c9, uuid_e2); - smb_message_put32(req, 2); // Another version - - // Let's send this ugly pile of shit over the network ! - res = smb_session_send_msg(s, req); - smb_message_destroy(req); - if (!res) - { - ret = DSM_ERROR_NETWORK; - goto error; - } - - // Is the server throwing pile of shit back at me ? - res = smb_session_recv_msg(s, &resp); - if (!res || resp.packet->payload[68]) - { - BDSM_dbg("Bind call failed: 0x%hhx (reason = 0x%hhx)\n", - resp.packet->payload[68], resp.packet->payload[70]); - ret = DSM_ERROR_NETWORK; - goto error; } - - - //// Phase 2: - // Now we have the 'bind' done (regarless of what it is), we'll call - // NetShareEnumAll - - req = smb_message_new(SMD_CMD_TRANS); - if (!req) - { - ret = DSM_ERROR_GENERIC; - goto error; - } - req->packet->header.tid = ipc_tid; - - // this struct will be set at the end when we know the data size - SMB_MSG_ADVANCE_PKT(req, smb_trans_req); - - smb_message_put8(req, 0); // Padding - smb_message_put_utf16(req, "\\PIPE\\", strlen("\\PIPE\\") + 1); - smb_message_put16(req, 0); // Padding - - // Now we'll 'build' the DCE/RPC Packet. This basically a copycat - // from wireshark values. - smb_message_put8(req, 5); // version major - smb_message_put8(req, 0); // minor - smb_message_put8(req, 0); // Packet type = 'request' - smb_message_put8(req, 0x03); // Packet flags = ?? - smb_message_put32(req, 0x10); // Representation = little endian/ASCII. Damn - // Let's save the cursor here to update that later - frag_len_cursor = req->cursor; - smb_message_put16(req, 0); // Data len again (frag length) - smb_message_put16(req, 0); // Auth len ? - smb_message_put32(req, 12); // Call ID ? - smb_message_put32(req, 64); // Alloc hint ? - smb_message_put16(req, 0); // Context ID ? - smb_message_put16(req, 15); // OpNum = NetShareEnumAll - - // Pointer to server UNC - smb_message_put32(req, 0x00020000); // Referent ID ? - smb_message_put32(req, strlen(s->srv.name) + 1); // Max count - smb_message_put32(req, 0); // Offset - smb_message_put32(req, strlen(s->srv.name) + 1); // Actual count - // The server name, supposed to be downcased - smb_message_put_utf16(req, s->srv.name, strlen(s->srv.name) + 1); - if ((strlen(s->srv.name) % 2) == 0) // It won't be aligned with the terminating byte - smb_message_put16(req, 0); - - smb_message_put32(req, 1); // Level 1 ? - smb_message_put32(req, 1); // Ctr ? - smb_message_put32(req, 0x00020004); // Referent ID ? - smb_message_put64(req, 0); // Count/Null Pointer to NetShareInfo1 - smb_message_put32(req, 0xffffffff); // Max Buffer (0xffffffff required by smbX) - - smb_message_put32(req, 0x00020008); // Referent ID ? - smb_message_put32(req, 0); // Resume ? - - // fill trans pkt at the end since we know the size at the end - SMB_MSG_INIT_PKT(trans); - trans.wct = 16; - trans.max_data_count = 4280; - trans.setup_count = 2; - trans.pipe_function = 0x26; // TransactNmPipe; - trans.fid = SMB_FD_FID(srvscv_fd); - trans.bct = req->cursor - sizeof(smb_trans_req); - trans.data_count = trans.bct - 17; // 17 -> padding + \PIPE\ + padding - trans.total_data_count = trans.data_count; - trans.data_offset = 84; - trans.param_offset = 84; - // but insert it at the begining - SMB_MSG_INSERT_PKT(req, 0, trans); - - req->packet->payload[frag_len_cursor] = trans.data_count; // (data_count SHOULD stay < 256) - - // Let's send this ugly pile of shit over the network ! - res = smb_session_send_msg(s, req); - smb_message_destroy(req); - if (!res) - { - ret = DSM_ERROR_NETWORK; - goto error; - } - - // Is the server throwing pile of shit back at me ? - res = smb_session_recv_msg(s, &resp); - if (!res && (uint32_t)resp.packet->payload[resp.payload_size - 4]) - { - BDSM_dbg("NetShareEnumAll call failed.\n"); - ret = DSM_ERROR_NETWORK; - goto error; - } - - - //// Phase 3 - // We parse the list of Share (finally !) and build function response - count = smb_share_parse_enum(&resp, list); - if (count == -1) - { - ret = DSM_ERROR_GENERIC; - goto error; - } - if (pcount != NULL) - *pcount = count; - ret = DSM_SUCCESS; - -error: - // Close the pipe - smb_fclose(s, srvscv_fd); + + ret = DSM_ERROR_GENERIC; return ret; + } diff --git a/src/smb_share.h b/src/smb_share.h index 94f1cac..1381d40 100644 --- a/src/smb_share.h +++ b/src/smb_share.h @@ -31,6 +31,6 @@ #ifndef _SMB_SHARE_H_ #define _SMB_SHARE_H_ -#include "bdsm/smb_share.h" +#include "../include/bdsm/smb_share.h" #endif diff --git a/src/smb_spnego.c b/src/smb_spnego.c index 8a197fc..df381b6 100644 --- a/src/smb_spnego.c +++ b/src/smb_spnego.c @@ -28,7 +28,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" #include #include @@ -41,7 +41,8 @@ #include "smb_session_msg.h" #include "smb_message.h" #include "smb_ntlm.h" -#include "spnego/spnego_asn1.h" +#include "../contrib/spnego/spnego_asn1.h" +#include "../xcode/extra/spnego_asn1_mutex.h" static const char spnego_oid[] = "1.3.6.1.5.5.2"; static const char ntlmssp_oid[] = "1.3.6.1.4.1.311.2.2.10"; @@ -51,38 +52,46 @@ static void asn1_display_error(const char *where, int errcode) // Avoids warning when not in debug mode (void)where; (void)errcode; - - BDSM_dbg("%s error: %s\n", where, asn1_strerror(errcode)); + const char *err = asn1_strerror(errcode); + BDSM_dbg("%s error: %s\n", where, err); } static int init_asn1(smb_session *s) { int res; - - assert(s != NULL); - - if (s->spnego_asn1 != NULL) - return DSM_ERROR_GENERIC; - - res = asn1_array2tree(spnego_asn1_conf, &s->spnego_asn1, NULL); - if (res != ASN1_SUCCESS) - { - asn1_display_error("init_asn1", res); - return DSM_ERROR_GENERIC; - } - else - { - BDSM_dbg("init_asn1: ASN.1 parser initialized\n"); - return DSM_SUCCESS; + + bdsm_assert(s != NULL); + + if(s!=NULL){ + + if (s->spnego_asn1 != NULL) + return DSM_ERROR_GENERIC; + + res = asn1_array2tree(spnego_asn1_conf, &s->spnego_asn1, NULL); + if (res != ASN1_SUCCESS) + { + asn1_display_error("init_asn1", res); + return DSM_ERROR_GENERIC; + } + else + { + BDSM_dbg("init_asn1: ASN.1 parser initialized\n"); + return DSM_SUCCESS; + } } + + return DSM_ERROR_GENERIC; } static void clean_asn1(smb_session *s) { - assert(s != NULL); - - if (s->spnego_asn1 != NULL) - asn1_delete_structure(&s->spnego_asn1); + bdsm_assert(s != NULL); + + if(s!=NULL){ + if (s->spnego_asn1 != NULL){ + asn1_delete_structure(&s->spnego_asn1); + } + } } static int negotiate(smb_session *s, const char *domain) @@ -93,16 +102,15 @@ static int negotiate(smb_session *s, const char *domain) ASN1_TYPE token; int res, der_size = 128; char der[128], err_desc[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; - + msg = smb_message_new(SMB_CMD_SETUP); if (!msg) return DSM_ERROR_GENERIC; - + // this struct will be set at the end when we know the payload size SMB_MSG_ADVANCE_PKT(msg, smb_session_xsec_req); - + asn1_create_element(s->spnego_asn1, "SPNEGO.GSSAPIContextToken", &token); - res = asn1_write_value(token, "thisMech", spnego_oid, 1); if (res != ASN1_SUCCESS) goto error; res = asn1_write_value(token, "spnego", "negTokenInit", 1); @@ -115,13 +123,12 @@ static int negotiate(smb_session *s, const char *domain) if (res != ASN1_SUCCESS) goto error; res = asn1_write_value(token, "spnego.negTokenInit.mechListMIC", NULL, 0); if (res != ASN1_SUCCESS) goto error; - + smb_ntlmssp_negotiate(domain, domain, &ntlm); res = asn1_write_value(token, "spnego.negTokenInit.mechToken", ntlm.data, ntlm.size); smb_buffer_free(&ntlm); if (res != ASN1_SUCCESS) goto error; - res = asn1_der_coding(token, "", der, &der_size, err_desc); if (res != ASN1_SUCCESS) { @@ -129,14 +136,14 @@ static int negotiate(smb_session *s, const char *domain) BDSM_dbg("Encoding error: %s", err_desc); return DSM_ERROR_GENERIC; } - + smb_message_append(msg, der, der_size); smb_message_put_utf16(msg, SMB_OS, strlen(SMB_OS)); smb_message_put16(msg, 0); smb_message_put_utf16(msg, SMB_LANMAN, strlen(SMB_LANMAN)); smb_message_put16(msg, 0); smb_message_put16(msg, 0); - + SMB_MSG_INIT_PKT_ANDX(req); req.wct = 12; req.max_buffer = SMB_SESSION_MAX_BUFFER; @@ -147,19 +154,18 @@ static int negotiate(smb_session *s, const char *domain) req.xsec_blob_size = der_size; req.payload_size = msg->cursor - sizeof(smb_session_xsec_req); SMB_MSG_INSERT_PKT(msg, 0, req); - asn1_delete_structure(&token); - + if (!smb_session_send_msg(s, msg)) { smb_message_destroy(msg); BDSM_dbg("Unable to send Session Setup AndX (NTLMSSP_NEGOTIATE) message\n"); return DSM_ERROR_NETWORK; } - + smb_message_destroy(msg); return DSM_SUCCESS; - + error: asn1_display_error("smb_session_login negotiate()", res); smb_message_destroy(msg); @@ -169,65 +175,76 @@ static int negotiate(smb_session *s, const char *domain) static int challenge(smb_session *s) { char err_desc[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; - char resp_token[256]; + char resp_token[512]; smb_message msg; smb_session_xsec_resp *resp; smb_ntlmssp_challenge *challenge; ASN1_TYPE token; - int res, resp_token_size = 256; - - assert(s != NULL); - - if (smb_session_recv_msg(s, &msg) == 0) - { - BDSM_dbg("spnego challenge(): Unable to receive message\n"); - return DSM_ERROR_NETWORK; - } - - if (msg.packet->header.status != NT_STATUS_MORE_PROCESSING_REQUIRED) - { - BDSM_dbg("spnego challenge(): Bad status (0x%x)\n", - msg.packet->header.status); - return DSM_ERROR_GENERIC; - } - - resp = (smb_session_xsec_resp *)msg.packet->payload; - - asn1_create_element(s->spnego_asn1, "SPNEGO.NegotiationToken", &token); - res = asn1_der_decoding(&token, resp->payload, resp->xsec_blob_size, - err_desc); - if (res != ASN1_SUCCESS) - { + int res, resp_token_size = sizeof(resp_token); + + + bdsm_assert(s != NULL); + + if(s!=NULL){ + + if (smb_session_recv_msg(s, &msg) == 0) + { + BDSM_dbg("spnego challenge(): Unable to receive message\n"); + return DSM_ERROR_NETWORK; + } + + if (msg.packet->header.status != NT_STATUS_MORE_PROCESSING_REQUIRED) + { + BDSM_dbg("spnego challenge(): Bad status (0x%x)\n", + msg.packet->header.status); + return DSM_ERROR_GENERIC; + } + + if (msg.payload_size < sizeof(smb_session_xsec_resp)) + { + BDSM_dbg("[smb_tree_disconnect]Malformed message\n"); + return DSM_ERROR_NETWORK; + } + + resp = (smb_session_xsec_resp *)msg.packet->payload; + asn1_create_element(s->spnego_asn1, "SPNEGO.NegotiationToken", &token); + res = asn1_der_decoding(&token, resp->payload, resp->xsec_blob_size, + err_desc); + + if (res != ASN1_SUCCESS) + { + asn1_delete_structure(&token); + asn1_display_error("NegTokenResp parsing", res); + BDSM_dbg("Parsing error detail: %s\n", err_desc); + return DSM_ERROR_GENERIC; + } + + // XXX Check the value of "negTokenResp.negResult" + res = asn1_read_value(token, "negTokenResp.responseToken", resp_token, + &resp_token_size); asn1_delete_structure(&token); - asn1_display_error("NegTokenResp parsing", res); - BDSM_dbg("Parsing error detail: %s\n", err_desc); - return DSM_ERROR_GENERIC; - } - - // XXX Check the value of "negTokenResp.negResult" - - res = asn1_read_value(token, "negTokenResp.responseToken", resp_token, - &resp_token_size); - asn1_delete_structure(&token); - if (res != ASN1_SUCCESS) - { - asn1_display_error("NegTokenResp read responseToken", res); - return DSM_ERROR_GENERIC; + if (res != ASN1_SUCCESS) + { + asn1_display_error("NegTokenResp read responseToken", res); + return DSM_ERROR_GENERIC; + } + + // We got the server challenge, yeaaah. + challenge = (smb_ntlmssp_challenge *)resp_token; + if (smb_buffer_alloc(&s->xsec_target, challenge->tgt_len) == 0){ + return DSM_ERROR_GENERIC; + } + memcpy(s->xsec_target.data, + challenge->data + challenge->tgt_offset - sizeof(smb_ntlmssp_challenge), + s->xsec_target.size); + s->srv.challenge = challenge->challenge; + s->srv.uid = msg.packet->header.uid; + + BDSM_dbg("Server challenge is 0x%"PRIx64"\n", s->srv.challenge); + + return DSM_SUCCESS; } - - // We got the server challenge, yeaaah. - challenge = (smb_ntlmssp_challenge *)resp_token; - if (smb_buffer_alloc(&s->xsec_target, challenge->tgt_len) == 0) - return DSM_ERROR_GENERIC; - memcpy(s->xsec_target.data, - challenge->data + challenge->tgt_offset - sizeof(smb_ntlmssp_challenge), - s->xsec_target.size); - s->srv.challenge = challenge->challenge; - s->srv.uid = msg.packet->header.uid; - - BDSM_dbg("Server challenge is 0x%"PRIx64"\n", s->srv.challenge); - - return DSM_SUCCESS; + return DSM_ERROR_GENERIC; } static int auth(smb_session *s, const char *domain, const char *user, @@ -239,20 +256,19 @@ static int auth(smb_session *s, const char *domain, const char *user, ASN1_TYPE token; int res, der_size = 512; char der[512], err_desc[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; - + msg = smb_message_new(SMB_CMD_SETUP); if (!msg) return DSM_ERROR_GENERIC; - + // this struct will be set at the end when we know the payload size SMB_MSG_ADVANCE_PKT(msg, smb_session_xsec_req); - asn1_create_element(s->spnego_asn1, "SPNEGO.NegotiationToken", &token); - + // Select a response message type res = asn1_write_value(token, "", "negTokenResp", 1); if (res != ASN1_SUCCESS) goto error; - + // Delete all optionnal field except 'ResponseToken' res = asn1_write_value(token, "negTokenResp.negResult", NULL, 0); if (res != ASN1_SUCCESS) goto error; @@ -260,15 +276,14 @@ static int auth(smb_session *s, const char *domain, const char *user, if (res != ASN1_SUCCESS) goto error; res = asn1_write_value(token, "negTokenResp.mechListMIC", NULL, 0); if (res != ASN1_SUCCESS) goto error; - - + + smb_ntlmssp_response(s->srv.challenge, s->srv.ts - 4200, domain, domain, user, password, &s->xsec_target, &ntlm); res = asn1_write_value(token, "negTokenResp.responseToken", ntlm.data, ntlm.size); smb_buffer_free(&ntlm); if (res != ASN1_SUCCESS) goto error; - res = asn1_der_coding(token, "", der, &der_size, err_desc); if (res != ASN1_SUCCESS) { @@ -276,7 +291,7 @@ static int auth(smb_session *s, const char *domain, const char *user, BDSM_dbg("Encoding error: %s", err_desc); return DSM_ERROR_GENERIC; } - + smb_message_append(msg, der, der_size); if (msg->cursor % 2) smb_message_put8(msg, 0); @@ -285,7 +300,7 @@ static int auth(smb_session *s, const char *domain, const char *user, smb_message_put_utf16(msg, SMB_LANMAN, strlen(SMB_LANMAN)); smb_message_put16(msg, 0); smb_message_put16(msg, 0); // Empty PDC name - + SMB_MSG_INIT_PKT_ANDX(req); req.wct = 12; req.max_buffer = SMB_SESSION_MAX_BUFFER; @@ -296,9 +311,9 @@ static int auth(smb_session *s, const char *domain, const char *user, req.xsec_blob_size = der_size; req.payload_size = msg->cursor - sizeof(smb_session_xsec_req); SMB_MSG_INSERT_PKT(msg, 0, req); - + asn1_delete_structure(&token); - + if (!smb_session_send_msg(s, msg)) { smb_message_destroy(msg); @@ -306,24 +321,34 @@ static int auth(smb_session *s, const char *domain, const char *user, return DSM_ERROR_NETWORK; } smb_message_destroy(msg); - + if (smb_session_recv_msg(s, &resp) == 0) + { return DSM_ERROR_NETWORK; - + } + if (!smb_session_check_nt_status(s, &resp)) + { return DSM_ERROR_NT; - else + } + + if (resp.payload_size < sizeof(smb_session_xsec_resp)) { - smb_session_xsec_resp *r = (smb_session_xsec_resp *)resp.packet->payload; - if (r->action & 0x0001) - s->guest = true; - - s->srv.uid = resp.packet->header.uid; - s->logged = true; - - return DSM_SUCCESS; + BDSM_dbg("[smb_tree_disconnect]Malformed message\n"); + return DSM_ERROR_NETWORK; } - + + smb_session_xsec_resp *r = (smb_session_xsec_resp *)resp.packet->payload; + if (r->action & 0x0001){ + s->guest = true; + } + + s->srv.uid = resp.packet->header.uid; + s->logged = true; + + return DSM_SUCCESS; + + error: asn1_display_error("smb_session_login auth()", res); smb_message_destroy(msg); @@ -331,31 +356,43 @@ static int auth(smb_session *s, const char *domain, const char *user, } int smb_session_login_spnego(smb_session *s, const char *domain, - const char *user, const char *password) + const char *user, const char *password) { int res; - assert(s != NULL && domain != NULL && user != NULL && password != NULL); - - // Clear User ID that might exists from previous authentication attempt - s->srv.uid = 0; - - if (init_asn1(s) != DSM_SUCCESS) - return DSM_ERROR_GENERIC; - - if ((res = negotiate(s, domain)) != DSM_SUCCESS) - goto error; - if ((res = challenge(s)) != DSM_SUCCESS) - goto error; - - res = auth(s, domain, user, password); - - clean_asn1(s); - - return res; - -error: - BDSM_dbg("login_spnego Interrupted\n"); - clean_asn1(s); - return res; + bdsm_assert(s != NULL && domain != NULL && user != NULL && password != NULL); + + if(s != NULL && domain != NULL && user != NULL && password != NULL){ + + // Clear User ID that might exists from previous authentication attempt + s->srv.uid = 0; + + asn1_lock(); + + if (init_asn1(s) != DSM_SUCCESS){ + asn1_unlock(); + return DSM_ERROR_GENERIC; + } + + if ((res = negotiate(s, domain)) != DSM_SUCCESS) + goto error; + + if ((res = challenge(s)) != DSM_SUCCESS) + goto error; + + res = auth(s, domain, user, password); + + clean_asn1(s); + asn1_unlock(); + return res; + + error: + BDSM_dbg("login_spnego Interrupted\n"); + clean_asn1(s); + asn1_unlock(); + return res; + + } + + return DSM_ERROR_GENERIC; } diff --git a/src/smb_stat.c b/src/smb_stat.c index 498dd94..edbb34a 100644 --- a/src/smb_stat.c +++ b/src/smb_stat.c @@ -30,17 +30,23 @@ #include +#include "../xcode/config.h" #include "smb_stat.h" #include "smb_fd.h" + smb_stat smb_stat_fd(smb_session *s, smb_fd fd) { - assert(s != NULL && fd); - - return smb_session_file_get(s, fd); + bdsm_assert(s != NULL && fd); + + if(s != NULL && fd){ + return smb_session_file_get(s, fd); + } + + return NULL; } -void smb_stat_destroy(smb_stat stat) +void smb_stat_destroy(smb_stat stat) { smb_stat_list_destroy((smb_stat_list) stat); } @@ -72,6 +78,11 @@ void smb_stat_list_destroy(smb_stat_list list) } } +smb_stat smb_stat_list_next(smb_stat_list list) +{ + return list->next; +} + smb_stat smb_stat_list_at(smb_stat_list list, size_t index) { size_t pos = 0; @@ -110,6 +121,8 @@ uint64_t smb_stat_get(smb_stat info, int what) return info->accessed; case SMB_STAT_WTIME: return info->written; + case SMB_STAT_WTIME_DEP: + return info->written_dep; case SMB_STAT_MTIME: return info->changed; case SMB_STAT_ISDIR: diff --git a/src/smb_stat.h b/src/smb_stat.h index ea8d18f..3bac335 100644 --- a/src/smb_stat.h +++ b/src/smb_stat.h @@ -36,6 +36,6 @@ #ifndef _SMB_STAT_H_ #define _SMB_STAT_H_ -#include "bdsm/smb_stat.h" +#include "../include/bdsm/smb_stat.h" #endif diff --git a/src/smb_trans2.c b/src/smb_trans2.c index d712167..f0edf51 100644 --- a/src/smb_trans2.c +++ b/src/smb_trans2.c @@ -28,14 +28,13 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include #include #include #include #include +#include "../xcode/config.h" #include "bdsm_debug.h" #include "smb_message.h" #include "smb_session.h" @@ -135,17 +134,22 @@ static void smb_find_first_parse(smb_message *msg, smb_file **files_p) uint8_t *eod; size_t count; - assert(msg != NULL); - - // Let's parse the answer we got from server - tr2 = (smb_trans2_resp *)msg->packet->payload; - params = (smb_tr2_findfirst2_params *)tr2->payload; - iter = (smb_tr2_find2_entry *)(tr2->payload + sizeof(smb_tr2_findfirst2_params)); - eod = msg->packet->payload + msg->payload_size; - count = params->count; - - smb_tr2_find2_parse_entries(files_p, iter, count, eod); - return; + bdsm_assert(msg != NULL); + + if(msg != NULL){ + + // Let's parse the answer we got from server + tr2 = (smb_trans2_resp *)msg->packet->payload; + + if(tr2->wct>0){ + params = (smb_tr2_findfirst2_params *)tr2->payload; + iter = (smb_tr2_find2_entry *)(tr2->payload + sizeof(smb_tr2_findfirst2_params)); + eod = msg->packet->payload + msg->payload_size; + count = params->count; + smb_tr2_find2_parse_entries(files_p, iter, count, eod); + } + + } } static void smb_find_next_parse(smb_message *msg, smb_file **files_p) @@ -156,16 +160,22 @@ static void smb_find_next_parse(smb_message *msg, smb_file **files_p) uint8_t *eod; size_t count; - assert(msg != NULL); + bdsm_assert(msg != NULL); + + if(msg != NULL){ - // Let's parse the answer we got from server - tr2 = (smb_trans2_resp *)msg->packet->payload; - params = (smb_tr2_findnext2_params *)tr2->payload; - iter = (smb_tr2_find2_entry *)(tr2->payload + sizeof(smb_tr2_findnext2_params)); - eod = msg->packet->payload + msg->payload_size; - count = params->count; - smb_tr2_find2_parse_entries(files_p, iter, count, eod); - return; + // Let's parse the answer we got from server + tr2 = (smb_trans2_resp *)msg->packet->payload; + + if(tr2->wct>0){ + params = (smb_tr2_findnext2_params *)tr2->payload; + iter = (smb_tr2_find2_entry *)(tr2->payload + sizeof(smb_tr2_findnext2_params)); + eod = msg->packet->payload + msg->payload_size; + count = params->count; + smb_tr2_find2_parse_entries(files_p, iter, count, eod); + } + + } } static smb_message *smb_trans2_find_first (smb_session *s, smb_tid tid, const char *pattern) @@ -178,65 +188,70 @@ static smb_message *smb_trans2_find_first (smb_session *s, smb_tid tid, const c int res; unsigned int padding = 0; - assert(s != NULL && pattern != NULL); + bdsm_assert(s != NULL && pattern != NULL); + + if(s != NULL && pattern != NULL){ - utf_pattern_len = smb_to_utf16(pattern, strlen(pattern) + 1, &utf_pattern); - if (utf_pattern_len == 0) - return NULL; + utf_pattern_len = smb_to_utf16(pattern, strlen(pattern) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return NULL; - tr2_bct = sizeof(smb_tr2_findfirst2) + utf_pattern_len; - tr2_param_count = tr2_bct; - tr2_bct += 3; - // Adds padding at the end if necessary. - while ((tr2_bct % 4) != 3) - { - padding++; - tr2_bct++; - } + tr2_bct = sizeof(smb_tr2_findfirst2) + utf_pattern_len; + tr2_param_count = tr2_bct; + tr2_bct += 3; + // Adds padding at the end if necessary. + while ((tr2_bct % 4) != 3) + { + padding++; + tr2_bct++; + } - msg = smb_message_new(SMB_CMD_TRANS2); - if (!msg) { + msg = smb_message_new(SMB_CMD_TRANS2); + if (!msg) { + free(utf_pattern); + return NULL; + } + msg->packet->header.tid = tid; + + SMB_MSG_INIT_PKT(tr2); + tr2.wct = 15; + tr2.max_param_count = 10; // ?? Why not the same or 12 ? + tr2.max_data_count = 0xffff;; + tr2.param_offset = 68; // Offset of find_first_params in packet; + tr2.data_count = 0; + tr2.data_offset = 88; // Offset of pattern in packet + tr2.setup_count = 1; + tr2.cmd = SMB_TR2_FIND_FIRST; + tr2.total_param_count = tr2_param_count; + tr2.param_count = tr2_param_count; + tr2.bct = tr2_bct; //3 == padding + SMB_MSG_PUT_PKT(msg, tr2); + + SMB_MSG_INIT_PKT(find); + find.attrs = SMB_FIND2_ATTR_DEFAULT; + find.count = 1366; // ?? + find.flags = SMB_FIND2_FLAG_CLOSE_EOS | SMB_FIND2_FLAG_RESUME; + find.interest = SMB_FIND2_INTEREST_BOTH_DIRECTORY_INFO; + SMB_MSG_PUT_PKT(msg, find); + smb_message_append(msg, utf_pattern, utf_pattern_len); + while (padding--) + smb_message_put8(msg, 0); + + res = smb_session_send_msg(s, msg); + smb_message_destroy(msg); free(utf_pattern); - return NULL; - } - msg->packet->header.tid = tid; - - SMB_MSG_INIT_PKT(tr2); - tr2.wct = 15; - tr2.max_param_count = 10; // ?? Why not the same or 12 ? - tr2.max_data_count = 0xffff;; - tr2.param_offset = 68; // Offset of find_first_params in packet; - tr2.data_count = 0; - tr2.data_offset = 88; // Offset of pattern in packet - tr2.setup_count = 1; - tr2.cmd = SMB_TR2_FIND_FIRST; - tr2.total_param_count = tr2_param_count; - tr2.param_count = tr2_param_count; - tr2.bct = tr2_bct; //3 == padding - SMB_MSG_PUT_PKT(msg, tr2); - - SMB_MSG_INIT_PKT(find); - find.attrs = SMB_FIND2_ATTR_DEFAULT; - find.count = 1366; // ?? - find.flags = SMB_FIND2_FLAG_CLOSE_EOS | SMB_FIND2_FLAG_RESUME; - find.interest = SMB_FIND2_INTEREST_BOTH_DIRECTORY_INFO; - SMB_MSG_PUT_PKT(msg, find); - smb_message_append(msg, utf_pattern, utf_pattern_len); - while (padding--) - smb_message_put8(msg, 0); - - res = smb_session_send_msg(s, msg); - smb_message_destroy(msg); - free(utf_pattern); - if (!res) - { - BDSM_dbg("Unable to query pattern: %s\n", pattern); - return NULL; - } + if (!res) + { + BDSM_dbg("Unable to query pattern: %s\n", pattern); + return NULL; + } - msg = smb_tr2_recv(s); - return msg; + msg = smb_tr2_recv(s); + return msg; + } + + return NULL; } static smb_message *smb_trans2_find_next (smb_session *s, smb_tid tid, uint16_t resume_key, uint16_t sid, const char *pattern) @@ -249,74 +264,78 @@ static smb_message *smb_trans2_find_next (smb_session *s, smb_tid tid, uint16_t int res; unsigned int padding = 0; - assert(s != NULL && pattern != NULL); + bdsm_assert(s != NULL && pattern != NULL); + + if(s != NULL && pattern != NULL){ - utf_pattern_len = smb_to_utf16(pattern, strlen(pattern) + 1, &utf_pattern); - if (utf_pattern_len == 0) - return NULL; + utf_pattern_len = smb_to_utf16(pattern, strlen(pattern) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return NULL; - tr2_bct = sizeof(smb_tr2_findnext2) + utf_pattern_len; - tr2_param_count = tr2_bct; - tr2_bct += 3; - // Adds padding at the end if necessary. - while ((tr2_bct % 4) != 3) - { - padding++; - tr2_bct++; - } + tr2_bct = sizeof(smb_tr2_findnext2) + utf_pattern_len; + tr2_param_count = tr2_bct; + tr2_bct += 3; + // Adds padding at the end if necessary. + while ((tr2_bct % 4) != 3) + { + padding++; + tr2_bct++; + } - msg_find_next2 = smb_message_new(SMB_CMD_TRANS2); - if (!msg_find_next2) - { + msg_find_next2 = smb_message_new(SMB_CMD_TRANS2); + if (!msg_find_next2) + { + free(utf_pattern); + return NULL; + } + msg_find_next2->packet->header.tid = tid; + + SMB_MSG_INIT_PKT(tr2_find_next2); + tr2_find_next2.wct = 0x0f; + tr2_find_next2.total_param_count = tr2_param_count; + tr2_find_next2.total_data_count = 0x0000; + tr2_find_next2.max_param_count = 10; // ?? Why not the same or 12 ? + tr2_find_next2.max_data_count = 0xffff; + //max_setup_count + //reserved + //flags + //timeout + //reserve2 + tr2_find_next2.param_count = tr2_param_count; + tr2_find_next2.param_offset = 68; // Offset of find_next_params in packet; + tr2_find_next2.data_count = 0; + tr2_find_next2.data_offset = 88; // Offset of pattern in packet + tr2_find_next2.setup_count = 1; + //reserve3 + tr2_find_next2.cmd = SMB_TR2_FIND_NEXT; + tr2_find_next2.bct = tr2_bct; //3 == padding + SMB_MSG_PUT_PKT(msg_find_next2, tr2_find_next2); + + SMB_MSG_INIT_PKT(find_next2); + find_next2.sid = sid; + find_next2.count = 255; + find_next2.interest = SMB_FIND2_INTEREST_BOTH_DIRECTORY_INFO; + find_next2.flags = SMB_FIND2_FLAG_CLOSE_EOS|SMB_FIND2_FLAG_CONTINUE; + find_next2.resume_key = resume_key; + SMB_MSG_PUT_PKT(msg_find_next2, find_next2); + smb_message_append(msg_find_next2, utf_pattern, utf_pattern_len); + while (padding--) + smb_message_put8(msg_find_next2, 0); + + res = smb_session_send_msg(s, msg_find_next2); + smb_message_destroy(msg_find_next2); free(utf_pattern); - return NULL; - } - msg_find_next2->packet->header.tid = tid; - - SMB_MSG_INIT_PKT(tr2_find_next2); - tr2_find_next2.wct = 0x0f; - tr2_find_next2.total_param_count = tr2_param_count; - tr2_find_next2.total_data_count = 0x0000; - tr2_find_next2.max_param_count = 10; // ?? Why not the same or 12 ? - tr2_find_next2.max_data_count = 0xffff; - //max_setup_count - //reserved - //flags - //timeout - //reserve2 - tr2_find_next2.param_count = tr2_param_count; - tr2_find_next2.param_offset = 68; // Offset of find_next_params in packet; - tr2_find_next2.data_count = 0; - tr2_find_next2.data_offset = 88; // Offset of pattern in packet - tr2_find_next2.setup_count = 1; - //reserve3 - tr2_find_next2.cmd = SMB_TR2_FIND_NEXT; - tr2_find_next2.bct = tr2_bct; //3 == padding - SMB_MSG_PUT_PKT(msg_find_next2, tr2_find_next2); - - SMB_MSG_INIT_PKT(find_next2); - find_next2.sid = sid; - find_next2.count = 255; - find_next2.interest = SMB_FIND2_INTEREST_BOTH_DIRECTORY_INFO; - find_next2.flags = SMB_FIND2_FLAG_CLOSE_EOS|SMB_FIND2_FLAG_CONTINUE; - find_next2.resume_key = resume_key; - SMB_MSG_PUT_PKT(msg_find_next2, find_next2); - smb_message_append(msg_find_next2, utf_pattern, utf_pattern_len); - while (padding--) - smb_message_put8(msg_find_next2, 0); - - res = smb_session_send_msg(s, msg_find_next2); - smb_message_destroy(msg_find_next2); - free(utf_pattern); - if (!res) - { - BDSM_dbg("Unable to query pattern: %s\n", pattern); - return NULL; - } + if (!res) + { + BDSM_dbg("Unable to query pattern: %s\n", pattern); + return NULL; + } - msg_find_next2 = smb_tr2_recv(s); - return msg_find_next2; + msg_find_next2 = smb_tr2_recv(s); + return msg_find_next2; + } + return NULL; } smb_file *smb_find(smb_session *s, smb_tid tid, const char *pattern) @@ -331,168 +350,362 @@ smb_file *smb_find(smb_session *s, smb_tid tid, const char *pattern) uint16_t resume_key; uint16_t error_offset; - assert(s != NULL && pattern != NULL); + bdsm_assert(s != NULL && pattern != NULL); + + if(s != NULL && pattern != NULL){ - // Send FIND_FIRST request - msg = smb_trans2_find_first(s,tid,pattern); - if (msg) - { - smb_find_first_parse(msg,&files); - if (files) + // Send FIND_FIRST request + msg = smb_trans2_find_first(s,tid,pattern); + + if (msg) { - // Check if we shall send a FIND_NEXT request - tr2_resp = (smb_trans2_resp *)msg->packet->payload; - findfirst2_params = (smb_tr2_findfirst2_params *)tr2_resp->payload; - - sid = findfirst2_params->id; - end_of_search = findfirst2_params->eos; - resume_key = findfirst2_params->last_name_offset; - error_offset = findfirst2_params->ea_error_offset; + smb_find_first_parse(msg,&files); + if (files) + { + // Check if we shall send a FIND_NEXT request + tr2_resp = (smb_trans2_resp *)msg->packet->payload; + findfirst2_params = (smb_tr2_findfirst2_params *)tr2_resp->payload; - smb_message_destroy(msg); + sid = findfirst2_params->id; + end_of_search = findfirst2_params->eos; + resume_key = findfirst2_params->last_name_offset; + error_offset = findfirst2_params->ea_error_offset; - // Send FIND_NEXT queries until the find is finished - // or until an error occurs - while ((!end_of_search) && (error_offset == 0)) - { - msg = smb_trans2_find_next(s, tid, resume_key, sid, pattern); + smb_message_destroy(msg); - if (msg) + // Send FIND_NEXT queries until the find is finished + // or until an error occurs + while ((!end_of_search) && (error_offset == 0)) { - // Update info for next FIND_NEXT query - tr2_resp = (smb_trans2_resp *)msg->packet->payload; - findnext2_params = (smb_tr2_findnext2_params *)tr2_resp->payload; - end_of_search = findnext2_params->eos; - resume_key = findnext2_params->last_name_offset; - error_offset = findnext2_params->ea_error_offset; - - // parse the result for files - smb_find_next_parse(msg, &files); - smb_message_destroy(msg); - - if (!files) + msg = smb_trans2_find_next(s, tid, resume_key, sid, pattern); + + if (msg) { - BDSM_dbg("Error during FIND_NEXT answer parsing\n"); - end_of_search = true; + // Update info for next FIND_NEXT query + tr2_resp = (smb_trans2_resp *)msg->packet->payload; + findnext2_params = (smb_tr2_findnext2_params *)tr2_resp->payload; + end_of_search = findnext2_params->eos; + resume_key = findnext2_params->last_name_offset; + error_offset = findnext2_params->ea_error_offset; + + // parse the result for files + smb_find_next_parse(msg, &files); + smb_message_destroy(msg); + + if (!files) + { + BDSM_dbg("Error during FIND_NEXT answer parsing\n"); + end_of_search = true; + } + } + else + { + BDSM_dbg("Error during FIND_NEXT request\n"); + smb_stat_list_destroy(files); + return NULL; } } - else - { - BDSM_dbg("Error during FIND_NEXT request\n"); - smb_stat_list_destroy(files); - return NULL; - } + } + else + { + BDSM_dbg("Error during FIND_FIRST answer parsing\n"); + smb_message_destroy(msg); } } else { - BDSM_dbg("Error during FIND_FIRST answer parsing\n"); + BDSM_dbg("Error during FIND_FIRST request\n"); + smb_stat_list_destroy(files); smb_message_destroy(msg); + return NULL; } - } - else - { - BDSM_dbg("Error during FIND_FIRST request\n"); - smb_stat_list_destroy(files); - smb_message_destroy(msg); - return NULL; - } - return files; + return files; + } + return NULL; } /* * Query management */ - -smb_file *smb_fstat(smb_session *s, smb_tid tid, const char *path) + +smb_file *smb_fstat_interest(smb_session *s, smb_tid tid, uint16_t interest, const char *path) { smb_message *msg, reply; - smb_trans2_req tr2; + smb_trans2_query_path_info_req tr2; smb_trans2_resp *tr2_resp; smb_tr2_query query; - smb_tr2_path_info *info; + smb_tr2_basic_path_info *info_basic; + smb_tr2_standard_path_info *info_standard; smb_file *file; size_t utf_path_len, msg_len; char *utf_path; int res, padding = 0; - assert(s != NULL && path != NULL); + bdsm_assert(s != NULL && path != NULL); + + bdsm_assert(interest == SMB_FIND2_QUERY_FILE_BASIC_INFO || interest == SMB_FIND2_QUERY_FILE_STANDARD_INFO); + + bdsm_assert(smb_session_supports(s, SMB_SESSION_NTSMB)); + if (smb_session_supports(s, SMB_SESSION_NTSMB) == false) + { + return NULL; + } + + if(s != NULL && path != NULL){ - utf_path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); - if (utf_path_len == 0) - return 0; + utf_path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path); + if (utf_path_len == 0) + return 0; - msg_len = sizeof(smb_trans2_req) + sizeof(smb_tr2_query); - msg_len += utf_path_len; - if (msg_len %4) - padding = 4 - msg_len % 4; + msg_len = sizeof(smb_trans2_req) + sizeof(smb_tr2_query); + msg_len += utf_path_len; + if (msg_len %4) + padding = 4 - msg_len % 4; - msg = smb_message_new(SMB_CMD_TRANS2); - if (!msg) { + msg = smb_message_new(SMB_CMD_TRANS2); + if (!msg) { + free(utf_path); + return 0; + } + msg->packet->header.tid = tid; + + SMB_MSG_INIT_PKT(tr2); + tr2.wct = 15; + tr2.total_param_count = utf_path_len + sizeof(smb_tr2_query); + tr2.param_count = tr2.total_param_count; + tr2.max_param_count = 2; // ?? Why not the same or 12 ? + tr2.max_data_count = 40; + tr2.param_offset = 66; // Offset of find_first_params in packet; + tr2.data_count = 0; + tr2.data_offset = 0; // Offset of pattern in packet + tr2.setup_count = 1; + tr2.cmd = SMB_TR2_QUERY_PATH; + tr2.bct = sizeof(smb_tr2_query) + utf_path_len + padding + 1; // 1 - reserved + SMB_MSG_PUT_PKT(msg, tr2); + + SMB_MSG_INIT_PKT(query); + query.interest = interest; + SMB_MSG_PUT_PKT(msg, query); + + smb_message_append(msg, utf_path, utf_path_len); free(utf_path); - return 0; + + // Adds padding at the end if necessary. + while (padding--) + smb_message_put8(msg, 0); + + res = smb_session_send_msg(s, msg); + smb_message_destroy(msg); + if (!res) + { + BDSM_dbg("Unable to query pattern: %s\n", path); + return NULL; + } + + if (!smb_session_recv_msg(s, &reply) || + !smb_session_check_nt_status(s, &reply)) + { + BDSM_dbg("Unable to recv msg or failure for %s\n", path); + return NULL; + } + + file = calloc(1, sizeof(smb_file)); + if (!file) { + BDSM_dbg("Unable to create file for %s\n", path); + return NULL; + } + + bool isBasicFileInfo = (query.interest == SMB_FIND2_QUERY_FILE_BASIC_INFO); + bool isStandardFileInfo = (query.interest == SMB_FIND2_QUERY_FILE_STANDARD_INFO); + + if (isBasicFileInfo && reply.payload_size < sizeof(smb_tr2_basic_path_info)) + { + BDSM_dbg("[smb_fstat]Malformed message %s\n", path); + return NULL; + } + + if (isStandardFileInfo && reply.payload_size < sizeof(smb_tr2_standard_path_info)) + { + BDSM_dbg("[smb_fstat]Malformed message %s\n", path); + return NULL; + } + + tr2_resp = (smb_trans2_resp *)reply.packet->payload; + + if (isBasicFileInfo) { + info_basic = (smb_tr2_basic_path_info *)(tr2_resp->payload + 4); //+4 is padding + + file->created = info_basic->created; + file->accessed = info_basic->accessed; + file->written = info_basic->written; + file->changed = info_basic->changed; + file->attr = info_basic->attr; + file->is_dir = info_basic->attr & SMB_ATTR_DIR; + } + else if (isStandardFileInfo) { + info_standard = (smb_tr2_standard_path_info *)(tr2_resp->payload + 4); //+4 is padding + + file->alloc_size = info_standard->alloc_size; + file->size = info_standard->size; + //file->link_count = info_standard->link_count; + //file->rm_pending = info_standard->rm_pending; + file->is_dir = info_standard->is_dir; + } + else{ + BDSM_dbg("[smb_fstat]Unknown file info %s\n", path); + } + + return file; } - msg->packet->header.tid = tid; - - SMB_MSG_INIT_PKT(tr2); - tr2.wct = 15; - tr2.total_param_count = utf_path_len + sizeof(smb_tr2_query); - tr2.param_count = tr2.total_param_count; - tr2.max_param_count = 2; // ?? Why not the same or 12 ? - tr2.max_data_count = 0xffff; - tr2.param_offset = 68; // Offset of find_first_params in packet; - tr2.data_count = 0; - tr2.data_offset = 96; // Offset of pattern in packet - tr2.setup_count = 1; - tr2.cmd = SMB_TR2_QUERY_PATH; - tr2.bct = sizeof(smb_tr2_query) + utf_path_len + padding; - SMB_MSG_PUT_PKT(msg, tr2); - - SMB_MSG_INIT_PKT(query); - query.interest = SMB_FIND2_QUERY_FILE_ALL_INFO; - SMB_MSG_PUT_PKT(msg, query); - - smb_message_append(msg, utf_path, utf_path_len); - free(utf_path); - - // Adds padding at the end if necessary. - while (padding--) - smb_message_put8(msg, 0); - - res = smb_session_send_msg(s, msg); - smb_message_destroy(msg); - if (!res) - { - BDSM_dbg("Unable to query pattern: %s\n", path); - return NULL; + return NULL; +} + +smb_file *smb_fstat_basic(smb_session *s, smb_tid tid, const char *path) +{ + return smb_fstat_interest(s, tid, SMB_FIND2_QUERY_FILE_BASIC_INFO, path); +} + +smb_file *smb_fstat_standard(smb_session *s, smb_tid tid, const char *path) +{ + return smb_fstat_interest(s, tid, SMB_FIND2_QUERY_FILE_STANDARD_INFO, path); +} + +//https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/847573c9-cbe6-4dcb-a0db-9b5af815759b +smb_file *smb_fstat_query_info(smb_session *s, smb_tid tid, const char *path) +{ + smb_message *req_msg, resp_msg; + smb_query_path_info_req req; + smb_query_path_info_resp *resp; + size_t utf_pattern_len; + char *utf_pattern; + smb_file *file; + + bdsm_assert(s != NULL && path != NULL); + + if(s != NULL && path != NULL){ + + utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern); + if (utf_pattern_len == 0) + return NULL; + + req_msg = smb_message_new(SMB_CMD_QUERY_INFO); + if (!req_msg) + { + free(utf_pattern); + return NULL; + } + + req_msg->packet->header.tid = (uint16_t)tid; + + SMB_MSG_INIT_PKT(req); + req.wct = 0x00; // Must be 0 + req.bct = (uint16_t)(utf_pattern_len + 1); + req.buffer_format = 0x04; // Must be 4 + SMB_MSG_PUT_PKT(req_msg, req); + smb_message_append(req_msg, utf_pattern, utf_pattern_len); + + smb_session_send_msg(s, req_msg); + smb_message_destroy(req_msg); + + free(utf_pattern); + + if (!smb_session_recv_msg(s, &resp_msg)){ + BDSM_dbg("Unable to recv msg or failure for %s\n", path); + return NULL; + } + + if (!smb_session_check_nt_status(s, &resp_msg)){ + BDSM_dbg("Unable to recv msg or failure for %s\n", path); + return NULL; + } + + if (resp_msg.payload_size < sizeof(smb_query_path_info_resp)) + { + BDSM_dbg("[smb_query_path_info]Malformed message %s\n", path); + return NULL; + } + + resp = (smb_query_path_info_resp *)resp_msg.packet->payload; + if ((resp->wct) == 0) { + BDSM_dbg("[smb_query_path_info]Malformed message wct == 0 %s\n", path); + return NULL; + } + + file = calloc(1, sizeof(smb_file)); + if (!file) { + BDSM_dbg("Unable to create file for %s\n", path); + return NULL; + } + + uint64_t time_zone = smb_session_server_time_zone(s); + + file->written_dep = resp->written + time_zone; + file->attr = resp->attr; + file->is_dir = resp->attr & SMB_ATTR_DIR; + file->size = resp->size; + file->alloc_size = resp->size; + + return file; } + return NULL; +} - if (!smb_session_recv_msg(s, &reply) - || !smb_session_check_nt_status(s, &reply)) + +smb_file *smb_fstat(smb_session *s, smb_tid tid, const char *path) +{ + + if (smb_session_supports(s, SMB_SESSION_NTSMB) == false) { - BDSM_dbg("Unable to recv msg or failure for %s\n", path); - return NULL; + //return deprecated query_info (needed for old NAS) + return smb_fstat_query_info(s,tid,path); } - tr2_resp = (smb_trans2_resp *)reply.packet->payload; - info = (smb_tr2_path_info *)(tr2_resp->payload + 4); //+4 is padding - file = calloc(1, sizeof(smb_file)); - if (!file) + smb_file *file = calloc(1, sizeof(smb_file)); + if (!file) { + BDSM_dbg("Unable to create file for %s\n", path); return NULL; - - file->name_len = smb_from_utf16((const char *)info->name, info->name_len, - &file->name); - file->name[info->name_len / 2] = 0; - - file->created = info->created; - file->accessed = info->accessed; - file->written = info->written; - file->changed = info->changed; - file->alloc_size = info->alloc_size; - file->size = info->size; - file->attr = info->attr; - file->is_dir = info->is_dir; - + } + + smb_stat statBasic = smb_fstat_basic(s, tid, path); + + if (statBasic != NULL) { + file->created = statBasic->created; + file->accessed = statBasic->accessed; + file->written = statBasic->written; + file->changed = statBasic->changed; + file->attr = statBasic->attr; + file->is_dir = statBasic->is_dir; + + smb_stat_destroy(statBasic); + } + else { + BDSM_dbg("Unable to recv basic info for file %s\n", path); + smb_stat_destroy(file); + + return NULL; + } + + smb_stat statStandard = smb_fstat_standard(s, tid, path); + + if (statStandard != NULL) { + file->alloc_size = statStandard->alloc_size; + file->size = statStandard->size; + + smb_stat_destroy(statStandard); + } + +//#ifdef DEBUG +// smb_stat statDeprecated = smb_fstat_query_info(s,tid,path); +// if (statDeprecated != NULL) { +// bdsm_assert(statDeprecated->attr == file->attr); +// bdsm_assert(statDeprecated->is_dir == file->is_dir); +// bdsm_assert(statDeprecated->alloc_size == file->alloc_size); +// smb_stat_destroy(statDeprecated); +// } +//#endif + return file; } + + diff --git a/src/smb_transport.c b/src/smb_transport.c index 6747fdf..87fec31 100644 --- a/src/smb_transport.c +++ b/src/smb_transport.c @@ -28,52 +28,58 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" - #include +#include "../xcode/config.h" #include "smb_transport.h" #include "netbios_session.h" // XXX: This can be simplified, since we have only one function that differs -int transport_connect_nbt(uint32_t ip, +int transport_connect_nbt(const char *ip, + const char *user_port, netbios_session *s, const char *name) { - return netbios_session_connect(ip, s, name, 0); + return netbios_session_connect(ip,user_port, s, name, 0); } -int transport_connect_tcp(uint32_t ip, +int transport_connect_tcp(const char *ip, + const char *user_port, netbios_session *s, const char *name) { - return netbios_session_connect(ip, s, name, 1); + return netbios_session_connect(ip,user_port, s, name, 1); } void smb_transport_nbt(smb_transport *tr) { - assert(tr != NULL); + bdsm_assert(tr != NULL); + + if(tr != NULL){ - // Sorry for the dirty cast. - tr->new = (void *)netbios_session_new; - tr->connect = (void *)transport_connect_nbt; - tr->destroy = (void *)netbios_session_destroy; - tr->pkt_init = (void *)netbios_session_packet_init; - tr->pkt_append = (void *)netbios_session_packet_append; - tr->send = (void *)netbios_session_packet_send; - tr->recv = (void *)netbios_session_packet_recv; + // Sorry for the dirty cast. + tr->new = (void *)netbios_session_new; + tr->connect = (void *)transport_connect_nbt; + tr->destroy = (void *)netbios_session_destroy; + tr->pkt_init = (void *)netbios_session_packet_init; + tr->pkt_append = (void *)netbios_session_packet_append; + tr->send = (void *)netbios_session_packet_send; + tr->recv = (void *)netbios_session_packet_recv; + } } void smb_transport_tcp(smb_transport *tr) { - assert(tr != NULL); + bdsm_assert(tr != NULL); - tr->new = (void *)netbios_session_new; - tr->connect = (void *)transport_connect_tcp; - tr->destroy = (void *)netbios_session_destroy; - tr->pkt_init = (void *)netbios_session_packet_init; - tr->pkt_append = (void *)netbios_session_packet_append; - tr->send = (void *)netbios_session_packet_send; - tr->recv = (void *)netbios_session_packet_recv; + if(tr != NULL){ + tr->new = (void *)netbios_session_new; + tr->connect = (void *)transport_connect_tcp; + tr->destroy = (void *)netbios_session_destroy; + tr->pkt_init = (void *)netbios_session_packet_init; + tr->pkt_append = (void *)netbios_session_packet_append; + tr->send = (void *)netbios_session_packet_send; + tr->recv = (void *)netbios_session_packet_recv; + } } diff --git a/src/smb_types.h b/src/smb_types.h index dea32aa..90e015b 100644 --- a/src/smb_types.h +++ b/src/smb_types.h @@ -39,7 +39,7 @@ #include #include -#include +#include "libtasn1.h" #if !defined _WIN32 # include @@ -47,7 +47,7 @@ # include #endif -#include "bdsm/smb_types.h" +#include "../include/bdsm/smb_types.h" #include "smb_buffer.h" #include "smb_packets.h" @@ -72,6 +72,7 @@ struct smb_file uint32_t attr; off_t offset; // Current position pointer int is_dir; // 0 -> file, 1 -> directory + uint64_t written_dep; }; typedef struct smb_share smb_share; @@ -90,7 +91,7 @@ struct smb_transport { void *session; void *(*new)(size_t buf_size); - int (*connect)(uint32_t ip, void *s, const char *name); + int (*connect)(const char *ip,const char *user_port, void *s, const char *name); void (*destroy)(void *s); void (*pkt_init)(void *s); int (*pkt_append)(void *s, void *data, size_t size); @@ -108,7 +109,8 @@ struct smb_srv_info uint32_t session_key; // The session key sent by the server on protocol negotiate uint32_t caps; // Server caps replyed during negotiate uint64_t challenge; // For challenge response security - uint64_t ts; // It seems Win7 requires it :-/ + uint64_t ts; // Server time + uint16_t tz; // Server time zone }; /** diff --git a/src/smb_utils.c b/src/smb_utils.c index 31c0403..79c9e00 100644 --- a/src/smb_utils.c +++ b/src/smb_utils.c @@ -28,15 +28,16 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "config.h" +#include "../xcode/config.h" -#include #include #include #include #include #include #include +#import +#import #if HAVE_LANGINFO_H && !defined( __APPLE__ ) # include @@ -45,6 +46,26 @@ #include "bdsm_debug.h" #include "smb_utils.h" +static pthread_mutex_t static_iconv_mutex = PTHREAD_MUTEX_INITIALIZER; +static char iconv_locked = 0; + +#define iconv_lock() {if (pthread_mutex_lock(&static_iconv_mutex)!=0){\ +bdsm_assert(0);\ +}\ +set_iconv_locked(1);\ +}\ + +#define iconv_unlock() {if (pthread_mutex_unlock(&static_iconv_mutex)!=0){\ +bdsm_assert(0);\ +}\ +set_iconv_locked(0);\ +}\ + +static void set_iconv_locked(char locked){ + //bdsm_assert(iconv_locked!=locked); + iconv_locked = locked; +} + static const char *current_encoding() { #if defined( __APPLE__ ) @@ -70,47 +91,68 @@ static size_t smb_iconv(const char *src, size_t src_len, char **dst, iconv_t ic; size_t ret = 0; - assert(src != NULL && dst != NULL && src_enc != NULL && dst_enc != NULL); + bdsm_assert(src != NULL && dst != NULL && src_enc != NULL && dst_enc != NULL); - if (!src_len) - { - *dst = NULL; - return 0; - } + if(src != NULL && dst != NULL && src_enc != NULL && dst_enc != NULL){ - if ((ic = iconv_open(dst_enc, src_enc)) == (iconv_t)-1) - { - BDSM_dbg("Unable to open iconv to convert from %s to %s\n", - src_enc, dst_enc); - *dst = NULL; - return 0; - } - for (unsigned mul = 4; mul < 16; mul++) - { - size_t outlen = mul * src_len; - char *out = malloc(outlen); - - const char *inp = src; - size_t inb = src_len; - char *outp = out; - size_t outb = outlen; - - if (!out) - break; - if (iconv(ic, (char **)&inp, &inb, &outp, &outb) != (size_t)(-1)) { - ret = outlen - outb; - *dst = out; - break; + if (!src_len) + { + *dst = NULL; + return 0; } - free(out); - if (errno != E2BIG) - break; - } - iconv_close(ic); + + iconv_lock(); + + ic = iconv_open(dst_enc, src_enc); + + if (ic == (iconv_t)-1) + { + BDSM_dbg("Unable to open iconv to convert from %s to %s\n", + src_enc, dst_enc); + *dst = NULL; + iconv_unlock(); + return 0; + } + for (unsigned mul = 4; mul < 16; mul++) + { + size_t outlen = mul * src_len; + char *out = malloc(outlen); + + const char *inp = src; + size_t inb = src_len; + char *outp = out; + size_t outb = outlen; - if (ret == 0) - *dst = NULL; - return ret; + if (!out){ + break; + } + + size_t iconvres = iconv(ic, (char **)&inp, &inb, &outp, &outb); + + if (iconvres != (size_t)(-1)) { + ret = outlen - outb; + *dst = out; + break; + } + free(out); + if (errno != E2BIG){ + break; + } + } + + iconv_close(ic); + + if (ret == 0){ + *dst = NULL; + } + + iconv_unlock(); + + return ret; + + } + + return 0; } size_t smb_to_utf16(const char *src, size_t src_len, char **dst) diff --git a/www/.gitignore b/www/.gitignore deleted file mode 100644 index a320f7b..0000000 --- a/www/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -# See http://help.github.com/ignore-files/ for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile ~/.gitignore_global - -# Ignore bundler config -/.bundle - -# Ignore the build directory -/build - -# Ignore cache -/.sass-cache -/.cache - -# Ignore .DS_store file -.DS_Store diff --git a/www/Gemfile b/www/Gemfile deleted file mode 100644 index 3b22928..0000000 --- a/www/Gemfile +++ /dev/null @@ -1,25 +0,0 @@ -# If you have OpenSSL installed, we recommend updating -# the following line to use "https" -source 'http://rubygems.org' - -gem "middleman", "~>3.3.3" - -# Live-reloading plugin -gem "middleman-livereload", "~> 3.1.0" - -# For faster file watcher updates on Windows: -gem "wdm", "~> 0.1.0", :platforms => [:mswin, :mingw] - -# Windows does not come with time zone data -gem "tzinfo-data", platforms: [:mswin, :mingw] - -gem "jquery-middleman" - -gem 'bootstrap-sass' - -gem 'slim' - -gem 'font-awesome-middleman' - -# Handle GitHub pages deployment -gem 'middleman-gh-pages', github: 'elthariel/middleman-gh-pages' diff --git a/www/Gemfile.lock b/www/Gemfile.lock deleted file mode 100644 index adfc457..0000000 --- a/www/Gemfile.lock +++ /dev/null @@ -1,144 +0,0 @@ -GIT - remote: git://github.com/elthariel/middleman-gh-pages.git - revision: 7f70eaa27ff670f668b423620c14d19f059c7768 - specs: - middleman-gh-pages (0.0.3) - rake (> 0.9.3) - -GEM - remote: http://rubygems.org/ - specs: - activesupport (4.1.4) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - bootstrap-sass (3.2.0.0) - sass (~> 3.2) - chunky_png (1.3.1) - coffee-script (2.2.0) - coffee-script-source - execjs - coffee-script-source (1.7.0) - compass (0.12.6) - chunky_png (~> 1.2) - fssm (>= 0.2.7) - sass (~> 3.2.19) - compass-import-once (1.0.4) - sass (>= 3.2, < 3.5) - em-websocket (0.5.1) - eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) - erubis (2.7.0) - eventmachine (1.0.3) - execjs (2.2.1) - ffi (1.9.3) - font-awesome-middleman (4.1.1) - middleman-core (>= 3.0.0) - fssm (0.2.10) - haml (4.0.5) - tilt - hike (1.2.3) - hooks (0.4.0) - uber (~> 0.0.4) - http_parser.rb (0.6.0) - i18n (0.6.9) - jquery-middleman (3.0.4) - thor (>= 0.14, < 2.0) - json (1.8.1) - kramdown (1.4.0) - listen (1.3.1) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - rb-kqueue (>= 0.2) - middleman (3.3.3) - coffee-script (~> 2.2.0) - compass (>= 0.12.4) - compass-import-once (= 1.0.4) - execjs (~> 2.0) - haml (>= 4.0.5) - kramdown (~> 1.2) - middleman-core (= 3.3.3) - middleman-sprockets (>= 3.1.2) - sass (>= 3.2.17, < 4.0) - uglifier (~> 2.5) - middleman-core (3.3.3) - activesupport (~> 4.1.0) - bundler (~> 1.1) - erubis - hooks (~> 0.3) - i18n (~> 0.6.9) - listen (~> 1.1) - padrino-helpers (~> 0.12.1) - rack (>= 1.4.5, < 2.0) - rack-test (~> 0.6.2) - thor (>= 0.15.2, < 2.0) - tilt (~> 1.4.1, < 2.0) - middleman-livereload (3.1.1) - em-websocket (>= 0.2.0) - middleman-core (>= 3.0.2) - multi_json (~> 1.0) - rack-livereload - middleman-sprockets (3.3.3) - middleman-core (>= 3.2) - sprockets (~> 2.2) - sprockets-helpers (~> 1.1.0) - sprockets-sass (~> 1.1.0) - minitest (5.3.5) - multi_json (1.10.1) - padrino-helpers (0.12.2) - i18n (~> 0.6, >= 0.6.7) - padrino-support (= 0.12.2) - tilt (~> 1.4.1) - padrino-support (0.12.2) - activesupport (>= 3.1) - rack (1.5.2) - rack-livereload (0.3.15) - rack - rack-test (0.6.2) - rack (>= 1.0) - rake (10.3.2) - rb-fsevent (0.9.4) - rb-inotify (0.9.5) - ffi (>= 0.5.0) - rb-kqueue (0.2.3) - ffi (>= 0.5.0) - sass (3.2.19) - slim (2.0.3) - temple (~> 0.6.6) - tilt (>= 1.3.3, < 2.1) - sprockets (2.12.1) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-helpers (1.1.0) - sprockets (~> 2.0) - sprockets-sass (1.1.0) - sprockets (~> 2.0) - tilt (~> 1.1) - temple (0.6.8) - thor (0.19.1) - thread_safe (0.3.4) - tilt (1.4.1) - tzinfo (1.2.1) - thread_safe (~> 0.1) - uber (0.0.7) - uglifier (2.5.1) - execjs (>= 0.3.0) - json (>= 1.8.0) - -PLATFORMS - ruby - -DEPENDENCIES - bootstrap-sass - font-awesome-middleman - jquery-middleman - middleman (~> 3.3.3) - middleman-gh-pages! - middleman-livereload (~> 3.1.0) - slim - tzinfo-data - wdm (~> 0.1.0) diff --git a/www/README b/www/README deleted file mode 100644 index b7ef54d..0000000 --- a/www/README +++ /dev/null @@ -1,3 +0,0 @@ -# apt-get install nodejs bundler doxygen ruby gem -$ bundle install -$ bundle exec rake publish diff --git a/www/Rakefile b/www/Rakefile deleted file mode 100644 index 43c191e..0000000 --- a/www/Rakefile +++ /dev/null @@ -1,3 +0,0 @@ -PROJECT_ROOT = `git rev-parse --show-toplevel`.strip + '/www' - -require 'middleman-gh-pages' diff --git a/www/config.rb b/www/config.rb deleted file mode 100644 index d705c9e..0000000 --- a/www/config.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'doxygen' - -activate :doxygen - -activate :relative_assets -set :relative_links, true diff --git a/www/doxygen.rb b/www/doxygen.rb deleted file mode 100644 index 36cc581..0000000 --- a/www/doxygen.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Doxygen < Middleman::Extension - def initialize(app, opts = {}, &block) - super - app.after_build do |builder| - builder.run 'rm -rf build/doc' - builder.run 'cd .. && make doc' - builder.run 'mv ../doc/html build/doc' - end - end -end - -::Middleman::Extensions.register(:doxygen, Doxygen) diff --git a/www/source/c/example1.c b/www/source/c/example1.c deleted file mode 100644 index 81a6e38..0000000 --- a/www/source/c/example1.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include - -int main() -{ - struct in_addr addr; - smb_session *session; - smb_tid tid; - smb_fd fd; - int result; - - session = smb_session_new(); - if (session == NULL) - exit(1); - - inet_aton("127.0.0.1", &addr); - - if (smb_session_connect(session, "EXAMPLE-PC", - addr.s_addr, SMB_TRANSPORT_TCP)) - { - printf("Unable to connect to host\n"); - exit(2); - } - - smb_session_set_creds(session, "EXAMPLE-PC", "EXAMPLE-USER", - "EXAMPLE-PASSWORD"); - - result = smb_session_login(session); - if (result == 0) - { - if (smb_session_is_guest(session)) - printf("Logged in as GUEST \n"); - else - printf("Successfully logged in\n"); - } - else - { - printf("Auth failed\n"); - exit(3); - } - - result = smb_tree_connect(session, "sharedfolder", &tid); - if (!tid || result != 0) - { - printf("Unable to connect to share\n"); - exit(4); - } - - result = smb_fopen(session, tid, "\\helloworld.txt", - SMB_MOD_READ, &fd); - if (!fd || result != 0) - { - printf("Unable to open file\n"); - exit(5); - } - - char buffer[12]; - smb_fread(session, fd, buffer, 12); - printf("%s\n" ,buffer); - - smb_fclose(session, fd); - smb_tree_disconnect(session, tid); - smb_session_destroy(session); - - return(0); -} diff --git a/www/source/c/example2.c b/www/source/c/example2.c deleted file mode 100644 index 9334e72..0000000 --- a/www/source/c/example2.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Netbios Discover */ -#include -#include -#include -#include - -static void print_entry(const char *what, void *p_opaque, - netbios_ns_entry *entry) -{ - struct in_addr addr; - addr.s_addr = netbios_ns_entry_ip(entry); - - printf("%s(%p): Ip: %s, name: %s/%s<%x>\n", - what, - p_opaque, - inet_ntoa(addr), - netbios_ns_entry_group(entry), - netbios_ns_entry_name(entry), - netbios_ns_entry_type(entry)); -} - -static void on_entry_added(void *p_opaque, - netbios_ns_entry *entry) -{ - print_entry("added", p_opaque, entry); -} - -static void on_entry_removed(void *p_opaque, - netbios_ns_entry *entry) -{ - print_entry("removed", p_opaque, entry); -} - -int main() -{ - netbios_ns *ns; - netbios_ns_discover_callbacks callbacks; - - ns = netbios_ns_new(); - - callbacks.p_opaque = (void*)0x42; - callbacks.pf_on_entry_added = on_entry_added; - callbacks.pf_on_entry_removed = on_entry_removed; - - printf("Discovering...\nPress Enter to quit\n"); - if (!netbios_ns_discover_start(ns, - 4, // broadcast every 4 sec - &callbacks)) - { - fprintf(stderr, "Error while discovering local network\n"); - exit(42); - } - - getchar(); - - netbios_ns_discover_stop(ns); - - return (0); -} diff --git a/www/source/images/background.png b/www/source/images/background.png deleted file mode 100644 index 8681d44..0000000 Binary files a/www/source/images/background.png and /dev/null differ diff --git a/www/source/images/escheresque_ste.png b/www/source/images/escheresque_ste.png deleted file mode 100644 index 9238d80..0000000 Binary files a/www/source/images/escheresque_ste.png and /dev/null differ diff --git a/www/source/images/middleman.png b/www/source/images/middleman.png deleted file mode 100644 index c685e56..0000000 Binary files a/www/source/images/middleman.png and /dev/null differ diff --git a/www/source/index.html.slim b/www/source/index.html.slim deleted file mode 100644 index 8b8a464..0000000 --- a/www/source/index.html.slim +++ /dev/null @@ -1,225 +0,0 @@ ---- -title: "libdsm - minimalist smb client" ---- - - -.container - .col-md-6.col-md-offset-6 - a#top - nav.navbar.navbar-inverse.navbar-static-top role="navigation" - .container - .navbar-header - button.navbar-toggle type="button" data-toggle="collapse" data-target=".navbar-collapse" - span.sr-only Toggle navigation - span.icon-bar - span.icon-bar - span.icon-bar - = link_to "libdsm", "#libdsm", class: "navbar-brand" - .collapse.navbar-collapse - ul.nav.navbar-nav - li= link_to "Features", "#features" - li= link_to "Examples", "#examples" - li= link_to "Doc", "#doc" - li= link_to "Download", "#download" - li= link_to "Contact", "#contact" - -.container - .row - .jumbotron - .row - h1 Looking for a tiny smb library ? - h2.pull-right --You're at the right place - - .row - .jumbotron - .row - .col-md-12.text-center - a#libdsm - h1 - | Discover - span.text-muted li - | bdsm - - br - br - .row - .col-md-3.col-xs-6.text-center - i.fa.fa-5x.fa-magic - h3 Simple - p Less than 42 API calls. - p Documented - .col-md-3.col-xs-6.text-center - i.fa.fa-5x.fa-send - h3 Lightweight - p Less than 150KB stripped - p Low memory footprint - .col-md-3.col-xs-6.text-center - i.fa.fa-5x.fa-laptop - h3 Portable - .small.text-muted theorically - p Only 2 dependencies - p Only POSIX calls - .col-md-3.col-xs-6.text-center - i.fa.fa-5x.fa-chain-broken - h3 Open-Source - p Dual LGPL - p and commercial licensing - a.gotop.pull-right href="#top" - i.fa.fa-angle-up - | Top - - - .row - .well - .row - a name="features" - .col-md-12 - h1 Features - .col-md-4 - ul - li Speaking SMB v1 - li Read-only client - li Discover hosts - li List shares - li List folders - li Read files - .col-md-4 - ul - li - | Transport - ul - li Netbios over TCP - li Direct-TCP - li - | Server compatibility - ul - li Samba 3 & 4 - li Apple SMBX - li Windows 7 & 8 - li older Windows untested - .col-md-4 - ul - li - | Netbios - ul - li Name lookup - li Reverse lookup - li - | Supported system - ul - li Linux - li OSX - li pkg-config enabled - li Unicode path support - - a.gotop.pull-right href="#top" - i.fa.fa-angle-up - | Top - - - .row - .well - .row - a#examples - .col-md-12 - h1.pull-right Examples - .row - .col-md-6 - pre.examples - code.hljs.c - = escape_html File.read('source/c/example1.c') - .col-md-6 - pre.examples - code.hljs.c - = escape_html File.read('source/c/example2.c') - .col-md-12 - 'Click - a href="http://github.com/videolabs/libdsm/bin" here - ' for complete code of examples. - a.gotop.pull-right href="#top" - i.fa.fa-angle-up - | Top - - - .row - .well - .row - a#doc - .col-md-12.text-center - h1 Documentation - - .row - .col-md-6 - h2 Building - p - | While the most up-to-date documentation can be found in the README of the project on - a href="https://github.com/videolabs/libdsm/" the github page, - | here's a brief summary - h3 Requirements - ul - li A Unix system with a shell - li A C99 compiler (gcc and clang tested) - li autotools - li libiconv - li - a href="http://www.gnu.org/software/libtasn1/" libtasn1 - li (optionnal) doxygen to generate documentation - li (optionnal) getopt_long for example programs - h3 Building - | Here you just have to roll the traditional - pre - | $> ./bootstrap - $> ./configure --prefix=/usr/local/libdsm - $> make && make install - .col-md-6 - h2 API Documentation - | You can find a few examples in the bin/ folder of the source code but you'll likely enjoy the - extensive API documentation you can fond by clicking the link below: - .text-center - a.btn.btn-lg.btn-primary href="doc/index.html" Doxygen documentation - .row - .well - .row - a#download - .col-md-12.text-center - h1 Download - .row - .col-md-4.col-md-offset-1.text-center - | You can download one of our stable release as a tarbal by clicking on the following link - .text-muted Last stable release : 0.0.4 - br - a.btn.btn-lg.btn-primary href="https://github.com/videolabs/libdsm/releases/" - i.fa.fa-download - | View the releases - - .col-md-2.hidden-xs.hidden-sm.text-center - i.fa.fa-3x.fa-heart - .col-md-4.text-center - | If you're more of a warrior or want to contribute, you can find this project's code on GitHub. - As always Pull Requests are always welcome :) - .div - br - a.btn.btn-lg.btn-info href="https://github.com/videolabs/libdsm/" - i.fa.fa-github - | Fork me on GitHub - a.gotop.pull-right href="#top" - i.fa.fa-angle-up - | Top - - .row - .well - .row - a#contact - .col-md-12.text-center - h1 Contact us - h3 Having some troubles with libdsm ? - | Please browse the existing - a href="https://github.com/videolabs/libdsm/issues" issues on GitHub - | and, if you doesn't find a solution to your problem, you can open a - a href="https://github.com/videolabs/libdsm/issues/new" new one. - - .small.text-muted - | For other concerns, you can mail 'contact' _AT_ lta _DOT_ io - a.gotop.pull-right href="#top" - i.fa.fa-angle-up - | Top diff --git a/www/source/javascripts/all.js b/www/source/javascripts/all.js deleted file mode 100644 index 44bda9e..0000000 --- a/www/source/javascripts/all.js +++ /dev/null @@ -1,7 +0,0 @@ -// -//= require jquery -//= require bootstrap -//= require highlight.pack -//= require_self - -hljs.initHighlightingOnLoad(); diff --git a/www/source/javascripts/highlight.pack.js b/www/source/javascripts/highlight.pack.js deleted file mode 100644 index a8ce09e..0000000 --- a/www/source/javascripts/highlight.pack.js +++ /dev/null @@ -1 +0,0 @@ -var hljs=new function(){function j(v){return v.replace(/&/gm,"&").replace(//gm,">")}function t(v){return v.nodeName.toLowerCase()}function h(w,x){var v=w&&w.exec(x);return v&&v.index==0}function r(w){var v=(w.className+" "+(w.parentNode?w.parentNode.className:"")).split(/\s+/);v=v.map(function(x){return x.replace(/^lang(uage)?-/,"")});return v.filter(function(x){return i(x)||x=="no-highlight"})[0]}function o(x,y){var v={};for(var w in x){v[w]=x[w]}if(y){for(var w in y){v[w]=y[w]}}return v}function u(x){var v=[];(function w(y,z){for(var A=y.firstChild;A;A=A.nextSibling){if(A.nodeType==3){z+=A.nodeValue.length}else{if(t(A)=="br"){z+=1}else{if(A.nodeType==1){v.push({event:"start",offset:z,node:A});z=w(A,z);v.push({event:"stop",offset:z,node:A})}}}}return z})(x,0);return v}function q(w,y,C){var x=0;var F="";var z=[];function B(){if(!w.length||!y.length){return w.length?w:y}if(w[0].offset!=y[0].offset){return(w[0].offset"}function E(G){F+=""}function v(G){(G.event=="start"?A:E)(G.node)}while(w.length||y.length){var D=B();F+=j(C.substr(x,D[0].offset-x));x=D[0].offset;if(D==w){z.reverse().forEach(E);do{v(D.splice(0,1)[0]);D=B()}while(D==w&&D.length&&D[0].offset==x);z.reverse().forEach(A)}else{if(D[0].event=="start"){z.push(D[0].node)}else{z.pop()}v(D.splice(0,1)[0])}}return F+j(C.substr(x))}function m(y){function v(z){return(z&&z.source)||z}function w(A,z){return RegExp(v(A),"m"+(y.cI?"i":"")+(z?"g":""))}function x(D,C){if(D.compiled){return}D.compiled=true;D.k=D.k||D.bK;if(D.k){var z={};var E=function(G,F){if(y.cI){F=F.toLowerCase()}F.split(" ").forEach(function(H){var I=H.split("|");z[I[0]]=[G,I[1]?Number(I[1]):1]})};if(typeof D.k=="string"){E("keyword",D.k)}else{Object.keys(D.k).forEach(function(F){E(F,D.k[F])})}D.k=z}D.lR=w(D.l||/\b[A-Za-z0-9_]+\b/,true);if(C){if(D.bK){D.b="\\b("+D.bK.split(" ").join("|")+")\\b"}if(!D.b){D.b=/\B|\b/}D.bR=w(D.b);if(!D.e&&!D.eW){D.e=/\B|\b/}if(D.e){D.eR=w(D.e)}D.tE=v(D.e)||"";if(D.eW&&C.tE){D.tE+=(D.e?"|":"")+C.tE}}if(D.i){D.iR=w(D.i)}if(D.r===undefined){D.r=1}if(!D.c){D.c=[]}var B=[];D.c.forEach(function(F){if(F.v){F.v.forEach(function(G){B.push(o(F,G))})}else{B.push(F=="self"?D:F)}});D.c=B;D.c.forEach(function(F){x(F,D)});if(D.starts){x(D.starts,C)}var A=D.c.map(function(F){return F.bK?"\\.?("+F.b+")\\.?":F.b}).concat([D.tE,D.i]).map(v).filter(Boolean);D.t=A.length?w(A.join("|"),true):{exec:function(F){return null}};D.continuation={}}x(y)}function c(S,L,J,R){function v(U,V){for(var T=0;T";U+=Z+'">';return U+X+Y}function N(){if(!I.k){return j(C)}var T="";var W=0;I.lR.lastIndex=0;var U=I.lR.exec(C);while(U){T+=j(C.substr(W,U.index-W));var V=E(I,U);if(V){H+=V[1];T+=w(V[0],j(U[0]))}else{T+=j(U[0])}W=I.lR.lastIndex;U=I.lR.exec(C)}return T+j(C.substr(W))}function F(){if(I.sL&&!f[I.sL]){return j(C)}var T=I.sL?c(I.sL,C,true,I.continuation.top):e(C);if(I.r>0){H+=T.r}if(I.subLanguageMode=="continuous"){I.continuation.top=T.top}return w(T.language,T.value,false,true)}function Q(){return I.sL!==undefined?F():N()}function P(V,U){var T=V.cN?w(V.cN,"",true):"";if(V.rB){D+=T;C=""}else{if(V.eB){D+=j(U)+T;C=""}else{D+=T;C=U}}I=Object.create(V,{parent:{value:I}})}function G(T,X){C+=T;if(X===undefined){D+=Q();return 0}var V=v(X,I);if(V){D+=Q();P(V,X);return V.rB?0:X.length}var W=z(I,X);if(W){var U=I;if(!(U.rE||U.eE)){C+=X}D+=Q();do{if(I.cN){D+=""}H+=I.r;I=I.parent}while(I!=W.parent);if(U.eE){D+=j(X)}C="";if(W.starts){P(W.starts,"")}return U.rE?0:X.length}if(A(X,I)){throw new Error('Illegal lexeme "'+X+'" for mode "'+(I.cN||"")+'"')}C+=X;return X.length||1}var M=i(S);if(!M){throw new Error('Unknown language: "'+S+'"')}m(M);var I=R||M;var D="";for(var K=I;K!=M;K=K.parent){if(K.cN){D+=w(K.cN,D,true)}}var C="";var H=0;try{var B,y,x=0;while(true){I.t.lastIndex=x;B=I.t.exec(L);if(!B){break}y=G(L.substr(x,B.index-x),B[0]);x=B.index+y}G(L.substr(x));for(var K=I;K.parent;K=K.parent){if(K.cN){D+=""}}return{r:H,value:D,language:S,top:I}}catch(O){if(O.message.indexOf("Illegal")!=-1){return{r:0,value:j(L)}}else{throw O}}}function e(y,x){x=x||b.languages||Object.keys(f);var v={r:0,value:j(y)};var w=v;x.forEach(function(z){if(!i(z)){return}var A=c(z,y,false);A.language=z;if(A.r>w.r){w=A}if(A.r>v.r){w=v;v=A}});if(w.language){v.second_best=w}return v}function g(v){if(b.tabReplace){v=v.replace(/^((<[^>]+>|\t)+)/gm,function(w,z,y,x){return z.replace(/\t/g,b.tabReplace)})}if(b.useBR){v=v.replace(/\n/g,"
")}return v}function p(z){var y=b.useBR?z.innerHTML.replace(/\n/g,"").replace(/
|
]*>/g,"\n").replace(/<[^>]*>/g,""):z.textContent;var A=r(z);if(A=="no-highlight"){return}var v=A?c(A,y,true):e(y);var w=u(z);if(w.length){var x=document.createElementNS("http://www.w3.org/1999/xhtml","pre");x.innerHTML=v.value;v.value=q(w,u(x),y)}v.value=g(v.value);z.innerHTML=v.value;z.className+=" hljs "+(!A&&v.language||"");z.result={language:v.language,re:v.r};if(v.second_best){z.second_best={language:v.second_best.language,re:v.second_best.r}}}var b={classPrefix:"hljs-",tabReplace:null,useBR:false,languages:undefined};function s(v){b=o(b,v)}function l(){if(l.called){return}l.called=true;var v=document.querySelectorAll("pre code");Array.prototype.forEach.call(v,p)}function a(){addEventListener("DOMContentLoaded",l,false);addEventListener("load",l,false)}var f={};var n={};function d(v,x){var w=f[v]=x(this);if(w.aliases){w.aliases.forEach(function(y){n[y]=v})}}function k(){return Object.keys(f)}function i(v){return f[v]||f[n[v]]}this.highlight=c;this.highlightAuto=e;this.fixMarkup=g;this.highlightBlock=p;this.configure=s;this.initHighlighting=l;this.initHighlightingOnLoad=a;this.registerLanguage=d;this.listLanguages=k;this.getLanguage=i;this.inherit=o;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\[\\s\\S]",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE]};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE]};this.PHRASAL_WORDS_MODE={b:/\b(a|an|the|are|I|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such)\b/};this.CLCM={cN:"comment",b:"//",e:"$",c:[this.PHRASAL_WORDS_MODE]};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/",c:[this.PHRASAL_WORDS_MODE]};this.HCM={cN:"comment",b:"#",e:"$",c:[this.PHRASAL_WORDS_MODE]};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.CSS_NUMBER_MODE={cN:"number",b:this.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0};this.REGEXP_MODE={cN:"regexp",b:/\//,e:/\/[gim]*/,i:/\n/,c:[this.BE,{b:/\[/,e:/\]/,r:0,c:[this.BE]}]};this.TM={cN:"title",b:this.IR,r:0};this.UTM={cN:"title",b:this.UIR,r:0}}();hljs.registerLanguage("cpp",function(a){var b={keyword:"false int float while private char catch export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const struct for static_cast|10 union namespace unsigned long throw volatile static protected bool template mutable if public friend do return goto auto void enum else break new extern using true class asm case typeid short reinterpret_cast|10 default double register explicit signed typename try this switch continue wchar_t inline delete alignof char16_t char32_t constexpr decltype noexcept nullptr static_assert thread_local restrict _Bool complex _Complex _Imaginary",built_in:"std string cin cout cerr clog stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap array shared_ptr abort abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf"};return{aliases:["c","h","c++","h++"],k:b,i:""]',k:"include",i:"\\n"},a.CLCM]},{cN:"stl_container",b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:b,c:["self"]},{b:a.IR+"::"}]}});hljs.registerLanguage("makefile",function(a){var b={cN:"variable",b:/\$\(/,e:/\)/,c:[a.BE]};return{aliases:["mk","mak"],c:[a.HCM,{b:/^\w+\s*\W*=/,rB:true,r:0,starts:{cN:"constant",e:/\s*\W*=/,eE:true,starts:{e:/$/,r:0,c:[b]}}},{cN:"title",b:/^[\w]+:\s*$/},{cN:"phony",b:/^\.PHONY:/,e:/$/,k:".PHONY",l:/[\.\w]+/},{b:/^\t+/,e:/$/,c:[a.QSM,b]}]}}); \ No newline at end of file diff --git a/www/source/layouts/layout.slim b/www/source/layouts/layout.slim deleted file mode 100644 index 3915100..0000000 --- a/www/source/layouts/layout.slim +++ /dev/null @@ -1,25 +0,0 @@ -doctype html - -html - head - meta charset="utf-8" - meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" - meta http-equiv="X-UA-Compatible" content="IE=edge" - meta name="viewport" content="width=device-width, initial-scale=1" - - title = current_page.data.title || "The Middleman" - - = stylesheet_link_tag "all" - = stylesheet_link_tag "solarized_dark" - == yield_content :css - - body - = yield - - .container - footer class="footer" - p © Julien 'Lta' Ballet & VideoLabs SAS - - = javascript_include_tag "all" - == yield_content :javascript - diff --git a/www/source/stylesheets/all.css.sass b/www/source/stylesheets/all.css.sass deleted file mode 100644 index 5630666..0000000 --- a/www/source/stylesheets/all.css.sass +++ /dev/null @@ -1,47 +0,0 @@ - -@import "font-awesome" -@import "bootstrap" - -/* MIXINS */ - -/* As hex codes */ - -$color-primary-0: #FF411E /* Main Primary color */ -$color-primary-1: #FFAFA0 -$color-primary-2: #FF7E67 -$color-primary-3: #B11C00 -$color-primary-4: #6D1100 - -$color-secondary-1-0: #FFE91E /* Main Secondary color (1) */ -$color-secondary-1-1: #FFF6A0 -$color-secondary-1-2: #FFF067 -$color-secondary-1-3: #B1A000 -$color-secondary-1-4: #6D6300 - -$color-secondary-2-0: #6A27C8 /* Main Secondary color (2) */ -$color-secondary-2-1: #8F76B2 -$color-secondary-2-2: #7951B2 -$color-secondary-2-3: #380A78 -$color-secondary-2-4: #22054A - -$color-complement-0: #19D157 /* Main Complement color */ -$color-complement-1: #78BF90 -$color-complement-2: #4DBE73 -$color-complement-3: #00822C -$color-complement-4: #00501B - -body - background-image: image-url("images/escheresque_ste.png") - -nav.navbar.navbar-static-top - border-radius: 5px -@media (min-width: $screen-sm-min) - nav.navbar.navbar-static-top - margin-top: 15px - -a.gotop - color: $text-color - -pre.examples - padding: 2px - //border: 0px diff --git a/www/source/stylesheets/normalize.css b/www/source/stylesheets/normalize.css deleted file mode 100644 index 73abb76..0000000 --- a/www/source/stylesheets/normalize.css +++ /dev/null @@ -1,375 +0,0 @@ -/*! normalize.css v2.0.1 | MIT License | git.io/normalize */ - -/* ========================================================================== - HTML5 display definitions - ========================================================================== */ - -/* - * Corrects `block` display not defined in IE 8/9. - */ - -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -nav, -section, -summary { - display: block; -} - -/* - * Corrects `inline-block` display not defined in IE 8/9. - */ - -audio, -canvas, -video { - display: inline-block; -} - -/* - * Prevents modern browsers from displaying `audio` without controls. - * Remove excess height in iOS 5 devices. - */ - -audio:not([controls]) { - display: none; - height: 0; -} - -/* - * Addresses styling for `hidden` attribute not present in IE 8/9. - */ - -[hidden] { - display: none; -} - -/* ========================================================================== - Base - ========================================================================== */ - -/* - * 1. Sets default font family to sans-serif. - * 2. Prevents iOS text size adjust after orientation change, without disabling - * user zoom. - */ - -html { - font-family: sans-serif; /* 1 */ - -webkit-text-size-adjust: 100%; /* 2 */ - -ms-text-size-adjust: 100%; /* 2 */ -} - -/* - * Removes default margin. - */ - -body { - margin: 0; -} - -/* ========================================================================== - Links - ========================================================================== */ - -/* - * Addresses `outline` inconsistency between Chrome and other browsers. - */ - -a:focus { - outline: thin dotted; -} - -/* - * Improves readability when focused and also mouse hovered in all browsers. - */ - -a:active, -a:hover { - outline: 0; -} - -/* ========================================================================== - Typography - ========================================================================== */ - -/* - * Addresses `h1` font sizes within `section` and `article` in Firefox 4+, - * Safari 5, and Chrome. - */ - -h1 { - font-size: 2em; -} - -/* - * Addresses styling not present in IE 8/9, Safari 5, and Chrome. - */ - -abbr[title] { - border-bottom: 1px dotted; -} - -/* - * Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome. - */ - -b, -strong { - font-weight: bold; -} - -/* - * Addresses styling not present in Safari 5 and Chrome. - */ - -dfn { - font-style: italic; -} - -/* - * Addresses styling not present in IE 8/9. - */ - -mark { - background: #ff0; - color: #000; -} - - -/* - * Corrects font family set oddly in Safari 5 and Chrome. - */ - -code, -kbd, -pre, -samp { - font-family: monospace, serif; - font-size: 1em; -} - -/* - * Improves readability of pre-formatted text in all browsers. - */ - -pre { - white-space: pre; - white-space: pre-wrap; - word-wrap: break-word; -} - -/* - * Sets consistent quote types. - */ - -q { - quotes: "\201C" "\201D" "\2018" "\2019"; -} - -/* - * Addresses inconsistent and variable font size in all browsers. - */ - -small { - font-size: 80%; -} - -/* - * Prevents `sub` and `sup` affecting `line-height` in all browsers. - */ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sup { - top: -0.5em; -} - -sub { - bottom: -0.25em; -} - -/* ========================================================================== - Embedded content - ========================================================================== */ - -/* - * Removes border when inside `a` element in IE 8/9. - */ - -img { - border: 0; -} - -/* - * Corrects overflow displayed oddly in IE 9. - */ - -svg:not(:root) { - overflow: hidden; -} - -/* ========================================================================== - Figures - ========================================================================== */ - -/* - * Addresses margin not present in IE 8/9 and Safari 5. - */ - -figure { - margin: 0; -} - -/* ========================================================================== - Forms - ========================================================================== */ - -/* - * Define consistent border, margin, and padding. - */ - -fieldset { - border: 1px solid #c0c0c0; - margin: 0 2px; - padding: 0.35em 0.625em 0.75em; -} - -/* - * 1. Corrects color not being inherited in IE 8/9. - * 2. Remove padding so people aren't caught out if they zero out fieldsets. - */ - -legend { - border: 0; /* 1 */ - padding: 0; /* 2 */ -} - -/* - * 1. Corrects font family not being inherited in all browsers. - * 2. Corrects font size not being inherited in all browsers. - * 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome - */ - -button, -input, -select, -textarea { - font-family: inherit; /* 1 */ - font-size: 100%; /* 2 */ - margin: 0; /* 3 */ -} - -/* - * Addresses Firefox 4+ setting `line-height` on `input` using `!important` in - * the UA stylesheet. - */ - -button, -input { - line-height: normal; -} - -/* - * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` - * and `video` controls. - * 2. Corrects inability to style clickable `input` types in iOS. - * 3. Improves usability and consistency of cursor style between image-type - * `input` and others. - */ - -button, -html input[type="button"], /* 1 */ -input[type="reset"], -input[type="submit"] { - -webkit-appearance: button; /* 2 */ - cursor: pointer; /* 3 */ -} - -/* - * Re-set default cursor for disabled elements. - */ - -button[disabled], -input[disabled] { - cursor: default; -} - -/* - * 1. Addresses box sizing set to `content-box` in IE 8/9. - * 2. Removes excess padding in IE 8/9. - */ - -input[type="checkbox"], -input[type="radio"] { - box-sizing: border-box; /* 1 */ - padding: 0; /* 2 */ -} - -/* - * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome. - * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome - * (include `-moz` to future-proof). - */ - -input[type="search"] { - -webkit-appearance: textfield; /* 1 */ - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; /* 2 */ - box-sizing: content-box; -} - -/* - * Removes inner padding and search cancel button in Safari 5 and Chrome - * on OS X. - */ - -input[type="search"]::-webkit-search-cancel-button, -input[type="search"]::-webkit-search-decoration { - -webkit-appearance: none; -} - -/* - * Removes inner padding and border in Firefox 4+. - */ - -button::-moz-focus-inner, -input::-moz-focus-inner { - border: 0; - padding: 0; -} - -/* - * 1. Removes default vertical scrollbar in IE 8/9. - * 2. Improves readability and alignment in all browsers. - */ - -textarea { - overflow: auto; /* 1 */ - vertical-align: top; /* 2 */ -} - -/* ========================================================================== - Tables - ========================================================================== */ - -/* - * Remove most spacing between table cells. - */ - -table { - border-collapse: collapse; - border-spacing: 0; -} \ No newline at end of file diff --git a/www/source/stylesheets/solarized_dark.css b/www/source/stylesheets/solarized_dark.css deleted file mode 100644 index 6187a41..0000000 --- a/www/source/stylesheets/solarized_dark.css +++ /dev/null @@ -1,108 +0,0 @@ -/* - -Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull - -*/ - -.hljs { - display: block; - overflow-x: auto; - padding: 0.5em; - background: #002b36; - color: #839496; -} - -.hljs-comment, -.hljs-template_comment, -.diff .hljs-header, -.hljs-doctype, -.hljs-pi, -.lisp .hljs-string, -.hljs-javadoc { - color: #586e75; -} - -/* Solarized Green */ -.hljs-keyword, -.hljs-winutils, -.method, -.hljs-addition, -.css .hljs-tag, -.hljs-request, -.hljs-status, -.nginx .hljs-title { - color: #859900; -} - -/* Solarized Cyan */ -.hljs-number, -.hljs-command, -.hljs-string, -.hljs-tag .hljs-value, -.hljs-rules .hljs-value, -.hljs-phpdoc, -.tex .hljs-formula, -.hljs-regexp, -.hljs-hexcolor, -.hljs-link_url { - color: #2aa198; -} - -/* Solarized Blue */ -.hljs-title, -.hljs-localvars, -.hljs-chunk, -.hljs-decorator, -.hljs-built_in, -.hljs-identifier, -.vhdl .hljs-literal, -.hljs-id, -.css .hljs-function { - color: #268bd2; -} - -/* Solarized Yellow */ -.hljs-attribute, -.hljs-variable, -.lisp .hljs-body, -.smalltalk .hljs-number, -.hljs-constant, -.hljs-class .hljs-title, -.hljs-parent, -.haskell .hljs-type, -.hljs-link_reference { - color: #b58900; -} - -/* Solarized Orange */ -.hljs-preprocessor, -.hljs-preprocessor .hljs-keyword, -.hljs-pragma, -.hljs-shebang, -.hljs-symbol, -.hljs-symbol .hljs-string, -.diff .hljs-change, -.hljs-special, -.hljs-attr_selector, -.hljs-subst, -.hljs-cdata, -.clojure .hljs-title, -.css .hljs-pseudo, -.hljs-header { - color: #cb4b16; -} - -/* Solarized Red */ -.hljs-deletion, -.hljs-important { - color: #dc322f; -} - -/* Solarized Violet */ -.hljs-link_label { - color: #6c71c4; -} - -.tex .hljs-formula { - background: #073642; -} diff --git a/xcode/config.h b/xcode/config.h new file mode 100644 index 0000000..6d6c1be --- /dev/null +++ b/xcode/config.h @@ -0,0 +1,172 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* ... */ +#define ASN1_ARRAY_TYPE asn1_static_node + +#define BDSM_DEBUG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ALLOCA_H 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. */ +/* #undef HAVE_BSD_STRING_H */ + +/* Define to 1 if the system has the type `clockid_t'. */ +#define HAVE_CLOCKID_T 1 + +/* Define to 1 if you have the `clock_gettime' function. */ +//#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if + you don't. */ +#define HAVE_DECL_CLOCK_MONOTONIC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `getifaddrs' function. */ +#define HAVE_GETIFADDRS 1 + +/* Define if you have the iconv() function and it works. */ +#define HAVE_ICONV 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_IFADDRS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LANGINFO_H 1 + +/* Does this system have libbsd strl*** functions implementation */ +#define HAVE_LIBBSD 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `pipe' function. */ +#define HAVE_PIPE 1 + +/* Define if you have POSIX threads libraries and header files. */ +#define HAVE_PTHREAD 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +#define HAVE_PTHREAD_PRIO_INHERIT 1 + +/* 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_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 `strlcpy' function. */ +#define HAVE_STRLCPY 1 + +/* Define to 1 if you have the `strndup' function. */ +#define HAVE_STRNDUP 1 + +/* Define to 1 if the system has the type `struct timespec'. */ +#define HAVE_STRUCT_TIMESPEC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* libtasn1 has v 3.0 downcase types */ +#define HAVE_TASN1_3PLUS 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `_pipe' function. */ +/* #undef HAVE__PIPE */ + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libdsm" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libdsm" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libdsm 0.2.7" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libdsm" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.2.7" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 for Unicode (Wide Chars) APIs. */ +/* #undef UNICODE */ + +/* Path of the random number generation device */ +#define URANDOM "/dev/urandom" + +/* Version number of package */ +#define VERSION "0.2.7" + +/* Define to 64 for large files support. */ +#define _FILE_OFFSET_BITS 64 + +/* Define to 2 to get glibc warnings. */ +#define _FORTIFY_SOURCE 2 + +/* Extensions to ISO C89 from ISO C99. */ +/* #undef _ISOC99_SOURCE */ + +/* IEEE Std 1003.1. */ +/* #undef _POSIX_C_SOURCE */ + +/* IEEE Std 1003.1. */ +/* #undef _POSIX_SOURCE */ + +/* Define to 1 for Unicode (Wide Chars) APIs. */ +/* #undef _UNICODE */ + +/* ... */ +/* #undef asn1_static_node */ + +//disable assert in release +#ifdef DEBUG + #define bdsm_assert(e) assert(e) +#else + #define bdsm_assert(e) ((void)0) +#endif diff --git a/xcode/dsm.xcodeproj/project.pbxproj b/xcode/dsm.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4432d7c --- /dev/null +++ b/xcode/dsm.xcodeproj/project.pbxproj @@ -0,0 +1,598 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + AC69AC65264D16E100DEEF08 /* libtasn1.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AC69AC62264D15A000DEEF08 /* libtasn1.a */; }; + EFD6E23A1FC7644200A52250 /* clock_gettime.c in Sources */ = {isa = PBXBuildFile; fileRef = EFD6E2391FC7644100A52250 /* clock_gettime.c */; }; + EFFC77BC1D943A6D006FD550 /* compat.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77641D943A6D006FD550 /* compat.c */; }; + EFFC77BE1D943A6D006FD550 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77681D943A6D006FD550 /* strndup.c */; }; + EFFC77BF1D943A6D006FD550 /* md4.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC776B1D943A6D006FD550 /* md4.c */; }; + EFFC77C01D943A6D006FD550 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC776D1D943A6D006FD550 /* md5.c */; }; + EFFC77C11D943A6D006FD550 /* rc4.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77701D943A6D006FD550 /* rc4.c */; }; + EFFC77C31D943A6D006FD550 /* hmac_md5.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77921D943A6D006FD550 /* hmac_md5.c */; }; + EFFC77C41D943A6D006FD550 /* netbios_ns.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77961D943A6D006FD550 /* netbios_ns.c */; }; + EFFC77C51D943A6D006FD550 /* netbios_query.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77971D943A6D006FD550 /* netbios_query.c */; }; + EFFC77C61D943A6D006FD550 /* netbios_session.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77991D943A6D006FD550 /* netbios_session.c */; }; + EFFC77C71D943A6D006FD550 /* netbios_utils.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC779B1D943A6D006FD550 /* netbios_utils.c */; }; + EFFC77C81D943A6D006FD550 /* smb_buffer.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC779D1D943A6D006FD550 /* smb_buffer.c */; }; + EFFC77C91D943A6D006FD550 /* smb_dir.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77A01D943A6D006FD550 /* smb_dir.c */; }; + EFFC77CA1D943A6D006FD550 /* smb_fd.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77A21D943A6D006FD550 /* smb_fd.c */; }; + EFFC77CB1D943A6D006FD550 /* smb_file.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77A41D943A6D006FD550 /* smb_file.c */; }; + EFFC77CC1D943A6D006FD550 /* smb_message.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77A61D943A6D006FD550 /* smb_message.c */; }; + EFFC77CD1D943A6D006FD550 /* smb_ntlm.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77A81D943A6D006FD550 /* smb_ntlm.c */; }; + EFFC77CE1D943A6D006FD550 /* smb_session.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77AB1D943A6D006FD550 /* smb_session.c */; }; + EFFC77CF1D943A6D006FD550 /* smb_session_msg.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77AD1D943A6D006FD550 /* smb_session_msg.c */; }; + EFFC77D01D943A6D006FD550 /* smb_share.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77AF1D943A6D006FD550 /* smb_share.c */; }; + EFFC77D11D943A6D006FD550 /* smb_spnego.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77B11D943A6D006FD550 /* smb_spnego.c */; }; + EFFC77D21D943A6D006FD550 /* smb_stat.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77B31D943A6D006FD550 /* smb_stat.c */; }; + EFFC77D31D943A6D006FD550 /* smb_trans2.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77B51D943A6D006FD550 /* smb_trans2.c */; }; + EFFC77D41D943A6D006FD550 /* smb_transport.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77B61D943A6D006FD550 /* smb_transport.c */; }; + EFFC77D51D943A6D006FD550 /* smb_utils.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77B91D943A6D006FD550 /* smb_utils.c */; }; + EFFC77DB1D943AD9006FD550 /* spnego_asn1.c in Sources */ = {isa = PBXBuildFile; fileRef = EFFC77D71D943AD9006FD550 /* spnego_asn1.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + AC69AC61264D15A000DEEF08 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = AC69AC5D264D15A000DEEF08 /* tasn1.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = EF6319DB1C7474D10032F5CC; + remoteInfo = tasn1; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + EF6319D91C7474D10032F5CC /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + AC69AC5D264D15A000DEEF08 /* tasn1.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = tasn1.xcodeproj; path = ../libtasn1/xcode/tasn1.xcodeproj; sourceTree = ""; }; + AC94AA8322FE10430048E6AC /* bdsm_debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bdsm_debug.h; sourceTree = ""; }; + EF6319DB1C7474D10032F5CC /* libdsm.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdsm.a; sourceTree = BUILT_PRODUCTS_DIR; }; + EFD6E2391FC7644100A52250 /* clock_gettime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = clock_gettime.c; sourceTree = ""; }; + EFFC77611D943986006FD550 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = ""; }; + EFFC77641D943A6D006FD550 /* compat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat.c; sourceTree = ""; }; + EFFC77651D943A6D006FD550 /* compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = compat.h; sourceTree = ""; }; + EFFC77661D943A6D006FD550 /* queue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = queue.h; sourceTree = ""; }; + EFFC77681D943A6D006FD550 /* strndup.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strndup.c; sourceTree = ""; }; + EFFC776B1D943A6D006FD550 /* md4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md4.c; sourceTree = ""; }; + EFFC776C1D943A6D006FD550 /* md4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md4.h; sourceTree = ""; }; + EFFC776D1D943A6D006FD550 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + EFFC776E1D943A6D006FD550 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + EFFC77701D943A6D006FD550 /* rc4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rc4.c; sourceTree = ""; }; + EFFC77711D943A6D006FD550 /* rc4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rc4.h; sourceTree = ""; }; + EFFC77751D943A6D006FD550 /* spnego_asn1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = spnego_asn1.h; sourceTree = ""; }; + EFFC77781D943A6D006FD550 /* netbios_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_defs.h; sourceTree = ""; }; + EFFC77791D943A6D006FD550 /* netbios_ns.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_ns.h; sourceTree = ""; }; + EFFC777A1D943A6D006FD550 /* smb_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_defs.h; sourceTree = ""; }; + EFFC777B1D943A6D006FD550 /* smb_dir.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_dir.h; sourceTree = ""; }; + EFFC777C1D943A6D006FD550 /* smb_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_file.h; sourceTree = ""; }; + EFFC777D1D943A6D006FD550 /* smb_session.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_session.h; sourceTree = ""; }; + EFFC777E1D943A6D006FD550 /* smb_share.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_share.h; sourceTree = ""; }; + EFFC777F1D943A6D006FD550 /* smb_stat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_stat.h; sourceTree = ""; }; + EFFC77801D943A6D006FD550 /* smb_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_types.h; sourceTree = ""; }; + EFFC77811D943A6D006FD550 /* bdsm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bdsm.h; sourceTree = ""; }; + EFFC77901D943A6D006FD550 /* bdsm_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bdsm_common.h; sourceTree = ""; }; + EFFC77921D943A6D006FD550 /* hmac_md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hmac_md5.c; sourceTree = ""; }; + EFFC77931D943A6D006FD550 /* hmac_md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hmac_md5.h; sourceTree = ""; }; + EFFC77951D943A6D006FD550 /* netbios_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_defs.h; sourceTree = ""; }; + EFFC77961D943A6D006FD550 /* netbios_ns.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = netbios_ns.c; sourceTree = ""; }; + EFFC77971D943A6D006FD550 /* netbios_query.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = netbios_query.c; sourceTree = ""; }; + EFFC77981D943A6D006FD550 /* netbios_query.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_query.h; sourceTree = ""; }; + EFFC77991D943A6D006FD550 /* netbios_session.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = netbios_session.c; sourceTree = ""; }; + EFFC779A1D943A6D006FD550 /* netbios_session.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_session.h; sourceTree = ""; }; + EFFC779B1D943A6D006FD550 /* netbios_utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = netbios_utils.c; sourceTree = ""; }; + EFFC779C1D943A6D006FD550 /* netbios_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netbios_utils.h; sourceTree = ""; }; + EFFC779D1D943A6D006FD550 /* smb_buffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_buffer.c; sourceTree = ""; }; + EFFC779E1D943A6D006FD550 /* smb_buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_buffer.h; sourceTree = ""; }; + EFFC779F1D943A6D006FD550 /* smb_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_defs.h; sourceTree = ""; }; + EFFC77A01D943A6D006FD550 /* smb_dir.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_dir.c; sourceTree = ""; }; + EFFC77A11D943A6D006FD550 /* smb_dir.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_dir.h; sourceTree = ""; }; + EFFC77A21D943A6D006FD550 /* smb_fd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_fd.c; sourceTree = ""; }; + EFFC77A31D943A6D006FD550 /* smb_fd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_fd.h; sourceTree = ""; }; + EFFC77A41D943A6D006FD550 /* smb_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_file.c; sourceTree = ""; }; + EFFC77A51D943A6D006FD550 /* smb_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_file.h; sourceTree = ""; }; + EFFC77A61D943A6D006FD550 /* smb_message.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_message.c; sourceTree = ""; }; + EFFC77A71D943A6D006FD550 /* smb_message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_message.h; sourceTree = ""; }; + EFFC77A81D943A6D006FD550 /* smb_ntlm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_ntlm.c; sourceTree = ""; }; + EFFC77A91D943A6D006FD550 /* smb_ntlm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_ntlm.h; sourceTree = ""; }; + EFFC77AA1D943A6D006FD550 /* smb_packets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_packets.h; sourceTree = ""; }; + EFFC77AB1D943A6D006FD550 /* smb_session.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_session.c; sourceTree = ""; }; + EFFC77AC1D943A6D006FD550 /* smb_session.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_session.h; sourceTree = ""; }; + EFFC77AD1D943A6D006FD550 /* smb_session_msg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_session_msg.c; sourceTree = ""; }; + EFFC77AE1D943A6D006FD550 /* smb_session_msg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_session_msg.h; sourceTree = ""; }; + EFFC77AF1D943A6D006FD550 /* smb_share.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_share.c; sourceTree = ""; }; + EFFC77B01D943A6D006FD550 /* smb_share.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_share.h; sourceTree = ""; }; + EFFC77B11D943A6D006FD550 /* smb_spnego.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_spnego.c; sourceTree = ""; }; + EFFC77B21D943A6D006FD550 /* smb_spnego.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_spnego.h; sourceTree = ""; }; + EFFC77B31D943A6D006FD550 /* smb_stat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_stat.c; sourceTree = ""; }; + EFFC77B41D943A6D006FD550 /* smb_stat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_stat.h; sourceTree = ""; }; + EFFC77B51D943A6D006FD550 /* smb_trans2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_trans2.c; sourceTree = ""; }; + EFFC77B61D943A6D006FD550 /* smb_transport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_transport.c; sourceTree = ""; }; + EFFC77B71D943A6D006FD550 /* smb_transport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_transport.h; sourceTree = ""; }; + EFFC77B81D943A6D006FD550 /* smb_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_types.h; sourceTree = ""; }; + EFFC77B91D943A6D006FD550 /* smb_utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb_utils.c; sourceTree = ""; }; + EFFC77BA1D943A6D006FD550 /* smb_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smb_utils.h; sourceTree = ""; }; + EFFC77D71D943AD9006FD550 /* spnego_asn1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = spnego_asn1.c; sourceTree = ""; }; + EFFC77DE1D943F73006FD550 /* spnego_asn1_mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = spnego_asn1_mutex.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + EF6319D81C7474D10032F5CC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + AC69AC65264D16E100DEEF08 /* libtasn1.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + AC69AC5E264D15A000DEEF08 /* Products */ = { + isa = PBXGroup; + children = ( + AC69AC62264D15A000DEEF08 /* libtasn1.a */, + ); + name = Products; + sourceTree = ""; + }; + AC69AC64264D16E100DEEF08 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; + EF6319D21C7474D10032F5CC = { + isa = PBXGroup; + children = ( + AC69AC5D264D15A000DEEF08 /* tasn1.xcodeproj */, + EFFC77D61D943AD9006FD550 /* extra */, + EFFC77621D943A6D006FD550 /* compat */, + EFFC77691D943A6D006FD550 /* contrib */, + EFFC77761D943A6D006FD550 /* include */, + EFFC778F1D943A6D006FD550 /* src */, + EFFC77611D943986006FD550 /* config.h */, + EF6319DC1C7474D10032F5CC /* Products */, + AC69AC64264D16E100DEEF08 /* Frameworks */, + ); + sourceTree = ""; + }; + EF6319DC1C7474D10032F5CC /* Products */ = { + isa = PBXGroup; + children = ( + EF6319DB1C7474D10032F5CC /* libdsm.a */, + ); + name = Products; + sourceTree = ""; + }; + EFFC77621D943A6D006FD550 /* compat */ = { + isa = PBXGroup; + children = ( + EFD6E2391FC7644100A52250 /* clock_gettime.c */, + EFFC77641D943A6D006FD550 /* compat.c */, + EFFC77651D943A6D006FD550 /* compat.h */, + EFFC77661D943A6D006FD550 /* queue.h */, + EFFC77681D943A6D006FD550 /* strndup.c */, + ); + name = compat; + path = ../compat; + sourceTree = ""; + }; + EFFC77691D943A6D006FD550 /* contrib */ = { + isa = PBXGroup; + children = ( + EFFC776A1D943A6D006FD550 /* mdx */, + EFFC776F1D943A6D006FD550 /* rc4 */, + EFFC77721D943A6D006FD550 /* spnego */, + ); + name = contrib; + path = ../contrib; + sourceTree = ""; + }; + EFFC776A1D943A6D006FD550 /* mdx */ = { + isa = PBXGroup; + children = ( + EFFC776B1D943A6D006FD550 /* md4.c */, + EFFC776C1D943A6D006FD550 /* md4.h */, + EFFC776D1D943A6D006FD550 /* md5.c */, + EFFC776E1D943A6D006FD550 /* md5.h */, + ); + path = mdx; + sourceTree = ""; + }; + EFFC776F1D943A6D006FD550 /* rc4 */ = { + isa = PBXGroup; + children = ( + EFFC77701D943A6D006FD550 /* rc4.c */, + EFFC77711D943A6D006FD550 /* rc4.h */, + ); + path = rc4; + sourceTree = ""; + }; + EFFC77721D943A6D006FD550 /* spnego */ = { + isa = PBXGroup; + children = ( + EFFC77751D943A6D006FD550 /* spnego_asn1.h */, + ); + path = spnego; + sourceTree = ""; + }; + EFFC77761D943A6D006FD550 /* include */ = { + isa = PBXGroup; + children = ( + EFFC77771D943A6D006FD550 /* bdsm */, + EFFC77811D943A6D006FD550 /* bdsm.h */, + ); + name = include; + path = ../include; + sourceTree = ""; + }; + EFFC77771D943A6D006FD550 /* bdsm */ = { + isa = PBXGroup; + children = ( + EFFC77781D943A6D006FD550 /* netbios_defs.h */, + EFFC77791D943A6D006FD550 /* netbios_ns.h */, + EFFC777A1D943A6D006FD550 /* smb_defs.h */, + EFFC777B1D943A6D006FD550 /* smb_dir.h */, + EFFC777C1D943A6D006FD550 /* smb_file.h */, + EFFC777D1D943A6D006FD550 /* smb_session.h */, + EFFC777E1D943A6D006FD550 /* smb_share.h */, + EFFC777F1D943A6D006FD550 /* smb_stat.h */, + EFFC77801D943A6D006FD550 /* smb_types.h */, + ); + path = bdsm; + sourceTree = ""; + }; + EFFC778F1D943A6D006FD550 /* src */ = { + isa = PBXGroup; + children = ( + AC94AA8322FE10430048E6AC /* bdsm_debug.h */, + EFFC77901D943A6D006FD550 /* bdsm_common.h */, + EFFC77921D943A6D006FD550 /* hmac_md5.c */, + EFFC77931D943A6D006FD550 /* hmac_md5.h */, + EFFC77951D943A6D006FD550 /* netbios_defs.h */, + EFFC77961D943A6D006FD550 /* netbios_ns.c */, + EFFC77971D943A6D006FD550 /* netbios_query.c */, + EFFC77981D943A6D006FD550 /* netbios_query.h */, + EFFC77991D943A6D006FD550 /* netbios_session.c */, + EFFC779A1D943A6D006FD550 /* netbios_session.h */, + EFFC779B1D943A6D006FD550 /* netbios_utils.c */, + EFFC779C1D943A6D006FD550 /* netbios_utils.h */, + EFFC779D1D943A6D006FD550 /* smb_buffer.c */, + EFFC779E1D943A6D006FD550 /* smb_buffer.h */, + EFFC779F1D943A6D006FD550 /* smb_defs.h */, + EFFC77A01D943A6D006FD550 /* smb_dir.c */, + EFFC77A11D943A6D006FD550 /* smb_dir.h */, + EFFC77A21D943A6D006FD550 /* smb_fd.c */, + EFFC77A31D943A6D006FD550 /* smb_fd.h */, + EFFC77A41D943A6D006FD550 /* smb_file.c */, + EFFC77A51D943A6D006FD550 /* smb_file.h */, + EFFC77A61D943A6D006FD550 /* smb_message.c */, + EFFC77A71D943A6D006FD550 /* smb_message.h */, + EFFC77A81D943A6D006FD550 /* smb_ntlm.c */, + EFFC77A91D943A6D006FD550 /* smb_ntlm.h */, + EFFC77AA1D943A6D006FD550 /* smb_packets.h */, + EFFC77AB1D943A6D006FD550 /* smb_session.c */, + EFFC77AC1D943A6D006FD550 /* smb_session.h */, + EFFC77AD1D943A6D006FD550 /* smb_session_msg.c */, + EFFC77AE1D943A6D006FD550 /* smb_session_msg.h */, + EFFC77AF1D943A6D006FD550 /* smb_share.c */, + EFFC77B01D943A6D006FD550 /* smb_share.h */, + EFFC77B11D943A6D006FD550 /* smb_spnego.c */, + EFFC77B21D943A6D006FD550 /* smb_spnego.h */, + EFFC77B31D943A6D006FD550 /* smb_stat.c */, + EFFC77B41D943A6D006FD550 /* smb_stat.h */, + EFFC77B51D943A6D006FD550 /* smb_trans2.c */, + EFFC77B61D943A6D006FD550 /* smb_transport.c */, + EFFC77B71D943A6D006FD550 /* smb_transport.h */, + EFFC77B81D943A6D006FD550 /* smb_types.h */, + EFFC77B91D943A6D006FD550 /* smb_utils.c */, + EFFC77BA1D943A6D006FD550 /* smb_utils.h */, + ); + name = src; + path = ../src; + sourceTree = ""; + }; + EFFC77D61D943AD9006FD550 /* extra */ = { + isa = PBXGroup; + children = ( + EFFC77DE1D943F73006FD550 /* spnego_asn1_mutex.h */, + EFFC77D71D943AD9006FD550 /* spnego_asn1.c */, + ); + path = extra; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + EF6319DA1C7474D10032F5CC /* dsm */ = { + isa = PBXNativeTarget; + buildConfigurationList = EF6319E41C7474D10032F5CC /* Build configuration list for PBXNativeTarget "dsm" */; + buildPhases = ( + EF6319D71C7474D10032F5CC /* Sources */, + EF6319D81C7474D10032F5CC /* Frameworks */, + EF6319D91C7474D10032F5CC /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = dsm; + productName = libdsm; + productReference = EF6319DB1C7474D10032F5CC /* libdsm.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + EF6319D31C7474D10032F5CC /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0720; + ORGANIZATIONNAME = myorg; + TargetAttributes = { + EF6319DA1C7474D10032F5CC = { + CreatedOnToolsVersion = 7.2; + }; + }; + }; + buildConfigurationList = EF6319D61C7474D10032F5CC /* Build configuration list for PBXProject "dsm" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + ); + mainGroup = EF6319D21C7474D10032F5CC; + productRefGroup = EF6319DC1C7474D10032F5CC /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = AC69AC5E264D15A000DEEF08 /* Products */; + ProjectRef = AC69AC5D264D15A000DEEF08 /* tasn1.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + EF6319DA1C7474D10032F5CC /* dsm */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + AC69AC62264D15A000DEEF08 /* libtasn1.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libtasn1.a; + remoteRef = AC69AC61264D15A000DEEF08 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXSourcesBuildPhase section */ + EF6319D71C7474D10032F5CC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EFFC77C81D943A6D006FD550 /* smb_buffer.c in Sources */, + EFFC77C11D943A6D006FD550 /* rc4.c in Sources */, + EFFC77C71D943A6D006FD550 /* netbios_utils.c in Sources */, + EFFC77CD1D943A6D006FD550 /* smb_ntlm.c in Sources */, + EFFC77DB1D943AD9006FD550 /* spnego_asn1.c in Sources */, + EFFC77C61D943A6D006FD550 /* netbios_session.c in Sources */, + EFFC77CB1D943A6D006FD550 /* smb_file.c in Sources */, + EFFC77CA1D943A6D006FD550 /* smb_fd.c in Sources */, + EFFC77C01D943A6D006FD550 /* md5.c in Sources */, + EFFC77D41D943A6D006FD550 /* smb_transport.c in Sources */, + EFFC77D21D943A6D006FD550 /* smb_stat.c in Sources */, + EFFC77D51D943A6D006FD550 /* smb_utils.c in Sources */, + EFFC77C51D943A6D006FD550 /* netbios_query.c in Sources */, + EFFC77C31D943A6D006FD550 /* hmac_md5.c in Sources */, + EFFC77D31D943A6D006FD550 /* smb_trans2.c in Sources */, + EFFC77D01D943A6D006FD550 /* smb_share.c in Sources */, + EFFC77D11D943A6D006FD550 /* smb_spnego.c in Sources */, + EFFC77CF1D943A6D006FD550 /* smb_session_msg.c in Sources */, + EFFC77C41D943A6D006FD550 /* netbios_ns.c in Sources */, + EFFC77BE1D943A6D006FD550 /* strndup.c in Sources */, + EFFC77CE1D943A6D006FD550 /* smb_session.c in Sources */, + EFFC77CC1D943A6D006FD550 /* smb_message.c in Sources */, + EFFC77BC1D943A6D006FD550 /* compat.c in Sources */, + EFFC77C91D943A6D006FD550 /* smb_dir.c in Sources */, + EFFC77BF1D943A6D006FD550 /* md4.c in Sources */, + EFD6E23A1FC7644200A52250 /* clock_gettime.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + EF6319E21C7474D10032F5CC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-ObjC"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TVOS_DEPLOYMENT_TARGET = 9.0; + WATCHOS_DEPLOYMENT_TARGET = 2.0; + }; + name = Debug; + }; + EF6319E31C7474D10032F5CC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-DNS_BLOCK_ASSERTIONS=1", + "-DNDEBUG", + ); + OTHER_LDFLAGS = "-ObjC"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TVOS_DEPLOYMENT_TARGET = 9.0; + VALIDATE_PRODUCT = YES; + WATCHOS_DEPLOYMENT_TARGET = 2.0; + }; + name = Release; + }; + EF6319E51C7474D10032F5CC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "../libtasn1/include/**", + "../include/**", + "../**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "../libtasn1/**", + "../include/**", + ); + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = dsm; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + EF6319E61C7474D10032F5CC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "../libtasn1/include/**", + "../include/**", + "../**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "../libtasn1/**", + "../include/**", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "-DNS_BLOCK_ASSERTIONS=1", + "-DNDEBUG", + ); + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = dsm; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + EF6319D61C7474D10032F5CC /* Build configuration list for PBXProject "dsm" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EF6319E21C7474D10032F5CC /* Debug */, + EF6319E31C7474D10032F5CC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EF6319E41C7474D10032F5CC /* Build configuration list for PBXNativeTarget "dsm" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EF6319E51C7474D10032F5CC /* Debug */, + EF6319E61C7474D10032F5CC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = EF6319D31C7474D10032F5CC /* Project object */; +} diff --git a/xcode/dsm.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/xcode/dsm.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca09337 --- /dev/null +++ b/xcode/dsm.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/dsm.xcscmblueprint b/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/dsm.xcscmblueprint new file mode 100644 index 0000000..77fc7ef --- /dev/null +++ b/xcode/dsm.xcodeproj/project.xcworkspace/xcshareddata/dsm.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "A5BF903B41F34D3DCE1237C6AD44B520272A9268", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "BAA428024A28FF1B10B975069015519D5CEE4DB6" : 9223372036854775807, + "A5BF903B41F34D3DCE1237C6AD44B520272A9268" : 9223372036854775807 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "41C3B127-9885-4BD7-8EE9-DFA8954F042D", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "BAA428024A28FF1B10B975069015519D5CEE4DB6" : "..", + "A5BF903B41F34D3DCE1237C6AD44B520272A9268" : "libdsm\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "dsm", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "xcode\/dsm.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/leshkoapps\/libdsm.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A5BF903B41F34D3DCE1237C6AD44B520272A9268" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/leshkoapps\/TOSMBClient.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "BAA428024A28FF1B10B975069015519D5CEE4DB6" + } + ] +} \ No newline at end of file diff --git a/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/ameleshko.xcuserdatad/UserInterfaceState.xcuserstate b/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/ameleshko.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..d1b31a7 Binary files /dev/null and b/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/ameleshko.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/artem.xcuserdatad/UserInterfaceState.xcuserstate b/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/artem.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..2160bda Binary files /dev/null and b/xcode/dsm.xcodeproj/project.xcworkspace/xcuserdata/artem.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/dsm.xcscheme b/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/dsm.xcscheme new file mode 100644 index 0000000..f09a192 --- /dev/null +++ b/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/dsm.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/xcschememanagement.plist b/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..16a7ffa --- /dev/null +++ b/xcode/dsm.xcodeproj/xcuserdata/ameleshko.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + dsm.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + EF6319DA1C7474D10032F5CC + + primary + + + + + diff --git a/xcode/dsm.xcodeproj/xcuserdata/artem.xcuserdatad/xcschemes/xcschememanagement.plist b/xcode/dsm.xcodeproj/xcuserdata/artem.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..e06ed97 --- /dev/null +++ b/xcode/dsm.xcodeproj/xcuserdata/artem.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + dsm.xcscheme + + orderHint + 61 + + dsm.xcscheme_^#shared#^_ + + orderHint + 1 + + + + diff --git a/xcode/extra/spnego_asn1.c b/xcode/extra/spnego_asn1.c new file mode 100644 index 0000000..f8e9381 --- /dev/null +++ b/xcode/extra/spnego_asn1.c @@ -0,0 +1,70 @@ +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "libtasn1.h" + +const asn1_static_node spnego_asn1_conf[] = { + { "SPNEGO", 536872976, NULL }, + { NULL, 1073741836, NULL }, + { "MechType", 1073741836, NULL }, + { "MechTypeList", 1610612747, NULL }, + { NULL, 2, "MechType"}, + { "ContextFlags", 1610874886, NULL }, + { "delegFlag", 1073741825, "0"}, + { "mutualFlag", 1073741825, "1"}, + { "replayFlag", 1073741825, "2"}, + { "sequenceFlag", 1073741825, "3"}, + { "anonFlag", 1073741825, "4"}, + { "confFlag", 1073741825, "5"}, + { "integFlag", 1, "6"}, + { "NegHints", 1610612741, NULL }, + { "hintName", 1610637339, NULL }, + { NULL, 2056, "0"}, + { "hintAddress", 536895495, NULL }, + { NULL, 2056, "1"}, + { "NegTokenInitWin", 1610612741, NULL }, + { "mechTypes", 1610620930, "MechTypeList"}, + { NULL, 2056, "0"}, + { "reqFlags", 1610637314, "ContextFlags"}, + { NULL, 2056, "1"}, + { "mechToken", 1610637319, NULL }, + { NULL, 2056, "2"}, + { "negHints", 536895490, "NegHints"}, + { NULL, 2056, "3"}, + { "NegTokenInit", 1610612741, NULL }, + { "mechTypes", 1610620930, "MechTypeList"}, + { NULL, 2056, "0"}, + { "reqFlags", 1610637314, "ContextFlags"}, + { NULL, 2056, "1"}, + { "mechToken", 1610637319, NULL }, + { NULL, 2056, "2"}, + { "mechListMIC", 536895495, NULL }, + { NULL, 2056, "3"}, + { "NegTokenResp", 1610612741, NULL }, + { "negResult", 1610899477, NULL }, + { NULL, 1073743880, "0"}, + { "accept_completed", 1073741825, "0"}, + { "accept_incomplete", 1073741825, "1"}, + { "reject", 1073741825, "2"}, + { "request-mic", 1, "3"}, + { "supportedMech", 1610637314, "MechType"}, + { NULL, 2056, "1"}, + { "responseToken", 1610637319, NULL }, + { NULL, 2056, "2"}, + { "mechListMIC", 536895495, NULL }, + { NULL, 2056, "3"}, + { "NegotiationToken", 1610612754, NULL }, + { "negTokenInit", 1610620930, "NegTokenInit"}, + { NULL, 2056, "0"}, + { "negTokenResp", 536879106, "NegTokenResp"}, + { NULL, 2056, "1"}, + { "NegotiationTokenWin", 1610612754, NULL }, + { "negTokenInit", 536879106, "NegTokenInitWin"}, + { NULL, 2056, "0"}, + { "GSSAPIContextToken", 536879109, NULL }, + { NULL, 1073746952, "0"}, + { "thisMech", 1073741826, "MechType"}, + { "spnego", 2, "NegotiationToken"}, + { NULL, 0, NULL } +}; diff --git a/xcode/extra/spnego_asn1_mutex.h b/xcode/extra/spnego_asn1_mutex.h new file mode 100644 index 0000000..3bed911 --- /dev/null +++ b/xcode/extra/spnego_asn1_mutex.h @@ -0,0 +1,26 @@ + +#include +#import +#import + +#include "../config.h" + +static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER; +static char asn1_locked = 0; + +#define asn1_lock() {if (pthread_mutex_lock(&static_mutex)!=0){\ +bdsm_assert(0);\ +}\ +set_asn1_locked(1);\ +}\ + +#define asn1_unlock() {if (pthread_mutex_unlock(&static_mutex)!=0){\ +bdsm_assert(0);\ +}\ +set_asn1_locked(0);\ +}\ + +static void set_asn1_locked(char locked){ + //bdsm_assert(asn1_locked!=locked); + asn1_locked = locked; +}