net: Convert time command to python.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 1 Mar 2010 21:33:01 +0000 (22:33 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 21:22:55 +0000 (23:22 +0200)
source4/libnet/py_net.c
source4/scripting/python/samba/netcmd/export.py
source4/utils/net/config.mk
source4/utils/net/net_time.c [deleted file]

index 569f3955bb68e182c1fbb795614d5443d5edd200..d6bd134fe5b85555bf21c9e41787b1e1acae80e2 100644 (file)
@@ -106,26 +106,20 @@ static PyObject *py_net_set_password(py_net_Object *self, PyObject *args, PyObje
 static const char py_net_set_password_doc[] = "set_password(account_name, domain_name, newpassword) -> True\n\n" \
 "Set password for a user. You must supply credential with enough rights to do this.\n\n" \
 "Sample usage is:\n" \
-"creds = samba.credentials.Credentials()\n" \
-"creds.set_username('admin_user')\n" \
-"creds.set_domain('domain_name')\n" \
-"creds.set_password('pass')\n\n" \
 "net.set_password(account_name=<account_name>,\n" \
-"                domain_name=creds.get_domain(),\n" \
-"                newpassword=new_pass,\n" \
-"                credentials=creds)\n";
+"                domain_name=domain_name,\n" \
+"                newpassword=new_pass)\n";
 
 
 static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObject *kwargs)
 {
        struct libnet_export_keytab r;
        TALLOC_CTX *mem_ctx;
-       const char *kwnames[] = { "keytab", "creds", NULL };
-       PyObject *py_creds;
+       const char *kwnames[] = { "keytab", NULL };
        NTSTATUS status;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:export_keytab", discard_const_p(char *, kwnames),
-                                        &r.in.keytab_name, &py_creds)) {
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:export_keytab", discard_const_p(char *, kwnames),
+                                        &r.in.keytab_name)) {
                return NULL;
        }
 
@@ -146,10 +140,54 @@ static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObj
 static const char py_net_export_keytab_doc[] = "export_keytab(keytab, name)\n\n"
 "Export the DC keytab to a keytab file.";
 
+static PyObject *py_net_time(py_net_Object *self, PyObject *args, PyObject *kwargs)
+{
+       const char *kwnames[] = { "server_name", NULL };
+       union libnet_RemoteTOD r;
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx;
+       char timestr[64];
+       PyObject *ret;
+       struct tm *tm;
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s",
+               discard_const_p(char *, kwnames), &r.generic.in.server_name))
+               return NULL;
+
+       r.generic.level                 = LIBNET_REMOTE_TOD_GENERIC;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       status = libnet_RemoteTOD(self->libnet_ctx, mem_ctx, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_SetString(PyExc_RuntimeError, r.generic.out.error_string);
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       ZERO_STRUCT(timestr);
+       tm = localtime(&r.generic.out.time);
+       strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
+       
+       ret = PyString_FromString(timestr);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+static const char py_net_time_doc[] = "time(server_name) -> timestr\n"
+"Retrieve the remote time on a server";
+
 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},
        { NULL }
 };
 
index 90b83689dd25c7b2630932d430adc646772bce9a..9f1ff3d13387d2692652c2e9080980a3c4c3d33c 100644 (file)
@@ -46,7 +46,7 @@ class cmd_export_keytab(Command):
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp)
         net = Net(creds, lp)
-        net.export_keytab(keytab=keytab, creds=creds)
+        net.export_keytab(keytab=keytab)
 
 
 class cmd_export(SuperCommand):
index 5b1e6968829a858114b2f3a87bfa1b38538bd560..496d339bf8e2a2f90bac2b7338e6a0913ac980a0 100644 (file)
@@ -41,7 +41,6 @@ net_OBJ_FILES = $(addprefix $(utilssrcdir)/net/,  \
                net.o \
                net_machinepw.o \
                net_password.o \
-               net_time.o \
                net_join.o \
                net_vampire.o \
                net_user.o)
diff --git a/source4/utils/net/net_time.c b/source4/utils/net/net_time.c
deleted file mode 100644 (file)
index 92e6e77..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* 
-   Samba Unix/Linux SMB client library 
-   Distributed SMB/CIFS Server Management Utility 
-
-   Copyright (C) 2004 Stefan Metzmacher (metze@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/>.
-*/
-
-#include "includes.h"
-#include "libnet/libnet.h"
-#include "utils/net/net.h"
-#include "system/time.h"
-#include "lib/events/events.h"
-
-/*
- * Code for getting the remote time
- */
-
-int net_time(struct net_context *ctx, int argc, const char **argv)
-{
-       NTSTATUS status;
-       struct libnet_context *libnetctx;
-       union libnet_RemoteTOD r;
-       const char *server_name;
-       struct tm *tm;
-       char timestr[64];
-
-       if (argc > 0 && argv[0]) {
-               server_name = argv[0];
-       } else {
-               return net_time_usage(ctx, argc, argv);
-       }
-
-       libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
-       if (!libnetctx) {
-               return -1;      
-       }
-       libnetctx->cred = ctx->credentials;
-
-       /* prepare to get the time */
-       r.generic.level                 = LIBNET_REMOTE_TOD_GENERIC;
-       r.generic.in.server_name        = server_name;
-
-       /* get the time */
-       status = libnet_RemoteTOD(libnetctx, ctx, &r);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0,("net_time: %s\n",r.generic.out.error_string));
-               return -1;
-       }
-
-       ZERO_STRUCT(timestr);
-       tm = localtime(&r.generic.out.time);
-       strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
-
-       printf("%s\n",timestr);
-
-       talloc_free(libnetctx);
-
-       return 0;
-}
-
-int net_time_usage(struct net_context *ctx, int argc, const char **argv)
-{
-       d_printf("net time <server> [options]\n");
-       return 0;       
-}