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/utils/net_util.c

    r454 r745  
    2222#include "includes.h"
    2323#include "utils/net.h"
    24 #include "../librpc/gen_ndr/cli_lsa.h"
    25 #include "../librpc/gen_ndr/cli_dssetup.h"
     24#include "rpc_client/cli_pipe.h"
     25#include "../librpc/gen_ndr/ndr_lsa_c.h"
     26#include "rpc_client/cli_lsarpc.h"
     27#include "../librpc/gen_ndr/ndr_dssetup_c.h"
     28#include "secrets.h"
     29#include "../libcli/security/security.h"
     30#include "libsmb/libsmb.h"
    2631
    2732NTSTATUS net_rpc_lookup_name(struct net_context *c,
    2833                             TALLOC_CTX *mem_ctx, struct cli_state *cli,
    2934                             const char *name, const char **ret_domain,
    30                              const char **ret_name, DOM_SID *ret_sid,
     35                             const char **ret_name, struct dom_sid *ret_sid,
    3136                             enum lsa_SidType *ret_type)
    3237{
    3338        struct rpc_pipe_client *lsa_pipe = NULL;
    3439        struct policy_handle pol;
    35         NTSTATUS result = NT_STATUS_OK;
     40        NTSTATUS status, result;
    3641        const char **dom_names;
    37         DOM_SID *sids;
     42        struct dom_sid *sids;
    3843        enum lsa_SidType *types;
     44        struct dcerpc_binding_handle *b;
    3945
    4046        ZERO_STRUCT(pol);
    4147
    42         result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     48        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
    4349                                          &lsa_pipe);
    44         if (!NT_STATUS_IS_OK(result)) {
     50        if (!NT_STATUS_IS_OK(status)) {
    4551                d_fprintf(stderr, _("Could not initialise lsa pipe\n"));
    46                 return result;
    47         }
    48 
    49         result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
     52                return status;
     53        }
     54
     55        b = lsa_pipe->binding_handle;
     56
     57        status = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
    5058                                        SEC_FLAG_MAXIMUM_ALLOWED,
    5159                                        &pol);
    52         if (!NT_STATUS_IS_OK(result)) {
     60        if (!NT_STATUS_IS_OK(status)) {
    5361                d_fprintf(stderr, "open_policy %s: %s\n", _("failed"),
    54                           nt_errstr(result));
    55                 return result;
    56         }
    57 
    58         result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
     62                          nt_errstr(status));
     63                return status;
     64        }
     65
     66        status = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
    5967                                         &name, &dom_names, 1, &sids, &types);
    6068
    61         if (!NT_STATUS_IS_OK(result)) {
     69        if (!NT_STATUS_IS_OK(status)) {
    6270                /* This can happen easily, don't log an error */
    6371                goto done;
     
    7987 done:
    8088        if (is_valid_policy_hnd(&pol)) {
    81                 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
     89                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
    8290        }
    8391        TALLOC_FREE(lsa_pipe);
    8492
    85         return result;
     93        return status;
    8694}
    8795
     
    106114        }
    107115#endif
    108 
    109116        c->opt_password = net_prompt_pass(c, c->opt_user_name);
    110117
     
    125132                                        service_name, service_type,
    126133                                        c->opt_user_name, c->opt_workgroup,
    127                                         c->opt_password, flags, Undefined, NULL);
     134                                        c->opt_password, flags, Undefined);
    128135        if (!NT_STATUS_IS_OK(nt_status)) {
    129136                d_fprintf(stderr, _("Could not connect to server %s\n"),
     
    209216                                        "IPC$", "IPC",
    210217                                        "", "",
    211                                         "", 0, Undefined, NULL);
     218                                        "", 0, Undefined);
    212219
    213220        if (NT_STATUS_IS_OK(nt_status)) {
     
    269276                                        c->opt_password,
    270277                                        CLI_FULL_CONNECTION_USE_KERBEROS,
    271                                         Undefined, NULL);
     278                                        Undefined);
    272279
    273280        SAFE_FREE(user_and_realm);
     
    423430                }
    424431
    425                 if (is_zero_addr((struct sockaddr *)&pdc_ss)) {
     432                if (is_zero_addr(&pdc_ss)) {
    426433                        return false;
    427434                }
     
    480487                return false;
    481488        }
    482         if (is_zero_addr((struct sockaddr *)server_ss)) {
     489        if (is_zero_addr(server_ss)) {
    483490                return false;
    484491        }
     
    626633}
    627634
     635static NTSTATUS net_scan_dc_noad(struct net_context *c,
     636                                 struct cli_state *cli,
     637                                 struct net_dc_info *dc_info)
     638{
     639        TALLOC_CTX *mem_ctx = talloc_tos();
     640        struct rpc_pipe_client *pipe_hnd = NULL;
     641        struct dcerpc_binding_handle *b;
     642        NTSTATUS status, result;
     643        struct policy_handle pol;
     644        union lsa_PolicyInformation *info;
     645
     646        ZERO_STRUCTP(dc_info);
     647        ZERO_STRUCT(pol);
     648
     649        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
     650                                          &pipe_hnd);
     651        if (!NT_STATUS_IS_OK(status)) {
     652                return status;
     653        }
     654
     655        b = pipe_hnd->binding_handle;
     656
     657        status = dcerpc_lsa_open_policy(b, mem_ctx,
     658                                        false,
     659                                        SEC_FLAG_MAXIMUM_ALLOWED,
     660                                        &pol,
     661                                        &result);
     662        if (!NT_STATUS_IS_OK(status)) {
     663                goto done;
     664        }
     665        if (!NT_STATUS_IS_OK(result)) {
     666                status = result;
     667                goto done;
     668        }
     669
     670        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
     671                                            &pol,
     672                                            LSA_POLICY_INFO_ACCOUNT_DOMAIN,
     673                                            &info,
     674                                            &result);
     675        if (!NT_STATUS_IS_OK(status)) {
     676                goto done;
     677        }
     678        if (!NT_STATUS_IS_OK(result)) {
     679                status = result;
     680                goto done;
     681        }
     682
     683        dc_info->netbios_domain_name = talloc_strdup(mem_ctx, info->account_domain.name.string);
     684        if (dc_info->netbios_domain_name == NULL) {
     685                status = NT_STATUS_NO_MEMORY;
     686                goto done;
     687        }
     688
     689 done:
     690        if (is_valid_policy_hnd(&pol)) {
     691                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
     692        }
     693
     694        TALLOC_FREE(pipe_hnd);
     695
     696        return status;
     697}
     698
    628699NTSTATUS net_scan_dc(struct net_context *c,
    629700                     struct cli_state *cli,
     
    632703        TALLOC_CTX *mem_ctx = talloc_tos();
    633704        struct rpc_pipe_client *dssetup_pipe = NULL;
     705        struct dcerpc_binding_handle *dssetup_handle = NULL;
    634706        union dssetup_DsRoleInfo info;
    635707        NTSTATUS status;
     708        WERROR werr;
    636709
    637710        ZERO_STRUCTP(dc_info);
     
    640713                                          &dssetup_pipe);
    641714        if (!NT_STATUS_IS_OK(status)) {
    642                 return status;
    643         }
    644 
    645         status = rpccli_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_pipe, mem_ctx,
     715                DEBUG(10,("net_scan_dc: failed to open dssetup pipe with %s, "
     716                        "retrying with lsa pipe\n", nt_errstr(status)));
     717                return net_scan_dc_noad(c, cli, dc_info);
     718        }
     719        dssetup_handle = dssetup_pipe->binding_handle;
     720
     721        status = dcerpc_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_handle, mem_ctx,
    646722                                                                  DS_ROLE_BASIC_INFORMATION,
    647723                                                                  &info,
    648                                                                   NULL);
     724                                                                  &werr);
    649725        TALLOC_FREE(dssetup_pipe);
    650726
     727        if (NT_STATUS_IS_OK(status)) {
     728                status = werror_to_ntstatus(werr);
     729        }
    651730        if (!NT_STATUS_IS_OK(status)) {
    652731                return status;
Note: See TracChangeset for help on using the changeset viewer.