2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "param/param.h"
22 #include "auth/gensec/gensec.h"
23 #include "libcli/util/pyerrors.h"
27 #ifndef Py_RETURN_NONE
28 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
31 static PyObject
*py_get_name_by_authtype(PyObject
*self
, PyObject
*args
)
35 struct gensec_security
*security
;
37 if (!PyArg_ParseTuple(args
, "i", &type
))
40 security
= (struct gensec_security
*)py_talloc_get_ptr(self
);
42 name
= gensec_get_name_by_authtype(security
, type
);
46 return PyString_FromString(name
);
49 static struct gensec_settings
*settings_from_object(PyObject
*object
)
51 return NULL
; /* FIXME */
54 static PyObject
*py_gensec_start_client(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
57 py_talloc_Object
*self
;
58 struct gensec_settings
*settings
;
59 const char *kwnames
[] = { "settings", NULL
};
60 PyObject
*py_settings
;
61 struct tevent_context
*ev
;
63 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "O", kwnames
, &py_settings
))
66 settings
= settings_from_object(py_settings
);
70 self
= (py_talloc_Object
*)type
->tp_alloc(type
, 0);
75 self
->talloc_ctx
= talloc_new(NULL
);
76 if (self
->talloc_ctx
== NULL
) {
80 ev
= tevent_context_init(self
->talloc_ctx
);
86 status
= gensec_client_start(self
->talloc_ctx
,
87 (struct gensec_security
**)&self
->ptr
, ev
, settings
);
88 if (!NT_STATUS_IS_OK(status
)) {
89 PyErr_SetNTSTATUS(status
);
93 return (PyObject
*)self
;
96 static PyObject
*py_gensec_session_info(PyObject
*self
)
99 struct gensec_security
*security
= (struct gensec_security
*)py_talloc_get_ptr(self
);
100 struct auth_session_info
*info
;
101 status
= gensec_session_info(security
, &info
);
102 if (NT_STATUS_IS_ERR(status
)) {
103 PyErr_SetNTSTATUS(status
);
111 static PyMethodDef py_gensec_security_methods
[] = {
112 { "start_client", (PyCFunction
)py_gensec_start_client
, METH_VARARGS
|METH_KEYWORDS
|METH_CLASS
,
113 "S.start_client(settings) -> gensec" },
114 /* { "start_server", (PyCFunction)py_gensec_start_server, METH_VARARGS|METH_KEYWORDS|METH_CLASS,
115 "S.start_server(auth_ctx, settings) -> gensec" },*/
116 { "session_info", (PyCFunction
)py_gensec_session_info
, METH_NOARGS
,
117 "S.session_info() -> info" },
118 { "get_name_by_authtype", (PyCFunction
)py_get_name_by_authtype
, METH_VARARGS
,
119 "S.get_name_by_authtype(authtype) -> name\nLookup an auth type." },
123 static PyTypeObject Py_Security
= {
124 .tp_name
= "Security",
125 .tp_flags
= Py_TPFLAGS_DEFAULT
,
126 .tp_methods
= py_gensec_security_methods
,
127 .tp_basicsize
= sizeof(py_talloc_Object
),
128 .tp_dealloc
= py_talloc_dealloc
,
131 void initgensec(void)
135 if (PyType_Ready(&Py_Security
) < 0)
138 m
= Py_InitModule3("gensec", NULL
, "Generic Security Interface.");
142 Py_INCREF(&Py_Security
);
143 PyModule_AddObject(m
, "Security", (PyObject
*)&Py_Security
);