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);
394 /****************************************************************
396 ****************************************************************/
398 NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
399 const char * domain_name /* [in] [ref] */,
400 struct GUID *domain_guid /* [in] [unique] */,
401 const char * site_name /* [in] [unique] */,
402 uint32_t flags /* [in] */,
403 struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */)
405 struct DsGetDcName r;
406 struct libnetapi_ctx *ctx = NULL;
407 NET_API_STATUS status;
410 status = libnetapi_getctx(&ctx);
416 r.in.server_name = server_name;
417 r.in.domain_name = domain_name;
418 r.in.domain_guid = domain_guid;
419 r.in.site_name = site_name;
423 r.out.dc_info = dc_info;
425 if (DEBUGLEVEL >= 10) {
426 NDR_PRINT_IN_DEBUG(DsGetDcName, &r);
429 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
430 werr = DsGetDcName_l(ctx, &r);
432 werr = DsGetDcName_r(ctx, &r);
435 r.out.result = W_ERROR_V(werr);
437 if (DEBUGLEVEL >= 10) {
438 NDR_PRINT_OUT_DEBUG(DsGetDcName, &r);
444 /****************************************************************
446 ****************************************************************/
448 NET_API_STATUS NetUserAdd(const char * server_name /* [in] [unique] */,
449 uint32_t level /* [in] */,
450 uint8_t *buffer /* [in] [ref] */,
451 uint32_t *parm_error /* [out] [ref] */)
454 struct libnetapi_ctx *ctx = NULL;
455 NET_API_STATUS status;
458 status = libnetapi_getctx(&ctx);
464 r.in.server_name = server_name;
466 r.in.buffer = buffer;
469 r.out.parm_error = parm_error;
471 if (DEBUGLEVEL >= 10) {
472 NDR_PRINT_IN_DEBUG(NetUserAdd, &r);
475 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
476 werr = NetUserAdd_l(ctx, &r);
478 werr = NetUserAdd_r(ctx, &r);
481 r.out.result = W_ERROR_V(werr);
483 if (DEBUGLEVEL >= 10) {
484 NDR_PRINT_OUT_DEBUG(NetUserAdd, &r);
490 /****************************************************************
492 ****************************************************************/
494 NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */,
495 const char * user_name /* [in] [ref] */)
498 struct libnetapi_ctx *ctx = NULL;
499 NET_API_STATUS status;
502 status = libnetapi_getctx(&ctx);
508 r.in.server_name = server_name;
509 r.in.user_name = user_name;
513 if (DEBUGLEVEL >= 10) {
514 NDR_PRINT_IN_DEBUG(NetUserDel, &r);
517 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
518 werr = NetUserDel_l(ctx, &r);
520 werr = NetUserDel_r(ctx, &r);
523 r.out.result = W_ERROR_V(werr);
525 if (DEBUGLEVEL >= 10) {
526 NDR_PRINT_OUT_DEBUG(NetUserDel, &r);
532 /****************************************************************
534 ****************************************************************/
536 NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */,
537 uint32_t level /* [in] */,
538 uint32_t filter /* [in] */,
539 uint8_t **buffer /* [out] [ref] */,
540 uint32_t prefmaxlen /* [in] */,
541 uint32_t *entries_read /* [out] [ref] */,
542 uint32_t *total_entries /* [out] [ref] */,
543 uint32_t *resume_handle /* [in,out] [ref] */)
545 struct NetUserEnum r;
546 struct libnetapi_ctx *ctx = NULL;
547 NET_API_STATUS status;
550 status = libnetapi_getctx(&ctx);
556 r.in.server_name = server_name;
558 r.in.filter = filter;
559 r.in.prefmaxlen = prefmaxlen;
560 r.in.resume_handle = resume_handle;
563 r.out.buffer = buffer;
564 r.out.entries_read = entries_read;
565 r.out.total_entries = total_entries;
566 r.out.resume_handle = resume_handle;
568 if (DEBUGLEVEL >= 10) {
569 NDR_PRINT_IN_DEBUG(NetUserEnum, &r);
572 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
573 werr = NetUserEnum_l(ctx, &r);
575 werr = NetUserEnum_r(ctx, &r);
578 r.out.result = W_ERROR_V(werr);
580 if (DEBUGLEVEL >= 10) {
581 NDR_PRINT_OUT_DEBUG(NetUserEnum, &r);