[SCM] Samba Shared Repository - branch master updated
Andrew Tridgell
tridge at samba.org
Mon Nov 29 00:50:02 MST 2010
The branch, master has been updated
via 7025087 wintest: cope with the heimdal version of kinit
via dc0c89c s4-samdb: give a better exception if multiple users match in password change
via c522cd7 s4-repl_schema: fixed ldb exception handling
via 37bfc4e s4-samba-tool: fixed exception handling in subcommands
via 6250690 s4-samba-tool: fixed ldb exception handling in domainlevel command
via a1f9692 s4-samba-tool: improved exception handling in samba-tool
via 8c59bbd s4-join: fixed exception handling in join command
via abe9ac5 s4-ldapcmp: make ldapcmp a samba-tool command
via f8d73e4 s4-ldapcmp: fixed exception handling
via 0dd2152 s4-pyglue: added get_debug_level() method
via 33d1787 s4-loadparm: use loadparm_init_global() instead of loadparm_init()
via b20ce43 s4-loadparm: added loadparm_init_global()
via 6982a00 s4-gpo: started on samba-tool gpo list command
via 6cd01c9 s4-dsdb: give full error message for operational failures
via 74d373d s4-pydsdb: two more GPO related flags
via 7a826d0 s4-samba-tool: started on gpo subcommands in python
via e54c8be s4-pydsdb: added GPO policy flags
from 97f0d6c samba.tests.hostconfig: Fix import.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 702508745682c29cb3f9959b7c22d535b767459f
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 17:19:55 2010 +1100
wintest: cope with the heimdal version of kinit
Autobuild-User: Andrew Tridgell <tridge at samba.org>
Autobuild-Date: Mon Nov 29 08:49:36 CET 2010 on sn-devel-104
commit dc0c89cf405e7cc1d66540c4f94b1b395da2439a
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 16:57:25 2010 +1100
s4-samdb: give a better exception if multiple users match in password change
commit c522cd73ac29c0bc2551e679284da71d46f533e1
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:16:18 2010 +1100
s4-repl_schema: fixed ldb exception handling
commit 37bfc4ec384df71a4cb1c19ceb136fecd3b9afc6
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:15:57 2010 +1100
s4-samba-tool: fixed exception handling in subcommands
this switches to the new pattern of:
except Exception, e:
raise CommandError("some error message", e)
commit 62506903101e8e8e1cfc6c70fee245f97c646844
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:14:01 2010 +1100
s4-samba-tool: fixed ldb exception handling in domainlevel command
Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
commit a1f96923e655d58ff339e06536cac9d1135dd0cb
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:11:57 2010 +1100
s4-samba-tool: improved exception handling in samba-tool
we now do reasonable printing on a wide range of common exception
classes, and always force a backtrace on an exception if the debug
level is >= 3
Pair-Programmed-With: Jelmer Vernooij <jelmer at samba.org>
commit 8c59bbd757e834f8dd1037edcd4ad5cf96a602a4
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:10:57 2010 +1100
s4-join: fixed exception handling in join command
commit abe9ac53f0d240a867d499f184866603143756cf
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 14:10:26 2010 +1100
s4-ldapcmp: make ldapcmp a samba-tool command
The ldapcmp tool is very useful, and should be available to Samba
admins, not just developers. This makes it a samba-tool command, which
also gives it the nicer command line handling that samba-tool has
commit f8d73e466b454a63f256021ad2f353e9ad93e8f7
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 13:30:46 2010 +1100
s4-ldapcmp: fixed exception handling
This pattern, which is common in our code, is wrong:
except LdbError, (ERR_NO_SUCH_OBJECT, _):
what it actually does it to change the value of ldb.ERR_NO_SUCH_OBJECT
to be equal to whatever ldb error occurred! This led to some really
bizarre behavior
commit 0dd2152b01b93b2a09ea0332ba60e2e0338b1c15
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 13:26:48 2010 +1100
s4-pyglue: added get_debug_level() method
Pair-Programmed-With: Jelmer Vernooij <jelmer at samba.org>
commit 33d178767b425510448435748bdd780402106ded
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 13:25:59 2010 +1100
s4-loadparm: use loadparm_init_global() instead of loadparm_init()
this prevents us having two lp_ctx contexts in these tools which leads
to bizarre behaviour
Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
commit b20ce4392e2d00c3edff8b4b8f329cf22341ea76
Author: Andrew Tridgell <tridge at samba.org>
Date: Mon Nov 29 13:24:51 2010 +1100
s4-loadparm: added loadparm_init_global()
This ensures we use the same loadparm_context in all our command line
tools.
Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
commit 6982a00ded40a70cddea22451482342e99102e58
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Nov 28 14:33:12 2010 +1100
s4-gpo: started on samba-tool gpo list command
commit 6cd01c9665de107e756dc1208727338d05bea98d
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Nov 28 14:32:51 2010 +1100
s4-dsdb: give full error message for operational failures
commit 74d373d0f7dfd8b3b7c8bbeb493de1e2bbc99ce4
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Nov 28 14:32:01 2010 +1100
s4-pydsdb: two more GPO related flags
commit 7a826d02a386cb2429a992b84ca597b174cfc35d
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Nov 28 12:20:15 2010 +1100
s4-samba-tool: started on gpo subcommands in python
this adds the listall GPO command. Currently the python variants are
available as "samba-tool gpo2 SUBCOMMAND". These will replace the
"samba-tool gpo" commands when complete
commit e54c8bef8a926abf7cd52af5906ed0736f52d800
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Nov 28 12:18:29 2010 +1100
s4-pydsdb: added GPO policy flags
-----------------------------------------------------------------------
Summary of changes:
source4/dsdb/pydsdb.c | 9 +
source4/dsdb/samdb/ldb_modules/operational.c | 4 +-
source4/kdc/mit_samba.c | 2 +-
source4/lib/cmdline/popt_common.c | 2 +-
source4/param/loadparm.c | 27 +++
source4/param/param.h | 1 +
source4/param/pyparam.c | 2 +-
source4/param/pyparam_util.c | 35 ++--
source4/scripting/python/pyglue.c | 7 +
source4/scripting/python/samba/__init__.py | 1 +
source4/scripting/python/samba/join.py | 19 +-
source4/scripting/python/samba/netcmd/__init__.py | 53 ++++-
.../scripting/python/samba/netcmd/domainlevel.py | 8 +-
source4/scripting/python/samba/netcmd/drs.py | 20 +-
source4/scripting/python/samba/netcmd/gpo.py | 222 +++++++++++++++++++
source4/scripting/python/samba/netcmd/group.py | 20 +-
.../ldapcmp => python/samba/netcmd/ldapcmp.py} | 230 ++++++++++----------
source4/scripting/python/samba/netcmd/newuser.py | 5 +-
source4/scripting/python/samba/netcmd/ntacl.py | 5 +-
.../scripting/python/samba/netcmd/pwsettings.py | 4 +-
source4/scripting/python/samba/netcmd/rodc.py | 8 +-
.../scripting/python/samba/netcmd/setpassword.py | 5 +-
source4/scripting/python/samba/ntacls.py | 4 +-
.../scripting/python/samba/provision/__init__.py | 22 +-
source4/scripting/python/samba/samdb.py | 13 +-
source4/scripting/python/samba/schema.py | 2 +-
source4/scripting/python/samba/upgradehelpers.py | 16 +-
source4/torture/drs/python/repl_schema.py | 6 +-
wintest/test-s4-howto.py | 3 +-
wintest/wintest.py | 10 +-
30 files changed, 538 insertions(+), 227 deletions(-)
create mode 100644 source4/scripting/python/samba/netcmd/gpo.py
rename source4/scripting/{devel/ldapcmp => python/samba/netcmd/ldapcmp.py} (85%)
Changeset truncated at 500 lines:
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index e5e6767..f5832d1 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -27,6 +27,7 @@
#include "system/kerberos.h"
#include "auth/kerberos/kerberos.h"
#include "librpc/rpc/pyrpc_util.h"
+#include "lib/policy/policy.h"
/* There's no Py_ssize_t in 2.4, apparently */
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
@@ -825,4 +826,12 @@ void initdsdb(void)
ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
+
+ /* GPO policy flags */
+ ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
+ ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
+ ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
+ ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
+ ADD_DSDB_FLAG(GPO_INHERIT);
+ ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
}
diff --git a/source4/dsdb/samdb/ldb_modules/operational.c b/source4/dsdb/samdb/ldb_modules/operational.c
index ebeec71..d981311 100644
--- a/source4/dsdb/samdb/ldb_modules/operational.c
+++ b/source4/dsdb/samdb/ldb_modules/operational.c
@@ -672,8 +672,8 @@ static int operational_search_post_process(struct ldb_module *module,
failed:
ldb_debug_set(ldb, LDB_DEBUG_WARNING,
- "operational_search_post_process failed for attribute '%s'",
- attrs_from_user[a]);
+ "operational_search_post_process failed for attribute '%s' - %s",
+ attrs_from_user[a], ldb_errstring(ldb));
return -1;
}
diff --git a/source4/kdc/mit_samba.c b/source4/kdc/mit_samba.c
index 956ccd3..3d5888c 100644
--- a/source4/kdc/mit_samba.c
+++ b/source4/kdc/mit_samba.c
@@ -70,7 +70,7 @@ static int mit_samba_context_init(struct mit_samba_context **_ctx)
ret = ENOMEM;
goto done;
}
- base_ctx.lp_ctx = loadparm_init(ctx);
+ base_ctx.lp_ctx = loadparm_init_global(false);
if (!base_ctx.lp_ctx) {
ret = ENOMEM;
goto done;
diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c
index 7d9e65d..76c6fb2 100644
--- a/source4/lib/cmdline/popt_common.c
+++ b/source4/lib/cmdline/popt_common.c
@@ -83,7 +83,7 @@ static void popt_samba_callback(poptContext con,
pname++;
if (reason == POPT_CALLBACK_REASON_PRE) {
- cmdline_lp_ctx = loadparm_init(talloc_autofree_context());
+ cmdline_lp_ctx = loadparm_init_global(false);
/* Hook for 'almost the first thing to do in a samba program' here */
/* setup for panics */
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index f6f894d..55cb45e 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -531,6 +531,8 @@ struct loadparm_context {
time_t modtime;
} *file_lists;
unsigned int flags[NUMPARAMETERS];
+ bool loaded;
+ bool refuse_free;
};
@@ -2263,6 +2265,13 @@ static int lp_destructor(struct loadparm_context *lp_ctx)
{
struct parmlist_entry *data;
+ if (lp_ctx->refuse_free) {
+ /* someone is trying to free the
+ global_loadparm_context.
+ We can't allow that. */
+ return -1;
+ }
+
if (lp_ctx->globals->param_opt != NULL) {
struct parmlist_entry *next;
for (data = lp_ctx->globals->param_opt; data; data=next) {
@@ -2278,6 +2287,8 @@ static int lp_destructor(struct loadparm_context *lp_ctx)
/**
* Initialise the global parameter structure.
+ *
+ * Note that most callers should use loadparm_init_global() instead
*/
struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
{
@@ -2481,6 +2492,21 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
return lp_ctx;
}
+/**
+ * Initialise the global parameter structure.
+ */
+struct loadparm_context *loadparm_init_global(bool load_default)
+{
+ if (global_loadparm_context == NULL) {
+ global_loadparm_context = loadparm_init(NULL);
+ }
+ if (load_default && !global_loadparm_context->loaded) {
+ lpcfg_load_default(global_loadparm_context);
+ }
+ global_loadparm_context->refuse_free = true;
+ return global_loadparm_context;
+}
+
const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
{
return lp_ctx->szConfigFile;
@@ -2588,6 +2614,7 @@ bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
/* set the context used by the lp_*() function
varients */
global_loadparm_context = lp_ctx;
+ lp_ctx->loaded = true;
}
return bRetval;
diff --git a/source4/param/param.h b/source4/param/param.h
index ea121fa..21a97fb 100644
--- a/source4/param/param.h
+++ b/source4/param/param.h
@@ -175,6 +175,7 @@ void lpcfg_killunused(struct loadparm_context *lp_ctx,
* Initialise the global parameter structure.
*/
struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
+struct loadparm_context *loadparm_init_global(bool load_default);
const char *lpcfg_configfile(struct loadparm_context *lp_ctx);
bool lpcfg_load_default(struct loadparm_context *lp_ctx);
const char *lp_default_path(void);
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
index cb7169e..be29c72 100644
--- a/source4/param/pyparam.c
+++ b/source4/param/pyparam.c
@@ -330,7 +330,7 @@ static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwa
PyErr_NoMemory();
return NULL;
}
- ret->ptr = loadparm_init(ret->talloc_ctx);
+ ret->ptr = loadparm_init_global(false);
return (PyObject *)ret;
}
diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c
index 474dd31..57a9b1b 100644
--- a/source4/param/pyparam_util.c
+++ b/source4/param/pyparam_util.c
@@ -22,33 +22,30 @@
#include "param/param.h"
#include "param/loadparm.h"
#include "lib/talloc/pytalloc.h"
+#include "lib/cmdline/popt_common.h"
#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context)
_PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyObject *py_obj)
{
- struct loadparm_context *lp_ctx;
+ struct loadparm_context *lp_ctx;
PyObject *param_mod;
PyTypeObject *lp_type;
bool is_lpobj;
- if (PyString_Check(py_obj)) {
- lp_ctx = loadparm_init(mem_ctx);
- if (!lpcfg_load(lp_ctx, PyString_AsString(py_obj))) {
- talloc_free(lp_ctx);
+ if (PyString_Check(py_obj)) {
+ lp_ctx = loadparm_init_global(false);
+ if (!lpcfg_load(lp_ctx, PyString_AsString(py_obj))) {
PyErr_Format(PyExc_RuntimeError, "Unable to load %s",
- PyString_AsString(py_obj));
- return NULL;
- }
- return lp_ctx;
- }
+ PyString_AsString(py_obj));
+ return NULL;
+ }
+ return lp_ctx;
+ }
- if (py_obj == Py_None) {
- lp_ctx = loadparm_init(mem_ctx);
- /* We're not checking that loading the file succeeded *on purpose */
- lpcfg_load_default(lp_ctx);
- return lp_ctx;
- }
+ if (py_obj == Py_None) {
+ return loadparm_init_global(true);
+ }
param_mod = PyImport_ImportModule("samba.param");
if (param_mod == NULL) {
@@ -74,11 +71,7 @@ _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyOb
struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx)
{
- struct loadparm_context *ret;
- ret = loadparm_init(mem_ctx);
- if (!lpcfg_load_default(ret))
- return NULL;
- return ret;
+ return loadparm_init_global(true);
}
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index b77ce2b..950e3e4 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -110,6 +110,11 @@ static PyObject *py_set_debug_level(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *py_get_debug_level(PyObject *self)
+{
+ return PyInt_FromLong(DEBUGLEVEL);
+}
+
/*
return the list of interface IPs we have configured
takes an loadparm context, returns a list of IPs in string form
@@ -181,6 +186,8 @@ static PyMethodDef py_misc_methods[] = {
"nttime2string(nttime) -> string" },
{ "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
"set debug level" },
+ { "get_debug_level", (PyCFunction)py_get_debug_level, METH_NOARGS,
+ "get debug level" },
{ "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
"get interface IP address list"},
{ NULL }
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index ee45d93..bd76289 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -327,6 +327,7 @@ from samba import _glue
version = _glue.version
interface_ips = _glue.interface_ips
set_debug_level = _glue.set_debug_level
+get_debug_level = _glue.get_debug_level
unix2nttime = _glue.unix2nttime
nttime2string = _glue.nttime2string
nttime2unix = _glue.nttime2unix
diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py
index 12df25a..60f3ac3 100644
--- a/source4/scripting/python/samba/join.py
+++ b/source4/scripting/python/samba/join.py
@@ -120,14 +120,14 @@ class dc_join:
if recursive:
try:
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_ONELEVEL, attrs=["dn"])
- except:
+ except Exception:
return
for r in res:
ctx.del_noerror(r.dn, recursive=True)
try:
ctx.samdb.delete(dn)
print "Deleted %s" % dn
- except:
+ except Exception:
pass
def cleanup_old_join(ctx):
@@ -151,16 +151,15 @@ class dc_join:
if res:
ctx.new_krbtgt_dn = res[0]["msDS-Krbtgtlink"][0]
ctx.del_noerror(ctx.new_krbtgt_dn)
- except:
+ except Exception:
pass
def find_dc(ctx, domain):
'''find a writeable DC for the given domain'''
try:
ctx.cldap_ret = ctx.net.finddc(domain, nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
- except Exception, reason:
- print("Failed to find a writeable DC for domain '%s': %s" % (domain, reason))
- sys.exit(1)
+ except Exception:
+ raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
ctx.site = ctx.cldap_ret.client_site
return ctx.cldap_ret.pdc_dns_name
@@ -199,8 +198,10 @@ class dc_join:
'''check if a DN exists'''
try:
res = ctx.samdb.search(base=dn, scope=ldb.SCOPE_BASE, attrs=[])
- except ldb.LdbError, (ERR_NO_SUCH_OBJECT, _):
- return False
+ except ldb.LdbError, (enum, estr):
+ if enum == ldb.ERR_NO_SUCH_OBJECT:
+ return False
+ raise
return True
def add_krbtgt_account(ctx):
@@ -506,7 +507,7 @@ class dc_join:
ctx.join_provision()
ctx.join_replicate()
ctx.join_finalise()
- except:
+ except Exception:
print "Join failed - cleaning up"
ctx.cleanup_old_join()
raise
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index af317ab..aa74f65 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -17,9 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import optparse
+import optparse, samba
from samba import getopt as options
-import sys
+from ldb import LdbError
+import sys, traceback
class Option(optparse.Option):
@@ -52,6 +53,40 @@ class Command(object):
ret += " " + " ".join([x.upper() for x in self.takes_args])
return ret
+ def show_command_error(self, e):
+ '''display a command error'''
+ if isinstance(e, CommandError):
+ (etype, evalue, etraceback) = e.exception_info
+ inner_exception = e.inner_exception
+ message = e.message
+ force_traceback = False
+ else:
+ (etype, evalue, etraceback) = sys.exc_info()
+ inner_exception = e
+ message = "uncaught exception"
+ force_traceback = True
+
+ if isinstance(inner_exception, LdbError):
+ (ldb_ecode, ldb_emsg) = inner_exception
+ print >>sys.stderr, "ERROR(ldb): %s - %s" % (message, ldb_emsg)
+ elif isinstance(inner_exception, AssertionError):
+ print >>sys.stderr, "ERROR(assert): %s" % message
+ force_traceback = True
+ elif isinstance(inner_exception, RuntimeError):
+ print >>sys.stderr, "ERROR(runtime): %s - %s" % (message, evalue)
+ elif type(inner_exception) is Exception:
+ print >>sys.stderr, "ERROR(exception): %s - %s" % (message, evalue)
+ force_traceback = True
+ elif inner_exception is None:
+ print >>sys.stderr, "ERROR: %s" % (message)
+ else:
+ print >>sys.stderr, "ERROR(%s): %s - %s" % (str(etype), message, evalue)
+ force_traceback = True
+
+ if force_traceback or samba.get_debug_level() >= 3:
+ traceback.print_tb(etraceback)
+
+
synopsis = property(_get_synopsis)
outf = sys.stdout
@@ -97,8 +132,8 @@ class Command(object):
return -1
try:
return self.run(*args, **kwargs)
- except CommandError, e:
- print >>sys.stderr, "ERROR: %s" % e
+ except Exception, e:
+ self.show_command_error(e)
return -1
def run(self):
@@ -130,7 +165,11 @@ class SuperCommand(Command):
class CommandError(Exception):
- pass
+ '''an exception class for netcmd errors'''
+ def __init__(self, message, inner_exception=None):
+ self.message = message
+ self.inner_exception = inner_exception
+ self.exception_info = sys.exc_info()
commands = {}
@@ -170,3 +209,7 @@ from samba.netcmd.rodc import cmd_rodc
commands["rodc"] = cmd_rodc()
from samba.netcmd.drs import cmd_drs
commands["drs"] = cmd_drs()
+from samba.netcmd.gpo import cmd_gpo
+commands["gpo2"] = cmd_gpo()
+from samba.netcmd.ldapcmp import cmd_ldapcmp
+commands["ldapcmp"] = cmd_ldapcmp()
diff --git a/source4/scripting/python/samba/netcmd/domainlevel.py b/source4/scripting/python/samba/netcmd/domainlevel.py
index 60cd844..54a778c 100644
--- a/source4/scripting/python/samba/netcmd/domainlevel.py
+++ b/source4/scripting/python/samba/netcmd/domainlevel.py
@@ -195,8 +195,8 @@ class cmd_domainlevel(Command):
ldb.FLAG_MOD_REPLACE, "nTMixedDomain")
try:
samdb.modify(m)
- except LdbError, (num, _):
- if num != ldb.ERR_UNWILLING_TO_PERFORM:
+ except ldb.LdbError, (enum, emsg):
+ if enum != ldb.ERR_UNWILLING_TO_PERFORM:
raise
# Directly on the base DN
@@ -215,8 +215,8 @@ class cmd_domainlevel(Command):
"msDS-Behavior-Version")
try:
samdb.modify(m)
- except LdbError, (num, _):
- if num != ldb.ERR_UNWILLING_TO_PERFORM:
+ except ldb.LdbError, (enum, emsg):
+ if enum != ldb.ERR_UNWILLING_TO_PERFORM:
raise
level_domain = new_level_domain
diff --git a/source4/scripting/python/samba/netcmd/drs.py b/source4/scripting/python/samba/netcmd/drs.py
index 387524b..6f5b5b8 100644
--- a/source4/scripting/python/samba/netcmd/drs.py
+++ b/source4/scripting/python/samba/netcmd/drs.py
@@ -44,8 +44,8 @@ def drsuapi_connect(ctx):
try:
ctx.drsuapi = drsuapi.drsuapi(binding_string, ctx.lp, ctx.creds)
(ctx.drsuapi_handle, ctx.bind_supported_extensions) = drs_utils.drs_DsBind(ctx.drsuapi)
- except Exception, estr:
- raise CommandError("DRS connection to %s failed - %s" % (ctx.server, estr))
+ except Exception, e:
+ raise CommandError("DRS connection to %s failed" % ctx.server, e)
def samdb_connect(ctx):
@@ -54,8 +54,8 @@ def samdb_connect(ctx):
ctx.samdb = SamDB(url="ldap://%s" % ctx.server,
session_info=system_session(),
credentials=ctx.creds, lp=ctx.lp)
- except Exception, estr:
- raise CommandError("LDAP connection to %s failed - %s" % (ctx.server, estr))
+ except Exception, e:
+ raise CommandError("LDAP connection to %s failed" % ctx.server, e)
def drs_errmsg(werr):
@@ -119,8 +119,8 @@ class cmd_drs_showrepl(Command):
req1.info_type = info_type
try:
(info_type, info) = ctx.drsuapi.DsReplicaGetInfo(ctx.drsuapi_handle, 1, req1)
- except Exception, estr:
- raise CommandError("DsReplicaGetInfo failed : %s" % estr)
+ except Exception, e:
+ raise CommandError("DsReplicaGetInfo of type %u failed" % info_type, e)
return (info_type, info)
@@ -221,8 +221,8 @@ class cmd_drs_kcc(Command):
req1 = drsuapi.DsExecuteKCC1()
try:
self.drsuapi.DsExecuteKCC(self.drsuapi_handle, 1, req1)
- except Exception, (ecode, estr):
- raise CommandError("DsExecuteKCC failed - %s" % estr)
+ except Exception, e:
+ raise CommandError("DsExecuteKCC failed", e)
print("Consistency check on %s successful." % DC)
@@ -289,8 +289,8 @@ class cmd_drs_replicate(Command):
try:
self.drsuapi.DsReplicaSync(self.drsuapi_handle, 1, req1)
- except Exception, (ecode, estr):
- raise CommandError("DsReplicaSync failed - %s" % estr)
+ except Exception, e:
+ raise CommandError("DsReplicaSync failed", estr)
print("Replicate from %s to %s was successful." % (SOURCE_DC, DEST_DC))
diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py
new file mode 100644
index 0000000..5e8748a
--- /dev/null
--
Samba Shared Repository
More information about the samba-cvs
mailing list