1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

Convert auth python module to "plain" C rather than using SWIG.

This commit is contained in:
Jelmer Vernooij 2008-12-21 03:37:31 +01:00
parent 2e7a6cb6bf
commit bfb29e94b1
8 changed files with 139 additions and 3350 deletions

View File

@ -1,52 +0,0 @@
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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/>.
*/
%define DOCSTRING
"Authentication and authorization support."
%enddef
%module(docstring=DOCSTRING,package="samba.auth") auth
%{
/* Include headers */
#include <stdint.h>
#include <stdbool.h>
#include "includes.h"
#include "auth/session.h"
#include "auth/system_session_proto.h"
#include "param/param.h"
%}
%import "carrays.i"
%import "stdint.i"
%import "typemaps.i"
%import "../lib/talloc/talloc.i"
%import "../param/param.i"
%typemap(default,noblock=1) struct auth_session_info * {
$1 = system_session_anon(NULL, global_loadparm);
}
%typemap(freearg,noblock=1) struct auth_session_info * {
talloc_free($1);
}
struct auth_session_info *system_session(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
struct auth_session_info *system_session_anon(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);

View File

@ -1,68 +0,0 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.36
#
# Don't modify this file, modify the SWIG interface instead.
"""
Authentication and authorization support.
"""
import _auth
import new
new_instancemethod = new.instancemethod
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'PySwigObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError,name
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
import types
try:
_object = types.ObjectType
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
del types
def _swig_setattr_nondynamic_method(set):
def set_attr(self,name,value):
if (name == "thisown"): return self.this.own(value)
if hasattr(self,name) or (name == "this"):
set(self,name,value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
return set_attr
import param
system_session = _auth.system_session
system_session_anon = _auth.system_session_anon

File diff suppressed because it is too large Load Diff

View File

@ -37,12 +37,10 @@ auth_sam_reply_OBJ_FILES = $(addprefix $(authsrcdir)/, auth_sam_reply.o)
$(eval $(call proto_header_template,$(authsrcdir)/auth_sam_reply.h,$(auth_sam_reply_OBJ_FILES:.o=.c)))
[PYTHON::swig_auth]
LIBRARY_REALNAME = samba/_auth.$(SHLIBEXT)
LIBRARY_REALNAME = samba/auth.$(SHLIBEXT)
PUBLIC_DEPENDENCIES = auth_system_session
PRIVATE_DEPENDENCIES = SAMDB
PRIVATE_DEPENDENCIES = SAMDB PYTALLOC param
$(eval $(call python_py_module_template,samba/auth.py,$(authsrcdir)/auth.py))
swig_auth_OBJ_FILES = $(authsrcdir)/pyauth.o
swig_auth_OBJ_FILES = $(authsrcdir)/auth_wrap.o
$(swig_auth_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL)
$(swig_auth_OBJ_FILES): CFLAGS+=$(CFLAG_NO_CAST_QUAL)

95
source4/auth/pyauth.c Normal file
View File

@ -0,0 +1,95 @@
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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 "param/param.h"
#include "pyauth.h"
#include "auth/system_session_proto.h"
/* FIXME: These should be in a header file somewhere, once we finish moving
* away from SWIG .. */
extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);
PyTypeObject PyAuthSession = {
.tp_name = "AuthSession",
.tp_basicsize = sizeof(py_talloc_Object),
.tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_repr = py_talloc_default_repr,
};
PyObject *PyAuthSession_FromSession(struct auth_session_info *session)
{
return py_talloc_import(&PyAuthSession, session);
}
static PyObject *py_system_session(PyObject *module, PyObject *args)
{
PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx = NULL;
struct auth_session_info *session;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL;
lp_ctx = lp_from_py_object(py_lp_ctx);
if (lp_ctx == NULL)
return NULL;
session = system_session(NULL, lp_ctx);
return PyAuthSession_FromSession(session);
}
static PyObject *py_system_session_anon(PyObject *module, PyObject *args)
{
PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx;
struct auth_session_info *session;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL;
lp_ctx = lp_from_py_object(py_lp_ctx);
if (lp_ctx == NULL)
return NULL;
session = system_session_anon(NULL, lp_ctx);
return PyAuthSession_FromSession(session);
}
static PyMethodDef py_auth_methods[] = {
{ "system_session", (PyCFunction)py_system_session, METH_VARARGS, NULL },
{ "system_session_anonymous", (PyCFunction)py_system_session_anon, METH_VARARGS, NULL },
{ NULL },
};
void initauth(void)
{
PyObject *m;
if (PyType_Ready(&PyAuthSession) < 0)
return;
m = Py_InitModule3("auth", py_auth_methods, "Authentication and authorization support.");
if (m == NULL)
return;
Py_INCREF(&PyAuthSession);
PyModule_AddObject(m, "AuthSession", (PyObject *)&PyAuthSession);
}

32
source4/auth/pyauth.h Normal file
View File

@ -0,0 +1,32 @@
/*
Unix SMB/CIFS implementation.
Samba utility functions
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
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/>.
*/
#ifndef _PYAUTH_H_
#define _PYAUTH_H_
#include "pytalloc.h"
#include "auth/session.h"
PyAPI_DATA(PyTypeObject) PyAuthSession;
#define PyAuthSession_AsSession(obj) py_talloc_get_ptr(obj)
#define PyAuthSession_Check(obj) PyObject_TypeCheck(obj, &PyAuthSession)
struct auth_session_info *PyObject_AsSession(PyObject *obj);
PyObject *PyAuthSession_FromSession(struct auth_session_info *session);
#endif /* _PYAUTH_H */

View File

@ -17,7 +17,7 @@ python_uuid_OBJ_FILES = $(pyscriptsrcdir)/uuidmodule.o
[PYTHON::python_glue]
LIBRARY_REALNAME = samba/glue.$(SHLIBEXT)
PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS swig_ldb python_dcerpc_misc python_dcerpc_security
PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS swig_ldb python_dcerpc_misc python_dcerpc_security swig_auth
python_glue_OBJ_FILES = $(pyscriptsrcdir)/pyglue.o

View File

@ -29,6 +29,7 @@
#include "libcli/util/pyerrors.h"
#include "librpc/gen_ndr/py_misc.h"
#include "librpc/gen_ndr/py_security.h"
#include "auth/pyauth.h"
/* FIXME: These should be in a header file somewhere, once we finish moving
* away from SWIG .. */
@ -121,7 +122,12 @@ static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
return NULL;
PyErr_LDB_OR_RAISE(py_ldb, ldb);
/* FIXME: Magic py_session_info -> info */
/*if (!PyAuthSession_Check(py_session_info)) {
PyErr_SetString(PyExc_TypeError, "Expected session info object");
return NULL;
}*/
info = PyAuthSession_AsSession(py_session_info);
ldb_set_opaque(ldb, "sessionInfo", info);