r26205: Pass loadparm_context to secrets_db_connect() rather than using global context.
[jelmer/samba4-debian.git] / source / libnet / libnet_join.c
index 44e2dfe5f0e025eaa92e93e220fc9781d8edb5fd..25ad0ca440244f6027ab13f4cacd01aad57da709 100644 (file)
@@ -7,7 +7,7 @@
  
    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
+   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,
@@ -16,8 +16,7 @@
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "lib/ldb/include/ldb_errors.h"
 #include "param/secrets.h"
 #include "dsdb/samdb/samdb.h"
-#include "db_wrap.h"
+#include "ldb_wrap.h"
+#include "util/util_ldb.h"
 #include "libcli/security/security.h"
 #include "auth/credentials/credentials.h"
 #include "auth/credentials/credentials_krb5.h"
 #include "librpc/gen_ndr/ndr_samr_c.h"
+#include "param/param.h"
 
 /*
  * complete a domain join, when joining to a AD domain:
@@ -111,7 +112,7 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J
        status = dcerpc_pipe_connect_b(tmp_ctx, 
                                       &drsuapi_pipe,
                                       drsuapi_binding,
-                                      &dcerpc_table_drsuapi,
+                                      &ndr_table_drsuapi,
                                       ctx->cred, 
                                       ctx->event_ctx);
        if (!NT_STATUS_IS_OK(status)) {
@@ -228,7 +229,8 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J
                return NT_STATUS_NO_MEMORY;
        }
 
-       remote_ldb = ldb_wrap_connect(tmp_ctx, remote_ldb_url, 
+       remote_ldb = ldb_wrap_connect(tmp_ctx, global_loadparm, 
+                                     remote_ldb_url, 
                                      NULL, ctx->cred, 0, NULL);
        if (!remote_ldb) {
                r->out.error_string = NULL;
@@ -480,7 +482,7 @@ NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru
        /* This level makes a connection to the LSA pipe on the way,
         * to get some useful bits of information about the domain */
        connect_with_info->level              = LIBNET_RPC_CONNECT_DC_INFO;
-       connect_with_info->in.dcerpc_iface    = &dcerpc_table_samr;
+       connect_with_info->in.dcerpc_iface    = &ndr_table_samr;
 
        /*
          establish the SAMR connection
@@ -504,7 +506,7 @@ NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru
 
        status = dcerpc_pipe_auth(tmp_ctx, &samr_pipe,
                                  connect_with_info->out.dcerpc_pipe->binding, 
-                                 &dcerpc_table_samr, ctx->cred);
+                                 &ndr_table_samr, ctx->cred);
        if (!NT_STATUS_IS_OK(status)) {
                r->out.error_string = talloc_asprintf(mem_ctx,
                                                "SAMR bind failed: %s",
@@ -535,8 +537,8 @@ NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru
                        connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, r->in.domain_name);
                } else {
                        /* Bugger, we just lost our way to automaticly find the domain name */
-                       connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, lp_workgroup());
-                       connect_with_info->out.realm = talloc_strdup(tmp_ctx, lp_realm());
+                       connect_with_info->out.domain_name = talloc_strdup(tmp_ctx, lp_workgroup(global_loadparm));
+                       connect_with_info->out.realm = talloc_strdup(tmp_ctx, lp_realm(global_loadparm));
                }
        }
 
@@ -888,7 +890,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
        if (r->in.netbios_name != NULL) {
                netbios_name = r->in.netbios_name;
        } else {
-               netbios_name = talloc_reference(tmp_mem, lp_netbios_name());
+               netbios_name = talloc_reference(tmp_mem, lp_netbios_name(global_loadparm));
                if (!netbios_name) {
                        r->out.error_string = NULL;
                        talloc_free(tmp_mem);
@@ -907,7 +909,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
         * Local secrets are stored in secrets.ldb 
         * open it to make sure we can write the info into it after the join
         */
-       ldb = secrets_db_connect(tmp_mem);
+       ldb = secrets_db_connect(tmp_mem, global_loadparm);
        if (!ldb) {
                r->out.error_string
                        = talloc_asprintf(mem_ctx, 
@@ -925,7 +927,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
        r2->in.netbios_name     = netbios_name;
        r2->in.level            = LIBNET_JOINDOMAIN_AUTOMATIC;
        r2->in.acct_type        = acct_type;
-       r2->in.recreate_account = False;
+       r2->in.recreate_account = false;
        status = libnet_JoinDomain(ctx, r2, r2);
        if (!NT_STATUS_IS_OK(status)) {
                r->out.error_string = talloc_steal(mem_ctx, r2->out.error_string);
@@ -1134,7 +1136,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
        }
 
        /* create the secret */
-       ret = samdb_add(ldb, tmp_mem, msg);
+       ret = ldb_add(ldb, msg);
        if (ret != 0) {
                r->out.error_string = talloc_asprintf(mem_ctx, "Failed to create secret record %s", 
                                                      ldb_dn_get_linearized(msg->dn));