[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Fri Apr 9 03:53:26 MDT 2010


The branch, master has been updated
       via  0d92dd1... s4-net: Cope with options without arguments.
       via  410527f... s4-net: 'net user create' -> 'net user add', for backwards compatibility.
       via  ececb73... Support --version in python scripts.
       via  9af8d02... s4-net: Convert machinepw command to python.
       via  f83aa13... s4-net: Convert vampire command over to Python.
       via  ffa73c4... s4-net: Convert user subcommand to Python.
      from  8149094... s4/dsdb: Set schemaInfo attribute value during provisioning

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 0d92dd1074971a3c1e3116de5188a475298587a2
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Apr 9 02:37:20 2010 +0200

    s4-net: Cope with options without arguments.

commit 410527f9369c44a25a5689b4665f3485c16d625a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Apr 9 02:31:57 2010 +0200

    s4-net: 'net user create' -> 'net user add', for backwards compatibility.

commit ececb7326200d6c59fa15f7542421099d3899297
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Apr 9 02:30:48 2010 +0200

    Support --version in python scripts.

commit 9af8d02b2230f78e4842106b918ff278dadd1d59
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Thu Apr 8 23:58:15 2010 +0200

    s4-net: Convert machinepw command to python.

commit f83aa13f6228e04359952f04ebd7afed9a742c4a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Thu Apr 8 23:53:19 2010 +0200

    s4-net: Convert vampire command over to Python.

commit ffa73c412e1190024ae0bf4758174d1b21c16e13
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon Mar 1 23:03:41 2010 +0100

    s4-net: Convert user subcommand to Python.

-----------------------------------------------------------------------

Summary of changes:
 source4/libnet/py_net.c                            |  126 ++++++++++++++++++++
 source4/scripting/python/samba/getopt.py           |    8 ++
 source4/scripting/python/samba/netcmd/__init__.py  |    9 ++-
 source4/scripting/python/samba/netcmd/join.py      |   59 +++++++++
 source4/scripting/python/samba/netcmd/machinepw.py |   53 ++++++++
 source4/scripting/python/samba/netcmd/user.py      |   74 ++++++++++++
 source4/scripting/python/samba/netcmd/vampire.py   |   52 ++++++++
 source4/utils/net/config.mk                        |    3 +-
 source4/utils/net/net.c                            |    3 -
 source4/utils/net/net_machinepw.c                  |   91 --------------
 source4/utils/net/net_user.c                       |  125 -------------------
 source4/utils/net/net_vampire.c                    |   67 -----------
 source4/utils/net/wscript_build                    |    2 +-
 13 files changed, 382 insertions(+), 290 deletions(-)
 create mode 100644 source4/scripting/python/samba/netcmd/join.py
 create mode 100644 source4/scripting/python/samba/netcmd/machinepw.py
 create mode 100644 source4/scripting/python/samba/netcmd/user.py
 create mode 100644 source4/scripting/python/samba/netcmd/vampire.py
 delete mode 100644 source4/utils/net/net_machinepw.c
 delete mode 100644 source4/utils/net/net_user.c


Changeset truncated at 500 lines:

diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index d6bd134..f2fc771 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -183,11 +183,137 @@ static PyObject *py_net_time(py_net_Object *self, PyObject *args, PyObject *kwar
 static const char py_net_time_doc[] = "time(server_name) -> timestr\n"
 "Retrieve the remote time on a server";
 
+static PyObject *py_net_user_create(py_net_Object *self, PyObject *args, PyObject *kwargs)
+{
+	const char *kwnames[] = { "username", NULL };
+	NTSTATUS status;
+	TALLOC_CTX *mem_ctx;
+	struct libnet_CreateUser r;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", discard_const_p(char *, kwnames), 
+									 &r.in.user_name))
+		return NULL;
+
+	r.in.domain_name = cli_credentials_get_domain(self->libnet_ctx->cred);
+
+	mem_ctx = talloc_new(NULL);
+	if (mem_ctx == NULL) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+
+	status = libnet_CreateUser(self->libnet_ctx, mem_ctx, &r);
+	if (!NT_STATUS_IS_OK(status)) {
+		PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+		talloc_free(mem_ctx);
+		return NULL;
+	}
+
+	talloc_free(mem_ctx);
+	
+	Py_RETURN_NONE;
+}
+
+static const char py_net_create_user_doc[] = "create_user(username)\n"
+"Create a new user.";
+
+static PyObject *py_net_user_delete(py_net_Object *self, PyObject *args, PyObject *kwargs)
+{
+	const char *kwnames[] = { "username", NULL };
+	NTSTATUS status;
+	TALLOC_CTX *mem_ctx;
+	struct libnet_DeleteUser r;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", discard_const_p(char *, kwnames), 
+									 &r.in.user_name))
+		return NULL;
+
+	r.in.domain_name = cli_credentials_get_domain(self->libnet_ctx->cred);
+
+	mem_ctx = talloc_new(NULL);
+	if (mem_ctx == NULL) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+
+	status = libnet_DeleteUser(self->libnet_ctx, mem_ctx, &r);
+	if (!NT_STATUS_IS_OK(status)) {
+		PyErr_SetString(PyExc_RuntimeError, r.out.error_string);
+		talloc_free(mem_ctx);
+		return NULL;
+	}
+
+	talloc_free(mem_ctx);
+	
+	Py_RETURN_NONE;
+}
+
+static const char py_net_delete_user_doc[] = "delete_user(username)\n"
+"Delete a user.";
+
+static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
+{
+	PyObject *mod_security, *dom_sid_Type;
+
+	mod_security = PyImport_ImportModule("samba.dcerpc.security");
+	if (mod_security == NULL)
+		return NULL;
+
+	dom_sid_Type = PyObject_GetAttrString(mod_security, "dom_sid");
+	if (dom_sid_Type == NULL)
+		return NULL;
+
+	return py_talloc_reference((PyTypeObject *)dom_sid_Type, sid);
+}
+
+static PyObject *py_net_vampire(py_net_Object *self, PyObject *args, PyObject *kwargs)
+{
+	const char *kwnames[] = { "domain", "target_dir", NULL };
+	NTSTATUS status;
+	TALLOC_CTX *mem_ctx;
+    PyObject *ret;
+	struct libnet_Vampire r;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s", discard_const_p(char *, kwnames), 
+									 &r.in.domain_name, &r.in.targetdir))
+		return NULL;
+
+	r.in.netbios_name  = lp_netbios_name(self->libnet_ctx->lp_ctx);
+	r.out.error_string = NULL;
+
+    mem_ctx = talloc_new(NULL);
+    if (mem_ctx == NULL) {
+        PyErr_NoMemory();
+        return NULL;
+    }
+
+	status = libnet_Vampire(self->libnet_ctx, mem_ctx, &r);
+
+	if (!NT_STATUS_IS_OK(status)) {
+        PyErr_SetString(PyExc_RuntimeError, 
+            r.out.error_string ? r.out.error_string : nt_errstr(status));
+        talloc_free(mem_ctx);
+		return NULL;
+	}
+
+    ret = Py_BuildValue("(sO)", r.out.domain_name, py_dom_sid_FromSid(r.out.domain_sid));
+
+    talloc_free(mem_ctx);
+
+    return ret;
+}
+
+static const char py_net_vampire_doc[] = "vampire(domain, target_dir=None)\n"
+"Vampire a domain.";
+
 static PyMethodDef net_obj_methods[] = {
 	{"join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS, py_net_join_doc},
 	{"set_password", (PyCFunction)py_net_set_password, METH_VARARGS|METH_KEYWORDS, py_net_set_password_doc},
 	{"export_keytab", (PyCFunction)py_net_export_keytab, METH_VARARGS|METH_KEYWORDS, py_net_export_keytab_doc},
 	{"time", (PyCFunction)py_net_time, METH_VARARGS|METH_KEYWORDS, py_net_time_doc},
+	{"create_user", (PyCFunction)py_net_user_create, METH_VARARGS|METH_KEYWORDS, py_net_create_user_doc},
+	{"delete_user", (PyCFunction)py_net_user_delete, METH_VARARGS|METH_KEYWORDS, py_net_delete_user_doc},
+    {"vampire", (PyCFunction)py_net_vampire, METH_VARARGS|METH_KEYWORDS, py_net_vampire_doc},
 	{ NULL }
 };
 
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 1fbfd9c..6ec7def 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -71,6 +71,14 @@ class VersionOptions(optparse.OptionGroup):
     """Command line option for printing Samba version."""
     def __init__(self, parser):
         optparse.OptionGroup.__init__(self, parser, "Version Options")
+        self.add_option("--version", action="callback",
+                callback=self._display_version, 
+                help="Display version number")
+
+    def _display_version(self, option, opt_str, arg, parser):
+        import samba, sys
+        print samba.version
+        sys.exit(0)
 
 
 class CredentialsOptions(optparse.OptionGroup):
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index f9c6445..3dcf019 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -79,7 +79,8 @@ class Command(object):
         kwargs = dict(opts.__dict__)
         for option_group in parser.option_groups:
             for option in option_group.option_list:
-                del kwargs[option.dest]
+                if option.dest is not None:
+                    del kwargs[option.dest]
         kwargs.update(optiongroups)
         min_args = 0
         max_args = 0
@@ -151,3 +152,9 @@ from samba.netcmd.export import cmd_export
 commands["export"] = cmd_export()
 from samba.netcmd.time import cmd_time
 commands["time"] = cmd_time()
+from samba.netcmd.user import cmd_user
+commands["user"] = cmd_user()
+from samba.netcmd.vampire import cmd_vampire
+commands["vampire"] = cmd_vampire()
+from samba.netcmd.machinepw import cmd_machinepw
+commands["machinepw"] = cmd_machinepw()
diff --git a/source4/scripting/python/samba/netcmd/join.py b/source4/scripting/python/samba/netcmd/join.py
new file mode 100644
index 0000000..981161d
--- /dev/null
+++ b/source4/scripting/python/samba/netcmd/join.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+#
+# joins
+# 
+# Copyright Jelmer Vernooij 2010
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import samba.getopt as options
+
+from samba.net import Net, LIBNET_JOIN_AUTOMATIC
+from samba.netcmd import Command, CommandError
+from samba.dcerpc.netr import SEC_CHAN_WKSTA, SEC_CHAN_BDC
+
+
+class cmd_join(Command):
+    """Joins domain as either member or backup domain controller."""
+
+    synopsis = "%prog join <domain> [BDC | MEMBER] [options]"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "versionopts": options.VersionOptions,
+        "credopts": options.CredentialsOptions,
+    }
+
+    takes_args = ["domain", "role?"]
+
+    def run(self, domain, role=None, sambaopts=None, credopts=None,
+            versionopts=None):
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp)
+        net = Net(creds, lp)
+        
+        if role is None:
+            secure_channel_type = SEC_CHAN_WKSTA
+        elif role == "BDC":
+            secure_channel_type = SEC_CHAN_BDC
+        elif role == "MEMBER":
+            secure_channel_type = SEC_CHAN_WKSTA
+        else:
+            raise CommandError("Invalid role %s (possible values: MEMBER, BDC)" % role)
+
+        (join_password, sid, domain_name) = net.join(domain,
+            lp.get("netbios name"), SEC_CHAN_WKSTA, LIBNET_JOIN_AUTOMATIC)
+
+        self.outf.write("Joined domain %s (%s)\n" % (domain_name, sid))
diff --git a/source4/scripting/python/samba/netcmd/machinepw.py b/source4/scripting/python/samba/netcmd/machinepw.py
new file mode 100644
index 0000000..8788e06
--- /dev/null
+++ b/source4/scripting/python/samba/netcmd/machinepw.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+#
+# Machine passwords
+# Copyright Jelmer Vernooij 2010
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import samba.getopt as options
+
+from samba import Ldb
+from samba.auth import system_session
+from samba.netcmd import Command, CommandError
+
+
+class cmd_machinepw(Command):
+    """Get a machine password out of our SAM."""
+
+    synopsis = "%prog machinepw <accountname>"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "versionopts": options.VersionOptions,
+        "credopts": options.CredentialsOptions,
+    }
+
+    takes_args = ["secret"]
+
+    def run(self, secret, sambaopts=None, credopts=None, versionopts=None):
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp)
+        url = lp.get("secrets database")
+        secretsdb = Ldb(url=url, session_info=system_session(),
+            credentials=creds, lp=lp)
+        
+        result = secretsdb.search(attrs=["secret"], 
+            expression="(&(objectclass=primaryDomain)(samaccountname=%s))" % secret)
+
+        if len(result) != 1:
+            raise CommandError("search returned %d records, expected 1" % len(result))
+
+        self.outf.write("%s\n" % result[0]["secret"])
diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py
new file mode 100644
index 0000000..7597f46
--- /dev/null
+++ b/source4/scripting/python/samba/netcmd/user.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+#
+# user management
+#
+# Copyright Jelmer Vernooij 2010 <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import samba.getopt as options
+
+from samba.net import Net
+
+from samba.netcmd import (
+    Command,
+    SuperCommand,
+    )
+
+class cmd_user_add(Command):
+    """Create a new user."""
+    synopsis = "%prog user add <name>"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "credopts": options.CredentialsOptions,
+        "versionopts": options.VersionOptions,
+        }
+
+    takes_args = ["name"]
+
+    def run(self, name, credopts=None, sambaopts=None, versionopts=None):
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp)
+        net = Net(creds, lp)
+        net.create_user(name)
+
+
+class cmd_user_delete(Command):
+    """Delete a user."""
+    synopsis = "%prog user delete <name>"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "credopts": options.CredentialsOptions,
+        "versionopts": options.VersionOptions,
+        }
+
+    takes_args = ["name"]
+
+    def run(self, name, credopts=None, sambaopts=None, versionopts=None):
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp)
+        net = Net(creds, lp)
+        net.delete_user(name)
+
+
+class cmd_user(SuperCommand):
+    """User management."""
+
+    subcommands = {}
+    subcommands["add"] = cmd_user_add()
+    subcommands["delete"] = cmd_user_delete()
+
diff --git a/source4/scripting/python/samba/netcmd/vampire.py b/source4/scripting/python/samba/netcmd/vampire.py
new file mode 100644
index 0000000..fcf9694
--- /dev/null
+++ b/source4/scripting/python/samba/netcmd/vampire.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+#
+# Vampire
+#
+# Copyright Jelmer Vernooij 2010 <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import samba.getopt as options
+
+from samba.net import Net
+
+from samba.netcmd import (
+    Command,
+    Option,
+    SuperCommand,
+    )
+
+class cmd_vampire(Command):
+    """Join and synchronise a remote AD domain to the local server."""
+    synopsis = "%prog vampire [options] <domain>"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "credopts": options.CredentialsOptions,
+        "versionopts": options.VersionOptions,
+        }
+
+    takes_options = [
+        Option("--target-dir", help="Target directory.", type=str),
+        ]
+
+    takes_args = ["domain"]
+
+    def run(self, domain, target_dir=None, credopts=None, sambaopts=None, versionopts=None):
+        lp = sambaopts.get_loadparm()
+        creds = credopts.get_credentials(lp)
+        net = Net(creds, lp)
+        (domain_name, domain_sid) = net.vampire(domain=domain, target_dir=target_dir)
+        self.outf.write("Vampired domain %s (%s)\n" % (domain_name, domain_sid))
diff --git a/source4/utils/net/config.mk b/source4/utils/net/config.mk
index 496d339..5b94140 100644
--- a/source4/utils/net/config.mk
+++ b/source4/utils/net/config.mk
@@ -42,8 +42,7 @@ net_OBJ_FILES = $(addprefix $(utilssrcdir)/net/,  \
 		net_machinepw.o \
 		net_password.o \
 		net_join.o \
-		net_vampire.o \
-		net_user.o)
+		net_vampire.o)
 
 
 $(eval $(call proto_header_template,$(utilssrcdir)/net/net_proto.h,$(net_OBJ_FILES:.o=.c)))
