From bcf8a4bb3fcbe7002c2db242a3223f8425fe7e18 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Mar 2005 17:03:13 +0000 Subject: [PATCH] r5754: implement derrell's solution for binary compatibilty in the _SMBCCTX structure; note that we break compat with 3.0.11 but are ok with earlier versions --- source/include/libsmb_internal.h | 214 ++++++++++++++------------------------- source/include/libsmbclient.h | 68 ++++++++++++- source/libsmb/libsmb_cache.c | 2 +- source/libsmb/libsmbclient.c | 16 ++- 4 files changed, 148 insertions(+), 152 deletions(-) rewrite source/include/libsmb_internal.h (70%) diff --git a/source/include/libsmb_internal.h b/source/include/libsmb_internal.h dissimilarity index 70% index 803f9e1f108..a1db5c27926 100644 --- a/source/include/libsmb_internal.h +++ b/source/include/libsmb_internal.h @@ -1,137 +1,77 @@ -#ifndef _LIBSMB_INTERNAL_H_ -#define _LIBSMB_INTERNAL_H_ - -#define SMBC_MAX_NAME 1023 -#define SMBC_FILE_MODE (S_IFREG | 0444) -#define SMBC_DIR_MODE (S_IFDIR | 0555) - - -#include "include/libsmbclient.h" - - -struct _SMBCSRV { - struct cli_state cli; - dev_t dev; - BOOL no_pathinfo2; - BOOL no_nt_session; - int server_fd; - - SMBCSRV *next, *prev; - -}; - -/* - * Keep directory entries in a list - */ -struct smbc_dir_list { - struct smbc_dir_list *next; - struct smbc_dirent *dirent; -}; - - -/* - * Structure for open file management - */ -struct _SMBCFILE { - int cli_fd; - char *fname; - off_t offset; - struct _SMBCSRV *srv; - BOOL file; - struct smbc_dir_list *dir_list, *dir_end, *dir_next; - int dir_type, dir_error; - - SMBCFILE *next, *prev; -}; - - -struct smbc_internal_data { - - /** INTERNAL: is this handle initialized ? - */ - int _initialized; - - /** INTERNAL: dirent pointer location - * - * Leave room for any urlencoded filename and the comment field. - * - * We really should use sizeof(struct smbc_dirent) plus (NAME_MAX * 3) - * plus whatever the max length of a comment is, plus a couple of null - * terminators (one after the filename, one after the comment). - * - * According to , NAME_MAX is 255. Is it longer - * anyplace else? - */ - char _dirent[1024]; - - /** INTERNAL: server connection list - */ - SMBCSRV * _servers; - - /** INTERNAL: open file/dir list - */ - SMBCFILE * _files; - /** user options selections that apply to this session - */ - struct _smbc_options { - - /* - * From how many local master browsers should the list of - * workgroups be retrieved? It can take up to 12 minutes or - * longer after a server becomes a local master browser, for - * it to have the entire browse list (the list of - * workgroups/domains) from an entire network. Since a client - * never knows which local master browser will be found first, - * the one which is found first and used to retrieve a browse - * list may have an incomplete or empty browse list. By - * requesting the browse list from multiple local master - * browsers, a more complete list can be generated. For small - * networks (few workgroups), it is recommended that this - * value be set to 0, causing the browse lists from all found - * local master browsers to be retrieved and merged. For - * networks with many workgroups, a suitable value for this - * variable is probably somewhere around 3. (Default: 3). - */ - int browse_max_lmb_count; - - /* - * There is a difference in the desired return strings from - * smbc_readdir() depending upon whether the filenames are to - * be displayed to the user, or whether they are to be - * appended to the path name passed to smbc_opendir() to call - * a further smbc_ function (e.g. open the file with - * smbc_open()). In the former case, the filename should be - * in "human readable" form. In the latter case, the smbc_ - * functions expect a URL which must be url-encoded. Those - * functions decode the URL. If, for example, smbc_readdir() - * returned a file name of "abc%20def.txt", passing a path - * with this file name attached to smbc_open() would cause - * smbc_open to attempt to open the file "abc def.txt" since - * the %20 is decoded into a space. - * - * Set this option to True if the names returned by - * smbc_readdir() should be url-encoded such that they can be - * passed back to another smbc_ call. Set it to False if the - * names returned by smbc_readdir() are to be presented to the - * user. - * - * For backwards compatibility, this option defaults to False. - */ - int urlencode_readdir_entries; - - /* - * Some Windows versions appear to have a limit to the number - * of concurrent SESSIONs and/or TREE CONNECTions. In - * one-shot programs (i.e. the program runs and then quickly - * ends, thereby shutting down all connections), it is - * probably reasonable to establish a new connection for each - * share. In long-running applications, the limitation can be - * avoided by using only a single connection to each server, - * and issuing a new TREE CONNECT when the share is accessed. - */ - int one_share_per_server; - } options; -}; - - -#endif +#ifndef _LIBSMB_INTERNAL_H_ +#define _LIBSMB_INTERNAL_H_ + +#define SMBC_MAX_NAME 1023 +#define SMBC_FILE_MODE (S_IFREG | 0444) +#define SMBC_DIR_MODE (S_IFDIR | 0555) + + +#include "include/libsmbclient.h" + + +struct _SMBCSRV { + struct cli_state cli; + dev_t dev; + BOOL no_pathinfo2; + BOOL no_nt_session; + int server_fd; + + SMBCSRV *next, *prev; + +}; + +/* + * Keep directory entries in a list + */ +struct smbc_dir_list { + struct smbc_dir_list *next; + struct smbc_dirent *dirent; +}; + + +/* + * Structure for open file management + */ +struct _SMBCFILE { + int cli_fd; + char *fname; + off_t offset; + struct _SMBCSRV *srv; + BOOL file; + struct smbc_dir_list *dir_list, *dir_end, *dir_next; + int dir_type, dir_error; + + SMBCFILE *next, *prev; +}; + + +struct smbc_internal_data { + + /** INTERNAL: is this handle initialized ? + */ + int _initialized; + + /** INTERNAL: dirent pointer location + * + * Leave room for any urlencoded filename and the comment field. + * + * We really should use sizeof(struct smbc_dirent) plus (NAME_MAX * 3) + * plus whatever the max length of a comment is, plus a couple of null + * terminators (one after the filename, one after the comment). + * + * According to , NAME_MAX is 255. Is it longer + * anyplace else? + */ + char _dirent[1024]; + + /** INTERNAL: server connection list + */ + SMBCSRV * _servers; + + /** INTERNAL: open file/dir list + */ + SMBCFILE * _files; +}; + + +#endif diff --git a/source/include/libsmbclient.h b/source/include/libsmbclient.h index abcf660c9de..636083b41d4 100644 --- a/source/include/libsmbclient.h +++ b/source/include/libsmbclient.h @@ -68,8 +68,6 @@ #include #include -#define SMBC_CTX_VERSION 1 - #define SMBC_BASE_FD 10000 /* smallest file descriptor returned */ #define SMBC_WORKGROUP 1 @@ -466,19 +464,79 @@ struct _SMBCCTX { */ struct smbc_server_cache * server_cache; + int flags; + + /** user options selections that apply to this session + */ + struct _smbc_options { + + /* + * From how many local master browsers should the list of + * workgroups be retrieved? It can take up to 12 minutes or + * longer after a server becomes a local master browser, for + * it to have the entire browse list (the list of + * workgroups/domains) from an entire network. Since a client + * never knows which local master browser will be found first, + * the one which is found first and used to retrieve a browse + * list may have an incomplete or empty browse list. By + * requesting the browse list from multiple local master + * browsers, a more complete list can be generated. For small + * networks (few workgroups), it is recommended that this + * value be set to 0, causing the browse lists from all found + * local master browsers to be retrieved and merged. For + * networks with many workgroups, a suitable value for this + * variable is probably somewhere around 3. (Default: 3). + */ + int browse_max_lmb_count; + + /* + * There is a difference in the desired return strings from + * smbc_readdir() depending upon whether the filenames are to + * be displayed to the user, or whether they are to be + * appended to the path name passed to smbc_opendir() to call + * a further smbc_ function (e.g. open the file with + * smbc_open()). In the former case, the filename should be + * in "human readable" form. In the latter case, the smbc_ + * functions expect a URL which must be url-encoded. Those + * functions decode the URL. If, for example, smbc_readdir() + * returned a file name of "abc%20def.txt", passing a path + * with this file name attached to smbc_open() would cause + * smbc_open to attempt to open the file "abc def.txt" since + * the %20 is decoded into a space. + * + * Set this option to True if the names returned by + * smbc_readdir() should be url-encoded such that they can be + * passed back to another smbc_ call. Set it to False if the + * names returned by smbc_readdir() are to be presented to the + * user. + * + * For backwards compatibility, this option defaults to False. + */ + int urlencode_readdir_entries; + + /* + * Some Windows versions appear to have a limit to the number + * of concurrent SESSIONs and/or TREE CONNECTions. In + * one-shot programs (i.e. the program runs and then quickly + * ends, thereby shutting down all connections), it is + * probably reasonable to establish a new connection for each + * share. In long-running applications, the limitation can be + * avoided by using only a single connection to each server, + * and issuing a new TREE CONNECT when the share is accessed. + */ + int one_share_per_server; + } options; + /** INTERNAL DATA * do _NOT_ touch this from your program ! */ struct smbc_internal_data * internal; - - int flags; }; /* Flags for SMBCCTX->flags */ #define SMB_CTX_FLAG_USE_KERBEROS (1 << 0) #define SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS (1 << 1) #define SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON (1 << 2) /* don't try to do automatic anon login */ -#define SMBCCTX_FLAG_CTXVER (1 << 3 ) /* internal flag used to define _SMBCCTX version */ /**@ingroup misc * Create a new SBMCCTX (a context). diff --git a/source/libsmb/libsmb_cache.c b/source/libsmb/libsmb_cache.c index 71399f14db8..dabf5a527d5 100644 --- a/source/libsmb/libsmb_cache.c +++ b/source/libsmb/libsmb_cache.c @@ -143,7 +143,7 @@ static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server, * a connection to the server (other than the * attribute server connection) is cool. */ - if (context->internal->options.one_share_per_server) { + if (context->options.one_share_per_server) { /* * The currently connected share name * doesn't match the requested share, so diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index c876720cfab..441ca96478b 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -571,7 +571,7 @@ SMBCSRV *smbc_server(SMBCCTX *context, * If we found a connection and we're only allowed one share per * server... */ - if (srv && *share != '\0' && context->internal->options.one_share_per_server) { + if (srv && *share != '\0' && context->options.one_share_per_server) { /* * ... then if there's no current connection to the share, @@ -1932,9 +1932,9 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) } /* Determine how many local master browsers to query */ - max_lmb_count = (context->internal->options.browse_max_lmb_count == 0 + max_lmb_count = (context->options.browse_max_lmb_count == 0 ? INT_MAX - : context->internal->options.browse_max_lmb_count); + : context->options.browse_max_lmb_count); pstrcpy(u_info.username, user); pstrcpy(u_info.password, password); @@ -2216,7 +2216,7 @@ static void smbc_readdir_internal(SMBCCTX * context, struct smbc_dirent *src, int max_namebuf_len) { - if (context->internal->options.urlencode_readdir_entries) { + if (context->options.urlencode_readdir_entries) { /* url-encode the name. get back remaining buffer space */ max_namebuf_len = @@ -4804,8 +4804,6 @@ SMBCCTX * smbc_new_context(void) return NULL; } - context->flags = SMBCCTX_FLAG_CTXVER; - ZERO_STRUCTP(context->internal); @@ -4813,9 +4811,9 @@ SMBCCTX * smbc_new_context(void) context->debug = 0; context->timeout = 20000; /* 20 seconds */ - context->internal->options.browse_max_lmb_count = 3; /* # LMBs to query */ - context->internal->options.urlencode_readdir_entries = False;/* backward compat */ - context->internal->options.one_share_per_server = False;/* backward compat */ + context->options.browse_max_lmb_count = 3; /* # LMBs to query */ + context->options.urlencode_readdir_entries = False;/* backward compat */ + context->options.one_share_per_server = False;/* backward compat */ context->open = smbc_open_ctx; context->creat = smbc_creat_ctx; -- 2.11.4.GIT