summaryrefslogtreecommitdiff
path: root/source3/python
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-08-02 05:35:09 +0000
committerTim Potter <tpot@samba.org>2002-08-02 05:35:09 +0000
commit598d62bd53732559a8a4ea8137b1b9635a1c5ebd (patch)
tree187a4a136154f5fb56ce6c4c64e3bfa0b02ff494 /source3/python
parent81a4862ae71795817cbe47edac615474ef26f0c9 (diff)
downloadsamba-598d62bd53732559a8a4ea8137b1b9635a1c5ebd.tar.gz
samba-598d62bd53732559a8a4ea8137b1b9635a1c5ebd.tar.bz2
samba-598d62bd53732559a8a4ea8137b1b9635a1c5ebd.zip
Added connect, session_request, session_setup and tconx methods.
(This used to be commit 76eacaa28546d65b9ddb7ff356f0bd2aaf2f86d8)
Diffstat (limited to 'source3/python')
-rw-r--r--source3/python/py_smb.c159
1 files changed, 138 insertions, 21 deletions
diff --git a/source3/python/py_smb.c b/source3/python/py_smb.c
index c206e6ba9b..77d7bb32fc 100644
--- a/source3/python/py_smb.c
+++ b/source3/python/py_smb.c
@@ -20,23 +20,6 @@
#include "python/py_smb.h"
-/*
- * Exceptions raised by this module
- */
-
-PyObject *smb_ntstatus; /* This exception is raised when a RPC call
- returns a status code other than
- NT_STATUS_OK */
-
-
-/*
- * Method dispatch tables
- */
-
-static PyMethodDef smb_methods[] = {
- { NULL }
-};
-
/* Create a new cli_state python object */
PyObject *new_cli_state_object(struct cli_state *cli)
@@ -50,6 +33,143 @@ PyObject *new_cli_state_object(struct cli_state *cli)
return (PyObject*)o;
}
+static PyObject *py_smb_connect(PyObject *self, PyObject *args, PyObject *kw)
+{
+ static char *kwlist[] = { "server", NULL };
+ struct cli_state *cli;
+ char *server;
+ struct in_addr ip;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &server))
+ return NULL;
+
+ if (!(cli = cli_initialise(NULL)))
+ return NULL;
+
+ ZERO_STRUCT(ip);
+
+ if (!cli_connect(cli, server, &ip))
+ return NULL;
+
+ return new_cli_state_object(cli);
+}
+
+static PyObject *py_smb_session_request(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ cli_state_object *cli = (cli_state_object *)self;
+ static char *kwlist[] = { "called", "calling", NULL };
+ char *calling_name = NULL, *called_name;
+ struct nmb_name calling, called;
+ extern pstring global_myname;
+ BOOL result;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|s", kwlist, &called_name,
+ &calling_name))
+ return NULL;
+
+ if (!calling_name)
+ calling_name = global_myname;
+
+ make_nmb_name(&calling, calling_name, 0x00);
+ make_nmb_name(&called, called_name, 0x20);
+
+ result = cli_session_request(cli->cli, &calling, &called);
+
+ return Py_BuildValue("i", result);
+}
+
+static PyObject *py_smb_negprot(PyObject *self, PyObject *args, PyObject *kw)
+{
+ cli_state_object *cli = (cli_state_object *)self;
+ static char *kwlist[] = { NULL };
+ BOOL result;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
+ return NULL;
+
+ result = cli_negprot(cli->cli);
+
+ return Py_BuildValue("i", result);
+}
+
+static PyObject *py_smb_session_setup(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ cli_state_object *cli = (cli_state_object *)self;
+ static char *kwlist[] = { "creds" };
+ PyObject *creds;
+ char *username, *domain, *password, *errstr;
+ BOOL result;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O", kwlist, &creds))
+ return NULL;
+
+ if (!py_parse_creds(creds, &username, &domain, &password, &errstr)) {
+ free(errstr);
+ return NULL;
+ }
+
+ result = cli_session_setup(
+ cli->cli, username, password, strlen(password) + 1,
+ password, strlen(password) + 1, domain);
+
+ return Py_BuildValue("i", result);
+}
+
+static PyObject *py_smb_tconx(PyObject *self, PyObject *args, PyObject *kw)
+{
+ cli_state_object *cli = (cli_state_object *)self;
+ static char *kwlist[] = { "service", "creds" };
+ PyObject *creds;
+ char *service, *username, *domain, *password, *errstr;
+ BOOL result;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "sO", kwlist, &service,
+ &creds))
+ return NULL;
+
+ if (!py_parse_creds(creds, &username, &domain, &password, &errstr)) {
+ free(errstr);
+ return NULL;
+ }
+
+ result = cli_send_tconX(
+ cli->cli, service, strequal(service, "IPC$") ? "IPC" : "?????",
+ password, strlen(password) + 1);
+
+ return Py_BuildValue("i", result);
+}
+
+static PyMethodDef smb_hnd_methods[] = {
+
+ { "session_request", (PyCFunction)py_smb_session_request,
+ METH_VARARGS | METH_KEYWORDS, "Request a session" },
+
+ { "negprot", (PyCFunction)py_smb_negprot,
+ METH_VARARGS | METH_KEYWORDS, "Protocol negotiation" },
+
+ { "session_setup", (PyCFunction)py_smb_session_setup,
+ METH_VARARGS | METH_KEYWORDS, "Session setup" },
+
+ { "tconx", (PyCFunction)py_smb_tconx,
+ METH_VARARGS | METH_KEYWORDS, "Tree connect" },
+
+ { NULL }
+};
+
+/*
+ * Method dispatch tables
+ */
+
+static PyMethodDef smb_methods[] = {
+
+ { "connect", (PyCFunction)py_smb_connect, METH_VARARGS | METH_KEYWORDS,
+ "Connect to a host" },
+
+ { NULL }
+};
+
static void py_cli_state_dealloc(PyObject* self)
{
PyObject_Del(self);
@@ -57,7 +177,7 @@ static void py_cli_state_dealloc(PyObject* self)
static PyObject *py_cli_state_getattr(PyObject *self, char *attrname)
{
- return Py_FindMethod(smb_methods, self, attrname);
+ return Py_FindMethod(smb_hnd_methods, self, attrname);
}
PyTypeObject cli_state_type = {
@@ -91,9 +211,6 @@ void initsmb(void)
module = Py_InitModule("smb", smb_methods);
dict = PyModule_GetDict(module);
- smb_ntstatus = PyErr_NewException("smb.ntstatus", NULL, NULL);
- PyDict_SetItemString(dict, "ntstatus", smb_ntstatus);
-
/* Initialise policy handle object */
cli_state_type.ob_type = &PyType_Type;