~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/utils/net_util.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "includes.h"
23
23
#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"
26
31
 
27
32
NTSTATUS net_rpc_lookup_name(struct net_context *c,
28
33
                             TALLOC_CTX *mem_ctx, struct cli_state *cli,
29
34
                             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,
31
36
                             enum lsa_SidType *ret_type)
32
37
{
33
38
        struct rpc_pipe_client *lsa_pipe = NULL;
34
39
        struct policy_handle pol;
35
 
        NTSTATUS result = NT_STATUS_OK;
 
40
        NTSTATUS status, result;
36
41
        const char **dom_names;
37
 
        DOM_SID *sids;
 
42
        struct dom_sid *sids;
38
43
        enum lsa_SidType *types;
 
44
        struct dcerpc_binding_handle *b;
39
45
 
40
46
        ZERO_STRUCT(pol);
41
47
 
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,
43
49
                                          &lsa_pipe);
44
 
        if (!NT_STATUS_IS_OK(result)) {
 
50
        if (!NT_STATUS_IS_OK(status)) {
45
51
                d_fprintf(stderr, _("Could not initialise lsa pipe\n"));
46
 
                return result;
 
52
                return status;
47
53
        }
48
54
 
49
 
        result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
 
55
        b = lsa_pipe->binding_handle;
 
56
 
 
57
        status = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
50
58
                                        SEC_FLAG_MAXIMUM_ALLOWED,
51
59
                                        &pol);
52
 
        if (!NT_STATUS_IS_OK(result)) {
 
60
        if (!NT_STATUS_IS_OK(status)) {
53
61
                d_fprintf(stderr, "open_policy %s: %s\n", _("failed"),
54
 
                          nt_errstr(result));
55
 
                return result;
 
62
                          nt_errstr(status));
 
63
                return status;
56
64
        }
57
65
 
58
 
        result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
 
66
        status = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
59
67
                                         &name, &dom_names, 1, &sids, &types);
60
68
 
61
 
        if (!NT_STATUS_IS_OK(result)) {
 
69
        if (!NT_STATUS_IS_OK(status)) {
62
70
                /* This can happen easily, don't log an error */
63
71
                goto done;
64
72
        }
78
86
 
79
87
 done:
80
88
        if (is_valid_policy_hnd(&pol)) {
81
 
                rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
 
89
                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
82
90
        }
83
91
        TALLOC_FREE(lsa_pipe);
84
92
 
85
 
        return result;
 
93
        return status;
86
94
}
87
95
 
