~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/libcli/security/tests/bindings.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/python
2
 
 
3
 
# Unix SMB/CIFS implementation.
4
 
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5
 
#   
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 3 of the License, or
9
 
# (at your option) any later version.
10
 
#   
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#   
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
#
19
 
 
20
 
import unittest
21
 
from samba.dcerpc import security
22
 
 
23
 
class SecurityTokenTests(unittest.TestCase):
24
 
    def setUp(self):
25
 
        self.token = security.token()
26
 
 
27
 
    def test_is_system(self):
28
 
        self.assertFalse(self.token.is_system())
29
 
 
30
 
    def test_is_anonymous(self):
31
 
        self.assertFalse(self.token.is_anonymous())
32
 
 
33
 
    def test_has_builtin_administrators(self):
34
 
        self.assertFalse(self.token.has_builtin_administrators())
35
 
 
36
 
    def test_has_nt_authenticated_users(self):
37
 
        self.assertFalse(self.token.has_nt_authenticated_users())
38
 
 
39
 
    def test_has_priv(self):
40
 
        self.assertFalse(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
41
 
 
42
 
    def test_set_priv(self):
43
 
        self.assertFalse(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
44
 
        self.assertFalse(self.token.set_privilege(security.SEC_PRIV_SHUTDOWN))
45
 
        self.assertTrue(self.token.has_privilege(security.SEC_PRIV_SHUTDOWN))
46
 
 
47
 
 
48
 
class SecurityDescriptorTests(unittest.TestCase):
49
 
    def setUp(self):
50
 
        self.descriptor = security.descriptor()
51
 
 
52
 
    def test_from_sddl(self):
53
 
        desc = security.descriptor.from_sddl("O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)", security.dom_sid("S-2-0-0"))
54
 
        self.assertEquals(desc.group_sid, security.dom_sid('S-2-0-0-512'))
55
 
        self.assertEquals(desc.owner_sid, security.dom_sid('S-1-5-32-548'))
56
 
        self.assertEquals(desc.revision, 1)
57
 
        self.assertEquals(desc.sacl, None)
58
 
        self.assertEquals(desc.type, 0x8004)
59
 
 
60
 
    def test_from_sddl_invalidsddl(self):
61
 
        self.assertRaises(TypeError,security.descriptor.from_sddl, "foo",security.dom_sid("S-2-0-0"))
62
 
 
63
 
    def test_from_sddl_invalidtype1(self):
64
 
        self.assertRaises(TypeError,security.descriptor.from_sddl, security.dom_sid('S-2-0-0-512'),security.dom_sid("S-2-0-0"))
65
 
 
66
 
    def test_from_sddl_invalidtype1(self):
67
 
        sddl = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
68
 
        self.assertRaises(TypeError,security.descriptor.from_sddl, sddl,"S-2-0-0")
69
 
 
70
 
    def test_as_sddl(self):
71
 
        text = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
72
 
        dom = security.dom_sid("S-2-0-0")
73
 
        desc1 = security.descriptor.from_sddl(text, dom)
74
 
        desc2 = security.descriptor.from_sddl(desc1.as_sddl(dom), dom)
75
 
        self.assertEquals(desc1.group_sid, desc2.group_sid)
76
 
        self.assertEquals(desc1.owner_sid, desc2.owner_sid)
77
 
        self.assertEquals(desc1.sacl, desc2.sacl)
78
 
        self.assertEquals(desc1.type, desc2.type)
79
 
 
80
 
    def test_as_sddl_invalid(self):
81
 
        text = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
82
 
        dom = security.dom_sid("S-2-0-0")
83
 
        desc1 = security.descriptor.from_sddl(text, dom)
84
 
        self.assertRaises(TypeError, desc1.as_sddl,text)
85
 
 
86
 
 
87
 
    def test_as_sddl_no_domainsid(self):
88
 
        dom = security.dom_sid("S-2-0-0")
89
 
        text = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
90
 
        desc1 = security.descriptor.from_sddl(text, dom)
91
 
        desc2 = security.descriptor.from_sddl(desc1.as_sddl(), dom)
92
 
        self.assertEquals(desc1.group_sid, desc2.group_sid)
93
 
        self.assertEquals(desc1.owner_sid, desc2.owner_sid)
94
 
        self.assertEquals(desc1.sacl, desc2.sacl)
95
 
        self.assertEquals(desc1.type, desc2.type)
96
 
 
97
 
    def test_domsid_nodomsid_as_sddl(self):
98
 
        dom = security.dom_sid("S-2-0-0")
99
 
        text = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
100
 
        desc1 = security.descriptor.from_sddl(text, dom)
101
 
        self.assertNotEqual(desc1.as_sddl(), desc1.as_sddl(dom))
102
 
 
103
 
 
104
 
class DomSidTests(unittest.TestCase):
105
 
    def test_parse_sid(self):
106
 
        sid = security.dom_sid("S-1-5-21")
107
 
        self.assertEquals("S-1-5-21", str(sid))
108
 
 
109
 
    def test_sid_equal(self):
110
 
        sid1 = security.dom_sid("S-1-5-21")
111
 
        sid2 = security.dom_sid("S-1-5-21")
112
 
        self.assertEquals(sid1, sid1)
113
 
        self.assertEquals(sid1, sid2)
114
 
 
115
 
    def test_random(self):
116
 
        sid = security.random_sid()
117
 
        self.assertTrue(str(sid).startswith("S-1-5-21-"))
118
 
 
119
 
    def test_repr(self):
120
 
        sid = security.random_sid()
121
 
        self.assertTrue(repr(sid).startswith("dom_sid('S-1-5-21-"))
122
 
 
123
 
 
124
 
class PrivilegeTests(unittest.TestCase):
125
 
    def test_privilege_name(self):
126
 
        self.assertEquals("SeShutdownPrivilege", security.privilege_name(security.SEC_PRIV_SHUTDOWN))
127
 
 
128
 
    def test_privilege_id(self):
129
 
        self.assertEquals(security.SEC_PRIV_SHUTDOWN, security.privilege_id("SeShutdownPrivilege"))
130