1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-03 04:22:09 +03:00

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
This commit is contained in:
Jelmer Vernooij
2012-02-26 20:51:04 +01:00
parent d5485a1e56
commit 411119db50
2 changed files with 10 additions and 14 deletions

View File

@ -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):

View File

@ -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,