88
96
/****************************************************************************
117
125
                                        server_ss, c->opt_port,
118
126
                                        service_name, service_type,
119
127
                                        c->opt_user_name, c->opt_workgroup,
120
 
                                        c->opt_password, flags, Undefined, NULL);
 
128
                                        c->opt_password, flags, Undefined);
121
129
        if (!NT_STATUS_IS_OK(nt_status)) {
122
130
                d_fprintf(stderr, _("Could not connect to server %s\n"),
123
131
                          server_name);
201
209
                                        server_name, server_ss, c->opt_port,
202
210
                                        "IPC$", "IPC",
203
211
                                        "", "",
204
 
                                        "", 0, Undefined, NULL);
 
212
                                        "", 0, Undefined);
205
213
 
206
214
        if (NT_STATUS_IS_OK(nt_status)) {
207
215
                return nt_status;
261
269
                                        user_and_realm, c->opt_workgroup,
262
270
                                        c->opt_password,
263
271
                                        CLI_FULL_CONNECTION_USE_KERBEROS,
264
 
                                        Undefined, NULL);
 
272
                                        Undefined);
265
273
 
266
274
        SAFE_FREE(user_and_realm);
267
275
 
415
423
                        return false;
416
424
                }
417
425
 
418
 
                if (is_zero_addr((struct sockaddr *)&pdc_ss)) {
 
426
                if (is_zero_addr(&pdc_ss)) {
419
427
                        return false;
420
428
                }
421
429
 
472
480
        if (!get_pdc_ip(domain_name, server_ss)) {
473
481
                return false;
474
482
        }
475
 
        if (is_zero_addr((struct sockaddr *)server_ss)) {
 
483
        if (is_zero_addr(server_ss)) {
476
484
                return false;
477
485
        }
478
486
 
618
626
        }
619
627
}
620
628
 
 
629
static NTSTATUS net_scan_dc_noad(struct net_context *c,
 
630
                                 struct cli_state *cli,
 
631
                                 struct net_dc_info *dc_info)
 
632
{
 
633
        TALLOC_CTX *mem_ctx = talloc_tos();
 
634
        struct rpc_pipe_client *pipe_hnd = NULL;
 
635
        struct dcerpc_binding_handle *b;
 
636
        NTSTATUS status, result;
 
637
        struct policy_handle pol;
 
638
        union lsa_PolicyInformation *info;
 
639
 
 
640
        ZERO_STRUCTP(dc_info);
 
641
        ZERO_STRUCT(pol);
 
642
 
 
643
        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
 
644
                                          &pipe_hnd);
 
645
        if (!NT_STATUS_IS_OK(status)) {
 
646
                return status;
 
647
        }
 
648
 
 
649
        b = pipe_hnd->binding_handle;
 
650
 
 
651
        status = dcerpc_lsa_open_policy(b, mem_ctx,
 
652
                                        false,
 
653
                                        SEC_FLAG_MAXIMUM_ALLOWED,
 
654
                                        &pol,
 
655
                                        &result);
 
656
        if (!NT_STATUS_IS_OK(status)) {
 
657
                goto done;
 
658
        }
 
659
        if (!NT_STATUS_IS_OK(result)) {
 
660
                status = result;
 
661
                goto done;
 
662
        }
 
663
 
 
664
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
 
665
                                            &pol,
 
666
                                            LSA_POLICY_INFO_ACCOUNT_DOMAIN,
 
667
                                            &info,
 
668
                                            &result);
 
669
        if (!NT_STATUS_IS_OK(status)) {
 
670
                goto done;
 
671
        }
 
672
        if (!NT_STATUS_IS_OK(result)) {
 
673
                status = result;
 
674
                goto done;
 
675
        }
 
676
 
 
677
        dc_info->netbios_domain_name = talloc_strdup(mem_ctx, info->account_domain.name.string);
 
678
        if (dc_info->netbios_domain_name == NULL) {
 
679
                status = NT_STATUS_NO_MEMORY;
 
680
                goto done;
 
681
        }
 
682
 
 
683
 done:
 
684
        if (is_valid_policy_hnd(&pol)) {
 
685
                dcerpc_lsa_Close(b, mem_ctx, &pol, &result);
 
686
        }
 
687
 
 
688
        TALLOC_FREE(pipe_hnd);
 
689
 
 
690
        return status;
 
691
}
 
692
 
621
693
NTSTATUS net_scan_dc(struct net_context *c,
622
694
                     struct cli_state *cli,
623
695
                     struct net_dc_info *dc_info)
624
696
{
625
697
        TALLOC_CTX *mem_ctx = talloc_tos();
626
698
        struct rpc_pipe_client *dssetup_pipe = NULL;
 
699
        struct dcerpc_binding_handle *dssetup_handle = NULL;
627
700
        union dssetup_DsRoleInfo info;
628
701
        NTSTATUS status;
 
702
        WERROR werr;
629
703
 
630
704
        ZERO_STRUCTP(dc_info);
631
705
 
632
706
        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_dssetup.syntax_id,
633
707
                                          &dssetup_pipe);
634
708
        if (!NT_STATUS_IS_OK(status)) {
635
 
                return status;
 
709
                DEBUG(10,("net_scan_dc: failed to open dssetup pipe with %s, "
 
710
                        "retrying with lsa pipe\n", nt_errstr(status)));
 
711
                return net_scan_dc_noad(c, cli, dc_info);
636
712
        }
 
713
        dssetup_handle = dssetup_pipe->binding_handle;
637
714
 
638
 
        status = rpccli_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_pipe, mem_ctx,
 
715
        status = dcerpc_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_handle, mem_ctx,
639
716
                                                                  DS_ROLE_BASIC_INFORMATION,
640
717
                                                                  &info,
641
 
                                                                  NULL);
 
718
                                                                  &werr);
642
719
        TALLOC_FREE(dssetup_pipe);
643
720
 
 
721
        if (NT_STATUS_IS_OK(status)) {
 
722
                status = werror_to_ntstatus(werr);
 
723
        }
644
724
        if (!NT_STATUS_IS_OK(status)) {
645
725
                return status;
646
726
        }