Ignore:
Timestamp:
Jun 9, 2016, 2:17:22 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: apply latest security patches to vendor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/libcli/auth/smbencrypt.c

    r917 r919  
    2727#include "../lib/crypto/crypto.h"
    2828#include "../libcli/auth/libcli_auth.h"
    29 #include "../librpc/gen_ndr/ntlmssp.h"
     29#include "../librpc/gen_ndr/ndr_ntlmssp.h"
    3030
    3131void SMBencrypt_hash(const uint8_t lm_hash[16], const uint8_t *c8, uint8_t p24[24])
     
    356356
    357357        /* Deliberately ignore return here.. */
    358         (void)msrpc_gen(mem_ctx, &names_blob,
    359                   "aaa",
    360                   MsvAvNbDomainName, domain,
    361                   MsvAvNbComputerName, hostname,
    362                   MsvAvEOL, "");
     358        if (hostname != NULL) {
     359                (void)msrpc_gen(mem_ctx, &names_blob,
     360                          "aaa",
     361                          MsvAvNbDomainName, domain,
     362                          MsvAvNbComputerName, hostname,
     363                          MsvAvEOL, "");
     364        } else {
     365                (void)msrpc_gen(mem_ctx, &names_blob,
     366                          "aa",
     367                          MsvAvNbDomainName, domain,
     368                          MsvAvEOL, "");
     369        }
    363370        return names_blob;
    364371}
     
    516523}
    517524
     525NTSTATUS NTLMv2_RESPONSE_verify_netlogon_creds(const char *account_name,
     526                        const char *account_domain,
     527                        const DATA_BLOB response,
     528                        const struct netlogon_creds_CredentialState *creds,
     529                        const char *workgroup)
     530{
     531        TALLOC_CTX *frame = NULL;
     532        /* RespType + HiRespType */
     533        static const char *magic = "\x01\x01";
     534        int cmp;
     535        struct NTLMv2_RESPONSE v2_resp;
     536        enum ndr_err_code err;
     537        const struct AV_PAIR *av_nb_cn = NULL;
     538        const struct AV_PAIR *av_nb_dn = NULL;
     539
     540        if (response.length < 48) {
     541                /*
     542                 * NTLMv2_RESPONSE has at least 48 bytes.
     543                 */
     544                return NT_STATUS_OK;
     545        }
     546
     547        cmp = memcmp(response.data + 16, magic, 2);
     548        if (cmp != 0) {
     549                /*
     550                 * It doesn't look like a valid NTLMv2_RESPONSE
     551                 */
     552                return NT_STATUS_OK;
     553        }
     554
     555        frame = talloc_stackframe();
     556
     557        err = ndr_pull_struct_blob(&response, frame, &v2_resp,
     558                (ndr_pull_flags_fn_t)ndr_pull_NTLMv2_RESPONSE);
     559        if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
     560                NTSTATUS status;
     561                status = ndr_map_error2ntstatus(err);
     562                DEBUG(2,("Failed to parse NTLMv2_RESPONSE "
     563                         "length %u - %s - %s\n",
     564                         (unsigned)response.length,
     565                         ndr_map_error2string(err),
     566                         nt_errstr(status)));
     567                dump_data(2, response.data, response.length);
     568                TALLOC_FREE(frame);
     569                return status;
     570        }
     571
     572        if (DEBUGLVL(10)) {
     573                NDR_PRINT_DEBUG(NTLMv2_RESPONSE, &v2_resp);
     574        }
     575
     576        /*
     577         * Make sure the netbios computer name in the
     578         * NTLMv2_RESPONSE matches the computer name
     579         * in the secure channel credentials for workstation
     580         * trusts.
     581         *
     582         * And the netbios domain name matches our
     583         * workgroup.
     584         *
     585         * This prevents workstations from requesting
     586         * the session key of NTLMSSP sessions of clients
     587         * to other hosts.
     588         */
     589        if (creds->secure_channel_type == SEC_CHAN_WKSTA) {
     590                av_nb_cn = ndr_ntlmssp_find_av(&v2_resp.Challenge.AvPairs,
     591                                               MsvAvNbComputerName);
     592                av_nb_dn = ndr_ntlmssp_find_av(&v2_resp.Challenge.AvPairs,
     593                                               MsvAvNbDomainName);
     594        }
     595
     596        if (av_nb_cn != NULL) {
     597                const char *v = NULL;
     598                char *a = NULL;
     599                size_t len;
     600
     601                v = av_nb_cn->Value.AvNbComputerName;
     602
     603                a = talloc_strdup(frame, creds->account_name);
     604                if (a == NULL) {
     605                        TALLOC_FREE(frame);
     606                        return NT_STATUS_NO_MEMORY;
     607                }
     608                len = strlen(a);
     609                if (len > 0 && a[len - 1] == '$') {
     610                        a[len - 1] = '\0';
     611                }
     612
     613#ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */
     614                cmp = strcasecmp_m(a, v);
     615#else /* smbd */
     616                cmp = StrCaseCmp(a, v);
     617#endif
     618                if (cmp != 0) {
     619                        DEBUG(2,("%s: NTLMv2_RESPONSE with "
     620                                 "NbComputerName[%s] rejected "
     621                                 "for user[%s\\%s] "
     622                                 "against SEC_CHAN_WKSTA[%s/%s] "
     623                                 "in workgroup[%s]\n",
     624                                 __func__, v,
     625                                 account_domain,
     626                                 account_name,
     627                                 creds->computer_name,
     628                                 creds->account_name,
     629                                 workgroup));
     630                        TALLOC_FREE(frame);
     631                        return NT_STATUS_LOGON_FAILURE;
     632                }
     633        }
     634        if (av_nb_dn != NULL) {
     635                const char *v = NULL;
     636
     637                v = av_nb_dn->Value.AvNbDomainName;
     638
     639#ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */
     640                cmp = strcasecmp_m(workgroup, v);
     641#else /* smbd */
     642                cmp = StrCaseCmp(workgroup, v);
     643#endif
     644                if (cmp != 0) {
     645                        DEBUG(2,("%s: NTLMv2_RESPONSE with "
     646                                 "NbDomainName[%s] rejected "
     647                                 "for user[%s\\%s] "
     648                                 "against SEC_CHAN_WKSTA[%s/%s] "
     649                                 "in workgroup[%s]\n",
     650                                 __func__, v,
     651                                 account_domain,
     652                                 account_name,
     653                                 creds->computer_name,
     654                                 creds->account_name,
     655                                 workgroup));
     656                        TALLOC_FREE(frame);
     657                        return NT_STATUS_LOGON_FAILURE;
     658                }
     659        }
     660
     661        TALLOC_FREE(frame);
     662        return NT_STATUS_OK;
     663}
     664
    518665/***********************************************************
    519666 encode a password buffer with a unicode password.  The buffer
Note: See TracChangeset for help on using the changeset viewer.