The branch, master has been updated
       via  cc9ff79d86c dbcheck: err_normalise-mismatch_replace: no msg if no 
error
       via  f1be8813b01 dbcheck: fix doc for err_normalise_mismatch*
       via  c28a3dd6d27 dbcheck: fix doc for do_rename()
       via  17fb635532d dbcheck: remove unused fix_incorrect_deleted_objects 
flag
       via  0aec5b930d9 dbcheck: improve some duplicate doc strings
       via  99cdb2191e9 dbcheck: drop py2 support from dump_attr_values()
       via  713117401c8 dbcheck: don't try to stringify values list twice
       via  081d12de529 dbcheck: add docstring for err_odd_userParameters
       via  9fabe3aafdb dbcheck: fix documentation for 
err_doubled_userParameters
       via  c7b39f1cea0 dbcheck: fix documentation and typo for 
err_utf_userParameters
       via  fa0350374d3 dbcheck: fix documentation for err_base64_userParameters
       via  3afd594273f dbcheck: fix documentation for err_duplicate_values
       via  9938a9f7db3 selftest/subunit: python file modernisation
       via  02c3a66cbec drs_utils: remove unused sendRemoveDsServer()
       via  a8d1a6c59b4 python: remove unused provision.check_install()
       via  e253c45c6d1 samba-tool gpo: use common attr_default
       via  816dee1a132 samba-tool drs: move attr_default to common
       via  2c48e90fad0 samba-tool pso uses common timestamp functions
       via  c8d3547c5fa samba-tool domain: move timestamp functions to common
      from  14768d0d544 s4:torture:smb2: remove unused fallback defines in 
oplock.c

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


- Log -----------------------------------------------------------------
commit cc9ff79d86c64cc25c5618866c95f308204716dd
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 11:53:48 2020 +1300

    dbcheck: err_normalise-mismatch_replace: no msg if no error
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>
    
    Autobuild-User(master): Noel Power <npo...@samba.org>
    Autobuild-Date(master): Wed Dec  9 17:04:23 UTC 2020 on sn-devel-184

commit f1be8813b01227c0c18052b622899026eb4b14d0
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 11:52:40 2020 +1300

    dbcheck: fix doc for err_normalise_mismatch*
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit c28a3dd6d27e60ca84933dac41f0f696eb963b41
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 11:51:42 2020 +1300

    dbcheck: fix doc for do_rename()
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 17fb635532dffb51a2237f1291d215d94e433146
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 11:19:50 2020 +1300

    dbcheck: remove unused fix_incorrect_deleted_objects flag
    
    This was introduced in db15993401f927fd2fcea1687c4155dce2272aa8
    but not actually referenced then or since.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 0aec5b930d9ca278c9045e6b58e4de2b34d8c591
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 10:15:24 2020 +1300

    dbcheck: improve some duplicate doc strings
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 99cdb2191e9ab633579f4e7951c2da042529b95d
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 10:10:50 2020 +1300

    dbcheck: drop py2 support from dump_attr_values()
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 713117401c85642dfa9de0772f0a9954a8b8d804
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 10:12:08 2020 +1300

    dbcheck: don't try to stringify values list twice
    
    dump_attr_values already turns it into a comma separated list.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 081d12de529ba89e8eb3930dd3e1cbf394783394
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 12:34:52 2020 +1300

    dbcheck: add docstring for err_odd_userParameters
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 9fabe3aafdb799db31cf222e186b5ac84b1ed024
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 12:34:22 2020 +1300

    dbcheck: fix documentation for err_doubled_userParameters
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit c7b39f1cea0ef4b27c4897d20ca718c5eb195210
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 12:34:02 2020 +1300

    dbcheck: fix documentation and typo for err_utf_userParameters
    
    pseudo, not psudo.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit fa0350374d3ffdf78e920361315556034730fde8
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 12:33:27 2020 +1300

    dbcheck: fix documentation for err_base64_userParameters
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 3afd594273f659056f15b6e6a1a45b68824bf113
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Fri Dec 4 11:56:00 2020 +1300

    dbcheck: fix documentation for err_duplicate_values
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 9938a9f7db37283a1e3d2c52e1246c573ecd649b
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 16:44:42 2020 +1300

    selftest/subunit: python file modernisation
    
    Python idioms for iterating over a line and closing it have improved,
    and we should keep up.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 02c3a66cbec2c670d809b186cacc7d075c16ec54
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 12:43:01 2020 +1300

    drs_utils: remove unused sendRemoveDsServer()
    
    The only caller of this was `samba-tool domain demote` which stopped
    using it in 2015 with commit f121173cbf46fe64746d73adf40015c43d5c55fc.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit a8d1a6c59b4e43869454a3e3528948613e9b0c61
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 12:23:45 2020 +1300

    python: remove unused provision.check_install()
    
    Unused for at last 10 years.
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit e253c45c6d1cd76da682f72a0903f01bf094c8a1
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 11:24:47 2020 +1300

    samba-tool gpo: use common attr_default
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 816dee1a132e6b586de8b0123fd8e9572aff4c32
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 11:24:25 2020 +1300

    samba-tool drs: move attr_default to common
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 2c48e90fad04db6a78fc4dc1f2cb12154db7f711
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 11:20:35 2020 +1300

    samba-tool pso uses common timestamp functions
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit c8d3547c5fa8724198541cb67b60e5c8e212a1ad
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu Nov 19 11:19:04 2020 +1300

    samba-tool domain: move timestamp functions to common
    
    Other tools use identical functions, and they too can use common.py
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

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