diff --git a/source4/utils/net/net.c b/source4/utils/net/net.c
index 1eafe4d..56f7c77 100644
--- a/source4/utils/net/net.c
+++ b/source4/utils/net/net.c
@@ -199,10 +199,7 @@ static const struct net_functable net_functable[] = {
 	{"password", "change password\n", net_password, net_password_usage},
 	{"join", "join a domain\n", net_join, net_join_usage},
 	{"samdump", "dump the sam of a domain\n", net_samdump, net_samdump_usage},
-	{"vampire", "join and syncronise an AD domain onto the local server\n", net_vampire, net_vampire_usage},
 	{"samsync", "synchronise into the local ldb the sam of an NT4 domain\n", net_samsync_ldb, net_samsync_ldb_usage},
-	{"user", "manage user accounts\n", net_user, net_user_usage},
-	{"machinepw", "Get a machine password out of our SAM\n", net_machinepw, net_machinepw_usage},
 	{"drs", "Implements functionality offered by repadmin.exe utility in Windows\n", net_drs, net_drs_usage},
 	{NULL, NULL, NULL, NULL}
 };
diff --git a/source4/utils/net/net_machinepw.c b/source4/utils/net/net_machinepw.c
deleted file mode 100644
index 390eb8d..0000000
--- a/source4/utils/net/net_machinepw.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
-   Samba Unix/Linux SMB client library
-   Distributed SMB/CIFS Server Management Utility
-
-   Copyright (C) 2008 Volker Lendecke
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.


-- 
Samba Shared Repository


More information about the samba-cvs mailing list