2 Unix SMB/CIFS implementation.
4 Minimal ktutil for selftest
6 Copyright (C) Ralph Boehme <slow@samba.org> 2016
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "krb5_wrap/krb5_samba.h"
25 static void smb_krb5_err(TALLOC_CTX
*mem_ctx
,
31 char *krb5_err_str
= smb_get_krb5_error_message(context
,
34 printf("%s: %s\n", msg
, krb5_err_str
? krb5_err_str
: "UNKOWN");
40 int main (int argc
, char **argv
)
42 TALLOC_CTX
*mem_ctx
= talloc_init("ktutil");
45 krb5_kt_cursor cursor
;
46 krb5_keytab_entry entry
;
48 char *keytab_name
= NULL
;
50 if (mem_ctx
== NULL
) {
51 printf("talloc_init() failed\n");
56 printf("Usage: %s KEYTAB\n", argv
[0]);
60 keytab_name
= argv
[1];
62 ret
= smb_krb5_init_context_common(&context
);
64 DBG_ERR("kerberos init context failed (%s)\n",
66 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_context");
69 ret
= smb_krb5_kt_open_relative(context
, keytab_name
, false, &keytab
);
71 smb_krb5_err(mem_ctx
, context
, 1, ret
, "open keytab");
74 ret
= krb5_kt_start_seq_get(context
, keytab
, &cursor
);
76 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_kt_start_seq_get");
79 for (ret
= krb5_kt_next_entry(context
, keytab
, &entry
, &cursor
);
81 ret
= krb5_kt_next_entry(context
, keytab
, &entry
, &cursor
))
83 char *principal
= NULL
;
84 char *enctype_str
= NULL
;
85 krb5_enctype enctype
= smb_krb5_kt_get_enctype_from_entry(&entry
);
87 ret
= smb_krb5_unparse_name(mem_ctx
,
92 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_enctype_to_string");
95 ret
= smb_krb5_enctype_to_string(context
,
99 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_enctype_to_string");
102 printf("%s (%s)\n", principal
, enctype_str
);
104 TALLOC_FREE(principal
);
105 SAFE_FREE(enctype_str
);
106 smb_krb5_kt_free_entry(context
, &entry
);
109 ret
= krb5_kt_end_seq_get(context
, keytab
, &cursor
);
111 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_kt_end_seq_get");
114 ret
= krb5_kt_close(context
, keytab
);
116 smb_krb5_err(mem_ctx
, context
, 1, ret
, "krb5_kt_close");
119 krb5_free_context(context
);
120 talloc_free(mem_ctx
);