2 Unix SMB/CIFS implementation.
3 dump the remote SAM using rpc samsync operations
5 Copyright (C) Guenther Deschner 2008.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libnet/libnet.h"
26 /****************************************************************
27 ****************************************************************/
29 static int keytab_close(struct libnet_keytab_context *ctx)
35 if (ctx->keytab && ctx->context) {
36 krb5_kt_close(ctx->context, ctx->keytab);
40 krb5_free_context(ctx->context);
44 ads_destroy(&ctx->ads);
52 /****************************************************************
53 ****************************************************************/
55 krb5_error_code libnet_keytab_init(TALLOC_CTX *mem_ctx,
56 const char *keytab_name,
57 struct libnet_keytab_context **ctx)
59 krb5_error_code ret = 0;
60 krb5_context context = NULL;
61 krb5_keytab keytab = NULL;
62 const char *keytab_string = NULL;
64 struct libnet_keytab_context *r;
66 r = TALLOC_ZERO_P(mem_ctx, struct libnet_keytab_context);
71 talloc_set_destructor(r, keytab_close);
73 initialize_krb5_error_table();
74 ret = krb5_init_context(&context);
76 DEBUG(1,("keytab_init: could not krb5_init_context: %s\n",
81 ret = smb_krb5_open_keytab(context, keytab_name, true, &keytab);
83 DEBUG(1,("keytab_init: smb_krb5_open_keytab failed (%s)\n",
85 krb5_free_context(context);
89 ret = smb_krb5_keytab_name(mem_ctx, context, keytab, &keytab_string);
91 krb5_kt_close(context, keytab);
92 krb5_free_context(context);
98 r->keytab_name = keytab_string;
105 /****************************************************************
106 ****************************************************************/
108 krb5_error_code libnet_keytab_add(struct libnet_keytab_context *ctx)
110 #if defined(ENCTYPE_ARCFOUR_HMAC)
111 krb5_error_code ret = 0;
112 krb5_enctype enctypes[2] = { ENCTYPE_ARCFOUR_HMAC, 0 };
115 for (i=0; i<ctx->count; i++) {
117 struct libnet_keytab_entry *entry = &ctx->entries[i];
120 password.data = (char *)entry->password.data;
121 password.length = entry->password.length;
123 ret = smb_krb5_kt_add_entry(ctx->context,
131 DEBUG(1,("libnet_keytab_add: "
132 "Failed to add entry to keytab file\n"));
140 #endif /* defined(ENCTYPE_ARCFOUR_HMAC) */
143 #endif /* HAVE_KRB5 */