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"
27 #include "param/param.h"
28 #include "lib/events/events.h"
30 static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
32 d_printf("net samdump keytab <keytab>\n");
36 static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
38 d_printf("Dumps kerberos keys of a domain into a keytab.\n");
42 static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv)
45 struct libnet_context *libnetctx;
46 struct libnet_SamDump_keytab r;
50 return net_samdump_keytab_usage(ctx, argc, argv);
53 r.in.keytab_name = argv[0];
57 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
61 libnetctx->cred = ctx->credentials;
63 r.out.error_string = NULL;
64 r.in.machine_account = NULL;
65 r.in.binding_string = NULL;
67 status = libnet_SamDump_keytab(libnetctx, ctx, &r);
68 if (!NT_STATUS_IS_OK(status)) {
69 DEBUG(0,("libnet_SamDump returned %s: %s\n",
75 talloc_free(libnetctx);
80 /* main function table */
81 static const struct net_functable net_samdump_functable[] = {
82 {"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
83 {NULL, NULL, NULL, NULL}
86 int net_samdump(struct net_context *ctx, int argc, const char **argv)
89 struct libnet_context *libnetctx;
90 struct libnet_SamDump r;
98 rc = net_run_function(ctx, argc, argv, net_samdump_functable,
103 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
107 libnetctx->cred = ctx->credentials;
109 r.out.error_string = NULL;
110 r.in.machine_account = NULL;
111 r.in.binding_string = NULL;
113 status = libnet_SamDump(libnetctx, ctx, &r);
114 if (!NT_STATUS_IS_OK(status)) {
115 DEBUG(0,("libnet_SamDump returned %s: %s\n",
117 r.out.error_string));
121 talloc_free(libnetctx);
126 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
128 d_printf("net samdump\n");
129 d_printf("net samdump keytab <keytab>\n");
133 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
135 d_printf("Dumps the sam of the domain we are joined to.\n");
139 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv)
142 struct libnet_context *libnetctx;
143 struct libnet_samsync_ldb r;
145 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
149 libnetctx->cred = ctx->credentials;
151 r.out.error_string = NULL;
152 r.in.machine_account = NULL;
153 r.in.binding_string = NULL;
155 /* Needed to override the ACLs on ldb */
156 r.in.session_info = system_session(libnetctx, ctx->lp_ctx);
158 status = libnet_samsync_ldb(libnetctx, libnetctx, &r);
159 if (!NT_STATUS_IS_OK(status)) {
160 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
162 r.out.error_string));
166 talloc_free(libnetctx);
171 int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv)
173 d_printf("net samsync\n");
177 int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv)
179 d_printf("Synchronise into the local ldb the SAM of a domain.\n");