From eba25f5d1897fbe61e8d7c623fcacb647629bf07 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 10:29:45 +0100 Subject: r26375: Move provision-independent utility function to main samba python module. (This used to be commit 9d0ff47be069422de7ef2794357c6f3e9c540e67) --- source4/scripting/python/samba/__init__.py | 9 +++++++++ source4/scripting/python/samba/provision.py | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 46d8ff7d37..00b82e1800 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -55,3 +55,12 @@ def substitute_var(text, values): return text + +def valid_netbios_name(name): + """Check whether a name is valid as a NetBIOS name. """ + # FIXME: There are probably more constraints here. + # crh has a paragraph on this in his book (1.4.1.1) + if len(name) > 13: + return False + return True + diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 3d391863da..692e49b095 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -14,7 +14,7 @@ import uuid, sid, misc from socket import gethostname, gethostbyname import param import registry -from samba import Ldb, substitute_var +from samba import Ldb, substitute_var, valid_netbios_name from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ LDB_ERR_NO_SUCH_OBJECT, timestring @@ -191,14 +191,17 @@ unixName: %s """ % (res[0].dn, unixname) ldb.modify(ldb.parse_ldif(mod).next()[1]) + def hostip(): """return first host IP.""" return gethostbyname(hostname()) + def hostname(): """return first part of hostname.""" return gethostname().split(".")[0] + def ldb_delete(ldb): """Delete a LDB file. @@ -805,15 +808,6 @@ member: %s ldb.transaction_commit() -def valid_netbios_name(name): - """Check whether a name is valid as a NetBIOS name. """ - # FIXME: There are probably more constraints here. - # crh has a paragraph on this in his book (1.4.1.1) - if len(name) > 13: - return False - return True - - def join_domain(domain, netbios_name, join_type, creds, message): ctx = NetContext(creds) joindom = object() -- cgit