summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-02-26 20:51:04 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-02-26 22:24:42 +0100
commit411119db501b131c0632d852129c9f3819cb4190 (patch)
tree7c92079b2af9a3eac3a48c9b1293067874a2cdcd /source4/scripting
parentd5485a1e5602ceac0ed37db665f5680c9a8ab43c (diff)
downloadsamba-411119db501b131c0632d852129c9f3819cb4190.tar.gz
samba-411119db501b131c0632d852129c9f3819cb4190.tar.bz2
samba-411119db501b131c0632d852129c9f3819cb4190.zip
provision: Share more code for determine_netbios_name() with samba.valid_netbios_name().
Autobuild-User: Jelmer Vernooij <jelmer@samba.org> Autobuild-Date: Sun Feb 26 22:24:42 CET 2012 on sn-devel-104
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/__init__.py10
-rw-r--r--source4/scripting/python/samba/provision/__init__.py14
2 files changed, 10 insertions, 14 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 20e6e70920..f6af472f83 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -300,16 +300,16 @@ def setup_file(template, fname, subst_vars=None):
finally:
f.close()
+MAX_NETBIOS_NAME_LEN = 15
+def is_valid_netbios_char(c):
+ return (c.isalnum() or c in " !#$%&'()-.@^_{}~")
def valid_netbios_name(name):
"""Check whether a name is valid as a NetBIOS name. """
# See crh's book (1.4.1.1)
- if len(name) > 15:
+ if len(name) > MAX_NETBIOS_NAME_LEN:
return False
- for x in name:
- if not x.isalnum() and not x in " !#$%&'()-.@^_{}~":
- return False
- return True
+ return all([is_valid_netbios_char(x) for x in name])
def import_bundled_package(modulename, location):
diff --git a/source4/scripting/python/samba/provision/__init__.py b/source4/scripting/python/samba/provision/__init__.py
index bff3ce6bf1..3a69a07177 100644
--- a/source4/scripting/python/samba/provision/__init__.py
+++ b/source4/scripting/python/samba/provision/__init__.py
@@ -46,7 +46,9 @@ import samba
from samba.dsdb import DS_DOMAIN_FUNCTION_2000
from samba import (
Ldb,
+ MAX_NETBIOS_NAME_LEN,
check_all_substituted,
+ is_valid_netbios_char,
setup_file,
substitute_var,
valid_netbios_name,
@@ -93,7 +95,6 @@ from samba.samdb import SamDB
from samba.dbchecker import dbcheck
-VALID_NETBIOS_CHARS = " !#$%&'()-.@^_{}~"
DEFAULT_POLICY_GUID = "31B2F340-016D-11D2-945F-00C04FB984F9"
DEFAULT_DC_POLICY_GUID = "6AC1786C-016F-11D2-945F-00C04fB984F9"
DEFAULTSITE = "Default-First-Site-Name"
@@ -482,14 +483,9 @@ def provision_paths_from_lp(lp, dnsdomain):
def determine_netbios_name(hostname):
"""Determine a netbios name from a hostname."""
- netbiosname = hostname
- # remove forbidden chars
- newnbname = ""
- for x in netbiosname:
- if x.isalnum() or x in VALID_NETBIOS_CHARS:
- newnbname = "%s%c" % (newnbname, x)
- # force the length to be <16
- return newnbname[0:15].upper()
+ # remove forbidden chars and force the length to be <16
+ netbiosname = "".join([x for x in hostname if is_valid_netbios_char(x)])
+ return netbiosname[:MAX_NETBIOS_NAME_LEN].upper()
def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None,