[SCM] Samba Shared Repository - branch master updated
David Mulder
dmulder at samba.org
Fri Oct 2 14:50:04 UTC 2020
The branch, master has been updated
via a3cd3153212 python2 reduction: Merge remaining compat code into common
via 85d2ff2f000 python: Move dsdb_Dn to samdb
from 234957a2e44 Fix build after removal of an extra safe_string.h
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit a3cd31532125ccb537af6cd9d27c761b7da4b03a
Author: David Mulder <dmulder at suse.com>
Date: Fri Sep 11 14:29:46 2020 -0600
python2 reduction: Merge remaining compat code into common
The remaining compat code (get_string, get_bytes,
cmp) are useful helper routines which we should
simply merge into common (especially since there
is some duplication here).
Signed-off-by: David Mulder <dmulder at suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Autobuild-User(master): David Mulder <dmulder at samba.org>
Autobuild-Date(master): Fri Oct 2 14:49:36 UTC 2020 on sn-devel-184
commit 85d2ff2f0003b106ca84866b7e7893723f1dd93c
Author: David Mulder <dmulder at suse.com>
Date: Mon Sep 14 11:12:37 2020 -0600
python: Move dsdb_Dn to samdb
The import dsdb needed for dsdb_Dn causes import
errors when trying to import get_bytes/get_string
in some places.
Signed-off-by: David Mulder <dmulder at suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
-----------------------------------------------------------------------
Summary of changes:
python/samba/common.py | 131 +++++++--------------
python/samba/compat.py | 76 ------------
python/samba/dbchecker.py | 2 +-
python/samba/emulate/traffic.py | 2 +-
python/samba/gp_parse/__init__.py | 2 +-
python/samba/gp_sec_ext.py | 2 +-
python/samba/gpclass.py | 2 +-
python/samba/join.py | 2 +-
python/samba/kcc/__init__.py | 4 +-
python/samba/kcc/kcc_utils.py | 2 +-
python/samba/kcc/ldif_import_export.py | 3 +-
python/samba/ms_forest_updates_markdown.py | 2 +-
python/samba/netcmd/computer.py | 2 +-
python/samba/netcmd/contact.py | 2 +-
python/samba/netcmd/domain.py | 2 +-
python/samba/netcmd/drs.py | 2 +-
python/samba/netcmd/group.py | 2 +-
python/samba/netcmd/user.py | 4 +-
python/samba/provision/sambadns.py | 2 +-
python/samba/samba3/__init__.py | 2 +-
python/samba/samdb.py | 76 +++++++++++-
python/samba/schema.py | 2 +-
python/samba/tests/auth_log_netlogon_bad_creds.py | 2 +-
python/samba/tests/auth_log_winbind.py | 2 +-
python/samba/tests/blackbox/netads_json.py | 2 +-
python/samba/tests/blackbox/samba_dnsupdate.py | 2 +-
python/samba/tests/common.py | 4 +-
python/samba/tests/dcerpc/misc.py | 8 +-
python/samba/tests/gpo.py | 2 +-
python/samba/tests/krb5/kcrypto.py | 2 +-
python/samba/tests/ntlm_auth.py | 2 +-
python/samba/tests/prefork_restart.py | 2 +-
python/samba/tests/py_credentials.py | 2 +-
python/samba/tests/samba_tool/help.py | 2 +-
python/samba/tests/samba_tool/user.py | 4 +-
python/samba/upgradehelpers.py | 4 +-
selftest/filter-subunit | 6 +-
source3/script/tests/test_wbinfo_sids2xids_int.py | 2 +-
source4/dsdb/tests/python/acl.py | 2 +-
source4/dsdb/tests/python/deletetest.py | 2 +-
source4/dsdb/tests/python/ldap.py | 2 +-
source4/dsdb/tests/python/sam.py | 2 +-
source4/dsdb/tests/python/sort.py | 10 +-
source4/dsdb/tests/python/tombstone_reanimation.py | 2 +-
source4/dsdb/tests/python/vlv.py | 4 +-
source4/scripting/bin/samba_dnsupdate | 2 +-
source4/scripting/bin/samba_spnupdate | 2 +-
source4/scripting/bin/samba_upgradeprovision | 6 +-
source4/torture/drs/python/drs_base.py | 8 +-
source4/torture/drs/python/getnc_exop.py | 14 +--
source4/torture/drs/python/repl_rodc.py | 2 +-
source4/torture/drs/python/replica_sync_rodc.py | 2 +-
.../torture/drs/python/samba_tool_drs_no_dns.py | 2 +-
.../torture/drs/python/samba_tool_drs_showrepl.py | 2 +-
54 files changed, 192 insertions(+), 246 deletions(-)
delete mode 100644 python/samba/compat.py
Changeset truncated at 500 lines:
diff --git a/python/samba/common.py b/python/samba/common.py
index 8876e4f4faa..d5945307c3a 100644
--- a/python/samba/common.py
+++ b/python/samba/common.py
@@ -1,6 +1,7 @@
# Samba common functions
#
# Copyright (C) Matthieu Patou <mat at matws.net>
+# Copyright (C) Lumir Balhar <lbalhar at redhat.com> 2017
#
# 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
@@ -17,21 +18,16 @@
#
-import ldb
-from samba import dsdb
-from samba.ndr import ndr_pack
-from samba.dcerpc import misc
-import binascii
-
-from samba.compat import PY3
-
+def cmp(x, y):
+ """
+ Replacement for built-in function cmp that was removed in Python 3
-if PY3:
- # cmp() exists only in Python 2
- def cmp(a, b):
- return (a > b) - (a < b)
+ Compare the two objects x and y and return an integer according to
+ the outcome. The return value is negative if x < y, zero if x == y
+ and strictly positive if x > y.
+ """
- raw_input = input
+ return (x > y) - (x < y)
def confirm(msg, forced=False, allow_all=False):
@@ -60,7 +56,7 @@ def confirm(msg, forced=False, allow_all=False):
prompt = '[y/N/all/none]'
while True:
- v = raw_input(msg + ' %s ' % prompt)
+ v = input(msg + ' %s ' % prompt)
v = v.upper()
if v in mapping:
return mapping[v]
@@ -74,75 +70,38 @@ def normalise_int32(ivalue):
return str(ivalue)
-class dsdb_Dn(object):
- '''a class for binary DN'''
-
- def __init__(self, samdb, dnstring, syntax_oid=None):
- '''create a dsdb_Dn'''
- if syntax_oid is None:
- # auto-detect based on string
- if dnstring.startswith("B:"):
- syntax_oid = dsdb.DSDB_SYNTAX_BINARY_DN
- elif dnstring.startswith("S:"):
- syntax_oid = dsdb.DSDB_SYNTAX_STRING_DN
- else:
- syntax_oid = dsdb.DSDB_SYNTAX_OR_NAME
- if syntax_oid in [dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN]:
- # it is a binary DN
- colons = dnstring.split(':')
- if len(colons) < 4:
- raise RuntimeError("Invalid DN %s" % dnstring)
- prefix_len = 4 + len(colons[1]) + int(colons[1])
- self.prefix = dnstring[0:prefix_len]
- self.binary = self.prefix[3 + len(colons[1]):-1]
- self.dnstring = dnstring[prefix_len:]
- else:
- self.dnstring = dnstring
- self.prefix = ''
- self.binary = ''
- self.dn = ldb.Dn(samdb, self.dnstring)
-
- def __str__(self):
- return self.prefix + str(self.dn.extended_str(mode=1))
-
- def __cmp__(self, other):
- ''' compare dsdb_Dn values similar to parsed_dn_compare()'''
- dn1 = self
- dn2 = other
- guid1 = dn1.dn.get_extended_component("GUID")
- guid2 = dn2.dn.get_extended_component("GUID")
-
- v = cmp(guid1, guid2)
- if v != 0:
- return v
- v = cmp(dn1.binary, dn2.binary)
- return v
-
- # In Python3, __cmp__ is replaced by these 6 methods
- def __eq__(self, other):
- return self.__cmp__(other) == 0
-
- def __ne__(self, other):
- return self.__cmp__(other) != 0
-
- def __lt__(self, other):
- return self.__cmp__(other) < 0
-
- def __le__(self, other):
- return self.__cmp__(other) <= 0
-
- def __gt__(self, other):
- return self.__cmp__(other) > 0
-
- def __ge__(self, other):
- return self.__cmp__(other) >= 0
-
- def get_binary_integer(self):
- '''return binary part of a dsdb_Dn as an integer, or None'''
- if self.prefix == '':
- return None
- return int(self.binary, 16)
-
- def get_bytes(self):
- '''return binary as a byte string'''
- return binascii.unhexlify(self.binary)
+# Sometimes in PY3 we have variables whose content can be 'bytes' or
+# 'str' and we can't be sure which. Generally this is because the
+# code variable can be initialised (or reassigned) a value from different
+# api(s) or functions depending on complex conditions or logic. Or another
+# common case is in PY2 the variable is 'type <str>' and in PY3 it is
+# 'class <str>' and the function to use e.g. b64encode requires 'bytes'
+# in PY3. In such cases it would be nice to avoid excessive testing in
+# the client code. Calling such a helper function should be avoided
+# if possible but sometimes this just isn't possible.
+# If a 'str' object is passed in it is encoded using 'utf8' or if 'bytes'
+# is passed in it is returned unchanged.
+# Using this function is PY2/PY3 code should ensure in most cases
+# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
+# encodes the variable (see PY2 implementation of this function below)
+def get_bytes(bytesorstring):
+ tmp = bytesorstring
+ if isinstance(bytesorstring, str):
+ tmp = bytesorstring.encode('utf8')
+ elif not isinstance(bytesorstring, bytes):
+ raise ValueError('Expected byte or string for %s:%s' % (type(bytesorstring), bytesorstring))
+ return tmp
+
+# helper function to get a string from a variable that maybe 'str' or
+# 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
+# it is returned unchanged
+# Using this function is PY2/PY3 code should ensure in most cases
+# the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
+# decodes the variable (see PY2 implementation of this function below)
+def get_string(bytesorstring):
+ tmp = bytesorstring
+ if isinstance(bytesorstring, bytes):
+ tmp = bytesorstring.decode('utf8')
+ elif not isinstance(bytesorstring, str):
+ raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
+ return tmp
diff --git a/python/samba/compat.py b/python/samba/compat.py
deleted file mode 100644
index a2b6f3c8645..00000000000
--- a/python/samba/compat.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# module which helps with porting to Python 3
-#
-# Copyright (C) Lumir Balhar <lbalhar at redhat.com> 2017
-#
-# 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/>.
-
-"""module which helps with porting to Python 3"""
-
-import sys
-
-PY3 = sys.version_info[0] == 3
-
-if PY3:
- # Sometimes in PY3 we have variables whose content can be 'bytes' or
- # 'str' and we can't be sure which. Generally this is because the
- # code variable can be initialised (or reassigned) a value from different
- # api(s) or functions depending on complex conditions or logic. Or another
- # common case is in PY2 the variable is 'type <str>' and in PY3 it is
- # 'class <str>' and the function to use e.g. b64encode requires 'bytes'
- # in PY3. In such cases it would be nice to avoid excessive testing in
- # the client code. Calling such a helper function should be avoided
- # if possible but sometimes this just isn't possible.
- # If a 'str' object is passed in it is encoded using 'utf8' or if 'bytes'
- # is passed in it is returned unchanged.
- # Using this function is PY2/PY3 code should ensure in most cases
- # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
- # encodes the variable (see PY2 implementation of this function below)
- def get_bytes(bytesorstring):
- tmp = bytesorstring
- if isinstance(bytesorstring, str):
- tmp = bytesorstring.encode('utf8')
- elif not isinstance(bytesorstring, bytes):
- raise ValueError('Expected byte or string for %s:%s' % (type(bytesorstring), bytesorstring))
- return tmp
-
- # helper function to get a string from a variable that maybe 'str' or
- # 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
- # it is returned unchanged
- # Using this function is PY2/PY3 code should ensure in most cases
- # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
- # decodes the variable (see PY2 implementation of this function below)
- def get_string(bytesorstring):
- tmp = bytesorstring
- if isinstance(bytesorstring, bytes):
- tmp = bytesorstring.decode('utf8')
- elif not isinstance(bytesorstring, str):
- raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
- return tmp
-
- def cmp_fn(x, y):
- """
- Replacement for built-in function cmp that was removed in Python 3
-
- Compare the two objects x and y and return an integer according to
- the outcome. The return value is negative if x < y, zero if x == y
- and strictly positive if x > y.
- """
-
- return (x > y) - (x < y)
- # compat functions
- from functools import cmp_to_key as cmp_to_key_fn
-
-
-else:
- raise NotImplementedError("Samba versions >= 4.11 do not support Python 2.x")
diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index 5b4645ebb45..339af01cb1b 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -28,7 +28,7 @@ from samba.dcerpc import misc
from samba.dcerpc import drsuapi
from samba.ndr import ndr_unpack, ndr_pack
from samba.dcerpc import drsblobs
-from samba.common import dsdb_Dn
+from samba.samdb import dsdb_Dn
from samba.dcerpc import security
from samba.descriptor import get_wellknown_sds, get_diff_sds
from samba.auth import system_session, admin_session
diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py
index c428b4e369e..9b6bdb6af57 100644
--- a/python/samba/emulate/traffic.py
+++ b/python/samba/emulate/traffic.py
@@ -53,7 +53,7 @@ from samba.dsdb import (
from samba.dcerpc.misc import SEC_CHAN_BDC
from samba import gensec
from samba import sd_utils
-from samba.compat import get_string
+from samba.common import get_string
from samba.logger import get_samba_logger
import bisect
diff --git a/python/samba/gp_parse/__init__.py b/python/samba/gp_parse/__init__.py
index 8ddd52d3657..bc6058638f1 100644
--- a/python/samba/gp_parse/__init__.py
+++ b/python/samba/gp_parse/__init__.py
@@ -21,7 +21,7 @@ from xml.dom import minidom
from io import BytesIO
from xml.etree.ElementTree import ElementTree, fromstring, tostring
from hashlib import md5
-from samba.compat import get_bytes
+from samba.common import get_bytes
ENTITY_USER_ID = 0
diff --git a/python/samba/gp_sec_ext.py b/python/samba/gp_sec_ext.py
index 070bde9fd60..136ba220de7 100644
--- a/python/samba/gp_sec_ext.py
+++ b/python/samba/gp_sec_ext.py
@@ -18,7 +18,7 @@
import os.path
from samba.gpclass import gp_inf_ext
from samba.auth import system_session
-from samba.compat import get_string
+from samba.common import get_string
try:
from ldb import LdbError
from samba.samdb import SamDB
diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py
index 8e9bfb9f0e3..ac73671eb58 100644
--- a/python/samba/gpclass.py
+++ b/python/samba/gpclass.py
@@ -23,7 +23,7 @@ sys.path.insert(0, "bin/python")
from samba import NTSTATUSError
from configparser import ConfigParser
from io import StringIO
-from samba.compat import get_bytes
+from samba.common import get_bytes
from abc import ABCMeta, abstractmethod
import xml.etree.ElementTree as etree
import re
diff --git a/python/samba/join.py b/python/samba/join.py
index dca9ff634d5..59de000a401 100644
--- a/python/samba/join.py
+++ b/python/samba/join.py
@@ -49,7 +49,7 @@ import re
import os
import tempfile
from collections import OrderedDict
-from samba.compat import get_string
+from samba.common import get_string
from samba.netcmd import CommandError
diff --git a/python/samba/kcc/__init__.py b/python/samba/kcc/__init__.py
index 734c7641883..73cdc9f1ef0 100644
--- a/python/samba/kcc/__init__.py
+++ b/python/samba/kcc/__init__.py
@@ -44,7 +44,7 @@ from samba.kcc.graph import Vertex
from samba.kcc.debug import DEBUG, DEBUG_FN, logger
from samba.kcc import debug
-from samba.compat import cmp_fn
+from samba.common import cmp
def sort_dsa_by_gc_and_guid(dsa1, dsa2):
@@ -61,7 +61,7 @@ def sort_dsa_by_gc_and_guid(dsa1, dsa2):
return -1
if not dsa1.is_gc() and dsa2.is_gc():
return +1
- return cmp_fn(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid))
+ return cmp(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid))
def is_smtp_replication_available():
diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py
index e0712e49c82..9b4a894b743 100644
--- a/python/samba/kcc/kcc_utils.py
+++ b/python/samba/kcc/kcc_utils.py
@@ -30,7 +30,7 @@ from samba.dcerpc import (
drsuapi,
misc,
)
-from samba.common import dsdb_Dn
+from samba.samdb import dsdb_Dn
from samba.ndr import ndr_unpack, ndr_pack
from collections import Counter
diff --git a/python/samba/kcc/ldif_import_export.py b/python/samba/kcc/ldif_import_export.py
index 86453f1e5c9..7ec553edcb9 100644
--- a/python/samba/kcc/ldif_import_export.py
+++ b/python/samba/kcc/ldif_import_export.py
@@ -23,8 +23,7 @@ import os
from samba import Ldb, ldb, read_and_sub_file
from samba.auth import system_session
-from samba.samdb import SamDB
-from samba.common import dsdb_Dn
+from samba.samdb import SamDB, dsdb_Dn
class LdifError(Exception):
diff --git a/python/samba/ms_forest_updates_markdown.py b/python/samba/ms_forest_updates_markdown.py
index 62e9ad9b354..e219211d027 100644
--- a/python/samba/ms_forest_updates_markdown.py
+++ b/python/samba/ms_forest_updates_markdown.py
@@ -27,7 +27,7 @@ import re
import os
import markdown
import xml.etree.ElementTree as ET
-from samba.compat import get_string
+from samba.common import get_string
# Display specifier updates or otherwise (ignored in forest_update.py)
diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py
index 86c7b824d82..9d7a220a005 100644
--- a/python/samba/netcmd/computer.py
+++ b/python/samba/netcmd/computer.py
@@ -34,7 +34,7 @@ from samba.ndr import ndr_unpack, ndr_pack, ndr_print
from samba.remove_dc import remove_dns_references
from samba.auth import system_session
from samba.samdb import SamDB
-from samba.compat import get_bytes
+from samba.common import get_bytes
from subprocess import check_call, CalledProcessError
from . import common
diff --git a/python/samba/netcmd/contact.py b/python/samba/netcmd/contact.py
index d3eeb23be64..064a3ce6691 100644
--- a/python/samba/netcmd/contact.py
+++ b/python/samba/netcmd/contact.py
@@ -36,7 +36,7 @@ from samba.netcmd import (
SuperCommand,
Option,
)
-from samba.compat import get_bytes
+from samba.common import get_bytes
from . import common
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
index 238f3c306c1..000688f4e7a 100644
--- a/python/samba/netcmd/domain.py
+++ b/python/samba/netcmd/domain.py
@@ -101,7 +101,7 @@ from samba.provision.common import (
from samba.netcmd.pso import cmd_domain_passwordsettings_pso
from samba.netcmd.domain_backup import cmd_domain_backup
-from samba.compat import get_string
+from samba.common import get_string
string_version_to_constant = {
"2008_R2": DS_DOMAIN_FUNCTION_2008_R2,
diff --git a/python/samba/netcmd/drs.py b/python/samba/netcmd/drs.py
index cebcca5f489..023b09d0506 100644
--- a/python/samba/netcmd/drs.py
+++ b/python/samba/netcmd/drs.py
@@ -46,7 +46,7 @@ from samba.uptodateness import (
get_utdv_summary,
get_kcc_and_dsas,
)
-from samba.compat import get_string
+from samba.common import get_string
from samba.samdb import get_default_backend_store
def drsuapi_connect(ctx):
diff --git a/python/samba/netcmd/group.py b/python/samba/netcmd/group.py
index 2942d553f2d..b5c86d33019 100644
--- a/python/samba/netcmd/group.py
+++ b/python/samba/netcmd/group.py
@@ -36,7 +36,7 @@ from samba.dsdb import (
)
from collections import defaultdict
from subprocess import check_call, CalledProcessError
-from samba.compat import get_bytes
+from samba.common import get_bytes
import os
import tempfile
from . import common
diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py
index c49dccd704f..f9762e761ea 100644
--- a/python/samba/netcmd/user.py
+++ b/python/samba/netcmd/user.py
@@ -53,8 +53,8 @@ from samba.netcmd import (
SuperCommand,
Option,
)
-from samba.compat import get_bytes
-from samba.compat import get_string
+from samba.common import get_bytes
+from samba.common import get_string
from . import common
# python[3]-gpgme is abandoned since ubuntu 1804 and debian 9
diff --git a/python/samba/provision/sambadns.py b/python/samba/provision/sambadns.py
index 4aa132abfa6..8a5d8a93442 100644
--- a/python/samba/provision/sambadns.py
+++ b/python/samba/provision/sambadns.py
@@ -60,7 +60,7 @@ from samba.provision.common import (
)
from samba.samdb import get_default_backend_store
-from samba.compat import get_string
+from samba.common import get_string
def get_domainguid(samdb, domaindn):
res = samdb.search(base=domaindn, scope=ldb.SCOPE_BASE, attrs=["objectGUID"])
diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py
index b092f450953..f15bb291394 100644
--- a/python/samba/samba3/__init__.py
+++ b/python/samba/samba3/__init__.py
@@ -28,7 +28,7 @@ import tdb
from samba.samba3 import passdb
from samba.samba3 import param as s3param
-from samba.compat import get_bytes
+from samba.common import get_bytes
def fetch_uint32(db, key):
try:
diff --git a/python/samba/samdb.py b/python/samba/samdb.py
index f1af3c28c30..0ec91ed3970 100644
--- a/python/samba/samdb.py
+++ b/python/samba/samdb.py
@@ -32,8 +32,9 @@ 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.compat import get_bytes
+from samba.common import get_bytes, cmp
--
Samba Shared Repository
More information about the samba-cvs
mailing list