Summary of changes:
 python/samba/dbchecker.py          | 55 ++++++++++++++++++--------------------
 python/samba/drs_utils.py          | 23 ----------------
 python/samba/netcmd/common.py      | 28 +++++++++++++++++++
 python/samba/netcmd/domain.py      | 23 +++-------------
 python/samba/netcmd/drs.py         |  8 +-----
 python/samba/netcmd/gpo.py         |  8 +-----
 python/samba/netcmd/pso.py         | 21 +++------------
 python/samba/provision/__init__.py | 15 -----------
 selftest/subunithelper.py          | 16 +++--------
 9 files changed, 66 insertions(+), 131 deletions(-)


Changeset truncated at 500 lines:

diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index 339af01cb1b..28b56edaafb 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -35,25 +35,20 @@ from samba.auth import system_session, admin_session
 from samba.netcmd import CommandError
 from samba.netcmd.fsmo import get_fsmo_roleowner
 
-# vals is a sequence of ldb.bytes objects which are a subclass
-# of 'byte' type in python3 and just a str type in python2, to
-# display as string these need to be converted to string via (str)
-# function in python3 but that may generate a UnicodeDecode error,
-# if so use repr instead.  We need to at least try to get the 'str'
-# value if possible to allow some tests which check the strings
-# outputted to pass, these tests compare attr values logged to stdout
-# against those in various results files.
 
 def dump_attr_values(vals):
-    result = ""
+    """Stringify a value list, using utf-8 if possible (which some tests
+    want), or the python bytes representation otherwise (with leading
+    'b' and escapes like b'\x00').
+    """
+    result = []
     for value in vals:
-        if len(result):
-            result = "," + result
         try:
-            result = result + str(value)
+            result.append(value.decode('utf-8'))
         except UnicodeDecodeError:
-            result = result + repr(value)
-    return result
+            result.append(repr(value))
+    return ','.join(result)
+
 
 class dbcheck(object):
     """check a SAM database for errors"""
@@ -102,7 +97,6 @@ class dbcheck(object):
         self.fix_replmetadata_wrong_attid = False
         self.fix_replmetadata_unsorted_attid = False
         self.fix_deleted_deleted_objects = False
-        self.fix_incorrect_deleted_objects = False
         self.fix_dn = False
         self.fix_base64_userparameters = False
         self.fix_utf8_userparameters = False
@@ -442,7 +436,7 @@ systemFlags: -1946157056%s""" % (dn, guid_suffix),
         return True
 
     def do_rename(self, from_dn, to_rdn, to_base, controls, msg):
-        '''perform a modify with optional verbose output'''
+        '''perform a rename with optional verbose output'''
         if self.verbose:
             self.report("""dn: %s
 changeType: modrdn
@@ -486,7 +480,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Removed empty attribute %s" % attrname)
 
     def err_normalise_mismatch(self, dn, attrname, values):
