py3: Remove #define PyInt_FromLong PyLong_FromLong
[samba.git] / source4 / auth / gensec / pygensec.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
4    
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.
9    
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.
14    
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/>.
17 */
18
19 #include <Python.h>
20 #include "python/py3compat.h"
21 #include "includes.h"
22 #include "python/modules.h"
23 #include "param/pyparam.h"
24 #include "auth/gensec/gensec.h"
25 #include "auth/gensec/gensec_internal.h" /* TODO: remove this */
26 #include "auth/credentials/pycredentials.h"
27 #include "libcli/util/pyerrors.h"
28 #include "python/modules.h"
29 #include <pytalloc.h>
30 #include <tevent.h>
31 #include "librpc/rpc/pyrpc_util.h"
32
33 static PyObject *py_get_name_by_authtype(PyObject *self, PyObject *args)
34 {
35         int type;
36         const char *name;
37         struct gensec_security *security;
38
39         if (!PyArg_ParseTuple(args, "i", &type))
40                 return NULL;
41
42         security = pytalloc_get_type(self, struct gensec_security);
43
44         name = gensec_get_name_by_authtype(security, type);
45         if (name == NULL)
46                 Py_RETURN_NONE;
47
48         return PyUnicode_FromString(name);
49 }
50
51 static struct gensec_settings *settings_from_object(TALLOC_CTX *mem_ctx, PyObject *object)
52 {
53         struct gensec_settings *s;
54         PyObject *py_hostname, *py_lp_ctx;
55
56         if (!PyDict_Check(object)) {
57                 PyErr_SetString(PyExc_ValueError, "settings should be a dictionary");
58                 return NULL;
59         }
60
61         s = talloc_zero(mem_ctx, struct gensec_settings);
62         if (!s) return NULL;
63
64         py_hostname = PyDict_GetItemString(object, "target_hostname");
65         if (!py_hostname) {
66                 PyErr_SetString(PyExc_ValueError, "settings.target_hostname not found");
67                 return NULL;
68         }
69
70         py_lp_ctx = PyDict_GetItemString(object, "lp_ctx");
71         if (!py_lp_ctx) {
72                 PyErr_SetString(PyExc_ValueError, "settings.lp_ctx not found");
73                 return NULL;
74         }
75
76         s->target_hostname = PyUnicode_AsUTF8(py_hostname);
77         s->lp_ctx = lpcfg_from_py_object(s, py_lp_ctx);
78         return s;
79 }
80
81 static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyObject *kwargs)
82 {
83         NTSTATUS status;
84         PyObject *self;
85         struct gensec_settings *settings;
86         const char *kwnames[] = { "settings", NULL };
87         PyObject *py_settings = Py_None;
88         struct gensec_security *gensec;
89         TALLOC_CTX *frame;
90
91         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", discard_const_p(char *, kwnames), &py_settings))
92                 return NULL;
93
94         frame = talloc_stackframe();
95
96         if (py_settings != Py_None) {
97                 settings = settings_from_object(frame, py_settings);
98                 if (settings == NULL) {
99                         PyErr_NoMemory();
100                         TALLOC_FREE(frame);
101                         return NULL;
102                 }
103         } else {
104                 settings = talloc_zero(frame, struct gensec_settings);
105                 if (settings == NULL) {
106                         PyErr_NoMemory();
107                         TALLOC_FREE(frame);
108                         return NULL;
109                 }
110
111                 settings->lp_ctx = loadparm_init_global(true);
112                 if (settings->lp_ctx == NULL) {
113                         PyErr_NoMemory();
114                         TALLOC_FREE(frame);
115                         return NULL;
116                 }
117         }
118
119         status = gensec_init();
120         if (!NT_STATUS_IS_OK(status)) {
121                 PyErr_SetNTSTATUS(status);
122                 TALLOC_FREE(frame);
123                 return NULL;
124         }
125
126         status = gensec_client_start(frame, &gensec, settings);
127         if (!NT_STATUS_IS_OK(status)) {
128                 PyErr_SetNTSTATUS(status);
129                 TALLOC_FREE(frame);
130                 return NULL;
131         }
132
133         self = pytalloc_steal(type, gensec);
134         TALLOC_FREE(frame);
135
136         return (PyObject *)self;
137 }
138
139 static PyObject *py_gensec_start_server(PyTypeObject *type, PyObject *args, PyObject *kwargs)
140 {
141         NTSTATUS status;
142         PyObject *self;
143         struct gensec_settings *settings = NULL;
144         const char *kwnames[] = { "settings", "auth_context", NULL };
145         PyObject *py_settings = Py_None;
146         PyObject *py_auth_context = Py_None;
147         struct gensec_security *gensec;
148         struct auth4_context *auth_context = NULL;
149         TALLOC_CTX *frame;
150
151         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", discard_const_p(char *, kwnames), &py_settings, &py_auth_context))
152                 return NULL;
153
154         frame = talloc_stackframe();
155
156         if (py_settings != Py_None) {
157                 settings = settings_from_object(frame, py_settings);
158                 if (settings == NULL) {
159                         PyErr_NoMemory();
160                         TALLOC_FREE(frame);
161                         return NULL;
162                 }
163         } else {
164                 settings = talloc_zero(frame, struct gensec_settings);
165                 if (settings == NULL) {
166                         PyErr_NoMemory();
167                         TALLOC_FREE(frame);
168                         return NULL;
169                 }
170
171                 settings->lp_ctx = loadparm_init_global(true);
172                 if (settings->lp_ctx == NULL) {
173                         PyErr_NoMemory();
174                         TALLOC_FREE(frame);
175                         return NULL;
176                 }
177         }
178
179         if (py_auth_context != Py_None) {
180                 bool ok = py_check_dcerpc_type(py_auth_context,
181                                                "samba.auth",
182                                                "AuthContext");
183                 if (!ok) {
184                         return NULL;
185                 }
186
187                 auth_context = pytalloc_get_type(py_auth_context,
188                                                  struct auth4_context);
189                 if (!auth_context) {
190                         PyErr_Format(PyExc_TypeError,
191                                      "Expected auth.AuthContext for auth_context argument, got %s",
192                                      pytalloc_get_name(py_auth_context));
193                         return NULL;
194                 }
195         }
196
197         status = gensec_init();
198         if (!NT_STATUS_IS_OK(status)) {
199                 PyErr_SetNTSTATUS(status);
200                 TALLOC_FREE(frame);
201                 return NULL;
202         }
203
204         status = gensec_server_start(frame, settings, auth_context, &gensec);
205         if (!NT_STATUS_IS_OK(status)) {
206                 PyErr_SetNTSTATUS(status);
207                 TALLOC_FREE(frame);
208                 return NULL;
209         }
210
211         self = pytalloc_steal(type, gensec);
212         TALLOC_FREE(frame);
213
214         return self;
215 }
216
217 static PyObject *py_gensec_set_target_hostname(PyObject *self, PyObject *args)
218 {
219         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
220         char *target_hostname;
221         NTSTATUS status;
222
223         if (!PyArg_ParseTuple(args, "s", &target_hostname))
224                 return NULL;
225
226         status = gensec_set_target_hostname(security, target_hostname);
227         if (!NT_STATUS_IS_OK(status)) {
228                 PyErr_SetNTSTATUS(status);
229                 return NULL;
230         }
231         
232         Py_RETURN_NONE;
233 }
234
235 static PyObject *py_gensec_set_target_service(PyObject *self, PyObject *args)
236 {
237         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
238         char *target_service;
239         NTSTATUS status;
240
241         if (!PyArg_ParseTuple(args, "s", &target_service))
242                 return NULL;
243
244         status = gensec_set_target_service(security, target_service);
245         if (!NT_STATUS_IS_OK(status)) {
246                 PyErr_SetNTSTATUS(status);
247                 return NULL;
248         }
249         
250         Py_RETURN_NONE;
251 }
252
253 static PyObject *py_gensec_set_target_service_description(PyObject *self, PyObject *args)
254 {
255         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
256         char *target_service_description;
257         NTSTATUS status;
258
259         if (!PyArg_ParseTuple(args, "s", &target_service_description))
260                 return NULL;
261
262         status = gensec_set_target_service_description(security,
263                                                        target_service_description);
264         if (!NT_STATUS_IS_OK(status)) {
265                 PyErr_SetNTSTATUS(status);
266                 return NULL;
267         }
268
269         Py_RETURN_NONE;
270 }
271
272 static PyObject *py_gensec_set_credentials(PyObject *self, PyObject *args)
273 {
274         PyObject *py_creds = Py_None;
275         struct cli_credentials *creds;
276         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
277         NTSTATUS status;
278
279         if (!PyArg_ParseTuple(args, "O", &py_creds))
280                 return NULL;
281
282         creds = PyCredentials_AsCliCredentials(py_creds);
283         if (!creds) {
284                 PyErr_Format(
285                         PyExc_TypeError,
286                         "Expected samba.credentials for credentials argument, "
287                         "got %s", pytalloc_get_name(py_creds));
288                 return NULL;
289         }
290
291         status = gensec_set_credentials(security, creds);
292         if (!NT_STATUS_IS_OK(status)) {
293                 PyErr_SetNTSTATUS(status);
294                 return NULL;
295         }
296
297         Py_RETURN_NONE;
298 }
299
300 static PyObject *py_gensec_session_info(PyObject *self,
301                 PyObject *Py_UNUSED(ignored))
302 {
303         TALLOC_CTX *mem_ctx;
304         NTSTATUS status;
305         PyObject *py_session_info;
306         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
307         struct auth_session_info *info;
308         if (security->ops == NULL) {
309                 PyErr_SetString(PyExc_RuntimeError, "no mechanism selected");
310                 return NULL;
311         }
312         mem_ctx = talloc_new(NULL);
313
314         status = gensec_session_info(security, mem_ctx, &info);
315         if (NT_STATUS_IS_ERR(status)) {
316                 PyErr_SetNTSTATUS(status);
317                 return NULL;
318         }
319
320         py_session_info = py_return_ndr_struct("samba.dcerpc.auth", "session_info",
321                                                  info, info);
322         talloc_free(mem_ctx);
323         return py_session_info;
324 }
325
326 static PyObject *py_gensec_session_key(PyObject *self,
327                 PyObject *Py_UNUSED(ignored))
328 {
329         TALLOC_CTX *mem_ctx;
330         NTSTATUS status;
331         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
332         DATA_BLOB session_key = data_blob_null;
333         static PyObject *session_key_obj = NULL;
334
335         if (security->ops == NULL) {
336                 PyErr_SetString(PyExc_RuntimeError, "no mechanism selected");
337                 return NULL;
338         }
339         mem_ctx = talloc_new(NULL);
340
341         status = gensec_session_key(security, mem_ctx, &session_key);
342         if (!NT_STATUS_IS_OK(status)) {
343                 talloc_free(mem_ctx);
344                 PyErr_SetNTSTATUS(status);
345                 return NULL;
346         }
347
348         session_key_obj = PyBytes_FromStringAndSize((const char *)session_key.data,
349                                                      session_key.length);
350         talloc_free(mem_ctx);
351         return session_key_obj;
352 }
353
354 static PyObject *py_gensec_start_mech_by_name(PyObject *self, PyObject *args)
355 {
356         char *name;
357         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
358         NTSTATUS status;
359
360         if (!PyArg_ParseTuple(args, "s", &name))
361                 return NULL;
362
363         status = gensec_start_mech_by_name(security, name);
364         if (!NT_STATUS_IS_OK(status)) {
365                 PyErr_SetNTSTATUS(status);
366                 return NULL;
367         }
368
369         Py_RETURN_NONE;
370 }
371
372 static PyObject *py_gensec_start_mech_by_sasl_name(PyObject *self, PyObject *args)
373 {
374         char *sasl_name;
375         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
376         NTSTATUS status;
377
378         if (!PyArg_ParseTuple(args, "s", &sasl_name))
379                 return NULL;
380
381         status = gensec_start_mech_by_sasl_name(security, sasl_name);
382         if (!NT_STATUS_IS_OK(status)) {
383                 PyErr_SetNTSTATUS(status);
384                 return NULL;
385         }
386
387         Py_RETURN_NONE;
388 }
389
390 static PyObject *py_gensec_start_mech_by_authtype(PyObject *self, PyObject *args)
391 {
392         int authtype, level;
393         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
394         NTSTATUS status;
395         if (!PyArg_ParseTuple(args, "ii", &authtype, &level))
396                 return NULL;
397
398         status = gensec_start_mech_by_authtype(security, authtype, level);
399         if (!NT_STATUS_IS_OK(status)) {
400                 PyErr_SetNTSTATUS(status);
401                 return NULL;
402         }
403
404         Py_RETURN_NONE;
405 }
406
407 static PyObject *py_gensec_want_feature(PyObject *self, PyObject *args)
408 {
409         int feature;
410         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
411         /* This is i (and declared as an int above) by design, as they are handled as an integer in python */
412         if (!PyArg_ParseTuple(args, "i", &feature))
413                 return NULL;
414
415         gensec_want_feature(security, feature);
416
417         Py_RETURN_NONE;
418 }
419
420 static PyObject *py_gensec_have_feature(PyObject *self, PyObject *args)
421 {
422         int feature;
423         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
424         /* This is i (and declared as an int above) by design, as they are handled as an integer in python */
425         if (!PyArg_ParseTuple(args, "i", &feature))
426                 return NULL;
427
428         if (gensec_have_feature(security, feature)) {
429                 return Py_True;
430         } 
431         return Py_False;
432 }
433
434 static PyObject *py_gensec_set_max_update_size(PyObject *self, PyObject *args)
435 {
436         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
437         unsigned int max_update_size = 0;
438
439         if (!PyArg_ParseTuple(args, "I", &max_update_size))
440                 return NULL;
441
442         gensec_set_max_update_size(security, max_update_size);
443
444         Py_RETURN_NONE;
445 }
446
447 static PyObject *py_gensec_max_update_size(PyObject *self,
448                 PyObject *Py_UNUSED(ignored))
449 {
450         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
451         unsigned int max_update_size = gensec_max_update_size(security);
452
453         return PyLong_FromLong(max_update_size);
454 }
455
456 static PyObject *py_gensec_update(PyObject *self, PyObject *args)
457 {
458         NTSTATUS status;
459         TALLOC_CTX *mem_ctx;
460         DATA_BLOB in, out;
461         PyObject *py_bytes, *result, *py_in;
462         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
463         PyObject *finished_processing;
464
465         if (!PyArg_ParseTuple(args, "O", &py_in))
466                 return NULL;
467
468         mem_ctx = talloc_new(NULL);
469         if (!PyBytes_Check(py_in)) {
470                 PyErr_Format(PyExc_TypeError, "bytes expected");
471                 return NULL;
472         }
473
474         in.data = (uint8_t *)PyBytes_AsString(py_in);
475         in.length = PyBytes_Size(py_in);
476
477         status = gensec_update(security, mem_ctx, in, &out);
478
479         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)
480             && !NT_STATUS_IS_OK(status)) {
481                 PyErr_SetNTSTATUS(status);
482                 talloc_free(mem_ctx);
483                 return NULL;
484         }
485         py_bytes = PyBytes_FromStringAndSize((const char *)out.data,
486                                              out.length);
487         talloc_free(mem_ctx);
488
489         if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
490                 finished_processing = Py_False;
491         } else {
492                 finished_processing = Py_True;
493         }
494
495         result = PyTuple_Pack(2, finished_processing, py_bytes);
496         Py_XDECREF(py_bytes);
497         return result;
498 }
499
500 static PyObject *py_gensec_wrap(PyObject *self, PyObject *args)
501 {
502         NTSTATUS status;
503
504         TALLOC_CTX *mem_ctx;
505         DATA_BLOB in, out;
506         PyObject *ret, *py_in;
507         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
508
509         if (!PyArg_ParseTuple(args, "O", &py_in))
510                 return NULL;
511
512         mem_ctx = talloc_new(NULL);
513
514         if (!PyBytes_Check(py_in)) {
515                 PyErr_Format(PyExc_TypeError, "bytes expected");
516                 return NULL;
517         }
518         in.data = (uint8_t *)PyBytes_AsString(py_in);
519         in.length = PyBytes_Size(py_in);
520
521         status = gensec_wrap(security, mem_ctx, &in, &out);
522
523         if (!NT_STATUS_IS_OK(status)) {
524                 PyErr_SetNTSTATUS(status);
525                 talloc_free(mem_ctx);
526                 return NULL;
527         }
528
529         ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
530         talloc_free(mem_ctx);
531         return ret;
532 }
533
534
535 static PyObject *py_gensec_unwrap(PyObject *self, PyObject *args)
536 {
537         NTSTATUS status;
538
539         TALLOC_CTX *mem_ctx;
540         DATA_BLOB in, out;
541         PyObject *ret, *py_in;
542         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
543
544         if (!PyArg_ParseTuple(args, "O", &py_in))
545                 return NULL;
546
547         mem_ctx = talloc_new(NULL);
548
549         if (!PyBytes_Check(py_in)) {
550                 PyErr_Format(PyExc_TypeError, "bytes expected");
551                 return NULL;
552         }
553
554         in.data = (uint8_t *)PyBytes_AsString(py_in);
555         in.length = PyBytes_Size(py_in);
556
557         status = gensec_unwrap(security, mem_ctx, &in, &out);
558
559         if (!NT_STATUS_IS_OK(status)) {
560                 PyErr_SetNTSTATUS(status);
561                 talloc_free(mem_ctx);
562                 return NULL;
563         }
564
565         ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
566         talloc_free(mem_ctx);
567         return ret;
568 }
569
570 static PyObject *py_gensec_sig_size(PyObject *self, PyObject *args)
571 {
572         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
573         Py_ssize_t data_size = 0;
574         size_t sig_size = 0;
575
576         if (!PyArg_ParseTuple(args, "n", &data_size)) {
577                 return NULL;
578         }
579
580         sig_size = gensec_sig_size(security, data_size);
581
582         return PyLong_FromSize_t(sig_size);
583 }
584
585 static PyObject *py_gensec_sign_packet(PyObject *self, PyObject *args)
586 {
587         NTSTATUS status;
588         TALLOC_CTX *mem_ctx = NULL;
589         Py_ssize_t data_length = 0;
590         Py_ssize_t pdu_length = 0;
591         DATA_BLOB data, pdu, sig;
592         PyObject *py_sig;
593         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
594
595         if (!PyArg_ParseTuple(args, "z#z#", &data.data, &data_length, &pdu.data, &pdu_length)) {
596                 return NULL;
597         }
598         data.length = data_length;
599         pdu.length = pdu_length;
600
601         mem_ctx = talloc_new(NULL);
602
603         status = gensec_sign_packet(security, mem_ctx,
604                                     data.data, data.length,
605                                     pdu.data, pdu.length, &sig);
606         if (!NT_STATUS_IS_OK(status)) {
607                 PyErr_SetNTSTATUS(status);
608                 talloc_free(mem_ctx);
609                 return NULL;
610         }
611
612         py_sig = PyBytes_FromStringAndSize((const char *)sig.data, sig.length);
613         talloc_free(mem_ctx);
614         return py_sig;
615 }
616
617 static PyObject *py_gensec_check_packet(PyObject *self, PyObject *args)
618 {
619         NTSTATUS status;
620         Py_ssize_t data_length = 0;
621         Py_ssize_t pdu_length = 0;
622         Py_ssize_t sig_length = 0;
623         DATA_BLOB data, pdu, sig;
624         struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
625
626         if (!PyArg_ParseTuple(args, "z#z#z#",
627                               &data.data, &data_length,
628                               &pdu.data, &pdu_length,
629                               &sig.data, &sig_length)) {
630                 return NULL;
631         }
632         data.length = data_length;
633         pdu.length = pdu_length;
634         sig.length = sig_length;
635
636         status = gensec_check_packet(security,
637                                      data.data, data.length,
638                                      pdu.data, pdu.length, &sig);
639         if (!NT_STATUS_IS_OK(status)) {
640                 PyErr_SetNTSTATUS(status);
641                 return NULL;
642         }
643
644         Py_RETURN_NONE;
645 }
646
647 static PyMethodDef py_gensec_security_methods[] = {
648         { "start_client", PY_DISCARD_FUNC_SIG(PyCFunction,
649                                               py_gensec_start_client),
650                 METH_VARARGS|METH_KEYWORDS|METH_CLASS,
651                 "S.start_client(settings) -> gensec" },
652         { "start_server", PY_DISCARD_FUNC_SIG(PyCFunction,
653                                               py_gensec_start_server),
654                 METH_VARARGS|METH_KEYWORDS|METH_CLASS,
655                 "S.start_server(auth_ctx, settings) -> gensec" },
656         { "set_credentials", (PyCFunction)py_gensec_set_credentials, METH_VARARGS, 
657                 "S.start_client(credentials)" },
658         { "set_target_hostname", (PyCFunction)py_gensec_set_target_hostname, METH_VARARGS, 
659                 "S.start_target_hostname(target_hostname) \n This sets the Kerberos target hostname to obtain a ticket for." },
660         { "set_target_service", (PyCFunction)py_gensec_set_target_service, METH_VARARGS, 
661                 "S.start_target_service(target_service) \n This sets the Kerberos target service to obtain a ticket for.  The default value is 'host'" },
662         { "set_target_service_description", (PyCFunction)py_gensec_set_target_service_description, METH_VARARGS,
663                 "S.start_target_service_description(target_service_description) \n This description is set server-side and used in authentication and authorization logs.  The default value is that provided to set_target_service() or None."},
664         { "session_info", (PyCFunction)py_gensec_session_info, METH_NOARGS,
665                 "S.session_info() -> info" },
666         { "session_key", (PyCFunction)py_gensec_session_key, METH_NOARGS,
667                 "S.session_key() -> key" },
668         { "start_mech_by_name", (PyCFunction)py_gensec_start_mech_by_name, METH_VARARGS,
669                 "S.start_mech_by_name(name)" },
670         { "start_mech_by_sasl_name", (PyCFunction)py_gensec_start_mech_by_sasl_name, METH_VARARGS,
671                 "S.start_mech_by_sasl_name(name)" },
672         { "start_mech_by_authtype", (PyCFunction)py_gensec_start_mech_by_authtype, METH_VARARGS,
673                 "S.start_mech_by_authtype(authtype, level)" },
674         { "get_name_by_authtype", (PyCFunction)py_get_name_by_authtype, METH_VARARGS,
675                 "S.get_name_by_authtype(authtype) -> name\nLookup an auth type." },
676         { "want_feature", (PyCFunction)py_gensec_want_feature, METH_VARARGS,
677                 "S.want_feature(feature)\n Request that GENSEC negotiate a particular feature." },
678         { "have_feature", (PyCFunction)py_gensec_have_feature, METH_VARARGS,
679                 "S.have_feature()\n Return True if GENSEC negotiated a particular feature." },
680         { "set_max_update_size",  (PyCFunction)py_gensec_set_max_update_size, METH_VARARGS,
681                 "S.set_max_update_size(max_size) \n Some mechs can fragment update packets, needs to be use before the mech is started." },
682         { "max_update_size",  (PyCFunction)py_gensec_max_update_size, METH_NOARGS,
683                 "S.max_update_size() \n Return the current max_update_size." },
684         { "update",  (PyCFunction)py_gensec_update, METH_VARARGS,
685                 "S.update(blob_in) -> (finished, blob_out)\nPerform one step in a GENSEC dance.  Repeat with new packets until finished is true or exception." },
686         { "wrap",  (PyCFunction)py_gensec_wrap, METH_VARARGS,
687                 "S.wrap(blob_in) -> blob_out\nPackage one clear packet into a wrapped GENSEC packet." },
688         { "unwrap",  (PyCFunction)py_gensec_unwrap, METH_VARARGS,
689                 "S.unwrap(blob_in) -> blob_out\nPerform one wrapped GENSEC packet into a clear packet." },
690         { "sig_size",  (PyCFunction)py_gensec_sig_size, METH_VARARGS,
691                 "S.sig_size(data_size) -> sig_size\nSize of the DCERPC packet signature" },
692         { "sign_packet",  (PyCFunction)py_gensec_sign_packet, METH_VARARGS,
693                 "S.sign_packet(data, whole_pdu) -> sig\nSign a DCERPC packet." },
694         { "check_packet",  (PyCFunction)py_gensec_check_packet, METH_VARARGS,
695                 "S.check_packet(data, whole_pdu, sig)\nCheck a DCERPC packet." },
696         { NULL }
697 };
698
699 static struct PyModuleDef moduledef = {
700     PyModuleDef_HEAD_INIT,
701     .m_name = "gensec",
702     .m_doc = "Generic Security Interface.",
703     .m_size = -1,
704 };
705
706 static PyTypeObject Py_Security = {
707         .tp_name = "gensec.Security",
708         .tp_flags = Py_TPFLAGS_DEFAULT,
709         .tp_methods = py_gensec_security_methods,
710 };
711
712 MODULE_INIT_FUNC(gensec)
713 {
714         PyObject *m;
715
716         if (pytalloc_BaseObject_PyType_Ready(&Py_Security) < 0)
717                 return NULL;
718
719         m = PyModule_Create(&moduledef);
720         if (m == NULL)
721                 return NULL;
722
723         PyModule_AddObject(m, "FEATURE_SESSION_KEY",     PyLong_FromLong(GENSEC_FEATURE_SESSION_KEY));
724         PyModule_AddObject(m, "FEATURE_SIGN",            PyLong_FromLong(GENSEC_FEATURE_SIGN));
725         PyModule_AddObject(m, "FEATURE_SEAL",            PyLong_FromLong(GENSEC_FEATURE_SEAL));
726         PyModule_AddObject(m, "FEATURE_DCE_STYLE",       PyLong_FromLong(GENSEC_FEATURE_DCE_STYLE));
727         PyModule_AddObject(m, "FEATURE_ASYNC_REPLIES",   PyLong_FromLong(GENSEC_FEATURE_ASYNC_REPLIES));
728         PyModule_AddObject(m, "FEATURE_DATAGRAM_MODE",   PyLong_FromLong(GENSEC_FEATURE_DATAGRAM_MODE));
729         PyModule_AddObject(m, "FEATURE_SIGN_PKT_HEADER", PyLong_FromLong(GENSEC_FEATURE_SIGN_PKT_HEADER));
730         PyModule_AddObject(m, "FEATURE_NEW_SPNEGO",      PyLong_FromLong(GENSEC_FEATURE_NEW_SPNEGO));
731
732         Py_INCREF(&Py_Security);
733         PyModule_AddObject(m, "Security", (PyObject *)&Py_Security);
734
735         return m;
736 }