diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-25 16:36:23 -0600 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-26 11:57:06 -0600 |
commit | cc30cb5e24160d107b67936d71f54645d9b3d23f (patch) | |
tree | 7e741cee81c15e47f4d013bb8e05180b207f48ca | |
parent | 3c22677a8ce1635d7e055f954153dec4c1796b17 (diff) | |
download | samba-cc30cb5e24160d107b67936d71f54645d9b3d23f.tar.gz samba-cc30cb5e24160d107b67936d71f54645d9b3d23f.tar.bz2 samba-cc30cb5e24160d107b67936d71f54645d9b3d23f.zip |
r26592: Finish fixing the samba3dump script.
(This used to be commit 85679f3fc98238f90280f9f10d42550d71eeb918)
-rw-r--r-- | source4/param/param.i | 59 | ||||
-rw-r--r-- | source4/param/param.py | 53 | ||||
-rw-r--r-- | source4/param/param_wrap.c | 194 | ||||
-rwxr-xr-x | source4/scripting/bin/samba3dump | 240 | ||||
-rw-r--r-- | source4/scripting/python/samba/samba3.py | 63 |
5 files changed, 476 insertions, 133 deletions
diff --git a/source4/param/param.i b/source4/param/param.i index 11cda9910a..375c3d0da4 100644 --- a/source4/param/param.i +++ b/source4/param/param.i @@ -181,6 +181,7 @@ typedef struct param_context { struct param_opt *get(const char *name, const char *section_name="global"); const char *get_string(const char *name, const char *section_name="global"); int set_string(const char *param, const char *value, const char *section="global"); +#ifdef SWIGPYTHON int set(const char *parameter, PyObject *ob, const char *section_name="global") { struct param_opt *opt = param_get_add($self, parameter, section_name); @@ -190,6 +191,11 @@ typedef struct param_context { return 0; } + +#endif + + struct param_section *first_section() { return $self->sections; } + struct param_section *next_section(struct param_section *s) { return s->next; } int read(const char *fn); int write(const char *fn); @@ -200,12 +206,38 @@ typedef struct param_context { if ret is None: raise KeyError("No such section %s" % name) return ret + + class SectionIterator: + def __init__(self, param): + self.param = param + self.key = None + + def __iter__(self): + return self + + def next(self): + if self.key is None: + self.key = self.param.first_section() + if self.key is None: + raise StopIteration + return self.key + else: + self.key = self.param.next_section(self.key) + if self.key is None: + raise StopIteration + return self.key + + def __iter__(self): + return self.SectionIterator(self) } } param; %talloctype(param_opt); typedef struct param_opt { + %immutable key; + %immutable value; + const char *key, *value; %extend { #ifdef SWIGPYTHON const char *__str__() { return $self->value; } @@ -215,8 +247,12 @@ typedef struct param_opt { %talloctype(param); typedef struct param_section { + %immutable name; + const char *name; %extend { struct param_opt *get(const char *name); + struct param_opt *first_parameter() { return $self->parameters; } + struct param_opt *next_parameter(struct param_opt *s) { return s->next; } } %pythoncode { def __getitem__(self, name): @@ -224,6 +260,29 @@ typedef struct param_section { if ret is None: raise KeyError("No such option %s" % name) return ret + + class ParamIterator: + def __init__(self, section): + self.section = section + self.key = None + + def __iter__(self): + return self + + def next(self): + if self.key is None: + self.key = self.section.first_parameter() + if self.key is None: + raise StopIteration + return self.key + else: + self.key = self.section.next_parameter(self.key) + if self.key is None: + raise StopIteration + return self.key + + def __iter__(self): + return self.ParamIterator(self) } } param_section; diff --git a/source4/param/param.py b/source4/param/param.py index 291459b9b6..66b51e5d3b 100644 --- a/source4/param/param.py +++ b/source4/param/param.py @@ -96,6 +96,29 @@ class ParamFile(object): raise KeyError("No such section %s" % name) return ret + class SectionIterator: + def __init__(self, param): + self.param = param + self.key = None + + def __iter__(self): + return self + + def next(self): + if self.key is None: + self.key = self.param.first_section() + if self.key is None: + raise StopIteration + return self.key + else: + self.key = self.param.next_section(self.key) + if self.key is None: + raise StopIteration + return self.key + + def __iter__(self): + return self.SectionIterator(self) + __swig_destroy__ = _param.delete_ParamFile ParamFile.get_section = new_instancemethod(_param.ParamFile_get_section,None,ParamFile) ParamFile.add_section = new_instancemethod(_param.ParamFile_add_section,None,ParamFile) @@ -103,6 +126,8 @@ ParamFile.get = new_instancemethod(_param.ParamFile_get,None,ParamFile) ParamFile.get_string = new_instancemethod(_param.ParamFile_get_string,None,ParamFile) ParamFile.set_string = new_instancemethod(_param.ParamFile_set_string,None,ParamFile) ParamFile.set = new_instancemethod(_param.ParamFile_set,None,ParamFile) +ParamFile.first_section = new_instancemethod(_param.ParamFile_first_section,None,ParamFile) +ParamFile.next_section = new_instancemethod(_param.ParamFile_next_section,None,ParamFile) ParamFile.read = new_instancemethod(_param.ParamFile_read,None,ParamFile) ParamFile.write = new_instancemethod(_param.ParamFile_write,None,ParamFile) ParamFile_swigregister = _param.ParamFile_swigregister @@ -112,6 +137,8 @@ class param_opt(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self): raise AttributeError, "No constructor defined" __repr__ = _swig_repr + key = _swig_property(_param.param_opt_key_get) + value = _swig_property(_param.param_opt_value_get) __swig_destroy__ = _param.delete_param_opt param_opt.__str__ = new_instancemethod(_param.param_opt___str__,None,param_opt) param_opt_swigregister = _param.param_opt_swigregister @@ -120,16 +147,42 @@ param_opt_swigregister(param_opt) class param_section(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr + name = _swig_property(_param.param_section_name_get) def __getitem__(self, name): ret = self.get(name) if ret is None: raise KeyError("No such option %s" % name) return ret + class ParamIterator: + def __init__(self, section): + self.section = section + self.key = None + + def __iter__(self): + return self + + def next(self): + if self.key is None: + self.key = self.section.first_parameter() + if self.key is None: + raise StopIteration + return self.key + else: + self.key = self.section.next_parameter(self.key) + if self.key is None: + raise StopIteration + return self.key + + def __iter__(self): + return self.ParamIterator(self) + def __init__(self, *args, **kwargs): _param.param_section_swiginit(self,_param.new_param_section(*args, **kwargs)) __swig_destroy__ = _param.delete_param_section param_section.get = new_instancemethod(_param.param_section_get,None,param_section) +param_section.first_parameter = new_instancemethod(_param.param_section_first_parameter,None,param_section) +param_section.next_parameter = new_instancemethod(_param.param_section_next_parameter,None,param_section) param_section_swigregister = _param.param_section_swigregister param_section_swigregister(param_section) diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c index 49c986aeb7..5f7ff880ff 100644 --- a/source4/param/param_wrap.c +++ b/source4/param/param_wrap.c @@ -2751,9 +2751,13 @@ SWIGINTERN int param_set(param *self,char const *parameter,PyObject *ob,char con return 0; } +SWIGINTERN struct param_section *param_first_section(param *self){ return self->sections; } +SWIGINTERN struct param_section *param_next_section(param *self,struct param_section *s){ return s->next; } SWIGINTERN void delete_param(param *self){ talloc_free(self); } SWIGINTERN char const *param_opt___str__(param_opt *self){ return self->value; } SWIGINTERN void delete_param_opt(param_opt *self){ talloc_free(self); } +SWIGINTERN struct param_opt *param_section_first_parameter(param_section *self){ return self->parameters; } +SWIGINTERN struct param_opt *param_section_next_parameter(param_section *self,struct param_opt *s){ return s->next; } #ifdef __cplusplus extern "C" { #endif @@ -3570,6 +3574,63 @@ fail: } +SWIGINTERN PyObject *_wrap_ParamFile_first_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + struct param_section *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_first_section" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + result = (struct param_section *)param_first_section(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_ParamFile_next_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + struct param_section *arg2 = (struct param_section *) 0 ; + struct param_section *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "s", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_next_section",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_next_section" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_section, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_next_section" "', argument " "2"" of type '" "struct param_section *""'"); + } + arg2 = (struct param_section *)(argp2); + result = (struct param_section *)param_next_section(arg1,arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param *arg1 = (param *) 0 ; @@ -3678,6 +3739,52 @@ SWIGINTERN PyObject *ParamFile_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject return SWIG_Python_InitShadowInstance(args); } +SWIGINTERN PyObject *_wrap_param_opt_key_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_opt_key_get" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + result = (char *) ((arg1)->key); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_param_opt_value_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_opt_value_get" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + result = (char *) ((arg1)->value); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_param_opt___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; param_opt *arg1 = (param_opt *) 0 ; @@ -3731,6 +3838,29 @@ SWIGINTERN PyObject *param_opt_swigregister(PyObject *SWIGUNUSEDPARM(self), PyOb return SWIG_Py_Void(); } +SWIGINTERN PyObject *_wrap_param_section_name_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_section *arg1 = (param_section *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_section, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_section_name_get" "', argument " "1"" of type '" "param_section *""'"); + } + arg1 = (param_section *)(argp1); + result = (char *) ((arg1)->name); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_param_section_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param_section *arg1 = (param_section *) 0 ; @@ -3768,6 +3898,63 @@ fail: } +SWIGINTERN PyObject *_wrap_param_section_first_parameter(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_section *arg1 = (param_section *) 0 ; + struct param_opt *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_section, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_section_first_parameter" "', argument " "1"" of type '" "param_section *""'"); + } + arg1 = (param_section *)(argp1); + result = (struct param_opt *)param_section_first_parameter(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_param_section_next_parameter(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param_section *arg1 = (param_section *) 0 ; + struct param_opt *arg2 = (struct param_opt *) 0 ; + struct param_opt *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "s", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:param_section_next_parameter",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_section, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_section_next_parameter" "', argument " "1"" of type '" "param_section *""'"); + } + arg1 = (param_section *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_opt, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "param_section_next_parameter" "', argument " "2"" of type '" "struct param_opt *""'"); + } + arg2 = (struct param_opt *)(argp2); + result = (struct param_opt *)param_section_next_parameter(arg1,arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_new_param_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; param_section *result = 0 ; @@ -3863,15 +4050,22 @@ static PyMethodDef SwigMethods[] = { { (char *)"ParamFile_get_string", (PyCFunction) _wrap_ParamFile_get_string, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_set_string", (PyCFunction) _wrap_ParamFile_set_string, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_set", (PyCFunction) _wrap_ParamFile_set, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_first_section", (PyCFunction)_wrap_ParamFile_first_section, METH_O, NULL}, + { (char *)"ParamFile_next_section", (PyCFunction) _wrap_ParamFile_next_section, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_write", (PyCFunction) _wrap_ParamFile_write, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_ParamFile", (PyCFunction)_wrap_delete_ParamFile, METH_O, NULL}, { (char *)"ParamFile_swigregister", ParamFile_swigregister, METH_VARARGS, NULL}, { (char *)"ParamFile_swiginit", ParamFile_swiginit, METH_VARARGS, NULL}, + { (char *)"param_opt_key_get", (PyCFunction)_wrap_param_opt_key_get, METH_O, NULL}, + { (char *)"param_opt_value_get", (PyCFunction)_wrap_param_opt_value_get, METH_O, NULL}, { (char *)"param_opt___str__", (PyCFunction)_wrap_param_opt___str__, METH_O, NULL}, { (char *)"delete_param_opt", (PyCFunction)_wrap_delete_param_opt, METH_O, NULL}, { (char *)"param_opt_swigregister", param_opt_swigregister, METH_VARARGS, NULL}, + { (char *)"param_section_name_get", (PyCFunction)_wrap_param_section_name_get, METH_O, NULL}, { (char *)"param_section_get", (PyCFunction) _wrap_param_section_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"param_section_first_parameter", (PyCFunction)_wrap_param_section_first_parameter, METH_O, NULL}, + { (char *)"param_section_next_parameter", (PyCFunction) _wrap_param_section_next_parameter, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_param_section", (PyCFunction)_wrap_new_param_section, METH_NOARGS, NULL}, { (char *)"delete_param_section", (PyCFunction)_wrap_delete_param_section, METH_O, NULL}, { (char *)"param_section_swigregister", param_section_swigregister, METH_VARARGS, NULL}, diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 0aa54d91cc..157a708ff6 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -1,8 +1,8 @@ #!/usr/bin/python # -# Dump Samba3 data -# Copyright Jelmer Vernooij 2005-2007 -# Released under the GNU GPL v3 or later +# Dump Samba3 data +# Copyright Jelmer Vernooij 2005-2007 +# Released under the GNU GPL v3 or later # import optparse @@ -13,160 +13,154 @@ import samba.samba3 parser = optparse.OptionParser("provision <libdir> [<smb.conf>]") parser.add_option("--format", type="choice", metavar="FORMAT", - choices=["full", "summary"]) + choices=["full", "summary"]) opts, args = parser.parse_args() if opts.format is None: - opts.format = "summary" + opts.format = "summary" def print_header(txt): - print "\n%s" % txt - print "==========================================" + print "\n%s" % txt + print "=" * len(txt) def print_samba3_policy(pol): - print_header("Account Policies") - print "Min password length: %d" % pol.min_password_length - print "Password history length: %d" % pol.password_history - if pol.user_must_logon_to_change_password: - print "User must logon to change password: %d" % pol.user_must_logon_to_change_password - if pol.maximum_password_age: - print "Maximum password age: %d" % pol.maximum_password_age - if pol.minimum_password_age: - print "Minimum password age: %d" % pol.minimum_password_age - if pol.lockout_duration: - print "Lockout duration: %d" % pol.lockout_duration - if pol.reset_count_minutes: - print "Reset Count Minutes: %d" % pol.reset_count_minutes - if pol.bad_lockout_minutes: - print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes - if pol.disconnect_time: - print "Disconnect Time: %d" % pol.disconnect_time - if pol.refuse_machine_password_change: - print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change - -def print_samba3_sam(samba3): - print_header("SAM Database") - - for a in samba3.samaccounts: - print "%d: %s" % a.user_rid, a.username - -def print_samba3_shares(samba3): - print_header("Configured shares") - for s in samba3.shares: - print "--- %s ---" % s.name - - for p in s.parameters: - print "\t%s = %s" % (p.name, p.value) - - print "" + print_header("Account Policies") + print "Min password length: %d" % pol.min_password_length + print "Password history length: %d" % pol.password_history + if pol.user_must_logon_to_change_password: + print "User must logon to change password: %d" % pol.user_must_logon_to_change_password + if pol.maximum_password_age: + print "Maximum password age: %d" % pol.maximum_password_age + if pol.minimum_password_age: + print "Minimum password age: %d" % pol.minimum_password_age + if pol.lockout_duration: + print "Lockout duration: %d" % pol.lockout_duration + if pol.reset_count_minutes: + print "Reset Count Minutes: %d" % pol.reset_count_minutes + if pol.bad_lockout_minutes: + print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes + if pol.disconnect_time: + print "Disconnect Time: %d" % pol.disconnect_time + if pol.refuse_machine_password_change: + print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change + +def print_samba3_sam(samdb): + print_header("SAM Database") + + for user in samdb: + print "%s" % user + +def print_samba3_shares(shares): + print_header("Configured shares") + for s in shares: + print "--- %s ---" % s.name + + for p in s: + print "\t%s = %s" % (p.key, p.value) + + print "" def print_samba3_secrets(secrets): - print_header("Secrets") - - if secrets.get_auth_user(): - print "IPC Credentials:" - if secrets.get_auth_user(): - print " User: %s\n" % secrets.get_auth_user() - if secrets.get_auth_password(): - print " Password: %s\n" % secrets.get_auth_password() - if secrets.get_auth_domain(): - print " Domain: %s\n" % secrets.get_auth_domain() - - if len(list(secrets.ldap_dns())) > 0: - print "LDAP passwords:" - for dn in secrets.ldap_dns(): - print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)) - print "" - - print "Domains:" - for domain in secrets.domains(): - print "\t--- %s ---" % domain - print "\tSID: %s" % secrets.get_sid(domain) - print "\tGUID: %s" % secrets.get_dom_guid(domain) - print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) - if secrets.get_machine_last_change_time(domain): - print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) - if secrets.get_machine_sec_channel_type(domain): - print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain) - - print "Trusted domains:" - for td in secrets.trusted_domains(): - print td + print_header("Secrets") + + if secrets.get_auth_user(): + print "IPC Credentials:" + if secrets.get_auth_user(): + print " User: %s\n" % secrets.get_auth_user() + if secrets.get_auth_password(): + print " Password: %s\n" % secrets.get_auth_password() + if secrets.get_auth_domain(): + print " Domain: %s\n" % secrets.get_auth_domain() + + if len(list(secrets.ldap_dns())) > 0: + print "LDAP passwords:" + for dn in secrets.ldap_dns(): + print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)) + print "" + + print "Domains:" + for domain in secrets.domains(): + print "\t--- %s ---" % domain + print "\tSID: %s" % secrets.get_sid(domain) + print "\tGUID: %s" % secrets.get_dom_guid(domain) + print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) + if secrets.get_machine_last_change_time(domain): + print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) + if secrets.get_machine_sec_channel_type(domain): + print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain) + + print "Trusted domains:" + for td in secrets.trusted_domains(): + print td def print_samba3_regdb(regdb): - print_header("Registry") + print_header("Registry") - for k in regdb.keys(): - print "%s" % k - for v in regdb.values(k): - print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) + for k in regdb.keys(): + print "%s" % k + for v in regdb.values(k): + print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) def print_samba3_winsdb(winsdb): - print_header("WINS Database") + print_header("WINS Database") - for name in winsdb: - (ttl, ips, nb_flags) = winsdb[name] - print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]) + for name in winsdb: + (ttl, ips, nb_flags) = winsdb[name] + print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]) def print_samba3_groupmappings(groupdb): - print_header("Group Mappings") - - for sid in groupdb.groupsids(): - print "\t--- Group: %s ---" % g.nt_name - print "\tComment: %s" % g.comment - print "\tGID: %d" % g.gid - print "\tSID Name Use: %d" % g.sid_name_use - print "\tSID: %s\n" % g.sid + print_header("Group Mappings") + + for sid in groupdb.groupsids(): + print "\t--- Group: %s ---" % sid def print_samba3_aliases(groupdb): - for a in groupdb.aliases: - print "\t--- Alias: %s ---" % a.sid - for m in a.members: - print "\t%s" % m + for sid in groupdb.aliases(): + print "\t--- Alias: %s ---" % sid def print_samba3_idmapdb(idmapdb): - print_header("Winbindd SID<->GID/UID mappings") + print_header("Winbindd SID<->GID/UID mappings") - print "User High Water Mark: %d" % idmapdb.user_hwm - print "Group High Water Mark: %d\n" % idmapdb.group_hwm + print "User High Water Mark: %d" % idmapdb.get_user_hwm() + print "Group High Water Mark: %d\n" % idmapdb.get_group_hwm() - for e in idmapdb.mappings: - if e.type == e.IDMAP_GROUP: - print "%s -> GID %d" % (e.sid, e.unix_id) - else: - print "%s -> UID %d" % (e.sid, e.unix_id) + for uid in idmapdb.uids(): + print "%s -> UID %d" % (idmapdb.get_user_sid(uid), uid) + + for gid in idmapdb.gids(): + print "%s -> GID %d" % (idmapdb.get_group_sid(gid), gid) def print_samba3(samba3): - print_samba3_policy(samba3.get_policy_db()) - print_samba3_winsdb(samba3.get_wins_db()) - print_samba3_regdb(samba3.get_registry()) - print_samba3_secrets(samba3.get_secrets_db()) - groupdb = samba3.get_groupmapping_db() - print_samba3_groupmappings(groupdb) - print_samba3_aliases(groupdb) - print_samba3_idmapdb(samba3.get_idmap_db()) - print_samba3_shares(samba3) - print_samba3_sam(samba3) + print_samba3_policy(samba3.get_policy_db()) + print_samba3_winsdb(samba3.get_wins_db()) + print_samba3_regdb(samba3.get_registry()) + print_samba3_secrets(samba3.get_secrets_db()) + print_samba3_idmapdb(samba3.get_idmap_db()) + print_samba3_sam(samba3.get_sam_db()) + groupdb = samba3.get_groupmapping_db() + print_samba3_groupmappings(groupdb) + print_samba3_aliases(groupdb) + print_samba3_shares(samba3.get_shares()) def print_samba3_summary(samba3): - print "WINS db entries: %d" % len(samba3.get_wins_db()) - print "Registry key count: %d" % len(samba3.get_registry()) - groupdb = samba3.get_groupmapping_db() - print "Groupmap count: %d" % len(list(groupdb.groupsids())) - print "Alias count: %d" % len(list(groupdb.aliases())) - idmapdb = samba3.get_idmap_db() - print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))) + print "WINS db entries: %d" % len(samba3.get_wins_db()) + print "Registry key count: %d" % len(samba3.get_registry()) + groupdb = samba3.get_groupmapping_db() + print "Groupmap count: %d" % len(list(groupdb.groupsids())) + print "Alias count: %d" % len(list(groupdb.aliases())) + idmapdb = samba3.get_idmap_db() + print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))) libdir = args[0] if len(args) > 1: - smbconf = args[2] + smbconf = args[2] else: - smbconf = os.path.join(libdir, "smb.conf") + smbconf = os.path.join(libdir, "smb.conf") samba3 = samba.samba3.Samba3(libdir, smbconf) if opts.format == "summary": - print_samba3_summary(samba3) + print_samba3_summary(samba3) elif opts.format == "full": - print_samba3(samba3) + print_samba3(samba3) diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py index 40443bd8ba..d125e3164b 100644 --- a/source4/scripting/python/samba/samba3.py +++ b/source4/scripting/python/samba/samba3.py @@ -222,7 +222,7 @@ SHARE_DATABASE_VERSION_V2 = 2 class ShareInfoDatabase: def __init__(self, file): self.tdb = tdb.Tdb(file, flags=os.O_RDONLY) - assert self.tdb.fetch_int32("INFO/version") in (SHARE_DATABASE_VERSION_V1, SHARE_DATABASE_VERSION_V2) + assert self.tdb.fetch_int32("INFO/version\0") in (SHARE_DATABASE_VERSION_V1, SHARE_DATABASE_VERSION_V2) def get_secdesc(self, name): secdesc = self.tdb.get("SECDESC/%s" % name) @@ -232,6 +232,19 @@ class ShareInfoDatabase: def close(self): self.tdb.close() + +class Shares: + def __init__(self, lp, shareinfo): + self.lp = lp + self.shareinfo = shareinfo + + def __len__(self): + return len(self.lp) - 1 + + def __iter__(self): + return self.lp.__iter__() + + ACB_DISABLED = 0x00000001 ACB_HOMDIRREQ = 0x00000002 ACB_PWNOTREQ = 0x00000004 @@ -323,7 +336,7 @@ class SmbpasswdFile: return self.users[name] def __iter__(self): - return iter(self.entries) + return iter(self.users) def close(self): # For consistency pass @@ -346,6 +359,8 @@ class TdbSam: if k.startswith(TDBSAM_USER_PREFIX): yield k[len(TDBSAM_USER_PREFIX):].rstrip("\0") + __iter__ = usernames + def close(self): self.tdb.close() @@ -409,24 +424,52 @@ class Samba3: def __init__(self, libdir, smbconfpath): self.smbconfpath = smbconfpath self.libdir = libdir + import param + self.lp = param.ParamFile() + self.lp.read(self.smbconfpath) + + def libdir_path(self, path): + if path[0] == "/" or path[0] == ".": + return path + return os.path.join(self.libdir, path) + + def get_conf(self): + return self.lp + + def get_sam_db(self): + lp = self.get_conf() + backends = str(lp.get("passdb backend")).split(" ") + if backends[0].startswith("smbpasswd"): + if ":" in backends[0]: + return SmbpasswdFile(self.libdir_path(backends[0][len("smbpasswd:"):])) + return SmbpasswdFile(self.libdir_path("smbpasswd")) + elif backends[0].startswith("tdbsam"): + if ":" in backends[0]: + return TdbSam(self.libdir_path(backends[0][len("tdbsam:"):])) + return TdbSam(self.libdir_path("passdb.tdb")) + else: + raise NotImplementedError("unsupported passdb backend %s" % backends[0]) def get_policy_db(self): - return PolicyDatabase(os.path.join(self.libdir, "account_policy.tdb")) + return PolicyDatabase(self.libdir_path("account_policy.tdb")) def get_registry(self): - return Registry(os.path.join(self.libdir, "registry.tdb")) + return Registry(self.libdir_path("registry.tdb")) def get_secrets_db(self): - return SecretsDatabase(os.path.join(self.libdir, "secrets.tdb")) + return SecretsDatabase(self.libdir_path("secrets.tdb")) - def get_shares_db(self): - return ShareInfoDatabase(os.path.join(self.libdir, "share_info.tdb")) + def get_shareinfo_db(self): + return ShareInfoDatabase(self.libdir_path("share_info.tdb")) def get_idmap_db(self): - return IdmapDatabase(os.path.join(self.libdir, "winbindd_idmap.tdb")) + return IdmapDatabase(self.libdir_path("winbindd_idmap.tdb")) def get_wins_db(self): - return WinsDatabase(os.path.join(self.libdir, "wins.dat")) + return WinsDatabase(self.libdir_path("wins.dat")) + + def get_shares(self): + return Shares(self.get_conf(), self.get_shareinfo_db()) def get_groupmapping_db(self): - return GroupMappingDatabase(os.path.join(self.libdir, "group_mapping.tdb")) + return GroupMappingDatabase(self.libdir_path("group_mapping.tdb")) |