Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

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

    r746 r988  
    2222#include "smbd/smbd.h"
    2323#include "smbd/globals.h"
    24 #include "../libcli/auth/spnego.h"
    2524#include "serverid.h"
    2625#include "auth.h"
    2726#include "messages.h"
    2827#include "smbprofile.h"
     28#include "auth/gensec/gensec.h"
     29#include "../libcli/smb/smb_signing.h"
    2930
    3031extern fstring remote_proto;
    3132
    32 static void get_challenge(struct smbd_server_connection *sconn, uint8 buff[8])
     33static void get_challenge(struct smbXsrv_connection *xconn, uint8_t buff[8])
    3334{
    3435        NTSTATUS nt_status;
     
    3637        /* We might be called more than once, multiple negprots are
    3738         * permitted */
    38         if (sconn->smb1.negprot.auth_context) {
     39        if (xconn->smb1.negprot.auth_context) {
    3940                DEBUG(3, ("get challenge: is this a secondary negprot? "
    4041                          "sconn->negprot.auth_context is non-NULL!\n"));
    41                         TALLOC_FREE(sconn->smb1.negprot.auth_context);
     42                TALLOC_FREE(xconn->smb1.negprot.auth_context);
    4243        }
    4344
    4445        DEBUG(10, ("get challenge: creating negprot_global_auth_context\n"));
    45         nt_status = make_auth_context_subsystem(
    46                 sconn, &sconn->smb1.negprot.auth_context);
     46        nt_status = make_auth4_context(
     47                xconn, &xconn->smb1.negprot.auth_context);
    4748        if (!NT_STATUS_IS_OK(nt_status)) {
    4849                DEBUG(0, ("make_auth_context_subsystem returned %s",
     
    5152        }
    5253        DEBUG(10, ("get challenge: getting challenge\n"));
    53         sconn->smb1.negprot.auth_context->get_ntlm_challenge(
    54                 sconn->smb1.negprot.auth_context, buff);
    55 }
    56 
    57 /****************************************************************************
    58  Reply for the core protocol.
    59 ****************************************************************************/
    60 
    61 static void reply_corep(struct smb_request *req, uint16 choice)
    62 {
    63         reply_outbuf(req, 1, 0);
    64         SSVAL(req->outbuf, smb_vwv0, choice);
    65 
    66         set_Protocol(PROTOCOL_CORE);
    67 }
    68 
    69 /****************************************************************************
    70  Reply for the coreplus protocol.
    71 ****************************************************************************/
    72 
    73 static void reply_coreplus(struct smb_request *req, uint16 choice)
    74 {
    75         int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
    76 
    77         reply_outbuf(req, 13, 0);
    78 
    79         SSVAL(req->outbuf,smb_vwv0,choice);
    80         SSVAL(req->outbuf,smb_vwv5,raw); /* tell redirector we support
    81                         readbraw and writebraw (possibly) */
    82         /* Reply, SMBlockread, SMBwritelock supported. */
    83         SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
    84         SSVAL(req->outbuf,smb_vwv1,0x1); /* user level security, don't
    85                                           * encrypt */
    86         set_Protocol(PROTOCOL_COREPLUS);
     54        xconn->smb1.negprot.auth_context->get_ntlm_challenge(
     55                xconn->smb1.negprot.auth_context, buff);
    8756}
    8857
     
    9160****************************************************************************/
    9261
    93 static void reply_lanman1(struct smb_request *req, uint16 choice)
     62static void reply_lanman1(struct smb_request *req, uint16_t choice)
    9463{
    95         int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
    9664        int secword=0;
    9765        time_t t = time(NULL);
    98         struct smbd_server_connection *sconn = req->sconn;
    99 
    100         sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
    101 
    102         if (lp_security()>=SEC_USER) {
    103                 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
    104         }
    105         if (sconn->smb1.negprot.encrypted_passwords) {
     66        struct smbXsrv_connection *xconn = req->xconn;
     67        uint16_t raw;
     68        if (lp_async_smb_echo_handler()) {
     69                raw = 0;
     70        } else {
     71                raw = (lp_read_raw()?1:0) | (lp_write_raw()?2:0);
     72        }
     73
     74        xconn->smb1.negprot.encrypted_passwords = lp_encrypt_passwords();
     75
     76        secword |= NEGOTIATE_SECURITY_USER_LEVEL;
     77        if (xconn->smb1.negprot.encrypted_passwords) {
    10678                secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
    10779        }
    10880
    109         reply_outbuf(req, 13, sconn->smb1.negprot.encrypted_passwords?8:0);
     81        reply_outbuf(req, 13, xconn->smb1.negprot.encrypted_passwords?8:0);
    11082
    11183        SSVAL(req->outbuf,smb_vwv0,choice);
    11284        SSVAL(req->outbuf,smb_vwv1,secword);
    11385        /* Create a token value and add it to the outgoing packet. */
    114         if (sconn->smb1.negprot.encrypted_passwords) {
    115                 get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
     86        if (xconn->smb1.negprot.encrypted_passwords) {
     87                get_challenge(xconn, (uint8_t *)smb_buf(req->outbuf));
    11688                SSVAL(req->outbuf,smb_vwv11, 8);
    11789        }
    11890
    119         set_Protocol(PROTOCOL_LANMAN1);
     91        smbXsrv_connection_init_tables(xconn, PROTOCOL_LANMAN1);
    12092
    12193        /* Reply, SMBlockread, SMBwritelock supported. */
    122         SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
    123         SSVAL(req->outbuf,smb_vwv2,sconn->smb1.negprot.max_recv);
    124         SSVAL(req->outbuf,smb_vwv3,lp_maxmux()); /* maxmux */
    125         SSVAL(req->outbuf,smb_vwv4,1);
    126         SSVAL(req->outbuf,smb_vwv5,raw); /* tell redirector we support
     94        SCVAL(req->outbuf,smb_flg, FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
     95        SSVAL(req->outbuf,smb_vwv2, xconn->smb1.negprot.max_recv);
     96        SSVAL(req->outbuf,smb_vwv3, lp_max_mux()); /* maxmux */
     97        SSVAL(req->outbuf,smb_vwv4, 1);
     98        SSVAL(req->outbuf,smb_vwv5, raw); /* tell redirector we support
    12799                readbraw writebraw (possibly) */
    128         SIVAL(req->outbuf,smb_vwv6,sys_getpid());
     100        SIVAL(req->outbuf,smb_vwv6, getpid());
    129101        SSVAL(req->outbuf,smb_vwv10, set_server_zone_offset(t)/60);
    130102
     
    138110****************************************************************************/
    139111
    140 static void reply_lanman2(struct smb_request *req, uint16 choice)
     112static void reply_lanman2(struct smb_request *req, uint16_t choice)
    141113{
    142         int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
    143114        int secword=0;
    144115        time_t t = time(NULL);
    145         struct smbd_server_connection *sconn = req->sconn;
    146 
    147         sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
    148 
    149         if (lp_security()>=SEC_USER) {
    150                 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
    151         }
    152         if (sconn->smb1.negprot.encrypted_passwords) {
     116        struct smbXsrv_connection *xconn = req->xconn;
     117        uint16_t raw;
     118        if (lp_async_smb_echo_handler()) {
     119                raw = 0;
     120        } else {
     121                raw = (lp_read_raw()?1:0) | (lp_write_raw()?2:0);
     122        }
     123
     124        xconn->smb1.negprot.encrypted_passwords = lp_encrypt_passwords();
     125
     126        secword |= NEGOTIATE_SECURITY_USER_LEVEL;
     127        if (xconn->smb1.negprot.encrypted_passwords) {
    153128                secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
    154129        }
    155130
    156         reply_outbuf(req, 13, sconn->smb1.negprot.encrypted_passwords?8:0);
    157 
    158         SSVAL(req->outbuf,smb_vwv0,choice);
    159         SSVAL(req->outbuf,smb_vwv1,secword);
    160         SIVAL(req->outbuf,smb_vwv6,sys_getpid());
     131        reply_outbuf(req, 13, xconn->smb1.negprot.encrypted_passwords?8:0);
     132
     133        SSVAL(req->outbuf,smb_vwv0, choice);
     134        SSVAL(req->outbuf,smb_vwv1, secword);
     135        SIVAL(req->outbuf,smb_vwv6, getpid());
    161136
    162137        /* Create a token value and add it to the outgoing packet. */
    163         if (sconn->smb1.negprot.encrypted_passwords) {
    164                 get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
     138        if (xconn->smb1.negprot.encrypted_passwords) {
     139                get_challenge(xconn, (uint8_t *)smb_buf(req->outbuf));
    165140                SSVAL(req->outbuf,smb_vwv11, 8);
    166141        }
    167142
    168         set_Protocol(PROTOCOL_LANMAN2);
     143        smbXsrv_connection_init_tables(xconn, PROTOCOL_LANMAN2);
    169144
    170145        /* Reply, SMBlockread, SMBwritelock supported. */
    171146        SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
    172         SSVAL(req->outbuf,smb_vwv2,sconn->smb1.negprot.max_recv);
    173         SSVAL(req->outbuf,smb_vwv3,lp_maxmux());
     147        SSVAL(req->outbuf,smb_vwv2,xconn->smb1.negprot.max_recv);
     148        SSVAL(req->outbuf,smb_vwv3,lp_max_mux());
    174149        SSVAL(req->outbuf,smb_vwv4,1);
    175150        SSVAL(req->outbuf,smb_vwv5,raw); /* readbraw and/or writebraw */
     
    182157****************************************************************************/
    183158
    184 DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn)
     159DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbXsrv_connection *xconn)
    185160{
    186161        DATA_BLOB blob = data_blob_null;
     
    188163        nstring dos_name;
    189164        fstring unix_name;
     165        NTSTATUS status;
    190166#ifdef DEVELOPER
    191167        size_t slen;
    192168#endif
    193         const char *OIDs_krb5[] = {OID_KERBEROS5,
    194                                    OID_KERBEROS5_OLD,
    195                                    OID_NTLMSSP,
    196                                    NULL};
    197         const char *OIDs_ntlm[] = {OID_NTLMSSP, NULL};
    198 
    199         sconn->smb1.negprot.spnego = true;
     169        struct gensec_security *gensec_security;
     170
     171        /* See if we can get an SPNEGO blob */
     172        status = auth_generic_prepare(talloc_tos(),
     173                                      xconn->remote_address,
     174                                      &gensec_security);
     175        if (NT_STATUS_IS_OK(status)) {
     176                status = gensec_start_mech_by_oid(gensec_security, GENSEC_OID_SPNEGO);
     177                if (NT_STATUS_IS_OK(status)) {
     178                        status = gensec_update(gensec_security, ctx,
     179                                               data_blob_null, &blob);
     180                        /* If we get the list of OIDs, the 'OK' answer
     181                         * is NT_STATUS_MORE_PROCESSING_REQUIRED */
     182                        if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
     183                                DEBUG(0, ("Failed to start SPNEGO handler for negprot OID list!\n"));
     184                                blob = data_blob_null;
     185                        }
     186                }
     187                TALLOC_FREE(gensec_security);
     188        }
     189
     190        xconn->smb1.negprot.spnego = true;
     191
    200192        /* strangely enough, NT does not sent the single OID NTLMSSP when
    201193           not a ADS member, it sends no OIDs at all
     
    211203        */
    212204
    213         if (lp_security() != SEC_ADS && !USE_KERBEROS_KEYTAB) {
    214 #if 0
    215                 /* Code for PocketPC client */
    216                 blob = data_blob(guid, 16);
    217 #else
    218                 /* Code for standalone WXP client */
    219                 blob = spnego_gen_negTokenInit(ctx, OIDs_ntlm, NULL, "NONE");
    220 #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);
    224         } else {
    225                 fstring myname;
    226                 char *host_princ_s = NULL;
    227                 name_to_fqdn(myname, global_myname());
    228                 strlower_m(myname);
    229                 if (asprintf(&host_princ_s, "cifs/%s@%s", myname, lp_realm())
    230                     == -1) {
    231                         return data_blob_null;
    232                 }
    233                 blob = spnego_gen_negTokenInit(ctx, OIDs_krb5, NULL, host_princ_s);
    234                 SAFE_FREE(host_princ_s);
    235         }
    236 
    237205        if (blob.length == 0 || blob.data == NULL) {
    238206                return data_blob_null;
     
    247215        memset(blob_out.data, '\0', 16);
    248216
    249         safe_strcpy(unix_name, global_myname(), sizeof(unix_name)-1);
    250         strlower_m(unix_name);
     217        checked_strlcpy(unix_name, lp_netbios_name(), sizeof(unix_name));
     218        (void)strlower_m(unix_name);
    251219        push_ascii_nstring(dos_name, unix_name);
    252220        strlcpy((char *)blob_out.data, dos_name, 17);
     
    271239****************************************************************************/
    272240
    273 static void reply_nt1(struct smb_request *req, uint16 choice)
     241static void reply_nt1(struct smb_request *req, uint16_t choice)
    274242{
    275243        /* dual names + lock_and_read + nt SMBs + remote API calls */
     
    281249        struct timespec ts;
    282250        ssize_t ret;
    283         struct smbd_server_connection *sconn = req->sconn;
    284 
    285         sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
     251        struct smbXsrv_connection *xconn = req->xconn;
     252        bool signing_desired = false;
     253        bool signing_required = false;
     254
     255        xconn->smb1.negprot.encrypted_passwords = lp_encrypt_passwords();
    286256
    287257        /* Check the flags field to see if this is Vista.
     
    290260
    291261        if ( (req->flags2 & FLAGS2_EXTENDED_SECURITY) &&
    292                 ((req->flags2 & FLAGS2_UNKNOWN_BIT4) == 0) )
     262                ((req->flags2 & FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED) == 0) )
    293263        {
    294                 if (get_remote_arch() != RA_SAMBA) {
     264                if ((get_remote_arch() != RA_SAMBA) &&
     265                                (get_remote_arch() != RA_CIFSFS)) {
    295266                        set_remote_arch( RA_VISTA );
    296267                }
     
    302273           supports it and we can do encrypted passwords */
    303274
    304         if (sconn->smb1.negprot.encrypted_passwords &&
    305             (lp_security() != SEC_SHARE) &&
     275        if (xconn->smb1.negprot.encrypted_passwords &&
    306276            lp_use_spnego() &&
    307277            (req->flags2 & FLAGS2_EXTENDED_SECURITY)) {
     
    315285        }
    316286
    317         capabilities |= CAP_NT_SMBS|CAP_RPC_REMOTE_APIS|CAP_UNICODE;
     287        capabilities |= CAP_NT_SMBS|CAP_RPC_REMOTE_APIS;
     288
     289        if (lp_unicode()) {
     290                capabilities |= CAP_UNICODE;
     291        }
    318292
    319293        if (lp_unix_extensions()) {
     
    321295        }
    322296
    323         if (lp_large_readwrite() && (SMB_OFF_T_BITS == 64))
     297        if (lp_large_readwrite())
    324298                capabilities |= CAP_LARGE_READX|CAP_LARGE_WRITEX|CAP_W2K_SMBS;
    325299
    326         if (SMB_OFF_T_BITS == 64)
    327                 capabilities |= CAP_LARGE_FILES;
    328 
    329         if (lp_readraw() && lp_writeraw())
     300        capabilities |= CAP_LARGE_FILES;
     301
     302        if (!lp_async_smb_echo_handler() && lp_read_raw() && lp_write_raw())
    330303                capabilities |= CAP_RAW_MODE;
    331304
     
    336309                capabilities |= CAP_DFS;
    337310
    338         if (lp_security() >= SEC_USER) {
    339                 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
    340         }
    341         if (sconn->smb1.negprot.encrypted_passwords) {
     311        secword |= NEGOTIATE_SECURITY_USER_LEVEL;
     312        if (xconn->smb1.negprot.encrypted_passwords) {
    342313                secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
    343314        }
    344315
    345         if (lp_server_signing()) {
    346                 if (lp_security() >= SEC_USER) {
    347                         secword |= NEGOTIATE_SECURITY_SIGNATURES_ENABLED;
    348                         /* No raw mode with smb signing. */
    349                         capabilities &= ~CAP_RAW_MODE;
    350                         if (lp_server_signing() == Required)
    351                                 secword |=NEGOTIATE_SECURITY_SIGNATURES_REQUIRED;
    352                         srv_set_signing_negotiated(sconn);
    353                 } else {
    354                         DEBUG(0,("reply_nt1: smb signing is incompatible with share level security !\n"));
    355                         if (lp_server_signing() == Required) {
    356                                 exit_server_cleanly("reply_nt1: smb signing required and share level security selected.");
    357                         }
     316        signing_desired = smb_signing_is_desired(xconn->smb1.signing_state);
     317        signing_required = smb_signing_is_mandatory(xconn->smb1.signing_state);
     318
     319        if (signing_desired) {
     320                secword |= NEGOTIATE_SECURITY_SIGNATURES_ENABLED;
     321                /* No raw mode with smb signing. */
     322                capabilities &= ~CAP_RAW_MODE;
     323                if (signing_required) {
     324                        secword |=NEGOTIATE_SECURITY_SIGNATURES_REQUIRED;
    358325                }
    359326        }
     
    362329        SCVAL(req->outbuf,smb_vwv1,secword);
    363330
    364         set_Protocol(PROTOCOL_NT1);
    365 
    366         SSVAL(req->outbuf,smb_vwv1+1,lp_maxmux()); /* maxmpx */
    367         SSVAL(req->outbuf,smb_vwv2+1,1); /* num vcs */
     331        smbXsrv_connection_init_tables(xconn, PROTOCOL_NT1);
     332
     333        SSVAL(req->outbuf,smb_vwv1+1, lp_max_mux()); /* maxmpx */
     334        SSVAL(req->outbuf,smb_vwv2+1, 1); /* num vcs */
    368335        SIVAL(req->outbuf,smb_vwv3+1,
    369               sconn->smb1.negprot.max_recv); /* max buffer. LOTS! */
    370         SIVAL(req->outbuf,smb_vwv5+1,0x10000); /* raw size. full 64k */
    371         SIVAL(req->outbuf,smb_vwv7+1,sys_getpid()); /* session key */
    372         SIVAL(req->outbuf,smb_vwv9+1,capabilities); /* capabilities */
     336              xconn->smb1.negprot.max_recv); /* max buffer. LOTS! */
     337        SIVAL(req->outbuf,smb_vwv5+1, 0x10000); /* raw size. full 64k */
     338        SIVAL(req->outbuf,smb_vwv7+1, getpid()); /* session key */
     339        SIVAL(req->outbuf,smb_vwv9+1, capabilities); /* capabilities */
    373340        clock_gettime(CLOCK_REALTIME,&ts);
    374341        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,(char *)req->outbuf+smb_vwv11+1,ts);
     
    377344        if (!negotiate_spnego) {
    378345                /* Create a token value and add it to the outgoing packet. */
    379                 if (sconn->smb1.negprot.encrypted_passwords) {
    380                         uint8 chal[8];
     346                if (xconn->smb1.negprot.encrypted_passwords) {
     347                        uint8_t chal[8];
    381348                        /* note that we do not send a challenge at all if
    382349                           we are using plaintext */
    383                         get_challenge(sconn, chal);
     350                        get_challenge(xconn, chal);
    384351                        ret = message_push_blob(
    385352                                &req->outbuf, data_blob_const(chal, sizeof(chal)));
     
    399366                        return;
    400367                }
     368                ret = message_push_string(&req->outbuf, lp_netbios_name(),
     369                                          STR_UNICODE|STR_TERMINATE
     370                                          |STR_NOALIGN);
     371                if (ret == -1) {
     372                        DEBUG(0, ("Could not push netbios name string\n"));
     373                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     374                        return;
     375                }
    401376                DEBUG(3,("not using SPNEGO\n"));
    402377        } else {
    403                 DATA_BLOB spnego_blob = negprot_spnego(req, req->sconn);
     378                DATA_BLOB spnego_blob = negprot_spnego(req, xconn);
    404379
    405380                if (spnego_blob.data == NULL) {
     
    468443protocol [LM1.2X002]
    469444protocol [LANMAN2.1]
     445
     446OSX:
     447protocol [NT LM 0.12]
     448protocol [SMB 2.002]
     449protocol [SMB 2.???]
    470450*/
    471451
     
    474454  *
    475455  * This appears to be the matrix of which protocol is used by which
    476   * MS product.
    477        Protocol                       WfWg    Win95   WinNT  Win2K  OS/2 Vista
    478        PC NETWORK PROGRAM 1.0          1       1       1      1      1     1
    479        XENIX CORE                                      2             2
    480        MICROSOFT NETWORKS 3.0          2       2       
    481        DOS LM1.2X002                   3       3       
    482        MICROSOFT NETWORKS 1.03                         3
    483        DOS LANMAN2.1                   4       4       
    484        LANMAN1.0                                       4      2      3     2
    485        Windows for Workgroups 3.1a     5       5       5      3            3
    486        LM1.2X002                                       6      4      4     4
    487        LANMAN2.1                                       7      5      5     5
    488        NT LM 0.12                              6       8      6            6
    489        SMB 2.001                                                           7
     456  * product.
     457       Protocol                       WfWg Win95 WinNT Win2K OS/2 Vista OSX
     458       PC NETWORK PROGRAM 1.0          1     1     1     1     1    1
     459       XENIX CORE                                  2           2
     460       MICROSOFT NETWORKS 3.0          2     2
     461       DOS LM1.2X002                   3     3
     462       MICROSOFT NETWORKS 1.03                     3
     463       DOS LANMAN2.1                   4     4
     464       LANMAN1.0                                   4     2     3    2
     465       Windows for Workgroups 3.1a     5     5     5     3          3
     466       LM1.2X002                                   6     4     4    4
     467       LANMAN2.1                                   7     5     5    5
     468       NT LM 0.12                            6     8     6     6    6    1
     469       SMB 2.001                                                    7
     470       SMB 2.002                                                         2
     471       SMB 2.???                                                         3
    490472  *
    491473  *  tim@fsg.com 09/29/95
     
    493475  */
    494476
    495 #define ARCH_WFWG     0x3      /* This is a fudge because WfWg is like Win95 */
    496 #define ARCH_WIN95    0x2
    497 #define ARCH_WINNT    0x4
    498 #define ARCH_WIN2K    0xC      /* Win2K is like NT */
    499 #define ARCH_OS2      0x14     /* Again OS/2 is like NT */
    500 #define ARCH_SAMBA    0x20
    501 #define ARCH_CIFSFS   0x40
    502 #define ARCH_VISTA    0x8C     /* Vista is like XP/2K */
    503 
    504 #define ARCH_ALL      0x7F
     477#define PROT_PC_NETWORK_PROGRAM_1_0             0x0001
     478#define PROT_XENIX_CORE                         0x0002
     479#define PROT_MICROSOFT_NETWORKS_3_0             0x0004
     480#define PROT_DOS_LM1_2X002                      0x0008
     481#define PROT_MICROSOFT_NETWORKS_1_03            0x0010
     482#define PROT_DOS_LANMAN2_1                      0x0020
     483#define PROT_LANMAN1_0                          0x0040
     484#define PROT_WFWG                               0x0080
     485#define PROT_LM1_2X002                          0x0100
     486#define PROT_LANMAN2_1                          0x0200
     487#define PROT_NT_LM_0_12                         0x0400
     488#define PROT_SMB_2_001                          0x0800
     489#define PROT_SMB_2_002                          0x1000
     490#define PROT_SMB_2_FF                           0x2000
     491#define PROT_SAMBA                              0x4000
     492#define PROT_POSIX_2                            0x8000
     493
     494#define ARCH_WFWG     ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_MICROSOFT_NETWORKS_3_0 | \
     495                        PROT_DOS_LM1_2X002 | PROT_DOS_LANMAN2_1 | PROT_WFWG )
     496#define ARCH_WIN95    ( ARCH_WFWG | PROT_NT_LM_0_12 )
     497#define ARCH_WINNT    ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_XENIX_CORE | \
     498                        PROT_MICROSOFT_NETWORKS_1_03 | PROT_LANMAN1_0 | PROT_WFWG | \
     499                        PROT_LM1_2X002 | PROT_LANMAN2_1 | PROT_NT_LM_0_12 )
     500#define ARCH_WIN2K    ( ARCH_WINNT & ~(PROT_XENIX_CORE | PROT_MICROSOFT_NETWORKS_1_03) )
     501#define ARCH_OS2      ( ARCH_WINNT & ~(PROT_MICROSOFT_NETWORKS_1_03 | PROT_WFWG) )
     502#define ARCH_VISTA    ( ARCH_WIN2K | PROT_SMB_2_001 )
     503#define ARCH_SAMBA    ( PROT_SAMBA )
     504#define ARCH_CIFSFS   ( PROT_POSIX_2 )
     505#define ARCH_OSX      ( PROT_NT_LM_0_12 | PROT_SMB_2_002 | PROT_SMB_2_FF )
    505506
    506507/* List of supported protocols, most desired first */
     
    508509        const char *proto_name;
    509510        const char *short_name;
    510         void (*proto_reply_fn)(struct smb_request *req, uint16 choice);
     511        void (*proto_reply_fn)(struct smb_request *req, uint16_t choice);
    511512        int protocol_level;
    512513} supported_protocols[] = {
    513         {"SMB 2.002",               "SMB2",     reply_smb2002,  PROTOCOL_SMB2},
     514        {"SMB 2.???",               "SMB2_FF",  reply_smb20ff,  PROTOCOL_SMB2_10},
     515        {"SMB 2.002",               "SMB2_02",  reply_smb2002,  PROTOCOL_SMB2_02},
    514516        {"NT LANMAN 1.0",           "NT1",      reply_nt1,      PROTOCOL_NT1},
    515517        {"NT LM 0.12",              "NT1",      reply_nt1,      PROTOCOL_NT1},
     
    521523        {"LANMAN1.0",               "LANMAN1",  reply_lanman1,  PROTOCOL_LANMAN1},
    522524        {"MICROSOFT NETWORKS 3.0",  "LANMAN1",  reply_lanman1,  PROTOCOL_LANMAN1},
    523         {"MICROSOFT NETWORKS 1.03", "COREPLUS", reply_coreplus, PROTOCOL_COREPLUS},
    524         {"PC NETWORK PROGRAM 1.0",  "CORE",     reply_corep,    PROTOCOL_CORE},
    525525        {NULL,NULL,NULL,0},
    526526};
     
    534534{
    535535        int choice= -1;
     536        int chosen_level = -1;
    536537        int protocol;
    537538        const char *p;
    538         int arch = ARCH_ALL;
     539        int protocols = 0;
    539540        int num_cliprotos;
    540541        char **cliprotos;
    541542        int i;
    542543        size_t converted_size;
     544        struct smbXsrv_connection *xconn = req->xconn;
    543545        struct smbd_server_connection *sconn = req->sconn;
     546        bool signing_required = true;
    544547
    545548        START_PROFILE(SMBnegprot);
    546549
    547         if (sconn->smb1.negprot.done) {
     550        if (xconn->smb1.negprot.done) {
    548551                END_PROFILE(SMBnegprot);
    549552                exit_server_cleanly("multiple negprot's are not permitted");
    550553        }
    551         sconn->smb1.negprot.done = true;
     554        xconn->smb1.negprot.done = true;
    552555
    553556        if (req->buflen == 0) {
     
    574577                char **tmp;
    575578
    576                 tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), cliprotos, char *,
     579                tmp = talloc_realloc(talloc_tos(), cliprotos, char *,
    577580                                           num_cliprotos+1);
    578581                if (tmp == NULL) {
     
    603606
    604607        for (i=0; i<num_cliprotos; i++) {
    605                 if (strcsequal(cliprotos[i], "Windows for Workgroups 3.1a"))
    606                         arch &= ( ARCH_WFWG | ARCH_WIN95 | ARCH_WINNT
    607                                   | ARCH_WIN2K );
    608                 else if (strcsequal(cliprotos[i], "DOS LM1.2X002"))
    609                         arch &= ( ARCH_WFWG | ARCH_WIN95 );
    610                 else if (strcsequal(cliprotos[i], "DOS LANMAN2.1"))
    611                         arch &= ( ARCH_WFWG | ARCH_WIN95 );
    612                 else if (strcsequal(cliprotos[i], "NT LM 0.12"))
    613                         arch &= ( ARCH_WIN95 | ARCH_WINNT | ARCH_WIN2K
    614                                   | ARCH_CIFSFS);
    615                 else if (strcsequal(cliprotos[i], "SMB 2.001"))
    616                         arch = ARCH_VISTA;             
    617                 else if (strcsequal(cliprotos[i], "LANMAN2.1"))
    618                         arch &= ( ARCH_WINNT | ARCH_WIN2K | ARCH_OS2 );
    619                 else if (strcsequal(cliprotos[i], "LM1.2X002"))
    620                         arch &= ( ARCH_WINNT | ARCH_WIN2K | ARCH_OS2 );
    621                 else if (strcsequal(cliprotos[i], "MICROSOFT NETWORKS 1.03"))
    622                         arch &= ARCH_WINNT;
    623                 else if (strcsequal(cliprotos[i], "XENIX CORE"))
    624                         arch &= ( ARCH_WINNT | ARCH_OS2 );
    625                 else if (strcsequal(cliprotos[i], "Samba")) {
    626                         arch = ARCH_SAMBA;
     608                if (strcsequal(cliprotos[i], "Windows for Workgroups 3.1a")) {
     609                        protocols |= PROT_WFWG;
     610                } else if (strcsequal(cliprotos[i], "DOS LM1.2X002")) {
     611                        protocols |= PROT_DOS_LM1_2X002;
     612                } else if (strcsequal(cliprotos[i], "DOS LANMAN2.1")) {
     613                        protocols |= PROT_DOS_LANMAN2_1;
     614                } else if (strcsequal(cliprotos[i], "LANMAN1.0")) {
     615                        protocols |= PROT_LANMAN1_0;
     616                } else if (strcsequal(cliprotos[i], "NT LM 0.12")) {
     617                        protocols |= PROT_NT_LM_0_12;
     618                } else if (strcsequal(cliprotos[i], "SMB 2.001")) {
     619                        protocols |= PROT_SMB_2_001;
     620                } else if (strcsequal(cliprotos[i], "SMB 2.002")) {
     621                        protocols |= PROT_SMB_2_002;
     622                } else if (strcsequal(cliprotos[i], "SMB 2.???")) {
     623                        protocols |= PROT_SMB_2_FF;
     624                } else if (strcsequal(cliprotos[i], "LANMAN2.1")) {
     625                        protocols |= PROT_LANMAN2_1;
     626                } else if (strcsequal(cliprotos[i], "LM1.2X002")) {
     627                        protocols |= PROT_LM1_2X002;
     628                } else if (strcsequal(cliprotos[i], "MICROSOFT NETWORKS 1.03")) {
     629                        protocols |= PROT_MICROSOFT_NETWORKS_1_03;
     630                } else if (strcsequal(cliprotos[i], "MICROSOFT NETWORKS 3.0")) {
     631                        protocols |= PROT_MICROSOFT_NETWORKS_3_0;
     632                } else if (strcsequal(cliprotos[i], "PC NETWORK PROGRAM 1.0")) {
     633                        protocols |= PROT_PC_NETWORK_PROGRAM_1_0;
     634                } else if (strcsequal(cliprotos[i], "XENIX CORE")) {
     635                        protocols |= PROT_XENIX_CORE;
     636                } else if (strcsequal(cliprotos[i], "Samba")) {
     637                        protocols = PROT_SAMBA;
    627638                        break;
    628639                } else if (strcsequal(cliprotos[i], "POSIX 2")) {
    629                         arch = ARCH_CIFSFS;
    630                         break;
    631                 }
    632         }
    633 
    634         /* CIFSFS can send one arch only, NT LM 0.12. */
    635         if (i == 1 && (arch & ARCH_CIFSFS)) {
    636                 arch = ARCH_CIFSFS;
    637         }
    638 
    639         switch ( arch ) {
     640                        protocols = PROT_POSIX_2;
     641                        break;
     642                }
     643        }
     644
     645        switch ( protocols ) {
     646                /* Old CIFSFS can send one arch only, NT LM 0.12. */
     647                case PROT_NT_LM_0_12:
    640648                case ARCH_CIFSFS:
    641649                        set_remote_arch(RA_CIFSFS);
     
    651659                        break;
    652660                case ARCH_WINNT:
    653                         if(req->flags2 == FLAGS2_WIN2K_SIGNATURE)
    654                                 set_remote_arch(RA_WIN2K);
    655                         else
    656                                 set_remote_arch(RA_WINNT);
     661                        set_remote_arch(RA_WINNT);
    657662                        break;
    658663                case ARCH_WIN2K:
    659                         /* Vista may have been set in the negprot so don't
    660                            override it here */
    661                         if ( get_remote_arch() != RA_VISTA )
    662                                 set_remote_arch(RA_WIN2K);
     664                        set_remote_arch(RA_WIN2K);
    663665                        break;
    664666                case ARCH_VISTA:
     
    667669                case ARCH_OS2:
    668670                        set_remote_arch(RA_OS2);
     671                        break;
     672                case ARCH_OSX:
     673                        set_remote_arch(RA_OSX);
    669674                        break;
    670675                default:
     
    674679
    675680        /* possibly reload - change of architecture */
    676         reload_services(sconn->msg_ctx, sconn->sock, True);
     681        reload_services(sconn, conn_snum_used, true);
    677682
    678683        /* moved from the netbios session setup code since we don't have that
     
    680685           window where we are listening to messages   -- jerry */
    681686
    682         serverid_register(sconn_server_id(sconn),
     687        serverid_register(messaging_server_id(sconn->msg_ctx),
    683688                          FLAG_MSG_GENERAL|FLAG_MSG_SMBD
    684689                          |FLAG_MSG_PRINT_GENERAL);
     
    687692        for (protocol = 0; supported_protocols[protocol].proto_name; protocol++) {
    688693                i = 0;
    689                 if ((supported_protocols[protocol].protocol_level <= lp_maxprotocol()) &&
    690                                 (supported_protocols[protocol].protocol_level >= lp_minprotocol()))
     694                if ((supported_protocols[protocol].protocol_level <= lp_server_max_protocol()) &&
     695                                (supported_protocols[protocol].protocol_level >= lp_server_min_protocol()))
    691696                        while (i < num_cliprotos) {
    692                                 if (strequal(cliprotos[i],supported_protocols[protocol].proto_name))
     697                                if (strequal(cliprotos[i],supported_protocols[protocol].proto_name)) {
    693698                                        choice = i;
     699                                        chosen_level = supported_protocols[protocol].protocol_level;
     700                                }
    694701                                i++;
    695702                        }
     
    700707        if(choice != -1) {
    701708                fstrcpy(remote_proto,supported_protocols[protocol].short_name);
    702                 reload_services(sconn->msg_ctx, sconn->sock, True);
     709                reload_services(sconn, conn_snum_used, true);
    703710                supported_protocols[protocol].proto_reply_fn(req, choice);
    704711                DEBUG(3,("Selected protocol %s\n",supported_protocols[protocol].proto_name));
     
    711718        DEBUG( 5, ( "negprot index=%d\n", choice ) );
    712719
    713         if ((lp_server_signing() == Required) && (get_Protocol() < PROTOCOL_NT1)) {
     720        /* We always have xconn->smb1.signing_state also for >= SMB2_02 */
     721        signing_required = smb_signing_is_mandatory(xconn->smb1.signing_state);
     722        if (signing_required && (chosen_level < PROTOCOL_NT1)) {
    714723                exit_server_cleanly("SMB signing is required and "
    715724                        "client negotiated a downlevel protocol");
     
    718727        TALLOC_FREE(cliprotos);
    719728
    720         if (lp_async_smb_echo_handler() && (get_Protocol() < PROTOCOL_SMB2) &&
    721             !fork_echo_handler(sconn)) {
     729        if (lp_async_smb_echo_handler() && (chosen_level < PROTOCOL_SMB2_02) &&
     730            !fork_echo_handler(xconn)) {
    722731                exit_server("Failed to fork echo handler");
    723732        }
Note: See TracChangeset for help on using the changeset viewer.