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/winbindd/winbindd_cm.c

    r596 r745  
    6262#include "winbindd.h"
    6363#include "../libcli/auth/libcli_auth.h"
    64 #include "../librpc/gen_ndr/cli_netlogon.h"
    65 #include "../librpc/gen_ndr/cli_samr.h"
    66 #include "../librpc/gen_ndr/cli_lsa.h"
    67 #include "../librpc/gen_ndr/cli_dssetup.h"
     64#include "../librpc/gen_ndr/ndr_netlogon_c.h"
     65#include "rpc_client/cli_pipe.h"
     66#include "rpc_client/cli_netlogon.h"
     67#include "../librpc/gen_ndr/ndr_samr_c.h"
     68#include "../librpc/gen_ndr/ndr_lsa_c.h"
     69#include "rpc_client/cli_lsarpc.h"
     70#include "../librpc/gen_ndr/ndr_dssetup_c.h"
     71#include "libads/sitename_cache.h"
     72#include "libsmb/libsmb.h"
     73#include "libsmb/clidgram.h"
     74#include "ads.h"
     75#include "secrets.h"
     76#include "../libcli/security/security.h"
     77#include "passdb.h"
     78#include "messages.h"
    6879
    6980#undef DBGC_CLASS
     
    179190        pid_t parent_pid = sys_getpid();
    180191        char *lfile = NULL;
     192        NTSTATUS status;
    181193
    182194        if (domain->dc_probe_pid != (pid_t)-1) {
     
    223235        }
    224236
    225         if (!winbindd_reinit_after_fork(lfile)) {
     237        status = winbindd_reinit_after_fork(NULL, lfile);
     238        if (!NT_STATUS_IS_OK(status)) {
     239                DEBUG(1, ("winbindd_reinit_after_fork failed: %s\n",
     240                          nt_errstr(status)));
    226241                messaging_send_buf(winbind_messaging_context(),
    227242                                   pid_to_procid(parent_pid),
     
    285300        /* Are we still in "startup" mode ? */
    286301
    287         if (domain->startup && (now.tv_sec > domain->startup_time + 30)) {
     302        if (domain->startup && (time_mono(NULL) > domain->startup_time + 30)) {
    288303                /* No longer in "startup" mode. */
    289304                DEBUG(10,("check_domain_online_handler: domain %s no longer in 'startup' mode.\n",
     
    502517
    503518        /* Go into "startup" mode again. */
    504         domain->startup_time = tev.tv_sec;
     519        domain->startup_time = time_mono(NULL);
    505520        domain->startup = True;
    506521
     
    535550****************************************************************/
    536551
    537 void winbind_add_failed_connection_entry(const struct winbindd_domain *domain,
    538                                         const char *server,
    539                                         NTSTATUS result)
     552static void winbind_add_failed_connection_entry(
     553        const struct winbindd_domain *domain,
     554        const char *server,
     555        NTSTATUS result)
    540556{
    541557        add_failed_connection_entry(domain->name, server, result);
     
    595611        const char *tmp = NULL;
    596612        const char *p;
     613        struct dcerpc_binding_handle *b;
    597614
    598615        /* Hmmmm. We can only open one connection to the NETLOGON pipe at the
     
    619636        }
    620637
     638        b = netlogon_pipe->binding_handle;
     639
    621640        /* This call can take a long time - allow the server to time out.
    622641           35 seconds should do it. */
     
    627646                struct netr_DsRGetDCNameInfo *domain_info = NULL;
    628647
    629                 result = rpccli_netr_DsRGetDCName(netlogon_pipe,
     648                result = dcerpc_netr_DsRGetDCName(b,
    630649                                                  mem_ctx,
    631650                                                  our_domain->dcname,
     
    654673                }
    655674        } else {
    656                 result = rpccli_netr_GetAnyDCName(netlogon_pipe, mem_ctx,
     675                result = dcerpc_netr_GetAnyDCName(b, mem_ctx,
    657676                                                  our_domain->dcname,
    658677                                                  domain->name,
     
    665684
    666685        if (!NT_STATUS_IS_OK(result)) {
    667                 DEBUG(10,("rpccli_netr_GetAnyDCName failed: %s\n",
     686                DEBUG(10,("dcerpc_netr_GetAnyDCName failed: %s\n",
    668687                        nt_errstr(result)));
    669688                talloc_destroy(mem_ctx);
     
    672691
    673692        if (!W_ERROR_IS_OK(werr)) {
    674                 DEBUG(10,("rpccli_netr_GetAnyDCName failed: %s\n",
     693                DEBUG(10,("dcerpc_netr_GetAnyDCName failed: %s\n",
    675694                           win_errstr(werr)));
    676695                talloc_destroy(mem_ctx);
     
    678697        }
    679698
    680         /* rpccli_netr_GetAnyDCName gives us a name with \\ */
     699        /* dcerpc_netr_GetAnyDCName gives us a name with \\ */
    681700        p = strip_hostname(tmp);
    682701
     
    685704        talloc_destroy(mem_ctx);
    686705
    687         DEBUG(10,("rpccli_netr_GetAnyDCName returned %s\n", dcname));
     706        DEBUG(10,("dcerpc_netr_GetAnyDCName returned %s\n", dcname));
    688707
    689708        if (!resolve_name(dcname, dc_ss, 0x20, true)) {
     
    802821        (*cli)->timeout = 10000;        /* 10 seconds */
    803822        (*cli)->fd = sockfd;
    804         fstrcpy((*cli)->desthost, controller);
     823        (*cli)->desthost = talloc_strdup((*cli), controller);
     824        if ((*cli)->desthost == NULL) {
     825                result = NT_STATUS_NO_MEMORY;
     826                goto done;
     827        }
     828
    805829        (*cli)->use_kerberos = True;
    806830
     
    10991123        struct ip_service ip_list;
    11001124        uint32_t nt_version = NETLOGON_NT_VERSION_1;
     1125        NTSTATUS status;
     1126        const char *dc_name;
    11011127
    11021128        ip_list.ss = *pss;
    11031129        ip_list.port = 0;
    11041130
    1105 #ifdef WITH_ADS
     1131#ifdef HAVE_ADS
    11061132        /* For active directory servers, try to get the ldap server name.
    11071133           None of these failures should be considered critical for now */
     
    11631189#endif
    11641190
    1165         /* try GETDC requests next */
    1166 
    1167         if (send_getdc_request(mem_ctx, winbind_messaging_context(),
    1168                                pss, domain->name, &domain->sid,
    1169                                nt_version)) {
    1170                 const char *dc_name = NULL;
    1171                 int i;
    1172                 smb_msleep(100);
    1173                 for (i=0; i<5; i++) {
    1174                         if (receive_getdc_response(mem_ctx, pss, domain->name,
    1175                                                    &nt_version,
    1176                                                    &dc_name, NULL)) {
    1177                                 fstrcpy(name, dc_name);
    1178                                 namecache_store(name, 0x20, 1, &ip_list);
    1179                                 return True;
    1180                         }
    1181                         smb_msleep(500);
    1182                 }
     1191        status = nbt_getdc(winbind_messaging_context(), pss, domain->name,
     1192                           &domain->sid, nt_version, mem_ctx, &nt_version,
     1193                           &dc_name, NULL);
     1194        if (NT_STATUS_IS_OK(status)) {
     1195                fstrcpy(name, dc_name);
     1196                namecache_store(name, 0x20, 1, &ip_list);
     1197                return True;
    11831198        }
    11841199
     
    13691384                return False;
    13701385
    1371         status = smbsock_any_connect(addrs, dcnames, num_addrs,
    1372                                      fd, &fd_index, NULL);
     1386        status = smbsock_any_connect(addrs, dcnames, NULL, NULL, NULL,
     1387                                     num_addrs, 0, 10, fd, &fd_index, NULL);
    13731388        if (!NT_STATUS_IS_OK(status)) {
    13741389                for (i=0; i<num_dcs; i++) {
     
    14171432}
    14181433
     1434static char *current_dc_key(TALLOC_CTX *mem_ctx, const char *domain_name)
     1435{
     1436        return talloc_asprintf_strupper_m(mem_ctx, "CURRENT_DCNAME/%s",
     1437                                          domain_name);
     1438}
     1439
     1440static void store_current_dc_in_gencache(const char *domain_name,
     1441                                         const char *dc_name,
     1442                                         struct cli_state *cli)
     1443{
     1444        char addr[INET6_ADDRSTRLEN];
     1445        char *key = NULL;
     1446        char *value = NULL;
     1447
     1448        if (cli == NULL) {
     1449                return;
     1450        }
     1451        if (cli->fd == -1) {
     1452                return;
     1453        }
     1454        get_peer_addr(cli->fd, addr, sizeof(addr));
     1455
     1456        key = current_dc_key(talloc_tos(), domain_name);
     1457        if (key == NULL) {
     1458                goto done;
     1459        }
     1460
     1461        value = talloc_asprintf(talloc_tos(), "%s %s", addr, dc_name);
     1462        if (value == NULL) {
     1463                goto done;
     1464        }
     1465
     1466        gencache_set(key, value, 0x7fffffff);
     1467done:
     1468        TALLOC_FREE(value);
     1469        TALLOC_FREE(key);
     1470}
     1471
     1472bool fetch_current_dc_from_gencache(TALLOC_CTX *mem_ctx,
     1473                                    const char *domain_name,
     1474                                    char **p_dc_name, char **p_dc_ip)
     1475{
     1476        char *key, *value, *p;
     1477        bool ret = false;
     1478        char *dc_name = NULL;
     1479        char *dc_ip = NULL;
     1480
     1481        key = current_dc_key(talloc_tos(), domain_name);
     1482        if (key == NULL) {
     1483                goto done;
     1484        }
     1485        if (!gencache_get(key, &value, NULL)) {
     1486                goto done;
     1487        }
     1488        p = strchr(value, ' ');
     1489        if (p == NULL) {
     1490                goto done;
     1491        }
     1492        dc_ip = talloc_strndup(mem_ctx, value, p - value);
     1493        if (dc_ip == NULL) {
     1494                goto done;
     1495        }
     1496        dc_name = talloc_strdup(mem_ctx, p+1);
     1497        if (dc_name == NULL) {
     1498                goto done;
     1499        }
     1500
     1501        if (p_dc_ip != NULL) {
     1502                *p_dc_ip = dc_ip;
     1503                dc_ip = NULL;
     1504        }
     1505        if (p_dc_name != NULL) {
     1506                *p_dc_name = dc_name;
     1507                dc_name = NULL;
     1508        }
     1509        ret = true;
     1510done:
     1511        TALLOC_FREE(dc_name);
     1512        TALLOC_FREE(dc_ip);
     1513        TALLOC_FREE(key);
     1514        return ret;
     1515}
     1516
    14191517static NTSTATUS cm_open_connection(struct winbindd_domain *domain,
    14201518                                   struct winbindd_cm_conn *new_conn)
     
    14321530
    14331531        /* we have to check the server affinity cache here since
    1434            later we selecte a DC based on response time and not preference */
     1532           later we select a DC based on response time and not preference */
    14351533
    14361534        /* Check the negative connection cache
     
    14811579                        NTSTATUS status;
    14821580
    1483                         status = smbsock_connect(&domain->dcaddr, NULL, NULL,
    1484                                                  &fd, NULL);
     1581                        status = smbsock_connect(&domain->dcaddr, 0,
     1582                                                 NULL, -1, NULL, -1,
     1583                                                 &fd, NULL, 10);
    14851584                        if (!NT_STATUS_IS_OK(status)) {
    14861585                                fd = -1;
     
    15171616                }
    15181617                set_domain_online(domain);
     1618
     1619                /*
     1620                 * Much as I hate global state, this seems to be the point
     1621                 * where we can be certain that we have a proper connection to
     1622                 * a DC. wbinfo --dc-info needs that information, store it in
     1623                 * gencache with a looong timeout. This will need revisiting
     1624                 * once we start to connect to multiple DCs, wbcDcInfo is
     1625                 * already prepared for that.
     1626                 */
     1627                store_current_dc_in_gencache(domain->name, domain->dcname,
     1628                                             new_conn->cli);
    15191629        } else {
    15201630                /* Ensure we setup the retry handler. */
     
    15301640void invalidate_cm_connection(struct winbindd_cm_conn *conn)
    15311641{
     1642        NTSTATUS result;
     1643
    15321644        /* We're closing down a possibly dead
    15331645           connection. Don't have impossibly long (10s) timeouts. */
     
    15381650
    15391651        if (conn->samr_pipe != NULL) {
     1652                if (is_valid_policy_hnd(&conn->sam_connect_handle)) {
     1653                        dcerpc_samr_Close(conn->samr_pipe->binding_handle,
     1654                                          talloc_tos(),
     1655                                          &conn->sam_connect_handle,
     1656                                          &result);
     1657                }
    15401658                TALLOC_FREE(conn->samr_pipe);
    15411659                /* Ok, it must be dead. Drop timeout to 0.5 sec. */
     
    15461664
    15471665        if (conn->lsa_pipe != NULL) {
     1666                if (is_valid_policy_hnd(&conn->lsa_policy)) {
     1667                        dcerpc_lsa_Close(conn->lsa_pipe->binding_handle,
     1668                                         talloc_tos(),
     1669                                         &conn->lsa_policy,
     1670                                         &result);
     1671                }
    15481672                TALLOC_FREE(conn->lsa_pipe);
    15491673                /* Ok, it must be dead. Drop timeout to 0.5 sec. */
     
    15541678
    15551679        if (conn->lsa_pipe_tcp != NULL) {
     1680                if (is_valid_policy_hnd(&conn->lsa_policy)) {
     1681                        dcerpc_lsa_Close(conn->lsa_pipe_tcp->binding_handle,
     1682                                         talloc_tos(),
     1683                                         &conn->lsa_policy,
     1684                                         &result);
     1685                }
    15561686                TALLOC_FREE(conn->lsa_pipe_tcp);
    15571687                /* Ok, it must be dead. Drop timeout to 0.5 sec. */
     
    15791709{
    15801710        struct winbindd_domain *domain;
     1711        struct winbindd_cli_state *cli_state;
    15811712
    15821713        for (domain = domain_list(); domain; domain = domain->next) {
    1583                 if (domain->conn.cli == NULL)
    1584                         continue;
    1585 
    1586                 if (domain->conn.cli->fd == -1)
    1587                         continue;
    1588 
    1589                 close(domain->conn.cli->fd);
    1590                 domain->conn.cli->fd = -1;
     1714                struct cli_state *cli = domain->conn.cli;
     1715
     1716                /*
     1717                 * first close the low level SMB TCP connection
     1718                 * so that we don't generate any SMBclose
     1719                 * requests in invalidate_cm_connection()
     1720                 */
     1721                if (cli && cli->fd != -1) {
     1722                        close(domain->conn.cli->fd);
     1723                        domain->conn.cli->fd = -1;
     1724                }
     1725
     1726                invalidate_cm_connection(&domain->conn);
     1727        }
     1728
     1729        for (cli_state = winbindd_client_list();
     1730             cli_state != NULL;
     1731             cli_state = cli_state->next) {
     1732                if (cli_state->sock >= 0) {
     1733                        close(cli_state->sock);
     1734                        cli_state->sock = -1;
     1735                }
    15911736        }
    15921737}
     
    16501795NTSTATUS init_dc_connection(struct winbindd_domain *domain)
    16511796{
     1797        if (domain->internal) {
     1798                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
     1799        }
     1800
    16521801        if (domain->initialized && !domain->online) {
    16531802                /* We check for online status elsewhere. */
     
    16831832        struct winbindd_domain *our_domain;
    16841833        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     1834        WERROR werr;
    16851835        struct netr_DomainTrustList trusts;
    16861836        int i;
     
    16901840        struct rpc_pipe_client *cli;
    16911841        TALLOC_CTX *mem_ctx = NULL;
     1842        struct dcerpc_binding_handle *b;
    16921843
    16931844        DEBUG(5, ("set_dc_type_and_flags_trustinfo: domain %s\n", domain->name ));
     
    17241875        }
    17251876
     1877        b = cli->binding_handle;
     1878
    17261879        if ( (mem_ctx = talloc_init("set_dc_type_and_flags_trustinfo")) == NULL ) {
    17271880                DEBUG(0,("set_dc_type_and_flags_trustinfo: talloc_init() failed!\n"));
     
    17291882        }       
    17301883
    1731         result = rpccli_netr_DsrEnumerateDomainTrusts(cli, mem_ctx,
     1884        result = dcerpc_netr_DsrEnumerateDomainTrusts(b, mem_ctx,
    17321885                                                      cli->desthost,
    17331886                                                      flags,
    17341887                                                      &trusts,
    1735                                                       NULL);
     1888                                                      &werr);
    17361889        if (!NT_STATUS_IS_OK(result)) {
    17371890                DEBUG(0,("set_dc_type_and_flags_trustinfo: "
     
    17411894                return false;
    17421895        }
     1896        if (!W_ERROR_IS_OK(werr)) {
     1897                DEBUG(0,("set_dc_type_and_flags_trustinfo: "
     1898                        "failed to query trusted domain list: %s\n",
     1899                        win_errstr(werr)));
     1900                talloc_destroy(mem_ctx);
     1901                return false;
     1902        }
    17431903
    17441904        /* Now find the domain name and get the flags */
     
    17891949static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
    17901950{
    1791         NTSTATUS                result;
     1951        NTSTATUS status, result;
    17921952        WERROR werr;
    17931953        TALLOC_CTX              *mem_ctx = NULL;
     
    18101970        DEBUG(5, ("set_dc_type_and_flags_connect: domain %s\n", domain->name ));
    18111971
    1812         result = cli_rpc_pipe_open_noauth(domain->conn.cli,
     1972        status = cli_rpc_pipe_open_noauth(domain->conn.cli,
    18131973                                          &ndr_table_dssetup.syntax_id,
    18141974                                          &cli);
    18151975
    1816         if (!NT_STATUS_IS_OK(result)) {
     1976        if (!NT_STATUS_IS_OK(status)) {
    18171977                DEBUG(5, ("set_dc_type_and_flags_connect: Could not bind to "
    18181978                          "PI_DSSETUP on domain %s: (%s)\n",
    1819                           domain->name, nt_errstr(result)));
     1979                          domain->name, nt_errstr(status)));
    18201980
    18211981                /* if this is just a non-AD domain we need to continue
     
    18261986        }
    18271987
    1828         result = rpccli_dssetup_DsRoleGetPrimaryDomainInformation(cli, mem_ctx,
     1988        status = dcerpc_dssetup_DsRoleGetPrimaryDomainInformation(cli->binding_handle, mem_ctx,
    18291989                                                                  DS_ROLE_BASIC_INFORMATION,
    18301990                                                                  &info,
     
    18321992        TALLOC_FREE(cli);
    18331993
    1834         if (!NT_STATUS_IS_OK(result)) {
     1994        if (NT_STATUS_IS_OK(status)) {
     1995                result = werror_to_ntstatus(werr);
     1996        }
     1997        if (!NT_STATUS_IS_OK(status)) {
    18351998                DEBUG(5, ("set_dc_type_and_flags_connect: rpccli_ds_getprimarydominfo "
    18361999                          "on domain %s failed: (%s)\n",
    1837                           domain->name, nt_errstr(result)));
     2000                          domain->name, nt_errstr(status)));
    18382001
    18392002                /* older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for
     
    18422005                 * set - gd */
    18432006
    1844                 if (NT_STATUS_V(result) == DCERPC_FAULT_OP_RNG_ERROR) {
     2007                if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
    18452008                        goto no_dssetup;
    18462009                }
     
    18582021
    18592022no_dssetup:
    1860         result = cli_rpc_pipe_open_noauth(domain->conn.cli,
     2023        status = cli_rpc_pipe_open_noauth(domain->conn.cli,
    18612024                                          &ndr_table_lsarpc.syntax_id, &cli);
    18622025
    1863         if (!NT_STATUS_IS_OK(result)) {
     2026        if (!NT_STATUS_IS_OK(status)) {
    18642027                DEBUG(5, ("set_dc_type_and_flags_connect: Could not bind to "
    18652028                          "PI_LSARPC on domain %s: (%s)\n",
    1866                           domain->name, nt_errstr(result)));
     2029                          domain->name, nt_errstr(status)));
    18672030                TALLOC_FREE(cli);
    18682031                TALLOC_FREE(mem_ctx);
     
    18702033        }
    18712034
    1872         result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
     2035        status = rpccli_lsa_open_policy2(cli, mem_ctx, True,
    18732036                                         SEC_FLAG_MAXIMUM_ALLOWED, &pol);
    18742037
    1875         if (NT_STATUS_IS_OK(result)) {
     2038        if (NT_STATUS_IS_OK(status)) {
    18762039                /* This particular query is exactly what Win2k clients use
    18772040                   to determine that the DC is active directory */
    1878                 result = rpccli_lsa_QueryInfoPolicy2(cli, mem_ctx,
     2041                status = dcerpc_lsa_QueryInfoPolicy2(cli->binding_handle, mem_ctx,
    18792042                                                     &pol,
    18802043                                                     LSA_POLICY_INFO_DNS,
    1881                                                      &lsa_info);
    1882         }
    1883 
    1884         if (NT_STATUS_IS_OK(result)) {
     2044                                                     &lsa_info,
     2045                                                     &result);
     2046        }
     2047
     2048        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
    18852049                domain->active_directory = True;
    18862050
     
    19122076                domain->active_directory = False;
    19132077
    1914                 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
     2078                status = rpccli_lsa_open_policy(cli, mem_ctx, True,
    19152079                                                SEC_FLAG_MAXIMUM_ALLOWED,
    19162080                                                &pol);
    19172081
    1918                 if (!NT_STATUS_IS_OK(result)) {
     2082                if (!NT_STATUS_IS_OK(status)) {
    19192083                        goto done;
    19202084                }
    19212085
    1922                 result = rpccli_lsa_QueryInfoPolicy(cli, mem_ctx,
     2086                status = dcerpc_lsa_QueryInfoPolicy(cli->binding_handle, mem_ctx,
    19232087                                                    &pol,
    19242088                                                    LSA_POLICY_INFO_ACCOUNT_DOMAIN,
    1925                                                     &lsa_info);
    1926 
    1927                 if (NT_STATUS_IS_OK(result)) {
     2089                                                    &lsa_info,
     2090                                                    &result);
     2091                if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
    19282092
    19292093                        if (lsa_info->account_domain.name.string) {
     
    19932157
    19942158        if (lp_client_schannel() == False) {
    1995                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;;
     2159                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
    19962160        }
    19972161
     
    20162180{
    20172181        struct winbindd_cm_conn *conn;
    2018         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     2182        NTSTATUS status, result;
    20192183        struct netlogon_creds_CredentialState *p_creds;
    20202184        char *machine_password = NULL;
     
    20222186        char *domain_name = NULL;
    20232187
    2024         result = init_dc_connection_rpc(domain);
    2025         if (!NT_STATUS_IS_OK(result)) {
    2026                 return result;
     2188        if (sid_check_is_domain(&domain->sid)) {
     2189                return open_internal_samr_conn(mem_ctx, domain, cli, sam_handle);
     2190        }
     2191
     2192        status = init_dc_connection_rpc(domain);
     2193        if (!NT_STATUS_IS_OK(status)) {
     2194                return status;
    20272195        }
    20282196
     
    20462214            (conn->cli->password == NULL || conn->cli->password[0] == '\0'))
    20472215        {
    2048                 result = get_trust_creds(domain, &machine_password,
     2216                status = get_trust_creds(domain, &machine_password,
    20492217                                         &machine_account, NULL);
    2050                 if (!NT_STATUS_IS_OK(result)) {
     2218                if (!NT_STATUS_IS_OK(status)) {
    20512219                        DEBUG(10, ("cm_connect_sam: No no user available for "
    20522220                                   "domain %s, trying schannel\n", conn->cli->domain));
     
    20612229
    20622230        if (!machine_password || !machine_account) {
    2063                 result = NT_STATUS_NO_MEMORY;
     2231                status = NT_STATUS_NO_MEMORY;
    20642232                goto done;
    20652233        }
     
    20672235        /* We have an authenticated connection. Use a NTLMSSP SPNEGO
    20682236           authenticated SAMR pipe with sign & seal. */
    2069         result = cli_rpc_pipe_open_spnego_ntlmssp(conn->cli,
     2237        status = cli_rpc_pipe_open_spnego_ntlmssp(conn->cli,
    20702238                                                  &ndr_table_samr.syntax_id,
    20712239                                                  NCACN_NP,
     
    20762244                                                  &conn->samr_pipe);
    20772245
    2078         if (!NT_STATUS_IS_OK(result)) {
     2246        if (!NT_STATUS_IS_OK(status)) {
    20792247                DEBUG(10,("cm_connect_sam: failed to connect to SAMR "
    20802248                          "pipe for domain %s using NTLMSSP "
    20812249                          "authenticated pipe: user %s\\%s. Error was "
    20822250                          "%s\n", domain->name, domain_name,
    2083                           machine_account, nt_errstr(result)));
     2251                          machine_account, nt_errstr(status)));
    20842252                goto schannel;
    20852253        }
     
    20902258                  domain_name, machine_account));
    20912259
    2092         result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
     2260        status = dcerpc_samr_Connect2(conn->samr_pipe->binding_handle, mem_ctx,
    20932261                                      conn->samr_pipe->desthost,
    20942262                                      SEC_FLAG_MAXIMUM_ALLOWED,
    2095                                       &conn->sam_connect_handle);
    2096         if (NT_STATUS_IS_OK(result)) {
     2263                                      &conn->sam_connect_handle,
     2264                                      &result);
     2265        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
    20972266                goto open_domain;
    20982267        }
    2099         DEBUG(10,("cm_connect_sam: ntlmssp-sealed rpccli_samr_Connect2 "
     2268        if (NT_STATUS_IS_OK(status)) {
     2269                status = result;
     2270        }
     2271
     2272        DEBUG(10,("cm_connect_sam: ntlmssp-sealed dcerpc_samr_Connect2 "
    21002273                  "failed for domain %s, error was %s. Trying schannel\n",
    2101                   domain->name, nt_errstr(result) ));
     2274                  domain->name, nt_errstr(status) ));
    21022275        TALLOC_FREE(conn->samr_pipe);
    21032276
     
    21062279        /* Fall back to schannel if it's a W2K pre-SP1 box. */
    21072280
    2108         result = cm_get_schannel_creds(domain, &p_creds);
    2109         if (!NT_STATUS_IS_OK(result)) {
     2281        status = cm_get_schannel_creds(domain, &p_creds);
     2282        if (!NT_STATUS_IS_OK(status)) {
    21102283                /* If this call fails - conn->cli can now be NULL ! */
    21112284                DEBUG(10, ("cm_connect_sam: Could not get schannel auth info "
    21122285                           "for domain %s (error %s), trying anon\n",
    21132286                        domain->name,
    2114                         nt_errstr(result) ));
     2287                        nt_errstr(status) ));
    21152288                goto anonymous;
    21162289        }
    2117         result = cli_rpc_pipe_open_schannel_with_key
     2290        status = cli_rpc_pipe_open_schannel_with_key
    21182291                (conn->cli, &ndr_table_samr.syntax_id, NCACN_NP,
    21192292                 DCERPC_AUTH_LEVEL_PRIVACY,
    21202293                 domain->name, &p_creds, &conn->samr_pipe);
    21212294
    2122         if (!NT_STATUS_IS_OK(result)) {
     2295        if (!NT_STATUS_IS_OK(status)) {
    21232296                DEBUG(10,("cm_connect_sam: failed to connect to SAMR pipe for "
    21242297                          "domain %s using schannel. Error was %s\n",
    2125                           domain->name, nt_errstr(result) ));
     2298                          domain->name, nt_errstr(status) ));
    21262299                goto anonymous;
    21272300        }
     
    21292302                  "schannel.\n", domain->name ));
    21302303
    2131         result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
     2304        status = dcerpc_samr_Connect2(conn->samr_pipe->binding_handle, mem_ctx,
    21322305                                      conn->samr_pipe->desthost,
    21332306                                      SEC_FLAG_MAXIMUM_ALLOWED,
    2134                                       &conn->sam_connect_handle);
    2135         if (NT_STATUS_IS_OK(result)) {
     2307                                      &conn->sam_connect_handle,
     2308                                      &result);
     2309        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(result)) {
    21362310                goto open_domain;
    21372311        }
    2138         DEBUG(10,("cm_connect_sam: schannel-sealed rpccli_samr_Connect2 failed "
     2312        if (NT_STATUS_IS_OK(status)) {
     2313                status = result;
     2314        }
     2315        DEBUG(10,("cm_connect_sam: schannel-sealed dcerpc_samr_Connect2 failed "
    21392316                  "for domain %s, error was %s. Trying anonymous\n",
    2140                   domain->name, nt_errstr(result) ));
     2317                  domain->name, nt_errstr(status) ));
    21412318        TALLOC_FREE(conn->samr_pipe);
    21422319
     
    21442321
    21452322        /* Finally fall back to anonymous. */
    2146         result = cli_rpc_pipe_open_noauth(conn->cli, &ndr_table_samr.syntax_id,
     2323        status = cli_rpc_pipe_open_noauth(conn->cli, &ndr_table_samr.syntax_id,
    21472324                                          &conn->samr_pipe);
    21482325
    2149         if (!NT_STATUS_IS_OK(result)) {
     2326        if (!NT_STATUS_IS_OK(status)) {
    21502327                goto done;
    21512328        }
    21522329
    2153         result = rpccli_samr_Connect2(conn->samr_pipe, mem_ctx,
     2330        status = dcerpc_samr_Connect2(conn->samr_pipe->binding_handle, mem_ctx,
    21542331                                      conn->samr_pipe->desthost,
    21552332                                      SEC_FLAG_MAXIMUM_ALLOWED,
    2156                                       &conn->sam_connect_handle);
    2157         if (!NT_STATUS_IS_OK(result)) {
     2333                                      &conn->sam_connect_handle,
     2334                                      &result);
     2335        if (!NT_STATUS_IS_OK(status)) {
    21582336                DEBUG(10,("cm_connect_sam: rpccli_samr_Connect2 failed "
    21592337                          "for domain %s Error was %s\n",
    2160                           domain->name, nt_errstr(result) ));
     2338                          domain->name, nt_errstr(status) ));
    21612339                goto done;
    21622340        }
     2341        if (!NT_STATUS_IS_OK(result)) {
     2342                status = result;
     2343                DEBUG(10,("cm_connect_sam: dcerpc_samr_Connect2 failed "
     2344                          "for domain %s Error was %s\n",
     2345                          domain->name, nt_errstr(result)));
     2346                goto done;
     2347        }
    21632348
    21642349 open_domain:
    2165         result = rpccli_samr_OpenDomain(conn->samr_pipe,
     2350        status = dcerpc_samr_OpenDomain(conn->samr_pipe->binding_handle,
    21662351                                        mem_ctx,
    21672352                                        &conn->sam_connect_handle,
    21682353                                        SEC_FLAG_MAXIMUM_ALLOWED,
    21692354                                        &domain->sid,
    2170                                         &conn->sam_domain_handle);
    2171 
     2355                                        &conn->sam_domain_handle,
     2356                                        &result);
     2357        if (!NT_STATUS_IS_OK(status)) {
     2358                goto done;
     2359        }
     2360
     2361        status = result;
    21722362 done:
    21732363
    2174         if (NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED)) {
     2364        if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
    21752365                /*
    21762366                 * if we got access denied, we might just have no access rights
     
    21822372                TALLOC_FREE(conn->samr_pipe);
    21832373                ZERO_STRUCT(conn->sam_domain_handle);
    2184                 return result;
    2185         } else if (!NT_STATUS_IS_OK(result)) {
     2374                return status;
     2375        } else if (!NT_STATUS_IS_OK(status)) {
    21862376                invalidate_cm_connection(conn);
    2187                 return result;
     2377                return status;
    21882378        }
    21892379
     
    21922382        SAFE_FREE(machine_password);
    21932383        SAFE_FREE(machine_account);
    2194         return result;
     2384        return status;
    21952385}
    21962386
     
    25042694        return NT_STATUS_OK;
    25052695}
     2696
     2697void winbind_msg_ip_dropped(struct messaging_context *msg_ctx,
     2698                            void *private_data,
     2699                            uint32_t msg_type,
     2700                            struct server_id server_id,
     2701                            DATA_BLOB *data)
     2702{
     2703        struct winbindd_domain *domain;
     2704        char *freeit = NULL;
     2705        char *addr;
     2706
     2707        if ((data == NULL)
     2708            || (data->data == NULL)
     2709            || (data->length == 0)
     2710            || (data->data[data->length-1] != '\0')) {
     2711                DEBUG(1, ("invalid msg_ip_dropped message: not a valid "
     2712                          "string\n"));
     2713                return;
     2714        }
     2715
     2716        addr = (char *)data->data;
     2717        DEBUG(10, ("IP %s dropped\n", addr));
     2718
     2719        if (!is_ipaddress(addr)) {
     2720                char *slash;
     2721                /*
     2722                 * Some code sends us ip addresses with the /netmask
     2723                 * suffix
     2724                 */
     2725                slash = strchr(addr, '/');
     2726                if (slash == NULL) {
     2727                        DEBUG(1, ("invalid msg_ip_dropped message: %s",
     2728                                  addr));
     2729                        return;
     2730                }
     2731                freeit = talloc_strndup(talloc_tos(), addr, slash-addr);
     2732                if (freeit == NULL) {
     2733                        DEBUG(1, ("talloc failed\n"));
     2734                        return;
     2735                }
     2736                addr = freeit;
     2737                DEBUG(10, ("Stripped /netmask to IP %s\n", addr));
     2738        }
     2739
     2740        for (domain = domain_list(); domain != NULL; domain = domain->next) {
     2741                char sockaddr[INET6_ADDRSTRLEN];
     2742                if (domain->conn.cli == NULL) {
     2743                        continue;
     2744                }
     2745                if (domain->conn.cli->fd == -1) {
     2746                        continue;
     2747                }
     2748                client_socket_addr(domain->conn.cli->fd, sockaddr,
     2749                                   sizeof(sockaddr));
     2750                if (strequal(sockaddr, addr)) {
     2751                        close(domain->conn.cli->fd);
     2752                        domain->conn.cli->fd = -1;
     2753                }
     2754        }
     2755        TALLOC_FREE(freeit);
     2756}
Note: See TracChangeset for help on using the changeset viewer.