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

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/negprot.c

    r618 r740  
    44   Copyright (C) Andrew Tridgell 1992-1998
    55   Copyright (C) Volker Lendecke 2007
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223#include "smbd/globals.h"
    2324#include "../libcli/auth/spnego.h"
     25#include "serverid.h"
     26#include "auth.h"
     27#include "messages.h"
     28#include "smbprofile.h"
    2429
    2530extern fstring remote_proto;
    2631
    27 static void get_challenge(uint8 buff[8])
     32static void get_challenge(struct smbd_server_connection *sconn, uint8 buff[8])
    2833{
    2934        NTSTATUS nt_status;
    30         struct smbd_server_connection *sconn = smbd_server_conn;
    3135
    3236        /* We might be called more than once, multiple negprots are
     
    3539                DEBUG(3, ("get challenge: is this a secondary negprot? "
    3640                          "sconn->negprot.auth_context is non-NULL!\n"));
    37                         sconn->smb1.negprot.auth_context->free(
    38                                 &sconn->smb1.negprot.auth_context);
     41                        TALLOC_FREE(sconn->smb1.negprot.auth_context);
    3942        }
    4043
    4144        DEBUG(10, ("get challenge: creating negprot_global_auth_context\n"));
    4245        nt_status = make_auth_context_subsystem(
    43                 &sconn->smb1.negprot.auth_context);
     46                sconn, &sconn->smb1.negprot.auth_context);
    4447        if (!NT_STATUS_IS_OK(nt_status)) {
    4548                DEBUG(0, ("make_auth_context_subsystem returned %s",
     
    9396        int secword=0;
    9497        time_t t = time(NULL);
    95         struct smbd_server_connection *sconn = smbd_server_conn;
     98        struct smbd_server_connection *sconn = req->sconn;
    9699
    97100        sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
     
    110113        /* Create a token value and add it to the outgoing packet. */
    111114        if (sconn->smb1.negprot.encrypted_passwords) {
    112                 get_challenge((uint8 *)smb_buf(req->outbuf));
     115                get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
    113116                SSVAL(req->outbuf,smb_vwv11, 8);
    114117        }
     
    140143        int secword=0;
    141144        time_t t = time(NULL);
    142         struct smbd_server_connection *sconn = smbd_server_conn;
     145        struct smbd_server_connection *sconn = req->sconn;
    143146
    144147        sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
    145  
     148
    146149        if (lp_security()>=SEC_USER) {
    147150                secword |= NEGOTIATE_SECURITY_USER_LEVEL;
     
    159162        /* Create a token value and add it to the outgoing packet. */
    160163        if (sconn->smb1.negprot.encrypted_passwords) {
    161                 get_challenge((uint8 *)smb_buf(req->outbuf));
     164                get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
    162165                SSVAL(req->outbuf,smb_vwv11, 8);
    163166        }
     
    179182****************************************************************************/
    180183
    181 DATA_BLOB negprot_spnego(void)
     184DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn)
    182185{
    183         DATA_BLOB blob;
     186        DATA_BLOB blob = data_blob_null;
     187        DATA_BLOB blob_out = data_blob_null;
    184188        nstring dos_name;
    185189        fstring unix_name;
     
    187191        size_t slen;
    188192#endif
    189         char guid[17];
    190193        const char *OIDs_krb5[] = {OID_KERBEROS5,
    191194                                   OID_KERBEROS5_OLD,
    192195                                   OID_NTLMSSP,
    193196                                   NULL};
    194         const char *OIDs_plain[] = {OID_NTLMSSP, NULL};
    195         struct smbd_server_connection *sconn = smbd_server_conn;
     197        const char *OIDs_ntlm[] = {OID_NTLMSSP, NULL};
    196198
    197199        sconn->smb1.negprot.spnego = true;
    198 
    199         memset(guid, '\0', sizeof(guid));
    200 
    201         safe_strcpy(unix_name, global_myname(), sizeof(unix_name)-1);
    202         strlower_m(unix_name);
    203         push_ascii_nstring(dos_name, unix_name);
    204         safe_strcpy(guid, dos_name, sizeof(guid)-1);
    205 
    206 #ifdef DEVELOPER
    207         /* Fix valgrind 'uninitialized bytes' issue. */
    208         slen = strlen(dos_name);
    209         if (slen < sizeof(guid)) {
    210                 memset(guid+slen, '\0', sizeof(guid) - slen);
    211         }
    212 #endif
    213 
    214200        /* strangely enough, NT does not sent the single OID NTLMSSP when
    215201           not a ADS member, it sends no OIDs at all
     
    231217#else
    232218                /* Code for standalone WXP client */
    233                 blob = spnego_gen_negTokenInit(guid, OIDs_plain, "NONE");
     219                blob = spnego_gen_negTokenInit(ctx, OIDs_ntlm, NULL, "NONE");
    234220#endif
     221        } else if (!lp_send_spnego_principal()) {
     222                /* By default, Windows 2008 and later sends not_defined_in_RFC4178@please_ignore */
     223                blob = spnego_gen_negTokenInit(ctx, OIDs_krb5, NULL, ADS_IGNORE_PRINCIPAL);
    235224        } else {
    236225                fstring myname;
     
    242231                        return data_blob_null;
    243232                }
    244                 blob = spnego_gen_negTokenInit(guid, OIDs_krb5, host_princ_s);
     233                blob = spnego_gen_negTokenInit(ctx, OIDs_krb5, NULL, host_princ_s);
    245234                SAFE_FREE(host_princ_s);
    246235        }
    247236
    248         return blob;
     237        if (blob.length == 0 || blob.data == NULL) {
     238                return data_blob_null;
     239        }
     240
     241        blob_out = data_blob_talloc(ctx, NULL, 16 + blob.length);
     242        if (blob_out.data == NULL) {
     243                data_blob_free(&blob);
     244                return data_blob_null;
     245        }
     246
     247        memset(blob_out.data, '\0', 16);
     248
     249        safe_strcpy(unix_name, global_myname(), sizeof(unix_name)-1);
     250        strlower_m(unix_name);
     251        push_ascii_nstring(dos_name, unix_name);
     252        strlcpy((char *)blob_out.data, dos_name, 17);
     253
     254#ifdef DEVELOPER
     255        /* Fix valgrind 'uninitialized bytes' issue. */
     256        slen = strlen(dos_name);
     257        if (slen < 16) {
     258                memset(blob_out.data+slen, '\0', 16 - slen);
     259        }
     260#endif
     261
     262        memcpy(&blob_out.data[16], blob.data, blob.length);
     263
     264        data_blob_free(&blob);
     265
     266        return blob_out;
    249267}
    250268
     
    260278
    261279        int secword=0;
    262         char *p, *q;
    263280        bool negotiate_spnego = False;
    264         time_t t = time(NULL);
     281        struct timespec ts;
    265282        ssize_t ret;
    266         struct smbd_server_connection *sconn = smbd_server_conn;
     283        struct smbd_server_connection *sconn = req->sconn;
    267284
    268285        sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
     
    284301        /* do spnego in user level security if the client
    285302           supports it and we can do encrypted passwords */
    286        
     303
    287304        if (sconn->smb1.negprot.encrypted_passwords &&
    288305            (lp_security() != SEC_SHARE) &&
     
    297314                      req->flags2 | FLAGS2_EXTENDED_SECURITY);
    298315        }
    299        
     316
    300317        capabilities |= CAP_NT_SMBS|CAP_RPC_REMOTE_APIS|CAP_UNICODE;
    301318
     
    303320                capabilities |= CAP_UNIX;
    304321        }
    305        
     322
    306323        if (lp_large_readwrite() && (SMB_OFF_T_BITS == 64))
    307324                capabilities |= CAP_LARGE_READX|CAP_LARGE_WRITEX|CAP_W2K_SMBS;
    308        
     325
    309326        if (SMB_OFF_T_BITS == 64)
    310327                capabilities |= CAP_LARGE_FILES;
     
    312329        if (lp_readraw() && lp_writeraw())
    313330                capabilities |= CAP_RAW_MODE;
    314        
     331
    315332        if (lp_nt_status_support())
    316333                capabilities |= CAP_STATUS32;
    317        
     334
    318335        if (lp_host_msdfs())
    319336                capabilities |= CAP_DFS;
    320        
     337
    321338        if (lp_security() >= SEC_USER) {
    322339                secword |= NEGOTIATE_SECURITY_USER_LEVEL;
     
    333350                        if (lp_server_signing() == Required)
    334351                                secword |=NEGOTIATE_SECURITY_SIGNATURES_REQUIRED;
    335                         srv_set_signing_negotiated(smbd_server_conn);
     352                        srv_set_signing_negotiated(sconn);
    336353                } else {
    337354                        DEBUG(0,("reply_nt1: smb signing is incompatible with share level security !\n"));
     
    344361        SSVAL(req->outbuf,smb_vwv0,choice);
    345362        SCVAL(req->outbuf,smb_vwv1,secword);
    346        
     363
    347364        set_Protocol(PROTOCOL_NT1);
    348        
     365
    349366        SSVAL(req->outbuf,smb_vwv1+1,lp_maxmux()); /* maxmpx */
    350367        SSVAL(req->outbuf,smb_vwv2+1,1); /* num vcs */
     
    354371        SIVAL(req->outbuf,smb_vwv7+1,sys_getpid()); /* session key */
    355372        SIVAL(req->outbuf,smb_vwv9+1,capabilities); /* capabilities */
    356         put_long_date((char *)req->outbuf+smb_vwv11+1,t);
    357         SSVALS(req->outbuf,smb_vwv15+1,set_server_zone_offset(t)/60);
    358        
    359         p = q = smb_buf(req->outbuf);
     373        clock_gettime(CLOCK_REALTIME,&ts);
     374        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,(char *)req->outbuf+smb_vwv11+1,ts);
     375        SSVALS(req->outbuf,smb_vwv15+1,set_server_zone_offset(ts.tv_sec)/60);
     376
    360377        if (!negotiate_spnego) {
    361378                /* Create a token value and add it to the outgoing packet. */
     
    364381                        /* note that we do not send a challenge at all if
    365382                           we are using plaintext */
    366                         get_challenge(chal);
     383                        get_challenge(sconn, chal);
    367384                        ret = message_push_blob(
    368385                                &req->outbuf, data_blob_const(chal, sizeof(chal)));
     
    373390                        }
    374391                        SCVAL(req->outbuf, smb_vwv16+1, ret);
    375                         p += ret;
    376392                }
    377393                ret = message_push_string(&req->outbuf, lp_workgroup(),
     
    379395                                          |STR_NOALIGN);
    380396                if (ret == -1) {
    381                         DEBUG(0, ("Could not push challenge\n"));
     397                        DEBUG(0, ("Could not push workgroup string\n"));
    382398                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    383399                        return;
    384400                }
    385                 p += ret;
    386401                DEBUG(3,("not using SPNEGO\n"));
    387402        } else {
    388                 DATA_BLOB spnego_blob = negprot_spnego();
     403                DATA_BLOB spnego_blob = negprot_spnego(req, req->sconn);
    389404
    390405                if (spnego_blob.data == NULL) {
     
    399414                        return;
    400415                }
    401                 p += ret;
    402416                data_blob_free(&spnego_blob);
    403417
     
    405419                DEBUG(3,("using SPNEGO\n"));
    406420        }
    407        
    408         SSVAL(req->outbuf,smb_vwv17, p - q); /* length of challenge+domain
    409                                               * strings */
    410421
    411422        return;
     
    481492  *  Win2K added by matty 17/7/99
    482493  */
    483  
     494
    484495#define ARCH_WFWG     0x3      /* This is a fudge because WfWg is like Win95 */
    485496#define ARCH_WIN95    0x2
     
    490501#define ARCH_CIFSFS   0x40
    491502#define ARCH_VISTA    0x8C     /* Vista is like XP/2K */
    492  
     503
    493504#define ARCH_ALL      0x7F
    494  
     505
    495506/* List of supported protocols, most desired first */
    496507static const struct {
     
    530541        int i;
    531542        size_t converted_size;
    532         struct smbd_server_connection *sconn = smbd_server_conn;
     543        struct smbd_server_connection *sconn = req->sconn;
    533544
    534545        START_PROFILE(SMBnegprot);
     
    661672                break;
    662673        }
    663  
     674
    664675        /* possibly reload - change of architecture */
    665         reload_services(True);     
    666        
     676        reload_services(sconn->msg_ctx, sconn->sock, True);
     677
    667678        /* moved from the netbios session setup code since we don't have that
    668679           when the client connects to port 445.  Of course there is a small
    669680           window where we are listening to messages   -- jerry */
    670681
    671         claim_connection(
    672                 NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
    673    
     682        serverid_register(sconn_server_id(sconn),
     683                          FLAG_MSG_GENERAL|FLAG_MSG_SMBD
     684                          |FLAG_MSG_PRINT_GENERAL);
     685
    674686        /* Check for protocols, most desirable first */
    675687        for (protocol = 0; supported_protocols[protocol].proto_name; protocol++) {
     
    685697                        break;
    686698        }
    687  
     699
    688700        if(choice != -1) {
    689701                fstrcpy(remote_proto,supported_protocols[protocol].short_name);
    690                 reload_services(True);         
     702                reload_services(sconn->msg_ctx, sconn->sock, True);
    691703                supported_protocols[protocol].proto_reply_fn(req, choice);
    692704                DEBUG(3,("Selected protocol %s\n",supported_protocols[protocol].proto_name));
     
    696708                SSVAL(req->outbuf, smb_vwv0, choice);
    697709        }
    698  
     710
    699711        DEBUG( 5, ( "negprot index=%d\n", choice ) );
    700712
Note: See TracChangeset for help on using the changeset viewer.