summaryrefslogtreecommitdiff
path: root/source4/libnet
diff options
context:
space:
mode:
authorAlexander Bokovoy <ab@samba.org>2012-04-10 12:09:20 +0300
committerAndreas Schneider <asn@cryptomilk.org>2012-04-12 15:23:19 +0200
commitbcc16f191175740f200c12925b63d45478f06454 (patch)
treec61461de3ab2d0d5af71ae73e1028deab59cc3d0 /source4/libnet
parentdda0531aae70e78e815fda8c594213369e76a847 (diff)
downloadsamba-bcc16f191175740f200c12925b63d45478f06454.tar.gz
samba-bcc16f191175740f200c12925b63d45478f06454.tar.bz2
samba-bcc16f191175740f200c12925b63d45478f06454.zip
s4-libnet: split export_keytab in a separate python module to avoid pulling in HDB dependency
Signed-off-by: Andreas Schneider <asn@samba.org> Autobuild-User: Andreas Schneider <asn@cryptomilk.org> Autobuild-Date: Thu Apr 12 15:23:19 CEST 2012 on sn-devel-104
Diffstat (limited to 'source4/libnet')
-rw-r--r--source4/libnet/libnet.h4
-rw-r--r--source4/libnet/libnet_export_keytab.c21
-rw-r--r--source4/libnet/libnet_export_keytab.h3
-rw-r--r--source4/libnet/py_net.c45
-rw-r--r--source4/libnet/py_net.h24
-rw-r--r--source4/libnet/py_net_dckeytab.c106
-rw-r--r--source4/libnet/wscript_build9
7 files changed, 164 insertions, 48 deletions
diff --git a/source4/libnet/libnet.h b/source4/libnet/libnet.h
index 4e55ed05f5..41ddbea682 100644
--- a/source4/libnet/libnet.h
+++ b/source4/libnet/libnet.h
@@ -17,6 +17,8 @@
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 LIBNET_H
+#define LIBNET_H
#include "librpc/gen_ndr/misc.h"
@@ -80,5 +82,5 @@ struct libnet_context {
#include "libnet/libnet_share.h"
#include "libnet/libnet_lookup.h"
#include "libnet/libnet_domain.h"
-#include "libnet/libnet_export_keytab.h"
#include "libnet/libnet_proto.h"
+#endif
diff --git a/source4/libnet/libnet_export_keytab.c b/source4/libnet/libnet_export_keytab.c
index 593f5fd5d9..1726d14228 100644
--- a/source4/libnet/libnet_export_keytab.c
+++ b/source4/libnet/libnet_export_keytab.c
@@ -1,9 +1,28 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
+
+ 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 "system/kerberos.h"
#include "auth/kerberos/kerberos.h"
#include <hdb.h>
#include "kdc/samba_kdc.h"
-#include "libnet/libnet.h"
+#include "libnet/libnet_export_keytab.h"
NTSTATUS libnet_export_keytab(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_export_keytab *r)
{
diff --git a/source4/libnet/libnet_export_keytab.h b/source4/libnet/libnet_export_keytab.h
index 289d19c7a6..2b4bdcde49 100644
--- a/source4/libnet/libnet_export_keytab.h
+++ b/source4/libnet/libnet_export_keytab.h
@@ -16,6 +16,8 @@
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 "libnet/libnet.h"
struct libnet_export_keytab {
struct {
@@ -27,3 +29,4 @@ struct libnet_export_keytab {
} out;
};
+NTSTATUS libnet_export_keytab(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_export_keytab *r);
diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index c710680b39..acb0a37759 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -32,16 +32,10 @@
#include "libcli/resolve/resolve.h"
#include "libcli/finddc.h"
#include "dsdb/samdb/samdb.h"
+#include "py_net.h"
void initnet(void);
-typedef struct {
- PyObject_HEAD
- TALLOC_CTX *mem_ctx;
- struct libnet_context *libnet_ctx;
- struct tevent_context *ev;
-} py_net_Object;
-
static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObject *kwargs)
{
struct libnet_Join_member r;
@@ -187,42 +181,6 @@ static const char py_net_set_password_doc[] = "set_password(account_name, domain
" newpassword=new_pass)\n";
-static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObject *kwargs)
-{
- struct libnet_export_keytab r;
- TALLOC_CTX *mem_ctx;
- const char *kwnames[] = { "keytab", "principal", NULL };
- NTSTATUS status;
- r.in.principal = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z:export_keytab", discard_const_p(char *, kwnames),
- &r.in.keytab_name,
- &r.in.principal)) {
- return NULL;
- }
-
- mem_ctx = talloc_new(self->mem_ctx);
- if (mem_ctx == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
-
- status = libnet_export_keytab(self->libnet_ctx, mem_ctx, &r);
- if (NT_STATUS_IS_ERR(status)) {
- PyErr_SetString(PyExc_RuntimeError,
- r.out.error_string?r.out.error_string:nt_errstr(status));
- talloc_free(mem_ctx);
- return NULL;
- }
-
- talloc_free(mem_ctx);
-
- Py_RETURN_NONE;
-}
-
-static const char py_net_export_keytab_doc[] = "export_keytab(keytab, name)\n\n"
-"Export the DC keytab to a keytab file.";
-
static PyObject *py_net_time(py_net_Object *self, PyObject *args, PyObject *kwargs)
{
const char *kwnames[] = { "server_name", NULL };
@@ -644,7 +602,6 @@ static PyMethodDef net_obj_methods[] = {
{"join_member", (PyCFunction)py_net_join_member, METH_VARARGS|METH_KEYWORDS, py_net_join_member_doc},
{"change_password", (PyCFunction)py_net_change_password, METH_VARARGS|METH_KEYWORDS, py_net_change_password_doc},
{"set_password", (PyCFunction)py_net_set_password, METH_VARARGS|METH_KEYWORDS, py_net_set_password_doc},
- {"export_keytab", (PyCFunction)py_net_export_keytab, METH_VARARGS|METH_KEYWORDS, py_net_export_keytab_doc},
{"time", (PyCFunction)py_net_time, METH_VARARGS|METH_KEYWORDS, py_net_time_doc},
{"create_user", (PyCFunction)py_net_user_create, METH_VARARGS|METH_KEYWORDS, py_net_create_user_doc},
{"delete_user", (PyCFunction)py_net_user_delete, METH_VARARGS|METH_KEYWORDS, py_net_delete_user_doc},
diff --git a/source4/libnet/py_net.h b/source4/libnet/py_net.h
new file mode 100644
index 0000000000..2894d47fe0
--- /dev/null
+++ b/source4/libnet/py_net.h
@@ -0,0 +1,24 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba python bindings to libnet library
+
+ 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/>.
+*/
+
+typedef struct {
+ PyObject_HEAD
+ TALLOC_CTX *mem_ctx;
+ struct libnet_context *libnet_ctx;
+ struct tevent_context *ev;
+} py_net_Object;
diff --git a/source4/libnet/py_net_dckeytab.c b/source4/libnet/py_net_dckeytab.c
new file mode 100644
index 0000000000..efb9267705
--- /dev/null
+++ b/source4/libnet/py_net_dckeytab.c
@@ -0,0 +1,106 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008-2010
+ Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
+ Copyright (C) Alexander Bokovoy <ab@samba.org> 2012
+
+ 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 <Python.h>
+#include "includes.h"
+#include "py_net.h"
+#include "libnet_export_keytab.h"
+
+void initdckeytab(void);
+
+static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObject *kwargs)
+{
+ struct libnet_export_keytab r;
+ TALLOC_CTX *mem_ctx;
+ const char *kwnames[] = { "keytab", "principal", NULL };
+ NTSTATUS status;
+ r.in.principal = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z:export_keytab", discard_const_p(char *, kwnames),
+ &r.in.keytab_name,
+ &r.in.principal)) {
+ return NULL;
+ }
+
+ mem_ctx = talloc_new(self->mem_ctx);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ status = libnet_export_keytab(self->libnet_ctx, mem_ctx, &r);
+ if (NT_STATUS_IS_ERR(status)) {
+ PyErr_SetString(PyExc_RuntimeError,
+ r.out.error_string?r.out.error_string:nt_errstr(status));
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ talloc_free(mem_ctx);
+
+ Py_RETURN_NONE;
+}
+
+static const char py_net_export_keytab_doc[] = "export_keytab(keytab, name)\n\n"
+"Export the DC keytab to a keytab file.";
+
+static PyMethodDef export_keytab_method_table[] = {
+ {"export_keytab", (PyCFunction)py_net_export_keytab, METH_VARARGS|METH_KEYWORDS, py_net_export_keytab_doc},
+ { NULL, NULL, 0, NULL }
+};
+
+/*
+ * A fake Python module to inject export_keytab() method into existing samba.net.Net class.
+ * Python enforces that every loaded module actually creates Python module record in
+ * the global module table even if we don't really need that record. Thus, we initialize
+ * dckeytab module but never use it.
+ * */
+void initdckeytab(void)
+{
+ PyObject *m;
+ PyObject *Net;
+ PyObject *descr;
+ int ret;
+
+ m = Py_InitModule3("dckeytab", NULL, NULL);
+ if (m == NULL)
+ return;
+
+ m = PyImport_ImportModule("samba.net");
+ if (m == NULL)
+ return;
+
+ Net = (PyObject *)PyObject_GetAttrString(m, "Net");
+ if (Net == NULL)
+ return;
+
+ descr = PyDescr_NewMethod((PyTypeObject*)Net, &export_keytab_method_table[0]);
+ if (descr == NULL)
+ return;
+
+ ret = PyDict_SetItemString(((PyTypeObject*)Net)->tp_dict,
+ export_keytab_method_table[0].ml_name,
+ descr);
+ if (ret != -1) {
+ Py_DECREF(descr);
+ }
+}
diff --git a/source4/libnet/wscript_build b/source4/libnet/wscript_build
index a30a4c36b0..57e3160c8b 100644
--- a/source4/libnet/wscript_build
+++ b/source4/libnet/wscript_build
@@ -1,9 +1,9 @@
#!/usr/bin/env python
bld.SAMBA_LIBRARY('samba-net',
- source='libnet.c libnet_passwd.c libnet_time.c libnet_rpc.c libnet_join.c libnet_site.c libnet_become_dc.c libnet_unbecome_dc.c libnet_vampire.c libnet_samdump.c libnet_samsync_ldb.c libnet_user.c libnet_group.c libnet_share.c libnet_lookup.c libnet_domain.c userinfo.c groupinfo.c userman.c groupman.c prereq_domain.c libnet_samsync.c libnet_export_keytab.c',
+ source='libnet.c libnet_passwd.c libnet_time.c libnet_rpc.c libnet_join.c libnet_site.c libnet_become_dc.c libnet_unbecome_dc.c libnet_vampire.c libnet_samdump.c libnet_samsync_ldb.c libnet_user.c libnet_group.c libnet_share.c libnet_lookup.c libnet_domain.c userinfo.c groupinfo.c userman.c groupman.c prereq_domain.c libnet_samsync.c',
autoproto='libnet_proto.h',
- public_deps='samba-credentials dcerpc dcerpc-samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI cli_composite LIBCLI_RESOLVE LIBCLI_FINDDCS cli_cldap LIBCLI_FINDDCS gensec_schannel LIBCLI_AUTH ndr smbpasswdparser PROVISION LIBCLI_SAMSYNC HDB_SAMBA4 LIBTSOCKET com_err',
+ public_deps='samba-credentials dcerpc dcerpc-samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI cli_composite LIBCLI_RESOLVE LIBCLI_FINDDCS cli_cldap LIBCLI_FINDDCS gensec_schannel LIBCLI_AUTH ndr smbpasswdparser PROVISION LIBCLI_SAMSYNC LIBTSOCKET',
private_library=True
)
@@ -14,3 +14,8 @@ bld.SAMBA_PYTHON('python_net',
realname='samba/net.so'
)
+bld.SAMBA_PYTHON('python_dckeytab',
+ source='py_net_dckeytab.c libnet_export_keytab.c',
+ deps='pyrpc_util HDB_SAMBA4 com_err',
+ realname='samba/dckeytab.so'
+ )