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 struct dom_sid_buf buf1
, buf2
;
72 d_printf(_("Cannot import users from %s at this time, "
73 "as the current domain:\n\t%s: %s\nconflicts "
74 "with the remote domain\n\t%s: %s\n"
75 "Perhaps you need to set: \n\n\tsecurity=user\n\t"
76 "workgroup=%s\n\n in your smb.conf?\n"),
78 get_global_sam_name(),
79 dom_sid_str_buf(get_global_sam_sid(), &buf1
),
81 dom_sid_str_buf(domain_sid
, &buf2
),
83 return NT_STATUS_UNSUCCESSFUL
;
86 status
= libnet_dssync_init_context(mem_ctx
,
88 if (!NT_STATUS_IS_OK(status
)) {
93 ctx
->domain_name
= domain_name
;
94 ctx
->ops
= &libnet_dssync_passdb_ops
;
96 status
= libnet_dssync(mem_ctx
, ctx
);
97 if (!NT_STATUS_IS_OK(status
) && ctx
->error_message
) {
98 d_fprintf(stderr
, "%s\n", ctx
->error_message
);
102 if (ctx
->result_message
) {
103 d_fprintf(stdout
, "%s\n", ctx
->result_message
);
112 int rpc_vampire_passdb(struct net_context
*c
, int argc
, const char **argv
)
116 struct cli_state
*cli
= NULL
;
117 struct net_dc_info dc_info
;
119 if (c
->display_usage
) {
121 "net rpc vampire passdb\n"
124 _("Dump remote SAM database to passdb"));
128 status
= net_make_ipc_connection(c
, 0, &cli
);
129 if (!NT_STATUS_IS_OK(status
)) {
133 status
= net_scan_dc(c
, cli
, &dc_info
);
134 if (!NT_STATUS_IS_OK(status
)) {
138 if (!dc_info
.is_ad
) {
139 printf(_("DC is not running Active Directory, exiting\n"));
145 "net rpc vampire passdb\n"
148 _("Should not be used against Active Directory, maybe use --force"));
152 ret
= run_rpc_command(c
, cli
, &ndr_table_drsuapi
,
153 NET_FLAGS_SEAL
| NET_FLAGS_TCP
,
154 rpc_vampire_ds_internals
, argc
, argv
);
158 static NTSTATUS
rpc_vampire_keytab_ds_internals(struct net_context
*c
,
159 const struct dom_sid
*domain_sid
,
160 const char *domain_name
,
161 struct cli_state
*cli
,
162 struct rpc_pipe_client
*pipe_hnd
,
168 struct dssync_context
*ctx
= NULL
;
170 status
= libnet_dssync_init_context(mem_ctx
,
172 if (!NT_STATUS_IS_OK(status
)) {
176 ctx
->force_full_replication
= c
->opt_force_full_repl
? true : false;
177 ctx
->clean_old_entries
= c
->opt_clean_old_entries
? true : false;
180 /* the caller should ensure that a filename is provided */
181 return NT_STATUS_INVALID_PARAMETER
;
183 ctx
->output_filename
= argv
[0];
187 ctx
->object_dns
= &argv
[1];
188 ctx
->object_count
= argc
- 1;
189 ctx
->single_object_replication
= c
->opt_single_obj_repl
? true
194 ctx
->domain_name
= domain_name
;
195 ctx
->ops
= &libnet_dssync_keytab_ops
;
197 status
= libnet_dssync(mem_ctx
, ctx
);
198 if (!NT_STATUS_IS_OK(status
) && ctx
->error_message
) {
199 d_fprintf(stderr
, "%s\n", ctx
->error_message
);
203 if (ctx
->result_message
) {
204 d_fprintf(stdout
, "%s\n", ctx
->result_message
);
214 * Basic function for 'net rpc vampire keytab'
216 * @param c A net_context structure
217 * @param argc Standard main() style argc
218 * @param argc Standard main() style argv. Initial components are already
222 int rpc_vampire_keytab(struct net_context
*c
, int argc
, const char **argv
)
226 struct cli_state
*cli
= NULL
;
227 struct net_dc_info dc_info
;
229 if (c
->display_usage
|| (argc
< 1)) {
232 _("net rpc vampire keytab <keytabfile>\n"
233 " Dump remote SAM database to Kerberos keytab "
238 status
= net_make_ipc_connection(c
, 0, &cli
);
239 if (!NT_STATUS_IS_OK(status
)) {
243 status
= net_scan_dc(c
, cli
, &dc_info
);
244 if (!NT_STATUS_IS_OK(status
)) {
248 if (!dc_info
.is_ad
) {
249 printf(_("DC is not running Active Directory, exiting\n"));
253 ret
= run_rpc_command(c
, cli
, &ndr_table_drsuapi
,
254 NET_FLAGS_SEAL
| NET_FLAGS_TCP
,
255 rpc_vampire_keytab_ds_internals
, argc
, argv
);