Ignore:
Timestamp:
Mar 12, 2008, 9:08:18 AM (17 years ago)
Author:
Paul Smedley
Message:

Update source to 3.0.28a

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/nsswitch/winbindd_cm.c

    r71 r124  
    586586}
    587587
     588/**
     589 * Helper function to assemble trust password and account name
     590 */
     591static NTSTATUS get_trust_creds(const struct winbindd_domain *domain,
     592                                char **machine_password,
     593                                char **machine_account,
     594                                char **machine_krb5_principal)
     595{
     596        const char *account_name;
     597
     598        if (!get_trust_pw_clear(domain->name, machine_password,
     599                                &account_name, NULL))
     600        {
     601                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
     602        }
     603
     604        if ((machine_account != NULL) &&
     605            (asprintf(machine_account, "%s$", account_name) == -1))
     606        {
     607                return NT_STATUS_NO_MEMORY;
     608        }
     609
     610        /* this is at least correct when domain is our domain,
     611         * which is the only case, when this is currently used: */
     612        if (machine_krb5_principal != NULL)
     613        {
     614                if (asprintf(machine_krb5_principal, "%s$@%s",
     615                             account_name, domain->alt_name) == -1)
     616                {
     617                        return NT_STATUS_NO_MEMORY;
     618                }
     619
     620                strupper_m(*machine_krb5_principal);
     621        }
     622
     623        return NT_STATUS_OK;
     624}
     625
    588626/************************************************************************
    589627 Given a fd with a just-connected TCP connection to a DC, open a connection
     
    597635                                      BOOL *retry)
    598636{
    599         char *machine_password, *machine_krb5_principal, *machine_account;
    600         char *ipc_username, *ipc_domain, *ipc_password;
     637        char *machine_password = NULL;
     638        char *machine_krb5_principal = NULL;
     639        char *machine_account = NULL;
     640        char *ipc_username = NULL;
     641        char *ipc_domain = NULL;
     642        char *ipc_password = NULL;
    601643
    602644        BOOL got_mutex;
     
    611653        DEBUG(10,("cm_prepare_connection: connecting to DC %s for domain %s\n",
    612654                controller, domain->name ));
    613 
    614         machine_password = secrets_fetch_machine_password(lp_workgroup(), NULL,
    615                                                           NULL);
    616        
    617         if (asprintf(&machine_account, "%s$", global_myname()) == -1) {
    618                 SAFE_FREE(machine_password);
    619                 return NT_STATUS_NO_MEMORY;
    620         }
    621 
    622         if (asprintf(&machine_krb5_principal, "%s$@%s", global_myname(),
    623                      lp_realm()) == -1) {
    624                 SAFE_FREE(machine_account);
    625                 SAFE_FREE(machine_password);
    626                 return NT_STATUS_NO_MEMORY;
    627         }
    628 
    629         cm_get_ipc_userpass(&ipc_username, &ipc_domain, &ipc_password);
    630655
    631656        *retry = True;
     
    685710                goto done;
    686711        }
    687                        
    688         if ((*cli)->protocol >= PROTOCOL_NT1 && (*cli)->capabilities & CAP_EXTENDED_SECURITY) {
     712
     713        if (!is_trusted_domain_situation(domain->name) &&
     714            (*cli)->protocol >= PROTOCOL_NT1 &&
     715            (*cli)->capabilities & CAP_EXTENDED_SECURITY)
     716        {
    689717                ADS_STATUS ads_status;
     718
     719                result = get_trust_creds(domain, &machine_password,
     720                                         &machine_account,
     721                                         &machine_krb5_principal);
     722                if (!NT_STATUS_IS_OK(result)) {
     723                        goto done;
     724                }
    690725
    691726                if (lp_security() == SEC_ADS) {
     
    701736                                                              machine_krb5_principal,
    702737                                                              machine_password,
    703                                                               lp_workgroup());
     738                                                              domain->name);
    704739
    705740                        if (!ADS_ERR_OK(ads_status)) {
     
    711746                        if (NT_STATUS_IS_OK(result)) {
    712747                                /* Ensure creds are stored for NTLMSSP authenticated pipe access. */
    713                                 cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
     748                                cli_init_creds(*cli, machine_account, domain->name, machine_password);
    714749                                goto session_setup_done;
    715750                        }
     
    721756                DEBUG(5, ("connecting to %s from %s with username "
    722757                          "[%s]\\[%s]\n",  controller, global_myname(),
    723                           lp_workgroup(), machine_account));
     758                          domain->name, machine_account));
    724759
    725760                ads_status = cli_session_setup_spnego(*cli,
    726761                                                      machine_account,
    727762                                                      machine_password,
    728                                                       lp_workgroup());
     763                                                      domain->name);
    729764                if (!ADS_ERR_OK(ads_status)) {
    730765                        DEBUG(4, ("authenticated session setup failed with %s\n",
     
    735770                if (NT_STATUS_IS_OK(result)) {
    736771                        /* Ensure creds are stored for NTLMSSP authenticated pipe access. */
    737                         cli_init_creds(*cli, machine_account, lp_workgroup(), machine_password);
     772                        cli_init_creds(*cli, machine_account, domain->name, machine_password);
    738773                        goto session_setup_done;
    739774                }
    740775        }
    741776
    742         /* Fall back to non-kerberos session setup */
     777        /* Fall back to non-kerberos session setup with auth_user */
    743778
    744779        (*cli)->use_kerberos = False;
     780
     781        cm_get_ipc_userpass(&ipc_username, &ipc_domain, &ipc_password);
    745782
    746783        if ((((*cli)->sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) != 0) &&
     
    908945        p += 2;
    909946
    910         p += dos_PutUniCode(p, global_myname(), sizeof(pstring), True);
     947        p += dos_PutUniCode(p, global_myname(),
     948                sizeof(outbuf) - PTR_DIFF(p, outbuf), True);
    911949        fstr_sprintf(my_acct_name, "%s$", global_myname());
    912         p += dos_PutUniCode(p, my_acct_name, sizeof(pstring), True);
     950        p += dos_PutUniCode(p, my_acct_name,
     951                        sizeof(outbuf) - PTR_DIFF(p, outbuf), True);
     952
     953        if (strlen(my_mailslot)+1 > sizeof(outbuf) - PTR_DIFF(p, outbuf)) {
     954                return False;
     955        }
    913956
    914957        memcpy(p, my_mailslot, strlen(my_mailslot)+1);
    915958        p += strlen(my_mailslot)+1;
    916959
     960        if (sizeof(outbuf) - PTR_DIFF(p, outbuf) < 8) {
     961                return False;
     962        }
    917963        SIVAL(p, 0, 0x80);
    918964        p+=4;
     
    923969        p = ALIGN4(p, outbuf);
    924970
    925         sid_linearize(p, sid_size(sid), sid);
     971        if (PTR_DIFF(p, outbuf) > sizeof(outbuf)) {
     972                return False;
     973        }
     974
     975        if (sid_size(sid) + 8 > sizeof(outbuf) - PTR_DIFF(p, outbuf)) {
     976                return False;
     977        }
     978
     979        sid_linearize(p, sizeof(outbuf) - PTR_DIFF(p, outbuf), sid);
    926980        p += sid_size(sid);
    927981
     
    16901744        fstring conn_pwd;
    16911745        struct dcinfo *p_dcinfo;
     1746        char *machine_password = NULL;
     1747        char *machine_account = NULL;
     1748        char *domain_name = NULL;
    16921749
    16931750        result = init_dc_connection(domain);
     
    17121769        if ((conn->cli->user_name[0] == '\0') ||
    17131770            (conn->cli->domain[0] == '\0') ||
    1714             (conn_pwd[0] == '\0')) {
    1715                 DEBUG(10, ("cm_connect_sam: No no user available for "
    1716                            "domain %s, trying schannel\n", conn->cli->domain));
    1717                 goto schannel;
     1771            (conn_pwd[0] == '\0'))
     1772        {
     1773                result = get_trust_creds(domain, &machine_password,
     1774                                         &machine_account, NULL);
     1775                if (!NT_STATUS_IS_OK(result)) {
     1776                        DEBUG(10, ("cm_connect_sam: No no user available for "
     1777                                   "domain %s, trying schannel\n", conn->cli->domain));
     1778                        goto schannel;
     1779                }
     1780                domain_name = domain->name;
     1781        } else {
     1782                machine_password = SMB_STRDUP(conn_pwd);               
     1783                machine_account = SMB_STRDUP(conn->cli->user_name);
     1784                domain_name = conn->cli->domain;
     1785        }
     1786
     1787        if (!machine_password || !machine_account) {
     1788                result = NT_STATUS_NO_MEMORY;
     1789                goto done;
    17181790        }
    17191791
     
    17231795                cli_rpc_pipe_open_spnego_ntlmssp(conn->cli, PI_SAMR,
    17241796                                                 PIPE_AUTH_LEVEL_PRIVACY,
    1725                                                  conn->cli->domain,
    1726                                                  conn->cli->user_name,
    1727                                                  conn_pwd, &result);
     1797                                                 domain_name,
     1798                                                 machine_account,
     1799                                                 machine_password, &result);
    17281800
    17291801        if (conn->samr_pipe == NULL) {
     
    17311803                          "pipe for domain %s using NTLMSSP "
    17321804                          "authenticated pipe: user %s\\%s. Error was "
    1733                           "%s\n", domain->name, conn->cli->domain,
    1734                           conn->cli->user_name, nt_errstr(result)));
     1805                          "%s\n", domain->name, domain_name,
     1806                          machine_account, nt_errstr(result)));
    17351807                goto schannel;
    17361808        }
     
    17391811                  "domain %s using NTLMSSP authenticated "
    17401812                  "pipe: user %s\\%s\n", domain->name,
    1741                   conn->cli->domain, conn->cli->user_name ));
     1813                  domain_name, machine_account));
    17421814
    17431815        result = rpccli_samr_connect(conn->samr_pipe, mem_ctx,
     
    18241896        *cli = conn->samr_pipe;
    18251897        *sam_handle = conn->sam_domain_handle;
     1898        SAFE_FREE(machine_password);
     1899        SAFE_FREE(machine_account);
    18261900        return result;
    18271901}
     
    19542028        NTSTATUS result;
    19552029
    1956         uint32 neg_flags = NETLOGON_NEG_AUTH2_FLAGS;
     2030        uint32 neg_flags = NETLOGON_NEG_SELECT_AUTH2_FLAGS;
    19572031        uint8  mach_pwd[16];
    19582032        uint32  sec_chan_type;
     
    19742048        }
    19752049
    1976         if (!get_trust_pw(domain->name, mach_pwd, &sec_chan_type)) {
    1977                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
    1978         }
    1979 
    19802050        netlogon_pipe = cli_rpc_pipe_open_noauth(conn->cli, PI_NETLOGON,
    19812051                                                 &result);
     
    19842054        }
    19852055
     2056        if ((!IS_DC) && (!domain->primary)) {
     2057                /* Clear the schannel request bit and drop down */
     2058                neg_flags &= ~NETLOGON_NEG_SCHANNEL;           
     2059                goto no_schannel;
     2060        }
     2061
    19862062        if (lp_client_schannel() != False) {
    19872063                neg_flags |= NETLOGON_NEG_SCHANNEL;
    19882064        }
    19892065
    1990         /* if we are a DC and this is a trusted domain, then we need to use our
    1991            domain name in the net_req_auth2() request */
    1992 
    1993         if ( IS_DC
    1994                 && !strequal(domain->name, lp_workgroup())
    1995                 && lp_allow_trusted_domains() )
     2066        if (!get_trust_pw_hash(domain->name, mach_pwd, &account_name,
     2067                               &sec_chan_type))
    19962068        {
    1997                 account_name = lp_workgroup();
    1998         } else {
    1999                 account_name = domain->primary ?
    2000                         global_myname() : domain->name;
    2001         }
    2002 
    2003         if (account_name == NULL) {
    20042069                cli_rpc_pipe_close(netlogon_pipe);
    2005                 return NT_STATUS_NO_MEMORY;
     2070                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
    20062071        }
    20072072
     
    20282093        }
    20292094
     2095 no_schannel:
    20302096        if ((lp_client_schannel() == False) ||
    20312097                        ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) {
Note: See TracChangeset for help on using the changeset viewer.