r26295: Remove use of global_loadparm for net and wb_pam_auth.
[sfrench/samba-autobuild/.git] / source4 / utils / net / net_vampire.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    Distributed SMB/CIFS Server Management Utility 
4
5    Copyright (C) 2004 Stefan Metzmacher <metze@samba.org>
6    Copyright (C) 2005 Andrew Bartlett <abartlet@samba.org>
7
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.
12    
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.
17    
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/>.
20 */
21
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
29 static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
30 {
31         d_printf("net samdump keytab <keytab>\n");
32         return 0;       
33 }
34
35 static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
36 {
37         d_printf("Dumps kerberos keys of a domain into a keytab.\n");
38         return 0;       
39 }
40
41 static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv) 
42 {
43         NTSTATUS status;
44         struct libnet_context *libnetctx;
45         struct libnet_SamDump_keytab r;
46
47         switch (argc) {
48         case 0:
49                 return net_samdump_keytab_usage(ctx, argc, argv);
50                 break;
51         case 1:
52                 r.in.keytab_name = argv[0];
53                 break;
54         }
55
56         libnetctx = libnet_context_init(NULL);
57         if (!libnetctx) {
58                 return -1;      
59         }
60         libnetctx->cred = ctx->credentials;
61
62         r.out.error_string = NULL;
63         r.in.machine_account = NULL;
64         r.in.binding_string = NULL;
65
66         status = libnet_SamDump_keytab(libnetctx, ctx->mem_ctx, &r);
67         if (!NT_STATUS_IS_OK(status)) {
68                 DEBUG(0,("libnet_SamDump returned %s: %s\n",
69                          nt_errstr(status),
70                          r.out.error_string));
71                 return -1;
72         }
73
74         talloc_free(libnetctx);
75
76         return 0;
77 }
78
79 /* main function table */
80 static const struct net_functable net_samdump_functable[] = {
81         {"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
82         {NULL, NULL, NULL, NULL}
83 };
84
85 int net_samdump(struct net_context *ctx, int argc, const char **argv) 
86 {
87         NTSTATUS status;
88         struct libnet_context *libnetctx;
89         struct libnet_SamDump r;
90         int rc;
91
92         switch (argc) {
93         case 0:
94                 break;
95         case 1:
96         default:
97                 rc = net_run_function(ctx, argc, argv, net_samdump_functable, 
98                                       net_samdump_usage);
99                 return rc;
100         }
101
102         libnetctx = libnet_context_init(NULL);
103         if (!libnetctx) {
104                 return -1;      
105         }
106         libnetctx->cred = ctx->credentials;
107
108         r.out.error_string = NULL;
109         r.in.machine_account = NULL;
110         r.in.binding_string = NULL;
111
112         status = libnet_SamDump(libnetctx, ctx->mem_ctx, &r);
113         if (!NT_STATUS_IS_OK(status)) {
114                 DEBUG(0,("libnet_SamDump returned %s: %s\n",
115                          nt_errstr(status),
116                          r.out.error_string));
117                 return -1;
118         }
119
120         talloc_free(libnetctx);
121
122         return 0;
123 }
124
125 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
126 {
127         d_printf("net samdump\n");
128         d_printf("net samdump keytab <keytab>\n");
129         return 0;       
130 }
131
132 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
133 {
134         d_printf("Dumps the sam of the domain we are joined to.\n");
135         return 0;       
136 }
137
138 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv) 
139 {
140         NTSTATUS status;
141         struct libnet_context *libnetctx;
142         struct libnet_samsync_ldb r;
143
144         libnetctx = libnet_context_init(NULL);
145         if (!libnetctx) {
146                 return -1;      
147         }
148         libnetctx->cred = ctx->credentials;
149
150         r.out.error_string = NULL;
151         r.in.machine_account = NULL;
152         r.in.binding_string = NULL;
153
154         /* Needed to override the ACLs on ldb */
155         r.in.session_info = system_session(libnetctx, ctx->lp_ctx);
156
157         status = libnet_samsync_ldb(libnetctx, libnetctx, &r);
158         if (!NT_STATUS_IS_OK(status)) {
159                 DEBUG(0,("libnet_samsync_ldb returned %s: %s\n",
160                          nt_errstr(status),
161                          r.out.error_string));
162                 return -1;
163         }
164
165         talloc_free(libnetctx);
166
167         return 0;
168 }
169
170 int net_samsync_ldb_usage(struct net_context *ctx, int argc, const char **argv)
171 {
172         d_printf("net samsync_ldb\n");
173         return 0;       
174 }
175
176 int net_samsync_ldb_help(struct net_context *ctx, int argc, const char **argv)
177 {
178         d_printf("Synchronise into the local ldb the SAM of a domain.\n");
179         return 0;       
180 }