s4:kerberos Add 'net export keytab' command for wireshark decryption
[samba.git] / source4 / utils / net / net_export_keytab.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    Distributed SMB/CIFS Server Management Utility 
4
5    Copyright (C) 2004 Stefan Metzmacher <metze@samba.org>
6    Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org>
7
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "utils/net/net.h"
24 #include "libnet/libnet.h"
25 #include "param/param.h"
26
27 static int net_export_keytab_usage(struct net_context *ctx, int argc, const char **argv)
28 {
29         d_printf("net export keytab <keytab>\n");
30         return 0;       
31 }
32
33 static int net_export_keytab_help(struct net_context *ctx, int argc, const char **argv)
34 {
35         d_printf("Dumps kerberos keys of the domain into a keytab.\n");
36         return 0;       
37 }
38
39 static int net_export_keytab(struct net_context *ctx, int argc, const char **argv) 
40 {
41         NTSTATUS status;
42         struct libnet_context *libnetctx;
43         struct libnet_export_keytab r;
44
45         switch (argc) {
46         case 0:
47                 return net_export_keytab_usage(ctx, argc, argv);
48                 break;
49         case 1:
50                 r.in.keytab_name = argv[0];
51                 break;
52         }
53
54         libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
55         if (!libnetctx) {
56                 return -1;      
57         }
58         libnetctx->cred = ctx->credentials;
59
60         r.out.error_string = NULL;
61
62         status = libnet_export_keytab(libnetctx, ctx, &r);
63         if (!NT_STATUS_IS_OK(status)) {
64                 DEBUG(0,("libnet_export_keytab returned %s: %s\n",
65                          nt_errstr(status),
66                          r.out.error_string));
67                 return -1;
68         }
69
70         talloc_free(libnetctx);
71
72         return 0;
73 }
74
75 /* main function table */
76 static const struct net_functable net_export_functable[] = {
77         {"keytab", "dump keys into a keytab\n", net_export_keytab, net_export_keytab_usage},
78         {NULL, NULL, NULL, NULL}
79 };
80
81 int net_export(struct net_context *ctx, int argc, const char **argv) 
82 {
83         int rc;
84
85         switch (argc) {
86         case 0:
87                 rc = net_export_usage(ctx, argc, argv);
88                 return rc;
89         case 1:
90         default:
91                 rc = net_run_function(ctx, argc, argv, net_export_functable, 
92                                       net_export_usage);
93                 return rc;
94         }
95
96         return 0;
97 }
98
99 int net_export_usage(struct net_context *ctx, int argc, const char **argv)
100 {
101         d_printf("net export keytab <keytab>\n");
102         return 0;       
103 }
104
105 int net_export_help(struct net_context *ctx, int argc, const char **argv)
106 {
107         d_printf("Dumps the sam of the domain we are joined to.\n");
108         return 0;       
109 }
110