util:ldb Allow multiple entries to be added in one LDIF snippit
[Samba/ekacnet.git] / source4 / libnet / libnet_export_keytab.c
bloba7006b4bf9d0d55ed8a8b8541f71f2d883bc2b79
1 #include "includes.h"
2 #include "system/kerberos.h"
3 #include "auth/kerberos/kerberos.h"
4 #include <hdb.h>
5 #include "kdc/hdb-samba4.h"
6 #include "libnet/libnet.h"
8 NTSTATUS libnet_export_keytab(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_export_keytab *r)
10 krb5_error_code ret;
11 struct smb_krb5_context *smb_krb5_context;
12 const char *from_keytab;
14 /* Register hdb-samba4 hooks for use as a keytab */
16 struct hdb_samba4_context *hdb_samba4_context = talloc(mem_ctx, struct hdb_samba4_context);
17 if (!hdb_samba4_context) {
18 return NT_STATUS_NO_MEMORY;
21 hdb_samba4_context->ev_ctx = ctx->event_ctx;
22 hdb_samba4_context->lp_ctx = ctx->lp_ctx;
24 from_keytab = talloc_asprintf(hdb_samba4_context, "HDB:samba4&%p", hdb_samba4_context);
25 if (!from_keytab) {
26 return NT_STATUS_NO_MEMORY;
29 ret = smb_krb5_init_context(ctx, ctx->event_ctx, ctx->lp_ctx, &smb_krb5_context);
30 if (ret) {
31 return NT_STATUS_NO_MEMORY;
34 ret = krb5_plugin_register(smb_krb5_context->krb5_context,
35 PLUGIN_TYPE_DATA, "hdb",
36 &hdb_samba4);
37 if(ret) {
38 return NT_STATUS_NO_MEMORY;
41 ret = krb5_kt_register(smb_krb5_context->krb5_context, &hdb_kt_ops);
42 if(ret) {
43 return NT_STATUS_NO_MEMORY;
46 ret = kt_copy(smb_krb5_context->krb5_context, from_keytab, r->in.keytab_name);
47 if(ret) {
48 r->out.error_string = smb_get_krb5_error_message(smb_krb5_context->krb5_context,
49 ret, mem_ctx);
50 return NT_STATUS_UNSUCCESSFUL;
52 return NT_STATUS_OK;