# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
# Copyright (C) Matthias Dieter Wallnoefer 2009
#
# Based on the original in EJS:
# Copyright (C) Andrew Tridgell <tridge@samba.org> 2005
# Copyright (C) Giampaolo Lauria <lauria2@yahoo.com> 2011
#
# 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/>.
#
"""Convenience functions for using the SAM."""
import samba
import ldb
import time
import base64
import os
import re
from samba import dsdb, dsdb_dns
from samba.ndr import ndr_unpack, ndr_pack
from samba.dcerpc import drsblobs, misc
from samba.common import normalise_int32
from samba.common import get_bytes, cmp
from samba.dcerpc import security
from samba import is_ad_dc_built
import binascii
__docformat__ = "restructuredText"
def get_default_backend_store():
return "tdb"
class SamDBError(Exception):
pass
class SamDBNotFoundError(SamDBError):
pass
class SamDB(samba.Ldb):
"""The SAM database."""
hash_oid_name = {}
hash_well_known = {}
class _CleanUpOnError:
def __init__(self, samdb, dn):
self.samdb = samdb
self.dn = dn
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
# We failed to modify the account. If we connected to the
# database over LDAP, we don't have transactions, and so when
# we call transaction_cancel(), the account will still exist in
# a half-created state. We'll delete the account to ensure that
# doesn't happen.
self.samdb.delete(self.dn)
# Don't suppress any exceptions
return False
def __init__(self, url=None, lp=None, modules_dir=None, session_info=None,
credentials=None, flags=ldb.FLG_DONT_CREATE_DB,
options=None, global_schema=True,
auto_connect=True, am_rodc=None):
self.lp = lp
if not auto_connect:
url = None
elif url is None and lp is not None:
url = lp.samdb_url()
self.url = url
super().__init__(url=url, lp=lp, modules_dir=modules_dir,
session_info=se
|