The branch, master has been updated
       via  41a5149... s3: Slightly simplify winbindd_dual_ccache_ntlm_auth
       via  e2f361d... s3: Fix some nonempty blank lines
       via  6ada1f2... libwbclient: Remove a pointless check
       via  6edfbbd... s3: Remove some unused code
       via  2d75aa0... s3: Convert cli_sesssetup_ntlmssp to the async API
       via  3f25fb5... s3: NT_STATUS_MORE_PROCESSING_REQUIRED is a valid 
sesssetup return value
       via  a321dd9... s3: Convert cli_session_setup_kerberos to the async API
      from  063900a... s3: Fix a typo

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 41a5149981eb7293a54f0497c3a4f4fc50661157
Author: Volker Lendecke <[email protected]>
Date:   Sun Dec 20 00:27:34 2009 +0100

    s3: Slightly simplify winbindd_dual_ccache_ntlm_auth
    
    data_blob_const can't fail

commit e2f361d05e4ccef71397dd52cf78c6d36bea628e
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 2 18:25:13 2010 +0100

    s3: Fix some nonempty blank lines

commit 6ada1f250b987ddedfb744b9009be93513b3a5a2
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 2 20:09:31 2010 +0100

    libwbclient: Remove a pointless check
    
    We have dereferenced "blobs" before

commit 6edfbbd79b958d7341bf25fc7fa6675cefc4e041
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 2 18:16:30 2010 +0100

    s3: Remove some unused code

commit 2d75aa04da365d0fd7a89b7823252de64c852862
Author: Volker Lendecke <[email protected]>
Date:   Tue Dec 22 23:31:20 2009 +0100

    s3: Convert cli_sesssetup_ntlmssp to the async API

commit 3f25fb567783e2da5d9685e3ee81a0f32c85b416
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 2 18:14:59 2010 +0100

    s3: NT_STATUS_MORE_PROCESSING_REQUIRED is a valid sesssetup return value

commit a321dd91a4a3bf79705144b299bee4428c9aa5da
Author: Volker Lendecke <[email protected]>
Date:   Sun Dec 20 14:47:09 2009 +0100

    s3: Convert cli_session_setup_kerberos to the async API
    
    This is still cheated, acquiring the ticket is not async yet, but the SMB
    part is

-----------------------------------------------------------------------

Summary of changes:
 nsswitch/libwbclient/wbc_util.c           |    2 +-
 source3/libsmb/async_smb.c                |   32 +-
 source3/libsmb/cliconnect.c               |  767 ++++++++++++++++++-----------
 source3/winbindd/winbindd_ccache_access.c |   24 +-
 4 files changed, 522 insertions(+), 303 deletions(-)


Changeset truncated at 500 lines:

diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c
index 16828ae..24699e9 100644
--- a/nsswitch/libwbclient/wbc_util.c
+++ b/nsswitch/libwbclient/wbc_util.c
@@ -669,7 +669,7 @@ wbcErr wbcAddNamedBlob(size_t *num_blobs,
 
        wbc_status = WBC_ERR_SUCCESS;
 done:
-       if (!WBC_ERROR_IS_OK(wbc_status) && blobs) {
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
                wbcFreeMemory(*blobs);
        }
        return wbc_status;
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 8b9cf09..f5000e4 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -815,16 +815,30 @@ NTSTATUS cli_smb_recv(struct tevent_req *req, uint8_t 
min_wct,
 
        status = cli_pull_error((char *)state->inbuf);
 
-       if (!have_andx_command((char *)state->inbuf, wct_ofs)
-           && NT_STATUS_IS_ERR(status)) {
-               /*
-                * The last command takes the error code. All further commands
-                * down the requested chain will get a
-                * NT_STATUS_REQUEST_ABORTED.
-                */
-               return status;
+       if (!have_andx_command((char *)state->inbuf, wct_ofs)) {
+
+               if ((cmd == SMBsesssetupX)
+                   && NT_STATUS_EQUAL(
+                           status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+                       /*
+                        * NT_STATUS_MORE_PROCESSING_REQUIRED is a
+                        * valid return code for session setup
+                        */
+                       goto no_err;
+               }
+
+               if (NT_STATUS_IS_ERR(status)) {
+                       /*
+                        * The last command takes the error code. All
+                        * further commands down the requested chain
+                        * will get a NT_STATUS_REQUEST_ABORTED.
+                        */
+                       return status;
+               }
        }
 
+no_err:
+
        wct = CVAL(state->inbuf, wct_ofs);
        bytes_offset = wct_ofs + 1 + wct * sizeof(uint16_t);
        num_bytes = SVAL(state->inbuf, bytes_offset);
@@ -856,7 +870,7 @@ NTSTATUS cli_smb_recv(struct tevent_req *req, uint8_t 
min_wct,
                *pbytes = (uint8_t *)state->inbuf + bytes_offset + 2;
        }
 
-       return NT_STATUS_OK;
+       return status;
 }
 
 size_t cli_smb_wct_ofs(struct tevent_req **reqs, int num_reqs)
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index dccc914..7815bf9 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -3,17 +3,17 @@
    client connect/disconnect routines
    Copyright (C) Andrew Tridgell 1994-1998
    Copyright (C) Andrew Bartlett 2001-2003
-   
+
    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/>.
 */
@@ -105,7 +105,7 @@ static NTSTATUS cli_session_setup_lanman2(struct cli_state 
*cli,
        cli_set_message(cli->outbuf,10, 0, True);
        SCVAL(cli->outbuf,smb_com,SMBsesssetupX);
        cli_setup_packet(cli);
-       
+
        SCVAL(cli->outbuf,smb_vwv0,0xFF);
        SSVAL(cli->outbuf,smb_vwv2,cli->max_xmit);
        SSVAL(cli->outbuf,smb_vwv3,2);
@@ -131,7 +131,7 @@ static NTSTATUS cli_session_setup_lanman2(struct cli_state 
*cli,
        if (cli_is_error(cli)) {
                return cli_nt_error(cli);
        }
-       
+
        /* use the returned vuid from now on */
        cli->vuid = SVAL(cli->inbuf,smb_uid);   
        status = cli_set_username(cli, user);
@@ -360,14 +360,14 @@ static NTSTATUS cli_session_setup_plaintext(struct 
cli_state *cli,
        char *p;
        NTSTATUS status;
        fstring lanman;
-       
+
        fstr_sprintf( lanman, "Samba %s", samba_version_string());
 
        memset(cli->outbuf, '\0', smb_size);
        cli_set_message(cli->outbuf,13,0,True);
        SCVAL(cli->outbuf,smb_com,SMBsesssetupX);
        cli_setup_packet(cli);
-                       
+
        SCVAL(cli->outbuf,smb_vwv0,0xFF);
        SSVAL(cli->outbuf,smb_vwv2,CLI_BUFFER_SIZE);
        SSVAL(cli->outbuf,smb_vwv3,2);
@@ -376,9 +376,9 @@ static NTSTATUS cli_session_setup_plaintext(struct 
cli_state *cli,
        SSVAL(cli->outbuf,smb_vwv8,0);
        SIVAL(cli->outbuf,smb_vwv11,capabilities); 
        p = smb_buf(cli->outbuf);
-       
+
        /* check wether to send the ASCII or UNICODE version of the password */
-       
+
        if ( (capabilities & CAP_UNICODE) == 0 ) {
                p += clistr_push(cli, p, pass, -1, STR_TERMINATE); /* password 
*/
                SSVAL(cli->outbuf,smb_vwv7,PTR_DIFF(p, smb_buf(cli->outbuf)));
@@ -394,7 +394,7 @@ static NTSTATUS cli_session_setup_plaintext(struct 
cli_state *cli,
                p += clistr_push(cli, p, pass, -1, STR_UNICODE|STR_TERMINATE); 
/* unicode password */
                SSVAL(cli->outbuf,smb_vwv8,PTR_DIFF(p, 
smb_buf(cli->outbuf))-1);        
        }
-       
+
        p += clistr_push(cli, p, user, -1, STR_TERMINATE); /* username */
        p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE); /* workgroup */
        p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE);
@@ -404,9 +404,9 @@ static NTSTATUS cli_session_setup_plaintext(struct 
cli_state *cli,
        if (!cli_send_smb(cli) || !cli_receive_smb(cli)) {
                return cli_nt_error(cli);
        }
-       
+
        show_msg(cli->inbuf);
-       
+
        if (cli_is_error(cli)) {
                return cli_nt_error(cli);
        }
@@ -525,7 +525,7 @@ static NTSTATUS cli_session_setup_nt1(struct cli_state 
*cli, const char *user,
        cli_set_message(cli->outbuf,13,0,True);
        SCVAL(cli->outbuf,smb_com,SMBsesssetupX);
        cli_setup_packet(cli);
-                       
+
        SCVAL(cli->outbuf,smb_vwv0,0xFF);
        SSVAL(cli->outbuf,smb_vwv2,CLI_BUFFER_SIZE);
        SSVAL(cli->outbuf,smb_vwv3,2);
@@ -575,7 +575,7 @@ static NTSTATUS cli_session_setup_nt1(struct cli_state 
*cli, const char *user,
 
        /* use the returned vuid from now on */
        cli->vuid = SVAL(cli->inbuf,smb_uid);
-       
+
        p = smb_buf(cli->inbuf);
        p += clistr_pull(cli->inbuf, cli->server_os, p, sizeof(fstring),
                         -1, STR_TERMINATE);
@@ -606,172 +606,212 @@ end:
        return result;
 }
 
-/****************************************************************************
- Send a extended security session setup blob
-****************************************************************************/
+/* The following is calculated from :
+ * (smb_size-4) = 35
+ * (smb_wcnt * 2) = 24 (smb_wcnt == 12 in cli_session_setup_blob_send() )
+ * (strlen("Unix") + 1 + strlen("Samba") + 1) * 2 = 22 (unicode strings at
+ * end of packet.
+ */
 
-static bool cli_session_setup_blob_send(struct cli_state *cli, DATA_BLOB blob)
-{
-       uint32 capabilities = cli_session_setup_capabilities(cli);
-       char *p;
+#define BASE_SESSSETUP_BLOB_PACKET_SIZE (35 + 24 + 22)
 
-       capabilities |= CAP_EXTENDED_SECURITY;
+struct cli_sesssetup_blob_state {
+       struct tevent_context *ev;
+       struct cli_state *cli;
+       DATA_BLOB blob;
+       uint16_t max_blob_size;
+       uint16_t vwv[12];
+       uint8_t *buf;
 
-       /* send a session setup command */
-       memset(cli->outbuf,'\0',smb_size);
+       NTSTATUS status;
+       char *inbuf;
+       DATA_BLOB ret_blob;
+};
 
-       cli_set_message(cli->outbuf,12,0,True);
-       SCVAL(cli->outbuf,smb_com,SMBsesssetupX);
+static bool cli_sesssetup_blob_next(struct cli_sesssetup_blob_state *state,
+                                   struct tevent_req **psubreq);
+static void cli_sesssetup_blob_done(struct tevent_req *subreq);
 
-       cli_setup_packet(cli);
+static struct tevent_req *cli_sesssetup_blob_send(TALLOC_CTX *mem_ctx,
+                                                 struct tevent_context *ev,
+                                                 struct cli_state *cli,
+                                                 DATA_BLOB blob)
+{
+       struct tevent_req *req, *subreq;
+       struct cli_sesssetup_blob_state *state;
 
-       SCVAL(cli->outbuf,smb_vwv0,0xFF);
-       SSVAL(cli->outbuf,smb_vwv2,CLI_BUFFER_SIZE);
-       SSVAL(cli->outbuf,smb_vwv3,2);
-       SSVAL(cli->outbuf,smb_vwv4,1);
-       SIVAL(cli->outbuf,smb_vwv5,0);
-       SSVAL(cli->outbuf,smb_vwv7,blob.length);
-       SIVAL(cli->outbuf,smb_vwv10,capabilities); 
-       p = smb_buf(cli->outbuf);
-       memcpy(p, blob.data, blob.length);
-       p += blob.length;
-       p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE);
-       p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE);
-       cli_setup_bcc(cli, p);
-       return cli_send_smb(cli);
-}
+       req = tevent_req_create(mem_ctx, &state,
+                               struct cli_sesssetup_blob_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->ev = ev;
+       state->blob = blob;
+       state->cli = cli;
 
-/****************************************************************************
- Send a extended security session setup blob, returning a reply blob.
-****************************************************************************/
+       if (cli->max_xmit < BASE_SESSSETUP_BLOB_PACKET_SIZE + 1) {
+               DEBUG(1, ("cli_session_setup_blob: cli->max_xmit too small "
+                         "(was %u, need minimum %u)\n",
+                         (unsigned int)cli->max_xmit,
+                         BASE_SESSSETUP_BLOB_PACKET_SIZE));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+       state->max_blob_size =
+               MIN(cli->max_xmit - BASE_SESSSETUP_BLOB_PACKET_SIZE, 0xFFFF);
+
+       if (!cli_sesssetup_blob_next(state, &subreq)) {
+               tevent_req_nomem(NULL, req);
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_sesssetup_blob_done, req);
+       return req;
+}
 
-static DATA_BLOB cli_session_setup_blob_receive(struct cli_state *cli)
+static bool cli_sesssetup_blob_next(struct cli_sesssetup_blob_state *state,
+                                   struct tevent_req **psubreq)
 {
-       DATA_BLOB blob2 = data_blob_null;
-       char *p;
-       size_t len;
+       struct tevent_req *subreq;
+       uint16_t thistime;
+
+       SCVAL(state->vwv+0, 0, 0xFF);
+       SCVAL(state->vwv+0, 1, 0);
+       SSVAL(state->vwv+1, 0, 0);
+       SSVAL(state->vwv+2, 0, CLI_BUFFER_SIZE);
+       SSVAL(state->vwv+3, 0, 2);
+       SSVAL(state->vwv+4, 0, 1);
+       SIVAL(state->vwv+5, 0, 0);
+
+       thistime = MIN(state->blob.length, state->max_blob_size);
+       SSVAL(state->vwv+7, 0, thistime);
+
+       SSVAL(state->vwv+8, 0, 0);
+       SSVAL(state->vwv+9, 0, 0);
+       SIVAL(state->vwv+10, 0,
+             cli_session_setup_capabilities(state->cli)
+             | CAP_EXTENDED_SECURITY);
+
+       state->buf = (uint8_t *)talloc_memdup(state, state->blob.data,
+                                             thistime);
+       if (state->buf == NULL) {
+               return false;
+       }
+       state->blob.data += thistime;
+       state->blob.length -= thistime;
 
-       if (!cli_receive_smb(cli))
-               return blob2;
+       state->buf = smb_bytes_push_str(state->buf, cli_ucs2(state->cli),
+                                       "Unix", 5, NULL);
+       state->buf = smb_bytes_push_str(state->buf, cli_ucs2(state->cli),
+                                       "Samba", 6, NULL);
+       if (state->buf == NULL) {
+               return false;
+       }
+       subreq = cli_smb_send(state, state->ev, state->cli, SMBsesssetupX, 0,
+                             12, state->vwv,
+                             talloc_get_size(state->buf), state->buf);
+       if (subreq == NULL) {
+               return false;
+       }
+       *psubreq = subreq;
+       return true;
+}
 
-       show_msg(cli->inbuf);
+static void cli_sesssetup_blob_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_sesssetup_blob_state *state = tevent_req_data(
+               req, struct cli_sesssetup_blob_state);
+       struct cli_state *cli = state->cli;
+       uint8_t wct;
+       uint16_t *vwv;
+       uint32_t num_bytes;
+       uint8_t *bytes;
+       NTSTATUS status;
+       uint8_t *p;
+       uint16_t blob_length;
 
-       if (cli_is_error(cli) && !NT_STATUS_EQUAL(cli_nt_error(cli),
-                                                 
NT_STATUS_MORE_PROCESSING_REQUIRED)) {
-               return blob2;
+       status = cli_smb_recv(subreq, 1, &wct, &vwv, &num_bytes, &bytes);
+       if (!NT_STATUS_IS_OK(status)
+           && !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+               TALLOC_FREE(subreq);
+               tevent_req_nterror(req, status);
+               return;
        }
 
-       /* use the returned vuid from now on */
-       cli->vuid = SVAL(cli->inbuf,smb_uid);
+       state->status = status;
+       TALLOC_FREE(state->buf);
 
-       p = smb_buf(cli->inbuf);
+       state->inbuf = (char *)cli_smb_inbuf(subreq);
+       cli->vuid = SVAL(state->inbuf, smb_uid);
 
-       blob2 = data_blob(p, SVAL(cli->inbuf, smb_vwv3));
+       blob_length = SVAL(vwv+3, 0);
+       if (blob_length > num_bytes) {
+               TALLOC_FREE(subreq);
+               tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
+               return;
+       }
+       state->ret_blob = data_blob_const(bytes, blob_length);
 
-       p += blob2.length;
-       p += clistr_pull(cli->inbuf, cli->server_os, p, sizeof(fstring),
-                        -1, STR_TERMINATE);
+       p = bytes + blob_length;
+
+       p += clistr_pull(state->inbuf, cli->server_os,
+                        (char *)p, sizeof(fstring),
+                        bytes+num_bytes-p, STR_TERMINATE);
+       p += clistr_pull(state->inbuf, cli->server_type,
+                        (char *)p, sizeof(fstring),
+                        bytes+num_bytes-p, STR_TERMINATE);
+       p += clistr_pull(state->inbuf, cli->server_domain,
+                        (char *)p, sizeof(fstring),
+                        bytes+num_bytes-p, STR_TERMINATE);
 
-       /* w2k with kerberos doesn't properly null terminate this field */
-       len = smb_bufrem(cli->inbuf, p);
-       if (p + len < cli->inbuf + cli->bufsize+SAFETY_MARGIN - 2) {
-               char *end_of_buf = p + len;
+       if (strstr(cli->server_type, "Samba")) {
+               cli->is_samba = True;
+       }
 
-               SSVAL(p, len, 0);
-               /* Now it's null terminated. */
-               p += clistr_pull(cli->inbuf, cli->server_type, p, 
sizeof(fstring),
-                       -1, STR_TERMINATE);
+       if (state->blob.length != 0) {
+               TALLOC_FREE(subreq);
                /*
-                * See if there's another string. If so it's the
-                * server domain (part of the 'standard' Samba
-                * server signature).
+                * More to send
                 */
-               if (p < end_of_buf) {
-                       p += clistr_pull(cli->inbuf, cli->server_domain, p, 
sizeof(fstring),
-                               -1, STR_TERMINATE);
+               if (!cli_sesssetup_blob_next(state, &subreq)) {
+                       tevent_req_nomem(NULL, req);
+                       return;
                }
-       } else {
-               /*
-                * No room to null terminate so we can't see if there
-                * is another string (server_domain) afterwards.
-                */
-               p += clistr_pull(cli->inbuf, cli->server_type, p, 
sizeof(fstring),
-                                len, 0);
+               tevent_req_set_callback(subreq, cli_sesssetup_blob_done, req);
+               return;
        }
-       return blob2;
+       tevent_req_done(req);
 }
 
-#ifdef HAVE_KRB5
-/****************************************************************************
- Send a extended security session setup blob, returning a reply blob.
-****************************************************************************/
-
-/* The following is calculated from :
- * (smb_size-4) = 35
- * (smb_wcnt * 2) = 24 (smb_wcnt == 12 in cli_session_setup_blob_send() )
- * (strlen("Unix") + 1 + strlen("Samba") + 1) * 2 = 22 (unicode strings at
- * end of packet.
- */
-
-#define BASE_SESSSETUP_BLOB_PACKET_SIZE (35 + 24 + 22)
-
-static bool cli_session_setup_blob(struct cli_state *cli, DATA_BLOB blob)
+static NTSTATUS cli_sesssetup_blob_recv(struct tevent_req *req,
+                                       TALLOC_CTX *mem_ctx,
+                                       DATA_BLOB *pblob,
+                                       char **pinbuf)
 {
-       int32 remaining = blob.length;
-       int32 cur = 0;
-       DATA_BLOB send_blob = data_blob_null;
-       int32 max_blob_size = 0;
-       DATA_BLOB receive_blob = data_blob_null;
+       struct cli_sesssetup_blob_state *state = tevent_req_data(
+               req, struct cli_sesssetup_blob_state);
+       NTSTATUS status;
+       char *inbuf;
 
-       if (cli->max_xmit < BASE_SESSSETUP_BLOB_PACKET_SIZE + 1) {
-               DEBUG(0,("cli_session_setup_blob: cli->max_xmit too small "
-                       "(was %u, need minimum %u)\n",
-                       (unsigned int)cli->max_xmit,
-                       BASE_SESSSETUP_BLOB_PACKET_SIZE));
-               cli_set_nt_error(cli, NT_STATUS_INVALID_PARAMETER);
-               return False;
+       if (tevent_req_is_nterror(req, &status)) {
+               state->cli->vuid = 0;
+               return status;
        }
 
-       max_blob_size = cli->max_xmit - BASE_SESSSETUP_BLOB_PACKET_SIZE;
-
-       while ( remaining > 0) {
-               if (remaining >= max_blob_size) {
-                       send_blob.length = max_blob_size;
-                       remaining -= max_blob_size;
-               } else {
-                       send_blob.length = remaining; 
-                        remaining = 0;
-               }
-
-               send_blob.data =  &blob.data[cur];
-               cur += send_blob.length;
-
-               DEBUG(10, ("cli_session_setup_blob: Remaining (%u) sending (%u) 
current (%u)\n", 
-                       (unsigned int)remaining,
-                       (unsigned int)send_blob.length,
-                       (unsigned int)cur ));
-
-               if (!cli_session_setup_blob_send(cli, send_blob)) {
-                       DEBUG(0, ("cli_session_setup_blob: send failed\n"));
-                       return False;
-               }
-
-               receive_blob = cli_session_setup_blob_receive(cli);
-               data_blob_free(&receive_blob);
-
-               if (cli_is_error(cli) &&
-                               !NT_STATUS_EQUAL( cli_get_nt_error(cli), 
-                                       NT_STATUS_MORE_PROCESSING_REQUIRED)) {


-- 
Samba Shared Repository

Reply via email to