2 Unix SMB/CIFS implementation.
3 dump the remote SAM using rpc samsync operations
5 Copyright (C) Andrew Tridgell 2002
6 Copyright (C) Tim Potter 2001,2002
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
8 Modified by Volker Lendecke 2002
9 Copyright (C) Jeremy Allison 2005.
10 Copyright (C) Guenther Deschner 2008.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "utils/net.h"
28 #include "../librpc/gen_ndr/ndr_netlogon.h"
29 #include "../librpc/gen_ndr/ndr_drsuapi.h"
30 #include "libnet/libnet_dssync.h"
31 #include "../libcli/security/security.h"
32 #include "passdb/machine_sid.h"
35 * Basic usage function for 'net rpc vampire'
37 * @param c A net_context structure
38 * @param argc Standard main() style argc
39 * @param argc Standard main() style argv. Initial components are already
43 int rpc_vampire_usage(struct net_context *c, int argc, const char **argv)
45 d_printf(_("net rpc vampire ([ldif [<ldif-filename>] | [keytab] "
46 "[<keytab-filename]) [options]\n"
47 "\t to pull accounts from a remote PDC where we are a BDC\n"
48 "\t\t no args puts accounts in local passdb from smb.conf\n"
49 "\t\t ldif - put accounts in ldif format (file defaults to "
51 "\t\t keytab - put account passwords in krb5 keytab "
52 "(defaults to system keytab)\n"));
54 net_common_flags_usage(c, argc, argv);
58 static NTSTATUS rpc_vampire_ds_internals(struct net_context *c,
59 const struct dom_sid *domain_sid,
60 const char *domain_name,
61 struct cli_state *cli,
62 struct rpc_pipe_client *pipe_hnd,
68 struct dssync_context *ctx = NULL;
70 if (!dom_sid_equal(domain_sid, get_global_sam_sid())) {
71 d_printf(_("Cannot import users from %s at this time, "
72 "as the current domain:\n\t%s: %s\nconflicts "
73 "with the remote domain\n\t%s: %s\n"
74 "Perhaps you need to set: \n\n\tsecurity=user\n\t"
75 "workgroup=%s\n\n in your smb.conf?\n"),
77 get_global_sam_name(),
78 sid_string_dbg(get_global_sam_sid()),
80 sid_string_dbg(domain_sid),
82 return NT_STATUS_UNSUCCESSFUL;
85 status = libnet_dssync_init_context(mem_ctx,
87 if (!NT_STATUS_IS_OK(status)) {
92 ctx->domain_name = domain_name;
93 ctx->ops = &libnet_dssync_passdb_ops;
95 status = libnet_dssync(mem_ctx, ctx);
96 if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
97 d_fprintf(stderr, "%s\n", ctx->error_message);
101 if (ctx->result_message) {
102 d_fprintf(stdout, "%s\n", ctx->result_message);
111 int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv)
115 struct cli_state *cli = NULL;
116 struct net_dc_info dc_info;
118 if (c->display_usage) {
120 "net rpc vampire passdb\n"
123 _("Dump remote SAM database to passdb"));
127 status = net_make_ipc_connection(c, 0, &cli);
128 if (!NT_STATUS_IS_OK(status)) {
132 status = net_scan_dc(c, cli, &dc_info);
133 if (!NT_STATUS_IS_OK(status)) {
137 if (!dc_info.is_ad) {
138 printf(_("DC is not running Active Directory, exiting\n"));
144 "net rpc vampire passdb\n"
147 _("Should not be used against Active Directory, maybe use --force"));
151 ret = run_rpc_command(c, cli, &ndr_table_drsuapi,
152 NET_FLAGS_SEAL | NET_FLAGS_TCP,
153 rpc_vampire_ds_internals, argc, argv);
157 static NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c,
158 const struct dom_sid *domain_sid,
159 const char *domain_name,
160 struct cli_state *cli,
161 struct rpc_pipe_client *pipe_hnd,
167 struct dssync_context *ctx = NULL;
169 status = libnet_dssync_init_context(mem_ctx,
171 if (!NT_STATUS_IS_OK(status)) {
175 ctx->force_full_replication = c->opt_force_full_repl ? true : false;
176 ctx->clean_old_entries = c->opt_clean_old_entries ? true : false;
179 /* the caller should ensure that a filename is provided */
180 return NT_STATUS_INVALID_PARAMETER;
182 ctx->output_filename = argv[0];
186 ctx->object_dns = &argv[1];
187 ctx->object_count = argc - 1;
188 ctx->single_object_replication = c->opt_single_obj_repl ? true
193 ctx->domain_name = domain_name;
194 ctx->ops = &libnet_dssync_keytab_ops;
196 status = libnet_dssync(mem_ctx, ctx);
197 if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
198 d_fprintf(stderr, "%s\n", ctx->error_message);
202 if (ctx->result_message) {
203 d_fprintf(stdout, "%s\n", ctx->result_message);
213 * Basic function for 'net rpc vampire keytab'
215 * @param c A net_context structure
216 * @param argc Standard main() style argc
217 * @param argc Standard main() style argv. Initial components are already
221 int rpc_vampire_keytab(struct net_context *c, int argc, const char **argv)
225 struct cli_state *cli = NULL;
226 struct net_dc_info dc_info;
228 if (c->display_usage || (argc < 1)) {
231 _("net rpc vampire keytab <keytabfile>\n"
232 " Dump remote SAM database to Kerberos keytab "
237 status = net_make_ipc_connection(c, 0, &cli);
238 if (!NT_STATUS_IS_OK(status)) {
242 status = net_scan_dc(c, cli, &dc_info);
243 if (!NT_STATUS_IS_OK(status)) {
247 if (!dc_info.is_ad) {
248 printf(_("DC is not running Active Directory, exiting\n"));
252 ret = run_rpc_command(c, cli, &ndr_table_drsuapi,
253 NET_FLAGS_SEAL | NET_FLAGS_TCP,
254 rpc_vampire_keytab_ds_internals, argc, argv);