2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008-2010
6 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
7 Copyright (C) Alexander Bokovoy <ab@samba.org> 2012
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "libnet_export_keytab.h"
28 void initdckeytab(void);
30 static PyObject
*py_net_export_keytab(py_net_Object
*self
, PyObject
*args
, PyObject
*kwargs
)
32 struct libnet_export_keytab r
;
34 const char *kwnames
[] = { "keytab", "principal", NULL
};
36 r
.in
.principal
= NULL
;
38 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "s|z:export_keytab", discard_const_p(char *, kwnames
),
44 mem_ctx
= talloc_new(self
->mem_ctx
);
45 if (mem_ctx
== NULL
) {
50 status
= libnet_export_keytab(self
->libnet_ctx
, mem_ctx
, &r
);
51 if (NT_STATUS_IS_ERR(status
)) {
52 PyErr_SetString(PyExc_RuntimeError
,
53 r
.out
.error_string
?r
.out
.error_string
:nt_errstr(status
));
63 static const char py_net_export_keytab_doc
[] = "export_keytab(keytab, name)\n\n"
64 "Export the DC keytab to a keytab file.";
66 static PyMethodDef export_keytab_method_table
[] = {
67 {"export_keytab", (PyCFunction
)py_net_export_keytab
, METH_VARARGS
|METH_KEYWORDS
, py_net_export_keytab_doc
},
68 { NULL
, NULL
, 0, NULL
}
72 * A fake Python module to inject export_keytab() method into existing samba.net.Net class.
73 * Python enforces that every loaded module actually creates Python module record in
74 * the global module table even if we don't really need that record. Thus, we initialize
75 * dckeytab module but never use it.
77 void initdckeytab(void)
84 m
= Py_InitModule3("dckeytab", NULL
, NULL
);
88 m
= PyImport_ImportModule("samba.net");
92 Net
= (PyObject
*)PyObject_GetAttrString(m
, "Net");
96 descr
= PyDescr_NewMethod((PyTypeObject
*)Net
, &export_keytab_method_table
[0]);
100 ret
= PyDict_SetItemString(((PyTypeObject
*)Net
)->tp_dict
,
101 export_keytab_method_table
[0].ml_name
,