-        '''fix attribute normalisation errors'''
+        '''fix attribute normalisation errors, without altering sort order'''
         self.report("ERROR: Normalisation error for attribute %s in %s" % 
(attrname, dn))
         mod_list = []
         for val in values:
@@ -517,12 +511,13 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Normalised attribute %s" % attrname)
 
     def err_normalise_mismatch_replace(self, dn, attrname, values):
-        '''fix attribute normalisation errors'''
+        '''fix attribute normalisation and/or sort errors'''
         normalised = self.samdb.dsdb_normalise_attributes(self.samdb_schema, 
attrname, values)
-        self.report("ERROR: Normalisation error for attribute '%s' in '%s'" % 
(attrname, dn))
-        self.report("Values/Order of values do/does not match: %s/%s!" % 
(values, list(normalised)))
         if list(normalised) == values:
+            # how we got here is a mystery.
             return
+        self.report("ERROR: Normalisation error for attribute '%s' in '%s'" % 
(attrname, dn))
+        self.report("Values/Order of values do/does not match: %s/%s!" % 
(values, list(normalised)))
         if not self.confirm_all("Fix normalisation for '%s' from '%s'?" % 
(attrname, dn), 'fix_all_normalisation'):
             self.report("Not fixing attribute '%s'" % attrname)
             return
@@ -537,9 +532,10 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Normalised attribute %s" % attrname)
 
     def err_duplicate_values(self, dn, attrname, dup_values, values):
-        '''fix attribute normalisation errors'''
+        '''fix duplicate attribute values'''
         self.report("ERROR: Duplicate values for attribute '%s' in '%s'" % 
(attrname, dn))
-        self.report("Values contain a duplicate: [%s]/[%s]!" % 
(','.join(dump_attr_values(dup_values)), ','.join(dump_attr_values(values))))
+        self.report("Values contain a duplicate: [%s]/[%s]!" %
+                    (dump_attr_values(dup_values), dump_attr_values(values)))
         if not self.confirm_all("Fix duplicates for '%s' from '%s'?" % 
(attrname, dn), 'fix_all_duplicates'):
             self.report("Not fixing attribute '%s'" % attrname)
             return
@@ -724,7 +720,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Fixed %s on attribute %s" % (errstr, attrname))
 
     def err_dn_string_component_old(self, dn, attrname, val, dsdb_dn, 
correct_dn):
-        """handle a DN string being incorrect"""
+        """handle a DN string being incorrect due to a rename or delete"""
         self.report("NOTE: old (due to rename or delete) DN string component 
for %s in object %s - %s" % (attrname, dn, val))
         dsdb_dn.dn = correct_dn
 
@@ -759,7 +755,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Fixed incorrect DN %s on attribute %s" % 
(mismatch_type, attrname))
 
     def err_dn_component_missing_target_sid(self, dn, attrname, val, dsdb_dn, 
target_sid_blob):
-        """handle a DN string being incorrect"""
+        """fix missing <SID=...> on linked attributes"""
         self.report("ERROR: missing DN SID component for %s in object %s - %s" 
% (attrname, dn, val))
 
         if len(dsdb_dn.prefix) != 0:
@@ -977,7 +973,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
         self.report("ERROR: incorrect userParameters value on object %s.  If 
you have another working DC that does not give this warning, please run 
'samba-tool drs replicate --full-sync --local <destinationDC> <sourceDC> %s'" % 
(obj.dn, self.samdb.get_nc_root(obj.dn)))
 
     def err_base64_userParameters(self, obj, attrname, value):
