mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
Skeleton for a libsmb python wrapper.
This commit is contained in:
107
source/python/py_smb.c
Normal file
107
source/python/py_smb.c
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
Python wrappers for DCERPC/SMB client routines.
|
||||
|
||||
Copyright (C) Tim Potter, 2002
|
||||
|
||||
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 2 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, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#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)
|
||||
{
|
||||
cli_state_object *o;
|
||||
|
||||
o = PyObject_New(cli_state_object, &cli_state_type);
|
||||
|
||||
o->cli = cli;
|
||||
|
||||
return (PyObject*)o;
|
||||
}
|
||||
|
||||
static void py_cli_state_dealloc(PyObject* self)
|
||||
{
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
static PyObject *py_cli_state_getattr(PyObject *self, char *attrname)
|
||||
{
|
||||
return Py_FindMethod(smb_methods, self, attrname);
|
||||
}
|
||||
|
||||
PyTypeObject cli_state_type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"SMB client connection",
|
||||
sizeof(cli_state_object),
|
||||
0,
|
||||
py_cli_state_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
py_cli_state_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
};
|
||||
|
||||
/*
|
||||
* Module initialisation
|
||||
*/
|
||||
|
||||
void initsmb(void)
|
||||
{
|
||||
PyObject *module, *dict;
|
||||
|
||||
/* Initialise module */
|
||||
|
||||
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;
|
||||
|
||||
/* Do samba initialisation */
|
||||
|
||||
py_samba_init();
|
||||
|
||||
setup_logging("smb", True);
|
||||
DEBUGLEVEL = 10;
|
||||
}
|
42
source/python/py_smb.h
Normal file
42
source/python/py_smb.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Python wrappers for DCERPC/SMB client routines.
|
||||
|
||||
Copyright (C) Tim Potter, 2002
|
||||
|
||||
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 2 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, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _PY_SMB_H
|
||||
#define _PY_SMB_H
|
||||
|
||||
#include "includes.h"
|
||||
#include "Python.h"
|
||||
|
||||
#include "python/py_common_proto.h"
|
||||
|
||||
/* cli_state handle object */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct cli_state *cli;
|
||||
} cli_state_object;
|
||||
|
||||
/* Exceptions raised by this module */
|
||||
|
||||
extern PyTypeObject cli_state_type;
|
||||
|
||||
extern PyObject *smb_ntstatus;
|
||||
|
||||
#endif /* _PY_SMB_H */
|
@ -4,7 +4,7 @@ RCS file: /data/cvs/samba/source/Makefile.in,v
|
||||
retrieving revision 1.500
|
||||
diff -u -r1.500 Makefile.in
|
||||
--- Makefile.in 2002/07/28 06:04:32 1.500
|
||||
+++ Makefile.in 2002/07/29 01:58:05
|
||||
+++ Makefile.in 2002/07/29 03:48:03
|
||||
@@ -838,6 +838,45 @@
|
||||
-$(INSTALLCMD) -d ${prefix}/include
|
||||
-$(INSTALLCMD) include/libsmbclient.h ${prefix}/include
|
||||
@ -12,7 +12,7 @@ diff -u -r1.500 Makefile.in
|
||||
+# Python extensions
|
||||
+
|
||||
+PYTHON_OBJS = $(LIB_OBJ) $(LIBSMB_OBJ) $(RPC_PARSE_OBJ) $(UBIQX_OBJ) \
|
||||
+ $(PARAM_OBJ) $(LIBMSRPC_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ)
|
||||
+ $(PARAM_OBJ) $(LIBMSRPC_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) $(SECRETS_OBJ)
|
||||
+
|
||||
+PY_SPOOLSS_PROTO_OBJ = python/py_spoolss.o \
|
||||
+ python/py_spoolss_printers.o python/py_spoolss_printers_conv.o\
|
||||
@ -57,7 +57,7 @@ RCS file: /data/cvs/samba/source/configure.in,v
|
||||
retrieving revision 1.324
|
||||
diff -u -r1.324 configure.in
|
||||
--- configure.in 2002/07/27 01:37:32 1.324
|
||||
+++ configure.in 2002/07/29 01:58:06
|
||||
+++ configure.in 2002/07/29 03:48:04
|
||||
@@ -2797,7 +2797,7 @@
|
||||
builddir=`pwd`
|
||||
AC_SUBST(builddir)
|
||||
|
@ -150,5 +150,14 @@ setup(
|
||||
library_dirs = ["/usr/kerberos/lib"],
|
||||
extra_objects = obj_list),
|
||||
|
||||
# libsmb module
|
||||
|
||||
Extension(name = "smb",
|
||||
sources = [samba_srcdir + "python/py_smb.c",
|
||||
samba_srcdir + "python/py_common.c"],
|
||||
libraries = lib_list,
|
||||
library_dirs = ["/usr/kerberos/lib"],
|
||||
extra_objects = obj_list),
|
||||
|
||||
],
|
||||
)
|
||||
|
Reference in New Issue
Block a user