s3-waf: Create a registry private library.
[Samba.git] / source4 / samba_tool / vampire.c
blob7f16c82668b61918a8c5c2ca00ab5abb65aeff30
1 /*
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/>.
22 #include "includes.h"
23 #include "samba_tool/samba_tool.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/samr.h"
26 #include "auth/auth.h"
27 #include "libcli/security/security.h"
28 #include "param/param.h"
29 #include "lib/events/events.h"
31 /* main function table */
32 static const struct net_functable net_samdump_functable[] = {
33 {NULL, NULL, NULL, NULL}
36 int net_samdump(struct net_context *ctx, int argc, const char **argv)
38 NTSTATUS status;
39 struct libnet_context *libnetctx;
40 struct libnet_SamDump r;
41 int rc;
43 switch (argc) {
44 case 0:
45 break;
46 case 1:
47 default:
48 rc = net_run_function(ctx, argc, argv, net_samdump_functable,
49 net_samdump_usage);
50 return rc;
53 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
54 if (!libnetctx) {
55 return -1;
57 libnetctx->cred = ctx->credentials;
59 r.out.error_string = NULL;
60 r.in.machine_account = NULL;
61 r.in.binding_string = NULL;
63 status = libnet_SamDump(libnetctx, ctx, &r);
64 if (!NT_STATUS_IS_OK(status)) {
65 DEBUG(0,("libnet_SamDump returned %s: %s\n",
66 nt_errstr(status),
67 r.out.error_string));
68 return -1;
71 talloc_free(libnetctx);
73 return 0;
76 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
78 d_printf("samba-tool samdump\n");
79 return 0;
82 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
84 d_printf("Dumps the sam of the domain we are joined to.\n");
85 return 0;
88 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv)
90 NTSTATUS status;
91 struct libnet_context *libnetctx;
92 struct libnet_samsync_ldb r;
94 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
95 if (!libnetctx) {
96 return -1;
98 libnetctx->cred = ctx->credentials;
100 r.out.error_string = NULL;
101 r.in.machine_account = NULL;
102 r.in.binding_string = NULL;
104 /* Needed to override the ACLs on ldb */
105 r.in.session_info = system_session(ctx->lp_ctx);
107 status = libnet_samsync_ldb(libnetctx, libnetctx, &r);
108 if (!NT_STATUS_IS_OK(status)) {
109 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
110 nt_errstr(status),
111 r.out.error_string));
112 return -1;
115 talloc_free(libnetctx);
117 return 0;
120 int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv)
122 d_printf("samba-tool samsync\n");
123 return 0;
126 int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv)
128 d_printf("Synchronise into the local ldb the SAM of a domain.\n");
129 return 0;