2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2007-2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "librpc/gen_ndr/libnetapi.h"
22 #include "lib/netapi/netapi.h"
23 #include "libnetapi.h"
24 #include "librpc/gen_ndr/ndr_libnetapi.h"
26 /****************************************************************
28 ****************************************************************/
30 NET_API_STATUS NetJoinDomain(const char * server /* [in] [unique] */,
31 const char * domain /* [in] [ref] */,
32 const char * account_ou /* [in] [unique] */,
33 const char * account /* [in] [unique] */,
34 const char * password /* [in] [unique] */,
35 uint32_t join_flags /* [in] */)
37 struct NetJoinDomain r;
38 struct libnetapi_ctx *ctx = NULL;
39 NET_API_STATUS status;
42 status = libnetapi_getctx(&ctx);
50 r.in.account_ou = account_ou;
51 r.in.account = account;
52 r.in.password = password;
53 r.in.join_flags = join_flags;
57 if (DEBUGLEVEL >= 10) {
58 NDR_PRINT_IN_DEBUG(NetJoinDomain, &r);
61 if (LIBNETAPI_LOCAL_SERVER(server)) {
62 werr = NetJoinDomain_l(ctx, &r);
64 werr = NetJoinDomain_r(ctx, &r);
67 r.out.result = W_ERROR_V(werr);
69 if (DEBUGLEVEL >= 10) {
70 NDR_PRINT_OUT_DEBUG(NetJoinDomain, &r);
76 /****************************************************************
78 ****************************************************************/
80 NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] [unique] */,
81 const char * account /* [in] [unique] */,
82 const char * password /* [in] [unique] */,
83 uint32_t unjoin_flags /* [in] */)
85 struct NetUnjoinDomain r;
86 struct libnetapi_ctx *ctx = NULL;
87 NET_API_STATUS status;
90 status = libnetapi_getctx(&ctx);
96 r.in.server_name = server_name;
97 r.in.account = account;
98 r.in.password = password;
99 r.in.unjoin_flags = unjoin_flags;
103 if (DEBUGLEVEL >= 10) {
104 NDR_PRINT_IN_DEBUG(NetUnjoinDomain, &r);
107 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
108 werr = NetUnjoinDomain_l(ctx, &r);
110 werr = NetUnjoinDomain_r(ctx, &r);
113 r.out.result = W_ERROR_V(werr);
115 if (DEBUGLEVEL >= 10) {
116 NDR_PRINT_OUT_DEBUG(NetUnjoinDomain, &r);
122 /****************************************************************
123 NetGetJoinInformation
124 ****************************************************************/
126 NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] [unique] */,
127 const char * *name_buffer /* [out] [ref] */,
128 uint16_t *name_type /* [out] [ref] */)
130 struct NetGetJoinInformation r;
131 struct libnetapi_ctx *ctx = NULL;
132 NET_API_STATUS status;
135 status = libnetapi_getctx(&ctx);
141 r.in.server_name = server_name;
144 r.out.name_buffer = name_buffer;
145 r.out.name_type = name_type;
147 if (DEBUGLEVEL >= 10) {
148 NDR_PRINT_IN_DEBUG(NetGetJoinInformation, &r);
151 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
152 werr = NetGetJoinInformation_l(ctx, &r);
154 werr = NetGetJoinInformation_r(ctx, &r);
157 r.out.result = W_ERROR_V(werr);
159 if (DEBUGLEVEL >= 10) {
160 NDR_PRINT_OUT_DEBUG(NetGetJoinInformation, &r);
166 /****************************************************************
168 ****************************************************************/
170 NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */,
171 const char * domain /* [in] [ref] */,
172 const char * account /* [in] [unique] */,
173 const char * password /* [in] [unique] */,
174 uint32_t *ou_count /* [out] [ref] */,
175 const char * **ous /* [out] [ref] */)
177 struct NetGetJoinableOUs r;
178 struct libnetapi_ctx *ctx = NULL;
179 NET_API_STATUS status;
182 status = libnetapi_getctx(&ctx);
188 r.in.server_name = server_name;
189 r.in.domain = domain;
190 r.in.account = account;
191 r.in.password = password;
194 r.out.ou_count = ou_count;
197 if (DEBUGLEVEL >= 10) {
198 NDR_PRINT_IN_DEBUG(NetGetJoinableOUs, &r);
201 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
202 werr = NetGetJoinableOUs_l(ctx, &r);
204 werr = NetGetJoinableOUs_r(ctx, &r);
207 r.out.result = W_ERROR_V(werr);
209 if (DEBUGLEVEL >= 10) {
210 NDR_PRINT_OUT_DEBUG(NetGetJoinableOUs, &r);
216 /****************************************************************
218 ****************************************************************/
220 NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */,
221 uint32_t level /* [in] */,
222 uint8_t **buffer /* [out] [ref] */)
224 struct NetServerGetInfo r;
225 struct libnetapi_ctx *ctx = NULL;
226 NET_API_STATUS status;
229 status = libnetapi_getctx(&ctx);
235 r.in.server_name = server_name;
239 r.out.buffer = buffer;
241 if (DEBUGLEVEL >= 10) {
242 NDR_PRINT_IN_DEBUG(NetServerGetInfo, &r);
245 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
246 werr = NetServerGetInfo_l(ctx, &r);
248 werr = NetServerGetInfo_r(ctx, &r);
251 r.out.result = W_ERROR_V(werr);
253 if (DEBUGLEVEL >= 10) {
254 NDR_PRINT_OUT_DEBUG(NetServerGetInfo, &r);
260 /****************************************************************
262 ****************************************************************/
264 NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] [unique] */,
265 uint32_t level /* [in] */,
266 uint8_t *buffer /* [in] [ref] */,
267 uint32_t *parm_error /* [out] [ref] */)
269 struct NetServerSetInfo r;
270 struct libnetapi_ctx *ctx = NULL;
271 NET_API_STATUS status;
274 status = libnetapi_getctx(&ctx);
280 r.in.server_name = server_name;
282 r.in.buffer = buffer;
285 r.out.parm_error = parm_error;
287 if (DEBUGLEVEL >= 10) {
288 NDR_PRINT_IN_DEBUG(NetServerSetInfo, &r);
291 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
292 werr = NetServerSetInfo_l(ctx, &r);
294 werr = NetServerSetInfo_r(ctx, &r);
297 r.out.result = W_ERROR_V(werr);
299 if (DEBUGLEVEL >= 10) {
300 NDR_PRINT_OUT_DEBUG(NetServerSetInfo, &r);
306 /****************************************************************
308 ****************************************************************/
310 NET_API_STATUS NetGetDCName(const char * server_name /* [in] [unique] */,
311 const char * domain_name /* [in] [unique] */,
312 uint8_t **buffer /* [out] [ref] */)
314 struct NetGetDCName r;
315 struct libnetapi_ctx *ctx = NULL;
316 NET_API_STATUS status;
319 status = libnetapi_getctx(&ctx);
325 r.in.server_name = server_name;
326 r.in.domain_name = domain_name;
329 r.out.buffer = buffer;
331 if (DEBUGLEVEL >= 10) {
332 NDR_PRINT_IN_DEBUG(NetGetDCName, &r);
335 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
336 werr = NetGetDCName_l(ctx, &r);
338 werr = NetGetDCName_r(ctx, &r);
341 r.out.result = W_ERROR_V(werr);
343 if (DEBUGLEVEL >= 10) {
344 NDR_PRINT_OUT_DEBUG(NetGetDCName, &r);
350 /****************************************************************
352 ****************************************************************/
354 NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */,
355 const char * domain_name /* [in] [unique] */,
356 uint8_t **buffer /* [out] [ref] */)
358 struct NetGetAnyDCName r;
359 struct libnetapi_ctx *ctx = NULL;
360 NET_API_STATUS status;
363 status = libnetapi_getctx(&ctx);
369 r.in.server_name = server_name;
370 r.in.domain_name = domain_name;
373 r.out.buffer = buffer;
375 if (DEBUGLEVEL >= 10) {
376 NDR_PRINT_IN_DEBUG(NetGetAnyDCName, &r);
379 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
380 werr = NetGetAnyDCName_l(ctx, &r);
382 werr = NetGetAnyDCName_r(ctx, &r);
385 r.out.result = W_ERROR_V(werr);
387 if (DEBUGLEVEL >= 10) {
388 NDR_PRINT_OUT_DEBUG(NetGetAnyDCName, &r);