#include "includes.h"
#include "utils/net.h"
-
-/* dump sam database via samsync rpc calls */
-NTSTATUS rpc_samdump_internals(struct net_context *c,
- const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv)
-{
- struct samsync_context *ctx = NULL;
- NTSTATUS status;
-
- status = libnet_samsync_init_context(mem_ctx,
- domain_sid,
- &ctx);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- ctx->mode = NET_SAMSYNC_MODE_DUMP;
- ctx->cli = pipe_hnd;
- ctx->delta_fn = display_sam_entries;
- ctx->domain_name = domain_name;
-
- libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
-
- libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
-
- libnet_samsync(SAM_DATABASE_PRIVS, ctx);
-
- TALLOC_FREE(ctx);
-
- return NT_STATUS_OK;
-}
+#include "../librpc/gen_ndr/ndr_netlogon.h"
+#include "../librpc/gen_ndr/ndr_drsuapi.h"
+#include "libnet/libnet_dssync.h"
+#include "../libcli/security/security.h"
+#include "passdb/machine_sid.h"
/**
* Basic usage function for 'net rpc vampire'
int rpc_vampire_usage(struct net_context *c, int argc, const char **argv)
{
- d_printf("net rpc vampire ([ldif [<ldif-filename>] | [keytab] [<keytab-filename]) [options]\n"
- "\t to pull accounts from a remote PDC where we are a BDC\n"
- "\t\t no args puts accounts in local passdb from smb.conf\n"
- "\t\t ldif - put accounts in ldif format (file defaults to "
- "/tmp/tmp.ldif)\n"
- "\t\t keytab - put account passwords in krb5 keytab (defaults "
- "to system keytab)\n");
+ d_printf(_("net rpc vampire ([ldif [<ldif-filename>] | [keytab] "
+ "[<keytab-filename]) [options]\n"
+ "\t to pull accounts from a remote PDC where we are a BDC\n"
+ "\t\t no args puts accounts in local passdb from smb.conf\n"
+ "\t\t ldif - put accounts in ldif format (file defaults to "
+ "/tmp/tmp.ldif)\n"
+ "\t\t keytab - put account passwords in krb5 keytab "
+ "(defaults to system keytab)\n"));
net_common_flags_usage(c, argc, argv);
return -1;
}
-
-/* dump sam database via samsync rpc calls */
-NTSTATUS rpc_vampire_internals(struct net_context *c,
- const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv)
+static NTSTATUS rpc_vampire_ds_internals(struct net_context *c,
+ const struct dom_sid *domain_sid,
+ const char *domain_name,
+ struct cli_state *cli,
+ struct rpc_pipe_client *pipe_hnd,
+ TALLOC_CTX *mem_ctx,
+ int argc,
+ const char **argv)
{
- NTSTATUS result;
- struct samsync_context *ctx = NULL;
-
- if (!sid_equal(domain_sid, get_global_sam_sid())) {
- d_printf("Cannot import users from %s at this time, "
- "as the current domain:\n\t%s: %s\nconflicts "
- "with the remote domain\n\t%s: %s\n"
- "Perhaps you need to set: \n\n\tsecurity=user\n\t"
- "workgroup=%s\n\n in your smb.conf?\n",
+ NTSTATUS status;
+ struct dssync_context *ctx = NULL;
+
+ if (!dom_sid_equal(domain_sid, get_global_sam_sid())) {
+ struct dom_sid_buf buf1, buf2;
+ d_printf(_("Cannot import users from %s at this time, "
+ "as the current domain:\n\t%s: %s\nconflicts "
+ "with the remote domain\n\t%s: %s\n"
+ "Perhaps you need to set: \n\n\tsecurity=user\n\t"
+ "workgroup=%s\n\n in your smb.conf?\n"),
domain_name,
get_global_sam_name(),
- sid_string_dbg(get_global_sam_sid()),
+ dom_sid_str_buf(get_global_sam_sid(), &buf1),
domain_name,
- sid_string_dbg(domain_sid),
+ dom_sid_str_buf(domain_sid, &buf2),
domain_name);
return NT_STATUS_UNSUCCESSFUL;
}
- result = libnet_samsync_init_context(mem_ctx,
- domain_sid,
- &ctx);
- if (!NT_STATUS_IS_OK(result)) {
- return result;
- }
-
- ctx->mode = NET_SAMSYNC_MODE_FETCH_PASSDB;
- ctx->cli = pipe_hnd;
- ctx->delta_fn = fetch_sam_entries;
- ctx->domain_name = domain_name;
-
- /* fetch domain */
- result = libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
-
- if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
- d_fprintf(stderr, "%s\n", ctx->error_message);
- goto fail;
- }
-
- if (ctx->result_message) {
- d_fprintf(stdout, "%s\n", ctx->result_message);
- }
-
- /* fetch builtin */
- ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
- ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
- result = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
-
- if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
- d_fprintf(stderr, "%s\n", ctx->error_message);
- goto fail;
- }
-
- if (ctx->result_message) {
- d_fprintf(stdout, "%s\n", ctx->result_message);
- }
-
- fail:
- TALLOC_FREE(ctx);
- return result;
-}
-
-NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
- const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv)
-{
- NTSTATUS status;
- struct samsync_context *ctx = NULL;
-
- status = libnet_samsync_init_context(mem_ctx,
- domain_sid,
- &ctx);
+ status = libnet_dssync_init_context(mem_ctx,
+ &ctx);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- if (argc >= 1) {
- ctx->output_filename = argv[0];
- }
-
- ctx->mode = NET_SAMSYNC_MODE_FETCH_LDIF;
ctx->cli = pipe_hnd;
- ctx->delta_fn = fetch_sam_entries_ldif;
ctx->domain_name = domain_name;
+ ctx->ops = &libnet_dssync_passdb_ops;
- /* fetch domain */
- status = libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
-
- if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
- d_fprintf(stderr, "%s\n", ctx->error_message);
- goto fail;
- }
-
- if (ctx->result_message) {
- d_fprintf(stdout, "%s\n", ctx->result_message);
- }
-
- /* fetch builtin */
- ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
- ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
- status = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
-
+ status = libnet_dssync(mem_ctx, ctx);
if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
d_fprintf(stderr, "%s\n", ctx->error_message);
- goto fail;
+ goto out;
}
if (ctx->result_message) {
d_fprintf(stdout, "%s\n", ctx->result_message);
}
- fail:
+ out:
TALLOC_FREE(ctx);
+
return status;
}
-int rpc_vampire_ldif(struct net_context *c, int argc, const char **argv)
+int rpc_vampire_passdb(struct net_context *c, int argc, const char **argv)
{
+ int ret = 0;
+ NTSTATUS status;
+ struct cli_state *cli = NULL;
+ struct net_dc_info dc_info;
+
if (c->display_usage) {
- d_printf("Usage\n"
- "net rpc vampire ldif\n"
- " Dump remote SAM database to LDIF file or stdout\n");
+ d_printf( "%s\n"
+ "net rpc vampire passdb\n"
+ " %s\n",
+ _("Usage:"),
+ _("Dump remote SAM database to passdb"));
return 0;
}
- return run_rpc_command(c, NULL, PI_NETLOGON, 0, rpc_vampire_ldif_internals,
- argc, argv);
-}
-
-
-NTSTATUS rpc_vampire_keytab_internals(struct net_context *c,
- const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv)
-{
- NTSTATUS status;
- struct samsync_context *ctx = NULL;
-
- status = libnet_samsync_init_context(mem_ctx,
- domain_sid,
- &ctx);
+ status = net_make_ipc_connection(c, 0, &cli);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ return -1;
}
- if (argc >= 1) {
- ctx->output_filename = argv[0];
+ status = net_scan_dc(c, cli, &dc_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ return -1;
}
- ctx->mode = NET_SAMSYNC_MODE_FETCH_KEYTAB;
- ctx->cli = pipe_hnd;
- ctx->delta_fn = fetch_sam_entries_keytab;
- ctx->domain_name = domain_name;
- ctx->username = c->opt_user_name;
- ctx->password = c->opt_password;
-
- /* fetch domain */
- status = libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
-
- if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
- d_fprintf(stderr, "%s\n", ctx->error_message);
- goto out;
+ if (!dc_info.is_ad) {
+ printf(_("DC is not running Active Directory, exiting\n"));
+ return -1;
}
- if (ctx->result_message) {
- d_fprintf(stdout, "%s\n", ctx->result_message);
+ if (!c->opt_force) {
+ d_printf( "%s\n"
+ "net rpc vampire passdb\n"
+ " %s\n",
+ _("Usage:"),
+ _("Should not be used against Active Directory, maybe use --force"));
+ return -1;
}
- out:
- TALLOC_FREE(ctx);
-
- return status;
+ ret = run_rpc_command(c, cli, &ndr_table_drsuapi,
+ NET_FLAGS_SEAL | NET_FLAGS_TCP,
+ rpc_vampire_ds_internals, argc, argv);
+ return ret;
}
-NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c,
- const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv)
+static NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c,
+ const struct dom_sid *domain_sid,
+ const char *domain_name,
+ struct cli_state *cli,
+ struct rpc_pipe_client *pipe_hnd,
+ TALLOC_CTX *mem_ctx,
+ int argc,
+ const char **argv)
{
NTSTATUS status;
struct dssync_context *ctx = NULL;
return status;
}
- if (argc >= 1) {
+ ctx->force_full_replication = c->opt_force_full_repl ? true : false;
+ ctx->clean_old_entries = c->opt_clean_old_entries ? true : false;
+
+ if (argc < 1) {
+ /* the caller should ensure that a filename is provided */
+ return NT_STATUS_INVALID_PARAMETER;
+ } else {
ctx->output_filename = argv[0];
}
+ if (argc >= 2) {
+ ctx->object_dns = &argv[1];
+ ctx->object_count = argc - 1;
+ ctx->single_object_replication = c->opt_single_obj_repl ? true
+ : false;
+ }
+
ctx->cli = pipe_hnd;
ctx->domain_name = domain_name;
- ctx->processing_fn = libnet_dssync_dump_keytab;
+ ctx->ops = &libnet_dssync_keytab_ops;
status = libnet_dssync(mem_ctx, ctx);
if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
int rpc_vampire_keytab(struct net_context *c, int argc, const char **argv)
{
int ret = 0;
-
- if (c->display_usage) {
- d_printf("Usage\n"
- "net rpc vampire keytab\n"
- " Dump remote SAM database to Kerberos keytab file\n");
+ NTSTATUS status;
+ struct cli_state *cli = NULL;
+ struct net_dc_info dc_info;
+
+ if (c->display_usage || (argc < 1)) {
+ d_printf("%s\n%s",
+ _("Usage:"),
+ _("net rpc vampire keytab <keytabfile>\n"
+ " Dump remote SAM database to Kerberos keytab "
+ "file\n"));
return 0;
}
- ret = run_rpc_command(c, NULL, PI_DRSUAPI, NET_FLAGS_SEAL,
- rpc_vampire_keytab_ds_internals, argc, argv);
- if (ret == 0) {
- return 0;
+ status = net_make_ipc_connection(c, 0, &cli);
+ if (!NT_STATUS_IS_OK(status)) {
+ return -1;
+ }
+
+ status = net_scan_dc(c, cli, &dc_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ return -1;
}
- return run_rpc_command(c, NULL, PI_NETLOGON, 0, rpc_vampire_keytab_internals,
- argc, argv);
+ if (!dc_info.is_ad) {
+ printf(_("DC is not running Active Directory, exiting\n"));
+ return -1;
+ }
+
+ ret = run_rpc_command(c, cli, &ndr_table_drsuapi,
+ NET_FLAGS_SEAL | NET_FLAGS_TCP,
+ rpc_vampire_keytab_ds_internals, argc, argv);
+ return ret;
}