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 "libcli/security/security.h"
28 #include "param/param.h"
29 #include "lib/events/events.h"
31 static int net_samdump_keytab_usage(struct net_context
*ctx
, int argc
, const char **argv
)
33 d_printf("net samdump keytab <keytab>\n");
37 static int net_samdump_keytab_help(struct net_context
*ctx
, int argc
, const char **argv
)
39 d_printf("Dumps kerberos keys of a domain into a keytab.\n");
43 static int net_samdump_keytab(struct net_context
*ctx
, int argc
, const char **argv
)
46 struct libnet_context
*libnetctx
;
47 struct libnet_SamDump_keytab r
;
51 return net_samdump_keytab_usage(ctx
, argc
, argv
);
54 r
.in
.keytab_name
= argv
[0];
58 libnetctx
= libnet_context_init(ctx
->event_ctx
, ctx
->lp_ctx
);
62 libnetctx
->cred
= ctx
->credentials
;
64 r
.out
.error_string
= NULL
;
65 r
.in
.machine_account
= NULL
;
66 r
.in
.binding_string
= NULL
;
68 status
= libnet_SamDump_keytab(libnetctx
, ctx
, &r
);
69 if (!NT_STATUS_IS_OK(status
)) {
70 DEBUG(0,("libnet_SamDump returned %s: %s\n",
76 talloc_free(libnetctx
);
81 /* main function table */
82 static const struct net_functable net_samdump_functable
[] = {
83 {"keytab", "dump keys into a keytab\n", net_samdump_keytab
, net_samdump_keytab_usage
},
84 {NULL
, NULL
, NULL
, NULL
}
87 int net_samdump(struct net_context
*ctx
, int argc
, const char **argv
)
90 struct libnet_context
*libnetctx
;
91 struct libnet_SamDump r
;
99 rc
= net_run_function(ctx
, argc
, argv
, net_samdump_functable
,
104 libnetctx
= libnet_context_init(ctx
->event_ctx
, ctx
->lp_ctx
);
108 libnetctx
->cred
= ctx
->credentials
;
110 r
.out
.error_string
= NULL
;
111 r
.in
.machine_account
= NULL
;
112 r
.in
.binding_string
= NULL
;
114 status
= libnet_SamDump(libnetctx
, ctx
, &r
);
115 if (!NT_STATUS_IS_OK(status
)) {
116 DEBUG(0,("libnet_SamDump returned %s: %s\n",
118 r
.out
.error_string
));
122 talloc_free(libnetctx
);
127 int net_samdump_usage(struct net_context
*ctx
, int argc
, const char **argv
)
129 d_printf("net samdump\n");
130 d_printf("net samdump keytab <keytab>\n");
134 int net_samdump_help(struct net_context
*ctx
, int argc
, const char **argv
)
136 d_printf("Dumps the sam of the domain we are joined to.\n");
140 int net_samsync_ldb(struct net_context
*ctx
, int argc
, const char **argv
)
143 struct libnet_context
*libnetctx
;
144 struct libnet_samsync_ldb r
;
146 libnetctx
= libnet_context_init(ctx
->event_ctx
, ctx
->lp_ctx
);
150 libnetctx
->cred
= ctx
->credentials
;
152 r
.out
.error_string
= NULL
;
153 r
.in
.machine_account
= NULL
;
154 r
.in
.binding_string
= NULL
;
156 /* Needed to override the ACLs on ldb */
157 r
.in
.session_info
= system_session(ctx
->lp_ctx
);
159 status
= libnet_samsync_ldb(libnetctx
, libnetctx
, &r
);
160 if (!NT_STATUS_IS_OK(status
)) {
161 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
163 r
.out
.error_string
));
167 talloc_free(libnetctx
);
172 int net_samsync_ldb_usage(struct net_context
*ctx
, int argc
, const char **argv
)
174 d_printf("net samsync\n");
178 int net_samsync_ldb_help(struct net_context
*ctx
, int argc
, const char **argv
)
180 d_printf("Synchronise into the local ldb the SAM of a domain.\n");
184 int net_vampire(struct net_context
*ctx
, int argc
, const char **argv
)
187 struct libnet_context
*libnetctx
;
188 struct libnet_Vampire
*r
;
189 char *tmp
, *targetdir
= NULL
;
190 const char *domain_name
;
193 case 0: /* no args -> fail */
194 return net_vampire_usage(ctx
, argc
, argv
);
195 case 1: /* only DOMAIN */
196 tmp
= talloc_strdup(ctx
, argv
[0]);
198 case 2: /* domain and target dir */
199 tmp
= talloc_strdup(ctx
, argv
[0]);
200 targetdir
= talloc_strdup(ctx
, argv
[1]);
202 default: /* too many args -> fail */
203 return net_vampire_usage(ctx
, argc
, argv
);
208 libnetctx
= libnet_context_init(ctx
->event_ctx
, ctx
->lp_ctx
);
212 libnetctx
->cred
= ctx
->credentials
;
213 r
= talloc(ctx
, struct libnet_Vampire
);
217 /* prepare parameters for the vampire */
218 r
->in
.netbios_name
= lp_netbios_name(ctx
->lp_ctx
);
219 r
->in
.domain_name
= domain_name
;
220 r
->in
.targetdir
= targetdir
;
221 r
->out
.error_string
= NULL
;
223 /* do the domain vampire */
224 status
= libnet_Vampire(libnetctx
, r
, r
);
226 if (!NT_STATUS_IS_OK(status
)) {
227 d_fprintf(stderr
, "Vampire of domain failed: %s\n",
228 r
->out
.error_string
? r
->out
.error_string
: nt_errstr(status
));
230 talloc_free(libnetctx
);
233 d_printf("Vampired domain %s (%s)\n", r
->out
.domain_name
, dom_sid_string(ctx
, r
->out
.domain_sid
));
235 talloc_free(libnetctx
);
239 int net_vampire_usage(struct net_context
*ctx
, int argc
, const char **argv
)
241 d_printf("net vampire <domain> [options]\n");
245 int net_vampire_help(struct net_context
*ctx
, int argc
, const char **argv
)
247 d_printf("Join and synchronise a remote AD domain to the local server.\n");