libnetapi: add NetQueryDisplayInformation skeleton.
[Samba.git] / source / lib / netapi / libnetapi.c
blobe71adc6893bca89afed99d02e1c9091b47be9de2
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetApi Support
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/>.
20 #include "includes.h"
21 #include "librpc/gen_ndr/libnetapi.h"
22 #include "lib/netapi/netapi.h"
23 #include "lib/netapi/netapi_private.h"
24 #include "libnetapi.h"
25 #include "librpc/gen_ndr/ndr_libnetapi.h"
27 /****************************************************************
28 NetJoinDomain
29 ****************************************************************/
31 NET_API_STATUS NetJoinDomain(const char * server /* [in] [unique] */,
32 const char * domain /* [in] [ref] */,
33 const char * account_ou /* [in] [unique] */,
34 const char * account /* [in] [unique] */,
35 const char * password /* [in] [unique] */,
36 uint32_t join_flags /* [in] */)
38 struct NetJoinDomain r;
39 struct libnetapi_ctx *ctx = NULL;
40 NET_API_STATUS status;
41 WERROR werr;
43 status = libnetapi_getctx(&ctx);
44 if (status != 0) {
45 return status;
48 /* In parameters */
49 r.in.server = server;
50 r.in.domain = domain;
51 r.in.account_ou = account_ou;
52 r.in.account = account;
53 r.in.password = password;
54 r.in.join_flags = join_flags;
56 /* Out parameters */
58 if (DEBUGLEVEL >= 10) {
59 NDR_PRINT_IN_DEBUG(NetJoinDomain, &r);
62 if (LIBNETAPI_LOCAL_SERVER(server)) {
63 werr = NetJoinDomain_l(ctx, &r);
64 } else {
65 werr = NetJoinDomain_r(ctx, &r);
68 r.out.result = W_ERROR_V(werr);
70 if (DEBUGLEVEL >= 10) {
71 NDR_PRINT_OUT_DEBUG(NetJoinDomain, &r);
74 return r.out.result;
77 /****************************************************************
78 NetUnjoinDomain
79 ****************************************************************/
81 NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] [unique] */,
82 const char * account /* [in] [unique] */,
83 const char * password /* [in] [unique] */,
84 uint32_t unjoin_flags /* [in] */)
86 struct NetUnjoinDomain r;
87 struct libnetapi_ctx *ctx = NULL;
88 NET_API_STATUS status;
89 WERROR werr;
91 status = libnetapi_getctx(&ctx);
92 if (status != 0) {
93 return status;
96 /* In parameters */
97 r.in.server_name = server_name;
98 r.in.account = account;
99 r.in.password = password;
100 r.in.unjoin_flags = unjoin_flags;
102 /* Out parameters */
104 if (DEBUGLEVEL >= 10) {
105 NDR_PRINT_IN_DEBUG(NetUnjoinDomain, &r);
108 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
109 werr = NetUnjoinDomain_l(ctx, &r);
110 } else {
111 werr = NetUnjoinDomain_r(ctx, &r);
114 r.out.result = W_ERROR_V(werr);
116 if (DEBUGLEVEL >= 10) {
117 NDR_PRINT_OUT_DEBUG(NetUnjoinDomain, &r);
120 return r.out.result;
123 /****************************************************************
124 NetGetJoinInformation
125 ****************************************************************/
127 NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] [unique] */,
128 const char * *name_buffer /* [out] [ref] */,
129 uint16_t *name_type /* [out] [ref] */)
131 struct NetGetJoinInformation r;
132 struct libnetapi_ctx *ctx = NULL;
133 NET_API_STATUS status;
134 WERROR werr;
136 status = libnetapi_getctx(&ctx);
137 if (status != 0) {
138 return status;
141 /* In parameters */
142 r.in.server_name = server_name;
144 /* Out parameters */
145 r.out.name_buffer = name_buffer;
146 r.out.name_type = name_type;
148 if (DEBUGLEVEL >= 10) {
149 NDR_PRINT_IN_DEBUG(NetGetJoinInformation, &r);
152 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
153 werr = NetGetJoinInformation_l(ctx, &r);
154 } else {
155 werr = NetGetJoinInformation_r(ctx, &r);
158 r.out.result = W_ERROR_V(werr);
160 if (DEBUGLEVEL >= 10) {
161 NDR_PRINT_OUT_DEBUG(NetGetJoinInformation, &r);
164 return r.out.result;
167 /****************************************************************
168 NetGetJoinableOUs
169 ****************************************************************/
171 NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] [unique] */,
172 const char * domain /* [in] [ref] */,
173 const char * account /* [in] [unique] */,
174 const char * password /* [in] [unique] */,
175 uint32_t *ou_count /* [out] [ref] */,
176 const char * **ous /* [out] [ref] */)
178 struct NetGetJoinableOUs r;
179 struct libnetapi_ctx *ctx = NULL;
180 NET_API_STATUS status;
181 WERROR werr;
183 status = libnetapi_getctx(&ctx);
184 if (status != 0) {
185 return status;
188 /* In parameters */
189 r.in.server_name = server_name;
190 r.in.domain = domain;
191 r.in.account = account;
192 r.in.password = password;
194 /* Out parameters */
195 r.out.ou_count = ou_count;
196 r.out.ous = ous;
198 if (DEBUGLEVEL >= 10) {
199 NDR_PRINT_IN_DEBUG(NetGetJoinableOUs, &r);
202 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
203 werr = NetGetJoinableOUs_l(ctx, &r);
204 } else {
205 werr = NetGetJoinableOUs_r(ctx, &r);
208 r.out.result = W_ERROR_V(werr);
210 if (DEBUGLEVEL >= 10) {
211 NDR_PRINT_OUT_DEBUG(NetGetJoinableOUs, &r);
214 return r.out.result;
217 /****************************************************************
218 NetServerGetInfo
219 ****************************************************************/
221 NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */,
222 uint32_t level /* [in] */,
223 uint8_t **buffer /* [out] [ref] */)
225 struct NetServerGetInfo r;
226 struct libnetapi_ctx *ctx = NULL;
227 NET_API_STATUS status;
228 WERROR werr;
230 status = libnetapi_getctx(&ctx);
231 if (status != 0) {
232 return status;
235 /* In parameters */
236 r.in.server_name = server_name;
237 r.in.level = level;
239 /* Out parameters */
240 r.out.buffer = buffer;
242 if (DEBUGLEVEL >= 10) {
243 NDR_PRINT_IN_DEBUG(NetServerGetInfo, &r);
246 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
247 werr = NetServerGetInfo_l(ctx, &r);
248 } else {
249 werr = NetServerGetInfo_r(ctx, &r);
252 r.out.result = W_ERROR_V(werr);
254 if (DEBUGLEVEL >= 10) {
255 NDR_PRINT_OUT_DEBUG(NetServerGetInfo, &r);
258 return r.out.result;
261 /****************************************************************
262 NetServerSetInfo
263 ****************************************************************/
265 NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] [unique] */,
266 uint32_t level /* [in] */,
267 uint8_t *buffer /* [in] [ref] */,
268 uint32_t *parm_error /* [out] [ref] */)
270 struct NetServerSetInfo r;
271 struct libnetapi_ctx *ctx = NULL;
272 NET_API_STATUS status;
273 WERROR werr;
275 status = libnetapi_getctx(&ctx);
276 if (status != 0) {
277 return status;
280 /* In parameters */
281 r.in.server_name = server_name;
282 r.in.level = level;
283 r.in.buffer = buffer;
285 /* Out parameters */
286 r.out.parm_error = parm_error;
288 if (DEBUGLEVEL >= 10) {
289 NDR_PRINT_IN_DEBUG(NetServerSetInfo, &r);
292 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
293 werr = NetServerSetInfo_l(ctx, &r);
294 } else {
295 werr = NetServerSetInfo_r(ctx, &r);
298 r.out.result = W_ERROR_V(werr);
300 if (DEBUGLEVEL >= 10) {
301 NDR_PRINT_OUT_DEBUG(NetServerSetInfo, &r);
304 return r.out.result;
307 /****************************************************************
308 NetGetDCName
309 ****************************************************************/
311 NET_API_STATUS NetGetDCName(const char * server_name /* [in] [unique] */,
312 const char * domain_name /* [in] [unique] */,
313 uint8_t **buffer /* [out] [ref] */)
315 struct NetGetDCName r;
316 struct libnetapi_ctx *ctx = NULL;
317 NET_API_STATUS status;
318 WERROR werr;
320 status = libnetapi_getctx(&ctx);
321 if (status != 0) {
322 return status;
325 /* In parameters */
326 r.in.server_name = server_name;
327 r.in.domain_name = domain_name;
329 /* Out parameters */
330 r.out.buffer = buffer;
332 if (DEBUGLEVEL >= 10) {
333 NDR_PRINT_IN_DEBUG(NetGetDCName, &r);
336 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
337 werr = NetGetDCName_l(ctx, &r);
338 } else {
339 werr = NetGetDCName_r(ctx, &r);
342 r.out.result = W_ERROR_V(werr);
344 if (DEBUGLEVEL >= 10) {
345 NDR_PRINT_OUT_DEBUG(NetGetDCName, &r);
348 return r.out.result;
351 /****************************************************************
352 NetGetAnyDCName
353 ****************************************************************/
355 NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */,
356 const char * domain_name /* [in] [unique] */,
357 uint8_t **buffer /* [out] [ref] */)
359 struct NetGetAnyDCName r;
360 struct libnetapi_ctx *ctx = NULL;
361 NET_API_STATUS status;
362 WERROR werr;
364 status = libnetapi_getctx(&ctx);
365 if (status != 0) {
366 return status;
369 /* In parameters */
370 r.in.server_name = server_name;
371 r.in.domain_name = domain_name;
373 /* Out parameters */
374 r.out.buffer = buffer;
376 if (DEBUGLEVEL >= 10) {
377 NDR_PRINT_IN_DEBUG(NetGetAnyDCName, &r);
380 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
381 werr = NetGetAnyDCName_l(ctx, &r);
382 } else {
383 werr = NetGetAnyDCName_r(ctx, &r);
386 r.out.result = W_ERROR_V(werr);
388 if (DEBUGLEVEL >= 10) {
389 NDR_PRINT_OUT_DEBUG(NetGetAnyDCName, &r);
392 return r.out.result;
395 /****************************************************************
396 DsGetDcName
397 ****************************************************************/
399 NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
400 const char * domain_name /* [in] [ref] */,
401 struct GUID *domain_guid /* [in] [unique] */,
402 const char * site_name /* [in] [unique] */,
403 uint32_t flags /* [in] */,
404 struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */)
406 struct DsGetDcName r;
407 struct libnetapi_ctx *ctx = NULL;
408 NET_API_STATUS status;
409 WERROR werr;
411 status = libnetapi_getctx(&ctx);
412 if (status != 0) {
413 return status;
416 /* In parameters */
417 r.in.server_name = server_name;
418 r.in.domain_name = domain_name;
419 r.in.domain_guid = domain_guid;
420 r.in.site_name = site_name;
421 r.in.flags = flags;
423 /* Out parameters */
424 r.out.dc_info = dc_info;
426 if (DEBUGLEVEL >= 10) {
427 NDR_PRINT_IN_DEBUG(DsGetDcName, &r);
430 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
431 werr = DsGetDcName_l(ctx, &r);
432 } else {
433 werr = DsGetDcName_r(ctx, &r);
436 r.out.result = W_ERROR_V(werr);
438 if (DEBUGLEVEL >= 10) {
439 NDR_PRINT_OUT_DEBUG(DsGetDcName, &r);
442 return r.out.result;
445 /****************************************************************
446 NetUserAdd
447 ****************************************************************/
449 NET_API_STATUS NetUserAdd(const char * server_name /* [in] [unique] */,
450 uint32_t level /* [in] */,
451 uint8_t *buffer /* [in] [ref] */,
452 uint32_t *parm_error /* [out] [ref] */)
454 struct NetUserAdd r;
455 struct libnetapi_ctx *ctx = NULL;
456 NET_API_STATUS status;
457 WERROR werr;
459 status = libnetapi_getctx(&ctx);
460 if (status != 0) {
461 return status;
464 /* In parameters */
465 r.in.server_name = server_name;
466 r.in.level = level;
467 r.in.buffer = buffer;
469 /* Out parameters */
470 r.out.parm_error = parm_error;
472 if (DEBUGLEVEL >= 10) {
473 NDR_PRINT_IN_DEBUG(NetUserAdd, &r);
476 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
477 werr = NetUserAdd_l(ctx, &r);
478 } else {
479 werr = NetUserAdd_r(ctx, &r);
482 r.out.result = W_ERROR_V(werr);
484 if (DEBUGLEVEL >= 10) {
485 NDR_PRINT_OUT_DEBUG(NetUserAdd, &r);
488 return r.out.result;
491 /****************************************************************
492 NetUserDel
493 ****************************************************************/
495 NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */,
496 const char * user_name /* [in] [ref] */)
498 struct NetUserDel r;
499 struct libnetapi_ctx *ctx = NULL;
500 NET_API_STATUS status;
501 WERROR werr;
503 status = libnetapi_getctx(&ctx);
504 if (status != 0) {
505 return status;
508 /* In parameters */
509 r.in.server_name = server_name;
510 r.in.user_name = user_name;
512 /* Out parameters */
514 if (DEBUGLEVEL >= 10) {
515 NDR_PRINT_IN_DEBUG(NetUserDel, &r);
518 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
519 werr = NetUserDel_l(ctx, &r);
520 } else {
521 werr = NetUserDel_r(ctx, &r);
524 r.out.result = W_ERROR_V(werr);
526 if (DEBUGLEVEL >= 10) {
527 NDR_PRINT_OUT_DEBUG(NetUserDel, &r);
530 return r.out.result;
533 /****************************************************************
534 NetUserEnum
535 ****************************************************************/
537 NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */,
538 uint32_t level /* [in] */,
539 uint32_t filter /* [in] */,
540 uint8_t **buffer /* [out] [ref] */,
541 uint32_t prefmaxlen /* [in] */,
542 uint32_t *entries_read /* [out] [ref] */,
543 uint32_t *total_entries /* [out] [ref] */,
544 uint32_t *resume_handle /* [in,out] [ref] */)
546 struct NetUserEnum r;
547 struct libnetapi_ctx *ctx = NULL;
548 NET_API_STATUS status;
549 WERROR werr;
551 status = libnetapi_getctx(&ctx);
552 if (status != 0) {
553 return status;
556 /* In parameters */
557 r.in.server_name = server_name;
558 r.in.level = level;
559 r.in.filter = filter;
560 r.in.prefmaxlen = prefmaxlen;
561 r.in.resume_handle = resume_handle;
563 /* Out parameters */
564 r.out.buffer = buffer;
565 r.out.entries_read = entries_read;
566 r.out.total_entries = total_entries;
567 r.out.resume_handle = resume_handle;
569 if (DEBUGLEVEL >= 10) {
570 NDR_PRINT_IN_DEBUG(NetUserEnum, &r);
573 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
574 werr = NetUserEnum_l(ctx, &r);
575 } else {
576 werr = NetUserEnum_r(ctx, &r);
579 r.out.result = W_ERROR_V(werr);
581 if (DEBUGLEVEL >= 10) {
582 NDR_PRINT_OUT_DEBUG(NetUserEnum, &r);
585 return r.out.result;
588 /****************************************************************
589 NetQueryDisplayInformation
590 ****************************************************************/
592 NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */,
593 uint32_t level /* [in] */,
594 uint32_t idx /* [in] */,
595 uint32_t entries_requested /* [in] */,
596 uint32_t prefmaxlen /* [in] */,
597 uint32_t *entries_read /* [out] [ref] */,
598 void **buffer /* [out] [noprint,ref] */)
600 struct NetQueryDisplayInformation r;
601 struct libnetapi_ctx *ctx = NULL;
602 NET_API_STATUS status;
603 WERROR werr;
605 status = libnetapi_getctx(&ctx);
606 if (status != 0) {
607 return status;
610 /* In parameters */
611 r.in.server_name = server_name;
612 r.in.level = level;
613 r.in.idx = idx;
614 r.in.entries_requested = entries_requested;
615 r.in.prefmaxlen = prefmaxlen;
617 /* Out parameters */
618 r.out.entries_read = entries_read;
619 r.out.buffer = buffer;
621 if (DEBUGLEVEL >= 10) {
622 NDR_PRINT_IN_DEBUG(NetQueryDisplayInformation, &r);
625 if (LIBNETAPI_LOCAL_SERVER(server_name)) {
626 werr = NetQueryDisplayInformation_l(ctx, &r);
627 } else {
628 werr = NetQueryDisplayInformation_r(ctx, &r);
631 r.out.result = W_ERROR_V(werr);
633 if (DEBUGLEVEL >= 10) {
634 NDR_PRINT_OUT_DEBUG(NetQueryDisplayInformation, &r);
637 return r.out.result;