From ffa73c412e1190024ae0bf4758174d1b21c16e13 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 Mar 2010 23:03:41 +0100 Subject: s4-net: Convert user subcommand to Python. --- source4/scripting/python/samba/netcmd/__init__.py | 2 + source4/scripting/python/samba/netcmd/user.py | 74 +++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 source4/scripting/python/samba/netcmd/user.py (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index f9c644582c..d4e21c1b4e 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -151,3 +151,5 @@ 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() diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py new file mode 100644 index 0000000000..319e8b0215 --- /dev/null +++ b/source4/scripting/python/samba/netcmd/user.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# +# user management +# +# 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 . +# + +import samba.getopt as options + +from samba.net import Net + +from samba.netcmd import ( + Command, + SuperCommand, + ) + +class cmd_user_create(Command): + """Create a new user.""" + synopsis = "%prog user create " + + 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 " + + 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["create"] = cmd_user_create() + subcommands["delete"] = cmd_user_delete() + -- cgit