diff options
388 files changed, 15389 insertions, 5319 deletions
diff --git a/WHATSNEW.txt b/WHATSNEW.txt index 0ce24fb60f..c4b8a04704 100644 --- a/WHATSNEW.txt +++ b/WHATSNEW.txt @@ -1,4 +1,4 @@ -What's new in Samba 4 alpha2 +What's new in Samba 4 alpha1 ============================ Samba 4 is the ambitious next version of the Samba suite that is being @@ -10,14 +10,17 @@ Samba 4 is currently not yet in a state where it is usable in production environments. Note the WARNINGS below, and the STATUS file, which aims to document what should and should not work. -Samba4 alpha2 follows on from our first alpha release, made in -September, and the Technology Preview series we have offered for some -time now. +Samba4 alpha1 is the culmination of 4.5 years of development under our +belt since Tridge first proposed a new Virtual File System (VFS) layer +for Samba3 (a project which eventually lead to our Active Directory +efforts), and 1.5 years since we first released a Technology Preview, +we wish to allow users, managers and developers to see how we have +progressed, and to invite feedback and support. WARNINGS ======== -Samba4 alpha2 is not a final Samba release. That is more a reference +Samba4 alpha1 is not a final Samba release. That is more a reference to Samba4's lack of the features we expect you will need than a statement of code quality, but clearly it hasn't seen a broad deployment yet. If you were to upgrade Samba3 (or indeed Windows) to @@ -55,7 +58,7 @@ annotation information (in streams) and NT ACLs in particular. The VFS is backed with an extensive automated test suite. A new scripting interface has been added to Samba 4, allowing -Python programs to interface to Samba's internals. +JavaScript programs to interface to Samba's internals. The Samba 4 architecture is based around an LDAP-like database that can use a range of modular backends. One of the backends supports @@ -64,26 +67,26 @@ working on modules to map between AD-like behaviours and this backend. We are aiming for Samba 4 to be powerful frontend to large directories. -CHANGES SINCE Alpha 1 -===================== +CHANGES SINCE TP5 +================= -In the time since Samba4 Alpha1 was released in September 2007, Samba has +In the time since TP5 was released in June 2007, Samba has continued to evolve, but you may particularly notice these areas: - MMC Support: The Active Directory Users and Computers console now - handles group membership correctly. + Group Policy Support: Basic group policies may be defined, and are + enforced by Windows clients - member/memberOf: These and other linked attributes are now kept in - sync + MMC Support: The Active Directory Users and Computers console now + works, supporting most operations. - subtree renames: Renaming a subtree of LDAP objects is now possible, - with all linked attributes being kept consistant. + Winbind: Kai Blin has been working hard on his Google Summer of + Code project, creating a winbind implementation for Samba4. - Python Bindings: Bindings for a future move to Python as the - internal scripting language have been created. + Heimdal update: A Heimdal 1.0 snapshot is now included as the + internal Kerberos library in Samba4. - Shared library use: In support of projects such as OpenChange, - which depend on Samba4, more of Samba4 is built as shared libraries. + In the past few weeks, many small but significant bugs have been + fixed, particularly thanks to Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> These are just some of the highlights of the work done in the past few months. More details can be found in our SVN history. @@ -103,6 +106,12 @@ KNOWN ISSUES - There is no printing support in the current release. +- Support for managing groups is currently poor (as the + memberOf/member linked attributes are not kept in sync). + +- Renaming and deleting subtrees (containers) in the the LDB tree will + have unexpected results. + - The Samba4 port of the CTDB clustering support is not yet complete - Clock Synchronisation is critical. Many 'wrong password' errors are diff --git a/prog_guide.txt b/prog_guide.txt index f5ac600f88..3814a11a4e 100644 --- a/prog_guide.txt +++ b/prog_guide.txt @@ -146,6 +146,7 @@ Static data is evil as it has the following consequences: - it makes code much less likely to be recursion-safe - it leads to subtle side effects when the same code is called from multiple places + - doesn't play well with shared libraries or plugins Static data is particularly evil in library code (such as our internal smb and rpc libraries). If you can get rid of all static data in diff --git a/source4/VERSION b/source4/VERSION index d53cfcecdb..2f5f7009de 100644 --- a/source4/VERSION +++ b/source4/VERSION @@ -57,7 +57,7 @@ SAMBA_VERSION_TP_RELEASE= # e.g. SAMBA_VERSION_ALPHA_RELEASE=1 # # -> "4.0.0alpha1" # ######################################################## -SAMBA_VERSION_ALPHA_RELEASE=2 +SAMBA_VERSION_ALPHA_RELEASE=3 ######################################################## # For 'pre' releases the version will be # @@ -89,7 +89,7 @@ SAMBA_VERSION_RC_RELEASE= # e.g. SAMBA_VERSION_IS_SVN_SNAPSHOT=yes # # -> "3.0.0-SVN-build-199" # ######################################################## -SAMBA_VERSION_IS_SVN_SNAPSHOT=no +SAMBA_VERSION_IS_SVN_SNAPSHOT=yes ######################################################## # This is for specifying a release nickname # diff --git a/source4/auth/auth.c b/source4/auth/auth.c index 0068c3bde7..918890b3f6 100644 --- a/source4/auth/auth.c +++ b/source4/auth/auth.c @@ -512,27 +512,21 @@ const struct auth_critical_sizes *auth_interface_version(void) return &critical_sizes; } -NTSTATUS auth_init(struct loadparm_context *lp_ctx) +NTSTATUS auth_init(void) { static bool initialized = false; init_module_fn static_init[] = STATIC_auth_MODULES; - init_module_fn *shared_init; if (initialized) return NT_STATUS_OK; initialized = true; - shared_init = load_samba_modules(NULL, lp_ctx, "auth"); - run_init_functions(static_init); - run_init_functions(shared_init); - - talloc_free(shared_init); return NT_STATUS_OK; } NTSTATUS server_service_auth_init(void) { - return auth_init(global_loadparm); + return auth_init(); } diff --git a/source4/auth/auth.i b/source4/auth/auth.i index 491157a88d..5c6f06edef 100644 --- a/source4/auth/auth.i +++ b/source4/auth/auth.i @@ -27,12 +27,14 @@ #include "includes.h" #include "auth/session.h" #include "auth/system_session_proto.h" +#include "param/param.h" %} -%include "carrays.i" -%include "stdint.i" -%include "typemaps.i" +%import "carrays.i" +%import "stdint.i" +%import "typemaps.i" %import "../lib/talloc/talloc.i" +%import "../param/param.i" %typemap(default) struct auth_session_info * { $1 = system_session_anon(NULL, global_loadparm); diff --git a/source4/auth/auth.py b/source4/auth/auth.py index d93591278f..88675f3626 100644 --- a/source4/auth/auth.py +++ b/source4/auth/auth.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _auth import new @@ -48,6 +47,17 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +import param system_session = _auth.system_session system_session_anon = _auth.system_session_anon diff --git a/source4/auth/auth_sam_reply.c b/source4/auth/auth_sam_reply.c index bbbda2dc89..6ab220498d 100644 --- a/source4/auth/auth_sam_reply.c +++ b/source4/auth/auth_sam_reply.c @@ -81,9 +81,7 @@ NTSTATUS auth_convert_server_info_sambaseinfo(TALLOC_CTX *mem_ctx, } } - sam->user_flags = 0; /* TODO: w2k3 uses 0x120. We know 0x20 - * as extra sids (PAC doc) but what is - * 0x100? */ + sam->user_flags = 0; /* w2k3 uses NETLOGON_EXTRA_SIDS | NETLOGON_NTLMV2_ENABLED */ sam->acct_flags = server_info->acct_flags; sam->logon_server.string = server_info->logon_server; sam->domain.string = server_info->domain_name; diff --git a/source4/auth/auth_server.c b/source4/auth/auth_server.c index b5fcda15b3..f200ad9665 100644 --- a/source4/auth/auth_server.c +++ b/source4/auth/auth_server.c @@ -24,7 +24,7 @@ Support for server level security. ****************************************************************************/ -static struct smbcli_state *server_cryptkey(TALLOC_CTX *mem_ctx, bool unicode, int maxprotocol, const char **name_resolve_order) +static struct smbcli_state *server_cryptkey(TALLOC_CTX *mem_ctx, bool unicode, int maxprotocol, struct resolve_context *resolve_ctx) { struct smbcli_state *cli = NULL; fstring desthost; @@ -45,7 +45,7 @@ static struct smbcli_state *server_cryptkey(TALLOC_CTX *mem_ctx, bool unicode, i while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) { strupper(desthost); - if(!resolve_name( desthost, &dest_ip, 0x20, name_resolve_order)) { + if(!resolve_name(resolve_ctx, desthost, &dest_ip, 0x20)) { DEBUG(1,("server_cryptkey: Can't resolve address for %s\n",desthost)); continue; } @@ -215,7 +215,7 @@ static NTSTATUS check_smbserver_security(const struct auth_context *auth_context if (cli) { } else { - cli = server_cryptkey(mem_ctx, lp_unicode(auth_context->lp_ctx), lp_cli_maxprotocol(auth_context->lp_ctx), lp_name_resolve_order(auth_context->lp_ctx)); + cli = server_cryptkey(mem_ctx, lp_unicode(auth_context->lp_ctx), lp_cli_maxprotocol(auth_context->lp_ctx), lp_resolve_context(auth_context->lp_ctx)); locally_made_cli = true; } diff --git a/source4/auth/auth_util.c b/source4/auth/auth_util.c index baecb15f1e..b1f0e60507 100644 --- a/source4/auth/auth_util.c +++ b/source4/auth/auth_util.c @@ -81,7 +81,9 @@ NTSTATUS map_user_info(TALLOC_CTX *mem_ctx, if (!*user_info_mapped) { return NT_STATUS_NO_MEMORY; } - talloc_reference(*user_info_mapped, user_info); + if (!talloc_reference(*user_info_mapped, user_info)) { + return NT_STATUS_NO_MEMORY; + } **user_info_mapped = *user_info; (*user_info_mapped)->mapped_state = true; (*user_info_mapped)->mapped.domain_name = talloc_strdup(*user_info_mapped, domain); @@ -129,7 +131,9 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex if (!user_info_temp) { return NT_STATUS_NO_MEMORY; } - talloc_reference(user_info_temp, user_info_in); + if (!talloc_reference(user_info_temp, user_info_in)) { + return NT_STATUS_NO_MEMORY; + } *user_info_temp = *user_info_in; user_info_temp->mapped_state = to_state; @@ -193,7 +197,9 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex if (!user_info_temp) { return NT_STATUS_NO_MEMORY; } - talloc_reference(user_info_temp, user_info_in); + if (!talloc_reference(user_info_temp, user_info_in)) { + return NT_STATUS_NO_MEMORY; + } *user_info_temp = *user_info_in; user_info_temp->mapped_state = to_state; diff --git a/source4/auth/auth_wrap.c b/source4/auth/auth_wrap.c index 4a6b509fda..b366689f8d 100644 --- a/source4/auth/auth_wrap.c +++ b/source4/auth/auth_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2461,15 +2461,18 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_char swig_types[2] #define SWIGTYPE_p_int swig_types[3] #define SWIGTYPE_p_loadparm_context swig_types[4] -#define SWIGTYPE_p_long_long swig_types[5] -#define SWIGTYPE_p_short swig_types[6] -#define SWIGTYPE_p_signed_char swig_types[7] -#define SWIGTYPE_p_unsigned_char swig_types[8] -#define SWIGTYPE_p_unsigned_int swig_types[9] -#define SWIGTYPE_p_unsigned_long_long swig_types[10] -#define SWIGTYPE_p_unsigned_short swig_types[11] -static swig_type_info *swig_types[13]; -static swig_module_info swig_module = {swig_types, 12, 0, 0, 0, 0}; +#define SWIGTYPE_p_loadparm_service swig_types[5] +#define SWIGTYPE_p_long_long swig_types[6] +#define SWIGTYPE_p_param_context swig_types[7] +#define SWIGTYPE_p_param_section swig_types[8] +#define SWIGTYPE_p_short swig_types[9] +#define SWIGTYPE_p_signed_char swig_types[10] +#define SWIGTYPE_p_unsigned_char swig_types[11] +#define SWIGTYPE_p_unsigned_int swig_types[12] +#define SWIGTYPE_p_unsigned_long_long swig_types[13] +#define SWIGTYPE_p_unsigned_short swig_types[14] +static swig_type_info *swig_types[16]; +static swig_module_info swig_module = {swig_types, 15, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2480,6 +2483,19 @@ static swig_module_info swig_module = {swig_types, 12, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _auth.so @@ -2504,9 +2520,7 @@ static swig_module_info swig_module = {swig_types, 12, 0, 0, 0, 0}; #include "includes.h" #include "auth/session.h" #include "auth/system_session_proto.h" - - -#include <stdint.h> // Use the C99 official header +#include "param/param.h" #ifdef __cplusplus extern "C" { @@ -2524,14 +2538,19 @@ SWIGINTERN PyObject *_wrap_system_session(PyObject *SWIGUNUSEDPARM(self), PyObje }; { + arg2 = loadparm_init(NULL); + } + { arg1 = NULL; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:system_session",kwnames,&obj0)) SWIG_fail; - res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "system_session" "', argument " "2"" of type '" "struct loadparm_context *""'"); + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:system_session",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "system_session" "', argument " "2"" of type '" "struct loadparm_context *""'"); + } + arg2 = (struct loadparm_context *)(argp2); } - arg2 = (struct loadparm_context *)(argp2); result = (struct auth_session_info *)system_session(arg1,arg2); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_auth_session_info, 0 | 0 ); return resultobj; @@ -2553,14 +2572,19 @@ SWIGINTERN PyObject *_wrap_system_session_anon(PyObject *SWIGUNUSEDPARM(self), P }; { + arg2 = loadparm_init(NULL); + } + { arg1 = NULL; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:system_session_anon",kwnames,&obj0)) SWIG_fail; - res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "system_session_anon" "', argument " "2"" of type '" "struct loadparm_context *""'"); + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:system_session_anon",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "system_session_anon" "', argument " "2"" of type '" "struct loadparm_context *""'"); + } + arg2 = (struct loadparm_context *)(argp2); } - arg2 = (struct loadparm_context *)(argp2); result = (struct auth_session_info *)system_session_anon(arg1,arg2); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_auth_session_info, 0 | 0 ); return resultobj; @@ -2582,8 +2606,11 @@ static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0 static swig_type_info _swigt__p_auth_session_info = {"_p_auth_session_info", "struct auth_session_info *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; @@ -2597,7 +2624,10 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_char, &_swigt__p_int, &_swigt__p_loadparm_context, + &_swigt__p_loadparm_service, &_swigt__p_long_long, + &_swigt__p_param_context, + &_swigt__p_param_section, &_swigt__p_short, &_swigt__p_signed_char, &_swigt__p_unsigned_char, @@ -2611,7 +2641,10 @@ static swig_cast_info _swigc__p_auth_session_info[] = { {&_swigt__p_auth_sessio static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; @@ -2625,7 +2658,10 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_char, _swigc__p_int, _swigc__p_loadparm_context, + _swigc__p_loadparm_service, _swigc__p_long_long, + _swigc__p_param_context, + _swigc__p_param_section, _swigc__p_short, _swigc__p_signed_char, _swigc__p_unsigned_char, diff --git a/source4/auth/config.mk b/source4/auth/config.mk index 046ce026d0..3514059cf0 100644 --- a/source4/auth/config.mk +++ b/source4/auth/config.mk @@ -7,11 +7,13 @@ include credentials/config.mk [SUBSYSTEM::auth_session] OBJ_FILES = session.o PUBLIC_PROTO_HEADER = session_proto.h +PUBLIC_DEPENDENCIES = CREDENTIALS [SUBSYSTEM::auth_system_session] OBJ_FILES = system_session.o PUBLIC_PROTO_HEADER = system_session_proto.h -PRIVATE_DEPENDENCIES = auth_session +PUBLIC_DEPENDENCIES = CREDENTIALS +PRIVATE_DEPENDENCIES = auth_session LIBSAMBA-UTIL LIBSECURITY [SUBSYSTEM::auth_sam] PRIVATE_PROTO_HEADER = auth_sam.h diff --git a/source4/auth/credentials/config.mk b/source4/auth/credentials/config.mk index 7b091313c9..4c8308d01f 100644 --- a/source4/auth/credentials/config.mk +++ b/source4/auth/credentials/config.mk @@ -2,26 +2,16 @@ # Start SUBSYSTEM CREDENTIALS [SUBSYSTEM::CREDENTIALS] PUBLIC_PROTO_HEADER = credentials_proto.h -PUBLIC_HEADERS = credentials.h +PUBLIC_HEADERS = credentials.h credentials_krb5.h OBJ_FILES = credentials.o \ credentials_files.o \ - credentials_ntlm.o + credentials_ntlm.o \ + credentials_krb5.o \ + ../kerberos/kerberos_util.o PUBLIC_DEPENDENCIES = \ - LIBCLI_AUTH SECRETS LIBCRYPTO KERBEROS -PRIVATE_DEPENDENCIES = CREDENTIALS_KRB5 -# End SUBSYSTEM CREDENTIALS -################################# - -################################# -# Start SUBSYSTEM CREDENTIALS -[SUBSYSTEM::CREDENTIALS_KRB5] -PUBLIC_PROTO_HEADER = credentials_krb5_proto.h -PUBLIC_HEADERS = credentials_krb5.h -OBJ_FILES = credentials_krb5.o -PUBLIC_DEPENDENCIES = \ - HEIMDAL_GSSAPI -# End SUBSYSTEM CREDENTIALS -################################# + LIBCLI_AUTH SECRETS LIBCRYPTO KERBEROS UTIL_LDB HEIMDAL_GSSAPI +PRIVATE_DEPENDENCIES = \ + SECRETS [PYTHON::swig_credentials] PUBLIC_DEPENDENCIES = CREDENTIALS LIBPYTHON diff --git a/source4/auth/credentials/credentials.c b/source4/auth/credentials/credentials.c index f4530f4b3c..6d5c1210c9 100644 --- a/source4/auth/credentials/credentials.c +++ b/source4/auth/credentials/credentials.c @@ -82,7 +82,6 @@ struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx) struct cli_credentials *anon_credentials; anon_credentials = cli_credentials_init(mem_ctx); - cli_credentials_set_conf(anon_credentials, global_loadparm); cli_credentials_set_anonymous(anon_credentials); return anon_credentials; @@ -119,7 +118,8 @@ uint32_t cli_credentials_get_gensec_features(struct cli_credentials *creds) const char *cli_credentials_get_username(struct cli_credentials *cred) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } if (cred->username_obtained == CRED_CALLBACK && @@ -187,7 +187,8 @@ const char *cli_credentials_get_bind_dn(struct cli_credentials *cred) const char *cli_credentials_get_principal(struct cli_credentials *cred, TALLOC_CTX *mem_ctx) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } if (cred->principal_obtained == CRED_CALLBACK && @@ -277,7 +278,8 @@ bool cli_credentials_authentication_requested(struct cli_credentials *cred) const char *cli_credentials_get_password(struct cli_credentials *cred) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } if (cred->password_obtained == CRED_CALLBACK && @@ -332,7 +334,8 @@ bool cli_credentials_set_password_callback(struct cli_credentials *cred, const char *cli_credentials_get_old_password(struct cli_credentials *cred) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } return cred->old_password; @@ -401,7 +404,8 @@ bool cli_credentials_set_nt_hash(struct cli_credentials *cred, const char *cli_credentials_get_domain(struct cli_credentials *cred) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } if (cred->domain_obtained == CRED_CALLBACK && @@ -455,7 +459,8 @@ bool cli_credentials_set_domain_callback(struct cli_credentials *cred, const char *cli_credentials_get_realm(struct cli_credentials *cred) { if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } if (cred->realm_obtained == CRED_CALLBACK && @@ -670,7 +675,7 @@ void cli_credentials_guess(struct cli_credentials *cred, } if (cli_credentials_get_kerberos_state(cred) != CRED_DONT_USE_KERBEROS) { - cli_credentials_set_ccache(cred, NULL, CRED_GUESS_FILE); + cli_credentials_set_ccache(cred, lp_ctx, NULL, CRED_GUESS_FILE); } } @@ -720,6 +725,8 @@ void cli_credentials_set_anonymous(struct cli_credentials *cred) cli_credentials_set_username(cred, "", CRED_SPECIFIED); cli_credentials_set_domain(cred, "", CRED_SPECIFIED); cli_credentials_set_password(cred, NULL, CRED_SPECIFIED); + cli_credentials_set_realm(cred, NULL, CRED_SPECIFIED); + cli_credentials_set_workstation(cred, "", CRED_UNINITIALISED); } /** @@ -732,7 +739,8 @@ bool cli_credentials_is_anonymous(struct cli_credentials *cred) const char *username; if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, + cred->machine_account_pending_lp_ctx); } username = cli_credentials_get_username(cred); diff --git a/source4/auth/credentials/credentials.h b/source4/auth/credentials/credentials.h index 7ea37e40d1..a3da5c6054 100644 --- a/source4/auth/credentials/credentials.h +++ b/source4/auth/credentials/credentials.h @@ -104,8 +104,8 @@ struct cli_credentials { /* We are flagged to get machine account details from the * secrets.ldb when we are asked for a username or password */ - bool machine_account_pending; + struct loadparm_context *machine_account_pending_lp_ctx; /* Is this a machine account? */ bool machine_account; @@ -128,6 +128,7 @@ struct cli_credentials { struct ldb_context; struct loadparm_context; +#include "auth/credentials/credentials_krb5.h" #include "auth/credentials/credentials_proto.h" #endif /* __CREDENTIALS_H__ */ diff --git a/source4/auth/credentials/credentials.i b/source4/auth/credentials/credentials.i index 456ea75519..78660bc46c 100644 --- a/source4/auth/credentials/credentials.i +++ b/source4/auth/credentials/credentials.i @@ -26,11 +26,13 @@ #include "includes.h" #include "auth/credentials/credentials.h" +#include "param/param.h" typedef struct cli_credentials cli_credentials; %} -%include "carrays.i" -%include "typemaps.i" +%import "carrays.i" +%import "typemaps.i" +%import "param/param.i" %typemap(default) struct cli_credentials * { $1 = NULL; @@ -44,13 +46,13 @@ typedef struct cli_credentials cli_credentials; $result = PyString_FromStringAndSize($1->hash, 16); } +%talloctype(cli_credentials); %rename(Credentials) cli_credentials; typedef struct cli_credentials { %extend { cli_credentials() { return cli_credentials_init(NULL); } - ~cli_credentials() { talloc_free($self); } /* username */ const char *get_username(void); bool set_username(const char *value, @@ -83,7 +85,7 @@ typedef struct cli_credentials { bool set_workstation(const char *workstation, enum credentials_obtained obtained=CRED_SPECIFIED); - void guess(struct loadparm_context *lp_ctx = NULL); + void guess(struct loadparm_context *lp_ctx); bool is_anonymous(void); const struct samr_Password *get_nt_hash(TALLOC_CTX *mem_ctx); diff --git a/source4/auth/credentials/credentials.py b/source4/auth/credentials/credentials.py index eb44b0789a..0d91526b8f 100644 --- a/source4/auth/credentials/credentials.py +++ b/source4/auth/credentials/credentials.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _credentials import new @@ -48,36 +47,41 @@ except AttributeError: del types -class Credentials(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, Credentials, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, Credentials, name) +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +import param +class Credentials(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _credentials.new_Credentials(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _credentials.Credentials_swiginit(self,_credentials.new_Credentials(*args, **kwargs)) __swig_destroy__ = _credentials.delete_Credentials - __del__ = lambda self : None; - def get_username(*args, **kwargs): return _credentials.Credentials_get_username(*args, **kwargs) - def set_username(*args, **kwargs): return _credentials.Credentials_set_username(*args, **kwargs) - def get_password(*args, **kwargs): return _credentials.Credentials_get_password(*args, **kwargs) - def set_password(*args, **kwargs): return _credentials.Credentials_set_password(*args, **kwargs) - def get_domain(*args, **kwargs): return _credentials.Credentials_get_domain(*args, **kwargs) - def set_domain(*args, **kwargs): return _credentials.Credentials_set_domain(*args, **kwargs) - def get_realm(*args, **kwargs): return _credentials.Credentials_get_realm(*args, **kwargs) - def set_realm(*args, **kwargs): return _credentials.Credentials_set_realm(*args, **kwargs) - def parse_string(*args, **kwargs): return _credentials.Credentials_parse_string(*args, **kwargs) - def get_bind_dn(*args, **kwargs): return _credentials.Credentials_get_bind_dn(*args, **kwargs) - def set_bind_dn(*args, **kwargs): return _credentials.Credentials_set_bind_dn(*args, **kwargs) - def get_workstation(*args, **kwargs): return _credentials.Credentials_get_workstation(*args, **kwargs) - def set_workstation(*args, **kwargs): return _credentials.Credentials_set_workstation(*args, **kwargs) - def guess(*args, **kwargs): return _credentials.Credentials_guess(*args, **kwargs) - def is_anonymous(*args, **kwargs): return _credentials.Credentials_is_anonymous(*args, **kwargs) - def get_nt_hash(*args, **kwargs): return _credentials.Credentials_get_nt_hash(*args, **kwargs) - def authentication_requested(*args, **kwargs): return _credentials.Credentials_authentication_requested(*args, **kwargs) - def wrong_password(*args, **kwargs): return _credentials.Credentials_wrong_password(*args, **kwargs) +Credentials.get_username = new_instancemethod(_credentials.Credentials_get_username,None,Credentials) +Credentials.set_username = new_instancemethod(_credentials.Credentials_set_username,None,Credentials) +Credentials.get_password = new_instancemethod(_credentials.Credentials_get_password,None,Credentials) +Credentials.set_password = new_instancemethod(_credentials.Credentials_set_password,None,Credentials) +Credentials.get_domain = new_instancemethod(_credentials.Credentials_get_domain,None,Credentials) +Credentials.set_domain = new_instancemethod(_credentials.Credentials_set_domain,None,Credentials) +Credentials.get_realm = new_instancemethod(_credentials.Credentials_get_realm,None,Credentials) +Credentials.set_realm = new_instancemethod(_credentials.Credentials_set_realm,None,Credentials) +Credentials.parse_string = new_instancemethod(_credentials.Credentials_parse_string,None,Credentials) +Credentials.get_bind_dn = new_instancemethod(_credentials.Credentials_get_bind_dn,None,Credentials) +Credentials.set_bind_dn = new_instancemethod(_credentials.Credentials_set_bind_dn,None,Credentials) +Credentials.get_workstation = new_instancemethod(_credentials.Credentials_get_workstation,None,Credentials) +Credentials.set_workstation = new_instancemethod(_credentials.Credentials_set_workstation,None,Credentials) +Credentials.guess = new_instancemethod(_credentials.Credentials_guess,None,Credentials) +Credentials.is_anonymous = new_instancemethod(_credentials.Credentials_is_anonymous,None,Credentials) +Credentials.get_nt_hash = new_instancemethod(_credentials.Credentials_get_nt_hash,None,Credentials) +Credentials.authentication_requested = new_instancemethod(_credentials.Credentials_authentication_requested,None,Credentials) +Credentials.wrong_password = new_instancemethod(_credentials.Credentials_wrong_password,None,Credentials) Credentials_swigregister = _credentials.Credentials_swigregister Credentials_swigregister(Credentials) diff --git a/source4/auth/credentials/credentials_files.c b/source4/auth/credentials/credentials_files.c index e7435f56f8..c1001c9622 100644 --- a/source4/auth/credentials/credentials_files.c +++ b/source4/auth/credentials/credentials_files.c @@ -305,13 +305,13 @@ NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred, * (chewing CPU time) from the password */ keytab = ldb_msg_find_attr_as_string(msgs[0], "krb5Keytab", NULL); if (keytab) { - cli_credentials_set_keytab_name(cred, keytab, CRED_SPECIFIED); + cli_credentials_set_keytab_name(cred, lp_ctx, keytab, CRED_SPECIFIED); } else { keytab = ldb_msg_find_attr_as_string(msgs[0], "privateKeytab", NULL); if (keytab) { keytab = talloc_asprintf(mem_ctx, "FILE:%s", private_path(mem_ctx, lp_ctx, keytab)); if (keytab) { - cli_credentials_set_keytab_name(cred, keytab, CRED_SPECIFIED); + cli_credentials_set_keytab_name(cred, lp_ctx, keytab, CRED_SPECIFIED); } } } @@ -326,7 +326,8 @@ NTSTATUS cli_credentials_set_secrets(struct cli_credentials *cred, * @param cred Credentials structure to fill in * @retval NTSTATUS error detailing any failure */ -NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred) +NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred, + struct loadparm_context *lp_ctx) { char *filter; /* Bleh, nasty recursion issues: We are setting a machine @@ -335,7 +336,7 @@ NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred) cred->machine_account_pending = false; filter = talloc_asprintf(cred, SECRETS_PRIMARY_DOMAIN_FILTER, cli_credentials_get_domain(cred)); - return cli_credentials_set_secrets(cred, global_loadparm, NULL, + return cli_credentials_set_secrets(cred, lp_ctx, NULL, SECRETS_PRIMARY_DOMAIN_DN, filter); } @@ -369,6 +370,7 @@ NTSTATUS cli_credentials_set_krbtgt(struct cli_credentials *cred, * @retval NTSTATUS error detailing any failure */ NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, const char *serviceprincipal) { char *filter; @@ -380,7 +382,7 @@ NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred, cli_credentials_get_realm(cred), cli_credentials_get_domain(cred), serviceprincipal); - return cli_credentials_set_secrets(cred, global_loadparm, NULL, + return cli_credentials_set_secrets(cred, lp_ctx, NULL, SECRETS_PRINCIPALS_DN, filter); } @@ -393,9 +395,11 @@ NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred, * than during, popt processing. * */ -void cli_credentials_set_machine_account_pending(struct cli_credentials *cred) +void cli_credentials_set_machine_account_pending(struct cli_credentials *cred, + struct loadparm_context *lp_ctx) { cred->machine_account_pending = true; + cred->machine_account_pending_lp_ctx = lp_ctx; } diff --git a/source4/auth/credentials/credentials_krb5.c b/source4/auth/credentials/credentials_krb5.c index cfdc2e3f5a..90b196e99e 100644 --- a/source4/auth/credentials/credentials_krb5.c +++ b/source4/auth/credentials/credentials_krb5.c @@ -127,6 +127,7 @@ static int free_dccache(struct ccache_container *ccc) { } int cli_credentials_set_ccache(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, const char *name, enum credentials_obtained obtained) { @@ -142,7 +143,7 @@ int cli_credentials_set_ccache(struct cli_credentials *cred, return ENOMEM; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &ccc->smb_krb5_context); if (ret) { talloc_free(ccc); @@ -201,6 +202,7 @@ int cli_credentials_set_ccache(struct cli_credentials *cred, static int cli_credentials_new_ccache(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, struct ccache_container **_ccc) { krb5_error_code ret; @@ -218,7 +220,7 @@ static int cli_credentials_new_ccache(struct cli_credentials *cred, return ENOMEM; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &ccc->smb_krb5_context); if (ret) { talloc_free(ccc); @@ -250,12 +252,13 @@ static int cli_credentials_new_ccache(struct cli_credentials *cred, } int cli_credentials_get_ccache(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, struct ccache_container **ccc) { krb5_error_code ret; if (cred->machine_account_pending) { - cli_credentials_set_machine_account(cred); + cli_credentials_set_machine_account(cred, lp_ctx); } if (cred->ccache_obtained >= cred->ccache_threshold && @@ -267,7 +270,7 @@ int cli_credentials_get_ccache(struct cli_credentials *cred, return EINVAL; } - ret = cli_credentials_new_ccache(cred, ccc); + ret = cli_credentials_new_ccache(cred, lp_ctx, ccc); if (ret) { return ret; } @@ -344,6 +347,7 @@ static int free_gssapi_creds(struct gssapi_creds_container *gcc) } int cli_credentials_get_client_gss_creds(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, struct gssapi_creds_container **_gcc) { int ret = 0; @@ -355,7 +359,7 @@ int cli_credentials_get_client_gss_creds(struct cli_credentials *cred, *_gcc = cred->client_gss_creds; return 0; } - ret = cli_credentials_get_ccache(cred, + ret = cli_credentials_get_ccache(cred, lp_ctx, &ccache); if (ret) { DEBUG(1, ("Failed to get CCACHE for GSSAPI client: %s\n", error_message(ret))); @@ -397,6 +401,7 @@ int cli_credentials_get_client_gss_creds(struct cli_credentials *cred, */ int cli_credentials_set_client_gss_creds(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, gss_cred_id_t gssapi_cred, enum credentials_obtained obtained) { @@ -413,7 +418,7 @@ int cli_credentials_set_client_gss_creds(struct cli_credentials *cred, return ENOMEM; } - ret = cli_credentials_new_ccache(cred, &ccc); + ret = cli_credentials_new_ccache(cred, lp_ctx, &ccc); if (ret != 0) { return ret; } @@ -450,6 +455,7 @@ int cli_credentials_set_client_gss_creds(struct cli_credentials *cred, * it will be generated from the password. */ int cli_credentials_get_keytab(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, struct keytab_container **_ktc) { krb5_error_code ret; @@ -468,7 +474,7 @@ int cli_credentials_get_keytab(struct cli_credentials *cred, return EINVAL; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &smb_krb5_context); if (ret) { return ret; @@ -503,6 +509,7 @@ int cli_credentials_get_keytab(struct cli_credentials *cred, * FILE:/etc/krb5.keytab), open it and attach it */ int cli_credentials_set_keytab_name(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, const char *keytab_name, enum credentials_obtained obtained) { @@ -515,7 +522,7 @@ int cli_credentials_set_keytab_name(struct cli_credentials *cred, return 0; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, &smb_krb5_context); + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &smb_krb5_context); if (ret) { return ret; } @@ -540,7 +547,8 @@ int cli_credentials_set_keytab_name(struct cli_credentials *cred, return ret; } -int cli_credentials_update_keytab(struct cli_credentials *cred) +int cli_credentials_update_keytab(struct cli_credentials *cred, + struct loadparm_context *lp_ctx) { krb5_error_code ret; struct keytab_container *ktc; @@ -553,7 +561,7 @@ int cli_credentials_update_keytab(struct cli_credentials *cred) return ENOMEM; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, &smb_krb5_context); + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &smb_krb5_context); if (ret) { talloc_free(mem_ctx); return ret; @@ -561,7 +569,7 @@ int cli_credentials_update_keytab(struct cli_credentials *cred) enctype_strings = cli_credentials_get_enctype_strings(cred); - ret = cli_credentials_get_keytab(cred, &ktc); + ret = cli_credentials_get_keytab(cred, lp_ctx, &ktc); if (ret != 0) { talloc_free(mem_ctx); return ret; @@ -576,6 +584,7 @@ int cli_credentials_update_keytab(struct cli_credentials *cred) /* Get server gss credentials (in gsskrb5, this means the keytab) */ int cli_credentials_get_server_gss_creds(struct cli_credentials *cred, + struct loadparm_context *lp_ctx, struct gssapi_creds_container **_gcc) { int ret = 0; @@ -593,13 +602,12 @@ int cli_credentials_get_server_gss_creds(struct cli_credentials *cred, return 0; } - ret = cli_credentials_get_krb5_context(cred, global_loadparm, &smb_krb5_context); + ret = cli_credentials_get_krb5_context(cred, lp_ctx, &smb_krb5_context); if (ret) { return ret; } - ret = cli_credentials_get_keytab(cred, - &ktc); + ret = cli_credentials_get_keytab(cred, lp_ctx, &ktc); if (ret) { DEBUG(1, ("Failed to get keytab for GSSAPI server: %s\n", error_message(ret))); return ret; diff --git a/source4/auth/credentials/credentials_krb5.h b/source4/auth/credentials/credentials_krb5.h index 1026508601..b963fbdca4 100644 --- a/source4/auth/credentials/credentials_krb5.h +++ b/source4/auth/credentials/credentials_krb5.h @@ -20,7 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef __CREDENTIALS_KRB5_H__ +#define __CREDENTIALS_KRB5_H__ + #include <gssapi/gssapi.h> +#include <krb5.h> struct ccache_container; @@ -28,4 +32,4 @@ struct gssapi_creds_container { gss_cred_id_t creds; }; -#include "auth/credentials/credentials_krb5_proto.h" +#endif /* __CREDENTIALS_KRB5_H__ */ diff --git a/source4/auth/credentials/credentials_wrap.c b/source4/auth/credentials/credentials_wrap.c index 9887061a7e..f8bd32af03 100644 --- a/source4/auth/credentials/credentials_wrap.c +++ b/source4/auth/credentials/credentials_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2459,9 +2459,20 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_TALLOC_CTX swig_types[0] #define SWIGTYPE_p_char swig_types[1] #define SWIGTYPE_p_cli_credentials swig_types[2] -#define SWIGTYPE_p_loadparm_context swig_types[3] -static swig_type_info *swig_types[5]; -static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; +#define SWIGTYPE_p_int swig_types[3] +#define SWIGTYPE_p_loadparm_context swig_types[4] +#define SWIGTYPE_p_loadparm_service swig_types[5] +#define SWIGTYPE_p_long_long swig_types[6] +#define SWIGTYPE_p_param_context swig_types[7] +#define SWIGTYPE_p_param_section swig_types[8] +#define SWIGTYPE_p_short swig_types[9] +#define SWIGTYPE_p_signed_char swig_types[10] +#define SWIGTYPE_p_unsigned_char swig_types[11] +#define SWIGTYPE_p_unsigned_int swig_types[12] +#define SWIGTYPE_p_unsigned_long_long swig_types[13] +#define SWIGTYPE_p_unsigned_short swig_types[14] +static swig_type_info *swig_types[16]; +static swig_module_info swig_module = {swig_types, 15, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2472,6 +2483,19 @@ static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _credentials.so @@ -2495,6 +2519,7 @@ static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; #include "includes.h" #include "auth/credentials/credentials.h" +#include "param/param.h" typedef struct cli_credentials cli_credentials; @@ -2503,7 +2528,6 @@ typedef struct cli_credentials cli_credentials; SWIGINTERN cli_credentials *new_cli_credentials(){ return cli_credentials_init(NULL); } -SWIGINTERN void delete_cli_credentials(cli_credentials *self){ talloc_free(self); } SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) @@ -2748,6 +2772,7 @@ SWIGINTERNINLINE PyObject* return PyBool_FromLong(value ? 1 : 0); } +SWIGINTERN void delete_cli_credentials(cli_credentials *self){ talloc_free(self); } #ifdef __cplusplus extern "C" { #endif @@ -2755,7 +2780,7 @@ SWIGINTERN PyObject *_wrap_new_Credentials(PyObject *SWIGUNUSEDPARM(self), PyObj PyObject *resultobj = 0; cli_credentials *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)":new_Credentials")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"new_Credentials",0,0,0)) SWIG_fail; result = (cli_credentials *)new_cli_credentials(); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_cli_credentials, SWIG_POINTER_NEW | 0 ); return resultobj; @@ -2764,36 +2789,6 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_Credentials(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - cli_credentials *arg1 = (cli_credentials *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char * kwnames[] = { - (char *) "self", NULL - }; - - { - arg1 = NULL; - } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:delete_Credentials",kwnames,&obj0)) SWIG_fail; - if (obj0) { - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_cli_credentials, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Credentials" "', argument " "1"" of type '" "cli_credentials *""'"); - } - arg1 = (cli_credentials *)(argp1); - } - delete_cli_credentials(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_Credentials_get_username(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; cli_credentials *arg1 = (cli_credentials *) 0 ; @@ -3350,7 +3345,7 @@ fail: SWIGINTERN PyObject *_wrap_Credentials_guess(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; cli_credentials *arg1 = (cli_credentials *) 0 ; - struct loadparm_context *arg2 = (struct loadparm_context *) NULL ; + struct loadparm_context *arg2 = (struct loadparm_context *) 0 ; void *argp1 = 0 ; int res1 = 0 ; void *argp2 = 0 ; @@ -3364,6 +3359,9 @@ SWIGINTERN PyObject *_wrap_Credentials_guess(PyObject *SWIGUNUSEDPARM(self), PyO { arg1 = NULL; } + { + arg2 = loadparm_init(NULL); + } if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:Credentials_guess",kwnames,&obj0,&obj1)) SWIG_fail; if (obj0) { res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_cli_credentials, 0 | 0 ); @@ -3424,18 +3422,18 @@ SWIGINTERN PyObject *_wrap_Credentials_get_nt_hash(PyObject *SWIGUNUSEDPARM(self struct samr_Password *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "mem_ctx", NULL + (char *) "self", NULL }; { arg1 = NULL; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:Credentials_get_nt_hash",kwnames,&obj0,&obj1)) SWIG_fail; + { + arg2 = NULL; + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:Credentials_get_nt_hash",kwnames,&obj0)) SWIG_fail; if (obj0) { res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_cli_credentials, 0 | 0 ); if (!SWIG_IsOK(res1)) { @@ -3443,13 +3441,6 @@ SWIGINTERN PyObject *_wrap_Credentials_get_nt_hash(PyObject *SWIGUNUSEDPARM(self } arg1 = (cli_credentials *)(argp1); } - if (obj1) { - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_TALLOC_CTX, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Credentials_get_nt_hash" "', argument " "2"" of type '" "TALLOC_CTX *""'"); - } - arg2 = (TALLOC_CTX *)(argp2); - } result = (struct samr_Password *)cli_credentials_get_nt_hash(arg1,arg2); { resultobj = PyString_FromStringAndSize(result->hash, 16); @@ -3520,16 +3511,49 @@ fail: } +SWIGINTERN PyObject *_wrap_delete_Credentials(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + cli_credentials *arg1 = (cli_credentials *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "self", NULL + }; + + { + arg1 = NULL; + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:delete_Credentials",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_cli_credentials, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Credentials" "', argument " "1"" of type '" "cli_credentials *""'"); + } + arg1 = (cli_credentials *)(argp1); + } + delete_cli_credentials(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *Credentials_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_cli_credentials, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Credentials_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + static PyMethodDef SwigMethods[] = { - { (char *)"new_Credentials", _wrap_new_Credentials, METH_VARARGS, NULL}, - { (char *)"delete_Credentials", (PyCFunction) _wrap_delete_Credentials, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"new_Credentials", (PyCFunction)_wrap_new_Credentials, METH_NOARGS, NULL}, { (char *)"Credentials_get_username", (PyCFunction) _wrap_Credentials_get_username, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_set_username", (PyCFunction) _wrap_Credentials_set_username, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_get_password", (PyCFunction) _wrap_Credentials_get_password, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -3548,7 +3572,9 @@ static PyMethodDef SwigMethods[] = { { (char *)"Credentials_get_nt_hash", (PyCFunction) _wrap_Credentials_get_nt_hash, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_authentication_requested", (PyCFunction) _wrap_Credentials_authentication_requested, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_wrong_password", (PyCFunction) _wrap_Credentials_wrong_password, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_Credentials", (PyCFunction) _wrap_delete_Credentials, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_swigregister", Credentials_swigregister, METH_VARARGS, NULL}, + { (char *)"Credentials_swiginit", Credentials_swiginit, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; @@ -3558,25 +3584,69 @@ static PyMethodDef SwigMethods[] = { static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_cli_credentials = {"_p_cli_credentials", "struct cli_credentials *|cli_credentials *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "uintptr_t *|uint_least32_t *|uint_fast32_t *|uint32_t *|unsigned int *|uint_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_long_long = {"_p_unsigned_long_long", "uint_least64_t *|uint_fast64_t *|uint64_t *|unsigned long long *|uintmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|uint_least16_t *|uint16_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_TALLOC_CTX, &_swigt__p_char, &_swigt__p_cli_credentials, + &_swigt__p_int, &_swigt__p_loadparm_context, + &_swigt__p_loadparm_service, + &_swigt__p_long_long, + &_swigt__p_param_context, + &_swigt__p_param_section, + &_swigt__p_short, + &_swigt__p_signed_char, + &_swigt__p_unsigned_char, + &_swigt__p_unsigned_int, + &_swigt__p_unsigned_long_long, + &_swigt__p_unsigned_short, }; static swig_cast_info _swigc__p_TALLOC_CTX[] = { {&_swigt__p_TALLOC_CTX, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_cli_credentials[] = { {&_swigt__p_cli_credentials, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_long_long[] = { {&_swigt__p_unsigned_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_TALLOC_CTX, _swigc__p_char, _swigc__p_cli_credentials, + _swigc__p_int, _swigc__p_loadparm_context, + _swigc__p_loadparm_service, + _swigc__p_long_long, + _swigc__p_param_context, + _swigc__p_param_section, + _swigc__p_short, + _swigc__p_signed_char, + _swigc__p_unsigned_char, + _swigc__p_unsigned_int, + _swigc__p_unsigned_long_long, + _swigc__p_unsigned_short, }; diff --git a/source4/auth/gensec/config.mk b/source4/auth/gensec/config.mk index 8ee942c63a..fea157c40b 100644 --- a/source4/auth/gensec/config.mk +++ b/source4/auth/gensec/config.mk @@ -6,9 +6,9 @@ SO_VERSION = 0 DESCRIPTION = Generic Security Library PUBLIC_HEADERS = gensec.h spnego.h PUBLIC_PROTO_HEADER = gensec_proto.h -OBJ_FILES = gensec.o +OBJ_FILES = gensec.o socket.o PUBLIC_DEPENDENCIES = \ - CREDENTIALS LIBSAMBA-UTIL LIBCRYPTO ASN1_UTIL + CREDENTIALS LIBSAMBA-UTIL LIBCRYPTO ASN1_UTIL samba-socket LIBPACKET # End SUBSYSTEM gensec ################################# @@ -18,7 +18,7 @@ PUBLIC_DEPENDENCIES = \ SUBSYSTEM = gensec INIT_FUNCTION = gensec_krb5_init OBJ_FILES = gensec_krb5.o -PRIVATE_DEPENDENCIES = CREDENTIALS_KRB5 KERBEROS auth auth_sam +PRIVATE_DEPENDENCIES = CREDENTIALS KERBEROS auth auth_sam # End MODULE gensec_krb5 ################################################ @@ -28,7 +28,7 @@ PRIVATE_DEPENDENCIES = CREDENTIALS_KRB5 KERBEROS auth auth_sam SUBSYSTEM = gensec INIT_FUNCTION = gensec_gssapi_init OBJ_FILES = gensec_gssapi.o -PRIVATE_DEPENDENCIES = HEIMDAL_GSSAPI CREDENTIALS_KRB5 KERBEROS +PRIVATE_DEPENDENCIES = HEIMDAL_GSSAPI CREDENTIALS KERBEROS # End MODULE gensec_gssapi ################################################ @@ -48,7 +48,7 @@ PRIVATE_DEPENDENCIES = CREDENTIALS SASL SUBSYSTEM = gensec INIT_FUNCTION = gensec_spnego_init PRIVATE_PROTO_HEADER = spnego_proto.h -PRIVATE_DEPENDENCIES = ASN1_UTIL GENSEC_SOCKET CREDENTIALS +PRIVATE_DEPENDENCIES = ASN1_UTIL CREDENTIALS OBJ_FILES = spnego.o spnego_parse.o # End MODULE gensec_spnego ################################################ @@ -61,7 +61,7 @@ PRIVATE_PROTO_HEADER = schannel_proto.h INIT_FUNCTION = gensec_schannel_init OBJ_FILES = schannel.o \ schannel_sign.o -PRIVATE_DEPENDENCIES = SCHANNELDB NDR_SCHANNEL CREDENTIALS +PRIVATE_DEPENDENCIES = SCHANNELDB NDR_SCHANNEL CREDENTIALS LIBNDR OUTPUT_TYPE = INTEGRATED # End MODULE gensec_schannel ################################################ @@ -72,19 +72,8 @@ OUTPUT_TYPE = INTEGRATED PRIVATE_PROTO_HEADER = schannel_state.h OBJ_FILES = \ schannel_state.o -PRIVATE_DEPENDENCIES = LDB_WRAP +PRIVATE_DEPENDENCIES = LDB_WRAP SAMDB # # End SUBSYSTEM SCHANNELDB ################################################ -################################################ -# Start SUBSYSTEM GENSEC_SOCKET -[SUBSYSTEM::GENSEC_SOCKET] -OBJ_FILES = \ - socket.o -PUBLIC_DEPENDENCIES = samba-socket LIBPACKET -#PUBLIC_DEPENDENCIES = gensec -# -# End SUBSYSTEM GENSEC_SOCKET -################################################ - diff --git a/source4/auth/gensec/cyrus_sasl.c b/source4/auth/gensec/cyrus_sasl.c index 0bce35e1c5..64a0b2f0c7 100644 --- a/source4/auth/gensec/cyrus_sasl.c +++ b/source4/auth/gensec/cyrus_sasl.c @@ -101,7 +101,7 @@ static int gensec_sasl_get_password(sasl_conn_t *conn, void *context, int id, return SASL_NOMEM; } secret->len = strlen(password); - safe_strcpy(secret->data, password, secret->len+1); + safe_strcpy((char*)secret->data, password, secret->len+1); *psecret = secret; return SASL_OK; } @@ -213,8 +213,9 @@ static NTSTATUS gensec_sasl_update(struct gensec_security *gensec_security, sasl_ret = sasl_client_start(gensec_sasl_state->conn, gensec_security->ops->sasl_name, NULL, &out_data, &out_len, &mech); } else { - sasl_ret = sasl_client_step(gensec_sasl_state->conn, - in.data, in.length, NULL, &out_data, &out_len); + sasl_ret = sasl_client_step(gensec_sasl_state->conn, + (char*)in.data, in.length, NULL, + &out_data, &out_len); } if (sasl_ret == SASL_OK || sasl_ret == SASL_CONTINUE) { *out = data_blob_talloc(out_mem_ctx, out_data, out_len); @@ -237,8 +238,9 @@ static NTSTATUS gensec_sasl_unwrap_packets(struct gensec_security *gensec_securi const char *out_data; unsigned int out_len; - int sasl_ret = sasl_decode(gensec_sasl_state->conn, - in->data, in->length, &out_data, &out_len); + int sasl_ret = sasl_decode(gensec_sasl_state->conn, + (char*)in->data, in->length, &out_data, + &out_len); if (sasl_ret == SASL_OK) { *out = data_blob_talloc(out_mem_ctx, out_data, out_len); *len_processed = in->length; @@ -260,8 +262,9 @@ static NTSTATUS gensec_sasl_wrap_packets(struct gensec_security *gensec_security const char *out_data; unsigned int out_len; - int sasl_ret = sasl_encode(gensec_sasl_state->conn, - in->data, in->length, &out_data, &out_len); + int sasl_ret = sasl_encode(gensec_sasl_state->conn, + (char*)in->data, in->length, &out_data, + &out_len); if (sasl_ret == SASL_OK) { *out = data_blob_talloc(out_mem_ctx, out_data, out_len); *len_processed = in->length; @@ -278,7 +281,8 @@ static bool gensec_sasl_have_feature(struct gensec_security *gensec_security, struct gensec_sasl_state *gensec_sasl_state = talloc_get_type(gensec_security->private_data, struct gensec_sasl_state); sasl_ssf_t ssf; - int sasl_ret = sasl_getprop(gensec_sasl_state->conn, SASL_SSF, &ssf); + int sasl_ret = sasl_getprop(gensec_sasl_state->conn, SASL_SSF, + (const void**)&ssf); if (sasl_ret != SASL_OK) { return false; } diff --git a/source4/auth/gensec/gensec.h b/source4/auth/gensec/gensec.h index dbedcf091a..3413e5c8ce 100644 --- a/source4/auth/gensec/gensec.h +++ b/source4/auth/gensec/gensec.h @@ -166,6 +166,37 @@ struct gensec_critical_sizes { int sizeof_gensec_security; }; +/* Socket wrapper */ + +struct gensec_security; +struct socket_context; + +NTSTATUS gensec_socket_init(struct gensec_security *gensec_security, + struct socket_context *current_socket, + struct event_context *ev, + void (*recv_handler)(void *, uint16_t), + void *recv_private, + struct socket_context **new_socket); +/* These functions are for use here only (public because SPNEGO must + * use them for recursion) */ +NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security, + TALLOC_CTX *mem_ctx, + const DATA_BLOB *in, + DATA_BLOB *out, + size_t *len_processed); +/* These functions are for use here only (public because SPNEGO must + * use them for recursion) */ +NTSTATUS gensec_unwrap_packets(struct gensec_security *gensec_security, + TALLOC_CTX *mem_ctx, + const DATA_BLOB *in, + DATA_BLOB *out, + size_t *len_processed); + +/* These functions are for use here only (public because SPNEGO must + * use them for recursion) */ +NTSTATUS gensec_packet_full_request(struct gensec_security *gensec_security, + DATA_BLOB blob, size_t *size); + struct loadparm_context; #include "auth/gensec/gensec_proto.h" diff --git a/source4/auth/gensec/gensec_gssapi.c b/source4/auth/gensec/gensec_gssapi.c index a0b42db141..87fa47646b 100644 --- a/source4/auth/gensec/gensec_gssapi.c +++ b/source4/auth/gensec/gensec_gssapi.c @@ -54,7 +54,7 @@ struct gensec_gssapi_state { gss_name_t server_name; gss_name_t client_name; OM_uint32 want_flags, got_flags; - const gss_OID_desc *gss_oid; + gss_OID gss_oid; DATA_BLOB session_key; DATA_BLOB pac; @@ -82,7 +82,7 @@ static size_t gensec_gssapi_max_wrapped_size(struct gensec_security *gensec_secu static char *gssapi_error_string(TALLOC_CTX *mem_ctx, OM_uint32 maj_stat, OM_uint32 min_stat, - const gss_OID_desc *mech) + const gss_OID mech) { OM_uint32 disp_min_stat, disp_maj_stat; gss_buffer_desc maj_error_message; @@ -271,7 +271,7 @@ static NTSTATUS gensec_gssapi_server_start(struct gensec_security *gensec_securi DEBUG(3, ("No machine account credentials specified\n")); return NT_STATUS_CANT_ACCESS_DOMAIN_INFO; } else { - ret = cli_credentials_get_server_gss_creds(machine_account, &gcc); + ret = cli_credentials_get_server_gss_creds(machine_account, gensec_security->lp_ctx, &gcc); if (ret) { DEBUG(1, ("Aquiring acceptor credentials failed: %s\n", error_message(ret))); @@ -357,7 +357,7 @@ static NTSTATUS gensec_gssapi_client_start(struct gensec_security *gensec_securi return NT_STATUS_INVALID_PARAMETER; } - ret = cli_credentials_get_client_gss_creds(creds, &gcc); + ret = cli_credentials_get_client_gss_creds(creds, gensec_security->lp_ctx, &gcc); switch (ret) { case 0: break; @@ -448,7 +448,7 @@ static NTSTATUS gensec_gssapi_update(struct gensec_security *gensec_security, gensec_gssapi_state->client_cred->creds, &gensec_gssapi_state->gssapi_context, gensec_gssapi_state->server_name, - discard_const_p(gss_OID_desc, gensec_gssapi_state->gss_oid), + gensec_gssapi_state->gss_oid, gensec_gssapi_state->want_flags, 0, gensec_gssapi_state->input_chan_bindings, @@ -1365,6 +1365,7 @@ static NTSTATUS gensec_gssapi_session_info(struct gensec_security *gensec_securi cli_credentials_set_anonymous(session_info->credentials); ret = cli_credentials_set_client_gss_creds(session_info->credentials, + gensec_security->lp_ctx, gensec_gssapi_state->delegated_cred_handle, CRED_SPECIFIED); if (ret) { diff --git a/source4/auth/gensec/gensec_krb5.c b/source4/auth/gensec/gensec_krb5.c index 282be5a001..5cd0de1ceb 100644 --- a/source4/auth/gensec/gensec_krb5.c +++ b/source4/auth/gensec/gensec_krb5.c @@ -246,7 +246,7 @@ static NTSTATUS gensec_krb5_client_start(struct gensec_security *gensec_security principal = gensec_get_target_principal(gensec_security); - ret = cli_credentials_get_ccache(gensec_get_credentials(gensec_security), &ccache_container); + ret = cli_credentials_get_ccache(gensec_get_credentials(gensec_security), gensec_security->lp_ctx, &ccache_container); switch (ret) { case 0: break; @@ -444,7 +444,7 @@ static NTSTATUS gensec_krb5_update(struct gensec_security *gensec_security, } /* Grab the keytab, however generated */ - ret = cli_credentials_get_keytab(gensec_get_credentials(gensec_security), &keytab); + ret = cli_credentials_get_keytab(gensec_get_credentials(gensec_security), gensec_security->lp_ctx, &keytab); if (ret) { return NT_STATUS_CANT_ACCESS_DOMAIN_INFO; } @@ -779,7 +779,7 @@ NTSTATUS gensec_krb5_init(void) { NTSTATUS ret; - auth_init(global_loadparm); + auth_init(); ret = gensec_register(&gensec_krb5_security_ops); if (!NT_STATUS_IS_OK(ret)) { diff --git a/source4/auth/gensec/socket.h b/source4/auth/gensec/socket.h deleted file mode 100644 index 83100c65da..0000000000 --- a/source4/auth/gensec/socket.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Generic Authentication Interface (socket wrapper) - - Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -struct gensec_security; -struct socket_context; - -NTSTATUS gensec_socket_init(struct gensec_security *gensec_security, - struct socket_context *current_socket, - struct event_context *ev, - void (*recv_handler)(void *, uint16_t), - void *recv_private, - struct socket_context **new_socket); -/* These functions are for use here only (public because SPNEGO must - * use them for recursion) */ -NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security, - TALLOC_CTX *mem_ctx, - const DATA_BLOB *in, - DATA_BLOB *out, - size_t *len_processed); -/* These functions are for use here only (public because SPNEGO must - * use them for recursion) */ -NTSTATUS gensec_unwrap_packets(struct gensec_security *gensec_security, - TALLOC_CTX *mem_ctx, - const DATA_BLOB *in, - DATA_BLOB *out, - size_t *len_processed); - -/* These functions are for use here only (public because SPNEGO must - * use them for recursion) */ -NTSTATUS gensec_packet_full_request(struct gensec_security *gensec_security, - DATA_BLOB blob, size_t *size); - diff --git a/source4/auth/gensec/spnego.c b/source4/auth/gensec/spnego.c index 15dabb8033..782aa44c75 100644 --- a/source4/auth/gensec/spnego.c +++ b/source4/auth/gensec/spnego.c @@ -26,7 +26,6 @@ #include "librpc/gen_ndr/ndr_dcerpc.h" #include "auth/credentials/credentials.h" #include "auth/gensec/gensec.h" -#include "auth/gensec/socket.h" enum spnego_state_position { SPNEGO_SERVER_START, diff --git a/source4/auth/kerberos/config.mk b/source4/auth/kerberos/config.mk index 1c70ef2e63..7493a6d06d 100644 --- a/source4/auth/kerberos/config.mk +++ b/source4/auth/kerberos/config.mk @@ -5,11 +5,10 @@ PRIVATE_PROTO_HEADER = proto.h OBJ_FILES = kerberos.o \ clikrb5.o \ kerberos_heimdal.o \ - kerberos_util.o \ kerberos_pac.o \ gssapi_parse.o \ krb5_init_context.o PUBLIC_DEPENDENCIES = HEIMDAL_KRB5 NDR_KRB5PAC samba-socket LIBCLI_RESOLVE -PRIVATE_DEPENDENCIES = ASN1_UTIL auth_sam_reply CREDENTIALS_KRB5 +PRIVATE_DEPENDENCIES = ASN1_UTIL auth_sam_reply LIBPACKET LIBNDR # End SUBSYSTEM KERBEROS ################################# diff --git a/source4/auth/kerberos/krb5_init_context.c b/source4/auth/kerberos/krb5_init_context.c index e3479b12d1..a455fda398 100644 --- a/source4/auth/kerberos/krb5_init_context.c +++ b/source4/auth/kerberos/krb5_init_context.c @@ -30,6 +30,7 @@ #include "lib/events/events.h" #include "roken.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" /* context structure for operations on cldap packets @@ -277,7 +278,7 @@ krb5_error_code smb_krb5_send_and_recv_func(krb5_context context, } status = socket_connect_ev(smb_krb5->sock, NULL, remote_addr, 0, - lp_name_resolve_order(global_loadparm), ev); + NULL, ev); if (!NT_STATUS_IS_OK(status)) { talloc_free(smb_krb5); continue; @@ -402,7 +403,7 @@ krb5_error_code smb_krb5_init_context(void *parent_ctx, } /* Use our local krb5.conf file by default */ - ret = krb5_prepend_config_files_default(config_file, &config_files); + ret = krb5_prepend_config_files_default(config_file == NULL?"":config_file, &config_files); if (ret) { DEBUG(1,("krb5_prepend_config_files_default failed (%s)\n", smb_get_krb5_error_message((*smb_krb5_context)->krb5_context, ret, tmp_ctx))); diff --git a/source4/auth/ntlm_check.c b/source4/auth/ntlm_check.c index a0846f00de..55f2595f44 100644 --- a/source4/auth/ntlm_check.c +++ b/source4/auth/ntlm_check.c @@ -320,7 +320,7 @@ NTSTATUS ntlm_password_check(TALLOC_CTX *mem_ctx, mdfour(client_nt.hash, nt_response->data, nt_response->length); if (lm_response->length && - (convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, + (convert_string_talloc(mem_ctx, lp_iconv_convenience(lp_ctx), CH_DOS, CH_UNIX, lm_response->data, lm_response->length, (void **)&unix_pw) != -1)) { if (E_deshash(unix_pw, client_lm.hash)) { diff --git a/source4/auth/ntlmssp/config.mk b/source4/auth/ntlmssp/config.mk index cb51dc9fa1..544850264a 100644 --- a/source4/auth/ntlmssp/config.mk +++ b/source4/auth/ntlmssp/config.mk @@ -12,7 +12,7 @@ OBJ_FILES = ntlmssp.o \ ntlmssp_sign.o \ ntlmssp_client.o \ ntlmssp_server.o -PRIVATE_DEPENDENCIES = MSRPC_PARSE +PRIVATE_DEPENDENCIES = MSRPC_PARSE CREDENTIALS OUTPUT_TYPE = INTEGRATED # End MODULE gensec_ntlmssp ################################################ diff --git a/source4/auth/ntlmssp/ntlmssp.c b/source4/auth/ntlmssp/ntlmssp.c index e30d1986ee..efb1e63047 100644 --- a/source4/auth/ntlmssp/ntlmssp.c +++ b/source4/auth/ntlmssp/ntlmssp.c @@ -428,7 +428,7 @@ NTSTATUS gensec_ntlmssp_init(void) { NTSTATUS ret; - auth_init(global_loadparm); + auth_init(); ret = gensec_register(&gensec_ntlmssp_security_ops); if (!NT_STATUS_IS_OK(ret)) { diff --git a/source4/auth/ntlmssp/ntlmssp_parse.c b/source4/auth/ntlmssp/ntlmssp_parse.c index ea80737c80..bb2d7a14a8 100644 --- a/source4/auth/ntlmssp/ntlmssp_parse.c +++ b/source4/auth/ntlmssp/ntlmssp_parse.c @@ -21,6 +21,7 @@ #include "includes.h" #include "pstring.h" +#include "param/param.h" /* this is a tiny msrpc packet generator. I am only using this to @@ -64,7 +65,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, case 'U': s = va_arg(ap, char *); head_size += 8; - n = push_ucs2_talloc(pointers, global_smb_iconv_convenience, (void **)&pointers[i].data, s); + n = push_ucs2_talloc(pointers, lp_iconv_convenience(global_loadparm), (void **)&pointers[i].data, s); if (n == -1) { return false; } @@ -75,7 +76,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, case 'A': s = va_arg(ap, char *); head_size += 8; - n = push_ascii_talloc(pointers, global_smb_iconv_convenience, (char **)&pointers[i].data, s); + n = push_ascii_talloc(pointers, lp_iconv_convenience(global_loadparm), (char **)&pointers[i].data, s); if (n == -1) { return false; } @@ -87,7 +88,7 @@ bool msrpc_gen(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, n = va_arg(ap, int); intargs[i] = n; s = va_arg(ap, char *); - n = push_ucs2_talloc(pointers, global_smb_iconv_convenience, (void **)&pointers[i].data, s); + n = push_ucs2_talloc(pointers, lp_iconv_convenience(global_loadparm), (void **)&pointers[i].data, s); if (n == -1) { return false; } @@ -209,7 +210,9 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, uint16_t len1, len2; uint32_t ptr; uint32_t *v; - pstring p; + size_t p_len = 1024; + char *p = talloc_array(mem_ctx, char, p_len); + bool ret = true; va_start(ap, format); for (i=0; format[i]; i++) { @@ -226,21 +229,27 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, } else { /* make sure its in the right format - be strict */ if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) { - return false; + ret = false; + goto cleanup; } if (len1 & 1) { /* if odd length and unicode */ - return false; + ret = false; + goto cleanup; + } + if (blob->data + ptr < (uint8_t *)ptr || + blob->data + ptr < blob->data) { + ret = false; + goto cleanup; } - if (blob->data + ptr < (uint8_t *)ptr || blob->data + ptr < blob->data) - return false; if (0 < len1) { - pull_string(global_smb_iconv_convenience, p, blob->data + ptr, sizeof(p), + pull_string(lp_iconv_convenience(global_loadparm), p, blob->data + ptr, p_len, len1, STR_UNICODE|STR_NOALIGN); (*ps) = talloc_strdup(mem_ctx, p); if (!(*ps)) { - return false; + ret = false; + goto cleanup; } } else { (*ps) = ""; @@ -259,18 +268,23 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, *ps = ""; } else { if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) { - return false; + ret = false; + goto cleanup; } - if (blob->data + ptr < (uint8_t *)ptr || blob->data + ptr < blob->data) - return false; + if (blob->data + ptr < (uint8_t *)ptr || + blob->data + ptr < blob->data) { + ret = false; + goto cleanup; + } if (0 < len1) { - pull_string(global_smb_iconv_convenience, p, blob->data + ptr, sizeof(p), + pull_string(lp_iconv_convenience(global_loadparm), p, blob->data + ptr, p_len, len1, STR_ASCII|STR_NOALIGN); (*ps) = talloc_strdup(mem_ctx, p); if (!(*ps)) { - return false; + ret = false; + goto cleanup; } } else { (*ps) = ""; @@ -289,12 +303,16 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, } else { /* make sure its in the right format - be strict */ if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) { - return false; + ret = false; + goto cleanup; + } + + if (blob->data + ptr < (uint8_t *)ptr || + blob->data + ptr < blob->data) { + ret = false; + goto cleanup; } - if (blob->data + ptr < (uint8_t *)ptr || blob->data + ptr < blob->data) - return false; - *b = data_blob_talloc(mem_ctx, blob->data + ptr, len1); } break; @@ -303,9 +321,12 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, len1 = va_arg(ap, uint_t); /* make sure its in the right format - be strict */ NEED_DATA(len1); - if (blob->data + head_ofs < (uint8_t *)head_ofs || blob->data + head_ofs < blob->data) - return false; - + if (blob->data + head_ofs < (uint8_t *)head_ofs || + blob->data + head_ofs < blob->data) { + ret = false; + goto cleanup; + } + *b = data_blob_talloc(mem_ctx, blob->data + head_ofs, len1); head_ofs += len1; break; @@ -317,19 +338,26 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, case 'C': s = va_arg(ap, char *); - if (blob->data + head_ofs < (uint8_t *)head_ofs || blob->data + head_ofs < blob->data) - return false; - - head_ofs += pull_string(global_smb_iconv_convenience, p, blob->data+head_ofs, sizeof(p), - blob->length - head_ofs, - STR_ASCII|STR_TERMINATE); + if (blob->data + head_ofs < (uint8_t *)head_ofs || + blob->data + head_ofs < blob->data) { + ret = false; + goto cleanup; + } + + head_ofs += pull_string(lp_iconv_convenience(global_loadparm), p, + blob->data+head_ofs, p_len, + blob->length - head_ofs, + STR_ASCII|STR_TERMINATE); if (strcmp(s, p) != 0) { - return false; + ret = false; + goto cleanup; } break; } } - va_end(ap); - return true; +cleanup: + va_end(ap); + talloc_free(p); + return ret; } diff --git a/source4/auth/system_session.c b/source4/auth/system_session.c index 7c1e97b74f..e99bbbb1ab 100644 --- a/source4/auth/system_session.c +++ b/source4/auth/system_session.c @@ -196,7 +196,7 @@ static NTSTATUS _auth_system_session_info(TALLOC_CTX *parent_ctx, if (anonymous_credentials) { cli_credentials_set_anonymous(session_info->credentials); } else { - cli_credentials_set_machine_account_pending(session_info->credentials); + cli_credentials_set_machine_account_pending(session_info->credentials, lp_ctx); } *_session_info = session_info; diff --git a/source4/build/smb_build/input.pm b/source4/build/smb_build/input.pm index aa34be4b94..92ab54a10e 100644 --- a/source4/build/smb_build/input.pm +++ b/source4/build/smb_build/input.pm @@ -108,6 +108,7 @@ sub check_module($$$) my $sane_subsystem = lc($mod->{SUBSYSTEM}); $sane_subsystem =~ s/^lib//; $mod->{INSTALLDIR} = "MODULESDIR/$sane_subsystem"; + push (@{$mod->{PRIVATE_DEPENDENCIES}}, $mod->{SUBSYSTEM}); } if (grep(/INTEGRATED/, @{$mod->{OUTPUT_TYPE}})) { push (@{$INPUT->{$mod->{SUBSYSTEM}}{INIT_FUNCTIONS}}, $mod->{INIT_FUNCTION}) if defined($mod->{INIT_FUNCTION}); diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 3b43dfb0b7..d9b5ac4d78 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -217,6 +217,8 @@ HOSTLD_FLAGS=$self->{config}->{LDFLAGS} XSLTPROC=$self->{config}->{XSLTPROC} +LIB_PATH_VAR=$self->{config}->{LIB_PATH_VAR} + LEX=$self->{config}->{LEX} YACC=$self->{config}->{YACC} YAPP=$self->{config}->{YAPP} @@ -567,7 +569,16 @@ sub PkgConfig($$$) if (defined($ctx->{PUBLIC_DEPENDENCIES})) { foreach (@{$ctx->{PUBLIC_DEPENDENCIES}}) { next if ($other->{$_}->{ENABLE} eq "NO"); - if ($other->{$_}->{TYPE} eq "LIBRARY") { + if ($other->{$_}->{TYPE} eq "EXT_LIB") { + my $e = $other->{$_}; + + my $ldflags = join(" ", @{$e->{LDFLAGS}}); + $ldflags .= " " unless $ldflags eq ""; + my $libs = join(" ", @{$e->{LIBS}}); + $libs .= " " unless $libs eq ""; + + $pubs .= $ldflags.$libs; + } elsif ($other->{$_}->{TYPE} eq "LIBRARY") { s/^LIB//g; $_ = lc($_); @@ -584,7 +595,16 @@ sub PkgConfig($$$) if (defined($ctx->{PRIVATE_DEPENDENCIES})) { foreach (@{$ctx->{PRIVATE_DEPENDENCIES}}) { next if ($other->{$_}->{ENABLE} eq "NO"); - if ($other->{$_}->{TYPE} eq "LIBRARY") { + if ($other->{$_}->{TYPE} eq "EXT_LIB") { + my $e = $other->{$_}; + + my $ldflags = join(" ", @{$e->{LDFLAGS}}); + $ldflags .= " " unless $ldflags eq ""; + my $libs = join(" ", @{$e->{LIBS}}); + $libs .= " " unless $libs eq ""; + + $privlibs .= $ldflags.$libs; + } elsif ($other->{$_}->{TYPE} eq "LIBRARY") { s/^LIB//g; $_ = lc($_); diff --git a/source4/build/tests/summary.c b/source4/build/tests/summary.c index 6fbe46b87b..95fa1cbae9 100644 --- a/source4/build/tests/summary.c +++ b/source4/build/tests/summary.c @@ -4,7 +4,7 @@ void exit(int); main() { -#if !(defined(HAVE_IFACE_IFCONF) || defined(HAVE_IFACE_IFREQ) || defined(HAVE_IFACE_AIX)) +#if !(defined(HAVE_IFACE_GETIFADDRS) || defined(HAVE_IFACE_IFCONF) || defined(HAVE_IFACE_IFREQ) || defined(HAVE_IFACE_AIX)) printf("WARNING: No automated network interface determination\n"); #endif diff --git a/source4/cldap_server/cldap_server.c b/source4/cldap_server/cldap_server.c index d71e933b5f..47597ff1db 100644 --- a/source4/cldap_server/cldap_server.c +++ b/source4/cldap_server/cldap_server.c @@ -121,12 +121,15 @@ static NTSTATUS cldapd_add_socket(struct cldapd_server *cldapd, struct loadparm_ /* setup our listening sockets on the configured network interfaces */ -static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct loadparm_context *lp_ctx) +static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct loadparm_context *lp_ctx, + struct interface *ifaces) { - int num_interfaces = iface_count(lp_ctx); + int num_interfaces; TALLOC_CTX *tmp_ctx = talloc_new(cldapd); NTSTATUS status; + num_interfaces = iface_count(ifaces); + /* if we are allowing incoming packets from any address, then we need to bind to the wildcard address */ if (!lp_bind_interfaces_only(lp_ctx)) { @@ -136,7 +139,7 @@ static NTSTATUS cldapd_startup_interfaces(struct cldapd_server *cldapd, struct l int i; for (i=0; i<num_interfaces; i++) { - const char *address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i)); + const char *address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i)); status = cldapd_add_socket(cldapd, lp_ctx, address); NT_STATUS_NOT_OK_RETURN(status); } @@ -154,8 +157,11 @@ static void cldapd_task_init(struct task_server *task) { struct cldapd_server *cldapd; NTSTATUS status; + struct interface *ifaces; + + load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces); - if (iface_count(task->lp_ctx) == 0) { + if (iface_count(ifaces) == 0) { task_server_terminate(task, "cldapd: no network interfaces configured"); return; } @@ -188,7 +194,7 @@ static void cldapd_task_init(struct task_server *task) } /* start listening on the configured network interfaces */ - status = cldapd_startup_interfaces(cldapd, task->lp_ctx); + status = cldapd_startup_interfaces(cldapd, task->lp_ctx, ifaces); if (!NT_STATUS_IS_OK(status)) { task_server_terminate(task, "cldapd failed to setup interfaces"); return; diff --git a/source4/cldap_server/netlogon.c b/source4/cldap_server/netlogon.c index d1f001e333..b79d678e88 100644 --- a/source4/cldap_server/netlogon.c +++ b/source4/cldap_server/netlogon.c @@ -64,6 +64,7 @@ static NTSTATUS cldapd_netlogon_fill(struct cldapd_server *cldapd, const char *client_site; const char *pdc_ip; struct ldb_dn *partitions_basedn; + struct interface *ifaces; partitions_basedn = samdb_partitions_dn(cldapd->samctx, mem_ctx); @@ -187,7 +188,8 @@ static NTSTATUS cldapd_netlogon_fill(struct cldapd_server *cldapd, lp_workgroup(lp_ctx)); server_site = "Default-First-Site-Name"; client_site = "Default-First-Site-Name"; - pdc_ip = iface_best_ip(lp_ctx, src_address); + load_interfaces(mem_ctx, lp_interfaces(lp_ctx), &ifaces); + pdc_ip = iface_best_ip(ifaces, src_address); ZERO_STRUCTP(netlogon); diff --git a/source4/client/cifsdd.c b/source4/client/cifsdd.c index 2ce01a2227..08c152c3a5 100644 --- a/source4/client/cifsdd.c +++ b/source4/client/cifsdd.c @@ -351,7 +351,7 @@ static void print_transfer_stats(void) } } -static struct dd_iohandle * open_file(const char * which) +static struct dd_iohandle * open_file(const char * which, const char **ports) { int options = 0; const char * path = NULL; @@ -371,12 +371,12 @@ static struct dd_iohandle * open_file(const char * which) if (strcmp(which, "if") == 0) { path = check_arg_pathname("if"); - handle = dd_open_path(path, check_arg_numeric("ibs"), + handle = dd_open_path(path, ports, check_arg_numeric("ibs"), options); } else if (strcmp(which, "of") == 0) { options |= DD_WRITE; path = check_arg_pathname("of"); - handle = dd_open_path(path, check_arg_numeric("obs"), + handle = dd_open_path(path, ports, check_arg_numeric("obs"), options); } else { SMB_ASSERT(0); @@ -431,11 +431,11 @@ static int copy_files(struct loadparm_context *lp_ctx) DEBUG(4, ("IO buffer size is %llu, max xmit is %d\n", (unsigned long long)iomax, lp_max_xmit(lp_ctx))); - if (!(ifile = open_file("if"))) { + if (!(ifile = open_file("if", lp_smb_ports(lp_ctx)))) { return(FILESYS_EXIT_CODE); } - if (!(ofile = open_file("of"))) { + if (!(ofile = open_file("of", lp_smb_ports(lp_ctx)))) { return(FILESYS_EXIT_CODE); } diff --git a/source4/client/cifsdd.h b/source4/client/cifsdd.h index 2fe8de6ea3..994c209103 100644 --- a/source4/client/cifsdd.h +++ b/source4/client/cifsdd.h @@ -89,6 +89,7 @@ struct dd_iohandle #define DD_OPLOCK 0x00000008 struct dd_iohandle * dd_open_path(const char * path, + const char **ports, uint64_t io_size, int options); bool dd_fill_block(struct dd_iohandle * h, uint8_t * buf, uint64_t * buf_size, uint64_t need_size, uint64_t block_size); diff --git a/source4/client/cifsddio.c b/source4/client/cifsddio.c index 5cea8cf305..c30bf53196 100644 --- a/source4/client/cifsddio.c +++ b/source4/client/cifsddio.c @@ -221,7 +221,8 @@ static bool smb_write_func(void * handle, uint8_t * buf, uint64_t wanted, } static struct smbcli_state * init_smb_session(const char * host, - const char * share) + const char **ports, + const char * share) { NTSTATUS ret; struct smbcli_state * cli = NULL; @@ -229,7 +230,7 @@ static struct smbcli_state * init_smb_session(const char * host, /* When we support SMB URLs, we can get different user credentials for * each connection, but for now, we just use the same one for both. */ - ret = smbcli_full_connection(NULL, &cli, host, share, + ret = smbcli_full_connection(NULL, &cli, host, ports, share, NULL /* devtype */, cmdline_credentials, NULL /* events */); if (!NT_STATUS_IS_OK(ret)) { @@ -289,6 +290,7 @@ static int open_smb_file(struct smbcli_state * cli, } static struct dd_iohandle * open_cifs_handle(const char * host, + const char **ports, const char * share, const char * path, uint64_t io_size, @@ -312,7 +314,7 @@ static struct dd_iohandle * open_cifs_handle(const char * host, smbh->h.io_write = smb_write_func; smbh->h.io_seek = smb_seek_func; - if ((smbh->cli = init_smb_session(host, share)) == NULL) { + if ((smbh->cli = init_smb_session(host, ports, share)) == NULL) { return(NULL); } @@ -328,6 +330,7 @@ static struct dd_iohandle * open_cifs_handle(const char * host, /* ------------------------------------------------------------------------- */ struct dd_iohandle * dd_open_path(const char * path, + const char **ports, uint64_t io_size, int options) { @@ -344,7 +347,7 @@ struct dd_iohandle * dd_open_path(const char * path, /* Skip over leading directory separators. */ while (*remain == '/' || *remain == '\\') { remain++; } - return(open_cifs_handle(host, share, remain, + return(open_cifs_handle(host, ports, share, remain, io_size, options)); } diff --git a/source4/client/client.c b/source4/client/client.c index 43135e13ea..2f6a7abcc0 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -2997,16 +2997,19 @@ static int process_stdin(struct smbclient_context *ctx) char *the_prompt = talloc_asprintf(ctx, "smb: %s> ", ctx->remote_cur_dir); char *cline = smb_readline(the_prompt, readline_callback, completion_fn); talloc_free(the_prompt); - + if (!cline) break; - + /* special case - first char is ! */ if (*cline == '!') { system(cline + 1); + free(cline); continue; } - rc |= process_command_string(ctx, cline); + rc |= process_command_string(ctx, cline); + free(cline); + } return rc; @@ -3017,7 +3020,7 @@ static int process_stdin(struct smbclient_context *ctx) return a connection to a server *******************************************************/ static bool do_connect(struct smbclient_context *ctx, - const char *specified_server, const char *specified_share, struct cli_credentials *cred) + const char *specified_server, const char **ports, const char *specified_share, struct cli_credentials *cred) { NTSTATUS status; char *server, *share; @@ -3034,7 +3037,7 @@ static bool do_connect(struct smbclient_context *ctx, ctx->remote_cur_dir = talloc_strdup(ctx, "\\"); - status = smbcli_full_connection(ctx, &ctx->cli, server, + status = smbcli_full_connection(ctx, &ctx->cli, server, ports, share, NULL, cred, cli_credentials_get_event_context(cred)); if (!NT_STATUS_IS_OK(status)) { @@ -3061,7 +3064,7 @@ static int do_host_query(struct loadparm_context *lp_ctx, const char *query_host /**************************************************************************** handle a message operation ****************************************************************************/ -static int do_message_op(const char *netbios_name, const char *desthost, const char *destip, int name_type, const char **name_resolve_order, int max_xmit, int max_mux) +static int do_message_op(const char *netbios_name, const char *desthost, const char **destports, const char *destip, int name_type, struct resolve_context *resolve_ctx, int max_xmit, int max_mux) { struct nbt_name called, calling; const char *server_name; @@ -3073,7 +3076,7 @@ static int do_message_op(const char *netbios_name, const char *desthost, const c server_name = destip ? destip : desthost; - if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name, name_resolve_order, max_xmit, max_mux)) { + if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name, destports, resolve_ctx, max_xmit, max_mux)) { d_printf("Connection to %s failed\n", server_name); return 1; } @@ -3221,10 +3224,10 @@ static int do_message_op(const char *netbios_name, const char *desthost, const c } if (message) { - return do_message_op(lp_netbios_name(cmdline_lp_ctx), desthost, dest_ip, name_type, lp_name_resolve_order(cmdline_lp_ctx), lp_max_xmit(cmdline_lp_ctx), lp_maxmux(cmdline_lp_ctx)); + return do_message_op(lp_netbios_name(cmdline_lp_ctx), desthost, lp_smb_ports(cmdline_lp_ctx), dest_ip, name_type, lp_resolve_context(cmdline_lp_ctx), lp_max_xmit(cmdline_lp_ctx), lp_maxmux(cmdline_lp_ctx)); } - if (!do_connect(ctx, desthost, service, cmdline_credentials)) + if (!do_connect(ctx, desthost, lp_smb_ports(cmdline_lp_ctx), service, cmdline_credentials)) return 1; if (base_directory) diff --git a/source4/client/smbspool.c b/source4/client/smbspool.c index 57050acab8..614e50bb0b 100644 --- a/source4/client/smbspool.c +++ b/source4/client/smbspool.c @@ -26,7 +26,7 @@ */ static void list_devices(void); -static struct smbcli_state *smb_connect(const char *, const char *, const char *, const char *, const char *); +static struct smbcli_state *smb_connect(const char *, const char *, const char **, const char *, const char *, const char *); static int smb_print(struct smbcli_state *, char *, FILE *); @@ -189,7 +189,7 @@ static int smb_print(struct smbcli_state *, char *, FILE *); do { - if ((cli = smb_connect(workgroup, server, printer, username, password)) == NULL) + if ((cli = smb_connect(workgroup, server, lp_smb_ports(lp_ctx), printer, username, password)) == NULL) { if (getenv("CLASS") == NULL) { @@ -255,6 +255,7 @@ list_devices(void) static struct smbcli_state * /* O - SMB connection */ smb_connect(const char *workgroup, /* I - Workgroup */ const char *server, /* I - Server */ + const char **ports, /* I - Ports */ const char *share, /* I - Printer */ const char *username, /* I - Username */ const char *password) /* I - Password */ @@ -269,7 +270,7 @@ smb_connect(const char *workgroup, /* I - Workgroup */ myname = get_myname(); - nt_status = smbcli_full_connection(NULL, &c, myname, server, 0, share, NULL, + nt_status = smbcli_full_connection(NULL, &c, myname, server, ports, share, NULL, username, workgroup, password, NULL); free(myname); diff --git a/source4/cluster/cluster.c b/source4/cluster/cluster.c index 673ce2be4e..6bac1dcbe5 100644 --- a/source4/cluster/cluster.c +++ b/source4/cluster/cluster.c @@ -69,10 +69,10 @@ const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id) /* open a temporary tdb in a cluster friendly manner */ -struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags) +struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *dbname, int flags) { cluster_init(); - return ops->cluster_tdb_tmp_open(ops, mem_ctx, dbname, flags); + return ops->cluster_tdb_tmp_open(ops, mem_ctx, lp_ctx, dbname, flags); } diff --git a/source4/cluster/cluster.h b/source4/cluster/cluster.h index c83cc2cfa3..7cd31282cc 100644 --- a/source4/cluster/cluster.h +++ b/source4/cluster/cluster.h @@ -38,7 +38,7 @@ typedef void (*cluster_message_fn_t)(struct messaging_context *, DATA_BLOB); /* prototypes */ struct server_id cluster_id(uint32_t id); const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id); -struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags); +struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *dbname, int flags); void *cluster_backend_handle(void); NTSTATUS cluster_message_init(struct messaging_context *msg, struct server_id server, diff --git a/source4/cluster/cluster_private.h b/source4/cluster/cluster_private.h index 6307ba8ae6..1c895b8640 100644 --- a/source4/cluster/cluster_private.h +++ b/source4/cluster/cluster_private.h @@ -27,7 +27,9 @@ struct cluster_ops { const char *(*cluster_id_string)(struct cluster_ops *ops, TALLOC_CTX *, struct server_id ); struct tdb_wrap *(*cluster_tdb_tmp_open)(struct cluster_ops *, - TALLOC_CTX *, const char *, int); + TALLOC_CTX *, + struct loadparm_context *, + const char *, int); void *(*backend_handle)(struct cluster_ops *); NTSTATUS (*message_init)(struct cluster_ops *ops, struct messaging_context *msg, struct server_id server, diff --git a/source4/cluster/ctdb/ctdb_cluster.c b/source4/cluster/ctdb/ctdb_cluster.c index 6bac350805..9a543ee3ee 100644 --- a/source4/cluster/ctdb/ctdb_cluster.c +++ b/source4/cluster/ctdb/ctdb_cluster.c @@ -80,6 +80,7 @@ static const char *ctdb_id_string(struct cluster_ops *ops, */ static struct tdb_wrap *ctdb_tdb_tmp_open(struct cluster_ops *ops, TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, const char *dbname, int flags) { const char *dir = lp_parm_string(global_loadparm, NULL, "ctdb", "shared data"); diff --git a/source4/cluster/ctdb/opendb_ctdb.c b/source4/cluster/ctdb/opendb_ctdb.c index c8b673e74d..bb8ae26d3d 100644 --- a/source4/cluster/ctdb/opendb_ctdb.c +++ b/source4/cluster/ctdb/opendb_ctdb.c @@ -97,7 +97,7 @@ static struct odb_context *odb_ctdb_init(TALLOC_CTX *mem_ctx, odb->ntvfs_ctx = ntvfs_ctx; /* leave oplocks disabled by default until the code is working */ - odb->oplocks = lp_parm_bool(global_loadparm, NULL, "opendb", "oplocks", false); + odb->oplocks = lp_parm_bool(ntvfs_ctx->lp_ctx, NULL, "opendb", "oplocks", false); return odb; } diff --git a/source4/cluster/local.c b/source4/cluster/local.c index c994596930..539e47d271 100644 --- a/source4/cluster/local.c +++ b/source4/cluster/local.c @@ -56,9 +56,10 @@ static const char *local_id_string(struct cluster_ops *ops, */ static struct tdb_wrap *local_tdb_tmp_open(struct cluster_ops *ops, TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, const char *dbname, int flags) { - char *path = smbd_tmp_path(mem_ctx, global_loadparm, dbname); + char *path = smbd_tmp_path(mem_ctx, lp_ctx, dbname); struct tdb_wrap *w; w = tdb_wrap_open(mem_ctx, path, 0, flags, O_RDWR|O_CREAT, 0600); diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c new file mode 100644 index 0000000000..efc1b20ae0 --- /dev/null +++ b/source4/dsdb/common/util.c @@ -0,0 +1,1895 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + + Copyright (C) Andrew Tridgell 2004 + Copyright (C) Volker Lendecke 2004 + Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006 + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "ldb.h" +#include "ldb_errors.h" +#include "lib/util/util_ldb.h" +#include "dsdb/samdb/samdb.h" +#include "libcli/security/security.h" +#include "librpc/gen_ndr/ndr_security.h" +#include "dsdb/common/flags.h" +#include "dsdb/common/proto.h" +#include "libcli/ldap/ldap_ndr.h" +#include "libcli/auth/libcli_auth.h" + +/* + search the sam for the specified attributes in a specific domain, filter on + objectSid being in domain_sid. +*/ +int samdb_search_domain(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***res, + const char * const *attrs, + const struct dom_sid *domain_sid, + const char *format, ...) _PRINTF_ATTRIBUTE(7,8) +{ + va_list ap; + int i, count; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, + res, attrs, format, ap); + va_end(ap); + + i=0; + + while (i<count) { + struct dom_sid *entry_sid; + + entry_sid = samdb_result_dom_sid(mem_ctx, (*res)[i], "objectSid"); + + if ((entry_sid == NULL) || + (!dom_sid_in_domain(domain_sid, entry_sid))) { + /* Delete that entry from the result set */ + (*res)[i] = (*res)[count-1]; + count -= 1; + talloc_free(entry_sid); + continue; + } + talloc_free(entry_sid); + i += 1; + } + + return count; +} + +/* + search the sam for a single string attribute in exactly 1 record +*/ +const char *samdb_search_string_v(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char *attr_name, + const char *format, va_list ap) _PRINTF_ATTRIBUTE(5,0) +{ + int count; + const char *attrs[2] = { NULL, NULL }; + struct ldb_message **res = NULL; + + attrs[0] = attr_name; + + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + if (count > 1) { + DEBUG(1,("samdb: search for %s %s not single valued (count=%d)\n", + attr_name, format, count)); + } + if (count != 1) { + talloc_free(res); + return NULL; + } + + return samdb_result_string(res[0], attr_name, NULL); +} + + +/* + search the sam for a single string attribute in exactly 1 record +*/ +const char *samdb_search_string(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char *attr_name, + const char *format, ...) _PRINTF_ATTRIBUTE(5,6) +{ + va_list ap; + const char *str; + + va_start(ap, format); + str = samdb_search_string_v(sam_ldb, mem_ctx, basedn, attr_name, format, ap); + va_end(ap); + + return str; +} + +struct ldb_dn *samdb_search_dn(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char *format, ...) _PRINTF_ATTRIBUTE(4,5) +{ + va_list ap; + struct ldb_dn *ret; + struct ldb_message **res = NULL; + int count; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, NULL, format, ap); + va_end(ap); + + if (count != 1) return NULL; + + ret = talloc_steal(mem_ctx, res[0]->dn); + talloc_free(res); + + return ret; +} + +/* + search the sam for a dom_sid attribute in exactly 1 record +*/ +struct dom_sid *samdb_search_dom_sid(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char *attr_name, + const char *format, ...) _PRINTF_ATTRIBUTE(5,6) +{ + va_list ap; + int count; + struct ldb_message **res; + const char *attrs[2] = { NULL, NULL }; + struct dom_sid *sid; + + attrs[0] = attr_name; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + if (count > 1) { + DEBUG(1,("samdb: search for %s %s not single valued (count=%d)\n", + attr_name, format, count)); + } + if (count != 1) { + talloc_free(res); + return NULL; + } + sid = samdb_result_dom_sid(mem_ctx, res[0], attr_name); + talloc_free(res); + return sid; +} + +/* + return the count of the number of records in the sam matching the query +*/ +int samdb_search_count(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char *format, ...) _PRINTF_ATTRIBUTE(4,5) +{ + va_list ap; + struct ldb_message **res; + const char * const attrs[] = { NULL }; + int ret; + + va_start(ap, format); + ret = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + + return ret; +} + + +/* + search the sam for a single integer attribute in exactly 1 record +*/ +uint_t samdb_search_uint(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + uint_t default_value, + struct ldb_dn *basedn, + const char *attr_name, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7) +{ + va_list ap; + int count; + struct ldb_message **res; + const char *attrs[2] = { NULL, NULL }; + + attrs[0] = attr_name; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + + if (count != 1) { + return default_value; + } + + return samdb_result_uint(res[0], attr_name, default_value); +} + +/* + search the sam for a single signed 64 bit integer attribute in exactly 1 record +*/ +int64_t samdb_search_int64(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + int64_t default_value, + struct ldb_dn *basedn, + const char *attr_name, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7) +{ + va_list ap; + int count; + struct ldb_message **res; + const char *attrs[2] = { NULL, NULL }; + + attrs[0] = attr_name; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + + if (count != 1) { + return default_value; + } + + return samdb_result_int64(res[0], attr_name, default_value); +} + +/* + search the sam for multipe records each giving a single string attribute + return the number of matches, or -1 on error +*/ +int samdb_search_string_multiple(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + const char ***strs, + const char *attr_name, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7) +{ + va_list ap; + int count, i; + const char *attrs[2] = { NULL, NULL }; + struct ldb_message **res = NULL; + + attrs[0] = attr_name; + + va_start(ap, format); + count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); + va_end(ap); + + if (count <= 0) { + return count; + } + + /* make sure its single valued */ + for (i=0;i<count;i++) { + if (res[i]->num_elements != 1) { + DEBUG(1,("samdb: search for %s %s not single valued\n", + attr_name, format)); + talloc_free(res); + return -1; + } + } + + *strs = talloc_array(mem_ctx, const char *, count+1); + if (! *strs) { + talloc_free(res); + return -1; + } + + for (i=0;i<count;i++) { + (*strs)[i] = samdb_result_string(res[i], attr_name, NULL); + } + (*strs)[count] = NULL; + + return count; +} + +/* + pull a uint from a result set. +*/ +uint_t samdb_result_uint(const struct ldb_message *msg, const char *attr, uint_t default_value) +{ + return ldb_msg_find_attr_as_uint(msg, attr, default_value); +} + +/* + pull a (signed) int64 from a result set. +*/ +int64_t samdb_result_int64(const struct ldb_message *msg, const char *attr, int64_t default_value) +{ + return ldb_msg_find_attr_as_int64(msg, attr, default_value); +} + +/* + pull a string from a result set. +*/ +const char *samdb_result_string(const struct ldb_message *msg, const char *attr, + const char *default_value) +{ + return ldb_msg_find_attr_as_string(msg, attr, default_value); +} + +struct ldb_dn *samdb_result_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const struct ldb_message *msg, + const char *attr, struct ldb_dn *default_value) +{ + struct ldb_dn *ret_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, msg, attr); + if (!ret_dn) { + return default_value; + } + return ret_dn; +} + +/* + pull a rid from a objectSid in a result set. +*/ +uint32_t samdb_result_rid_from_sid(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, + const char *attr, uint32_t default_value) +{ + struct dom_sid *sid; + uint32_t rid; + + sid = samdb_result_dom_sid(mem_ctx, msg, attr); + if (sid == NULL) { + return default_value; + } + rid = sid->sub_auths[sid->num_auths-1]; + talloc_free(sid); + return rid; +} + +/* + pull a dom_sid structure from a objectSid in a result set. +*/ +struct dom_sid *samdb_result_dom_sid(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, + const char *attr) +{ + const struct ldb_val *v; + struct dom_sid *sid; + enum ndr_err_code ndr_err; + v = ldb_msg_find_ldb_val(msg, attr); + if (v == NULL) { + return NULL; + } + sid = talloc(mem_ctx, struct dom_sid); + if (sid == NULL) { + return NULL; + } + ndr_err = ndr_pull_struct_blob(v, sid, sid, + (ndr_pull_flags_fn_t)ndr_pull_dom_sid); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + talloc_free(sid); + return NULL; + } + return sid; +} + +/* + pull a guid structure from a objectGUID in a result set. +*/ +struct GUID samdb_result_guid(const struct ldb_message *msg, const char *attr) +{ + const struct ldb_val *v; + enum ndr_err_code ndr_err; + struct GUID guid; + TALLOC_CTX *mem_ctx; + + ZERO_STRUCT(guid); + + v = ldb_msg_find_ldb_val(msg, attr); + if (!v) return guid; + + mem_ctx = talloc_named_const(NULL, 0, "samdb_result_guid"); + if (!mem_ctx) return guid; + ndr_err = ndr_pull_struct_blob(v, mem_ctx, &guid, + (ndr_pull_flags_fn_t)ndr_pull_GUID); + talloc_free(mem_ctx); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return guid; + } + + return guid; +} + +/* + pull a sid prefix from a objectSid in a result set. + this is used to find the domain sid for a user +*/ +struct dom_sid *samdb_result_sid_prefix(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, + const char *attr) +{ + struct dom_sid *sid = samdb_result_dom_sid(mem_ctx, msg, attr); + if (!sid || sid->num_auths < 1) return NULL; + sid->num_auths--; + return sid; +} + +/* + pull a NTTIME in a result set. +*/ +NTTIME samdb_result_nttime(struct ldb_message *msg, const char *attr, NTTIME default_value) +{ + return ldb_msg_find_attr_as_uint64(msg, attr, default_value); +} + +/* + pull a uint64_t from a result set. +*/ +uint64_t samdb_result_uint64(struct ldb_message *msg, const char *attr, uint64_t default_value) +{ + return ldb_msg_find_attr_as_uint64(msg, attr, default_value); +} + + +/* + construct the allow_password_change field from the PwdLastSet attribute and the + domain password settings +*/ +NTTIME samdb_result_allow_password_change(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *domain_dn, + struct ldb_message *msg, + const char *attr) +{ + uint64_t attr_time = samdb_result_uint64(msg, attr, 0); + int64_t minPwdAge; + + if (attr_time == 0) { + return 0; + } + + minPwdAge = samdb_search_int64(sam_ldb, mem_ctx, 0, domain_dn, "minPwdAge", NULL); + + /* yes, this is a -= not a += as minPwdAge is stored as the negative + of the number of 100-nano-seconds */ + attr_time -= minPwdAge; + + return attr_time; +} + +/* + construct the force_password_change field from the PwdLastSet attribute and the + domain password settings +*/ +NTTIME samdb_result_force_password_change(struct ldb_context *sam_ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *domain_dn, + struct ldb_message *msg) +{ + uint64_t attr_time = samdb_result_uint64(msg, "pwdLastSet", 0); + uint32_t user_flags = samdb_result_uint64(msg, "userAccountControl", 0); + int64_t maxPwdAge; + + if (user_flags & UF_DONT_EXPIRE_PASSWD) { + return 0x7FFFFFFFFFFFFFFFULL; + } + + if (attr_time == 0) { + return 0; + } + + maxPwdAge = samdb_search_int64(sam_ldb, mem_ctx, 0, domain_dn, "maxPwdAge", NULL); + if (maxPwdAge == 0) { + return 0; + } else { + attr_time -= maxPwdAge; + } + + return attr_time; +} + +/* + pull a samr_Password structutre from a result set. +*/ +struct samr_Password *samdb_result_hash(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr) +{ + struct samr_Password *hash = NULL; + const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); + if (val && (val->length >= sizeof(hash->hash))) { + hash = talloc(mem_ctx, struct samr_Password); + memcpy(hash->hash, val->data, MIN(val->length, sizeof(hash->hash))); + } + return hash; +} + +/* + pull an array of samr_Password structutres from a result set. +*/ +uint_t samdb_result_hashes(TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr, struct samr_Password **hashes) +{ + uint_t count = 0; + const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); + int i; + + *hashes = NULL; + if (!val) { + return 0; + } + count = val->length / 16; + if (count == 0) { + return 0; + } + + *hashes = talloc_array(mem_ctx, struct samr_Password, count); + if (! *hashes) { + return 0; + } + + for (i=0;i<count;i++) { + memcpy((*hashes)[i].hash, (i*16)+(char *)val->data, 16); + } + + return count; +} + +NTSTATUS samdb_result_passwords(TALLOC_CTX *mem_ctx, struct ldb_message *msg, + struct samr_Password **lm_pwd, struct samr_Password **nt_pwd) +{ + struct samr_Password *lmPwdHash, *ntPwdHash; + if (nt_pwd) { + int num_nt; + num_nt = samdb_result_hashes(mem_ctx, msg, "unicodePwd", &ntPwdHash); + if (num_nt == 0) { + *nt_pwd = NULL; + } else if (num_nt > 1) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } else { + *nt_pwd = &ntPwdHash[0]; + } + } + if (lm_pwd) { + int num_lm; + num_lm = samdb_result_hashes(mem_ctx, msg, "dBCSPwd", &lmPwdHash); + if (num_lm == 0) { + *lm_pwd = NULL; + } else if (num_lm > 1) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } else { + *lm_pwd = &lmPwdHash[0]; + } + } + return NT_STATUS_OK; +} + +/* + pull a samr_LogonHours structutre from a result set. +*/ +struct samr_LogonHours samdb_result_logon_hours(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr) +{ + struct samr_LogonHours hours; + const int units_per_week = 168; + const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); + ZERO_STRUCT(hours); + hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week); + if (!hours.bits) { + return hours; + } + hours.units_per_week = units_per_week; + memset(hours.bits, 0xFF, units_per_week); + if (val) { + memcpy(hours.bits, val->data, MIN(val->length, units_per_week)); + } + return hours; +} + +/* + pull a set of account_flags from a result set. +*/ +uint16_t samdb_result_acct_flags(struct ldb_message *msg, const char *attr) +{ + uint_t userAccountControl = ldb_msg_find_attr_as_uint(msg, attr, 0); + return samdb_uf2acb(userAccountControl); +} + + +/* Find an attribute, with a particular value */ + +/* The current callers of this function expect a very specific + * behaviour: In particular, objectClass subclass equivilance is not + * wanted. This means that we should not lookup the schema for the + * comparison function */ +struct ldb_message_element *samdb_find_attribute(struct ldb_context *ldb, + const struct ldb_message *msg, + const char *name, const char *value) +{ + int i; + struct ldb_message_element *el = ldb_msg_find_element(msg, name); + + if (!el) { + return NULL; + } + + for (i=0;i<el->num_values;i++) { + if (ldb_attr_cmp(value, (char *)el->values[i].data) == 0) { + return el; + } + } + + return NULL; +} + +int samdb_find_or_add_value(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value) +{ + if (samdb_find_attribute(ldb, msg, name, set_value) == NULL) { + return samdb_msg_add_string(ldb, msg, msg, name, set_value); + } + return LDB_SUCCESS; +} + +int samdb_find_or_add_attribute(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value) +{ + struct ldb_message_element *el; + + el = ldb_msg_find_element(msg, name); + if (el) { + return LDB_SUCCESS; + } + + return samdb_msg_add_string(ldb, msg, msg, name, set_value); +} + + + +/* + add a string element to a message +*/ +int samdb_msg_add_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *str) +{ + char *s = talloc_strdup(mem_ctx, str); + char *a = talloc_strdup(mem_ctx, attr_name); + if (s == NULL || a == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + return ldb_msg_add_string(msg, a, s); +} + +/* + add a dom_sid element to a message +*/ +int samdb_msg_add_dom_sid(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, struct dom_sid *sid) +{ + struct ldb_val v; + enum ndr_err_code ndr_err; + + ndr_err = ndr_push_struct_blob(&v, mem_ctx, sid, + (ndr_push_flags_fn_t)ndr_push_dom_sid); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return -1; + } + return ldb_msg_add_value(msg, attr_name, &v, NULL); +} + + +/* + add a delete element operation to a message +*/ +int samdb_msg_add_delete(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name) +{ + /* we use an empty replace rather than a delete, as it allows for + samdb_replace() to be used everywhere */ + return ldb_msg_add_empty(msg, attr_name, LDB_FLAG_MOD_REPLACE, NULL); +} + +/* + add a add attribute value to a message +*/ +int samdb_msg_add_addval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *value) +{ + struct ldb_message_element *el; + char *a, *v; + int ret; + a = talloc_strdup(mem_ctx, attr_name); + if (a == NULL) + return -1; + v = talloc_strdup(mem_ctx, value); + if (v == NULL) + return -1; + ret = ldb_msg_add_string(msg, a, v); + if (ret != 0) + return ret; + el = ldb_msg_find_element(msg, a); + if (el == NULL) + return -1; + el->flags = LDB_FLAG_MOD_ADD; + return 0; +} + +/* + add a delete attribute value to a message +*/ +int samdb_msg_add_delval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *value) +{ + struct ldb_message_element *el; + char *a, *v; + int ret; + a = talloc_strdup(mem_ctx, attr_name); + if (a == NULL) + return -1; + v = talloc_strdup(mem_ctx, value); + if (v == NULL) + return -1; + ret = ldb_msg_add_string(msg, a, v); + if (ret != 0) + return ret; + el = ldb_msg_find_element(msg, a); + if (el == NULL) + return -1; + el->flags = LDB_FLAG_MOD_DELETE; + return 0; +} + +/* + add a int element to a message +*/ +int samdb_msg_add_int(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, int v) +{ + const char *s = talloc_asprintf(mem_ctx, "%d", v); + return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); +} + +/* + add a uint_t element to a message +*/ +int samdb_msg_add_uint(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, uint_t v) +{ + const char *s = talloc_asprintf(mem_ctx, "%u", v); + return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); +} + +/* + add a (signed) int64_t element to a message +*/ +int samdb_msg_add_int64(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, int64_t v) +{ + const char *s = talloc_asprintf(mem_ctx, "%lld", (long long)v); + return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); +} + +/* + add a uint64_t element to a message +*/ +int samdb_msg_add_uint64(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, uint64_t v) +{ + const char *s = talloc_asprintf(mem_ctx, "%llu", (unsigned long long)v); + return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); +} + +/* + add a samr_Password element to a message +*/ +int samdb_msg_add_hash(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, struct samr_Password *hash) +{ + struct ldb_val val; + val.data = talloc_memdup(mem_ctx, hash->hash, 16); + if (!val.data) { + return -1; + } + val.length = 16; + return ldb_msg_add_value(msg, attr_name, &val, NULL); +} + +/* + add a samr_Password array to a message +*/ +int samdb_msg_add_hashes(TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, struct samr_Password *hashes, uint_t count) +{ + struct ldb_val val; + int i; + val.data = talloc_array_size(mem_ctx, 16, count); + val.length = count*16; + if (!val.data) { + return -1; + } + for (i=0;i<count;i++) { + memcpy(i*16 + (char *)val.data, hashes[i].hash, 16); + } + return ldb_msg_add_value(msg, attr_name, &val, NULL); +} + +/* + add a acct_flags element to a message +*/ +int samdb_msg_add_acct_flags(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, uint32_t v) +{ + return samdb_msg_add_uint(sam_ldb, mem_ctx, msg, attr_name, samdb_acb2uf(v)); +} + +/* + add a logon_hours element to a message +*/ +int samdb_msg_add_logon_hours(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, struct samr_LogonHours *hours) +{ + struct ldb_val val; + val.length = hours->units_per_week / 8; + val.data = hours->bits; + return ldb_msg_add_value(msg, attr_name, &val, NULL); +} + +/* + add a general value element to a message +*/ +int samdb_msg_add_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const struct ldb_val *val) +{ + return ldb_msg_add_value(msg, attr_name, val, NULL); +} + +/* + sets a general value element to a message +*/ +int samdb_msg_set_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const struct ldb_val *val) +{ + struct ldb_message_element *el; + + el = ldb_msg_find_element(msg, attr_name); + if (el) { + el->num_values = 0; + } + return ldb_msg_add_value(msg, attr_name, val, NULL); +} + +/* + set a string element in a message +*/ +int samdb_msg_set_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name, const char *str) +{ + struct ldb_message_element *el; + + el = ldb_msg_find_element(msg, attr_name); + if (el) { + el->num_values = 0; + } + return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, str); +} + +/* + replace elements in a record +*/ +int samdb_replace(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg) +{ + int i; + + /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ + for (i=0;i<msg->num_elements;i++) { + msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; + } + + /* modify the samdb record */ + return ldb_modify(sam_ldb, msg); +} + +/* + return a default security descriptor +*/ +struct security_descriptor *samdb_default_security_descriptor(TALLOC_CTX *mem_ctx) +{ + struct security_descriptor *sd; + + sd = security_descriptor_initialise(mem_ctx); + + return sd; +} + +struct ldb_dn *samdb_base_dn(struct ldb_context *sam_ctx) +{ + return ldb_get_default_basedn(sam_ctx); +} + +struct ldb_dn *samdb_config_dn(struct ldb_context *sam_ctx) +{ + return ldb_get_config_basedn(sam_ctx); +} + +struct ldb_dn *samdb_schema_dn(struct ldb_context *sam_ctx) +{ + return ldb_get_schema_basedn(sam_ctx); +} + +struct ldb_dn *samdb_root_dn(struct ldb_context *sam_ctx) +{ + return ldb_get_root_basedn(sam_ctx); +} + +struct ldb_dn *samdb_partitions_dn(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx) +{ + struct ldb_dn *new_dn; + + new_dn = ldb_dn_copy(mem_ctx, samdb_config_dn(sam_ctx)); + if ( ! ldb_dn_add_child_fmt(new_dn, "CN=Partitions")) { + talloc_free(new_dn); + return NULL; + } + return new_dn; +} + +struct ldb_dn *samdb_sites_dn(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx) +{ + struct ldb_dn *new_dn; + + new_dn = ldb_dn_copy(mem_ctx, samdb_config_dn(sam_ctx)); + if ( ! ldb_dn_add_child_fmt(new_dn, "CN=Sites")) { + talloc_free(new_dn); + return NULL; + } + return new_dn; +} + +/* + work out the domain sid for the current open ldb +*/ +const struct dom_sid *samdb_domain_sid(struct ldb_context *ldb) +{ + TALLOC_CTX *tmp_ctx; + struct dom_sid *domain_sid; + + /* see if we have a cached copy */ + domain_sid = (struct dom_sid *)ldb_get_opaque(ldb, "cache.domain_sid"); + if (domain_sid) { + return domain_sid; + } + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + /* find the domain_sid */ + domain_sid = samdb_search_dom_sid(ldb, tmp_ctx, ldb_get_default_basedn(ldb), + "objectSid", "objectClass=domainDNS"); + if (domain_sid == NULL) { + goto failed; + } + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.domain_sid", domain_sid) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, domain_sid); + talloc_free(tmp_ctx); + + return domain_sid; + +failed: + DEBUG(1,("Failed to find domain_sid for open ldb\n")); + talloc_free(tmp_ctx); + return NULL; +} + +bool samdb_set_domain_sid(struct ldb_context *ldb, const struct dom_sid *dom_sid_in) +{ + TALLOC_CTX *tmp_ctx; + struct dom_sid *dom_sid_new; + struct dom_sid *dom_sid_old; + + /* see if we have a cached copy */ + dom_sid_old = talloc_get_type(ldb_get_opaque(ldb, + "cache.domain_sid"), struct dom_sid); + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + dom_sid_new = dom_sid_dup(tmp_ctx, dom_sid_in); + if (!dom_sid_new) { + goto failed; + } + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.domain_sid", dom_sid_new) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, dom_sid_new); + talloc_free(tmp_ctx); + talloc_free(dom_sid_old); + + return true; + +failed: + DEBUG(1,("Failed to set our own cached domain SID in the ldb!\n")); + talloc_free(tmp_ctx); + return false; +} + +/* Obtain the short name of the flexible single master operator + * (FSMO), such as the PDC Emulator */ +const char *samdb_result_fsmo_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const struct ldb_message *msg, + const char *attr) +{ + /* Format is cn=NTDS Settings,cn=<NETBIOS name of FSMO>,.... */ + struct ldb_dn *fsmo_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, msg, attr); + const struct ldb_val *val = ldb_dn_get_component_val(fsmo_dn, 1); + const char *name = ldb_dn_get_component_name(fsmo_dn, 1); + + if (!name || (ldb_attr_cmp(name, "cn") != 0)) { + /* Ensure this matches the format. This gives us a + * bit more confidence that a 'cn' value will be a + * ascii string */ + return NULL; + } + if (val) { + return (char *)val->data; + } + return NULL; +} + +/* + work out the ntds settings dn for the current open ldb +*/ +struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb) +{ + TALLOC_CTX *tmp_ctx; + const char *root_attrs[] = { "dsServiceName", NULL }; + int ret; + struct ldb_result *root_res; + struct ldb_dn *settings_dn; + + /* see if we have a cached copy */ + settings_dn = (struct ldb_dn *)ldb_get_opaque(ldb, "cache.settings_dn"); + if (settings_dn) { + return settings_dn; + } + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + + ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, ""), LDB_SCOPE_BASE, NULL, root_attrs, &root_res); + if (ret) { + DEBUG(1,("Searching for dsServiceName in rootDSE failed: %s\n", + ldb_errstring(ldb))); + goto failed; + } + talloc_steal(tmp_ctx, root_res); + + if (root_res->count != 1) { + goto failed; + } + + settings_dn = ldb_msg_find_attr_as_dn(ldb, tmp_ctx, root_res->msgs[0], "dsServiceName"); + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.settings_dn", settings_dn) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, settings_dn); + talloc_free(tmp_ctx); + + return settings_dn; + +failed: + DEBUG(1,("Failed to find our own NTDS Settings DN in the ldb!\n")); + talloc_free(tmp_ctx); + return NULL; +} + +/* + work out the ntds settings invocationId for the current open ldb +*/ +const struct GUID *samdb_ntds_invocation_id(struct ldb_context *ldb) +{ + TALLOC_CTX *tmp_ctx; + const char *attrs[] = { "invocationId", NULL }; + int ret; + struct ldb_result *res; + struct GUID *invocation_id; + + /* see if we have a cached copy */ + invocation_id = (struct GUID *)ldb_get_opaque(ldb, "cache.invocation_id"); + if (invocation_id) { + return invocation_id; + } + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res); + if (ret) { + goto failed; + } + talloc_steal(tmp_ctx, res); + + if (res->count != 1) { + goto failed; + } + + invocation_id = talloc(tmp_ctx, struct GUID); + if (!invocation_id) { + goto failed; + } + + *invocation_id = samdb_result_guid(res->msgs[0], "invocationId"); + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.invocation_id", invocation_id) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, invocation_id); + talloc_free(tmp_ctx); + + return invocation_id; + +failed: + DEBUG(1,("Failed to find our own NTDS Settings invocationId in the ldb!\n")); + talloc_free(tmp_ctx); + return NULL; +} + +bool samdb_set_ntds_invocation_id(struct ldb_context *ldb, const struct GUID *invocation_id_in) +{ + TALLOC_CTX *tmp_ctx; + struct GUID *invocation_id_new; + struct GUID *invocation_id_old; + + /* see if we have a cached copy */ + invocation_id_old = (struct GUID *)ldb_get_opaque(ldb, + "cache.invocation_id"); + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + invocation_id_new = talloc(tmp_ctx, struct GUID); + if (!invocation_id_new) { + goto failed; + } + + *invocation_id_new = *invocation_id_in; + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.invocation_id", invocation_id_new) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, invocation_id_new); + talloc_free(tmp_ctx); + talloc_free(invocation_id_old); + + return true; + +failed: + DEBUG(1,("Failed to set our own cached invocationId in the ldb!\n")); + talloc_free(tmp_ctx); + return false; +} + +/* + work out the ntds settings objectGUID for the current open ldb +*/ +const struct GUID *samdb_ntds_objectGUID(struct ldb_context *ldb) +{ + TALLOC_CTX *tmp_ctx; + const char *attrs[] = { "objectGUID", NULL }; + int ret; + struct ldb_result *res; + struct GUID *ntds_guid; + + /* see if we have a cached copy */ + ntds_guid = (struct GUID *)ldb_get_opaque(ldb, "cache.ntds_guid"); + if (ntds_guid) { + return ntds_guid; + } + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res); + if (ret) { + goto failed; + } + talloc_steal(tmp_ctx, res); + + if (res->count != 1) { + goto failed; + } + + ntds_guid = talloc(tmp_ctx, struct GUID); + if (!ntds_guid) { + goto failed; + } + + *ntds_guid = samdb_result_guid(res->msgs[0], "objectGUID"); + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.ntds_guid", ntds_guid) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, ntds_guid); + talloc_free(tmp_ctx); + + return ntds_guid; + +failed: + DEBUG(1,("Failed to find our own NTDS Settings objectGUID in the ldb!\n")); + talloc_free(tmp_ctx); + return NULL; +} + +bool samdb_set_ntds_objectGUID(struct ldb_context *ldb, const struct GUID *ntds_guid_in) +{ + TALLOC_CTX *tmp_ctx; + struct GUID *ntds_guid_new; + struct GUID *ntds_guid_old; + + /* see if we have a cached copy */ + ntds_guid_old = (struct GUID *)ldb_get_opaque(ldb, "cache.ntds_guid"); + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + goto failed; + } + + ntds_guid_new = talloc(tmp_ctx, struct GUID); + if (!ntds_guid_new) { + goto failed; + } + + *ntds_guid_new = *ntds_guid_in; + + /* cache the domain_sid in the ldb */ + if (ldb_set_opaque(ldb, "cache.ntds_guid", ntds_guid_new) != LDB_SUCCESS) { + goto failed; + } + + talloc_steal(ldb, ntds_guid_new); + talloc_free(tmp_ctx); + talloc_free(ntds_guid_old); + + return true; + +failed: + DEBUG(1,("Failed to set our own cached invocationId in the ldb!\n")); + talloc_free(tmp_ctx); + return false; +} + +/* + work out the server dn for the current open ldb +*/ +struct ldb_dn *samdb_server_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) +{ + return ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb)); +} + +/* + work out the server dn for the current open ldb +*/ +struct ldb_dn *samdb_server_site_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) +{ + struct ldb_dn *server_dn; + struct ldb_dn *server_site_dn; + + server_dn = samdb_server_dn(ldb, mem_ctx); + if (!server_dn) return NULL; + + server_site_dn = ldb_dn_get_parent(mem_ctx, server_dn); + + talloc_free(server_dn); + return server_site_dn; +} + +/* + work out if we are the PDC for the domain of the current open ldb +*/ +bool samdb_is_pdc(struct ldb_context *ldb) +{ + const char *dom_attrs[] = { "fSMORoleOwner", NULL }; + int ret; + struct ldb_result *dom_res; + TALLOC_CTX *tmp_ctx; + bool is_pdc; + struct ldb_dn *pdc; + + tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + DEBUG(1, ("talloc_new failed in samdb_is_pdc")); + return false; + } + + ret = ldb_search(ldb, ldb_get_default_basedn(ldb), LDB_SCOPE_BASE, NULL, dom_attrs, &dom_res); + if (ret) { + DEBUG(1,("Searching for fSMORoleOwner in %s failed: %s\n", + ldb_dn_get_linearized(ldb_get_default_basedn(ldb)), + ldb_errstring(ldb))); + goto failed; + } + talloc_steal(tmp_ctx, dom_res); + if (dom_res->count != 1) { + goto failed; + } + + pdc = ldb_msg_find_attr_as_dn(ldb, tmp_ctx, dom_res->msgs[0], "fSMORoleOwner"); + + if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc) == 0) { + is_pdc = true; + } else { + is_pdc = false; + } + + talloc_free(tmp_ctx); + + return is_pdc; + +failed: + DEBUG(1,("Failed to find if we are the PDC for this ldb\n")); + talloc_free(tmp_ctx); + return false; +} + + +/* Find a domain object in the parents of a particular DN. */ +int samdb_search_for_parent_domain(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *dn, + struct ldb_dn **parent_dn, const char **errstring) +{ + TALLOC_CTX *local_ctx; + struct ldb_dn *sdn = dn; + struct ldb_result *res = NULL; + int ret = 0; + const char *attrs[] = { NULL }; + + local_ctx = talloc_new(mem_ctx); + if (local_ctx == NULL) return LDB_ERR_OPERATIONS_ERROR; + + while ((sdn = ldb_dn_get_parent(local_ctx, sdn))) { + ret = ldb_search(ldb, sdn, LDB_SCOPE_BASE, + "(|(objectClass=domain)(objectClass=builtinDomain))", attrs, &res); + if (ret == LDB_SUCCESS) { + talloc_steal(local_ctx, res); + if (res->count == 1) { + break; + } + } else { + break; + } + } + + if (ret != LDB_SUCCESS) { + *errstring = talloc_asprintf(mem_ctx, "Error searching for parent domain of %s, failed searching for %s: %s", + ldb_dn_get_linearized(dn), + ldb_dn_get_linearized(sdn), + ldb_errstring(ldb)); + talloc_free(local_ctx); + return ret; + } + if (res->count != 1) { + *errstring = talloc_asprintf(mem_ctx, "Invalid dn (%s), not child of a domain object", + ldb_dn_get_linearized(dn)); + talloc_free(local_ctx); + return LDB_ERR_CONSTRAINT_VIOLATION; + } + + *parent_dn = talloc_steal(mem_ctx, res->msgs[0]->dn); + talloc_free(local_ctx); + return ret; +} + +/* + check that a password is sufficiently complex +*/ +static bool samdb_password_complexity_ok(const char *pass) +{ + return check_password_quality(pass); +} + + + +/* + set the user password using plaintext, obeying any user or domain + password restrictions + + note that this function doesn't actually store the result in the + database, it just fills in the "mod" structure with ldb modify + elements to setup the correct change when samdb_replace() is + called. This allows the caller to combine the change with other + changes (as is needed by some of the set user info levels) + + The caller should probably have a transaction wrapping this +*/ +_PUBLIC_ NTSTATUS samdb_set_password(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, + struct ldb_dn *user_dn, + struct ldb_dn *domain_dn, + struct ldb_message *mod, + const char *new_pass, + struct samr_Password *lmNewHash, + struct samr_Password *ntNewHash, + bool user_change, + enum samr_RejectReason *reject_reason, + struct samr_DomInfo1 **_dominfo) +{ + const char * const user_attrs[] = { "userAccountControl", "lmPwdHistory", + "ntPwdHistory", + "dBCSPwd", "unicodePwd", + "objectSid", + "pwdLastSet", NULL }; + const char * const domain_attrs[] = { "pwdProperties", "pwdHistoryLength", + "maxPwdAge", "minPwdAge", + "minPwdLength", NULL }; + NTTIME pwdLastSet; + int64_t minPwdAge; + uint_t minPwdLength, pwdProperties, pwdHistoryLength; + uint_t userAccountControl; + struct samr_Password *sambaLMPwdHistory, *sambaNTPwdHistory, *lmPwdHash, *ntPwdHash; + struct samr_Password local_lmNewHash, local_ntNewHash; + int sambaLMPwdHistory_len, sambaNTPwdHistory_len; + struct dom_sid *domain_sid; + struct ldb_message **res; + bool restrictions; + int count; + time_t now = time(NULL); + NTTIME now_nt; + int i; + + /* we need to know the time to compute password age */ + unix_to_nt_time(&now_nt, now); + + /* pull all the user parameters */ + count = gendb_search_dn(ctx, mem_ctx, user_dn, &res, user_attrs); + if (count != 1) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + userAccountControl = samdb_result_uint(res[0], "userAccountControl", 0); + sambaLMPwdHistory_len = samdb_result_hashes(mem_ctx, res[0], + "lmPwdHistory", &sambaLMPwdHistory); + sambaNTPwdHistory_len = samdb_result_hashes(mem_ctx, res[0], + "ntPwdHistory", &sambaNTPwdHistory); + lmPwdHash = samdb_result_hash(mem_ctx, res[0], "dBCSPwd"); + ntPwdHash = samdb_result_hash(mem_ctx, res[0], "unicodePwd"); + pwdLastSet = samdb_result_uint64(res[0], "pwdLastSet", 0); + + /* Only non-trust accounts have restrictions (possibly this + * test is the wrong way around, but I like to be restrictive + * if possible */ + restrictions = !(userAccountControl & (UF_INTERDOMAIN_TRUST_ACCOUNT + |UF_WORKSTATION_TRUST_ACCOUNT + |UF_SERVER_TRUST_ACCOUNT)); + + if (domain_dn) { + /* pull the domain parameters */ + count = gendb_search_dn(ctx, mem_ctx, domain_dn, &res, domain_attrs); + if (count != 1) { + DEBUG(2, ("samdb_set_password: Domain DN %s is invalid, for user %s\n", + ldb_dn_get_linearized(domain_dn), + ldb_dn_get_linearized(user_dn))); + return NT_STATUS_NO_SUCH_DOMAIN; + } + } else { + /* work out the domain sid, and pull the domain from there */ + domain_sid = samdb_result_sid_prefix(mem_ctx, res[0], "objectSid"); + if (domain_sid == NULL) { + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + count = gendb_search(ctx, mem_ctx, NULL, &res, domain_attrs, + "(objectSid=%s)", + ldap_encode_ndr_dom_sid(mem_ctx, domain_sid)); + if (count != 1) { + DEBUG(2, ("samdb_set_password: Could not find domain to match SID: %s, for user %s\n", + dom_sid_string(mem_ctx, domain_sid), + ldb_dn_get_linearized(user_dn))); + return NT_STATUS_NO_SUCH_DOMAIN; + } + } + + pwdProperties = samdb_result_uint(res[0], "pwdProperties", 0); + pwdHistoryLength = samdb_result_uint(res[0], "pwdHistoryLength", 0); + minPwdLength = samdb_result_uint(res[0], "minPwdLength", 0); + minPwdAge = samdb_result_int64(res[0], "minPwdAge", 0); + + if (_dominfo) { + struct samr_DomInfo1 *dominfo; + /* on failure we need to fill in the reject reasons */ + dominfo = talloc(mem_ctx, struct samr_DomInfo1); + if (dominfo == NULL) { + return NT_STATUS_NO_MEMORY; + } + dominfo->min_password_length = minPwdLength; + dominfo->password_properties = pwdProperties; + dominfo->password_history_length = pwdHistoryLength; + dominfo->max_password_age = minPwdAge; + dominfo->min_password_age = minPwdAge; + *_dominfo = dominfo; + } + + if (restrictions && new_pass) { + + /* check the various password restrictions */ + if (restrictions && minPwdLength > strlen_m(new_pass)) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_TOO_SHORT; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + + /* possibly check password complexity */ + if (restrictions && pwdProperties & DOMAIN_PASSWORD_COMPLEX && + !samdb_password_complexity_ok(new_pass)) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_COMPLEXITY; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + + /* compute the new nt and lm hashes */ + if (E_deshash(new_pass, local_lmNewHash.hash)) { + lmNewHash = &local_lmNewHash; + } + if (!E_md4hash(new_pass, local_ntNewHash.hash)) { + /* If we can't convert this password to UCS2, then we should not accept it */ + if (reject_reason) { + *reject_reason = SAMR_REJECT_OTHER; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + ntNewHash = &local_ntNewHash; + } + + if (user_change) { + /* are all password changes disallowed? */ + if (pwdProperties & DOMAIN_REFUSE_PASSWORD_CHANGE) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_OTHER; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + + /* can this user change password? */ + if (userAccountControl & UF_PASSWD_CANT_CHANGE) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_OTHER; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + + /* yes, this is a minus. The ages are in negative 100nsec units! */ + if (pwdLastSet - minPwdAge > now_nt) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_OTHER; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + + /* check the immediately past password */ + if (pwdHistoryLength > 0) { + if (lmNewHash && lmPwdHash && memcmp(lmNewHash->hash, lmPwdHash->hash, 16) == 0) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_IN_HISTORY; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + if (ntNewHash && ntPwdHash && memcmp(ntNewHash->hash, ntPwdHash->hash, 16) == 0) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_IN_HISTORY; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + } + + /* check the password history */ + sambaLMPwdHistory_len = MIN(sambaLMPwdHistory_len, pwdHistoryLength); + sambaNTPwdHistory_len = MIN(sambaNTPwdHistory_len, pwdHistoryLength); + + for (i=0; lmNewHash && i<sambaLMPwdHistory_len;i++) { + if (memcmp(lmNewHash->hash, sambaLMPwdHistory[i].hash, 16) == 0) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_IN_HISTORY; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + } + for (i=0; ntNewHash && i<sambaNTPwdHistory_len;i++) { + if (memcmp(ntNewHash->hash, sambaNTPwdHistory[i].hash, 16) == 0) { + if (reject_reason) { + *reject_reason = SAMR_REJECT_IN_HISTORY; + } + return NT_STATUS_PASSWORD_RESTRICTION; + } + } + } + +#define CHECK_RET(x) do { if (x != 0) return NT_STATUS_NO_MEMORY; } while(0) + + /* the password is acceptable. Start forming the new fields */ + if (new_pass) { + /* if we know the cleartext, then only set it. + * Modules in ldb will set all the appropriate + * hashes */ + CHECK_RET(samdb_msg_add_string(ctx, mem_ctx, mod, + "sambaPassword", new_pass)); + } else { + /* We don't have the cleartext, so delete the old one + * and set what we have of the hashes */ + CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "sambaPassword")); + + if (lmNewHash) { + CHECK_RET(samdb_msg_add_hash(ctx, mem_ctx, mod, "dBCSPwd", lmNewHash)); + } else { + CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "dBCSPwd")); + } + + if (ntNewHash) { + CHECK_RET(samdb_msg_add_hash(ctx, mem_ctx, mod, "unicodePwd", ntNewHash)); + } else { + CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "unicodePwd")); + } + } + + return NT_STATUS_OK; +} + + +/* + set the user password using plaintext, obeying any user or domain + password restrictions + + This wrapper function takes a SID as input, rather than a user DN, + and actually performs the password change + +*/ +_PUBLIC_ NTSTATUS samdb_set_password_sid(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, + const struct dom_sid *user_sid, + const char *new_pass, + struct samr_Password *lmNewHash, + struct samr_Password *ntNewHash, + bool user_change, + enum samr_RejectReason *reject_reason, + struct samr_DomInfo1 **_dominfo) +{ + NTSTATUS nt_status; + struct ldb_dn *user_dn; + struct ldb_message *msg; + int ret; + + ret = ldb_transaction_start(ctx); + if (ret) { + DEBUG(1, ("Failed to start transaction: %s\n", ldb_errstring(ctx))); + return NT_STATUS_TRANSACTION_ABORTED; + } + + user_dn = samdb_search_dn(ctx, mem_ctx, NULL, + "(&(objectSid=%s)(objectClass=user))", + ldap_encode_ndr_dom_sid(mem_ctx, user_sid)); + if (!user_dn) { + ldb_transaction_cancel(ctx); + DEBUG(3, ("samdb_set_password_sid: SID %s not found in samdb, returning NO_SUCH_USER\n", + dom_sid_string(mem_ctx, user_sid))); + return NT_STATUS_NO_SUCH_USER; + } + + msg = ldb_msg_new(mem_ctx); + if (msg == NULL) { + ldb_transaction_cancel(ctx); + return NT_STATUS_NO_MEMORY; + } + + msg->dn = ldb_dn_copy(msg, user_dn); + if (!msg->dn) { + ldb_transaction_cancel(ctx); + return NT_STATUS_NO_MEMORY; + } + + nt_status = samdb_set_password(ctx, mem_ctx, + user_dn, NULL, + msg, new_pass, + lmNewHash, ntNewHash, + user_change, /* This is a password set, not change */ + reject_reason, _dominfo); + if (!NT_STATUS_IS_OK(nt_status)) { + ldb_transaction_cancel(ctx); + return nt_status; + } + + /* modify the samdb record */ + ret = samdb_replace(ctx, mem_ctx, msg); + if (ret != 0) { + ldb_transaction_cancel(ctx); + return NT_STATUS_ACCESS_DENIED; + } + + ret = ldb_transaction_commit(ctx); + if (ret != 0) { + DEBUG(0,("Failed to commit transaction to change password on %s: %s\n", + ldb_dn_get_linearized(msg->dn), + ldb_errstring(ctx))); + return NT_STATUS_TRANSACTION_ABORTED; + } + return NT_STATUS_OK; +} + + + +NTSTATUS samdb_create_foreign_security_principal(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx, + struct dom_sid *sid, struct ldb_dn **ret_dn) +{ + struct ldb_message *msg; + struct ldb_dn *basedn; + const char *sidstr; + int ret; + + sidstr = dom_sid_string(mem_ctx, sid); + NT_STATUS_HAVE_NO_MEMORY(sidstr); + + /* We might have to create a ForeignSecurityPrincipal, even if this user + * is in our own domain */ + + msg = ldb_msg_new(mem_ctx); + if (msg == NULL) { + return NT_STATUS_NO_MEMORY; + } + + /* TODO: Hmmm. This feels wrong. How do I find the base dn to + * put the ForeignSecurityPrincipals? d_state->domain_dn does + * not work, this is wrong for the Builtin domain, there's no + * cn=For...,cn=Builtin,dc={BASEDN}. -- vl + */ + + basedn = samdb_search_dn(sam_ctx, mem_ctx, NULL, + "(&(objectClass=container)(cn=ForeignSecurityPrincipals))"); + + if (basedn == NULL) { + DEBUG(0, ("Failed to find DN for " + "ForeignSecurityPrincipal container\n")); + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + /* add core elements to the ldb_message for the alias */ + msg->dn = ldb_dn_copy(mem_ctx, basedn); + if ( ! ldb_dn_add_child_fmt(msg->dn, "CN=%s", sidstr)) + return NT_STATUS_NO_MEMORY; + + samdb_msg_add_string(sam_ctx, mem_ctx, msg, + "objectClass", + "foreignSecurityPrincipal"); + + /* create the alias */ + ret = ldb_add(sam_ctx, msg); + if (ret != 0) { + DEBUG(0,("Failed to create foreignSecurityPrincipal " + "record %s: %s\n", + ldb_dn_get_linearized(msg->dn), + ldb_errstring(sam_ctx))); + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + *ret_dn = msg->dn; + return NT_STATUS_OK; +} + + +/* + Find the DN of a domain, assuming it to be a dotted.dns name +*/ + +struct ldb_dn *samdb_dns_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *dns_domain) +{ + int i; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + const char *binary_encoded; + const char **split_realm; + struct ldb_dn *dn; + + if (!tmp_ctx) { + return NULL; + } + + split_realm = str_list_make(tmp_ctx, dns_domain, "."); + if (!split_realm) { + talloc_free(tmp_ctx); + return NULL; + } + dn = ldb_dn_new(mem_ctx, ldb, NULL); + for (i=0; split_realm[i]; i++) { + binary_encoded = ldb_binary_encode_string(tmp_ctx, split_realm[i]); + if (!ldb_dn_add_base_fmt(dn, "dc=%s", binary_encoded)) { + DEBUG(2, ("Failed to add dc=%s element to DN %s\n", + binary_encoded, ldb_dn_get_linearized(dn))); + talloc_free(tmp_ctx); + return NULL; + } + } + if (!ldb_dn_validate(dn)) { + DEBUG(2, ("Failed to validated DN %s\n", + ldb_dn_get_linearized(dn))); + return NULL; + } + return dn; +} +/* + Find the DN of a domain, be it the netbios or DNS name +*/ + +struct ldb_dn *samdb_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, + const char *domain_name) +{ + const char * const domain_ref_attrs[] = { + "ncName", NULL + }; + const char * const domain_ref2_attrs[] = { + NULL + }; + struct ldb_result *res_domain_ref; + char *escaped_domain = ldb_binary_encode_string(mem_ctx, domain_name); + /* find the domain's DN */ + int ret_domain = ldb_search_exp_fmt(ldb, mem_ctx, + &res_domain_ref, + samdb_partitions_dn(ldb, mem_ctx), + LDB_SCOPE_ONELEVEL, + domain_ref_attrs, + "(&(nETBIOSName=%s)(objectclass=crossRef))", + escaped_domain); + if (ret_domain != 0) { + return NULL; + } + + if (res_domain_ref->count == 0) { + ret_domain = ldb_search_exp_fmt(ldb, mem_ctx, + &res_domain_ref, + samdb_dns_domain_to_dn(ldb, mem_ctx, domain_name), + LDB_SCOPE_BASE, + domain_ref2_attrs, + "(objectclass=domain)"); + if (ret_domain != 0) { + return NULL; + } + + if (res_domain_ref->count == 1) { + return res_domain_ref->msgs[0]->dn; + } + return NULL; + } + + if (res_domain_ref->count > 1) { + DEBUG(0,("Found %d records matching domain [%s]\n", + ret_domain, domain_name)); + return NULL; + } + + return samdb_result_dn(ldb, mem_ctx, res_domain_ref->msgs[0], "nCName", NULL); + +} diff --git a/source4/dsdb/config.mk b/source4/dsdb/config.mk index ad9721458f..de00b401c8 100644 --- a/source4/dsdb/config.mk +++ b/source4/dsdb/config.mk @@ -9,20 +9,30 @@ PUBLIC_PROTO_HEADER = samdb/samdb_proto.h PUBLIC_HEADERS = samdb/samdb.h PUBLIC_DEPENDENCIES = HEIMDAL_KRB5 PRIVATE_DEPENDENCIES = LIBNDR NDR_MISC NDR_DRSUAPI NDR_DRSBLOBS NSS_WRAPPER \ - auth_system_session LDAP_ENCODE + auth_system_session LDAP_ENCODE LIBCLI_AUTH LIBNDR \ + SAMDB_SCHEMA LDB_WRAP SAMDB_COMMON OBJ_FILES = \ samdb/samdb.o \ samdb/samdb_privilege.o \ samdb/cracknames.o \ + repl/replicated_objects.o + +[SUBSYSTEM::SAMDB_COMMON] +PUBLIC_PROTO_HEADER = common/proto.h +PRIVATE_DEPENDENCIES = LIBLDB +OBJ_FILES = \ common/sidmap.o \ common/flag_mapping.o \ + common/util.o + +[SUBSYSTEM::SAMDB_SCHEMA] +PUBLIC_PROTO_HEADER = schema/proto.h +PUBLIC_HEADERS = schema/schema.h +PRIVATE_DEPENDENCIES = SAMDB_COMMON NDR_DRSUAPI NDR_DRSBLOBS +OBJ_FILES = \ schema/schema_init.o \ schema/schema_syntax.o \ schema/schema_constructed.o \ - repl/replicated_objects.o -# -# End SUBSYSTEM SAMDB -################################################ ####################### # Start SUBSYSTEM DREPL_SRV diff --git a/source4/dsdb/samdb/ldb_modules/anr.c b/source4/dsdb/samdb/ldb_modules/anr.c new file mode 100644 index 0000000000..901215e972 --- /dev/null +++ b/source4/dsdb/samdb/ldb_modules/anr.c @@ -0,0 +1,310 @@ +/* + ldb database library + + Copyright (C) Amdrew Bartlett <abartlet@samba.org> 2007 + Copyright (C) Andrew Tridgell 2004 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* + * Name: ldb + * + * Component: ldb anr module + * + * Description: module to implement 'ambiguous name resolution' + * + * Author: Andrew Bartlett + */ + +#include "includes.h" +#include "ldb_includes.h" +#include "dsdb/samdb/samdb.h" + +/** + * Make a and 'and' or 'or' tree from the two supplied elements + */ +struct ldb_parse_tree *make_parse_list(struct ldb_module *module, + TALLOC_CTX *mem_ctx, enum ldb_parse_op op, + struct ldb_parse_tree *first_arm, struct ldb_parse_tree *second_arm) +{ + struct ldb_parse_tree *list; + + list = talloc(mem_ctx, struct ldb_parse_tree); + if (list == NULL){ + ldb_oom(module->ldb); + return NULL; + } + list->operation = op; + + list->u.list.num_elements = 2; + list->u.list.elements = talloc_array(list, struct ldb_parse_tree *, 2); + if (!list->u.list.elements) { + ldb_oom(module->ldb); + return NULL; + } + list->u.list.elements[0] = talloc_steal(list, first_arm); + list->u.list.elements[1] = talloc_steal(list, second_arm); + return list; +} + +/** + * Make an equality or prefix match tree, from the attribute, operation and matching value supplied + */ +struct ldb_parse_tree *make_match_tree(struct ldb_module *module, + TALLOC_CTX *mem_ctx, enum ldb_parse_op op, + const char *attr, const DATA_BLOB *match) +{ + struct ldb_parse_tree *match_tree; + + match_tree = talloc(mem_ctx, struct ldb_parse_tree); + + /* Depending on what type of match was selected, fill in the right part of the union */ + + match_tree->operation = op; + switch (op) { + case LDB_OP_SUBSTRING: + match_tree->u.substring.attr = attr; + + match_tree->u.substring.start_with_wildcard = 0; + match_tree->u.substring.end_with_wildcard = 1; + match_tree->u.substring.chunks = talloc_array(match_tree, struct ldb_val *, 2); + + if (match_tree->u.substring.chunks == NULL){ + ldb_oom(module->ldb); + return NULL; + } + match_tree->u.substring.chunks[0] = match; + match_tree->u.substring.chunks[1] = NULL; + break; + case LDB_OP_EQUALITY: + match_tree->u.equality.attr = attr; + match_tree->u.equality.value = *match; + break; + } + return match_tree; +} + +struct anr_context { + bool found_anr; + struct ldb_module *module; +}; + +/** + * Given the match for an 'ambigious name resolution' query, create a + * parse tree with an 'or' of all the anr attributes in the schema. + */ + +typedef struct ldb_parse_tree *(*anr_parse_tree_callback_t)(TALLOC_CTX *mem_ctx, + const struct ldb_val *match, + void *context); + + +/** + * Callback function to do the heavy lifting for the for the parse tree walker + */ +struct ldb_parse_tree *anr_replace_callback(TALLOC_CTX *mem_ctx, + const struct ldb_val *match, + void *context) +{ + struct ldb_parse_tree *tree = NULL; + struct anr_context *anr_context = talloc_get_type(context, struct anr_context); + struct ldb_module *module = anr_context->module; + struct ldb_parse_tree *match_tree; + uint8_t *p; + enum ldb_parse_op op; + struct dsdb_attribute *cur; + const struct dsdb_schema *schema = dsdb_get_schema(module->ldb); + if (!schema) { + ldb_asprintf_errstring(module->ldb, "no schema with which to construct anr filter"); + return NULL; + } + + anr_context->found_anr = true; + + if (match->length > 1 && match->data[0] == '=') { + DATA_BLOB *match2 = talloc(tree, DATA_BLOB); + *match2 = data_blob_const(match->data+1, match->length - 1); + if (match2 == NULL){ + ldb_oom(module->ldb); + return NULL; + } + match = match2; + op = LDB_OP_EQUALITY; + } else { + op = LDB_OP_SUBSTRING; + } + for (cur = schema->attributes; cur; cur = cur->next) { + if (!(cur->searchFlags & 0x4)) continue; + match_tree = make_match_tree(module, mem_ctx, op, cur->lDAPDisplayName, match); + + if (tree) { + /* Inject an 'or' with the current tree */ + tree = make_parse_list(module, mem_ctx, LDB_OP_OR, tree, match_tree); + if (tree == NULL) { + ldb_oom(module->ldb); + return NULL; + } + } else { + tree = match_tree; + } + } + + + /* If the search term has a space in it, + split it up at the first space. */ + + p = memchr(match->data, ' ', match->length); + + if (p) { + struct ldb_parse_tree *first_split_filter, *second_split_filter, *split_filters, *match_tree_1, *match_tree_2; + DATA_BLOB *first_match = talloc(tree, DATA_BLOB); + DATA_BLOB *second_match = talloc(tree, DATA_BLOB); + if (!first_match || !second_match) { + ldb_oom(module->ldb); + return NULL; + } + *first_match = data_blob_const(match->data, p-match->data); + *second_match = data_blob_const(p+1, match->length - (p-match->data) - 1); + + /* Add (|(&(givenname=first)(sn=second))(&(givenname=second)(sn=first))) */ + + match_tree_1 = make_match_tree(module, mem_ctx, op, "givenName", first_match); + match_tree_2 = make_match_tree(module, mem_ctx, op, "sn", second_match); + + first_split_filter = make_parse_list(module, context, LDB_OP_AND, match_tree_1, match_tree_2); + if (first_split_filter == NULL){ + ldb_oom(module->ldb); + return NULL; + } + + match_tree_1 = make_match_tree(module, mem_ctx, op, "sn", first_match); + match_tree_2 = make_match_tree(module, mem_ctx, op, "givenName", second_match); + + second_split_filter = make_parse_list(module, context, LDB_OP_AND, match_tree_1, match_tree_2); + if (second_split_filter == NULL){ + ldb_oom(module->ldb); + return NULL; + } + + split_filters = make_parse_list(module, mem_ctx, LDB_OP_OR, + first_split_filter, second_split_filter); + if (split_filters == NULL) { + ldb_oom(module->ldb); + return NULL; + } + + if (tree) { + /* Inject an 'or' with the current tree */ + tree = make_parse_list(module, mem_ctx, LDB_OP_OR, tree, split_filters); + } else { + tree = split_filters; + } + } + return tree; +} + +/* + replace any occurances of an attribute with a new, generated attribute tree +*/ +struct ldb_parse_tree *anr_replace_subtrees(struct ldb_parse_tree *tree, + const char *attr, + anr_parse_tree_callback_t callback, + void *context) +{ + int i; + switch (tree->operation) { + case LDB_OP_AND: + case LDB_OP_OR: + for (i=0;i<tree->u.list.num_elements;i++) { + tree->u.list.elements[i] = anr_replace_subtrees(tree->u.list.elements[i], + attr, callback, context); + if (!tree->u.list.elements[i]) { + return NULL; + } + } + break; + case LDB_OP_NOT: + tree->u.isnot.child = anr_replace_subtrees(tree->u.isnot.child, attr, callback, context); + if (!tree->u.isnot.child) { + return NULL; + } + break; + case LDB_OP_EQUALITY: + if (ldb_attr_cmp(tree->u.equality.attr, attr) == 0) { + tree = callback(tree, &tree->u.equality.value, + context); + if (!tree) { + return NULL; + } + } + break; + case LDB_OP_SUBSTRING: + if (ldb_attr_cmp(tree->u.substring.attr, attr) == 0) { + if (tree->u.substring.start_with_wildcard == 0 && + tree->u.substring.end_with_wildcard == 1 && + tree->u.substring.chunks[0] != NULL && + tree->u.substring.chunks[1] == NULL) { + tree = callback(tree, tree->u.substring.chunks[0], context); + if (!tree) { + return NULL; + } + } + } + break; + } + return tree; +} + +/* search */ +static int anr_search(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_parse_tree *anr_tree; + struct anr_context *context = talloc(req, struct anr_context); + if (!context) { + ldb_oom(module->ldb); + return LDB_ERR_OPERATIONS_ERROR; + } + + context->module = module; + context->found_anr = false; + + /* Yes, this is a problem with req->op.search.tree being const... */ + anr_tree = anr_replace_subtrees(req->op.search.tree, "anr", anr_replace_callback, context); + if (!anr_tree) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (context->found_anr) { + /* The above function modifies the tree if it finds "anr", so no + * point just setting this on the down_req */ + req->op.search.tree = talloc_steal(req, anr_tree); + + } + + /* TODO: Add a callback, and ensure we retry the search with surname and given name if we fail to match */ + + return ldb_next_request(module, req); +} + +static const struct ldb_module_ops anr_ops = { + .name = "anr", + .search = anr_search +}; + +int ldb_anr_init(void) +{ + return ldb_register_module(&anr_ops); +} + diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk index b585d0da7f..95bb7de06c 100644 --- a/source4/dsdb/samdb/ldb_modules/config.mk +++ b/source4/dsdb/samdb/ldb_modules/config.mk @@ -11,11 +11,12 @@ OBJ_FILES = \ ################################################ ################################################ -# Start MODULE ldb_repl_mata_data +# Start MODULE ldb_repl_meta_data [MODULE::ldb_repl_meta_data] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC LIBNDR NDR_MISC NDR_DRSUAPI NDR_DRSBLOBS +PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC LIBNDR NDR_MISC NDR_DRSUAPI \ + NDR_DRSBLOBS LIBNDR INIT_FUNCTION = repl_meta_data_module_init OBJ_FILES = \ repl_meta_data.o @@ -75,7 +76,7 @@ OBJ_FILES = \ [MODULE::ldb_samldb] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC LDAP_ENCODE +PRIVATE_DEPENDENCIES = LIBTALLOC LDAP_ENCODE NDR_MISC SAMDB INIT_FUNCTION = samldb_module_init OBJ_FILES = \ samldb.o @@ -89,7 +90,8 @@ OBJ_FILES = \ SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY INIT_FUNCTION = ldb_samba3sam_module_init -PRIVATE_DEPENDENCIES = LIBTALLOC ldb_map SMBPASSWD NSS_WRAPPER +PRIVATE_DEPENDENCIES = LIBTALLOC ldb_map SMBPASSWD NSS_WRAPPER LIBSECURITY \ + NDR_SECURITY OBJ_FILES = \ samba3sam.o # @@ -102,7 +104,7 @@ OBJ_FILES = \ SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY INIT_FUNCTION = ldb_simple_ldap_map_module_init -PRIVATE_DEPENDENCIES = LIBTALLOC ldb_map +PRIVATE_DEPENDENCIES = LIBTALLOC ldb_map LIBNDR NDR_MISC ENABLE = YES ALIASES = entryuuid nsuniqueid OBJ_FILES = \ @@ -127,7 +129,7 @@ OBJ_FILES = \ # Start MODULE ldb_rootdse [MODULE::ldb_rootdse] SUBSYSTEM = LIBLDB -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC SAMDB OUTPUT_TYPE = SHARED_LIBRARY INIT_FUNCTION = rootdse_module_init OBJ_FILES = \ @@ -143,7 +145,8 @@ SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY INIT_FUNCTION = password_hash_module_init OBJ_FILES = password_hash.o -PRIVATE_DEPENDENCIES = HEIMDAL_HDB_KEYS LIBTALLOC HEIMDAL_KRB5 LDAP_ENCODE +PRIVATE_DEPENDENCIES = HEIMDAL_HDB_KEYS LIBTALLOC HEIMDAL_KRB5 LDAP_ENCODE \ + LIBCLI_AUTH NDR_DRSBLOBS KERBEROS SAMDB # # End MODULE ldb_password_hash ################################################ @@ -151,7 +154,7 @@ PRIVATE_DEPENDENCIES = HEIMDAL_HDB_KEYS LIBTALLOC HEIMDAL_KRB5 LDAP_ENCODE ################################################ # Start MODULE ldb_local_password [MODULE::ldb_local_password] -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC LIBNDR SAMDB OUTPUT_TYPE = SHARED_LIBRARY SUBSYSTEM = LIBLDB INIT_FUNCTION = local_password_module_init @@ -163,7 +166,7 @@ OBJ_FILES = local_password.o ################################################ # Start MODULE ldb_kludge_acl [MODULE::ldb_kludge_acl] -PRIVATE_DEPENDENCIES = LIBTALLOC LIBSECURITY +PRIVATE_DEPENDENCIES = LIBTALLOC LIBSECURITY SAMDB OUTPUT_TYPE = SHARED_LIBRARY SUBSYSTEM = LIBLDB INIT_FUNCTION = ldb_kludge_acl_init @@ -178,7 +181,7 @@ OBJ_FILES = \ [MODULE::ldb_extended_dn] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC LIBNDR LIBSECURITY SAMDB INIT_FUNCTION = ldb_extended_dn_init OBJ_FILES = \ extended_dn.o @@ -204,7 +207,7 @@ OBJ_FILES = \ [MODULE::ldb_partition] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC SAMDB INIT_FUNCTION = ldb_partition_init OBJ_FILES = \ partition.o @@ -217,7 +220,7 @@ OBJ_FILES = \ [MODULE::ldb_schema] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC LIBLDB INIT_FUNCTION = ldb_schema_init OBJ_FILES = \ schema.o schema_syntax.o @@ -230,7 +233,7 @@ OBJ_FILES = \ [MODULE::ldb_update_keytab] SUBSYSTEM = LIBLDB OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC CREDENTIALS_KRB5 +PRIVATE_DEPENDENCIES = LIBTALLOC CREDENTIALS #Also depends on credentials, but that would loop INIT_FUNCTION = ldb_update_kt_init OBJ_FILES = \ @@ -245,7 +248,7 @@ OBJ_FILES = \ INIT_FUNCTION = ldb_objectclass_init OUTPUT_TYPE = SHARED_LIBRARY CFLAGS = -Ilib/ldb/include -PRIVATE_DEPENDENCIES = LIBTALLOC +PRIVATE_DEPENDENCIES = LIBTALLOC LIBSECURITY NDR_SECURITY SAMDB SUBSYSTEM = LIBLDB OBJ_FILES = \ objectclass.o @@ -284,7 +287,7 @@ OBJ_FILES = \ INIT_FUNCTION = ldb_linked_attributes_init CFLAGS = -Ilib/ldb/include OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC SAMDB +PRIVATE_DEPENDENCIES = LIBTALLOC SAMDB SUBSYSTEM = LIBLDB OBJ_FILES = \ linked_attributes.o @@ -304,3 +307,16 @@ OBJ_FILES = \ # End MODULE ldb_ranged_results ################################################ +################################################ +# Start MODULE ldb_anr +[MODULE::ldb_anr] +INIT_FUNCTION = ldb_anr_init +CFLAGS = -Ilib/ldb/include +OUTPUT_TYPE = SHARED_LIBRARY +PRIVATE_DEPENDENCIES = LIBTALLOC LIBSAMBA-UTIL SAMDB +SUBSYSTEM = LIBLDB +OBJ_FILES = \ + anr.o +# End MODULE ldb_anr +################################################ + diff --git a/source4/dsdb/samdb/ldb_modules/naming_fsmo.c b/source4/dsdb/samdb/ldb_modules/naming_fsmo.c index ddd357a4c6..d6b6a24287 100644 --- a/source4/dsdb/samdb/ldb_modules/naming_fsmo.c +++ b/source4/dsdb/samdb/ldb_modules/naming_fsmo.c @@ -52,7 +52,7 @@ static int naming_fsmo_init(struct ldb_module *module) naming_dn = samdb_partitions_dn(module->ldb, mem_ctx); if (!naming_dn) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)"); + "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } @@ -70,7 +70,7 @@ static int naming_fsmo_init(struct ldb_module *module) &naming_res); if (ret == LDB_ERR_NO_SUCH_OBJECT) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)"); + "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } @@ -84,7 +84,7 @@ static int naming_fsmo_init(struct ldb_module *module) talloc_steal(mem_ctx, naming_res); if (naming_res->count == 0) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "naming_fsmo_init: no cross-ref container present: (skip loading of naming contexts details)"); + "naming_fsmo_init: no cross-ref container present: (skip loading of naming contexts details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (naming_res->count > 1) { @@ -110,7 +110,7 @@ static int naming_fsmo_init(struct ldb_module *module) talloc_steal(module, naming_fsmo); ldb_debug(module->ldb, LDB_DEBUG_TRACE, - "naming_fsmo_init: we are master: %s", + "naming_fsmo_init: we are master: %s\n", (naming_fsmo->we_are_master?"yes":"no")); talloc_free(mem_ctx); diff --git a/source4/dsdb/samdb/ldb_modules/partition.c b/source4/dsdb/samdb/ldb_modules/partition.c index bf4421ab0d..4586810d96 100644 --- a/source4/dsdb/samdb/ldb_modules/partition.c +++ b/source4/dsdb/samdb/ldb_modules/partition.c @@ -117,9 +117,9 @@ static struct dsdb_control_current_partition *find_partition(struct partition_pr return NULL; }; -/* - fire the caller's callback for every entry, but only send 'done' once. -*/ +/** + * fire the caller's callback for every entry, but only send 'done' once. + */ static int partition_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { struct partition_context *ac; @@ -139,9 +139,9 @@ static int partition_search_callback(struct ldb_context *ldb, void *context, str } } -/* - only fire the 'last' callback, and only for START-TLS for now -*/ +/** + * only fire the 'last' callback, and only for START-TLS for now + */ static int partition_other_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { struct partition_context *ac; @@ -248,7 +248,9 @@ static int partition_send_request(struct partition_context *ac, struct ldb_contr return LDB_SUCCESS; } -/* Send a request down to all the partitions */ +/** + * Send a request down to all the partitions + */ static int partition_send_all(struct ldb_module *module, struct partition_context *ac, struct ldb_control *remove_control, @@ -270,8 +272,10 @@ static int partition_send_all(struct ldb_module *module, return LDB_SUCCESS; } -/* Figure out which backend a request needs to be aimed at. Some - * requests must be replicated to all backends */ +/** + * Figure out which backend a request needs to be aimed at. Some + * requests must be replicated to all backends + */ static int partition_replicate(struct ldb_module *module, struct ldb_request *req, struct ldb_dn *dn) { unsigned i; diff --git a/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c b/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c index ed9b554bb1..0f3293ed1d 100644 --- a/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c +++ b/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c @@ -51,7 +51,7 @@ static int pdc_fsmo_init(struct ldb_module *module) pdc_dn = samdb_base_dn(module->ldb); if (!pdc_dn) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "pdc_fsmo_init: no domain dn present: (skip loading of domain details)"); + "pdc_fsmo_init: no domain dn present: (skip loading of domain details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } @@ -69,7 +69,7 @@ static int pdc_fsmo_init(struct ldb_module *module) &pdc_res); if (ret == LDB_ERR_NO_SUCH_OBJECT) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "pdc_fsmo_init: no domain object present: (skip loading of domain details)"); + "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (ret != LDB_SUCCESS) { @@ -82,7 +82,7 @@ static int pdc_fsmo_init(struct ldb_module *module) talloc_steal(mem_ctx, pdc_res); if (pdc_res->count == 0) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "pdc_fsmo_init: no domain object present: (skip loading of domain details)"); + "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (pdc_res->count > 1) { @@ -108,7 +108,7 @@ static int pdc_fsmo_init(struct ldb_module *module) talloc_steal(module, pdc_fsmo); ldb_debug(module->ldb, LDB_DEBUG_TRACE, - "pdc_fsmo_init: we are master: %s", + "pdc_fsmo_init: we are master: %s\n", (pdc_fsmo->we_are_master?"yes":"no")); talloc_free(mem_ctx); diff --git a/source4/dsdb/samdb/ldb_modules/schema.c b/source4/dsdb/samdb/ldb_modules/schema.c index cf923d673b..525193ac8c 100644 --- a/source4/dsdb/samdb/ldb_modules/schema.c +++ b/source4/dsdb/samdb/ldb_modules/schema.c @@ -329,7 +329,7 @@ done: static int schema_init_classes(struct ldb_module *module, struct schema_private_data *data) { - static const char *schema_attrs[] = { "governsID", + const char *schema_attrs[] = { "governsID", "lDAPDisplayName", "objectClassCategory", "defaultObjectCategory", @@ -542,7 +542,7 @@ static int schema_add_check_parent(struct ldb_context *ldb, void *context, struc static int schema_add_build_parent_req(struct schema_context *sctx) { - static const char * const parent_attrs[] = { "objectClass", NULL }; + const char * const parent_attrs[] = { "objectClass", NULL }; int ret; sctx->parent_req = talloc_zero(sctx, struct ldb_request); diff --git a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c b/source4/dsdb/samdb/ldb_modules/schema_fsmo.c index 28853f3e34..559c91bd2d 100644 --- a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c +++ b/source4/dsdb/samdb/ldb_modules/schema_fsmo.c @@ -60,7 +60,7 @@ static int schema_fsmo_init(struct ldb_module *module) schema_dn = samdb_schema_dn(module->ldb); if (!schema_dn) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "schema_fsmo_init: no schema dn present: (skip schema loading)"); + "schema_fsmo_init: no schema dn present: (skip schema loading)\n"); return ldb_next_init(module); } @@ -92,7 +92,7 @@ static int schema_fsmo_init(struct ldb_module *module) &schema_res); if (ret == LDB_ERR_NO_SUCH_OBJECT) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "schema_fsmo_init: no schema head present: (skip schema loading)"); + "schema_fsmo_init: no schema head present: (skip schema loading)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (ret != LDB_SUCCESS) { @@ -105,7 +105,7 @@ static int schema_fsmo_init(struct ldb_module *module) talloc_steal(mem_ctx, schema_res); if (schema_res->count == 0) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, - "schema_fsmo_init: no schema head present: (skip schema loading)"); + "schema_fsmo_init: no schema head present: (skip schema loading)\n"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (schema_res->count > 1) { @@ -246,7 +246,7 @@ static int schema_fsmo_init(struct ldb_module *module) talloc_steal(module, schema_fsmo); ldb_debug(module->ldb, LDB_DEBUG_TRACE, - "schema_fsmo_init: we are master: %s", + "schema_fsmo_init: we are master: %s\n", (schema_fsmo->we_are_master?"yes":"no")); talloc_free(mem_ctx); diff --git a/source4/dsdb/samdb/ldb_modules/update_keytab.c b/source4/dsdb/samdb/ldb_modules/update_keytab.c index 87efa6a6f8..a18efd757a 100644 --- a/source4/dsdb/samdb/ldb_modules/update_keytab.c +++ b/source4/dsdb/samdb/ldb_modules/update_keytab.c @@ -158,7 +158,7 @@ static int update_kt_end_trans(struct ldb_module *module) struct dn_list *p; for (p=data->changed_dns; p; p = p->next) { int kret; - kret = cli_credentials_update_keytab(p->creds); + kret = cli_credentials_update_keytab(p->creds, ldb_get_opaque(module->ldb, "loadparm")); if (kret != 0) { talloc_free(data->changed_dns); data->changed_dns = NULL; diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index 4366b7d0b9..b042d1d3b7 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -86,623 +86,6 @@ struct ldb_context *samdb_connect(TALLOC_CTX *mem_ctx, } /* - search the sam for the specified attributes in a specific domain, filter on - objectSid being in domain_sid. -*/ -int samdb_search_domain(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - struct ldb_message ***res, - const char * const *attrs, - const struct dom_sid *domain_sid, - const char *format, ...) _PRINTF_ATTRIBUTE(7,8) -{ - va_list ap; - int i, count; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, - res, attrs, format, ap); - va_end(ap); - - i=0; - - while (i<count) { - struct dom_sid *entry_sid; - - entry_sid = samdb_result_dom_sid(mem_ctx, (*res)[i], "objectSid"); - - if ((entry_sid == NULL) || - (!dom_sid_in_domain(domain_sid, entry_sid))) { - /* Delete that entry from the result set */ - (*res)[i] = (*res)[count-1]; - count -= 1; - talloc_free(entry_sid); - continue; - } - talloc_free(entry_sid); - i += 1; - } - - return count; -} - -/* - search the sam for a single string attribute in exactly 1 record -*/ -const char *samdb_search_string_v(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char *attr_name, - const char *format, va_list ap) _PRINTF_ATTRIBUTE(5,0) -{ - int count; - const char *attrs[2] = { NULL, NULL }; - struct ldb_message **res = NULL; - - attrs[0] = attr_name; - - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - if (count > 1) { - DEBUG(1,("samdb: search for %s %s not single valued (count=%d)\n", - attr_name, format, count)); - } - if (count != 1) { - talloc_free(res); - return NULL; - } - - return samdb_result_string(res[0], attr_name, NULL); -} - - -/* - search the sam for a single string attribute in exactly 1 record -*/ -const char *samdb_search_string(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char *attr_name, - const char *format, ...) _PRINTF_ATTRIBUTE(5,6) -{ - va_list ap; - const char *str; - - va_start(ap, format); - str = samdb_search_string_v(sam_ldb, mem_ctx, basedn, attr_name, format, ap); - va_end(ap); - - return str; -} - -struct ldb_dn *samdb_search_dn(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char *format, ...) _PRINTF_ATTRIBUTE(4,5) -{ - va_list ap; - struct ldb_dn *ret; - struct ldb_message **res = NULL; - int count; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, NULL, format, ap); - va_end(ap); - - if (count != 1) return NULL; - - ret = talloc_steal(mem_ctx, res[0]->dn); - talloc_free(res); - - return ret; -} - -/* - search the sam for a dom_sid attribute in exactly 1 record -*/ -struct dom_sid *samdb_search_dom_sid(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char *attr_name, - const char *format, ...) _PRINTF_ATTRIBUTE(5,6) -{ - va_list ap; - int count; - struct ldb_message **res; - const char *attrs[2] = { NULL, NULL }; - struct dom_sid *sid; - - attrs[0] = attr_name; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - va_end(ap); - if (count > 1) { - DEBUG(1,("samdb: search for %s %s not single valued (count=%d)\n", - attr_name, format, count)); - } - if (count != 1) { - talloc_free(res); - return NULL; - } - sid = samdb_result_dom_sid(mem_ctx, res[0], attr_name); - talloc_free(res); - return sid; -} - -/* - return the count of the number of records in the sam matching the query -*/ -int samdb_search_count(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char *format, ...) _PRINTF_ATTRIBUTE(4,5) -{ - va_list ap; - struct ldb_message **res; - const char * const attrs[] = { NULL }; - int ret; - - va_start(ap, format); - ret = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - va_end(ap); - - return ret; -} - - -/* - search the sam for a single integer attribute in exactly 1 record -*/ -uint_t samdb_search_uint(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - uint_t default_value, - struct ldb_dn *basedn, - const char *attr_name, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7) -{ - va_list ap; - int count; - struct ldb_message **res; - const char *attrs[2] = { NULL, NULL }; - - attrs[0] = attr_name; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - va_end(ap); - - if (count != 1) { - return default_value; - } - - return samdb_result_uint(res[0], attr_name, default_value); -} - -/* - search the sam for a single signed 64 bit integer attribute in exactly 1 record -*/ -int64_t samdb_search_int64(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - int64_t default_value, - struct ldb_dn *basedn, - const char *attr_name, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7) -{ - va_list ap; - int count; - struct ldb_message **res; - const char *attrs[2] = { NULL, NULL }; - - attrs[0] = attr_name; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - va_end(ap); - - if (count != 1) { - return default_value; - } - - return samdb_result_int64(res[0], attr_name, default_value); -} - -/* - search the sam for multipe records each giving a single string attribute - return the number of matches, or -1 on error -*/ -int samdb_search_string_multiple(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - const char ***strs, - const char *attr_name, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7) -{ - va_list ap; - int count, i; - const char *attrs[2] = { NULL, NULL }; - struct ldb_message **res = NULL; - - attrs[0] = attr_name; - - va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, attrs, format, ap); - va_end(ap); - - if (count <= 0) { - return count; - } - - /* make sure its single valued */ - for (i=0;i<count;i++) { - if (res[i]->num_elements != 1) { - DEBUG(1,("samdb: search for %s %s not single valued\n", - attr_name, format)); - talloc_free(res); - return -1; - } - } - - *strs = talloc_array(mem_ctx, const char *, count+1); - if (! *strs) { - talloc_free(res); - return -1; - } - - for (i=0;i<count;i++) { - (*strs)[i] = samdb_result_string(res[i], attr_name, NULL); - } - (*strs)[count] = NULL; - - return count; -} - -/* - pull a uint from a result set. -*/ -uint_t samdb_result_uint(const struct ldb_message *msg, const char *attr, uint_t default_value) -{ - return ldb_msg_find_attr_as_uint(msg, attr, default_value); -} - -/* - pull a (signed) int64 from a result set. -*/ -int64_t samdb_result_int64(const struct ldb_message *msg, const char *attr, int64_t default_value) -{ - return ldb_msg_find_attr_as_int64(msg, attr, default_value); -} - -/* - pull a string from a result set. -*/ -const char *samdb_result_string(const struct ldb_message *msg, const char *attr, - const char *default_value) -{ - return ldb_msg_find_attr_as_string(msg, attr, default_value); -} - -struct ldb_dn *samdb_result_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const struct ldb_message *msg, - const char *attr, struct ldb_dn *default_value) -{ - struct ldb_dn *ret_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, msg, attr); - if (!ret_dn) { - return default_value; - } - return ret_dn; -} - -/* - pull a rid from a objectSid in a result set. -*/ -uint32_t samdb_result_rid_from_sid(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, - const char *attr, uint32_t default_value) -{ - struct dom_sid *sid; - uint32_t rid; - - sid = samdb_result_dom_sid(mem_ctx, msg, attr); - if (sid == NULL) { - return default_value; - } - rid = sid->sub_auths[sid->num_auths-1]; - talloc_free(sid); - return rid; -} - -/* - pull a dom_sid structure from a objectSid in a result set. -*/ -struct dom_sid *samdb_result_dom_sid(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, - const char *attr) -{ - const struct ldb_val *v; - struct dom_sid *sid; - enum ndr_err_code ndr_err; - v = ldb_msg_find_ldb_val(msg, attr); - if (v == NULL) { - return NULL; - } - sid = talloc(mem_ctx, struct dom_sid); - if (sid == NULL) { - return NULL; - } - ndr_err = ndr_pull_struct_blob(v, sid, sid, - (ndr_pull_flags_fn_t)ndr_pull_dom_sid); - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - talloc_free(sid); - return NULL; - } - return sid; -} - -/* - pull a guid structure from a objectGUID in a result set. -*/ -struct GUID samdb_result_guid(const struct ldb_message *msg, const char *attr) -{ - const struct ldb_val *v; - enum ndr_err_code ndr_err; - struct GUID guid; - TALLOC_CTX *mem_ctx; - - ZERO_STRUCT(guid); - - v = ldb_msg_find_ldb_val(msg, attr); - if (!v) return guid; - - mem_ctx = talloc_named_const(NULL, 0, "samdb_result_guid"); - if (!mem_ctx) return guid; - ndr_err = ndr_pull_struct_blob(v, mem_ctx, &guid, - (ndr_pull_flags_fn_t)ndr_pull_GUID); - talloc_free(mem_ctx); - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - return guid; - } - - return guid; -} - -/* - pull a sid prefix from a objectSid in a result set. - this is used to find the domain sid for a user -*/ -struct dom_sid *samdb_result_sid_prefix(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, - const char *attr) -{ - struct dom_sid *sid = samdb_result_dom_sid(mem_ctx, msg, attr); - if (!sid || sid->num_auths < 1) return NULL; - sid->num_auths--; - return sid; -} - -/* - pull a NTTIME in a result set. -*/ -NTTIME samdb_result_nttime(struct ldb_message *msg, const char *attr, NTTIME default_value) -{ - return ldb_msg_find_attr_as_uint64(msg, attr, default_value); -} - -/* - pull a uint64_t from a result set. -*/ -uint64_t samdb_result_uint64(struct ldb_message *msg, const char *attr, uint64_t default_value) -{ - return ldb_msg_find_attr_as_uint64(msg, attr, default_value); -} - - -/* - construct the allow_password_change field from the PwdLastSet attribute and the - domain password settings -*/ -NTTIME samdb_result_allow_password_change(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *domain_dn, - struct ldb_message *msg, - const char *attr) -{ - uint64_t attr_time = samdb_result_uint64(msg, attr, 0); - int64_t minPwdAge; - - if (attr_time == 0) { - return 0; - } - - minPwdAge = samdb_search_int64(sam_ldb, mem_ctx, 0, domain_dn, "minPwdAge", NULL); - - /* yes, this is a -= not a += as minPwdAge is stored as the negative - of the number of 100-nano-seconds */ - attr_time -= minPwdAge; - - return attr_time; -} - -/* - construct the force_password_change field from the PwdLastSet attribute and the - domain password settings -*/ -NTTIME samdb_result_force_password_change(struct ldb_context *sam_ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *domain_dn, - struct ldb_message *msg) -{ - uint64_t attr_time = samdb_result_uint64(msg, "pwdLastSet", 0); - uint32_t user_flags = samdb_result_uint64(msg, "userAccountControl", 0); - int64_t maxPwdAge; - - if (user_flags & UF_DONT_EXPIRE_PASSWD) { - return 0x7FFFFFFFFFFFFFFFULL; - } - - if (attr_time == 0) { - return 0; - } - - maxPwdAge = samdb_search_int64(sam_ldb, mem_ctx, 0, domain_dn, "maxPwdAge", NULL); - if (maxPwdAge == 0) { - return 0; - } else { - attr_time -= maxPwdAge; - } - - return attr_time; -} - -/* - pull a samr_Password structutre from a result set. -*/ -struct samr_Password *samdb_result_hash(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr) -{ - struct samr_Password *hash = NULL; - const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); - if (val && (val->length >= sizeof(hash->hash))) { - hash = talloc(mem_ctx, struct samr_Password); - memcpy(hash->hash, val->data, MIN(val->length, sizeof(hash->hash))); - } - return hash; -} - -/* - pull an array of samr_Password structutres from a result set. -*/ -uint_t samdb_result_hashes(TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr, struct samr_Password **hashes) -{ - uint_t count = 0; - const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); - int i; - - *hashes = NULL; - if (!val) { - return 0; - } - count = val->length / 16; - if (count == 0) { - return 0; - } - - *hashes = talloc_array(mem_ctx, struct samr_Password, count); - if (! *hashes) { - return 0; - } - - for (i=0;i<count;i++) { - memcpy((*hashes)[i].hash, (i*16)+(char *)val->data, 16); - } - - return count; -} - -NTSTATUS samdb_result_passwords(TALLOC_CTX *mem_ctx, struct ldb_message *msg, - struct samr_Password **lm_pwd, struct samr_Password **nt_pwd) -{ - struct samr_Password *lmPwdHash, *ntPwdHash; - if (nt_pwd) { - int num_nt; - num_nt = samdb_result_hashes(mem_ctx, msg, "unicodePwd", &ntPwdHash); - if (num_nt == 0) { - *nt_pwd = NULL; - } else if (num_nt > 1) { - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } else { - *nt_pwd = &ntPwdHash[0]; - } - } - if (lm_pwd) { - int num_lm; - num_lm = samdb_result_hashes(mem_ctx, msg, "dBCSPwd", &lmPwdHash); - if (num_lm == 0) { - *lm_pwd = NULL; - } else if (num_lm > 1) { - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } else { - *lm_pwd = &lmPwdHash[0]; - } - } - return NT_STATUS_OK; -} - -/* - pull a samr_LogonHours structutre from a result set. -*/ -struct samr_LogonHours samdb_result_logon_hours(TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr) -{ - struct samr_LogonHours hours; - const int units_per_week = 168; - const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr); - ZERO_STRUCT(hours); - hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week); - if (!hours.bits) { - return hours; - } - hours.units_per_week = units_per_week; - memset(hours.bits, 0xFF, units_per_week); - if (val) { - memcpy(hours.bits, val->data, MIN(val->length, units_per_week)); - } - return hours; -} - -/* - pull a set of account_flags from a result set. -*/ -uint16_t samdb_result_acct_flags(struct ldb_message *msg, const char *attr) -{ - uint_t userAccountControl = ldb_msg_find_attr_as_uint(msg, attr, 0); - return samdb_uf2acb(userAccountControl); -} - - -/* Find an attribute, with a particular value */ - -/* The current callers of this function expect a very specific - * behaviour: In particular, objectClass subclass equivilance is not - * wanted. This means that we should not lookup the schema for the - * comparison function */ -struct ldb_message_element *samdb_find_attribute(struct ldb_context *ldb, - const struct ldb_message *msg, - const char *name, const char *value) -{ - int i; - struct ldb_message_element *el = ldb_msg_find_element(msg, name); - - if (!el) { - return NULL; - } - - for (i=0;i<el->num_values;i++) { - if (ldb_attr_cmp(value, (char *)el->values[i].data) == 0) { - return el; - } - } - - return NULL; -} - -int samdb_find_or_add_value(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value) -{ - if (samdb_find_attribute(ldb, msg, name, set_value) == NULL) { - return samdb_msg_add_string(ldb, msg, msg, name, set_value); - } - return LDB_SUCCESS; -} - -int samdb_find_or_add_attribute(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value) -{ - struct ldb_message_element *el; - - el = ldb_msg_find_element(msg, name); - if (el) { - return LDB_SUCCESS; - } - - return samdb_msg_add_string(ldb, msg, msg, name, set_value); -} - - -/* copy from a template record to a message */ int samdb_copy_template(struct ldb_context *ldb, @@ -795,1098 +178,6 @@ int samdb_copy_template(struct ldb_context *ldb, } -/* - add a string element to a message -*/ -int samdb_msg_add_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const char *str) -{ - char *s = talloc_strdup(mem_ctx, str); - char *a = talloc_strdup(mem_ctx, attr_name); - if (s == NULL || a == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - return ldb_msg_add_string(msg, a, s); -} - -/* - add a dom_sid element to a message -*/ -int samdb_msg_add_dom_sid(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, struct dom_sid *sid) -{ - struct ldb_val v; - enum ndr_err_code ndr_err; - - ndr_err = ndr_push_struct_blob(&v, mem_ctx, sid, - (ndr_push_flags_fn_t)ndr_push_dom_sid); - if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - return -1; - } - return ldb_msg_add_value(msg, attr_name, &v, NULL); -} - - -/* - add a delete element operation to a message -*/ -int samdb_msg_add_delete(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name) -{ - /* we use an empty replace rather than a delete, as it allows for - samdb_replace() to be used everywhere */ - return ldb_msg_add_empty(msg, attr_name, LDB_FLAG_MOD_REPLACE, NULL); -} - -/* - add a add attribute value to a message -*/ -int samdb_msg_add_addval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const char *value) -{ - struct ldb_message_element *el; - char *a, *v; - int ret; - a = talloc_strdup(mem_ctx, attr_name); - if (a == NULL) - return -1; - v = talloc_strdup(mem_ctx, value); - if (v == NULL) - return -1; - ret = ldb_msg_add_string(msg, a, v); - if (ret != 0) - return ret; - el = ldb_msg_find_element(msg, a); - if (el == NULL) - return -1; - el->flags = LDB_FLAG_MOD_ADD; - return 0; -} - -/* - add a delete attribute value to a message -*/ -int samdb_msg_add_delval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const char *value) -{ - struct ldb_message_element *el; - char *a, *v; - int ret; - a = talloc_strdup(mem_ctx, attr_name); - if (a == NULL) - return -1; - v = talloc_strdup(mem_ctx, value); - if (v == NULL) - return -1; - ret = ldb_msg_add_string(msg, a, v); - if (ret != 0) - return ret; - el = ldb_msg_find_element(msg, a); - if (el == NULL) - return -1; - el->flags = LDB_FLAG_MOD_DELETE; - return 0; -} - -/* - add a int element to a message -*/ -int samdb_msg_add_int(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, int v) -{ - const char *s = talloc_asprintf(mem_ctx, "%d", v); - return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); -} - -/* - add a uint_t element to a message -*/ -int samdb_msg_add_uint(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, uint_t v) -{ - const char *s = talloc_asprintf(mem_ctx, "%u", v); - return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); -} - -/* - add a (signed) int64_t element to a message -*/ -int samdb_msg_add_int64(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, int64_t v) -{ - const char *s = talloc_asprintf(mem_ctx, "%lld", (long long)v); - return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); -} - -/* - add a uint64_t element to a message -*/ -int samdb_msg_add_uint64(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, uint64_t v) -{ - const char *s = talloc_asprintf(mem_ctx, "%llu", (unsigned long long)v); - return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, s); -} - -/* - add a samr_Password element to a message -*/ -int samdb_msg_add_hash(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, struct samr_Password *hash) -{ - struct ldb_val val; - val.data = talloc_memdup(mem_ctx, hash->hash, 16); - if (!val.data) { - return -1; - } - val.length = 16; - return ldb_msg_add_value(msg, attr_name, &val, NULL); -} - -/* - add a samr_Password array to a message -*/ -int samdb_msg_add_hashes(TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, struct samr_Password *hashes, uint_t count) -{ - struct ldb_val val; - int i; - val.data = talloc_array_size(mem_ctx, 16, count); - val.length = count*16; - if (!val.data) { - return -1; - } - for (i=0;i<count;i++) { - memcpy(i*16 + (char *)val.data, hashes[i].hash, 16); - } - return ldb_msg_add_value(msg, attr_name, &val, NULL); -} - -/* - add a acct_flags element to a message -*/ -int samdb_msg_add_acct_flags(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, uint32_t v) -{ - return samdb_msg_add_uint(sam_ldb, mem_ctx, msg, attr_name, samdb_acb2uf(v)); -} - -/* - add a logon_hours element to a message -*/ -int samdb_msg_add_logon_hours(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, struct samr_LogonHours *hours) -{ - struct ldb_val val; - val.length = hours->units_per_week / 8; - val.data = hours->bits; - return ldb_msg_add_value(msg, attr_name, &val, NULL); -} - -/* - add a general value element to a message -*/ -int samdb_msg_add_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const struct ldb_val *val) -{ - return ldb_msg_add_value(msg, attr_name, val, NULL); -} - -/* - sets a general value element to a message -*/ -int samdb_msg_set_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const struct ldb_val *val) -{ - struct ldb_message_element *el; - - el = ldb_msg_find_element(msg, attr_name); - if (el) { - el->num_values = 0; - } - return ldb_msg_add_value(msg, attr_name, val, NULL); -} - -/* - set a string element in a message -*/ -int samdb_msg_set_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, const char *str) -{ - struct ldb_message_element *el; - - el = ldb_msg_find_element(msg, attr_name); - if (el) { - el->num_values = 0; - } - return samdb_msg_add_string(sam_ldb, mem_ctx, msg, attr_name, str); -} - -/* - replace elements in a record -*/ -int samdb_replace(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg) -{ - int i; - - /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ - for (i=0;i<msg->num_elements;i++) { - msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; - } - - /* modify the samdb record */ - return ldb_modify(sam_ldb, msg); -} - -/* - return a default security descriptor -*/ -struct security_descriptor *samdb_default_security_descriptor(TALLOC_CTX *mem_ctx) -{ - struct security_descriptor *sd; - - sd = security_descriptor_initialise(mem_ctx); - - return sd; -} - -struct ldb_dn *samdb_base_dn(struct ldb_context *sam_ctx) -{ - return ldb_get_default_basedn(sam_ctx); -} - -struct ldb_dn *samdb_config_dn(struct ldb_context *sam_ctx) -{ - return ldb_get_config_basedn(sam_ctx); -} - -struct ldb_dn *samdb_schema_dn(struct ldb_context *sam_ctx) -{ - return ldb_get_schema_basedn(sam_ctx); -} - -struct ldb_dn *samdb_root_dn(struct ldb_context *sam_ctx) -{ - return ldb_get_root_basedn(sam_ctx); -} - -struct ldb_dn *samdb_partitions_dn(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx) -{ - struct ldb_dn *new_dn; - - new_dn = ldb_dn_copy(mem_ctx, samdb_config_dn(sam_ctx)); - if ( ! ldb_dn_add_child_fmt(new_dn, "CN=Partitions")) { - talloc_free(new_dn); - return NULL; - } - return new_dn; -} - -struct ldb_dn *samdb_sites_dn(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx) -{ - struct ldb_dn *new_dn; - - new_dn = ldb_dn_copy(mem_ctx, samdb_config_dn(sam_ctx)); - if ( ! ldb_dn_add_child_fmt(new_dn, "CN=Sites")) { - talloc_free(new_dn); - return NULL; - } - return new_dn; -} - -/* - work out the domain sid for the current open ldb -*/ -const struct dom_sid *samdb_domain_sid(struct ldb_context *ldb) -{ - TALLOC_CTX *tmp_ctx; - struct dom_sid *domain_sid; - - /* see if we have a cached copy */ - domain_sid = (struct dom_sid *)ldb_get_opaque(ldb, "cache.domain_sid"); - if (domain_sid) { - return domain_sid; - } - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - /* find the domain_sid */ - domain_sid = samdb_search_dom_sid(ldb, tmp_ctx, ldb_get_default_basedn(ldb), - "objectSid", "objectClass=domainDNS"); - if (domain_sid == NULL) { - goto failed; - } - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.domain_sid", domain_sid) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, domain_sid); - talloc_free(tmp_ctx); - - return domain_sid; - -failed: - DEBUG(1,("Failed to find domain_sid for open ldb\n")); - talloc_free(tmp_ctx); - return NULL; -} - -bool samdb_set_domain_sid(struct ldb_context *ldb, const struct dom_sid *dom_sid_in) -{ - TALLOC_CTX *tmp_ctx; - struct dom_sid *dom_sid_new; - struct dom_sid *dom_sid_old; - - /* see if we have a cached copy */ - dom_sid_old = talloc_get_type(ldb_get_opaque(ldb, - "cache.domain_sid"), struct dom_sid); - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - dom_sid_new = dom_sid_dup(tmp_ctx, dom_sid_in); - if (!dom_sid_new) { - goto failed; - } - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.domain_sid", dom_sid_new) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, dom_sid_new); - talloc_free(tmp_ctx); - talloc_free(dom_sid_old); - - return true; - -failed: - DEBUG(1,("Failed to set our own cached domain SID in the ldb!\n")); - talloc_free(tmp_ctx); - return false; -} - -/* Obtain the short name of the flexible single master operator - * (FSMO), such as the PDC Emulator */ -const char *samdb_result_fsmo_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const struct ldb_message *msg, - const char *attr) -{ - /* Format is cn=NTDS Settings,cn=<NETBIOS name of FSMO>,.... */ - struct ldb_dn *fsmo_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, msg, attr); - const struct ldb_val *val = ldb_dn_get_component_val(fsmo_dn, 1); - const char *name = ldb_dn_get_component_name(fsmo_dn, 1); - - if (!name || (ldb_attr_cmp(name, "cn") != 0)) { - /* Ensure this matches the format. This gives us a - * bit more confidence that a 'cn' value will be a - * ascii string */ - return NULL; - } - if (val) { - return (char *)val->data; - } - return NULL; -} - -/* - work out the ntds settings dn for the current open ldb -*/ -struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb) -{ - TALLOC_CTX *tmp_ctx; - const char *root_attrs[] = { "dsServiceName", NULL }; - int ret; - struct ldb_result *root_res; - struct ldb_dn *settings_dn; - - /* see if we have a cached copy */ - settings_dn = (struct ldb_dn *)ldb_get_opaque(ldb, "cache.settings_dn"); - if (settings_dn) { - return settings_dn; - } - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - - ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, ""), LDB_SCOPE_BASE, NULL, root_attrs, &root_res); - if (ret) { - DEBUG(1,("Searching for dsServiceName in rootDSE failed: %s\n", - ldb_errstring(ldb))); - goto failed; - } - talloc_steal(tmp_ctx, root_res); - - if (root_res->count != 1) { - goto failed; - } - - settings_dn = ldb_msg_find_attr_as_dn(ldb, tmp_ctx, root_res->msgs[0], "dsServiceName"); - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.settings_dn", settings_dn) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, settings_dn); - talloc_free(tmp_ctx); - - return settings_dn; - -failed: - DEBUG(1,("Failed to find our own NTDS Settings DN in the ldb!\n")); - talloc_free(tmp_ctx); - return NULL; -} - -/* - work out the ntds settings invocationId for the current open ldb -*/ -const struct GUID *samdb_ntds_invocation_id(struct ldb_context *ldb) -{ - TALLOC_CTX *tmp_ctx; - const char *attrs[] = { "invocationId", NULL }; - int ret; - struct ldb_result *res; - struct GUID *invocation_id; - - /* see if we have a cached copy */ - invocation_id = (struct GUID *)ldb_get_opaque(ldb, "cache.invocation_id"); - if (invocation_id) { - return invocation_id; - } - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res); - if (ret) { - goto failed; - } - talloc_steal(tmp_ctx, res); - - if (res->count != 1) { - goto failed; - } - - invocation_id = talloc(tmp_ctx, struct GUID); - if (!invocation_id) { - goto failed; - } - - *invocation_id = samdb_result_guid(res->msgs[0], "invocationId"); - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.invocation_id", invocation_id) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, invocation_id); - talloc_free(tmp_ctx); - - return invocation_id; - -failed: - DEBUG(1,("Failed to find our own NTDS Settings invocationId in the ldb!\n")); - talloc_free(tmp_ctx); - return NULL; -} - -bool samdb_set_ntds_invocation_id(struct ldb_context *ldb, const struct GUID *invocation_id_in) -{ - TALLOC_CTX *tmp_ctx; - struct GUID *invocation_id_new; - struct GUID *invocation_id_old; - - /* see if we have a cached copy */ - invocation_id_old = (struct GUID *)ldb_get_opaque(ldb, - "cache.invocation_id"); - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - invocation_id_new = talloc(tmp_ctx, struct GUID); - if (!invocation_id_new) { - goto failed; - } - - *invocation_id_new = *invocation_id_in; - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.invocation_id", invocation_id_new) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, invocation_id_new); - talloc_free(tmp_ctx); - talloc_free(invocation_id_old); - - return true; - -failed: - DEBUG(1,("Failed to set our own cached invocationId in the ldb!\n")); - talloc_free(tmp_ctx); - return false; -} - -/* - work out the ntds settings objectGUID for the current open ldb -*/ -const struct GUID *samdb_ntds_objectGUID(struct ldb_context *ldb) -{ - TALLOC_CTX *tmp_ctx; - const char *attrs[] = { "objectGUID", NULL }; - int ret; - struct ldb_result *res; - struct GUID *ntds_guid; - - /* see if we have a cached copy */ - ntds_guid = (struct GUID *)ldb_get_opaque(ldb, "cache.ntds_guid"); - if (ntds_guid) { - return ntds_guid; - } - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res); - if (ret) { - goto failed; - } - talloc_steal(tmp_ctx, res); - - if (res->count != 1) { - goto failed; - } - - ntds_guid = talloc(tmp_ctx, struct GUID); - if (!ntds_guid) { - goto failed; - } - - *ntds_guid = samdb_result_guid(res->msgs[0], "objectGUID"); - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.ntds_guid", ntds_guid) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, ntds_guid); - talloc_free(tmp_ctx); - - return ntds_guid; - -failed: - DEBUG(1,("Failed to find our own NTDS Settings objectGUID in the ldb!\n")); - talloc_free(tmp_ctx); - return NULL; -} - -bool samdb_set_ntds_objectGUID(struct ldb_context *ldb, const struct GUID *ntds_guid_in) -{ - TALLOC_CTX *tmp_ctx; - struct GUID *ntds_guid_new; - struct GUID *ntds_guid_old; - - /* see if we have a cached copy */ - ntds_guid_old = (struct GUID *)ldb_get_opaque(ldb, "cache.ntds_guid"); - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - goto failed; - } - - ntds_guid_new = talloc(tmp_ctx, struct GUID); - if (!ntds_guid_new) { - goto failed; - } - - *ntds_guid_new = *ntds_guid_in; - - /* cache the domain_sid in the ldb */ - if (ldb_set_opaque(ldb, "cache.ntds_guid", ntds_guid_new) != LDB_SUCCESS) { - goto failed; - } - - talloc_steal(ldb, ntds_guid_new); - talloc_free(tmp_ctx); - talloc_free(ntds_guid_old); - - return true; - -failed: - DEBUG(1,("Failed to set our own cached invocationId in the ldb!\n")); - talloc_free(tmp_ctx); - return false; -} - -/* - work out the server dn for the current open ldb -*/ -struct ldb_dn *samdb_server_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) -{ - return ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb)); -} - -/* - work out the server dn for the current open ldb -*/ -struct ldb_dn *samdb_server_site_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) -{ - struct ldb_dn *server_dn; - struct ldb_dn *server_site_dn; - - server_dn = samdb_server_dn(ldb, mem_ctx); - if (!server_dn) return NULL; - - server_site_dn = ldb_dn_get_parent(mem_ctx, server_dn); - - talloc_free(server_dn); - return server_site_dn; -} - -/* - work out if we are the PDC for the domain of the current open ldb -*/ -bool samdb_is_pdc(struct ldb_context *ldb) -{ - const char *dom_attrs[] = { "fSMORoleOwner", NULL }; - int ret; - struct ldb_result *dom_res; - TALLOC_CTX *tmp_ctx; - bool is_pdc; - struct ldb_dn *pdc; - - tmp_ctx = talloc_new(ldb); - if (tmp_ctx == NULL) { - DEBUG(1, ("talloc_new failed in samdb_is_pdc")); - return false; - } - - ret = ldb_search(ldb, ldb_get_default_basedn(ldb), LDB_SCOPE_BASE, NULL, dom_attrs, &dom_res); - if (ret) { - DEBUG(1,("Searching for fSMORoleOwner in %s failed: %s\n", - ldb_dn_get_linearized(ldb_get_default_basedn(ldb)), - ldb_errstring(ldb))); - goto failed; - } - talloc_steal(tmp_ctx, dom_res); - if (dom_res->count != 1) { - goto failed; - } - - pdc = ldb_msg_find_attr_as_dn(ldb, tmp_ctx, dom_res->msgs[0], "fSMORoleOwner"); - - if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc) == 0) { - is_pdc = true; - } else { - is_pdc = false; - } - - talloc_free(tmp_ctx); - - return is_pdc; - -failed: - DEBUG(1,("Failed to find if we are the PDC for this ldb\n")); - talloc_free(tmp_ctx); - return false; -} - - -/* Find a domain object in the parents of a particular DN. */ -int samdb_search_for_parent_domain(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *dn, - struct ldb_dn **parent_dn, const char **errstring) -{ - TALLOC_CTX *local_ctx; - struct ldb_dn *sdn = dn; - struct ldb_result *res = NULL; - int ret = 0; - const char *attrs[] = { NULL }; - - local_ctx = talloc_new(mem_ctx); - if (local_ctx == NULL) return LDB_ERR_OPERATIONS_ERROR; - - while ((sdn = ldb_dn_get_parent(local_ctx, sdn))) { - ret = ldb_search(ldb, sdn, LDB_SCOPE_BASE, - "(|(objectClass=domain)(objectClass=builtinDomain))", attrs, &res); - if (ret == LDB_SUCCESS) { - talloc_steal(local_ctx, res); - if (res->count == 1) { - break; - } - } else { - break; - } - } - - if (ret != LDB_SUCCESS) { - *errstring = talloc_asprintf(mem_ctx, "Error searching for parent domain of %s, failed searching for %s: %s", - ldb_dn_get_linearized(dn), - ldb_dn_get_linearized(sdn), - ldb_errstring(ldb)); - talloc_free(local_ctx); - return ret; - } - if (res->count != 1) { - *errstring = talloc_asprintf(mem_ctx, "Invalid dn (%s), not child of a domain object", - ldb_dn_get_linearized(dn)); - talloc_free(local_ctx); - return LDB_ERR_CONSTRAINT_VIOLATION; - } - - *parent_dn = talloc_steal(mem_ctx, res->msgs[0]->dn); - talloc_free(local_ctx); - return ret; -} - -/* - check that a password is sufficiently complex -*/ -static bool samdb_password_complexity_ok(const char *pass) -{ - return check_password_quality(pass); -} - - - -/* - set the user password using plaintext, obeying any user or domain - password restrictions - - note that this function doesn't actually store the result in the - database, it just fills in the "mod" structure with ldb modify - elements to setup the correct change when samdb_replace() is - called. This allows the caller to combine the change with other - changes (as is needed by some of the set user info levels) - - The caller should probably have a transaction wrapping this -*/ -_PUBLIC_ NTSTATUS samdb_set_password(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, - struct ldb_dn *user_dn, - struct ldb_dn *domain_dn, - struct ldb_message *mod, - const char *new_pass, - struct samr_Password *lmNewHash, - struct samr_Password *ntNewHash, - bool user_change, - enum samr_RejectReason *reject_reason, - struct samr_DomInfo1 **_dominfo) -{ - const char * const user_attrs[] = { "userAccountControl", "lmPwdHistory", - "ntPwdHistory", - "dBCSPwd", "unicodePwd", - "objectSid", - "pwdLastSet", NULL }; - const char * const domain_attrs[] = { "pwdProperties", "pwdHistoryLength", - "maxPwdAge", "minPwdAge", - "minPwdLength", NULL }; - NTTIME pwdLastSet; - int64_t minPwdAge; - uint_t minPwdLength, pwdProperties, pwdHistoryLength; - uint_t userAccountControl; - struct samr_Password *sambaLMPwdHistory, *sambaNTPwdHistory, *lmPwdHash, *ntPwdHash; - struct samr_Password local_lmNewHash, local_ntNewHash; - int sambaLMPwdHistory_len, sambaNTPwdHistory_len; - struct dom_sid *domain_sid; - struct ldb_message **res; - bool restrictions; - int count; - time_t now = time(NULL); - NTTIME now_nt; - int i; - - /* we need to know the time to compute password age */ - unix_to_nt_time(&now_nt, now); - - /* pull all the user parameters */ - count = gendb_search_dn(ctx, mem_ctx, user_dn, &res, user_attrs); - if (count != 1) { - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - userAccountControl = samdb_result_uint(res[0], "userAccountControl", 0); - sambaLMPwdHistory_len = samdb_result_hashes(mem_ctx, res[0], - "lmPwdHistory", &sambaLMPwdHistory); - sambaNTPwdHistory_len = samdb_result_hashes(mem_ctx, res[0], - "ntPwdHistory", &sambaNTPwdHistory); - lmPwdHash = samdb_result_hash(mem_ctx, res[0], "dBCSPwd"); - ntPwdHash = samdb_result_hash(mem_ctx, res[0], "unicodePwd"); - pwdLastSet = samdb_result_uint64(res[0], "pwdLastSet", 0); - - /* Only non-trust accounts have restrictions (possibly this - * test is the wrong way around, but I like to be restrictive - * if possible */ - restrictions = !(userAccountControl & (UF_INTERDOMAIN_TRUST_ACCOUNT - |UF_WORKSTATION_TRUST_ACCOUNT - |UF_SERVER_TRUST_ACCOUNT)); - - if (domain_dn) { - /* pull the domain parameters */ - count = gendb_search_dn(ctx, mem_ctx, domain_dn, &res, domain_attrs); - if (count != 1) { - DEBUG(2, ("samdb_set_password: Domain DN %s is invalid, for user %s\n", - ldb_dn_get_linearized(domain_dn), - ldb_dn_get_linearized(user_dn))); - return NT_STATUS_NO_SUCH_DOMAIN; - } - } else { - /* work out the domain sid, and pull the domain from there */ - domain_sid = samdb_result_sid_prefix(mem_ctx, res[0], "objectSid"); - if (domain_sid == NULL) { - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - - count = gendb_search(ctx, mem_ctx, NULL, &res, domain_attrs, - "(objectSid=%s)", - ldap_encode_ndr_dom_sid(mem_ctx, domain_sid)); - if (count != 1) { - DEBUG(2, ("samdb_set_password: Could not find domain to match SID: %s, for user %s\n", - dom_sid_string(mem_ctx, domain_sid), - ldb_dn_get_linearized(user_dn))); - return NT_STATUS_NO_SUCH_DOMAIN; - } - } - - pwdProperties = samdb_result_uint(res[0], "pwdProperties", 0); - pwdHistoryLength = samdb_result_uint(res[0], "pwdHistoryLength", 0); - minPwdLength = samdb_result_uint(res[0], "minPwdLength", 0); - minPwdAge = samdb_result_int64(res[0], "minPwdAge", 0); - - if (_dominfo) { - struct samr_DomInfo1 *dominfo; - /* on failure we need to fill in the reject reasons */ - dominfo = talloc(mem_ctx, struct samr_DomInfo1); - if (dominfo == NULL) { - return NT_STATUS_NO_MEMORY; - } - dominfo->min_password_length = minPwdLength; - dominfo->password_properties = pwdProperties; - dominfo->password_history_length = pwdHistoryLength; - dominfo->max_password_age = minPwdAge; - dominfo->min_password_age = minPwdAge; - *_dominfo = dominfo; - } - - if (restrictions && new_pass) { - - /* check the various password restrictions */ - if (restrictions && minPwdLength > strlen_m(new_pass)) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_TOO_SHORT; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - - /* possibly check password complexity */ - if (restrictions && pwdProperties & DOMAIN_PASSWORD_COMPLEX && - !samdb_password_complexity_ok(new_pass)) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_COMPLEXITY; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - - /* compute the new nt and lm hashes */ - if (E_deshash(new_pass, local_lmNewHash.hash)) { - lmNewHash = &local_lmNewHash; - } - if (!E_md4hash(new_pass, local_ntNewHash.hash)) { - /* If we can't convert this password to UCS2, then we should not accept it */ - if (reject_reason) { - *reject_reason = SAMR_REJECT_OTHER; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - ntNewHash = &local_ntNewHash; - } - - if (user_change) { - /* are all password changes disallowed? */ - if (pwdProperties & DOMAIN_REFUSE_PASSWORD_CHANGE) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_OTHER; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - - /* can this user change password? */ - if (userAccountControl & UF_PASSWD_CANT_CHANGE) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_OTHER; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - - /* yes, this is a minus. The ages are in negative 100nsec units! */ - if (pwdLastSet - minPwdAge > now_nt) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_OTHER; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - - /* check the immediately past password */ - if (pwdHistoryLength > 0) { - if (lmNewHash && lmPwdHash && memcmp(lmNewHash->hash, lmPwdHash->hash, 16) == 0) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_IN_HISTORY; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - if (ntNewHash && ntPwdHash && memcmp(ntNewHash->hash, ntPwdHash->hash, 16) == 0) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_IN_HISTORY; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - } - - /* check the password history */ - sambaLMPwdHistory_len = MIN(sambaLMPwdHistory_len, pwdHistoryLength); - sambaNTPwdHistory_len = MIN(sambaNTPwdHistory_len, pwdHistoryLength); - - for (i=0; lmNewHash && i<sambaLMPwdHistory_len;i++) { - if (memcmp(lmNewHash->hash, sambaLMPwdHistory[i].hash, 16) == 0) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_IN_HISTORY; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - } - for (i=0; ntNewHash && i<sambaNTPwdHistory_len;i++) { - if (memcmp(ntNewHash->hash, sambaNTPwdHistory[i].hash, 16) == 0) { - if (reject_reason) { - *reject_reason = SAMR_REJECT_IN_HISTORY; - } - return NT_STATUS_PASSWORD_RESTRICTION; - } - } - } - -#define CHECK_RET(x) do { if (x != 0) return NT_STATUS_NO_MEMORY; } while(0) - - /* the password is acceptable. Start forming the new fields */ - if (new_pass) { - /* if we know the cleartext, then only set it. - * Modules in ldb will set all the appropriate - * hashes */ - CHECK_RET(samdb_msg_add_string(ctx, mem_ctx, mod, - "sambaPassword", new_pass)); - } else { - /* We don't have the cleartext, so delete the old one - * and set what we have of the hashes */ - CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "sambaPassword")); - - if (lmNewHash) { - CHECK_RET(samdb_msg_add_hash(ctx, mem_ctx, mod, "dBCSPwd", lmNewHash)); - } else { - CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "dBCSPwd")); - } - - if (ntNewHash) { - CHECK_RET(samdb_msg_add_hash(ctx, mem_ctx, mod, "unicodePwd", ntNewHash)); - } else { - CHECK_RET(samdb_msg_add_delete(ctx, mem_ctx, mod, "unicodePwd")); - } - } - - return NT_STATUS_OK; -} - - -/* - set the user password using plaintext, obeying any user or domain - password restrictions - - This wrapper function takes a SID as input, rather than a user DN, - and actually performs the password change - -*/ -_PUBLIC_ NTSTATUS samdb_set_password_sid(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, - const struct dom_sid *user_sid, - const char *new_pass, - struct samr_Password *lmNewHash, - struct samr_Password *ntNewHash, - bool user_change, - enum samr_RejectReason *reject_reason, - struct samr_DomInfo1 **_dominfo) -{ - NTSTATUS nt_status; - struct ldb_dn *user_dn; - struct ldb_message *msg; - int ret; - - ret = ldb_transaction_start(ctx); - if (ret) { - DEBUG(1, ("Failed to start transaction: %s\n", ldb_errstring(ctx))); - return NT_STATUS_TRANSACTION_ABORTED; - } - - user_dn = samdb_search_dn(ctx, mem_ctx, NULL, - "(&(objectSid=%s)(objectClass=user))", - ldap_encode_ndr_dom_sid(mem_ctx, user_sid)); - if (!user_dn) { - ldb_transaction_cancel(ctx); - DEBUG(3, ("samdb_set_password_sid: SID %s not found in samdb, returning NO_SUCH_USER\n", - dom_sid_string(mem_ctx, user_sid))); - return NT_STATUS_NO_SUCH_USER; - } - - msg = ldb_msg_new(mem_ctx); - if (msg == NULL) { - ldb_transaction_cancel(ctx); - return NT_STATUS_NO_MEMORY; - } - - msg->dn = ldb_dn_copy(msg, user_dn); - if (!msg->dn) { - ldb_transaction_cancel(ctx); - return NT_STATUS_NO_MEMORY; - } - - nt_status = samdb_set_password(ctx, mem_ctx, - user_dn, NULL, - msg, new_pass, - lmNewHash, ntNewHash, - user_change, /* This is a password set, not change */ - reject_reason, _dominfo); - if (!NT_STATUS_IS_OK(nt_status)) { - ldb_transaction_cancel(ctx); - return nt_status; - } - - /* modify the samdb record */ - ret = samdb_replace(ctx, mem_ctx, msg); - if (ret != 0) { - ldb_transaction_cancel(ctx); - return NT_STATUS_ACCESS_DENIED; - } - - ret = ldb_transaction_commit(ctx); - if (ret != 0) { - DEBUG(0,("Failed to commit transaction to change password on %s: %s\n", - ldb_dn_get_linearized(msg->dn), - ldb_errstring(ctx))); - return NT_STATUS_TRANSACTION_ABORTED; - } - return NT_STATUS_OK; -} - /**************************************************************************** Create the SID list for this user. ****************************************************************************/ @@ -1961,153 +252,3 @@ NTSTATUS security_token_create(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } - - -NTSTATUS samdb_create_foreign_security_principal(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx, - struct dom_sid *sid, struct ldb_dn **ret_dn) -{ - struct ldb_message *msg; - struct ldb_dn *basedn; - const char *sidstr; - int ret; - - sidstr = dom_sid_string(mem_ctx, sid); - NT_STATUS_HAVE_NO_MEMORY(sidstr); - - /* We might have to create a ForeignSecurityPrincipal, even if this user - * is in our own domain */ - - msg = ldb_msg_new(mem_ctx); - if (msg == NULL) { - return NT_STATUS_NO_MEMORY; - } - - /* TODO: Hmmm. This feels wrong. How do I find the base dn to - * put the ForeignSecurityPrincipals? d_state->domain_dn does - * not work, this is wrong for the Builtin domain, there's no - * cn=For...,cn=Builtin,dc={BASEDN}. -- vl - */ - - basedn = samdb_search_dn(sam_ctx, mem_ctx, NULL, - "(&(objectClass=container)(cn=ForeignSecurityPrincipals))"); - - if (basedn == NULL) { - DEBUG(0, ("Failed to find DN for " - "ForeignSecurityPrincipal container\n")); - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - - /* add core elements to the ldb_message for the alias */ - msg->dn = ldb_dn_copy(mem_ctx, basedn); - if ( ! ldb_dn_add_child_fmt(msg->dn, "CN=%s", sidstr)) - return NT_STATUS_NO_MEMORY; - - samdb_msg_add_string(sam_ctx, mem_ctx, msg, - "objectClass", - "foreignSecurityPrincipal"); - - /* create the alias */ - ret = ldb_add(sam_ctx, msg); - if (ret != 0) { - DEBUG(0,("Failed to create foreignSecurityPrincipal " - "record %s: %s\n", - ldb_dn_get_linearized(msg->dn), - ldb_errstring(sam_ctx))); - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - *ret_dn = msg->dn; - return NT_STATUS_OK; -} - - -/* - Find the DN of a domain, assuming it to be a dotted.dns name -*/ - -struct ldb_dn *samdb_dns_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *dns_domain) -{ - int i; - TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); - const char *binary_encoded; - const char **split_realm; - struct ldb_dn *dn; - - if (!tmp_ctx) { - return NULL; - } - - split_realm = str_list_make(tmp_ctx, dns_domain, "."); - if (!split_realm) { - talloc_free(tmp_ctx); - return NULL; - } - dn = ldb_dn_new(mem_ctx, ldb, NULL); - for (i=0; split_realm[i]; i++) { - binary_encoded = ldb_binary_encode_string(tmp_ctx, split_realm[i]); - if (!ldb_dn_add_base_fmt(dn, "dc=%s", binary_encoded)) { - DEBUG(2, ("Failed to add dc=%s element to DN %s\n", - binary_encoded, ldb_dn_get_linearized(dn))); - talloc_free(tmp_ctx); - return NULL; - } - } - if (!ldb_dn_validate(dn)) { - DEBUG(2, ("Failed to validated DN %s\n", - ldb_dn_get_linearized(dn))); - return NULL; - } - return dn; -} -/* - Find the DN of a domain, be it the netbios or DNS name -*/ - -struct ldb_dn *samdb_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, - const char *domain_name) -{ - const char * const domain_ref_attrs[] = { - "ncName", NULL - }; - const char * const domain_ref2_attrs[] = { - NULL - }; - struct ldb_result *res_domain_ref; - char *escaped_domain = ldb_binary_encode_string(mem_ctx, domain_name); - /* find the domain's DN */ - int ret_domain = ldb_search_exp_fmt(ldb, mem_ctx, - &res_domain_ref, - samdb_partitions_dn(ldb, mem_ctx), - LDB_SCOPE_ONELEVEL, - domain_ref_attrs, - "(&(nETBIOSName=%s)(objectclass=crossRef))", - escaped_domain); - if (ret_domain != 0) { - return NULL; - } - - if (res_domain_ref->count == 0) { - ret_domain = ldb_search_exp_fmt(ldb, mem_ctx, - &res_domain_ref, - samdb_dns_domain_to_dn(ldb, mem_ctx, domain_name), - LDB_SCOPE_BASE, - domain_ref2_attrs, - "(objectclass=domain)"); - if (ret_domain != 0) { - return NULL; - } - - if (res_domain_ref->count == 1) { - return res_domain_ref->msgs[0]->dn; - } - return NULL; - } - - if (res_domain_ref->count > 1) { - DEBUG(0,("Found %d records matching domain [%s]\n", - ret_domain, domain_name)); - return NULL; - } - - return samdb_result_dn(ldb, mem_ctx, res_domain_ref->msgs[0], "nCName", NULL); - -} diff --git a/source4/dsdb/samdb/samdb.h b/source4/dsdb/samdb/samdb.h index 54d1ce2e75..5d8694d2d4 100644 --- a/source4/dsdb/samdb/samdb.h +++ b/source4/dsdb/samdb/samdb.h @@ -35,6 +35,7 @@ struct loadparm_context; #include "librpc/gen_ndr/drsblobs.h" #include "dsdb/schema/schema.h" #include "dsdb/samdb/samdb_proto.h" +#include "dsdb/common/proto.h" #define DSDB_CONTROL_CURRENT_PARTITION_OID "1.3.6.1.4.1.7165.4.3.2" struct dsdb_control_current_partition { diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h index 1125f775ff..1379ddee9f 100644 --- a/source4/dsdb/schema/schema.h +++ b/source4/dsdb/schema/schema.h @@ -151,4 +151,6 @@ struct dsdb_schema { struct dsdb_class *classes; }; +#include "dsdb/schema/proto.h" + #endif /* _DSDB_SCHEMA_H */ diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c index 278f18cf0d..f15b03c9b4 100644 --- a/source4/dsdb/schema/schema_init.c +++ b/source4/dsdb/schema/schema_init.c @@ -3,7 +3,8 @@ DSDB schema header Copyright (C) Stefan Metzmacher <metze@samba.org> 2006 - + Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or @@ -26,6 +27,7 @@ #include "librpc/gen_ndr/ndr_misc.h" #include "librpc/gen_ndr/ndr_drsuapi.h" #include "librpc/gen_ndr/ndr_drsblobs.h" +#include "param/param.h" WERROR dsdb_load_oid_mappings_drsuapi(struct dsdb_schema *schema, const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr) { @@ -619,7 +621,7 @@ static struct drsuapi_DsReplicaAttribute *dsdb_find_object_attr_name(struct dsdb } \ if (_a && _a->value_ctr.num_values >= 1) { \ ssize_t _ret; \ - _ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, \ + _ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, \ _a->value_ctr.values[0].blob->data, \ _a->value_ctr.values[0].blob->length, \ (void **)discard_const(&(p)->elem)); \ @@ -1038,6 +1040,11 @@ WERROR dsdb_linked_attribute_lDAPDisplayName_list(const struct dsdb_schema *sche return WERR_OK; } +/** + * Attach the schema to an opaque pointer on the ldb, so ldb modules + * can find it + */ + int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema) { int ret; @@ -1052,8 +1059,14 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema) return LDB_SUCCESS; } +/** + * Global variable to hold one copy of the schema, used to avoid memory bloat + */ static struct dsdb_schema *global_schema; +/** + * Make this ldb use the 'global' schema, setup to avoid having multiple copies in this process + */ int dsdb_set_global_schema(struct ldb_context *ldb) { int ret; @@ -1068,10 +1081,14 @@ int dsdb_set_global_schema(struct ldb_context *ldb) return LDB_SUCCESS; } -const struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb) +/** + * Find the schema object for this ldb + */ + +struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb) { const void *p; - const struct dsdb_schema *schema; + struct dsdb_schema *schema; /* see if we have a cached copy */ p = ldb_get_opaque(ldb, "dsdb_schema"); @@ -1087,18 +1104,13 @@ const struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb) return schema; } +/** + * Make the schema found on this ldb the 'global' schema + */ + void dsdb_make_schema_global(struct ldb_context *ldb) { - const void *p; - const struct dsdb_schema *schema; - - /* see if we have a cached copy */ - p = ldb_get_opaque(ldb, "dsdb_schema"); - if (!p) { - return; - } - - schema = talloc_get_type(p, struct dsdb_schema); + struct dsdb_schema *schema = dsdb_get_schema(ldb); if (!schema) { return; } @@ -1109,6 +1121,13 @@ void dsdb_make_schema_global(struct ldb_context *ldb) dsdb_set_global_schema(ldb); } + +/** + * Rather than read a schema from the LDB itself, read it from an ldif + * file. This allows schema to be loaded and used while adding the + * schema itself to the directory. + */ + WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf, const char *df) { struct ldb_ldif *ldif; diff --git a/source4/dsdb/schema/schema_syntax.c b/source4/dsdb/schema/schema_syntax.c index 749064d5cf..a8fe4a3b9d 100644 --- a/source4/dsdb/schema/schema_syntax.c +++ b/source4/dsdb/schema/schema_syntax.c @@ -25,6 +25,7 @@ #include "system/time.h" #include "lib/charset/charset.h" #include "librpc/ndr/libndr.h" +#include "param/param.h" static WERROR dsdb_syntax_FOOBAR_drsuapi_to_ldb(const struct dsdb_schema *schema, const struct dsdb_attribute *attr, @@ -766,7 +767,7 @@ static WERROR dsdb_syntax_UNICODE_drsuapi_to_ldb(const struct dsdb_schema *schem return WERR_FOOBAR; } - ret = convert_string_talloc(out->values, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + ret = convert_string_talloc(out->values, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, in->value_ctr.values[i].blob->data, in->value_ctr.values[i].blob->length, (void **)&str); @@ -808,7 +809,7 @@ static WERROR dsdb_syntax_UNICODE_ldb_to_drsuapi(const struct dsdb_schema *schem out->value_ctr.values[i].blob = &blobs[i]; - ret = convert_string_talloc(blobs, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + ret = convert_string_talloc(blobs, lp_iconv_convenience(global_loadparm), CH_UNIX, CH_UTF16, in->values[i].data, in->values[i].length, (void **)&blobs[i].data); @@ -1043,7 +1044,7 @@ static WERROR dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb(const struct dsdb_ return WERR_FOOBAR; } - ret = convert_string_talloc(out->values, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + ret = convert_string_talloc(out->values, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, in->value_ctr.values[i].blob->data+4, in->value_ctr.values[i].blob->length-4, (void **)&str); @@ -1086,7 +1087,7 @@ static WERROR dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi(const struct dsdb_ out->value_ctr.values[i].blob = &blobs[i]; - ret = convert_string_talloc(blobs, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + ret = convert_string_talloc(blobs, lp_iconv_convenience(global_loadparm), CH_UNIX, CH_UTF16, in->values[i].data, in->values[i].length, (void **)&data); diff --git a/source4/headermap.txt b/source4/headermap.txt index a5ec108359..6ace20519f 100644 --- a/source4/headermap.txt +++ b/source4/headermap.txt @@ -100,6 +100,9 @@ param/proto.h: param/proto.h param/param.h: param.h dsdb/samdb/samdb.h: samdb.h dsdb/samdb/samdb_proto.h: samdb/proto.h +dsdb/schema/schema.h: samdb/schema.h +dsdb/schema/proto.h: samdb/schema_proto.h +dsdb/common/proto.h: samdb/common_proto.h libcli/util/asn_1.h: samba/asn1.h libcli/util/asn1_proto.h: samba/asn1/proto.h libcli/util/error.h: core/error.h diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index ce5fa6e98e..b534c9bc9f 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -429,7 +429,7 @@ PUBLIC_DEPENDENCIES = \ [SUBSYSTEM::HEIMDAL_GLUE] CFLAGS = -Iheimdal_build -Iheimdal/lib/krb5 -Iheimdal/lib/asn1 -Iheimdal/lib/com_err OBJ_FILES = glue.o -PUBLIC_DEPENDENCIES = LIBNETIF +PUBLIC_DEPENDENCIES = LIBNETIF LIBSAMBA-CONFIG # End SUBSYSTEM HEIMDAL_GLUE ####################### diff --git a/source4/heimdal_build/glue.c b/source4/heimdal_build/glue.c index df08cae57c..07062ae8bf 100644 --- a/source4/heimdal_build/glue.c +++ b/source4/heimdal_build/glue.c @@ -31,22 +31,30 @@ krb5_error_code KRB5_LIB_FUNCTION krb5_get_all_client_addrs(krb5_context context, krb5_addresses *res) { int i; - res->len = iface_count(global_loadparm); + struct interface *ifaces; + + load_interfaces(NULL, lp_interfaces(global_loadparm), &ifaces); + + res->len = iface_count(ifaces); res->val = malloc_array_p(HostAddress, res->len); if (res->val == NULL) { + talloc_free(ifaces); return ENOMEM; } for (i=0;i<res->len;i++) { - const char *ip = iface_n_ip(global_loadparm, i); + const char *ip = iface_n_ip(ifaces, i); res->val[i].addr_type = AF_INET; res->val[i].address.length = 4; res->val[i].address.data = malloc(4); if (res->val[i].address.data == NULL) { + talloc_free(ifaces); return ENOMEM; } ((struct in_addr *)res->val[i].address.data)->s_addr = inet_addr(ip); } + talloc_free(ifaces); + return 0; } diff --git a/source4/kdc/config.mk b/source4/kdc/config.mk index 52a377dbba..c787343515 100644 --- a/source4/kdc/config.mk +++ b/source4/kdc/config.mk @@ -22,7 +22,7 @@ OBJ_FILES = \ hdb-ldb.o \ pac-glue.o PRIVATE_DEPENDENCIES = \ - LIBLDB auth_sam auth_sam_reply KERBEROS + LIBLDB auth_sam auth_sam_reply KERBEROS CREDENTIALS # End SUBSYSTEM KDC ####################### diff --git a/source4/kdc/kdc.c b/source4/kdc/kdc.c index 18fc86b8e0..5c8b2afe0f 100644 --- a/source4/kdc/kdc.c +++ b/source4/kdc/kdc.c @@ -520,16 +520,18 @@ static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address, /* setup our listening sockets on the configured network interfaces */ -static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx) +static NTSTATUS kdc_startup_interfaces(struct kdc_server *kdc, struct loadparm_context *lp_ctx, + struct interface *ifaces) { - int num_interfaces = iface_count(lp_ctx); + int num_interfaces; TALLOC_CTX *tmp_ctx = talloc_new(kdc); NTSTATUS status; - int i; + + num_interfaces = iface_count(ifaces); for (i=0; i<num_interfaces; i++) { - const char *address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i)); + const char *address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i)); status = kdc_add_socket(kdc, address, lp_krb5_port(lp_ctx), lp_kpasswd_port(lp_ctx)); NT_STATUS_NOT_OK_RETURN(status); @@ -558,6 +560,7 @@ static void kdc_task_init(struct task_server *task) struct kdc_server *kdc; NTSTATUS status; krb5_error_code ret; + struct interface *ifaces; switch (lp_server_role(task->lp_ctx)) { case ROLE_STANDALONE: @@ -571,7 +574,9 @@ static void kdc_task_init(struct task_server *task) break; } - if (iface_count(task->lp_ctx) == 0) { + load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces); + + if (iface_count(ifaces) == 0) { task_server_terminate(task, "kdc: no network interfaces configured"); return; } @@ -641,7 +646,7 @@ static void kdc_task_init(struct task_server *task) kdc_mem_ctx = kdc->smb_krb5_context; /* start listening on the configured network interfaces */ - status = kdc_startup_interfaces(kdc, task->lp_ctx); + status = kdc_startup_interfaces(kdc, task->lp_ctx, ifaces); if (!NT_STATUS_IS_OK(status)) { task_server_terminate(task, "kdc failed to setup interfaces"); return; diff --git a/source4/kdc/kpasswdd.c b/source4/kdc/kpasswdd.c index c8c569b7ed..f468fea6c4 100644 --- a/source4/kdc/kpasswdd.c +++ b/source4/kdc/kpasswdd.c @@ -62,7 +62,7 @@ static bool kpasswdd_make_error_reply(struct kdc_server *kdc, DEBUG(result_code ? 3 : 10, ("kpasswdd: %s\n", error_string)); - len = push_utf8_talloc(mem_ctx, global_smb_iconv_convenience, &error_string_utf8, error_string); + len = push_utf8_talloc(mem_ctx, lp_iconv_convenience(kdc->task->lp_ctx), &error_string_utf8, error_string); if (len == -1) { return false; } @@ -474,7 +474,7 @@ bool kpasswdd_process(struct kdc_server *kdc, * we already have, rather than a new context */ cli_credentials_set_krb5_context(server_credentials, kdc->smb_krb5_context); cli_credentials_set_conf(server_credentials, kdc->task->lp_ctx); - nt_status = cli_credentials_set_stored_principal(server_credentials, "kadmin/changepw"); + nt_status = cli_credentials_set_stored_principal(server_credentials, kdc->task->lp_ctx, "kadmin/changepw"); if (!NT_STATUS_IS_OK(nt_status)) { ret = kpasswdd_make_unauth_error_reply(kdc, mem_ctx, KRB5_KPASSWD_HARDERROR, diff --git a/source4/ldap_server/config.mk b/source4/ldap_server/config.mk index 51650a116f..9892376821 100644 --- a/source4/ldap_server/config.mk +++ b/source4/ldap_server/config.mk @@ -14,6 +14,7 @@ OBJ_FILES = \ PRIVATE_DEPENDENCIES = CREDENTIALS \ LIBCLI_LDAP SAMDB \ process_model \ - GENSEC_SOCKET + gensec \ + LIBSAMBA-CONFIG # End SUBSYSTEM SMB ####################### diff --git a/source4/ldap_server/ldap_bind.c b/source4/ldap_server/ldap_bind.c index 53cef5b349..f2c974ae3f 100644 --- a/source4/ldap_server/ldap_bind.c +++ b/source4/ldap_server/ldap_bind.c @@ -26,7 +26,6 @@ #include "lib/ldb/include/ldb_errors.h" #include "dsdb/samdb/samdb.h" #include "auth/gensec/gensec.h" -#include "auth/gensec/socket.h" #include "param/param.h" static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call) diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c index 99889f1f7f..a2521ca406 100644 --- a/source4/ldap_server/ldap_server.c +++ b/source4/ldap_server/ldap_server.c @@ -397,7 +397,7 @@ static void ldapsrv_accept(struct stream_connection *c) } cli_credentials_set_conf(server_credentials, conn->lp_ctx); - status = cli_credentials_set_machine_account(server_credentials); + status = cli_credentials_set_machine_account(server_credentials, conn->lp_ctx); if (!NT_STATUS_IS_OK(status)) { stream_terminate_connection(c, talloc_asprintf(conn, "Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(status))); return; @@ -546,15 +546,19 @@ static void ldapsrv_task_init(struct task_server *task) if (ldap_service->tls_params == NULL) goto failed; if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) { - int num_interfaces = iface_count(task->lp_ctx); + struct interface *ifaces; + int num_interfaces; int i; + load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces); + num_interfaces = iface_count(ifaces); + /* We have been given an interfaces line, and been told to only bind to those interfaces. Create a socket per interface and bind to only these. */ for(i = 0; i < num_interfaces; i++) { - const char *address = iface_n_ip(task->lp_ctx, i); + const char *address = iface_n_ip(ifaces, i); status = add_socket(task->event_ctx, task->lp_ctx, model_ops, address, ldap_service); if (!NT_STATUS_IS_OK(status)) goto failed; } diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 83bd11563f..54a0676599 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -42,7 +42,6 @@ struct smb_iconv_convenience { const char *unix_charset; const char *dos_charset; - const char *display_charset; bool native_iconv; smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; }; @@ -57,7 +56,6 @@ static const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) case CH_UTF16: return "UTF-16LE"; case CH_UNIX: return ic->unix_charset; case CH_DOS: return ic->dos_charset; - case CH_DISPLAY: return ic->display_charset; case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; default: @@ -88,7 +86,6 @@ static int close_iconv(struct smb_iconv_convenience *data) struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, const char *dos_charset, const char *unix_charset, - const char *display_charset, bool native_iconv) { struct smb_iconv_convenience *ret = talloc_zero(mem_ctx, @@ -102,7 +99,6 @@ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, ret->dos_charset = talloc_strdup(ret, dos_charset); ret->unix_charset = talloc_strdup(ret, unix_charset); - ret->display_charset = talloc_strdup(ret, display_charset); ret->native_iconv = native_iconv; return ret; @@ -115,10 +111,10 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, charset_t from, charset_t to) { const char *n1, *n2; - static int initialised; + static bool initialised; - if (initialised == 0) { - initialised = 1; + if (initialised == false) { + initialised = true; #ifdef LC_ALL /* we set back the locale to C to get ASCII-compatible @@ -138,7 +134,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, n1 = charset_name(ic, from); n2 = charset_name(ic, to); - ic->conv_handles[from][to] = smb_iconv_open(n2, n1, ic->native_iconv); + ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, + ic->native_iconv); if (ic->conv_handles[from][to] == (smb_iconv_t)-1) { if ((from == CH_DOS || to == CH_DOS) && @@ -150,8 +147,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, n1 = charset_name(ic, from); n2 = charset_name(ic, to); - ic->conv_handles[from][to] = smb_iconv_open(n2, n1, - ic->native_iconv); + ic->conv_handles[from][to] = + smb_iconv_open_ex(ic, n2, n1, ic->native_iconv); } } diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index b1bb18a7c8..1d42a0ad91 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -24,9 +24,9 @@ #include <talloc.h> /* this defines the charset types used in samba */ -typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; +typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE} charset_t; -#define NUM_CHARSETS 6 +#define NUM_CHARSETS 5 /* * for each charset we have a function that pulls from that charset to diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index b2035672ba..4f0c80c79d 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -9,6 +9,5 @@ PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG -LDFLAGS = bin/static/libsamba-config.a bin/static/libsamba-util.a # End SUBSYSTEM CHARSET ################################################ diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 937b3ec8b5..db212a83c4 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -154,17 +154,17 @@ static bool is_utf16(const char *name) strcasecmp(name, "UTF-16LE") == 0; } -/* - simple iconv_open() wrapper - */ -smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode, - bool native_iconv) + + +smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, + const char *fromcode, bool native_iconv) { smb_iconv_t ret; const struct charset_functions *from=NULL, *to=NULL; int i; - ret = (smb_iconv_t)talloc_named(NULL, sizeof(*ret), + ret = (smb_iconv_t)talloc_named(mem_ctx, + sizeof(*ret), "iconv(%s,%s)", tocode, fromcode); if (!ret) { errno = ENOMEM; @@ -261,6 +261,14 @@ failed: } /* + simple iconv_open() wrapper + */ +smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) +{ + return smb_iconv_open_ex(NULL, tocode, fromcode, true); +} + +/* simple iconv_close() wrapper */ int smb_iconv_close(smb_iconv_t cd) diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index ca13dc503a..aeb42c2fa1 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -157,8 +157,8 @@ static bool test_buffer(struct torture_context *test, "failed to open %s to UTF-16LE", charset)); } - cd2 = smb_iconv_open(charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); - cd3 = smb_iconv_open("UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); + cd2 = smb_iconv_open_ex(test, charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); + cd3 = smb_iconv_open_ex(test, "UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); last_charset = charset; } @@ -288,7 +288,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) size_t size, size2; codepoint_t c; - size = push_codepoint(global_smb_iconv_convenience, (char *)buf, codepoint); + size = push_codepoint(lp_iconv_convenience(tctx->lp_ctx), (char *)buf, codepoint); torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), "Invalid Codepoint range"); @@ -299,7 +299,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) buf[size+2] = random(); buf[size+3] = random(); - c = next_codepoint(global_smb_iconv_convenience, (char *)buf, &size2); + c = next_codepoint(lp_iconv_convenience(tctx->lp_ctx), (char *)buf, &size2); torture_assert(tctx, c == codepoint, talloc_asprintf(tctx, diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 67a790c250..e0e1aed222 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -21,6 +21,7 @@ #include "includes.h" #include "system/locale.h" #include "dynconfig.h" +#include "param/param.h" /** * @file @@ -129,8 +130,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (s2 == NULL) return 1; while (*s1 && *s2) { - c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); - c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); + c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); s1 += size1; s2 += size2; @@ -215,8 +216,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) while (*s1 && *s2 && n) { n--; - c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); - c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); + c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); s1 += size1; s2 += size2; @@ -275,7 +276,7 @@ _PUBLIC_ void string_replace_w(char *s, char oldc, char newc) { while (s && *s) { size_t size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c == oldc) { *s = newc; } @@ -353,7 +354,7 @@ _PUBLIC_ size_t strlen_m(const char *s) while (*s) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); if (c < 0x10000) { count += 1; } else { @@ -391,7 +392,7 @@ _PUBLIC_ char *strchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) { return discard_const_p(char, s); } @@ -416,7 +417,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) { ret = discard_const_p(char, s); } @@ -436,7 +437,7 @@ _PUBLIC_ bool strhaslower(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(global_smb_iconv_convenience, string, &c_size); + s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); string += c_size; t = toupper_w(s); @@ -459,7 +460,7 @@ _PUBLIC_ bool strhasupper(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(global_smb_iconv_convenience, string, &c_size); + s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); string += c_size; t = tolower_w(s); @@ -489,12 +490,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); src += c_size; c = tolower_w(c); - c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); + c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -533,12 +534,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); src += c_size; c = toupper_w(c); - c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); + c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -579,8 +580,8 @@ _PUBLIC_ void strlower_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); - c_size2 = push_codepoint(global_smb_iconv_convenience, d, tolower_w(c)); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); + c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, tolower_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", c, tolower_w(c), (int)c_size, (int)c_size2)); @@ -615,8 +616,8 @@ _PUBLIC_ void strupper_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); - c_size2 = push_codepoint(global_smb_iconv_convenience, d, toupper_w(c)); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); + c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, toupper_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", c, toupper_w(c), (int)c_size, (int)c_size2)); @@ -638,7 +639,7 @@ _PUBLIC_ size_t count_chars_w(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) count++; s += size; } diff --git a/source4/lib/cmdline/config.mk b/source4/lib/cmdline/config.mk index 8f2591bad6..a1f876d56a 100644 --- a/source4/lib/cmdline/config.mk +++ b/source4/lib/cmdline/config.mk @@ -11,5 +11,5 @@ PUBLIC_DEPENDENCIES = LIBPOPT [SUBSYSTEM::POPT_CREDENTIALS] PRIVATE_PROTO_HEADER = popt_credentials.h OBJ_FILES = popt_credentials.o -PUBLIC_DEPENDENCIES = CREDENTIALS_KRB5 LIBCMDLINE_CREDENTIALS LIBPOPT +PUBLIC_DEPENDENCIES = CREDENTIALS LIBCMDLINE_CREDENTIALS LIBPOPT PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL diff --git a/source4/lib/cmdline/popt_credentials.c b/source4/lib/cmdline/popt_credentials.c index 25c9a2e5ff..de5ea7c1b6 100644 --- a/source4/lib/cmdline/popt_credentials.c +++ b/source4/lib/cmdline/popt_credentials.c @@ -54,8 +54,6 @@ static void popt_common_credentials_callback(poptContext con, const struct poptOption *opt, const char *arg, const void *data) { - struct cli_credentials *creds = data; - if (reason == POPT_CALLBACK_REASON_PRE) { cmdline_credentials = cli_credentials_init(talloc_autofree_context()); return; @@ -98,7 +96,7 @@ static void popt_common_credentials_callback(poptContext con, case 'P': /* Later, after this is all over, get the machine account details from the secrets.ldb */ - cli_credentials_set_machine_account_pending(cmdline_credentials); + cli_credentials_set_machine_account_pending(cmdline_credentials, cmdline_lp_ctx); break; case OPT_KERBEROS: diff --git a/source4/lib/events/config.mk b/source4/lib/events/config.mk index 7f4bfafb54..6750ca2d49 100644 --- a/source4/lib/events/config.mk +++ b/source4/lib/events/config.mk @@ -33,7 +33,7 @@ INIT_FUNCTION = s4_events_standard_init [SUBSYSTEM::LIBEVENTS] OBJ_FILES = events.o events_timed.o events_signal.o PUBLIC_HEADERS = events.h events_internal.h -PUBLIC_DEPENDENCIES = LIBTALLOC +PUBLIC_DEPENDENCIES = LIBTALLOC LIBSAMBA-UTIL # End SUBSYSTEM LIBEVENTS ############################## diff --git a/source4/lib/events/events.py b/source4/lib/events/events.py index 9cce31fac4..1e41e2d7e7 100644 --- a/source4/lib/events/events.py +++ b/source4/lib/events/events.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _events import new @@ -48,6 +47,16 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + event_context_init = _events.event_context_init event_context_init_byname = _events.event_context_init_byname event_backend_list = _events.event_backend_list diff --git a/source4/lib/events/events_wrap.c b/source4/lib/events/events_wrap.c index b2381d5160..08158cdc63 100644 --- a/source4/lib/events/events_wrap.c +++ b/source4/lib/events/events_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2472,6 +2472,19 @@ static swig_module_info swig_module = {swig_types, 4, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _events.so @@ -2569,7 +2582,7 @@ SWIGINTERN PyObject *_wrap_event_context_init(PyObject *SWIGUNUSEDPARM(self), Py { arg1 = NULL; } - if (!PyArg_ParseTuple(args,(char *)":event_context_init")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"event_context_init",0,0,0)) SWIG_fail; result = (struct event_context *)event_context_init(arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_event_context, 0 | 0 ); return resultobj; @@ -2618,7 +2631,7 @@ SWIGINTERN PyObject *_wrap_event_backend_list(PyObject *SWIGUNUSEDPARM(self), Py { arg1 = NULL; } - if (!PyArg_ParseTuple(args,(char *)":event_backend_list")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"event_backend_list",0,0,0)) SWIG_fail; result = (char **)event_backend_list(arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_p_char, 0 | 0 ); return resultobj; @@ -2628,9 +2641,9 @@ fail: static PyMethodDef SwigMethods[] = { - { (char *)"event_context_init", _wrap_event_context_init, METH_VARARGS, NULL}, + { (char *)"event_context_init", (PyCFunction)_wrap_event_context_init, METH_NOARGS, NULL}, { (char *)"event_context_init_byname", (PyCFunction) _wrap_event_context_init_byname, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"event_backend_list", _wrap_event_backend_list, METH_VARARGS, NULL}, + { (char *)"event_backend_list", (PyCFunction)_wrap_event_backend_list, METH_NOARGS, NULL}, { NULL, NULL, 0, NULL } }; diff --git a/source4/lib/ldb-samba/config.mk b/source4/lib/ldb-samba/config.mk index d29b3f319c..fa3ac46021 100644 --- a/source4/lib/ldb-samba/config.mk +++ b/source4/lib/ldb-samba/config.mk @@ -3,7 +3,7 @@ [SUBSYSTEM::LDBSAMBA] PUBLIC_DEPENDENCIES = LIBLDB PRIVATE_PROTO_HEADER = ldif_handlers.h -PRIVATE_DEPENDENCIES = LIBSECURITY SAMDB +PRIVATE_DEPENDENCIES = LIBSECURITY SAMDB_SCHEMA LIBNDR NDR_MISC OBJ_FILES = \ ldif_handlers.o # End SUBSYSTEM LDBSAMBA diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index f687e152d3..87f791cb38 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -126,7 +126,11 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op fn = ldb_find_backend(backend); if (fn == NULL) { - if (ldb_try_load_dso(ldb, backend) == 0) { + int (*init_fn) (void); + + init_fn = ldb_dso_load_symbol(ldb, backend, + "init_module"); + if (init_fn != NULL && init_fn() == 0) { fn = ldb_find_backend(backend); } } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 508389e374..72ed969298 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -168,7 +168,7 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name) int ldb_global_init(void) { - static int (*static_init_fns[])(void) = STATIC_LIBLDB_MODULES; + int (*static_init_fns[])(void) = STATIC_LIBLDB_MODULES; static int initialized = 0; int ret = 0, i; @@ -203,14 +203,15 @@ int ldb_register_module(const struct ldb_module_ops *ops) return 0; } -int ldb_try_load_dso(struct ldb_context *ldb, const char *name) +void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, + const char *symbol) { char *path; void *handle; - int (*init_fn) (void); + void *sym; if (ldb->modules_dir == NULL) - return -1; + return NULL; path = talloc_asprintf(ldb, "%s/%s.%s", ldb->modules_dir, name, SHLIBEXT); @@ -220,19 +221,19 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name) handle = dlopen(path, RTLD_NOW); if (handle == NULL) { ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror()); - return -1; + return NULL; } - init_fn = (int (*)(void))dlsym(handle, "init_module"); + sym = (int (*)(void))dlsym(handle, symbol); - if (init_fn == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `init_module' found in %s: %s\n", path, dlerror()); - return -1; + if (sym == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `%s' found in %s: %s\n", symbol, path, dlerror()); + return NULL; } talloc_free(path); - return init_fn(); + return sym; } int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out) @@ -248,10 +249,19 @@ int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, str ops = ldb_find_module_ops(module_list[i]); if (ops == NULL) { - if (ldb_try_load_dso(ldb, module_list[i]) == 0) { + int (*init_fn) (void); + + init_fn = ldb_dso_load_symbol(ldb, module_list[i], + "init_module"); + if (init_fn != NULL && init_fn() == 0) { ops = ldb_find_module_ops(module_list[i]); } } + + if (ops == NULL) { + ops = ldb_dso_load_symbol(ldb, module_list[i], + "ldb_module_ops"); + } if (ops == NULL) { ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 528d1d54f1..c1ea9db56b 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -124,11 +124,6 @@ int ldb_msg_add_empty( struct ldb_message *msg, { struct ldb_message_element *els; - /* FIXME: we should probably leave this to the schema module to check */ - if (! ldb_valid_attr_name(attr_name)) { - return LDB_ERR_OPERATIONS_ERROR; - } - els = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!els) { diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index d37cd0d650..a3b10a22d5 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -128,6 +128,7 @@ PRIVATE_DEPENDENCIES = \ [LIBRARY::LIBLDB] VERSION = 0.0.1 SO_VERSION = 0 +OUTPUT_TYPE = SHARED_LIBRARY CFLAGS = -Ilib/ldb/include DESCRIPTION = LDAP-like embedded database library INIT_FUNCTION_TYPE = int (*) (void) @@ -148,7 +149,6 @@ OBJ_FILES = \ PUBLIC_DEPENDENCIES = \ LIBTALLOC PRIVATE_DEPENDENCIES = \ - DYNCONFIG \ SOCKET_WRAPPER MANPAGE = man/ldb.3 PUBLIC_HEADERS = include/ldb.h include/ldb_errors.h diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 59f5f67fd2..e2ff8c6f98 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1217,7 +1217,7 @@ char *ldb_casefold(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *s); /** Check the attribute name is valid according to rfc2251 - \param s tthe string to check + \param s the string to check \return 1 if the name is ok */ diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index f88c55664d..d9f2defdc9 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -159,7 +159,8 @@ void ldb_reset_err_string(struct ldb_context *ldb); int ldb_register_module(const struct ldb_module_ops *); int ldb_register_backend(const char *url_prefix, ldb_connect_fn); -int ldb_try_load_dso(struct ldb_context *ldb, const char *name); +void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, + const char *symbol); /* The following definitions come from lib/ldb/common/ldb_debug.c */ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index aec4e2294f..15a49ec9c5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -25,7 +25,7 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -%module(package="ldb") ldb +%module ldb %{ @@ -96,37 +96,6 @@ typedef int ldb_error; $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); } -%typemap(in) ldb_msg *add_msg (int dict_pos, int msg_pos, PyObject *key, - PyObject *value, ldb_msg_element *msgel) { - if (PyDict_Check($input)) { - $1 = ldb_msg_new(NULL); - $1->num_elements = PyDict_Size($input) - 1; /* dn isn't in there */ - $1->elements = talloc_zero_array($1, struct ldb_message_element, $1->num_elements+1); - msg_pos = dict_pos = 0; - while (PyDict_Next($input, &dict_pos, &key, &value)) { - if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(value, &$1->dn) != 0) - SWIG_exception(SWIG_TypeError, "unable to convert dn"); - } else { - msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); - memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel)); - msg_pos++; - } - dict_pos++; - } - - if ($1->dn == NULL) - SWIG_exception(SWIG_TypeError, "no dn set"); - } else { - if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) - return NULL; - } -} - -%typemap(freearg) ldb_msg *add_msg { -//talloc_free($1); -} - /* * Wrap struct ldb_result */ @@ -222,10 +191,16 @@ fail: } ldb_dn; #ifdef SWIGPYTHON -%inline { -int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn) +%{ +int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, + struct ldb_context *ldb, ldb_dn **dn) { - return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, 0); + if (ldb != NULL && PyString_Check(object)) { + *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); + return 0; + } + return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, + SWIG_POINTER_EXCEPTION); } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, @@ -274,7 +249,7 @@ PyObject *ldb_msg_element_to_set(ldb_msg_element *me) return result; } -} +%} #endif /* ldb_message_element */ @@ -450,7 +425,7 @@ PyObject *PyExc_LdbError; * Wrap ldb functions */ -%rename(Ldb) ldb; +%rename(Ldb) ldb_context; /* Top-level ldb operations */ typedef struct ldb_context { %typemap(out) ldb_error { @@ -493,6 +468,48 @@ fail: ldb_error delete(ldb_dn *dn); ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); ldb_error add(ldb_msg *add_msg); + ldb_error add(PyObject *py_msg) + { + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + ldb_msg *msg = NULL; + if (PyDict_Check(py_msg)) { + msg = ldb_msg_new(NULL); + msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */ + msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1); + msg_pos = dict_pos = 0; + while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject(msg, value, $self, &msg->dn) != 0) { + return LDB_ERR_OTHER; + } + } else { + msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); + memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + dict_pos++; + } + + if (msg->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + return LDB_ERR_OTHER; + } + } else { + if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) + return LDB_ERR_OTHER; + } + + ret = ldb_add($self,msg); + + talloc_free(msg); + return ret; + + fail: + return LDB_ERR_OTHER; + } ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); @@ -535,7 +552,7 @@ fail: } ldb; %nodefault ldb_message; -%nodefault Ldb; +%nodefault ldb_context; %nodefault Dn; %rename(valid_attr_name) ldb_valid_attr_name; diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index b887b21aea..ce4a5ec494 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _ldb import new @@ -48,6 +47,16 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + SCOPE_DEFAULT = _ldb.SCOPE_DEFAULT SCOPE_BASE = _ldb.SCOPE_BASE SCOPE_ONELEVEL = _ldb.SCOPE_ONELEVEL @@ -56,51 +65,38 @@ CHANGETYPE_NONE = _ldb.CHANGETYPE_NONE CHANGETYPE_ADD = _ldb.CHANGETYPE_ADD CHANGETYPE_DELETE = _ldb.CHANGETYPE_DELETE CHANGETYPE_MODIFY = _ldb.CHANGETYPE_MODIFY -class Dn(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, Dn, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, Dn, name) +class Dn(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _ldb.new_Dn(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _ldb.Dn_swiginit(self,_ldb.new_Dn(*args, **kwargs)) __swig_destroy__ = _ldb.delete_Dn - __del__ = lambda self : None; - def validate(*args, **kwargs): return _ldb.Dn_validate(*args, **kwargs) - def get_casefold(*args, **kwargs): return _ldb.Dn_get_casefold(*args, **kwargs) - def __str__(*args, **kwargs): return _ldb.Dn___str__(*args, **kwargs) - def parent(*args, **kwargs): return _ldb.Dn_parent(*args, **kwargs) - def __cmp__(*args, **kwargs): return _ldb.Dn___cmp__(*args, **kwargs) - def is_valid(*args, **kwargs): return _ldb.Dn_is_valid(*args, **kwargs) - def is_special(*args, **kwargs): return _ldb.Dn_is_special(*args, **kwargs) - def is_null(*args, **kwargs): return _ldb.Dn_is_null(*args, **kwargs) - def check_special(*args, **kwargs): return _ldb.Dn_check_special(*args, **kwargs) - def __len__(*args, **kwargs): return _ldb.Dn___len__(*args, **kwargs) - def add_child(*args, **kwargs): return _ldb.Dn_add_child(*args, **kwargs) - def add_base(*args, **kwargs): return _ldb.Dn_add_base(*args, **kwargs) - def canonical_str(*args, **kwargs): return _ldb.Dn_canonical_str(*args, **kwargs) - def canonical_ex_str(*args, **kwargs): return _ldb.Dn_canonical_ex_str(*args, **kwargs) - def __add__(*args, **kwargs): return _ldb.Dn___add__(*args, **kwargs) +Dn.validate = new_instancemethod(_ldb.Dn_validate,None,Dn) +Dn.get_casefold = new_instancemethod(_ldb.Dn_get_casefold,None,Dn) +Dn.__str__ = new_instancemethod(_ldb.Dn___str__,None,Dn) +Dn.parent = new_instancemethod(_ldb.Dn_parent,None,Dn) +Dn.__cmp__ = new_instancemethod(_ldb.Dn___cmp__,None,Dn) +Dn.is_valid = new_instancemethod(_ldb.Dn_is_valid,None,Dn) +Dn.is_special = new_instancemethod(_ldb.Dn_is_special,None,Dn) +Dn.is_null = new_instancemethod(_ldb.Dn_is_null,None,Dn) +Dn.check_special = new_instancemethod(_ldb.Dn_check_special,None,Dn) +Dn.__len__ = new_instancemethod(_ldb.Dn___len__,None,Dn) +Dn.add_child = new_instancemethod(_ldb.Dn_add_child,None,Dn) +Dn.add_base = new_instancemethod(_ldb.Dn_add_base,None,Dn) +Dn.canonical_str = new_instancemethod(_ldb.Dn_canonical_str,None,Dn) +Dn.canonical_ex_str = new_instancemethod(_ldb.Dn_canonical_ex_str,None,Dn) +Dn.__add__ = new_instancemethod(_ldb.Dn___add__,None,Dn) Dn_swigregister = _ldb.Dn_swigregister Dn_swigregister(Dn) -ldb_dn_from_pyobject = _ldb.ldb_dn_from_pyobject -ldb_msg_element_from_pyobject = _ldb.ldb_msg_element_from_pyobject -ldb_msg_element_to_set = _ldb.ldb_msg_element_to_set -class ldb_msg_element(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, ldb_msg_element, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, ldb_msg_element, name) +class ldb_msg_element(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self): raise AttributeError, "No constructor defined" __repr__ = _swig_repr - def __iter__(*args, **kwargs): return _ldb.ldb_msg_element___iter__(*args, **kwargs) - def __set__(*args, **kwargs): return _ldb.ldb_msg_element___set__(*args, **kwargs) __swig_destroy__ = _ldb.delete_ldb_msg_element - __del__ = lambda self : None; - def __cmp__(*args, **kwargs): return _ldb.ldb_msg_element___cmp__(*args, **kwargs) +ldb_msg_element.__iter__ = new_instancemethod(_ldb.ldb_msg_element___iter__,None,ldb_msg_element) +ldb_msg_element.__set__ = new_instancemethod(_ldb.ldb_msg_element___set__,None,ldb_msg_element) +ldb_msg_element.__cmp__ = new_instancemethod(_ldb.ldb_msg_element___cmp__,None,ldb_msg_element) ldb_msg_element_swigregister = _ldb.ldb_msg_element_swigregister ldb_msg_element_swigregister(ldb_msg_element) @@ -109,27 +105,19 @@ def MessageElement(*args, **kwargs): return val ldb_msg_list_elements = _ldb.ldb_msg_list_elements -class Message(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, Message, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, Message, name) +class Message(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr - __swig_setmethods__["dn"] = _ldb.Message_dn_set - __swig_getmethods__["dn"] = _ldb.Message_dn_get - if _newclass:dn = _swig_property(_ldb.Message_dn_get, _ldb.Message_dn_set) + dn = _swig_property(_ldb.Message_dn_get, _ldb.Message_dn_set) def __init__(self, *args, **kwargs): - this = _ldb.new_Message(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _ldb.Message_swiginit(self,_ldb.new_Message(*args, **kwargs)) __swig_destroy__ = _ldb.delete_Message - __del__ = lambda self : None; - def __getitem__(*args, **kwargs): return _ldb.Message___getitem__(*args, **kwargs) - def __setitem__(*args): return _ldb.Message___setitem__(*args) - def __len__(*args, **kwargs): return _ldb.Message___len__(*args, **kwargs) - def keys(*args, **kwargs): return _ldb.Message_keys(*args, **kwargs) - def __iter__(*args, **kwargs): return _ldb.Message___iter__(*args, **kwargs) - def __delitem__(*args, **kwargs): return _ldb.Message___delitem__(*args, **kwargs) +Message.__getitem__ = new_instancemethod(_ldb.Message___getitem__,None,Message) +Message.__setitem__ = new_instancemethod(_ldb.Message___setitem__,None,Message) +Message.__len__ = new_instancemethod(_ldb.Message___len__,None,Message) +Message.keys = new_instancemethod(_ldb.Message_keys,None,Message) +Message.__iter__ = new_instancemethod(_ldb.Message___iter__,None,Message) +Message.__delitem__ = new_instancemethod(_ldb.Message___delitem__,None,Message) Message_swigregister = _ldb.Message_swigregister Message_swigregister(Message) @@ -174,42 +162,35 @@ LDB_ERR_ENTRY_ALREADY_EXISTS = _ldb.LDB_ERR_ENTRY_ALREADY_EXISTS LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED = _ldb.LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED LDB_ERR_AFFECTS_MULTIPLE_DSAS = _ldb.LDB_ERR_AFFECTS_MULTIPLE_DSAS LDB_ERR_OTHER = _ldb.LDB_ERR_OTHER -class ldb(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, ldb, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, ldb, name) - def __init__(self): raise AttributeError, "No constructor defined" +class Ldb(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr - def connect(*args, **kwargs): return _ldb.ldb_connect(*args, **kwargs) - __swig_destroy__ = _ldb.delete_ldb - __del__ = lambda self : None; - def search(*args, **kwargs): return _ldb.ldb_search(*args, **kwargs) - def delete(*args, **kwargs): return _ldb.ldb_delete(*args, **kwargs) - def rename(*args, **kwargs): return _ldb.ldb_rename(*args, **kwargs) - def add(*args, **kwargs): return _ldb.ldb_add(*args, **kwargs) - def modify(*args, **kwargs): return _ldb.ldb_modify(*args, **kwargs) - def get_config_basedn(*args, **kwargs): return _ldb.ldb_get_config_basedn(*args, **kwargs) - def get_root_basedn(*args, **kwargs): return _ldb.ldb_get_root_basedn(*args, **kwargs) - def get_schema_basedn(*args, **kwargs): return _ldb.ldb_get_schema_basedn(*args, **kwargs) - def get_default_basedn(*args, **kwargs): return _ldb.ldb_get_default_basedn(*args, **kwargs) - def errstring(*args, **kwargs): return _ldb.ldb_errstring(*args, **kwargs) - def set_create_perms(*args, **kwargs): return _ldb.ldb_set_create_perms(*args, **kwargs) - def set_modules_dir(*args, **kwargs): return _ldb.ldb_set_modules_dir(*args, **kwargs) - def set_debug(*args, **kwargs): return _ldb.ldb_set_debug(*args, **kwargs) - def set_opaque(*args, **kwargs): return _ldb.ldb_set_opaque(*args, **kwargs) - def get_opaque(*args, **kwargs): return _ldb.ldb_get_opaque(*args, **kwargs) - def transaction_start(*args, **kwargs): return _ldb.ldb_transaction_start(*args, **kwargs) - def transaction_commit(*args, **kwargs): return _ldb.ldb_transaction_commit(*args, **kwargs) - def transaction_cancel(*args, **kwargs): return _ldb.ldb_transaction_cancel(*args, **kwargs) - def __contains__(*args, **kwargs): return _ldb.ldb___contains__(*args, **kwargs) - def parse_ldif(*args, **kwargs): return _ldb.ldb_parse_ldif(*args, **kwargs) -ldb_swigregister = _ldb.ldb_swigregister -ldb_swigregister(ldb) - -def Ldb(*args, **kwargs): - val = _ldb.new_Ldb(*args, **kwargs) - return val + def __init__(self, *args, **kwargs): + _ldb.Ldb_swiginit(self,_ldb.new_Ldb(*args, **kwargs)) + __swig_destroy__ = _ldb.delete_Ldb +Ldb.connect = new_instancemethod(_ldb.Ldb_connect,None,Ldb) +Ldb.search = new_instancemethod(_ldb.Ldb_search,None,Ldb) +Ldb.delete = new_instancemethod(_ldb.Ldb_delete,None,Ldb) +Ldb.rename = new_instancemethod(_ldb.Ldb_rename,None,Ldb) +Ldb.add = new_instancemethod(_ldb.Ldb_add,None,Ldb) +Ldb.modify = new_instancemethod(_ldb.Ldb_modify,None,Ldb) +Ldb.get_config_basedn = new_instancemethod(_ldb.Ldb_get_config_basedn,None,Ldb) +Ldb.get_root_basedn = new_instancemethod(_ldb.Ldb_get_root_basedn,None,Ldb) +Ldb.get_schema_basedn = new_instancemethod(_ldb.Ldb_get_schema_basedn,None,Ldb) +Ldb.get_default_basedn = new_instancemethod(_ldb.Ldb_get_default_basedn,None,Ldb) +Ldb.errstring = new_instancemethod(_ldb.Ldb_errstring,None,Ldb) +Ldb.set_create_perms = new_instancemethod(_ldb.Ldb_set_create_perms,None,Ldb) +Ldb.set_modules_dir = new_instancemethod(_ldb.Ldb_set_modules_dir,None,Ldb) +Ldb.set_debug = new_instancemethod(_ldb.Ldb_set_debug,None,Ldb) +Ldb.set_opaque = new_instancemethod(_ldb.Ldb_set_opaque,None,Ldb) +Ldb.get_opaque = new_instancemethod(_ldb.Ldb_get_opaque,None,Ldb) +Ldb.transaction_start = new_instancemethod(_ldb.Ldb_transaction_start,None,Ldb) +Ldb.transaction_commit = new_instancemethod(_ldb.Ldb_transaction_commit,None,Ldb) +Ldb.transaction_cancel = new_instancemethod(_ldb.Ldb_transaction_cancel,None,Ldb) +Ldb.__contains__ = new_instancemethod(_ldb.Ldb___contains__,None,Ldb) +Ldb.parse_ldif = new_instancemethod(_ldb.Ldb_parse_ldif,None,Ldb) +Ldb_swigregister = _ldb.Ldb_swigregister +Ldb_swigregister(Ldb) valid_attr_name = _ldb.valid_attr_name timestring = _ldb.timestring diff --git a/source4/lib/ldb/ldb_ildap/config.mk b/source4/lib/ldb/ldb_ildap/config.mk index 83c43b6c35..01d9ec88ff 100644 --- a/source4/lib/ldb/ldb_ildap/config.mk +++ b/source4/lib/ldb/ldb_ildap/config.mk @@ -3,8 +3,8 @@ [MODULE::ldb_ildap] SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include -#OUTPUT_TYPE = SHARED_LIBRARY -PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP +OUTPUT_TYPE = SHARED_LIBRARY +PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP CREDENTIALS INIT_FUNCTION = ldb_ildap_init ALIASES = ldapi ldaps ldap OBJ_FILES = \ diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index b542fd6b8b..975e91dbe4 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2470,18 +2470,17 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_ldb_result swig_types[8] #define SWIGTYPE_p_long_long swig_types[9] #define SWIGTYPE_p_p_char swig_types[10] -#define SWIGTYPE_p_p_ldb_dn swig_types[11] -#define SWIGTYPE_p_p_ldb_result swig_types[12] -#define SWIGTYPE_p_short swig_types[13] -#define SWIGTYPE_p_signed_char swig_types[14] -#define SWIGTYPE_p_unsigned_char swig_types[15] -#define SWIGTYPE_p_unsigned_int swig_types[16] -#define SWIGTYPE_p_unsigned_long swig_types[17] -#define SWIGTYPE_p_unsigned_long_long swig_types[18] -#define SWIGTYPE_p_unsigned_short swig_types[19] -#define SWIGTYPE_p_void swig_types[20] -static swig_type_info *swig_types[22]; -static swig_module_info swig_module = {swig_types, 21, 0, 0, 0, 0}; +#define SWIGTYPE_p_p_ldb_result swig_types[11] +#define SWIGTYPE_p_short swig_types[12] +#define SWIGTYPE_p_signed_char swig_types[13] +#define SWIGTYPE_p_unsigned_char swig_types[14] +#define SWIGTYPE_p_unsigned_int swig_types[15] +#define SWIGTYPE_p_unsigned_long swig_types[16] +#define SWIGTYPE_p_unsigned_long_long swig_types[17] +#define SWIGTYPE_p_unsigned_short swig_types[18] +#define SWIGTYPE_p_void swig_types[19] +static swig_type_info *swig_types[21]; +static swig_module_info swig_module = {swig_types, 20, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2492,6 +2491,19 @@ static swig_module_info swig_module = {swig_types, 21, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _ldb.so @@ -2658,9 +2670,15 @@ SWIGINTERN ldb_dn *ldb_dn___add__(ldb_dn *self,ldb_dn *other){ return ret; } -int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn) +int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, + struct ldb_context *ldb, ldb_dn **dn) { - return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, 0); + if (ldb != NULL && PyString_Check(object)) { + *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); + return 0; + } + return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, + SWIG_POINTER_EXCEPTION); } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, @@ -2710,6 +2728,12 @@ PyObject *ldb_msg_element_to_set(ldb_msg_element *me) } +SWIGINTERN PyObject *ldb_msg_element___iter__(ldb_msg_element *self){ + return PyObject_GetIter(ldb_msg_element_to_set(self)); + } +SWIGINTERN PyObject *ldb_msg_element___set__(ldb_msg_element *self){ + return ldb_msg_element_to_set(self); + } #include <limits.h> #if !defined(SWIG_NO_LLONG_MAX) @@ -2855,12 +2879,6 @@ SWIG_AsVal_int (PyObject * obj, int *val) return res; } -SWIGINTERN PyObject *ldb_msg_element___iter__(ldb_msg_element *self){ - return PyObject_GetIter(ldb_msg_element_to_set(self)); - } -SWIGINTERN PyObject *ldb_msg_element___set__(ldb_msg_element *self){ - return ldb_msg_element_to_set(self); - } SWIGINTERN ldb_msg_element *new_ldb_msg_element(PyObject *set_obj,int flags,char const *name){ return ldb_msg_element_from_pyobject(set_obj, flags, name); } @@ -3025,6 +3043,47 @@ fail: return NULL; } SWIGINTERN void delete_ldb(ldb *self){ talloc_free(self); } +SWIGINTERN ldb_error ldb_add__SWIG_1(ldb *self,PyObject *py_msg){ + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + ldb_msg *msg = NULL; + if (PyDict_Check(py_msg)) { + msg = ldb_msg_new(NULL); + msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */ + msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1); + msg_pos = dict_pos = 0; + while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject(msg, value, self, &msg->dn) != 0) { + return 80; + } + } else { + msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); + memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + dict_pos++; + } + + if (msg->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + return 80; + } + } else { + if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) + return 80; + } + + ret = ldb_add(self,msg); + + talloc_free(msg); + return ret; + + fail: + return 80; + } SWIGINTERN ldb_error ldb___contains__(ldb *self,ldb_dn *dn,struct ldb_result **result_as_bool){ return ldb_search(self, dn, LDB_SCOPE_BASE, NULL, NULL, result_as_bool); @@ -3062,7 +3121,7 @@ SWIGINTERN PyObject *_wrap_new_Dn(PyObject *SWIGUNUSEDPARM(self), PyObject *args PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; char * kwnames[] = { - (char *) "Ldb",(char *) "str", NULL + (char *) "ldb",(char *) "str", NULL }; if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:new_Dn",kwnames,&obj0,&obj1)) SWIG_fail; @@ -3096,10 +3155,11 @@ SWIGINTERN PyObject *_wrap_delete_Dn(PyObject *SWIGUNUSEDPARM(self), PyObject *a ldb_dn *arg1 = (ldb_dn *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_Dn",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Dn" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3119,10 +3179,11 @@ SWIGINTERN PyObject *_wrap_Dn_validate(PyObject *SWIGUNUSEDPARM(self), PyObject bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_validate",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_validate" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3141,10 +3202,11 @@ SWIGINTERN PyObject *_wrap_Dn_get_casefold(PyObject *SWIGUNUSEDPARM(self), PyObj char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_get_casefold",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_get_casefold" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3163,10 +3225,11 @@ SWIGINTERN PyObject *_wrap_Dn___str__(PyObject *SWIGUNUSEDPARM(self), PyObject * char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn___str__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn___str__" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3185,10 +3248,11 @@ SWIGINTERN PyObject *_wrap_Dn_parent(PyObject *SWIGUNUSEDPARM(self), PyObject *a ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_parent",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_parent" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3241,10 +3305,11 @@ SWIGINTERN PyObject *_wrap_Dn_is_valid(PyObject *SWIGUNUSEDPARM(self), PyObject bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_is_valid",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_is_valid" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3263,10 +3328,11 @@ SWIGINTERN PyObject *_wrap_Dn_is_special(PyObject *SWIGUNUSEDPARM(self), PyObjec bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_is_special",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_is_special" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3285,10 +3351,11 @@ SWIGINTERN PyObject *_wrap_Dn_is_null(PyObject *SWIGUNUSEDPARM(self), PyObject * bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_is_null",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_is_null" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3344,10 +3411,11 @@ SWIGINTERN PyObject *_wrap_Dn___len__(PyObject *SWIGUNUSEDPARM(self), PyObject * int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn___len__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn___len__" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3434,10 +3502,11 @@ SWIGINTERN PyObject *_wrap_Dn_canonical_str(PyObject *SWIGUNUSEDPARM(self), PyOb char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_canonical_str",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_canonical_str" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3456,10 +3525,11 @@ SWIGINTERN PyObject *_wrap_Dn_canonical_ex_str(PyObject *SWIGUNUSEDPARM(self), P char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Dn_canonical_ex_str",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Dn_canonical_ex_str" "', argument " "1"" of type '" "ldb_dn *""'"); } @@ -3508,114 +3578,26 @@ fail: SWIGINTERN PyObject *Dn_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_ldb_dn, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } -SWIGINTERN PyObject *_wrap_ldb_dn_from_pyobject(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - PyObject *arg1 = (PyObject *) 0 ; - ldb_dn **arg2 = (ldb_dn **) 0 ; - int result; - void *argp2 = 0 ; - int res2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "object",(char *) "dn", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_dn_from_pyobject",kwnames,&obj0,&obj1)) SWIG_fail; - arg1 = obj0; - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_p_ldb_dn, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_dn_from_pyobject" "', argument " "2"" of type '" "ldb_dn **""'"); - } - arg2 = (ldb_dn **)(argp2); - result = (int)ldb_dn_from_pyobject(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_ldb_msg_element_from_pyobject(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - PyObject *arg1 = (PyObject *) 0 ; - int arg2 ; - char *arg3 = (char *) 0 ; - ldb_msg_element *result = 0 ; - int val2 ; - int ecode2 = 0 ; - int res3 ; - char *buf3 = 0 ; - int alloc3 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - char * kwnames[] = { - (char *) "set_obj",(char *) "flags",(char *) "attr_name", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ldb_msg_element_from_pyobject",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; - arg1 = obj0; - ecode2 = SWIG_AsVal_int(obj1, &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ldb_msg_element_from_pyobject" "', argument " "2"" of type '" "int""'"); - } - arg2 = (int)(val2); - res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ldb_msg_element_from_pyobject" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = (char *)(buf3); - result = (ldb_msg_element *)ldb_msg_element_from_pyobject(arg1,arg2,(char const *)arg3); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ldb_message_element, 0 | 0 ); - if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); - return resultobj; -fail: - if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); - return NULL; -} - - -SWIGINTERN PyObject *_wrap_ldb_msg_element_to_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; - PyObject *result = 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char * kwnames[] = { - (char *) "me", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:ldb_msg_element_to_set",kwnames,&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element_to_set" "', argument " "1"" of type '" "ldb_msg_element *""'"); - } - arg1 = (ldb_msg_element *)(argp1); - result = (PyObject *)ldb_msg_element_to_set(arg1); - resultobj = result; - return resultobj; -fail: - return NULL; +SWIGINTERN PyObject *Dn_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); } - SWIGINTERN PyObject *_wrap_ldb_msg_element___iter__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_msg_element___iter__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___iter__" "', argument " "1"" of type '" "ldb_msg_element *""'"); } @@ -3634,10 +3616,11 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element___set__(PyObject *SWIGUNUSEDPARM(self PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_msg_element___set__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___set__" "', argument " "1"" of type '" "ldb_msg_element *""'"); } @@ -3699,10 +3682,11 @@ SWIGINTERN PyObject *_wrap_delete_ldb_msg_element(PyObject *SWIGUNUSEDPARM(self) ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_ldb_msg_element",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_ldb_msg_element" "', argument " "1"" of type '" "ldb_msg_element *""'"); } @@ -3752,7 +3736,7 @@ fail: SWIGINTERN PyObject *ldb_msg_element_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_ldb_message_element, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } @@ -3795,16 +3779,15 @@ SWIGINTERN PyObject *_wrap_Message_dn_set(PyObject *SWIGUNUSEDPARM(self), PyObje int res1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; + PyObject *swig_obj[2] ; - if (!PyArg_ParseTuple(args,(char *)"OO:Message_dn_set",&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!SWIG_Python_UnpackTuple(args,"Message_dn_set",2,2,swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message_dn_set" "', argument " "1"" of type '" "ldb_msg *""'"); } arg1 = (ldb_msg *)(argp1); - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_dn, SWIG_POINTER_DISOWN | 0 ); + res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_ldb_dn, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Message_dn_set" "', argument " "2"" of type '" "ldb_dn *""'"); } @@ -3829,10 +3812,11 @@ SWIGINTERN PyObject *_wrap_Message_dn_get(PyObject *SWIGUNUSEDPARM(self), PyObje ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Message_dn_get",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message_dn_get" "', argument " "1"" of type '" "ldb_msg *""'"); } @@ -3882,10 +3866,11 @@ SWIGINTERN PyObject *_wrap_delete_Message(PyObject *SWIGUNUSEDPARM(self), PyObje ldb_msg *arg1 = (ldb_msg *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_Message",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Message" "', argument " "1"" of type '" "ldb_msg *""'"); } @@ -3951,7 +3936,7 @@ fail: } -SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_0(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; ldb_msg *arg1 = (ldb_msg *) 0 ; char *arg2 = (char *) 0 ; @@ -3963,22 +3948,19 @@ SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_0(PyObject *SWIGUNUSEDPARM( int alloc2 = 0 ; void *argp3 = 0 ; int res3 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OOO:Message___setitem__",&obj0,&obj1,&obj2)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message___setitem__" "', argument " "1"" of type '" "ldb_msg *""'"); } arg1 = (ldb_msg *)(argp1); - res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Message___setitem__" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); - res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + res3 = SWIG_ConvertPtr(swig_obj[2], &argp3,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res3)) { SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Message___setitem__" "', argument " "3"" of type '" "ldb_msg_element *""'"); } @@ -3998,7 +3980,7 @@ fail: } -SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_1(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; ldb_msg *arg1 = (ldb_msg *) 0 ; char *arg2 = (char *) 0 ; @@ -4008,22 +3990,19 @@ SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_1(PyObject *SWIGUNUSEDPARM( int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OOO:Message___setitem__",&obj0,&obj1,&obj2)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message___setitem__" "', argument " "1"" of type '" "ldb_msg *""'"); } arg1 = (ldb_msg *)(argp1); - res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Message___setitem__" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); - arg3 = obj2; + arg3 = swig_obj[2]; { if (arg1 == NULL) SWIG_exception(SWIG_ValueError, @@ -4042,46 +4021,23 @@ fail: SWIGINTERN PyObject *_wrap_Message___setitem__(PyObject *self, PyObject *args) { int argc; PyObject *argv[4]; - int ii; - if (!PyTuple_Check(args)) SWIG_fail; - argc = (int)PyObject_Length(args); - for (ii = 0; (ii < argc) && (ii < 3); ii++) { - argv[ii] = PyTuple_GET_ITEM(args,ii); - } + if (!(argc = SWIG_Python_UnpackTuple(args,"Message___setitem__",0,3,argv))) SWIG_fail; + --argc; if (argc == 3) { - int _v; - void *vptr = 0; - int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_ldb_message, 0); - _v = SWIG_CheckState(res); - if (_v) { - int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[2], &vptr, SWIGTYPE_p_ldb_message_element, 0); _v = SWIG_CheckState(res); - if (_v) { - void *vptr = 0; - int res = SWIG_ConvertPtr(argv[2], &vptr, SWIGTYPE_p_ldb_message_element, 0); - _v = SWIG_CheckState(res); - if (_v) { - return _wrap_Message___setitem____SWIG_0(self, args); - } - } } + if (!_v) goto check_1; + return _wrap_Message___setitem____SWIG_0(self, argc, argv); } +check_1: + if (argc == 3) { - int _v; - void *vptr = 0; - int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_ldb_message, 0); - _v = SWIG_CheckState(res); - if (_v) { - int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); - _v = SWIG_CheckState(res); - if (_v) { - _v = (argv[2] != 0); - if (_v) { - return _wrap_Message___setitem____SWIG_1(self, args); - } - } - } + return _wrap_Message___setitem____SWIG_1(self, argc, argv); } fail: @@ -4096,10 +4052,11 @@ SWIGINTERN PyObject *_wrap_Message___len__(PyObject *SWIGUNUSEDPARM(self), PyObj unsigned int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Message___len__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message___len__" "', argument " "1"" of type '" "ldb_msg *""'"); } @@ -4123,10 +4080,11 @@ SWIGINTERN PyObject *_wrap_Message_keys(PyObject *SWIGUNUSEDPARM(self), PyObject PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Message_keys",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message_keys" "', argument " "1"" of type '" "ldb_msg *""'"); } @@ -4150,10 +4108,11 @@ SWIGINTERN PyObject *_wrap_Message___iter__(PyObject *SWIGUNUSEDPARM(self), PyOb PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:Message___iter__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Message___iter__" "', argument " "1"" of type '" "ldb_msg *""'"); } @@ -4214,11 +4173,15 @@ fail: SWIGINTERN PyObject *Message_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_ldb_message, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Message_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_ldb_ldif_to_pyobject(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb_ldif *arg1 = (ldb_ldif *) 0 ; @@ -4287,7 +4250,7 @@ SWIGINTERN PyObject *_wrap_new_Ldb(PyObject *SWIGUNUSEDPARM(self), PyObject *arg arg3 = (char **)(argp3); } result = (ldb *)new_ldb((char const *)arg1,arg2,(char const *(*))arg3); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ldb_context, SWIG_POINTER_OWN | 0 ); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ldb_context, SWIG_POINTER_NEW | 0 ); if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); return resultobj; fail: @@ -4296,7 +4259,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_connect(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_connect(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *arg2 = (char *) 0 ; @@ -4320,28 +4283,28 @@ SWIGINTERN PyObject *_wrap_ldb_connect(PyObject *SWIGUNUSEDPARM(self), PyObject (char *) "self",(char *) "url",(char *) "flags",(char *) "options", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|OO:ldb_connect",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|OO:Ldb_connect",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_connect" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_connect" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_connect" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_connect" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); if (obj2) { ecode3 = SWIG_AsVal_unsigned_SS_int(obj2, &val3); if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ldb_connect" "', argument " "3"" of type '" "unsigned int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Ldb_connect" "', argument " "3"" of type '" "unsigned int""'"); } arg3 = (unsigned int)(val3); } if (obj3) { res4 = SWIG_ConvertPtr(obj3, &argp4,SWIGTYPE_p_p_char, 0 | 0 ); if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ldb_connect" "', argument " "4"" of type '" "char const *[]""'"); + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Ldb_connect" "', argument " "4"" of type '" "char const *[]""'"); } arg4 = (char **)(argp4); } @@ -4366,17 +4329,18 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_ldb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_delete_Ldb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_ldb",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_ldb" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Ldb" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4393,7 +4357,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_search(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_search(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *arg2 = (ldb_dn *) NULL ; @@ -4425,30 +4389,30 @@ SWIGINTERN PyObject *_wrap_ldb_search(PyObject *SWIGUNUSEDPARM(self), PyObject * { arg6 = &temp_ldb_result6; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OOOO:ldb_search",kwnames,&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OOOO:Ldb_search",kwnames,&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_search" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_search" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); if (obj1) { res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_search" "', argument " "2"" of type '" "ldb_dn *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_search" "', argument " "2"" of type '" "ldb_dn *""'"); } arg2 = (ldb_dn *)(argp2); } if (obj2) { ecode3 = SWIG_AsVal_int(obj2, &val3); if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ldb_search" "', argument " "3"" of type '" "enum ldb_scope""'"); + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Ldb_search" "', argument " "3"" of type '" "enum ldb_scope""'"); } arg3 = (enum ldb_scope)(val3); } if (obj3) { res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ldb_search" "', argument " "4"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Ldb_search" "', argument " "4"" of type '" "char const *""'"); } arg4 = (char *)(buf4); } @@ -4502,7 +4466,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *arg2 = (ldb_dn *) 0 ; @@ -4517,15 +4481,15 @@ SWIGINTERN PyObject *_wrap_ldb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "dn", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_delete",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_delete",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_delete" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_delete" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_delete" "', argument " "2"" of type '" "ldb_dn *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_delete" "', argument " "2"" of type '" "ldb_dn *""'"); } arg2 = (ldb_dn *)(argp2); { @@ -4547,7 +4511,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_rename(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_rename(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *arg2 = (ldb_dn *) 0 ; @@ -4566,20 +4530,20 @@ SWIGINTERN PyObject *_wrap_ldb_rename(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "olddn",(char *) "newdn", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ldb_rename",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Ldb_rename",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_rename" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_rename" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_rename" "', argument " "2"" of type '" "ldb_dn *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_rename" "', argument " "2"" of type '" "ldb_dn *""'"); } arg2 = (ldb_dn *)(argp2); res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ldb_rename" "', argument " "3"" of type '" "ldb_dn *""'"); + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Ldb_rename" "', argument " "3"" of type '" "ldb_dn *""'"); } arg3 = (ldb_dn *)(argp3); { @@ -4601,55 +4565,27 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_add__SWIG_0(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_msg *arg2 = (ldb_msg *) 0 ; ldb_error result; void *argp1 = 0 ; int res1 = 0 ; - int dict_pos2 ; - int msg_pos2 ; - PyObject *key2 ; - PyObject *value2 ; - ldb_msg_element *msgel2 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "add_msg", NULL - }; + void *argp2 = 0 ; + int res2 = 0 ; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_add",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_add" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_add" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); - { - if (PyDict_Check(obj1)) { - arg2 = ldb_msg_new(NULL); - arg2->num_elements = PyDict_Size(obj1) - 1; /* dn isn't in there */ - arg2->elements = talloc_zero_array(arg2, struct ldb_message_element, arg2->num_elements+1); - msg_pos2 = dict_pos2 = 0; - while (PyDict_Next(obj1, &dict_pos2, &key2, &value2)) { - if (!strcmp(PyString_AsString(key2), "dn")) { - if (ldb_dn_from_pyobject(value2, &arg2->dn) != 0) - SWIG_exception(SWIG_TypeError, "unable to convert dn"); - } else { - msgel2 = ldb_msg_element_from_pyobject(value2, 0, PyString_AsString(key2)); - memcpy(&arg2->elements[msg_pos2], msgel2, sizeof(*msgel2)); - msg_pos2++; - } - dict_pos2++; - } - - if (arg2->dn == NULL) - SWIG_exception(SWIG_TypeError, "no dn set"); - } else { - if (SWIG_ConvertPtr(obj1, (void **)&arg2, SWIGTYPE_p_ldb_message, 0) != 0) - return NULL; - } + res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_ldb_message, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_add" "', argument " "2"" of type '" "ldb_msg *""'"); } + arg2 = (ldb_msg *)(argp2); { if (arg1 == NULL) SWIG_exception(SWIG_ValueError, @@ -4668,19 +4604,75 @@ SWIGINTERN PyObject *_wrap_ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *arg } resultobj = Py_None; } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Ldb_add__SWIG_1(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + ldb *arg1 = (ldb *) 0 ; + PyObject *arg2 = (PyObject *) 0 ; + ldb_error result; + void *argp1 = 0 ; + int res1 = 0 ; + + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_add" "', argument " "1"" of type '" "ldb *""'"); + } + arg1 = (ldb *)(argp1); + arg2 = swig_obj[1]; + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + result = ldb_add__SWIG_1(arg1,arg2); { - //talloc_free(arg2); + if (result != 0) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", result, ldb_strerror(result))); + SWIG_fail; + } + resultobj = Py_None; } return resultobj; fail: - { - //talloc_free(arg2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *self, PyObject *args) { + int argc; + PyObject *argv[3]; + + if (!(argc = SWIG_Python_UnpackTuple(args,"Ldb_add",0,2,argv))) SWIG_fail; + --argc; + if (argc == 2) { + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_ldb_message, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + return _wrap_Ldb_add__SWIG_0(self, argc, argv); + } +check_1: + + if (argc == 2) { + return _wrap_Ldb_add__SWIG_1(self, argc, argv); } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'Ldb_add'.\n Possible C/C++ prototypes are:\n"" add(ldb *,ldb_msg *)\n"" add(ldb *,PyObject *)\n"); return NULL; } -SWIGINTERN PyObject *_wrap_ldb_modify(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_modify(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_msg *arg2 = (ldb_msg *) 0 ; @@ -4695,15 +4687,15 @@ SWIGINTERN PyObject *_wrap_ldb_modify(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "message", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_modify",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_modify",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_modify" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_modify" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_message, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_modify" "', argument " "2"" of type '" "ldb_msg *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_modify" "', argument " "2"" of type '" "ldb_msg *""'"); } arg2 = (ldb_msg *)(argp2); { @@ -4730,18 +4722,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_get_config_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_get_config_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_get_config_basedn",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_get_config_basedn" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_get_config_basedn" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4757,18 +4750,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_get_root_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_get_root_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_get_root_basedn",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_get_root_basedn" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_get_root_basedn" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4784,18 +4778,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_get_schema_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_get_schema_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_get_schema_basedn",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_get_schema_basedn" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_get_schema_basedn" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4811,18 +4806,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_get_default_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_get_default_basedn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_get_default_basedn",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_get_default_basedn" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_get_default_basedn" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4838,18 +4834,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_errstring(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_errstring(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_errstring",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_errstring" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_errstring" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4865,7 +4862,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_set_create_perms(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_set_create_perms(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; unsigned int arg2 ; @@ -4879,15 +4876,15 @@ SWIGINTERN PyObject *_wrap_ldb_set_create_perms(PyObject *SWIGUNUSEDPARM(self), (char *) "self",(char *) "perms", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_set_create_perms",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_set_create_perms",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_create_perms" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_set_create_perms" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ldb_set_create_perms" "', argument " "2"" of type '" "unsigned int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Ldb_set_create_perms" "', argument " "2"" of type '" "unsigned int""'"); } arg2 = (unsigned int)(val2); { @@ -4903,7 +4900,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_set_modules_dir(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_set_modules_dir(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *arg2 = (char *) 0 ; @@ -4918,15 +4915,15 @@ SWIGINTERN PyObject *_wrap_ldb_set_modules_dir(PyObject *SWIGUNUSEDPARM(self), P (char *) "self",(char *) "path", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_set_modules_dir",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_set_modules_dir",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_modules_dir" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_set_modules_dir" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_modules_dir" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_set_modules_dir" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); { @@ -4944,7 +4941,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_set_debug(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_set_debug(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; void (*arg2)(void *,enum ldb_debug_level,char const *,va_list) = (void (*)(void *,enum ldb_debug_level,char const *,va_list)) 0 ; @@ -4958,10 +4955,10 @@ SWIGINTERN PyObject *_wrap_ldb_set_debug(PyObject *SWIGUNUSEDPARM(self), PyObjec (char *) "self",(char *) "debug", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_set_debug",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_set_debug",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_debug" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_set_debug" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -4990,7 +4987,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_set_opaque(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_set_opaque(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *arg2 = (char *) 0 ; @@ -5009,20 +5006,20 @@ SWIGINTERN PyObject *_wrap_ldb_set_opaque(PyObject *SWIGUNUSEDPARM(self), PyObje (char *) "self",(char *) "name",(char *) "value", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ldb_set_opaque",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Ldb_set_opaque",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_opaque" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_set_opaque" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_opaque" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_set_opaque" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); res3 = SWIG_ConvertPtr(obj2,SWIG_as_voidptrptr(&arg3), 0, 0); if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ldb_set_opaque" "', argument " "3"" of type '" "void *""'"); + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Ldb_set_opaque" "', argument " "3"" of type '" "void *""'"); } { if (arg1 == NULL) @@ -5045,7 +5042,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_get_opaque(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_get_opaque(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *arg2 = (char *) 0 ; @@ -5061,15 +5058,15 @@ SWIGINTERN PyObject *_wrap_ldb_get_opaque(PyObject *SWIGUNUSEDPARM(self), PyObje (char *) "self",(char *) "name", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_get_opaque",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_get_opaque",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_get_opaque" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_get_opaque" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_get_opaque" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_get_opaque" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); { @@ -5087,18 +5084,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_error result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_transaction_start",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_transaction_start" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_transaction_start" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -5120,18 +5118,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_error result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_transaction_commit",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_transaction_commit" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_transaction_commit" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -5153,18 +5152,19 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Ldb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_error result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:ldb_transaction_cancel",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_transaction_cancel" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_transaction_cancel" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); { @@ -5186,7 +5186,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb___contains__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb___contains__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; ldb_dn *arg2 = (ldb_dn *) 0 ; @@ -5206,15 +5206,15 @@ SWIGINTERN PyObject *_wrap_ldb___contains__(PyObject *SWIGUNUSEDPARM(self), PyOb { arg3 = &tmp3; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb___contains__",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb___contains__",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb___contains__" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb___contains__" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_dn, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb___contains__" "', argument " "2"" of type '" "ldb_dn *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb___contains__" "', argument " "2"" of type '" "ldb_dn *""'"); } arg2 = (ldb_dn *)(argp2); { @@ -5245,7 +5245,7 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_parse_ldif(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Ldb_parse_ldif(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; char *arg2 = (char *) 0 ; @@ -5261,15 +5261,15 @@ SWIGINTERN PyObject *_wrap_ldb_parse_ldif(PyObject *SWIGUNUSEDPARM(self), PyObje (char *) "self",(char *) "s", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_parse_ldif",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_parse_ldif",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_parse_ldif" "', argument " "1"" of type '" "ldb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_parse_ldif" "', argument " "1"" of type '" "ldb *""'"); } arg1 = (ldb *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_parse_ldif" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_parse_ldif" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); { @@ -5287,13 +5287,17 @@ fail: } -SWIGINTERN PyObject *ldb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *Ldb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_ldb_context, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Ldb_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_valid_attr_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; char *arg1 = (char *) 0 ; @@ -5377,69 +5381,69 @@ fail: static PyMethodDef SwigMethods[] = { { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_Dn", _wrap_delete_Dn, METH_VARARGS, NULL}, - { (char *)"Dn_validate", _wrap_Dn_validate, METH_VARARGS, NULL}, - { (char *)"Dn_get_casefold", _wrap_Dn_get_casefold, METH_VARARGS, NULL}, - { (char *)"Dn___str__", _wrap_Dn___str__, METH_VARARGS, NULL}, - { (char *)"Dn_parent", _wrap_Dn_parent, METH_VARARGS, NULL}, + { (char *)"delete_Dn", (PyCFunction)_wrap_delete_Dn, METH_O, NULL}, + { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, NULL}, + { (char *)"Dn_get_casefold", (PyCFunction)_wrap_Dn_get_casefold, METH_O, NULL}, + { (char *)"Dn___str__", (PyCFunction)_wrap_Dn___str__, METH_O, NULL}, + { (char *)"Dn_parent", (PyCFunction)_wrap_Dn_parent, METH_O, NULL}, { (char *)"Dn___cmp__", (PyCFunction) _wrap_Dn___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Dn_is_valid", _wrap_Dn_is_valid, METH_VARARGS, NULL}, - { (char *)"Dn_is_special", _wrap_Dn_is_special, METH_VARARGS, NULL}, - { (char *)"Dn_is_null", _wrap_Dn_is_null, METH_VARARGS, NULL}, + { (char *)"Dn_is_valid", (PyCFunction)_wrap_Dn_is_valid, METH_O, NULL}, + { (char *)"Dn_is_special", (PyCFunction)_wrap_Dn_is_special, METH_O, NULL}, + { (char *)"Dn_is_null", (PyCFunction)_wrap_Dn_is_null, METH_O, NULL}, { (char *)"Dn_check_special", (PyCFunction) _wrap_Dn_check_special, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Dn___len__", _wrap_Dn___len__, METH_VARARGS, NULL}, + { (char *)"Dn___len__", (PyCFunction)_wrap_Dn___len__, METH_O, NULL}, { (char *)"Dn_add_child", (PyCFunction) _wrap_Dn_add_child, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_add_base", (PyCFunction) _wrap_Dn_add_base, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Dn_canonical_str", _wrap_Dn_canonical_str, METH_VARARGS, NULL}, - { (char *)"Dn_canonical_ex_str", _wrap_Dn_canonical_ex_str, METH_VARARGS, NULL}, + { (char *)"Dn_canonical_str", (PyCFunction)_wrap_Dn_canonical_str, METH_O, NULL}, + { (char *)"Dn_canonical_ex_str", (PyCFunction)_wrap_Dn_canonical_ex_str, METH_O, NULL}, { (char *)"Dn___add__", (PyCFunction) _wrap_Dn___add__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_swigregister", Dn_swigregister, METH_VARARGS, NULL}, - { (char *)"ldb_dn_from_pyobject", (PyCFunction) _wrap_ldb_dn_from_pyobject, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_msg_element_from_pyobject", (PyCFunction) _wrap_ldb_msg_element_from_pyobject, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_msg_element_to_set", (PyCFunction) _wrap_ldb_msg_element_to_set, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_msg_element___iter__", _wrap_ldb_msg_element___iter__, METH_VARARGS, NULL}, - { (char *)"ldb_msg_element___set__", _wrap_ldb_msg_element___set__, METH_VARARGS, NULL}, + { (char *)"Dn_swiginit", Dn_swiginit, METH_VARARGS, NULL}, + { (char *)"ldb_msg_element___iter__", (PyCFunction)_wrap_ldb_msg_element___iter__, METH_O, NULL}, + { (char *)"ldb_msg_element___set__", (PyCFunction)_wrap_ldb_msg_element___set__, METH_O, NULL}, { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_ldb_msg_element", _wrap_delete_ldb_msg_element, METH_VARARGS, NULL}, + { (char *)"delete_ldb_msg_element", (PyCFunction)_wrap_delete_ldb_msg_element, METH_O, NULL}, { (char *)"ldb_msg_element___cmp__", (PyCFunction) _wrap_ldb_msg_element___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ldb_msg_element_swigregister", ldb_msg_element_swigregister, METH_VARARGS, NULL}, { (char *)"ldb_msg_list_elements", (PyCFunction) _wrap_ldb_msg_list_elements, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Message_dn_set", _wrap_Message_dn_set, METH_VARARGS, NULL}, - { (char *)"Message_dn_get", _wrap_Message_dn_get, METH_VARARGS, NULL}, + { (char *)"Message_dn_get", (PyCFunction)_wrap_Message_dn_get, METH_O, NULL}, { (char *)"new_Message", (PyCFunction) _wrap_new_Message, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_Message", _wrap_delete_Message, METH_VARARGS, NULL}, + { (char *)"delete_Message", (PyCFunction)_wrap_delete_Message, METH_O, NULL}, { (char *)"Message___getitem__", (PyCFunction) _wrap_Message___getitem__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Message___setitem__", _wrap_Message___setitem__, METH_VARARGS, NULL}, - { (char *)"Message___len__", _wrap_Message___len__, METH_VARARGS, NULL}, - { (char *)"Message_keys", _wrap_Message_keys, METH_VARARGS, NULL}, - { (char *)"Message___iter__", _wrap_Message___iter__, METH_VARARGS, NULL}, + { (char *)"Message___len__", (PyCFunction)_wrap_Message___len__, METH_O, NULL}, + { (char *)"Message_keys", (PyCFunction)_wrap_Message_keys, METH_O, NULL}, + { (char *)"Message___iter__", (PyCFunction)_wrap_Message___iter__, METH_O, NULL}, { (char *)"Message___delitem__", (PyCFunction) _wrap_Message___delitem__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Message_swigregister", Message_swigregister, METH_VARARGS, NULL}, + { (char *)"Message_swiginit", Message_swiginit, METH_VARARGS, NULL}, { (char *)"ldb_ldif_to_pyobject", (PyCFunction) _wrap_ldb_ldif_to_pyobject, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_Ldb", (PyCFunction) _wrap_new_Ldb, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_connect", (PyCFunction) _wrap_ldb_connect, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_ldb", _wrap_delete_ldb, METH_VARARGS, NULL}, - { (char *)"ldb_search", (PyCFunction) _wrap_ldb_search, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_delete", (PyCFunction) _wrap_ldb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_rename", (PyCFunction) _wrap_ldb_rename, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_add", (PyCFunction) _wrap_ldb_add, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_modify", (PyCFunction) _wrap_ldb_modify, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_get_config_basedn", _wrap_ldb_get_config_basedn, METH_VARARGS, NULL}, - { (char *)"ldb_get_root_basedn", _wrap_ldb_get_root_basedn, METH_VARARGS, NULL}, - { (char *)"ldb_get_schema_basedn", _wrap_ldb_get_schema_basedn, METH_VARARGS, NULL}, - { (char *)"ldb_get_default_basedn", _wrap_ldb_get_default_basedn, METH_VARARGS, NULL}, - { (char *)"ldb_errstring", _wrap_ldb_errstring, METH_VARARGS, NULL}, - { (char *)"ldb_set_create_perms", (PyCFunction) _wrap_ldb_set_create_perms, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_set_modules_dir", (PyCFunction) _wrap_ldb_set_modules_dir, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_set_debug", (PyCFunction) _wrap_ldb_set_debug, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_set_opaque", (PyCFunction) _wrap_ldb_set_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_get_opaque", (PyCFunction) _wrap_ldb_get_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_transaction_start", _wrap_ldb_transaction_start, METH_VARARGS, NULL}, - { (char *)"ldb_transaction_commit", _wrap_ldb_transaction_commit, METH_VARARGS, NULL}, - { (char *)"ldb_transaction_cancel", _wrap_ldb_transaction_cancel, METH_VARARGS, NULL}, - { (char *)"ldb___contains__", (PyCFunction) _wrap_ldb___contains__, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_parse_ldif", (PyCFunction) _wrap_ldb_parse_ldif, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_swigregister", ldb_swigregister, METH_VARARGS, NULL}, + { (char *)"Ldb_connect", (PyCFunction) _wrap_Ldb_connect, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_Ldb", (PyCFunction)_wrap_delete_Ldb, METH_O, NULL}, + { (char *)"Ldb_search", (PyCFunction) _wrap_Ldb_search, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_delete", (PyCFunction) _wrap_Ldb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_rename", (PyCFunction) _wrap_Ldb_rename, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_add", _wrap_Ldb_add, METH_VARARGS, NULL}, + { (char *)"Ldb_modify", (PyCFunction) _wrap_Ldb_modify, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_get_config_basedn", (PyCFunction)_wrap_Ldb_get_config_basedn, METH_O, NULL}, + { (char *)"Ldb_get_root_basedn", (PyCFunction)_wrap_Ldb_get_root_basedn, METH_O, NULL}, + { (char *)"Ldb_get_schema_basedn", (PyCFunction)_wrap_Ldb_get_schema_basedn, METH_O, NULL}, + { (char *)"Ldb_get_default_basedn", (PyCFunction)_wrap_Ldb_get_default_basedn, METH_O, NULL}, + { (char *)"Ldb_errstring", (PyCFunction)_wrap_Ldb_errstring, METH_O, NULL}, + { (char *)"Ldb_set_create_perms", (PyCFunction) _wrap_Ldb_set_create_perms, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_set_modules_dir", (PyCFunction) _wrap_Ldb_set_modules_dir, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_set_debug", (PyCFunction) _wrap_Ldb_set_debug, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_set_opaque", (PyCFunction) _wrap_Ldb_set_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_get_opaque", (PyCFunction) _wrap_Ldb_get_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_transaction_start", (PyCFunction)_wrap_Ldb_transaction_start, METH_O, NULL}, + { (char *)"Ldb_transaction_commit", (PyCFunction)_wrap_Ldb_transaction_commit, METH_O, NULL}, + { (char *)"Ldb_transaction_cancel", (PyCFunction)_wrap_Ldb_transaction_cancel, METH_O, NULL}, + { (char *)"Ldb___contains__", (PyCFunction) _wrap_Ldb___contains__, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_parse_ldif", (PyCFunction) _wrap_Ldb_parse_ldif, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_swigregister", Ldb_swigregister, METH_VARARGS, NULL}, + { (char *)"Ldb_swiginit", Ldb_swiginit, METH_VARARGS, NULL}, { (char *)"valid_attr_name", (PyCFunction) _wrap_valid_attr_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"timestring", (PyCFunction) _wrap_timestring, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"string_to_time", (PyCFunction) _wrap_string_to_time, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -5460,7 +5464,6 @@ static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_p_ldb_dn = {"_p_p_ldb_dn", "struct ldb_dn **|ldb_dn **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_ldb_result = {"_p_p_ldb_result", "struct ldb_result **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; @@ -5483,7 +5486,6 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_ldb_result, &_swigt__p_long_long, &_swigt__p_p_char, - &_swigt__p_p_ldb_dn, &_swigt__p_p_ldb_result, &_swigt__p_short, &_swigt__p_signed_char, @@ -5506,7 +5508,6 @@ static swig_cast_info _swigc__p_ldb_message_element[] = { {&_swigt__p_ldb_messa static swig_cast_info _swigc__p_ldb_result[] = { {&_swigt__p_ldb_result, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_p_ldb_dn[] = { {&_swigt__p_p_ldb_dn, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_ldb_result[] = { {&_swigt__p_p_ldb_result, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; @@ -5529,7 +5530,6 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_ldb_result, _swigc__p_long_long, _swigc__p_p_char, - _swigc__p_p_ldb_dn, _swigc__p_p_ldb_result, _swigc__p_short, _swigc__p_signed_char, diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index b140bfc599..b6d6170ec2 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -1,8 +1,11 @@ #!/usr/bin/python -# Simple tests for the ldb python API +# Simple tests for the ldb python bindings. # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org> + import sys import unittest + +# Required for the standalone LDB build sys.path.append("swig") sys.path.append("build/lib.linux-i686-2.4") @@ -116,6 +119,16 @@ class SimpleLdb(unittest.TestCase): finally: l.delete(ldb.Dn(l, "dc=foo")) + def test_add_dict_string_dn(self): + l = ldb.Ldb("foo.tdb") + m = {"dn": "dc=foo", "bla": "bla"} + self.assertEquals(len(l.search()), 1) + l.add(m) + try: + self.assertEquals(len(l.search()), 2) + finally: + l.delete(ldb.Dn(l, "dc=foo")) + def test_rename(self): l = ldb.Ldb("foo.tdb") m = ldb.Message() diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/lib/ldb/tools/ad2oLschema.c index 5fcf752578..c8974d7e7d 100644 --- a/source4/lib/ldb/tools/ad2oLschema.c +++ b/source4/lib/ldb/tools/ad2oLschema.c @@ -37,6 +37,7 @@ #include "tools/cmdline.h" #include "tools/convert.h" #include "param/param.h" +#include "lib/cmdline/popt_common.h" struct schema_conv { int count; @@ -677,7 +678,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } - target_str = lp_parm_string(global_loadparm, NULL, "convert", "target"); + target_str = lp_parm_string(cmdline_lp_ctx, NULL, "convert", "target"); if (!target_str || strcasecmp(target_str, "openldap") == 0) { target = TARGET_OPENLDAP; diff --git a/source4/lib/messaging/config.mk b/source4/lib/messaging/config.mk index 843851e853..3fec9c0c90 100644 --- a/source4/lib/messaging/config.mk +++ b/source4/lib/messaging/config.mk @@ -10,6 +10,7 @@ PUBLIC_DEPENDENCIES = \ NDR_IRPC \ UNIX_PRIVS \ UTIL_TDB \ - CLUSTER + CLUSTER \ + LIBNDR # End SUBSYSTEM MESSAGING ################################################ diff --git a/source4/lib/messaging/irpc.h b/source4/lib/messaging/irpc.h index 989e5d4255..d596c6721e 100644 --- a/source4/lib/messaging/irpc.h +++ b/source4/lib/messaging/irpc.h @@ -92,9 +92,11 @@ NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private, struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, const char *dir, struct server_id server_id, + struct smb_iconv_convenience *iconv_convenience, struct event_context *ev); struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, const char *dir, + struct smb_iconv_convenience *iconv_convenience, struct event_context *ev); NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, uint32_t msg_type, void *ptr); diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index df0bfa32a6..811d5a85bf 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -49,6 +49,7 @@ struct messaging_context { struct idr_context *dispatch_tree; struct messaging_rec *pending; struct messaging_rec *retry_queue; + struct smb_iconv_convenience *iconv_convenience; struct irpc_list *irpc; struct idr_context *idr; const char **names; @@ -532,6 +533,7 @@ static int messaging_destructor(struct messaging_context *msg) struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, const char *dir, struct server_id server_id, + struct smb_iconv_convenience *iconv_convenience, struct event_context *ev) { struct messaging_context *msg; @@ -560,6 +562,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, msg->base_path = talloc_reference(msg, dir); msg->path = messaging_path(msg, server_id); msg->server_id = server_id; + msg->iconv_convenience = iconv_convenience; msg->idr = idr_init(msg); msg->dispatch_tree = idr_init(msg); msg->start_time = timeval_current(); @@ -609,12 +612,13 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, */ struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, const char *dir, + struct smb_iconv_convenience *iconv_convenience, struct event_context *ev) { struct server_id id; ZERO_STRUCT(id); id.id = random() % 0x10000000; - return messaging_init(mem_ctx, dir, id, ev); + return messaging_init(mem_ctx, dir, id, iconv_convenience, ev); } /* a list of registered irpc server functions @@ -698,7 +702,7 @@ NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status) m->header.status = status; /* setup the reply */ - push = ndr_push_init_ctx(m->ndr); + push = ndr_push_init_ctx(m->ndr, m->msg_ctx->iconv_convenience); if (push == NULL) { status = NT_STATUS_NO_MEMORY; goto failed; @@ -798,7 +802,7 @@ static void irpc_handler(struct messaging_context *msg_ctx, void *private, m->from = src; - m->ndr = ndr_pull_init_blob(packet, m); + m->ndr = ndr_pull_init_blob(packet, m, msg_ctx->iconv_convenience); if (m->ndr == NULL) goto failed; m->ndr->flags |= LIBNDR_FLAG_REF_ALLOC; @@ -890,7 +894,7 @@ struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, header.status = NT_STATUS_OK; /* construct the irpc packet */ - ndr = ndr_push_init_ctx(irpc); + ndr = ndr_push_init_ctx(irpc, msg_ctx->iconv_convenience); if (ndr == NULL) goto failed; ndr_err = ndr_push_irpc_header(ndr, NDR_SCALARS|NDR_BUFFERS, &header); diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index 0618adcfb2..ce3d1045e5 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -221,13 +221,17 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) torture_assert(tctx, data->msg_ctx1 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID1), data->ev), + cluster_id(MSG_ID1), + lp_iconv_convenience(tctx->lp_ctx), + data->ev), "Failed to init first messaging context"); torture_assert(tctx, data->msg_ctx2 = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(MSG_ID2), data->ev), + cluster_id(MSG_ID2), + lp_iconv_convenience(tctx->lp_ctx), + data->ev), "Failed to init second messaging context"); /* register the server side function */ diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index ba3d2f91d6..0df04bce2b 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -73,7 +73,9 @@ static bool test_ping_speed(struct torture_context *tctx) msg_server_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(1), ev); + cluster_id(1), + lp_iconv_convenience(tctx->lp_ctx), + ev); torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context"); @@ -82,7 +84,9 @@ static bool test_ping_speed(struct torture_context *tctx) msg_client_ctx = messaging_init(tctx, lp_messaging_path(tctx, tctx->lp_ctx), - cluster_id(2), ev); + cluster_id(2), + lp_iconv_convenience(tctx->lp_ctx), + ev); torture_assert(tctx, msg_client_ctx != NULL, "msg_client_ctx messaging_init() failed"); diff --git a/source4/lib/policy/lex.c b/source4/lib/policy/lex.c index 5364706fc4..c2899aa808 100644 --- a/source4/lib/policy/lex.c +++ b/source4/lib/policy/lex.c @@ -587,6 +587,7 @@ char *yytext; #line 23 "lex.l" #include "includes.h" #include "lib/policy/parse_adm.h" +#include "param/param.h" void error_message (const char *format, ...); int yyparse (void); @@ -600,7 +601,7 @@ static bool utf16 = false; if (fread(&v, 2, 1, yyin) < 1) \ result = YY_NULL; \ else \ - result = push_codepoint(global_smb_iconv_convenience, buf, v); \ + result = push_codepoint(lp_iconv_convenience(global_loadparm), buf, v); \ } else { \ int c = getc(yyin); \ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ diff --git a/source4/lib/registry/dir.c b/source4/lib/registry/dir.c index 532770bcaf..2f00d2fea0 100644 --- a/source4/lib/registry/dir.c +++ b/source4/lib/registry/dir.c @@ -272,7 +272,7 @@ static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx, } static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx, - const struct hive_key *key, int idx, + struct hive_key *key, int idx, const char **name, uint32_t *type, DATA_BLOB *data) { diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c index 16534aac9c..64bee8251b 100644 --- a/source4/lib/registry/hive.c +++ b/source4/lib/registry/hive.c @@ -27,6 +27,7 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, + struct loadparm_context *lp_ctx, struct hive_key **root) { int fd, num; @@ -51,11 +52,11 @@ _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, if (!strncmp(peek, "regf", 4)) { close(fd); - return reg_open_regf_file(parent_ctx, location, root); + return reg_open_regf_file(parent_ctx, location, lp_ctx, root); } else if (!strncmp(peek, "TDB file", 8)) { close(fd); return reg_open_ldb_file(parent_ctx, location, session_info, - credentials, root); + credentials, lp_ctx, root); } return WERR_BADFILE; diff --git a/source4/lib/registry/hive.h b/source4/lib/registry/hive.h index 2f783dd15d..ffb92f8e79 100644 --- a/source4/lib/registry/hive.h +++ b/source4/lib/registry/hive.h @@ -22,6 +22,7 @@ #define __REGISTRY_HIVE_H__ #include <talloc.h> +#include "libcli/util/werror.h" #include "librpc/gen_ndr/security.h" #include "libcli/util/ntstatus.h" @@ -81,7 +82,7 @@ struct hive_operations { * Retrieve a registry value with a specific index. */ WERROR (*enum_value) (TALLOC_CTX *mem_ctx, - const struct hive_key *key, int idx, + struct hive_key *key, int idx, const char **name, uint32_t *type, DATA_BLOB *data); @@ -143,6 +144,7 @@ struct auth_session_info; WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, + struct loadparm_context *lp_ctx, struct hive_key **root); WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key, const char **classname, uint32_t *num_subkeys, @@ -182,10 +184,12 @@ WERROR hive_key_flush(struct hive_key *key); WERROR reg_open_directory(TALLOC_CTX *parent_ctx, const char *location, struct hive_key **key); WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, - const char *location, struct hive_key **key); + const char *location, struct loadparm_context *lp_ctx, + struct hive_key **key); WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, + struct loadparm_context *lp_ctx, struct hive_key **k); diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c index 8f60a55ae9..b914fbab30 100644 --- a/source4/lib/registry/interface.c +++ b/source4/lib/registry/interface.c @@ -74,7 +74,7 @@ _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx, } /** Get predefined key by id. */ -_PUBLIC_ WERROR reg_get_predefined_key(const struct registry_context *ctx, +_PUBLIC_ WERROR reg_get_predefined_key(struct registry_context *ctx, uint32_t hkey, struct registry_key **key) { return ctx->ops->get_predefined_key(ctx, hkey, key); diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 0e556da9e2..c9697ddb4c 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -54,7 +54,7 @@ static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, struct ldb_message *msg, { case REG_SZ: case REG_EXPAND_SZ: - data->length = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF8, CH_UTF16, + data->length = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF8, CH_UTF16, val->data, val->length, (void **)&data->data); break; @@ -85,7 +85,7 @@ static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, switch (type) { case REG_SZ: case REG_EXPAND_SZ: - val.length = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + val.length = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, (void *)data.data, data.length, (void **)&val.data); @@ -249,7 +249,7 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx, return WERR_OK; } -static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, const struct hive_key *k, +static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct hive_key *k, int idx, const char **name, uint32_t *data_type, DATA_BLOB *data) { @@ -337,6 +337,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h, WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, + struct loadparm_context *lp_ctx, struct hive_key **k) { struct ldb_key_data *kd; @@ -345,7 +346,7 @@ WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, if (location == NULL) return WERR_INVALID_PARAM; - wrap = ldb_wrap_connect(parent_ctx, global_loadparm, + wrap = ldb_wrap_connect(parent_ctx, lp_ctx, location, session_info, credentials, 0, NULL); if (wrap == NULL) { diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c index b54f0cf30a..1ed4f0262e 100644 --- a/source4/lib/registry/local.c +++ b/source4/lib/registry/local.c @@ -126,7 +126,7 @@ static WERROR local_open_key(TALLOC_CTX *mem_ctx, return WERR_OK; } -WERROR local_get_predefined_key(const struct registry_context *ctx, +WERROR local_get_predefined_key(struct registry_context *ctx, uint32_t key_id, struct registry_key **key) { struct registry_local *rctx = talloc_get_type(ctx, @@ -168,7 +168,7 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx, struct security_descriptor *security, struct registry_key **key) { - const struct local_key *local_parent; + struct local_key *local_parent; struct hive_key *hivekey; const char **elements; int i; @@ -177,11 +177,11 @@ static WERROR local_create_key(TALLOC_CTX *mem_ctx, last_part = strrchr(name, '\\'); if (last_part == NULL) { last_part = name; - local_parent = (const struct local_key *)parent_key; + local_parent = (struct local_key *)parent_key; } else { W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key, talloc_strndup(mem_ctx, name, last_part-name), - &local_parent)); + (struct registry_key **)&local_parent)); last_part++; } @@ -321,7 +321,7 @@ WERROR reg_mount_hive(struct registry_context *rctx, mp->path.predefined_key = key_id; mp->prev = mp->next = NULL; mp->key = hive_key; - if (elements != NULL) { + if (elements != NULL && str_list_length(elements) != 0) { mp->path.elements = talloc_array(mp, const char *, str_list_length(elements)); for (i = 0; elements[i] != NULL; i++) { diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index 6af239fc21..9cc9a5dec2 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -23,7 +23,7 @@ #include "lib/registry/registry.h" #include "lib/registry/patchfile.h" #include "system/filesys.h" -#include "pstring.h" +#include "param/param.h" struct preg_data { int fd; @@ -36,20 +36,18 @@ static WERROR preg_read_utf16(int fd, char *c) if (read(fd, &v, 2) < 2) { return WERR_GENERAL_FAILURE; } - push_codepoint(global_smb_iconv_convenience, c, v); + push_codepoint(lp_iconv_convenience(global_loadparm), c, v); return WERR_OK; } /* FIXME These functions need to be implemented */ static WERROR reg_preg_diff_add_key(void *_data, const char *key_name) { - struct preg_data *data = (struct preg_data *)_data; return WERR_OK; } static WERROR reg_preg_diff_del_key(void *_data, const char *key_name) { - struct preg_data *data = (struct preg_data *)_data; return WERR_OK; } @@ -57,20 +55,17 @@ static WERROR reg_preg_diff_set_value(void *_data, const char *key_name, const char *value_name, uint32_t value_type, DATA_BLOB value_data) { - struct preg_data *data = (struct preg_data *)_data; return WERR_OK; } static WERROR reg_preg_diff_del_value(void *_data, const char *key_name, const char *value_name) { - struct preg_data *data = (struct preg_data *)_data; return WERR_OK; } static WERROR reg_preg_diff_del_all_values(void *_data, const char *key_name) { - struct preg_data *data = (struct preg_data *)_data; return WERR_OK; } @@ -135,22 +130,29 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, char hdr[4]; uint32_t version; } preg_header; - pstring buf; - char *buf_ptr = buf; + char *buf; + size_t buf_size = 1024; + char *buf_ptr; TALLOC_CTX *mem_ctx = talloc_init("reg_preg_diff_load"); + WERROR ret = WERR_OK; + DATA_BLOB data = {NULL, 0}; + char *key = NULL; + char *value_name = NULL; + buf = talloc_array(mem_ctx, char, buf_size); + buf_ptr = buf; /* Read first 8 bytes (the header) */ if (read(fd, &preg_header, 8) != 8) { DEBUG(0, ("Could not read PReg file: %s\n", strerror(errno))); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } if (strncmp(preg_header.hdr, "PReg", 4) != 0) { DEBUG(0, ("This file is not a valid preg registry file\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } if (preg_header.version > 1) { DEBUG(0, ("Warning: file format version is higher than expected.\n")); @@ -158,23 +160,21 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, /* Read the entries */ while(1) { - char *key, *value_name; uint32_t value_type, length; - DATA_BLOB data; if (!W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr))) { break; } if (*buf_ptr != '[') { DEBUG(0, ("Error in PReg file.\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } /* Get the path */ buf_ptr = buf; while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && - *buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) { + *buf_ptr != ';' && buf_ptr-buf < buf_size) { buf_ptr++; } key = talloc_asprintf(mem_ctx, "\\%s", buf); @@ -182,7 +182,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, /* Get the name */ buf_ptr = buf; while (W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && - *buf_ptr != ';' && buf_ptr-buf < sizeof(buf)) { + *buf_ptr != ';' && buf_ptr-buf < buf_size) { buf_ptr++; } value_name = talloc_strdup(mem_ctx, buf); @@ -190,45 +190,45 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, /* Get the type */ if (read(fd, &value_type, 4) < 4) { DEBUG(0, ("Error while reading PReg\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } /* Read past delimiter */ buf_ptr = buf; if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && - *buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) { + *buf_ptr == ';') && buf_ptr-buf < buf_size) { DEBUG(0, ("Error in PReg file.\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } /* Get data length */ if (read(fd, &length, 4) < 4) { DEBUG(0, ("Error while reading PReg\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } /* Read past delimiter */ buf_ptr = buf; if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && - *buf_ptr == ';') && buf_ptr-buf < sizeof(buf)) { + *buf_ptr == ';') && buf_ptr-buf < buf_size) { DEBUG(0, ("Error in PReg file.\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } /* Get the data */ buf_ptr = buf; - if (length < sizeof(buf) && + if (length < buf_size && read(fd, buf_ptr, length) != length) { DEBUG(0, ("Error while reading PReg\n")); - close(fd); - return WERR_GENERAL_FAILURE; + ret = WERR_GENERAL_FAILURE; + goto cleanup; } data = data_blob_talloc(mem_ctx, buf, length); /* Check if delimiter is in place (whine if it isn't) */ buf_ptr = buf; if (!(W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr)) && - *buf_ptr == ']') && buf_ptr-buf < sizeof(buf)) { + *buf_ptr == ']') && buf_ptr-buf < buf_size) { DEBUG(0, ("Warning: Missing ']' in PReg file, expected ']', got '%c' 0x%x.\n", *buf_ptr, *buf_ptr)); } @@ -277,10 +277,12 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, callbacks->set_value(callback_data, key, value_name, value_type, data); } - talloc_free(key); - talloc_free(value_name); - talloc_free(data.data); } +cleanup: close(fd); - return WERR_OK; + talloc_free(data.data); + talloc_free(key); + talloc_free(value_name); + talloc_free(buf); + return ret; } diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c index 3ae299b3ef..28bd0ad461 100644 --- a/source4/lib/registry/regf.c +++ b/source4/lib/registry/regf.c @@ -24,6 +24,7 @@ #include "lib/registry/tdr_regf.h" #include "librpc/gen_ndr/ndr_security.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" static struct hive_operations reg_backend_regf; @@ -47,6 +48,7 @@ struct regf_data { int fd; struct hbin_block **hbins; struct regf_hdr *header; + struct smb_iconv_convenience *iconv_convenience; }; static WERROR regf_save_hbin(struct regf_data *data); @@ -131,21 +133,22 @@ static DATA_BLOB hbin_get(const struct regf_data *data, uint32_t offset) static bool hbin_get_tdr(struct regf_data *regf, uint32_t offset, TALLOC_CTX *ctx, tdr_pull_fn_t pull_fn, void *p) { - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); - ZERO_STRUCT(pull); - - pull.data = hbin_get(regf, offset); - if (!pull.data.data) { + pull->data = hbin_get(regf, offset); + if (!pull->data.data) { DEBUG(1, ("Unable to get data at 0x%04x\n", offset)); + talloc_free(pull); return false; } - if (NT_STATUS_IS_ERR(pull_fn(&pull, ctx, p))) { + if (NT_STATUS_IS_ERR(pull_fn(pull, ctx, p))) { DEBUG(1, ("Error parsing record at 0x%04x using tdr\n", offset)); + talloc_free(pull); return false; } + talloc_free(pull); return true; } @@ -263,7 +266,7 @@ static uint32_t hbin_store (struct regf_data *data, DATA_BLOB blob) static uint32_t hbin_store_tdr(struct regf_data *data, tdr_push_fn_t push_fn, void *p) { - struct tdr_push *push = talloc_zero(data, struct tdr_push); + struct tdr_push *push = tdr_push_init(data, data->iconv_convenience); uint32_t ret; if (NT_STATUS_IS_ERR(push_fn(push, p))) { @@ -390,7 +393,7 @@ static uint32_t hbin_store_tdr_resize(struct regf_data *regf, tdr_push_fn_t push_fn, uint32_t orig_offset, void *p) { - struct tdr_push *push = talloc_zero(regf, struct tdr_push); + struct tdr_push *push = tdr_push_init(regf, regf->iconv_convenience); uint32_t ret; if (NT_STATUS_IS_ERR(push_fn(push, p))) { @@ -485,7 +488,7 @@ static struct regf_key_data *regf_get_key(TALLOC_CTX *ctx, } -static WERROR regf_get_value(TALLOC_CTX *ctx, const struct hive_key *key, +static WERROR regf_get_value(TALLOC_CTX *ctx, struct hive_key *key, int idx, const char **name, uint32_t *data_type, DATA_BLOB *data) { @@ -592,16 +595,17 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, if (!strncmp((char *)data.data, "li", 2)) { struct li_block li; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(private_data->hive, private_data->hive->iconv_convenience); DEBUG(10, ("Subkeys in LI list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, nk, &li))) { + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, nk, &li))) { DEBUG(0, ("Error parsing LI list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(li.header, "li", 2)); if (li.key_count != nk->num_subkeys) { @@ -612,16 +616,17 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, } else if (!strncmp((char *)data.data, "lf", 2)) { struct lf_block lf; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(private_data->hive, private_data->hive->iconv_convenience); DEBUG(10, ("Subkeys in LF list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lf_block(&pull, nk, &lf))) { + if (NT_STATUS_IS_ERR(tdr_pull_lf_block(pull, nk, &lf))) { DEBUG(0, ("Error parsing LF list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lf.header, "lf", 2)); if (lf.key_count != nk->num_subkeys) { @@ -632,16 +637,17 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, key_off = lf.hr[idx].nk_offset; } else if (!strncmp((char *)data.data, "lh", 2)) { struct lh_block lh; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(private_data->hive, private_data->hive->iconv_convenience); DEBUG(10, ("Subkeys in LH list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, nk, &lh))) { + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, nk, &lh))) { DEBUG(0, ("Error parsing LH list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lh.header, "lh", 2)); if (lh.key_count != nk->num_subkeys) { @@ -651,16 +657,16 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, key_off = lh.hr[idx].nk_offset; } else if (!strncmp((char *)data.data, "ri", 2)) { struct ri_block ri; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); uint16_t i; uint16_t sublist_count = 0; DEBUG(10, ("Subkeys in RI list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_ri_block(&pull, nk, &ri))) { + if (NT_STATUS_IS_ERR(tdr_pull_ri_block(pull, nk, &ri))) { DEBUG(0, ("Error parsing RI list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(ri.header, "ri", 2)); @@ -672,21 +678,22 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, list_data = hbin_get(private_data->hive, ri.offset[i]); if (!list_data.data) { DEBUG(0, ("Error getting RI list.")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } - ZERO_STRUCT(pull); - pull.data = list_data; + pull->data = list_data; if (!strncmp((char *)list_data.data, "li", 2)) { struct li_block li; DEBUG(10, ("Subkeys in RI->LI list\n")); - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, nk, &li))) { DEBUG(0, ("Error parsing LI list from RI\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(li.header, "li", 2)); @@ -704,10 +711,11 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, DEBUG(10, ("Subkeys in RI->LH list\n")); - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, nk, &lh))) { DEBUG(0, ("Error parsing LH list from RI\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(lh.header, "lh", 2)); @@ -722,11 +730,14 @@ static WERROR regf_get_subkey_by_index(TALLOC_CTX *ctx, break; } else { DEBUG(0,("Unknown sublist in ri block\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } } + talloc_free(pull); + if (idx > sublist_count) { return WERR_NO_MORE_ITEMS; @@ -769,7 +780,7 @@ static WERROR regf_match_subkey_by_name(TALLOC_CTX *ctx, { DATA_BLOB subkey_data; struct nk_block subkey; - struct tdr_pull pull; + struct tdr_pull *pull; const struct regf_key_data *private_data = (const struct regf_key_data *)key; @@ -779,13 +790,16 @@ static WERROR regf_match_subkey_by_name(TALLOC_CTX *ctx, return WERR_GENERAL_FAILURE; } - ZERO_STRUCT(pull); - pull.data = subkey_data; + pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); + + pull->data = subkey_data; - if (NT_STATUS_IS_ERR(tdr_pull_nk_block(&pull, ctx, &subkey))) { + if (NT_STATUS_IS_ERR(tdr_pull_nk_block(pull, ctx, &subkey))) { DEBUG(0, ("Error parsing NK structure.\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); if (strncmp(subkey.header, "nk", 2)) { DEBUG(0, ("Not an NK structure.\n")); @@ -819,17 +833,18 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, if (!strncmp((char *)data.data, "li", 2)) { struct li_block li; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); uint16_t i; DEBUG(10, ("Subkeys in LI list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, nk, &li))) { + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, nk, &li))) { DEBUG(0, ("Error parsing LI list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(li.header, "li", 2)); if (li.key_count != nk->num_subkeys) { @@ -849,17 +864,18 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, return WERR_NOT_FOUND; } else if (!strncmp((char *)data.data, "lf", 2)) { struct lf_block lf; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); uint16_t i; DEBUG(10, ("Subkeys in LF list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lf_block(&pull, nk, &lf))) { + if (NT_STATUS_IS_ERR(tdr_pull_lf_block(pull, nk, &lf))) { DEBUG(0, ("Error parsing LF list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lf.header, "lf", 2)); if (lf.key_count != nk->num_subkeys) { @@ -883,18 +899,19 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, return WERR_NOT_FOUND; } else if (!strncmp((char *)data.data, "lh", 2)) { struct lh_block lh; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); uint16_t i; uint32_t hash; DEBUG(10, ("Subkeys in LH list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, nk, &lh))) { + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, nk, &lh))) { DEBUG(0, ("Error parsing LH list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lh.header, "lh", 2)); if (lh.key_count != nk->num_subkeys) { @@ -919,15 +936,15 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, return WERR_NOT_FOUND; } else if (!strncmp((char *)data.data, "ri", 2)) { struct ri_block ri; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(ctx, private_data->hive->iconv_convenience); uint16_t i, j; DEBUG(10, ("Subkeys in RI list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_ri_block(&pull, nk, &ri))) { + if (NT_STATUS_IS_ERR(tdr_pull_ri_block(pull, nk, &ri))) { DEBUG(0, ("Error parsing RI list\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(ri.header, "ri", 2)); @@ -939,19 +956,20 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, list_data = hbin_get(private_data->hive, ri.offset[i]); if (list_data.data == NULL) { DEBUG(0, ("Error getting RI list.")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } - ZERO_STRUCT(pull); - pull.data = list_data; + pull->data = list_data; if (!strncmp((char *)list_data.data, "li", 2)) { struct li_block li; - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, nk, &li))) { DEBUG(0, ("Error parsing LI list from RI\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(li.header, "li", 2)); @@ -968,10 +986,11 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, struct lh_block lh; uint32_t hash; - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, nk, &lh))) { DEBUG(0, ("Error parsing LH list from RI\n")); + talloc_free(pull); return WERR_GENERAL_FAILURE; } SMB_ASSERT(!strncmp(lh.header, "lh", 2)); @@ -992,6 +1011,7 @@ static WERROR regf_get_subkey_by_name(TALLOC_CTX *ctx, if (key_off) break; } + talloc_free(pull); if (!key_off) return WERR_NOT_FOUND; } else { @@ -1258,16 +1278,17 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset, } if (!strncmp((char *)data.data, "li", 2)) { - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); struct li_block li; - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, regf, &li))) { + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, regf, &li))) { DEBUG(0, ("Error parsing LI list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); if (strncmp(li.header, "li", 2) != 0) { abort(); @@ -1286,16 +1307,17 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset, talloc_free(li.nk_offset); } else if (!strncmp((char *)data.data, "lf", 2)) { - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); struct lf_block lf; - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lf_block(&pull, regf, &lf))) { + if (NT_STATUS_IS_ERR(tdr_pull_lf_block(pull, regf, &lf))) { DEBUG(0, ("Error parsing LF list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lf.header, "lf", 2)); lf.hr = talloc_realloc(regf, lf.hr, struct hash_record, @@ -1311,16 +1333,17 @@ static WERROR regf_sl_add_entry(struct regf_data *regf, uint32_t list_offset, talloc_free(lf.hr); } else if (!strncmp((char *)data.data, "lh", 2)) { - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); struct lh_block lh; - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, regf, &lh))) { + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, regf, &lh))) { DEBUG(0, ("Error parsing LH list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lh.header, "lh", 2)); lh.hr = talloc_realloc(regf, lh.hr, struct lh_hash, @@ -1359,19 +1382,20 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset, if (strncmp((char *)data.data, "li", 2) == 0) { struct li_block li; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); uint16_t i; bool found_offset = false; DEBUG(10, ("Subkeys in LI list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_li_block(&pull, regf, &li))) { + if (NT_STATUS_IS_ERR(tdr_pull_li_block(pull, regf, &li))) { DEBUG(0, ("Error parsing LI list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); SMB_ASSERT(!strncmp(li.header, "li", 2)); @@ -1402,19 +1426,20 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset, list_offset, &li); } else if (strncmp((char *)data.data, "lf", 2) == 0) { struct lf_block lf; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); uint16_t i; bool found_offset = false; DEBUG(10, ("Subkeys in LF list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lf_block(&pull, regf, &lf))) { + if (NT_STATUS_IS_ERR(tdr_pull_lf_block(pull, regf, &lf))) { DEBUG(0, ("Error parsing LF list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lf.header, "lf", 2)); @@ -1447,19 +1472,20 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset, list_offset, &lf); } else if (strncmp((char *)data.data, "lh", 2) == 0) { struct lh_block lh; - struct tdr_pull pull; + struct tdr_pull *pull = tdr_pull_init(regf, regf->iconv_convenience); uint16_t i; bool found_offset = false; DEBUG(10, ("Subkeys in LH list\n")); - ZERO_STRUCT(pull); - pull.data = data; + pull->data = data; - if (NT_STATUS_IS_ERR(tdr_pull_lh_block(&pull, regf, &lh))) { + if (NT_STATUS_IS_ERR(tdr_pull_lh_block(pull, regf, &lh))) { DEBUG(0, ("Error parsing LF list\n")); + talloc_free(pull); return WERR_BADFILE; } + talloc_free(pull); SMB_ASSERT(!strncmp(lh.header, "lh", 2)); @@ -1503,8 +1529,7 @@ static WERROR regf_sl_del_entry(struct regf_data *regf, uint32_t list_offset, static WERROR regf_del_value (struct hive_key *key, const char *name) { - const struct regf_key_data *private_data = - (const struct regf_key_data *)key; + struct regf_key_data *private_data = (struct regf_key_data *)key; struct regf_data *regf = private_data->hive; struct nk_block *nk = private_data->nk; struct vk_block vk; @@ -1677,8 +1702,7 @@ static WERROR regf_add_key(TALLOC_CTX *ctx, const struct hive_key *parent, static WERROR regf_set_value(struct hive_key *key, const char *name, uint32_t type, const DATA_BLOB data) { - const struct regf_key_data *private_data = - (const struct regf_key_data *)key; + struct regf_key_data *private_data = (struct regf_key_data *)key; struct regf_data *regf = private_data->hive; struct nk_block *nk = private_data->nk; struct vk_block vk; @@ -1788,7 +1812,7 @@ static WERROR regf_set_value(struct hive_key *key, const char *name, static WERROR regf_save_hbin(struct regf_data *regf) { - struct tdr_push *push = talloc_zero(regf, struct tdr_push); + struct tdr_push *push = tdr_push_init(regf, regf->iconv_convenience); int i; W_ERROR_HAVE_NO_MEMORY(push); @@ -1806,7 +1830,7 @@ static WERROR regf_save_hbin(struct regf_data *regf) regf->header->chksum = regf_hdr_checksum(push->data.data); talloc_free(push); - if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, + if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, regf->iconv_convenience, (tdr_push_fn_t)tdr_push_regf_hdr, regf->header))) { DEBUG(0, ("Error writing registry file header\n")); @@ -1819,7 +1843,7 @@ static WERROR regf_save_hbin(struct regf_data *regf) } for (i = 0; regf->hbins[i]; i++) { - if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, + if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, regf->iconv_convenience, (tdr_push_fn_t)tdr_push_hbin_block, regf->hbins[i]))) { DEBUG(0, ("Error writing HBIN block\n")); @@ -1835,13 +1859,14 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location, { struct regf_data *regf; struct regf_hdr *regf_hdr; - struct tdr_pull pull; int i; struct nk_block nk; WERROR error; regf = (struct regf_data *)talloc_zero(NULL, struct regf_data); + regf->iconv_convenience = lp_iconv_convenience(global_loadparm); + W_ERROR_HAVE_NO_MEMORY(regf); DEBUG(5, ("Attempting to create registry file\n")); @@ -1870,8 +1895,6 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location, regf->header = regf_hdr; - pull.offset = 0x1000; - i = 0; /* Create all hbin blocks */ regf->hbins = talloc_array(regf, struct hbin_block *, 1); @@ -1917,16 +1940,18 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, const char *location, return WERR_OK; } -WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, - const char *location, struct hive_key **key) +WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location, + struct loadparm_context *lp_ctx, struct hive_key **key) { struct regf_data *regf; struct regf_hdr *regf_hdr; - struct tdr_pull pull; + struct tdr_pull *pull; int i; regf = (struct regf_data *)talloc_zero(NULL, struct regf_data); + regf->iconv_convenience = lp_iconv_convenience(lp_ctx); + W_ERROR_HAVE_NO_MEMORY(regf); DEBUG(5, ("Attempting to load registry file\n")); @@ -1941,10 +1966,11 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, return WERR_GENERAL_FAILURE; } - ZERO_STRUCT(pull); - pull.data.data = (uint8_t*)fd_load(regf->fd, &pull.data.length, regf); + pull = tdr_pull_init(regf, regf->iconv_convenience); + + pull->data.data = (uint8_t*)fd_load(regf->fd, &pull->data.length, regf); - if (pull.data.data == NULL) { + if (pull->data.data == NULL) { DEBUG(0, ("Error reading data\n")); talloc_free(regf); return WERR_GENERAL_FAILURE; @@ -1953,7 +1979,7 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, regf_hdr = talloc(regf, struct regf_hdr); W_ERROR_HAVE_NO_MEMORY(regf_hdr); - if (NT_STATUS_IS_ERR(tdr_pull_regf_hdr(&pull, regf_hdr, regf_hdr))) { + if (NT_STATUS_IS_ERR(tdr_pull_regf_hdr(pull, regf_hdr, regf_hdr))) { talloc_free(regf); return WERR_GENERAL_FAILURE; } @@ -1968,15 +1994,15 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, } /* Validate the header ... */ - if (regf_hdr_checksum(pull.data.data) != regf_hdr->chksum) { + if (regf_hdr_checksum(pull->data.data) != regf_hdr->chksum) { DEBUG(0, ("Registry file checksum error: %s: %d,%d\n", location, regf_hdr->chksum, - regf_hdr_checksum(pull.data.data))); + regf_hdr_checksum(pull->data.data))); talloc_free(regf); return WERR_GENERAL_FAILURE; } - pull.offset = 0x1000; + pull->offset = 0x1000; i = 0; /* Read in all hbin blocks */ @@ -1985,14 +2011,14 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, regf->hbins[0] = NULL; - while (pull.offset < pull.data.length && - pull.offset <= regf->header->last_block) { + while (pull->offset < pull->data.length && + pull->offset <= regf->header->last_block) { struct hbin_block *hbin = talloc(regf->hbins, struct hbin_block); W_ERROR_HAVE_NO_MEMORY(hbin); - if (NT_STATUS_IS_ERR(tdr_pull_hbin_block(&pull, hbin, hbin))) { + if (NT_STATUS_IS_ERR(tdr_pull_hbin_block(pull, hbin, hbin))) { DEBUG(0, ("[%d] Error parsing HBIN block\n", i)); talloc_free(regf); return WERR_FOOBAR; @@ -2012,6 +2038,8 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, regf->hbins[i] = NULL; } + talloc_free(pull); + DEBUG(1, ("%d HBIN blocks read\n", i)); *key = (struct hive_key *)regf_get_key(parent_ctx, regf, diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h index edd6c6713f..a02acbea1e 100644 --- a/source4/lib/registry/registry.h +++ b/source4/lib/registry/registry.h @@ -94,7 +94,7 @@ struct registry_operations { WERROR (*flush_key) (struct registry_key *key); - WERROR (*get_predefined_key) (const struct registry_context *ctx, + WERROR (*get_predefined_key) (struct registry_context *ctx, uint32_t key_id, struct registry_key **key); @@ -195,7 +195,7 @@ const char *reg_get_predef_name(uint32_t hkey); WERROR reg_get_predefined_key_by_name(struct registry_context *ctx, const char *name, struct registry_key **key); -WERROR reg_get_predefined_key(const struct registry_context *ctx, +WERROR reg_get_predefined_key(struct registry_context *ctx, uint32_t hkey, struct registry_key **key); diff --git a/source4/lib/registry/registry.i b/source4/lib/registry/registry.i index 330f0856e1..1819e7df80 100644 --- a/source4/lib/registry/registry.i +++ b/source4/lib/registry/registry.i @@ -25,6 +25,7 @@ #include "includes.h" #include "registry.h" +#include "param/param.h" typedef struct registry_context reg; typedef struct hive_key hive; @@ -39,6 +40,7 @@ typedef struct hive_key hive; %import "../../lib/talloc/talloc.i" %import "../../auth/credentials/credentials.i" %import "../../libcli/util/errors.i" +%import "../../param/param.i" /* Utility functions */ @@ -86,10 +88,11 @@ WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx, free((char **) $1); } +%talloctype(reg); + typedef struct registry_context { %extend { - ~reg() { talloc_free($self); } WERROR get_predefined_key_by_name(const char *name, struct registry_key **key); @@ -101,11 +104,18 @@ typedef struct registry_context { WERROR mount_hive(struct hive_key *hive_key, uint32_t hkey_id, const char **elements=NULL); - } - %pythoncode { - def mount(self, path, hkey_id, elements=[]): - self.mount_hive(Hive(path), hkey_id, elements) + WERROR mount_hive(struct hive_key *hive_key, const char *predef_name) + { + int i; + for (i = 0; reg_predefined_keys[i].name; i++) { + if (!strcasecmp(reg_predefined_keys[i].name, predef_name)) + return reg_mount_hive($self, hive_key, + reg_predefined_keys[i].handle, NULL); + } + return WERR_INVALID_NAME; + } + } } reg; @@ -123,12 +133,12 @@ typedef struct registry_context { WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, + struct loadparm_context *lp_ctx, struct hive_key **root); +%talloctype(hive); + typedef struct hive_key { - %extend { - ~hive() { talloc_free($self); } - } } hive; %rename(open_samba) reg_open_samba; diff --git a/source4/lib/registry/registry.py b/source4/lib/registry/registry.py index b61d713df8..67607cd7ac 100644 --- a/source4/lib/registry/registry.py +++ b/source4/lib/registry/registry.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _registry import new @@ -48,45 +47,41 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + import credentials +import param reg_get_predef_name = _registry.reg_get_predef_name str_regtype = _registry.str_regtype Registry = _registry.Registry -class reg(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, reg, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, reg, name) +class reg(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr - __swig_destroy__ = _registry.delete_reg - __del__ = lambda self : None; - def get_predefined_key_by_name(*args, **kwargs): return _registry.reg_get_predefined_key_by_name(*args, **kwargs) - def get_predefined_key(*args, **kwargs): return _registry.reg_get_predefined_key(*args, **kwargs) - def apply_patchfile(*args, **kwargs): return _registry.reg_apply_patchfile(*args, **kwargs) - def mount_hive(*args, **kwargs): return _registry.reg_mount_hive(*args, **kwargs) - def mount(self, path, hkey_id, elements=[]): - self.mount_hive(Hive(path), hkey_id, elements) - def __init__(self, *args, **kwargs): - this = _registry.new_reg(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _registry.reg_swiginit(self,_registry.new_reg(*args, **kwargs)) + __swig_destroy__ = _registry.delete_reg +reg.get_predefined_key_by_name = new_instancemethod(_registry.reg_get_predefined_key_by_name,None,reg) +reg.get_predefined_key = new_instancemethod(_registry.reg_get_predefined_key,None,reg) +reg.apply_patchfile = new_instancemethod(_registry.reg_apply_patchfile,None,reg) +reg.mount_hive = new_instancemethod(_registry.reg_mount_hive,None,reg) reg_swigregister = _registry.reg_swigregister reg_swigregister(reg) Hive = _registry.Hive -class hive(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, hive, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, hive, name) +class hive(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr - __swig_destroy__ = _registry.delete_hive - __del__ = lambda self : None; def __init__(self, *args, **kwargs): - this = _registry.new_hive(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _registry.hive_swiginit(self,_registry.new_hive(*args, **kwargs)) + __swig_destroy__ = _registry.delete_hive hive_swigregister = _registry.hive_swigregister hive_swigregister(hive) diff --git a/source4/lib/registry/registry_wrap.c b/source4/lib/registry/registry_wrap.c index 3ab0af10b5..fcbd2ea165 100644 --- a/source4/lib/registry/registry_wrap.c +++ b/source4/lib/registry/registry_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2463,20 +2463,24 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_hive_key swig_types[4] #define SWIGTYPE_p_int swig_types[5] #define SWIGTYPE_p_loadparm_context swig_types[6] -#define SWIGTYPE_p_long_long swig_types[7] -#define SWIGTYPE_p_p_char swig_types[8] -#define SWIGTYPE_p_p_hive_key swig_types[9] -#define SWIGTYPE_p_p_registry_context swig_types[10] -#define SWIGTYPE_p_p_registry_key swig_types[11] -#define SWIGTYPE_p_registry_context swig_types[12] -#define SWIGTYPE_p_short swig_types[13] -#define SWIGTYPE_p_signed_char swig_types[14] -#define SWIGTYPE_p_unsigned_char swig_types[15] -#define SWIGTYPE_p_unsigned_int swig_types[16] -#define SWIGTYPE_p_unsigned_long_long swig_types[17] -#define SWIGTYPE_p_unsigned_short swig_types[18] -static swig_type_info *swig_types[20]; -static swig_module_info swig_module = {swig_types, 19, 0, 0, 0, 0}; +#define SWIGTYPE_p_loadparm_service swig_types[7] +#define SWIGTYPE_p_long_long swig_types[8] +#define SWIGTYPE_p_p_char swig_types[9] +#define SWIGTYPE_p_p_hive_key swig_types[10] +#define SWIGTYPE_p_p_registry_context swig_types[11] +#define SWIGTYPE_p_p_registry_key swig_types[12] +#define SWIGTYPE_p_param_context swig_types[13] +#define SWIGTYPE_p_param_opt swig_types[14] +#define SWIGTYPE_p_param_section swig_types[15] +#define SWIGTYPE_p_registry_context swig_types[16] +#define SWIGTYPE_p_short swig_types[17] +#define SWIGTYPE_p_signed_char swig_types[18] +#define SWIGTYPE_p_unsigned_char swig_types[19] +#define SWIGTYPE_p_unsigned_int swig_types[20] +#define SWIGTYPE_p_unsigned_long_long swig_types[21] +#define SWIGTYPE_p_unsigned_short swig_types[22] +static swig_type_info *swig_types[24]; +static swig_module_info swig_module = {swig_types, 23, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2487,6 +2491,19 @@ static swig_module_info swig_module = {swig_types, 19, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _registry.so @@ -2509,6 +2526,7 @@ static swig_module_info swig_module = {swig_types, 19, 0, 0, 0, 0}; #include "includes.h" #include "registry.h" +#include "param/param.h" typedef struct registry_context reg; typedef struct hive_key hive; @@ -2755,7 +2773,6 @@ SWIG_AsVal_int (PyObject * obj, int *val) return res; } -SWIGINTERN void delete_reg(reg *self){ talloc_free(self); } SWIGINTERN int SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) @@ -2814,7 +2831,15 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) SWIGINTERN WERROR reg_apply_patchfile(reg *self,char const *filename){ return reg_diff_apply(filename, self); } -SWIGINTERN void delete_hive(hive *self){ talloc_free(self); } +SWIGINTERN WERROR reg_mount_hive__SWIG_1(reg *self,struct hive_key *hive_key,char const *predef_name){ + int i; + for (i = 0; reg_predefined_keys[i].name; i++) { + if (!strcasecmp(reg_predefined_keys[i].name, predef_name)) + return reg_mount_hive(self, hive_key, + reg_predefined_keys[i].handle, NULL); + } + return WERR_INVALID_NAME; + } #define SWIG_From_long PyInt_FromLong @@ -2949,28 +2974,6 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_reg(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - reg *arg1 = (reg *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_reg",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_registry_context, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_reg" "', argument " "1"" of type '" "reg *""'"); - } - arg1 = (reg *)(argp1); - delete_reg(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_reg_get_predefined_key_by_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; reg *arg1 = (reg *) 0 ; @@ -3118,7 +3121,7 @@ fail: } -SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_reg_mount_hive__SWIG_0(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; reg *arg1 = (reg *) 0 ; struct hive_key *arg2 = (struct hive_key *) 0 ; @@ -3131,41 +3134,34 @@ SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *SWIGUNUSEDPARM(self), PyObje int res2 = 0 ; unsigned int val3 ; int ecode3 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - PyObject * obj3 = 0 ; - char * kwnames[] = { - (char *) "self",(char *) "hive_key",(char *) "hkey_id",(char *) "elements", NULL - }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:reg_mount_hive",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_registry_context, 0 | 0 ); + if ((nobjs < 3) || (nobjs > 4)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_registry_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "reg_mount_hive" "', argument " "1"" of type '" "reg *""'"); } arg1 = (reg *)(argp1); - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_hive_key, 0 | 0 ); + res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_hive_key, 0 | 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "reg_mount_hive" "', argument " "2"" of type '" "struct hive_key *""'"); } arg2 = (struct hive_key *)(argp2); - ecode3 = SWIG_AsVal_unsigned_SS_int(obj2, &val3); + ecode3 = SWIG_AsVal_unsigned_SS_int(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "reg_mount_hive" "', argument " "3"" of type '" "uint32_t""'"); } arg3 = (uint32_t)(val3); - if (obj3) { + if (swig_obj[3]) { { /* Check if is a list */ - if (PyList_Check(obj3)) { - int size = PyList_Size(obj3); + if (PyList_Check(swig_obj[3])) { + int size = PyList_Size(swig_obj[3]); int i = 0; arg4 = (char **) malloc((size+1)*sizeof(const char *)); for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem(obj3,i); + PyObject *o = PyList_GetItem(swig_obj[3],i); if (PyString_Check(o)) - arg4[i] = PyString_AsString(PyList_GetItem(obj3,i)); + arg4[i] = PyString_AsString(PyList_GetItem(swig_obj[3],i)); else { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free(arg4); @@ -3200,11 +3196,87 @@ fail: } +SWIGINTERN PyObject *_wrap_reg_mount_hive__SWIG_1(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + reg *arg1 = (reg *) 0 ; + struct hive_key *arg2 = (struct hive_key *) 0 ; + char *arg3 = (char *) 0 ; + WERROR result; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_registry_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "reg_mount_hive" "', argument " "1"" of type '" "reg *""'"); + } + arg1 = (reg *)(argp1); + res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_hive_key, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "reg_mount_hive" "', argument " "2"" of type '" "struct hive_key *""'"); + } + arg2 = (struct hive_key *)(argp2); + res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "reg_mount_hive" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + result = reg_mount_hive__SWIG_1(arg1,arg2,(char const *)arg3); + { + if (!W_ERROR_IS_OK(result)) { + PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result)); + PyErr_SetObject(PyExc_RuntimeError, obj); + } else if (resultobj == NULL) { + resultobj = Py_None; + } + } + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *self, PyObject *args) { + int argc; + PyObject *argv[5]; + + if (!(argc = SWIG_Python_UnpackTuple(args,"reg_mount_hive",0,4,argv))) SWIG_fail; + --argc; + if ((argc >= 3) && (argc <= 4)) { + int _v = 0; + { + { + int res = SWIG_AsVal_unsigned_SS_int(argv[2], NULL); + _v = SWIG_CheckState(res); + } + } + if (!_v) goto check_1; + return _wrap_reg_mount_hive__SWIG_0(self, argc, argv); + } +check_1: + + if (argc == 3) { + return _wrap_reg_mount_hive__SWIG_1(self, argc, argv); + } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'reg_mount_hive'.\n Possible C/C++ prototypes are:\n"" mount_hive(reg *,struct hive_key *,uint32_t,char const **)\n"" mount_hive(reg *,struct hive_key *,char const *)\n"); + return NULL; +} + + SWIGINTERN PyObject *_wrap_new_reg(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; reg *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)":new_reg")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"new_reg",0,0,0)) SWIG_fail; result = (reg *)(reg *) calloc(1, sizeof(reg)); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_registry_context, SWIG_POINTER_NEW | 0 ); return resultobj; @@ -3213,20 +3285,48 @@ fail: } +SWIGINTERN PyObject *_wrap_delete_reg(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + reg *arg1 = (reg *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_registry_context, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_reg" "', argument " "1"" of type '" "reg *""'"); + } + arg1 = (reg *)(argp1); + free((char *) arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *reg_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_registry_context, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *reg_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_Hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; char *arg2 = (char *) 0 ; struct auth_session_info *arg3 = (struct auth_session_info *) 0 ; struct cli_credentials *arg4 = (struct cli_credentials *) 0 ; - struct hive_key **arg5 = (struct hive_key **) 0 ; + struct loadparm_context *arg5 = (struct loadparm_context *) 0 ; + struct hive_key **arg6 = (struct hive_key **) 0 ; WERROR result; int res2 ; char *buf2 = 0 ; @@ -3235,12 +3335,15 @@ SWIGINTERN PyObject *_wrap_Hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, int res3 = 0 ; void *argp4 = 0 ; int res4 = 0 ; - struct hive_key *tmp5 ; + void *argp5 = 0 ; + int res5 = 0 ; + struct hive_key *tmp6 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; char * kwnames[] = { - (char *) "location",(char *) "session_info",(char *) "credentials", NULL + (char *) "location",(char *) "session_info",(char *) "credentials",(char *) "lp_ctx", NULL }; { @@ -3250,12 +3353,15 @@ SWIGINTERN PyObject *_wrap_Hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, arg4 = NULL; } { + arg5 = loadparm_init(NULL); + } + { arg1 = NULL; } { - arg5 = &tmp5; + arg6 = &tmp6; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OO:Hive",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OOO:Hive",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res2 = SWIG_AsCharPtrAndSize(obj0, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Hive" "', argument " "2"" of type '" "char const *""'"); @@ -3275,7 +3381,14 @@ SWIGINTERN PyObject *_wrap_Hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, } arg4 = (struct cli_credentials *)(argp4); } - result = reg_open_hive(arg1,(char const *)arg2,arg3,arg4,arg5); + if (obj3) { + res5 = SWIG_ConvertPtr(obj3, &argp5,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "Hive" "', argument " "5"" of type '" "struct loadparm_context *""'"); + } + arg5 = (struct loadparm_context *)(argp5); + } + result = reg_open_hive(arg1,(char const *)arg2,arg3,arg4,arg5,arg6); { if (!W_ERROR_IS_OK(result)) { PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result)); @@ -3286,7 +3399,7 @@ SWIGINTERN PyObject *_wrap_Hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, } { Py_XDECREF(resultobj); - resultobj = SWIG_NewPointerObj(*arg5, SWIGTYPE_p_hive_key, 0); + resultobj = SWIG_NewPointerObj(*arg6, SWIGTYPE_p_hive_key, 0); } if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return resultobj; @@ -3296,20 +3409,34 @@ fail: } +SWIGINTERN PyObject *_wrap_new_hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + hive *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_hive",0,0,0)) SWIG_fail; + result = (hive *)(hive *) calloc(1, sizeof(hive)); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_hive_key, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_delete_hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; hive *arg1 = (hive *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_hive",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_hive_key, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_hive_key, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_hive" "', argument " "1"" of type '" "hive *""'"); } arg1 = (hive *)(argp1); - delete_hive(arg1); + free((char *) arg1); resultobj = SWIG_Py_Void(); return resultobj; @@ -3318,26 +3445,17 @@ fail: } -SWIGINTERN PyObject *_wrap_new_hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - hive *result = 0 ; - - if (!PyArg_ParseTuple(args,(char *)":new_hive")) SWIG_fail; - result = (hive *)(hive *) calloc(1, sizeof(hive)); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_hive_key, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *hive_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_hive_key, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *hive_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_open_samba(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -3361,6 +3479,9 @@ SWIGINTERN PyObject *_wrap_open_samba(PyObject *SWIGUNUSEDPARM(self), PyObject * }; { + arg3 = loadparm_init(NULL); + } + { arg4 = NULL; } { @@ -3372,12 +3493,14 @@ SWIGINTERN PyObject *_wrap_open_samba(PyObject *SWIGUNUSEDPARM(self), PyObject * { arg2 = &tmp2; } - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OO:open_samba",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; - res3 = SWIG_ConvertPtr(obj0, &argp3,SWIGTYPE_p_loadparm_context, 0 | 0 ); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "open_samba" "', argument " "3"" of type '" "struct loadparm_context *""'"); + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OOO:open_samba",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (obj0) { + res3 = SWIG_ConvertPtr(obj0, &argp3,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "open_samba" "', argument " "3"" of type '" "struct loadparm_context *""'"); + } + arg3 = (struct loadparm_context *)(argp3); } - arg3 = (struct loadparm_context *)(argp3); if (obj1) { res4 = SWIG_ConvertPtr(obj1, &argp4,SWIGTYPE_p_auth_session_info, 0 | 0 ); if (!SWIG_IsOK(res4)) { @@ -3414,17 +3537,19 @@ static PyMethodDef SwigMethods[] = { { (char *)"reg_get_predef_name", (PyCFunction) _wrap_reg_get_predef_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"str_regtype", (PyCFunction) _wrap_str_regtype, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Registry", (PyCFunction) _wrap_Registry, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_reg", _wrap_delete_reg, METH_VARARGS, NULL}, { (char *)"reg_get_predefined_key_by_name", (PyCFunction) _wrap_reg_get_predefined_key_by_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"reg_get_predefined_key", (PyCFunction) _wrap_reg_get_predefined_key, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"reg_apply_patchfile", (PyCFunction) _wrap_reg_apply_patchfile, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"reg_mount_hive", (PyCFunction) _wrap_reg_mount_hive, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"new_reg", _wrap_new_reg, METH_VARARGS, NULL}, + { (char *)"reg_mount_hive", _wrap_reg_mount_hive, METH_VARARGS, NULL}, + { (char *)"new_reg", (PyCFunction)_wrap_new_reg, METH_NOARGS, NULL}, + { (char *)"delete_reg", (PyCFunction)_wrap_delete_reg, METH_O, NULL}, { (char *)"reg_swigregister", reg_swigregister, METH_VARARGS, NULL}, + { (char *)"reg_swiginit", reg_swiginit, METH_VARARGS, NULL}, { (char *)"Hive", (PyCFunction) _wrap_Hive, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_hive", _wrap_delete_hive, METH_VARARGS, NULL}, - { (char *)"new_hive", _wrap_new_hive, METH_VARARGS, NULL}, + { (char *)"new_hive", (PyCFunction)_wrap_new_hive, METH_NOARGS, NULL}, + { (char *)"delete_hive", (PyCFunction)_wrap_delete_hive, METH_O, NULL}, { (char *)"hive_swigregister", hive_swigregister, METH_VARARGS, NULL}, + { (char *)"hive_swiginit", hive_swiginit, METH_VARARGS, NULL}, { (char *)"open_samba", (PyCFunction) _wrap_open_samba, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } }; @@ -3438,12 +3563,16 @@ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_cli_credentials = {"_p_cli_credentials", "struct cli_credentials *|cli_credentials *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_hive_key = {"_p_hive_key", "struct hive_key *|hive *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_hive_key = {"_p_p_hive_key", "struct hive_key **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_registry_context = {"_p_p_registry_context", "struct registry_context **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_registry_key = {"_p_p_registry_key", "struct registry_key **", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_registry_context = {"_p_registry_context", "struct registry_context *|reg *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; @@ -3460,11 +3589,15 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_hive_key, &_swigt__p_int, &_swigt__p_loadparm_context, + &_swigt__p_loadparm_service, &_swigt__p_long_long, &_swigt__p_p_char, &_swigt__p_p_hive_key, &_swigt__p_p_registry_context, &_swigt__p_p_registry_key, + &_swigt__p_param_context, + &_swigt__p_param_opt, + &_swigt__p_param_section, &_swigt__p_registry_context, &_swigt__p_short, &_swigt__p_signed_char, @@ -3481,11 +3614,15 @@ static swig_cast_info _swigc__p_cli_credentials[] = { {&_swigt__p_cli_credentia static swig_cast_info _swigc__p_hive_key[] = { {&_swigt__p_hive_key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_hive_key[] = { {&_swigt__p_p_hive_key, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_registry_context[] = { {&_swigt__p_p_registry_context, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_registry_key[] = { {&_swigt__p_p_registry_key, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_opt[] = { {&_swigt__p_param_opt, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_registry_context[] = { {&_swigt__p_registry_context, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; @@ -3502,11 +3639,15 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_hive_key, _swigc__p_int, _swigc__p_loadparm_context, + _swigc__p_loadparm_service, _swigc__p_long_long, _swigc__p_p_char, _swigc__p_p_hive_key, _swigc__p_p_registry_context, _swigc__p_p_registry_key, + _swigc__p_param_context, + _swigc__p_param_opt, + _swigc__p_param_section, _swigc__p_registry_context, _swigc__p_short, _swigc__p_signed_char, diff --git a/source4/lib/registry/rpc.c b/source4/lib/registry/rpc.c index ac0eecd0ac..7f800b786e 100644 --- a/source4/lib/registry/rpc.c +++ b/source4/lib/registry/rpc.c @@ -91,7 +91,7 @@ static struct { static WERROR rpc_query_key(const struct registry_key *k); -static WERROR rpc_get_predefined_key(const struct registry_context *ctx, +static WERROR rpc_get_predefined_key(struct registry_context *ctx, uint32_t hkey_type, struct registry_key **k) { diff --git a/source4/lib/registry/samba.c b/source4/lib/registry/samba.c index a5a60ba610..02f3363bab 100644 --- a/source4/lib/registry/samba.c +++ b/source4/lib/registry/samba.c @@ -40,11 +40,11 @@ static WERROR mount_samba_hive(struct registry_context *ctx, lp_private_dir(lp_ctx), name); - error = reg_open_hive(ctx, location, auth_info, creds, &hive); + error = reg_open_hive(ctx, location, auth_info, creds, lp_ctx, &hive); if (W_ERROR_EQUAL(error, WERR_NOT_FOUND)) error = reg_open_ldb_file(ctx, location, auth_info, - creds, &hive); + creds, lp_ctx, &hive); if (!W_ERROR_IS_OK(error)) return error; diff --git a/source4/lib/registry/tests/generic.c b/source4/lib/registry/tests/generic.c index 1acb6342e7..25a89793bd 100644 --- a/source4/lib/registry/tests/generic.c +++ b/source4/lib/registry/tests/generic.c @@ -23,6 +23,7 @@ #include "lib/registry/registry.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx); struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx); @@ -52,7 +53,7 @@ static bool test_reg_val_data_string_dword(struct torture_context *ctx) static bool test_reg_val_data_string_sz(struct torture_context *ctx) { DATA_BLOB db; - db.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + db.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "bla", 3, (void **)&db.data); torture_assert_str_equal(ctx, "bla", reg_val_data_string(ctx, REG_SZ, db), @@ -87,7 +88,7 @@ static bool test_reg_val_data_string_empty(struct torture_context *ctx) static bool test_reg_val_description(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "stationary traveller", strlen("stationary traveller"), (void **)&data.data); @@ -101,7 +102,7 @@ static bool test_reg_val_description(struct torture_context *ctx) static bool test_reg_val_description_nullname(struct torture_context *ctx) { DATA_BLOB data; - data.length = convert_string_talloc(ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + data.length = convert_string_talloc(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UNIX, CH_UTF16, "west berlin", strlen("west berlin"), (void **)&data.data); diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 2a0f04eb54..fdb7282395 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -290,7 +290,7 @@ static bool hive_setup_dir(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-dir", &dirname); @@ -314,7 +314,7 @@ static bool hive_setup_ldb(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-ldb", &dirname); @@ -323,7 +323,7 @@ static bool hive_setup_ldb(struct torture_context *tctx, void **data) rmdir(dirname); - error = reg_open_ldb_file(tctx, dirname, NULL, NULL, &key); + error = reg_open_ldb_file(tctx, dirname, NULL, NULL, tctx->lp_ctx, &key); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to initialize ldb hive\n"); return false; @@ -338,7 +338,7 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) { struct hive_key *key; WERROR error; - const char *dirname; + char *dirname; NTSTATUS status; status = torture_temp_dir(tctx, "hive-dir", &dirname); diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index f0035071f2..6c520f54ed 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -535,7 +535,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) { struct registry_context *rctx; WERROR error; - const char *tempdir; + char *tempdir; NTSTATUS status; struct hive_key *hive_key; const char *filename; @@ -547,7 +547,7 @@ static bool setup_local_registry(struct torture_context *tctx, void **data) torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, &hive_key); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &hive_key); torture_assert_werr_ok(tctx, error, "Opening classes_root file failed"); error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL); diff --git a/source4/lib/registry/tools/common.c b/source4/lib/registry/tools/common.c index c9293cd310..29e96475e6 100644 --- a/source4/lib/registry/tools/common.c +++ b/source4/lib/registry/tools/common.c @@ -42,13 +42,14 @@ struct registry_context *reg_common_open_remote(const char *remote, } struct registry_key *reg_common_open_file(const char *path, + struct loadparm_context *lp_ctx, struct cli_credentials *creds) { struct hive_key *hive_root; struct registry_context *h; WERROR error; - error = reg_open_hive(NULL, path, NULL, creds, &hive_root); + error = reg_open_hive(NULL, path, NULL, creds, lp_ctx, &hive_root); if(!W_ERROR_IS_OK(error)) { fprintf(stderr, "Unable to open '%s': %s \n", diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c index 2c692952fb..329d6ab670 100644 --- a/source4/lib/registry/tools/regshell.c +++ b/source4/lib/registry/tools/regshell.c @@ -500,7 +500,7 @@ int main(int argc, char **argv) ctx->registry = reg_common_open_remote(remote, cmdline_lp_ctx, cmdline_credentials); } else if (file != NULL) { - ctx->current = reg_common_open_file(file, cmdline_credentials); + ctx->current = reg_common_open_file(file, cmdline_lp_ctx, cmdline_credentials); if (ctx->current == NULL) return 1; ctx->registry = ctx->current->context; @@ -546,12 +546,16 @@ int main(int argc, char **argv) via readline :-( */ line = smb_readline(prompt, NULL, reg_completion); - if (line == NULL) + if (line == NULL) { + free(prompt); break; + } if (line[0] != '\n') { ret = W_ERROR_IS_OK(process_cmd(ctx, line)); } + free(line); + free(prompt); } talloc_free(ctx); diff --git a/source4/lib/registry/tools/regtree.c b/source4/lib/registry/tools/regtree.c index b267e11b43..0f47d8f8dd 100644 --- a/source4/lib/registry/tools/regtree.c +++ b/source4/lib/registry/tools/regtree.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) if (remote != NULL) { h = reg_common_open_remote(remote, cmdline_lp_ctx, cmdline_credentials); } else if (file != NULL) { - start_key = reg_common_open_file(file, cmdline_credentials); + start_key = reg_common_open_file(file, cmdline_lp_ctx, cmdline_credentials); } else { h = reg_common_open_local(cmdline_credentials, cmdline_lp_ctx); } diff --git a/source4/lib/registry/util.c b/source4/lib/registry/util.c index f75fc835b5..a251ae49a5 100644 --- a/source4/lib/registry/util.c +++ b/source4/lib/registry/util.c @@ -20,6 +20,7 @@ #include "includes.h" #include "lib/registry/registry.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" /** * @file @@ -61,7 +62,7 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, switch (type) { case REG_EXPAND_SZ: case REG_SZ: - convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, data.data, data.length, (void **)&ret); return ret; @@ -117,7 +118,7 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, { case REG_SZ: case REG_EXPAND_SZ: - data->length = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + data->length = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UNIX, CH_UTF16, data_str, strlen(data_str), (void **)&data->data); break; diff --git a/source4/lib/replace/README b/source4/lib/replace/README index c61f78a951..268a1b15cf 100644 --- a/source4/lib/replace/README +++ b/source4/lib/replace/README @@ -60,6 +60,8 @@ getaddrinfo freeaddrinfo getnameinfo gai_strerror +getifaddrs +freeifaddrs Types: bool diff --git a/source4/lib/replace/getifaddrs.c b/source4/lib/replace/getifaddrs.c new file mode 100644 index 0000000000..4037d647d7 --- /dev/null +++ b/source4/lib/replace/getifaddrs.c @@ -0,0 +1,392 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Jeremy Allison 2007 + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "replace.h" +#include "system/network.h" + +#include <unistd.h> +#include <stdio.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + +#ifndef SIOCGIFCONF +#ifdef HAVE_SYS_SOCKIO_H +#include <sys/sockio.h> +#endif +#endif + +#ifdef HAVE_IFACE_GETIFADDRS +#define _FOUND_IFACE_ANY +#else + +void rep_freeifaddrs(struct ifaddrs *ifp) +{ + free(ifp->ifa_name); + free(ifp->ifa_addr); + free(ifp->ifa_netmask); + free(ifp->ifa_dstaddr); + if (ifp->ifa_next != NULL) + freeifaddrs(ifp->ifa_next); + free(ifp); +} + +static struct sockaddr *sockaddr_dup(struct sockaddr *sa) +{ + struct sockaddr *ret; + socklen_t socklen; +#ifdef HAVE_SOCKADDR_SA_LEN + socklen = sa->sa_len; +#else + socklen = sizeof(struct sockaddr_storage); +#endif + ret = calloc(1, socklen); + if (ret == NULL) + return NULL; + memcpy(ret, sa, socklen); + return ret; +} +#endif + +#if HAVE_IFACE_IFCONF + +/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 + V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. + + It probably also works on any BSD style system. */ + +int rep_getifaddrs(struct ifaddrs **ifap) +{ + struct ifconf ifc; + char buff[8192]; + int fd, i, n; + struct ifreq *ifr=NULL; + int total = 0; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + struct ifaddrs *curif, *lastif; + + *ifap = NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + + n = ifc.ifc_len / sizeof(struct ifreq); + + /* Loop through interfaces, looking for given IP address */ + for (i=n-1;i>=0 && total < max_interfaces;i--) { + if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { + freeifaddrs(*ifap); + } + + curif = calloc(1, sizeof(struct ifaddrs)); + if (lastif == NULL) { + *ifap = curif; + } else { + lastif->ifa_next = (*ifap); + } + + curif->ifa_name = strdup(ifr[i].ifr_name); + curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr); + curif->ifa_dstaddr = NULL; + curif->ifa_data = NULL; + curif->ifa_next = NULL; + curif->ifa_netmask = NULL; + + if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) { + freeifaddrs(*ifap); + return -1; + } + + curif->ifa_flags = ifr[i].ifr_flags; + + if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { + freeifaddrs(*ifap); + return -1; + } + + curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr); + + lastif = curif; + } + + close(fd); + + return 0; +} + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_IFCONF */ +#ifdef HAVE_IFACE_IFREQ + +#ifndef I_STR +#include <sys/stropts.h> +#endif + +/**************************************************************************** +this should cover most of the streams based systems +Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code +****************************************************************************/ +int rep_getifaddrs(struct ifaddrs **ifap) +{ + struct ifreq ifreq; + struct strioctl strioctl; + char buff[8192]; + int fd, i, n; + struct ifreq *ifr=NULL; + int total = 0; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + struct ifaddrs *curif; + + *ifap = NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + strioctl.ic_cmd = SIOCGIFCONF; + strioctl.ic_dp = buff; + strioctl.ic_len = sizeof(buff); + if (ioctl(fd, I_STR, &strioctl) < 0) { + close(fd); + return -1; + } + + /* we can ignore the possible sizeof(int) here as the resulting + number of interface structures won't change */ + n = strioctl.ic_len / sizeof(struct ifreq); + + /* we will assume that the kernel returns the length as an int + at the start of the buffer if the offered size is a + multiple of the structure size plus an int */ + if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { + ifr = (struct ifreq *)(buff + sizeof(int)); + } else { + ifr = (struct ifreq *)buff; + } + + /* Loop through interfaces */ + + for (i = 0; i<n && total < max_interfaces; i++) { + ifreq = ifr[i]; + + curif = calloc(1, sizeof(struct ifaddrs)); + if (lastif == NULL) { + *ifap = curif; + } else { + lastif->ifa_next = (*ifap); + } + + strioctl.ic_cmd = SIOCGIFFLAGS; + strioctl.ic_dp = (char *)&ifreq; + strioctl.ic_len = sizeof(struct ifreq); + if (ioctl(fd, I_STR, &strioctl) != 0) { + freeifaddrs(*ifap); + return -1; + } + + curif->ifa_flags = ifreq.ifr_flags; + + strioctl.ic_cmd = SIOCGIFADDR; + strioctl.ic_dp = (char *)&ifreq; + strioctl.ic_len = sizeof(struct ifreq); + if (ioctl(fd, I_STR, &strioctl) != 0) { + freeifaddrs(*ifap); + return -1; + } + + curif->ifa_name = strdup(ifreq.ifr_name); + curif->ifa_addr = sockaddr_dup(&ifreq.ifr_addr); + curif->ifa_dstaddr = NULL; + curif->ifa_data = NULL; + curif->ifa_next = NULL; + curif->ifa_netmask = NULL; + + strioctl.ic_cmd = SIOCGIFNETMASK; + strioctl.ic_dp = (char *)&ifreq; + strioctl.ic_len = sizeof(struct ifreq); + if (ioctl(fd, I_STR, &strioctl) != 0) { + freeifaddrs(*ifap); + return -1; + } + + curif->ifa_netmask = sockaddr_dup(&ifreq.ifr_addr); + + lastif = curif; + } + + close(fd); + + return 0; +} + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_IFREQ */ +#ifdef HAVE_IFACE_AIX + +/**************************************************************************** +this one is for AIX (tested on 4.2) +****************************************************************************/ +int rep_getifaddrs(struct ifaddrs **ifap) +{ + char buff[8192]; + int fd, i; + struct ifconf ifc; + struct ifreq *ifr=NULL; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + int total = 0; + struct ifaddrs *curif, *lastif; + + *ifap = NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + + /* Loop through interfaces */ + i = ifc.ifc_len; + + while (i > 0) { + uint_t inc; + + inc = ifr->ifr_addr.sa_len; + + if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { + freeaddrinfo(*ifap); + return -1; + } + + curif = calloc(1, sizeof(struct ifaddrs)); + if (lastif == NULL) { + *ifap = curif; + } else { + lastif->ifa_next = (*ifap); + } + + curif->ifa_name = strdup(ifr->ifr_name); + curif->ifa_addr = sockaddr_dup(&ifr->ifr_addr); + curif->ifa_dstaddr = NULL; + curif->ifa_data = NULL; + curif->ifa_netmask = NULL; + curif->ifa_next = NULL; + + if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { + freeaddrinfo(*ifap); + return -1; + } + + curif->ifa_flags = ifr->ifr_flags; + + if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { + freeaddrinfo(*ifap); + return -1; + } + + curif->ifa_netmask = sockaddr_dup(&ifr->ifr_addr); + + lastif = curif; + + next: + /* + * Patch from Archie Cobbs (archie@whistle.com). The + * addresses in the SIOCGIFCONF interface list have a + * minimum size. Usually this doesn't matter, but if + * your machine has tunnel interfaces, etc. that have + * a zero length "link address", this does matter. */ + + if (inc < sizeof(ifr->ifr_addr)) + inc = sizeof(ifr->ifr_addr); + inc += IFNAMSIZ; + + ifr = (struct ifreq*) (((char*) ifr) + inc); + i -= inc; + } + + close(fd); + return 0; +} + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_AIX */ +#ifndef _FOUND_IFACE_ANY +int rep_getifaddrs(struct ifaddrs **ifap) +{ + errno = ENOSYS; + return -1; +} +#endif + +#ifdef AUTOCONF_TEST +/* this is the autoconf driver to test get_interfaces() */ + + int main() +{ + struct ifaddrs *ifs = NULL; + int ret; + + ret = getifaddrs(&ifs); + if (ret != 0) { + perror("getifaddrs() failed"); + return 1; + } + + while (ifs) { + printf("%-10s ", ifs->ifa_name); + if (ifs->ifa_addr != NULL && + ifs->ifa_addr->sa_family == AF_INET) { + printf("IP=%s ", inet_ntoa(((struct sockaddr_in *)ifs->ifa_addr)->sin_addr)); + if (ifs->ifa_netmask != NULL) + printf("NETMASK=%s", inet_ntoa(((struct sockaddr_in *)ifs->ifa_netmask)->sin_addr)); + } + printf("\n"); + ifs = ifs->ifa_next; + } + return 0; +} +#endif diff --git a/source4/lib/replace/getifaddrs.m4 b/source4/lib/replace/getifaddrs.m4 new file mode 100644 index 0000000000..85f08ee6c3 --- /dev/null +++ b/source4/lib/replace/getifaddrs.m4 @@ -0,0 +1,97 @@ +AC_CHECK_HEADERS([ifaddrs.h]) + +dnl Used when getifaddrs is not available +AC_CHECK_MEMBERS([struct sockaddr.sa_len], + [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])], + [], + [#include <sys/socket.h>]) + +dnl test for getifaddrs and freeifaddrs +AC_CACHE_CHECK([for getifaddrs and freeifaddrs],samba_cv_HAVE_GETIFADDRS,[ +AC_TRY_COMPILE([ +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <ifaddrs.h> +#include <netdb.h>], +[ +struct ifaddrs *ifp = NULL; +int ret = getifaddrs (&ifp); +freeifaddrs(ifp); +], +samba_cv_HAVE_GETIFADDRS=yes,samba_cv_HAVE_GETIFADDRS=no)]) +if test x"$samba_cv_HAVE_GETIFADDRS" = x"yes"; then + AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs]) + AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs]) + AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available]) +fi + +################## +# look for a method of finding the list of network interfaces +# +# This tests need LIBS="$NSL_LIBS $SOCKET_LIBS" +# +old_LIBS=$LIBS +LIBS="$NSL_LIBS $SOCKET_LIBS" +iface=no; +################## +# look for a method of finding the list of network interfaces +iface=no; +AC_CACHE_CHECK([for iface getifaddrs],samba_cv_HAVE_IFACE_GETIFADDRS,[ +SAVE_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}" +AC_TRY_RUN([ +#define NO_CONFIG_H 1 +#define HAVE_IFACE_GETIFADDRS 1 +#define AUTOCONF_TEST 1 +#include "$libreplacedir/replace.c" +#include "$libreplacedir/getifaddrs.c"], + samba_cv_HAVE_IFACE_GETIFADDRS=yes,samba_cv_HAVE_IFACE_GETIFADDRS=no,samba_cv_HAVE_IFACE_GETIFADDRS=cross)]) +CPPFLAGS="$SAVE_CPPFLAGS" +if test x"$samba_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then + iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available]) +else + LIBREPLACEOBJ="${LIBREPLACEOBJ} getifaddrs.o" +fi + + +if test $iface = no; then +AC_CACHE_CHECK([for iface AIX],samba_cv_HAVE_IFACE_AIX,[ +AC_TRY_RUN([ +#define HAVE_IFACE_AIX 1 +#define AUTOCONF_TEST 1 +#undef _XOPEN_SOURCE_EXTENDED +#include "$libreplacedir/getifaddrs.c"], + samba_cv_HAVE_IFACE_AIX=yes,samba_cv_HAVE_IFACE_AIX=no,samba_cv_HAVE_IFACE_AIX=cross)]) +if test x"$samba_cv_HAVE_IFACE_AIX" = x"yes"; then + iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available]) +fi +fi + + +if test $iface = no; then +AC_CACHE_CHECK([for iface ifconf],samba_cv_HAVE_IFACE_IFCONF,[ +AC_TRY_RUN([ +#define HAVE_IFACE_IFCONF 1 +#define AUTOCONF_TEST 1 +#include "$libreplacedir/getifaddrs.c"], + samba_cv_HAVE_IFACE_IFCONF=yes,samba_cv_HAVE_IFACE_IFCONF=no,samba_cv_HAVE_IFACE_IFCONF=cross)]) +if test x"$samba_cv_HAVE_IFACE_IFCONF" = x"yes"; then + iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available]) +fi +fi + +if test $iface = no; then +AC_CACHE_CHECK([for iface ifreq],samba_cv_HAVE_IFACE_IFREQ,[ +AC_TRY_RUN([ +#define HAVE_IFACE_IFREQ 1 +#define AUTOCONF_TEST 1 +#include "$libreplacedir/getifaddrs.c"], + samba_cv_HAVE_IFACE_IFREQ=yes,samba_cv_HAVE_IFACE_IFREQ=no,samba_cv_HAVE_IFACE_IFREQ=cross)]) +if test x"$samba_cv_HAVE_IFACE_IFREQ" = x"yes"; then + iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available]) +fi +fi + +LIBS=$old_LIBS diff --git a/source4/lib/replace/libreplace.m4 b/source4/lib/replace/libreplace.m4 index c10a4b2381..7e456b4d03 100644 --- a/source4/lib/replace/libreplace.m4 +++ b/source4/lib/replace/libreplace.m4 @@ -327,6 +327,7 @@ m4_include(inet_ntop.m4) m4_include(inet_pton.m4) m4_include(getaddrinfo.m4) m4_include(repdir.m4) +m4_include(getifaddrs.m4) AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])]) diff --git a/source4/lib/replace/libreplace_ld.m4 b/source4/lib/replace/libreplace_ld.m4 index a2e43bbe13..cb8e21434e 100644 --- a/source4/lib/replace/libreplace_ld.m4 +++ b/source4/lib/replace/libreplace_ld.m4 @@ -142,7 +142,7 @@ AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_FLAGS], LD_SHLIB_FLAGS="-shared" ;; *darwin*) - LD_SHLIB_FLAGS="-bundle -flat_namespace -Wl,-search_paths_first" + LD_SHLIB_FLAGS="-dynamiclib -Wl,-search_paths_first" ;; esac @@ -164,7 +164,7 @@ AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG], LD_SHLIB_DISALLOW_UNDEF_FLAG="-warning_unresolved" ;; *darwin*) - LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined warning" + LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined error" ;; esac @@ -268,7 +268,7 @@ AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG], LD_SHLIB_ALLOW_UNDEF_FLAG="-expect_unresolved '*'" ;; *darwin*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined suppress" + LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup" ;; esac diff --git a/source4/lib/replace/replace.h b/source4/lib/replace/replace.h index 973c68ee14..f8a89a7213 100644 --- a/source4/lib/replace/replace.h +++ b/source4/lib/replace/replace.h @@ -340,6 +340,16 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset) /* prototype is in "system/network.h" */ #endif +#ifndef HAVE_GETIFADDRS +#define getifaddrs rep_getifaddrs +/* prototype is in "system/network.h" */ +#endif + +#ifndef HAVE_FREEIFADDRS +#define freeifaddrs rep_freeifaddrs +/* prototype is in "system/network.h" */ +#endif + #ifdef HAVE_LIMITS_H #include <limits.h> #endif diff --git a/source4/lib/replace/system/network.h b/source4/lib/replace/system/network.h index d3ae2bf398..f72b233712 100644 --- a/source4/lib/replace/system/network.h +++ b/source4/lib/replace/system/network.h @@ -6,6 +6,7 @@ networking system include wrappers Copyright (C) Andrew Tridgell 2004 + Copyright (C) Jelmer Vernooij 2007 ** NOTE! The following LGPL license applies to the replace ** library. This does NOT imply that all of Samba is released @@ -93,6 +94,31 @@ int rep_inet_pton(int af, const char *src, void *dst); const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size); #endif +#ifdef HAVE_IFADDRS_H +#include <ifaddrs.h> +#endif + +#ifndef HAVE_STRUCT_IFADDRS +struct ifaddrs { + struct ifaddrs *ifa_next; /* Pointer to next struct */ + char *ifa_name; /* Interface name */ + unsigned int ifa_flags; /* Interface flags */ + struct sockaddr *ifa_addr; /* Interface address */ + struct sockaddr *ifa_netmask; /* Interface netmask */ +#undef ifa_dstaddr + struct sockaddr *ifa_dstaddr; /* P2P interface destination */ + void *ifa_data; /* Address specific data */ +}; +#endif + +#ifndef HAVE_GETIFADDRS +int rep_getifaddrs(struct ifaddrs **); +#endif + +#ifndef HAVE_FREEIFADDRS +void rep_freeifaddrs(struct ifaddrs *); +#endif + /* * Some systems have getaddrinfo but not the * defines needed to use it. diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c index 5b95ae395c..c9f3301005 100644 --- a/source4/lib/replace/test/testsuite.c +++ b/source4/lib/replace/test/testsuite.c @@ -856,6 +856,25 @@ static int test_strptime(void) return libreplace_test_strptime(); } +static int test_getifaddrs(void) +{ + struct ifaddrs *ifa; + int ret; + + printf("test: getifaddrs\n"); + + ret = getifaddrs(&ifa); + if (ret != 0) { + printf("failure: getifaddrs\n"); + return false; + } + + freeifaddrs(ifa); + + printf("success: getifaddrs\n"); + return true; +} + struct torture_context; bool torture_local_replace(struct torture_context *ctx) { @@ -903,6 +922,7 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_MAX(); ret &= test_socketpair(); ret &= test_strptime(); + ret &= test_getifaddrs(); return ret; } diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk index aefb077cf5..76f1ce5096 100644 --- a/source4/lib/samba3/config.mk +++ b/source4/lib/samba3/config.mk @@ -10,7 +10,8 @@ OBJ_FILES = tdbsam.o policy.o \ idmap.o winsdb.o samba3.o group.o \ registry.o secrets.o share_info.o PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBTDB NDR_SECURITY \ - CREDENTIALS SMBPASSWD + SMBPASSWD LIBSECURITY +PUBLIC_DEPENDENCIES = CREDENTIALS # End SUBSYSTEM LIBSAMBA3 ################################################ @@ -19,5 +20,6 @@ PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBTDB NDR_SECURITY \ [SUBSYSTEM::SMBPASSWD] PRIVATE_PROTO_HEADER = samba3_smbpasswd_proto.h OBJ_FILES = smbpasswd.o +PRIVATE_DEPENDENCIES = CHARSET LIBSAMBA-UTIL # End SUBSYSTEM LIBSAMBA3 ################################################ diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c index 74985fab8a..4bd08f188a 100644 --- a/source4/lib/samba3/samba3.c +++ b/source4/lib/samba3/samba3.c @@ -36,7 +36,7 @@ NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct char *dbfile; NTSTATUS status = NT_STATUS_OK; int i; - const char **backends = param_get_string_list(samba3->configuration, NULL, "passdb backend", NULL); + const char **backends = param_get_string_list(samba3->configuration, "passdb backend", NULL, NULL); /* Default to smbpasswd */ if (backends == NULL) @@ -59,7 +59,7 @@ NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct const char *p = strchr(backends[i], ':'); if (p && p[1]) { dbfile = talloc_strdup(ctx, p+1); - } else if ((p = param_get_string(samba3->configuration, NULL, "smb passwd file"))) { + } else if ((p = param_get_string(samba3->configuration, "smb passwd file", NULL))) { dbfile = talloc_strdup(ctx, p); } else { dbfile = talloc_strdup(ctx, "/etc/samba/smbpasswd"); diff --git a/source4/lib/samba3/share_info.c b/source4/lib/samba3/share_info.c index e0778fafb5..4dd15aa918 100644 --- a/source4/lib/samba3/share_info.c +++ b/source4/lib/samba3/share_info.c @@ -76,7 +76,7 @@ NTSTATUS samba3_read_share_info(const char *fn, TALLOC_CTX *ctx, struct samba3 * blob.data = (uint8_t *)vbuf.dptr; blob.length = vbuf.dsize; - pull = ndr_pull_init_blob(&blob, ctx); + pull = ndr_pull_init_blob(&blob, ctx, lp_iconv_convenience(global_loadparm)); ndr_pull_security_descriptor(pull, NDR_SCALARS|NDR_BUFFERS, &share->secdesc); diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index 2a72750efb..a85f335b8a 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "pstring.h" #include "system/filesys.h" #include "system/select.h" #include "system/readline.h" @@ -78,22 +77,27 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) char **(completion_fn)(const char *text, int start, int end)) { fd_set fds; - static pstring line; + char *line; struct timeval timeout; int fd = STDIN_FILENO; char *ret; do_debug("%s", prompt); + line = (char *)malloc(BUFSIZ); + if (!line) { + return NULL; + } + while (1) { timeout.tv_sec = 5; timeout.tv_usec = 0; FD_ZERO(&fds); FD_SET(fd,&fds); - + if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) { - ret = x_fgets(line, sizeof(line), x_stdin); + ret = x_fgets(line, BUFSIZ, x_stdin); return ret; } if (callback) diff --git a/source4/lib/socket/config.m4 b/source4/lib/socket/config.m4 index 3296730c82..a713090c6d 100644 --- a/source4/lib/socket/config.m4 +++ b/source4/lib/socket/config.m4 @@ -97,50 +97,5 @@ dnl don't build ipv6 by default, unless the above test enables it, or dnl the configure uses --with-static-modules=socket_ipv6 -################## -# look for a method of finding the list of network interfaces -# -# This tests need LIBS="$NSL_LIBS $SOCKET_LIBS" -# -old_CFLAGS=$CFLAGS -old_LIBS=$LIBS -LIBS="$NSL_LIBS $SOCKET_LIBS" -CFLAGS="$CFLAGS -Ilib/replace" -iface=no; -AC_CACHE_CHECK([for iface AIX],samba_cv_HAVE_IFACE_AIX,[ -AC_TRY_RUN([ -#define HAVE_IFACE_AIX 1 -#define AUTOCONF_TEST 1 -#undef _XOPEN_SOURCE_EXTENDED -#include "${srcdir-.}/lib/socket/netif.c"], - samba_cv_HAVE_IFACE_AIX=yes,samba_cv_HAVE_IFACE_AIX=no,samba_cv_HAVE_IFACE_AIX=cross)]) -if test x"$samba_cv_HAVE_IFACE_AIX" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available]) -fi - -if test $iface = no; then -AC_CACHE_CHECK([for iface ifconf],samba_cv_HAVE_IFACE_IFCONF,[ -AC_TRY_RUN([ -#define HAVE_IFACE_IFCONF 1 -#define AUTOCONF_TEST 1 -#include "${srcdir-.}/lib/socket/netif.c"], - samba_cv_HAVE_IFACE_IFCONF=yes,samba_cv_HAVE_IFACE_IFCONF=no,samba_cv_HAVE_IFACE_IFCONF=cross)]) -if test x"$samba_cv_HAVE_IFACE_IFCONF" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available]) -fi -fi -if test $iface = no; then -AC_CACHE_CHECK([for iface ifreq],samba_cv_HAVE_IFACE_IFREQ,[ -AC_TRY_RUN([ -#define HAVE_IFACE_IFREQ 1 -#define AUTOCONF_TEST 1 -#include "${srcdir-.}/lib/socket/netif.c"], - samba_cv_HAVE_IFACE_IFREQ=yes,samba_cv_HAVE_IFACE_IFREQ=no,samba_cv_HAVE_IFACE_IFREQ=cross)]) -if test x"$samba_cv_HAVE_IFACE_IFREQ" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available]) -fi -fi -CFLAGS=$old_CFLAGS -LIBS=$old_LIBS diff --git a/source4/lib/socket/config.mk b/source4/lib/socket/config.mk index d1e0bcfef5..fe64c90b81 100644 --- a/source4/lib/socket/config.mk +++ b/source4/lib/socket/config.mk @@ -39,9 +39,7 @@ OBJ_FILES = \ access.o \ connect_multi.o \ connect.o -LDFLAGS = $(SUBSYSTEM_LIBCLI_RESOLVE_OUTPUT) $(SUBSYSTEM_LIBCLI_NBT_OUTPUT) $(SUBSYSTEM_NDR_NBT_OUTPUT) $(LIBRARY_NDR_SVCCTL_OUTPUT) PUBLIC_DEPENDENCIES = LIBTALLOC -PRIVATE_DEPENDENCIES = SOCKET_WRAPPER LIBCLI_COMPOSITE -#LIBCLI_RESOLVE +PRIVATE_DEPENDENCIES = SOCKET_WRAPPER LIBCLI_COMPOSITE LIBCLI_RESOLVE # End SUBSYSTEM SOCKET ################################################ diff --git a/source4/lib/socket/connect.c b/source4/lib/socket/connect.c index cad8967dab..773bf41873 100644 --- a/source4/lib/socket/connect.c +++ b/source4/lib/socket/connect.c @@ -85,7 +85,7 @@ struct composite_context *socket_connect_send(struct socket_context *sock, struct socket_address *my_address, struct socket_address *server_address, uint32_t flags, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { struct composite_context *result; @@ -123,12 +123,11 @@ struct composite_context *socket_connect_send(struct socket_context *sock, set_blocking(socket_get_fd(sock), false); - if (server_address->addr && strcmp(sock->backend_name, "ipv4") == 0) { + if (resolve_ctx != NULL && server_address->addr && strcmp(sock->backend_name, "ipv4") == 0) { struct nbt_name name; struct composite_context *creq; make_nbt_name_client(&name, server_address->addr); - creq = resolve_name_send(&name, result->event_ctx, - lp_name_resolve_order(global_loadparm)); + creq = resolve_name_send(resolve_ctx, &name, result->event_ctx); if (composite_nomem(creq, result)) return result; composite_continue(result, creq, continue_resolve_name, result); return result; @@ -207,11 +206,11 @@ NTSTATUS socket_connect_recv(struct composite_context *result) NTSTATUS socket_connect_ev(struct socket_context *sock, struct socket_address *my_address, struct socket_address *server_address, - uint32_t flags, const char **name_resolve_order, + uint32_t flags, struct resolve_context *resolve_ctx, struct event_context *ev) { struct composite_context *ctx; ctx = socket_connect_send(sock, my_address, - server_address, flags, name_resolve_order, ev); + server_address, flags, resolve_ctx, ev); return socket_connect_recv(ctx); } diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c index 58ab673965..2f736a4b05 100644 --- a/source4/lib/socket/connect_multi.c +++ b/source4/lib/socket/connect_multi.c @@ -38,7 +38,7 @@ struct connect_multi_state { int num_ports; uint16_t *ports; - const char **name_resolve_order; + struct resolve_context *resolve_ctx; struct socket_context *sock; uint16_t result_port; @@ -70,7 +70,7 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send( const char *server_address, int num_server_ports, uint16_t *server_ports, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { struct composite_context *result; @@ -90,7 +90,7 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send( if (composite_nomem(multi->server_address, result)) goto failed; multi->num_ports = num_server_ports; - multi->name_resolve_order = str_list_copy(multi, name_resolve_order); + multi->resolve_ctx = talloc_reference(multi, resolve_ctx); multi->ports = talloc_array(multi, uint16_t, multi->num_ports); if (composite_nomem(multi->ports, result)) goto failed; @@ -107,8 +107,7 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send( struct nbt_name name; struct composite_context *creq; make_nbt_name_client(&name, server_address); - creq = resolve_name_send(&name, result->event_ctx, - name_resolve_order); + creq = resolve_name_send(resolve_ctx, &name, result->event_ctx); if (composite_nomem(creq, result)) goto failed; composite_continue(result, creq, continue_resolve_name, result); return result; @@ -161,7 +160,7 @@ static void connect_multi_next_socket(struct composite_context *result) talloc_steal(state, state->sock); creq = socket_connect_send(state->sock, NULL, - state->addr, 0, multi->name_resolve_order, + state->addr, 0, multi->resolve_ctx, result->event_ctx); if (composite_nomem(creq, result)) return; talloc_steal(state, creq); @@ -269,7 +268,7 @@ _PUBLIC_ NTSTATUS socket_connect_multi_recv(struct composite_context *ctx, NTSTATUS socket_connect_multi(TALLOC_CTX *mem_ctx, const char *server_address, int num_server_ports, uint16_t *server_ports, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct socket_context **result, uint16_t *result_port) @@ -277,7 +276,7 @@ NTSTATUS socket_connect_multi(TALLOC_CTX *mem_ctx, struct composite_context *ctx = socket_connect_multi_send(mem_ctx, server_address, num_server_ports, server_ports, - name_resolve_order, + resolve_ctx, event_ctx); return socket_connect_multi_recv(ctx, mem_ctx, result, result_port); } diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 79c5673022..c327f02bbd 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -35,8 +35,6 @@ struct interface { const char *nmask_s; }; -static struct interface *local_interfaces; - #define ALLONES ((uint32_t)0xFFFFFFFF) /* address construction based on a patch from fred@datalync.com @@ -47,12 +45,13 @@ static struct interface *local_interfaces; /**************************************************************************** Try and find an interface that matches an ip. If we cannot, return NULL **************************************************************************/ -static struct interface *iface_find(struct in_addr ip, bool CheckMask) +static struct interface *iface_find(struct interface *interfaces, + struct in_addr ip, bool CheckMask) { struct interface *i; - if (is_zero_ip(ip)) return local_interfaces; + if (is_zero_ip(ip)) return interfaces; - for (i=local_interfaces;i;i=i->next) + for (i=interfaces;i;i=i->next) if (CheckMask) { if (same_net(i->ip,ip,i->nmask)) return i; } else if (i->ip.s_addr == ip.s_addr) return i; @@ -64,18 +63,19 @@ static struct interface *iface_find(struct in_addr ip, bool CheckMask) /**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ -static void add_interface(struct in_addr ip, struct in_addr nmask) +static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr nmask, struct interface **interfaces) { struct interface *iface; struct in_addr bcast; - if (iface_find(ip, false)) { + if (iface_find(*interfaces, ip, false)) { DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); return; } - iface = talloc(local_interfaces == NULL ? talloc_autofree_context() : local_interfaces, struct interface); - if (!iface) return; + iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); + if (iface == NULL) + return; ZERO_STRUCTPN(iface); @@ -92,7 +92,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) iface->bcast_s = talloc_strdup(iface, inet_ntoa(bcast)); } - DLIST_ADD_END(local_interfaces, iface, struct interface *); + DLIST_ADD_END(*interfaces, iface, struct interface *); DEBUG(2,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s)); } @@ -110,12 +110,15 @@ This handles the following different forms: 4) ip/mask 5) bcast/mask **/ -static void interpret_interface(const char *token, +static void interpret_interface(TALLOC_CTX *mem_ctx, + const char *token, struct iface_struct *probed_ifaces, - int total_probed) + int total_probed, + struct interface **local_interfaces) { struct in_addr ip, nmask; char *p; + char *address; int i, added=0; ip.s_addr = 0; @@ -124,8 +127,9 @@ static void interpret_interface(const char *token, /* first check if it is an interface name */ for (i=0;i<total_probed;i++) { if (gen_fnmatch(token, probed_ifaces[i].name) == 0) { - add_interface(probed_ifaces[i].ip, - probed_ifaces[i].netmask); + add_interface(mem_ctx, probed_ifaces[i].ip, + probed_ifaces[i].netmask, + local_interfaces); added = 1; } } @@ -141,8 +145,9 @@ static void interpret_interface(const char *token, ip.s_addr = interpret_addr2(token).s_addr; for (i=0;i<total_probed;i++) { if (ip.s_addr == probed_ifaces[i].ip.s_addr) { - add_interface(probed_ifaces[i].ip, - probed_ifaces[i].netmask); + add_interface(mem_ctx, probed_ifaces[i].ip, + probed_ifaces[i].netmask, + local_interfaces); return; } } @@ -150,10 +155,13 @@ static void interpret_interface(const char *token, return; } + address = talloc_strdup(mem_ctx, token); + p = strchr_m(address,'/'); + /* parse it into an IP address/netmasklength pair */ *p++ = 0; - ip.s_addr = interpret_addr2(token).s_addr; + ip.s_addr = interpret_addr2(address).s_addr; if (strlen(p) > 2) { nmask.s_addr = interpret_addr2(p).s_addr; @@ -166,22 +174,26 @@ static void interpret_interface(const char *token, ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) { for (i=0;i<total_probed;i++) { if (same_net(ip, probed_ifaces[i].ip, nmask)) { - add_interface(probed_ifaces[i].ip, nmask); + add_interface(mem_ctx, probed_ifaces[i].ip, nmask, + local_interfaces); + talloc_free(address); return; } } - DEBUG(2,("Can't determine ip for broadcast address %s\n", token)); + DEBUG(2,("Can't determine ip for broadcast address %s\n", address)); + talloc_free(address); return; } - add_interface(ip, nmask); + add_interface(mem_ctx, ip, nmask, local_interfaces); + talloc_free(address); } /** load the list of network interfaces **/ -static void load_interfaces(const char **interfaces) +void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces) { const char **ptr = interfaces; int i; @@ -189,9 +201,7 @@ static void load_interfaces(const char **interfaces) struct in_addr loopback_ip; int total_probed; - if (local_interfaces != NULL) { - return; - } + *local_interfaces = NULL; loopback_ip = interpret_addr2("127.0.0.1"); @@ -206,43 +216,31 @@ static void load_interfaces(const char **interfaces) } for (i=0;i<total_probed;i++) { if (ifaces[i].ip.s_addr != loopback_ip.s_addr) { - add_interface(ifaces[i].ip, - ifaces[i].netmask); + add_interface(mem_ctx, ifaces[i].ip, + ifaces[i].netmask, local_interfaces); } } } while (ptr && *ptr) { - interpret_interface(*ptr, ifaces, total_probed); + interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces); ptr++; } - if (!local_interfaces) { + if (!*local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } } - -/** - unload the interfaces list, so it can be reloaded when needed -*/ -void unload_interfaces(void) -{ - talloc_free(local_interfaces); - local_interfaces = NULL; -} - /** how many interfaces do we have **/ -int iface_count(struct loadparm_context *lp_ctx) +int iface_count(struct interface *ifaces) { int ret = 0; struct interface *i; - load_interfaces(lp_interfaces(lp_ctx)); - - for (i=local_interfaces;i;i=i->next) + for (i=ifaces;i;i=i->next) ret++; return ret; } @@ -250,13 +248,11 @@ int iface_count(struct loadparm_context *lp_ctx) /** return IP of the Nth interface **/ -const char *iface_n_ip(struct loadparm_context *lp_ctx, int n) +const char *iface_n_ip(struct interface *ifaces, int n) { struct interface *i; - load_interfaces(lp_interfaces(lp_ctx)); - - for (i=local_interfaces;i && n;i=i->next) + for (i=ifaces;i && n;i=i->next) n--; if (i) { @@ -268,13 +264,11 @@ const char *iface_n_ip(struct loadparm_context *lp_ctx, int n) /** return bcast of the Nth interface **/ -const char *iface_n_bcast(struct loadparm_context *lp_ctx, int n) +const char *iface_n_bcast(struct interface *ifaces, int n) { struct interface *i; - load_interfaces(lp_interfaces(lp_ctx)); - - for (i=local_interfaces;i && n;i=i->next) + for (i=ifaces;i && n;i=i->next) n--; if (i) { @@ -286,13 +280,11 @@ const char *iface_n_bcast(struct loadparm_context *lp_ctx, int n) /** return netmask of the Nth interface **/ -const char *iface_n_netmask(struct loadparm_context *lp_ctx, int n) +const char *iface_n_netmask(struct interface *ifaces, int n) { struct interface *i; - load_interfaces(lp_interfaces(lp_ctx)); - - for (i=local_interfaces;i && n;i=i->next) + for (i=ifaces;i && n;i=i->next) n--; if (i) { @@ -305,32 +297,28 @@ const char *iface_n_netmask(struct loadparm_context *lp_ctx, int n) return the local IP address that best matches a destination IP, or our first interface if none match */ -const char *iface_best_ip(struct loadparm_context *lp_ctx, const char *dest) +const char *iface_best_ip(struct interface *ifaces, const char *dest) { struct interface *iface; struct in_addr ip; - load_interfaces(lp_interfaces(lp_ctx)); - ip.s_addr = interpret_addr(dest); - iface = iface_find(ip, true); + iface = iface_find(ifaces, ip, true); if (iface) { return iface->ip_s; } - return iface_n_ip(lp_ctx, 0); + return iface_n_ip(ifaces, 0); } /** return true if an IP is one one of our local networks */ -bool iface_is_local(struct loadparm_context *lp_ctx, const char *dest) +bool iface_is_local(struct interface *ifaces, const char *dest) { struct in_addr ip; - load_interfaces(lp_interfaces(lp_ctx)); - ip.s_addr = interpret_addr(dest); - if (iface_find(ip, true)) { + if (iface_find(ifaces, ip, true)) { return true; } return false; diff --git a/source4/lib/socket/netif.c b/source4/lib/socket/netif.c index c9f43e811a..bf410af441 100644 --- a/source4/lib/socket/netif.c +++ b/source4/lib/socket/netif.c @@ -2,6 +2,8 @@ Unix SMB/CIFS implementation. return a list of network interfaces Copyright (C) Andrew Tridgell 1998 + Copyright (C) Jeremy Allison 2007 + Copyright (C) Jelmer Vernooij 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,327 +31,63 @@ */ -#ifndef AUTOCONF_TEST #include "includes.h" -#endif - -#include <unistd.h> -#include <stdio.h> -#include <sys/types.h> -#include <netdb.h> -#include <sys/ioctl.h> -#include <netdb.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#ifndef SIOCGIFCONF -#ifdef HAVE_SYS_SOCKIO_H -#include <sys/sockio.h> -#endif -#endif - -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif - -#ifdef __COMPAR_FN_T -#define QSORT_CAST (__compar_fn_t) -#endif - -#ifndef QSORT_CAST -#define QSORT_CAST (int (*)(const void *, const void *)) -#endif - -#ifdef HAVE_NET_IF_H -#include <net/if.h> -#endif - +#include "system/network.h" #include "netif.h" -#if HAVE_IFACE_IFCONF - -/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 - V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. - - It probably also works on any BSD style system. */ - /**************************************************************************** - get the netmask address for a local interface + Try the "standard" getifaddrs/freeifaddrs interfaces. + Also gets IPv6 interfaces. ****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - struct ifconf ifc; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; - int total = 0; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - n = ifc.ifc_len / sizeof(struct ifreq); - - /* Loop through interfaces, looking for given IP address */ - for (i=n-1;i>=0 && total < max_interfaces;i--) { - if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { - continue; - } - - iname = ifr[i].ifr_name; - ipaddr = (*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr; - - if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) { - continue; - } - - if (!(ifr[i].ifr_flags & IFF_UP)) { - continue; - } - - if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { - continue; - } - - nmask = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; - total++; - } - - close(fd); - - return total; -} - -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_IFCONF */ -#ifdef HAVE_IFACE_IFREQ - -#ifndef I_STR -#include <sys/stropts.h> -#endif /**************************************************************************** -this should cover most of the streams based systems -Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code + Get the netmask address for a local interface. ****************************************************************************/ + static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) { - struct ifreq ifreq; - struct strioctl strioctl; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; + struct ifaddrs *iflist = NULL; + struct ifaddrs *ifptr = NULL; int total = 0; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + if (getifaddrs(&iflist) < 0) { return -1; } - - strioctl.ic_cmd = SIOCGIFCONF; - strioctl.ic_dp = buff; - strioctl.ic_len = sizeof(buff); - if (ioctl(fd, I_STR, &strioctl) < 0) { - close(fd); - return -1; - } - - /* we can ignore the possible sizeof(int) here as the resulting - number of interface structures won't change */ - n = strioctl.ic_len / sizeof(struct ifreq); - /* we will assume that the kernel returns the length as an int - at the start of the buffer if the offered size is a - multiple of the structure size plus an int */ - if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { - ifr = (struct ifreq *)(buff + sizeof(int)); - } else { - ifr = (struct ifreq *)buff; - } + /* Loop through interfaces, looking for given IP address */ + for (ifptr = iflist, total = 0; + ifptr != NULL && total < max_interfaces; + ifptr = ifptr->ifa_next) { - /* Loop through interfaces */ + memset(&ifaces[total], '\0', sizeof(ifaces[total])); - for (i = 0; i<n && total < max_interfaces; i++) { - ifreq = ifr[i]; - - strioctl.ic_cmd = SIOCGIFFLAGS; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { - continue; - } - - if (!(ifreq.ifr_flags & IFF_UP)) { + if (!ifptr->ifa_addr || !ifptr->ifa_netmask) { continue; } - strioctl.ic_cmd = SIOCGIFADDR; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { + /* Check the interface is up. */ + if (!(ifptr->ifa_flags & IFF_UP)) { continue; } - ipaddr = (*(struct sockaddr_in *) &ifreq.ifr_addr).sin_addr; - iname = ifreq.ifr_name; - - strioctl.ic_cmd = SIOCGIFNETMASK; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { + /* We don't support IPv6 *yet* */ + if (ifptr->ifa_addr->sa_family != AF_INET) { continue; } - nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; + ifaces[total].ip = ((struct sockaddr_in *)ifptr->ifa_addr)->sin_addr; + ifaces[total].netmask = ((struct sockaddr_in *)ifptr->ifa_netmask)->sin_addr; + strlcpy(ifaces[total].name, ifptr->ifa_name, + sizeof(ifaces[total].name)); total++; } - close(fd); + freeifaddrs(iflist); return total; } -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_IFREQ */ -#ifdef HAVE_IFACE_AIX - -/**************************************************************************** -this one is for AIX (tested on 4.2) -****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - char buff[8192]; - int fd, i; - struct ifconf ifc; - struct ifreq *ifr=NULL; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - int total = 0; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - /* Loop through interfaces */ - i = ifc.ifc_len; - - while (i > 0 && total < max_interfaces) { - uint_t inc; - - inc = ifr->ifr_addr.sa_len; - - if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { - goto next; - } - - ipaddr = (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr; - iname = ifr->ifr_name; - - if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { - goto next; - } - - if (!(ifr->ifr_flags & IFF_UP)) { - goto next; - } - - if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { - goto next; - } - - nmask = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; - - total++; - - next: - /* - * Patch from Archie Cobbs (archie@whistle.com). The - * addresses in the SIOCGIFCONF interface list have a - * minimum size. Usually this doesn't matter, but if - * your machine has tunnel interfaces, etc. that have - * a zero length "link address", this does matter. */ - - if (inc < sizeof(ifr->ifr_addr)) - inc = sizeof(ifr->ifr_addr); - inc += IFNAMSIZ; - - ifr = (struct ifreq*) (((char*) ifr) + inc); - i -= inc; - } - - - close(fd); - return total; -} - -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_AIX */ -#ifndef _FOUND_IFACE_ANY -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - return -1; -} -#endif - - static int iface_comp(struct iface_struct *i1, struct iface_struct *i2) { int r; @@ -386,25 +124,3 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces) return total; } - - -#ifdef AUTOCONF_TEST -/* this is the autoconf driver to test get_interfaces() */ - - int main() -{ - struct iface_struct ifaces[MAX_INTERFACES]; - int total = get_interfaces(ifaces, MAX_INTERFACES); - int i; - - printf("got %d interfaces:\n", total); - if (total <= 0) exit(1); - - for (i=0;i<total;i++) { - printf("%-10s ", ifaces[i].name); - printf("IP=%s ", inet_ntoa(ifaces[i].ip)); - printf("NETMASK=%s\n", inet_ntoa(ifaces[i].netmask)); - } - return 0; -} -#endif diff --git a/source4/lib/socket/netif.h b/source4/lib/socket/netif.h index 4855f4bd73..417c6e074f 100644 --- a/source4/lib/socket/netif.h +++ b/source4/lib/socket/netif.h @@ -27,6 +27,8 @@ struct iface_struct { struct in_addr netmask; }; +struct interface; + #define MAX_INTERFACES 128 #ifndef AUTOCONF_TEST diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h index 24bc5f1aac..4baa0cfbb1 100644 --- a/source4/lib/socket/socket.h +++ b/source4/lib/socket/socket.h @@ -126,6 +126,7 @@ struct socket_context { int family; }; +struct resolve_context; /* prototypes */ NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops, @@ -178,21 +179,21 @@ struct composite_context *socket_connect_send(struct socket_context *sock, struct socket_address *my_address, struct socket_address *server_address, uint32_t flags, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx); NTSTATUS socket_connect_recv(struct composite_context *ctx); NTSTATUS socket_connect_ev(struct socket_context *sock, struct socket_address *my_address, struct socket_address *server_address, uint32_t flags, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *ev); struct composite_context *socket_connect_multi_send(TALLOC_CTX *mem_ctx, const char *server_address, int num_server_ports, uint16_t *server_ports, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx); NTSTATUS socket_connect_multi_recv(struct composite_context *ctx, TALLOC_CTX *mem_ctx, @@ -200,7 +201,7 @@ NTSTATUS socket_connect_multi_recv(struct composite_context *ctx, uint16_t *port); NTSTATUS socket_connect_multi(TALLOC_CTX *mem_ctx, const char *server_address, int num_server_ports, uint16_t *server_ports, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct socket_context **result, uint16_t *port); diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c index e3676ad71a..e61b6d82fc 100644 --- a/source4/lib/socket/socket_ip.c +++ b/source4/lib/socket/socket_ip.c @@ -130,6 +130,8 @@ static NTSTATUS ipv4_connect(struct socket_context *sock, if (!srv_ip.s_addr) { return NT_STATUS_BAD_NETWORK_NAME; } + + SMB_ASSERT(srv_address->port != 0); ZERO_STRUCT(srv_addr); #ifdef HAVE_SOCK_SIN_LEN @@ -356,6 +358,8 @@ static NTSTATUS ipv4_sendto(struct socket_context *sock, } else { struct sockaddr_in srv_addr; struct in_addr addr; + + SMB_ASSERT(dest_addr->port != 0); ZERO_STRUCT(srv_addr); #ifdef HAVE_SOCK_SIN_LEN diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c index dea740dbc8..6d4d81a884 100644 --- a/source4/lib/socket/testsuite.c +++ b/source4/lib/socket/testsuite.c @@ -26,8 +26,9 @@ #include "lib/socket/netif.h" #include "torture/torture.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" -/* +/** basic testing of udp routines */ static bool test_udp(struct torture_context *tctx) @@ -39,6 +40,9 @@ static bool test_udp(struct torture_context *tctx) DATA_BLOB blob, blob2; size_t sent, nread; TALLOC_CTX *mem_ctx = tctx; + struct interface *ifaces; + + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0); torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1"); @@ -49,7 +53,7 @@ static bool test_udp(struct torture_context *tctx) talloc_steal(mem_ctx, sock2); localhost = socket_address_from_strings(sock1, sock1->backend_name, - iface_best_ip(tctx->lp_ctx, "127.0.0.1"), 0); + iface_best_ip(ifaces, "127.0.0.1"), 0); torture_assert(tctx, localhost, "Localhost not found"); @@ -58,10 +62,10 @@ static bool test_udp(struct torture_context *tctx) srv_addr = socket_get_my_addr(sock1, mem_ctx); torture_assert(tctx, srv_addr != NULL && - strcmp(srv_addr->addr, iface_best_ip(tctx->lp_ctx, "127.0.0.1")) == 0, + strcmp(srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1")) == 0, talloc_asprintf(tctx, "Expected server address of %s but got %s", - iface_best_ip(tctx->lp_ctx, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL)); + iface_best_ip(ifaces, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL)); torture_comment(tctx, "server port is %d\n", srv_addr->port); @@ -121,6 +125,7 @@ static bool test_tcp(struct torture_context *tctx) size_t sent, nread; TALLOC_CTX *mem_ctx = tctx; struct event_context *ev = event_context_init(mem_ctx); + struct interface *ifaces; status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0); torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1"); @@ -130,8 +135,9 @@ static bool test_tcp(struct torture_context *tctx) torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1"); talloc_steal(mem_ctx, sock2); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); localhost = socket_address_from_strings(sock1, sock1->backend_name, - iface_best_ip(tctx->lp_ctx, "127.0.0.1"), 0); + iface_best_ip(ifaces, "127.0.0.1"), 0); torture_assert(tctx, localhost, "Localhost not found"); status = socket_listen(sock1, localhost, 0, 0); @@ -141,12 +147,12 @@ static bool test_tcp(struct torture_context *tctx) torture_assert(tctx, srv_addr && srv_addr->addr, "Unexpected socket_get_my_addr NULL\n"); - torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(tctx->lp_ctx, "127.0.0.1"), + torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1"), "Unexpected server address"); torture_comment(tctx, "server port is %d\n", srv_addr->port); - status = socket_connect_ev(sock2, NULL, srv_addr, 0, lp_name_resolve_order(tctx->lp_ctx), ev); + status = socket_connect_ev(sock2, NULL, srv_addr, 0, NULL, ev); torture_assert_ntstatus_ok(tctx, status, "connect() on socket 2"); status = socket_accept(sock1, &sock3); diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index 4d72c0e871..f9aefcd6de 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -1246,12 +1246,12 @@ char *talloc_strndup_append_buffer(char *s, const char *a, size_t n) #endif char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) -{ +{ int len; char *ret; va_list ap2; char c; - + /* this call looks strange, but it makes it work on older solaris boxes */ va_copy(ap2, ap); len = vsnprintf(&c, 1, fmt, ap2); diff --git a/source4/lib/talloc/talloc.i b/source4/lib/talloc/talloc.i index c35d5d2411..c852ae8f9f 100644 --- a/source4/lib/talloc/talloc.i +++ b/source4/lib/talloc/talloc.i @@ -22,3 +22,10 @@ %typemap(in, numinputs=0) TALLOC_CTX * { $1 = NULL; } + +%define %talloctype(TYPE) +%nodefaultctor TYPE; +%extend TYPE { + ~TYPE() { talloc_free($self); } +} +%enddef diff --git a/source4/lib/tdb/tdb.py b/source4/lib/tdb/tdb.py index 1105291099..d4cf9f5c6f 100644 --- a/source4/lib/tdb/tdb.py +++ b/source4/lib/tdb/tdb.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _tdb import new @@ -48,6 +47,16 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + REPLACE = _tdb.REPLACE INSERT = _tdb.INSERT MODIFY = _tdb.MODIFY @@ -69,39 +78,11 @@ TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY -class tdb(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, tdb, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, tdb, name) +class tdb(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self): raise AttributeError, "No constructor defined" __repr__ = _swig_repr - def error(*args, **kwargs): return _tdb.tdb_error(*args, **kwargs) __swig_destroy__ = _tdb.delete_tdb - __del__ = lambda self : None; - def close(*args, **kwargs): return _tdb.tdb_close(*args, **kwargs) - def append(*args, **kwargs): return _tdb.tdb_append(*args, **kwargs) - def errorstr(*args, **kwargs): return _tdb.tdb_errorstr(*args, **kwargs) - def fetch(*args, **kwargs): return _tdb.tdb_fetch(*args, **kwargs) - def delete(*args, **kwargs): return _tdb.tdb_delete(*args, **kwargs) - def store(*args, **kwargs): return _tdb.tdb_store(*args, **kwargs) - def exists(*args, **kwargs): return _tdb.tdb_exists(*args, **kwargs) - def firstkey(*args, **kwargs): return _tdb.tdb_firstkey(*args, **kwargs) - def nextkey(*args, **kwargs): return _tdb.tdb_nextkey(*args, **kwargs) - def lock_all(*args, **kwargs): return _tdb.tdb_lock_all(*args, **kwargs) - def unlock_all(*args, **kwargs): return _tdb.tdb_unlock_all(*args, **kwargs) - def read_lock_all(*args, **kwargs): return _tdb.tdb_read_lock_all(*args, **kwargs) - def read_unlock_all(*args, **kwargs): return _tdb.tdb_read_unlock_all(*args, **kwargs) - def reopen(*args, **kwargs): return _tdb.tdb_reopen(*args, **kwargs) - def transaction_start(*args, **kwargs): return _tdb.tdb_transaction_start(*args, **kwargs) - def transaction_commit(*args, **kwargs): return _tdb.tdb_transaction_commit(*args, **kwargs) - def transaction_cancel(*args, **kwargs): return _tdb.tdb_transaction_cancel(*args, **kwargs) - def transaction_recover(*args, **kwargs): return _tdb.tdb_transaction_recover(*args, **kwargs) - def hash_size(*args, **kwargs): return _tdb.tdb_hash_size(*args, **kwargs) - def map_size(*args, **kwargs): return _tdb.tdb_map_size(*args, **kwargs) - def get_flags(*args, **kwargs): return _tdb.tdb_get_flags(*args, **kwargs) - def set_max_dead(*args, **kwargs): return _tdb.tdb_set_max_dead(*args, **kwargs) - def name(*args, **kwargs): return _tdb.tdb_name(*args, **kwargs) def __str__(self): return self.name() @@ -173,6 +154,30 @@ class tdb(_object): +tdb.error = new_instancemethod(_tdb.tdb_error,None,tdb) +tdb.close = new_instancemethod(_tdb.tdb_close,None,tdb) +tdb.append = new_instancemethod(_tdb.tdb_append,None,tdb) +tdb.errorstr = new_instancemethod(_tdb.tdb_errorstr,None,tdb) +tdb.fetch = new_instancemethod(_tdb.tdb_fetch,None,tdb) +tdb.delete = new_instancemethod(_tdb.tdb_delete,None,tdb) +tdb.store = new_instancemethod(_tdb.tdb_store,None,tdb) +tdb.exists = new_instancemethod(_tdb.tdb_exists,None,tdb) +tdb.firstkey = new_instancemethod(_tdb.tdb_firstkey,None,tdb) +tdb.nextkey = new_instancemethod(_tdb.tdb_nextkey,None,tdb) +tdb.lock_all = new_instancemethod(_tdb.tdb_lock_all,None,tdb) +tdb.unlock_all = new_instancemethod(_tdb.tdb_unlock_all,None,tdb) +tdb.read_lock_all = new_instancemethod(_tdb.tdb_read_lock_all,None,tdb) +tdb.read_unlock_all = new_instancemethod(_tdb.tdb_read_unlock_all,None,tdb) +tdb.reopen = new_instancemethod(_tdb.tdb_reopen,None,tdb) +tdb.transaction_start = new_instancemethod(_tdb.tdb_transaction_start,None,tdb) +tdb.transaction_commit = new_instancemethod(_tdb.tdb_transaction_commit,None,tdb) +tdb.transaction_cancel = new_instancemethod(_tdb.tdb_transaction_cancel,None,tdb) +tdb.transaction_recover = new_instancemethod(_tdb.tdb_transaction_recover,None,tdb) +tdb.hash_size = new_instancemethod(_tdb.tdb_hash_size,None,tdb) +tdb.map_size = new_instancemethod(_tdb.tdb_map_size,None,tdb) +tdb.get_flags = new_instancemethod(_tdb.tdb_get_flags,None,tdb) +tdb.set_max_dead = new_instancemethod(_tdb.tdb_set_max_dead,None,tdb) +tdb.name = new_instancemethod(_tdb.tdb_name,None,tdb) tdb_swigregister = _tdb.tdb_swigregister tdb_swigregister(tdb) diff --git a/source4/lib/tdb/tdb_wrap.c b/source4/lib/tdb/tdb_wrap.c index b9660c3428..841cd78399 100644 --- a/source4/lib/tdb/tdb_wrap.c +++ b/source4/lib/tdb/tdb_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2479,6 +2479,19 @@ static swig_module_info swig_module = {swig_types, 11, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _tdb.so @@ -2880,10 +2893,11 @@ SWIGINTERN PyObject *_wrap_tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *a enum TDB_ERROR result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_error",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_error" "', argument " "1"" of type '" "tdb *""'"); } @@ -2901,10 +2915,11 @@ SWIGINTERN PyObject *_wrap_delete_tdb(PyObject *SWIGUNUSEDPARM(self), PyObject * tdb *arg1 = (tdb *) 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:delete_tdb",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, SWIG_POINTER_DISOWN | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_tdb" "', argument " "1"" of type '" "tdb *""'"); } @@ -2924,10 +2939,11 @@ SWIGINTERN PyObject *_wrap_tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *a int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_close",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_close" "', argument " "1"" of type '" "tdb *""'"); } @@ -2991,10 +3007,11 @@ SWIGINTERN PyObject *_wrap_tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_errorstr",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_errorstr" "', argument " "1"" of type '" "tdb *""'"); } @@ -3184,10 +3201,11 @@ SWIGINTERN PyObject *_wrap_tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject TDB_DATA result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_firstkey",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_firstkey" "', argument " "1"" of type '" "tdb *""'"); } @@ -3255,10 +3273,11 @@ SWIGINTERN PyObject *_wrap_tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_lock_all",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_lock_all" "', argument " "1"" of type '" "tdb *""'"); } @@ -3277,10 +3296,11 @@ SWIGINTERN PyObject *_wrap_tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObje int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_unlock_all",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_unlock_all" "', argument " "1"" of type '" "tdb *""'"); } @@ -3299,10 +3319,11 @@ SWIGINTERN PyObject *_wrap_tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyO int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_read_lock_all",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_read_lock_all" "', argument " "1"" of type '" "tdb *""'"); } @@ -3321,10 +3342,11 @@ SWIGINTERN PyObject *_wrap_tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), P int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_read_unlock_all",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_read_unlock_all" "', argument " "1"" of type '" "tdb *""'"); } @@ -3343,10 +3365,11 @@ SWIGINTERN PyObject *_wrap_tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject * int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_reopen",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_reopen" "', argument " "1"" of type '" "tdb *""'"); } @@ -3365,10 +3388,11 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_transaction_start",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_start" "', argument " "1"" of type '" "tdb *""'"); } @@ -3387,10 +3411,11 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self) int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_transaction_commit",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_commit" "', argument " "1"" of type '" "tdb *""'"); } @@ -3409,10 +3434,11 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self) int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_transaction_cancel",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_cancel" "', argument " "1"" of type '" "tdb *""'"); } @@ -3431,10 +3457,11 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_transaction_recover",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_recover" "', argument " "1"" of type '" "tdb *""'"); } @@ -3453,10 +3480,11 @@ SWIGINTERN PyObject *_wrap_tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObjec int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_hash_size",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_hash_size" "', argument " "1"" of type '" "tdb *""'"); } @@ -3475,10 +3503,11 @@ SWIGINTERN PyObject *_wrap_tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject size_t result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_map_size",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_map_size" "', argument " "1"" of type '" "tdb *""'"); } @@ -3497,10 +3526,11 @@ SWIGINTERN PyObject *_wrap_tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObjec int result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_get_flags",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_get_flags" "', argument " "1"" of type '" "tdb *""'"); } @@ -3552,10 +3582,11 @@ SWIGINTERN PyObject *_wrap_tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *ar char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:tdb_name",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_name" "', argument " "1"" of type '" "tdb *""'"); } @@ -3570,38 +3601,38 @@ fail: SWIGINTERN PyObject *tdb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_tdb_context, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } static PyMethodDef SwigMethods[] = { { (char *)"new_Tdb", (PyCFunction) _wrap_new_Tdb, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_error", _wrap_tdb_error, METH_VARARGS, NULL}, - { (char *)"delete_tdb", _wrap_delete_tdb, METH_VARARGS, NULL}, - { (char *)"tdb_close", _wrap_tdb_close, METH_VARARGS, NULL}, + { (char *)"tdb_error", (PyCFunction)_wrap_tdb_error, METH_O, NULL}, + { (char *)"delete_tdb", (PyCFunction)_wrap_delete_tdb, METH_O, NULL}, + { (char *)"tdb_close", (PyCFunction)_wrap_tdb_close, METH_O, NULL}, { (char *)"tdb_append", (PyCFunction) _wrap_tdb_append, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_errorstr", _wrap_tdb_errorstr, METH_VARARGS, NULL}, + { (char *)"tdb_errorstr", (PyCFunction)_wrap_tdb_errorstr, METH_O, NULL}, { (char *)"tdb_fetch", (PyCFunction) _wrap_tdb_fetch, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"tdb_delete", (PyCFunction) _wrap_tdb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"tdb_store", (PyCFunction) _wrap_tdb_store, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"tdb_exists", (PyCFunction) _wrap_tdb_exists, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_firstkey", _wrap_tdb_firstkey, METH_VARARGS, NULL}, + { (char *)"tdb_firstkey", (PyCFunction)_wrap_tdb_firstkey, METH_O, NULL}, { (char *)"tdb_nextkey", (PyCFunction) _wrap_tdb_nextkey, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_lock_all", _wrap_tdb_lock_all, METH_VARARGS, NULL}, - { (char *)"tdb_unlock_all", _wrap_tdb_unlock_all, METH_VARARGS, NULL}, - { (char *)"tdb_read_lock_all", _wrap_tdb_read_lock_all, METH_VARARGS, NULL}, - { (char *)"tdb_read_unlock_all", _wrap_tdb_read_unlock_all, METH_VARARGS, NULL}, - { (char *)"tdb_reopen", _wrap_tdb_reopen, METH_VARARGS, NULL}, - { (char *)"tdb_transaction_start", _wrap_tdb_transaction_start, METH_VARARGS, NULL}, - { (char *)"tdb_transaction_commit", _wrap_tdb_transaction_commit, METH_VARARGS, NULL}, - { (char *)"tdb_transaction_cancel", _wrap_tdb_transaction_cancel, METH_VARARGS, NULL}, - { (char *)"tdb_transaction_recover", _wrap_tdb_transaction_recover, METH_VARARGS, NULL}, - { (char *)"tdb_hash_size", _wrap_tdb_hash_size, METH_VARARGS, NULL}, - { (char *)"tdb_map_size", _wrap_tdb_map_size, METH_VARARGS, NULL}, - { (char *)"tdb_get_flags", _wrap_tdb_get_flags, METH_VARARGS, NULL}, + { (char *)"tdb_lock_all", (PyCFunction)_wrap_tdb_lock_all, METH_O, NULL}, + { (char *)"tdb_unlock_all", (PyCFunction)_wrap_tdb_unlock_all, METH_O, NULL}, + { (char *)"tdb_read_lock_all", (PyCFunction)_wrap_tdb_read_lock_all, METH_O, NULL}, + { (char *)"tdb_read_unlock_all", (PyCFunction)_wrap_tdb_read_unlock_all, METH_O, NULL}, + { (char *)"tdb_reopen", (PyCFunction)_wrap_tdb_reopen, METH_O, NULL}, + { (char *)"tdb_transaction_start", (PyCFunction)_wrap_tdb_transaction_start, METH_O, NULL}, + { (char *)"tdb_transaction_commit", (PyCFunction)_wrap_tdb_transaction_commit, METH_O, NULL}, + { (char *)"tdb_transaction_cancel", (PyCFunction)_wrap_tdb_transaction_cancel, METH_O, NULL}, + { (char *)"tdb_transaction_recover", (PyCFunction)_wrap_tdb_transaction_recover, METH_O, NULL}, + { (char *)"tdb_hash_size", (PyCFunction)_wrap_tdb_hash_size, METH_O, NULL}, + { (char *)"tdb_map_size", (PyCFunction)_wrap_tdb_map_size, METH_O, NULL}, + { (char *)"tdb_get_flags", (PyCFunction)_wrap_tdb_get_flags, METH_O, NULL}, { (char *)"tdb_set_max_dead", (PyCFunction) _wrap_tdb_set_max_dead, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_name", _wrap_tdb_name, METH_VARARGS, NULL}, + { (char *)"tdb_name", (PyCFunction)_wrap_tdb_name, METH_O, NULL}, { (char *)"tdb_swigregister", tdb_swigregister, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; diff --git a/source4/lib/tdr/tdr.c b/source4/lib/tdr/tdr.c index 0757a02e47..f75cac9810 100644 --- a/source4/lib/tdr/tdr.c +++ b/source4/lib/tdr/tdr.c @@ -24,6 +24,7 @@ #include "system/filesys.h" #include "system/network.h" #include "tdr/tdr.h" +#include "param/param.h" #define TDR_BASE_MARSHALL_SIZE 1024 @@ -153,7 +154,7 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v, TDR_PULL_NEED_BYTES(tdr, el_size*length); - ret = convert_string_talloc(ctx, global_smb_iconv_convenience, chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v)); + ret = convert_string_talloc(ctx, lp_iconv_convenience(global_loadparm), chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v)); if (ret == -1) { return NT_STATUS_INVALID_PARAMETER; @@ -175,7 +176,7 @@ NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length, required = el_size * length; TDR_PUSH_NEED_BYTES(tdr, required); - ret = convert_string(global_smb_iconv_convenience, CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required); + ret = convert_string(tdr->iconv_convenience, CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required); if (ret == -1) { return NT_STATUS_INVALID_PARAMETER; @@ -371,9 +372,33 @@ NTSTATUS tdr_pull_DATA_BLOB(struct tdr_pull *tdr, TALLOC_CTX *ctx, DATA_BLOB *bl return NT_STATUS_OK; } -NTSTATUS tdr_push_to_fd(int fd, tdr_push_fn_t push_fn, const void *p) +struct tdr_push *tdr_push_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic) { - struct tdr_push *push = talloc_zero(NULL, struct tdr_push); + struct tdr_push *push = talloc_zero(mem_ctx, struct tdr_push); + + if (push == NULL) + return NULL; + + push->iconv_convenience = talloc_reference(push, ic); + + return push; +} + +struct tdr_pull *tdr_pull_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic) +{ + struct tdr_pull *pull = talloc_zero(mem_ctx, struct tdr_pull); + + if (pull == NULL) + return NULL; + + pull->iconv_convenience = talloc_reference(pull, ic); + + return pull; +} + +NTSTATUS tdr_push_to_fd(int fd, struct smb_iconv_convenience *iconv_convenience, tdr_push_fn_t push_fn, const void *p) +{ + struct tdr_push *push = tdr_push_init(NULL, iconv_convenience); if (push == NULL) return NT_STATUS_NO_MEMORY; @@ -404,9 +429,7 @@ void tdr_print_debug_helper(struct tdr_print *tdr, const char *format, ...) _PRI vasprintf(&s, format, ap); va_end(ap); - for (i=0;i<tdr->level;i++) { - DEBUG(0,(" ")); - } + for (i=0;i<tdr->level;i++) { DEBUG(0,(" ")); } DEBUG(0,("%s\n", s)); free(s); diff --git a/source4/lib/tdr/tdr.h b/source4/lib/tdr/tdr.h index 689b9f3ebb..301cd3002e 100644 --- a/source4/lib/tdr/tdr.h +++ b/source4/lib/tdr/tdr.h @@ -33,11 +33,13 @@ struct tdr_pull { DATA_BLOB data; uint32_t offset; int flags; + struct smb_iconv_convenience *iconv_convenience; }; struct tdr_push { DATA_BLOB data; int flags; + struct smb_iconv_convenience *iconv_convenience; }; struct tdr_print { diff --git a/source4/lib/tdr/testsuite.c b/source4/lib/tdr/testsuite.c index 20afca25a5..44c5810f90 100644 --- a/source4/lib/tdr/testsuite.c +++ b/source4/lib/tdr/testsuite.c @@ -21,11 +21,12 @@ #include "includes.h" #include "torture/torture.h" #include "lib/tdr/tdr.h" +#include "param/param.h" static bool test_push_uint8(struct torture_context *tctx) { uint8_t v = 4; - struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push); + struct tdr_push *tdr = tdr_push_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ntstatus_ok(tctx, tdr_push_uint8(tdr, &v), "push failed"); torture_assert_int_equal(tctx, tdr->data.length, 1, "length incorrect"); @@ -37,14 +38,14 @@ static bool test_pull_uint8(struct torture_context *tctx) { uint8_t d = 2; uint8_t l; - struct tdr_pull tdr; - tdr.data.data = &d; - tdr.data.length = 1; - tdr.offset = 0; - tdr.flags = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_uint8(&tdr, tctx, &l), + struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); + tdr->data.data = &d; + tdr->data.length = 1; + tdr->offset = 0; + tdr->flags = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_uint8(tdr, tctx, &l), "pull failed"); - torture_assert_int_equal(tctx, 1, tdr.offset, + torture_assert_int_equal(tctx, 1, tdr->offset, "offset invalid"); return true; } @@ -52,7 +53,7 @@ static bool test_pull_uint8(struct torture_context *tctx) static bool test_push_uint16(struct torture_context *tctx) { uint16_t v = 0xF32; - struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push); + struct tdr_push *tdr = tdr_push_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ntstatus_ok(tctx, tdr_push_uint16(tdr, &v), "push failed"); torture_assert_int_equal(tctx, tdr->data.length, 2, "length incorrect"); @@ -65,15 +66,14 @@ static bool test_pull_uint16(struct torture_context *tctx) { uint8_t d[2] = { 782 & 0xFF, (782 & 0xFF00) / 0x100 }; uint16_t l; - struct tdr_pull tdr; - tdr.data.data = d; - tdr.data.length = 2; - tdr.offset = 0; - tdr.flags = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_uint16(&tdr, tctx, &l), + struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); + tdr->data.data = d; + tdr->data.length = 2; + tdr->offset = 0; + tdr->flags = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_uint16(tdr, tctx, &l), "pull failed"); - torture_assert_int_equal(tctx, 2, tdr.offset, - "offset invalid"); + torture_assert_int_equal(tctx, 2, tdr->offset, "offset invalid"); torture_assert_int_equal(tctx, 782, l, "right int read"); return true; } @@ -81,7 +81,7 @@ static bool test_pull_uint16(struct torture_context *tctx) static bool test_push_uint32(struct torture_context *tctx) { uint32_t v = 0x100F32; - struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push); + struct tdr_push *tdr = tdr_push_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ntstatus_ok(tctx, tdr_push_uint32(tdr, &v), "push failed"); torture_assert_int_equal(tctx, tdr->data.length, 4, "length incorrect"); @@ -96,35 +96,35 @@ static bool test_pull_uint32(struct torture_context *tctx) { uint8_t d[4] = { 782 & 0xFF, (782 & 0xFF00) / 0x100, 0, 0 }; uint32_t l; - struct tdr_pull tdr; - tdr.data.data = d; - tdr.data.length = 4; - tdr.offset = 0; - tdr.flags = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_uint32(&tdr, tctx, &l), + struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); + tdr->data.data = d; + tdr->data.length = 4; + tdr->offset = 0; + tdr->flags = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_uint32(tdr, tctx, &l), "pull failed"); - torture_assert_int_equal(tctx, 4, tdr.offset, "offset invalid"); + torture_assert_int_equal(tctx, 4, tdr->offset, "offset invalid"); torture_assert_int_equal(tctx, 782, l, "right int read"); return true; } static bool test_pull_charset(struct torture_context *tctx) { - struct tdr_pull tdr; + struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); const char *l = NULL; - tdr.data.data = (uint8_t *)talloc_strdup(tctx, "bla"); - tdr.data.length = 4; - tdr.offset = 0; - tdr.flags = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, -1, 1, CH_DOS), + tdr->data.data = (uint8_t *)talloc_strdup(tctx, "bla"); + tdr->data.length = 4; + tdr->offset = 0; + tdr->flags = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, -1, 1, CH_DOS), "pull failed"); - torture_assert_int_equal(tctx, 4, tdr.offset, "offset invalid"); + torture_assert_int_equal(tctx, 4, tdr->offset, "offset invalid"); torture_assert_str_equal(tctx, "bla", l, "right int read"); - tdr.offset = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, 2, 1, CH_UNIX), + tdr->offset = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, 2, 1, CH_UNIX), "pull failed"); - torture_assert_int_equal(tctx, 2, tdr.offset, "offset invalid"); + torture_assert_int_equal(tctx, 2, tdr->offset, "offset invalid"); torture_assert_str_equal(tctx, "bl", l, "right int read"); return true; @@ -132,15 +132,15 @@ static bool test_pull_charset(struct torture_context *tctx) static bool test_pull_charset_empty(struct torture_context *tctx) { - struct tdr_pull tdr; + struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); const char *l = NULL; - tdr.data.data = (uint8_t *)talloc_strdup(tctx, "bla"); - tdr.data.length = 4; - tdr.offset = 0; - tdr.flags = 0; - torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, 0, 1, CH_DOS), + tdr->data.data = (uint8_t *)talloc_strdup(tctx, "bla"); + tdr->data.length = 4; + tdr->offset = 0; + tdr->flags = 0; + torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, 0, 1, CH_DOS), "pull failed"); - torture_assert_int_equal(tctx, 0, tdr.offset, "offset invalid"); + torture_assert_int_equal(tctx, 0, tdr->offset, "offset invalid"); torture_assert_str_equal(tctx, "", l, "right string read"); return true; @@ -151,7 +151,7 @@ static bool test_pull_charset_empty(struct torture_context *tctx) static bool test_push_charset(struct torture_context *tctx) { const char *l = "bloe"; - struct tdr_push *tdr = talloc_zero(tctx, struct tdr_push); + struct tdr_push *tdr = tdr_push_init(tctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ntstatus_ok(tctx, tdr_push_charset(tdr, &l, 4, 1, CH_UTF8), "push failed"); torture_assert_int_equal(tctx, 4, tdr->data.length, "offset invalid"); diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 5b3fe4b1ea..308d81b105 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. display print functions Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,13 +33,26 @@ #include "includes.h" #include "system/locale.h" +#include "param/param.h" + +static smb_iconv_t display_cd = (smb_iconv_t)-1; + +void d_set_iconv(smb_iconv_t cd) +{ + display_cd = cd; +} _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p, *p2; - int ret, maxlen, clen; + int ret, clen; va_list ap2; + /* If there's nothing to convert, take a shortcut */ + if (display_cd == (smb_iconv_t)-1) { + return vfprintf(f, format, ap); + } + /* do any message translations */ va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); @@ -46,16 +60,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU if (ret <= 0) return ret; - /* now we have the string in unix format, convert it to the display - charset, but beware of it growing */ - maxlen = ret*2; -again: - p2 = (char *)malloc(maxlen); - if (!p2) { - SAFE_FREE(p); - return -1; - } - clen = convert_string(global_smb_iconv_convenience, CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string_talloc_descriptor(NULL, display_cd, p, ret, (void **)&p2); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ @@ -68,22 +73,13 @@ again: } } SAFE_FREE(p); - SAFE_FREE(p2); return ret; } - - if (clen >= maxlen) { - /* it didn't fit - try a larger buffer */ - maxlen *= 2; - SAFE_FREE(p2); - goto again; - } - /* good, its converted OK */ SAFE_FREE(p); ret = fwrite(p2, 1, clen, f); - SAFE_FREE(p2); + talloc_free(p2); return ret; } @@ -112,3 +108,4 @@ _PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) return ret; } + diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index e1bf6f94c5..1fb57b07a4 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -29,6 +29,7 @@ */ #include "includes.h" +#include "param/param.h" static int null_match(const char *p) { @@ -64,7 +65,7 @@ static int ms_fnmatch_core(const char *p, const char *n, int i; size_t size, size_n; - while ((c = next_codepoint(global_smb_iconv_convenience, p, &size))) { + while ((c = next_codepoint(lp_iconv_convenience(global_loadparm), p, &size))) { p += size; switch (c) { @@ -74,7 +75,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return null_match(p); } for (i=0; n[i]; i += size_n) { - next_codepoint(global_smb_iconv_convenience, n+i, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) { return 0; } @@ -93,7 +94,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return -1; } for (i=0; n[i]; i += size_n) { - next_codepoint(global_smb_iconv_convenience, n+i, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0; if (n+i == ldot) { if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0; @@ -109,7 +110,7 @@ static int ms_fnmatch_core(const char *p, const char *n, if (! *n) { return -1; } - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; @@ -123,7 +124,7 @@ static int ms_fnmatch_core(const char *p, const char *n, break; } if (! *n) return null_match(p); - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; @@ -133,12 +134,12 @@ static int ms_fnmatch_core(const char *p, const char *n, return 0; } if (*n != '.') return -1; - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; default: - c2 = next_codepoint(global_smb_iconv_convenience, n, &size_n); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); if (c != c2 && codepoint_cmpi(c, c2) != 0) { return -1; } diff --git a/source4/lib/util/smbrun.c b/source4/lib/util/smbrun.c deleted file mode 100644 index 26330ab992..0000000000 --- a/source4/lib/util/smbrun.c +++ /dev/null @@ -1,341 +0,0 @@ -/* - Unix SMB/CIFS implementation. - run a command as a specified user - Copyright (C) Andrew Tridgell 1992-1998 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" - -/* need to move this from here!! need some sleep ... */ -struct current_user current_user; - -/**************************************************************************** -This is a utility function of smbrun(). -****************************************************************************/ - -static int setup_out_fd(void) -{ - int fd; - TALLOC_CTX *ctx = talloc_stackframe(); - char *path = NULL; - - path = talloc_asprintf(ctx, - "%s/smb.XXXXXX", - tmpdir()); - if (!path) { - TALLOC_FREE(ctx); - errno = ENOMEM; - return -1; - } - - /* now create the file */ - fd = smb_mkstemp(path); - - if (fd == -1) { - DEBUG(0,("setup_out_fd: Failed to create file %s. (%s)\n", - path, strerror(errno) )); - TALLOC_FREE(ctx); - return -1; - } - - DEBUG(10,("setup_out_fd: Created tmp file %s\n", path )); - - /* Ensure file only kept around by open fd. */ - unlink(path); - TALLOC_FREE(ctx); - return fd; -} - -/**************************************************************************** -run a command being careful about uid/gid handling and putting the output in -outfd (or discard it if outfd is NULL). -****************************************************************************/ - -static int smbrun_internal(const char *cmd, int *outfd, BOOL sanitize) -{ - pid_t pid; - uid_t uid = current_user.ut.uid; - gid_t gid = current_user.ut.gid; - - /* - * Lose any elevated privileges. - */ - drop_effective_capability(KERNEL_OPLOCK_CAPABILITY); - drop_effective_capability(DMAPI_ACCESS_CAPABILITY); - - /* point our stdout at the file we want output to go into */ - - if (outfd && ((*outfd = setup_out_fd()) == -1)) { - return -1; - } - - /* in this method we will exec /bin/sh with the correct - arguments, after first setting stdout to point at the file */ - - /* - * We need to temporarily stop CatchChild from eating - * SIGCLD signals as it also eats the exit status code. JRA. - */ - - CatchChildLeaveStatus(); - - if ((pid=sys_fork()) < 0) { - DEBUG(0,("smbrun: fork failed with error %s\n", strerror(errno) )); - CatchChild(); - if (outfd) { - close(*outfd); - *outfd = -1; - } - return errno; - } - - if (pid) { - /* - * Parent. - */ - int status=0; - pid_t wpid; - - - /* the parent just waits for the child to exit */ - while((wpid = sys_waitpid(pid,&status,0)) < 0) { - if(errno == EINTR) { - errno = 0; - continue; - } - break; - } - - CatchChild(); - - if (wpid != pid) { - DEBUG(2,("waitpid(%d) : %s\n",(int)pid,strerror(errno))); - if (outfd) { - close(*outfd); - *outfd = -1; - } - return -1; - } - - /* Reset the seek pointer. */ - if (outfd) { - sys_lseek(*outfd, 0, SEEK_SET); - } - -#if defined(WIFEXITED) && defined(WEXITSTATUS) - if (WIFEXITED(status)) { - return WEXITSTATUS(status); - } -#endif - - return status; - } - - CatchChild(); - - /* we are in the child. we exec /bin/sh to do the work for us. we - don't directly exec the command we want because it may be a - pipeline or anything else the config file specifies */ - - /* point our stdout at the file we want output to go into */ - if (outfd) { - close(1); - if (sys_dup2(*outfd,1) != 1) { - DEBUG(2,("Failed to create stdout file descriptor\n")); - close(*outfd); - exit(80); - } - } - - /* now completely lose our privileges. This is a fairly paranoid - way of doing it, but it does work on all systems that I know of */ - - become_user_permanently(uid, gid); - - if (getuid() != uid || geteuid() != uid || - getgid() != gid || getegid() != gid) { - /* we failed to lose our privileges - do not execute - the command */ - exit(81); /* we can't print stuff at this stage, - instead use exit codes for debugging */ - } - -#ifndef __INSURE__ - /* close all other file descriptors, leaving only 0, 1 and 2. 0 and - 2 point to /dev/null from the startup code */ - { - int fd; - for (fd=3;fd<256;fd++) close(fd); - } -#endif - - { - const char *newcmd = sanitize ? escape_shell_string(cmd) : cmd; - if (!newcmd) { - exit(82); - } - execl("/bin/sh","sh","-c",newcmd,NULL); - } - - /* not reached */ - exit(83); - return 1; -} - -/**************************************************************************** - Use only in known safe shell calls (printing). -****************************************************************************/ - -int smbrun_no_sanitize(const char *cmd, int *outfd) -{ - return smbrun_internal(cmd, outfd, False); -} - -/**************************************************************************** - By default this now sanitizes shell expansion. -****************************************************************************/ - -int smbrun(const char *cmd, int *outfd) -{ - return smbrun_internal(cmd, outfd, True); -} - -/**************************************************************************** -run a command being careful about uid/gid handling and putting the output in -outfd (or discard it if outfd is NULL). -sends the provided secret to the child stdin. -****************************************************************************/ - -int smbrunsecret(const char *cmd, const char *secret) -{ - pid_t pid; - uid_t uid = current_user.ut.uid; - gid_t gid = current_user.ut.gid; - int ifd[2]; - - /* - * Lose any elevated privileges. - */ - drop_effective_capability(KERNEL_OPLOCK_CAPABILITY); - drop_effective_capability(DMAPI_ACCESS_CAPABILITY); - - /* build up an input pipe */ - if(pipe(ifd)) { - return -1; - } - - /* in this method we will exec /bin/sh with the correct - arguments, after first setting stdout to point at the file */ - - /* - * We need to temporarily stop CatchChild from eating - * SIGCLD signals as it also eats the exit status code. JRA. - */ - - CatchChildLeaveStatus(); - - if ((pid=sys_fork()) < 0) { - DEBUG(0, ("smbrunsecret: fork failed with error %s\n", strerror(errno))); - CatchChild(); - return errno; - } - - if (pid) { - /* - * Parent. - */ - int status = 0; - pid_t wpid; - size_t towrite; - ssize_t wrote; - - close(ifd[0]); - /* send the secret */ - towrite = strlen(secret); - wrote = write(ifd[1], secret, towrite); - if ( wrote != towrite ) { - DEBUG(0,("smbrunsecret: wrote %ld of %lu bytes\n",(long)wrote,(unsigned long)towrite)); - } - fsync(ifd[1]); - close(ifd[1]); - - /* the parent just waits for the child to exit */ - while((wpid = sys_waitpid(pid, &status, 0)) < 0) { - if(errno == EINTR) { - errno = 0; - continue; - } - break; - } - - CatchChild(); - - if (wpid != pid) { - DEBUG(2, ("waitpid(%d) : %s\n", (int)pid, strerror(errno))); - return -1; - } - -#if defined(WIFEXITED) && defined(WEXITSTATUS) - if (WIFEXITED(status)) { - return WEXITSTATUS(status); - } -#endif - - return status; - } - - CatchChild(); - - /* we are in the child. we exec /bin/sh to do the work for us. we - don't directly exec the command we want because it may be a - pipeline or anything else the config file specifies */ - - close(ifd[1]); - close(0); - if (sys_dup2(ifd[0], 0) != 0) { - DEBUG(2,("Failed to create stdin file descriptor\n")); - close(ifd[0]); - exit(80); - } - - /* now completely lose our privileges. This is a fairly paranoid - way of doing it, but it does work on all systems that I know of */ - - become_user_permanently(uid, gid); - - if (getuid() != uid || geteuid() != uid || - getgid() != gid || getegid() != gid) { - /* we failed to lose our privileges - do not execute - the command */ - exit(81); /* we can't print stuff at this stage, - instead use exit codes for debugging */ - } - -#ifndef __INSURE__ - /* close all other file descriptors, leaving only 0, 1 and 2. 0 and - 2 point to /dev/null from the startup code */ - { - int fd; - for (fd = 3; fd < 256; fd++) close(fd); - } -#endif - - execl("/bin/sh", "sh", "-c", cmd, NULL); - - /* not reached */ - exit(82); - return 1; -} diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 437d9d741a..3ecb982e24 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -64,6 +64,29 @@ static bool test_lists_shell(struct torture_context *tctx, return true; } +static bool test_list_copy(struct torture_context *tctx) +{ + const char **result; + const char *list[] = { "foo", "bar", NULL }; + const char *empty_list[] = { NULL }; + const char **null_list = NULL; + + result = str_list_copy(tctx, list); + torture_assert_int_equal(tctx, str_list_length(result), 2, "list length"); + torture_assert_str_equal(tctx, result[0], "foo", "element 0"); + torture_assert_str_equal(tctx, result[1], "bar", "element 1"); + torture_assert_str_equal(tctx, result[2], NULL, "element 2"); + + result = str_list_copy(tctx, empty_list); + torture_assert_int_equal(tctx, str_list_length(result), 0, "list length"); + torture_assert_str_equal(tctx, result[0], NULL, "element 0"); + + result = str_list_copy(tctx, null_list); + torture_assert(tctx, result == NULL, "result NULL"); + + return true; +} + struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST"); @@ -75,5 +98,7 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) &test_lists_shell_strings[i]); } + torture_suite_add_simple_test(suite, "list_copy", test_list_copy); + return suite; } diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index f3adbb3333..9e106052f2 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -262,6 +262,7 @@ _PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); /* The following definitions come from lib/util/dprintf.c */ +_PUBLIC_ void d_set_iconv(smb_iconv_t); _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2,3); _PUBLIC_ int d_printf(const char *format, ...) PRINTF_ATTRIBUTE(1,2); diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index ba8443c236..a8719af190 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -23,16 +23,16 @@ #include "includes.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" - +#include "lib/util/util_ldb.h" /* search the sam for the specified attributes - va_list variant */ -int gendb_search_v(struct ldb_context *ldb, +int gendb_search_v(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***msgs, const char * const *attrs, - const char *format, + const char *format, va_list ap) _PRINTF_ATTRIBUTE(6,0) { enum ldb_scope scope = LDB_SCOPE_SUBTREE; diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 1f1cc17d00..30de4b962d 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -199,8 +199,14 @@ _PUBLIC_ size_t str_list_length(const char **list) _PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) { int i; - const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); - if (ret == NULL) return NULL; + const char **ret; + + if (list == NULL) + return NULL; + + ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); + if (ret == NULL) + return NULL; for (i=0;list && list[i];i++) { ret[i] = talloc_strdup(ret, list[i]); diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index d7bddbde01..77ad4eb617 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -445,7 +445,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) int len; int *i; void **p; - char *s, **b; + char *s, **b, **ps; char c; char *buf0 = buf; const char *fmt0 = fmt; @@ -453,7 +453,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) tdb_log_func log_fn = tdb_log_fn(tdb); va_start(ap, fmt); - + while (*fmt) { switch ((c=*fmt++)) { case 'b': @@ -485,11 +485,10 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) *p = (void *)IVAL(buf, 0); break; case 'P': - s = va_arg(ap,char *); - len = strlen(buf) + 1; - if (bufsize < len || len > sizeof(pstring)) - goto no_space; - memcpy(s, buf, len); + /* Return a malloc'ed string. */ + ps = va_arg(ap,char ** ); + len = strlen((const char *)buf) + 1; + *ps = strdup((const char *)buf); break; case 'f': s = va_arg(ap,char *); @@ -518,7 +517,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) memcpy(*b, buf+4, *i); break; default: - log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n", + log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n", c, fmt); len = 0; @@ -531,7 +530,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) va_end(ap); - log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", + log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); return PTR_DIFF(buf, buf0); diff --git a/source4/libcli/auth/config.mk b/source4/libcli/auth/config.mk index 5a0b7e14dc..6cea0a08f0 100644 --- a/source4/libcli/auth/config.mk +++ b/source4/libcli/auth/config.mk @@ -8,6 +8,7 @@ OBJ_FILES = credentials.o \ smbencrypt.o \ smbdes.o PUBLIC_DEPENDENCIES = \ - SCHANNELDB MSRPC_PARSE + MSRPC_PARSE \ + LIBSAMBA-CONFIG # End SUBSYSTEM LIBCLI_AUTH ################################# diff --git a/source4/libcli/auth/smbencrypt.c b/source4/libcli/auth/smbencrypt.c index ccad1058bf..26b78d25ef 100644 --- a/source4/libcli/auth/smbencrypt.c +++ b/source4/libcli/auth/smbencrypt.c @@ -28,6 +28,7 @@ #include "lib/crypto/crypto.h" #include "libcli/auth/libcli_auth.h" #include "pstring.h" +#include "param/param.h" /* This implements the X/Open SMB password encryption @@ -67,7 +68,7 @@ _PUBLIC_ bool E_md4hash(const char *passwd, uint8_t p16[16]) int len; void *wpwd; - len = push_ucs2_talloc(NULL, global_smb_iconv_convenience, &wpwd, passwd); + len = push_ucs2_talloc(NULL, lp_iconv_convenience(global_loadparm), &wpwd, passwd); if (len < 2) { /* We don't want to return fixed data, as most callers * don't check */ @@ -97,7 +98,7 @@ _PUBLIC_ bool E_deshash(const char *passwd, uint8_t p16[16]) ZERO_STRUCT(dospwd); /* Password must be converted to DOS charset - null terminated, uppercase. */ - push_string(global_smb_iconv_convenience, dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); + push_string(lp_iconv_convenience(global_loadparm), dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); /* Only the fisrt 14 chars are considered, password need not be null terminated. */ E_P16((const uint8_t *)dospwd, p16); @@ -150,14 +151,14 @@ bool ntv2_owf_gen(const uint8_t owf[16], } } - user_byte_len = push_ucs2_talloc(mem_ctx, global_smb_iconv_convenience, &user, user_in); + user_byte_len = push_ucs2_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), &user, user_in); if (user_byte_len == (ssize_t)-1) { DEBUG(0, ("push_uss2_talloc() for user returned -1 (probably talloc() failure)\n")); talloc_free(mem_ctx); return false; } - domain_byte_len = push_ucs2_talloc(mem_ctx, global_smb_iconv_convenience, &domain, domain_in); + domain_byte_len = push_ucs2_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), &domain, domain_in); if (domain_byte_len == (ssize_t)-1) { DEBUG(0, ("push_ucs2_talloc() for domain returned -1 (probably talloc() failure)\n")); talloc_free(mem_ctx); @@ -468,7 +469,7 @@ bool encode_pw_buffer(uint8_t buffer[516], const char *password, int string_flag /* the incoming buffer can be any alignment. */ string_flags |= STR_NOALIGN; - new_pw_len = push_string(global_smb_iconv_convenience, new_pw, + new_pw_len = push_string(lp_iconv_convenience(global_loadparm), new_pw, password, sizeof(new_pw), string_flags); @@ -521,7 +522,7 @@ bool decode_pw_buffer(uint8_t in_buffer[516], char *new_pwrd, } /* decode into the return buffer. Buffer length supplied */ - *new_pw_len = pull_string(global_smb_iconv_convenience, new_pwrd, &in_buffer[512 - byte_len], new_pwrd_size, + *new_pw_len = pull_string(lp_iconv_convenience(global_loadparm), new_pwrd, &in_buffer[512 - byte_len], new_pwrd_size, byte_len, string_flags); #ifdef DEBUG_PASSWORD diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c index b9fd06db1a..7ec914e831 100644 --- a/source4/libcli/cliconnect.c +++ b/source4/libcli/cliconnect.c @@ -31,12 +31,12 @@ wrapper around smbcli_sock_connect() */ bool smbcli_socket_connect(struct smbcli_state *cli, const char *server, - const char **name_resolve_order, + const char **ports, struct resolve_context *resolve_ctx, int max_xmit, int max_mux) { struct smbcli_socket *sock; - sock = smbcli_sock_connect_byname(server, 0, NULL, name_resolve_order, + sock = smbcli_sock_connect_byname(server, ports, NULL, resolve_ctx, NULL); if (sock == NULL) return false; @@ -66,7 +66,8 @@ NTSTATUS smbcli_negprot(struct smbcli_state *cli, bool unicode, int maxprotocol) /* wrapper around smb_raw_sesssetup() */ NTSTATUS smbcli_session_setup(struct smbcli_state *cli, - struct cli_credentials *credentials) + struct cli_credentials *credentials, + const char *workgroup) { struct smb_composite_sesssetup setup; NTSTATUS status; @@ -77,7 +78,7 @@ NTSTATUS smbcli_session_setup(struct smbcli_state *cli, setup.in.sesskey = cli->transport->negotiate.sesskey; setup.in.capabilities = cli->transport->negotiate.capabilities; setup.in.credentials = credentials; - setup.in.workgroup = lp_workgroup(global_loadparm); + setup.in.workgroup = workgroup; status = smb_composite_sesssetup(cli->session, &setup); @@ -135,6 +136,7 @@ NTSTATUS smbcli_tconX(struct smbcli_state *cli, const char *sharename, NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_state **ret_cli, const char *host, + const char **ports, const char *sharename, const char *devtype, struct cli_credentials *credentials, @@ -146,7 +148,8 @@ NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx, *ret_cli = NULL; status = smbcli_tree_full_connection(parent_ctx, - &tree, host, 0, sharename, devtype, + &tree, host, ports, + sharename, devtype, credentials, ev); if (!NT_STATUS_IS_OK(status)) { goto done; diff --git a/source4/libcli/config.mk b/source4/libcli/config.mk index 3bfc1478bc..adb51c6c9a 100644 --- a/source4/libcli/config.mk +++ b/source4/libcli/config.mk @@ -17,6 +17,7 @@ OBJ_FILES = util/asn1.o PRIVATE_PROTO_HEADER = util/clilsa.h OBJ_FILES = util/clilsa.o PUBLIC_DEPENDENCIES = RPC_NDR_LSA +PRIVATE_DEPENDENCIES = LIBSECURITY [SUBSYSTEM::LIBCLI_COMPOSITE] PRIVATE_PROTO_HEADER = composite/proto.h @@ -34,7 +35,7 @@ OBJ_FILES = \ smb_composite/fetchfile.o \ smb_composite/appendacl.o \ smb_composite/fsinfo.o -PUBLIC_DEPENDENCIES = LIBCLI_COMPOSITE CREDENTIALS gensec +PUBLIC_DEPENDENCIES = LIBCLI_COMPOSITE CREDENTIALS gensec LIBCLI_RESOLVE [SUBSYSTEM::NDR_NBT_BUF] PRIVATE_PROTO_HEADER = nbt/nbtname.h @@ -73,7 +74,7 @@ OBJ_FILES = \ dgram/netlogon.o \ dgram/ntlogon.o \ dgram/browse.o -PUBLIC_DEPENDENCIES = LIBCLI_NBT +PUBLIC_DEPENDENCIES = LIBCLI_NBT LIBNDR LIBCLI_RESOLVE [LIBRARY::LIBCLI_CLDAP] VERSION = 0.0.1 @@ -91,18 +92,24 @@ SO_VERSION = 0 DESCRIPTION = WINS Replication client library OBJ_FILES = \ wrepl/winsrepl.o -PUBLIC_DEPENDENCIES = NDR_WINSREPL samba-socket LIBCLI_RESOLVE LIBEVENTS LIBPACKET +PUBLIC_DEPENDENCIES = NDR_WINSREPL samba-socket LIBCLI_RESOLVE LIBEVENTS \ + LIBPACKET LIBNDR [SUBSYSTEM::LIBCLI_RESOLVE] PRIVATE_PROTO_HEADER = resolve/proto.h OBJ_FILES = \ - resolve/resolve.o \ + resolve/resolve.o +PUBLIC_DEPENDENCIES = NDR_NBT + +[SUBSYSTEM::LP_RESOLVE] +PRIVATE_PROTO_HEADER = resolve/lp_proto.h +OBJ_FILES = \ resolve/bcast.o \ resolve/nbtlist.o \ resolve/wins.o \ - resolve/host.o -PUBLIC_DEPENDENCIES = LIBNETIF -PRIVATE_DEPENDENCIES = LIBCLI_NBT + resolve/host.o \ + resolve/resolve_lp.o +PRIVATE_DEPENDENCIES = LIBCLI_NBT LIBSAMBA-CONFIG LIBNETIF [SUBSYSTEM::LIBCLI_FINDDCS] PRIVATE_PROTO_HEADER = finddcs.h @@ -129,9 +136,9 @@ PUBLIC_DEPENDENCIES = LIBCLI_RAW LIBSAMBA-ERRORS LIBCLI_AUTH \ [SUBSYSTEM::LIBCLI_RAW] PRIVATE_PROTO_HEADER = raw/raw_proto.h -PRIVATE_DEPENDENCIES = LIBCLI_COMPOSITE -PUBLIC_DEPENDENCIES = samba-socket LIBPACKET gensec LIBCRYPTO +PRIVATE_DEPENDENCIES = LIBCLI_COMPOSITE LP_RESOLVE gensec LIBCLI_RESOLVE LIBSECURITY LIBNDR LDFLAGS = $(SUBSYSTEM_LIBCLI_SMB_COMPOSITE_OUTPUT) +PUBLIC_DEPENDENCIES = samba-socket LIBPACKET gensec LIBCRYPTO CREDENTIALS OBJ_FILES = raw/rawfile.o \ raw/smb_signing.o \ raw/clisocket.o \ diff --git a/source4/libcli/finddcs.c b/source4/libcli/finddcs.c index 83bf9837f9..606809751e 100644 --- a/source4/libcli/finddcs.c +++ b/source4/libcli/finddcs.c @@ -28,7 +28,6 @@ #include "libcli/libcli.h" #include "libcli/resolve/resolve.h" #include "libcli/finddcs.h" -#include "param/param.h" struct finddcs_state { struct composite_context *ctx; @@ -43,6 +42,7 @@ struct finddcs_state { int num_dcs; struct nbt_dc_name *dcs; + uint16_t nbt_port; }; static void finddcs_name_resolved(struct composite_context *ctx); @@ -62,10 +62,11 @@ static void fallback_node_status_replied(struct nbt_name_request *name_req); struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx, const char *my_netbios_name, + uint16_t nbt_port, const char *domain_name, int name_type, struct dom_sid *domain_sid, - const char **methods, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct messaging_context *msg_ctx) { @@ -82,6 +83,7 @@ struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx, state->ctx = c; + state->nbt_port = nbt_port; state->my_netbios_name = talloc_strdup(state, my_netbios_name); state->domain_name = talloc_strdup(state, domain_name); if (composite_nomem(state->domain_name, c)) return c; @@ -96,7 +98,7 @@ struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx, state->msg_ctx = msg_ctx; make_nbt_name(&name, state->domain_name, name_type); - creq = resolve_name_send(&name, event_ctx, methods); + creq = resolve_name_send(resolve_ctx, &name, event_ctx); composite_continue(c, creq, finddcs_name_resolved, state); return c; } @@ -177,7 +179,7 @@ static void finddcs_getdc_replied(struct irpc_request *ireq) composite_done(state->ctx); } -/* The GetDC request might not be availible (such as occours when the +/* The GetDC request might not be available (such as occours when the * NBT server is down). Fallback to a node status. It is the best * hope we have... */ static void fallback_node_status(struct finddcs_state *state) @@ -189,6 +191,7 @@ static void fallback_node_status(struct finddcs_state *state) state->node_status.in.name.type = NBT_NAME_CLIENT; state->node_status.in.name.scope = NULL; state->node_status.in.dest_addr = state->dcs[0].address; + state->node_status.in.dest_port = state->nbt_port; state->node_status.in.timeout = 1; state->node_status.in.retries = 2; @@ -247,17 +250,19 @@ NTSTATUS finddcs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, NTSTATUS finddcs(TALLOC_CTX *mem_ctx, const char *my_netbios_name, + uint16_t nbt_port, const char *domain_name, int name_type, struct dom_sid *domain_sid, - const char **methods, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct messaging_context *msg_ctx, int *num_dcs, struct nbt_dc_name **dcs) { struct composite_context *c = finddcs_send(mem_ctx, my_netbios_name, + nbt_port, domain_name, name_type, - domain_sid, methods, + domain_sid, resolve_ctx, event_ctx, msg_ctx); return finddcs_recv(c, mem_ctx, num_dcs, dcs); } diff --git a/source4/libcli/ldap/config.mk b/source4/libcli/ldap/config.mk index 444306b328..239ee1f161 100644 --- a/source4/libcli/ldap/config.mk +++ b/source4/libcli/ldap/config.mk @@ -9,7 +9,7 @@ OBJ_FILES = ldap.o \ ldap_controls.o PUBLIC_DEPENDENCIES = LIBSAMBA-ERRORS LIBEVENTS LIBPACKET PRIVATE_DEPENDENCIES = LIBCLI_COMPOSITE samba-socket NDR_SAMR LIBTLS ASN1_UTIL \ - LDAP_ENCODE LIBNDR + LDAP_ENCODE LIBNDR LP_RESOLVE gensec [SUBSYSTEM::LDAP_ENCODE] diff --git a/source4/libcli/ldap/ldap_bind.c b/source4/libcli/ldap/ldap_bind.c index bd548be38e..fd15ff2fc7 100644 --- a/source4/libcli/ldap/ldap_bind.c +++ b/source4/libcli/ldap/ldap_bind.c @@ -26,7 +26,6 @@ #include "libcli/ldap/ldap_client.h" #include "lib/tls/tls.h" #include "auth/gensec/gensec.h" -#include "auth/gensec/socket.h" #include "auth/credentials/credentials.h" #include "lib/stream/packet.h" #include "param/param.h" @@ -221,6 +220,8 @@ NTSTATUS ldap_bind_sasl(struct ldap_connection *conn, NULL }; + gensec_init(lp_ctx); + status = gensec_client_start(conn, &conn->gensec, NULL, lp_ctx); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to start GENSEC engine (%s)\n", nt_errstr(status))); diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c index 906e9c2574..6b8a7a3f28 100644 --- a/source4/libcli/ldap/ldap_client.c +++ b/source4/libcli/ldap/ldap_client.c @@ -35,6 +35,7 @@ #include "auth/gensec/gensec.h" #include "system/time.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" /** @@ -355,7 +356,7 @@ struct composite_context *ldap_connect_send(struct ldap_connection *conn, } ctx = socket_connect_send(conn->sock, NULL, unix_addr, - 0, lp_name_resolve_order(conn->lp_ctx), conn->event.event_ctx); + 0, lp_resolve_context(conn->lp_ctx), conn->event.event_ctx); ctx->async.fn = ldap_connect_recv_unix_conn; ctx->async.private_data = state; return result; @@ -368,7 +369,7 @@ struct composite_context *ldap_connect_send(struct ldap_connection *conn, } ctx = socket_connect_multi_send(state, conn->host, 1, &conn->port, - lp_name_resolve_order(conn->lp_ctx), conn->event.event_ctx); + lp_resolve_context(conn->lp_ctx), conn->event.event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = ldap_connect_recv_tcp_conn; diff --git a/source4/libcli/nbt/libnbt.h b/source4/libcli/nbt/libnbt.h index 2f7ce8d1b4..c95d99db54 100644 --- a/source4/libcli/nbt/libnbt.h +++ b/source4/libcli/nbt/libnbt.h @@ -147,6 +147,7 @@ struct nbt_name_status { struct { struct nbt_name name; const char *dest_addr; + uint16_t dest_port; int timeout; /* in seconds */ int retries; } in; @@ -162,6 +163,7 @@ struct nbt_name_register { struct { struct nbt_name name; const char *dest_addr; + uint16_t dest_port; const char *address; uint16_t nb_flags; bool register_demand; @@ -184,6 +186,7 @@ struct nbt_name_register_bcast { struct { struct nbt_name name; const char *dest_addr; + uint16_t dest_port; const char *address; uint16_t nb_flags; uint32_t ttl; @@ -197,6 +200,7 @@ struct nbt_name_register_wins { struct { struct nbt_name name; const char **wins_servers; + uint16_t wins_port; const char **addresses; uint16_t nb_flags; uint32_t ttl; @@ -214,6 +218,7 @@ struct nbt_name_refresh { struct { struct nbt_name name; const char *dest_addr; + uint16_t dest_port; const char *address; uint16_t nb_flags; bool broadcast; @@ -235,6 +240,7 @@ struct nbt_name_refresh_wins { struct { struct nbt_name name; const char **wins_servers; + uint16_t wins_port; const char **addresses; uint16_t nb_flags; uint32_t ttl; @@ -251,6 +257,7 @@ struct nbt_name_release { struct { struct nbt_name name; const char *dest_addr; + uint16_t dest_port; const char *address; uint16_t nb_flags; bool broadcast; diff --git a/source4/libcli/nbt/namequery.c b/source4/libcli/nbt/namequery.c index 6bc6878194..e3432bfda1 100644 --- a/source4/libcli/nbt/namequery.c +++ b/source4/libcli/nbt/namequery.c @@ -158,7 +158,7 @@ _PUBLIC_ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *n packet->questions[0].question_class = NBT_QCLASS_IP; dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, - io->in.dest_addr, lp_nbt_port(global_loadparm)); + io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, io->in.timeout, io->in.retries, false); diff --git a/source4/libcli/nbt/namerefresh.c b/source4/libcli/nbt/namerefresh.c index d723eed9f5..1157c110a1 100644 --- a/source4/libcli/nbt/namerefresh.c +++ b/source4/libcli/nbt/namerefresh.c @@ -69,7 +69,7 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock, dest = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name, - io->in.dest_addr, lp_nbt_port(global_loadparm)); + io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, io->in.timeout, io->in.retries, false); @@ -137,7 +137,7 @@ NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock, -/* +/** a wins name refresh with multiple WINS servers and multiple addresses to refresh. Try each WINS server in turn, until we get a reply for each address @@ -146,13 +146,14 @@ struct refresh_wins_state { struct nbt_name_socket *nbtsock; struct nbt_name_refresh *io; const char **wins_servers; + uint16_t wins_port; const char **addresses; int address_idx; struct nbt_name_request *req; }; -/* +/** state handler for WINS multi-homed multi-server name refresh */ static void name_refresh_wins_handler(struct nbt_name_request *req) @@ -174,6 +175,7 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) goto done; } state->io->in.dest_addr = state->wins_servers[0]; + state->io->in.dest_port = state->wins_port; state->io->in.address = state->addresses[0]; state->req = nbt_name_refresh_send(state->nbtsock, state->io); if (state->req == NULL) { @@ -212,7 +214,7 @@ done: } } -/* +/** the async send call for a multi-server WINS refresh */ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbtsock, @@ -230,6 +232,7 @@ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbt state->io = talloc(state, struct nbt_name_refresh); if (state->io == NULL) goto failed; + state->wins_port = io->in.wins_port; state->wins_servers = str_list_copy(state, io->in.wins_servers); if (state->wins_servers == NULL || state->wins_servers[0] == NULL) goto failed; @@ -240,6 +243,7 @@ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbt state->io->in.name = io->in.name; state->io->in.dest_addr = state->wins_servers[0]; + state->io->in.dest_port = state->wins_port; state->io->in.address = io->in.addresses[0]; state->io->in.nb_flags = io->in.nb_flags; state->io->in.broadcast = false; diff --git a/source4/libcli/nbt/nameregister.c b/source4/libcli/nbt/nameregister.c index fd4a94dd44..6667564664 100644 --- a/source4/libcli/nbt/nameregister.c +++ b/source4/libcli/nbt/nameregister.c @@ -77,7 +77,7 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock, if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed; dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, - io->in.dest_addr, lp_nbt_port(global_loadparm)); + io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, io->in.timeout, io->in.retries, false); @@ -224,6 +224,7 @@ struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *n state->io->in.name = io->in.name; state->io->in.dest_addr = io->in.dest_addr; + state->io->in.dest_port = io->in.dest_port; state->io->in.address = io->in.address; state->io->in.nb_flags = io->in.nb_flags; state->io->in.register_demand = false; @@ -283,6 +284,7 @@ struct register_wins_state { struct nbt_name_socket *nbtsock; struct nbt_name_register *io; const char **wins_servers; + uint16_t wins_port; const char **addresses; int address_idx; struct nbt_name_request *req; @@ -311,6 +313,7 @@ static void name_register_wins_handler(struct nbt_name_request *req) goto done; } state->io->in.dest_addr = state->wins_servers[0]; + state->io->in.dest_port = state->wins_port; state->io->in.address = state->addresses[0]; state->req = nbt_name_register_send(state->nbtsock, state->io); if (state->req == NULL) { @@ -367,6 +370,7 @@ struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nb state->io = talloc(state, struct nbt_name_register); if (state->io == NULL) goto failed; + state->wins_port = io->in.wins_port; state->wins_servers = str_list_copy(state, io->in.wins_servers); if (state->wins_servers == NULL || state->wins_servers[0] == NULL) goto failed; @@ -377,6 +381,7 @@ struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nb state->io->in.name = io->in.name; state->io->in.dest_addr = state->wins_servers[0]; + state->io->in.dest_port = state->wins_port; state->io->in.address = io->in.addresses[0]; state->io->in.nb_flags = io->in.nb_flags; state->io->in.broadcast = false; diff --git a/source4/libcli/nbt/namerelease.c b/source4/libcli/nbt/namerelease.c index 1b3c9ae17e..d735892516 100644 --- a/source4/libcli/nbt/namerelease.c +++ b/source4/libcli/nbt/namerelease.c @@ -67,7 +67,7 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock, talloc_strdup(packet->additional, io->in.address); dest = socket_address_from_strings(packet, nbtsock->sock->backend_name, - io->in.dest_addr, lp_nbt_port(global_loadparm)); + io->in.dest_addr, io->in.dest_port); if (dest == NULL) goto failed; req = nbt_name_request_send(nbtsock, dest, packet, io->in.timeout, io->in.retries, false); diff --git a/source4/libcli/nbt/nbtsocket.c b/source4/libcli/nbt/nbtsocket.c index 1f34b4583b..743f2b0f19 100644 --- a/source4/libcli/nbt/nbtsocket.c +++ b/source4/libcli/nbt/nbtsocket.c @@ -150,7 +150,7 @@ static void nbt_name_socket_timeout(struct event_context *ev, struct timed_event -/* +/** handle recv events on a nbt name socket */ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9b744dcc18..9732ab1638 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -45,12 +45,13 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx); struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, const char *host_addr, - int port, + const char **ports, const char *host_name, struct event_context *event_ctx) { struct composite_context *result, *ctx; struct sock_connect_state *state; + int i; result = talloc_zero(mem_ctx, struct composite_context); if (result == NULL) goto failed; @@ -72,31 +73,16 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, state->host_name = talloc_strdup(state, host_name); if (state->host_name == NULL) goto failed; - if (port == 0) { - const char **ports = lp_smb_ports(global_loadparm); - int i; - - for (i=0;ports[i];i++) /* noop */ ; - if (i == 0) { - DEBUG(3, ("no smb ports defined\n")); - goto failed; - } - state->num_ports = i; - state->ports = talloc_array(state, uint16_t, i); - if (state->ports == NULL) goto failed; - for (i=0;ports[i];i++) { - state->ports[i] = atoi(ports[i]); - } - } else { - state->ports = talloc_array(state, uint16_t, 1); - if (state->ports == NULL) goto failed; - state->num_ports = 1; - state->ports[0] = port; + state->num_ports = str_list_length(ports); + state->ports = talloc_array(state, uint16_t, state->num_ports); + if (state->ports == NULL) goto failed; + for (i=0;ports[i];i++) { + state->ports[i] = atoi(ports[i]); } ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, - lp_name_resolve_order(global_loadparm), + lp_resolve_context(global_loadparm), state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; @@ -164,13 +150,13 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, sync version of the function */ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, - const char *host_addr, int port, + const char *host_addr, const char **ports, const char *host_name, struct event_context *event_ctx, struct smbcli_socket **result) { struct composite_context *c = - smbcli_sock_connect_send(mem_ctx, host_addr, port, host_name, + smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name, event_ctx); return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -198,9 +184,9 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, TALLOC_CTX *mem_ctx, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; @@ -241,13 +227,13 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, name_resolve_order); + status = resolve_name(resolve_ctx, &nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; } - status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, + status = smbcli_sock_connect(mem_ctx, address, ports, name, event_ctx, &result); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 54f8ac95a4..890d5470da 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -171,7 +171,7 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) */ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_tree **ret_tree, - const char *dest_host, int port, + const char *dest_host, const char **dest_ports, const char *service, const char *service_type, struct cli_credentials *credentials, struct event_context *ev) @@ -184,7 +184,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, } io.in.dest_host = dest_host; - io.in.port = port; + io.in.dest_ports = dest_ports; io.in.called_name = strupper_talloc(tmp_ctx, dest_host); io.in.service = service; io.in.service_type = service_type; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index a11a9c9e58..6c97e61f04 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -30,6 +30,7 @@ struct smbcli_request; /* forward declare */ struct smbcli_session; /* forward declare */ struct smbcli_transport; /* forward declare */ +struct resolve_context; struct cli_credentials; /* default timeout for all smb requests */ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 0f2fdb60af..9d2068f35f 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "librpc/gen_ndr/ndr_security.h" +#include "param/param.h" /**************************************************************************** fetch file ACL (async send) @@ -76,7 +77,8 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, nt.out.data.length = IVAL(nt.out.params.data, 0); - ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx); + ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, + lp_iconv_convenience(global_loadparm)); if (!ndr) { return NT_STATUS_INVALID_PARAMETER; } @@ -134,7 +136,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.params.data = params; nt.in.params.length = 8; - ndr = ndr_push_init_ctx(NULL); + ndr = ndr_push_init_ctx(NULL, lp_iconv_convenience(global_loadparm)); if (!ndr) return NULL; ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 972ae7f5e1..9827217a04 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "librpc/gen_ndr/ndr_security.h" +#include "param/param.h" /* local macros to make the code more readable */ #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ @@ -62,7 +63,7 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, return NT_STATUS_INFO_LENGTH_MISMATCH; } size = convert_string_talloc(io->streams, - global_smb_iconv_convenience, + lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, blob.data+ofs+24, nlen, &vstr); if (size == -1) { diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 43c984721b..e7dffaf054 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -26,6 +26,7 @@ #include "libcli/raw/libcliraw.h" #include "lib/util/dlinklist.h" #include "lib/events/events.h" +#include "param/param.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 0 @@ -418,7 +419,7 @@ size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uin smbcli_req_grow_allocation(req, len + req->out.data_size); - len = push_string(global_smb_iconv_convenience, req->out.data + req->out.data_size, str, len, flags); + len = push_string(lp_iconv_convenience(global_loadparm), req->out.data + req->out.data_size, str, len, flags); smbcli_req_grow_data(req, len + req->out.data_size); @@ -574,7 +575,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c return 0; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; return 0; @@ -616,7 +617,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; @@ -769,7 +770,7 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 = utf16_len_n(src, src_len); - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; return 0; @@ -815,7 +816,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; @@ -965,7 +966,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return 0; } - len = push_string(global_smb_iconv_convenience, blob->data + blob->length, str, max_len, flags); + len = push_string(lp_iconv_convenience(global_loadparm), blob->data + blob->length, str, max_len, flags); blob->length += len; diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index ad574e4c9e..c8d4ab2df3 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -4,6 +4,7 @@ broadcast name resolution module Copyright (C) Andrew Tridgell 2005 + Copyright (C) Jelmer Vernooij 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,23 +26,32 @@ #include "lib/socket/netif.h" #include "param/param.h" +struct resolve_bcast_data { + struct interface *ifaces; + uint16_t nbt_port; +}; + /** broadcast name resolution method - async send */ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *userdata, struct nbt_name *name) { - int num_interfaces = iface_count(global_loadparm); + int num_interfaces; const char **address_list; struct composite_context *c; int i, count=0; + struct resolve_bcast_data *data = talloc_get_type(userdata, struct resolve_bcast_data); + + num_interfaces = iface_count(data->ifaces); address_list = talloc_array(mem_ctx, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;i<num_interfaces;i++) { - const char *bcast = iface_n_bcast(global_loadparm, i); + const char *bcast = iface_n_bcast(data->ifaces, i); if (bcast == NULL) continue; address_list[count] = talloc_strdup(address_list, bcast); if (address_list[count] == NULL) { @@ -52,7 +62,7 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, } address_list[count] = NULL; - c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, true, false); + c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, data->ifaces, data->nbt_port, true, false); talloc_free(address_list); return c; @@ -72,9 +82,30 @@ NTSTATUS resolve_name_bcast_recv(struct composite_context *c, */ NTSTATUS resolve_name_bcast(struct nbt_name *name, TALLOC_CTX *mem_ctx, + struct interface *ifaces, + uint16_t nbt_port, const char **reply_addr) { - struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, name); + struct resolve_bcast_data *data = talloc(mem_ctx, struct resolve_bcast_data); + struct composite_context *c; + data->ifaces = talloc_reference(data, ifaces); + data->nbt_port = nbt_port; + + c = resolve_name_bcast_send(mem_ctx, NULL, data, name); return resolve_name_bcast_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interface *ifaces, uint16_t nbt_port) +{ + struct resolve_bcast_data *data = talloc(ctx, struct resolve_bcast_data); + data->ifaces = ifaces; + data->nbt_port = nbt_port; + return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, data); +} + +bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) +{ + struct interface *ifaces; + load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); + return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx)); +} diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index e98bbc51b2..4b8f3f9553 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -34,6 +34,7 @@ #include "system/filesys.h" #include "libcli/composite/composite.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "libcli/resolve/resolve.h" struct host_state { struct nbt_name name; @@ -123,6 +124,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, */ struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *privdata, struct nbt_name *name) { struct composite_context *c; @@ -213,7 +215,12 @@ NTSTATUS resolve_name_host(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr) { - struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, name); + struct composite_context *c = resolve_name_host_send(mem_ctx, NULL, NULL, name); return resolve_name_host_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_host_method(struct resolve_context *ctx) +{ + return resolve_context_add_method(ctx, resolve_name_host_send, resolve_name_host_recv, + NULL); +} diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index daa602f97c..e1452c09d2 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -38,6 +38,7 @@ struct nbtlist_state { struct nbt_name_request **queries; struct nbt_name_query *io_queries; const char *reply_addr; + struct interface *ifaces; }; /* @@ -77,7 +78,7 @@ static void nbtlist_handler(struct nbt_name_request *req) /* favor a local address if possible */ state->reply_addr = NULL; for (i=0;i<q->out.num_addrs;i++) { - if (iface_is_local(global_loadparm, q->out.reply_addrs[i])) { + if (iface_is_local(state->ifaces, q->out.reply_addrs[i])) { state->reply_addr = talloc_steal(state, q->out.reply_addrs[i]); break; @@ -99,6 +100,8 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, struct nbt_name *name, const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, bool broadcast, bool wins_lookup) { @@ -126,6 +129,8 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, if (composite_nomem(state->name.scope, c)) return c; } + state->ifaces = talloc_reference(state, ifaces); + /* * we can't push long names on the wire, * so bail out here to give a useful error message @@ -151,7 +156,7 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx, for (i=0;i<state->num_queries;i++) { state->io_queries[i].in.name = state->name; state->io_queries[i].in.dest_addr = talloc_strdup(state->io_queries, address_list[i]); - state->io_queries[i].in.dest_port = lp_nbt_port(global_loadparm); + state->io_queries[i].in.dest_port = nbt_port; if (composite_nomem(state->io_queries[i].in.dest_addr, c)) return c; state->io_queries[i].in.broadcast = broadcast; @@ -194,10 +199,14 @@ NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c, NTSTATUS resolve_name_nbtlist(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, bool broadcast, bool wins_lookup, const char **reply_addr) { - struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, name, address_list, + struct composite_context *c = resolve_name_nbtlist_send(mem_ctx, NULL, + name, address_list, + ifaces, nbt_port, broadcast, wins_lookup); return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr); } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index 0f8839a3b7..33ace09443 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -4,6 +4,7 @@ general name resolution interface Copyright (C) Andrew Tridgell 2005 + Copyright (C) Jelmer Vernooij 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,57 +27,67 @@ #include "librpc/gen_ndr/ndr_nbt.h" #include "param/param.h" #include "system/network.h" +#include "util/dlinklist.h" struct resolve_state { + struct resolve_context *ctx; + struct resolve_method *method; struct nbt_name name; - const char **methods; struct composite_context *creq; const char *reply_addr; }; static struct composite_context *setup_next_method(struct composite_context *c); -/* pointers to the resolver backends */ -static const struct resolve_method { - const char *name; - struct composite_context *(*send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, struct nbt_name *); - NTSTATUS (*recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); -} resolve_methods[] = { - { "bcast", resolve_name_bcast_send, resolve_name_bcast_recv }, - { "wins", resolve_name_wins_send, resolve_name_wins_recv }, - { "host", resolve_name_host_send, resolve_name_host_recv } +struct resolve_context { + struct resolve_method { + resolve_name_send_fn send_fn; + resolve_name_recv_fn recv_fn; + void *privdata; + struct resolve_method *prev, *next; + } *methods; }; +/** + * Initialize a resolve context + */ +struct resolve_context *resolve_context_init(TALLOC_CTX *mem_ctx) +{ + return talloc_zero(mem_ctx, struct resolve_context); +} -/* - find a matching backend -*/ -static const struct resolve_method *find_method(const char *name) +/** + * Add a resolve method + */ +bool resolve_context_add_method(struct resolve_context *ctx, resolve_name_send_fn send_fn, + resolve_name_recv_fn recv_fn, void *userdata) { - int i; - if (name == NULL) return NULL; - for (i=0;i<ARRAY_SIZE(resolve_methods);i++) { - if (strcasecmp(name, resolve_methods[i].name) == 0) { - return &resolve_methods[i]; - } - } - return NULL; + struct resolve_method *method = talloc_zero(ctx, struct resolve_method); + + if (method == NULL) + return false; + + method->send_fn = send_fn; + method->recv_fn = recv_fn; + method->privdata = userdata; + DLIST_ADD_END(ctx->methods, method, struct resolve_method *); + return true; } -/* +/** handle completion of one name resolve method */ static void resolve_handler(struct composite_context *creq) { struct composite_context *c = (struct composite_context *)creq->async.private_data; struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); - const struct resolve_method *method = find_method(state->methods[0]); + const struct resolve_method *method = state->method; c->status = method->recv_fn(creq, state, &state->reply_addr); if (!NT_STATUS_IS_OK(c->status)) { - state->methods++; + state->method = state->method->next; state->creq = setup_next_method(c); if (state->creq != NULL) { return; @@ -100,13 +111,12 @@ static struct composite_context *setup_next_method(struct composite_context *c) struct composite_context *creq = NULL; do { - const struct resolve_method *method = find_method(state->methods[0]); - if (method) { - creq = method->send_fn(c, c->event_ctx, &state->name); + if (state->method) { + creq = state->method->send_fn(c, c->event_ctx, state->method->privdata, &state->name); } - if (creq == NULL && state->methods[0]) state->methods++; + if (creq == NULL && state->method) state->method = state->method->next; - } while (!creq && state->methods[0]); + } while (!creq && state->method); if (creq) { creq->async.fn = resolve_handler; @@ -119,8 +129,9 @@ static struct composite_context *setup_next_method(struct composite_context *c) /* general name resolution - async send */ -struct composite_context *resolve_name_send(struct nbt_name *name, struct event_context *event_ctx, - const char **methods) +struct composite_context *resolve_name_send(struct resolve_context *ctx, + struct nbt_name *name, + struct event_context *event_ctx) { struct composite_context *c; struct resolve_state *state; @@ -128,7 +139,7 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c = composite_create(event_ctx, event_ctx); if (c == NULL) return NULL; - if (methods == NULL) { + if (ctx == NULL) { composite_error(c, NT_STATUS_INVALID_PARAMETER); return c; } @@ -147,8 +158,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ c->status = nbt_name_dup(state, name, &state->name); if (!composite_is_ok(c)) return c; - state->methods = str_list_copy(state, methods); - if (composite_nomem(state->methods, c)) return c; + state->ctx = talloc_reference(state, ctx); + if (composite_nomem(state->ctx, c)) return c; if (is_ipaddress(state->name.name) || strcasecmp(state->name.name, "localhost") == 0) { @@ -159,6 +170,7 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ return c; } + state->method = ctx->methods; state->creq = setup_next_method(c); if (composite_nomem(state->creq, c)) return c; @@ -187,9 +199,9 @@ NTSTATUS resolve_name_recv(struct composite_context *c, /* general name resolution - sync call */ -NTSTATUS resolve_name(struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev, const char **name_resolve_order) +NTSTATUS resolve_name(struct resolve_context *ctx, struct nbt_name *name, TALLOC_CTX *mem_ctx, const char **reply_addr, struct event_context *ev) { - struct composite_context *c = resolve_name_send(name, ev, name_resolve_order); + struct composite_context *c = resolve_name_send(ctx, name, ev); return resolve_name_recv(c, mem_ctx, reply_addr); } @@ -215,3 +227,5 @@ void make_nbt_name_server(struct nbt_name *nbt, const char *name) { make_nbt_name(nbt, name, NBT_NAME_SERVER); } + + diff --git a/source4/libcli/resolve/resolve.h b/source4/libcli/resolve/resolve.h index 72db3839a2..79b91dc836 100644 --- a/source4/libcli/resolve/resolve.h +++ b/source4/libcli/resolve/resolve.h @@ -23,6 +23,10 @@ #define __RESOLVE_H__ #include "libcli/nbt/libnbt.h" +typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx, struct event_context *, void *privdata, struct nbt_name *); +typedef NTSTATUS (*resolve_name_recv_fn)(struct composite_context *, TALLOC_CTX *, const char **); #include "libcli/resolve/proto.h" +struct interface; +#include "libcli/resolve/lp_proto.h" #endif /* __RESOLVE_H__ */ diff --git a/source4/libcli/resolve/resolve_lp.c b/source4/libcli/resolve/resolve_lp.c new file mode 100644 index 0000000000..b41e2b98d8 --- /dev/null +++ b/source4/libcli/resolve/resolve_lp.c @@ -0,0 +1,46 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "libcli/resolve/resolve.h" +#include "param/param.h" + +struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx) +{ + const char **methods = lp_name_resolve_order(lp_ctx); + int i; + struct resolve_context *ret = resolve_context_init(lp_ctx); + + if (ret == NULL) + return NULL; + + for (i = 0; methods != NULL && methods[i] != NULL; i++) { + if (!strcmp(methods[i], "wins")) { + resolve_context_add_wins_method_lp(ret, lp_ctx); + } else if (!strcmp(methods[i], "bcast")) { + resolve_context_add_bcast_method_lp(ret, lp_ctx); + } else if (!strcmp(methods[i], "host")) { + resolve_context_add_host_method(ret); + } else { + DEBUG(0, ("Unknown resolve method '%s'\n", methods[i])); + } + } + + return ret; +} diff --git a/source4/libcli/resolve/testsuite.c b/source4/libcli/resolve/testsuite.c index b87b59b81a..73a8c841bb 100644 --- a/source4/libcli/resolve/testsuite.c +++ b/source4/libcli/resolve/testsuite.c @@ -44,7 +44,7 @@ static bool test_async_resolve(struct torture_context *tctx) host, timelimit); while (timeval_elapsed(&tv) < timelimit) { const char *s; - struct composite_context *c = resolve_name_host_send(mem_ctx, ev, &n); + struct composite_context *c = resolve_name_host_send(mem_ctx, ev, NULL, &n); torture_assert(tctx, c != NULL, "resolve_name_host_send"); torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s), "async resolve failed"); diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 2cbcd5f483..78624ad81a 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -23,18 +23,26 @@ #include "libcli/nbt/libnbt.h" #include "libcli/resolve/resolve.h" #include "param/param.h" +#include "lib/socket/netif.h" -/* +struct resolve_wins_data { + const char **address_list; + struct interface *ifaces; + uint16_t nbt_port; +}; + +/** wins name resolution method - async send */ struct composite_context *resolve_name_wins_send( TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + void *userdata, struct nbt_name *name) { - const char **address_list = lp_wins_server_list(global_loadparm); - if (address_list == NULL) return NULL; - return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, false, true); + struct resolve_wins_data *wins_data = talloc_get_type(userdata, struct resolve_wins_data); + if (wins_data->address_list == NULL) return NULL; + return resolve_name_nbtlist_send(mem_ctx, event_ctx, name, wins_data->address_list, wins_data->ifaces, wins_data->nbt_port, false, true); } /* @@ -51,9 +59,33 @@ NTSTATUS resolve_name_wins_recv(struct composite_context *c, */ NTSTATUS resolve_name_wins(struct nbt_name *name, TALLOC_CTX *mem_ctx, + const char **address_list, + struct interface *ifaces, + uint16_t nbt_port, const char **reply_addr) { - struct composite_context *c = resolve_name_wins_send(mem_ctx, NULL, name); + struct composite_context *c; + struct resolve_wins_data *wins_data = talloc(mem_ctx, struct resolve_wins_data); + wins_data->address_list = address_list; + wins_data->ifaces = ifaces; + wins_data->nbt_port = nbt_port; + c = resolve_name_wins_send(mem_ctx, NULL, wins_data, name); return resolve_name_wins_recv(c, mem_ctx, reply_addr); } +bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port) +{ + struct resolve_wins_data *wins_data = talloc(ctx, struct resolve_wins_data); + wins_data->address_list = str_list_copy(wins_data, address_list); + wins_data->ifaces = talloc_reference(wins_data, ifaces); + wins_data->nbt_port = nbt_port; + return resolve_context_add_method(ctx, resolve_name_wins_send, resolve_name_wins_recv, + wins_data); +} + +bool resolve_context_add_wins_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) +{ + struct interface *ifaces; + load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); + return resolve_context_add_wins_method(ctx, lp_wins_server_list(lp_ctx), ifaces, lp_nbt_port(lp_ctx)); +} diff --git a/source4/libcli/security/config.mk b/source4/libcli/security/config.mk index ff7480c957..8c66df0325 100644 --- a/source4/libcli/security/config.mk +++ b/source4/libcli/security/config.mk @@ -6,7 +6,7 @@ OBJ_FILES = security_token.o \ access_check.o \ privilege.o \ sddl.o -PUBLIC_DEPENDENCIES = NDR_MISC +PUBLIC_DEPENDENCIES = NDR_MISC LIBNDR [PYTHON::swig_security] SWIG_FILE = security.i diff --git a/source4/libcli/security/security.i b/source4/libcli/security/security.i index 1f100b0b8f..7e48251e51 100644 --- a/source4/libcli/security/security.i +++ b/source4/libcli/security/security.i @@ -60,10 +60,11 @@ enum sec_privilege { %rename(SecurityToken) security_token; +%talloctype(security_token); + typedef struct security_token { %extend { security_token(TALLOC_CTX *mem_ctx) { return security_token_initialise(mem_ctx); } - ~security_token() { talloc_free($self); } bool is_sid(const struct dom_sid *sid); bool is_system(); bool is_anonymous(); @@ -75,10 +76,11 @@ typedef struct security_token { } } security_token; +%talloctype(security_descriptor); + typedef struct security_descriptor { %extend { security_descriptor(TALLOC_CTX *mem_ctx) { return security_descriptor_initialise(mem_ctx); } - ~security_descriptor() { talloc_free($self); } NTSTATUS sacl_add(const struct security_ace *ace); NTSTATUS dacl_add(const struct security_ace *ace); NTSTATUS dacl_del(const struct security_ace *ace); @@ -92,12 +94,13 @@ typedef struct security_descriptor { %rename(Sid) dom_sid; +%talloctype(dom_sid); + typedef struct dom_sid { %extend { dom_sid(TALLOC_CTX *mem_ctx, const char *text) { return dom_sid_parse_talloc(mem_ctx, text); } - ~dom_sid() { talloc_free($self); } #ifdef SWIGPYTHON const char *__str__(TALLOC_CTX *mem_ctx) { return dom_sid_string(mem_ctx, $self); diff --git a/source4/libcli/security/security.py b/source4/libcli/security/security.py index 6b69251b4a..10b263b27b 100644 --- a/source4/libcli/security/security.py +++ b/source4/libcli/security/security.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _security import new @@ -48,6 +47,16 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + SEC_PRIV_SECURITY = _security.SEC_PRIV_SECURITY SEC_PRIV_BACKUP = _security.SEC_PRIV_BACKUP SEC_PRIV_RESTORE = _security.SEC_PRIV_RESTORE @@ -72,63 +81,45 @@ SEC_PRIV_ENABLE_DELEGATION = _security.SEC_PRIV_ENABLE_DELEGATION SEC_PRIV_INTERACTIVE_LOGON = _security.SEC_PRIV_INTERACTIVE_LOGON SEC_PRIV_NETWORK_LOGON = _security.SEC_PRIV_NETWORK_LOGON SEC_PRIV_REMOTE_INTERACTIVE_LOGON = _security.SEC_PRIV_REMOTE_INTERACTIVE_LOGON -class SecurityToken(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, SecurityToken, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, SecurityToken, name) +class SecurityToken(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _security.new_SecurityToken(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _security.SecurityToken_swiginit(self,_security.new_SecurityToken(*args, **kwargs)) __swig_destroy__ = _security.delete_SecurityToken - __del__ = lambda self : None; - def is_sid(*args, **kwargs): return _security.SecurityToken_is_sid(*args, **kwargs) - def is_system(*args, **kwargs): return _security.SecurityToken_is_system(*args, **kwargs) - def is_anonymous(*args, **kwargs): return _security.SecurityToken_is_anonymous(*args, **kwargs) - def has_sid(*args, **kwargs): return _security.SecurityToken_has_sid(*args, **kwargs) - def has_builtin_administrators(*args, **kwargs): return _security.SecurityToken_has_builtin_administrators(*args, **kwargs) - def has_nt_authenticated_users(*args, **kwargs): return _security.SecurityToken_has_nt_authenticated_users(*args, **kwargs) - def has_privilege(*args, **kwargs): return _security.SecurityToken_has_privilege(*args, **kwargs) - def set_privilege(*args, **kwargs): return _security.SecurityToken_set_privilege(*args, **kwargs) +SecurityToken.is_sid = new_instancemethod(_security.SecurityToken_is_sid,None,SecurityToken) +SecurityToken.is_system = new_instancemethod(_security.SecurityToken_is_system,None,SecurityToken) +SecurityToken.is_anonymous = new_instancemethod(_security.SecurityToken_is_anonymous,None,SecurityToken) +SecurityToken.has_sid = new_instancemethod(_security.SecurityToken_has_sid,None,SecurityToken) +SecurityToken.has_builtin_administrators = new_instancemethod(_security.SecurityToken_has_builtin_administrators,None,SecurityToken) +SecurityToken.has_nt_authenticated_users = new_instancemethod(_security.SecurityToken_has_nt_authenticated_users,None,SecurityToken) +SecurityToken.has_privilege = new_instancemethod(_security.SecurityToken_has_privilege,None,SecurityToken) +SecurityToken.set_privilege = new_instancemethod(_security.SecurityToken_set_privilege,None,SecurityToken) SecurityToken_swigregister = _security.SecurityToken_swigregister SecurityToken_swigregister(SecurityToken) -class security_descriptor(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, security_descriptor, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, security_descriptor, name) +class security_descriptor(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _security.new_security_descriptor(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _security.security_descriptor_swiginit(self,_security.new_security_descriptor(*args, **kwargs)) __swig_destroy__ = _security.delete_security_descriptor - __del__ = lambda self : None; - def sacl_add(*args, **kwargs): return _security.security_descriptor_sacl_add(*args, **kwargs) - def dacl_add(*args, **kwargs): return _security.security_descriptor_dacl_add(*args, **kwargs) - def dacl_del(*args, **kwargs): return _security.security_descriptor_dacl_del(*args, **kwargs) - def sacl_del(*args, **kwargs): return _security.security_descriptor_sacl_del(*args, **kwargs) - def __eq__(*args, **kwargs): return _security.security_descriptor___eq__(*args, **kwargs) +security_descriptor.sacl_add = new_instancemethod(_security.security_descriptor_sacl_add,None,security_descriptor) +security_descriptor.dacl_add = new_instancemethod(_security.security_descriptor_dacl_add,None,security_descriptor) +security_descriptor.dacl_del = new_instancemethod(_security.security_descriptor_dacl_del,None,security_descriptor) +security_descriptor.sacl_del = new_instancemethod(_security.security_descriptor_sacl_del,None,security_descriptor) +security_descriptor.__eq__ = new_instancemethod(_security.security_descriptor___eq__,None,security_descriptor) security_descriptor_swigregister = _security.security_descriptor_swigregister security_descriptor_swigregister(security_descriptor) -class Sid(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, Sid, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, Sid, name) +class Sid(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _security.new_Sid(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _security.Sid_swiginit(self,_security.new_Sid(*args, **kwargs)) __swig_destroy__ = _security.delete_Sid - __del__ = lambda self : None; - def __str__(*args, **kwargs): return _security.Sid___str__(*args, **kwargs) - def __eq__(*args, **kwargs): return _security.Sid___eq__(*args, **kwargs) +Sid.__str__ = new_instancemethod(_security.Sid___str__,None,Sid) +Sid.__eq__ = new_instancemethod(_security.Sid___eq__,None,Sid) Sid_swigregister = _security.Sid_swigregister Sid_swigregister(Sid) diff --git a/source4/libcli/security/security_wrap.c b/source4/libcli/security/security_wrap.c index b9f9157012..9c572425eb 100644 --- a/source4/libcli/security/security_wrap.c +++ b/source4/libcli/security/security_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2482,6 +2482,19 @@ static swig_module_info swig_module = {swig_types, 14, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _security.so @@ -2516,7 +2529,6 @@ SWIG_From_int (int value) } SWIGINTERN security_token *new_security_token(TALLOC_CTX *mem_ctx){ return security_token_initialise(mem_ctx); } -SWIGINTERN void delete_security_token(security_token *self){ talloc_free(self); } SWIGINTERNINLINE PyObject* SWIG_From_bool (bool value) @@ -2669,6 +2681,7 @@ SWIG_AsVal_int (PyObject * obj, int *val) return res; } +SWIGINTERN void delete_security_token(security_token *self){ talloc_free(self); } SWIGINTERN security_descriptor *new_security_descriptor(TALLOC_CTX *mem_ctx){ return security_descriptor_initialise(mem_ctx); } SWIGINTERN void delete_security_descriptor(security_descriptor *self){ talloc_free(self); } @@ -2742,7 +2755,6 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) SWIGINTERN dom_sid *new_dom_sid(TALLOC_CTX *mem_ctx,char const *text){ return dom_sid_parse_talloc(mem_ctx, text); } -SWIGINTERN void delete_dom_sid(dom_sid *self){ talloc_free(self); } SWIGINTERN char const *dom_sid___str__(dom_sid *self,TALLOC_CTX *mem_ctx){ return dom_sid_string(mem_ctx, self); } @@ -2770,6 +2782,7 @@ SWIG_FromCharPtr(const char *cptr) return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); } +SWIGINTERN void delete_dom_sid(dom_sid *self){ talloc_free(self); } static struct dom_sid *random_sid(TALLOC_CTX *mem_ctx) { @@ -2792,7 +2805,7 @@ SWIGINTERN PyObject *_wrap_new_SecurityToken(PyObject *SWIGUNUSEDPARM(self), PyO { arg1 = NULL; } - if (!PyArg_ParseTuple(args,(char *)":new_SecurityToken")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"new_SecurityToken",0,0,0)) SWIG_fail; result = (security_token *)new_security_token(arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_security_token, SWIG_POINTER_NEW | 0 ); return resultobj; @@ -2801,28 +2814,6 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_SecurityToken(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - security_token *arg1 = (security_token *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_SecurityToken",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_token, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_SecurityToken" "', argument " "1"" of type '" "security_token *""'"); - } - arg1 = (security_token *)(argp1); - delete_security_token(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_SecurityToken_is_sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; security_token *arg1 = (security_token *) 0 ; @@ -2863,10 +2854,11 @@ SWIGINTERN PyObject *_wrap_SecurityToken_is_system(PyObject *SWIGUNUSEDPARM(self bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:SecurityToken_is_system",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_token, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_token, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SecurityToken_is_system" "', argument " "1"" of type '" "security_token *""'"); } @@ -2885,10 +2877,11 @@ SWIGINTERN PyObject *_wrap_SecurityToken_is_anonymous(PyObject *SWIGUNUSEDPARM(s bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:SecurityToken_is_anonymous",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_token, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_token, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SecurityToken_is_anonymous" "', argument " "1"" of type '" "security_token *""'"); } @@ -2941,10 +2934,11 @@ SWIGINTERN PyObject *_wrap_SecurityToken_has_builtin_administrators(PyObject *SW bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:SecurityToken_has_builtin_administrators",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_token, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_token, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SecurityToken_has_builtin_administrators" "', argument " "1"" of type '" "security_token *""'"); } @@ -2963,10 +2957,11 @@ SWIGINTERN PyObject *_wrap_SecurityToken_has_nt_authenticated_users(PyObject *SW bool result; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; - if (!PyArg_ParseTuple(args,(char *)"O:SecurityToken_has_nt_authenticated_users",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_token, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_token, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SecurityToken_has_nt_authenticated_users" "', argument " "1"" of type '" "security_token *""'"); } @@ -3046,13 +3041,40 @@ fail: } +SWIGINTERN PyObject *_wrap_delete_SecurityToken(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + security_token *arg1 = (security_token *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_token, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_SecurityToken" "', argument " "1"" of type '" "security_token *""'"); + } + arg1 = (security_token *)(argp1); + delete_security_token(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *SecurityToken_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_security_token, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *SecurityToken_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_new_security_descriptor(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -3061,7 +3083,7 @@ SWIGINTERN PyObject *_wrap_new_security_descriptor(PyObject *SWIGUNUSEDPARM(self { arg1 = NULL; } - if (!PyArg_ParseTuple(args,(char *)":new_security_descriptor")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"new_security_descriptor",0,0,0)) SWIG_fail; result = (security_descriptor *)new_security_descriptor(arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_security_descriptor, SWIG_POINTER_NEW | 0 ); return resultobj; @@ -3070,28 +3092,6 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_security_descriptor(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - security_descriptor *arg1 = (security_descriptor *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_security_descriptor",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_security_descriptor, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_security_descriptor" "', argument " "1"" of type '" "security_descriptor *""'"); - } - arg1 = (security_descriptor *)(argp1); - delete_security_descriptor(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_security_descriptor_sacl_add(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; security_descriptor *arg1 = (security_descriptor *) 0 ; @@ -3290,13 +3290,40 @@ fail: } +SWIGINTERN PyObject *_wrap_delete_security_descriptor(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + security_descriptor *arg1 = (security_descriptor *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_security_descriptor, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_security_descriptor" "', argument " "1"" of type '" "security_descriptor *""'"); + } + arg1 = (security_descriptor *)(argp1); + delete_security_descriptor(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *security_descriptor_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_security_descriptor, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *security_descriptor_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_new_Sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -3329,28 +3356,6 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_Sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - dom_sid *arg1 = (dom_sid *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - - if (!PyArg_ParseTuple(args,(char *)"O:delete_Sid",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_dom_sid, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Sid" "', argument " "1"" of type '" "dom_sid *""'"); - } - arg1 = (dom_sid *)(argp1); - delete_dom_sid(arg1); - - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - SWIGINTERN PyObject *_wrap_Sid___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; dom_sid *arg1 = (dom_sid *) 0 ; @@ -3358,13 +3363,14 @@ SWIGINTERN PyObject *_wrap_Sid___str__(PyObject *SWIGUNUSEDPARM(self), PyObject char *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; - PyObject * obj0 = 0 ; + PyObject *swig_obj[1] ; { arg2 = NULL; } - if (!PyArg_ParseTuple(args,(char *)"O:Sid___str__",&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_dom_sid, 0 | 0 ); + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_dom_sid, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Sid___str__" "', argument " "1"" of type '" "dom_sid *""'"); } @@ -3411,13 +3417,40 @@ fail: } +SWIGINTERN PyObject *_wrap_delete_Sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + dom_sid *arg1 = (dom_sid *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_dom_sid, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Sid" "', argument " "1"" of type '" "dom_sid *""'"); + } + arg1 = (dom_sid *)(argp1); + delete_dom_sid(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *Sid_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_dom_sid, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Sid_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_random_sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -3426,7 +3459,7 @@ SWIGINTERN PyObject *_wrap_random_sid(PyObject *SWIGUNUSEDPARM(self), PyObject * { arg1 = NULL; } - if (!PyArg_ParseTuple(args,(char *)":random_sid")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"random_sid",0,0,0)) SWIG_fail; result = (struct dom_sid *)random_sid(arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_dom_sid, 0 | 0 ); return resultobj; @@ -3489,31 +3522,34 @@ fail: static PyMethodDef SwigMethods[] = { - { (char *)"new_SecurityToken", _wrap_new_SecurityToken, METH_VARARGS, NULL}, - { (char *)"delete_SecurityToken", _wrap_delete_SecurityToken, METH_VARARGS, NULL}, + { (char *)"new_SecurityToken", (PyCFunction)_wrap_new_SecurityToken, METH_NOARGS, NULL}, { (char *)"SecurityToken_is_sid", (PyCFunction) _wrap_SecurityToken_is_sid, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"SecurityToken_is_system", _wrap_SecurityToken_is_system, METH_VARARGS, NULL}, - { (char *)"SecurityToken_is_anonymous", _wrap_SecurityToken_is_anonymous, METH_VARARGS, NULL}, + { (char *)"SecurityToken_is_system", (PyCFunction)_wrap_SecurityToken_is_system, METH_O, NULL}, + { (char *)"SecurityToken_is_anonymous", (PyCFunction)_wrap_SecurityToken_is_anonymous, METH_O, NULL}, { (char *)"SecurityToken_has_sid", (PyCFunction) _wrap_SecurityToken_has_sid, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"SecurityToken_has_builtin_administrators", _wrap_SecurityToken_has_builtin_administrators, METH_VARARGS, NULL}, - { (char *)"SecurityToken_has_nt_authenticated_users", _wrap_SecurityToken_has_nt_authenticated_users, METH_VARARGS, NULL}, + { (char *)"SecurityToken_has_builtin_administrators", (PyCFunction)_wrap_SecurityToken_has_builtin_administrators, METH_O, NULL}, + { (char *)"SecurityToken_has_nt_authenticated_users", (PyCFunction)_wrap_SecurityToken_has_nt_authenticated_users, METH_O, NULL}, { (char *)"SecurityToken_has_privilege", (PyCFunction) _wrap_SecurityToken_has_privilege, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"SecurityToken_set_privilege", (PyCFunction) _wrap_SecurityToken_set_privilege, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_SecurityToken", (PyCFunction)_wrap_delete_SecurityToken, METH_O, NULL}, { (char *)"SecurityToken_swigregister", SecurityToken_swigregister, METH_VARARGS, NULL}, - { (char *)"new_security_descriptor", _wrap_new_security_descriptor, METH_VARARGS, NULL}, - { (char *)"delete_security_descriptor", _wrap_delete_security_descriptor, METH_VARARGS, NULL}, + { (char *)"SecurityToken_swiginit", SecurityToken_swiginit, METH_VARARGS, NULL}, + { (char *)"new_security_descriptor", (PyCFunction)_wrap_new_security_descriptor, METH_NOARGS, NULL}, { (char *)"security_descriptor_sacl_add", (PyCFunction) _wrap_security_descriptor_sacl_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor_dacl_add", (PyCFunction) _wrap_security_descriptor_dacl_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor_dacl_del", (PyCFunction) _wrap_security_descriptor_dacl_del, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor_sacl_del", (PyCFunction) _wrap_security_descriptor_sacl_del, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor___eq__", (PyCFunction) _wrap_security_descriptor___eq__, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_security_descriptor", (PyCFunction)_wrap_delete_security_descriptor, METH_O, NULL}, { (char *)"security_descriptor_swigregister", security_descriptor_swigregister, METH_VARARGS, NULL}, + { (char *)"security_descriptor_swiginit", security_descriptor_swiginit, METH_VARARGS, NULL}, { (char *)"new_Sid", (PyCFunction) _wrap_new_Sid, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_Sid", _wrap_delete_Sid, METH_VARARGS, NULL}, - { (char *)"Sid___str__", _wrap_Sid___str__, METH_VARARGS, NULL}, + { (char *)"Sid___str__", (PyCFunction)_wrap_Sid___str__, METH_O, NULL}, { (char *)"Sid___eq__", (PyCFunction) _wrap_Sid___eq__, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_Sid", (PyCFunction)_wrap_delete_Sid, METH_O, NULL}, { (char *)"Sid_swigregister", Sid_swigregister, METH_VARARGS, NULL}, - { (char *)"random_sid", _wrap_random_sid, METH_VARARGS, NULL}, + { (char *)"Sid_swiginit", Sid_swiginit, METH_VARARGS, NULL}, + { (char *)"random_sid", (PyCFunction)_wrap_random_sid, METH_NOARGS, NULL}, { (char *)"privilege_name", (PyCFunction) _wrap_privilege_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"privilege_id", (PyCFunction) _wrap_privilege_id, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } diff --git a/source4/libcli/smb2/connect.c b/source4/libcli/smb2/connect.c index 39bb992d11..4d250fdded 100644 --- a/source4/libcli/smb2/connect.c +++ b/source4/libcli/smb2/connect.c @@ -147,11 +147,12 @@ static void continue_resolve(struct composite_context *creq) struct smb2_connect_state *state = talloc_get_type(c->private_data, struct smb2_connect_state); const char *addr; - + const char *ports[2] = { "445", NULL }; + c->status = resolve_name_recv(creq, state, &addr); if (!composite_is_ok(c)) return; - creq = smbcli_sock_connect_send(state, addr, 445, state->host, c->event_ctx); + creq = smbcli_sock_connect_send(state, addr, ports, state->host, c->event_ctx); composite_continue(c, creq, continue_socket, c); } @@ -163,7 +164,7 @@ static void continue_resolve(struct composite_context *creq) struct composite_context *smb2_connect_send(TALLOC_CTX *mem_ctx, const char *host, const char *share, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct cli_credentials *credentials, struct event_context *ev) { @@ -188,7 +189,7 @@ struct composite_context *smb2_connect_send(TALLOC_CTX *mem_ctx, ZERO_STRUCT(name); name.name = host; - creq = resolve_name_send(&name, c->event_ctx, name_resolve_order); + creq = resolve_name_send(resolve_ctx, &name, c->event_ctx); composite_continue(c, creq, continue_resolve, c); return c; } @@ -215,13 +216,13 @@ NTSTATUS smb2_connect_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, */ NTSTATUS smb2_connect(TALLOC_CTX *mem_ctx, const char *host, const char *share, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct cli_credentials *credentials, struct smb2_tree **tree, struct event_context *ev) { struct composite_context *c = smb2_connect_send(mem_ctx, host, share, - name_resolve_order, + resolve_ctx, credentials, ev); return smb2_connect_recv(c, mem_ctx, tree); } diff --git a/source4/libcli/smb2/request.c b/source4/libcli/smb2/request.c index 5a7534f906..73c74dcfeb 100644 --- a/source4/libcli/smb2/request.c +++ b/source4/libcli/smb2/request.c @@ -26,6 +26,7 @@ #include "lib/util/dlinklist.h" #include "lib/events/events.h" #include "libcli/smb2/smb2_calls.h" +#include "param/param.h" /* initialise a smb2 request @@ -579,7 +580,7 @@ NTSTATUS smb2_pull_o16s16_string(struct smb2_request_buffer *buf, TALLOC_CTX *me return NT_STATUS_OK; } - size = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + size = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, blob.data, blob.length, &vstr); data_blob_free(&blob); (*str) = (char *)vstr; @@ -604,7 +605,7 @@ NTSTATUS smb2_push_o16s16_string(struct smb2_request_buffer *buf, return smb2_push_o16s16_blob(buf, ofs, data_blob(NULL, 0)); } - size = convert_string_talloc(buf->buffer, global_smb_iconv_convenience, CH_UNIX, CH_UTF16, + size = convert_string_talloc(buf->buffer, lp_iconv_convenience(global_loadparm), CH_UNIX, CH_UTF16, str, strlen(str), (void **)&blob.data); if (size == -1) { return NT_STATUS_ILLEGAL_CHARACTER; diff --git a/source4/libcli/smb2/smb2_calls.h b/source4/libcli/smb2/smb2_calls.h index 318a634ac4..6a551da4ae 100644 --- a/source4/libcli/smb2/smb2_calls.h +++ b/source4/libcli/smb2/smb2_calls.h @@ -95,4 +95,5 @@ struct smb2_setinfo { struct cli_credentials; struct event_context; +struct resolve_context; #include "libcli/smb2/smb2_proto.h" diff --git a/source4/libcli/smb_composite/connect.c b/source4/libcli/smb_composite/connect.c index 9579cd20b5..fafd3b0173 100644 --- a/source4/libcli/smb_composite/connect.c +++ b/source4/libcli/smb_composite/connect.c @@ -360,7 +360,8 @@ static NTSTATUS connect_resolve(struct composite_context *c, status = resolve_name_recv(state->creq, state, &address); NT_STATUS_NOT_OK_RETURN(status); - state->creq = smbcli_sock_connect_send(state, address, io->in.port, + state->creq = smbcli_sock_connect_send(state, address, + io->in.dest_ports, io->in.dest_host, c->event_ctx); NT_STATUS_HAVE_NO_MEMORY(state->creq); @@ -463,8 +464,7 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec state->stage = CONNECT_RESOLVE; make_nbt_name_server(&name, io->in.dest_host); - state->creq = resolve_name_send(&name, c->event_ctx, - lp_name_resolve_order(global_loadparm)); + state->creq = resolve_name_send(lp_resolve_context(global_loadparm), &name, c->event_ctx); if (state->creq == NULL) goto failed; state->creq->async.private_data = c; diff --git a/source4/libcli/smb_composite/fetchfile.c b/source4/libcli/smb_composite/fetchfile.c index 2dbaff5a66..a4f73ffd70 100644 --- a/source4/libcli/smb_composite/fetchfile.c +++ b/source4/libcli/smb_composite/fetchfile.c @@ -137,7 +137,7 @@ struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetc state->io = io; state->connect->in.dest_host = io->in.dest_host; - state->connect->in.port = io->in.port; + state->connect->in.dest_ports = io->in.ports; state->connect->in.called_name = io->in.called_name; state->connect->in.service = io->in.service; state->connect->in.service_type = io->in.service_type; diff --git a/source4/libcli/smb_composite/fsinfo.c b/source4/libcli/smb_composite/fsinfo.c index faf3723539..f37213e2f9 100644 --- a/source4/libcli/smb_composite/fsinfo.c +++ b/source4/libcli/smb_composite/fsinfo.c @@ -143,7 +143,7 @@ struct composite_context *smb_composite_fsinfo_send(struct smbcli_tree *tree, if (state->connect == NULL) goto failed; state->connect->in.dest_host = io->in.dest_host; - state->connect->in.port = io->in.port; + state->connect->in.dest_ports = io->in.dest_ports; state->connect->in.called_name = io->in.called_name; state->connect->in.service = io->in.service; state->connect->in.service_type = io->in.service_type; diff --git a/source4/libcli/smb_composite/smb_composite.h b/source4/libcli/smb_composite/smb_composite.h index 617daaf442..a3188c4fe2 100644 --- a/source4/libcli/smb_composite/smb_composite.h +++ b/source4/libcli/smb_composite/smb_composite.h @@ -45,7 +45,7 @@ struct smb_composite_loadfile { struct smb_composite_fetchfile { struct { const char *dest_host; - int port; + const char **ports; const char *called_name; const char *service; const char *service_type; @@ -84,7 +84,7 @@ struct smb_composite_savefile { struct smb_composite_connect { struct { const char *dest_host; - int port; + const char **dest_ports; const char *called_name; const char *service; const char *service_type; @@ -121,7 +121,7 @@ struct smb_composite_sesssetup { struct smb_composite_fsinfo { struct { const char *dest_host; - int port; + const char **dest_ports; const char *called_name; const char *service; const char *service_type; diff --git a/source4/libcli/wrepl/winsrepl.c b/source4/libcli/wrepl/winsrepl.c index 9f7bd91ec9..63b0a60f6c 100644 --- a/source4/libcli/wrepl/winsrepl.c +++ b/source4/libcli/wrepl/winsrepl.c @@ -30,6 +30,7 @@ #include "system/network.h" #include "lib/socket/netif.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status); @@ -312,6 +313,7 @@ static void wrepl_connect_handler(struct composite_context *creq) connect a wrepl_socket to a WINS server */ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket, + struct resolve_context *resolve_ctx, const char *our_ip, const char *peer_ip) { struct composite_context *result; @@ -331,7 +333,9 @@ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket, state->wrepl_socket = wrepl_socket; if (!our_ip) { - our_ip = iface_best_ip(global_loadparm, peer_ip); + struct interface *ifaces; + load_interfaces(state, lp_interfaces(global_loadparm), &ifaces); + our_ip = iface_best_ip(ifaces, peer_ip); } us = socket_address_from_strings(state, wrepl_socket->sock->backend_name, @@ -343,7 +347,7 @@ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket, if (composite_nomem(peer, result)) return result; state->creq = socket_connect_send(wrepl_socket->sock, us, peer, - 0, lp_name_resolve_order(global_loadparm), + 0, resolve_ctx, wrepl_socket->event.ctx); composite_continue(result, state->creq, wrepl_connect_handler, state); return result; @@ -370,9 +374,10 @@ NTSTATUS wrepl_connect_recv(struct composite_context *result) /* connect a wrepl_socket to a WINS server - sync API */ -NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, const char *our_ip, const char *peer_ip) +NTSTATUS wrepl_connect(struct wrepl_socket *wrepl_socket, struct resolve_context *resolve_ctx, + const char *our_ip, const char *peer_ip) { - struct composite_context *c_req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip); + struct composite_context *c_req = wrepl_connect_send(wrepl_socket, resolve_ctx, our_ip, peer_ip); return wrepl_connect_recv(c_req); } diff --git a/source4/libcli/wrepl/winsrepl.h b/source4/libcli/wrepl/winsrepl.h index 8ce8b418a2..52b0bee69e 100644 --- a/source4/libcli/wrepl/winsrepl.h +++ b/source4/libcli/wrepl/winsrepl.h @@ -154,4 +154,6 @@ struct wrepl_pull_names { } out; }; +struct resolve_context; + #include "libcli/wrepl/winsrepl_proto.h" diff --git a/source4/libnet/config.mk b/source4/libnet/config.mk index ef0c7ff6ca..93d6a7251e 100644 --- a/source4/libnet/config.mk +++ b/source4/libnet/config.mk @@ -30,5 +30,4 @@ OBJ_FILES = \ userman.o \ groupman.o \ prereq_domain.o -PUBLIC_DEPENDENCIES = CREDENTIALS dcerpc dcerpc_samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI LIBCLI_COMPOSITE LIBCLI_RESOLVE LIBCLI_FINDDCS LIBSAMBA3 LIBCLI_CLDAP LIBCLI_FINDDCS gensec_schannel -PRIVATE_DEPENDENCIES = CREDENTIALS_KRB5 +PUBLIC_DEPENDENCIES = CREDENTIALS dcerpc dcerpc_samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI LIBCLI_COMPOSITE LIBCLI_RESOLVE LIBCLI_FINDDCS LIBSAMBA3 LIBCLI_CLDAP LIBCLI_FINDDCS gensec_schannel LIBCLI_AUTH LIBNDR diff --git a/source4/libnet/libnet.c b/source4/libnet/libnet.c index 5c483a757c..d1605bc17d 100644 --- a/source4/libnet/libnet.c +++ b/source4/libnet/libnet.c @@ -21,6 +21,7 @@ #include "libnet/libnet.h" #include "lib/events/events.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" struct libnet_context *libnet_context_init(struct event_context *ev, struct loadparm_context *lp_ctx) @@ -45,7 +46,7 @@ struct libnet_context *libnet_context_init(struct event_context *ev, ctx->lp_ctx = lp_ctx; /* name resolution methods */ - ctx->name_res_methods = str_list_copy(ctx, lp_name_resolve_order(lp_ctx)); + ctx->resolve_ctx = lp_resolve_context(lp_ctx); /* connected services' params */ ZERO_STRUCT(ctx->samr); diff --git a/source4/libnet/libnet.h b/source4/libnet/libnet.h index 4f3acc6010..71ee8ef8e4 100644 --- a/source4/libnet/libnet.h +++ b/source4/libnet/libnet.h @@ -47,7 +47,7 @@ struct libnet_context { } lsa; /* name resolution methods */ - const char **name_res_methods; + struct resolve_context *resolve_ctx; struct event_context *event_ctx; diff --git a/source4/libnet/libnet_group.c b/source4/libnet/libnet_group.c index 39e5e7a4f9..c4d44eefe8 100644 --- a/source4/libnet/libnet_group.c +++ b/source4/libnet/libnet_group.c @@ -22,6 +22,10 @@ #include "libnet/libnet.h" #include "libcli/composite/composite.h" #include "librpc/gen_ndr/lsa.h" +#include "librpc/gen_ndr/ndr_lsa_c.h" +#include "librpc/gen_ndr/samr.h" +#include "librpc/gen_ndr/ndr_samr_c.h" +#include "libcli/security/security.h" struct group_info_state { @@ -230,3 +234,249 @@ NTSTATUS libnet_GroupInfo(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, io, NULL); return libnet_GroupInfo_recv(c, mem_ctx, io); } + + +struct grouplist_state { + struct libnet_context *ctx; + const char *domain_name; + struct lsa_DomainInfo dominfo; + int page_size; + uint32_t resume_index; + struct grouplist *groups; + uint32_t count; + + struct libnet_DomainOpen domain_open; + struct lsa_QueryInfoPolicy query_domain; + struct samr_EnumDomainGroups group_list; + + void (*monitor_fn)(struct monitor_msg*); +}; + + +static void continue_lsa_domain_opened(struct composite_context *ctx); +static void continue_domain_queried(struct rpc_request *req); +static void continue_samr_domain_opened(struct composite_context *ctx); +static void continue_domain_queried(struct rpc_request *req); +static void continue_groups_enumerated(struct rpc_request *req); + + +struct composite_context *libnet_GroupList_send(struct libnet_context *ctx, + TALLOC_CTX *mem_ctx, + struct libnet_GroupList *io, + void (*monitor)(struct monitor_msg*)) +{ + struct composite_context *c; + struct grouplist_state *s; + struct rpc_request *query_req; + bool prereq_met = false; + + c = composite_create(mem_ctx, ctx->event_ctx); + if (c == NULL) return NULL; + + s = talloc_zero(c, struct grouplist_state); + if (composite_nomem(s, c)) return c; + + c->private_data = s; + + s->ctx = ctx; + s->page_size = io->in.page_size; + s->resume_index = (uint32_t)io->in.resume_index; + s->domain_name = talloc_strdup(c, io->in.domain_name); + s->monitor_fn = monitor; + + prereq_met = lsa_domain_opened(ctx, s->domain_name, &c, &s->domain_open, + continue_lsa_domain_opened, monitor); + if (!prereq_met) return c; + + s->query_domain.in.handle = &ctx->lsa.handle; + s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN; + + query_req = dcerpc_lsa_QueryInfoPolicy_send(ctx->lsa.pipe, c, &s->query_domain); + if (composite_nomem(query_req, c)) return c; + + composite_continue_rpc(c, query_req, continue_domain_queried, c); + return c; +} + + +static void continue_lsa_domain_opened(struct composite_context *ctx) +{ + struct composite_context *c; + struct grouplist_state *s; + struct rpc_request *query_req; + + c = talloc_get_type(ctx->async.private_data, struct composite_context); + s = talloc_get_type(c->private_data, struct grouplist_state); + + c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open); + if (!composite_is_ok(c)) return; + + s->query_domain.in.handle = &s->ctx->lsa.handle; + s->query_domain.in.level = LSA_POLICY_INFO_DOMAIN; + + query_req = dcerpc_lsa_QueryInfoPolicy_send(s->ctx->lsa.pipe, c, &s->query_domain); + if (composite_nomem(query_req, c)) return; + + composite_continue_rpc(c, query_req, continue_domain_queried, c); +} + + +static void continue_domain_queried(struct rpc_request *req) +{ + struct composite_context *c; + struct grouplist_state *s; + struct rpc_request *enum_req; + bool prereq_met = false; + + c = talloc_get_type(req->async.private_data, struct composite_context); + s = talloc_get_type(c->private_data, struct grouplist_state); + + /* receive result of rpc request */ + c->status = dcerpc_ndr_request_recv(req); + if (!composite_is_ok(c)) return; + + /* get the returned domain info */ + s->dominfo = s->query_domain.out.info->domain; + + /* make sure we have samr domain handle before continuing */ + prereq_met = samr_domain_opened(s->ctx, s->domain_name, &c, &s->domain_open, + continue_samr_domain_opened, s->monitor_fn); + if (!prereq_met) return; + + /* prepare arguments od EnumDomainGroups call */ + s->group_list.in.domain_handle = &s->ctx->samr.handle; + s->group_list.in.max_size = s->page_size; + s->group_list.in.resume_handle = &s->resume_index; + s->group_list.out.resume_handle = &s->resume_index; + + /* send the request */ + enum_req = dcerpc_samr_EnumDomainGroups_send(s->ctx->samr.pipe, c, &s->group_list); + if (composite_nomem(enum_req, c)) return; + + composite_continue_rpc(c, enum_req, continue_groups_enumerated, c); +} + + +static void continue_samr_domain_opened(struct composite_context *ctx) +{ + struct composite_context *c; + struct grouplist_state *s; + struct rpc_request *enum_req; + + c = talloc_get_type(ctx->async.private_data, struct composite_context); + s = talloc_get_type(c->private_data, struct grouplist_state); + + /* receive samr domain handle */ + c->status = libnet_DomainOpen_recv(ctx, s->ctx, c, &s->domain_open); + if (!composite_is_ok(c)) return; + + s->group_list.in.domain_handle = &s->ctx->samr.handle; + s->group_list.in.max_size = s->page_size; + s->group_list.in.resume_handle = &s->resume_index; + s->group_list.out.resume_handle = &s->resume_index; + + enum_req = dcerpc_samr_EnumDomainGroups_send(s->ctx->samr.pipe, c, &s->group_list); + if (composite_nomem(enum_req, c)) return; + + composite_continue_rpc(c, enum_req, continue_groups_enumerated, c); +} + + +static void continue_groups_enumerated(struct rpc_request *req) +{ + struct composite_context *c; + struct grouplist_state *s; + int i; + + c = talloc_get_type(req->async.private_data, struct composite_context); + s = talloc_get_type(c->private_data, struct grouplist_state); + + c->status = dcerpc_ndr_request_recv(req); + if (!composite_is_ok(c)) return; + + c->status = s->group_list.out.result; + + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, STATUS_MORE_ENTRIES) || + NT_STATUS_EQUAL(c->status, NT_STATUS_NO_MORE_ENTRIES)) { + + s->resume_index = *s->group_list.out.resume_handle; + s->count = s->group_list.out.num_entries; + + s->groups = talloc_array(c, struct grouplist, s->group_list.out.sam->count); + if (composite_nomem(s->groups, c)) return; + + for (i = 0; i < s->group_list.out.sam->count; i++) { + struct dom_sid *group_sid; + struct samr_SamEntry *entry = &s->group_list.out.sam->entries[i]; + struct dom_sid *domain_sid = s->query_domain.out.info->domain.sid; + + group_sid = dom_sid_add_rid(c, domain_sid, entry->idx); + if (composite_nomem(group_sid, c)) return; + + s->groups[i].groupname = talloc_strdup(c, entry->name.string); + if (composite_nomem(s->groups[i].groupname, c)) return; + + s->groups[i].sid = dom_sid_string(c, group_sid); + if (composite_nomem(s->groups[i].sid, c)) return; + } + + composite_done(c); + + } else { + composite_error(c, c->status); + } +} + + +NTSTATUS libnet_GroupList_recv(struct composite_context *c, TALLOC_CTX *mem_ctx, + struct libnet_GroupList *io) +{ + NTSTATUS status; + struct grouplist_state *s; + + if (c == NULL || mem_ctx == NULL || io == NULL) { + return NT_STATUS_INVALID_PARAMETER; + } + + status = composite_wait(c); + if (NT_STATUS_IS_OK(status) || + NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) || + NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) { + + s = talloc_get_type(c->private_data, struct grouplist_state); + + io->out.count = s->count; + io->out.resume_index = s->resume_index; + io->out.groups = talloc_steal(mem_ctx, s->groups); + + if (NT_STATUS_IS_OK(status)) { + io->out.error_string = talloc_asprintf(mem_ctx, "Success"); + } else { + io->out.error_string = talloc_asprintf(mem_ctx, "Success (status: %s)", + nt_errstr(status)); + } + + } else { + io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s", nt_errstr(status)); + } + + return status; +} + + +/** + * Gets list of groups + * + * @param ctx initialised libnet context + * @param mem_ctx memory context of this call + * @param r pointer to a structure containing arguments and result of this call + * @return nt status + */ +NTSTATUS libnet_GroupList(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, + struct libnet_GroupList *io) +{ + struct composite_context *c = libnet_GroupList_send(ctx, mem_ctx, + io, NULL); + return libnet_GroupList_recv(c, mem_ctx, io); +} diff --git a/source4/libnet/libnet_group.h b/source4/libnet/libnet_group.h index 7cab1c90e6..aa414a6667 100644 --- a/source4/libnet/libnet_group.h +++ b/source4/libnet/libnet_group.h @@ -32,3 +32,23 @@ struct libnet_GroupInfo { const char *error_string; } out; }; + + +struct libnet_GroupList { + struct { + const char *domain_name; + int page_size; + uint resume_index; + } in; + struct { + int count; + uint resume_index; + + struct grouplist { + const char *sid; + const char *groupname; + } *groups; + + const char *error_string; + } out; +}; diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c index 6d7fcd09ad..8297172a58 100644 --- a/source4/libnet/libnet_join.c +++ b/source4/libnet/libnet_join.c @@ -390,7 +390,7 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J r->out.account_guid = samdb_result_guid(res->msgs[0], "objectGUID"); if (r->in.acct_type == ACB_SVRTRUST) { - status = libnet_JoinSite(remote_ldb, r); + status = libnet_JoinSite(ctx, remote_ldb, r); } talloc_free(tmp_ctx); diff --git a/source4/libnet/libnet_lookup.c b/source4/libnet/libnet_lookup.c index fcb24601e4..409cc7575b 100644 --- a/source4/libnet/libnet_lookup.c +++ b/source4/libnet/libnet_lookup.c @@ -57,7 +57,7 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx, struct composite_context *c; struct lookup_state *s; struct composite_context *cresolve_req; - const char** methods; + struct resolve_context *resolve_ctx; /* allocate context and state structures */ c = composite_create(ctx, ctx->event_ctx); @@ -81,14 +81,14 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx, s->hostname.scope = NULL; /* name resolution methods */ - if (io->in.methods) { - methods = io->in.methods; + if (io->in.resolve_ctx) { + resolve_ctx = io->in.resolve_ctx; } else { - methods = ctx->name_res_methods; + resolve_ctx = ctx->resolve_ctx; } /* send resolve request */ - cresolve_req = resolve_name_send(&s->hostname, c->event_ctx, methods); + cresolve_req = resolve_name_send(resolve_ctx, &s->hostname, c->event_ctx); if (composite_nomem(cresolve_req, c)) return c; composite_continue(c, cresolve_req, continue_name_resolved, c); @@ -192,11 +192,12 @@ struct composite_context* libnet_LookupDCs_send(struct libnet_context *ctx, { struct composite_context *c; struct messaging_context *msg_ctx = - messaging_client_init(mem_ctx, lp_messaging_path(mem_ctx, ctx->lp_ctx), ctx->event_ctx); + messaging_client_init(mem_ctx, lp_messaging_path(mem_ctx, ctx->lp_ctx), + lp_iconv_convenience(ctx->lp_ctx), ctx->event_ctx); - c = finddcs_send(mem_ctx, lp_netbios_name(ctx->lp_ctx), + c = finddcs_send(mem_ctx, lp_netbios_name(ctx->lp_ctx), lp_nbt_port(ctx->lp_ctx), io->in.domain_name, io->in.name_type, - NULL, ctx->name_res_methods, ctx->event_ctx, msg_ctx); + NULL, ctx->resolve_ctx, ctx->event_ctx, msg_ctx); return c; } diff --git a/source4/libnet/libnet_lookup.h b/source4/libnet/libnet_lookup.h index 69cc0b5ade..189ae58b39 100644 --- a/source4/libnet/libnet_lookup.h +++ b/source4/libnet/libnet_lookup.h @@ -22,7 +22,7 @@ struct libnet_Lookup { struct { const char *hostname; int type; - const char **methods; + struct resolve_context *resolve_ctx; } in; struct { const char **address; diff --git a/source4/libnet/libnet_samdump.c b/source4/libnet/libnet_samdump.c index 93e25aa428..9d417d280d 100644 --- a/source4/libnet/libnet_samdump.c +++ b/source4/libnet/libnet_samdump.c @@ -185,7 +185,7 @@ NTSTATUS libnet_SamDump(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, if (strcasecmp_m(s->name, secret_name) != 0) { continue; } - if (convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + if (convert_string_talloc(mem_ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF16, CH_UNIX, s->secret.data, s->secret.length, (void **)&secret_string) == -1) { r->out.error_string = talloc_asprintf(mem_ctx, diff --git a/source4/libnet/libnet_samdump_keytab.c b/source4/libnet/libnet_samdump_keytab.c index c235df6d25..c25cb4d9c5 100644 --- a/source4/libnet/libnet_samdump_keytab.c +++ b/source4/libnet/libnet_samdump_keytab.c @@ -28,6 +28,7 @@ #include "param/param.h" static NTSTATUS samdump_keytab_handle_user(TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, const char *keytab_name, struct netr_DELTA_ENUM *delta) { @@ -45,19 +46,19 @@ static NTSTATUS samdump_keytab_handle_user(TALLOC_CTX *mem_ctx, if (!credentials) { return NT_STATUS_NO_MEMORY; } - cli_credentials_set_conf(credentials, global_loadparm); + cli_credentials_set_conf(credentials, lp_ctx); cli_credentials_set_username(credentials, username, CRED_SPECIFIED); /* We really should consult ldap in the main SamSync code, and * pass a value in here */ cli_credentials_set_kvno(credentials, 0); cli_credentials_set_nt_hash(credentials, &user->ntpassword, CRED_SPECIFIED); - ret = cli_credentials_set_keytab_name(credentials, keytab_name, CRED_SPECIFIED); + ret = cli_credentials_set_keytab_name(credentials, lp_ctx, keytab_name, CRED_SPECIFIED); if (ret) { return NT_STATUS_UNSUCCESSFUL; } - ret = cli_credentials_update_keytab(credentials); + ret = cli_credentials_update_keytab(credentials, lp_ctx); if (ret) { return NT_STATUS_UNSUCCESSFUL; } @@ -81,6 +82,7 @@ static NTSTATUS libnet_samdump_keytab_fn(TALLOC_CTX *mem_ctx, /* not interested in builtin users */ if (database == SAM_DATABASE_DOMAIN) { nt_status = samdump_keytab_handle_user(mem_ctx, + global_loadparm, keytab_name, delta); break; diff --git a/source4/libnet/libnet_site.c b/source4/libnet/libnet_site.c index 9351aef634..9db9494865 100644 --- a/source4/libnet/libnet_site.c +++ b/source4/libnet/libnet_site.c @@ -51,7 +51,7 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_JoinSite *r) /* Resolve the site name. */ ZERO_STRUCT(search); search.in.dest_address = r->in.dest_address; - search.in.dest_port = lp_cldap_port(global_loadparm); + search.in.dest_port = r->in.cldap_port; search.in.acct_control = -1; search.in.version = 6; @@ -116,7 +116,8 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_JoinSite *r) * 2. Add entry CN=<netbios name>,CN=Servers,CN=<site name>,CN=Sites,CN=Configuration,<domain dn>. * TODO: 3.) use DsAddEntry() to create CN=NTDS Settings,CN=<netbios name>,CN=Servers,CN=<site name>,... */ -NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb, +NTSTATUS libnet_JoinSite(struct libnet_context *ctx, + struct ldb_context *remote_ldb, struct libnet_JoinDomain *libnet_r) { NTSTATUS status; @@ -147,7 +148,7 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb, } make_nbt_name_client(&name, libnet_r->out.samr_binding->host); - status = resolve_name(&name, r, &dest_addr, NULL, lp_name_resolve_order(global_loadparm)); + status = resolve_name(lp_resolve_context(ctx->lp_ctx), &name, r, &dest_addr, NULL); if (!NT_STATUS_IS_OK(status)) { libnet_r->out.error_string = NULL; talloc_free(tmp_ctx); @@ -158,6 +159,7 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb, r->in.dest_address = dest_addr; r->in.netbios_name = libnet_r->in.netbios_name; r->in.domain_dn_str = libnet_r->out.domain_dn_str; + r->in.cldap_port = lp_cldap_port(ctx->lp_ctx); status = libnet_FindSite(tmp_ctx, r); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/libnet/libnet_site.h b/source4/libnet/libnet_site.h index 9a0484c2a9..8e607c5b6a 100644 --- a/source4/libnet/libnet_site.h +++ b/source4/libnet/libnet_site.h @@ -22,6 +22,7 @@ struct libnet_JoinSite { const char *dest_address; const char *netbios_name; const char *domain_dn_str; + uint16_t cldap_port; } in; struct { diff --git a/source4/libnet/libnet_vampire.c b/source4/libnet/libnet_vampire.c index 574b34c246..df4cb4d657 100644 --- a/source4/libnet/libnet_vampire.c +++ b/source4/libnet/libnet_vampire.c @@ -186,7 +186,7 @@ NTSTATUS libnet_SamSync_netlogon(struct libnet_context *ctx, TALLOC_CTX *mem_ctx return NT_STATUS_NO_MEMORY; } cli_credentials_set_conf(machine_account, ctx->lp_ctx); - nt_status = cli_credentials_set_machine_account(machine_account); + nt_status = cli_credentials_set_machine_account(machine_account, ctx->lp_ctx); if (!NT_STATUS_IS_OK(nt_status)) { r->out.error_string = talloc_strdup(mem_ctx, "Could not obtain machine account password - are we joined to the domain?"); talloc_free(samsync_ctx); diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index 187ba9f309..2b2f39b650 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -487,7 +487,9 @@ PRIVATE_DEPENDENCIES = \ samba-socket LIBCLI_RESOLVE LIBCLI_SMB LIBCLI_SMB2 \ LIBNDR NDR_DCERPC RPC_NDR_EPMAPPER \ NDR_SCHANNEL RPC_NDR_NETLOGON \ - gensec LIBCLI_AUTH LIBCLI_RAW CREDENTIALS + gensec LIBCLI_AUTH LIBCLI_RAW \ + LP_RESOLVE +PUBLIC_DEPENDENCIES = CREDENTIALS # End SUBSYSTEM dcerpc ################################################ diff --git a/source4/librpc/idl/spoolss.idl b/source4/librpc/idl/spoolss.idl index 8224976a26..9c26b14892 100644 --- a/source4/librpc/idl/spoolss.idl +++ b/source4/librpc/idl/spoolss.idl @@ -1313,6 +1313,67 @@ import "security.idl", "winreg.idl"; [case(1)] spoolss_UserLevel1 *level1; } spoolss_UserLevel; + typedef bitmap { + SERVER_ACCESS_ADMINISTER = 0x00000001, + SERVER_ACCESS_ENUMERATE = 0x00000002, + PRINTER_ACCESS_ADMINISTER = 0x00000004, + PRINTER_ACCESS_USE = 0x00000008, + JOB_ACCESS_ADMINISTER = 0x00000010 + } spoolss_AccessRights; + + /* Access rights for print servers */ + const int SERVER_ALL_ACCESS = SEC_STD_REQUIRED | + SERVER_ACCESS_ADMINISTER | + SERVER_ACCESS_ENUMERATE; + + const int SERVER_READ = SEC_STD_READ_CONTROL | + SERVER_ACCESS_ENUMERATE; + + const int SERVER_WRITE = STANDARD_RIGHTS_WRITE_ACCESS | + SERVER_ACCESS_ADMINISTER | + SERVER_ACCESS_ENUMERATE; + + const int SERVER_EXECUTE = SEC_STD_READ_CONTROL | + SERVER_ACCESS_ENUMERATE; + + /* Access rights for printers */ + const int PRINTER_ALL_ACCESS = SEC_STD_REQUIRED | + PRINTER_ACCESS_ADMINISTER | + PRINTER_ACCESS_USE; + + const int PRINTER_READ = SEC_STD_READ_CONTROL | + PRINTER_ACCESS_USE; + + const int PRINTER_WRITE = STANDARD_RIGHTS_WRITE_ACCESS | + PRINTER_ACCESS_USE; + + const int PRINTER_EXECUTE = SEC_STD_READ_CONTROL | + PRINTER_ACCESS_USE; + + /* Access rights for jobs */ + const int JOB_ALL_ACCESS = SEC_STD_REQUIRED | + JOB_ACCESS_ADMINISTER; + + const int JOB_READ = SEC_STD_READ_CONTROL | + JOB_ACCESS_ADMINISTER; + + const int JOB_WRITE = STANDARD_RIGHTS_WRITE_ACCESS | + JOB_ACCESS_ADMINISTER; + + const int JOB_EXECUTE = SEC_STD_READ_CONTROL | + JOB_ACCESS_ADMINISTER; + + /* ACE masks for various print permissions */ + const int PRINTER_ACE_FULL_CONTROL = SEC_GENERIC_ALL | + PRINTER_ALL_ACCESS; + + const int PRINTER_ACE_MANAGE_DOCUMENTS = SEC_GENERIC_ALL | + READ_CONTROL_ACCESS; + + const int PRINTER_ACE_PRINT = GENERIC_EXECUTE_ACCESS | + READ_CONTROL_ACCESS | + PRINTER_ACCESS_USE; + /******************/ /* Function: 0x45 */ [public] WERROR spoolss_OpenPrinterEx( @@ -1416,9 +1477,9 @@ import "security.idl", "winreg.idl"; [public] WERROR spoolss_EnumPrinterKey( [in, ref] policy_handle *handle, [in] [string,charset(UTF16)] uint16 key_name[], - [out, ref] uint32 *key_buffer_size, - [out] uint8 key_buffer[*key_buffer_size], - [in,out,ref] uint32 *needed + [out] uint32 key_buffer_size, + [out] uint16 key_buffer[key_buffer_size], + [in,out] uint32 needed ); /******************/ diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h index 2ac0b86f57..1ecc6f3c38 100644 --- a/source4/librpc/ndr/libndr.h +++ b/source4/librpc/ndr/libndr.h @@ -52,6 +52,8 @@ struct ndr_pull { uint32_t data_size; uint32_t offset; + struct smb_iconv_convenience *iconv_convenience; + uint32_t relative_base_offset; struct ndr_token_list *relative_base_list; @@ -84,6 +86,8 @@ struct ndr_push { /* this is used to ensure we generate unique reference IDs */ uint32_t ptr_count; + + struct smb_iconv_convenience *iconv_convenience; }; /* structure passed to functions that print IDL structures */ diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c index 40afeacebf..0dafda7086 100644 --- a/source4/librpc/ndr/ndr.c +++ b/source4/librpc/ndr/ndr.c @@ -30,6 +30,7 @@ #include "librpc/ndr/libndr.h" #include "lib/util/dlinklist.h" #include "librpc/gen_ndr/dcerpc.h" +#include "param/param.h" #define NDR_BASE_MARSHALL_SIZE 1024 @@ -56,7 +57,7 @@ _PUBLIC_ size_t ndr_align_size(uint32_t offset, size_t n) /* initialise a ndr parse structure from a data blob */ -_PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx) +_PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience) { struct ndr_pull *ndr; @@ -66,6 +67,7 @@ _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX * ndr->data = blob->data; ndr->data_size = blob->length; + ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience); return ndr; } @@ -99,7 +101,7 @@ static enum ndr_err_code ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs) } /* create a ndr_push structure, ready for some marshalling */ -_PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx) +_PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience) { struct ndr_push *ndr; @@ -114,6 +116,7 @@ _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx) if (!ndr->data) { return NULL; } + ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience); return ndr; } @@ -438,6 +441,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_start(struct ndr_pull *ndr, subndr->data = ndr->data + ndr->offset; subndr->offset = 0; subndr->data_size = r_content_size; + subndr->iconv_convenience = talloc_reference(subndr, ndr->iconv_convenience); *_subndr = subndr; return NDR_ERR_SUCCESS; @@ -467,7 +471,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_start(struct ndr_push *ndr, { struct ndr_push *subndr; - subndr = ndr_push_init_ctx(ndr); + subndr = ndr_push_init_ctx(ndr, ndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(subndr); subndr->flags = ndr->flags; @@ -690,7 +694,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CT ndr_pull_flags_fn_t fn) { struct ndr_pull *ndr; - ndr = ndr_pull_init_blob(blob, mem_ctx); + ndr = ndr_pull_init_blob(blob, mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); return NDR_ERR_SUCCESS; @@ -703,7 +707,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLO ndr_pull_flags_fn_t fn) { struct ndr_pull *ndr; - ndr = ndr_pull_init_blob(blob, mem_ctx); + ndr = ndr_pull_init_blob(blob, mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); if (ndr->offset < ndr->data_size) { @@ -721,7 +725,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX uint32_t level, ndr_pull_flags_fn_t fn) { struct ndr_pull *ndr; - ndr = ndr_pull_init_blob(blob, mem_ctx); + ndr = ndr_pull_init_blob(blob, mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(ndr_pull_set_switch_value(ndr, p, level)); NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); @@ -736,7 +740,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC uint32_t level, ndr_pull_flags_fn_t fn) { struct ndr_pull *ndr; - ndr = ndr_pull_init_blob(blob, mem_ctx); + ndr = ndr_pull_init_blob(blob, mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(ndr_pull_set_switch_value(ndr, p, level)); NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); @@ -755,7 +759,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem ndr_push_flags_fn_t fn) { struct ndr_push *ndr; - ndr = ndr_push_init_ctx(mem_ctx); + ndr = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); @@ -774,7 +778,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ uint32_t level, ndr_push_flags_fn_t fn) { struct ndr_push *ndr; - ndr = ndr_push_init_ctx(mem_ctx); + ndr = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_CHECK(ndr_push_set_switch_value(ndr, p, level)); @@ -799,7 +803,7 @@ _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t pu /* avoid recursion */ if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0; - ndr = ndr_push_init_ctx(NULL); + ndr = ndr_push_init_ctx(NULL, lp_iconv_convenience(global_loadparm)); if (!ndr) return 0; ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE; status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p)); @@ -824,7 +828,7 @@ _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_pus /* avoid recursion */ if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0; - ndr = ndr_push_init_ctx(NULL); + ndr = ndr_push_init_ctx(NULL, lp_iconv_convenience(global_loadparm)); if (!ndr) return 0; ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE; diff --git a/source4/librpc/ndr/ndr_compression.c b/source4/librpc/ndr/ndr_compression.c index 411d4a17e2..310f8c4ce4 100644 --- a/source4/librpc/ndr/ndr_compression.c +++ b/source4/librpc/ndr/ndr_compression.c @@ -86,7 +86,7 @@ static enum ndr_err_code ndr_pull_compression_mszip(struct ndr_pull *subndr, struct decomp_state *decomp_state; bool last = false; - ndrpush = ndr_push_init_ctx(subndr); + ndrpush = ndr_push_init_ctx(subndr, subndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(ndrpush); decomp_state = ZIPdecomp_state(subndr); @@ -197,7 +197,7 @@ static enum ndr_err_code ndr_pull_compression_xpress(struct ndr_pull *subndr, DATA_BLOB uncompressed; bool last = false; - ndrpush = ndr_push_init_ctx(subndr); + ndrpush = ndr_push_init_ctx(subndr, subndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(ndrpush); while (!last) { @@ -264,7 +264,7 @@ enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, { struct ndr_push *comndr; - comndr = ndr_push_init_ctx(subndr); + comndr = ndr_push_init_ctx(subndr, subndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(comndr); comndr->flags = subndr->flags; diff --git a/source4/librpc/ndr/ndr_spoolss_buf.c b/source4/librpc/ndr/ndr_spoolss_buf.c index 9800430203..e01c5fd225 100644 --- a/source4/librpc/ndr/ndr_spoolss_buf.c +++ b/source4/librpc/ndr/ndr_spoolss_buf.c @@ -23,6 +23,7 @@ #include "includes.h" #include "librpc/gen_ndr/ndr_spoolss.h" +#include "param/param.h" #define NDR_SPOOLSS_PUSH_ENUM_IN(fn) do { \ if (!r->in.buffer && r->in.offered != 0) {\ @@ -55,7 +56,7 @@ }\ if (r->in.buffer) {\ DATA_BLOB _data_blob_info;\ - _ndr_info = ndr_push_init_ctx(ndr);\ + _ndr_info = ndr_push_init_ctx(ndr, ndr->iconv_convenience);\ NDR_ERR_HAVE_NO_MEMORY(_ndr_info);\ _ndr_info->flags= ndr->flags;\ if (r->out.info) {\ @@ -120,7 +121,7 @@ r->out.count = _r.out.count;\ r->out.result = _r.out.result;\ if (_r.out.info) {\ - struct ndr_pull *_ndr_info = ndr_pull_init_blob(_r.out.info, ndr);\ + struct ndr_pull *_ndr_info = ndr_pull_init_blob(_r.out.info, ndr, ndr->iconv_convenience);\ NDR_ERR_HAVE_NO_MEMORY(_ndr_info);\ _ndr_info->flags= ndr->flags;\ if (r->in.offered != _ndr_info->data_size) {\ @@ -164,7 +165,7 @@ #define NDR_SPOOLSS_SIZE_ENUM(fn) do { \ struct __##fn __r;\ DATA_BLOB _data_blob_info;\ - struct ndr_push *_ndr_info = ndr_push_init_ctx(mem_ctx);\ + struct ndr_push *_ndr_info = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm));\ if (!_ndr_info) return 0;\ _ndr_info->flags|=0;\ __r.in.level = level;\ @@ -414,7 +415,7 @@ enum ndr_err_code ndr_push_spoolss_GetPrinterData(struct ndr_push *ndr, int flag _r.out.result = r->out.result; { struct __spoolss_GetPrinterData __r; - _ndr_info = ndr_push_init_ctx(ndr); + _ndr_info = ndr_push_init_ctx(ndr, ndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(_ndr_info); _ndr_info->flags= ndr->flags; __r.in.type = r->out.type; @@ -469,7 +470,7 @@ enum ndr_err_code ndr_pull_spoolss_GetPrinterData(struct ndr_pull *ndr, int flag } if (_r.out.data.length > 0 && r->out.needed <= _r.out.data.length) { struct __spoolss_GetPrinterData __r; - struct ndr_pull *_ndr_data = ndr_pull_init_blob(&_r.out.data, ndr); + struct ndr_pull *_ndr_data = ndr_pull_init_blob(&_r.out.data, ndr, ndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(_ndr_data); _ndr_data->flags= ndr->flags; __r.in.type = r->out.type; @@ -494,7 +495,7 @@ enum ndr_err_code ndr_push_spoolss_SetPrinterData(struct ndr_push *ndr, int flag struct __spoolss_SetPrinterData __r; DATA_BLOB _data_blob_data; - _ndr_data = ndr_push_init_ctx(ndr); + _ndr_data = ndr_push_init_ctx(ndr, ndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(_ndr_data); _ndr_data->flags= ndr->flags; diff --git a/source4/librpc/ndr/ndr_string.c b/source4/librpc/ndr/ndr_string.c index 7e84211e87..69a7eca1a8 100644 --- a/source4/librpc/ndr/ndr_string.c +++ b/source4/librpc/ndr/ndr_string.c @@ -82,7 +82,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, chset, CH_UNIX, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len2 + c_len_term)*byte_mul, (void **)&as); @@ -119,7 +119,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len1 + c_len_term)*byte_mul, @@ -158,7 +158,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len1 + c_len_term)*byte_mul, @@ -193,7 +193,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, (len3 + c_len_term)*byte_mul, @@ -226,7 +226,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len3, @@ -247,7 +247,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, len1 = utf16_len_n(ndr->data+ndr->offset, ndr->data_size - ndr->offset); } ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, chset, CH_UNIX, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len1, (void **)&as); @@ -264,7 +264,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, len1 = (flags & LIBNDR_FLAG_STR_FIXLEN32)?32:15; NDR_PULL_NEED_BYTES(ndr, len1*byte_mul); ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len1*byte_mul, @@ -290,7 +290,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, as = talloc_strdup(ndr->current_mem_ctx, ""); } else { ret = convert_string_talloc(ndr->current_mem_ctx, - global_smb_iconv_convenience, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, len1, @@ -355,7 +355,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, int ndr_flags, LIBNDR_FLAG_STR_FIXLEN32))) { s_len++; } - d_len = convert_string_talloc(ndr, global_smb_iconv_convenience, CH_UNIX, chset, s, s_len, (void **)&dest); + d_len = convert_string_talloc(ndr, ndr->iconv_convenience, CH_UNIX, chset, s, s_len, (void **)&dest); if (d_len == -1) { return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion"); @@ -689,7 +689,8 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, NDR_PULL_NEED_BYTES(ndr, length*byte_mul); - ret = convert_string_talloc(ndr->current_mem_ctx, global_smb_iconv_convenience, + ret = convert_string_talloc(ndr->current_mem_ctx, + ndr->iconv_convenience, chset, CH_UNIX, ndr->data+ndr->offset, length*byte_mul, @@ -714,7 +715,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, required = byte_mul * length; NDR_PUSH_NEED_BYTES(ndr, required); - ret = convert_string(global_smb_iconv_convenience, CH_UNIX, chset, + ret = convert_string(ndr->iconv_convenience, CH_UNIX, chset, var, strlen(var), ndr->data+ndr->offset, required); if (ret == -1) { diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c index 74dc2562ed..f5eae1b09a 100644 --- a/source4/librpc/rpc/dcerpc.c +++ b/source4/librpc/rpc/dcerpc.c @@ -164,13 +164,13 @@ void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v) } -/* +/** setup for a ndr pull, also setting up any flags from the binding string */ static struct ndr_pull *ndr_pull_init_flags(struct dcerpc_connection *c, DATA_BLOB *blob, TALLOC_CTX *mem_ctx) { - struct ndr_pull *ndr = ndr_pull_init_blob(blob, mem_ctx); + struct ndr_pull *ndr = ndr_pull_init_blob(blob, mem_ctx, lp_iconv_convenience(global_loadparm)); if (ndr == NULL) return ndr; @@ -350,7 +350,7 @@ static NTSTATUS ncacn_push_request_sign(struct dcerpc_connection *c, return ncacn_push_auth(blob, mem_ctx, pkt, c->security_state.auth_info); } - ndr = ndr_push_init_ctx(mem_ctx); + ndr = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!ndr) { return NT_STATUS_NO_MEMORY; } @@ -1194,7 +1194,7 @@ static NTSTATUS dcerpc_ndr_validate_in(struct dcerpc_connection *c, return ndr_map_error2ntstatus(ndr_err); } - push = ndr_push_init_ctx(mem_ctx); + push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!push) { return NT_STATUS_NO_MEMORY; } @@ -1252,7 +1252,7 @@ static NTSTATUS dcerpc_ndr_validate_out(struct dcerpc_connection *c, } memcpy(st, struct_ptr, struct_size); - push = ndr_push_init_ctx(mem_ctx); + push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!push) { return NT_STATUS_NO_MEMORY; } @@ -1283,7 +1283,7 @@ static NTSTATUS dcerpc_ndr_validate_out(struct dcerpc_connection *c, return ndr_map_error2ntstatus(ndr_err); } - push = ndr_push_init_ctx(mem_ctx); + push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!push) { return NT_STATUS_NO_MEMORY; } @@ -1354,7 +1354,7 @@ struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p, call = &table->calls[opnum]; /* setup for a ndr_push_* call */ - push = ndr_push_init_ctx(mem_ctx); + push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!push) { return NULL; } @@ -1521,10 +1521,13 @@ NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p, */ const char *dcerpc_server_name(struct dcerpc_pipe *p) { - if (!p->conn->transport.peer_name) { - return ""; + if (!p->conn->transport.target_hostname) { + if (!p->conn->transport.peer_name) { + return ""; + } + return p->conn->transport.peer_name(p->conn); } - return p->conn->transport.peer_name(p->conn); + return p->conn->transport.target_hostname(p->conn); } diff --git a/source4/librpc/rpc/dcerpc.h b/source4/librpc/rpc/dcerpc.h index ff827e50f2..9936ebe001 100644 --- a/source4/librpc/rpc/dcerpc.h +++ b/source4/librpc/rpc/dcerpc.h @@ -177,7 +177,7 @@ struct dcerpc_pipe_connect { const char *pipe_name; const struct ndr_interface_table *interface; struct cli_credentials *creds; - const char **name_resolve_order; + struct resolve_context *resolve_ctx; }; diff --git a/source4/librpc/rpc/dcerpc.py b/source4/librpc/rpc/dcerpc.py index b2edb17f33..da3664d80e 100644 --- a/source4/librpc/rpc/dcerpc.py +++ b/source4/librpc/rpc/dcerpc.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _dcerpc import new @@ -48,36 +47,40 @@ except AttributeError: del types -class Credentials(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, Credentials, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, Credentials, name) +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class Credentials(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - this = _dcerpc.new_Credentials(*args, **kwargs) - try: self.this.append(this) - except: self.this = this + _dcerpc.Credentials_swiginit(self,_dcerpc.new_Credentials(*args, **kwargs)) __swig_destroy__ = _dcerpc.delete_Credentials - __del__ = lambda self : None; - def get_username(*args, **kwargs): return _dcerpc.Credentials_get_username(*args, **kwargs) - def set_username(*args, **kwargs): return _dcerpc.Credentials_set_username(*args, **kwargs) - def get_password(*args, **kwargs): return _dcerpc.Credentials_get_password(*args, **kwargs) - def set_password(*args, **kwargs): return _dcerpc.Credentials_set_password(*args, **kwargs) - def get_domain(*args, **kwargs): return _dcerpc.Credentials_get_domain(*args, **kwargs) - def set_domain(*args, **kwargs): return _dcerpc.Credentials_set_domain(*args, **kwargs) - def get_realm(*args, **kwargs): return _dcerpc.Credentials_get_realm(*args, **kwargs) - def set_realm(*args, **kwargs): return _dcerpc.Credentials_set_realm(*args, **kwargs) - def parse_string(*args, **kwargs): return _dcerpc.Credentials_parse_string(*args, **kwargs) - def get_bind_dn(*args, **kwargs): return _dcerpc.Credentials_get_bind_dn(*args, **kwargs) - def set_bind_dn(*args, **kwargs): return _dcerpc.Credentials_set_bind_dn(*args, **kwargs) - def get_workstation(*args, **kwargs): return _dcerpc.Credentials_get_workstation(*args, **kwargs) - def set_workstation(*args, **kwargs): return _dcerpc.Credentials_set_workstation(*args, **kwargs) - def guess(*args, **kwargs): return _dcerpc.Credentials_guess(*args, **kwargs) - def is_anonymous(*args, **kwargs): return _dcerpc.Credentials_is_anonymous(*args, **kwargs) - def get_nt_hash(*args, **kwargs): return _dcerpc.Credentials_get_nt_hash(*args, **kwargs) - def authentication_requested(*args, **kwargs): return _dcerpc.Credentials_authentication_requested(*args, **kwargs) - def wrong_password(*args, **kwargs): return _dcerpc.Credentials_wrong_password(*args, **kwargs) +Credentials.get_username = new_instancemethod(_dcerpc.Credentials_get_username,None,Credentials) +Credentials.set_username = new_instancemethod(_dcerpc.Credentials_set_username,None,Credentials) +Credentials.get_password = new_instancemethod(_dcerpc.Credentials_get_password,None,Credentials) +Credentials.set_password = new_instancemethod(_dcerpc.Credentials_set_password,None,Credentials) +Credentials.get_domain = new_instancemethod(_dcerpc.Credentials_get_domain,None,Credentials) +Credentials.set_domain = new_instancemethod(_dcerpc.Credentials_set_domain,None,Credentials) +Credentials.get_realm = new_instancemethod(_dcerpc.Credentials_get_realm,None,Credentials) +Credentials.set_realm = new_instancemethod(_dcerpc.Credentials_set_realm,None,Credentials) +Credentials.parse_string = new_instancemethod(_dcerpc.Credentials_parse_string,None,Credentials) +Credentials.get_bind_dn = new_instancemethod(_dcerpc.Credentials_get_bind_dn,None,Credentials) +Credentials.set_bind_dn = new_instancemethod(_dcerpc.Credentials_set_bind_dn,None,Credentials) +Credentials.get_workstation = new_instancemethod(_dcerpc.Credentials_get_workstation,None,Credentials) +Credentials.set_workstation = new_instancemethod(_dcerpc.Credentials_set_workstation,None,Credentials) +Credentials.guess = new_instancemethod(_dcerpc.Credentials_guess,None,Credentials) +Credentials.is_anonymous = new_instancemethod(_dcerpc.Credentials_is_anonymous,None,Credentials) +Credentials.get_nt_hash = new_instancemethod(_dcerpc.Credentials_get_nt_hash,None,Credentials) +Credentials.authentication_requested = new_instancemethod(_dcerpc.Credentials_authentication_requested,None,Credentials) +Credentials.wrong_password = new_instancemethod(_dcerpc.Credentials_wrong_password,None,Credentials) Credentials_swigregister = _dcerpc.Credentials_swigregister Credentials_swigregister(Credentials) diff --git a/source4/librpc/rpc/dcerpc_connect.c b/source4/librpc/rpc/dcerpc_connect.c index e6244fe229..8fd783fb83 100644 --- a/source4/librpc/rpc/dcerpc_connect.c +++ b/source4/librpc/rpc/dcerpc_connect.c @@ -32,6 +32,7 @@ #include "librpc/rpc/dcerpc.h" #include "auth/credentials/credentials.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" struct pipe_np_smb_state { @@ -110,7 +111,7 @@ static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CT /* prepare smb connection parameters: we're connecting to IPC$ share on remote rpc server */ conn->in.dest_host = s->io.binding->host; - conn->in.port = 0; + conn->in.dest_ports = lp_smb_ports(global_loadparm); if (s->io.binding->target_hostname == NULL) conn->in.called_name = "*SMBSERVER"; /* FIXME: This is invalid */ else @@ -236,7 +237,7 @@ static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send( /* send smb2 connect request */ conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, "IPC$", - s->io.name_resolve_order, + s->io.resolve_ctx, s->io.creds, c->event_ctx); composite_continue(c, conn_req, continue_smb2_connect, c); @@ -308,7 +309,7 @@ static struct composite_context* dcerpc_pipe_connect_ncacn_ip_tcp_send(TALLOC_CT /* send pipe open request on tcp/ip */ pipe_req = dcerpc_pipe_open_tcp_send(s->io.pipe->conn, s->host, s->target_hostname, - s->port, io->name_resolve_order); + s->port, io->resolve_ctx); composite_continue(c, pipe_req, continue_pipe_open_ncacn_ip_tcp, c); return c; } @@ -521,7 +522,7 @@ static void continue_connect(struct composite_context *c, struct pipe_connect_st pc.binding = s->binding; pc.interface = s->table; pc.creds = s->credentials; - pc.name_resolve_order = lp_name_resolve_order(global_loadparm); + pc.resolve_ctx = lp_resolve_context(global_loadparm); /* connect dcerpc pipe depending on required transport */ switch (s->binding->transport) { diff --git a/source4/librpc/rpc/dcerpc_secondary.c b/source4/librpc/rpc/dcerpc_secondary.c index 0aa38d55ed..5e8dd955d3 100644 --- a/source4/librpc/rpc/dcerpc_secondary.c +++ b/source4/librpc/rpc/dcerpc_secondary.c @@ -29,6 +29,7 @@ #include "librpc/rpc/dcerpc.h" #include "auth/credentials/credentials.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" struct sec_conn_state { @@ -93,7 +94,7 @@ struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p s->binding->host, s->binding->target_hostname, atoi(s->binding->endpoint), - lp_name_resolve_order(global_loadparm)); + lp_resolve_context(global_loadparm)); composite_continue(c, pipe_tcp_req, continue_open_tcp, c); return c; diff --git a/source4/librpc/rpc/dcerpc_sock.c b/source4/librpc/rpc/dcerpc_sock.c index 327b1bf419..2e5a8388a1 100644 --- a/source4/librpc/rpc/dcerpc_sock.c +++ b/source4/librpc/rpc/dcerpc_sock.c @@ -332,7 +332,8 @@ static struct composite_context *dcerpc_pipe_open_socket_send(TALLOC_CTX *mem_ct talloc_steal(s->sock, s->socket_ctx); - conn_req = socket_connect_send(s->socket_ctx, NULL, s->server, 0, lp_name_resolve_order(global_loadparm), + conn_req = socket_connect_send(s->socket_ctx, NULL, s->server, 0, + lp_resolve_context(global_loadparm), c->event_ctx); composite_continue(c, conn_req, continue_socket_connect, c); return c; @@ -454,7 +455,7 @@ struct composite_context* dcerpc_pipe_open_tcp_send(struct dcerpc_connection *co const char *server, const char *target_hostname, uint32_t port, - const char **name_resolve_order) + struct resolve_context *resolve_ctx) { struct composite_context *c; struct pipe_tcp_state *s; @@ -480,7 +481,7 @@ struct composite_context* dcerpc_pipe_open_tcp_send(struct dcerpc_connection *co s->conn = conn; make_nbt_name_server(&name, server); - resolve_req = resolve_name_send(&name, c->event_ctx, name_resolve_order); + resolve_req = resolve_name_send(resolve_ctx, &name, c->event_ctx); composite_continue(c, resolve_req, continue_ip_resolve_name, c); return c; } diff --git a/source4/librpc/rpc/dcerpc_util.c b/source4/librpc/rpc/dcerpc_util.c index 32cee4308e..ecc6f19e8c 100644 --- a/source4/librpc/rpc/dcerpc_util.c +++ b/source4/librpc/rpc/dcerpc_util.c @@ -56,7 +56,7 @@ NTSTATUS ncacn_push_auth(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct ndr_push *ndr; enum ndr_err_code ndr_err; - ndr = ndr_push_init_ctx(mem_ctx); + ndr = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); if (!ndr) { return NT_STATUS_NO_MEMORY; } @@ -439,7 +439,7 @@ NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_ NTSTATUS dcerpc_floor_get_lhs_data(struct epm_floor *epm_floor, struct ndr_syntax_id *syntax) { TALLOC_CTX *mem_ctx = talloc_init("floor_get_lhs_data"); - struct ndr_pull *ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx); + struct ndr_pull *ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx, NULL); enum ndr_err_code ndr_err; uint16_t if_version=0; @@ -466,7 +466,7 @@ NTSTATUS dcerpc_floor_get_lhs_data(struct epm_floor *epm_floor, struct ndr_synta static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax) { - struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx); + struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx, NULL); ndr->flags |= LIBNDR_FLAG_NOALIGN; @@ -939,7 +939,6 @@ struct composite_context *dcerpc_epm_map_binding_send(TALLOC_CTX *mem_ctx, /* anonymous credentials for rpc connection used to get endpoint mapping */ anon_creds = cli_credentials_init(mem_ctx); cli_credentials_set_event_context(anon_creds, ev); - cli_credentials_set_conf(anon_creds, global_loadparm); cli_credentials_set_anonymous(anon_creds); /* diff --git a/source4/librpc/rpc/dcerpc_wrap.c b/source4/librpc/rpc/dcerpc_wrap.c index c9eb72fb9e..c60fef9e9d 100644 --- a/source4/librpc/rpc/dcerpc_wrap.c +++ b/source4/librpc/rpc/dcerpc_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2476,6 +2476,19 @@ static swig_module_info swig_module = {swig_types, 8, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _dcerpc.so @@ -2775,7 +2788,7 @@ SWIGINTERN PyObject *_wrap_new_Credentials(PyObject *SWIGUNUSEDPARM(self), PyObj PyObject *resultobj = 0; cli_credentials *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)":new_Credentials")) SWIG_fail; + if (!SWIG_Python_UnpackTuple(args,"new_Credentials",0,0,0)) SWIG_fail; result = (cli_credentials *)new_cli_credentials(); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_cli_credentials, SWIG_POINTER_NEW | 0 ); return resultobj; @@ -3535,11 +3548,15 @@ fail: SWIGINTERN PyObject *Credentials_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args,(char*)"O|swigregister", &obj)) return NULL; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_cli_credentials, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Credentials_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_pipe_connect(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; @@ -3665,7 +3682,7 @@ fail: static PyMethodDef SwigMethods[] = { - { (char *)"new_Credentials", _wrap_new_Credentials, METH_VARARGS, NULL}, + { (char *)"new_Credentials", (PyCFunction)_wrap_new_Credentials, METH_NOARGS, NULL}, { (char *)"delete_Credentials", (PyCFunction) _wrap_delete_Credentials, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_get_username", (PyCFunction) _wrap_Credentials_get_username, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_set_username", (PyCFunction) _wrap_Credentials_set_username, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -3686,6 +3703,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Credentials_authentication_requested", (PyCFunction) _wrap_Credentials_authentication_requested, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_wrong_password", (PyCFunction) _wrap_Credentials_wrong_password, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_swigregister", Credentials_swigregister, METH_VARARGS, NULL}, + { (char *)"Credentials_swiginit", Credentials_swiginit, METH_VARARGS, NULL}, { (char *)"pipe_connect", (PyCFunction) _wrap_pipe_connect, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"dcerpc_server_name", (PyCFunction) _wrap_dcerpc_server_name, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } diff --git a/source4/librpc/tools/ndrdump.c b/source4/librpc/tools/ndrdump.c index a86b349aa9..bc1436916f 100644 --- a/source4/librpc/tools/ndrdump.c +++ b/source4/librpc/tools/ndrdump.c @@ -25,6 +25,7 @@ #include "system/locale.h" #include "librpc/ndr/libndr.h" #include "librpc/ndr/ndr_table.h" +#include "param/param.h" #endif static const struct ndr_interface_call *find_function( @@ -303,7 +304,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force) blob.data = data; blob.length = size; - ndr_pull = ndr_pull_init_blob(&blob, mem_ctx); + ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx)); ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC; ndr_err = f->ndr_pull(ndr_pull, NDR_IN, st); @@ -340,7 +341,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force) blob.data = data; blob.length = size; - ndr_pull = ndr_pull_init_blob(&blob, mem_ctx); + ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx)); ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC; ndr_err = f->ndr_pull(ndr_pull, flags, st); @@ -379,7 +380,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force) uint8_t byte_a, byte_b; bool differ; - ndr_v_push = ndr_push_init_ctx(mem_ctx); + ndr_v_push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(cmdline_lp_ctx)); ndr_err = f->ndr_push(ndr_v_push, flags, st); status = ndr_map_error2ntstatus(ndr_err); @@ -396,7 +397,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force) ndrdump_data(v_blob.data, v_blob.length, dumpdata); } - ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx); + ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx)); ndr_v_pull->flags |= LIBNDR_FLAG_REF_ALLOC; ndr_err = f->ndr_pull(ndr_v_pull, flags, v_st); diff --git a/source4/nbt_server/config.mk b/source4/nbt_server/config.mk index 18c5734f2a..68ef56c11e 100644 --- a/source4/nbt_server/config.mk +++ b/source4/nbt_server/config.mk @@ -21,7 +21,7 @@ INIT_FUNCTION = wins_ldb_module_init OBJ_FILES = \ wins/wins_ldb.o PRIVATE_DEPENDENCIES = \ - LIBNETIF + LIBNETIF LIBSAMBA-CONFIG LIBSAMBA-UTIL # End MODULE ldb_wins_ldb ####################### diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c index 21ebada3c8..486acfbad5 100644 --- a/source4/nbt_server/interfaces.c +++ b/source4/nbt_server/interfaces.c @@ -216,9 +216,10 @@ static NTSTATUS nbtd_add_wins_socket(struct nbtd_server *nbtsrv) /* setup our listening sockets on the configured network interfaces */ -NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_context *lp_ctx) +NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_context *lp_ctx, + struct interface *ifaces) { - int num_interfaces = iface_count(lp_ctx); + int num_interfaces = iface_count(ifaces); int i; TALLOC_CTX *tmp_ctx = talloc_new(nbtsrv); NTSTATUS status; @@ -232,7 +233,7 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_con for non-WINS queries not made on a specific interface */ if (num_interfaces > 0) { - primary_address = iface_n_ip(lp_ctx, 0); + primary_address = iface_n_ip(ifaces, 0); } else { primary_address = inet_ntoa(interpret_addr2( lp_netbios_name(lp_ctx))); @@ -250,15 +251,15 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv, struct loadparm_con } for (i=0; i<num_interfaces; i++) { - const char *bcast = iface_n_bcast(lp_ctx, i); + const char *bcast = iface_n_bcast(ifaces, i); const char *address, *netmask; /* we can't assume every interface is broadcast capable */ if (bcast == NULL) continue; - address = talloc_strdup(tmp_ctx, iface_n_ip(lp_ctx, i)); + address = talloc_strdup(tmp_ctx, iface_n_ip(ifaces, i)); bcast = talloc_strdup(tmp_ctx, bcast); - netmask = talloc_strdup(tmp_ctx, iface_n_netmask(lp_ctx, i)); + netmask = talloc_strdup(tmp_ctx, iface_n_netmask(ifaces, i)); status = nbtd_add_socket(nbtsrv, lp_ctx, address, address, bcast, netmask); diff --git a/source4/nbt_server/nbt_server.c b/source4/nbt_server/nbt_server.c index 22f46dec69..c7fb3b286a 100644 --- a/source4/nbt_server/nbt_server.c +++ b/source4/nbt_server/nbt_server.c @@ -37,8 +37,11 @@ static void nbtd_task_init(struct task_server *task) { struct nbtd_server *nbtsrv; NTSTATUS status; + struct interface *ifaces; - if (iface_count(task->lp_ctx) == 0) { + load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces); + + if (iface_count(ifaces) == 0) { task_server_terminate(task, "nbtd: no network interfaces configured"); return; } @@ -57,7 +60,7 @@ static void nbtd_task_init(struct task_server *task) nbtsrv->wins_interface = NULL; /* start listening on the configured network interfaces */ - status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx); + status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx, ifaces); if (!NT_STATUS_IS_OK(status)) { task_server_terminate(task, "nbtd failed to setup interfaces"); return; @@ -82,8 +85,6 @@ static void nbtd_task_init(struct task_server *task) nbtd_register_names(nbtsrv); irpc_add_name(task->msg_ctx, "nbt_server"); - - } diff --git a/source4/nbt_server/nbt_server.h b/source4/nbt_server/nbt_server.h index 506098b691..688b6a7a7d 100644 --- a/source4/nbt_server/nbt_server.h +++ b/source4/nbt_server/nbt_server.h @@ -88,4 +88,5 @@ struct nbtd_server { } \ } while (0) +struct interface; #include "nbt_server/nbt_server_proto.h" diff --git a/source4/nbt_server/register.c b/source4/nbt_server/register.c index c185001e23..a17d503190 100644 --- a/source4/nbt_server/register.c +++ b/source4/nbt_server/register.c @@ -93,6 +93,7 @@ static void name_refresh_handler(struct event_context *ev, struct timed_event *t registration packets */ io.in.name = iname->name; io.in.dest_addr = iface->bcast_address; + io.in.dest_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx); io.in.address = iface->ip_address; io.in.nb_flags = iname->nb_flags; io.in.ttl = iname->ttl; @@ -210,6 +211,7 @@ static void nbtd_register_name_iface(struct nbtd_interface *iface, /* setup a broadcast name registration request */ io.in.name = iname->name; io.in.dest_addr = iface->bcast_address; + io.in.dest_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx); io.in.address = iface->ip_address; io.in.nb_flags = nb_flags; io.in.ttl = iname->ttl; diff --git a/source4/nbt_server/wins/wins_dns_proxy.c b/source4/nbt_server/wins/wins_dns_proxy.c index 24bcf1f3d1..3322ad55fd 100644 --- a/source4/nbt_server/wins/wins_dns_proxy.c +++ b/source4/nbt_server/wins/wins_dns_proxy.c @@ -72,10 +72,7 @@ void nbtd_wins_dns_proxy_query(struct nbt_name_socket *nbtsock, struct nbtd_interface); struct wins_dns_proxy_state *s; struct composite_context *creq; - const char *methods[] = { - "host", - NULL - }; + struct resolve_context *resolve_ctx; s = talloc(nbtsock, struct wins_dns_proxy_state); if (!s) goto failed; @@ -86,7 +83,11 @@ void nbtd_wins_dns_proxy_query(struct nbt_name_socket *nbtsock, goto failed; } - creq = resolve_name_send(name, iface->nbtsrv->task->event_ctx, methods); + resolve_ctx = resolve_context_init(s); + if (resolve_ctx == NULL) goto failed; + resolve_context_add_host_method(resolve_ctx); + + creq = resolve_name_send(resolve_ctx, name, iface->nbtsrv->task->event_ctx); if (!creq) goto failed; creq->async.fn = nbtd_wins_dns_proxy_handler; diff --git a/source4/nbt_server/wins/wins_ldb.c b/source4/nbt_server/wins/wins_ldb.c index 7caab34aaa..47aa415667 100644 --- a/source4/nbt_server/wins/wins_ldb.c +++ b/source4/nbt_server/wins/wins_ldb.c @@ -90,7 +90,9 @@ static int wins_ldb_init(struct ldb_module *ctx) owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner"); if (!owner) { - owner = iface_n_ip(lp_ctx, 0); + struct interface *ifaces; + load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces); + owner = iface_n_ip(ifaces, 0); if (!owner) { owner = "0.0.0.0"; } diff --git a/source4/nbt_server/wins/winsclient.c b/source4/nbt_server/wins/winsclient.c index 046be28515..1d07f4a60a 100644 --- a/source4/nbt_server/wins/winsclient.c +++ b/source4/nbt_server/wins/winsclient.c @@ -141,6 +141,7 @@ static void nbtd_wins_refresh(struct event_context *ev, struct timed_event *te, /* setup a wins name refresh request */ io.in.name = iname->name; io.in.wins_servers = str_list_make(tmp_ctx, iname->wins_server, NULL); + io.in.wins_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx); io.in.addresses = nbtd_address_list(iface, tmp_ctx); io.in.nb_flags = iname->nb_flags; io.in.ttl = iname->ttl; @@ -236,6 +237,7 @@ void nbtd_winsclient_register(struct nbtd_iface_name *iname) /* setup a wins name register request */ io.in.name = iname->name; + io.in.wins_port = lp_nbt_port(iname->iface->nbtsrv->task->lp_ctx); io.in.wins_servers = lp_wins_server_list(iname->iface->nbtsrv->task->lp_ctx); io.in.addresses = nbtd_address_list(iface, iname); io.in.nb_flags = iname->nb_flags; diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c index 428b154731..7de5bba468 100644 --- a/source4/nbt_server/wins/winsdb.c +++ b/source4/nbt_server/wins/winsdb.c @@ -1011,10 +1011,10 @@ failed: } struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + const char *owner, enum winsdb_handle_caller caller) { struct winsdb_handle *h = NULL; - const char *owner; unsigned int flags = 0; bool ret; int ldb_err; @@ -1033,11 +1033,6 @@ struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx, struct loadparm_contex h->caller = caller; h->hook_script = lp_wins_hook(lp_ctx); - owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner"); - if (!owner) { - owner = iface_n_ip(lp_ctx, 0); - } - h->local_owner = talloc_strdup(h, owner); if (!h->local_owner) goto failed; diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c index 98262a2f84..f116c45898 100644 --- a/source4/nbt_server/wins/winsserver.c +++ b/source4/nbt_server/wins/winsserver.c @@ -33,6 +33,7 @@ #include "lib/socket/netif.h" #include "lib/ldb/include/ldb.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" /* work out the ttl we will use given a client requested ttl @@ -377,6 +378,7 @@ static void wins_register_wack(struct nbt_name_socket *nbtsock, if (talloc_reference(s, src) == NULL) goto failed; s->io.in.nbtd_server = iface->nbtsrv; + s->io.in.nbt_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx); s->io.in.event_ctx = iface->nbtsrv->task->event_ctx; s->io.in.name = rec->name; s->io.in.num_addresses = winsdb_addr_list_length(rec->addresses); @@ -958,6 +960,7 @@ void nbtd_winsserver_request(struct nbt_name_socket *nbtsock, NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv) { uint32_t tmp; + const char *owner; if (!lp_wins_support(nbtsrv->task->lp_ctx)) { nbtsrv->winssrv = NULL; @@ -974,8 +977,16 @@ NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv) tmp = lp_parm_int(nbtsrv->task->lp_ctx, NULL, "wreplsrv"," tombstone_timeout", 1*24*60*60); nbtsrv->winssrv->config.tombstone_timeout = tmp; + owner = lp_parm_string(nbtsrv->task->lp_ctx, NULL, "winsdb", "local_owner"); + + if (owner == NULL) { + struct interface *ifaces; + load_interfaces(nbtsrv->task, lp_interfaces(nbtsrv->task->lp_ctx), &ifaces); + owner = iface_n_ip(ifaces, 0); + } + nbtsrv->winssrv->wins_db = winsdb_connect(nbtsrv->winssrv, nbtsrv->task->lp_ctx, - WINSDB_HANDLE_CALLER_NBTD); + owner, WINSDB_HANDLE_CALLER_NBTD); if (!nbtsrv->winssrv->wins_db) { return NT_STATUS_INTERNAL_DB_ERROR; } diff --git a/source4/nbt_server/wins/winsserver.h b/source4/nbt_server/wins/winsserver.h index 15dd4bd3db..edb924c1e3 100644 --- a/source4/nbt_server/wins/winsserver.h +++ b/source4/nbt_server/wins/winsserver.h @@ -51,6 +51,7 @@ struct wins_server { struct wins_challenge_io { struct { struct nbtd_server *nbtd_server; + uint16_t nbt_port; struct event_context *event_ctx; struct nbt_name *name; uint32_t num_addresses; diff --git a/source4/nbt_server/wins/winswack.c b/source4/nbt_server/wins/winswack.c index 82b16bb20d..929155c842 100644 --- a/source4/nbt_server/wins/winswack.c +++ b/source4/nbt_server/wins/winswack.c @@ -27,6 +27,7 @@ #include "system/time.h" #include "libcli/composite/composite.h" #include "param/param.h" +#include "smbd/service_task.h" struct wins_challenge_state { struct wins_challenge_io *io; @@ -47,7 +48,7 @@ static void wins_challenge_handler(struct nbt_name_request *req) if (state->current_address < state->io->in.num_addresses) { struct nbtd_interface *iface; - state->query.in.dest_port = lp_nbt_port(global_loadparm); + state->query.in.dest_port = state->io->in.nbt_port; state->query.in.dest_addr = state->io->in.addresses[state->current_address]; iface = nbtd_find_request_iface(state->io->in.nbtd_server, state->query.in.dest_addr, true); @@ -105,7 +106,7 @@ struct composite_context *wins_challenge_send(TALLOC_CTX *mem_ctx, struct wins_c /* setup a name query to the first address */ state->query.in.name = *state->io->in.name; - state->query.in.dest_port = lp_nbt_port(global_loadparm); + state->query.in.dest_port = state->io->in.nbt_port; state->query.in.dest_addr = state->io->in.addresses[state->current_address]; state->query.in.broadcast = false; state->query.in.wins_lookup = true; @@ -162,6 +163,7 @@ static void wins_release_demand_handler(struct nbt_name_request *req) if (state->current_address < state->io->in.num_addresses) { struct nbtd_interface *iface; + state->release.in.dest_port = lp_nbt_port(state->io->in.nbtd_server->task->lp_ctx); state->release.in.dest_addr = state->io->in.addresses[state->current_address]; state->release.in.address = state->release.in.dest_addr; state->release.in.timeout = (state->addresses_left > 1 ? 2 : 1); @@ -221,6 +223,7 @@ static struct composite_context *wins_release_demand_send(TALLOC_CTX *mem_ctx, s * with 2 retries */ state->release.in.name = *state->io->in.name; + state->release.in.dest_port = lp_nbt_port(state->io->in.nbtd_server->task->lp_ctx); state->release.in.dest_addr = state->io->in.addresses[state->current_address]; state->release.in.address = state->release.in.dest_addr; state->release.in.broadcast = false; @@ -303,6 +306,7 @@ NTSTATUS nbtd_proxy_wins_challenge(struct irpc_message *msg, s->req = req; s->io.in.nbtd_server = nbtd_server; + s->io.in.nbt_port = lp_nbt_port(global_loadparm); s->io.in.event_ctx = msg->ev; s->io.in.name = &req->in.name; s->io.in.num_addresses = req->in.num_addrs; diff --git a/source4/nsswitch/winbind_struct_protocol.h b/source4/nsswitch/winbind_struct_protocol.h index 0e3ad8bcaf..33797e2254 100644 --- a/source4/nsswitch/winbind_struct_protocol.h +++ b/source4/nsswitch/winbind_struct_protocol.h @@ -246,7 +246,7 @@ struct winbindd_request { character is. */ fstring user; fstring pass; - pstring require_membership_of_sid; + char require_membership_of_sid[1024]; fstring krb5_cc_type; uid_t uid; } auth; /* pam_winbind auth module */ diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 152a4056c5..9426355ecb 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -180,7 +180,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, if (domain) { cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED); } - status = cli_credentials_set_machine_account(credentials); + status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -194,7 +194,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, /* connect to the server, using the smbd event context */ io.in.dest_host = host; - io.in.port = 0; + io.in.dest_ports = lp_smb_ports(ntvfs->ctx->lp_ctx); io.in.called_name = host; io.in.credentials = credentials; io.in.fallback_to_anonymous = false; diff --git a/source4/ntvfs/common/notify.c b/source4/ntvfs/common/notify.c index 16cf4e4b54..8bbf2d04b3 100644 --- a/source4/ntvfs/common/notify.c +++ b/source4/ntvfs/common/notify.c @@ -35,6 +35,7 @@ #include "ntvfs/common/ntvfs_common.h" #include "ntvfs/sysdep/sys_notify.h" #include "cluster/cluster.h" +#include "param/param.h" struct notify_context { struct tdb_wrap *w; @@ -81,6 +82,7 @@ static int notify_destructor(struct notify_context *notify) */ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, struct messaging_context *messaging_ctx, + struct loadparm_context *lp_ctx, struct event_context *ev, struct share_config *scfg) { @@ -95,7 +97,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, return NULL; } - notify->w = cluster_tdb_tmp_open(notify, "notify.tdb", TDB_SEQNUM); + notify->w = cluster_tdb_tmp_open(notify, lp_ctx, "notify.tdb", TDB_SEQNUM); if (notify->w == NULL) { talloc_free(notify); return NULL; diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index b8b8a5cb33..41b5ad2ebe 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -79,7 +79,7 @@ static struct odb_context *odb_tdb_init(TALLOC_CTX *mem_ctx, return NULL; } - odb->w = cluster_tdb_tmp_open(odb, "openfiles.tdb", TDB_DEFAULT); + odb->w = cluster_tdb_tmp_open(odb, ntvfs_ctx->lp_ctx, "openfiles.tdb", TDB_DEFAULT); if (odb->w == NULL) { talloc_free(odb); return NULL; diff --git a/source4/ntvfs/ipc/ipc_rap.c b/source4/ntvfs/ipc/ipc_rap.c index d8e9812dd8..85bc5c212f 100644 --- a/source4/ntvfs/ipc/ipc_rap.c +++ b/source4/ntvfs/ipc/ipc_rap.c @@ -23,6 +23,7 @@ #include "libcli/rap/rap.h" #include "ntvfs/ipc/proto.h" #include "librpc/ndr/libndr.h" +#include "param/param.h" #define NDR_RETURN(call) do { \ enum ndr_err_code _ndr_err; \ @@ -115,10 +116,10 @@ static struct rap_call *new_rap_srv_call(TALLOC_CTX *mem_ctx, call->mem_ctx = mem_ctx; - call->ndr_pull_param = ndr_pull_init_blob(&trans->in.params, mem_ctx); + call->ndr_pull_param = ndr_pull_init_blob(&trans->in.params, mem_ctx, lp_iconv_convenience(global_loadparm)); call->ndr_pull_param->flags = RAPNDR_FLAGS; - call->ndr_pull_data = ndr_pull_init_blob(&trans->in.data, mem_ctx); + call->ndr_pull_data = ndr_pull_init_blob(&trans->in.data, mem_ctx, lp_iconv_convenience(global_loadparm)); call->ndr_pull_data->flags = RAPNDR_FLAGS; call->heap = talloc(mem_ctx, struct rap_string_heap); @@ -444,8 +445,8 @@ NTSTATUS ipc_rap_call(TALLOC_CTX *mem_ctx, struct smb_trans2 *trans) NDR_RETURN(ndr_pull_string(call->ndr_pull_param, NDR_SCALARS, &call->datadesc)); - call->ndr_push_param = ndr_push_init_ctx(call); - call->ndr_push_data = ndr_push_init_ctx(call); + call->ndr_push_param = ndr_push_init_ctx(call, lp_iconv_convenience(global_loadparm)); + call->ndr_push_data = ndr_push_init_ctx(call, lp_iconv_convenience(global_loadparm)); if ((call->ndr_push_param == NULL) || (call->ndr_push_data == NULL)) return NT_STATUS_NO_MEMORY; @@ -470,8 +471,8 @@ NTSTATUS ipc_rap_call(TALLOC_CTX *mem_ctx, struct smb_trans2 *trans) result_param = ndr_push_blob(call->ndr_push_param); result_data = ndr_push_blob(call->ndr_push_data); - final_param = ndr_push_init_ctx(call); - final_data = ndr_push_init_ctx(call); + final_param = ndr_push_init_ctx(call, lp_iconv_convenience(global_loadparm)); + final_data = ndr_push_init_ctx(call, lp_iconv_convenience(global_loadparm)); if ((final_param == NULL) || (final_data == NULL)) return NT_STATUS_NO_MEMORY; diff --git a/source4/ntvfs/ipc/rap_server.c b/source4/ntvfs/ipc/rap_server.c index d1a4dd9edc..7d3020a259 100644 --- a/source4/ntvfs/ipc/rap_server.c +++ b/source4/ntvfs/ipc/rap_server.c @@ -23,6 +23,7 @@ #include "libcli/rap/rap.h" #include "librpc/gen_ndr/srvsvc.h" #include "rpc_server/common/common.h" +#include "param/param.h" /* At this moment these are just dummy functions, but you might get the * idea. */ @@ -40,7 +41,7 @@ NTSTATUS rap_netshareenum(TALLOC_CTX *mem_ctx, r->out.available = 0; r->out.info = NULL; - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(global_loadparm), global_loadparm, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return nterr; } diff --git a/source4/ntvfs/ntvfs_base.c b/source4/ntvfs/ntvfs_base.c index 3873afbdfa..28f43eabe8 100644 --- a/source4/ntvfs/ntvfs_base.c +++ b/source4/ntvfs/ntvfs_base.c @@ -201,8 +201,14 @@ NTSTATUS ntvfs_init_connection(TALLOC_CTX *mem_ctx, struct share_config *scfg, e NTSTATUS ntvfs_init(struct loadparm_context *lp_ctx) { + static bool initialized = false; init_module_fn static_init[] = STATIC_ntvfs_MODULES; - init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "ntvfs"); + init_module_fn *shared_init; + + if (initialized) return NT_STATUS_OK; + initialized = true; + + shared_init = load_samba_modules(NULL, lp_ctx, "ntvfs"); run_init_functions(static_init); run_init_functions(shared_init); diff --git a/source4/ntvfs/posix/pvfs_rename.c b/source4/ntvfs/posix/pvfs_rename.c index 5c351b2df2..3b9842db7f 100644 --- a/source4/ntvfs/posix/pvfs_rename.c +++ b/source4/ntvfs/posix/pvfs_rename.c @@ -22,6 +22,7 @@ #include "includes.h" #include "vfs_posix.h" #include "librpc/gen_ndr/security.h" +#include "param/param.h" /* @@ -107,16 +108,16 @@ static const char *pvfs_resolve_wildcard_component(TALLOC_CTX *mem_ctx, while (*p2) { codepoint_t c1, c2; size_t c_size1, c_size2; - c1 = next_codepoint(global_smb_iconv_convenience, p1, &c_size1); - c2 = next_codepoint(global_smb_iconv_convenience, p2, &c_size2); + c1 = next_codepoint(lp_iconv_convenience(global_loadparm), p1, &c_size1); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), p2, &c_size2); if (c2 == '?') { - d += push_codepoint(global_smb_iconv_convenience, d, c1); + d += push_codepoint(lp_iconv_convenience(global_loadparm), d, c1); } else if (c2 == '*') { memcpy(d, p1, strlen(p1)); d += strlen(p1); break; } else { - d += push_codepoint(global_smb_iconv_convenience, d, c2); + d += push_codepoint(lp_iconv_convenience(global_loadparm), d, c2); } p1 += c_size1; diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c index f1d701b343..949fa131a4 100644 --- a/source4/ntvfs/posix/pvfs_resolve.c +++ b/source4/ntvfs/posix/pvfs_resolve.c @@ -29,8 +29,9 @@ #include "includes.h" #include "vfs_posix.h" #include "system/dir.h" +#include "param/param.h" -/* +/** compare two filename components. This is where the name mangling hook will go */ static int component_compare(struct pvfs_state *pvfs, const char *comp, const char *name) @@ -256,7 +257,7 @@ static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name, while (*p) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, p, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), p, &c_size); switch (c) { case '\\': if (name->has_wildcard) { @@ -340,7 +341,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, const char **fname, uint_t if (s == NULL) return NT_STATUS_NO_MEMORY; for (num_components=1, p=s; *p; p += c_size) { - c = next_codepoint(global_smb_iconv_convenience, p, &c_size); + c = next_codepoint(lp_iconv_convenience(global_loadparm), p, &c_size); if (c == '\\') num_components++; } @@ -352,7 +353,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, const char **fname, uint_t components[0] = s; for (i=0, p=s; *p; p += c_size) { - c = next_codepoint(global_smb_iconv_convenience, p, &c_size); + c = next_codepoint(lp_iconv_convenience(global_loadparm), p, &c_size); if (c == '\\') { *p = 0; components[++i] = p+1; diff --git a/source4/ntvfs/posix/pvfs_shortname.c b/source4/ntvfs/posix/pvfs_shortname.c index 68e415000e..083a281819 100644 --- a/source4/ntvfs/posix/pvfs_shortname.c +++ b/source4/ntvfs/posix/pvfs_shortname.c @@ -388,7 +388,7 @@ static bool is_legal_name(struct pvfs_mangle_context *ctx, const char *name) { while (*name) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, name, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), name, &c_size); if (c == INVALID_CODEPOINT) { return false; } diff --git a/source4/ntvfs/posix/pvfs_util.c b/source4/ntvfs/posix/pvfs_util.c index b7cba00d9b..b52c3e387b 100644 --- a/source4/ntvfs/posix/pvfs_util.c +++ b/source4/ntvfs/posix/pvfs_util.c @@ -22,6 +22,7 @@ #include "includes.h" #include "vfs_posix.h" +#include "param/param.h" /* return true if a string contains one of the CIFS wildcard characters @@ -181,7 +182,7 @@ uint32_t pvfs_name_hash(const char *key, size_t length) while (*key && length--) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, key, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), key, &c_size); c = toupper_w(c); value *= fnv1_prime; value ^= (uint32_t)c; diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c index 8e5e5a6942..e058e6f546 100644 --- a/source4/ntvfs/posix/vfs_posix.c +++ b/source4/ntvfs/posix/vfs_posix.c @@ -214,6 +214,7 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs, pvfs->notify_context = notify_init(pvfs, pvfs->ntvfs->ctx->server_id, pvfs->ntvfs->ctx->msg_ctx, + pvfs->ntvfs->ctx->lp_ctx, event_context_find(pvfs), pvfs->ntvfs->ctx->config); diff --git a/source4/ntvfs/print/vfs_print.c b/source4/ntvfs/print/vfs_print.c index 5fdb7aada6..aa9b11a973 100644 --- a/source4/ntvfs/print/vfs_print.c +++ b/source4/ntvfs/print/vfs_print.c @@ -83,8 +83,8 @@ static NTSTATUS print_ioctl(struct ntvfs_module_context *ntvfs, p = (char *)io->ioctl.out.blob.data; SSVAL(p,0, 1 /* REWRITE: fsp->rap_print_jobid */); - push_string(global_smb_iconv_convenience, p+2, lp_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII); - push_string(global_smb_iconv_convenience, p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII); + push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p+2, lp_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII); + push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII); return NT_STATUS_OK; } diff --git a/source4/param/config.mk b/source4/param/config.mk index 24feec12bd..b28f6639c0 100644 --- a/source4/param/config.mk +++ b/source4/param/config.mk @@ -8,7 +8,7 @@ OBJ_FILES = loadparm.o \ util.o \ ../lib/version.o PUBLIC_DEPENDENCIES = LIBSAMBA-UTIL -PRIVATE_DEPENDENCIES = DYNCONFIG +PRIVATE_DEPENDENCIES = DYNCONFIG LIBREPLACE_EXT CHARSET PUBLIC_PROTO_HEADER = proto.h PUBLIC_HEADERS = param.h @@ -41,10 +41,14 @@ PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL SUBSYSTEM = share INIT_FUNCTION = share_ldb_init OBJ_FILES = share_ldb.o -PRIVATE_DEPENDENCIES = LIBLDB +PRIVATE_DEPENDENCIES = LIBLDB LDB_WRAP # End MODULE share_ldb ################################################ [SUBSYSTEM::SECRETS] OBJ_FILES = secrets.o -PRIVATE_DEPENDENCIES = LIBLDB TDB_WRAP UTIL_TDB +PRIVATE_DEPENDENCIES = LIBLDB TDB_WRAP UTIL_TDB NDR_SECURITY + +[PYTHON::param] +SWIG_FILE = param.i +PRIVATE_DEPENDENCIES = LIBSAMBA-CONFIG diff --git a/source4/param/generic.c b/source4/param/generic.c index f706dd6407..2327000fc9 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -49,7 +49,7 @@ struct param_opt *param_section_get(struct param_section *section, return NULL; } -struct param_opt *param_get (struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get (struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section = param_get_section(ctx, section_name); if (section == NULL) @@ -58,8 +58,20 @@ struct param_opt *param_get (struct param_context *ctx, const char *section_name return param_section_get(section, name); } +struct param_section *param_add_section(struct param_context *ctx, const char *section_name) +{ + struct param_section *section; + section = talloc_zero(ctx, struct param_section); + if (section == NULL) + return NULL; + + section->name = talloc_strdup(section, section_name); + DLIST_ADD_END(ctx->sections, section, struct param_section *); + return section; +} + /* Look up parameter. If it is not found, add it */ -static struct param_opt *param_get_add(struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get_add(struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section; struct param_opt *p; @@ -70,12 +82,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se section = param_get_section(ctx, section_name); if (section == NULL) { - section = talloc_zero(ctx, struct param_section); - if (section == NULL) - return NULL; - - section->name = talloc_strdup(section, section_name); - DLIST_ADD_END(ctx->sections, section, struct param_section *); + section = param_add_section(ctx, section_name); } p = param_section_get(section, name); @@ -91,9 +98,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se return p; } -const char *param_get_string(struct param_context *ctx, const char *section, const char *param) +const char *param_get_string(struct param_context *ctx, const char *param, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -101,9 +108,9 @@ const char *param_get_string(struct param_context *ctx, const char *section, con return p->value; } -int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) +int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); if (p == NULL) return -1; @@ -113,10 +120,9 @@ int param_set_string(struct param_context *ctx, const char *section, const char return 0; } -const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, - const char *separator) +const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -127,18 +133,18 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio return str_list_make(ctx, p->value, separator); } -int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) +int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); p->value = str_list_join(p, list, ' '); return 0; } -int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v) +int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtol(value, NULL, 0); @@ -146,7 +152,7 @@ int param_get_int(struct param_context *ctx, const char *section, const char *pa return default_v; } -void param_set_int(struct param_context *ctx, const char *section, const char *param, int value) +void param_set_int(struct param_context *ctx, const char *param, int value, const char *section) { struct param_opt *p = param_get_add(ctx, section, param); @@ -156,9 +162,9 @@ void param_set_int(struct param_context *ctx, const char *section, const char *p p->value = talloc_asprintf(p, "%d", value); } -unsigned long param_get_ulong(struct param_context *ctx, const char *section, const char *param, unsigned long default_v) +unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtoul(value, NULL, 0); @@ -166,9 +172,9 @@ unsigned long param_get_ulong(struct param_context *ctx, const char *section, co return default_v; } -void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value) +void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, name); + struct param_opt *p = param_get_add(ctx, name, section); if (!p) return; diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index 564dede3a5..51d4beb0ae 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -531,6 +531,7 @@ struct loadparm_context { time_t modtime; } *file_lists; unsigned int flags[NUMPARAMETERS]; + struct smb_iconv_convenience *iconv_convenience; }; @@ -610,7 +611,7 @@ static const char *lp_string(const char *s) char fn_name(void) {return(*(char *)(ptr));} #endif #define FN_GLOBAL_INTEGER(fn_name,var_name) \ - int fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return 0; return lp_ctx->globals->var_name;} + int fn_name(struct loadparm_context *lp_ctx) {return lp_ctx->globals->var_name;} #define FN_LOCAL_STRING(fn_name,val) \ const char *fn_name(struct loadparm_service *service) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault.val)));} @@ -763,6 +764,9 @@ const char *lp_get_parametric(struct loadparm_context *lp_ctx, { char *vfskey; struct param_opt *data; + + if (lp_ctx == NULL) + return NULL; data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt); @@ -858,9 +862,11 @@ static bool lp_bool(const char *s) } -/* Return parametric option from a given service. Type is a part of option before ':' */ -/* Parametric option has following syntax: 'Type: option = value' */ -/* Returned value is allocated in 'lp_talloc' context */ +/** + * Return parametric option from a given service. Type is a part of option before ':' + * Parametric option has following syntax: 'Type: option = value' + * Returned value is allocated in 'lp_talloc' context + */ const char *lp_parm_string(struct loadparm_context *lp_ctx, struct loadparm_service *service, const char *type, @@ -874,9 +880,11 @@ const char *lp_parm_string(struct loadparm_context *lp_ctx, return NULL; } -/* Return parametric option from a given service. Type is a part of option before ':' */ -/* Parametric option has following syntax: 'Type: option = value' */ -/* Returned value is allocated in 'lp_talloc' context */ +/** + * Return parametric option from a given service. Type is a part of option before ':' + * Parametric option has following syntax: 'Type: option = value' + * Returned value is allocated in 'lp_talloc' context + */ const char **lp_parm_string_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, @@ -892,8 +900,10 @@ const char **lp_parm_string_list(TALLOC_CTX *mem_ctx, return NULL; } -/* Return parametric option from a given service. Type is a part of option before ':' */ -/* Parametric option has following syntax: 'Type: option = value' */ +/** + * Return parametric option from a given service. Type is a part of option before ':' + * Parametric option has following syntax: 'Type: option = value' + */ int lp_parm_int(struct loadparm_context *lp_ctx, struct loadparm_service *service, const char *type, @@ -907,7 +917,8 @@ int lp_parm_int(struct loadparm_context *lp_ctx, return default_v; } -/* Return parametric option from a given service. Type is a part of +/** + * Return parametric option from a given service. Type is a part of * option before ':'. * Parametric option has following syntax: 'Type: option = value'. */ @@ -929,9 +940,11 @@ int lp_parm_bytes(struct loadparm_context *lp_ctx, return default_v; } -/* Return parametric option from a given service. Type is a part of option before ':' */ -/* Parametric option has following syntax: 'Type: option = value' */ - +/** + * Return parametric option from a given service. + * Type is a part of option before ':' + * Parametric option has following syntax: 'Type: option = value' + */ unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx, struct loadparm_service *service, const char *type, const char *option, unsigned long default_v) @@ -957,8 +970,10 @@ double lp_parm_double(struct loadparm_context *lp_ctx, return default_v; } -/* Return parametric option from a given service. Type is a part of option before ':' */ -/* Parametric option has following syntax: 'Type: option = value' */ +/** + * Return parametric option from a given service. Type is a part of option before ':' + * Parametric option has following syntax: 'Type: option = value' + */ bool lp_parm_bool(struct loadparm_context *lp_ctx, struct loadparm_service *service, const char *type, @@ -986,9 +1001,9 @@ static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx) } /** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ + * Set a string value, deallocating any existing space, and allocing the space + * for the string + */ static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src) { talloc_free(*dest); @@ -2252,7 +2267,12 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx) parm_table[i].type == P_USTRING) && parm_table[i].offset != -1 && !(lp_ctx->flags[i] & FLAG_CMDLINE)) { - char **r = ((char *)(parm_table[i].class == P_LOCAL)?&sDefault:lp_ctx->globals) + parm_table[i].offset; + char **r; + if (parm_table[i].class == P_LOCAL) { + r = (char **)(((char *)&sDefault) + parm_table[i].offset); + } else { + r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset); + } *r = talloc_strdup(lp_ctx, ""); } } @@ -2270,7 +2290,7 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx) myname = get_myname(); lp_do_global_parameter(lp_ctx, "netbios name", myname); SAFE_FREE(myname); - lp_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast"); + lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast"); lp_do_global_parameter(lp_ctx, "fstype", FSTYPE_STRING); lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default"); @@ -2442,7 +2462,13 @@ bool lp_load(struct loadparm_context *lp_ctx, const char *filename) panic_action = lp_ctx->globals->panic_action; - reload_charcnv(); + reload_charcnv(lp_ctx); + + /* FIXME: Check locale in environment for this: */ + if (strcmp(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx)) != 0) + d_set_iconv(smb_iconv_open(lp_display_charset(lp_ctx), lp_unix_charset(lp_ctx))); + else + d_set_iconv((smb_iconv_t)-1); return bRetval; } @@ -2499,7 +2525,7 @@ struct loadparm_service *lp_service(struct loadparm_context *lp_ctx, { int iService; char *serviceName; - + for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) { if (lp_ctx->services[iService] && lp_ctx->services[iService]->szService) { @@ -2556,3 +2582,21 @@ int lp_maxprintjobs(struct loadparm_service *service) return maxjobs; } + +struct smb_iconv_convenience *lp_iconv_convenience(struct loadparm_context *lp_ctx) +{ + if (lp_ctx == NULL) { + static struct smb_iconv_convenience *fallback_ic = NULL; + if (fallback_ic == NULL) + fallback_ic = smb_iconv_convenience_init(talloc_autofree_context(), + "CP850", "UTF8", true); + return fallback_ic; + } + return lp_ctx->iconv_convenience; +} + +_PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx) +{ + talloc_free(lp_ctx->iconv_convenience); + lp_ctx->iconv_convenience = smb_iconv_convenience_init_lp(lp_ctx, lp_ctx); +} diff --git a/source4/param/param.i b/source4/param/param.i new file mode 100644 index 0000000000..dca2496f94 --- /dev/null +++ b/source4/param/param.i @@ -0,0 +1,231 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +%module(package="samba.param") param + +%{ +#include <stdint.h> +#include <stdbool.h> + +#include "includes.h" +#include "param/param.h" +#include "param/loadparm.h" + +typedef struct param_context param; +typedef struct loadparm_context loadparm_context; +typedef struct loadparm_service loadparm_service; +typedef struct param_section param_section; +typedef struct param_opt param_opt; +%} + +%import "stdint.i" +%import "carrays.i" +%import "typemaps.i" +%import "../lib/talloc/talloc.i" + +%typemap(default) struct loadparm_context * { + $1 = loadparm_init(NULL); +} + +%rename(LoadParm) loadparm_context; + +%talloctype(loadparm_context); + +typedef struct loadparm_context { + %extend { + loadparm_context(TALLOC_CTX *mem_ctx) { return loadparm_init(mem_ctx); } + bool load(const char *filename) { return lp_load($self, filename); } +#ifdef SWIGPYTHON + int __len__() { return lp_numservices($self); } + struct loadparm_service *__getitem__(const char *name) { return lp_service($self, name); } +#endif + const char *configfile() { return lp_configfile($self); } + bool is_mydomain(const char *domain) { return lp_is_mydomain($self, domain); } + bool is_myname(const char *name) { return lp_is_myname($self, name); } + int use(struct param_context *param) { return param_use($self, param); } + bool set(const char *parm_name, const char *parm_value) { + return lp_set_cmdline($self, parm_name, parm_value); + } + + PyObject *get(const char *param_name, const char *service_name) + { + struct parm_struct *parm = NULL; + void *parm_ptr = NULL; + int i; + + if (service_name != NULL) { + struct loadparm_service *service; + /* its a share parameter */ + service = lp_service($self, service_name); + if (service == NULL) { + return Py_None; + } + if (strchr(param_name, ':')) { + /* its a parametric option on a share */ + const char *type = talloc_strndup($self, + param_name, + strcspn(param_name, ":")); + const char *option = strchr(param_name, ':') + 1; + const char *value; + if (type == NULL || option == NULL) { + return Py_None; + } + value = lp_get_parametric($self, service, type, option); + if (value == NULL) { + return Py_None; + } + return PyString_FromString(value); + } + + parm = lp_parm_struct(param_name); + if (parm == NULL || parm->class == P_GLOBAL) { + return Py_None; + } + parm_ptr = lp_parm_ptr($self, service, parm); + } else if (strchr(param_name, ':')) { + /* its a global parametric option */ + const char *type = talloc_strndup($self, + param_name, strcspn(param_name, ":")); + const char *option = strchr(param_name, ':') + 1; + const char *value; + if (type == NULL || option == NULL) { + return Py_None; + } + value = lp_get_parametric($self, NULL, type, option); + if (value == NULL) + return Py_None; + return PyString_FromString(value); + } else { + /* its a global parameter */ + parm = lp_parm_struct(param_name); + if (parm == NULL) { + return Py_None; + } + parm_ptr = lp_parm_ptr($self, NULL, parm); + } + + if (parm == NULL || parm_ptr == NULL) { + return Py_None; + } + + /* construct and return the right type of python object */ + switch (parm->type) { + case P_STRING: + case P_USTRING: + return PyString_FromString(*(char **)parm_ptr); + case P_BOOL: + return PyBool_FromLong(*(bool *)parm_ptr); + case P_INTEGER: + case P_OCTAL: + case P_BYTES: + return PyLong_FromLong(*(int *)parm_ptr); + case P_ENUM: + for (i=0; parm->enum_list[i].name; i++) { + if (*(int *)parm_ptr == parm->enum_list[i].value) { + return PyString_FromString(parm->enum_list[i].name); + } + } + return Py_None; + case P_LIST: + { + int i; + const char **strlist = *(const char ***)parm_ptr; + PyObject *pylist = PyList_New(str_list_length(strlist)); + for (i = 0; strlist[i]; i++) + PyList_SetItem(pylist, i, + PyString_FromString(strlist[i])); + return pylist; + } + + break; + } + return Py_None; + } + } +} loadparm_context; + +%nodefaultctor loadparm_service; +%nodefaultdtor loadparm_service; + +typedef struct loadparm_service { + %extend { + const char *volume_label() { return volume_label($self); } + const char *printername() { return lp_printername($self); } + int maxprintjobs() { return lp_maxprintjobs($self); } + } +} loadparm_service; + +%rename(ParamFile) param_context; + +%talloctype(param_context); +typedef struct param_context { + %extend { + param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); } + struct param_section *get_section(const char *name); + struct param_section *add_section(const char *name); + struct param_opt *get(const char *name, const char *section_name="global"); + const char *get_string(const char *name, const char *section_name="global"); + int set_string(const char *param, const char *value, const char *section="global"); + int set(const char *param, PyObject *ob, const char *section_name="global") + { + struct param_opt *opt = param_get_add($self, param, section_name); + + talloc_free(opt->value); + opt->value = talloc_strdup(opt, PyObject_Str(ob)); + + return 0; + } + + int read(const char *fn); + int write(const char *fn); + } + %pythoncode { + def __getitem__(self, name): + ret = self.get_section(name) + if ret is None: + raise KeyError("No such section %s" % name) + return ret + } +} param; + +%talloctype(param_opt); + +typedef struct param_opt { + %extend { +#ifdef SWIGPYTHON + const char *__str__() { return $self->value; } +#endif + } +} param_opt; + +%talloctype(param); +typedef struct param_section { + %extend { + struct param_opt *get(const char *name); + } + %pythoncode { + def __getitem__(self, name): + ret = self.get(name) + if ret is None: + raise KeyError("No such option %s" % name) + return ret + } +} param_section; + +%rename(default_config) global_loadparm; +struct loadparm_context *global_loadparm; diff --git a/source4/param/param.py b/source4/param/param.py new file mode 100644 index 0000000000..291459b9b6 --- /dev/null +++ b/source4/param/param.py @@ -0,0 +1,138 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 1.3.33 +# +# Don't modify this file, modify the SWIG interface instead. + +import _param +import new +new_instancemethod = new.instancemethod +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'PySwigObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError,name + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +import types +try: + _object = types.ObjectType + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 +del types + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class LoadParm(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self, *args, **kwargs): + _param.LoadParm_swiginit(self,_param.new_LoadParm(*args, **kwargs)) + __swig_destroy__ = _param.delete_LoadParm +LoadParm.load = new_instancemethod(_param.LoadParm_load,None,LoadParm) +LoadParm.__len__ = new_instancemethod(_param.LoadParm___len__,None,LoadParm) +LoadParm.__getitem__ = new_instancemethod(_param.LoadParm___getitem__,None,LoadParm) +LoadParm.configfile = new_instancemethod(_param.LoadParm_configfile,None,LoadParm) +LoadParm.is_mydomain = new_instancemethod(_param.LoadParm_is_mydomain,None,LoadParm) +LoadParm.is_myname = new_instancemethod(_param.LoadParm_is_myname,None,LoadParm) +LoadParm.use = new_instancemethod(_param.LoadParm_use,None,LoadParm) +LoadParm.set = new_instancemethod(_param.LoadParm_set,None,LoadParm) +LoadParm.get = new_instancemethod(_param.LoadParm_get,None,LoadParm) +LoadParm_swigregister = _param.LoadParm_swigregister +LoadParm_swigregister(LoadParm) + +class loadparm_service(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + def __init__(self): raise AttributeError, "No constructor defined" + __repr__ = _swig_repr +loadparm_service.volume_label = new_instancemethod(_param.loadparm_service_volume_label,None,loadparm_service) +loadparm_service.printername = new_instancemethod(_param.loadparm_service_printername,None,loadparm_service) +loadparm_service.maxprintjobs = new_instancemethod(_param.loadparm_service_maxprintjobs,None,loadparm_service) +loadparm_service_swigregister = _param.loadparm_service_swigregister +loadparm_service_swigregister(loadparm_service) + +class ParamFile(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self, *args, **kwargs): + _param.ParamFile_swiginit(self,_param.new_ParamFile(*args, **kwargs)) + def __getitem__(self, name): + ret = self.get_section(name) + if ret is None: + raise KeyError("No such section %s" % name) + return ret + + __swig_destroy__ = _param.delete_ParamFile +ParamFile.get_section = new_instancemethod(_param.ParamFile_get_section,None,ParamFile) +ParamFile.add_section = new_instancemethod(_param.ParamFile_add_section,None,ParamFile) +ParamFile.get = new_instancemethod(_param.ParamFile_get,None,ParamFile) +ParamFile.get_string = new_instancemethod(_param.ParamFile_get_string,None,ParamFile) +ParamFile.set_string = new_instancemethod(_param.ParamFile_set_string,None,ParamFile) +ParamFile.set = new_instancemethod(_param.ParamFile_set,None,ParamFile) +ParamFile.read = new_instancemethod(_param.ParamFile_read,None,ParamFile) +ParamFile.write = new_instancemethod(_param.ParamFile_write,None,ParamFile) +ParamFile_swigregister = _param.ParamFile_swigregister +ParamFile_swigregister(ParamFile) + +class param_opt(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + def __init__(self): raise AttributeError, "No constructor defined" + __repr__ = _swig_repr + __swig_destroy__ = _param.delete_param_opt +param_opt.__str__ = new_instancemethod(_param.param_opt___str__,None,param_opt) +param_opt_swigregister = _param.param_opt_swigregister +param_opt_swigregister(param_opt) + +class param_section(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __getitem__(self, name): + ret = self.get(name) + if ret is None: + raise KeyError("No such option %s" % name) + return ret + + def __init__(self, *args, **kwargs): + _param.param_section_swiginit(self,_param.new_param_section(*args, **kwargs)) + __swig_destroy__ = _param.delete_param_section +param_section.get = new_instancemethod(_param.param_section_get,None,param_section) +param_section_swigregister = _param.param_section_swigregister +param_section_swigregister(param_section) + + +cvar = _param.cvar + diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c new file mode 100644 index 0000000000..e66d8a2043 --- /dev/null +++ b/source4/param/param_wrap.c @@ -0,0 +1,4498 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.33 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +#define SWIGPYTHON +#define SWIG_PYTHON_NO_BUILD_NONE +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + + +/* Python.h has to appear first */ +#include <Python.h> + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic CAPI SWIG runtime support for pointer + * type checking. + * ----------------------------------------------------------------------------- */ + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "3" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +# define SWIG_QUOTE_STRING(x) #x +# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +# define SWIG_TYPE_TABLE_NAME +#endif + +/* + You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for + creating a static or dynamic library from the swig runtime code. + In 99.9% of the cases, swig just needs to declare them as 'static'. + + But only do this if is strictly necessary, ie, if you have problems + with your compiler or so. +*/ + +#ifndef SWIGRUNTIME +# define SWIGRUNTIME SWIGINTERN +#endif + +#ifndef SWIGRUNTIMEINLINE +# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE +#endif + +/* Generic buffer size */ +#ifndef SWIG_BUFFER_SIZE +# define SWIG_BUFFER_SIZE 1024 +#endif + +/* Flags for pointer conversions */ +#define SWIG_POINTER_DISOWN 0x1 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + The swig conversion methods, as ConvertPtr, return and integer + that tells if the conversion was successful or not. And if not, + an error code can be returned (see swigerrors.swg for the codes). + + Use the following macros/flags to set or process the returning + states. + + In old swig versions, you usually write code as: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit as: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + that seems to be the same, but now you can also do + + Type *ptr; + int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); + if (SWIG_IsOK(res)) { + // success code + if (SWIG_IsNewObj(res) { + ... + delete *ptr; + } else { + ... + } + } else { + // fail code + } + + I.e., now SWIG_ConvertPtr can return new objects and you can + identify the case and take care of the deallocation. Of course that + requires also to SWIG_ConvertPtr to return new result values, as + + int SWIG_ConvertPtr(obj, ptr,...) { + if (<obj is ok>) { + if (<need new object>) { + *ptr = <ptr to new allocated object>; + return SWIG_NEWOBJ; + } else { + *ptr = <ptr to old object>; + return SWIG_OLDOBJ; + } + } else { + return SWIG_BADOBJ; + } + } + + Of course, returning the plain '0(success)/-1(fail)' still works, but you can be + more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the + swig errors code. + + Finally, if the SWIG_CASTRANK_MODE is enabled, the result code + allows to return the 'cast rank', for example, if you have this + + int food(double) + int fooi(int); + + and you call + + food(1) // cast rank '1' (1 -> 1.0) + fooi(1) // cast rank '0' + + just use the SWIG_AddCast()/SWIG_CheckState() + + + */ +#define SWIG_OK (0) +#define SWIG_ERROR (-1) +#define SWIG_IsOK(r) (r >= 0) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* The CastRankLimit says how many bits are used for the cast rank */ +#define SWIG_CASTRANKLIMIT (1 << 8) +/* The NewMask denotes the object was created (using new/malloc) */ +#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) +/* The TmpMask is for in/out typemaps that use temporal objects */ +#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) +/* Simple returning values */ +#define SWIG_BADOBJ (SWIG_ERROR) +#define SWIG_OLDOBJ (SWIG_OK) +#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) +#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) +/* Check, add and del mask methods */ +#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) +#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) +#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) +#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) +#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) +#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) + + +/* Cast-Rank Mode */ +#if defined(SWIG_CASTRANK_MODE) +# ifndef SWIG_TypeRank +# define SWIG_TypeRank unsigned long +# endif +# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ +# define SWIG_MAXCASTRANK (2) +# endif +# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) +# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) +SWIGINTERNINLINE int SWIG_AddCast(int r) { + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; +} +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; +} +#else /* no cast-rank mode */ +# define SWIG_AddCast +# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) +#endif + + + + +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *(*swig_converter_func)(void *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store inforomation on one type */ +typedef struct swig_type_info { + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ +} swig_type_info; + +/* Structure to store a type and conversion function used for casting */ +typedef struct swig_cast_info { + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ +} swig_cast_info; + +/* Structure used to store module information + * Each module generates one structure like this, and the runtime collects + * all of these structures and stores them in a circularly linked list.*/ +typedef struct swig_module_info { + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ +} swig_module_info; + +/* + Compare two type names skipping the space characters, therefore + "char*" == "char *" and "Class<int>" == "Class<int >", etc. + + Return 0 when the two name types are equivalent, as in + strncmp, but skipping ' '. +*/ +SWIGRUNTIME int +SWIG_TypeNameComp(const char *f1, const char *l1, + const char *f2, const char *l2) { + for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); +} + +/* + Check type equivalence in a name list like <name1>|<name2>|... + Return 0 if not equal, 1 if equal +*/ +SWIGRUNTIME int +SWIG_TypeEquiv(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + +/* + Check type equivalence in a name list like <name1>|<name2>|... + Return 0 if equal, -1 if nb < tb, 1 if nb > tb +*/ +SWIGRUNTIME int +SWIG_TypeCompare(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + + +/* think of this as a c++ template<> or a scheme macro */ +#define SWIG_TypeCheck_Template(comparison, ty) \ + if (ty) { \ + swig_cast_info *iter = ty->cast; \ + while (iter) { \ + if (comparison) { \ + if (iter == ty->cast) return iter; \ + /* Move iter to the top of the linked list */ \ + iter->prev->next = iter->next; \ + if (iter->next) \ + iter->next->prev = iter->prev; \ + iter->next = ty->cast; \ + iter->prev = 0; \ + if (ty->cast) ty->cast->prev = iter; \ + ty->cast = iter; \ + return iter; \ + } \ + iter = iter->next; \ + } \ + } \ + return 0 + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); +} + +/* Same as previous function, except strcmp is replaced with a pointer comparison */ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { + SWIG_TypeCheck_Template(iter->type == from, into); +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); +} + +/* + Dynamic pointer casting. Down an inheritance hierarchy +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; +} + +/* + Return the name associated with this type +*/ +SWIGRUNTIMEINLINE const char * +SWIG_TypeName(const swig_type_info *ty) { + return ty->name; +} + +/* + Return the pretty name associated with this type, + that is an unmangled type name in a form presentable to the user. +*/ +SWIGRUNTIME const char * +SWIG_TypePrettyName(const swig_type_info *type) { + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s+1; + return last_name; + } + else + return type->name; +} + +/* + Set the clientdata field for a type +*/ +SWIGRUNTIME void +SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; + + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; + } +} +SWIGRUNTIME void +SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; +} + +/* + Search for a swig_type_info structure only by mangled name + Search is a O(log #types) + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + register size_t l = 0; + register size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + register size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + register int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; +} + +/* + Search for a swig_type_info structure for either a mangled name or a human readable name. + It first searches the mangled names of the types, which is a O(log #types) + If a type is not found it then searches the human readable names, which is O(#types). + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + register size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } + + /* neither found a match */ + return 0; +} + +/* + Pack binary data into a string +*/ +SWIGRUNTIME char * +SWIG_PackData(char *c, void *ptr, size_t sz) { + static const char hex[17] = "0123456789abcdef"; + register const unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* + Unpack binary data from a string +*/ +SWIGRUNTIME const char * +SWIG_UnpackData(const char *c, void *ptr, size_t sz) { + register unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register char d = *(c++); + register unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = ((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = ((d - ('a'-10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (d - ('a'-10)); + else + return (char *) 0; + *u = uu; + } + return c; +} + +/* + Pack 'void *' into a string buffer. +*/ +SWIGRUNTIME char * +SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { + char *r = buff; + if ((2*sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,&ptr,sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r,name); + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sizeof(void *)); +} + +SWIGRUNTIME char * +SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2*sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + if (lname) { + strncpy(r,name,lname+1); + } else { + *r = 0; + } + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + memset(ptr,0,sz); + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sz); +} + +#ifdef __cplusplus +} +#endif + +/* Errors in SWIG */ +#define SWIG_UnknownError -1 +#define SWIG_IOError -2 +#define SWIG_RuntimeError -3 +#define SWIG_IndexError -4 +#define SWIG_TypeError -5 +#define SWIG_DivisionByZero -6 +#define SWIG_OverflowError -7 +#define SWIG_SyntaxError -8 +#define SWIG_ValueError -9 +#define SWIG_SystemError -10 +#define SWIG_AttributeError -11 +#define SWIG_MemoryError -12 +#define SWIG_NullReferenceError -13 + + + + +/* Add PyOS_snprintf for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +# define PyOS_snprintf _snprintf +# else +# define PyOS_snprintf snprintf +# endif +#endif + +/* A crude PyString_FromFormat implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 + +#ifndef SWIG_PYBUFFER_SIZE +# define SWIG_PYBUFFER_SIZE 1024 +#endif + +static PyObject * +PyString_FromFormat(const char *fmt, ...) { + va_list ap; + char buf[SWIG_PYBUFFER_SIZE * 2]; + int res; + va_start(ap, fmt); + res = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); +} +#endif + +/* Add PyObject_Del for old Pythons */ +#if PY_VERSION_HEX < 0x01060000 +# define PyObject_Del(op) PyMem_DEL((op)) +#endif +#ifndef PyObject_DEL +# define PyObject_DEL PyObject_Del +#endif + +/* A crude PyExc_StopIteration exception for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# ifndef PyExc_StopIteration +# define PyExc_StopIteration PyExc_RuntimeError +# endif +# ifndef PyObject_GenericGetAttr +# define PyObject_GenericGetAttr 0 +# endif +#endif +/* Py_NotImplemented is defined in 2.1 and up. */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef Py_NotImplemented +# define Py_NotImplemented PyExc_RuntimeError +# endif +#endif + + +/* A crude PyString_AsStringAndSize implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef PyString_AsStringAndSize +# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} +# endif +#endif + +/* PySequence_Size for old Pythons */ +#if PY_VERSION_HEX < 0x02000000 +# ifndef PySequence_Size +# define PySequence_Size PySequence_Length +# endif +#endif + + +/* PyBool_FromLong for old Pythons */ +#if PY_VERSION_HEX < 0x02030000 +static +PyObject *PyBool_FromLong(long ok) +{ + PyObject *result = ok ? Py_True : Py_False; + Py_INCREF(result); + return result; +} +#endif + +/* Py_ssize_t for old Pythons */ +/* This code is as recommended by: */ +/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +# define PY_SSIZE_T_MAX INT_MAX +# define PY_SSIZE_T_MIN INT_MIN +#endif + +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIME PyObject* +SWIG_Python_ErrorType(int code) { + PyObject* type = 0; + switch(code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; +} + + +SWIGRUNTIME void +SWIG_Python_AddErrorMsg(const char* mesg) +{ + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + + if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + PyErr_Clear(); + Py_XINCREF(type); + PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_Format(PyExc_RuntimeError, mesg); + } +} + + + +#if defined(SWIG_PYTHON_NO_THREADS) +# if defined(SWIG_PYTHON_THREADS) +# undef SWIG_PYTHON_THREADS +# endif +#endif +#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ +# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) +# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ +# define SWIG_PYTHON_USE_GIL +# endif +# endif +# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ +# ifndef SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# endif +# ifdef __cplusplus /* C++ code */ + class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } + }; + class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } + }; +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# else /* C code */ +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() +# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() +# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) +# endif +# else /* Old thread way, not implemented, user must provide it */ +# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) +# define SWIG_PYTHON_INITIALIZE_THREADS +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif +# endif +#else /* No thread support */ +# define SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# define SWIG_PYTHON_THREAD_END_BLOCK +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# define SWIG_PYTHON_THREAD_END_ALLOW +#endif + +/* ----------------------------------------------------------------------------- + * Python API portion that goes into the runtime + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_PY_POINTER 4 +#define SWIG_PY_BINARY 5 + +/* Constant information structure */ +typedef struct swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; +} swig_const_info; + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * pyrun.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * ----------------------------------------------------------------------------- */ + +/* Common SWIG API */ + +/* for raw pointers */ +#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) +#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) +#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) +#define swig_owntype int + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) + +/* for C or C++ function pointers */ +#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) +#define SWIG_NewClientData(obj) PySwigClientData_New(obj) + +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Runtime API implementation */ + +/* Error manipulation */ + +SWIGINTERN void +SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +SWIGINTERN void +SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, (char *) msg); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) + +/* Set a constant value */ + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); +} + +/* Append a value to the result obj */ + +SWIGINTERN PyObject* +SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { +#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyList_Check(result)) { + PyObject *o2 = result; + result = PyList_New(1); + PyList_SetItem(result, 0, o2); + } + PyList_Append(result,obj); + Py_DECREF(obj); + } + return result; +#else + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SET_ITEM(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; +#endif +} + +/* Unpack the argument tuple */ + +SWIGINTERN int +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) +{ + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } + } + if (!PyTuple_Check(args)) { + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; + } else { + register Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)l); + return 0; + } else { + register int i; + for (i = 0; i < l; ++i) { + objs[i] = PyTuple_GET_ITEM(args, i); + } + for (; l < max; ++l) { + objs[l] = 0; + } + return i + 1; + } + } +} + +/* A functor is a function object with one single object argument */ +#if PY_VERSION_HEX >= 0x02020000 +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); +#else +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); +#endif + +/* + Helper for static pointer initialization for both C and C++ code, for example + static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); +*/ +#ifdef __cplusplus +#define SWIG_STATIC_POINTER(var) var +#else +#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var +#endif + +/* ----------------------------------------------------------------------------- + * Pointer declarations + * ----------------------------------------------------------------------------- */ + +/* Flags for new pointer objects */ +#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) +#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) + +#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* How to access Py_None */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_BUILD_NONE +# ifndef SWIG_PYTHON_BUILD_NONE +# define SWIG_PYTHON_BUILD_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_BUILD_NONE +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif +SWIGRUNTIMEINLINE PyObject * +_SWIG_Py_None(void) +{ + PyObject *none = Py_BuildValue((char*)""); + Py_DECREF(none); + return none; +} +SWIGRUNTIME PyObject * +SWIG_Py_None(void) +{ + static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); + return none; +} +#endif + +/* The python void return value */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) +{ + PyObject *none = Py_None; + Py_INCREF(none); + return none; +} + +/* PySwigClientData */ + +typedef struct { + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; +} PySwigClientData; + +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) +{ + PySwigClientData *data = (PySwigClientData *)ty->clientdata; + return data ? data->implicitconv : 0; +} + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_ExceptionType(swig_type_info *desc) { + PySwigClientData *data = desc ? (PySwigClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); +} + + +SWIGRUNTIME PySwigClientData * +PySwigClientData_New(PyObject* obj) +{ + if (!obj) { + return 0; + } else { + PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* the newraw method and newargs arguments used to create a new raw instance */ + if (PyClass_Check(obj)) { + data->newraw = 0; + data->newargs = obj; + Py_INCREF(obj); + } else { +#if (PY_VERSION_HEX < 0x02020000) + data->newraw = 0; +#else + data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); +#endif + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + flags = PyCFunction_GET_FLAGS(data->destroy); +#ifdef METH_O + data->delargs = !(flags & (METH_O)); +#else + data->delargs = 0; +#endif + } else { + data->delargs = 0; + } + data->implicitconv = 0; + return data; + } +} + +SWIGRUNTIME void +PySwigClientData_Del(PySwigClientData* data) +{ + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); +} + +/* =============== PySwigObject =====================*/ + +typedef struct { + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; +} PySwigObject; + +SWIGRUNTIME PyObject * +PySwigObject_long(PySwigObject *v) +{ + return PyLong_FromVoidPtr(v->ptr); +} + +SWIGRUNTIME PyObject * +PySwigObject_format(const char* fmt, PySwigObject *v) +{ + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { + PyObject *ofmt = PyString_FromString(fmt); + if (ofmt) { + res = PyString_Format(ofmt,args); + Py_DECREF(ofmt); + } + Py_DECREF(args); + } + } + return res; +} + +SWIGRUNTIME PyObject * +PySwigObject_oct(PySwigObject *v) +{ + return PySwigObject_format("%o",v); +} + +SWIGRUNTIME PyObject * +PySwigObject_hex(PySwigObject *v) +{ + return PySwigObject_format("%x",v); +} + +SWIGRUNTIME PyObject * +#ifdef METH_NOARGS +PySwigObject_repr(PySwigObject *v) +#else +PySwigObject_repr(PySwigObject *v, PyObject *args) +#endif +{ + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *hex = PySwigObject_hex(v); + PyObject *repr = PyString_FromFormat("<Swig Object of type '%s' at 0x%s>", name, PyString_AsString(hex)); + Py_DECREF(hex); + if (v->next) { +#ifdef METH_NOARGS + PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); +#else + PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next, args); +#endif + PyString_ConcatAndDel(&repr,nrep); + } + return repr; +} + +SWIGRUNTIME int +PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ +#ifdef METH_NOARGS + PyObject *repr = PySwigObject_repr(v); +#else + PyObject *repr = PySwigObject_repr(v, NULL); +#endif + if (repr) { + fputs(PyString_AsString(repr), fp); + Py_DECREF(repr); + return 0; + } else { + return 1; + } +} + +SWIGRUNTIME PyObject * +PySwigObject_str(PySwigObject *v) +{ + char result[SWIG_BUFFER_SIZE]; + return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? + PyString_FromString(result) : 0; +} + +SWIGRUNTIME int +PySwigObject_compare(PySwigObject *v, PySwigObject *w) +{ + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); +} + +SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); + +SWIGRUNTIME PyTypeObject* +PySwigObject_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); + return type; +} + +SWIGRUNTIMEINLINE int +PySwigObject_Check(PyObject *op) { + return ((op)->ob_type == PySwigObject_type()) + || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); +} + +SWIGRUNTIME PyObject * +PySwigObject_New(void *ptr, swig_type_info *ty, int own); + +SWIGRUNTIME void +PySwigObject_dealloc(PyObject *v) +{ + PySwigObject *sobj = (PySwigObject *) v; + PyObject *next = sobj->next; + if (sobj->own) { + swig_type_info *ty = sobj->ty; + PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; + PyObject *destroy = data ? data->destroy : 0; + if (destroy) { + /* destroy is always a VARARGS method */ + PyObject *res; + if (data->delargs) { + /* we need to create a temporal object to carry the destroy operation */ + PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + Py_XDECREF(res); + } else { + const char *name = SWIG_TypePrettyName(ty); +#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); +#endif + } + } + Py_XDECREF(next); + PyObject_DEL(v); +} + +SWIGRUNTIME PyObject* +PySwigObject_append(PyObject* v, PyObject* next) +{ + PySwigObject *sobj = (PySwigObject *) v; +#ifndef METH_O + PyObject *tmp = 0; + if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; + next = tmp; +#endif + if (!PySwigObject_Check(next)) { + return NULL; + } + sobj->next = next; + Py_INCREF(next); + return SWIG_Py_Void(); +} + +SWIGRUNTIME PyObject* +#ifdef METH_NOARGS +PySwigObject_next(PyObject* v) +#else +PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +PySwigObject_disown(PyObject *v) +#else +PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *)v; + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +PySwigObject_acquire(PyObject *v) +#else +PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +PySwigObject_own(PyObject *v, PyObject *args) +{ + PyObject *val = 0; +#if (PY_VERSION_HEX < 0x02020000) + if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) +#else + if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) +#endif + { + return NULL; + } + else + { + PySwigObject *sobj = (PySwigObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { +#ifdef METH_NOARGS + if (PyObject_IsTrue(val)) { + PySwigObject_acquire(v); + } else { + PySwigObject_disown(v); + } +#else + if (PyObject_IsTrue(val)) { + PySwigObject_acquire(v,args); + } else { + PySwigObject_disown(v,args); + } +#endif + } + return obj; + } +} + +#ifdef METH_O +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)PySwigObject_append, METH_O, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)PySwigObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_NOARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#else +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)PySwigObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)PySwigObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_VARARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#endif + +#if PY_VERSION_HEX < 0x02020000 +SWIGINTERN PyObject * +PySwigObject_getattr(PySwigObject *sobj,char *name) +{ + return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); +} +#endif + +SWIGRUNTIME PyTypeObject* +_PySwigObject_type(void) { + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + + static PyNumberMethods PySwigObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + (binaryfunc)0, /*nb_divide*/ + (binaryfunc)0, /*nb_remainder*/ + (binaryfunc)0, /*nb_divmod*/ + (ternaryfunc)0,/*nb_power*/ + (unaryfunc)0, /*nb_negative*/ + (unaryfunc)0, /*nb_positive*/ + (unaryfunc)0, /*nb_absolute*/ + (inquiry)0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + (coercion)0, /*nb_coerce*/ + (unaryfunc)PySwigObject_long, /*nb_int*/ + (unaryfunc)PySwigObject_long, /*nb_long*/ + (unaryfunc)0, /*nb_float*/ + (unaryfunc)PySwigObject_oct, /*nb_oct*/ + (unaryfunc)PySwigObject_hex, /*nb_hex*/ +#if PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ +#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ +#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ + 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ +#endif + }; + + static PyTypeObject pyswigobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + (char *)"PySwigObject", /* tp_name */ + sizeof(PySwigObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PySwigObject_dealloc, /* tp_dealloc */ + (printfunc)PySwigObject_print, /* tp_print */ +#if PY_VERSION_HEX < 0x02020000 + (getattrfunc)PySwigObject_getattr, /* tp_getattr */ +#else + (getattrfunc)0, /* tp_getattr */ +#endif + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)PySwigObject_compare, /* tp_compare */ + (reprfunc)PySwigObject_repr, /* tp_repr */ + &PySwigObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)PySwigObject_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigobject_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + swigobject_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + pyswigobject_type = tmp; + pyswigobject_type.ob_type = &PyType_Type; + type_init = 1; + } + return &pyswigobject_type; +} + +SWIGRUNTIME PyObject * +PySwigObject_New(void *ptr, swig_type_info *ty, int own) +{ + PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); + if (sobj) { + sobj->ptr = ptr; + sobj->ty = ty; + sobj->own = own; + sobj->next = 0; + } + return (PyObject *)sobj; +} + +/* ----------------------------------------------------------------------------- + * Implements a simple Swig Packed type, and use it instead of string + * ----------------------------------------------------------------------------- */ + +typedef struct { + PyObject_HEAD + void *pack; + swig_type_info *ty; + size_t size; +} PySwigPacked; + +SWIGRUNTIME int +PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char result[SWIG_BUFFER_SIZE]; + fputs("<Swig Packed ", fp); + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + fputs("at ", fp); + fputs(result, fp); + } + fputs(v->ty->name,fp); + fputs(">", fp); + return 0; +} + +SWIGRUNTIME PyObject * +PySwigPacked_repr(PySwigPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return PyString_FromFormat("<Swig Packed at %s%s>", result, v->ty->name); + } else { + return PyString_FromFormat("<Swig Packed %s>", v->ty->name); + } +} + +SWIGRUNTIME PyObject * +PySwigPacked_str(PySwigPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ + return PyString_FromFormat("%s%s", result, v->ty->name); + } else { + return PyString_FromString(v->ty->name); + } +} + +SWIGRUNTIME int +PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) +{ + size_t i = v->size; + size_t j = w->size; + int s = (i < j) ? -1 : ((i > j) ? 1 : 0); + return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); +} + +SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); + +SWIGRUNTIME PyTypeObject* +PySwigPacked_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); + return type; +} + +SWIGRUNTIMEINLINE int +PySwigPacked_Check(PyObject *op) { + return ((op)->ob_type == _PySwigPacked_type()) + || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); +} + +SWIGRUNTIME void +PySwigPacked_dealloc(PyObject *v) +{ + if (PySwigPacked_Check(v)) { + PySwigPacked *sobj = (PySwigPacked *) v; + free(sobj->pack); + } + PyObject_DEL(v); +} + +SWIGRUNTIME PyTypeObject* +_PySwigPacked_type(void) { + static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; + static PyTypeObject pyswigpacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + (char *)"PySwigPacked", /* tp_name */ + sizeof(PySwigPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PySwigPacked_dealloc, /* tp_dealloc */ + (printfunc)PySwigPacked_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)PySwigPacked_compare, /* tp_compare */ + (reprfunc)PySwigPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)PySwigPacked_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigpacked_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + pyswigpacked_type = tmp; + pyswigpacked_type.ob_type = &PyType_Type; + type_init = 1; + } + return &pyswigpacked_type; +} + +SWIGRUNTIME PyObject * +PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) +{ + PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); + if (sobj) { + void *pack = malloc(size); + if (pack) { + memcpy(pack, ptr, size); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = size; + } else { + PyObject_DEL((PyObject *) sobj); + sobj = 0; + } + } + return (PyObject *) sobj; +} + +SWIGRUNTIME swig_type_info * +PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) +{ + if (PySwigPacked_Check(obj)) { + PySwigPacked *sobj = (PySwigPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } +} + +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIMEINLINE PyObject * +_SWIG_This(void) +{ + return PyString_FromString("this"); +} + +SWIGRUNTIME PyObject * +SWIG_This(void) +{ + static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); + return swig_this; +} + +/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ + +SWIGRUNTIME PySwigObject * +SWIG_Python_GetSwigThis(PyObject *pyobj) +{ + if (PySwigObject_Check(pyobj)) { + return (PySwigObject *) pyobj; + } else { + PyObject *obj = 0; +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); + } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } + } + } +#else + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } +#endif + if (obj && !PySwigObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + PySwigObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (PySwigObject *)obj; + } +} + +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Python_AcquirePtr(PyObject *obj, int own) { + if (own) { + PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (sobj) { + int oldown = sobj->own; + sobj->own = own; + return oldown; + } + } + return 0; +} + +/* Convert a pointer value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { + if (!obj) return SWIG_ERROR; + if (obj == Py_None) { + if (ptr) *ptr = 0; + return SWIG_OK; + } else { + PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + while (sobj) { + void *vptr = sobj->ptr; + if (ty) { + swig_type_info *to = sobj->ty; + if (to == ty) { + /* no type cast needed */ + if (ptr) *ptr = vptr; + break; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) { + sobj = (PySwigObject *)sobj->next; + } else { + if (ptr) *ptr = SWIG_TypeCast(tc,vptr); + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) *own = sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; + } + return SWIG_OK; + } else { + int res = SWIG_ERROR; + if (flags & SWIG_POINTER_IMPLICIT_CONV) { + PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; + if (data && !data->implicitconv) { + PyObject *klass = data->klass; + if (klass) { + PyObject *impconv; + data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ + impconv = SWIG_Python_CallFunctor(klass, obj); + data->implicitconv = 0; + if (PyErr_Occurred()) { + PyErr_Clear(); + impconv = 0; + } + if (impconv) { + PySwigObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(res); + } else { + res = SWIG_AddCast(res); + } + } + } + Py_DECREF(impconv); + } + } + } + } + return res; + } + } +} + +/* Convert a function ptr value */ + +SWIGRUNTIME int +SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { + if (!PyCFunction_Check(obj)) { + return SWIG_ConvertPtr(obj, ptr, ty, 0); + } else { + void *vptr = 0; + + /* here we get the method pointer for callbacks */ + const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); + const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; + if (desc) { + desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; + if (!desc) return SWIG_ERROR; + } + if (ty) { + swig_cast_info *tc = SWIG_TypeCheck(desc,ty); + if (!tc) return SWIG_ERROR; + *ptr = SWIG_TypeCast(tc,vptr); + } else { + *ptr = vptr; + } + return SWIG_OK; + } +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +/* ----------------------------------------------------------------------------- + * Create a new pointer object + * ----------------------------------------------------------------------------- */ + +/* + Create a new instance object, whitout calling __init__, and set the + 'this' attribute. +*/ + +SWIGRUNTIME PyObject* +SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) +{ +#if (PY_VERSION_HEX >= 0x02020000) + PyObject *inst = 0; + PyObject *newraw = data->newraw; + if (newraw) { + inst = PyObject_Call(newraw, data->newargs, NULL); + if (inst) { +#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + PyDict_SetItem(dict, SWIG_This(), swig_this); + } + } +#else + PyObject *key = SWIG_This(); + PyObject_SetAttr(inst, key, swig_this); +#endif + } + } else { + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } + return inst; +#else +#if (PY_VERSION_HEX >= 0x02010000) + PyObject *inst; + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + return (PyObject *) inst; +#else + PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); + if (inst == NULL) { + return NULL; + } + inst->in_class = (PyClassObject *)data->newargs; + Py_INCREF(inst->in_class); + inst->in_dict = PyDict_New(); + if (inst->in_dict == NULL) { + Py_DECREF(inst); + return NULL; + } +#ifdef Py_TPFLAGS_HAVE_WEAKREFS + inst->in_weakreflist = NULL; +#endif +#ifdef Py_TPFLAGS_GC + PyObject_GC_Init(inst); +#endif + PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); + return (PyObject *) inst; +#endif +#endif +} + +SWIGRUNTIME void +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) +{ + PyObject *dict; +#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } +#endif + dict = PyObject_GetAttrString(inst, (char*)"__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} + + +SWIGINTERN PyObject * +SWIG_Python_InitShadowInstance(PyObject *args) { + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { + return NULL; + } else { + PySwigObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + PySwigObject_append((PyObject*) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); + } +} + +/* Create a new pointer object */ + +SWIGRUNTIME PyObject * +SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + if (!ptr) { + return SWIG_Py_Void(); + } else { + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + PyObject *robj = PySwigObject_New(ptr, type, own); + PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; + if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + if (inst) { + Py_DECREF(robj); + robj = inst; + } + } + return robj; + } +} + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); +} + +/* -----------------------------------------------------------------------------* + * Get type list + * -----------------------------------------------------------------------------*/ + +#ifdef SWIG_LINK_RUNTIME +void *SWIG_ReturnGlobalTypeList(void *); +#endif + +SWIGRUNTIME swig_module_info * +SWIG_Python_GetModule(void) { + static void *type_pointer = (void *)0; + /* first check if module already created */ + if (!type_pointer) { +#ifdef SWIG_LINK_RUNTIME + type_pointer = SWIG_ReturnGlobalTypeList((void *)0); +#else + type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; + } +#endif + } + return (swig_module_info *) type_pointer; +} + +#if PY_MAJOR_VERSION < 2 +/* PyModule_AddObject function was introduced in Python 2.0. The following function + is copied out of Python/modsupport.c in python version 2.3.4 */ +SWIGINTERN int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m)) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs module as first arg"); + return SWIG_ERROR; + } + if (!o) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs non-NULL value"); + return SWIG_ERROR; + } + + dict = PyModule_GetDict(m); + if (dict == NULL) { + /* Internal error -- modules must have a dict! */ + PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", + PyModule_GetName(m)); + return SWIG_ERROR; + } + if (PyDict_SetItemString(dict, name, o)) + return SWIG_ERROR; + Py_DECREF(o); + return SWIG_OK; +} +#endif + +SWIGRUNTIME void +SWIG_Python_DestroyModule(void *vptr) +{ + swig_module_info *swig_module = (swig_module_info *) vptr; + swig_type_info **types = swig_module->types; + size_t i; + for (i =0; i < swig_module->size; ++i) { + swig_type_info *ty = types[i]; + if (ty->owndata) { + PySwigClientData *data = (PySwigClientData *) ty->clientdata; + if (data) PySwigClientData_Del(data); + } + } + Py_DECREF(SWIG_This()); +} + +SWIGRUNTIME void +SWIG_Python_SetModule(swig_module_info *swig_module) { + static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ + + PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + swig_empty_runtime_method_table); + PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } +} + +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + +SWIGRUNTIME swig_type_info * +SWIG_Python_TypeQuery(const char *type) +{ + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = PyString_FromString(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { + descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); + } else { + swig_module_info *swig_module = SWIG_Python_GetModule(); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { + obj = PyCObject_FromVoidPtr(descriptor, NULL); + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } + } + Py_DECREF(key); + return descriptor; +} + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +SWIGRUNTIME int +SWIG_Python_AddErrMesg(const char* mesg, int infront) +{ + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); + } else { + PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); + } + Py_DECREF(old_str); + } + return 1; + } else { + return 0; + } +} + +SWIGRUNTIME int +SWIG_Python_ArgFail(int argnum) +{ + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIMEINLINE const char * +PySwigObject_GetDesc(PyObject *self) +{ + PySwigObject *v = (PySwigObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : (char*)""; +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && PySwigObject_Check(obj)) { + const char *otype = (const char *) PySwigObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? PyString_AsString(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* Convert a pointer value, signal an exception on a type mismatch */ +SWIGRUNTIME void * +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); + if (flags & SWIG_POINTER_EXCEPTION) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } + } + return result; +} + + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + + +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_p_TALLOC_CTX swig_types[0] +#define SWIGTYPE_p_char swig_types[1] +#define SWIGTYPE_p_int swig_types[2] +#define SWIGTYPE_p_loadparm_context swig_types[3] +#define SWIGTYPE_p_loadparm_service swig_types[4] +#define SWIGTYPE_p_long_long swig_types[5] +#define SWIGTYPE_p_param_context swig_types[6] +#define SWIGTYPE_p_param_opt swig_types[7] +#define SWIGTYPE_p_param_section swig_types[8] +#define SWIGTYPE_p_short swig_types[9] +#define SWIGTYPE_p_signed_char swig_types[10] +#define SWIGTYPE_p_unsigned_char swig_types[11] +#define SWIGTYPE_p_unsigned_int swig_types[12] +#define SWIGTYPE_p_unsigned_long_long swig_types[13] +#define SWIGTYPE_p_unsigned_short swig_types[14] +static swig_type_info *swig_types[16]; +static swig_module_info swig_module = {swig_types, 15, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + +#if (PY_VERSION_HEX <= 0x02000000) +# if !defined(SWIG_PYTHON_CLASSIC) +# error "This python version requires swig to be run with the '-classic' option" +# endif +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery + +/*----------------------------------------------- + @(target):= _param.so + ------------------------------------------------*/ +#define SWIG_init init_param + +#define SWIG_name "_param" + +#define SWIGVERSION 0x010333 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) (void *)((const void *)(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) + + +#include <stdint.h> +#include <stdbool.h> + +#include "includes.h" +#include "param/param.h" +#include "param/loadparm.h" + +typedef struct param_context param; +typedef struct loadparm_context loadparm_context; +typedef struct loadparm_service loadparm_service; +typedef struct param_section param_section; +typedef struct param_opt param_opt; + +SWIGINTERN loadparm_context *new_loadparm_context(TALLOC_CTX *mem_ctx){ return loadparm_init(mem_ctx); } + +SWIGINTERN swig_type_info* +SWIG_pchar_descriptor(void) +{ + static int init = 0; + static swig_type_info* info = 0; + if (!init) { + info = SWIG_TypeQuery("_p_char"); + init = 1; + } + return info; +} + + +SWIGINTERN int +SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) +{ + if (PyString_Check(obj)) { + char *cstr; Py_ssize_t len; + PyString_AsStringAndSize(obj, &cstr, &len); + if (cptr) { + if (alloc) { + /* + In python the user should not be able to modify the inner + string representation. To warranty that, if you define + SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string + buffer is always returned. + + The default behavior is just to return the pointer value, + so, be careful. + */ +#if defined(SWIG_PYTHON_SAFE_CSTRINGS) + if (*alloc != SWIG_OLDOBJ) +#else + if (*alloc == SWIG_NEWOBJ) +#endif + { + *cptr = (char *)memcpy((char *)malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); + *alloc = SWIG_NEWOBJ; + } + else { + *cptr = cstr; + *alloc = SWIG_OLDOBJ; + } + } else { + *cptr = PyString_AsString(obj); + } + } + if (psize) *psize = len + 1; + return SWIG_OK; + } else { + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + if (pchar_descriptor) { + void* vptr = 0; + if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { + if (cptr) *cptr = (char *) vptr; + if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; + if (alloc) *alloc = SWIG_OLDOBJ; + return SWIG_OK; + } + } + } + return SWIG_TypeError; +} + + + + +SWIGINTERN bool loadparm_context_load(loadparm_context *self,char const *filename){ return lp_load(self, filename); } + +SWIGINTERNINLINE PyObject* + SWIG_From_bool (bool value) +{ + return PyBool_FromLong(value ? 1 : 0); +} + +SWIGINTERN int loadparm_context___len__(loadparm_context *self){ return lp_numservices(self); } + + #define SWIG_From_long PyInt_FromLong + + +SWIGINTERNINLINE PyObject * +SWIG_From_int (int value) +{ + return SWIG_From_long (value); +} + +SWIGINTERN struct loadparm_service *loadparm_context___getitem__(loadparm_context *self,char const *name){ return lp_service(self, name); } +SWIGINTERN char const *loadparm_context_configfile(loadparm_context *self){ return lp_configfile(self); } + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + if (carray) { + if (size > INT_MAX) { + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + return pchar_descriptor ? + SWIG_NewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); + } else { + return PyString_FromStringAndSize(carray, (int)(size)); + } + } else { + return SWIG_Py_Void(); + } +} + + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtr(const char *cptr) +{ + return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); +} + +SWIGINTERN bool loadparm_context_is_mydomain(loadparm_context *self,char const *domain){ return lp_is_mydomain(self, domain); } +SWIGINTERN bool loadparm_context_is_myname(loadparm_context *self,char const *name){ return lp_is_myname(self, name); } +SWIGINTERN int loadparm_context_use(loadparm_context *self,struct param_context *param){ return param_use(self, param); } +SWIGINTERN bool loadparm_context_set(loadparm_context *self,char const *parm_name,char const *parm_value){ + return lp_set_cmdline(self, parm_name, parm_value); + } +SWIGINTERN PyObject *loadparm_context_get(loadparm_context *self,char const *param_name,char const *service_name){ + struct parm_struct *parm = NULL; + void *parm_ptr = NULL; + int i; + + if (service_name != NULL) { + struct loadparm_service *service; + /* its a share parameter */ + service = lp_service(self, service_name); + if (service == NULL) { + return Py_None; + } + if (strchr(param_name, ':')) { + /* its a parametric option on a share */ + const char *type = talloc_strndup(self, + param_name, + strcspn(param_name, ":")); + const char *option = strchr(param_name, ':') + 1; + const char *value; + if (type == NULL || option == NULL) { + return Py_None; + } + value = lp_get_parametric(self, service, type, option); + if (value == NULL) { + return Py_None; + } + return PyString_FromString(value); + } + + parm = lp_parm_struct(param_name); + if (parm == NULL || parm->class == P_GLOBAL) { + return Py_None; + } + parm_ptr = lp_parm_ptr(self, service, parm); + } else if (strchr(param_name, ':')) { + /* its a global parametric option */ + const char *type = talloc_strndup(self, + param_name, strcspn(param_name, ":")); + const char *option = strchr(param_name, ':') + 1; + const char *value; + if (type == NULL || option == NULL) { + return Py_None; + } + value = lp_get_parametric(self, NULL, type, option); + if (value == NULL) + return Py_None; + return PyString_FromString(value); + } else { + /* its a global parameter */ + parm = lp_parm_struct(param_name); + if (parm == NULL) { + return Py_None; + } + parm_ptr = lp_parm_ptr(self, NULL, parm); + } + + if (parm == NULL || parm_ptr == NULL) { + return Py_None; + } + + /* construct and return the right type of python object */ + switch (parm->type) { + case P_STRING: + case P_USTRING: + return PyString_FromString(*(char **)parm_ptr); + case P_BOOL: + return PyBool_FromLong(*(bool *)parm_ptr); + case P_INTEGER: + case P_OCTAL: + case P_BYTES: + return PyLong_FromLong(*(int *)parm_ptr); + case P_ENUM: + for (i=0; parm->enum_list[i].name; i++) { + if (*(int *)parm_ptr == parm->enum_list[i].value) { + return PyString_FromString(parm->enum_list[i].name); + } + } + return Py_None; + case P_LIST: + { + int i; + const char **strlist = *(const char ***)parm_ptr; + PyObject *pylist = PyList_New(str_list_length(strlist)); + for (i = 0; strlist[i]; i++) + PyList_SetItem(pylist, i, + PyString_FromString(strlist[i])); + return pylist; + } + + break; + } + return Py_None; + } +SWIGINTERN void delete_loadparm_context(loadparm_context *self){ talloc_free(self); } +SWIGINTERN char const *loadparm_service_volume_label(loadparm_service *self){ return volume_label(self); } +SWIGINTERN char const *loadparm_service_printername(loadparm_service *self){ return lp_printername(self); } +SWIGINTERN int loadparm_service_maxprintjobs(loadparm_service *self){ return lp_maxprintjobs(self); } +SWIGINTERN param *new_param(TALLOC_CTX *mem_ctx){ return param_init(mem_ctx); } +SWIGINTERN int param_set(param *self,char const *param,PyObject *ob,char const *section_name){ + struct param_opt *opt = param_get_add(self, param, section_name); + + talloc_free(opt->value); + opt->value = talloc_strdup(opt, PyObject_Str(ob)); + + return 0; + } +SWIGINTERN void delete_param(param *self){ talloc_free(self); } +SWIGINTERN char const *param_opt___str__(param_opt *self){ return self->value; } +SWIGINTERN void delete_param_opt(param_opt *self){ talloc_free(self); } +#ifdef __cplusplus +extern "C" { +#endif +SWIGINTERN PyObject *_wrap_new_LoadParm(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; + loadparm_context *result = 0 ; + + { + arg1 = NULL; + } + if (!SWIG_Python_UnpackTuple(args,"new_LoadParm",0,0,0)) SWIG_fail; + result = (loadparm_context *)new_loadparm_context(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_loadparm_context, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_load(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + bool result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "filename", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_load",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_load" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_load" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + result = (bool)loadparm_context_load(arg1,(char const *)arg2); + resultobj = SWIG_From_bool((bool)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm___len__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "self", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:LoadParm___len__",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm___len__" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + result = (int)loadparm_context___len__(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm___getitem__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + struct loadparm_service *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm___getitem__",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm___getitem__" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm___getitem__" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + result = (struct loadparm_service *)loadparm_context___getitem__(arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_loadparm_service, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_configfile(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "self", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:LoadParm_configfile",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_configfile" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + result = (char *)loadparm_context_configfile(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_is_mydomain(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + bool result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "domain", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_is_mydomain",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_is_mydomain" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_is_mydomain" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + result = (bool)loadparm_context_is_mydomain(arg1,(char const *)arg2); + resultobj = SWIG_From_bool((bool)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_is_myname(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + bool result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_is_myname",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_is_myname" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_is_myname" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + result = (bool)loadparm_context_is_myname(arg1,(char const *)arg2); + resultobj = SWIG_From_bool((bool)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_use(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + struct param_context *arg2 = (struct param_context *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "param", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_use",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_use" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_use" "', argument " "2"" of type '" "struct param_context *""'"); + } + arg2 = (struct param_context *)(argp2); + } + result = (int)loadparm_context_use(arg1,arg2); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + bool result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "parm_name",(char *) "parm_value", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OOO:LoadParm_set",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_set" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_set" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "LoadParm_set" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + } + result = (bool)loadparm_context_set(arg1,(char const *)arg2,(char const *)arg3); + resultobj = SWIG_From_bool((bool)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_LoadParm_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + PyObject *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "param_name",(char *) "service_name", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OOO:LoadParm_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_get" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_get" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + } + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "LoadParm_get" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + } + result = (PyObject *)loadparm_context_get(arg1,(char const *)arg2,(char const *)arg3); + resultobj = result; + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_LoadParm(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "self", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|O:delete_LoadParm",kwnames,&obj0)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_LoadParm" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + delete_loadparm_context(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *LoadParm_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_loadparm_context, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *LoadParm_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + +SWIGINTERN PyObject *_wrap_loadparm_service_volume_label(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + loadparm_service *arg1 = (loadparm_service *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_loadparm_service, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "loadparm_service_volume_label" "', argument " "1"" of type '" "loadparm_service *""'"); + } + arg1 = (loadparm_service *)(argp1); + result = (char *)loadparm_service_volume_label(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_loadparm_service_printername(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + loadparm_service *arg1 = (loadparm_service *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_loadparm_service, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "loadparm_service_printername" "', argument " "1"" of type '" "loadparm_service *""'"); + } + arg1 = (loadparm_service *)(argp1); + result = (char *)loadparm_service_printername(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_loadparm_service_maxprintjobs(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + loadparm_service *arg1 = (loadparm_service *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_loadparm_service, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "loadparm_service_maxprintjobs" "', argument " "1"" of type '" "loadparm_service *""'"); + } + arg1 = (loadparm_service *)(argp1); + result = (int)loadparm_service_maxprintjobs(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *loadparm_service_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_loadparm_service, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *_wrap_new_ParamFile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; + param *result = 0 ; + + { + arg1 = NULL; + } + if (!SWIG_Python_UnpackTuple(args,"new_ParamFile",0,0,0)) SWIG_fail; + result = (param *)new_param(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_context, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_get_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + struct param_section *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_get_section",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get_section" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get_section" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (struct param_section *)param_get_section(arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_add_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + struct param_section *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_add_section",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_add_section" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_add_section" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (struct param_section *)param_add_section(arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) "global" ; + struct param_opt *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name",(char *) "section_name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + } + result = (struct param_opt *)param_get(arg1,(char const *)arg2,(char const *)arg3); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_get_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) "global" ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name",(char *) "section_name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get_string",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get_string" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get_string" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + } + result = (char *)param_get_string(arg1,(char const *)arg2,(char const *)arg3); + resultobj = SWIG_FromCharPtr((const char *)result); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) "global" ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "param",(char *) "value",(char *) "section", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set_string",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set_string" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_set_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_set_string" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + if (obj3) { + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set_string" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + } + result = (int)param_set_string(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4); + resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + char *arg4 = (char *) "global" ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "param",(char *) "ob",(char *) "section_name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_set" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + arg3 = obj2; + if (obj3) { + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + } + result = (int)param_set(arg1,(char const *)arg2,arg3,(char const *)arg4); + resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "fn", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_read",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_read" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_read" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (int)param_read(arg1,(char const *)arg2); + resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_write(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "fn", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_write",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_write" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_write" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (int)param_write(arg1,(char const *)arg2); + resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_ParamFile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_context, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_ParamFile" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + delete_param(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *ParamFile_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_param_context, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *ParamFile_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + +SWIGINTERN PyObject *_wrap_param_opt___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_opt___str__" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + result = (char *)param_opt___str__(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_param_opt(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_param_opt" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + delete_param_opt(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *param_opt_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_param_opt, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *_wrap_param_section_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param_section *arg1 = (param_section *) 0 ; + char *arg2 = (char *) 0 ; + struct param_opt *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:param_section_get",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_section, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_section_get" "', argument " "1"" of type '" "param_section *""'"); + } + arg1 = (param_section *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "param_section_get" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (struct param_opt *)param_section_get(arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_param_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_section *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_param_section",0,0,0)) SWIG_fail; + result = (param_section *)(param_section *) calloc(1, sizeof(param_section)); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_param_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_section *arg1 = (param_section *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_section, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_param_section" "', argument " "1"" of type '" "param_section *""'"); + } + arg1 = (param_section *)(argp1); + free((char *) arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *param_section_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_param_section, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject *param_section_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + +SWIGINTERN int Swig_var_default_config_set(PyObject *_val) { + { + void *argp = 0; + int res = SWIG_ConvertPtr(_val, &argp, SWIGTYPE_p_loadparm_context, 0 ); + if (!SWIG_IsOK(res)) { + SWIG_exception_fail(SWIG_ArgError(res), "in variable '""global_loadparm""' of type '""struct loadparm_context *""'"); + } + global_loadparm = (struct loadparm_context *)(argp); + } + return 0; +fail: + return 1; +} + + +SWIGINTERN PyObject *Swig_var_default_config_get(void) { + PyObject *pyobj = 0; + + pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(global_loadparm), SWIGTYPE_p_loadparm_context, 0 ); + return pyobj; +} + + +static PyMethodDef SwigMethods[] = { + { (char *)"new_LoadParm", (PyCFunction)_wrap_new_LoadParm, METH_NOARGS, NULL}, + { (char *)"LoadParm_load", (PyCFunction) _wrap_LoadParm_load, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm___len__", (PyCFunction) _wrap_LoadParm___len__, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm___getitem__", (PyCFunction) _wrap_LoadParm___getitem__, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_configfile", (PyCFunction) _wrap_LoadParm_configfile, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_is_mydomain", (PyCFunction) _wrap_LoadParm_is_mydomain, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_is_myname", (PyCFunction) _wrap_LoadParm_is_myname, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_use", (PyCFunction) _wrap_LoadParm_use, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_set", (PyCFunction) _wrap_LoadParm_set, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_get", (PyCFunction) _wrap_LoadParm_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_LoadParm", (PyCFunction) _wrap_delete_LoadParm, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_swigregister", LoadParm_swigregister, METH_VARARGS, NULL}, + { (char *)"LoadParm_swiginit", LoadParm_swiginit, METH_VARARGS, NULL}, + { (char *)"loadparm_service_volume_label", (PyCFunction)_wrap_loadparm_service_volume_label, METH_O, NULL}, + { (char *)"loadparm_service_printername", (PyCFunction)_wrap_loadparm_service_printername, METH_O, NULL}, + { (char *)"loadparm_service_maxprintjobs", (PyCFunction)_wrap_loadparm_service_maxprintjobs, METH_O, NULL}, + { (char *)"loadparm_service_swigregister", loadparm_service_swigregister, METH_VARARGS, NULL}, + { (char *)"new_ParamFile", (PyCFunction)_wrap_new_ParamFile, METH_NOARGS, NULL}, + { (char *)"ParamFile_get_section", (PyCFunction) _wrap_ParamFile_get_section, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_add_section", (PyCFunction) _wrap_ParamFile_add_section, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_get", (PyCFunction) _wrap_ParamFile_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_get_string", (PyCFunction) _wrap_ParamFile_get_string, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_set_string", (PyCFunction) _wrap_ParamFile_set_string, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_set", (PyCFunction) _wrap_ParamFile_set, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_write", (PyCFunction) _wrap_ParamFile_write, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_ParamFile", (PyCFunction)_wrap_delete_ParamFile, METH_O, NULL}, + { (char *)"ParamFile_swigregister", ParamFile_swigregister, METH_VARARGS, NULL}, + { (char *)"ParamFile_swiginit", ParamFile_swiginit, METH_VARARGS, NULL}, + { (char *)"param_opt___str__", (PyCFunction)_wrap_param_opt___str__, METH_O, NULL}, + { (char *)"delete_param_opt", (PyCFunction)_wrap_delete_param_opt, METH_O, NULL}, + { (char *)"param_opt_swigregister", param_opt_swigregister, METH_VARARGS, NULL}, + { (char *)"param_section_get", (PyCFunction) _wrap_param_section_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"new_param_section", (PyCFunction)_wrap_new_param_section, METH_NOARGS, NULL}, + { (char *)"delete_param_section", (PyCFunction)_wrap_delete_param_section, METH_O, NULL}, + { (char *)"param_section_swigregister", param_section_swigregister, METH_VARARGS, NULL}, + { (char *)"param_section_swiginit", param_section_swiginit, METH_VARARGS, NULL}, + { NULL, NULL, 0, NULL } +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "uintptr_t *|uint_least32_t *|uint_fast32_t *|uint32_t *|unsigned int *|uint_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_long_long = {"_p_unsigned_long_long", "uint_least64_t *|uint_fast64_t *|uint64_t *|unsigned long long *|uintmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|uint_least16_t *|uint16_t *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__p_TALLOC_CTX, + &_swigt__p_char, + &_swigt__p_int, + &_swigt__p_loadparm_context, + &_swigt__p_loadparm_service, + &_swigt__p_long_long, + &_swigt__p_param_context, + &_swigt__p_param_opt, + &_swigt__p_param_section, + &_swigt__p_short, + &_swigt__p_signed_char, + &_swigt__p_unsigned_char, + &_swigt__p_unsigned_int, + &_swigt__p_unsigned_long_long, + &_swigt__p_unsigned_short, +}; + +static swig_cast_info _swigc__p_TALLOC_CTX[] = { {&_swigt__p_TALLOC_CTX, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_opt[] = { {&_swigt__p_param_opt, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_long_long[] = { {&_swigt__p_unsigned_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__p_TALLOC_CTX, + _swigc__p_char, + _swigc__p_int, + _swigc__p_loadparm_context, + _swigc__p_loadparm_service, + _swigc__p_long_long, + _swigc__p_param_context, + _swigc__p_param_opt, + _swigc__p_param_section, + _swigc__p_short, + _swigc__p_signed_char, + _swigc__p_unsigned_char, + _swigc__p_unsigned_int, + _swigc__p_unsigned_long_long, + _swigc__p_unsigned_short, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + +static swig_const_info swig_const_table[] = { +{0, 0, 0, 0.0, 0, 0}}; + +#ifdef __cplusplus +} +#endif +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned staticly to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int found; + + clientdata = clientdata; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + module_head = &swig_module; + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + found=0; + iter=module_head; + do { + if (iter==&swig_module) { + found=1; + break; + } + iter=iter->next; + } while (iter!= module_head); + + /* if the is found in the list, then all is done and we may leave */ + if (found) return; + /* otherwise we must add out module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* This function will propagate the clientdata field of type to +* any new swig_type_info structures that have been added into the list +* of equivalent types. It is like calling +* SWIG_TypeClientData(type, clientdata) a second time. +*/ +SWIGRUNTIME void +SWIG_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ + /* c-mode */ +#endif +} +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + /* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + + /* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + + typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; + } swig_globalvar; + + typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; + } swig_varlinkobject; + + SWIGINTERN PyObject * + swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { + return PyString_FromString("<Swig global variables>"); + } + + SWIGINTERN PyObject * + swig_varlink_str(swig_varlinkobject *v) { + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); + return str; + } + + SWIGINTERN int + swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { + PyObject *str = swig_varlink_str(v); + fprintf(fp,"Swig global variables "); + fprintf(fp,"%s\n", PyString_AsString(str)); + Py_DECREF(str); + return 0; + } + + SWIGINTERN void + swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } + } + + SWIGINTERN PyObject * + swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN int + swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN PyTypeObject* + swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* Number of items in variable part (ob_size) */ + (char *)"swigvarlink", /* Type name (tp_name) */ + sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ + 0, /* Itemsize (tp_itemsize) */ + (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ + (printfunc) swig_varlink_print, /* Print (tp_print) */ + (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ + (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc)swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + varlink_type = tmp; + varlink_type.ob_type = &PyType_Type; + type_init = 1; + } + return &varlink_type; + } + + /* Create a variable linking object for use later */ + SWIGINTERN PyObject * + SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); + } + + SWIGINTERN void + SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; + } + + SWIGINTERN PyObject * + SWIG_globals(void) { + static PyObject *_SWIG_globals = 0; + if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); + return _SWIG_globals; + } + + /* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + + /* Install Constants */ + SWIGINTERN void + SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { + PyObject *obj = 0; + size_t i; + for (i = 0; constants[i].type; ++i) { + switch(constants[i].type) { + case SWIG_PY_POINTER: + obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } + } + } + + /* -----------------------------------------------------------------------------*/ + /* Fix SwigMethods to carry the callback ptrs when needed */ + /* -----------------------------------------------------------------------------*/ + + SWIGINTERN void + SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { + size_t i; + for (i = 0; methods[i].ml_name; ++i) { + const char *c = methods[i].ml_doc; + if (c && (c = strstr(c, "swig_ptr: "))) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; + char *ndoc = (char*)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } + } + } + } + } + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" +#endif +SWIGEXPORT void SWIG_init(void) { + PyObject *m, *d; + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + + m = Py_InitModule((char *) SWIG_name, SwigMethods); + d = PyModule_GetDict(m); + + SWIG_InitializeModule(0); + SWIG_InstallConstants(d,swig_const_table); + + + PyDict_SetItemString(d,(char*)"cvar", SWIG_globals()); + SWIG_addvarlink(SWIG_globals(),(char*)"default_config",Swig_var_default_config_get, Swig_var_default_config_set); +} + diff --git a/source4/param/share.c b/source4/param/share.c index 7ee1d8037a..2ada9999ea 100644 --- a/source4/param/share.c +++ b/source4/param/share.c @@ -126,9 +126,9 @@ NTSTATUS share_register(const struct share_ops *ops) return NT_STATUS_OK; } -NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, - const char *backend_name, - struct share_context **ctx) +NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name, + struct loadparm_context *lp_ctx, + struct share_context **ctx) { const struct share_ops *ops; @@ -138,12 +138,7 @@ NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, return NT_STATUS_INTERNAL_ERROR; } - return ops->init(mem_ctx, ops, ctx); -} - -NTSTATUS share_get_context(TALLOC_CTX *mem_ctx, struct share_context **ctx) -{ - return share_get_context_by_name(mem_ctx, lp_share_backend(global_loadparm), ctx); + return ops->init(mem_ctx, ops, lp_ctx, ctx); } /* diff --git a/source4/param/share.h b/source4/param/share.h index fae1c31c13..51f45781c1 100644 --- a/source4/param/share.h +++ b/source4/param/share.h @@ -49,7 +49,8 @@ struct share_info { struct share_ops { const char *name; - NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct share_context **); + NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct loadparm_context *lp_ctx, + struct share_context **); const char *(*string_option)(struct share_config *, const char *, const char *); int (*int_option)(struct share_config *, const char *, int); bool (*bool_option)(struct share_config *, const char *, bool); diff --git a/source4/param/share_classic.c b/source4/param/share_classic.c index 4a7fbcb263..b517c9c4c2 100644 --- a/source4/param/share_classic.c +++ b/source4/param/share_classic.c @@ -25,6 +25,7 @@ static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, + struct loadparm_context *lp_ctx, struct share_context **ctx) { *ctx = talloc(mem_ctx, struct share_context); @@ -34,7 +35,7 @@ static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, } (*ctx)->ops = ops; - (*ctx)->priv_data = global_loadparm; + (*ctx)->priv_data = lp_ctx; return NT_STATUS_OK; } diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 487359eff6..bdea94a5cd 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -27,7 +27,8 @@ #include "param/share.h" #include "param/param.h" -static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx) +static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct loadparm_context *lp_ctx, + struct share_context **ctx) { struct ldb_context *sdb; @@ -37,9 +38,9 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru return NT_STATUS_NO_MEMORY; } - sdb = ldb_wrap_connect(*ctx, global_loadparm, - private_path(*ctx, global_loadparm, "share.ldb"), - system_session(*ctx, global_loadparm), + sdb = ldb_wrap_connect(*ctx, lp_ctx, + private_path(*ctx, lp_ctx, "share.ldb"), + system_session(*ctx, lp_ctx), NULL, 0, NULL); if (!sdb) { diff --git a/source4/param/tests/bindings.py b/source4/param/tests/bindings.py new file mode 100644 index 0000000000..9ea1c00daf --- /dev/null +++ b/source4/param/tests/bindings.py @@ -0,0 +1,69 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import param +import unittest + +class LoadParmTestCase(unittest.TestCase): + def test_init(self): + file = param.LoadParm() + self.assertTrue(file is not None) + + def test_length(self): + file = param.LoadParm() + self.assertEquals(0, len(file)) + + def test_set_workgroup(self): + file = param.LoadParm() + file.set("workgroup", "bla") + self.assertEquals("BLA", file.get("workgroup")) + + def test_is_mydomain(self): + file = param.LoadParm() + file.set("workgroup", "bla") + self.assertTrue(file.is_mydomain("BLA")) + self.assertFalse(file.is_mydomain("FOOBAR")) + + def test_is_myname(self): + file = param.LoadParm() + file.set("netbios name", "bla") + self.assertTrue(file.is_myname("BLA")) + self.assertFalse(file.is_myname("FOOBAR")) + + +class ParamTestCase(unittest.TestCase): + def test_init(self): + file = param.ParamFile() + self.assertTrue(file is not None) + + def test_add_section(self): + file = param.ParamFile() + file.add_section("global") + self.assertTrue(file["global"] is not None) + + def test_set_param_string(self): + file = param.ParamFile() + file.add_section("global") + file.set_string("data", "bar") + self.assertEquals("bar", file.get_string("data")) + + def test_get_section(self): + file = param.ParamFile() + self.assertEquals(None, file.get_section("unknown")) + self.assertRaises(KeyError, lambda: file["unknown"]) diff --git a/source4/param/tests/share.c b/source4/param/tests/share.c index 1f8ecb2d84..390da9dede 100644 --- a/source4/param/tests/share.c +++ b/source4/param/tests/share.c @@ -178,12 +178,12 @@ static void tcase_add_share_tests(struct torture_tcase *tcase) static bool setup_ldb(struct torture_context *tctx, void **data) { - return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", (struct share_context **)data)); + return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", tctx->lp_ctx, (struct share_context **)data)); } static bool setup_classic(struct torture_context *tctx, void **data) { - return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", (struct share_context **)data)); + return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", tctx->lp_ctx, (struct share_context **)data)); } static bool teardown(struct torture_context *tctx, void *data) diff --git a/source4/param/util.c b/source4/param/util.c index 89498b57a6..1cf05d4fa7 100644 --- a/source4/param/util.c +++ b/source4/param/util.c @@ -106,6 +106,9 @@ _PUBLIC_ char *config_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx, { char *fname, *config_dir, *p; config_dir = talloc_strdup(mem_ctx, lp_configfile(lp_ctx)); + if (config_dir == NULL) { + return NULL; + } p = strrchr(config_dir, '/'); if (p == NULL) { return NULL; @@ -283,19 +286,12 @@ _PUBLIC_ const char *lp_messaging_path(TALLOC_CTX *mem_ctx, return smbd_tmp_path(mem_ctx, lp_ctx, "messaging"); } -struct smb_iconv_convenience *global_smb_iconv_convenience = NULL; - struct smb_iconv_convenience *smb_iconv_convenience_init_lp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx) { return smb_iconv_convenience_init(mem_ctx, lp_dos_charset(lp_ctx), lp_unix_charset(lp_ctx), - lp_display_charset(lp_ctx), lp_parm_bool(lp_ctx, NULL, "iconv", "native", true)); } -_PUBLIC_ void reload_charcnv(void) -{ - talloc_free(global_smb_iconv_convenience); - global_smb_iconv_convenience = smb_iconv_convenience_init_lp(talloc_autofree_context(), global_loadparm); -} + diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm index 29f7835949..58b52df8d3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm @@ -60,6 +60,8 @@ sub ParseInterface($$) pidl "typedef struct $if->{NAME} { struct dcerpc_pipe *pipe; } $if->{NAME};"; pidl "}"; pidl ""; + pidl "%talloctype($if->{NAME});"; + pidl ""; pidl "\%extend $if->{NAME} {"; indent(); pidl "$if->{NAME} () {"; @@ -75,10 +77,6 @@ sub ParseInterface($$) deindent; pidl "}"; pidl ""; - pidl "~$if->{NAME}() {"; - pidl "\ttalloc_free(\$self);"; - pidl "}"; - pidl ""; foreach my $fn (@{$if->{FUNCTIONS}}) { pidl "/* $fn->{NAME} */"; @@ -158,6 +156,7 @@ sub Parse($$$$) pidl "%}"; pidl "\%import \"../rpc/dcerpc.i\""; pidl "\%import \"../../libcli/util/errors.i\""; + pidl "\%import \"../../lib/talloc/talloc.i\""; pidl ""; foreach (@$ndr) { IgnoreInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE"); diff --git a/source4/pidl/tests/ndr_align.pl b/source4/pidl/tests/ndr_align.pl index 1f4a0da9bb..cc089eaa1f 100755 --- a/source4/pidl/tests/ndr_align.pl +++ b/source4/pidl/tests/ndr_align.pl @@ -16,7 +16,7 @@ test_samba4_ndr('align-uint8-uint16', } bla; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct bla r; uint8_t expected[] = { 0x0D, 0x00, 0xef, 0xbe }; DATA_BLOB expected_blob = { expected, 4 }; @@ -41,7 +41,7 @@ test_samba4_ndr('align-uint8-uint32', } bla; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct bla r; uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xef, 0xbe }; DATA_BLOB expected_blob = { expected, 8 }; @@ -67,7 +67,7 @@ test_samba4_ndr('align-uint8-hyper', } bla; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct bla r; uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe }; @@ -93,7 +93,7 @@ test_samba4_ndr('noalignflag-uint8-uint16', } bla; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct bla r; uint8_t expected[] = { 0x0D, 0xef, 0xbe }; DATA_BLOB expected_blob = { expected, 3 }; @@ -121,7 +121,7 @@ test_samba4_ndr('align-blob-align2', } blie; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct blie r; uint8_t data[] = { 0x01, 0x02 }; uint8_t expected[] = { 0x0D, 0x00, 0x0E }; diff --git a/source4/pidl/tests/ndr_alloc.pl b/source4/pidl/tests/ndr_alloc.pl index e967bb7cdb..399fbd21d6 100755 --- a/source4/pidl/tests/ndr_alloc.pl +++ b/source4/pidl/tests/ndr_alloc.pl @@ -20,7 +20,7 @@ test_samba4_ndr("alloc-scalar", ',' uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 }; DATA_BLOB b = { data, 5 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct TestAlloc r; if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) @@ -44,7 +44,7 @@ test_samba4_ndr("alloc-buffer", ',' uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 }; DATA_BLOB b = { data, 5 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct TestAlloc r; if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) @@ -65,7 +65,7 @@ test_samba4_ndr("ref-noalloc-null", ',' uint8_t data[] = { 0x03 }; DATA_BLOB b = { data, 1 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct TestAlloc r; r.in.t = NULL; @@ -81,7 +81,7 @@ test_samba4_ndr("ref-noalloc", ',' uint8_t data[] = { 0x03 }; DATA_BLOB b = { data, 1 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct TestAlloc r; uint8_t x; r.in.t = &x; @@ -101,7 +101,7 @@ test_samba4_ndr("ref-alloc", ',' uint8_t data[] = { 0x03 }; DATA_BLOB b = { data, 1 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct TestAlloc r; ndr->flags |= LIBNDR_FLAG_REF_ALLOC; r.in.t = NULL; diff --git a/source4/pidl/tests/ndr_array.pl b/source4/pidl/tests/ndr_array.pl index 174d702c07..2a6b5bbd57 100755 --- a/source4/pidl/tests/ndr_array.pl +++ b/source4/pidl/tests/ndr_array.pl @@ -23,7 +23,7 @@ test_samba4_ndr( b.data = data; b.length = 10; - ndr = ndr_pull_init_blob(&b, mem_ctx); + ndr = ndr_pull_init_blob(&b, mem_ctx, NULL); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_Test(ndr, NDR_IN, &r))) return 1; diff --git a/source4/pidl/tests/ndr_fullptr.pl b/source4/pidl/tests/ndr_fullptr.pl index 27d4e69447..cc6fca7ab3 100755 --- a/source4/pidl/tests/ndr_fullptr.pl +++ b/source4/pidl/tests/ndr_fullptr.pl @@ -17,7 +17,7 @@ test_samba4_ndr("fullptr-push-dup", [public] uint16 echo_TestFull([in,ptr] uint32 *x, [in,ptr] uint32 *y); ', ' - struct ndr_push *ndr = ndr_push_init(); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); uint32_t v = 13; struct echo_TestFull r; r.in.x = &v; diff --git a/source4/pidl/tests/ndr_refptr.pl b/source4/pidl/tests/ndr_refptr.pl index 0fb4810285..d5dd83957a 100755 --- a/source4/pidl/tests/ndr_refptr.pl +++ b/source4/pidl/tests/ndr_refptr.pl @@ -18,7 +18,7 @@ test_samba4_ndr("noptr-push", [public] uint16 echo_TestRef([in] xstruct foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); uint16_t v = 13; struct echo_TestRef r; r.in.foo.x = v; @@ -48,7 +48,7 @@ test_samba4_ndr("ptr-embedded-push", ', ' uint16_t v = 13; - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo.x = &v; @@ -74,7 +74,7 @@ test_samba4_ndr("ptr-embedded-push-null", [public] uint16 echo_TestRef([in] xstruct foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo.x = NULL; @@ -99,7 +99,7 @@ test_samba4_ndr("refptr-embedded-push", ', ' uint16_t v = 13; - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo.x = &v; @@ -126,7 +126,7 @@ test_samba4_ndr("refptr-embedded-push-null", [public] uint16 echo_TestRef([in] xstruct foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo.x = NULL; @@ -144,7 +144,7 @@ test_samba4_ndr("ptr-top-push", [public] uint16 echo_TestRef([in] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; struct xstruct s; s.x = 13; @@ -169,7 +169,7 @@ test_samba4_ndr("ptr-top-push-null", [public] uint16 echo_TestRef([in] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo = NULL; @@ -189,7 +189,7 @@ test_samba4_ndr("refptr-top-push", [public] uint16 echo_TestRef([in,ref] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; struct xstruct s; s.x = 13; @@ -214,7 +214,7 @@ test_samba4_ndr("refptr-top-push-null", [public] uint16 echo_TestRef([in,ref] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo = NULL; @@ -233,7 +233,7 @@ test_samba4_ndr("uniqueptr-top-push", [public] uint16 echo_TestRef([in,unique] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; struct xstruct s; s.x = 13; @@ -261,7 +261,7 @@ test_samba4_ndr("uniqueptr-top-push-null", [public] uint16 echo_TestRef([in,unique] xstruct *foo); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo = NULL; @@ -288,7 +288,7 @@ test_samba4_ndr("ptr-top-out-pull", ' uint8_t data[] = { 0x0D, 0x00 }; DATA_BLOB b = { data, 2 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct xstruct s; struct echo_TestRef r; @@ -315,7 +315,7 @@ test_samba4_ndr("ptr-top-out-pull-null", ' uint8_t data[] = { 0x0D, 0x00 }; DATA_BLOB b = { data, 2 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct echo_TestRef r; r.out.foo = NULL; @@ -338,7 +338,7 @@ test_samba4_ndr("refptr-top-out-pull", ' uint8_t data[] = { 0x0D, 0x00 }; DATA_BLOB b = { data, 2 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct xstruct s; struct echo_TestRef r; @@ -365,7 +365,7 @@ test_samba4_ndr("refptr-top-out-pull-null", ' uint8_t data[] = { 0x0D, 0x00 }; DATA_BLOB b = { data, 2 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL); struct echo_TestRef r; r.out.foo = NULL; @@ -381,7 +381,7 @@ test_samba4_ndr("ptr-top-push-double", ' [public] void echo_TestRef([in] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; uint16_t v = 13; uint16_t *pv = &v; @@ -408,7 +408,7 @@ test_samba4_ndr("ptr-top-push-double-sndnull", ' [public] void echo_TestRef([in] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; uint16_t *pv = NULL; r.in.foo = &pv; @@ -429,7 +429,7 @@ test_samba4_ndr("ptr-top-push-double-fstnull", ' [public] void echo_TestRef([in] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo = NULL; @@ -445,7 +445,7 @@ test_samba4_ndr("refptr-top-push-double", ' [public] void echo_TestRef([in,ref] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; uint16_t v = 13; uint16_t *pv = &v; @@ -473,7 +473,7 @@ test_samba4_ndr("refptr-top-push-double-sndnull", ' [public] void echo_TestRef([in,ref] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; uint16_t *pv = NULL; r.in.foo = &pv; @@ -494,7 +494,7 @@ test_samba4_ndr("refptr-top-push-double-fstnull", ' [public] void echo_TestRef([in,ref] uint16 **foo); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; r.in.foo = NULL; @@ -511,7 +511,7 @@ test_samba4_ndr("ignore-ptr", ' [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar); ', -' struct ndr_push *ndr = ndr_push_init_ctx(NULL); +' struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct echo_TestRef r; uint16_t v = 10; r.in.foo = &v; diff --git a/source4/pidl/tests/ndr_represent.pl b/source4/pidl/tests/ndr_represent.pl index 8c52015642..2d65fb92b0 100755 --- a/source4/pidl/tests/ndr_represent.pl +++ b/source4/pidl/tests/ndr_represent.pl @@ -15,7 +15,7 @@ test_samba4_ndr('represent_as-simple', ' uint8_t expected[] = { 0x0D }; DATA_BLOB in_blob = { expected, 1 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL, NULL); struct bla r; if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r))) @@ -46,7 +46,7 @@ test_samba4_ndr('transmit_as-simple', ' uint8_t expected[] = { 0x0D }; DATA_BLOB in_blob = { expected, 1 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL, NULL); struct bla r; if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r))) diff --git a/source4/pidl/tests/ndr_simple.pl b/source4/pidl/tests/ndr_simple.pl index e5e4197a4f..15e07d5693 100755 --- a/source4/pidl/tests/ndr_simple.pl +++ b/source4/pidl/tests/ndr_simple.pl @@ -18,7 +18,7 @@ test_samba4_ndr("simple", "void Test(); ", b.data = data; b.length = 1; - ndr = ndr_pull_init_blob(&b, mem_ctx); + ndr = ndr_pull_init_blob(&b, mem_ctx, NULL); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_uint8(ndr, NDR_SCALARS, &result))) return 1; diff --git a/source4/pidl/tests/ndr_string.pl b/source4/pidl/tests/ndr_string.pl index 834ef5a289..2f2d941665 100755 --- a/source4/pidl/tests/ndr_string.pl +++ b/source4/pidl/tests/ndr_string.pl @@ -14,7 +14,8 @@ test_samba4_ndr("string-pull-empty", ' uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 }; DATA_BLOB b = { data, 4 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, + smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true)); struct TestString r; r.in.data = NULL; @@ -36,7 +37,8 @@ test_samba4_ndr("string-ascii-pull", uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, \'f\', \'o\', \'o\', 0 }; DATA_BLOB b = { data, 8 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, + smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true)); struct TestString r; r.in.data = NULL; @@ -64,7 +66,8 @@ test_samba4_ndr("string-out", uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, \'f\', \'o\', \'o\', 0 }; DATA_BLOB b = { data, 8 }; - struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); + struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, + smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true)); struct TestString r; char *str = NULL; r.out.data = &str; diff --git a/source4/pidl/tests/ndr_tagtype.pl b/source4/pidl/tests/ndr_tagtype.pl index 4d6bcb53af..3f9b717bfe 100755 --- a/source4/pidl/tests/ndr_tagtype.pl +++ b/source4/pidl/tests/ndr_tagtype.pl @@ -10,7 +10,7 @@ use Util qw(test_samba4_ndr); test_samba4_ndr('struct-notypedef', '[public] struct bla { uint8 x; }; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct bla r; uint8_t expected[] = { 0x0D }; DATA_BLOB expected_blob = { expected, 1 }; @@ -29,7 +29,7 @@ test_samba4_ndr('struct-notypedef', '[public] struct bla { uint8 x; }; ', test_samba4_ndr('struct-notypedef-used', '[public] struct bla { uint8 x; }; [public] void myfn([in] struct bla r); ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct myfn fn; uint8_t expected[] = { 0x0D }; DATA_BLOB expected_blob = { expected, 1 }; @@ -49,7 +49,7 @@ test_samba4_ndr('struct-notypedef-used', '[public] struct bla { uint8 x; }; test_samba4_ndr('struct-notypedef-embedded', 'struct bla { uint8 x; }; [public] struct myst { struct bla r; }; ', ' - struct ndr_push *ndr = ndr_push_init_ctx(NULL); + struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL); struct myst st; uint8_t expected[] = { 0x0D }; DATA_BLOB expected_blob = { expected, 1 }; diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c index 256f20ed54..b043424faa 100644 --- a/source4/rpc_server/dcerpc_server.c +++ b/source4/rpc_server/dcerpc_server.c @@ -821,7 +821,8 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call) return dcesrv_fault(call, DCERPC_FAULT_UNK_IF); } - pull = ndr_pull_init_blob(&call->pkt.u.request.stub_and_verifier, call); + pull = ndr_pull_init_blob(&call->pkt.u.request.stub_and_verifier, call, + lp_iconv_convenience(call->conn->dce_ctx->lp_ctx)); NT_STATUS_HAVE_NO_MEMORY(pull); pull->flags |= LIBNDR_FLAG_REF_ALLOC; @@ -884,7 +885,7 @@ _PUBLIC_ NTSTATUS dcesrv_reply(struct dcesrv_call_state *call) } /* form the reply NDR */ - push = ndr_push_init_ctx(call); + push = ndr_push_init_ctx(call, lp_iconv_convenience(call->conn->dce_ctx->lp_ctx)); NT_STATUS_HAVE_NO_MEMORY(push); /* carry over the pointer count to the reply in case we are @@ -1049,7 +1050,7 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn) blob = dce_conn->partial_input; blob.length = dcerpc_get_frag_length(&blob); - ndr = ndr_pull_init_blob(&blob, call); + ndr = ndr_pull_init_blob(&blob, call, lp_iconv_convenience(call->conn->dce_ctx->lp_ctx)); if (!ndr) { talloc_free(dce_conn->partial_input.data); talloc_free(call); diff --git a/source4/rpc_server/dcesrv_auth.c b/source4/rpc_server/dcesrv_auth.c index fa724a0726..aa37de2826 100644 --- a/source4/rpc_server/dcesrv_auth.c +++ b/source4/rpc_server/dcesrv_auth.c @@ -73,7 +73,7 @@ bool dcesrv_auth_bind(struct dcesrv_call_state *call) } cli_credentials_set_conf(server_credentials, call->conn->dce_ctx->lp_ctx); - status = cli_credentials_set_machine_account(server_credentials); + status = cli_credentials_set_machine_account(server_credentials, call->conn->dce_ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(status))); talloc_free(server_credentials); @@ -326,7 +326,7 @@ bool dcesrv_auth_request(struct dcesrv_call_state *call, DATA_BLOB *full_packet) pkt->u.request.stub_and_verifier.length -= auth_blob.length; /* pull the auth structure */ - ndr = ndr_pull_init_blob(&auth_blob, call); + ndr = ndr_pull_init_blob(&auth_blob, call, lp_iconv_convenience(call->conn->dce_ctx->lp_ctx)); if (!ndr) { return false; } @@ -406,7 +406,7 @@ bool dcesrv_auth_response(struct dcesrv_call_state *call, return NT_STATUS_IS_OK(status); } - ndr = ndr_push_init_ctx(call); + ndr = ndr_push_init_ctx(call, lp_iconv_convenience(dce_conn->dce_ctx->lp_ctx)); if (!ndr) { return false; } diff --git a/source4/rpc_server/remote/dcesrv_remote.c b/source4/rpc_server/remote/dcesrv_remote.c index 3b5c0a02ae..cd32160d88 100644 --- a/source4/rpc_server/remote/dcesrv_remote.c +++ b/source4/rpc_server/remote/dcesrv_remote.c @@ -89,7 +89,7 @@ static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct if (domain) { cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED); } - status = cli_credentials_set_machine_account(credentials); + status = cli_credentials_set_machine_account(credentials, dce_call->conn->dce_ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { return status; } diff --git a/source4/rpc_server/service_rpc.c b/source4/rpc_server/service_rpc.c index 265cf0b812..33a86851a8 100644 --- a/source4/rpc_server/service_rpc.c +++ b/source4/rpc_server/service_rpc.c @@ -377,10 +377,15 @@ static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, /* Add TCP/IP sockets */ if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) { - int num_interfaces = iface_count(lp_ctx); + int num_interfaces; int i; + struct interface *ifaces; + + load_interfaces(dce_ctx, lp_interfaces(lp_ctx), &ifaces); + + num_interfaces = iface_count(ifaces); for(i = 0; i < num_interfaces; i++) { - const char *address = iface_n_ip(lp_ctx, i); + const char *address = iface_n_ip(ifaces, i); status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address); NT_STATUS_NOT_OK_RETURN(status); } diff --git a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c index 55a647b7ef..ebbeb2d0df 100644 --- a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c +++ b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c @@ -444,7 +444,7 @@ static WERROR dcesrv_srvsvc_NetShareAdd(struct dcesrv_call_state *dce_call, TALL int count = 8; int i; - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -542,7 +542,7 @@ static WERROR dcesrv_srvsvc_NetShareAdd(struct dcesrv_call_state *dce_call, TALL int count = 10; int i; - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -734,7 +734,7 @@ static WERROR dcesrv_srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, /* TODO: - paging of results */ - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -983,7 +983,7 @@ static WERROR dcesrv_srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, return WERR_INVALID_PARAM; } - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -1237,7 +1237,7 @@ static WERROR dcesrv_srvsvc_NetShareSetInfo(struct dcesrv_call_state *dce_call, return WERR_INVALID_PARAM; } - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -1414,7 +1414,7 @@ static WERROR dcesrv_srvsvc_NetShareCheck(struct dcesrv_call_state *dce_call, TA } all_string_sub(device, "\\", "/", 0); - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -1828,7 +1828,7 @@ static WERROR dcesrv_srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TAL /* TODO: - paging of results */ - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } @@ -2291,7 +2291,7 @@ static WERROR dcesrv_srvsvc_NetShareDel(struct dcesrv_call_state *dce_call, TALL NTSTATUS nterr; struct share_context *sctx; - nterr = share_get_context(mem_ctx, &sctx); + nterr = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } diff --git a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c index 21fbc53f2c..ccd6c4f74e 100644 --- a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c +++ b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c @@ -25,6 +25,7 @@ #include "rpc_server/common/common.h" #include "rpc_server/srvsvc/proto.h" #include "lib/socket/socket.h" +#include "param/param.h" struct socket_address *srvsvc_get_my_addr(void *p, TALLOC_CTX *mem_ctx) { @@ -61,7 +62,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, struct share_config *scfg; const char *sharetype; - status = share_get_context(mem_ctx, &sctx); + status = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->conn->dce_ctx->lp_ctx, &sctx); if (!NT_STATUS_IS_OK(status)) { return status; } diff --git a/source4/samba4-skip b/source4/samba4-skip index 853d54d0a2..d88f010511 100644 --- a/source4/samba4-skip +++ b/source4/samba4-skip @@ -49,7 +49,3 @@ RPC-FRSAPI # Not provided by Samba 4 ^samba4.NET-API-BECOME-DC.*$ # Fails WINBIND # FIXME: This should not be skipped NSS-TEST # Fails -samba4.ldb.python # Fails to link properly -samba4.credentials.python # Fails to link properly -samba4.registry.python # Fails to link properly -samba4.auth.python # Fails to link properly diff --git a/source4/scripting/ejs/smbcalls_auth.c b/source4/scripting/ejs/smbcalls_auth.c index 7747bb14c6..89370890c8 100644 --- a/source4/scripting/ejs/smbcalls_auth.c +++ b/source4/scripting/ejs/smbcalls_auth.c @@ -56,7 +56,8 @@ static int ejs_doauth(MprVarHandle eid, } else { /* Hope we can find the event context somewhere up there... */ ev = event_context_find(tmp_ctx); - msg = messaging_client_init(tmp_ctx, lp_messaging_path(tmp_ctx, global_loadparm), ev); + msg = messaging_client_init(tmp_ctx, lp_messaging_path(tmp_ctx, global_loadparm), + lp_iconv_convenience(global_loadparm), ev); } if (auth_types) { diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c index e08a098833..a7210eb0fb 100644 --- a/source4/scripting/ejs/smbcalls_cli.c +++ b/source4/scripting/ejs/smbcalls_cli.c @@ -437,7 +437,7 @@ static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv) /* Do connect */ io.in.dest_host = hostname; - io.in.port = 0; + io.in.dest_ports = lp_smb_ports(global_loadparm); io.in.called_name = strupper_talloc(mem_ctx, hostname); io.in.service = sharename; io.in.service_type = "?????"; diff --git a/source4/scripting/ejs/smbcalls_config.c b/source4/scripting/ejs/smbcalls_config.c index 88c153ead3..07e0f479da 100644 --- a/source4/scripting/ejs/smbcalls_config.c +++ b/source4/scripting/ejs/smbcalls_config.c @@ -199,9 +199,6 @@ static int ejs_lpReload(MprVarHandle eid, int argc, char **argv) const char *filename = lp_configfile(global_loadparm); ret = lp_load(global_loadparm, filename); - if (ret) { - unload_interfaces(); - } mpr_Return(eid, mprCreateBoolVar(ret)); return 0; } diff --git a/source4/scripting/ejs/smbcalls_creds.c b/source4/scripting/ejs/smbcalls_creds.c index 781843371a..6dfff8f925 100644 --- a/source4/scripting/ejs/smbcalls_creds.c +++ b/source4/scripting/ejs/smbcalls_creds.c @@ -192,7 +192,7 @@ static int ejs_creds_set_machine_account(MprVarHandle eid, int argc, struct MprV return -1; } - if (NT_STATUS_IS_OK(cli_credentials_set_machine_account(creds))) { + if (NT_STATUS_IS_OK(cli_credentials_set_machine_account(creds, global_loadparm))) { mpr_Return(eid, mprCreateBoolVar(true)); } else { mpr_Return(eid, mprCreateBoolVar(false)); diff --git a/source4/scripting/ejs/smbcalls_data.c b/source4/scripting/ejs/smbcalls_data.c index d0dd96c087..3ea41d46fb 100644 --- a/source4/scripting/ejs/smbcalls_data.c +++ b/source4/scripting/ejs/smbcalls_data.c @@ -177,7 +177,7 @@ static int ejs_regToVar(MprVarHandle eid, int argc, struct MprVar **argv) case REG_EXPAND_SZ: { char *s; ssize_t len; - len = convert_string_talloc(mprMemCtx(), global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, blob->data, blob->length, (void **)&s); if (len == -1) { ejsSetErrorMsg(eid, "regToVar invalid REG_SZ string"); @@ -225,7 +225,7 @@ static int ejs_regToVar(MprVarHandle eid, int argc, struct MprVar **argv) if (slen == 2 && b.length == 2 && SVAL(b.data, 0) == 0) { break; } - len = convert_string_talloc(mprMemCtx(), global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, b.data, slen, (void **)&s); if (len == -1) { ejsSetErrorMsg(eid, "regToVar invalid REG_MULTI_SZ string"); diff --git a/source4/scripting/ejs/smbcalls_nbt.c b/source4/scripting/ejs/smbcalls_nbt.c index 5eaf458f34..c3679b1ec7 100644 --- a/source4/scripting/ejs/smbcalls_nbt.c +++ b/source4/scripting/ejs/smbcalls_nbt.c @@ -70,7 +70,7 @@ static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv) result = 0; - nt_status = resolve_name(&name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx), lp_name_resolve_order(global_loadparm)); + nt_status = resolve_name(lp_resolve_context(global_loadparm), &name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx)); if (NT_STATUS_IS_OK(nt_status)) { mprSetPropertyValue(argv[0], "value", mprString(reply_addr)); diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c index 830c45d978..5fbb0bb017 100644 --- a/source4/scripting/ejs/smbcalls_param.c +++ b/source4/scripting/ejs/smbcalls_param.c @@ -45,7 +45,7 @@ static int ejs_param_get(MprVarHandle eid, int argc, char **argv) if (argc == 2) { ret = param_get_string(ctx, argv[0], argv[1]); } else { - ret = param_get_string(ctx, NULL, argv[0]); + ret = param_get_string(ctx, argv[0], NULL); } if (ret) { @@ -78,7 +78,7 @@ static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv) if (argc == 2) { ret = param_get_string_list(ctx, argv[0], argv[1], NULL); } else { - ret = param_get_string_list(ctx, NULL, argv[0], NULL); + ret = param_get_string_list(ctx, argv[0], NULL, NULL); } if (ret != NULL) { @@ -123,9 +123,9 @@ static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv) list = mprToList(mprMemCtx(), value); if (list) { - ret = param_set_string_list(ctx, section, paramname, list); + ret = param_set_string_list(ctx, paramname, list, section); } else { - ret = param_set_string(ctx, section, paramname, mprToString(value)); + ret = param_set_string(ctx, paramname, mprToString(value), section); } mpr_Return(eid, mprCreateBoolVar(ret)); diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c index 535c1d2e34..2bfc8b5883 100644 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ b/source4/scripting/ejs/smbcalls_rpc.c @@ -80,7 +80,9 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv) for (i=0;i<10000;i++) { p->msg_ctx = messaging_init(p, lp_messaging_path(p, global_loadparm), - cluster_id(EJS_ID_BASE + i), ev); + cluster_id(EJS_ID_BASE + i), + lp_iconv_convenience(global_loadparm), + ev); if (p->msg_ctx) break; } if (p->msg_ctx == NULL) { diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c index 86e0873e09..72ddf90231 100644 --- a/source4/scripting/ejs/smbcalls_sys.c +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -32,11 +32,18 @@ */ static int ejs_sys_interfaces(MprVarHandle eid, int argc, struct MprVar **argv) { - int i, count = iface_count(global_loadparm); + int i, count; struct MprVar ret = mprArray("interfaces"); + struct interface *ifaces; + + load_interfaces(NULL, lp_interfaces(global_loadparm), &ifaces); + + count = iface_count(ifaces); for (i=0;i<count;i++) { - mprAddArray(&ret, i, mprString(iface_n_ip(global_loadparm, i))); + mprAddArray(&ret, i, mprString(iface_n_ip(ifaces, i))); } + + talloc_free(ifaces); mpr_Return(eid, ret); return 0; } diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js index f9814884f3..0da02ae276 100644 --- a/source4/scripting/libjs/provision.js +++ b/source4/scripting/libjs/provision.js @@ -1018,6 +1018,7 @@ function provision_guess() var modules_list = new Array("rootdse", "paged_results", "ranged_results", + "anr", "server_sort", "extended_dn", "asq", diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 5e982556fc..96e4da9add 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -65,7 +65,7 @@ if test -z "$PYTHON_LDFLAGS"; then py_version=`$PYTHON -c "from distutils.sysconfig import *; \ from string import join; \ print join(get_config_vars('VERSION'))"` - if test "$py_version" == "[None]"; then + if test "$py_version" = "[None]"; then if test -n "$PYTHON_VERSION"; then py_version=$PYTHON_VERSION else @@ -119,9 +119,31 @@ AC_SUBST(PYTHON_EXTRA_LDFLAGS) SMB_EXT_LIB(LIBPYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CPPFLAGS]) + +AC_MSG_CHECKING(working python module support) if test x$working_python = xyes then - SMB_ENABLE(LIBPYTHON,YES) + ac_save_LIBS="$LIBS" + ac_save_CFLAGS="$CFLAGS" + LIBS="$LIBS $PYTHON_LDFLAGS" + CFLAGS="$CFLAGS $PYTHON_CPPFLAGS" + + AC_TRY_LINK([ + #include <Python.h> + #include <stdlib.h> + ],[ + Py_InitModule(NULL, NULL); + ],[ + SMB_ENABLE(LIBPYTHON,YES) + AC_MSG_RESULT([yes]) + ],[ + SMB_ENABLE(LIBPYTHON,NO) + AC_MSG_RESULT([no]) + ]) + + LIBS="$ac_save_LIBS" + CFLAGS="$ac_save_CFLAGS" else SMB_ENABLE(LIBPYTHON,NO) + AC_MSG_RESULT([no]) fi diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index 91437e1e0b..d0d3829eef 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -1,13 +1,9 @@ -[PYTHON::python_param] -PRIVATE_DEPENDENCIES = LIBSAMBA-CONFIG -OBJ_FILES = parammodule.o - [PYTHON::python_uuid] PRIVATE_DEPENDENCIES = LIBNDR OBJ_FILES = uuidmodule.o [PYTHON::python_misc] -PRIVATE_DEPENDENCIES = LIBNDR LIBLDB +PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB SWIG_FILE = misc.i # Swig extensions @@ -16,7 +12,7 @@ swig: pythonmods .SUFFIXES: _wrap.c .i .i_wrap.c: - [ "$(SWIG)" == "no" ] || $(SWIG) -Wall -I$(srcdir)/scripting/swig -python -keyword $< + [ "$(SWIG)" == "no" ] || $(SWIG) -O -Wall -I$(srcdir)/scripting/swig -python -keyword $< realdistclean:: @echo "Removing SWIG output files" @@ -29,3 +25,7 @@ PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py pydoctor:: pythonmods LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES)) + +clean:: + @echo "Removing python modules" + @rm -f bin/python/* diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i index 088522320e..3af10dfce9 100644 --- a/source4/scripting/python/misc.i +++ b/source4/scripting/python/misc.i @@ -21,12 +21,47 @@ %{ #include "includes.h" #include "ldb.h" -#include "auth/credentials/credentials.h" +#include "param/param.h" +#include "dsdb/samdb/samdb.h" +#include "lib/ldb-samba/ldif_handlers.h" %} %import "stdint.i" +%include "exception.i" %import "../../lib/talloc/talloc.i" +%import "../../lib/ldb/ldb.i" +%import "../../auth/credentials/credentials.i" +%import "../../param/param.i" +%import "../../libcli/security/security.i" +%import "../../libcli/util/errors.i" %rename(random_password) generate_random_str; char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); +%inline %{ +void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds) +{ + ldb_set_opaque(ldb, "credentials", creds); +} + +void ldb_set_session_info(struct ldb_context *ldb, struct auth_session_info *session_info) +{ + ldb_set_opaque(ldb, "sessionInfo", session_info); +} + +void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx) +{ + ldb_set_opaque(ldb, "loadparm", lp_ctx); +} + +%} + +bool samdb_set_domain_sid(struct ldb_context *ldb, + const struct dom_sid *dom_sid_in); + +WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf, const char *df); + +%rename(version) samba_version_string; +const char *samba_version_string(void); +int dsdb_set_global_schema(struct ldb_context *ldb); +int ldb_register_samba_handlers(struct ldb_context *ldb); diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py index 94625be2c9..ae900a1f62 100644 --- a/source4/scripting/python/misc.py +++ b/source4/scripting/python/misc.py @@ -2,7 +2,6 @@ # Version 1.3.33 # # Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. import _misc import new @@ -48,6 +47,28 @@ except AttributeError: del types +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +import ldb +import credentials +import param +import security random_password = _misc.random_password +ldb_set_credentials = _misc.ldb_set_credentials +ldb_set_session_info = _misc.ldb_set_session_info +ldb_set_loadparm = _misc.ldb_set_loadparm +samdb_set_domain_sid = _misc.samdb_set_domain_sid +dsdb_attach_schema_from_ldif_file = _misc.dsdb_attach_schema_from_ldif_file +version = _misc.version +dsdb_set_global_schema = _misc.dsdb_set_global_schema +ldb_register_samba_handlers = _misc.ldb_register_samba_handlers diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c index 2237f9cb03..dc1203e2f0 100644 --- a/source4/scripting/python/misc_wrap.c +++ b/source4/scripting/python/misc_wrap.c @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ #define SWIGPYTHON -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIG_PYTHON_NO_BUILD_NONE /* ----------------------------------------------------------------------------- * This section contains generic SWIG labels for method/variable * declarations/attributes, and other compiler dependent labels. @@ -2454,20 +2454,40 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) + #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail;; } while(0) + + /* -------- TYPES TABLE (BEGIN) -------- */ #define SWIGTYPE_p_TALLOC_CTX swig_types[0] -#define SWIGTYPE_p_char swig_types[1] -#define SWIGTYPE_p_int swig_types[2] -#define SWIGTYPE_p_long_long swig_types[3] -#define SWIGTYPE_p_short swig_types[4] -#define SWIGTYPE_p_signed_char swig_types[5] -#define SWIGTYPE_p_unsigned_char swig_types[6] -#define SWIGTYPE_p_unsigned_int swig_types[7] -#define SWIGTYPE_p_unsigned_long_long swig_types[8] -#define SWIGTYPE_p_unsigned_short swig_types[9] -static swig_type_info *swig_types[11]; -static swig_module_info swig_module = {swig_types, 10, 0, 0, 0, 0}; +#define SWIGTYPE_p_auth_session_info swig_types[1] +#define SWIGTYPE_p_char swig_types[2] +#define SWIGTYPE_p_cli_credentials swig_types[3] +#define SWIGTYPE_p_dom_sid swig_types[4] +#define SWIGTYPE_p_int swig_types[5] +#define SWIGTYPE_p_ldb_context swig_types[6] +#define SWIGTYPE_p_ldb_dn swig_types[7] +#define SWIGTYPE_p_ldb_ldif swig_types[8] +#define SWIGTYPE_p_ldb_message swig_types[9] +#define SWIGTYPE_p_ldb_message_element swig_types[10] +#define SWIGTYPE_p_ldb_result swig_types[11] +#define SWIGTYPE_p_loadparm_context swig_types[12] +#define SWIGTYPE_p_loadparm_service swig_types[13] +#define SWIGTYPE_p_long_long swig_types[14] +#define SWIGTYPE_p_param_context swig_types[15] +#define SWIGTYPE_p_param_opt swig_types[16] +#define SWIGTYPE_p_param_section swig_types[17] +#define SWIGTYPE_p_security_descriptor swig_types[18] +#define SWIGTYPE_p_security_token swig_types[19] +#define SWIGTYPE_p_short swig_types[20] +#define SWIGTYPE_p_signed_char swig_types[21] +#define SWIGTYPE_p_unsigned_char swig_types[22] +#define SWIGTYPE_p_unsigned_int swig_types[23] +#define SWIGTYPE_p_unsigned_long swig_types[24] +#define SWIGTYPE_p_unsigned_long_long swig_types[25] +#define SWIGTYPE_p_unsigned_short swig_types[26] +static swig_type_info *swig_types[28]; +static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2478,6 +2498,19 @@ static swig_module_info swig_module = {swig_types, 10, 0, 0, 0, 0}; # error "This python version requires swig to be run with the '-classic' option" # endif #endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery /*----------------------------------------------- @(target):= _misc.so @@ -2496,7 +2529,9 @@ static swig_module_info swig_module = {swig_types, 10, 0, 0, 0, 0}; #include "includes.h" #include "ldb.h" -#include "auth/credentials/credentials.h" +#include "param/param.h" +#include "dsdb/samdb/samdb.h" +#include "lib/ldb-samba/ldif_handlers.h" SWIGINTERN int @@ -2669,6 +2704,95 @@ SWIG_FromCharPtr(const char *cptr) return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); } + +void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds) +{ + ldb_set_opaque(ldb, "credentials", creds); +} + +void ldb_set_session_info(struct ldb_context *ldb, struct auth_session_info *session_info) +{ + ldb_set_opaque(ldb, "sessionInfo", session_info); +} + +void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx) +{ + ldb_set_opaque(ldb, "loadparm", lp_ctx); +} + + + +SWIGINTERNINLINE PyObject* + SWIG_From_bool (bool value) +{ + return PyBool_FromLong(value ? 1 : 0); +} + + +SWIGINTERN int +SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) +{ + if (PyString_Check(obj)) { + char *cstr; Py_ssize_t len; + PyString_AsStringAndSize(obj, &cstr, &len); + if (cptr) { + if (alloc) { + /* + In python the user should not be able to modify the inner + string representation. To warranty that, if you define + SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string + buffer is always returned. + + The default behavior is just to return the pointer value, + so, be careful. + */ +#if defined(SWIG_PYTHON_SAFE_CSTRINGS) + if (*alloc != SWIG_OLDOBJ) +#else + if (*alloc == SWIG_NEWOBJ) +#endif + { + *cptr = (char *)memcpy((char *)malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); + *alloc = SWIG_NEWOBJ; + } + else { + *cptr = cstr; + *alloc = SWIG_OLDOBJ; + } + } else { + *cptr = PyString_AsString(obj); + } + } + if (psize) *psize = len + 1; + return SWIG_OK; + } else { + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + if (pchar_descriptor) { + void* vptr = 0; + if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { + if (cptr) *cptr = (char *) vptr; + if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; + if (alloc) *alloc = SWIG_OLDOBJ; + return SWIG_OK; + } + } + } + return SWIG_TypeError; +} + + + + + + #define SWIG_From_long PyInt_FromLong + + +SWIGINTERNINLINE PyObject * +SWIG_From_int (int value) +{ + return SWIG_From_long (value); +} + #ifdef __cplusplus extern "C" { #endif @@ -2701,8 +2825,313 @@ fail: } +SWIGINTERN PyObject *_wrap_ldb_set_credentials(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + struct cli_credentials *arg2 = (struct cli_credentials *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "ldb",(char *) "creds", NULL + }; + + { + arg2 = NULL; + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|O:ldb_set_credentials",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_credentials" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + if (obj1) { + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_cli_credentials, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_credentials" "', argument " "2"" of type '" "struct cli_credentials *""'"); + } + arg2 = (struct cli_credentials *)(argp2); + } + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + ldb_set_credentials(arg1,arg2); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ldb_set_session_info(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + struct auth_session_info *arg2 = (struct auth_session_info *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "ldb",(char *) "session_info", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_set_session_info",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_session_info" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_auth_session_info, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_session_info" "', argument " "2"" of type '" "struct auth_session_info *""'"); + } + arg2 = (struct auth_session_info *)(argp2); + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + ldb_set_session_info(arg1,arg2); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ldb_set_loadparm(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + struct loadparm_context *arg2 = (struct loadparm_context *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "ldb",(char *) "lp_ctx", NULL + }; + + { + arg2 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|O:ldb_set_loadparm",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_loadparm" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + if (obj1) { + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_loadparm" "', argument " "2"" of type '" "struct loadparm_context *""'"); + } + arg2 = (struct loadparm_context *)(argp2); + } + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + ldb_set_loadparm(arg1,arg2); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_samdb_set_domain_sid(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + struct dom_sid *arg2 = (struct dom_sid *) 0 ; + bool result; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "ldb",(char *) "dom_sid_in", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:samdb_set_domain_sid",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "samdb_set_domain_sid" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_dom_sid, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "samdb_set_domain_sid" "', argument " "2"" of type '" "struct dom_sid const *""'"); + } + arg2 = (struct dom_sid *)(argp2); + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + result = (bool)samdb_set_domain_sid(arg1,(struct dom_sid const *)arg2); + resultobj = SWIG_From_bool((bool)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_dsdb_attach_schema_from_ldif_file(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + WERROR result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "ldb",(char *) "pf",(char *) "df", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:dsdb_attach_schema_from_ldif_file",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "dsdb_attach_schema_from_ldif_file" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "dsdb_attach_schema_from_ldif_file" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "dsdb_attach_schema_from_ldif_file" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + result = dsdb_attach_schema_from_ldif_file(arg1,(char const *)arg2,(char const *)arg3); + { + if (!W_ERROR_IS_OK(result)) { + PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result)); + PyErr_SetObject(PyExc_RuntimeError, obj); + } else if (resultobj == NULL) { + resultobj = Py_None; + } + } + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_version(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"version",0,0,0)) SWIG_fail; + result = (char *)samba_version_string(); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_dsdb_set_global_schema(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "ldb", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:dsdb_set_global_schema",kwnames,&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "dsdb_set_global_schema" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + result = (int)dsdb_set_global_schema(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ldb_register_samba_handlers(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + char * kwnames[] = { + (char *) "ldb", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:ldb_register_samba_handlers",kwnames,&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_register_samba_handlers" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + { + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + } + result = (int)ldb_register_samba_handlers(arg1); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_set_session_info", (PyCFunction) _wrap_ldb_set_session_info, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"dsdb_attach_schema_from_ldif_file", (PyCFunction) _wrap_dsdb_attach_schema_from_ldif_file, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"version", (PyCFunction)_wrap_version, METH_NOARGS, NULL}, + { (char *)"dsdb_set_global_schema", (PyCFunction) _wrap_dsdb_set_global_schema, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } }; @@ -2710,49 +3139,117 @@ static PyMethodDef SwigMethods[] = { /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_auth_session_info = {"_p_auth_session_info", "struct auth_session_info *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_cli_credentials = {"_p_cli_credentials", "struct cli_credentials *|cli_credentials *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_dom_sid = {"_p_dom_sid", "struct dom_sid *|dom_sid *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_context = {"_p_ldb_context", "struct ldb_context *|ldb *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_dn = {"_p_ldb_dn", "struct ldb_dn *|ldb_dn *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_ldif = {"_p_ldb_ldif", "struct ldb_ldif *|ldb_ldif *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_message = {"_p_ldb_message", "ldb_msg *|struct ldb_message *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_msg_element *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_security_descriptor = {"_p_security_descriptor", "struct security_descriptor *|security_descriptor *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_security_token = {"_p_security_token", "struct security_token *|security_token *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "uintptr_t *|uint_least32_t *|uint_fast32_t *|uint32_t *|unsigned int *|uint_fast16_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_long = {"_p_unsigned_long", "unsigned long *|time_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_unsigned_long_long = {"_p_unsigned_long_long", "uint_least64_t *|uint_fast64_t *|uint64_t *|unsigned long long *|uintmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|uint_least16_t *|uint16_t *", 0, 0, (void*)0, 0}; static swig_type_info *swig_type_initial[] = { &_swigt__p_TALLOC_CTX, + &_swigt__p_auth_session_info, &_swigt__p_char, + &_swigt__p_cli_credentials, + &_swigt__p_dom_sid, &_swigt__p_int, + &_swigt__p_ldb_context, + &_swigt__p_ldb_dn, + &_swigt__p_ldb_ldif, + &_swigt__p_ldb_message, + &_swigt__p_ldb_message_element, + &_swigt__p_ldb_result, + &_swigt__p_loadparm_context, + &_swigt__p_loadparm_service, &_swigt__p_long_long, + &_swigt__p_param_context, + &_swigt__p_param_opt, + &_swigt__p_param_section, + &_swigt__p_security_descriptor, + &_swigt__p_security_token, &_swigt__p_short, &_swigt__p_signed_char, &_swigt__p_unsigned_char, &_swigt__p_unsigned_int, + &_swigt__p_unsigned_long, &_swigt__p_unsigned_long_long, &_swigt__p_unsigned_short, }; static swig_cast_info _swigc__p_TALLOC_CTX[] = { {&_swigt__p_TALLOC_CTX, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_auth_session_info[] = { {&_swigt__p_auth_session_info, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_cli_credentials[] = { {&_swigt__p_cli_credentials, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_dom_sid[] = { {&_swigt__p_dom_sid, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_context[] = { {&_swigt__p_ldb_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_dn[] = { {&_swigt__p_ldb_dn, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_ldif[] = { {&_swigt__p_ldb_ldif, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_message[] = { {&_swigt__p_ldb_message, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_message_element[] = { {&_swigt__p_ldb_message_element, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_result[] = { {&_swigt__p_ldb_result, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_opt[] = { {&_swigt__p_param_opt, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_security_descriptor[] = { {&_swigt__p_security_descriptor, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_security_token[] = { {&_swigt__p_security_token, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_long[] = { {&_swigt__p_unsigned_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_unsigned_long_long[] = { {&_swigt__p_unsigned_long_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { _swigc__p_TALLOC_CTX, + _swigc__p_auth_session_info, _swigc__p_char, + _swigc__p_cli_credentials, + _swigc__p_dom_sid, _swigc__p_int, + _swigc__p_ldb_context, + _swigc__p_ldb_dn, + _swigc__p_ldb_ldif, + _swigc__p_ldb_message, + _swigc__p_ldb_message_element, + _swigc__p_ldb_result, + _swigc__p_loadparm_context, + _swigc__p_loadparm_service, _swigc__p_long_long, + _swigc__p_param_context, + _swigc__p_param_opt, + _swigc__p_param_section, + _swigc__p_security_descriptor, + _swigc__p_security_token, _swigc__p_short, _swigc__p_signed_char, _swigc__p_unsigned_char, _swigc__p_unsigned_int, + _swigc__p_unsigned_long, _swigc__p_unsigned_long_long, _swigc__p_unsigned_short, }; diff --git a/source4/scripting/python/parammodule.c b/source4/scripting/python/parammodule.c deleted file mode 100644 index bb7adab240..0000000000 --- a/source4/scripting/python/parammodule.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Python wrapper for reading smb.conf files - - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "Python.h" -#include "param/param.h" - -staticforward PyTypeObject param_ParamFileType; - -typedef struct { - PyObject_HEAD - struct param_context *param_ctx; -} param_ParamFileObject; - -static param_ParamFileObject *py_param_init(void) -{ - param_ParamFileObject *param; - - param = PyObject_New(param_ParamFileObject, ¶m_ParamFileType); - - param->param_ctx = param_init(NULL); - - return param; -} - -static PyObject *py_param_load(PyObject *self, PyObject *args) -{ - char *filename = NULL; - param_ParamFileObject *param; - - if (!PyArg_ParseTuple(args, "|s:new", &filename)) - return NULL; - - param = py_param_init(); - - if (filename != NULL) { - int ret = param_read(param->param_ctx, filename); - - if (ret == -1) { - PyErr_SetString(PyExc_TypeError, "reading file failed"); - return NULL; - } - } - - return (PyObject *)param; -} - -static void -param_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -static PyObject *py_param_get(PyObject *_self, PyObject *args) -{ - struct param_opt *param; - const char *section_name = NULL, *param_name = NULL; - param_ParamFileObject *self = (param_ParamFileObject *)_self; - - if (!PyArg_ParseTuple(args, (char *)"s|s", ¶m_name, §ion_name)) - return NULL; - - param = param_get(self->param_ctx, section_name, param_name); - if (param == NULL) - return Py_None; - - return PyString_FromString(param->value); -} - -static PyObject *py_param_set(PyObject *_self, PyObject *args) -{ - param_ParamFileObject *self = (param_ParamFileObject *)_self; - const char *section_name = NULL, *param_name = NULL, *param_value = NULL; - - if (!PyArg_ParseTuple(args, "ss|s", ¶m_name, ¶m_value, §ion_name)) - return NULL; - - if (section_name == NULL) - section_name = GLOBAL_NAME; - - if (param_set_string(self->param_ctx, section_name, param_name, param_value) != 0) { - PyErr_SetString(PyExc_TypeError, "setting variable failed"); - return NULL; - } - - return Py_None; -} - -static PyObject *py_param_save(PyObject *_self, PyObject *args) -{ - param_ParamFileObject *self = (param_ParamFileObject *)_self; - const char *filename = NULL; - - if (!PyArg_ParseTuple(args, "s", &filename)) - return NULL; - - if (param_write(self->param_ctx, filename) != 0) { - PyErr_SetString(PyExc_TypeError, "unable to save"); - return NULL; - } - - return Py_None; -} - -static PyObject *py_param_use(PyObject *_self, PyObject *args) -{ - param_ParamFileObject *self = (param_ParamFileObject *)_self; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - if (param_use(global_loadparm, self->param_ctx) != 0) { - PyErr_SetString(PyExc_TypeError, "unable to use"); - return NULL; - } - - return Py_None; -} - -static PyMethodDef param_methods[] = { - {"get", (PyCFunction)py_param_get, METH_VARARGS, - "Get a parameter."}, - {"set", (PyCFunction)py_param_set, METH_VARARGS, - "Set a parameter."}, - {"save", (PyCFunction)py_param_save, METH_VARARGS, - "Save file" }, - {"use", (PyCFunction)py_param_use, METH_VARARGS, - "Use param file" }, - {NULL, NULL, 0, NULL} -}; - -static PyObject * -param_getattr(PyTypeObject *obj, char *name) -{ - return Py_FindMethod(param_methods, (PyObject *)obj, name); -} - -static PyTypeObject param_ParamFileType = { - PyObject_HEAD_INIT(NULL) 0, - .tp_name = "ParamFile", - .tp_basicsize = sizeof(param_ParamFileObject), - .tp_dealloc = param_dealloc, - .tp_getattr = param_getattr, -}; - - -static PyMethodDef methods[] = { - { "ParamFile", (PyCFunction)py_param_load, METH_VARARGS, NULL}, - { NULL, NULL } -}; - -PyDoc_STRVAR(param_doc, "Simple wrappers around the smb.conf parsers"); - -PyMODINIT_FUNC initparam(void) -{ - PyObject *mod = Py_InitModule3("param", methods, param_doc); - if (mod == NULL) - return; - - PyModule_AddObject(mod, "configfile", - PyString_FromString(lp_configfile(global_loadparm))); -} diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 46d8ff7d37..2c46f72883 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -19,27 +19,140 @@ # import os -from misc import ldb_set_credentials -def Ldb(url, session_info=None, credentials=None, modules_dir=None): - """Open a Samba Ldb file. +def _in_source_tree(): + """Check whether the script is being run from the source dir. """ + return os.path.exists("%s/../../../samba4-skip" % os.path.dirname(__file__)) - This is different from a regular Ldb file in that the Samba-specific - modules-dir is used by default and that credentials and session_info - can be passed through (required by some modules). + +# When running, in-tree, make sure bin/python is in the PYTHONPATH +if _in_source_tree(): + import sys + srcdir = "%s/../../.." % os.path.dirname(__file__) + sys.path.append("%s/bin/python" % srcdir) + default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir + + +import ldb +import credentials +import misc + +class Ldb(ldb.Ldb): + """Simple Samba-specific LDB subclass that takes care + of setting up the modules dir, credentials pointers, etc. + + Please note that this is intended to be for all Samba LDB files, + not necessarily the Sam database. For Sam-specific helper + functions see samdb.py. """ - import ldb - ret = ldb.Ldb() - if modules_dir is None: - modules_dir = os.path.join(os.getcwd(), "bin", "modules", "ldb") - ret.set_modules_dir(modules_dir) - def samba_debug(level,text): - print "%d %s" % (level, text) - ldb_set_opaque("credentials", credentials) - ret.set_opaque("sessionInfo", session_info) - #ret.set_debug(samba_debug) - ret.connect(url) - return ret + def __init__(self, url=None, session_info=None, credentials=None, + modules_dir=None, lp=None): + """Open a Samba Ldb file. + + :param url: Optional LDB URL to open + :param session_info: Optional session information + :param credentials: Optional credentials, defaults to anonymous. + :param modules_dir: Modules directory, if not the default. + :param lp: Loadparm object, optional. + + This is different from a regular Ldb file in that the Samba-specific + modules-dir is used by default and that credentials and session_info + can be passed through (required by some modules). + """ + super(Ldb, self).__init__() + + if modules_dir is not None: + self.set_modules_dir(modules_dir) + elif default_ldb_modules_dir is not None: + self.set_modules_dir(default_ldb_modules_dir) + + if credentials is not None: + self.set_credentials(self, credentials) + + if session_info is not None: + self.set_session_info(self, session_info) + + if lp is not None: + self.set_loadparm(self, lp) + + def msg(l,text): + print text + #self.set_debug(msg) + + if url is not None: + self.connect(url) + + + set_credentials = misc.ldb_set_credentials + set_session_info = misc.ldb_set_session_info + set_loadparm = misc.ldb_set_loadparm + + def searchone(self, basedn, attribute, expression=None, + scope=ldb.SCOPE_BASE): + """Search for one attribute as a string.""" + res = self.search(basedn, scope, expression, [attribute]) + if len(res) != 1 or res[0][attribute] is None: + return None + values = set(res[0][attribute]) + assert len(values) == 1 + return values.pop() + + def erase(self): + """Erase an ldb, removing all records.""" + # delete the specials + for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", + "@OPTIONS", "@PARTITION", "@KLUDGEACL"]: + try: + self.delete(ldb.Dn(self, attr)) + except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): + # Ignore missing dn errors + pass + + basedn = ldb.Dn(self, "") + # and the rest + for msg in self.search(basedn, ldb.SCOPE_SUBTREE, + "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", + ["dn"]): + try: + self.delete(msg.dn) + except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): + # Ignor eno such object errors + pass + + res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]) + assert len(res) == 0 + + def erase_partitions(self): + """Erase an ldb, removing all records.""" + res = self.search(ldb.Dn(self, ""), ldb.SCOPE_BASE, "(objectClass=*)", + ["namingContexts"]) + assert len(res) == 1 + if not "namingContexts" in res[0]: + return + for basedn in res[0]["namingContexts"]: + previous_remaining = 1 + current_remaining = 0 + + k = 0 + while ++k < 10 and (previous_remaining != current_remaining): + # and the rest + res2 = self.search(ldb.Dn(self, basedn), ldb.SCOPE_SUBTREE, "(|(objectclass=*)(dn=*))", ["dn"]) + previous_remaining = current_remaining + current_remaining = len(res2) + for msg in res2: + self.delete(msg.dn) + + def load_ldif_file_add(self, ldif_path): + """Load a LDIF file. + + :param ldif_path: Path to LDIF file. + """ + self.load_ldif_add(open(ldif_path, 'r').read()) + + def load_ldif_add(self, ldif): + for changetype, msg in self.parse_ldif(ldif): + assert changetype == ldb.CHANGETYPE_NONE + self.add(msg) def substitute_var(text, values): @@ -51,7 +164,19 @@ def substitute_var(text, values): """ for (name, value) in values.items(): + assert isinstance(name, str), "%r is not a string" % name + assert isinstance(value, str), "Value %r for %s is not a string" % (value, name) text = text.replace("${%s}" % name, value) return text + +def valid_netbios_name(name): + """Check whether a name is valid as a NetBIOS name. """ + # FIXME: There are probably more constraints here. + # crh has a paragraph on this in his book (1.4.1.1) + if len(name) > 13: + return False + return True + +version = misc.version diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py new file mode 100644 index 0000000000..90f7cd0697 --- /dev/null +++ b/source4/scripting/python/samba/provision.py @@ -0,0 +1,813 @@ +# +# backend code for provisioning a Samba4 server +# Released under the GNU GPL v2 or later +# Copyright Jelmer Vernooij 2007 +# +# Based on the original in EJS: +# Copyright Andrew Tridgell 2005 +# + +from base64 import b64encode +import os +import pwd +import grp +import time +import uuid, misc +from socket import gethostname, gethostbyname +import param +import registry +import samba +from samba import Ldb, substitute_var, valid_netbios_name +from samba.samdb import SamDB +import security +from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ + LDB_ERR_NO_SUCH_OBJECT, timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE + + +DEFAULTSITE = "Default-First-Site-Name" + +class InvalidNetbiosName(Exception): + def __init__(self, name): + super(InvalidNetbiosName, self).__init__("The name '%r' is not a valid NetBIOS name" % name) + + +class ProvisionPaths: + def __init__(self): + self.smbconf = None + self.shareconf = None + self.hklm = None + self.hkcu = None + self.hkcr = None + self.hku = None + self.hkpd = None + self.hkpt = None + self.samdb = None + self.secrets = None + self.keytab = None + self.dns_keytab = None + self.dns = None + self.winsdb = None + self.ldap_basedn_ldif = None + self.ldap_config_basedn_ldif = None + self.ldap_schema_basedn_ldif = None + + +def install_ok(lp, session_info, credentials): + """Check whether the current install seems ok.""" + if lp.get("realm") == "": + return False + ldb = Ldb(lp.get("sam database"), session_info=session_info, + credentials=credentials, lp=lp) + if len(ldb.search(ldb.Dn("(cn=Administrator)"))) != 1: + return False + return True + + +def findnss(nssfn, *names): + """Find a user or group from a list of possibilities.""" + for name in names: + try: + return nssfn(name) + except KeyError: + pass + raise Exception("Unable to find user/group for %s" % arguments[1]) + + +def open_ldb(session_info, credentials, lp, dbname): + assert session_info is not None + try: + return Ldb(dbname, session_info=session_info, credentials=credentials, + lp=lp) + except LdbError, e: + print e + os.unlink(dbname) + return Ldb(dbname, session_info=session_info, credentials=credentials, + lp=lp) + + +def setup_add_ldif(ldb, ldif_path, subst_vars=None): + """Setup a ldb in the private dir.""" + assert isinstance(ldif_path, str) + + data = open(ldif_path, 'r').read() + if subst_vars is not None: + data = substitute_var(data, subst_vars) + + assert "${" not in data + + ldb.load_ldif_add(data) + + +def setup_modify_ldif(ldb, ldif_path, substvars=None): + """Modify a ldb in the private dir. + + :param ldb: LDB object. + :param ldif_path: LDIF file path. + :param substvars: Optional dictionary with substitution variables. + """ + data = open(ldif_path, 'r').read() + if substvars is not None: + data = substitute_var(data, substvars) + + assert "${" not in data + + for (changetype, msg) in ldb.parse_ldif(data): + assert changetype == CHANGETYPE_MODIFY + ldb.modify(msg) + + +def setup_ldb(ldb, ldif_path, subst_vars): + assert ldb is not None + ldb.transaction_start() + try: + setup_add_ldif(ldb, ldif_path, subst_vars) + except: + ldb.transaction_cancel() + raise + ldb.transaction_commit() + + +def setup_file(template, fname, substvars): + """Setup a file in the private dir.""" + f = fname + + if os.path.exists(f): + os.unlink(f) + + data = open(template, 'r').read() + if substvars: + data = substitute_var(data, substvars) + assert not "${" in data + + open(f, 'w').write(data) + + +def provision_default_paths(lp, dnsdomain): + """Set the default paths for provisioning. + + :param lp: Loadparm context. + :param dnsdomain: DNS Domain name + """ + paths = ProvisionPaths() + private_dir = lp.get("private dir") + paths.shareconf = os.path.join(private_dir, "share.ldb") + paths.samdb = os.path.join(private_dir, lp.get("sam database") or "samdb.ldb") + paths.secrets = os.path.join(private_dir, lp.get("secrets database") or "secrets.ldb") + paths.templates = os.path.join(private_dir, "templates.ldb") + paths.keytab = os.path.join(private_dir, "secrets.keytab") + paths.dns_keytab = os.path.join(private_dir, "dns.keytab") + paths.dns = os.path.join(private_dir, dnsdomain + ".zone") + paths.winsdb = os.path.join(private_dir, "wins.ldb") + paths.ldap_basedn_ldif = os.path.join(private_dir, + dnsdomain + ".ldif") + paths.ldap_config_basedn_ldif = os.path.join(private_dir, + dnsdomain + "-config.ldif") + paths.ldap_schema_basedn_ldif = os.path.join(private_dir, + dnsdomain + "-schema.ldif") + paths.s4_ldapi_path = os.path.join(private_dir, "ldapi") + paths.phpldapadminconfig = os.path.join(private_dir, + "phpldapadmin-config.php") + paths.hklm = os.path.join(private_dir, "hklm.ldb") + paths.sysvol = lp.get("sysvol", "path") + if paths.sysvol is None: + paths.sysvol = os.path.join(lp.get("lock dir"), "sysvol") + + paths.netlogon = lp.get("netlogon", "path") + if paths.netlogon is None: + paths.netlogon = os.path.join(os.path.join(paths.sysvol, "scripts")) + + return paths + + +def setup_name_mappings(ldb, sid, domaindn, root, nobody, nogroup, users, + wheel, backup): + """setup reasonable name mappings for sam names to unix names.""" + # add some foreign sids if they are not present already + ldb.add_foreign(domaindn, "S-1-5-7", "Anonymous") + ldb.add_foreign(domaindn, "S-1-1-0", "World") + ldb.add_foreign(domaindn, "S-1-5-2", "Network") + ldb.add_foreign(domaindn, "S-1-5-18", "System") + ldb.add_foreign(domaindn, "S-1-5-11", "Authenticated Users") + + # some well known sids + ldb.setup_name_mapping(domaindn, "S-1-5-7", nobody) + ldb.setup_name_mapping(domaindn, "S-1-1-0", nogroup) + ldb.setup_name_mapping(domaindn, "S-1-5-2", nogroup) + ldb.setup_name_mapping(domaindn, "S-1-5-18", root) + ldb.setup_name_mapping(domaindn, "S-1-5-11", users) + ldb.setup_name_mapping(domaindn, "S-1-5-32-544", wheel) + ldb.setup_name_mapping(domaindn, "S-1-5-32-545", users) + ldb.setup_name_mapping(domaindn, "S-1-5-32-546", nogroup) + ldb.setup_name_mapping(domaindn, "S-1-5-32-551", backup) + + # and some well known domain rids + ldb.setup_name_mapping(domaindn, sid + "-500", root) + ldb.setup_name_mapping(domaindn, sid + "-518", wheel) + ldb.setup_name_mapping(domaindn, sid + "-519", wheel) + ldb.setup_name_mapping(domaindn, sid + "-512", wheel) + ldb.setup_name_mapping(domaindn, sid + "-513", users) + ldb.setup_name_mapping(domaindn, sid + "-520", wheel) + + +def provision_become_dc(setup_dir, message, paths, lp, session_info, + credentials): + assert session_info is not None + erase = False + + def setup_path(file): + return os.path.join(setup_dir, file) + os.path.unlink(paths.samdb) + + message("Setting up templates db") + setup_templatesdb(paths.templates, setup_path, session_info, + credentials, lp) + + # Also wipes the database + message("Setting up sam.ldb") + samdb = SamDB(paths.samdb, credentials=credentials, + session_info=session_info, lp=lp) + + message("Setting up sam.ldb partitions") + setup_samdb_partitions(samdb, setup_path, schemadn, + configdn, domaindn) + + samdb = SamDB(paths.samdb, credentials=credentials, + session_info=session_info, lp=lp) + + ldb.transaction_start() + try: + message("Setting up sam.ldb attributes") + samdb.load_ldif_file_add(setup_path("provision_init.ldif")) + + message("Setting up sam.ldb rootDSE") + setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, + hostname, dnsdomain, realm, rootdn, configdn, + netbiosname) + + if erase: + message("Erasing data from partitions") + samdb.erase_partitions() + + message("Setting up sam.ldb indexes") + samdb.load_ldif_file_add(setup_path("provision_index.ldif")) + except: + samdb.transaction_cancel() + raise + + samdb.transaction_commit() + + message("Setting up %s" % paths.secrets) + secrets_ldb = setup_secretsdb(paths.secrets, setup_path, session_info, credentials, lp) + setup_ldb(secrets_ldb, setup_path("secrets_dc.ldif"), + { "MACHINEPASS_B64": b64encode(machinepass) }) + + +def setup_secretsdb(path, setup_path, session_info, credentials, lp): + secrets_ldb = Ldb(path, session_info=session_info, credentials=credentials, lp=lp) + secrets_ldb.erase() + secrets_ldb.load_ldif_file_add(setup_path("secrets_init.ldif")) + secrets_ldb.load_ldif_file_add(setup_path("secrets.ldif")) + return secrets_ldb + + +def setup_templatesdb(path, setup_path, session_info, credentials, lp): + templates_ldb = SamDB(path, session_info=session_info, + credentials=credentials, lp=lp) + templates_ldb.erase() + templates_ldb.load_ldif_file_add(setup_path("provision_templates.ldif")) + + +def setup_registry(path, setup_path, session_info, credentials, lp): + reg = registry.Registry() + hive = registry.Hive(path, session_info=session_info, + credentials=credentials, lp_ctx=lp) + reg.mount_hive(hive, "HKEY_LOCAL_MACHINE") + provision_reg = setup_path("provision.reg") + assert os.path.exists(provision_reg) + reg.apply_patchfile(provision_reg) + + +def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, + dnsdomain, realm, rootdn, configdn, netbiosname): + setup_add_ldif(samdb, setup_path("provision_rootdse_add.ldif"), { + "SCHEMADN": schemadn, + "NETBIOSNAME": netbiosname, + "DNSDOMAIN": dnsdomain, + "DEFAULTSITE": DEFAULTSITE, + "REALM": realm, + "DNSNAME": "%s.%s" % (hostname, dnsdomain), + "DOMAINDN": domaindn, + "ROOTDN": rootdn, + "CONFIGDN": configdn, + "VERSION": samba.version(), + }) + + +def setup_samdb_partitions(samdb, setup_path, schemadn, configdn, domaindn): + #Add modules to the list to activate them by default + #beware often order is important + # + # Some Known ordering constraints: + # - rootdse must be first, as it makes redirects from "" -> cn=rootdse + # - objectclass must be before password_hash, because password_hash checks + # that the objectclass is of type person (filled in by objectclass + # module when expanding the objectclass list) + # - partition must be last + # - each partition has its own module list then + modules_list = ["rootdse", + "paged_results", + "ranged_results", + "anr", + "server_sort", + "extended_dn", + "asq", + "samldb", + "rdn_name", + "objectclass", + "kludge_acl", + "operational"] + tdb_modules_list = [ + "subtree_rename", + "subtree_delete", + "linked_attributes"] + modules_list2 = ["show_deleted", + "partition"] + + setup_add_ldif(samdb, setup_path("provision_partitions.ldif"), { + "SCHEMADN": schemadn, + "SCHEMADN_LDB": "schema.ldb", + "SCHEMADN_MOD2": ",objectguid", + "CONFIGDN": configdn, + "CONFIGDN_LDB": "configuration.ldb", + "DOMAINDN": domaindn, + "DOMAINDN_LDB": "users.ldb", + "SCHEMADN_MOD": "schema_fsmo", + "CONFIGDN_MOD": "naming_fsmo", + "CONFIGDN_MOD2": ",objectguid", + "DOMAINDN_MOD": "pdc_fsmo,password_hash", + "DOMAINDN_MOD2": ",objectguid", + "MODULES_LIST": ",".join(modules_list), + "TDB_MODULES_LIST": ","+",".join(tdb_modules_list), + "MODULES_LIST2": ",".join(modules_list2), + }) + + + +def provision(lp, setup_dir, message, blank, paths, session_info, + credentials, ldapbackend, realm=None, domain=None, hostname=None, + hostip=None, domainsid=None, hostguid=None, adminpass=None, + krbtgtpass=None, domainguid=None, policyguid=None, + invocationid=None, machinepass=None, dnspass=None, root=None, + nobody=None, nogroup=None, users=None, wheel=None, backup=None, + aci=None, serverrole=None): + """Provision samba4 + + :note: caution, this wipes all existing data! + """ + + def setup_path(file): + return os.path.join(setup_dir, file) + + erase = False + + if domainsid is None: + domainsid = security.random_sid() + if policyguid is None: + policyguid = uuid.random() + if invocationid is None: + invocationid = uuid.random() + if adminpass is None: + adminpass = misc.random_password(12) + if krbtgtpass is None: + krbtgtpass = misc.random_password(12) + if machinepass is None: + machinepass = misc.random_password(12) + if dnspass is None: + dnspass = misc.random_password(12) + if root is None: + root = findnss(pwd.getpwnam, "root")[4] + if nobody is None: + nobody = findnss(pwd.getpwnam, "nobody")[4] + if nogroup is None: + nogroup = findnss(grp.getgrnam, "nogroup", "nobody")[2] + if users is None: + users = findnss(grp.getgrnam, "users", "guest", "other", "unknown", "usr")[2] + if wheel is None: + wheel = findnss(grp.getgrnam, "wheel", "root", "staff", "adm")[2] + if backup is None: + backup = findnss(grp.getgrnam, "backup", "wheel", "root", "staff")[2] + if aci is None: + aci = "# no aci for local ldb" + if serverrole is None: + serverrole = lp.get("server role") + + if realm is None: + realm = lp.get("realm") + else: + if lp.get("realm").upper() != realm.upper(): + raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" % + (lp.get("realm"), realm)) + + assert realm is not None + realm = realm.upper() + + if domain is None: + domain = lp.get("workgroup") + else: + if lp.get("workgroup").upper() != domain.upper(): + raise Error("workgroup '%s' in smb.conf must match chosen domain '%s'\n", + lp.get("workgroup"), domain) + + assert domain is not None + domain = domain.upper() + if not valid_netbios_name(domain): + raise InvalidNetbiosName(domain) + + if hostname is None: + hostname = gethostname().split(".")[0].lower() + + if hostip is None: + hostip = gethostbyname(hostname) + + netbiosname = hostname.upper() + if not valid_netbios_name(netbiosname): + raise InvalidNetbiosName(netbiosname) + + dnsdomain = realm.lower() + domaindn = "DC=" + dnsdomain.replace(".", ",DC=") + rootdn = domaindn + configdn = "CN=Configuration," + rootdn + schemadn = "CN=Schema," + configdn + + rdn_dc = domaindn.split(",")[0][len("DC="):] + + message("set DOMAIN SID: %s" % str(domainsid)) + message("Provisioning for %s in realm %s" % (domain, realm)) + message("Using administrator password: %s" % adminpass) + + assert paths.smbconf is not None + + # only install a new smb.conf if there isn't one there already + if not os.path.exists(paths.smbconf): + message("Setting up smb.conf") + if serverrole == "domain controller": + smbconfsuffix = "dc" + elif serverrole == "member": + smbconfsuffix = "member" + else: + assert "Invalid server role setting: %s" % serverrole + setup_file(setup_path("provision.smb.conf.%s" % smbconfsuffix), paths.smbconf, { + "HOSTNAME": hostname, + "DOMAIN_CONF": domain, + "REALM_CONF": realm, + "SERVERROLE": serverrole, + "NETLOGONPATH": paths.netlogon, + "SYSVOLPATH": paths.sysvol, + }) + lp.reload() + + # only install a new shares config db if there is none + if not os.path.exists(paths.shareconf): + message("Setting up share.ldb") + share_ldb = Ldb(paths.shareconf, session_info=session_info, + credentials=credentials, lp=lp) + share_ldb.load_ldif_file_add(setup_path("share.ldif")) + + message("Setting up secrets.ldb") + secrets_ldb = setup_secretsdb(paths.secrets, setup_path, session_info=session_info, + credentials=credentials, lp=lp) + + message("Setting up the registry") + # FIXME: Still fails for some reason + #setup_registry(paths.hklm, setup_path, session_info, + # credentials=credentials, lp=lp) + + message("Setting up templates db") + setup_templatesdb(paths.templates, setup_path, session_info=session_info, + credentials=credentials, lp=lp) + + samdb = SamDB(paths.samdb, session_info=session_info, + credentials=credentials, lp=lp) + + message("Setting up sam.ldb partitions") + setup_samdb_partitions(samdb, setup_path, schemadn, configdn, domaindn) + + samdb = SamDB(paths.samdb, session_info=session_info, + credentials=credentials, lp=lp) + + samdb.transaction_start() + try: + message("Setting up sam.ldb attributes") + samdb.load_ldif_file_add(setup_path("provision_init.ldif")) + + message("Setting up sam.ldb rootDSE") + setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, + hostname, dnsdomain, realm, rootdn, configdn, + netbiosname) + + if erase: + message("Erasing data from partitions") + samdb.erase_partitions() + except: + samdb.transaction_cancel() + raise + + samdb.transaction_commit() + + message("Pre-loading the Samba 4 and AD schema") + samdb = SamDB(paths.samdb, session_info=session_info, + credentials=credentials, lp=lp) + samdb.set_domain_sid(domainsid) + load_schema(setup_path, samdb, schemadn, netbiosname, configdn) + + samdb.transaction_start() + + try: + message("Adding DomainDN: %s (permitted to fail)" % domaindn) + setup_add_ldif(samdb, setup_path("provision_basedn.ldif"), { + "DOMAINDN": domaindn, + "ACI": aci, + "EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb", + "RDN_DC": rdn_dc, + }) + + message("Modifying DomainDN: " + domaindn + "") + if domainguid is not None: + domainguid_mod = "replace: objectGUID\nobjectGUID: %s\n-" % domainguid + else: + domainguid_mod = "" + + setup_modify_ldif(samdb, setup_path("provision_basedn_modify.ldif"), { + "RDN_DC": rdn_dc, + "LDAPTIME": timestring(int(time.time())), + "DOMAINSID": str(domainsid), + "SCHEMADN": schemadn, + "NETBIOSNAME": netbiosname, + "DEFAULTSITE": DEFAULTSITE, + "CONFIGDN": configdn, + "POLICYGUID": policyguid, + "DOMAINDN": domaindn, + "DOMAINGUID_MOD": domainguid_mod, + }) + + message("Adding configuration container (permitted to fail)") + setup_add_ldif(samdb, setup_path("provision_configuration_basedn.ldif"), { + "CONFIGDN": configdn, + "ACI": aci, + "EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb", + }) + message("Modifying configuration container") + setup_modify_ldif(samdb, setup_path("provision_configuration_basedn_modify.ldif"), { + "CONFIGDN": configdn, + "SCHEMADN": schemadn, + }) + + message("Adding schema container (permitted to fail)") + setup_add_ldif(samdb, setup_path("provision_schema_basedn.ldif"), { + "SCHEMADN": schemadn, + "ACI": aci, + "EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb" + }) + message("Modifying schema container") + setup_modify_ldif(samdb, setup_path("provision_schema_basedn_modify.ldif"), { + "SCHEMADN": schemadn, + "NETBIOSNAME": netbiosname, + "DEFAULTSITE": DEFAULTSITE, + "CONFIGDN": configdn, + }) + + message("Setting up sam.ldb Samba4 schema") + setup_add_ldif(samdb, setup_path("schema_samba4.ldif"), + {"SCHEMADN": schemadn }) + message("Setting up sam.ldb AD schema") + setup_add_ldif(samdb, setup_path("schema.ldif"), + {"SCHEMADN": schemadn}) + + message("Setting up sam.ldb configuration data") + setup_add_ldif(samdb, setup_path("provision_configuration.ldif"), { + "CONFIGDN": configdn, + "NETBIOSNAME": netbiosname, + "DEFAULTSITE": DEFAULTSITE, + "DNSDOMAIN": dnsdomain, + "DOMAIN": domain, + "SCHEMADN": schemadn, + "DOMAINDN": domaindn, + }) + + message("Setting up display specifiers") + setup_add_ldif(samdb, setup_path("display_specifiers.ldif"), + {"CONFIGDN": configdn}) + + message("Adding users container (permitted to fail)") + setup_add_ldif(samdb, setup_path("provision_users_add.ldif"), { + "DOMAINDN": domaindn}) + message("Modifying users container") + setup_modify_ldif(samdb, setup_path("provision_users_modify.ldif"), { + "DOMAINDN": domaindn}) + message("Adding computers container (permitted to fail)") + setup_add_ldif(samdb, setup_path("provision_computers_add.ldif"), { + "DOMAINDN": domaindn}) + message("Modifying computers container") + setup_modify_ldif(samdb, setup_path("provision_computers_modify.ldif"), { + "DOMAINDN": domaindn}) + message("Setting up sam.ldb data") + setup_add_ldif(samdb, setup_path("provision.ldif"), { + "DOMAINDN": domaindn, + "NETBIOSNAME": netbiosname, + "DEFAULTSITE": DEFAULTSITE, + "CONFIGDN": configdn, + }) + + if not blank: + + # message("Activate schema module") + # setup_modify_ldif("schema_activation.ldif", info, samdb, False) + # + # // (hack) Reload, now we have the schema loaded. + # commit_ok = samdb.transaction_commit() + # if (!commit_ok) { + # message("samdb commit failed: " + samdb.errstring() + "\n") + # assert(commit_ok) + # } + # samdb.close() + # + # samdb = open_ldb(info, paths.samdb, False) + # + message("Setting up sam.ldb users and groups") + setup_add_ldif(samdb, setup_path("provision_users.ldif"), { + "DOMAINDN": domaindn, + "DOMAINSID": str(domainsid), + "CONFIGDN": configdn, + "ADMINPASS_B64": b64encode(adminpass), + "KRBTGTPASS_B64": b64encode(krbtgtpass), + }) + + if lp.get("server role") == "domain controller": + message("Setting up self join") + if hostguid is not None: + hostguid_add = "objectGUID: %s" % hostguid + else: + hostguid_add = "" + + setup_add_ldif(samdb, setup_path("provision_self_join.ldif"), { + "CONFIGDN": configdn, + "SCHEMADN": schemadn, + "DOMAINDN": domaindn, + "INVOCATIONID": invocationid, + "NETBIOSNAME": netbiosname, + "DEFAULTSITE": DEFAULTSITE, + "DNSNAME": "%s.%s" % (hostname, dnsdomain), + "MACHINEPASS_B64": b64encode(machinepass), + "DNSPASS_B64": b64encode(dnspass), + "REALM": realm, + "DOMAIN": domain, + "HOSTGUID_ADD": hostguid_add, + "DNSDOMAIN": dnsdomain}) + setup_add_ldif(samdb, setup_path("provision_group_policy.ldif"), { + "POLICYGUID": policyguid, + "DNSDOMAIN": dnsdomain, + "DOMAINSID": str(domainsid), + "DOMAINDN": domaindn}) + + os.makedirs(os.path.join(paths.sysvol, dnsdomain, "Policies", "{" + policyguid + "}"), 0755) + os.makedirs(os.path.join(paths.sysvol, dnsdomain, "Policies", "{" + policyguid + "}", "Machine"), 0755) + os.makedirs(os.path.join(paths.sysvol, dnsdomain, "Policies", "{" + policyguid + "}", "User"), 0755) + if not os.path.isdir(paths.netlogon): + os.makedirs(paths.netlogon, 0755) + setup_ldb(secrets_ldb, setup_path("secrets_dc.ldif"), { + "MACHINEPASS_B64": b64encode(machinepass), + "DOMAIN": domain, + "REALM": realm, + "LDAPTIME": timestring(int(time.time())), + "DNSDOMAIN": dnsdomain, + "DOMAINSID": str(domainsid), + "SECRETS_KEYTAB": paths.keytab, + "NETBIOSNAME": netbiosname, + "SAM_LDB": paths.samdb, + "DNS_KEYTAB": paths.dns_keytab, + "DNSPASS_B64": b64encode(dnspass), + }) + + setup_name_mappings(samdb, str(domainsid), + domaindn, root=root, nobody=nobody, + nogroup=nogroup, wheel=wheel, users=users, + backup=backup) + + message("Setting up sam.ldb index") + samdb.load_ldif_file_add(setup_path("provision_index.ldif")) + + message("Setting up sam.ldb rootDSE marking as syncronized") + setup_modify_ldif(samdb, setup_path("provision_rootdse_modify.ldif")) + except: + samdb.transaction_cancel() + raise + + samdb.transaction_commit() + + message("Setting up phpLDAPadmin configuration") + create_phplpapdadmin_config(paths.phpldapadminconfig, setup_path, paths.s4_ldapi_path) + + message("Please install the phpLDAPadmin configuration located at %s into /etc/phpldapadmin/config.php" % paths.phpldapadminconfig) + + message("Setting up DNS zone: %s" % dnsdomain) + create_zone_file(paths.dns, setup_path, samdb, + hostname=hostname, hostip=hostip, dnsdomain=dnsdomain, + domaindn=domaindn, dnspass=dnspass, realm=realm) + message("Please install the zone located in %s into your DNS server" % paths.dns) + +def create_phplpapdadmin_config(path, setup_path, s4_ldapi_path): + setup_file(setup_path("phpldapadmin-config.php"), + path, {"S4_LDAPI_URI": "ldapi://%s" % s4_ldapi_path.replace("/", "%2F")}) + + +def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, + hostip, hostname, dnspass, realm): + """Write out a DNS zone file, from the info in the current database.""" + + # connect to the sam + # These values may have changed, due to an incoming SamSync, + # or may not have been specified, so fetch them from the database + domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID") + hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID" , + expression="(&(objectClass=computer)(cn=%s))" % hostname) + + setup_file(setup_path("provision.zone"), path, { + "DNSPASS_B64": b64encode(dnspass), + "HOSTNAME": hostname, + "DNSDOMAIN": dnsdomain, + "REALM": realm, + "HOSTIP": hostip, + "DOMAINGUID": domainguid, + "DATESTRING": time.strftime("%Y%m%d%H"), + "DEFAULTSITE": DEFAULTSITE, + "HOSTGUID": hostguid, + }) + + +def provision_ldapbase(setup_dir, message, paths): + """Write out a DNS zone file, from the info in the current database.""" + message("Setting up LDAP base entry: %s" % domaindn) + rdns = domaindn.split(",") + + rdn_dc = rdns[0][len("DC="):] + + def setup_path(file): + return os.path.join(setup_dir, file) + + setup_file(setup_path("provision_basedn.ldif"), + paths.ldap_basedn_ldif) + + setup_file(setup_path("provision_configuration_basedn.ldif"), + paths.ldap_config_basedn_ldif) + + setup_file(setup_path("provision_schema_basedn.ldif"), + paths.ldap_schema_basedn_ldif, { + "SCHEMADN": schemadn, + "ACI": "# no aci for local ldb", + "EXTENSIBLEOBJECT": "objectClass: extensibleObject"}) + + message("Please install the LDIF located in " + paths.ldap_basedn_ldif + ", " + paths.ldap_config_basedn_ldif + " and " + paths.ldap_schema_basedn_ldif + " into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server") + + +def load_schema(setup_path, samdb, schemadn, netbiosname, configdn): + """Load schema.""" + schema_data = open(setup_path("schema.ldif"), 'r').read() + schema_data += open(setup_path("schema_samba4.ldif"), 'r').read() + schema_data = substitute_var(schema_data, {"SCHEMADN": schemadn}) + head_data = open(setup_path("provision_schema_basedn_modify.ldif"), 'r').read() + head_data = substitute_var(head_data, { + "SCHEMADN": schemadn, + "NETBIOSNAME": netbiosname, + "CONFIGDN": configdn, + "DEFAULTSITE": DEFAULTSITE}) + samdb.attach_schema_from_ldif(head_data, schema_data) + + +def join_domain(domain, netbios_name, join_type, creds): + ctx = NetContext(creds) + joindom = object() + joindom.domain = domain + joindom.join_type = join_type + joindom.netbios_name = netbios_name + if not ctx.JoinDomain(joindom): + raise Exception("Domain Join failed: " + joindom.error_string) + + +def vampire(domain, session_info, credentials, message): + """Vampire a remote domain. + + Session info and credentials are required for for + access to our local database (might be remote ldap) + """ + ctx = NetContext(credentials) + machine_creds = Credentials() + machine_creds.set_domain(form.domain) + if not machine_creds.set_machine_account(): + raise Exception("Failed to access domain join information!") + vampire_ctx.machine_creds = machine_creds + vampire_ctx.session_info = session_info + if not ctx.SamSyncLdb(vampire_ctx): + raise Exception("Migration of remote domain to Samba failed: %s " % vampire_ctx.error_string) + + + diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py new file mode 100644 index 0000000000..84b604dbc4 --- /dev/null +++ b/source4/scripting/python/samba/samdb.py @@ -0,0 +1,132 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# Based on the original in EJS: +# Copyright (C) Andrew Tridgell 2005 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import samba +import misc +import ldb + +class SamDB(samba.Ldb): + def __init__(self, url=None, session_info=None, credentials=None, + modules_dir=None, lp=None): + super(SamDB, self).__init__(session_info=session_info, credentials=credentials, + modules_dir=modules_dir, lp=lp) + assert misc.dsdb_set_global_schema(self) == 0 + assert misc.ldb_register_samba_handlers(self) == 0 + if url: + self.connect(url) + + def add_foreign(self, domaindn, sid, desc): + """Add a foreign security principle.""" + add = """ +dn: CN=%s,CN=ForeignSecurityPrincipals,%s +objectClass: top +objectClass: foreignSecurityPrincipal +description: %s + """ % (sid, domaindn, desc) + # deliberately ignore errors from this, as the records may + # already exist + for msg in self.parse_ldif(add): + self.add(msg[1]) + + def setup_name_mapping(self, domaindn, sid, unixname): + """Setup a mapping between a sam name and a unix name.""" + res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE, + "objectSid=%s" % sid, ["dn"]) + assert len(res) == 1, "Failed to find record for objectSid %s" % sid + + mod = """ +dn: %s +changetype: modify +replace: unixName +unixName: %s +""" % (res[0].dn, unixname) + self.modify(self.parse_ldif(mod).next()[1]) + + def enable_account(self, user_dn): + """enable the account. + + :param user_dn: Dn of the account to enable. + """ + res = self.search(user_dn, SCOPE_ONELEVEL, None, ["userAccountControl"]) + assert len(res) == 1 + userAccountControl = res[0].userAccountControl + userAccountControl = userAccountControl - 2 # remove disabled bit + mod = """ +dn: %s +changetype: modify +replace: userAccountControl +userAccountControl: %u +""" % (user_dn, userAccountControl) + self.modify(mod) + + def newuser(self, username, unixname, password, message): + """add a new user record""" + # connect to the sam + self.transaction_start() + + # find the DNs for the domain and the domain users group + res = self.search("", SCOPE_BASE, "defaultNamingContext=*", + ["defaultNamingContext"]) + assert(len(res) == 1 and res[0].defaultNamingContext is not None) + domain_dn = res[0].defaultNamingContext + assert(domain_dn is not None) + dom_users = self.searchone(domain_dn, "dn", "name=Domain Users") + assert(dom_users is not None) + + user_dn = "CN=%s,CN=Users,%s" % (username, domain_dn) + + # + # the new user record. note the reliance on the samdb module to fill + # in a sid, guid etc + # + ldif = """ +dn: %s +sAMAccountName: %s +unixName: %s +sambaPassword: %s +objectClass: user + """ % (user_dn, username, unixname, password) + # add the user to the users group as well + modgroup = """ +dn: %s +changetype: modify +add: member +member: %s +""" % (dom_users, user_dn) + + + # now the real work + message("Adding user %s" % user_dn) + self.add(ldif) + + message("Modifying group %s" % dom_users) + self.modify(modgroup) + + # modify the userAccountControl to remove the disabled bit + enable_account(self, user_dn) + self.transaction_commit() + + def set_domain_sid(self, sid): + misc.samdb_set_domain_sid(self, sid) + + def attach_schema_from_ldif(self, pf, df): + misc.dsdb_attach_schema_from_ldif_file(self, pf, df) diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py new file mode 100644 index 0000000000..e213c1cc1f --- /dev/null +++ b/source4/scripting/python/samba/tests/__init__.py @@ -0,0 +1,72 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import os +import ldb +import samba +import tempfile +import unittest + +class LdbTestCase(unittest.TestCase): + def setUp(self): + self.filename = os.tempnam() + self.ldb = samba.Ldb(self.filename) + + def set_modules(self, modules=[]): + m = ldb.Message() + m.dn = ldb.Dn(self.ldb, "@MODULES") + m["@LIST"] = ",".join(modules) + self.ldb.add(m) + self.ldb = samba.Ldb(self.filename) + + +class TestCaseInTempDir(unittest.TestCase): + def setUp(self): + super(TestCaseInTempDir, self).setUp() + self.tempdir = tempfile.mkdtemp() + + def tearDown(self): + super(TestCaseInTempDir, self).tearDown() + + +class SubstituteVarTestCase(unittest.TestCase): + def test_empty(self): + self.assertEquals("", samba.substitute_var("", {})) + + def test_nothing(self): + self.assertEquals("foo bar", samba.substitute_var("foo bar", {"bar": "bla"})) + + def test_replace(self): + self.assertEquals("foo bla", samba.substitute_var("foo ${bar}", {"bar": "bla"})) + + def test_broken(self): + self.assertEquals("foo ${bdkjfhsdkfh sdkfh ", + samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"})) + + def test_unknown_var(self): + self.assertEquals("foo ${bla} gsff", + samba.substitute_var("foo ${bla} gsff", {"bar": "bla"})) + + +class LdbExtensionTests(TestCaseInTempDir): + def test_searchone(self): + l = samba.Ldb(self.tempdir + "/searchone.ldb") + l.add({"dn": "foo=dc", "bar": "bla"}) + self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar")) + diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py new file mode 100644 index 0000000000..bf7182dbd3 --- /dev/null +++ b/source4/scripting/python/samba/tests/provision.py @@ -0,0 +1,71 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import os +from samba.provision import setup_secretsdb +import samba.tests +from ldb import Dn + +setup_dir = "setup" +def setup_path(file): + return os.path.join(setup_dir, file) + + +class ProvisionTestCase(samba.tests.TestCaseInTempDir): + def test_setup_secretsdb(self): + ldb = setup_secretsdb(os.path.join(self.tempdir, "secrets.ldb"), + setup_path, None, None, None) + self.assertEquals("LSA Secrets", + ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN")) + + +class Disabled: + def test_setup_templatesdb(self): + raise NotImplementedError(self.test_setup_templatesdb) + + def test_setup_registry(self): + raise NotImplementedError(self.test_setup_registry) + + def test_setup_samdb_rootdse(self): + raise NotImplementedError(self.test_setup_samdb_rootdse) + + def test_setup_samdb_partitions(self): + raise NotImplementedError(self.test_setup_samdb_partitions) + + def test_create_phpldapadmin_config(self): + raise NotImplementedError(self.test_create_phpldapadmin_config) + + def test_provision_dns(self): + raise NotImplementedError(self.test_provision_dns) + + def test_provision_ldapbase(self): + raise NotImplementedError(self.test_provision_ldapbase) + + def test_provision_guess(self): + raise NotImplementedError(self.test_provision_guess) + + def test_join_domain(self): + raise NotImplementedError(self.test_join_domain) + + def test_vampire(self): + raise NotImplementedError(self.test_vampire) + + def test_erase_partitions(self): + raise NotImplementedError(self.test_erase_partitions) + diff --git a/source4/scripting/python/samba/tests/upgrade.py b/source4/scripting/python/samba/tests/upgrade.py new file mode 100644 index 0000000000..a25743425b --- /dev/null +++ b/source4/scripting/python/samba/tests/upgrade.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +from samba.upgrade import regkey_to_dn +from unittest import TestCase + +class RegkeyDnTests(TestCase): + def test_empty(self): + self.assertEquals("hive=NONE", regkey_to_dn("")) + + def test_nested(self): + self.assertEquals("key=bar,key=foo,hive=NONE", regkey_to_dn("foo/bar")) diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py new file mode 100644 index 0000000000..1c27f8ec25 --- /dev/null +++ b/source4/scripting/python/samba/upgrade.py @@ -0,0 +1,553 @@ +#!/usr/bin/python +# +# backend code for upgrading from Samba3 +# Copyright Jelmer Vernooij 2005-2007 +# Released under the GNU GPL v3 or later +# + +"""Support code for upgrading from Samba 3 to Samba 4.""" + +from provision import findnss +import provision +import grp +import pwd +import uuid + +def regkey_to_dn(name): + """Convert a registry key to a DN. + + :name: The registry key name. + :return: A matching DN.""" + dn = "hive=NONE" + + if name == "": + return dn + + for el in name.split("/"): + dn = "key=%s," % el + dn + + return dn + +# Where prefix is any of: +# - HKLM +# HKU +# HKCR +# HKPD +# HKPT +# + +def upgrade_registry(regdb,prefix,ldb): + """Migrate registry contents.""" + assert regdb is not None + prefix_up = prefix.upper() + ldif = [] + + for rk in regdb.keys: + pts = rk.name.split("/") + + # Only handle selected hive + if pts[0].upper() != prefix_up: + continue + + keydn = regkey_to_dn(rk.name) + + pts = rk.name.split("/") + + # Convert key name to dn + ldif[rk.name] = """ +dn: %s +name: %s + +""" % (keydn, pts[0]) + + for rv in rk.values: + ldif[rk.name + " (" + rv.name + ")"] = """ +dn: %s,value=%s +value: %s +type: %d +data:: %s""" % (keydn, rv.name, rv.name, rv.type, ldb.encode(rv.data)) + + return ldif + +def upgrade_sam_policy(samba3,dn): + ldif = """ +dn: %s +changetype: modify +replace: minPwdLength +minPwdLength: %d +pwdHistoryLength: %d +minPwdAge: %d +maxPwdAge: %d +lockoutDuration: %d +samba3ResetCountMinutes: %d +samba3UserMustLogonToChangePassword: %d +samba3BadLockoutMinutes: %d +samba3DisconnectTime: %d + +""" % (dn, samba3.policy.min_password_length, + samba3.policy.password_history, samba3.policy.minimum_password_age, + samba3.policy.maximum_password_age, samba3.policy.lockout_duration, + samba3.policy.reset_count_minutes, samba3.policy.user_must_logon_to_change_password, + samba3.policy.bad_lockout_minutes, samba3.policy.disconnect_time) + + return ldif + +def upgrade_sam_account(ldb,acc,domaindn,domainsid): + """Upgrade a SAM account.""" + if acc.nt_username is None or acc.nt_username == "": + acc.nt_username = acc.username + + if acc.fullname is None: + acc.fullname = pwd.getpwnam(acc.fullname)[4] + + acc.fullname = acc.fullname.split(",")[0] + + if acc.fullname is None: + acc.fullname = acc.username + + assert acc.fullname is not None + assert acc.nt_username is not None + + ldif = """dn: cn=%s,%s +objectClass: top +objectClass: user +lastLogon: %d +lastLogoff: %d +unixName: %s +sAMAccountName: %s +cn: %s +description: %s +primaryGroupID: %d +badPwdcount: %d +logonCount: %d +samba3Domain: %s +samba3DirDrive: %s +samba3MungedDial: %s +samba3Homedir: %s +samba3LogonScript: %s +samba3ProfilePath: %s +samba3Workstations: %s +samba3KickOffTime: %d +samba3BadPwdTime: %d +samba3PassLastSetTime: %d +samba3PassCanChangeTime: %d +samba3PassMustChangeTime: %d +objectSid: %s-%d +lmPwdHash:: %s +ntPwdHash:: %s + +""" % (ldb.dn_escape(acc.fullname), domaindn, acc.logon_time, acc.logoff_time, acc.username, acc.nt_username, acc.nt_username, +acc.acct_desc, acc.group_rid, acc.bad_password_count, acc.logon_count, +acc.domain, acc.dir_drive, acc.munged_dial, acc.homedir, acc.logon_script, +acc.profile_path, acc.workstations, acc.kickoff_time, acc.bad_password_time, +acc.pass_last_set_time, acc.pass_can_change_time, acc.pass_must_change_time, domainsid, acc.user_rid, + ldb.encode(acc.lm_pw), ldb.encode(acc.nt_pw)) + + return ldif + +def upgrade_sam_group(group,domaindn): + """Upgrade a SAM group.""" + if group.sid_name_use == 5: # Well-known group + return None + + if group.nt_name in ("Domain Guests", "Domain Users", "Domain Admins"): + return None + + if group.gid == -1: + gr = grp.getgrnam(grp.nt_name) + else: + gr = grp.getgrgid(grp.gid) + + if gr is None: + group.unixname = "UNKNOWN" + else: + group.unixname = gr.gr_name + + assert group.unixname is not None + + ldif = """dn: cn=%s,%s +objectClass: top +objectClass: group +description: %s +cn: %s +objectSid: %s +unixName: %s +samba3SidNameUse: %d +""" % (group.nt_name, domaindn, +group.comment, group.nt_name, group.sid, group.unixname, group.sid_name_use) + + return ldif + +def upgrade_winbind(samba3,domaindn): + ldif = """ + +dn: dc=none +userHwm: %d +groupHwm: %d + +""" % (samba3.idmap.user_hwm, samba3.idmap.group_hwm) + + for m in samba3.idmap.mappings: + ldif += """ +dn: SID=%s,%s +SID: %s +type: %d +unixID: %d""" % (m.sid, domaindn, m.sid, m.type, m.unix_id) + + return ldif + +def upgrade_wins(samba3): + """Upgrade the WINS database.""" + ldif = "" + version_id = 0 + + for e in samba3.winsentries: + now = sys.nttime() + ttl = sys.unix2nttime(e.ttl) + + version_id+=1 + + numIPs = len(e.ips) + + if e.type == 0x1C: + rType = 0x2 + elif e.type & 0x80: + if numIPs > 1: + rType = 0x2 + else: + rType = 0x1 + else: + if numIPs > 1: + rType = 0x3 + else: + rType = 0x0 + + if ttl > now: + rState = 0x0 # active + else: + rState = 0x1 # released + + nType = ((e.nb_flags & 0x60)>>5) + + ldif += """ +dn: name=%s,type=0x%02X +type: 0x%02X +name: %s +objectClass: winsRecord +recordType: %u +recordState: %u +nodeType: %u +isStatic: 0 +expireTime: %s +versionID: %llu +""" % (e.name, e.type, e.type, e.name, + rType, rState, nType, + ldaptime(ttl), version_id) + + for ip in e.ips: + ldif += "address: %s\n" % ip + + ldif += """ +dn: CN=VERSION +objectClass: winsMaxVersion +maxVersion: %llu +""" % version_id + + return ldif + +def upgrade_provision(lp, samba3): + domainname = samba3.configuration.get("workgroup") + + if domainname is None: + domainname = samba3.secrets.domains[0].name + print "No domain specified in smb.conf file, assuming '%s'\n" % domainname + + domsec = samba3.find_domainsecrets(domainname) + hostsec = samba3.find_domainsecrets(hostname()) + realm = samba3.configuration.get("realm") + + if realm is None: + realm = domainname + print "No realm specified in smb.conf file, assuming '%s'\n" % realm + random_init(local) + + subobj.realm = realm + subobj.domain = domainname + + if domsec is not None: + subobj.DOMAINGUID = domsec.guid + subobj.DOMAINSID = domsec.sid + else: + print "Can't find domain secrets for '%s'; using random SID and GUID\n" % domainname + subobj.DOMAINGUID = uuid.random() + subobj.DOMAINSID = randsid() + + if hostsec: + hostguid = hostsec.guid + subobj.krbtgtpass = randpass(12) + subobj.machinepass = randpass(12) + subobj.adminpass = randpass(12) + subobj.datestring = datestring() + subobj.root = findnss(pwd.getpwnam, "root")[4] + subobj.nobody = findnss(pwd.getpwnam, "nobody")[4] + subobj.nogroup = findnss(grp.getgrnam, "nogroup", "nobody")[2] + subobj.wheel = findnss(grp.getgrnam, "wheel", "root")[2] + subobj.users = findnss(grp.getgrnam, "users", "guest", "other")[2] + subobj.dnsdomain = subobj.realm.lower() + subobj.dnsname = "%s.%s" % (subobj.hostname.lower(), subobj.dnsdomain) + subobj.basedn = "DC=" + ",DC=".join(subobj.realm.split(".")) + rdn_list = subobj.dnsdomain.split(".") + subobj.domaindn = "DC=" + ",DC=".join(rdn_list) + subobj.domaindn_ldb = "users.ldb" + subobj.rootdn = subobj.domaindn + + modules_list = ["rootdse", + "kludge_acl", + "paged_results", + "server_sort", + "extended_dn", + "asq", + "samldb", + "password_hash", + "operational", + "objectclass", + "rdn_name", + "show_deleted", + "partition"] + subobj.modules_list = ",".join(modules_list) + + return subobj + +smbconf_keep = [ + "dos charset", + "unix charset", + "display charset", + "comment", + "path", + "directory", + "workgroup", + "realm", + "netbios name", + "netbios aliases", + "netbios scope", + "server string", + "interfaces", + "bind interfaces only", + "security", + "auth methods", + "encrypt passwords", + "null passwords", + "obey pam restrictions", + "password server", + "smb passwd file", + "private dir", + "passwd chat", + "password level", + "lanman auth", + "ntlm auth", + "client NTLMv2 auth", + "client lanman auth", + "client plaintext auth", + "read only", + "hosts allow", + "hosts deny", + "log level", + "debuglevel", + "log file", + "smb ports", + "large readwrite", + "max protocol", + "min protocol", + "unicode", + "read raw", + "write raw", + "disable netbios", + "nt status support", + "announce version", + "announce as", + "max mux", + "max xmit", + "name resolve order", + "max wins ttl", + "min wins ttl", + "time server", + "unix extensions", + "use spnego", + "server signing", + "client signing", + "max connections", + "paranoid server security", + "socket options", + "strict sync", + "max print jobs", + "printable", + "print ok", + "printer name", + "printer", + "map system", + "map hidden", + "map archive", + "preferred master", + "prefered master", + "local master", + "browseable", + "browsable", + "wins server", + "wins support", + "csc policy", + "strict locking", + "preload", + "auto services", + "lock dir", + "lock directory", + "pid directory", + "socket address", + "copy", + "include", + "available", + "volume", + "fstype", + "panic action", + "msdfs root", + "host msdfs", + "winbind separator"] + +def upgrade_smbconf(oldconf,mark): + """Remove configuration variables not present in Samba4 + + :param oldconf: Old configuration structure + :param mark: Whether removed configuration variables should be + kept in the new configuration as "samba3:<name>" + """ + data = oldconf.data() + newconf = param_init() + + for s in data: + for p in data[s]: + keep = False + for k in smbconf_keep: + if smbconf_keep[k] == p: + keep = True + break + + if keep: + newconf.set(s, p, oldconf.get(s, p)) + elif mark: + newconf.set(s, "samba3:"+p, oldconf.get(s,p)) + + if oldconf.get("domain logons") == "True": + newconf.set("server role", "domain controller") + else: + if oldconf.get("security") == "user": + newconf.set("server role", "standalone") + else: + newconf.set("server role", "member server") + + return newconf + +def upgrade(subobj, samba3, message, paths, session_info, credentials): + ret = 0 + lp = loadparm_init() + samdb = Ldb(paths.samdb, session_info=session_info, credentials=credentials) + + message("Writing configuration") + newconf = upgrade_smbconf(samba3.configuration,True) + newconf.save(paths.smbconf) + + message("Importing account policies") + ldif = upgrade_sam_policy(samba3,subobj.BASEDN) + samdb.modify(ldif) + regdb = Ldb(paths.hklm) + + regdb.modify(""" +dn: value=RefusePasswordChange,key=Parameters,key=Netlogon,key=Services,key=CurrentControlSet,key=System,HIVE=NONE +replace: type +type: 4 +replace: data +data: %d +""" % samba3.policy.refuse_machine_password_change) + + message("Importing users") + for account in samba3.samaccounts: + msg = "... " + account.username + ldif = upgrade_sam_account(samdb, accounts,subobj.BASEDN,subobj.DOMAINSID) + try: + samdb.add(ldif) + except LdbError, e: + # FIXME: Ignore 'Record exists' errors + msg += "... error: " + str(e) + ret += 1; + message(msg) + + message("Importing groups") + for mapping in samba3.groupmappings: + msg = "... " + mapping.nt_name + ldif = upgrade_sam_group(mapping, subobj.BASEDN) + if ldif is not None: + try: + samdb.add(ldif) + except LdbError, e: + # FIXME: Ignore 'Record exists' errors + msg += "... error: " + str(e) + ret += 1 + message(msg) + + message("Importing registry data") + for hive in ["hkcr","hkcu","hklm","hkpd","hku","hkpt"]: + message("... " + hive) + regdb = Ldb(paths[hive]) + ldif = upgrade_registry(samba3.registry, hive, regdb) + for j in ldif: + msg = "... ... " + j + try: + regdb.add(ldif[j]) + except LdbError, e: + # FIXME: Ignore 'Record exists' errors + msg += "... error: " + str(e) + ret += 1 + message(msg) + + message("Importing WINS data") + winsdb = Ldb(paths.winsdb) + ldb_erase(winsdb) + + ldif = upgrade_wins(samba3) + winsdb.add(ldif) + + # figure out ldapurl, if applicable + ldapurl = None + pdb = samba3.configuration.get_list("passdb backend") + if pdb is not None: + for backend in pdb: + if len(backend) >= 7 and backend[0:7] == "ldapsam": + ldapurl = backend[7:] + + # URL was not specified in passdb backend but ldap /is/ used + if ldapurl == "": + ldapurl = "ldap://%s" % samba3.configuration.get("ldap server") + + # Enable samba3sam module if original passdb backend was ldap + if ldapurl is not None: + message("Enabling Samba3 LDAP mappings for SAM database") + + samdb.modify(""" +dn: @MODULES +changetype: modify +replace: @LIST +@LIST: samldb,operational,objectguid,rdn_name,samba3sam +""") + + samdb.add({"dn": "@MAP=samba3sam", "@MAP_URL": ldapurl}) + + return ret + +def upgrade_verify(subobj, samba3, paths, message): + message("Verifying account policies") + + samldb = Ldb(paths.samdb) + + for account in samba3.samaccounts: + msg = samldb.search("(&(sAMAccountName=" + account.nt_username + ")(objectclass=user))") + assert(len(msg) >= 1) + + # FIXME diff --git a/source4/scripting/python/subunit/__init__.py b/source4/scripting/python/subunit/__init__.py index e44dd766cc..4d3434a3ea 100644 --- a/source4/scripting/python/subunit/__init__.py +++ b/source4/scripting/python/subunit/__init__.py @@ -20,7 +20,6 @@ import os from StringIO import StringIO -import subprocess import sys import unittest @@ -216,14 +215,14 @@ class TestProtocolClient(unittest.TestResult): def addError(self, test, error): """Report an error in test test.""" self._stream.write("error: %s [\n" % (test.shortDescription() or str(test))) - for line in self._exc_info_to_string(error, test).split(): + for line in self._exc_info_to_string(error, test).splitlines(): self._stream.write("%s\n" % line) self._stream.write("]\n") def addFailure(self, test, error): """Report a failure in test test.""" self._stream.write("failure: %s [\n" % (test.shortDescription() or str(test))) - for line in self._exc_info_to_string(error, test).split(): + for line in self._exc_info_to_string(error, test).splitlines(): self._stream.write("%s\n" % line) self._stream.write("]\n") @@ -315,9 +314,8 @@ class ExecTestCase(unittest.TestCase): def _run(self, result): protocol = TestProtocolServer(result) - output = subprocess.Popen([self.script], - stdout=subprocess.PIPE).communicate()[0] - protocol.readFrom(StringIO(output)) + output = os.popen(self.script, mode='r') + protocol.readFrom(output) class IsolatedTestCase(unittest.TestCase): diff --git a/source4/selftest/config.mk b/source4/selftest/config.mk index 52148090ad..72bc10cf56 100644 --- a/source4/selftest/config.mk +++ b/source4/selftest/config.mk @@ -1,4 +1,4 @@ -SELFTEST = $(PERL) $(srcdir)/selftest/selftest.pl --prefix=${selftest_prefix} \ +SELFTEST = $(LIB_PATH_VAR)=$(builddir)/bin/shared $(PERL) $(srcdir)/selftest/selftest.pl --prefix=${selftest_prefix} \ --builddir=$(builddir) --srcdir=$(srcdir) \ --expected-failures=$(srcdir)/samba4-knownfail \ --exclude=$(srcdir)/samba4-skip --testlist="./selftest/samba4_tests.sh|" \ diff --git a/source4/selftest/env/Samba4.pm b/source4/selftest/env/Samba4.pm index 9e3c29b32b..f2ba37f618 100644 --- a/source4/selftest/env/Samba4.pm +++ b/source4/selftest/env/Samba4.pm @@ -25,9 +25,11 @@ sub new($$$$) { sub openldap_start($$$) { my ($slapd_conf, $uri, $logs) = @_; my $oldpath = $ENV{PATH}; + my $olroot = ""; my $olpath = ""; - if (defined $ENV{OPENLDAP_PATH}) { - $olpath = "$ENV{OPENLDAP_PATH}:" + if (defined $ENV{OPENLDAP_ROOT}) { + $olroot = "$ENV{OPENLDAP_ROOT}"; + $olpath = "$olroot/libexec:$olroot/sbin:"; } $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; system("slapd -d63 -f $slapd_conf -h $uri > $logs 2>&1 &"); @@ -225,8 +227,10 @@ sub mk_openldap($$$) my $oldpath = $ENV{PATH}; my $olpath = ""; - if (defined $ENV{OPENLDAP_PATH}) { - $olpath = "$ENV{OPENLDAP_PATH}:" + my $olroot = ""; + if (defined $ENV{OPENLDAP_ROOT}) { + $olroot = "$ENV{OPENLDAP_ROOT}"; + $olpath = "$olroot/libexec:$olroot/sbin:"; } $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; @@ -624,8 +628,12 @@ nogroup:x:65534:nobody my @provision_options = (); push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\""); push (@provision_options, "NSS_WRAPPER_GROUP=\"$nsswrap_group\""); - push (@provision_options, "$self->{bindir}/smbscript"); - push (@provision_options, "$self->{setupdir}/provision"); + if (defined($ENV{PROVISION_PYTHON})) { + push (@provision_options, "$self->{setupdir}/provision.py"); + } else { + push (@provision_options, "$self->{bindir}/smbscript"); + push (@provision_options, "$self->{setupdir}/provision"); + } push (@provision_options, split(' ', $configuration)); push (@provision_options, "--host-name=$netbiosname"); push (@provision_options, "--host-ip=$ifaceipv4"); diff --git a/source4/selftest/output/plain.pm b/source4/selftest/output/plain.pm index 0406ca7d3d..8a56d1c922 100644 --- a/source4/selftest/output/plain.pm +++ b/source4/selftest/output/plain.pm @@ -70,6 +70,7 @@ sub end_testsuite($$$$$$) if ($ret != $expected_ret and $self->{immediate} and not $self->{verbose}) { $out .= $self->{test_output}->{$name}; + push (@{$self->{suitesfailed}}, $name); } print $out; @@ -108,6 +109,13 @@ sub summary($) if ($#{$self->{suitesfailed}} > -1) { print SUMMARY "= Failed tests =\n"; + + foreach (@{$self->{suitesfailed}}) { + print SUMMARY "== $_ ==\n"; + print SUMMARY $self->{test_output}->{$_}."\n\n"; + } + + print SUMMARY "\n"; } if (not $self->{immediate} and not $self->{verbose}) { @@ -116,9 +124,6 @@ sub summary($) print "FAIL: $_\n"; print $self->{test_output}->{$_}; print "\n"; - - print SUMMARY "= $_ =\n"; - print SUMMARY $self->{test_output}->{$_}."\n\n"; } } diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 9043de72d4..95baff2be7 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -212,7 +212,7 @@ if test x"${PIDL_TESTS_SKIP}" = x"yes"; then echo "Skipping pidl tests - PIDL_TESTS_SKIP=yes" elif $PERL -e 'eval require Test::More;' > /dev/null 2>&1; then for f in $samba4srcdir/pidl/tests/*.pl; do - plantest "pidl/`basename $f`" none $PERL $f "|" $samba4srcdir/script/harness2subunit.pl + plantest "pidl.`basename $f .pl`" none $PERL $f "|" $samba4srcdir/script/harness2subunit.pl done else echo "Skipping pidl tests - Test::More not installed" @@ -279,13 +279,6 @@ for env in dc member; do done done -# Tests for SWIG -# export PYTHONPATH=lib/tdb/swig:lib/ldb/swig:scripting/swig:$PYTHONPATH -# export LD_LIBRARY_PATH=bin:$LD_LIBRARY_PATH - -# plantest "tdb wrappers" scripting/swig/torture/torture_tdb.py -# plantest "ldb wrappers" scripting/swig/torture/torture_ldb.py - if test -f $samba4bindir/nsstest then plantest "NSS-TEST using winbind" member $VALGRIND $samba4bindir/nsstest $samba4bindir/shared/libnss_winbind.so @@ -300,4 +293,8 @@ then plantest "tdb.python" none PYTHONPATH=bin/python:scripting/python:lib/tdb/python/tests scripting/bin/subunitrun simple plantest "auth.python" none PYTHONPATH=bin/python:scripting/python:auth/tests/ scripting/bin/subunitrun bindings plantest "security.python" none PYTHONPATH=bin/python:scripting/python:libcli/security/tests/ scripting/bin/subunitrun bindings + plantest "param.python" none PYTHONPATH=bin/python:scripting/python:param/tests scripting/bin/subunitrun bindings + plantest "upgrade.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.upgrade + plantest "samba.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests + plantest "provision.python" none PYTHONPATH=bin/python:scripting/python scripting/bin/subunitrun samba.tests.provision fi diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index a1aca161a8..456b483f07 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -405,11 +405,6 @@ my $tls_enabled = not $opt_quick; $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no"); $ENV{LDB_MODULES_PATH} = "$old_pwd/bin/modules/ldb"; $ENV{LD_SAMBA_MODULE_PATH} = "$old_pwd/bin/modules"; -if (defined($ENV{LD_LIBRARY_PATH})) { - $ENV{LD_LIBRARY_PATH} = "$old_pwd/bin/shared:$ENV{LD_LIBRARY_PATH}"; -} else { - $ENV{LD_LIBRARY_PATH} = "$old_pwd/bin/shared"; -} if (defined($ENV{PKG_CONFIG_PATH})) { $ENV{PKG_CONFIG_PATH} = "$old_pwd/bin/pkgconfig:$ENV{PKG_CONFIG_PATH}"; } else { diff --git a/source4/selftest/test_w2k3.sh b/source4/selftest/test_w2k3.sh index b262029892..3cd034d000 100755 --- a/source4/selftest/test_w2k3.sh +++ b/source4/selftest/test_w2k3.sh @@ -4,7 +4,7 @@ # add tests to this list as they start passing, so we test # that they stay passing -ncacn_np_tests="RPC-SCHANNEL RPC-DSSETUP RPC-EPMAPPER RPC-SAMR RPC-WKSSVC RPC-SRVSVC RPC-EVENTLOG RPC-NETLOGON RPC-LSA RPC-SAMLOGON RPC-SAMSYNC RPC-MULTIBIND RPC-WINREG" +ncacn_np_tests="RPC-SCHANNEL RPC-DSSETUP RPC-EPMAPPER RPC-SAMR RPC-WKSSVC RPC-SRVSVC RPC-EVENTLOG RPC-NETLOGON RPC-LSA RPC-SAMLOGON RPC-SAMSYNC RPC-MULTIBIND RPC-WINREG RPC-SPOOLSS RPC-SPOOLSS-WIN" ncacn_ip_tcp_tests="RPC-SCHANNEL RPC-EPMAPPER RPC-SAMR RPC-NETLOGON RPC-LSA RPC-SAMLOGON RPC-SAMSYNC RPC-MULTIBIND" if [ $# -lt 4 ]; then diff --git a/source4/selftest/test_win.sh b/source4/selftest/test_win.sh index 4e5558c206..960bd20ded 100755 --- a/source4/selftest/test_win.sh +++ b/source4/selftest/test_win.sh @@ -35,7 +35,7 @@ testit "$name" smb $WINTEST_DIR/wintest_net.sh $SMBTORTURE_REMOTE_HOST \ name="Windows 2003 against smbd" testit "$name" smb $WINTEST_DIR/wintest_client.sh $SMBTORTURE_REMOTE_HOST -dc_tests="RPC-DRSUAPI RPC-SPOOLSS ncacn_np ncacn_ip_tcp" +dc_tests="RPC-DRSUAPI ncacn_np ncacn_ip_tcp" for name in $dc_tests; do testit "$name against Windows 2003 DC" rpc $WINTEST_DIR/wintest_2k3_dc.sh \ "$name" diff --git a/source4/setup/provision.py b/source4/setup/provision.py new file mode 100755 index 0000000000..898dfc7405 --- /dev/null +++ b/source4/setup/provision.py @@ -0,0 +1,173 @@ +#!/usr/bin/python +# +# Unix SMB/CIFS implementation. +# provision a Samba4 server +# Copyright (C) Andrew Tridgell 2005 +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +import getopt +import optparse +import sys + +# Add path to the library for in-tree use +sys.path.append("scripting/python") + +import samba + +from auth import system_session +import samba.getopt as options +import param +from samba.provision import (provision, + provision_default_paths, provision_ldapbase) + +parser = optparse.OptionParser("provision [options]") +parser.add_option_group(options.SambaOptions(parser)) +parser.add_option_group(options.VersionOptions(parser)) +credopts = options.CredentialsOptions(parser) +parser.add_option_group(credopts) +parser.add_option("--setupdir", type="string", metavar="DIR", + help="directory with setup files") +parser.add_option("--realm", type="string", metavar="REALM", help="set realm") +parser.add_option("--domain", type="string", metavar="DOMAIN", + help="set domain") +parser.add_option("--domain-guid", type="string", metavar="GUID", + help="set domainguid (otherwise random)") +parser.add_option("--domain-sid", type="string", metavar="SID", + help="set domainsid (otherwise random)") +parser.add_option("--policy-guid", type="string", metavar="GUID", + help="set policy guid") +parser.add_option("--host-name", type="string", metavar="HOSTNAME", + help="set hostname") +parser.add_option("--host-ip", type="string", metavar="IPADDRESS", + help="set ipaddress") +parser.add_option("--host-guid", type="string", metavar="GUID", + help="set hostguid (otherwise random)") +parser.add_option("--invocationid", type="string", metavar="GUID", + help="set invocationid (otherwise random)") +parser.add_option("--adminpass", type="string", metavar="PASSWORD", + help="choose admin password (otherwise random)") +parser.add_option("--krbtgtpass", type="string", metavar="PASSWORD", + help="choose krbtgt password (otherwise random)") +parser.add_option("--machinepass", type="string", metavar="PASSWORD", + help="choose machine password (otherwise random)") +parser.add_option("--dnspass", type="string", metavar="PASSWORD", + help="choose dns password (otherwise random)") +parser.add_option("--root", type="string", metavar="USERNAME", + help="choose 'root' unix username") +parser.add_option("--nobody", type="string", metavar="USERNAME", + help="choose 'nobody' user") +parser.add_option("--nogroup", type="string", metavar="GROUPNAME", + help="choose 'nogroup' group") +parser.add_option("--wheel", type="string", metavar="GROUPNAME", + help="choose 'wheel' privileged group") +parser.add_option("--users", type="string", metavar="GROUPNAME", + help="choose 'users' group") +parser.add_option("--quiet", help="Be quiet", action="store_true") +parser.add_option("--blank", + help="do not add users or groups, just the structure") +parser.add_option("--ldap-base", + help="output only an LDIF file, suitable for creating an LDAP baseDN", + action="store_true") +parser.add_option("--ldap-backend", type="string", metavar="LDAPSERVER", + help="LDAP server to use for this provision") +parser.add_option("--ldap-module=", type="string", metavar="MODULE", + help="LDB mapping module to use for the LDAP backend") +parser.add_option("--aci", type="string", metavar="ACI", + help="An arbitary LDIF fragment, particularly useful to loading a backend ACI value into a target LDAP server. You must provide at least a realm and domain") +parser.add_option("--server-role", type="choice", metavar="ROLE", + choices=["domain controller", "member server"], + help="Set server role to provision for (default standalone)") +parser.add_option("--partitions-only", + help="Configure Samba's partitions, but do not modify them (ie, join a BDC)", action="store_true") + +opts = parser.parse_args()[0] + +def message(text): + """print a message if quiet is not set.""" + if not opts.quiet: + print text + +hostname = opts.host_name + +if opts.realm is None or opts.domain is None or opts.host_name is None: + if opts.realm is None: + print >>sys.stderr, "No realm set" + if opts.domain is None: + print >>sys.stderr, "No domain set" + if opts.host_name is None: + print >>sys.stderr, "No host name set" + parser.print_usage() + sys.exit(1) + +# cope with an initially blank smb.conf +lp = param.LoadParm() +lp.load(opts.configfile) +lp.set("realm", opts.realm) +lp.set("workgroup", opts.domain) +lp.set("server role", opts.server_role) + +if opts.aci is not None: + print "set ACI: %s" % opts.aci + +paths = provision_default_paths(lp, opts.realm.lower()) +paths.smbconf = opts.configfile + +if opts.ldap_backend: + if opts.ldap_backend == "ldapi": + subobj.ldap_backend = subobj.ldapi_uri + + if not opts.ldap_module: + subobj.ldapmodule = "entryuuid" + + subobj.domaindn_ldb = subobj.ldap_backend + subobj.domaindn_mod2 = ",%s,paged_searches" % subobj.ldapmodule + subobj.configdn_ldb = subobj.ldap_backend + subobj.configdn_mod2 = ",%s,paged_searches" % subobj.ldapmodule + subobj.schemadn_ldb = subobj.ldap_backend + subobj.schemadn_mod2 = ",%s,paged_searches" % subobj.ldapmodule + message("LDAP module: %s on backend: %s" % (subobj.ldapmodule, subobj.ldap_backend)) + +creds = credopts.get_credentials() + +setup_dir = opts.setupdir +if setup_dir is None: + setup_dir = "setup" +if opts.ldap_base: + provision_ldapbase(setup_dir, message, paths) + message("Please install the LDIF located in %s, %s and into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server" % (paths.ldap_basedn_ldif, paths.ldap_config_basedn_ldif, paths.ldap_schema_basedn_ldif)) +elif opts.partitions_only: + provision_become_dc(setup_dir, message, False, + paths, lp, system_session(), creds) +else: + provision(lp, setup_dir, message, opts.blank, paths, + system_session(), creds, opts.ldap_backend, realm=opts.realm, + domainguid=opts.domain_guid, domainsid=opts.domain_sid, + policyguid=opts.policy_guid, hostname=opts.host_name, + hostip=opts.host_ip, hostguid=opts.host_guid, + invocationid=opts.invocationid, adminpass=opts.adminpass, + krbtgtpass=opts.krbtgtpass, machinepass=opts.machinepass, + dnspass=opts.dnspass, root=opts.root, nobody=opts.nobody, + nogroup=opts.nogroup, wheel=opts.wheel, users=opts.users, + aci=opts.aci, serverrole=opts.server_role) + message("To reproduce this provision, run with:") + def shell_escape(arg): + if " " in arg: + return '"%s"' % arg + return arg + message(" ".join([shell_escape(arg) for arg in sys.argv])) + +message("All OK") diff --git a/source4/setup/slapd.conf b/source4/setup/slapd.conf index 0fd018e943..446facbf3d 100644 --- a/source4/setup/slapd.conf +++ b/source4/setup/slapd.conf @@ -22,7 +22,7 @@ include ${LDAPDIR}/modules.conf defaultsearchbase ${DOMAINDN} backend hdb -database bdb +database hdb suffix ${SCHEMADN} directory ${LDAPDIR}/db/schema index objectClass eq diff --git a/source4/setup/upgrade.py b/source4/setup/upgrade.py new file mode 100755 index 0000000000..96584a1026 --- /dev/null +++ b/source4/setup/upgrade.py @@ -0,0 +1,66 @@ +#!/usr/bin/python +# +# Upgrade from Samba3 +# Copyright Jelmer Vernooij 2005-2007 +# Released under the GNU GPL v3 or later +# +import getopt +import optparse +import sys +sys.path.append("scripting/python") +import samba +import samba.getopt + +parser = optparse.OptionParser("upgrade [options]") +parser.add_option_group(options.SambaOptions(parser)) +parser.add_option_group(options.VersionOptions(parser)) +parser.add_option_group(options.CredentialsOptions(parser)) +parser.add_option("--realm", type="string", metavar="REALM", help="set realm") +parser.add_option("--quiet", help="Be quiet") +parser.add_option("--verify", help="Verify resulting configuration") +parser.add_option("--blank", + help="do not add users or groups, just the structure") +parser.add_option("--targetdir", type="string", metavar="DIR", + help="Set target directory") + +opts = parser.parse_args()[0] + +def message(text): + """Print a message if quiet is not set.""" + if opts.quiet: + print text + +message("Reading Samba3 databases and smb.conf\n") +samba3 = samba3_read(options.ARGV[0], options.ARGV[1]) + +message("Provisioning\n") +subobj = upgrade_provision(samba3) +if options.targetdir is not None: + paths = ProvisionPaths() + paths.smbconf = os.path.join(options.targetdir, "smb.conf") + ldbs = ["hklm","hkcr","hku","hkcu","hkpd","hkpt","samdb","rootdse","secrets","wins"] + for n in ldbs: + paths[n] = sprintf("tdb://%s/%s.ldb", options.targetdir, n) + paths.dns = os.path.join(options.targetdir, "dns.zone") +else: + paths = provision_default_paths(subobj) + +creds = options.get_credentials() +system_session = system_session() +paths = provision_default_paths(subobj) + +if options.realm: + subobj.realm = options.realm + +provision(lp, subobj, message, options.blank, paths, system_session, creds, undefined) + +ret = upgrade(subobj,samba3,message,paths, system_session, creds) +if ret > 0: + message("Failed to import %d entries\n", ret) +else: + provision_dns(subobj, message, paths, system_session, creds) + message("All OK\n") + +if options.verify: + message("Verifying...\n") + ret = upgrade_verify(subobj, samba3, paths, message) diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c index 237ebd4d7e..21cddc4d7d 100644 --- a/source4/smb_server/blob.c +++ b/source4/smb_server/blob.c @@ -24,6 +24,7 @@ #include "librpc/gen_ndr/ndr_misc.h" #include "ntvfs/ntvfs.h" #include "libcli/raw/libcliraw.h" +#include "param/param.h" #define BLOB_CHECK(cmd) do { \ NTSTATUS _status; \ @@ -138,10 +139,10 @@ size_t smbsrv_blob_push_string(TALLOC_CTX *mem_ctx, alignment = 1; if (dest_len > 0) { SCVAL(blob->data + offset, 0, 0); - ret = push_string(global_smb_iconv_convenience, blob->data + offset + 1, str, dest_len-1, flags); + ret = push_string(lp_iconv_convenience(global_loadparm), blob->data + offset + 1, str, dest_len-1, flags); } } else { - ret = push_string(global_smb_iconv_convenience, blob->data + offset, str, dest_len, flags); + ret = push_string(lp_iconv_convenience(global_loadparm), blob->data + offset, str, dest_len, flags); } /* sometimes the string needs to be terminated, but the length diff --git a/source4/smb_server/smb/config.mk b/source4/smb_server/smb/config.mk index 05ff69316d..22151ebd3b 100644 --- a/source4/smb_server/smb/config.mk +++ b/source4/smb_server/smb/config.mk @@ -15,7 +15,7 @@ OBJ_FILES = \ trans2.o \ signing.o PUBLIC_DEPENDENCIES = \ - ntvfs LIBPACKET + ntvfs LIBPACKET CREDENTIALS LDFLAGS = $(SUBSYSTEM_SMB_SERVER_OUTPUT) # End SUBSYSTEM SMB_PROTOCOL ####################### diff --git a/source4/smb_server/smb/negprot.c b/source4/smb_server/smb/negprot.c index f92c542ef6..6d9ff838cb 100644 --- a/source4/smb_server/smb/negprot.c +++ b/source4/smb_server/smb/negprot.c @@ -375,7 +375,7 @@ static void reply_nt1(struct smbsrv_request *req, uint16_t choice) } cli_credentials_set_conf(server_credentials, req->smb_conn->lp_ctx); - nt_status = cli_credentials_set_machine_account(server_credentials); + nt_status = cli_credentials_set_machine_account(server_credentials, req->smb_conn->lp_ctx); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(10, ("Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(nt_status))); talloc_free(server_credentials); diff --git a/source4/smb_server/smb/nttrans.c b/source4/smb_server/smb/nttrans.c index 25cddd6654..34f9df8706 100644 --- a/source4/smb_server/smb/nttrans.c +++ b/source4/smb_server/smb/nttrans.c @@ -26,6 +26,7 @@ #include "ntvfs/ntvfs.h" #include "libcli/raw/libcliraw.h" #include "librpc/gen_ndr/ndr_security.h" +#include "param/param.h" /* hold the state of a nttrans op while in progress. Needed to allow for async backend @@ -372,7 +373,7 @@ static NTSTATUS nttrans_notify_change_send(struct nttrans_op *op) ssize_t len; SIVAL(p, 4, info->nttrans.out.changes[i].action); - len = push_string(global_smb_iconv_convenience, p + 12, info->nttrans.out.changes[i].name.s, + len = push_string(lp_iconv_convenience(global_loadparm), p + 12, info->nttrans.out.changes[i].name.s, op->trans->out.params.length - (p+12 - op->trans->out.params.data), STR_UNICODE); SIVAL(p, 8, len); diff --git a/source4/smb_server/smb/request.c b/source4/smb_server/smb/request.c index cdeba02dd7..8f6d664500 100644 --- a/source4/smb_server/smb/request.c +++ b/source4/smb_server/smb/request.c @@ -27,6 +27,7 @@ #include "smbd/service_stream.h" #include "lib/stream/packet.h" #include "ntvfs/ntvfs.h" +#include "param/param.h" /* we over allocate the data buffer to prevent too many realloc calls */ @@ -408,7 +409,7 @@ size_t req_push_str(struct smbsrv_request *req, uint8_t *dest, const char *str, dest = req->out.buffer + PTR_DIFF(dest, buf0); } - len = push_string(global_smb_iconv_convenience, dest, str, len, flags); + len = push_string(lp_iconv_convenience(global_loadparm), dest, str, len, flags); grow_size = len + PTR_DIFF(dest, req->out.data); @@ -494,7 +495,7 @@ static size_t req_pull_ucs2(struct smbsrv_request *req, const char **dest, const return src_len2 + alignment; } - ret = convert_string_talloc(req, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(req, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; @@ -543,7 +544,7 @@ static size_t req_pull_ascii(struct smbsrv_request *req, const char **dest, cons src_len2++; } - ret = convert_string_talloc(req, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(req, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; diff --git a/source4/smb_server/smb2/fileio.c b/source4/smb_server/smb2/fileio.c index a5fc3d8268..e853743b2f 100644 --- a/source4/smb_server/smb2/fileio.c +++ b/source4/smb_server/smb2/fileio.c @@ -24,6 +24,7 @@ #include "smb_server/service_smb_proto.h" #include "smb_server/smb2/smb2_server.h" #include "ntvfs/ntvfs.h" +#include "param/param.h" static void smb2srv_create_send(struct ntvfs_request *ntvfs) { @@ -352,7 +353,7 @@ static void smb2srv_notify_send(struct ntvfs_request *ntvfs) ssize_t len; SIVAL(p, 4, io->smb2.out.changes[i].action); - len = push_string(global_smb_iconv_convenience, p + 12, io->smb2.out.changes[i].name.s, + len = push_string(lp_iconv_convenience(global_loadparm), p + 12, io->smb2.out.changes[i].name.s, blob.length - (p+12 - blob.data), STR_UNICODE); SIVAL(p, 8, len); diff --git a/source4/smb_server/smb2/negprot.c b/source4/smb_server/smb2/negprot.c index 664079812a..8e3cfd3547 100644 --- a/source4/smb_server/smb2/negprot.c +++ b/source4/smb_server/smb2/negprot.c @@ -55,7 +55,7 @@ static NTSTATUS smb2srv_negprot_secblob(struct smb2srv_request *req, DATA_BLOB * } cli_credentials_set_conf(server_credentials, req->smb_conn->lp_ctx); - nt_status = cli_credentials_set_machine_account(server_credentials); + nt_status = cli_credentials_set_machine_account(server_credentials, req->smb_conn->lp_ctx); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(10, ("Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(nt_status))); talloc_free(server_credentials); diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index c91566e244..082de6540b 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -156,7 +156,8 @@ static void smbsrv_accept(struct stream_connection *conn) smbsrv_management_init(smb_conn); - if (!NT_STATUS_IS_OK(share_get_context(smb_conn, &(smb_conn->share_context)))) { + if (!NT_STATUS_IS_OK(share_get_context_by_name(smb_conn, lp_share_backend(smb_conn->lp_ctx), + smb_conn->lp_ctx, &(smb_conn->share_context)))) { smbsrv_terminate_connection(smb_conn, "share_init failed!"); return; } @@ -217,15 +218,20 @@ static void smbsrv_task_init(struct task_server *task) task_server_set_title(task, "task[smbsrv]"); if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) { - int num_interfaces = iface_count(task->lp_ctx); + int num_interfaces; int i; + struct interface *ifaces; + + load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces); + + num_interfaces = iface_count(ifaces); /* We have been given an interfaces line, and been told to only bind to those interfaces. Create a socket per interface and bind to only these. */ for(i = 0; i < num_interfaces; i++) { - const char *address = iface_n_ip(task->lp_ctx, i); + const char *address = iface_n_ip(ifaces, i); status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops, address); if (!NT_STATUS_IS_OK(status)) goto failed; } diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index fdeaefc443..09d32d05aa 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -198,7 +198,7 @@ _NORETURN_ static void standard_terminate(struct event_context *ev, const char * /* this reload_charcnv() has the effect of freeing the iconv context memory, which makes leak checking easier */ - reload_charcnv(); + reload_charcnv(global_loadparm); /* the secrets db should really hang off the connection structure */ secrets_shutdown(); diff --git a/source4/smbd/server.c b/source4/smbd/server.c index e7d7d1a7fc..3f1d3c35d8 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -226,7 +226,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[ model = poptGetOptArg(pc); break; default: - d_fprintf(stderr, "\nInvalid option %s: %s\n\n", + fprintf(stderr, "\nInvalid option %s: %s\n\n", poptBadOption(pc, 0), poptStrerror(opt)); poptPrintUsage(pc, stderr, 0); exit(1); @@ -234,7 +234,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[ } if (opt_daemon && opt_interactive) { - d_fprintf(stderr,"\nERROR: " + fprintf(stderr,"\nERROR: " "Option -i|--interactive is not allowed together with -D|--daemon\n\n"); poptPrintUsage(pc, stderr, 0); exit(1); diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c index 8df8c474f5..6d2e95dc94 100644 --- a/source4/smbd/service_stream.c +++ b/source4/smbd/service_stream.c @@ -183,7 +183,9 @@ static void stream_new_connection(struct event_context *ev, /* setup to receive internal messages on this connection */ srv_conn->msg_ctx = messaging_init(srv_conn, lp_messaging_path(srv_conn, global_loadparm), - srv_conn->server_id, ev); + srv_conn->server_id, + lp_iconv_convenience(global_loadparm), + ev); if (!srv_conn->msg_ctx) { stream_terminate_connection(srv_conn, "messaging_init() failed"); return; diff --git a/source4/smbd/service_stream.h b/source4/smbd/service_stream.h index 6eb26a4282..04d23a56f2 100644 --- a/source4/smbd/service_stream.h +++ b/source4/smbd/service_stream.h @@ -48,6 +48,7 @@ struct stream_connection { struct socket_context *socket; struct messaging_context *msg_ctx; + struct loadparm_context *lp_ctx; bool processing; const char *terminate; diff --git a/source4/smbd/service_task.c b/source4/smbd/service_task.c index dceda5a922..f286da5cf6 100644 --- a/source4/smbd/service_task.c +++ b/source4/smbd/service_task.c @@ -68,7 +68,9 @@ static void task_server_callback(struct event_context *event_ctx, task->msg_ctx = messaging_init(task, lp_messaging_path(task, task->lp_ctx), - task->server_id, task->event_ctx); + task->server_id, + lp_iconv_convenience(task->lp_ctx), + task->event_ctx); if (!task->msg_ctx) { task_server_terminate(task, "messaging_init() failed"); return; diff --git a/source4/torture/basic/base.c b/source4/torture/basic/base.c index 24c0d292ac..cba57ac413 100644 --- a/source4/torture/basic/base.c +++ b/source4/torture/basic/base.c @@ -51,7 +51,7 @@ static struct smbcli_state *open_nbt_connection(struct torture_context *tctx) goto failed; } - if (!smbcli_socket_connect(cli, host, lp_name_resolve_order(tctx->lp_ctx), lp_max_xmit(tctx->lp_ctx), lp_maxmux(tctx->lp_ctx))) { + if (!smbcli_socket_connect(cli, host, lp_smb_ports(tctx->lp_ctx), lp_resolve_context(tctx->lp_ctx), lp_max_xmit(tctx->lp_ctx), lp_maxmux(tctx->lp_ctx))) { torture_comment(tctx, "Failed to connect with %s\n", host); goto failed; } diff --git a/source4/torture/basic/charset.c b/source4/torture/basic/charset.c index 6b993aad8c..a5d534b92b 100644 --- a/source4/torture/basic/charset.c +++ b/source4/torture/basic/charset.c @@ -24,6 +24,7 @@ #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" #include "torture/util.h" +#include "param/param.h" #define BASEDIR "\\chartest\\" @@ -55,7 +56,7 @@ static NTSTATUS unicode_open(struct torture_context *tctx, } SSVAL(ucs_name, i*2, 0); - i = convert_string_talloc(ucs_name, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname); + i = convert_string_talloc(ucs_name, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname); if (i == -1) { torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n"); talloc_free(ucs_name); diff --git a/source4/torture/basic/misc.c b/source4/torture/basic/misc.c index e9a41e8299..0832556b53 100644 --- a/source4/torture/basic/misc.c +++ b/source4/torture/basic/misc.c @@ -815,7 +815,7 @@ static struct composite_context *torture_connect_async( torture_comment(tctx, "Open Connection to %s/%s\n",host,share); smb->in.dest_host=talloc_strdup(mem_ctx,host); smb->in.service=talloc_strdup(mem_ctx,share); - smb->in.port=0; + smb->in.dest_ports=lp_smb_ports(tctx->lp_ctx); smb->in.called_name = strupper_talloc(mem_ctx, host); smb->in.service_type=NULL; smb->in.credentials=cmdline_credentials; diff --git a/source4/torture/basic/scanner.c b/source4/torture/basic/scanner.c index 884be8490d..68fccc5010 100644 --- a/source4/torture/basic/scanner.c +++ b/source4/torture/basic/scanner.c @@ -23,11 +23,12 @@ #include "torture/util.h" #include "libcli/raw/libcliraw.h" #include "system/filesys.h" -#include "pstring.h" +#include "param/param.h" #define VERBOSE 0 #define OP_MIN 0 #define OP_MAX 100 +#define PARAM_SIZE 1024 /**************************************************************************** look for a partial hit @@ -81,12 +82,12 @@ static NTSTATUS try_trans2(struct smbcli_state *cli, *rdata_len = t2.out.data.length; talloc_free(mem_ctx); - + return status; } -static NTSTATUS try_trans2_len(struct smbcli_state *cli, +static NTSTATUS try_trans2_len(struct smbcli_state *cli, const char *format, int op, int level, uint8_t *param, uint8_t *data, @@ -96,14 +97,14 @@ static NTSTATUS try_trans2_len(struct smbcli_state *cli, NTSTATUS ret=NT_STATUS_OK; ret = try_trans2(cli, op, param, data, param_len, - sizeof(pstring), rparam_len, rdata_len); -#if VERBOSE + PARAM_SIZE, rparam_len, rdata_len); +#if VERBOSE printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret)); #endif if (!NT_STATUS_IS_OK(ret)) return ret; *data_len = 0; - while (*data_len < sizeof(pstring)) { + while (*data_len < PARAM_SIZE) { ret = try_trans2(cli, op, param, data, param_len, *data_len, rparam_len, rdata_len); if (NT_STATUS_IS_OK(ret)) break; @@ -124,124 +125,162 @@ check whether a trans2 opnum exists at all ****************************************************************************/ static bool trans2_op_exists(struct smbcli_state *cli, int op) { - int data_len = 0; - int param_len = 0; + int data_len = PARAM_SIZE; + int param_len = PARAM_SIZE; int rparam_len, rdata_len; - uint8_t param[1024], data[1024]; + uint8_t *param, *data; NTSTATUS status1, status2; + TALLOC_CTX *mem_ctx; - memset(data, 0, sizeof(data)); - data_len = 4; + mem_ctx = talloc_init("trans2_op_exists"); /* try with a info level only */ - param_len = sizeof(param); - data_len = sizeof(data); - memset(param, 0xFF, sizeof(param)); - memset(data, 0xFF, sizeof(data)); - - status1 = try_trans2(cli, 0xFFFF, param, data, param_len, data_len, + param = talloc_array(mem_ctx, uint8_t, param_len); + data = talloc_array(mem_ctx, uint8_t, data_len); + + memset(param, 0xFF, param_len); + memset(data, 0xFF, data_len); + + status1 = try_trans2(cli, 0xFFFF, param, data, param_len, data_len, &rparam_len, &rdata_len); - status2 = try_trans2(cli, op, param, data, param_len, data_len, + status2 = try_trans2(cli, op, param, data, param_len, data_len, &rparam_len, &rdata_len); - if (NT_STATUS_EQUAL(status1, status2)) return false; + if (NT_STATUS_EQUAL(status1, status2)) { + talloc_free(mem_ctx); + return false; + } printf("Found op %d (status=%s)\n", op, nt_errstr(status2)); + talloc_free(mem_ctx); return true; } /**************************************************************************** check for existance of a trans2 call ****************************************************************************/ -static bool scan_trans2(struct smbcli_state *cli, int op, int level, +static bool scan_trans2(struct smbcli_state *cli, int op, int level, int fnum, int dnum, int qfnum, const char *fname) { int data_len = 0; int param_len = 0; int rparam_len, rdata_len; - uint8_t param[1024], data[1024]; + uint8_t *param, *data; NTSTATUS status; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("scan_trans2"); + + data = talloc_array(mem_ctx, uint8_t, PARAM_SIZE); + param = talloc_array(mem_ctx, uint8_t, PARAM_SIZE); - memset(data, 0, sizeof(data)); + memset(data, 0, PARAM_SIZE); data_len = 4; /* try with a info level only */ param_len = 2; SSVAL(param, 0, level); - status = try_trans2_len(cli, "void", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_trans2_len(cli, "void", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a file descriptor */ param_len = 6; SSVAL(param, 0, fnum); SSVAL(param, 2, level); SSVAL(param, 4, 0); - status = try_trans2_len(cli, "fnum", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_trans2_len(cli, "fnum", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a quota file descriptor */ param_len = 6; SSVAL(param, 0, qfnum); SSVAL(param, 2, level); SSVAL(param, 4, 0); - status = try_trans2_len(cli, "qfnum", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_trans2_len(cli, "qfnum", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a notify style */ param_len = 6; SSVAL(param, 0, dnum); SSVAL(param, 2, dnum); SSVAL(param, 4, level); - status = try_trans2_len(cli, "notify", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_trans2_len(cli, "notify", op, level, param, data, + param_len, &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(global_smb_iconv_convenience, ¶m[6], fname, sizeof(pstring)-7, STR_TERMINATE|STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[6], fname, PARAM_SIZE-7, + STR_TERMINATE|STR_UNICODE); - status = try_trans2_len(cli, "fname", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_trans2_len(cli, "fname", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a new file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(global_smb_iconv_convenience, ¶m[6], "\\newfile.dat", sizeof(pstring)-7, STR_TERMINATE|STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[6], "\\newfile.dat", PARAM_SIZE-7, + STR_TERMINATE|STR_UNICODE); - status = try_trans2_len(cli, "newfile", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); + status = try_trans2_len(cli, "newfile", op, level, param, data, + param_len, &data_len, &rparam_len, &rdata_len); smbcli_unlink(cli->tree, "\\newfile.dat"); smbcli_rmdir(cli->tree, "\\newfile.dat"); - if (NT_STATUS_IS_OK(status)) return true; + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try dfs style */ smbcli_mkdir(cli->tree, "\\testdir"); param_len = 2; SSVAL(param, 0, level); - param_len += push_string(global_smb_iconv_convenience, ¶m[2], "\\testdir", sizeof(pstring)-3, STR_TERMINATE|STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[2], "\\testdir", PARAM_SIZE-3, + STR_TERMINATE|STR_UNICODE); - status = try_trans2_len(cli, "dfs", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); + status = try_trans2_len(cli, "dfs", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); smbcli_rmdir(cli->tree, "\\testdir"); - if (NT_STATUS_IS_OK(status)) return true; + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } + talloc_free(mem_ctx); return false; } - -bool torture_trans2_scan(struct torture_context *torture, +bool torture_trans2_scan(struct torture_context *torture, struct smbcli_state *cli) { int op, level; @@ -361,7 +400,7 @@ static NTSTATUS try_nttrans(struct smbcli_state *cli, } -static NTSTATUS try_nttrans_len(struct smbcli_state *cli, +static NTSTATUS try_nttrans_len(struct smbcli_state *cli, const char *format, int op, int level, uint8_t *param, uint8_t *data, @@ -371,14 +410,14 @@ static NTSTATUS try_nttrans_len(struct smbcli_state *cli, NTSTATUS ret=NT_STATUS_OK; ret = try_nttrans(cli, op, param, data, param_len, - sizeof(pstring), rparam_len, rdata_len); -#if VERBOSE + PARAM_SIZE, rparam_len, rdata_len); +#if VERBOSE printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret)); #endif if (!NT_STATUS_IS_OK(ret)) return ret; *data_len = 0; - while (*data_len < sizeof(pstring)) { + while (*data_len < PARAM_SIZE) { ret = try_nttrans(cli, op, param, data, param_len, *data_len, rparam_len, rdata_len); if (NT_STATUS_IS_OK(ret)) break; @@ -396,79 +435,108 @@ static NTSTATUS try_nttrans_len(struct smbcli_state *cli, /**************************************************************************** check for existance of a nttrans call ****************************************************************************/ -static bool scan_nttrans(struct smbcli_state *cli, int op, int level, +static bool scan_nttrans(struct smbcli_state *cli, int op, int level, int fnum, int dnum, const char *fname) { int data_len = 0; int param_len = 0; int rparam_len, rdata_len; - uint8_t param[1024], data[1024]; + uint8_t *param, *data; NTSTATUS status; + TALLOC_CTX *mem_ctx; - memset(data, 0, sizeof(data)); + mem_ctx = talloc_init("scan_nttrans"); + + param = talloc_array(mem_ctx, uint8_t, PARAM_SIZE); + data = talloc_array(mem_ctx, uint8_t, PARAM_SIZE); + memset(data, 0, PARAM_SIZE); data_len = 4; /* try with a info level only */ param_len = 2; SSVAL(param, 0, level); - status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_nttrans_len(cli, "void", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a file descriptor */ param_len = 6; SSVAL(param, 0, fnum); SSVAL(param, 2, level); SSVAL(param, 4, 0); - status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; - + status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a notify style */ param_len = 6; SSVAL(param, 0, dnum); SSVAL(param, 2, dnum); SSVAL(param, 4, level); - status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_nttrans_len(cli, "notify", op, level, param, data, + param_len, &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(global_smb_iconv_convenience, ¶m[6], fname, sizeof(pstring), STR_TERMINATE | STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[6], fname, PARAM_SIZE, + STR_TERMINATE | STR_UNICODE); - status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); - if (NT_STATUS_IS_OK(status)) return true; + status = try_nttrans_len(cli, "fname", op, level, param, data, + param_len, &data_len, &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try with a new file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); - param_len += push_string(global_smb_iconv_convenience, ¶m[6], "\\newfile.dat", sizeof(pstring), STR_TERMINATE | STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[6], "\\newfile.dat", PARAM_SIZE, + STR_TERMINATE | STR_UNICODE); - status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); + status = try_nttrans_len(cli, "newfile", op, level, param, data, + param_len, &data_len, &rparam_len, &rdata_len); smbcli_unlink(cli->tree, "\\newfile.dat"); smbcli_rmdir(cli->tree, "\\newfile.dat"); - if (NT_STATUS_IS_OK(status)) return true; + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } /* try dfs style */ smbcli_mkdir(cli->tree, "\\testdir"); param_len = 2; SSVAL(param, 0, level); - param_len += push_string(global_smb_iconv_convenience, ¶m[2], "\\testdir", sizeof(pstring), STR_TERMINATE | STR_UNICODE); + param_len += push_string(lp_iconv_convenience(global_loadparm), + ¶m[2], "\\testdir", PARAM_SIZE, + STR_TERMINATE | STR_UNICODE); - status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len, - &rparam_len, &rdata_len); + status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, + &data_len, &rparam_len, &rdata_len); smbcli_rmdir(cli->tree, "\\testdir"); - if (NT_STATUS_IS_OK(status)) return true; + if (NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return true; + } + talloc_free(mem_ctx); return false; } diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c index 244378dbc9..112cf323a1 100644 --- a/source4/torture/basic/utable.c +++ b/source4/torture/basic/utable.c @@ -24,6 +24,7 @@ #include "libcli/libcli.h" #include "torture/util.h" #include "pstring.h" +#include "param/param.h" bool torture_utable(struct torture_context *tctx, struct smbcli_state *cli) @@ -49,7 +50,7 @@ bool torture_utable(struct torture_context *tctx, SSVAL(c2, 0, c); fstrcpy(fname, "\\utable\\x"); p = fname+strlen(fname); - len = convert_string(global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + len = convert_string(lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, c2, 2, p, sizeof(fname)-strlen(fname)); p[len] = 0; @@ -108,7 +109,7 @@ static char *form_name(int c) p = fname+strlen(fname); SSVAL(c2, 0, c); - len = convert_string(global_smb_iconv_convenience, CH_UTF16, CH_UNIX, + len = convert_string(lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, c2, 2, p, sizeof(fname)-strlen(fname)); p[len] = 0; diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 7f615a785c..e9171d5330 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -130,6 +130,7 @@ OBJ_FILES = \ rpc/dssync.o \ rpc/spoolss.o \ rpc/spoolss_notify.o \ + rpc/spoolss_win.o \ rpc/unixinfo.o \ rpc/samr.o \ rpc/samr_accessmask.o \ diff --git a/source4/torture/gentest.c b/source4/torture/gentest.c index 25512b9567..b257f1dc35 100644 --- a/source4/torture/gentest.c +++ b/source4/torture/gentest.c @@ -152,7 +152,7 @@ static bool connect_servers_fast(void) /***************************************************** connect to the servers *******************************************************/ -static bool connect_servers(void) +static bool connect_servers(struct loadparm_context *lp_ctx) { int i, j; @@ -185,6 +185,7 @@ static bool connect_servers(void) status = smbcli_full_connection(NULL, &servers[i].cli[j], servers[i].server_name, + lp_smb_ports(lp_ctx), servers[i].share_name, NULL, servers[i].credentials, NULL); if (!NT_STATUS_IS_OK(status)) { @@ -1927,11 +1928,11 @@ static struct { run the test with the current set of op_parms parameters return the number of operations that completed successfully */ -static int run_test(void) +static int run_test(struct loadparm_context *lp_ctx) { int op, i; - if (!connect_servers()) { + if (!connect_servers(lp_ctx)) { printf("Failed to connect to servers\n"); exit(1); } @@ -2008,7 +2009,7 @@ static int run_test(void) perform a backtracking analysis of the minimal set of operations to generate an error */ -static void backtrack_analyze(void) +static void backtrack_analyze(struct loadparm_context *lp_ctx) { int chunk, ret; @@ -2029,7 +2030,7 @@ static void backtrack_analyze(void) } printf("Testing %d ops with %d-%d disabled\n", options.numops, base, max-1); - ret = run_test(); + ret = run_test(lp_ctx); printf("Completed %d of %d ops\n", ret, options.numops); for (i=base;i<max; i++) { op_parms[i].disabled = false; @@ -2061,7 +2062,7 @@ static void backtrack_analyze(void) } while (chunk > 0); printf("Reduced to %d ops\n", options.numops); - ret = run_test(); + ret = run_test(lp_ctx); if (ret != options.numops - 1) { printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops); } @@ -2070,7 +2071,7 @@ static void backtrack_analyze(void) /* start the main gentest process */ -static bool start_gentest(void) +static bool start_gentest(struct loadparm_context *lp_ctx) { int op; int ret; @@ -2106,15 +2107,15 @@ static bool start_gentest(void) } } - ret = run_test(); + ret = run_test(lp_ctx); if (ret != options.numops && options.analyze) { options.numops = ret+1; - backtrack_analyze(); + backtrack_analyze(lp_ctx); } else if (options.analyze_always) { - backtrack_analyze(); + backtrack_analyze(lp_ctx); } else if (options.analyze_continuous) { - while (run_test() == options.numops) ; + while (run_test(lp_ctx) == options.numops) ; } return ret == options.numops; @@ -2279,7 +2280,7 @@ static bool split_unc_name(const char *unc, char **server, char **share) printf("seed=%u\n", options.seed); - ret = start_gentest(); + ret = start_gentest(lp_ctx); if (ret) { printf("gentest completed - no errors\n"); diff --git a/source4/torture/ldap/cldapbench.c b/source4/torture/ldap/cldapbench.c index 47b1348ef6..c57ed6d48a 100644 --- a/source4/torture/ldap/cldapbench.c +++ b/source4/torture/ldap/cldapbench.c @@ -116,7 +116,7 @@ bool torture_bench_cldap(struct torture_context *torture) make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL)); /* do an initial name resolution to find its IP */ - status = resolve_name(&name, torture, &address, event_context_find(torture), lp_name_resolve_order(torture->lp_ctx)); + status = resolve_name(lp_resolve_context(torture->lp_ctx), &name, torture, &address, event_context_find(torture)); if (!NT_STATUS_IS_OK(status)) { printf("Failed to resolve %s - %s\n", name.name, nt_errstr(status)); diff --git a/source4/torture/libnet/libnet.c b/source4/torture/libnet/libnet.c index 0e5c9301f8..0bb70df1e0 100644 --- a/source4/torture/libnet/libnet.c +++ b/source4/torture/libnet/libnet.c @@ -42,6 +42,7 @@ NTSTATUS torture_net_init(void) torture_suite_add_simple_test(suite, "API-USERINFO", torture_userinfo_api); torture_suite_add_simple_test(suite, "API-USERLIST", torture_userlist); torture_suite_add_simple_test(suite, "API-GROUPINFO", torture_groupinfo_api); + torture_suite_add_simple_test(suite, "API-GROUPLIST", torture_grouplist); torture_suite_add_simple_test(suite, "API-RPCCONN-BIND", torture_rpc_connect_binding); torture_suite_add_simple_test(suite, "API-RPCCONN-SRV", torture_rpc_connect_srv); torture_suite_add_simple_test(suite, "API-RPCCONN-PDC", torture_rpc_connect_pdc); diff --git a/source4/torture/libnet/libnet_group.c b/source4/torture/libnet/libnet_group.c index 02fc0f7fd5..83aab48e90 100644 --- a/source4/torture/libnet/libnet_group.c +++ b/source4/torture/libnet/libnet_group.c @@ -202,6 +202,25 @@ static bool test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, } +static bool test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle) +{ + NTSTATUS status; + struct lsa_Close r; + + r.in.handle = domain_handle; + r.out.handle = domain_handle; + + status = dcerpc_lsa_Close(p, mem_ctx, &r); + if (!NT_STATUS_IS_OK(status)) { + printf("Close lsa domain failed - %s\n", nt_errstr(status)); + return false; + } + + return true; +} + + bool torture_groupinfo_api(struct torture_context *torture) { const char *name = TEST_GROUPNAME; @@ -269,3 +288,64 @@ done: talloc_free(mem_ctx); return ret; } + + +bool torture_grouplist(struct torture_context *torture) +{ + bool ret = true; + NTSTATUS status; + TALLOC_CTX *mem_ctx = NULL; + struct libnet_context *ctx; + struct lsa_String domain_name; + struct libnet_GroupList req; + int i; + + ctx = libnet_context_init(NULL, torture->lp_ctx); + ctx->cred = cmdline_credentials; + + domain_name.string = lp_workgroup(torture->lp_ctx); + mem_ctx = talloc_init("torture group list"); + + ZERO_STRUCT(req); + + printf("listing group accounts:\n"); + + do { + req.in.domain_name = domain_name.string; + req.in.page_size = 128; + req.in.resume_index = req.out.resume_index; + + status = libnet_GroupList(ctx, mem_ctx, &req); + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break; + + for (i = 0; i < req.out.count; i++) { + printf("\tgroup: %s, sid=%s\n", + req.out.groups[i].groupname, req.out.groups[i].sid); + } + + } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)); + + if (!(NT_STATUS_IS_OK(status) || + NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) { + printf("libnet_GroupList call failed: %s\n", nt_errstr(status)); + ret = false; + goto done; + } + + if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { + printf("domain close failed\n"); + ret = false; + } + + if (!test_lsa_close(ctx->lsa.pipe, mem_ctx, &ctx->lsa.handle)) { + printf("lsa domain close failed\n"); + ret = false; + } + + talloc_free(ctx); + +done: + talloc_free(mem_ctx); + return ret; +} diff --git a/source4/torture/libnet/libnet_lookup.c b/source4/torture/libnet/libnet_lookup.c index e4473b0fdd..bf3c77fb44 100644 --- a/source4/torture/libnet/libnet_lookup.c +++ b/source4/torture/libnet/libnet_lookup.c @@ -52,7 +52,7 @@ bool torture_lookup(struct torture_context *torture) } lookup.in.type = NBT_NAME_CLIENT; - lookup.in.methods = NULL; + lookup.in.resolve_ctx = NULL; lookup.out.address = NULL; status = libnet_Lookup(ctx, mem_ctx, &lookup); @@ -95,7 +95,7 @@ bool torture_lookup_host(struct torture_context *torture) } } - lookup.in.methods = NULL; + lookup.in.resolve_ctx = NULL; lookup.out.address = NULL; status = libnet_LookupHost(ctx, mem_ctx, &lookup); diff --git a/source4/torture/libnet/libnet_user.c b/source4/torture/libnet/libnet_user.c index 8671e438b7..ae87e6da87 100644 --- a/source4/torture/libnet/libnet_user.c +++ b/source4/torture/libnet/libnet_user.c @@ -691,6 +691,8 @@ bool torture_userlist(struct torture_context *torture) req.in.resume_index = req.out.resume_index; status = libnet_UserList(ctx, mem_ctx, &req); + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break; for (i = 0; i < req.out.count; i++) { printf("\tuser: %s, sid=%s\n", diff --git a/source4/torture/locktest.c b/source4/torture/locktest.c index 82e9b416b3..9758cd2cf6 100644 --- a/source4/torture/locktest.c +++ b/source4/torture/locktest.c @@ -153,6 +153,7 @@ static struct smbcli_state *connect_one(struct loadparm_context *lp_ctx, printf("\\\\%s\\%s\n", server, share); status = smbcli_full_connection(NULL, &c, server, + lp_smb_ports(lp_ctx), share, NULL, servers[snum], NULL); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/locktest2.c b/source4/torture/locktest2.c index 1dfefc15ed..db323e1391 100644 --- a/source4/torture/locktest2.c +++ b/source4/torture/locktest2.c @@ -136,7 +136,7 @@ static bool try_unlock(struct smbcli_state *c, int fstype, /***************************************************** return a connection to a server *******************************************************/ -static struct smbcli_state *connect_one(char *share) +static struct smbcli_state *connect_one(char *share, const char **ports) { struct smbcli_state *c; char *server_n; @@ -163,7 +163,7 @@ static struct smbcli_state *connect_one(char *share) slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); nt_status = smbcli_full_connection(NULL, - &c, myname, server_n, 0, share, NULL, + &c, myname, server_n, ports, share, NULL, username, lp_workgroup(), password, NULL); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0, ("smbcli_full_connection failed with error %s\n", nt_errstr(nt_status))); @@ -179,6 +179,7 @@ static struct smbcli_state *connect_one(char *share) static void reconnect(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], + const char **ports, char *share1, char *share2) { int server, conn, f, fstype; @@ -197,7 +198,7 @@ static void reconnect(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], smbcli_ulogoff(cli[server][conn]); talloc_free(cli[server][conn]); } - cli[server][conn] = connect_one(share[server]); + cli[server][conn] = connect_one(share[server], ports); if (!cli[server][conn]) { DEBUG(0,("Failed to connect to %s\n", share[server])); exit(1); @@ -343,7 +344,7 @@ static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], we then do random locking ops in tamdem on the 4 fnums from each server and ensure that the results match */ -static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2) +static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2, const char **ports) { struct smbcli_state *cli[NSERVERS][NCONNECTIONS]; char *nfs[NSERVERS]; @@ -372,7 +373,7 @@ static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath recorded[n].needed = true; } - reconnect(cli, nfs, fnum, share1, share2); + reconnect(cli, nfs, fnum, share1, share2, ports); open_files(cli, nfs, fnum); n = retest(cli, nfs, fnum, numops); @@ -383,7 +384,7 @@ static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath n1 = n; close_files(cli, nfs, fnum); - reconnect(cli, nfs, fnum, share1, share2); + reconnect(cli, nfs, fnum, share1, share2, ports); open_files(cli, nfs, fnum); for (i=0;i<n-1;i++) { @@ -410,7 +411,7 @@ static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath } close_files(cli, nfs, fnum); - reconnect(cli, nfs, fnum, share1, share2); + reconnect(cli, nfs, fnum, share1, share2, ports); open_files(cli, nfs, fnum); showall = true; n1 = retest(cli, nfs, fnum, n); @@ -538,7 +539,7 @@ static void usage(void) srandom(seed); locking_init(1); - test_locks(share1, share2, nfspath1, nfspath2); + test_locks(share1, share2, nfspath1, nfspath2, lp_smb_ports(lp_ctx)); return(0); } diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c index dab8193753..3eb815fe28 100644 --- a/source4/torture/masktest.c +++ b/source4/torture/masktest.c @@ -69,7 +69,7 @@ static char *reg_test(struct smbcli_state *cli, char *pattern, char *long_name, /***************************************************** return a connection to a server *******************************************************/ -static struct smbcli_state *connect_one(char *share) +static struct smbcli_state *connect_one(char *share, const char **ports) { struct smbcli_state *c; fstring server; @@ -85,6 +85,7 @@ static struct smbcli_state *connect_one(char *share) status = smbcli_full_connection(NULL, &c, server, + ports, share, NULL, credentials, NULL); @@ -287,8 +288,6 @@ static void usage(void) setup_logging("masktest", DEBUG_STDOUT); - lp_set_cmdline(global_loadparm, "log level", "0"); - if (argc < 2 || argv[1][0] == '-') { usage(); exit(1); @@ -311,8 +310,6 @@ static void usage(void) seed = time(NULL); - reload_charcnv(); - while ((opt = getopt(argc, argv, "n:d:U:s:hm:f:aoW:M:vEl:")) != EOF) { switch (opt) { case 'n': @@ -365,7 +362,7 @@ static void usage(void) argc -= optind; argv += optind; - cli = connect_one(share); + cli = connect_one(share, lp_smb_ports(lp_ctx)); if (!cli) { DEBUG(0,("Failed to connect to %s\n", share)); exit(1); diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index bc3aa5dd57..0315989d66 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -77,6 +77,8 @@ static bool nbt_test_netlogon(struct torture_context *tctx) const char *address; struct nbt_name name; + + struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -84,10 +86,11 @@ static bool nbt_test_netlogon(struct torture_context *tctx) /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, - resolve_name(&name, tctx, &address, event_context_find(tctx), lp_name_resolve_order(tctx->lp_ctx)), + resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)), talloc_asprintf(tctx, "Failed to resolve %s", name.name)); - myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address)); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, @@ -156,6 +159,8 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) const char *address; struct nbt_name name; + + struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -163,10 +168,11 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, - resolve_name(&name, tctx, &address, event_context_find(tctx), lp_name_resolve_order(tctx->lp_ctx)), + resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)), talloc_asprintf(tctx, "Failed to resolve %s", name.name)); - myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address)); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, lp_dgram_port(tctx->lp_ctx)); @@ -265,6 +271,8 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) struct socket_address *socket_address; const char *address; struct nbt_name name; + + struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -272,10 +280,11 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, - resolve_name(&name, tctx, &address, event_context_find(tctx), lp_name_resolve_order(tctx->lp_ctx)), + resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, event_context_find(tctx)), talloc_asprintf(tctx, "Failed to resolve %s", name.name)); - myaddress = talloc_strdup(dgmsock, iface_best_ip(tctx->lp_ctx, address)); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, lp_dgram_port(tctx->lp_ctx)); diff --git a/source4/torture/nbt/nbt.c b/source4/torture/nbt/nbt.c index 7cf2a48c4e..6cb9507398 100644 --- a/source4/torture/nbt/nbt.c +++ b/source4/torture/nbt/nbt.c @@ -34,7 +34,7 @@ bool torture_nbt_get_name(struct torture_context *tctx, /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, - resolve_name(name, tctx, address, NULL, lp_name_resolve_order(tctx->lp_ctx)), + resolve_name(lp_resolve_context(tctx->lp_ctx), name, tctx, address, NULL), talloc_asprintf(tctx, "Failed to resolve %s", name->name)); diff --git a/source4/torture/nbt/register.c b/source4/torture/nbt/register.c index cc3a55a787..508c6b4840 100644 --- a/source4/torture/nbt/register.c +++ b/source4/torture/nbt/register.c @@ -26,6 +26,7 @@ #include "lib/socket/netif.h" #include "torture/torture.h" #include "torture/nbt/proto.h" +#include "param/param.h" #define CHECK_VALUE(tctx, v, correct) \ torture_assert_int_equal(tctx, v, correct, "Incorrect value") @@ -48,11 +49,14 @@ static bool nbt_register_own(struct torture_context *tctx) struct nbt_name name; const char *address; const char *myaddress; + struct interface *ifaces; if (!torture_nbt_get_name(tctx, &name, &address)) return false; - myaddress = iface_best_ip(tctx->lp_ctx, address); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + + myaddress = iface_best_ip(ifaces, address); socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name, myaddress, 0); @@ -66,6 +70,7 @@ static bool nbt_register_own(struct torture_context *tctx) io.in.name = name; io.in.dest_addr = address; + io.in.dest_port = lp_nbt_port(tctx->lp_ctx); io.in.address = myaddress; io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE; io.in.register_demand = false; @@ -113,11 +118,14 @@ static bool nbt_refresh_own(struct torture_context *tctx) struct socket_address *socket_address; struct nbt_name name; const char *address; + struct interface *ifaces; if (!torture_nbt_get_name(tctx, &name, &address)) return false; - myaddress = iface_best_ip(tctx->lp_ctx, address); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + + myaddress = iface_best_ip(ifaces, address); socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name, myaddress, 0); @@ -132,6 +140,7 @@ static bool nbt_refresh_own(struct torture_context *tctx) io.in.name = name; io.in.dest_addr = address; + io.in.dest_port = lp_nbt_port(tctx->lp_ctx); io.in.address = myaddress; io.in.nb_flags = NBT_NODE_B | NBT_NM_ACTIVE; io.in.broadcast = false; diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c index 2ba7f221c9..cf115fcd75 100644 --- a/source4/torture/nbt/wins.c +++ b/source4/torture/nbt/wins.c @@ -54,8 +54,13 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address struct nbt_name_release release; NTSTATUS status; struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, NULL); - const char *myaddress = talloc_strdup(tctx, iface_best_ip(tctx->lp_ctx, address)); + const char *myaddress; struct socket_address *socket_address; + struct interface *ifaces; + + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + + myaddress = talloc_strdup(tctx, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(tctx, nbtsock->sock->backend_name, @@ -75,6 +80,7 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address torture_comment(tctx, "release the name\n"); release.in.name = *name; + release.in.dest_port = lp_nbt_port(tctx->lp_ctx); release.in.dest_addr = address; release.in.address = myaddress; release.in.nb_flags = nb_flags; @@ -88,6 +94,7 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address torture_comment(tctx, "register the name\n"); io.in.name = *name; + io.in.wins_port = lp_nbt_port(tctx->lp_ctx); io.in.wins_servers = str_list_make(tctx, address, NULL); io.in.addresses = str_list_make(tctx, myaddress, NULL); io.in.nb_flags = nb_flags; @@ -160,6 +167,7 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address torture_comment(tctx, "refresh the name\n"); refresh.in.name = *name; + refresh.in.wins_port = lp_nbt_port(tctx->lp_ctx); refresh.in.wins_servers = str_list_make(tctx, address, NULL); refresh.in.addresses = str_list_make(tctx, myaddress, NULL); refresh.in.nb_flags = nb_flags; diff --git a/source4/torture/nbt/winsbench.c b/source4/torture/nbt/winsbench.c index 82223d9dd7..1488c17757 100644 --- a/source4/torture/nbt/winsbench.c +++ b/source4/torture/nbt/winsbench.c @@ -87,6 +87,7 @@ static void generate_register(struct nbt_name_socket *nbtsock, struct wins_state io.in.name = generate_name(tmp_ctx, idx); io.in.dest_addr = state->wins_server; + io.in.dest_port = state->wins_port; io.in.address = state->my_ip; io.in.nb_flags = NBT_NODE_H; io.in.register_demand = false; @@ -138,6 +139,7 @@ static void generate_release(struct nbt_name_socket *nbtsock, struct wins_state istate->state = state; io.in.name = generate_name(tmp_ctx, idx); + io.in.dest_port = state->wins_port; io.in.dest_addr = state->wins_server; io.in.address = state->my_ip; io.in.nb_flags = NBT_NODE_H; @@ -233,6 +235,7 @@ static bool bench_wins(struct torture_context *tctx) struct socket_address *my_ip; struct nbt_name name; const char *address; + struct interface *ifaces; if (!torture_nbt_get_name(tctx, &name, &address)) return false; @@ -243,7 +246,8 @@ static bool bench_wins(struct torture_context *tctx) state->registered = talloc_zero_array(state, bool, state->num_names); state->wins_server = address; state->wins_port = lp_nbt_port(tctx->lp_ctx); - state->my_ip = talloc_strdup(tctx, iface_best_ip(tctx->lp_ctx, address)); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + state->my_ip = talloc_strdup(tctx, iface_best_ip(ifaces, address)); state->ttl = timelimit; my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name, diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c index b427843b80..d96ed3e931 100644 --- a/source4/torture/nbt/winsreplication.c +++ b/source4/torture/nbt/winsreplication.c @@ -107,10 +107,10 @@ static bool test_assoc_ctx1(struct torture_context *tctx) wrepl_socket2 = wrepl_socket_init(tctx, NULL); torture_comment(tctx, "Setup 2 wrepl connections\n"); - status = wrepl_connect(wrepl_socket1, NULL, address); + status = wrepl_connect(wrepl_socket1, lp_resolve_context(tctx->lp_ctx), NULL, address); CHECK_STATUS(tctx, status, NT_STATUS_OK); - status = wrepl_connect(wrepl_socket2, NULL, address); + status = wrepl_connect(wrepl_socket2, lp_resolve_context(tctx->lp_ctx), NULL, address); CHECK_STATUS(tctx, status, NT_STATUS_OK); torture_comment(tctx, "Send a start association request (conn1)\n"); @@ -189,7 +189,7 @@ static bool test_assoc_ctx2(struct torture_context *tctx) wrepl_socket = wrepl_socket_init(tctx, NULL); torture_comment(tctx, "Setup wrepl connections\n"); - status = wrepl_connect(wrepl_socket, NULL, address); + status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), NULL, address); CHECK_STATUS(tctx, status, NT_STATUS_OK); torture_comment(tctx, "Send 1st start association request\n"); @@ -258,7 +258,7 @@ static bool test_wins_replication(struct torture_context *tctx) wrepl_socket = wrepl_socket_init(tctx, NULL); torture_comment(tctx, "Setup wrepl connections\n"); - status = wrepl_connect(wrepl_socket, NULL, address); + status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), NULL, address); CHECK_STATUS(tctx, status, NT_STATUS_OK); torture_comment(tctx, "Send a start association request\n"); @@ -547,6 +547,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( struct socket_address *nbt_srv_addr; NTSTATUS status; uint32_t i; + struct interface *ifaces; ctx = talloc_zero(tctx, struct test_wrepl_conflict_conn); if (!ctx) return NULL; @@ -556,7 +557,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( if (!ctx->pull) return NULL; torture_comment(tctx, "Setup wrepl conflict pull connection\n"); - status = wrepl_connect(ctx->pull, NULL, ctx->address); + status = wrepl_connect(ctx->pull, lp_resolve_context(tctx->lp_ctx), NULL, ctx->address); if (!NT_STATUS_IS_OK(status)) return NULL; status = wrepl_associate(ctx->pull, &associate); @@ -612,12 +613,14 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( ctx->nbtsock = nbt_name_socket_init(ctx, NULL); if (!ctx->nbtsock) return NULL; - ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(tctx->lp_ctx, address), 0); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + + ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(ifaces, address), 0); if (!ctx->myaddr) return NULL; - for (i = 0; i < iface_count(tctx->lp_ctx); i++) { - if (strcmp(ctx->myaddr->addr, iface_n_ip(tctx->lp_ctx, i)) == 0) continue; - ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(tctx->lp_ctx, i), 0); + for (i = 0; i < iface_count(ifaces); i++) { + if (strcmp(ctx->myaddr->addr, iface_n_ip(ifaces, i)) == 0) continue; + ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(ifaces, i), 0); if (!ctx->myaddr2) return NULL; break; } @@ -674,12 +677,12 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx( ctx->addresses_best[0].owner = ctx->b.address; ctx->addresses_best[0].ip = ctx->myaddr->addr; - ctx->addresses_all_num = iface_count(tctx->lp_ctx); + ctx->addresses_all_num = iface_count(ifaces); ctx->addresses_all = talloc_array(ctx, struct wrepl_ip, ctx->addresses_all_num); if (!ctx->addresses_all) return NULL; for (i=0; i < ctx->addresses_all_num; i++) { ctx->addresses_all[i].owner = ctx->b.address; - ctx->addresses_all[i].ip = talloc_strdup(ctx->addresses_all, iface_n_ip(tctx->lp_ctx, i)); + ctx->addresses_all[i].ip = talloc_strdup(ctx->addresses_all, iface_n_ip(ifaces, i)); if (!ctx->addresses_all[i].ip) return NULL; } @@ -721,7 +724,7 @@ static bool test_wrepl_update_one(struct torture_context *tctx, wrepl_socket = wrepl_socket_init(ctx, NULL); - status = wrepl_connect(wrepl_socket, NULL, ctx->address); + status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), NULL, ctx->address); CHECK_STATUS(tctx, status, NT_STATUS_OK); status = wrepl_associate(wrepl_socket, &associate); @@ -6530,6 +6533,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx */ name_register->in.name = records[i].name; name_register->in.dest_addr = ctx->address; + name_register->in.dest_port = lp_nbt_port(tctx->lp_ctx); name_register->in.address = records[i].wins.ips[0].ip; name_register->in.nb_flags = records[i].wins.nb_flags; name_register->in.register_demand= false; @@ -6558,6 +6562,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx /* release the record */ release->in.name = records[i].name; + release->in.dest_port = lp_nbt_port(tctx->lp_ctx); release->in.dest_addr = ctx->address; release->in.address = records[i].wins.ips[0].ip; release->in.nb_flags = records[i].wins.nb_flags; @@ -6612,6 +6617,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx } else { release->in.name = records[i].name; release->in.dest_addr = ctx->address; + release->in.dest_port = lp_nbt_port(tctx->lp_ctx); release->in.address = records[i].wins.ips[0].ip; release->in.nb_flags = records[i].wins.nb_flags; release->in.broadcast = false; @@ -9218,6 +9224,7 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx, name_register->in.name = records[i].name; name_register->in.dest_addr = ctx->address; + name_register->in.dest_port = lp_nbt_port(tctx->lp_ctx); name_register->in.address = records[i].wins.ips[j].ip; name_register->in.nb_flags = records[i].wins.nb_flags; name_register->in.register_demand= false; @@ -9363,6 +9370,7 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx, release->in.name = records[i].name; release->in.dest_addr = ctx->address; + release->in.dest_port = lp_nbt_port(tctx->lp_ctx); release->in.address = records[i].wins.ips[j].ip; release->in.nb_flags = records[i].wins.nb_flags; release->in.broadcast = false; diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c index e1e2918cba..55b00d1fb8 100644 --- a/source4/torture/ndr/ndr.c +++ b/source4/torture/ndr/ndr.c @@ -23,6 +23,7 @@ #include "torture/ndr/proto.h" #include "torture/ui.h" #include "util/dlinklist.h" +#include "param/param.h" struct ndr_pull_test_data { DATA_BLOB data; @@ -38,7 +39,7 @@ static bool wrap_ndr_pull_test(struct torture_context *tctx, bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn; const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data; void *ds = talloc_zero_size(tctx, data->struct_size); - struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx); + struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx, lp_iconv_convenience(tctx->lp_ctx)); ndr->flags |= LIBNDR_FLAG_REF_ALLOC; @@ -97,7 +98,7 @@ static bool test_check_string_terminator(struct torture_context *tctx) /* Simple test */ blob = strhex_to_data_blob("0000"); - ndr = ndr_pull_init_blob(&blob, mem_ctx); + ndr = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ndr_success(tctx, ndr_check_string_terminator(ndr, 1, 2), "simple check_string_terminator test failed"); @@ -115,7 +116,7 @@ static bool test_check_string_terminator(struct torture_context *tctx) talloc_free(ndr); blob = strhex_to_data_blob("11220000"); - ndr = ndr_pull_init_blob(&blob, mem_ctx); + ndr = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx)); torture_assert_ndr_success(tctx, ndr_check_string_terminator(ndr, 4, 1), diff --git a/source4/torture/rap/rap.c b/source4/torture/rap/rap.c index 7ef2555800..9deb53086a 100644 --- a/source4/torture/rap/rap.c +++ b/source4/torture/rap/rap.c @@ -26,6 +26,7 @@ #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" #include "librpc/ndr/libndr.h" +#include "param/param.h" #define RAP_GOTO(call) do { \ NTSTATUS _status; \ @@ -86,10 +87,10 @@ static struct rap_call *new_rap_cli_call(TALLOC_CTX *mem_ctx, uint16_t callno) call->paramdesc = NULL; call->datadesc = NULL; - call->ndr_push_param = ndr_push_init_ctx(mem_ctx); + call->ndr_push_param = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); call->ndr_push_param->flags = RAPNDR_FLAGS; - call->ndr_push_data = ndr_push_init_ctx(mem_ctx); + call->ndr_push_data = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(global_loadparm)); call->ndr_push_data->flags = RAPNDR_FLAGS; return call; @@ -182,7 +183,7 @@ static NTSTATUS rap_pull_string(TALLOC_CTX *mem_ctx, struct ndr_pull *ndr, return NT_STATUS_INVALID_PARAMETER; *dest = talloc_zero_array(mem_ctx, char, len+1); - pull_string(global_smb_iconv_convenience, *dest, p, len+1, len, STR_ASCII); + pull_string(ndr->iconv_convenience, *dest, p, len+1, len, STR_ASCII); return NT_STATUS_OK; } @@ -194,7 +195,7 @@ static NTSTATUS rap_cli_do_call(struct smbcli_tree *tree, struct rap_call *call) struct ndr_push *params; struct smb_trans2 trans; - params = ndr_push_init_ctx(call); + params = ndr_push_init_ctx(call, lp_iconv_convenience(global_loadparm)); if (params == NULL) return NT_STATUS_NO_MEMORY; @@ -228,10 +229,12 @@ static NTSTATUS rap_cli_do_call(struct smbcli_tree *tree, struct rap_call *call) if (!NT_STATUS_IS_OK(result)) return result; - call->ndr_pull_param = ndr_pull_init_blob(&trans.out.params, call); + call->ndr_pull_param = ndr_pull_init_blob(&trans.out.params, call, + lp_iconv_convenience(global_loadparm)); call->ndr_pull_param->flags = RAPNDR_FLAGS; - call->ndr_pull_data = ndr_pull_init_blob(&trans.out.data, call); + call->ndr_pull_data = ndr_pull_init_blob(&trans.out.data, call, + lp_iconv_convenience(global_loadparm)); call->ndr_pull_data->flags = RAPNDR_FLAGS; return result; diff --git a/source4/torture/raw/composite.c b/source4/torture/raw/composite.c index 5a663fb565..0367110ddc 100644 --- a/source4/torture/raw/composite.c +++ b/source4/torture/raw/composite.c @@ -153,7 +153,7 @@ static bool test_fetchfile(struct smbcli_state *cli, struct torture_context *tct } io2.in.dest_host = torture_setting_string(tctx, "host", NULL); - io2.in.port = 0; + io2.in.ports = lp_smb_ports(tctx->lp_ctx); io2.in.called_name = torture_setting_string(tctx, "host", NULL); io2.in.service = torture_setting_string(tctx, "share", NULL); io2.in.service_type = "A:"; @@ -341,7 +341,7 @@ static bool test_fsinfo(struct smbcli_state *cli, struct torture_context *tctx) bool ret = true; io1.in.dest_host = torture_setting_string(tctx, "host", NULL); - io1.in.port = 0; + io1.in.dest_ports = lp_smb_ports(tctx->lp_ctx); io1.in.called_name = torture_setting_string(tctx, "host", NULL); io1.in.service = torture_setting_string(tctx, "share", NULL); io1.in.service_type = "A:"; diff --git a/source4/torture/raw/lockbench.c b/source4/torture/raw/lockbench.c index 113634f264..744aab66b1 100644 --- a/source4/torture/raw/lockbench.c +++ b/source4/torture/raw/lockbench.c @@ -185,7 +185,7 @@ static void reopen_connection(struct event_context *ev, struct timed_event *te, } io->in.dest_host = state->dest_host; - io->in.port = state->dest_port; + io->in.dest_ports = state->dest_port; io->in.called_name = state->called_name; io->in.service = share; io->in.service_type = state->service_type; diff --git a/source4/torture/raw/openbench.c b/source4/torture/raw/openbench.c index 8f9803fa4d..ceb52cdfcf 100644 --- a/source4/torture/raw/openbench.c +++ b/source4/torture/raw/openbench.c @@ -123,7 +123,7 @@ static void reopen_connection(struct event_context *ev, struct timed_event *te, } io->in.dest_host = state->dest_host; - io->in.port = state->dest_port; + io->in.dest_ports = state->dest_port; io->in.called_name = state->called_name; io->in.service = share; io->in.service_type = state->service_type; diff --git a/source4/torture/rpc/eventlog.c b/source4/torture/rpc/eventlog.c index 64b012fba6..047146edaf 100644 --- a/source4/torture/rpc/eventlog.c +++ b/source4/torture/rpc/eventlog.c @@ -25,6 +25,7 @@ #include "librpc/gen_ndr/ndr_eventlog_c.h" #include "librpc/gen_ndr/ndr_lsa.h" #include "torture/rpc/rpc.h" +#include "param/param.h" static void init_lsa_String(struct lsa_String *name, const char *s) { @@ -137,7 +138,7 @@ static bool test_ReadEventLog(struct torture_context *tctx, blob.length = *r.out.sent_size; blob.data = talloc_steal(tctx, r.out.data); - ndr = ndr_pull_init_blob(&blob, tctx); + ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx)); ndr_err = ndr_pull_eventlog_Record( ndr, NDR_SCALARS|NDR_BUFFERS, &rec); diff --git a/source4/torture/rpc/join.c b/source4/torture/rpc/join.c index d973d2d083..8ab6ae03ea 100644 --- a/source4/torture/rpc/join.c +++ b/source4/torture/rpc/join.c @@ -5,6 +5,8 @@ #include "auth/credentials/credentials.h" #include "torture/rpc/rpc.h" +#include "param/param.h" + #define TORTURE_NETBIOS_NAME "smbtorturejoin" @@ -29,6 +31,7 @@ bool torture_rpc_join(struct torture_context *torture) } status = smbcli_full_connection(tj, &cli, host, + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, machine_account, NULL); @@ -53,6 +56,7 @@ bool torture_rpc_join(struct torture_context *torture) } status = smbcli_full_connection(tj, &cli, host, + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, machine_account, NULL); diff --git a/source4/torture/rpc/rpc.c b/source4/torture/rpc/rpc.c index 198c888f17..6e38d0465a 100644 --- a/source4/torture/rpc/rpc.c +++ b/source4/torture/rpc/rpc.c @@ -390,6 +390,7 @@ NTSTATUS torture_rpc_init(void) torture_suite_add_suite(suite, torture_rpc_winreg(suite)); torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss); torture_suite_add_suite(suite, torture_rpc_spoolss_notify(suite)); + torture_suite_add_suite(suite, torture_rpc_spoolss_win(suite)); torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr); torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users); torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords); diff --git a/source4/torture/rpc/samba3rpc.c b/source4/torture/rpc/samba3rpc.c index 96ed03fc6f..a63772e964 100644 --- a/source4/torture/rpc/samba3rpc.c +++ b/source4/torture/rpc/samba3rpc.c @@ -80,6 +80,7 @@ bool torture_bind_authcontext(struct torture_context *torture) status = smbcli_full_connection(mem_ctx, &cli, torture_setting_string(torture, "host", NULL), + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, cmdline_credentials, NULL); if (!NT_STATUS_IS_OK(status)) { @@ -287,6 +288,7 @@ bool torture_bind_samba3(struct torture_context *torture) status = smbcli_full_connection(mem_ctx, &cli, torture_setting_string(torture, "host", NULL), + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, cmdline_credentials, NULL); if (!NT_STATUS_IS_OK(status)) { @@ -1144,6 +1146,7 @@ bool torture_netlogon_samba3(struct torture_context *torture) status = smbcli_full_connection(mem_ctx, &cli, torture_setting_string(torture, "host", NULL), + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, anon_creds, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("smbcli_full_connection failed: %s\n", @@ -1225,6 +1228,7 @@ static bool test_join3(struct torture_context *tctx, status = smbcli_full_connection(tctx, &cli, torture_setting_string(tctx, "host", NULL), + lp_smb_ports(tctx->lp_ctx), "IPC$", NULL, smb_creds, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("smbcli_full_connection failed: %s\n", @@ -1588,6 +1592,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture) status = smbcli_full_connection( mem_ctx, &cli, torture_setting_string(torture, "host", NULL), + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, cmdline_credentials, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("(%s) smbcli_full_connection failed: %s\n", @@ -1612,6 +1617,7 @@ bool torture_samba3_rpc_getusername(struct torture_context *torture) status = smbcli_full_connection( mem_ctx, &cli, torture_setting_string(torture, "host", NULL), + lp_smb_ports(torture->lp_ctx), "IPC$", NULL, anon_creds, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("(%s) anon smbcli_full_connection failed: %s\n", @@ -2308,7 +2314,7 @@ static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree, memcpy(servername, r.out.info.info0.name, 16); servername[16] = '\0'; - if (pull_ascii_talloc(mem_ctx, global_smb_iconv_convenience, + if (pull_ascii_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), name, servername) < 0) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c index b60cef7d53..7fd5199908 100644 --- a/source4/torture/rpc/samlogon.c +++ b/source4/torture/rpc/samlogon.c @@ -1158,7 +1158,7 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea ZERO_STRUCT(user_session_key); if ((push_ucs2_talloc(samlogon_state->mem_ctx, - global_smb_iconv_convenience, + lp_iconv_convenience(global_loadparm), &unicodepw, samlogon_state->password)) == -1) { DEBUG(0, ("push_ucs2_allocate failed!\n")); exit(1); @@ -1169,7 +1169,7 @@ static bool test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_brea password = strupper_talloc(samlogon_state->mem_ctx, samlogon_state->password); if ((convert_string_talloc(samlogon_state->mem_ctx, - global_smb_iconv_convenience, + lp_iconv_convenience(global_loadparm), CH_UNIX, CH_DOS, password, strlen(password)+1, (void**)&dospw)) == -1) { diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c index f8d5b7030c..9d6c73891b 100644 --- a/source4/torture/rpc/samr.c +++ b/source4/torture/rpc/samr.c @@ -824,6 +824,7 @@ static bool test_SetAliasInfo(struct dcerpc_pipe *p, struct torture_context *tct case ALIASINFONAME: init_lsa_String(&r.in.info->name,TEST_ALIASNAME); break; case ALIASINFODESCRIPTION: init_lsa_String(&r.in.info->description, "Test Description, should test I18N as well"); break; + case ALIASINFOALL: printf("ALIASINFOALL ignored\n"); break; } status = dcerpc_samr_SetAliasInfo(p, tctx, &r); diff --git a/source4/torture/rpc/schannel.c b/source4/torture/rpc/schannel.c index 6b0cbbf525..cb9b8be2c9 100644 --- a/source4/torture/rpc/schannel.c +++ b/source4/torture/rpc/schannel.c @@ -244,7 +244,8 @@ static bool test_schannel(struct torture_context *tctx, struct creds_CredentialState *creds; struct cli_credentials *credentials; - join_ctx = torture_join_domain(tctx, talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, i), + join_ctx = torture_join_domain(tctx, + talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, i), acct_flags, &credentials); torture_assert(tctx, join_ctx != NULL, "Failed to join domain"); diff --git a/source4/torture/rpc/spoolss_notify.c b/source4/torture/rpc/spoolss_notify.c index bdbdc6b0c6..0065101447 100644 --- a/source4/torture/rpc/spoolss_notify.c +++ b/source4/torture/rpc/spoolss_notify.c @@ -193,6 +193,9 @@ static bool test_RFFPCNEx(struct torture_context *tctx, struct policy_handle handle; const char *address; + struct interface *ifaces; + + ntvfs_init(tctx->lp_ctx); ZERO_STRUCT(q); @@ -226,7 +229,8 @@ static bool test_RFFPCNEx(struct torture_context *tctx, lp_set_cmdline(tctx->lp_ctx, "dcerpc endpoint servers", "spoolss"); - address = iface_n_ip(tctx->lp_ctx, 0); + load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); + address = iface_n_ip(ifaces, 0); torture_comment(tctx, "Listening for callbacks on %s\n", address); status = smbsrv_add_socket(p->conn->event_ctx, tctx->lp_ctx, &single_ops, address); torture_assert_ntstatus_ok(tctx, status, "starting smb server"); @@ -289,7 +293,6 @@ struct torture_suite *torture_rpc_spoolss_notify(TALLOC_CTX *mem_ctx) struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite, "notify", &ndr_table_spoolss); - ntvfs_init(global_loadparm); torture_rpc_tcase_add_test(tcase, "testRFFPCNEx", test_RFFPCNEx); return suite; diff --git a/source4/torture/rpc/spoolss_win.c b/source4/torture/rpc/spoolss_win.c new file mode 100644 index 0000000000..9e2921d406 --- /dev/null +++ b/source4/torture/rpc/spoolss_win.c @@ -0,0 +1,579 @@ +/* + Unix SMB/CIFS implementation. + test suite for spoolss rpc operations as performed by various win versions + + Copyright (C) Kai Blin 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/torture.h" +#include "torture/ui.h" +#include "torture/rpc/rpc.h" +#include "librpc/gen_ndr/ndr_spoolss_c.h" +#include "rpc_server/dcerpc_server.h" +#include "ntvfs/ntvfs.h" +#include "param/param.h" + +struct test_spoolss_win_context { + /* EnumPrinters */ + uint32_t printer_count; + union spoolss_PrinterInfo *printer_info; + union spoolss_PrinterInfo *current_info; + + /* EnumPrinterKeys */ + char *printer_keys; +}; + +/* This is a convenience function for all OpenPrinterEx calls */ +static bool test_OpenPrinterEx(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + const char *printer_name, + uint32_t access_mask) +{ + NTSTATUS status; + struct spoolss_OpenPrinterEx op; + struct spoolss_UserLevel1 ul_1; + + torture_comment(tctx, "Opening printer '%s'\n", printer_name); + + op.in.printername = talloc_strdup(tctx, printer_name); + op.in.datatype = NULL; + op.in.devmode_ctr.devmode = NULL; + op.in.access_mask = access_mask; + op.in.level = 1; + op.in.userlevel.level1 = &ul_1; + op.out.handle = handle; + + ul_1.size = 1234; + ul_1.client = "\\clientname"; + ul_1.user = "username"; + ul_1.build = 1; + ul_1.major = 2; + ul_1.minor = 3; + ul_1.processor = 4567; + + status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &op); + torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed"); + torture_assert_werr_ok(tctx, op.out.result, "OpenPrinterEx failed"); + + return true; +} + +static bool test_OpenPrinterAsAdmin(struct torture_context *tctx, + struct dcerpc_pipe *p, + const char *printername) +{ + NTSTATUS status; + struct spoolss_OpenPrinterEx op; + struct spoolss_ClosePrinter cp; + struct spoolss_UserLevel1 ul_1; + struct policy_handle handle; + + ul_1.size = 1234; + ul_1.client = "\\clientname"; + ul_1.user = "username"; + ul_1.build = 1; + ul_1.major = 2; + ul_1.minor = 3; + ul_1.processor = 4567; + + op.in.printername = talloc_strdup(tctx, printername); + op.in.datatype = NULL; + op.in.devmode_ctr.devmode = NULL; + op.in.access_mask = SERVER_ALL_ACCESS; + op.in.level = 1; + op.in.userlevel.level1 = &ul_1; + op.out.handle = &handle; + + cp.in.handle = &handle; + cp.out.handle = &handle; + + torture_comment(tctx, "Testing OpenPrinterEx(%s) with admin rights\n", + op.in.printername); + + status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &op); + + if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(op.out.result)) { + status = dcerpc_spoolss_ClosePrinter(p, tctx, &cp); + torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed"); + } + + return true; +} + + +static bool test_ClosePrinter(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle); + +/* This replicates the opening sequence of OpenPrinterEx calls XP does */ +static bool test_OpenPrinterSequence(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle) +{ + bool ret; + char *printername = talloc_asprintf(tctx, "\\\\%s", + dcerpc_server_name(p)); + + /* First, see if we can open the printer read_only */ + ret = test_OpenPrinterEx(tctx, p, handle, printername, 0); + torture_assert(tctx, ret == true, "OpenPrinterEx failed."); + + ret = test_ClosePrinter(tctx, p, handle); + torture_assert(tctx, ret, "ClosePrinter failed"); + + /* Now let's see if we have admin rights to it. */ + ret = test_OpenPrinterAsAdmin(tctx, p, printername); + torture_assert(tctx, ret == true, + "OpenPrinterEx as admin failed unexpectedly."); + + ret = test_OpenPrinterEx(tctx, p, handle, printername, SERVER_EXECUTE); + torture_assert(tctx, ret == true, "OpenPrinterEx failed."); + + return true; +} + +static bool test_GetPrinterData(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + const char *value_name, + WERROR expected_werr, + uint32_t expected_value) +{ + NTSTATUS status; + struct spoolss_GetPrinterData gpd; + + torture_comment(tctx, "Testing GetPrinterData(%s).\n", value_name); + gpd.in.handle = handle; + gpd.in.value_name = value_name; + gpd.in.offered = 4; + + status = dcerpc_spoolss_GetPrinterData(p, tctx, &gpd); + torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed."); + torture_assert_werr_equal(tctx, gpd.out.result, expected_werr, + "GetPrinterData did not return expected error value."); + + if (W_ERROR_IS_OK(expected_werr)) { + torture_assert_int_equal(tctx, gpd.out.data.value, + expected_value, + "GetPrinterData did not return expected value."); + } + return true; +} + +static bool test_EnumPrinters(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct test_spoolss_win_context *ctx, + uint32_t initial_blob_size) +{ + NTSTATUS status; + struct spoolss_EnumPrinters ep; + DATA_BLOB blob = data_blob_talloc_zero(ctx, initial_blob_size); + + ep.in.flags = PRINTER_ENUM_NAME; + ep.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); + ep.in.level = 2; + ep.in.buffer = &blob; + ep.in.offered = initial_blob_size; + + status = dcerpc_spoolss_EnumPrinters(p, ctx, &ep); + torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed."); + + if (W_ERROR_EQUAL(ep.out.result, WERR_INSUFFICIENT_BUFFER)) { + blob = data_blob_talloc_zero(ctx, ep.out.needed); + ep.in.buffer = &blob; + ep.in.offered = ep.out.needed; + status = dcerpc_spoolss_EnumPrinters(p, ctx, &ep); + torture_assert_ntstatus_ok(tctx, status,"EnumPrinters failed."); + } + + torture_assert_werr_ok(tctx, ep.out.result, "EnumPrinters failed."); + + ctx->printer_count = ep.out.count; + ctx->printer_info = ep.out.info; + + torture_comment(tctx, "Found %d printer(s).\n", ctx->printer_count); + + return true; +} + +static bool test_GetPrinter(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + struct test_spoolss_win_context *ctx, + uint32_t level, + uint32_t initial_blob_size) +{ + NTSTATUS status; + struct spoolss_GetPrinter gp; + DATA_BLOB blob = data_blob_talloc_zero(ctx, initial_blob_size); + + torture_comment(tctx, "Test GetPrinter level %d\n", level); + + gp.in.handle = handle; + gp.in.level = level; + gp.in.buffer = (initial_blob_size == 0)?NULL:&blob; + gp.in.offered = initial_blob_size; + + status = dcerpc_spoolss_GetPrinter(p, tctx, &gp); + torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed"); + + if (W_ERROR_EQUAL(gp.out.result, WERR_INSUFFICIENT_BUFFER)) { + blob = data_blob_talloc_zero(ctx, gp.out.needed); + gp.in.buffer = &blob; + gp.in.offered = gp.out.needed; + status = dcerpc_spoolss_GetPrinter(p, tctx, &gp); + torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed"); + } + + torture_assert_werr_ok(tctx, gp.out.result, "GetPrinter failed"); + + ctx->current_info = gp.out.info; + return true; +} + +static bool test_EnumJobs(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle) +{ + NTSTATUS status; + struct spoolss_EnumJobs ej; + DATA_BLOB blob = data_blob_talloc_zero(tctx, 1024); + + torture_comment(tctx, "Test EnumJobs\n"); + + ej.in.handle = handle; + ej.in.level = 2; + ej.in.buffer = &blob; + ej.in.offered = 1024; + + status = dcerpc_spoolss_EnumJobs(p, tctx, &ej); + torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed"); + torture_assert_werr_ok(tctx, ej.out.result, "EnumJobs failed"); + + return true; +} + +static bool test_GetPrinterDriver2(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle) +{ + NTSTATUS status; + struct spoolss_GetPrinterDriver2 gpd2; + DATA_BLOB blob = data_blob_talloc_zero(tctx, 87424); + + torture_comment(tctx, "Testing GetPrinterDriver2\n"); + + gpd2.in.handle = handle; + gpd2.in.architecture = "Windows NT x86"; + gpd2.in.level = 101; + gpd2.in.buffer = &blob; + gpd2.in.offered = 87424; + gpd2.in.client_major_version = 3; + gpd2.in.client_minor_version = 0; + + status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &gpd2); + torture_assert_ntstatus_ok(tctx, status, "GetPrinterDriver2 failed"); + torture_assert_werr_ok(tctx, gpd2.out.result, + "GetPrinterDriver2 failed."); + + return true; +} + +static bool test_EnumForms(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + uint32_t initial_blob_size) +{ + NTSTATUS status; + struct spoolss_EnumForms ef; + DATA_BLOB blob = data_blob_talloc_zero(tctx, initial_blob_size); + + torture_comment(tctx, "Testing EnumForms\n"); + + ef.in.handle = handle; + ef.in.level = 1; + ef.in.buffer = (initial_blob_size == 0)?NULL:&blob; + ef.in.offered = initial_blob_size; + + status = dcerpc_spoolss_EnumForms(p, tctx, &ef); + torture_assert_ntstatus_ok(tctx, status, "EnumForms failed"); + + if (W_ERROR_EQUAL(ef.out.result, WERR_INSUFFICIENT_BUFFER)) { + blob = data_blob_talloc_zero(tctx, ef.out.needed); + ef.in.buffer = &blob; + ef.in.offered = ef.out.needed; + status = dcerpc_spoolss_EnumForms(p, tctx, &ef); + torture_assert_ntstatus_ok(tctx, status, "EnumForms failed"); + } + + torture_assert_werr_ok(tctx, ef.out.result, "EnumForms failed"); + + return true; +} + +static bool test_EnumPrinterKey(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + const char* key, + struct test_spoolss_win_context *ctx) +{ + NTSTATUS status; + struct spoolss_EnumPrinterKey epk; + uint32_t needed = 0; + + torture_comment(tctx, "Testing EnumPrinterKey(%s)\n", key); + + epk.in.handle = handle; + epk.in.key_name = talloc_strdup(tctx, key); + epk.in.needed = needed; + + status = dcerpc_spoolss_EnumPrinterKey(p, tctx, &epk); + torture_assert_ntstatus_ok(tctx, status, "EnumPrinterKey failed"); + + + if (W_ERROR_EQUAL(epk.out.result, WERR_MORE_DATA)) { + epk.in.needed = epk.out.needed; + status = dcerpc_spoolss_EnumPrinterKey(p, tctx, &epk); + torture_assert_ntstatus_ok(tctx, status, + "EnumPrinterKey failed"); + } + + torture_assert_werr_ok(tctx, epk.out.result, "EnumPrinterKey failed"); + + convert_string_talloc(ctx, lp_iconv_convenience(tctx->lp_ctx), CH_UTF16, + CH_UNIX, epk.out.key_buffer, epk.out.needed, + (void**)&ctx->printer_keys); + + return true; +} + +static bool test_EnumPrinterDataEx(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle, + const char *key, + uint32_t initial_blob_size, + WERROR expected_error) +{ + NTSTATUS status; + struct spoolss_EnumPrinterDataEx epde; + + torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key); + + epde.in.handle = handle; + epde.in.key_name = talloc_strdup(tctx, key); + epde.in.offered = 0; + + status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &epde); + torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed."); + if (W_ERROR_EQUAL(epde.out.result, WERR_MORE_DATA)) { + epde.in.offered = epde.out.needed; + status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &epde); + torture_assert_ntstatus_ok(tctx, status, + "EnumPrinterDataEx failed."); + } + + torture_assert_werr_equal(tctx, epde.out.result, expected_error, + "EnumPrinterDataEx failed."); + + return true; +} + +static bool test_ClosePrinter(struct torture_context *tctx, + struct dcerpc_pipe *p, + struct policy_handle *handle) +{ + NTSTATUS status; + struct spoolss_ClosePrinter cp; + + cp.in.handle = handle; + cp.out.handle = handle; + + status = dcerpc_spoolss_ClosePrinter(p, tctx, &cp); + torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed"); + + return true; +} + +static bool test_WinXP(struct torture_context *tctx, struct dcerpc_pipe *p) +{ + bool ret = true; + struct test_spoolss_win_context *ctx, *tmp_ctx; + struct policy_handle handle01, handle02, handle03, handle04; + /* Sometimes a handle stays unused. In order to make this clear in the + * code, the unused_handle structures are used for that. */ + struct policy_handle unused_handle1, unused_handle2; + char *server_name; + char *key_pointer; + + ntvfs_init(tctx->lp_ctx); + + ctx = talloc_zero(tctx, struct test_spoolss_win_context); + tmp_ctx = talloc_zero(tctx, struct test_spoolss_win_context); + + ret &= test_OpenPrinterSequence(tctx, p, &handle01); + ret &= test_GetPrinterData(tctx, p, &handle01,"UISingleJobStatusString", + WERR_INVALID_PARAM, 0); + torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n"); + + server_name = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p)); + ret &= test_OpenPrinterEx(tctx, p, &unused_handle1, server_name, 0); + + ret &= test_EnumPrinters(tctx, p, ctx, 1024); + + ret &= test_OpenPrinterEx(tctx, p, &handle02, server_name, 0); + ret &= test_GetPrinterData(tctx, p, &handle02, "MajorVersion", WERR_OK, + 3); + ret &= test_ClosePrinter(tctx, p, &handle02); + + /* If no printers were found, skip all tests that need a printer */ + if (ctx->printer_count == 0) { + goto end_testWinXP; + } + + ret &= test_OpenPrinterEx(tctx, p, &handle02, + ctx->printer_info[0].info2.printername, + PRINTER_ACCESS_USE); + ret &= test_GetPrinter(tctx, p, &handle02, ctx, 2, 0); + + torture_assert_str_equal(tctx, ctx->current_info->info2.printername, + ctx->printer_info[0].info2.printername, + "GetPrinter returned unexpected printername"); + /*FIXME: Test more components of the PrinterInfo2 struct */ + + ret &= test_OpenPrinterEx(tctx, p, &handle03, + ctx->printer_info[0].info2.printername, 0); + ret &= test_GetPrinter(tctx, p, &handle03, ctx, 0, 1164); + ret &= test_GetPrinter(tctx, p, &handle03, ctx, 2, 0); + + ret &= test_OpenPrinterEx(tctx, p, &handle04, + ctx->printer_info[0].info2.printername, 0); + ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 0); + ret &= test_ClosePrinter(tctx, p, &handle04); + + ret &= test_OpenPrinterEx(tctx, p, &handle04, + ctx->printer_info[0].info2.printername, 0); + ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 4096); + ret &= test_ClosePrinter(tctx, p, &handle04); + + ret &= test_OpenPrinterAsAdmin(tctx, p, + ctx->printer_info[0].info2.printername); + + ret &= test_OpenPrinterEx(tctx, p, &handle04, + ctx->printer_info[0].info2.printername, PRINTER_READ); + ret &= test_GetPrinterData(tctx, p, &handle04,"UISingleJobStatusString", + WERR_BADFILE, 0); + torture_comment(tctx, "Skip RemoteFindNextPrinterChangeNotifyEx test\n"); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + + ret &= test_EnumJobs(tctx, p, &handle04); + ret &= test_GetPrinter(tctx, p, &handle04, ctx, 2, 4096); + + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + ret &= test_ClosePrinter(tctx, p, &handle04); + + ret &= test_EnumPrinters(tctx, p, ctx, 1556); + ret &= test_GetPrinterDriver2(tctx, p, &handle03); + ret &= test_EnumForms(tctx, p, &handle03, 0); + + ret &= test_EnumPrinterKey(tctx, p, &handle03, "", ctx); + key_pointer = ctx->printer_keys; + while(*key_pointer != '\0') { + char *end_pointer; + char *key_name; + + for(end_pointer = key_pointer; *end_pointer != '\0'; + ++end_pointer) { + /* Do nothing, just move the pointer */ + } + key_name = talloc_strndup(tctx, key_pointer, + end_pointer - key_pointer); + + ret &= test_EnumPrinterKey(tctx, p, &handle03, key_name, + tmp_ctx); + ret &= test_EnumPrinterDataEx(tctx, p, &handle03, key_name, 0, + WERR_OK); + + key_pointer = ++end_pointer; + } + + ret &= test_EnumPrinterDataEx(tctx, p, &handle03, "", 0, + WERR_INVALID_PARAM); + + ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 2, 0); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + + ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 2, 2556); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + + ret &= test_GetPrinter(tctx, p, &handle03, tmp_ctx, 7, 0); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + + ret &= test_ClosePrinter(tctx, p, &handle03); + + ret &= test_OpenPrinterEx(tctx, p, &unused_handle2, + ctx->printer_info[0].info2.printername, 0); + ret &= test_ClosePrinter(tctx, p, &unused_handle2); + + ret &= test_OpenPrinterEx(tctx, p, &handle03, server_name, 0); + ret &= test_GetPrinterData(tctx, p, &handle03, "W3SvcInstalled", + WERR_OK, 0); + ret &= test_ClosePrinter(tctx, p, &handle03); + + ret &= test_ClosePrinter(tctx, p, &unused_handle1); + ret &= test_ClosePrinter(tctx, p, &handle02); + + ret &= test_OpenPrinterEx(tctx, p, &handle02, + ctx->printer_info[0].info2.sharename, 0); + ret &= test_GetPrinter(tctx, p, &handle02, tmp_ctx, 2, 0); + ret &= test_ClosePrinter(tctx, p, &handle02); + +end_testWinXP: + ret &= test_ClosePrinter(tctx, p, &handle01); + + talloc_free(tmp_ctx); + talloc_free(ctx); + return ret; +} + +struct torture_suite *torture_rpc_spoolss_win(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-WIN"); + + struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite, + "win", &ndr_table_spoolss); + + torture_rpc_tcase_add_test(tcase, "testWinXP", test_WinXP); + + return suite; +} + diff --git a/source4/torture/rpc/wkssvc.c b/source4/torture/rpc/wkssvc.c index ddec59a15d..b212a44b33 100644 --- a/source4/torture/rpc/wkssvc.c +++ b/source4/torture/rpc/wkssvc.c @@ -966,7 +966,7 @@ static bool test_NetrMessageBufferSend(struct torture_context *tctx, size_t size; uint8_t *msg; - size = push_ucs2_talloc(tctx, global_smb_iconv_convenience, + size = push_ucs2_talloc(tctx, lp_iconv_convenience(tctx->lp_ctx), (void **)&msg, message); r.in.server_name = dcerpc_server_name(p); diff --git a/source4/torture/smb2/scan.c b/source4/torture/smb2/scan.c index 1ec67492bf..84be11c047 100644 --- a/source4/torture/smb2/scan.c +++ b/source4/torture/smb2/scan.c @@ -26,6 +26,7 @@ #include "lib/events/events.h" #include "torture/torture.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" #include "torture/smb2/proto.h" @@ -201,7 +202,7 @@ bool torture_smb2_scan(struct torture_context *torture) struct smb2_request *req; status = smb2_connect(mem_ctx, host, share, - lp_name_resolve_order(torture->lp_ctx), + lp_resolve_context(torture->lp_ctx), credentials, &tree, event_context_find(mem_ctx)); if (!NT_STATUS_IS_OK(status)) { @@ -218,7 +219,7 @@ bool torture_smb2_scan(struct torture_context *torture) if (!smb2_request_receive(req)) { talloc_free(tree); status = smb2_connect(mem_ctx, host, share, - lp_name_resolve_order(torture->lp_ctx), + lp_resolve_context(torture->lp_ctx), credentials, &tree, event_context_find(mem_ctx)); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/smb2/util.c b/source4/torture/smb2/util.c index 3170b0073d..fe88296a32 100644 --- a/source4/torture/smb2/util.c +++ b/source4/torture/smb2/util.c @@ -27,6 +27,7 @@ #include "system/time.h" #include "librpc/gen_ndr/ndr_security.h" #include "param/param.h" +#include "libcli/resolve/resolve.h" #include "torture/torture.h" #include "torture/smb2/proto.h" @@ -310,7 +311,7 @@ bool torture_smb2_connection(struct torture_context *tctx, struct smb2_tree **tr struct cli_credentials *credentials = cmdline_credentials; status = smb2_connect(tctx, host, share, - lp_name_resolve_order(tctx->lp_ctx), + lp_resolve_context(tctx->lp_ctx), credentials, tree, event_context_find(tctx)); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/smbiconv.c b/source4/torture/smbiconv.c index 1eb09cae45..4eece66bdf 100644 --- a/source4/torture/smbiconv.c +++ b/source4/torture/smbiconv.c @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) } } - cd = smb_iconv_open(to, from, lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true)); + cd = smb_iconv_open_ex(tctx, to, from, lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true)); if((int)cd == -1) { DEBUG(0,("unable to find from or to encoding, exiting...\n")); return 1; diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index b35e623610..371ddc7297 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -50,7 +50,7 @@ static bool run_matching(struct torture_context *torture, for (o = torture_root->children; o; o = o->next) { if (gen_fnmatch(expr, o->name) == 0) { *matched = true; - reload_charcnv(); + reload_charcnv(torture->lp_ctx); ret &= torture_run_suite(torture, o); continue; } @@ -67,7 +67,7 @@ static bool run_matching(struct torture_context *torture, if (gen_fnmatch(expr, name) == 0) { *matched = true; - reload_charcnv(); + reload_charcnv(torture->lp_ctx); torture->active_testname = talloc_strdup(torture, prefix); ret &= torture_run_suite(torture, c); free(name); @@ -83,7 +83,7 @@ static bool run_matching(struct torture_context *torture, asprintf(&name, "%s-%s", prefix, t->name); if (gen_fnmatch(expr, name) == 0) { *matched = true; - reload_charcnv(); + reload_charcnv(torture->lp_ctx); torture->active_testname = talloc_strdup(torture, prefix); ret &= torture_run_tcase(torture, t); talloc_free(torture->active_testname); @@ -500,6 +500,7 @@ void run_shell(struct torture_context *tctx) run_test(tctx, argv[1]); } } + free(cline); } } diff --git a/source4/torture/unix/unix_info2.c b/source4/torture/unix/unix_info2.c index 882dc7a084..d5fe8bc260 100644 --- a/source4/torture/unix/unix_info2.c +++ b/source4/torture/unix/unix_info2.c @@ -26,6 +26,7 @@ #include "torture/basic/proto.h" #include "lib/cmdline/popt_common.h" #include "auth/credentials/credentials.h" +#include "param/param.h" struct unix_info2 { uint64_t end_of_file; @@ -54,8 +55,9 @@ static struct smbcli_state *connect_to_server(struct torture_context *tctx) const char *host = torture_setting_string(tctx, "host", NULL); const char *share = torture_setting_string(tctx, "share", NULL); - status = smbcli_full_connection(tctx, &cli, - host, share, NULL, + status = smbcli_full_connection(tctx, &cli, host, + lp_smb_ports(tctx->lp_ctx), + share, NULL, cmdline_credentials, NULL); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/unix/whoami.c b/source4/torture/unix/whoami.c index 422e2abcbf..412a256da7 100644 --- a/source4/torture/unix/whoami.c +++ b/source4/torture/unix/whoami.c @@ -75,8 +75,9 @@ static struct smbcli_state *connect_to_server(struct torture_context *tctx, const char *host = torture_setting_string(tctx, "host", NULL); const char *share = torture_setting_string(tctx, "share", NULL); - status = smbcli_full_connection(tctx, &cli, - host, share, NULL, + status = smbcli_full_connection(tctx, &cli, host, + lp_smb_ports(tctx->lp_ctx), + share, NULL, creds, NULL); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/torture/util_smb.c b/source4/torture/util_smb.c index 65dfaec1cc..1168f31679 100644 --- a/source4/torture/util_smb.c +++ b/source4/torture/util_smb.c @@ -474,6 +474,7 @@ _PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx, NTSTATUS status; status = smbcli_full_connection(mem_ctx, c, hostname, + lp_smb_ports(tctx->lp_ctx), sharename, NULL, cmdline_credentials, ev); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/utils/getntacl.c b/source4/utils/getntacl.c index 382a020c40..132d689dcb 100644 --- a/source4/utils/getntacl.c +++ b/source4/utils/getntacl.c @@ -23,6 +23,7 @@ #include "system/filesys.h" #include "librpc/gen_ndr/ndr_xattr.h" #include "lib/util/wrap_xattr.h" +#include "param/param.h" static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3); @@ -71,7 +72,7 @@ static NTSTATUS get_ntacl(TALLOC_CTX *mem_ctx, } blob.length = size; - ndr = ndr_pull_init_blob(&blob, NULL); + ndr = ndr_pull_init_blob(&blob, NULL, NULL); ndr_err = ndr_pull_xattr_NTACL(ndr, NDR_SCALARS|NDR_BUFFERS, *ntacl); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { diff --git a/source4/utils/nmblookup.c b/source4/utils/nmblookup.c index a3e33e2748..7eae9c7765 100644 --- a/source4/utils/nmblookup.c +++ b/source4/utils/nmblookup.c @@ -104,7 +104,7 @@ static char *node_status_flags(TALLOC_CTX *mem_ctx, uint16_t flags) /* do a single node status */ static bool do_node_status(struct nbt_name_socket *nbtsock, - const char *addr) + const char *addr, uint16_t port) { struct nbt_name_status io; NTSTATUS status; @@ -113,6 +113,7 @@ static bool do_node_status(struct nbt_name_socket *nbtsock, io.in.name.type = NBT_NAME_CLIENT; io.in.name.scope = NULL; io.in.dest_addr = addr; + io.in.dest_port = port; io.in.timeout = 1; io.in.retries = 2; @@ -172,14 +173,15 @@ static NTSTATUS do_node_query(struct nbt_name_socket *nbtsock, io.out.name.type); } if (options.node_status && io.out.num_addrs > 0) { - do_node_status(nbtsock, io.out.reply_addrs[0]); + do_node_status(nbtsock, io.out.reply_addrs[0], port); } return status; } -static bool process_one(struct loadparm_context *lp_ctx, const char *name, int nbt_port) +static bool process_one(struct loadparm_context *lp_ctx, + struct interface *ifaces, const char *name, int nbt_port) { TALLOC_CTX *tmp_ctx = talloc_new(NULL); enum nbt_name_type node_type = NBT_NAME_CLIENT; @@ -229,7 +231,7 @@ static bool process_one(struct loadparm_context *lp_ctx, const char *name, int n } if (options.lookup_by_ip) { - ret = do_node_status(nbtsock, name); + ret = do_node_status(nbtsock, name, nbt_port); talloc_free(tmp_ctx); return ret; } @@ -241,9 +243,11 @@ static bool process_one(struct loadparm_context *lp_ctx, const char *name, int n status = do_node_query(nbtsock, options.unicast_address, nbt_port, node_name, node_type, false); } else { - int i, num_interfaces = iface_count(lp_ctx); + int i, num_interfaces; + + num_interfaces = iface_count(ifaces); for (i=0;i<num_interfaces;i++) { - const char *bcast = iface_n_bcast(lp_ctx, i); + const char *bcast = iface_n_bcast(ifaces, i); if (bcast == NULL) continue; status = do_node_query(nbtsock, bcast, nbt_port, node_name, node_type, true); @@ -266,6 +270,7 @@ static bool process_one(struct loadparm_context *lp_ctx, const char *name, int n int main(int argc, const char *argv[]) { bool ret = true; + struct interface *ifaces; poptContext pc; int opt; enum { @@ -349,13 +354,17 @@ int main(int argc, const char *argv[]) poptPrintUsage(pc, stderr, 0); exit(1); } + + load_interfaces(NULL, lp_interfaces(cmdline_lp_ctx), &ifaces); while (poptPeekArg(pc)) { const char *name = poptGetArg(pc); - ret &= process_one(cmdline_lp_ctx, name, lp_nbt_port(cmdline_lp_ctx)); + ret &= process_one(cmdline_lp_ctx, ifaces, name, lp_nbt_port(cmdline_lp_ctx)); } + talloc_free(ifaces); + poptFreeContext(pc); if (!ret) { diff --git a/source4/utils/ntlm_auth.c b/source4/utils/ntlm_auth.c index 93d1909a56..3144fe91b1 100644 --- a/source4/utils/ntlm_auth.c +++ b/source4/utils/ntlm_auth.c @@ -339,16 +339,25 @@ static const char *get_password(struct cli_credentials *credentials) **/ static bool in_list(const char *s, const char *list, bool casesensitive) { - pstring tok; + char *tok; + size_t tok_len = 1024; const char *p=list; if (!list) return false; - while (next_token(&p, tok, LIST_SEP, sizeof(tok))) { - if ((casesensitive?strcmp:strcasecmp_m)(tok,s) == 0) + tok = (char *)malloc(tok_len); + if (!tok) { + return false; + } + + while (next_token(&p, tok, LIST_SEP, tok_len)) { + if ((casesensitive?strcmp:strcasecmp_m)(tok,s) == 0) { + free(tok); return true; + } } + free(tok); return false; } @@ -471,7 +480,8 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode, if (!ev) { exit(1); } - msg = messaging_client_init(state, lp_messaging_path(state, lp_ctx), ev); + msg = messaging_client_init(state, lp_messaging_path(state, lp_ctx), + lp_iconv_convenience(lp_ctx), ev); if (!msg) { exit(1); } @@ -504,7 +514,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode, switch (stdio_helper_mode) { case GSS_SPNEGO_SERVER: case SQUID_2_5_NTLMSSP: - cli_credentials_set_machine_account(creds); + cli_credentials_set_machine_account(creds, lp_ctx); break; default: break; diff --git a/source4/web_server/web_server.c b/source4/web_server/web_server.c index a8fd9234ae..87cab2cc92 100644 --- a/source4/web_server/web_server.c +++ b/source4/web_server/web_server.c @@ -251,10 +251,15 @@ static void websrv_task_init(struct task_server *task) if (!model_ops) goto failed; if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) { - int num_interfaces = iface_count(task->lp_ctx); + int num_interfaces; int i; + struct interface *ifaces; + + load_interfaces(NULL, lp_interfaces(task->lp_ctx), &ifaces); + + num_interfaces = iface_count(ifaces); for(i = 0; i < num_interfaces; i++) { - const char *address = iface_n_ip(task->lp_ctx, i); + const char *address = iface_n_ip(ifaces, i); status = stream_setup_socket(task->event_ctx, model_ops, &web_stream_ops, "ipv4", address, @@ -262,6 +267,8 @@ static void websrv_task_init(struct task_server *task) task); if (!NT_STATUS_IS_OK(status)) goto failed; } + + talloc_free(ifaces); } else { status = stream_setup_socket(task->event_ctx, model_ops, &web_stream_ops, diff --git a/source4/winbind/wb_dom_info.c b/source4/winbind/wb_dom_info.c index e53e3d827b..7558fc9d62 100644 --- a/source4/winbind/wb_dom_info.c +++ b/source4/winbind/wb_dom_info.c @@ -68,9 +68,10 @@ struct composite_context *wb_get_dom_info_send(TALLOC_CTX *mem_ctx, if (dom_sid == NULL) goto failed; ctx = finddcs_send(mem_ctx, lp_netbios_name(service->task->lp_ctx), + lp_nbt_port(service->task->lp_ctx), domain_name, NBT_NAME_LOGON, dom_sid, - lp_name_resolve_order(service->task->lp_ctx), + lp_resolve_context(service->task->lp_ctx), service->task->event_ctx, service->task->msg_ctx); if (ctx == NULL) goto failed; diff --git a/source4/winbind/wb_dom_info_trusted.c b/source4/winbind/wb_dom_info_trusted.c index 5d960cb1d4..46d3bf37f6 100644 --- a/source4/winbind/wb_dom_info_trusted.c +++ b/source4/winbind/wb_dom_info_trusted.c @@ -192,8 +192,8 @@ static void trusted_dom_info_recv_dcname(struct rpc_request *req) if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++; make_nbt_name(&name, state->info->dcs[0].name, 0x20); - ctx = resolve_name_send(&name, state->service->task->event_ctx, - lp_name_resolve_order(state->service->task->lp_ctx)); + ctx = resolve_name_send(lp_resolve_context(state->service->task->lp_ctx), + &name, state->service->task->event_ctx); composite_continue(state->ctx, ctx, trusted_dom_info_recv_dcaddr, state); diff --git a/source4/winbind/wb_init_domain.c b/source4/winbind/wb_init_domain.c index cee7e5c3e7..fc35f11db6 100644 --- a/source4/winbind/wb_init_domain.c +++ b/source4/winbind/wb_init_domain.c @@ -157,7 +157,7 @@ struct composite_context *wb_init_domain_send(TALLOC_CTX *mem_ctx, /* Connect the machine account to the credentials */ state->ctx->status = - cli_credentials_set_machine_account(state->domain->libnet_ctx->cred); + cli_credentials_set_machine_account(state->domain->libnet_ctx->cred, state->domain->libnet_ctx->lp_ctx); if (!NT_STATUS_IS_OK(state->ctx->status)) goto failed; state->domain->netlogon_binding = init_domain_binding(state, &ndr_table_netlogon); diff --git a/source4/wrepl_server/wrepl_in_connection.c b/source4/wrepl_server/wrepl_in_connection.c index 089bdd5f3e..4d834a6a5a 100644 --- a/source4/wrepl_server/wrepl_in_connection.c +++ b/source4/wrepl_server/wrepl_in_connection.c @@ -276,15 +276,20 @@ NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadpar } if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) { - int num_interfaces = iface_count(lp_ctx); + int num_interfaces; int i; + struct interface *ifaces; + + load_interfaces(task, lp_interfaces(lp_ctx), &ifaces); + + num_interfaces = iface_count(ifaces); /* We have been given an interfaces line, and been told to only bind to those interfaces. Create a socket per interface and bind to only these. */ for(i = 0; i < num_interfaces; i++) { - address = iface_n_ip(lp_ctx, i); + address = iface_n_ip(ifaces, i); status = stream_setup_socket(task->event_ctx, model_ops, &wreplsrv_stream_ops, "ipv4", address, &port, lp_socket_options(task->lp_ctx), diff --git a/source4/wrepl_server/wrepl_out_helpers.c b/source4/wrepl_server/wrepl_out_helpers.c index 2599ef4d09..f809095f22 100644 --- a/source4/wrepl_server/wrepl_out_helpers.c +++ b/source4/wrepl_server/wrepl_out_helpers.c @@ -29,6 +29,7 @@ #include "nbt_server/wins/winsdb.h" #include "libcli/composite/composite.h" #include "libcli/wrepl/winsrepl.h" +#include "libcli/resolve/resolve.h" enum wreplsrv_out_connect_stage { WREPLSRV_OUT_CONNECT_STAGE_WAIT_SOCKET, @@ -191,6 +192,7 @@ static struct composite_context *wreplsrv_out_connect_send(struct wreplsrv_partn state->stage = WREPLSRV_OUT_CONNECT_STAGE_WAIT_SOCKET; state->wreplconn= wreplconn; state->c_req = wrepl_connect_send(wreplconn->sock, + lp_resolve_context(service->task->lp_ctx), partner->our_address, partner->address); if (!state->c_req) goto failed; @@ -379,8 +381,7 @@ static NTSTATUS wreplsrv_pull_table_recv(struct composite_context *c, TALLOC_CTX struct wreplsrv_pull_table_state *state = talloc_get_type(c->private_data, struct wreplsrv_pull_table_state); io->out.num_owners = state->table_io.out.num_partners; - io->out.owners = state->table_io.out.partners; - talloc_reference(mem_ctx, state->table_io.out.partners); + io->out.owners = talloc_reference(mem_ctx, state->table_io.out.partners); } talloc_free(c); @@ -535,8 +536,7 @@ static NTSTATUS wreplsrv_pull_names_recv(struct composite_context *c, TALLOC_CTX struct wreplsrv_pull_names_state *state = talloc_get_type(c->private_data, struct wreplsrv_pull_names_state); io->out.num_names = state->pull_io.out.num_names; - io->out.names = state->pull_io.out.names; - talloc_reference(mem_ctx, state->pull_io.out.names); + io->out.names = talloc_reference(mem_ctx, state->pull_io.out.names); } talloc_free(c); diff --git a/source4/wrepl_server/wrepl_server.c b/source4/wrepl_server/wrepl_server.c index 7455c57d75..7d4be3e1b5 100644 --- a/source4/wrepl_server/wrepl_server.c +++ b/source4/wrepl_server/wrepl_server.c @@ -32,6 +32,7 @@ #include "auth/auth.h" #include "ldb_wrap.h" #include "param/param.h" +#include "lib/socket/netif.h" static struct ldb_context *wins_config_db_connect(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx) @@ -74,7 +75,15 @@ failed: static NTSTATUS wreplsrv_open_winsdb(struct wreplsrv_service *service, struct loadparm_context *lp_ctx) { - service->wins_db = winsdb_connect(service, lp_ctx, WINSDB_HANDLE_CALLER_WREPL); + const char *owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner"); + + if (owner == NULL) { + struct interface *ifaces; + load_interfaces(service, lp_interfaces(lp_ctx), &ifaces); + owner = iface_n_ip(ifaces, 0); + } + + service->wins_db = winsdb_connect(service, lp_ctx, owner, WINSDB_HANDLE_CALLER_WREPL); if (!service->wins_db) { return NT_STATUS_INTERNAL_DB_ERROR; } diff --git a/testprogs/ejs/ldap.js b/testprogs/ejs/ldap.js index 877240890d..c03dbe9ce2 100755 --- a/testprogs/ejs/ldap.js +++ b/testprogs/ejs/ldap.js @@ -51,6 +51,8 @@ dn: cn=ldaptestuser,cn=uSers," + base_dn + " objectclass: user objectclass: person cN: LDAPtestUSER +givenname: ldap +sn: testy "); if (ok.error != 0) { ok = ldb.del("cn=ldaptestuser,cn=users," + base_dn); @@ -63,6 +65,8 @@ dn: cn=ldaptestuser,cn=uSers," + base_dn + " objectclass: user objectclass: person cN: LDAPtestUSER +givenname: ldap +sn: testy "); if (ok.error != 0) { println(ok.errstr); @@ -112,6 +116,7 @@ dn: cn=ldaptest2computer,cn=computers," + base_dn + " objectClass: computer cn: LDAPtest2COMPUTER userAccountControl: 4096 +displayname: ldap testy "); if (ok.error != 0) { ok = ldb.del("cn=ldaptest2computer,cn=computers," + base_dn); @@ -124,6 +129,7 @@ dn: cn=ldaptest2computer,cn=computers," + base_dn + " objectClass: computer cn: LDAPtest2COMPUTER userAccountControl: 4096 +displayname: ldap testy "); if (ok.error != 0) { println(ok.errstr); @@ -131,6 +137,7 @@ userAccountControl: 4096 } } + println("Testing attribute or value exists behaviour"); ok = ldb.modify(" dn: cn=ldaptest2computer,cn=computers," + base_dn + " changetype: modify @@ -146,11 +153,183 @@ servicePrincipalName: cifs/ldaptest2computer assert(ok.error == 20); } - ok = ldb.add(" + ok = ldb.modify(" +dn: cn=ldaptest2computer,cn=computers," + base_dn + " +changetype: modify +replace: servicePrincipalName +servicePrincipalName: host/ldaptest2computer +servicePrincipalName: cifs/ldaptest2computer +"); + + if (ok.error != 0) { + println("Failed to replace servicePrincpalName:" + ok.errstr); + assert(ok.error == 20); + } + + ok = ldb.modify(" +dn: cn=ldaptest2computer,cn=computers," + base_dn + " +changetype: modify +add: servicePrincipalName +servicePrincipalName: host/ldaptest2computer +"); + +//LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS + if (ok.error != 20) { + println("Expected error LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS, got :" + ok.errstr); + assert(ok.error == 20); + } + + println("Testing ranged results"); + ok = ldb.modify(" +dn: cn=ldaptest2computer,cn=computers," + base_dn + " +changetype: modify +replace: servicePrincipalName +"); + if (ok.error != 0) { + println("Failed to replace servicePrincpalName:" + ok.errstr); + assert(ok.error == 0); + } + + ok = ldb.modify(" +dn: cn=ldaptest2computer,cn=computers," + base_dn + " +changetype: modify +add: servicePrincipalName +servicePrincipalName: host/ldaptest2computer0 +servicePrincipalName: host/ldaptest2computer1 +servicePrincipalName: host/ldaptest2computer2 +servicePrincipalName: host/ldaptest2computer3 +servicePrincipalName: host/ldaptest2computer4 +servicePrincipalName: host/ldaptest2computer5 +servicePrincipalName: host/ldaptest2computer6 +servicePrincipalName: host/ldaptest2computer7 +servicePrincipalName: host/ldaptest2computer8 +servicePrincipalName: host/ldaptest2computer9 +servicePrincipalName: host/ldaptest2computer10 +servicePrincipalName: host/ldaptest2computer11 +servicePrincipalName: host/ldaptest2computer12 +servicePrincipalName: host/ldaptest2computer13 +servicePrincipalName: host/ldaptest2computer14 +servicePrincipalName: host/ldaptest2computer15 +servicePrincipalName: host/ldaptest2computer16 +servicePrincipalName: host/ldaptest2computer17 +servicePrincipalName: host/ldaptest2computer18 +servicePrincipalName: host/ldaptest2computer19 +servicePrincipalName: host/ldaptest2computer20 +servicePrincipalName: host/ldaptest2computer21 +servicePrincipalName: host/ldaptest2computer22 +servicePrincipalName: host/ldaptest2computer23 +servicePrincipalName: host/ldaptest2computer24 +servicePrincipalName: host/ldaptest2computer25 +servicePrincipalName: host/ldaptest2computer26 +servicePrincipalName: host/ldaptest2computer27 +servicePrincipalName: host/ldaptest2computer28 +servicePrincipalName: host/ldaptest2computer29 +"); + + if (ok.error != 0) { + println("Failed to replace servicePrincpalName:" + ok.errstr); + assert(ok.error == 0); + } + + + var attrs = new Array("servicePrincipalName;range=0-*"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } +// println(res.msgs[0]["servicePrincipalName;range=0-*"].length); + assert(res.msgs[0]["servicePrincipalName;range=0-*"].length == 30); + + var attrs = new Array("servicePrincipalName;range=0-19"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } +// println(res.msgs[0]["servicePrincipalName;range=0-19"].length); + assert(res.msgs[0]["servicePrincipalName;range=0-19"].length == 20); + + var attrs = new Array("servicePrincipalName;range=0-30"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=0-*"].length == 30); + + var attrs = new Array("servicePrincipalName;range=0-40"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=0-*"].length == 30); + + var attrs = new Array("servicePrincipalName;range=30-40"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=30-*"].length == 0); + + var attrs = new Array("servicePrincipalName;range=10-40"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=10-*"].length == 20); +// var pos_11 = res.msgs[0]["servicePrincipalName;range=10-*"][18]; + + var attrs = new Array("servicePrincipalName;range=11-40"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=11-*"].length == 19); +// println(res.msgs[0]["servicePrincipalName;range=11-*"][18]); +// println(pos_11); +// assert((res.msgs[0]["servicePrincipalName;range=11-*"][18]) == pos_11); + + var attrs = new Array("servicePrincipalName;range=11-15"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + assert(res.msgs[0]["servicePrincipalName;range=11-15"].length == 5); +// assert(res.msgs[0]["servicePrincipalName;range=11-15"][4] == pos_11); + + var attrs = new Array("servicePrincipalName"); + var res = ldb.search("(cn=ldaptest2computer))", base_dn, ldb.SCOPE_SUBTREE, attrs); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (cn=ldaptest2computer)"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } +// println(res.msgs[0]["servicePrincipalName"][18]); +// println(pos_11); + assert(res.msgs[0]["servicePrincipalName"].length == 30); +// assert(res.msgs[0]["servicePrincipalName"][18] == pos_11); + + ok = ldb.add(" dn: cn=ldaptestuser2,cn=useRs," + base_dn + " objectClass: person objectClass: user cn: LDAPtestUSER2 +givenname: testy +sn: ldap user2 "); if (ok.error != 0) { ok = ldb.del("cn=ldaptestuser2,cn=users," + base_dn); @@ -163,6 +342,8 @@ dn: cn=ldaptestuser2,cn=useRs," + base_dn + " objectClass: person objectClass: user cn: LDAPtestUSER2 +givenname: testy +sn: ldap user2 "); if (ok.error != 0) { println(ok.errstr); @@ -170,6 +351,137 @@ cn: LDAPtestUSER2 } } + + println("Testing Ambigious Name Resolution"); +// Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + var res = ldb.search("(&(anr=ldap testy)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 3) { + println("Could not find (&(anr=ldap testy)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 3); + } + +// Testing ldb.search for (&(anr=testy ldap)(objectClass=user)) + var res = ldb.search("(&(anr=testy ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 2) { + println("Found only " + res.msgs.length + " for (&(anr=testy ldap)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 2); + } + +// Testing ldb.search for (&(anr=ldap)(objectClass=user)) + var res = ldb.search("(&(anr=ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 4) { + println("Found only " + res.msgs.length + " for (&(anr=ldap)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 4); + } + +// Testing ldb.search for (&(anr==ldap)(objectClass=user)) + var res = ldb.search("(&(anr==ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Found only " + res.msgs.length + " for (&(anr=ldap)(objectClass=user))"); + println("Could not find (&(anr==ldap)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser"); + assert(res.msgs[0].name == "ldaptestuser"); + +// Testing ldb.search for (&(anr=testy)(objectClass=user)) + var res = ldb.search("(&(anr=testy)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 2) { + println("Found only " + res.msgs.length + " for (&(anr=testy)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 2); + } + +// Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + var res = ldb.search("(&(anr=testy ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 2) { + println("Found only " + res.msgs.length + " for (&(anr=ldap testy)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 2); + } + +// Testing ldb.search for (&(anr==ldap testy)(objectClass=user)) + var res = ldb.search("(&(anr==testy ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Found only " + res.msgs.length + " for (&(anr==ldap testy)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser"); + assert(res.msgs[0].name == "ldaptestuser"); + +// Testing ldb.search for (&(anr==testy ldap)(objectClass=user)) + var res = ldb.search("(&(anr==testy ldap)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (&(anr==testy ldap)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser"); + assert(res.msgs[0].name == "ldaptestuser"); + + // Testing ldb.search for (&(anr=testy ldap user)(objectClass=user)) + var res = ldb.search("(&(anr=testy ldap user)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (&(anr=testy ldap user)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser2,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser2"); + assert(res.msgs[0].name == "ldaptestuser2"); + + // Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user)) + var res = ldb.search("(&(anr==testy ldap user2)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (&(anr==testy ldap user2)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser2,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser2"); + assert(res.msgs[0].name == "ldaptestuser2"); + + // Testing ldb.search for (&(anr==ldap user2)(objectClass=user)) + var res = ldb.search("(&(anr==ldap user2)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (&(anr==ldap user2)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + assert(res.msgs[0].dn == ("CN=ldaptestuser2,CN=Users," + base_dn)); + assert(res.msgs[0].cn == "ldaptestuser2"); + assert(res.msgs[0].name == "ldaptestuser2"); + + // Testing ldb.search for (&(anr==not ldap user2)(objectClass=user)) + var res = ldb.search("(&(anr==not ldap user2)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 0) { + println("Must not find (&(anr==not ldap user2)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 0); + } + + // Testing ldb.search for (&(anr=not ldap user2)(objectClass=user)) + var res = ldb.search("(&(anr=not ldap user2)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 0) { + println("Must not find (&(anr=not ldap user2)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 0); + } + println("Testing Group Modifies"); ok = ldb.modify(" dn: cn=ldaptestgroup,cn=users," + base_dn + " @@ -884,6 +1196,20 @@ member: CN=ldaptestutf8user èùéìòà,CN=Users," + base_dn + " assert(ok.error == 0); } + println("Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))"); + var res = ldb.search("(&(cn=ldaptestutf8user2*)(objectClass=user))"); + if (res.error != 0 || res.msgs.length != 1) { + println("Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))"); + assert(res.error == 0); + assert(res.msgs.length == 1); + } + + ok = ldb.del(res.msgs[0].dn); + if (ok.error != 0) { + println(ok.errstr); + assert(ok.error == 0); + } + ok = ldb.del(("CN=ldaptestgroup2,CN=Users," + base_dn)) if (ok.error != 0) { println(ok.errstr); |