-        '''handle a wrong userParameters'''
+        '''handle a userParameters that is wrongly base64 encoded'''
         self.report("ERROR: wrongly formatted userParameters %s on %s, should 
not be base64-encoded" % (value, obj.dn))
         if not self.confirm_all('Convert userParameters from base64 encoding 
on %s?' % (obj.dn), 'fix_base64_userparameters'):
             self.report('Not changing userParameters from base64 encoding on 
%s' % (obj.dn))
@@ -991,8 +987,9 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Corrected base64-encoded userParameters on %s by 
converting from base64" % (obj.dn))
 
     def err_utf8_userParameters(self, obj, attrname, value):
-        '''handle a wrong userParameters'''
-        self.report("ERROR: wrongly formatted userParameters on %s, should not 
be psudo-UTF8 encoded" % (obj.dn))
+        '''handle a userParameters that is wrongly utf-8 encoded'''
+        self.report("ERROR: wrongly formatted userParameters on %s, "
+                    "should not be pseudo-UTF8 encoded" % (obj.dn))
         if not self.confirm_all('Convert userParameters from UTF8 encoding on 
%s?' % (obj.dn), 'fix_utf8_userparameters'):
             self.report('Not changing userParameters from UTF8 encoding on %s' 
% (obj.dn))
             return
@@ -1006,7 +1003,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Corrected psudo-UTF8 encoded userParameters on %s by 
converting from UTF8" % (obj.dn))
 
     def err_doubled_userParameters(self, obj, attrname, value):
-        '''handle a wrong userParameters'''
+        '''handle a userParameters that has been utf-16 encoded twice'''
         self.report("ERROR: wrongly formatted userParameters on %s, should not 
be double UTF16 encoded" % (obj.dn))
         if not self.confirm_all('Convert userParameters from doubled UTF-16 
encoding on %s?' % (obj.dn), 'fix_doubled_userparameters'):
             self.report('Not changing userParameters from doubled UTF-16 
encoding on %s' % (obj.dn))
@@ -1032,7 +1029,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), 
str(to_base)))
             self.report("Corrected doubled-UTF16 encoded userParameters on %s 
by converting" % (obj.dn))
 
     def err_odd_userParameters(self, obj, attrname):
-        # This is a truncated userParameters due to a pre 4.1 replication bug
+        """Fix a truncated userParameters due to a pre 4.1 replication bug"""
         self.report("ERROR: incorrect userParameters value on object %s (odd 
length).  If you have another working DC that does not give this warning, 
please run 'samba-tool drs replicate --full-sync --local <destinationDC> 
<sourceDC> %s'" % (obj.dn, self.samdb.get_nc_root(obj.dn)))
 
     def find_revealed_link(self, dn, attrname, guid):
diff --git a/python/samba/drs_utils.py b/python/samba/drs_utils.py
index 43d1b4a2488..feab89b0d8e 100644
--- a/python/samba/drs_utils.py
+++ b/python/samba/drs_utils.py
@@ -92,29 +92,6 @@ def sendDsReplicaSync(drsuapiBind, drsuapi_handle, 
source_dsa_guid,
         raise drsException("DsReplicaSync failed %s" % estr)
 
 
-def sendRemoveDsServer(drsuapiBind, drsuapi_handle, server_dsa_dn, domain):
-    """Send RemoveDSServer request.
-
-    :param drsuapiBind: a drsuapi Bind object
-    :param drsuapi_handle: a drsuapi handle on the drsuapi connection
-    :param server_dsa_dn: a DN object of the server's dsa that we want to
-        demote
-    :param domain: a DN object of the server's domain
-    :raise drsException: if any error occur while sending and receiving the
-        reply for the DsRemoveDSServer
-    """
-
-    try:
-        req1 = drsuapi.DsRemoveDSServerRequest1()
-        req1.server_dn = str(server_dsa_dn)
-        req1.domain_dn = str(domain)
-        req1.commit = 1
-
-        drsuapiBind.DsRemoveDSServer(drsuapi_handle, 1, req1)
-    except Exception as estr:
-        raise drsException("DsRemoveDSServer failed %s" % estr)
-
-
 def drs_DsBind(drs):
     '''make a DsBind call, returning the binding handle'''
     bind_info = drsuapi.DsBindInfoCtr()
diff --git a/python/samba/netcmd/common.py b/python/samba/netcmd/common.py
index f53ff4555a9..bb17bfa10f2 100644
--- a/python/samba/netcmd/common.py
+++ b/python/samba/netcmd/common.py
@@ -22,6 +22,11 @@ from samba.dcerpc import nbt
 from samba.net import Net
 import ldb
 
+
+# In MS AD, setting a timeout to '(never)' corresponds to this value
+NEVER_TIMESTAMP = int(-0x8000000000000000)
+
+
 def _get_user_realm_domain(user):
     r""" get the realm or the domain and the base user
         from user like:
@@ -112,3 +117,26 @@ def get_ldif_for_editor(samdb, msg):
     result_ldif = samdb.write_ldif(m, ldb.CHANGETYPE_NONE)
 
     return result_ldif
+
+
+def timestamp_to_mins(timestamp_str):
+    """Converts a timestamp in -100 nanosecond units to minutes"""
+    # treat a timestamp of 'never' the same as zero (this should work OK for
+    # most settings, and it displays better than trying to convert
+    # -0x8000000000000000 to minutes)
+    if int(timestamp_str) == NEVER_TIMESTAMP:
+        return 0
+    else:
+        return abs(int(timestamp_str)) / (1e7 * 60)
+
+
+def timestamp_to_days(timestamp_str):
+    """Converts a timestamp in -100 nanosecond units to days"""
+    return timestamp_to_mins(timestamp_str) / (60 * 24)
+
+
+def attr_default(msg, attrname, default):
+    '''get an attribute from a ldap msg with a default'''
+    if attrname in msg:
+        return msg[attrname][0]
+    return default
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
index 71dacf67a89..6a02b2ecac0 100644
--- a/python/samba/netcmd/domain.py
+++ b/python/samba/netcmd/domain.py
@@ -62,6 +62,9 @@ from samba.netcmd import (
 )
 from samba.netcmd.fsmo import get_fsmo_roleowner
 from samba.netcmd.common import netcmd_get_domain_infos_via_cldap
+from samba.netcmd.common import (NEVER_TIMESTAMP,
+                                 timestamp_to_mins,
+                                 timestamp_to_days)
 from samba.samba3 import Samba3
 from samba.samba3 import param as s3param
 from samba.upgrade import upgrade_from_samba3
@@ -1210,26 +1213,6 @@ class cmd_domain_level(Command):
             raise CommandError("invalid argument: '%s' (choose from 'show', 
'raise')" % subcommand)
 
 
-# In MS AD, setting a timeout to '(never)' corresponds to this value
-NEVER_TIMESTAMP = int(-0x8000000000000000)
-
-
-def timestamp_to_mins(timestamp_str):
-    """Converts a timestamp in -100 nanosecond units to minutes"""
-    # treat a timestamp of 'never' the same as zero (this should work OK for
-    # most settings, and it displays better than trying to convert
-    # -0x8000000000000000 to minutes)
-    if int(timestamp_str) == NEVER_TIMESTAMP:
-        return 0
-    else:
-        return abs(int(timestamp_str)) / (1e7 * 60)
-
-
-def timestamp_to_days(timestamp_str):
-    """Converts a timestamp in -100 nanosecond units to days"""
-    return timestamp_to_mins(timestamp_str) / (60 * 24)
-
-
 class cmd_domain_passwordsettings_show(Command):
     """Display current password settings for the domain."""
 
diff --git a/python/samba/netcmd/drs.py b/python/samba/netcmd/drs.py
index 023b09d0506..5b439f8e6e1 100644
--- a/python/samba/netcmd/drs.py
+++ b/python/samba/netcmd/drs.py
@@ -33,6 +33,7 @@ from samba.netcmd import (
     Option,
     SuperCommand,
 )
+from samba.netcmd.common import attr_default
 from samba.samdb import SamDB
 from samba import drs_utils, nttime2string, dsdb
 from samba.dcerpc import drsuapi, misc
@@ -75,13 +76,6 @@ def drs_errmsg(werr):
     return "failed, result %u (%s)" % (ecode, estring)
 
 
-def attr_default(msg, attrname, default):
-    '''get an attribute from a ldap msg with a default'''
-    if attrname in msg:
-        return msg[attrname][0]
-    return default
-
-
 def drs_parse_ntds_dn(ntds_dn):
     '''parse a NTDS DN returning a site and server'''
     a = ntds_dn.split(',')
diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py
index bbaa0c17881..ca479207d6e 100644
--- a/python/samba/netcmd/gpo.py
+++ b/python/samba/netcmd/gpo.py
@@ -63,13 +63,7 @@ from samba.gp_parse.gp_inf import GptTmplInfParser
 from samba.gp_parse.gp_aas import GPAasParser
 from samba import param
 from samba.credentials import SMB_SIGNING_REQUIRED
-
-
-def attr_default(msg, attrname, default):
-    '''get an attribute from a ldap msg with a default'''
-    if attrname in msg:
-        return msg[attrname][0]
-    return default
+from samba.netcmd.common import attr_default
 
 
 def gpo_flags_string(value):
diff --git a/python/samba/netcmd/pso.py b/python/samba/netcmd/pso.py
index 200b6ff2a9e..d260e3bd406 100644
--- a/python/samba/netcmd/pso.py
+++ b/python/samba/netcmd/pso.py
@@ -22,30 +22,15 @@ from samba.netcmd import (Command, CommandError, Option, 
SuperCommand)
 from samba.dcerpc.samr import (DOMAIN_PASSWORD_COMPLEX,
                                DOMAIN_PASSWORD_STORE_CLEARTEXT)
 from samba.auth import system_session
-
-NEVER_TIMESTAMP = int(-0x8000000000000000)
+from samba.netcmd.common import (NEVER_TIMESTAMP,
+                                 timestamp_to_mins,
+                                 timestamp_to_days)
 
 
 def pso_container(samdb):
     return "CN=Password Settings Container,CN=System,%s" % samdb.domain_dn()
 
 
-def timestamp_to_mins(timestamp_str):
-    """Converts a timestamp in -100 nanosecond units to minutes"""
-    # treat a timestamp of 'never' the same as zero (this should work OK for
-    # most settings, and it displays better than trying to convert
-    # -0x8000000000000000 to minutes)
-    if int(timestamp_str) == NEVER_TIMESTAMP:
-        return 0
-    else:
-        return abs(int(timestamp_str)) / (1e7 * 60)
-
-
-def timestamp_to_days(timestamp_str):
-    """Converts a timestamp in -100 nanosecond units to days"""
-    return timestamp_to_mins(timestamp_str) / (60 * 24)
-
-
 def mins_to_timestamp(mins):
     """Converts a value in minutes to -100 nanosecond units"""
     timestamp = -int((1e7) * 60 * mins)
diff --git a/python/samba/provision/__init__.py 
b/python/samba/provision/__init__.py
index 0706f39c581..136267e7aad 100644
--- a/python/samba/provision/__init__.py
+++ b/python/samba/provision/__init__.py
@@ -499,21 +499,6 @@ class ProvisionResult(object):
             self.backend_result.report_logger(logger)
 
 
-def check_install(lp, session_info, credentials):
-    """Check whether the current install seems ok.
-
-    :param lp: Loadparm context
-    :param session_info: Session information
-    :param credentials: Credentials
-    """
-    if lp.get("realm") == "":
-        raise Exception("Realm empty")
-    samdb = Ldb(lp.samdb_url(), session_info=session_info,
-                credentials=credentials, lp=lp)
-    if len(samdb.search("(cn=Administrator)")) != 1:
-        raise ProvisioningError("No administrator account found")
-
-
 def findnss(nssfn, names):
     """Find a user or group from a list of possibilities.
 
diff --git a/selftest/subunithelper.py b/selftest/subunithelper.py
index 26158cad339..4fbb5442839 100644
--- a/selftest/subunithelper.py
+++ b/selftest/subunithelper.py
@@ -45,10 +45,7 @@ def parse_results(msg_ops, statistics, fh):
     exitcode = 0
     open_tests = {}
 
-    while fh:
-        l = fh.readline()
-        if l == "":
-            break
+    for l in fh:
         parts = l.split(None, 1)
         if not len(parts) == 2 or not l.startswith(parts[0]):
             msg_ops.output_msg(l)
@@ -80,10 +77,7 @@ def parse_results(msg_ops, statistics, fh):
                 reason = ""
                 # reason may be specified in next lines
                 terminated = False
-                while fh:
-                    l = fh.readline()
-                    if l == "":
-                        break
+                for l in fh:
                     msg_ops.control_msg(l)
                     if l == "]\n":
                         terminated = True
@@ -250,8 +244,7 @@ def read_test_regexes(*names):
             files.append(name)
 
     for filename in files:
-        f = open(filename, 'r')
-        try:
+        with open(filename, 'r') as f:
             for l in f:
                 l = l.strip()
                 if l == "" or l[0] == "#":
@@ -261,8 +254,7 @@ def read_test_regexes(*names):
                     ret[regex.strip()] = reason.strip()
                 else:
                     ret[l] = None
-        finally:
-            f.close()
+
     return ret
 
 


-- 
Samba Shared Repository

Reply via email to