Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified vendor/current/source4/rpc_server/dcesrv_auth.c

    r414 r740  
    2424#include "rpc_server/dcerpc_server.h"
    2525#include "rpc_server/dcerpc_server_proto.h"
     26#include "rpc_server/common/proto.h"
    2627#include "librpc/rpc/dcerpc_proto.h"
    2728#include "librpc/gen_ndr/ndr_dcerpc.h"
     
    3031#include "auth/auth.h"
    3132#include "param/param.h"
     33#include "librpc/rpc/rpc_common.h"
    3234
    3335/*
     
    4345        struct dcesrv_auth *auth = &dce_conn->auth_state;
    4446        NTSTATUS status;
    45         enum ndr_err_code ndr_err;
     47        uint32_t auth_length;
    4648
    4749        if (pkt->u.bind.auth_info.length == 0) {
     
    5557        }
    5658
    57         ndr_err = ndr_pull_struct_blob(&pkt->u.bind.auth_info,
    58                                        call, NULL,
    59                                        dce_conn->auth_state.auth_info,
    60                                        (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth);
    61         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    62                 return false;
    63         }
    64 
     59        status = dcerpc_pull_auth_trailer(pkt, call, &pkt->u.bind.auth_info,
     60                                          dce_conn->auth_state.auth_info,
     61                                          &auth_length, false);
    6562        server_credentials
    6663                = cli_credentials_init(call);
     
    8077        status = samba_server_gensec_start(dce_conn, call->event_ctx,
    8178                                           call->msg_ctx,
    82                                            call->conn->dce_ctx->lp_ctx, 
     79                                           call->conn->dce_ctx->lp_ctx,
    8380                                           server_credentials,
    8481                                           NULL,
     
    8986
    9087        if (!NT_STATUS_IS_OK(status)) {
    91                 DEBUG(1, ("Failed to start GENSEC mechanism for DCERPC server: auth_type=%d, auth_level=%d: %s\n",
     88                DEBUG(3, ("Failed to start GENSEC mechanism for DCERPC server: auth_type=%d, auth_level=%d: %s\n",
    9289                          (int)auth->auth_info->auth_type,
    9390                          (int)auth->auth_info->auth_level,
     
    142139                return NT_STATUS_OK;
    143140        } else {
    144                 DEBUG(2, ("Failed to start dcesrv auth negotiate: %s\n", nt_errstr(status)));
     141                DEBUG(4, ("GENSEC mech rejected the incoming authentication at bind_ack: %s\n",
     142                          nt_errstr(status)));
    145143                return status;
    146144        }
     
    156154        struct dcesrv_connection *dce_conn = call->conn;
    157155        NTSTATUS status;
    158         enum ndr_err_code ndr_err;
     156        uint32_t auth_length;
    159157
    160158        /* We can't work without an existing gensec state, and an new blob to feed it */
     
    165163        }
    166164
    167         ndr_err = ndr_pull_struct_blob(&pkt->u.auth3.auth_info,
    168                                        call, NULL,
    169                                        dce_conn->auth_state.auth_info,
    170                                        (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth);
    171         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     165        status = dcerpc_pull_auth_trailer(pkt, call, &pkt->u.auth3.auth_info,
     166                                          dce_conn->auth_state.auth_info, &auth_length, true);
     167        if (!NT_STATUS_IS_OK(status)) {
    172168                return false;
    173169        }
     
    189185                return true;
    190186        } else {
    191                 DEBUG(4, ("dcesrv_auth_auth3: failed to authenticate: %s\n",
     187                DEBUG(4, ("GENSEC mech rejected the incoming authentication at bind_auth3: %s\n",
    192188                          nt_errstr(status)));
    193189                return false;
    194190        }
    195 
    196         return true;
    197191}
    198192
     
    206200        struct ncacn_packet *pkt = &call->pkt;
    207201        struct dcesrv_connection *dce_conn = call->conn;
    208         enum ndr_err_code ndr_err;
     202        NTSTATUS status;
     203        uint32_t auth_length;
    209204
    210205        /* on a pure interface change there is no auth blob */
     
    223218        }
    224219
    225         ndr_err = ndr_pull_struct_blob(&pkt->u.alter.auth_info,
    226                                        call, NULL,
    227                                        dce_conn->auth_state.auth_info,
    228                                        (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth);
    229         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     220        status = dcerpc_pull_auth_trailer(pkt, call, &pkt->u.alter.auth_info,
     221                                          dce_conn->auth_state.auth_info,
     222                                          &auth_length, true);
     223        if (!NT_STATUS_IS_OK(status)) {
    230224                return false;
    231225        }
     
    276270        }
    277271
    278         DEBUG(2, ("Failed to finish dcesrv auth alter_ack: %s\n", nt_errstr(status)));
     272        DEBUG(4, ("GENSEC mech rejected the incoming authentication at auth alter_ack: %s\n",
     273                  nt_errstr(status)));
    279274        return status;
    280275}
     
    287282        struct ncacn_packet *pkt = &call->pkt;
    288283        struct dcesrv_connection *dce_conn = call->conn;
    289         DATA_BLOB auth_blob;
    290284        struct dcerpc_auth auth;
    291         struct ndr_pull *ndr;
    292         NTSTATUS status;
    293         enum ndr_err_code ndr_err;
     285        NTSTATUS status;
     286        uint32_t auth_length;
    294287        size_t hdr_size = DCERPC_REQUEST_LENGTH;
    295288
     
    297290            !dce_conn->auth_state.gensec_security) {
    298291                return true;
     292        }
     293
     294        if (pkt->pfc_flags & DCERPC_PFC_FLAG_OBJECT_UUID) {
     295                hdr_size += 16;
    299296        }
    300297
     
    319316        }
    320317
    321         auth_blob.length = 8 + pkt->auth_length;
    322 
    323         /* check for a valid length */
    324         if (pkt->u.request.stub_and_verifier.length < auth_blob.length) {
    325                 return false;
    326         }
    327 
    328         auth_blob.data =
    329                 pkt->u.request.stub_and_verifier.data +
    330                 pkt->u.request.stub_and_verifier.length - auth_blob.length;
    331         pkt->u.request.stub_and_verifier.length -= auth_blob.length;
    332 
    333         /* pull the auth structure */
    334         ndr = ndr_pull_init_blob(&auth_blob, call, lp_iconv_convenience(call->conn->dce_ctx->lp_ctx));
    335         if (!ndr) {
    336                 return false;
    337         }
    338 
    339         if (!(pkt->drep[0] & DCERPC_DREP_LE)) {
    340                 ndr->flags |= LIBNDR_FLAG_BIGENDIAN;
    341         }
    342 
    343         if (pkt->pfc_flags & DCERPC_PFC_FLAG_OBJECT_UUID) {
    344                 ndr->flags |= LIBNDR_FLAG_OBJECT_PRESENT;
    345                 hdr_size += 16;
    346         }
    347 
    348         ndr_err = ndr_pull_dcerpc_auth(ndr, NDR_SCALARS|NDR_BUFFERS, &auth);
    349         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    350                 talloc_free(ndr);
    351                 return false;
    352         }
     318        status = dcerpc_pull_auth_trailer(pkt, call,
     319                                          &pkt->u.request.stub_and_verifier,
     320                                          &auth, &auth_length, false);
     321        if (!NT_STATUS_IS_OK(status)) {
     322                return false;
     323        }
     324
     325        pkt->u.request.stub_and_verifier.length -= auth_length;
    353326
    354327        /* check signature or unseal the packet */
     
    389362        /* remove the indicated amount of padding */
    390363        if (pkt->u.request.stub_and_verifier.length < auth.auth_pad_length) {
    391                 talloc_free(ndr);
    392364                return false;
    393365        }
    394366        pkt->u.request.stub_and_verifier.length -= auth.auth_pad_length;
    395         talloc_free(ndr);
    396367
    397368        return NT_STATUS_IS_OK(status);
     
    415386        /* non-signed packets are simple */
    416387        if (sig_size == 0) {
    417                 status = ncacn_push_auth(blob, call, lp_iconv_convenience(dce_conn->dce_ctx->lp_ctx), pkt, NULL);
     388                status = ncacn_push_auth(blob, call, pkt, NULL);
    418389                return NT_STATUS_IS_OK(status);
    419390        }
     
    426397        case DCERPC_AUTH_LEVEL_CONNECT:
    427398                /*
    428                  * TODO: let the gensec mech decide if it wants to generate a signature
    429                  *       that might be needed for schannel...
     399                 * TODO: let the gensec mech decide if it wants to generate a
     400                 *       signature that might be needed for schannel...
    430401                 */
    431                 status = ncacn_push_auth(blob, call, lp_iconv_convenience(dce_conn->dce_ctx->lp_ctx), pkt, NULL);
     402                status = ncacn_push_auth(blob, call, pkt, NULL);
    432403                return NT_STATUS_IS_OK(status);
    433404
    434405        case DCERPC_AUTH_LEVEL_NONE:
    435                 status = ncacn_push_auth(blob, call, lp_iconv_convenience(dce_conn->dce_ctx->lp_ctx), pkt, NULL);
     406                status = ncacn_push_auth(blob, call, pkt, NULL);
    436407                return NT_STATUS_IS_OK(status);
    437408
     
    440411        }
    441412
    442         ndr = ndr_push_init_ctx(call, lp_iconv_convenience(dce_conn->dce_ctx->lp_ctx));
     413        ndr = ndr_push_init_ctx(call);
    443414        if (!ndr) {
    444415                return false;
     
    454425        }
    455426
    456         /* pad to 16 byte multiple, match win2k3 */
     427        /* pad to 16 byte multiple in the payload portion of the
     428           packet. This matches what w2k3 does. Note that we can't use
     429           ndr_push_align() as that is relative to the start of the
     430           whole packet, whereas w2k8 wants it relative to the start
     431           of the stub */
    457432        dce_conn->auth_state.auth_info->auth_pad_length =
    458433                (16 - (pkt->u.response.stub_and_verifier.length & 15)) & 15;
    459         ndr_err = ndr_push_zero(ndr, dce_conn->auth_state.auth_info->auth_pad_length);
     434        ndr_err = ndr_push_zero(ndr,
     435                                dce_conn->auth_state.auth_info->auth_pad_length);
    460436        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    461437                return false;
     
    470446        /* add the auth verifier */
    471447        ndr_err = ndr_push_dcerpc_auth(ndr, NDR_SCALARS|NDR_BUFFERS,
    472                                       dce_conn->auth_state.auth_info);
     448                                       dce_conn->auth_state.auth_info);
    473449        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    474450                return false;
     
    514490        }
    515491
    516         if (NT_STATUS_IS_OK(status)) {
    517                 if (creds2.length != sig_size) {
    518                         DEBUG(0,("dcesrv_auth_response: creds2.length[%u] != sig_size[%u] pad[%u] stub[%u]\n",
    519                                  (unsigned)creds2.length, (uint32_t)sig_size,
    520                                  (unsigned)dce_conn->auth_state.auth_info->auth_pad_length,
    521                                  (unsigned)pkt->u.response.stub_and_verifier.length));
    522                         data_blob_free(&creds2);
    523                         status = NT_STATUS_INTERNAL_ERROR;
    524                 }
    525         }
    526 
    527         if (NT_STATUS_IS_OK(status)) {
    528                 if (!data_blob_append(call, blob, creds2.data, creds2.length)) {
    529                         status = NT_STATUS_NO_MEMORY;
    530                 }
    531                 data_blob_free(&creds2);
    532         }
    533 
    534492        if (!NT_STATUS_IS_OK(status)) {
    535493                return false;
    536494        }       
    537495
     496        if (creds2.length != sig_size) {
     497                DEBUG(3,("dcesrv_auth_response: creds2.length[%u] != sig_size[%u] pad[%u] stub[%u]\n",
     498                         (unsigned)creds2.length, (uint32_t)sig_size,
     499                         (unsigned)dce_conn->auth_state.auth_info->auth_pad_length,
     500                         (unsigned)pkt->u.response.stub_and_verifier.length));
     501                dcerpc_set_frag_length(blob, blob->length + creds2.length);
     502                dcerpc_set_auth_length(blob, creds2.length);
     503        }
     504
     505        if (!data_blob_append(call, blob, creds2.data, creds2.length)) {
     506                status = NT_STATUS_NO_MEMORY;
     507                return false;
     508        }
     509        data_blob_free(&creds2);
     510
    538511        return true;
    539512}
Note: See TracChangeset for help on using the changeset viewer.