mirror of
https://github.com/samba-team/samba.git
synced 2025-02-09 09:57:48 +03:00
Added connect, session_request, session_setup and tconx methods.
This commit is contained in:
parent
10889241d5
commit
76eacaa285
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user