remove needless rpath stuff for default paths as early as possible
[Samba/gebeck_regimport.git] / source4 / utils / net / net_vampire.c
blob14f6a07e4bbe92ffbe5cc4939c5fa3b33c61cef8
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 "utils/net/net.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/samr.h"
26 #include "auth/auth.h"
27 #include "param/param.h"
28 #include "lib/events/events.h"
30 static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
32 d_printf("net samdump keytab <keytab>\n");
33 return 0;
36 static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
38 d_printf("Dumps kerberos keys of a domain into a keytab.\n");
39 return 0;
42 static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv)
44 NTSTATUS status;
45 struct libnet_context *libnetctx;
46 struct libnet_SamDump_keytab r;
48 switch (argc) {
49 case 0:
50 return net_samdump_keytab_usage(ctx, argc, argv);
51 break;
52 case 1:
53 r.in.keytab_name = argv[0];
54 break;
57 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
58 if (!libnetctx) {
59 return -1;
61 libnetctx->cred = ctx->credentials;
63 r.out.error_string = NULL;
64 r.in.machine_account = NULL;
65 r.in.binding_string = NULL;
67 status = libnet_SamDump_keytab(libnetctx, ctx, &r);
68 if (!NT_STATUS_IS_OK(status)) {
69 DEBUG(0,("libnet_SamDump returned %s: %s\n",
70 nt_errstr(status),
71 r.out.error_string));
72 return -1;
75 talloc_free(libnetctx);
77 return 0;
80 /* main function table */
81 static const struct net_functable net_samdump_functable[] = {
82 {"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
83 {NULL, NULL, NULL, NULL}
86 int net_samdump(struct net_context *ctx, int argc, const char **argv)
88 NTSTATUS status;
89 struct libnet_context *libnetctx;
90 struct libnet_SamDump r;
91 int rc;
93 switch (argc) {
94 case 0:
95 break;
96 case 1:
97 default:
98 rc = net_run_function(ctx, argc, argv, net_samdump_functable,
99 net_samdump_usage);
100 return rc;
103 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
104 if (!libnetctx) {
105 return -1;
107 libnetctx->cred = ctx->credentials;
109 r.out.error_string = NULL;
110 r.in.machine_account = NULL;
111 r.in.binding_string = NULL;
113 status = libnet_SamDump(libnetctx, ctx, &r);
114 if (!NT_STATUS_IS_OK(status)) {
115 DEBUG(0,("libnet_SamDump returned %s: %s\n",
116 nt_errstr(status),
117 r.out.error_string));
118 return -1;
121 talloc_free(libnetctx);
123 return 0;
126 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
128 d_printf("net samdump\n");
129 d_printf("net samdump keytab <keytab>\n");
130 return 0;
133 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
135 d_printf("Dumps the sam of the domain we are joined to.\n");
136 return 0;
139 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv)
141 NTSTATUS status;
142 struct libnet_context *libnetctx;
143 struct libnet_samsync_ldb r;
145 libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
146 if (!libnetctx) {
147 return -1;
149 libnetctx->cred = ctx->credentials;
151 r.out.error_string = NULL;
152 r.in.machine_account = NULL;
153 r.in.binding_string = NULL;
155 /* Needed to override the ACLs on ldb */
156 r.in.session_info = system_session(libnetctx, ctx->lp_ctx);
158 status = libnet_samsync_ldb(libnetctx, libnetctx, &r);
159 if (!NT_STATUS_IS_OK(status)) {
160 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
161 nt_errstr(status),
162 r.out.error_string));
163 return -1;
166 talloc_free(libnetctx);
168 return 0;
171 int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv)
173 d_printf("net samsync\n");
174 return 0;
177 int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv)
179 d_printf("Synchronise into the local ldb the SAM of a domain.\n");
180 return 0;