2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
5 Copyright (C) 2004 Stefan Metzmacher <metze@samba.org>
6 Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org>
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 "utils/net/net.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/samr.h"
26 #include "auth/auth.h"
28 static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
30 d_printf("net samdump keytab <keytab>\n");
34 static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
36 d_printf("Dumps kerberos keys of a domain into a keytab.\n");
40 static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv)
43 struct libnet_context *libnetctx;
44 struct libnet_SamDump_keytab r;
48 return net_samdump_keytab_usage(ctx, argc, argv);
51 r.in.keytab_name = argv[0];
55 libnetctx = libnet_context_init(NULL);
59 libnetctx->cred = ctx->credentials;
61 r.out.error_string = NULL;
62 r.in.machine_account = NULL;
63 r.in.binding_string = NULL;
65 status = libnet_SamDump_keytab(libnetctx, ctx->mem_ctx, &r);
66 if (!NT_STATUS_IS_OK(status)) {
67 DEBUG(0,("libnet_SamDump returned %s: %s\n",
73 talloc_free(libnetctx);
78 /* main function table */
79 static const struct net_functable net_samdump_functable[] = {
80 {"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
81 {NULL, NULL, NULL, NULL}
84 int net_samdump(struct net_context *ctx, int argc, const char **argv)
87 struct libnet_context *libnetctx;
88 struct libnet_SamDump r;
96 rc = net_run_function(ctx, argc, argv, net_samdump_functable,
101 libnetctx = libnet_context_init(NULL);
105 libnetctx->cred = ctx->credentials;
107 r.out.error_string = NULL;
108 r.in.machine_account = NULL;
109 r.in.binding_string = NULL;
111 status = libnet_SamDump(libnetctx, ctx->mem_ctx, &r);
112 if (!NT_STATUS_IS_OK(status)) {
113 DEBUG(0,("libnet_SamDump returned %s: %s\n",
115 r.out.error_string));
119 talloc_free(libnetctx);
124 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
126 d_printf("net samdump\n");
127 d_printf("net samdump keytab <keytab>\n");
131 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
133 d_printf("Dumps the sam of the domain we are joined to.\n");
137 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv)
140 struct libnet_context *libnetctx;
141 struct libnet_samsync_ldb r;
143 libnetctx = libnet_context_init(NULL);
147 libnetctx->cred = ctx->credentials;
149 r.out.error_string = NULL;
150 r.in.machine_account = NULL;
151 r.in.binding_string = NULL;
153 /* Needed to override the ACLs on ldb */
154 r.in.session_info = system_session(libnetctx);
156 status = libnet_samsync_ldb(libnetctx, libnetctx, &r);
157 if (!NT_STATUS_IS_OK(status)) {
158 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
160 r.out.error_string));
164 talloc_free(libnetctx);
169 int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv)
171 d_printf("net samsync_ldb\n");
175 int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv)
177 d_printf("Synchronise into the local ldb the SAM of a domain.\n");