r10675: Connect to the DC's IPC$
authorVolker Lendecke <vlendec@samba.org>
Sat, 1 Oct 2005 16:36:04 +0000 (16:36 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:39:17 +0000 (13:39 -0500)
Volker
(This used to be commit c7557884843a5b2bac9e21ec81cafcaadf436bca)

source4/nbt_server/nbt_server.c
source4/winbind/wb_async_helpers.c
source4/winbind/wb_samba3_cmd.c
source4/winbind/wb_samba3_protocol.c

index 83a7ae8a2f38cbba5d7d0811b1dfcdfe60ec0cb3..f1c9b67dd865cedd68c9779fd2dfd31619234357 100644 (file)
@@ -74,13 +74,17 @@ static void getdc_recv_ntlogon_reply(struct dgram_mailslot_handler *dgmslot,
        case NTLOGON_SAM_LOGON:
                DEBUG(0, ("Huh -- got NTLOGON_SAM_LOGON as reply\n"));
                break;
-       case NTLOGON_SAM_LOGON_REPLY:
+       case NTLOGON_SAM_LOGON_REPLY: {
+               const char *p = ntlogon.req.reply.server;
+
                DEBUG(10, ("NTLOGON_SAM_LOGON_REPLY: server: %s, user: %s, "
-                          "domain: %s\n", ntlogon.req.reply.server,
-                          ntlogon.req.reply.user_name,
+                          "domain: %s\n", p, ntlogon.req.reply.user_name,
                           ntlogon.req.reply.domain));
-               s->req->out.dcname =
-                       talloc_strdup(s->req, ntlogon.req.reply.server);
+
+               if (*p == '\\') p += 1;
+               if (*p == '\\') p += 1;
+
+               s->req->out.dcname = talloc_strdup(s->req, p);
                if (s->req->out.dcname == NULL) {
                        DEBUG(0, ("talloc failed\n"));
                        status = NT_STATUS_NO_MEMORY;
@@ -88,6 +92,7 @@ static void getdc_recv_ntlogon_reply(struct dgram_mailslot_handler *dgmslot,
                }
                status = NT_STATUS_OK;
                break;
+       }
        default:
                DEBUG(0, ("Got unknown packet: %d\n", ntlogon.command));
                break;
index d6f2f1cac4b749feccca9a35cd3e52e25106087a..a802f0e45e15dfd8b044d94eb71f111979e52c8a 100644 (file)
@@ -66,6 +66,7 @@ static void finddcs_getdc(struct irpc_request *ireq)
            c->async.fn) {
                c->async.fn(c);
        }
+       talloc_free(ireq);
 }
 
 /*
index 752a368d31f0da3f33c425f4314a2a81fcabda15..a1593ef8bdef4624c771023e58c38346d54f45ca 100644 (file)
@@ -30,6 +30,7 @@
 #include "librpc/gen_ndr/nbt.h"
 #include "libcli/raw/libcliraw.h"
 #include "libcli/composite/composite.h"
+#include "libcli/smb_composite/smb_composite.h"
 #include "include/version.h"
 
 NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
@@ -78,9 +79,10 @@ NTSTATUS wbsrv_samba3_ping(struct wbsrv_samba3_call *s3call)
 
 struct check_machacc_state {
        struct wb_finddcs *io;
+       struct smb_composite_connect *conn;
 };
 
-static void wbsrv_samba3_check_machacc_reply(struct composite_context *action)
+static void wbsrv_samba3_check_machacc_receive_tree(struct composite_context *action)
 {
        struct wbsrv_samba3_call *s3call =
                talloc_get_type(action->async.private_data,
@@ -90,18 +92,90 @@ static void wbsrv_samba3_check_machacc_reply(struct composite_context *action)
                                struct check_machacc_state);
        NTSTATUS status;
 
+       status = smb_composite_connect_recv(action, state);
+       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.nt_status_string,
+                               nt_errstr(status));
+       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.error_string,
+                               nt_errstr(status));
+       s3call->response.data.auth.pam_error = nt_status_to_pam(status);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5, ("Connect failed: %s\n", nt_errstr(status)));
+               goto done;
+       }
+
+       s3call->response.result = WINBINDD_OK;
+       
+ done:
+       if (!NT_STATUS_IS_OK(status)) {
+               s3call->response.result = WINBINDD_ERROR;
+       }
+
+       status = wbsrv_send_reply(s3call->call);
+       if (!NT_STATUS_IS_OK(status)) {
+               wbsrv_terminate_connection(s3call->call->wbconn,
+                                          "wbsrv_queue_reply() failed");
+               return;
+       }
+}
+
+static void wbsrv_samba3_check_machacc_receive_dcs(struct composite_context *action)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(action->async.private_data,
+                               struct wbsrv_samba3_call);
+       struct check_machacc_state *state =
+               talloc_get_type(s3call->private_data,
+                               struct check_machacc_state);
+       struct composite_context *ctx;
+       NTSTATUS status;
+
        status = wb_finddcs_recv(action, s3call);
 
        s3call->response.data.auth.nt_status = NT_STATUS_V(status);
-       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.nt_status_string, nt_errstr(status));
-       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.error_string, nt_errstr(status));
+       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.nt_status_string,
+                               nt_errstr(status));
+       WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.error_string,
+                               nt_errstr(status));
        s3call->response.data.auth.pam_error = nt_status_to_pam(status);
 
-       if (NT_STATUS_IS_OK(status)) {
-               DEBUG(10, ("Got name %s\n", state->io->out.dcs[0].name));
-               s3call->response.result = WINBINDD_OK;
-       } else {
-               DEBUG(10, ("Got no addr: %s\n", nt_errstr(status)));
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       state->conn = talloc(state, struct smb_composite_connect);
+       if (state->conn == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       state->conn->in.dest_host = state->io->out.dcs[0].address;
+       state->conn->in.port = 0;
+       state->conn->in.called_name = state->io->out.dcs[0].name;
+       state->conn->in.service = "IPC$";
+       state->conn->in.service_type = "IPC";
+       state->conn->in.workgroup = lp_workgroup();
+
+       state->conn->in.credentials = cli_credentials_init(state->conn);
+       if (state->conn->in.credentials == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+       cli_credentials_set_conf(state->conn->in.credentials);
+       cli_credentials_set_anonymous(state->conn->in.credentials);
+
+       ctx = smb_composite_connect_send(state->conn, s3call->call->event_ctx);
+       if (ctx == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       ctx->async.fn = wbsrv_samba3_check_machacc_receive_tree;
+       ctx->async.private_data = s3call;
+       return;
+
+ done:
+       if (!NT_STATUS_IS_OK(status)) {
                s3call->response.result = WINBINDD_ERROR;
        }
 
@@ -134,7 +208,7 @@ NTSTATUS wbsrv_samba3_check_machacc(struct wbsrv_samba3_call *s3call)
        NT_STATUS_HAVE_NO_MEMORY(resolve_req);
 
        /* setup the callbacks */
-       resolve_req->async.fn           = wbsrv_samba3_check_machacc_reply;
+       resolve_req->async.fn = wbsrv_samba3_check_machacc_receive_dcs;
        resolve_req->async.private_data = s3call;
 
        /* tell the caller we reply later */
index af63b4c876ff50aff5806cf7b7fbc7f613aa3635..d7e32daddb3db758255568019f87adc82d249769 100644 (file)
@@ -33,7 +33,8 @@ uint32_t wbsrv_samba3_packet_length(DATA_BLOB blob)
        return *len;
 }
 
-NTSTATUS wbsrv_samba3_pull_request(DATA_BLOB blob, TALLOC_CTX *mem_ctx, struct wbsrv_call **_call)
+NTSTATUS wbsrv_samba3_pull_request(DATA_BLOB blob, TALLOC_CTX *mem_ctx,
+                                  struct wbsrv_call **_call)
 {
        struct wbsrv_call *call;
        struct wbsrv_samba3_call *s3_call;