1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
#!/usr/bin/python
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""Support for reading Samba 3 data files."""
REGISTRY_VALUE_PREFIX = "SAMBA_REGVAL"
REGISTRY_DB_VERSION = 1
import os
import tdb
class Registry:
"""Simple read-only support for reading the Samba3 registry."""
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
def close(self):
self.tdb.close()
def __len__(self):
"""Return the number of keys."""
return len(self.keys())
def keys(self):
"""Return list with all the keys."""
return [k.rstrip("\x00") for k in self.tdb.keys() if not k.startswith(REGISTRY_VALUE_PREFIX)]
def subkeys(self, key):
data = self.tdb.get("%s\x00" % key)
if data is None:
return []
# FIXME: Parse data
return []
def values(self, key):
"""Return a dictionary with the values set for a specific key."""
data = self.tdb.get("%s/%s\x00" % (REGISTRY_VALUE_PREFIX, key))
if data is None:
return {}
# FIXME: Parse data
return {}
class PolicyDatabase:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
self.min_password_length = self.tdb.fetch_uint32("min password length\x00")
self.password_history = self.tdb.fetch_uint32("password history\x00")
self.user_must_logon_to_change_password = self.tdb.fetch_uint32("user must logon to change pasword\x00")
self.maximum_password_age = self.tdb.fetch_uint32("maximum password age\x00")
self.minimum_password_age = self.tdb.fetch_uint32("minimum password age\x00")
self.lockout_duration = self.tdb.fetch_uint32("lockout duration\x00")
self.reset_count_minutes = self.tdb.fetch_uint32("reset count minutes\x00")
self.bad_lockout_minutes = self.tdb.fetch_uint32("bad lockout minutes\x00")
self.disconnect_time = self.tdb.fetch_int32("disconnect time\x00")
self.refuse_machine_password_change = self.tdb.fetch_uint32("refuse machine password change\x00")
# FIXME: Read privileges as well
GROUPDB_DATABASE_VERSION_V1 = 1 # native byte format.
GROUPDB_DATABASE_VERSION_V2 = 2 # le format.
GROUP_PREFIX = "UNIXGROUP/"
# Alias memberships are stored reverse, as memberships. The performance
# critical operation is to determine the aliases a SID is member of, not
# listing alias members. So we store a list of alias SIDs a SID is member of
# hanging of the member as key.
MEMBEROF_PREFIX = "MEMBEROF/"
class GroupMappingDatabase:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
# High water mark keys
HWM_GROUP = "GROUP HWM"
HWM_USER = "USER HWM"
# idmap version determines auto-conversion
IDMAP_VERSION = 2
class IdmapDatabase:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
assert self.tdb.fetch_int32("IDMAP_VERSION") == IDMAP_VERSION
class SecretsDatabase:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
self.domains = {}
for k, v in self.tdb.items():
if k == "SECRETS/AUTH_PASSWORD":
self.auth_password = v
elif k == "SECRETS/AUTH_DOMAIN":
self.auth_domain = v
elif k == "SECRETS/AUTH_USER":
self.auth_user = v
elif k.startswith("SECRETS/SID/"):
pass # FIXME
elif k.startswith("SECRETS/DOMGUID/"):
pass # FIXME
elif k.startswith("SECRETS/LDAP_BIND_PW/"):
pass # FIXME
elif k.startswith("SECRETS/AFS_KEYFILE/"):
pass # FIXME
elif k.startswith("SECRETS/MACHINE_SEC_CHANNEL_TYPE/"):
pass # FIXME
elif k.startswith("SECRETS/MACHINE_LAST_CHANGE_TIME/"):
pass # FIXME
elif k.startswith("SECRETS/MACHINE_PASSWORD/"):
pass # FIXME
elif k.startswith("SECRETS/$MACHINE.ACC/"):
pass # FIXME
elif k.startswith("SECRETS/$DOMTRUST.ACC/"):
pass # FIXME
elif k == "INFO/random_seed":
self.random_seed = v
else:
raise "Unknown key %s in secrets database" % k
SHARE_DATABASE_VERSION_V1 = 1
SHARE_DATABASE_VERSION_V2 = 2
class ShareInfoDatabase:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
assert self.tdb.fetch_int32("INFO/version") in (SHARE_DATABASE_VERSION_V1, SHARE_DATABASE_VERSION_V2)
def get_secdesc(self, name):
secdesc = self.tdb.get("SECDESC/%s" % name)
# FIXME: Run ndr_pull_security_descriptor
ACB_DISABLED = 0x00000001
ACB_HOMDIRREQ = 0x00000002
ACB_PWNOTREQ = 0x00000004
ACB_TEMPDUP = 0x00000008
ACB_NORMAL = 0x00000010
ACB_MNS = 0x00000020
ACB_DOMTRUST = 0x00000040
ACB_WSTRUST = 0x00000080
ACB_SVRTRUST = 0x00000100
ACB_PWNOEXP = 0x00000200
ACB_AUTOLOCK = 0x00000400
ACB_ENC_TXT_PWD_ALLOWED = 0x00000800
ACB_SMARTCARD_REQUIRED = 0x00001000
ACB_TRUSTED_FOR_DELEGATION = 0x00002000
ACB_NOT_DELEGATED = 0x00004000
ACB_USE_DES_KEY_ONLY = 0x00008000
ACB_DONT_REQUIRE_PREAUTH = 0x00010000
ACB_PW_EXPIRED = 0x00020000
ACB_NO_AUTH_DATA_REQD = 0x00080000
acb_info_mapping = {
'N': ACB_PWNOTREQ, # 'N'o password.
'D': ACB_DISABLED, # 'D'isabled.
'H': ACB_HOMDIRREQ, # 'H'omedir required.
'T': ACB_TEMPDUP, # 'T'emp account.
'U': ACB_NORMAL, # 'U'ser account (normal).
'M': ACB_MNS, # 'M'NS logon user account. What is this ?
'W': ACB_WSTRUST, # 'W'orkstation account.
'S': ACB_SVRTRUST, # 'S'erver account.
'L': ACB_AUTOLOCK, # 'L'ocked account.
'X': ACB_PWNOEXP, # No 'X'piry on password
'I': ACB_DOMTRUST, # 'I'nterdomain trust account.
' ': 0
}
class Smbpasswd:
def __init__(self, file):
pass
class TdbSam:
def __init__(self, file):
self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
class WinsDatabase:
def __init__(self, file):
pass
class Samba3:
def __init__(self, smbconfpath, libdir):
self.smbconfpath = smbconfpath
self.libdir = libdir
def get_policy_db(self):
return PolicyDatabase(os.path.join(libdir, "account_policy.tdb"))
def get_registry(self):
return Registry(os.path.join(libdir, "registry.tdb"))
def get_secrets_db(self):
return SecretsDatabase(os.path.join(libdir, "secrets.tdb"))
def get_shares_db(self):
return ShareInfoDatabase(os.path.join(libdir, "share_info.tdb"))
def get_idmap_db(self):
return IdmapDatabase(os.path.join(libdir, "winbindd_idmap.tdb"))
def get_wins_db(self):
return WinsDatabase(os.path.join(libdir, "wins.dat"))
def get_groupmapping_db(self):
return GroupMappingDatabase(os.path.join(libdir, "group_mapping.tdb"))
|