~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/torture/drs/python/drs_base.py

  • 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:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# Unix SMB/CIFS implementation.
 
5
# Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2011
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
 
 
21
 
 
22
import sys
 
23
import time
 
24
import os
 
25
 
 
26
sys.path.insert(0, "bin/python")
 
27
import samba
 
28
samba.ensure_external_module("testtools", "testtools")
 
29
samba.ensure_external_module("subunit", "subunit/python")
 
30
 
 
31
from ldb import (
 
32
    SCOPE_BASE,
 
33
    Message,
 
34
    FLAG_MOD_REPLACE,
 
35
    )
 
36
 
 
37
import samba.tests
 
38
 
 
39
 
 
40
class DrsBaseTestCase(samba.tests.BlackboxTestCase):
 
41
    """Base class implementation for all DRS python tests.
 
42
       It is intended to provide common initialization and
 
43
       and functionality used by all DRS tests in drs/python
 
44
       test package. For instance, DC1 and DC2 are always used
 
45
       to pass URLs for DCs to test against"""
 
46
 
 
47
    def setUp(self):
 
48
        super(DrsBaseTestCase, self).setUp()
 
49
 
 
50
        # connect to DCs
 
51
        url_dc = samba.tests.env_get_var_value("DC1")
 
52
        (self.ldb_dc1, self.info_dc1) = samba.tests.connect_samdb_ex(url_dc,
 
53
                                                                     ldap_only=True)
 
54
        url_dc = samba.tests.env_get_var_value("DC2")
 
55
        (self.ldb_dc2, self.info_dc2) = samba.tests.connect_samdb_ex(url_dc,
 
56
                                                                     ldap_only=True)
 
57
 
 
58
        # cache some of RootDSE props
 
59
        self.schema_dn = self.info_dc1["schemaNamingContext"][0]
 
60
        self.domain_dn = self.info_dc1["defaultNamingContext"][0]
 
61
        self.config_dn = self.info_dc1["configurationNamingContext"][0]
 
62
        self.forest_level = int(self.info_dc1["forestFunctionality"][0])
 
63
 
 
64
        # we will need DCs DNS names for 'samba-tool drs' command
 
65
        self.dnsname_dc1 = self.info_dc1["dnsHostName"][0]
 
66
        self.dnsname_dc2 = self.info_dc2["dnsHostName"][0]
 
67
 
 
68
    def tearDown(self):
 
69
        super(DrsBaseTestCase, self).tearDown()
 
70
 
 
71
    def _GUID_string(self, guid):
 
72
        return self.ldb_dc1.schema_format_value("objectGUID", guid)
 
73
 
 
74
    def _ldap_schemaUpdateNow(self, sam_db):
 
75
        rec = {"dn": "",
 
76
               "schemaUpdateNow": "1"}
 
77
        m = Message.from_dict(sam_db, rec, FLAG_MOD_REPLACE)
 
78
        sam_db.modify(m)
 
79
 
 
80
    def _deleted_objects_dn(self, sam_ldb):
 
81
        wkdn = "<WKGUID=18E2EA80684F11D2B9AA00C04F79F805,%s>" % self.domain_dn
 
82
        res = sam_ldb.search(base=wkdn,
 
83
                             scope=SCOPE_BASE,
 
84
                             controls=["show_deleted:1"])
 
85
        self.assertEquals(len(res), 1)
 
86
        return str(res[0]["dn"])
 
87
 
 
88
    def _make_obj_name(self, prefix):
 
89
        return prefix + time.strftime("%s", time.gmtime())
 
90
 
 
91
    def _samba_tool_cmdline(self, drs_command):
 
92
        # find out where is net command
 
93
        samba_tool_cmd = os.path.abspath("./bin/samba-tool")
 
94
        # make command line credentials string
 
95
        creds = self.get_credentials()
 
96
        cmdline_auth = "-U%s/%s%%%s" % (creds.get_domain(),
 
97
                                        creds.get_username(), creds.get_password())
 
98
        # bin/samba-tool drs <drs_command> <cmdline_auth>
 
99
        return "%s drs %s %s" % (samba_tool_cmd, drs_command, cmdline_auth)
 
100
 
 
101
    def _net_drs_replicate(self, DC, fromDC, nc_dn=None, forced=True):
 
102
        if nc_dn is None:
 
103
            nc_dn = self.domain_dn
 
104
        # make base command line
 
105
        samba_tool_cmdline = self._samba_tool_cmdline("replicate")
 
106
        if forced:
 
107
            samba_tool_cmdline += " --sync-forced"
 
108
        # bin/samba-tool drs replicate <Dest_DC_NAME> <Src_DC_NAME> <Naming Context>
 
109
        cmd_line = "%s %s %s %s" % (samba_tool_cmdline, DC, fromDC, nc_dn)
 
110
        return self.check_output(cmd_line)
 
111
 
 
112
    def _enable_inbound_repl(self, DC):
 
113
        # make base command line
 
114
        samba_tool_cmd = self._samba_tool_cmdline("options")
 
115
        # disable replication
 
116
        self.check_run("%s %s --dsa-option=-DISABLE_INBOUND_REPL" %(samba_tool_cmd, DC))
 
117
 
 
118
    def _disable_inbound_repl(self, DC):
 
119
        # make base command line
 
120
        samba_tool_cmd = self._samba_tool_cmdline("options")
 
121
        # disable replication
 
122
        self.check_run("%s %s --dsa-option=+DISABLE_INBOUND_REPL" %(samba_tool_cmd, DC))