Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/auth/auth_ntlmssp.c

    r596 r745  
    2222
    2323#include "includes.h"
     24#include "auth.h"
     25#include "../libcli/auth/ntlmssp.h"
     26#include "ntlmssp_wrap.h"
     27#include "../librpc/gen_ndr/netlogon.h"
     28#include "smbd/smbd.h"
     29
     30NTSTATUS auth_ntlmssp_steal_session_info(TALLOC_CTX *mem_ctx,
     31                                        struct auth_ntlmssp_state *auth_ntlmssp_state,
     32                                        struct auth_serversupplied_info **session_info)
     33{
     34        /* Free the current server_info user_session_key and reset it from the
     35         * current ntlmssp_state session_key */
     36        data_blob_free(&auth_ntlmssp_state->server_info->user_session_key);
     37        /* Set up the final session key for the connection */
     38        auth_ntlmssp_state->server_info->user_session_key =
     39                data_blob_talloc(
     40                        auth_ntlmssp_state->server_info,
     41                        auth_ntlmssp_state->ntlmssp_state->session_key.data,
     42                        auth_ntlmssp_state->ntlmssp_state->session_key.length);
     43        if (auth_ntlmssp_state->ntlmssp_state->session_key.length &&
     44            !auth_ntlmssp_state->server_info->user_session_key.data) {
     45                *session_info = NULL;
     46                return NT_STATUS_NO_MEMORY;
     47        }
     48        /* Steal session_info away from auth_ntlmssp_state */
     49        *session_info = talloc_move(mem_ctx, &auth_ntlmssp_state->server_info);
     50        return NT_STATUS_OK;
     51}
    2452
    2553/**
     
    2856 */
    2957
    30 static void auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
    31                                        uint8_t chal[8])
    32 {
    33         AUTH_NTLMSSP_STATE *auth_ntlmssp_state =
    34                 (AUTH_NTLMSSP_STATE *)ntlmssp_state->auth_context;
     58static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
     59                                           uint8_t chal[8])
     60{
     61        struct auth_ntlmssp_state *auth_ntlmssp_state =
     62                (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
    3563        auth_ntlmssp_state->auth_context->get_ntlm_challenge(
    3664                auth_ntlmssp_state->auth_context, chal);
     65        return NT_STATUS_OK;
    3766}
    3867
     
    4473static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
    4574{
    46         AUTH_NTLMSSP_STATE *auth_ntlmssp_state =
    47                 (AUTH_NTLMSSP_STATE *)ntlmssp_state->auth_context;
     75        struct auth_ntlmssp_state *auth_ntlmssp_state =
     76                (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
    4877        struct auth_context *auth_context = auth_ntlmssp_state->auth_context;
    4978
     
    5786static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
    5887{
    59         AUTH_NTLMSSP_STATE *auth_ntlmssp_state =
    60                 (AUTH_NTLMSSP_STATE *)ntlmssp_state->auth_context;
     88        struct auth_ntlmssp_state *auth_ntlmssp_state =
     89                (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
    6190        struct auth_context *auth_context = auth_ntlmssp_state->auth_context;
    6291
    6392        SMB_ASSERT(challenge->length == 8);
    6493
    65         auth_context->challenge = data_blob_talloc(auth_context->mem_ctx,
     94        auth_context->challenge = data_blob_talloc(auth_context,
    6695                                                   challenge->data, challenge->length);
    6796
     
    80109 */
    81110
    82 static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
    83 {
    84         AUTH_NTLMSSP_STATE *auth_ntlmssp_state =
    85                 (AUTH_NTLMSSP_STATE *)ntlmssp_state->auth_context;
    86         auth_usersupplied_info *user_info = NULL;
     111static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
     112                                            DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
     113{
     114        struct auth_ntlmssp_state *auth_ntlmssp_state =
     115                (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
     116        struct auth_usersupplied_info *user_info = NULL;
    87117        NTSTATUS nt_status;
    88118        bool username_was_mapped;
     
    91121           we need to possibly reload smb.conf if smb.conf includes depend on the machine name */
    92122
    93         set_remote_machine_name(auth_ntlmssp_state->ntlmssp_state->workstation, True);
     123        set_remote_machine_name(auth_ntlmssp_state->ntlmssp_state->client.netbios_name, True);
    94124
    95125        /* setup the string used by %U */
     
    97127        sub_set_smb_name(auth_ntlmssp_state->ntlmssp_state->user);
    98128
    99         reload_services(True);
     129        reload_services(smbd_messaging_context(), -1, True);
    100130
    101131        nt_status = make_user_info_map(&user_info,
    102132                                       auth_ntlmssp_state->ntlmssp_state->user,
    103133                                       auth_ntlmssp_state->ntlmssp_state->domain,
    104                                        auth_ntlmssp_state->ntlmssp_state->workstation,
     134                                       auth_ntlmssp_state->ntlmssp_state->client.netbios_name,
    105135                                       auth_ntlmssp_state->ntlmssp_state->lm_resp.data ? &auth_ntlmssp_state->ntlmssp_state->lm_resp : NULL,
    106136                                       auth_ntlmssp_state->ntlmssp_state->nt_resp.data ? &auth_ntlmssp_state->ntlmssp_state->nt_resp : NULL,
    107137                                       NULL, NULL, NULL,
    108                                        True);
     138                                       AUTH_PASSWORD_RESPONSE);
     139
     140        if (!NT_STATUS_IS_OK(nt_status)) {
     141                return nt_status;
     142        }
    109143
    110144        user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT;
    111 
    112         if (!NT_STATUS_IS_OK(nt_status)) {
    113                 return nt_status;
    114         }
    115145
    116146        nt_status = auth_ntlmssp_state->auth_context->check_ntlm_password(auth_ntlmssp_state->auth_context,
     
    127157        auth_ntlmssp_state->server_info->nss_token |= username_was_mapped;
    128158
    129         if (auth_ntlmssp_state->server_info->ptok == NULL) {
    130                 nt_status = create_local_token(auth_ntlmssp_state->server_info);
    131                 if (!NT_STATUS_IS_OK(nt_status)) {
    132                         DEBUG(10, ("create_local_token failed: %s\n",
    133                                    nt_errstr(nt_status)));
    134                         return nt_status;
    135                 }
    136         }
    137 
     159        nt_status = create_local_token(auth_ntlmssp_state->server_info);
     160
     161        if (!NT_STATUS_IS_OK(nt_status)) {
     162                DEBUG(10, ("create_local_token failed: %s\n",
     163                        nt_errstr(nt_status)));
     164                return nt_status;
     165        }
     166
     167        /* Clear out the session keys, and pass them to the caller.
     168         * They will not be used in this form again - instead the
     169         * NTLMSSP code will decide on the final correct session key,
     170         * and put it back here at the end of
     171         * auth_ntlmssp_steal_server_info */
    138172        if (auth_ntlmssp_state->server_info->user_session_key.length) {
    139173                DEBUG(10, ("Got NT session key of length %u\n",
    140174                        (unsigned int)auth_ntlmssp_state->server_info->user_session_key.length));
    141                 *user_session_key = data_blob_talloc(auth_ntlmssp_state->mem_ctx,
    142                                                    auth_ntlmssp_state->server_info->user_session_key.data,
    143                                                    auth_ntlmssp_state->server_info->user_session_key.length);
     175                *user_session_key = auth_ntlmssp_state->server_info->user_session_key;
     176                talloc_steal(mem_ctx, auth_ntlmssp_state->server_info->user_session_key.data);
     177                auth_ntlmssp_state->server_info->user_session_key = data_blob_null;
    144178        }
    145179        if (auth_ntlmssp_state->server_info->lm_session_key.length) {
    146180                DEBUG(10, ("Got LM session key of length %u\n",
    147181                        (unsigned int)auth_ntlmssp_state->server_info->lm_session_key.length));
    148                 *lm_session_key = data_blob_talloc(auth_ntlmssp_state->mem_ctx,
    149                                                    auth_ntlmssp_state->server_info->lm_session_key.data,
    150                                                    auth_ntlmssp_state->server_info->lm_session_key.length);
     182                *lm_session_key = auth_ntlmssp_state->server_info->lm_session_key;
     183                talloc_steal(mem_ctx, auth_ntlmssp_state->server_info->lm_session_key.data);
     184                auth_ntlmssp_state->server_info->lm_session_key = data_blob_null;
    151185        }
    152186        return nt_status;
    153187}
    154188
    155 NTSTATUS auth_ntlmssp_start(AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
     189static int auth_ntlmssp_state_destructor(void *ptr);
     190
     191NTSTATUS auth_ntlmssp_start(struct auth_ntlmssp_state **auth_ntlmssp_state)
    156192{
    157193        NTSTATUS nt_status;
    158         TALLOC_CTX *mem_ctx;
    159 
    160         mem_ctx = talloc_init("AUTH NTLMSSP context");
    161        
    162         *auth_ntlmssp_state = TALLOC_ZERO_P(mem_ctx, AUTH_NTLMSSP_STATE);
    163         if (!*auth_ntlmssp_state) {
     194        bool is_standalone;
     195        const char *netbios_name;
     196        const char *netbios_domain;
     197        const char *dns_name;
     198        char *dns_domain;
     199        struct auth_ntlmssp_state *ans;
     200        struct auth_context *auth_context;
     201
     202        if ((enum server_types)lp_server_role() == ROLE_STANDALONE) {
     203                is_standalone = true;
     204        } else {
     205                is_standalone = false;
     206        }
     207
     208        netbios_name = global_myname();
     209        netbios_domain = lp_workgroup();
     210        /* This should be a 'netbios domain -> DNS domain' mapping */
     211        dns_domain = get_mydnsdomname(talloc_tos());
     212        if (dns_domain) {
     213                strlower_m(dns_domain);
     214        }
     215        dns_name = get_mydnsfullname();
     216
     217        ans = talloc_zero(NULL, struct auth_ntlmssp_state);
     218        if (!ans) {
    164219                DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
    165                 talloc_destroy(mem_ctx);
    166220                return NT_STATUS_NO_MEMORY;
    167221        }
    168222
    169         ZERO_STRUCTP(*auth_ntlmssp_state);
    170 
    171         (*auth_ntlmssp_state)->mem_ctx = mem_ctx;
    172 
    173         if (!NT_STATUS_IS_OK(nt_status = ntlmssp_server_start(&(*auth_ntlmssp_state)->ntlmssp_state))) {
    174                 return nt_status;
    175         }
    176 
    177         if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(&(*auth_ntlmssp_state)->auth_context))) {
    178                 return nt_status;
    179         }
    180 
    181         (*auth_ntlmssp_state)->ntlmssp_state->auth_context = (*auth_ntlmssp_state);
    182         (*auth_ntlmssp_state)->ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
    183         (*auth_ntlmssp_state)->ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
    184         (*auth_ntlmssp_state)->ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
    185         (*auth_ntlmssp_state)->ntlmssp_state->check_password = auth_ntlmssp_check_password;
    186         (*auth_ntlmssp_state)->ntlmssp_state->server_role = (enum server_types)lp_server_role();
    187 
    188         return NT_STATUS_OK;
    189 }
    190 
    191 void auth_ntlmssp_end(AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
    192 {
    193         TALLOC_CTX *mem_ctx;
    194 
    195         if (*auth_ntlmssp_state == NULL) {
    196                 return;
    197         }
    198 
    199         mem_ctx = (*auth_ntlmssp_state)->mem_ctx;
    200         if ((*auth_ntlmssp_state)->ntlmssp_state) {
    201                 ntlmssp_end(&(*auth_ntlmssp_state)->ntlmssp_state);
    202         }
    203         if ((*auth_ntlmssp_state)->auth_context) {
    204                 ((*auth_ntlmssp_state)->auth_context->free)(&(*auth_ntlmssp_state)->auth_context);
    205         }
    206         if ((*auth_ntlmssp_state)->server_info) {
    207                 TALLOC_FREE((*auth_ntlmssp_state)->server_info);
    208         }
    209         talloc_destroy(mem_ctx);
    210         *auth_ntlmssp_state = NULL;
    211 }
    212 
    213 NTSTATUS auth_ntlmssp_update(AUTH_NTLMSSP_STATE *auth_ntlmssp_state,
    214                              const DATA_BLOB request, DATA_BLOB *reply)
    215 {
    216         return ntlmssp_update(auth_ntlmssp_state->ntlmssp_state, request, reply);
    217 }
     223        nt_status = ntlmssp_server_start(ans,
     224                                         is_standalone,
     225                                         netbios_name,
     226                                         netbios_domain,
     227                                         dns_name,
     228                                         dns_domain,
     229                                         &ans->ntlmssp_state);
     230        if (!NT_STATUS_IS_OK(nt_status)) {
     231                return nt_status;
     232        }
     233
     234        nt_status = make_auth_context_subsystem(talloc_tos(), &auth_context);
     235        if (!NT_STATUS_IS_OK(nt_status)) {
     236                return nt_status;
     237        }
     238        ans->auth_context = talloc_steal(ans, auth_context);
     239
     240        ans->ntlmssp_state->callback_private = ans;
     241        ans->ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
     242        ans->ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
     243        ans->ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
     244        ans->ntlmssp_state->check_password = auth_ntlmssp_check_password;
     245
     246        talloc_set_destructor((TALLOC_CTX *)ans, auth_ntlmssp_state_destructor);
     247
     248        *auth_ntlmssp_state = ans;
     249        return NT_STATUS_OK;
     250}
     251
     252static int auth_ntlmssp_state_destructor(void *ptr)
     253{
     254        struct auth_ntlmssp_state *ans;
     255
     256        ans = talloc_get_type(ptr, struct auth_ntlmssp_state);
     257
     258        TALLOC_FREE(ans->server_info);
     259        TALLOC_FREE(ans->ntlmssp_state);
     260        return 0;
     261}
Note: See TracChangeset for help on using the changeset viewer.