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/smbd/sesssetup.c

    r599 r745  
    2424
    2525#include "includes.h"
     26#include "../lib/tsocket/tsocket.h"
     27#include "smbd/smbd.h"
    2628#include "smbd/globals.h"
    2729#include "../libcli/auth/spnego.h"
     30#include "../libcli/auth/ntlmssp.h"
     31#include "ntlmssp_wrap.h"
     32#include "../librpc/gen_ndr/krb5pac.h"
     33#include "libads/kerberos_proto.h"
     34#include "../lib/util/asn1.h"
     35#include "auth.h"
     36#include "messages.h"
     37#include "smbprofile.h"
    2838
    2939/* For split krb5 SPNEGO blobs. */
     
    4050  is set approriately
    4151*/
    42 static NTSTATUS do_map_to_guest(NTSTATUS status,
    43                                 auth_serversupplied_info **server_info,
    44                                 const char *user, const char *domain)
     52NTSTATUS do_map_to_guest(NTSTATUS status,
     53                        struct auth_serversupplied_info **server_info,
     54                        const char *user, const char *domain)
    4555{
     56        user = user ? user : "";
     57        domain = domain ? domain : "";
     58
    4659        if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
    4760                if ((lp_map_to_guest() == MAP_TO_GUEST_ON_BAD_USER) ||
     
    132145****************************************************************************/
    133146
    134 static NTSTATUS check_guest_password(auth_serversupplied_info **server_info)
     147static NTSTATUS check_guest_password(struct auth_serversupplied_info **server_info)
    135148{
    136149        struct auth_context *auth_context;
    137         auth_usersupplied_info *user_info = NULL;
     150        struct auth_usersupplied_info *user_info = NULL;
    138151
    139152        NTSTATUS nt_status;
    140         unsigned char chal[8];
    141 
    142         ZERO_STRUCT(chal);
     153        static unsigned char chal[8] = { 0, };
    143154
    144155        DEBUG(3,("Got anonymous request\n"));
    145156
    146         if (!NT_STATUS_IS_OK(nt_status = make_auth_context_fixed(&auth_context,
    147                                         chal))) {
     157        nt_status = make_auth_context_fixed(talloc_tos(), &auth_context, chal);
     158        if (!NT_STATUS_IS_OK(nt_status)) {
    148159                return nt_status;
    149160        }
    150161
    151162        if (!make_user_info_guest(&user_info)) {
    152                 (auth_context->free)(&auth_context);
     163                TALLOC_FREE(auth_context);
    153164                return NT_STATUS_NO_MEMORY;
    154165        }
     
    157168                                                user_info,
    158169                                                server_info);
    159         (auth_context->free)(&auth_context);
     170        TALLOC_FREE(auth_context);
    160171        free_user_info(&user_info);
    161172        return nt_status;
     
    240251        TALLOC_CTX *mem_ctx;
    241252        DATA_BLOB ticket;
    242         char *client, *p, *domain;
    243         fstring netbios_domain_name;
    244253        struct passwd *pw;
    245         fstring user;
    246254        int sess_vuid = req->vuid;
    247255        NTSTATUS ret = NT_STATUS_OK;
    248         struct PAC_DATA *pac_data = NULL;
    249256        DATA_BLOB ap_rep, ap_rep_wrapped, response;
    250         auth_serversupplied_info *server_info = NULL;
     257        struct auth_serversupplied_info *server_info = NULL;
    251258        DATA_BLOB session_key = data_blob_null;
    252259        uint8 tok_id[2];
    253260        DATA_BLOB nullblob = data_blob_null;
    254         fstring real_username;
    255261        bool map_domainuser_to_guest = False;
    256262        bool username_was_mapped;
    257263        struct PAC_LOGON_INFO *logon_info = NULL;
    258         struct smbd_server_connection *sconn = smbd_server_conn;
     264        struct smbd_server_connection *sconn = req->sconn;
     265        char *principal;
     266        char *user;
     267        char *domain;
     268        char *real_username;
    259269
    260270        ZERO_STRUCT(ticket);
     
    272282        }
    273283
    274         if (!spnego_parse_krb5_wrap(*secblob, &ticket, tok_id)) {
     284        if (!spnego_parse_krb5_wrap(mem_ctx, *secblob, &ticket, tok_id)) {
    275285                talloc_destroy(mem_ctx);
    276286                reply_nterror(req, nt_status_squash(NT_STATUS_LOGON_FAILURE));
     
    279289
    280290        ret = ads_verify_ticket(mem_ctx, lp_realm(), 0, &ticket,
    281                                 &client, &pac_data, &ap_rep,
     291                                &principal, &logon_info, &ap_rep,
    282292                                &session_key, True);
    283293
     
    340350        }
    341351
    342         DEBUG(3,("Ticket name is [%s]\n", client));
    343 
    344         p = strchr_m(client, '@');
    345         if (!p) {
    346                 DEBUG(3,("Doesn't look like a valid principal\n"));
     352        ret = get_user_from_kerberos_info(talloc_tos(),
     353                                          sconn->client_id.name,
     354                                          principal, logon_info,
     355                                          &username_was_mapped,
     356                                          &map_domainuser_to_guest,
     357                                          &user, &domain,
     358                                          &real_username, &pw);
     359        if (!NT_STATUS_IS_OK(ret)) {
    347360                data_blob_free(&ap_rep);
    348361                data_blob_free(&session_key);
     
    352365        }
    353366
    354         *p = 0;
    355 
    356367        /* save the PAC data if we have it */
    357 
    358         if (pac_data) {
    359                 logon_info = get_logon_info_from_pac(pac_data);
    360                 if (logon_info) {
    361                         netsamlogon_cache_store( client, &logon_info->info3 );
    362                 }
    363         }
    364 
    365         if (!strequal(p+1, lp_realm())) {
    366                 DEBUG(3,("Ticket for foreign realm %s@%s\n", client, p+1));
    367                 if (!lp_allow_trusted_domains()) {
    368                         data_blob_free(&ap_rep);
    369                         data_blob_free(&session_key);
    370                         talloc_destroy(mem_ctx);
    371                         reply_nterror(req, nt_status_squash(
    372                                               NT_STATUS_LOGON_FAILURE));
    373                         return;
    374                 }
    375         }
    376 
    377         /* this gives a fully qualified user name (ie. with full realm).
    378            that leads to very long usernames, but what else can we do? */
    379 
    380         domain = p+1;
    381 
    382         if (logon_info && logon_info->info3.base.domain.string) {
    383                 fstrcpy(netbios_domain_name,
    384                         logon_info->info3.base.domain.string);
    385                 domain = netbios_domain_name;
    386                 DEBUG(10, ("Mapped to [%s] (using PAC)\n", domain));
    387 
    388         } else {
    389 
    390                 /* If we have winbind running, we can (and must) shorten the
    391                    username by using the short netbios name. Otherwise we will
    392                    have inconsistent user names. With Kerberos, we get the
    393                    fully qualified realm, with ntlmssp we get the short
    394                    name. And even w2k3 does use ntlmssp if you for example
    395                    connect to an ip address. */
    396 
    397                 wbcErr wbc_status;
    398                 struct wbcDomainInfo *info = NULL;
    399 
    400                 DEBUG(10, ("Mapping [%s] to short name\n", domain));
    401 
    402                 wbc_status = wbcDomainInfo(domain, &info);
    403 
    404                 if (WBC_ERROR_IS_OK(wbc_status)) {
    405 
    406                         fstrcpy(netbios_domain_name,
    407                                 info->short_name);
    408 
    409                         wbcFreeMemory(info);
    410                         domain = netbios_domain_name;
    411                         DEBUG(10, ("Mapped to [%s] (using Winbind)\n", domain));
    412                 } else {
    413                         DEBUG(3, ("Could not find short name: %s\n",
    414                                 wbcErrorString(wbc_status)));
    415                 }
    416         }
    417 
    418         fstr_sprintf(user, "%s%c%s", domain, *lp_winbind_separator(), client);
    419 
    420         /* lookup the passwd struct, create a new user if necessary */
    421 
    422         username_was_mapped = map_username(sconn, user);
    423 
    424         pw = smb_getpwnam( mem_ctx, user, real_username, True );
    425 
    426         if (pw) {
    427                 /* if a real user check pam account restrictions */
    428                 /* only really perfomed if "obey pam restriction" is true */
    429                 /* do this before an eventual mapping to guest occurs */
    430                 ret = smb_pam_accountcheck(pw->pw_name);
    431                 if (  !NT_STATUS_IS_OK(ret)) {
    432                         DEBUG(1,("PAM account restriction "
    433                                 "prevents user login\n"));
    434                         data_blob_free(&ap_rep);
    435                         data_blob_free(&session_key);
    436                         TALLOC_FREE(mem_ctx);
    437                         reply_nterror(req, nt_status_squash(ret));
    438                         return;
    439                 }
    440         }
    441 
    442         if (!pw) {
    443 
    444                 /* this was originally the behavior of Samba 2.2, if a user
    445                    did not have a local uid but has been authenticated, then
    446                    map them to a guest account */
    447 
    448                 if (lp_map_to_guest() == MAP_TO_GUEST_ON_BAD_UID){
    449                         map_domainuser_to_guest = True;
    450                         fstrcpy(user,lp_guestaccount());
    451                         pw = smb_getpwnam( mem_ctx, user, real_username, True );
    452                 }
    453 
    454                 /* extra sanity check that the guest account is valid */
    455 
    456                 if ( !pw ) {
    457                         DEBUG(1,("Username %s is invalid on this system\n",
    458                                 user));
    459                         data_blob_free(&ap_rep);
    460                         data_blob_free(&session_key);
    461                         TALLOC_FREE(mem_ctx);
    462                         reply_nterror(req, nt_status_squash(
    463                                               NT_STATUS_LOGON_FAILURE));
    464                         return;
    465                 }
     368        if (logon_info) {
     369                netsamlogon_cache_store(user, &logon_info->info3);
    466370        }
    467371
    468372        /* setup the string used by %U */
    469 
    470         sub_set_smb_name( real_username );
    471         reload_services(True);
    472 
    473         if ( map_domainuser_to_guest ) {
    474                 make_server_info_guest(NULL, &server_info);
    475         } else if (logon_info) {
    476                 /* pass the unmapped username here since map_username()
    477                    will be called again from inside make_server_info_info3() */
    478 
    479                 ret = make_server_info_info3(mem_ctx, client, domain,
    480                                              &server_info, &logon_info->info3);
    481                 if ( !NT_STATUS_IS_OK(ret) ) {
    482                         DEBUG(1,("make_server_info_info3 failed: %s!\n",
    483                                  nt_errstr(ret)));
    484                         data_blob_free(&ap_rep);
    485                         data_blob_free(&session_key);
    486                         TALLOC_FREE(mem_ctx);
    487                         reply_nterror(req, nt_status_squash(ret));
    488                         return;
    489                 }
    490 
    491         } else {
    492                 /*
    493                  * We didn't get a PAC, we have to make up the user
    494                  * ourselves. Try to ask the pdb backend to provide
    495                  * SID consistency with ntlmssp session setup
    496                  */
    497                 struct samu *sampass;
    498 
    499                 sampass = samu_new(talloc_tos());
    500                 if (sampass == NULL) {
    501                         ret = NT_STATUS_NO_MEMORY;
    502                         data_blob_free(&ap_rep);
    503                         data_blob_free(&session_key);
    504                         TALLOC_FREE(mem_ctx);
    505                         reply_nterror(req, nt_status_squash(ret));
    506                         return;
    507                 }
    508 
    509                 if (pdb_getsampwnam(sampass, real_username)) {
    510                         DEBUG(10, ("found user %s in passdb, calling "
    511                                    "make_server_info_sam\n", real_username));
    512                         ret = make_server_info_sam(&server_info, sampass);
    513                 } else {
    514                         /*
    515                          * User not in passdb, make it up artificially
    516                          */
    517                         TALLOC_FREE(sampass);
    518                         DEBUG(10, ("didn't find user %s in passdb, calling "
    519                                    "make_server_info_pw\n", real_username));
    520                         ret = make_server_info_pw(&server_info, real_username,
    521                                                   pw);
    522                 }
    523 
    524                 if ( !NT_STATUS_IS_OK(ret) ) {
    525                         DEBUG(1,("make_server_info_[sam|pw] failed: %s!\n",
    526                                  nt_errstr(ret)));
    527                         data_blob_free(&ap_rep);
    528                         data_blob_free(&session_key);
    529                         TALLOC_FREE(mem_ctx);
    530                         reply_nterror(req, nt_status_squash(ret));
    531                         return;
    532                 }
    533 
    534                 /* make_server_info_pw does not set the domain. Without this
    535                  * we end up with the local netbios name in substitutions for
    536                  * %D. */
    537 
    538                 if (server_info->sam_account != NULL) {
    539                         pdb_set_domain(server_info->sam_account,
    540                                         domain, PDB_SET);
    541                 }
     373        sub_set_smb_name(real_username);
     374
     375        /* reload services so that the new %U is taken into account */
     376        reload_services(sconn->msg_ctx, sconn->sock, True);
     377
     378        ret = make_server_info_krb5(mem_ctx,
     379                                    user, domain, real_username, pw,
     380                                    logon_info, map_domainuser_to_guest,
     381                                    &server_info);
     382        if (!NT_STATUS_IS_OK(ret)) {
     383                DEBUG(1, ("make_server_info_krb5 failed!\n"));
     384                data_blob_free(&ap_rep);
     385                data_blob_free(&session_key);
     386                TALLOC_FREE(mem_ctx);
     387                reply_nterror(req, nt_status_squash(ret));
     388                return;
    542389        }
    543390
     
    547394           already does this */
    548395
    549         if ( !server_info->ptok ) {
     396        if ( !server_info->security_token ) {
    550397                ret = create_local_token( server_info );
    551398                if ( !NT_STATUS_IS_OK(ret) ) {
     
    566413
    567414        data_blob_free(&server_info->user_session_key);
     415        /* Set the kerberos-derived session key onto the server_info */
    568416        server_info->user_session_key = session_key;
     417        talloc_steal(server_info, session_key.data);
     418
    569419        session_key = data_blob_null;
    570420
     
    574424         * it.... */
    575425
    576         sess_vuid = register_existing_vuid(sconn,
    577                                         sess_vuid,
    578                                         server_info,
    579                                         nullblob,
    580                                         client);
     426        sess_vuid = register_existing_vuid(sconn, sess_vuid,
     427                                           server_info, nullblob, user);
    581428
    582429        reply_outbuf(req, 4, 0);
     
    587434        } else {
    588435                /* current_user_info is changed on new vuid */
    589                 reload_services( True );
     436                reload_services(sconn->msg_ctx, sconn->sock, True);
    590437
    591438                SSVAL(req->outbuf, smb_vwv3, 0);
     
    603450        /* wrap that up in a nice GSS-API wrapping */
    604451        if (NT_STATUS_IS_OK(ret)) {
    605                 ap_rep_wrapped = spnego_gen_krb5_wrap(ap_rep,
     452                ap_rep_wrapped = spnego_gen_krb5_wrap(talloc_tos(), ap_rep,
    606453                                TOK_ID_KRB_AP_REP);
    607454        } else {
    608455                ap_rep_wrapped = data_blob_null;
    609456        }
    610         response = spnego_gen_auth_response(&ap_rep_wrapped, ret,
     457        response = spnego_gen_auth_response(talloc_tos(), &ap_rep_wrapped, ret,
    611458                        mechOID);
    612459        reply_sesssetup_blob(req, response, ret);
     
    630477static void reply_spnego_ntlmssp(struct smb_request *req,
    631478                                 uint16 vuid,
    632                                  AUTH_NTLMSSP_STATE **auth_ntlmssp_state,
     479                                 struct auth_ntlmssp_state **auth_ntlmssp_state,
    633480                                 DATA_BLOB *ntlmssp_blob, NTSTATUS nt_status,
    634481                                 const char *OID,
    635482                                 bool wrap)
    636483{
     484        bool do_invalidate = true;
    637485        DATA_BLOB response;
    638         struct auth_serversupplied_info *server_info = NULL;
    639         struct smbd_server_connection *sconn = smbd_server_conn;
     486        struct auth_serversupplied_info *session_info = NULL;
     487        struct smbd_server_connection *sconn = req->sconn;
    640488
    641489        if (NT_STATUS_IS_OK(nt_status)) {
    642                 server_info = (*auth_ntlmssp_state)->server_info;
     490                nt_status = auth_ntlmssp_steal_session_info(talloc_tos(),
     491                                        (*auth_ntlmssp_state), &session_info);
    643492        } else {
     493                /* Note that this session_info won't have a session
     494                 * key.  But for map to guest, that's exactly the right
     495                 * thing - we can't reasonably guess the key the
     496                 * client wants, as the password was wrong */
    644497                nt_status = do_map_to_guest(nt_status,
    645                             &server_info,
    646                             (*auth_ntlmssp_state)->ntlmssp_state->user,
    647                             (*auth_ntlmssp_state)->ntlmssp_state->domain);
     498                                            &session_info,
     499                                            auth_ntlmssp_get_username(*auth_ntlmssp_state),
     500                                            auth_ntlmssp_get_domain(*auth_ntlmssp_state));
    648501        }
    649502
     
    660513                }
    661514
    662                 data_blob_free(&server_info->user_session_key);
    663                 server_info->user_session_key =
    664                         data_blob_talloc(
    665                         server_info,
    666                         (*auth_ntlmssp_state)->ntlmssp_state->session_key.data,
    667                         (*auth_ntlmssp_state)->ntlmssp_state->session_key.length);
    668 
    669515                /* register_existing_vuid keeps the server info */
    670516                if (register_existing_vuid(sconn, vuid,
    671                                 server_info, nullblob,
    672                                 (*auth_ntlmssp_state)->ntlmssp_state->user) !=
    673                                         vuid) {
     517                                           session_info, nullblob,
     518                                           auth_ntlmssp_get_username(*auth_ntlmssp_state)) !=
     519                                           vuid) {
     520                        /* The problem is, *auth_ntlmssp_state points
     521                         * into the vuser this will have
     522                         * talloc_free()'ed in
     523                         * register_existing_vuid() */
     524                        do_invalidate = false;
    674525                        nt_status = NT_STATUS_LOGON_FAILURE;
    675526                        goto out;
    676527                }
    677528
    678                 (*auth_ntlmssp_state)->server_info = NULL;
    679 
    680529                /* current_user_info is changed on new vuid */
    681                 reload_services( True );
     530                reload_services(sconn->msg_ctx, sconn->sock, True);
    682531
    683532                SSVAL(req->outbuf, smb_vwv3, 0);
    684533
    685                 if (server_info->guest) {
     534                if (session_info->guest) {
    686535                        SSVAL(req->outbuf,smb_vwv2,1);
    687536                }
     
    691540
    692541        if (wrap) {
    693                 response = spnego_gen_auth_response(ntlmssp_blob,
     542                response = spnego_gen_auth_response(talloc_tos(),
     543                                ntlmssp_blob,
    694544                                nt_status, OID);
    695545        } else {
     
    707557        if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
    708558                /* NB. This is *NOT* an error case. JRA */
    709                 auth_ntlmssp_end(auth_ntlmssp_state);
    710                 if (!NT_STATUS_IS_OK(nt_status)) {
    711                         /* Kill the intermediate vuid */
    712                         invalidate_vuid(sconn, vuid);
     559                if (do_invalidate) {
     560                        TALLOC_FREE(*auth_ntlmssp_state);
     561                        if (!NT_STATUS_IS_OK(nt_status)) {
     562                                /* Kill the intermediate vuid */
     563                                invalidate_vuid(sconn, vuid);
     564                        }
    713565                }
    714566        }
     
    719571****************************************************************************/
    720572
    721 NTSTATUS parse_spnego_mechanisms(DATA_BLOB blob_in,
     573NTSTATUS parse_spnego_mechanisms(TALLOC_CTX *ctx,
     574                DATA_BLOB blob_in,
    722575                DATA_BLOB *pblob_out,
    723576                char **kerb_mechOID)
     
    730583
    731584        /* parse out the OIDs and the first sec blob */
    732         if (!parse_negTokenTarg(blob_in, OIDs, pblob_out) ||
    733                         OIDs[0] == NULL) {
     585        if (!spnego_parse_negTokenInit(ctx, blob_in, OIDs, NULL, pblob_out) ||
     586                        (OIDs[0] == NULL)) {
    734587                return NT_STATUS_LOGON_FAILURE;
    735588        }
     
    748601        if (strcmp(OID_KERBEROS5, OIDs[0]) == 0 ||
    749602            strcmp(OID_KERBEROS5_OLD, OIDs[0]) == 0) {
    750                 *kerb_mechOID = SMB_STRDUP(OIDs[0]);
     603                *kerb_mechOID = talloc_strdup(ctx, OIDs[0]);
    751604                if (*kerb_mechOID == NULL) {
    752605                        ret = NT_STATUS_NO_MEMORY;
     
    777630                "but set to downgrade to NTLMSSP\n"));
    778631
    779         response = spnego_gen_auth_response(NULL,
     632        response = spnego_gen_auth_response(talloc_tos(), NULL,
    780633                        NT_STATUS_MORE_PROCESSING_REQUIRED,
    781634                        OID_NTLMSSP);
     
    791644                                   uint16 vuid,
    792645                                   DATA_BLOB blob1,
    793                                    AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
     646                                   struct auth_ntlmssp_state **auth_ntlmssp_state)
    794647{
    795648        DATA_BLOB secblob;
     
    797650        char *kerb_mech = NULL;
    798651        NTSTATUS status;
    799         struct smbd_server_connection *sconn = smbd_server_conn;
    800 
    801         status = parse_spnego_mechanisms(blob1, &secblob, &kerb_mech);
     652        struct smbd_server_connection *sconn = req->sconn;
     653
     654        status = parse_spnego_mechanisms(talloc_tos(),
     655                        blob1, &secblob, &kerb_mech);
    802656        if (!NT_STATUS_IS_OK(status)) {
    803657                /* Kill the intermediate vuid */
     
    821675                        invalidate_vuid(sconn, vuid);
    822676                }
    823                 SAFE_FREE(kerb_mech);
     677                TALLOC_FREE(kerb_mech);
    824678                return;
    825679        }
    826680#endif
    827681
    828         if (*auth_ntlmssp_state) {
    829                 auth_ntlmssp_end(auth_ntlmssp_state);
    830         }
     682        TALLOC_FREE(*auth_ntlmssp_state);
    831683
    832684        if (kerb_mech) {
     
    835687                 * we need to fall back to NTLM. */
    836688                reply_spnego_downgrade_to_ntlmssp(req, vuid);
    837                 SAFE_FREE(kerb_mech);
     689                TALLOC_FREE(kerb_mech);
    838690                return;
    839691        }
     
    868720                              uint16 vuid,
    869721                              DATA_BLOB blob1,
    870                               AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
     722                              struct auth_ntlmssp_state **auth_ntlmssp_state)
    871723{
    872724        DATA_BLOB auth = data_blob_null;
     
    874726        DATA_BLOB secblob = data_blob_null;
    875727        NTSTATUS status = NT_STATUS_LOGON_FAILURE;
    876         struct smbd_server_connection *sconn = smbd_server_conn;
    877 
    878         if (!spnego_parse_auth(blob1, &auth)) {
     728        struct smbd_server_connection *sconn = req->sconn;
     729
     730        if (!spnego_parse_auth(talloc_tos(), blob1, &auth)) {
    879731#if 0
    880732                file_save("auth.dat", blob1.data, blob1.length);
     
    892744                char *kerb_mech = NULL;
    893745
    894                 status = parse_spnego_mechanisms(auth, &secblob, &kerb_mech);
     746                status = parse_spnego_mechanisms(talloc_tos(),
     747                                auth, &secblob, &kerb_mech);
    895748
    896749                if (!NT_STATUS_IS_OK(status)) {
     
    915768                                invalidate_vuid(sconn, vuid);
    916769                        }
    917                         SAFE_FREE(kerb_mech);
     770                        TALLOC_FREE(kerb_mech);
    918771                        return;
    919772                }
     
    931784                        reply_nterror(req, nt_status_squash(
    932785                                        NT_STATUS_LOGON_FAILURE));
    933                         SAFE_FREE(kerb_mech);
     786                        TALLOC_FREE(kerb_mech);
    934787                }
    935788        }
     
    12121065        NTSTATUS status = NT_STATUS_OK;
    12131066        uint16 smbpid = req->smbpid;
    1214         struct smbd_server_connection *sconn = smbd_server_conn;
     1067        struct smbd_server_connection *sconn = req->sconn;
    12151068
    12161069        DEBUG(3,("Doing spnego session setup\n"));
     
    12711124                } else {
    12721125                        ra_lanman_string( native_lanman );
     1126                }
     1127        } else if ( ra_type == RA_VISTA ) {
     1128                if ( strncmp(native_os, "Mac OS X", 8) == 0 ) {
     1129                        set_remote_arch(RA_OSX);
    12731130                }
    12741131        }
     
    13831240****************************************************************************/
    13841241
    1385 static int shutdown_other_smbds(struct db_record *rec,
    1386                                 const struct connections_key *key,
     1242struct shutdown_state {
     1243        const char *ip;
     1244        struct messaging_context *msg_ctx;
     1245};
     1246
     1247static int shutdown_other_smbds(const struct connections_key *key,
    13871248                                const struct connections_data *crec,
    13881249                                void *private_data)
    13891250{
    1390         const char *ip = (const char *)private_data;
     1251        struct shutdown_state *state = (struct shutdown_state *)private_data;
     1252
     1253        DEBUG(10, ("shutdown_other_smbds: %s, %s\n",
     1254                   procid_str(talloc_tos(), &crec->pid), crec->addr));
    13911255
    13921256        if (!process_exists(crec->pid)) {
     1257                DEBUG(10, ("process does not exist\n"));
    13931258                return 0;
    13941259        }
    13951260
    13961261        if (procid_is_me(&crec->pid)) {
     1262                DEBUG(10, ("It's me\n"));
    13971263                return 0;
    13981264        }
    13991265
    1400         if (strcmp(ip, crec->addr) != 0) {
     1266        if (strcmp(state->ip, crec->addr) != 0) {
     1267                DEBUG(10, ("%s does not match %s\n", state->ip, crec->addr));
    14011268                return 0;
    14021269        }
    14031270
    1404         DEBUG(0,("shutdown_other_smbds: shutting down pid %u "
    1405                  "(IP %s)\n", (unsigned int)procid_to_pid(&crec->pid), ip));
    1406 
    1407         messaging_send(smbd_messaging_context(), crec->pid, MSG_SHUTDOWN,
     1271        DEBUG(1, ("shutdown_other_smbds: shutting down pid %u "
     1272                  "(IP %s)\n", (unsigned int)procid_to_pid(&crec->pid),
     1273                  state->ip));
     1274
     1275        messaging_send(state->msg_ctx, crec->pid, MSG_SHUTDOWN,
    14081276                       &data_blob_null);
    14091277        return 0;
    14101278}
    14111279
    1412 static void setup_new_vc_session(void)
     1280static void setup_new_vc_session(struct smbd_server_connection *sconn)
    14131281{
    1414         char addr[INET6_ADDRSTRLEN];
    1415 
    14161282        DEBUG(2,("setup_new_vc_session: New VC == 0, if NT4.x "
    14171283                "compatible we would close all old resources.\n"));
     
    14211287#endif
    14221288        if (lp_reset_on_zero_vc()) {
    1423                 connections_forall(shutdown_other_smbds,
    1424                         CONST_DISCARD(void *,
    1425                         client_addr(get_client_fd(),addr,sizeof(addr))));
     1289                char *addr;
     1290                struct shutdown_state state;
     1291
     1292                addr = tsocket_address_inet_addr_string(
     1293                        sconn->remote_address, talloc_tos());
     1294                if (addr == NULL) {
     1295                        return;
     1296                }
     1297                state.ip = addr;
     1298                state.msg_ctx = sconn->msg_ctx;
     1299                connections_forall_read(shutdown_other_smbds, &state);
     1300                TALLOC_FREE(addr);
    14261301        }
    14271302}
     
    14401315        char *tmp;
    14411316        const char *user;
    1442         fstring sub_user; /* Sainitised username for substituion */
     1317        fstring sub_user; /* Sanitised username for substituion */
    14431318        const char *domain;
    14441319        const char *native_os;
    14451320        const char *native_lanman;
    14461321        const char *primary_domain;
    1447         auth_usersupplied_info *user_info = NULL;
    1448         auth_serversupplied_info *server_info = NULL;
     1322        struct auth_usersupplied_info *user_info = NULL;
     1323        struct auth_serversupplied_info *server_info = NULL;
    14491324        uint16 smb_flag2 = req->flags2;
    14501325
    14511326        NTSTATUS nt_status;
    1452         struct smbd_server_connection *sconn = smbd_server_conn;
     1327        struct smbd_server_connection *sconn = req->sconn;
    14531328
    14541329        bool doencrypt = sconn->smb1.negprot.encrypted_passwords;
     
    14781353
    14791354                if (SVAL(req->vwv+4, 0) == 0) {
    1480                         setup_new_vc_session();
     1355                        setup_new_vc_session(req->sconn);
    14811356                }
    14821357
     
    16751550
    16761551        if (SVAL(req->vwv+4, 0) == 0) {
    1677                 setup_new_vc_session();
     1552                setup_new_vc_session(req->sconn);
    16781553        }
    16791554
     
    17021577        sub_set_smb_name(sub_user);
    17031578
    1704         reload_services(True);
     1579        reload_services(sconn->msg_ctx, sconn->sock, True);
    17051580
    17061581        if (lp_security() == SEC_SHARE) {
     1582                char *sub_user_mapped = NULL;
    17071583                /* In share level we should ignore any passwords */
    17081584
     
    17111587                data_blob_clear_free(&plaintext_password);
    17121588
    1713                 map_username(sconn, sub_user);
     1589                (void)map_username(talloc_tos(), sub_user, &sub_user_mapped);
     1590                if (!sub_user_mapped) {
     1591                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     1592                        END_PROFILE(SMBsesssetupX);
     1593                        return;
     1594                }
     1595                fstrcpy(sub_user, sub_user_mapped);
    17141596                add_session_user(sconn, sub_user);
    17151597                add_session_workgroup(sconn, domain);
     
    17461628
    17471629                nt_status = make_auth_context_subsystem(
    1748                                 &plaintext_auth_context);
     1630                        talloc_tos(), &plaintext_auth_context);
    17491631
    17501632                if (NT_STATUS_IS_OK(nt_status)) {
     
    17661648                                                &server_info);
    17671649
    1768                                 (plaintext_auth_context->free)(
    1769                                                 &plaintext_auth_context);
     1650                                TALLOC_FREE(plaintext_auth_context);
    17701651                        }
    17711652                }
     
    17961677        }
    17971678
    1798         if (!server_info->ptok) {
     1679        if (!server_info->security_token) {
    17991680                nt_status = create_local_token(server_info);
    18001681
     
    18561737
    18571738                /* current_user_info is changed on new vuid */
    1858                 reload_services( True );
     1739                reload_services(sconn->msg_ctx, sconn->sock, True);
    18591740        }
    18601741
Note: See TracChangeset for help on using the changeset viewer.