diff options
Diffstat (limited to 'source4/scripting/python/samba')
103 files changed, 0 insertions, 30623 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py deleted file mode 100644 index cd2a309fc0a..00000000000 --- a/source4/scripting/python/samba/__init__.py +++ /dev/null @@ -1,363 +0,0 @@ -# Unix SMB/CIFS implementation. -# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008 -# -# Based on the original in EJS: -# Copyright (C) Andrew Tridgell <tridge@samba.org> 2005 -# -# 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/>. -# - -"""Samba 4.""" - -__docformat__ = "restructuredText" - -import os -import sys -import samba.param - - -def source_tree_topdir(): - """Return the top level source directory.""" - paths = ["../../..", "../../../.."] - for p in paths: - topdir = os.path.normpath(os.path.join(os.path.dirname(__file__), p)) - if os.path.exists(os.path.join(topdir, 'source4')): - return topdir - raise RuntimeError("unable to find top level source directory") - - -def in_source_tree(): - """Return True if we are running from within the samba source tree""" - try: - topdir = source_tree_topdir() - except RuntimeError: - return False - return True - - -import ldb -from samba._ldb import Ldb as _Ldb - - -class Ldb(_Ldb): - """Simple Samba-specific LDB subclass that takes care - of setting up the modules dir, credentials pointers, etc. - - Please note that this is intended to be for all Samba LDB files, - not necessarily the Sam database. For Sam-specific helper - functions see samdb.py. - """ - - def __init__(self, url=None, lp=None, modules_dir=None, session_info=None, - credentials=None, flags=0, options=None): - """Opens a Samba Ldb file. - - :param url: Optional LDB URL to open - :param lp: Optional loadparm object - :param modules_dir: Optional modules directory - :param session_info: Optional session information - :param credentials: Optional credentials, defaults to anonymous. - :param flags: Optional LDB flags - :param options: Additional options (optional) - - This is different from a regular Ldb file in that the Samba-specific - modules-dir is used by default and that credentials and session_info - can be passed through (required by some modules). - """ - - if modules_dir is not None: - self.set_modules_dir(modules_dir) - else: - self.set_modules_dir(os.path.join(samba.param.modules_dir(), "ldb")) - - if session_info is not None: - self.set_session_info(session_info) - - if credentials is not None: - self.set_credentials(credentials) - - if lp is not None: - self.set_loadparm(lp) - - # This must be done before we load the schema, as these handlers for - # objectSid and objectGUID etc must take precedence over the 'binary - # attribute' declaration in the schema - self.register_samba_handlers() - - # TODO set debug - def msg(l, text): - print text - #self.set_debug(msg) - - self.set_utf8_casefold() - - # Allow admins to force non-sync ldb for all databases - if lp is not None: - nosync_p = lp.get("nosync", "ldb") - if nosync_p is not None and nosync_p: - flags |= ldb.FLG_NOSYNC - - self.set_create_perms(0600) - - if url is not None: - self.connect(url, flags, options) - - def searchone(self, attribute, basedn=None, expression=None, - scope=ldb.SCOPE_BASE): - """Search for one attribute as a string. - - :param basedn: BaseDN for the search. - :param attribute: Name of the attribute - :param expression: Optional search expression. - :param scope: Search scope (defaults to base). - :return: Value of attribute as a string or None if it wasn't found. - """ - res = self.search(basedn, scope, expression, [attribute]) - if len(res) != 1 or res[0][attribute] is None: - return None - values = set(res[0][attribute]) - assert len(values) == 1 - return self.schema_format_value(attribute, values.pop()) - - def erase_users_computers(self, dn): - """Erases user and computer objects from our AD. - - This is needed since the 'samldb' module denies the deletion of primary - groups. Therefore all groups shouldn't be primary somewhere anymore. - """ - - try: - res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[], - expression="(|(objectclass=user)(objectclass=computer))") - except ldb.LdbError, (errno, _): - if errno == ldb.ERR_NO_SUCH_OBJECT: - # Ignore no such object errors - return - else: - raise - - try: - for msg in res: - self.delete(msg.dn, ["relax:0"]) - except ldb.LdbError, (errno, _): - if errno != ldb.ERR_NO_SUCH_OBJECT: - # Ignore no such object errors - raise - - def erase_except_schema_controlled(self): - """Erase this ldb. - - :note: Removes all records, except those that are controlled by - Samba4's schema. - """ - - basedn = "" - - # Try to delete user/computer accounts to allow deletion of groups - self.erase_users_computers(basedn) - - # Delete the 'visible' records, and the invisble 'deleted' records (if - # this DB supports it) - for msg in self.search(basedn, ldb.SCOPE_S |
