[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Sun Nov 28 10:09:01 MST 2010


The branch, master has been updated
       via  97f0d6c samba.tests.hostconfig: Fix import.
       via  eb5a8e2 s4-python: Some reformatting for the purpose of pydoctor.
       via  20516df samba.upgradehelpers: Simplify code a bit.
       via  ca495e6 samba.hostconfig: Move samba.shares into samba.hostconfig.
       via  979d298 samba.getopt: Fix missing import of sys.
       via  28b5095 chgtdcpass: Fix program name in usage message.
      from  56969ad s4:torture/smb2/acls.c - remove two unused variables

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 97f0d6c27834975256fe21518007807400e61f4b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 16:38:27 2010 +0100

    samba.tests.hostconfig: Fix import.
    
    Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
    Autobuild-Date: Sun Nov 28 18:08:33 CET 2010 on sn-devel-104

commit eb5a8e29cf362ea382da7bb9dd8c9eb175b9ebe3
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 14:09:30 2010 +0100

    s4-python: Some reformatting for the purpose of pydoctor.

commit 20516df27574ad999073b7eb9620e70833e3170d
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 13:45:56 2010 +0100

    samba.upgradehelpers: Simplify code a bit.

commit ca495e67b2c2c8b50e16c5bcfcafdc5c2ae5bc72
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 13:39:12 2010 +0100

    samba.hostconfig: Move samba.shares into samba.hostconfig.

commit 979d298b0d6e5692f606a5bfe21a64d1ecce5613
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 13:37:31 2010 +0100

    samba.getopt: Fix missing import of sys.

commit 28b509579df99ee576d5353eada31cd58aaa2508
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Nov 28 13:34:19 2010 +0100

    chgtdcpass: Fix program name in usage message.

-----------------------------------------------------------------------

Summary of changes:
 source4/scripting/devel/chgtdcpass                 |    9 +--
 source4/scripting/python/samba/__init__.py         |   16 +++--
 source4/scripting/python/samba/getopt.py           |   22 ++++---
 source4/scripting/python/samba/hostconfig.py       |   64 +++++++++++++++++--
 source4/scripting/python/samba/join.py             |    9 ++-
 source4/scripting/python/samba/ms_schema.py        |    5 +-
 source4/scripting/python/samba/ndr.py              |   28 +++++++--
 source4/scripting/python/samba/ntacls.py           |    3 +
 .../scripting/python/samba/provision/__init__.py   |    9 ++-
 .../scripting/python/samba/provision/backend.py    |    3 +-
 source4/scripting/python/samba/samba3.py           |   12 ++--
 source4/scripting/python/samba/samdb.py            |   31 ++++++----
 source4/scripting/python/samba/schema.py           |    3 +-
 source4/scripting/python/samba/shares.py           |   61 -------------------
 .../samba/tests/{shares.py => hostconfig.py}       |    2 +-
 source4/scripting/python/samba/upgrade.py          |   50 +++++++++------
 source4/scripting/python/samba/upgradehelpers.py   |   38 +++++-------
 source4/selftest/tests.py                          |    2 +-
 18 files changed, 199 insertions(+), 168 deletions(-)
 delete mode 100644 source4/scripting/python/samba/shares.py
 rename source4/scripting/python/samba/tests/{shares.py => hostconfig.py} (97%)


Changeset truncated at 500 lines:

diff --git a/source4/scripting/devel/chgtdcpass b/source4/scripting/devel/chgtdcpass
index 1030531..dc24983 100755
--- a/source4/scripting/devel/chgtdcpass
+++ b/source4/scripting/devel/chgtdcpass
@@ -17,6 +17,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+__docformat__ = "restructuredText"
+
+
 import optparse
 import sys
 # Allow to run from s4 source directory (without installing samba)
@@ -30,10 +33,7 @@ from samba.upgradehelpers import (get_paths,
                                  find_provision_key_parameters, get_ldbs,
                                  update_machine_account_password)
 
-__docformat__ = "restructuredText"
-
-
-parser = optparse.OptionParser("provision [options]")
+parser = optparse.OptionParser("chgtdcpass [options]")
 sambaopts = options.SambaOptions(parser)
 parser.add_option_group(sambaopts)
 parser.add_option_group(options.VersionOptions(parser))
@@ -42,7 +42,6 @@ parser.add_option_group(credopts)
 
 opts = parser.parse_args()[0]
 
-
 lp = sambaopts.get_loadparm()
 smbconf = lp.configfile
 creds = credopts.get_credentials(lp)
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index a9b4349..ee45d93 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -128,7 +128,7 @@ class Ldb(_Ldb):
 
     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.
         """
@@ -153,7 +153,7 @@ class Ldb(_Ldb):
 
     def erase_except_schema_controlled(self):
         """Erase this ldb.
-        
+
         :note: Removes all records, except those that are controlled by
             Samba4's schema.
         """
@@ -246,7 +246,8 @@ def substitute_var(text, values):
 
 
 def check_all_substituted(text):
-    """Make sure that all substitution variables in a string have been replaced.
+    """Check that all substitution variables in a string have been replaced.
+
     If not, raise an exception.
 
     :param text: The text to search for substitution variables
@@ -257,7 +258,8 @@ def check_all_substituted(text):
     var_start = text.find("${")
     var_end = text.find("}", var_start)
 
-    raise Exception("Not all variables substituted: %s" % text[var_start:var_end+1])
+    raise Exception("Not all variables substituted: %s" %
+        text[var_start:var_end+1])
 
 
 def read_and_sub_file(file_name, subst_vars):
@@ -306,14 +308,14 @@ def ensure_external_module(modulename, location):
     """Add a location to sys.path if an external dependency can't be found.
 
     :param modulename: Module name to import
-    :param location: Location to add to sys.path (can be relative to 
-        ${srcdir}/lib
+    :param location: Location to add to sys.path (can be relative to
+        ${srcdir}/lib)
     """
     try:
         __import__(modulename)
     except ImportError:
         if in_source_tree():
-            sys.path.insert(0, 
+            sys.path.insert(0,
                 os.path.join(os.path.dirname(__file__),
                              "../../../../lib", location))
             __import__(modulename)
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 8104faf..a5a3392 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -19,17 +19,23 @@
 
 """Support for parsing Samba-related command-line options."""
 
+__docformat__ = "restructuredText"
+
 import optparse, os
-from credentials import Credentials, DONT_USE_KERBEROS, MUST_USE_KERBEROS
-from hostconfig import Hostconfig
-import samba
+from samba.credentials import (
+    Credentials,
+    DONT_USE_KERBEROS,
+    MUST_USE_KERBEROS,
+    )
+from samba.hostconfig import Hostconfig
+import sys
 
-__docformat__ = "restructuredText"
 
 class SambaOptions(optparse.OptionGroup):
     """General Samba-related command line options."""
+
     def __init__(self, parser):
-        import os, param
+        from samba.param import LoadParm
         optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
         self.add_option("-s", "--configfile", action="callback",
                         type=str, metavar="FILE", help="Configuration file",
@@ -44,7 +50,7 @@ class SambaOptions(optparse.OptionGroup):
                         type=str, metavar="REALM", help="set the realm name",
                         callback=self._set_realm)
         self._configfile = None
-        self._lp = param.LoadParm()
+        self._lp = LoadParm()
 
     def get_loadparm_path(self):
         """Return the path to the smb.conf file specified on the command line.  """
@@ -85,11 +91,11 @@ class VersionOptions(optparse.OptionGroup):
     def __init__(self, parser):
         optparse.OptionGroup.__init__(self, parser, "Version Options")
         self.add_option("--version", action="callback",
-                callback=self._display_version, 
+                callback=self._display_version,
                 help="Display version number")
 
     def _display_version(self, option, opt_str, arg, parser):
-        import samba, sys
+        import samba
         print samba.version
         sys.exit(0)
 
diff --git a/source4/scripting/python/samba/hostconfig.py b/source4/scripting/python/samba/hostconfig.py
index 6eee6cf..3e6dc6b 100644
--- a/source4/scripting/python/samba/hostconfig.py
+++ b/source4/scripting/python/samba/hostconfig.py
@@ -2,32 +2,82 @@
 
 # Unix SMB/CIFS implementation.
 # Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
-#   
+#
 # 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/>.
 #
 
+"""Local host configuration."""
+
 from samdb import SamDB
 
 class Hostconfig(object):
-    """Aggregate object that contains all information about the configuration 
+    """Aggregate object that contains all information about the configuration
     of a Samba host."""
 
-    def __init__(self, lp):       
+    def __init__(self, lp):
         self.lp = lp
 
+    def get_shares(self):
+        return SharesContainer(self.lp)
+
     def get_samdb(self, session_info, credentials):
-        return SamDB(url=self.lp.get("sam database"), 
-                     session_info=session_info, credentials=credentials, 
+        """Access the SamDB host.
+
+        :param session_info: Session info to use
+        :param credentials: Credentials to access the SamDB with
+        """
+        return SamDB(url=self.lp.get("sam database"),
+                     session_info=session_info, credentials=credentials,
                      lp=self.lp)
 
+
+# TODO: Rather than accessing Loadparm directly here, we should really
+# have bindings to the param/shares.c and use those.
+
+
+class SharesContainer(object):
+    """A shares container."""
+
+    def __init__(self, lp):
+        self._lp = lp
+
+    def __getitem__(self, name):
+        if name == "global":
+            # [global] is not a share
+            raise KeyError
+        return Share(self._lp[name])
+
+    def __len__(self):
+        if "global" in self._lp.services():
+            return len(self._lp)-1
+        return len(self._lp)
+
+    def keys(self):
+        return [name for name in self._lp.services() if name != "global"]
+
+    def __iter__(self):
+        return iter(self.keys())
+
+
+class Share(object):
+    """A file share."""
+
+    def __init__(self, service):
+        self._service = service
+
+    def __getitem__(self, name):
+        return self._service[name]
+
+    def __setitem__(self, name, value):
+        self._service[name] = value
diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py
index deeedc5..12df25a 100644
--- a/source4/scripting/python/samba/join.py
+++ b/source4/scripting/python/samba/join.py
@@ -18,13 +18,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import samba.getopt as options
+"""Joining a domain."""
+
 from samba.auth import system_session
 from samba.samdb import SamDB
-from samba import gensec, Ldb, drs_utils, dsdb
+from samba import gensec, Ldb, drs_utils
 import ldb, samba, sys, os, uuid
-from samba.ndr import ndr_pack, ndr_unpack, ndr_print
-from samba.dcerpc import security, drsuapi, misc, netlogon, nbt
+from samba.ndr import ndr_pack
+from samba.dcerpc import security, drsuapi, misc, nbt
 from samba.credentials import Credentials, DONT_USE_KERBEROS
 from samba.provision import secretsdb_self_join, provision, FILL_DRS, find_setup_dir
 from samba.schema import Schema
diff --git a/source4/scripting/python/samba/ms_schema.py b/source4/scripting/python/samba/ms_schema.py
index 2c773bd..64bb28a 100644
--- a/source4/scripting/python/samba/ms_schema.py
+++ b/source4/scripting/python/samba/ms_schema.py
@@ -1,10 +1,11 @@
-#!/usr/bin/env python
 #
 # create schema.ldif (as a string) from WSPP documentation
 #
 # based on minschema.py and minschema_wspp
 #
 
+"""Generate LDIF from WSPP documentation."""
+
 import re
 import base64
 import uuid
@@ -276,5 +277,3 @@ if __name__ == '__main__':
         sys.exit(1)
         
     print read_ms_schema(attr_file, classes_file)
-
-        
diff --git a/source4/scripting/python/samba/ndr.py b/source4/scripting/python/samba/ndr.py
index 3397e1d..1126685 100644
--- a/source4/scripting/python/samba/ndr.py
+++ b/source4/scripting/python/samba/ndr.py
@@ -1,31 +1,49 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # Unix SMB/CIFS implementation.
 # Copyright © Jelmer Vernooij <jelmer at samba.org> 2008
-#   
+#
 # 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/>.
 #
 
+
+"""Network Data Representation (NDR) marshalling and unmarshalling."""
+
+
 def ndr_pack(object):
-    return object.__ndr_pack__()
+    """Pack a NDR object.
+    
+    :param object: Object to pack
+    :return: String object with marshalled object.
+    """
+    ndr_pack = getattr(object, "__ndr_pack__", None)
+    if ndr_pack is None:
+        raise TypeError("%r is not a NDR object" % object)
+    return ndr_pack()
 
 
 def ndr_unpack(cls, data):
+    """NDR unpack an object.
+
+    :param cls: Class of the object to unpack
+    :param data: Buffer to unpack
+    :return: Unpacked object
+    """
     object = cls()
     object.__ndr_unpack__(data)
     return object
 
+
 def ndr_print(object):
     return object.__ndr_print__()
diff --git a/source4/scripting/python/samba/ntacls.py b/source4/scripting/python/samba/ntacls.py
index 4f1c922..0667a51 100644
--- a/source4/scripting/python/samba/ntacls.py
+++ b/source4/scripting/python/samba/ntacls.py
@@ -18,6 +18,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+"""NT Acls."""
+
+
 import os
 import samba.xattr_native, samba.xattr_tdb
 from samba.dcerpc import security, xattr
diff --git a/source4/scripting/python/samba/provision/__init__.py b/source4/scripting/python/samba/provision/__init__.py
index 6b32a71..37d99a5 100644
--- a/source4/scripting/python/samba/provision/__init__.py
+++ b/source4/scripting/python/samba/provision/__init__.py
@@ -53,17 +53,20 @@ from samba import (
     valid_netbios_name,
     version,
     )
+from samba.dcerpc import security
+from samba.dcerpc.misc import (
+    SEC_CHAN_BDC,
+    SEC_CHAN_WKSTA,
+    )
 from samba.dsdb import (
     DS_DOMAIN_FUNCTION_2003,
     DS_DOMAIN_FUNCTION_2008_R2,
     ENC_ALL_TYPES,
     )
-from samba.dcerpc import security
-from samba.dcerpc.misc import SEC_CHAN_BDC, SEC_CHAN_WKSTA
 from samba.idmap import IDmapDB
 from samba.ms_display_specifiers import read_ms_ldif
 from samba.ntacls import setntacl, dsacl2fsacl
-from samba.ndr import ndr_pack,ndr_unpack
+from samba.ndr import ndr_pack, ndr_unpack
 from samba.provision.backend import (
     ExistingBackend,
     FDSBackend,
diff --git a/source4/scripting/python/samba/provision/backend.py b/source4/scripting/python/samba/provision/backend.py
index 8bd9d1f..809dd4f 100644
--- a/source4/scripting/python/samba/provision/backend.py
+++ b/source4/scripting/python/samba/provision/backend.py
@@ -319,7 +319,8 @@ class OpenLDAPBackend(LDAPBackend):
         """Setup a Berkeley database.
 
         :param setup_path: Setup path function.
-        :param dbdir: Database directory."""
+        :param dbdir: Database directory.
+        """
         if not os.path.isdir(os.path.join(dbdir, "bdb-logs")):
             os.makedirs(os.path.join(dbdir, "bdb-logs"), 0700)
             if not os.path.isdir(os.path.join(dbdir, "tmp")):
diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py
index 42e9f9b..2c323bd 100644
--- a/source4/scripting/python/samba/samba3.py
+++ b/source4/scripting/python/samba/samba3.py
@@ -1,18 +1,16 @@
-#!/usr/bin/env python
-
 # Unix SMB/CIFS implementation.
 # Copyright (C) Jelmer Vernooij <jelmer at 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/>.
 #
@@ -67,7 +65,7 @@ class TdbDatabase(object):
 
 class Registry(TdbDatabase):
     """Simple read-only support for reading the Samba3 registry.
-    
+
     :note: This object uses the same syntax for registry key paths as 
         Samba 3. This particular format uses forward slashes for key path 
         separators and abbreviations for the predefined key names. 
@@ -769,7 +767,7 @@ class Samba3(object):
 
     def get_policy_db(self):
         return PolicyDatabase(self.libdir_path("account_policy.tdb"))
-    
+
     def get_registry(self):
         return Registry(self.libdir_path("registry.tdb"))
 
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index a86302a..43b1938 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -83,10 +83,12 @@ class SamDB(samba.Ldb):
         user_dn = res[0].dn
 
         userAccountControl = int(res[0]["userAccountControl"][0])
-        if (userAccountControl & 0x2):
-            userAccountControl = userAccountControl & ~0x2 # remove disabled bit
-        if (userAccountControl & 0x20):
-            userAccountControl = userAccountControl & ~0x20 # remove 'no password required' bit
+        if userAccountControl & 0x2:
+            # remove disabled bit
+            userAccountControl = userAccountControl & ~0x2
+        if userAccountControl & 0x20:
+             # remove 'no password required' bit
+            userAccountControl = userAccountControl & ~0x20
 
         mod = """
 dn: %s
@@ -179,7 +181,8 @@ pwdLastSet: 0
 
         :param groupname: Name of the target group
         :param listofmembers: Comma-separated list of group members
-        :param add_members_operation: Defines if its an add or remove operation
+        :param add_members_operation: Defines if its an add or remove
+            operation
         """
 
         groupfilter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % (groupname, "CN=Group,CN=Schema,CN=Configuration", self.domain_dn())
@@ -444,6 +447,9 @@ accountExpires: %u
         """Read the domain SID used by this LDB. """
         return dsdb._samdb_get_domain_sid(self)
 
+    domain_sid = property(get_domain_sid, set_domain_sid,
+        "SID for the domain")
+
     def set_invocation_id(self, invocation_id):
         """Set the invocation id for this SamDB handle.
 
@@ -451,6 +457,13 @@ accountExpires: %u
         """
         dsdb._dsdb_set_ntds_invocation_id(self, invocation_id)
 
+    def get_invocation_id(self):
+        """Get the invocation_id id"""
+        return dsdb._samdb_ntds_invocation_id(self)
+
+    invocation_id = property(get_invocation_id, set_invocation_id,
+        "Invocation ID GUID")


-- 
Samba Shared Repository


More information about the samba-cvs mailing list