Add NetUserEnum to libnetapi.
[samba.git] / source3 / lib / netapi / libnetapi.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  NetApi Support
4  *  Copyright (C) Guenther Deschner 2007-2008
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "includes.h"
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"
25
26 /****************************************************************
27  NetJoinDomain
28 ****************************************************************/
29
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] */)
36 {
37         struct NetJoinDomain r;
38         struct libnetapi_ctx *ctx = NULL;
39         NET_API_STATUS status;
40         WERROR werr;
41
42         status = libnetapi_getctx(&ctx);
43         if (status != 0) {
44                 return status;
45         }
46
47         /* In parameters */
48         r.in.server = server;
49         r.in.domain = domain;
50         r.in.account_ou = account_ou;
51         r.in.account = account;
52         r.in.password = password;
53         r.in.join_flags = join_flags;
54
55         /* Out parameters */
56
57         if (DEBUGLEVEL >= 10) {
58                 NDR_PRINT_IN_DEBUG(NetJoinDomain, &r);
59         }
60
61         if (LIBNETAPI_LOCAL_SERVER(server)) {
62                 werr = NetJoinDomain_l(ctx, &r);
63         } else {
64                 werr = NetJoinDomain_r(ctx, &r);
65         }
66
67         r.out.result = W_ERROR_V(werr);
68
69         if (DEBUGLEVEL >= 10) {
70                 NDR_PRINT_OUT_DEBUG(NetJoinDomain, &r);
71         }
72
73         return r.out.result;
74 }
75
76 /****************************************************************
77  NetUnjoinDomain
78 ****************************************************************/
79
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] */)
84 {
85         struct NetUnjoinDomain r;
86         struct libnetapi_ctx *ctx = NULL;
87         NET_API_STATUS status;
88         WERROR werr;
89
90         status = libnetapi_getctx(&ctx);
91         if (status != 0) {
92                 return status;
93         }
94
95         /* In parameters */
96         r.in.server_name = server_name;
97         r.in.account = account;
98         r.in.password = password;
99         r.in.unjoin_flags = unjoin_flags;
100
101         /* Out parameters */
102
103         if (DEBUGLEVEL >= 10) {
104                 NDR_PRINT_IN_DEBUG(NetUnjoinDomain, &r);
105         }
106
107         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
108                 werr = NetUnjoinDomain_l(ctx, &r);
109         } else {
110                 werr = NetUnjoinDomain_r(ctx, &r);
111         }
112
113         r.out.result = W_ERROR_V(werr);
114
115         if (DEBUGLEVEL >= 10) {
116                 NDR_PRINT_OUT_DEBUG(NetUnjoinDomain, &r);
117         }
118
119         return r.out.result;
120 }
121
122 /****************************************************************
123  NetGetJoinInformation
124 ****************************************************************/
125
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] */)
129 {
130         struct NetGetJoinInformation r;
131         struct libnetapi_ctx *ctx = NULL;
132         NET_API_STATUS status;
133         WERROR werr;
134
135         status = libnetapi_getctx(&ctx);
136         if (status != 0) {
137                 return status;
138         }
139
140         /* In parameters */
141         r.in.server_name = server_name;
142
143         /* Out parameters */
144         r.out.name_buffer = name_buffer;
145         r.out.name_type = name_type;
146
147         if (DEBUGLEVEL >= 10) {
148                 NDR_PRINT_IN_DEBUG(NetGetJoinInformation, &r);
149         }
150
151         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
152                 werr = NetGetJoinInformation_l(ctx, &r);
153         } else {
154                 werr = NetGetJoinInformation_r(ctx, &r);
155         }
156
157         r.out.result = W_ERROR_V(werr);
158
159         if (DEBUGLEVEL >= 10) {
160                 NDR_PRINT_OUT_DEBUG(NetGetJoinInformation, &r);
161         }
162
163         return r.out.result;
164 }
165
166 /****************************************************************
167  NetGetJoinableOUs
168 ****************************************************************/
169
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] */)
176 {
177         struct NetGetJoinableOUs r;
178         struct libnetapi_ctx *ctx = NULL;
179         NET_API_STATUS status;
180         WERROR werr;
181
182         status = libnetapi_getctx(&ctx);
183         if (status != 0) {
184                 return status;
185         }
186
187         /* In parameters */
188         r.in.server_name = server_name;
189         r.in.domain = domain;
190         r.in.account = account;
191         r.in.password = password;
192
193         /* Out parameters */
194         r.out.ou_count = ou_count;
195         r.out.ous = ous;
196
197         if (DEBUGLEVEL >= 10) {
198                 NDR_PRINT_IN_DEBUG(NetGetJoinableOUs, &r);
199         }
200
201         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
202                 werr = NetGetJoinableOUs_l(ctx, &r);
203         } else {
204                 werr = NetGetJoinableOUs_r(ctx, &r);
205         }
206
207         r.out.result = W_ERROR_V(werr);
208
209         if (DEBUGLEVEL >= 10) {
210                 NDR_PRINT_OUT_DEBUG(NetGetJoinableOUs, &r);
211         }
212
213         return r.out.result;
214 }
215
216 /****************************************************************
217  NetServerGetInfo
218 ****************************************************************/
219
220 NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] [unique] */,
221                                 uint32_t level /* [in] */,
222                                 uint8_t **buffer /* [out] [ref] */)
223 {
224         struct NetServerGetInfo r;
225         struct libnetapi_ctx *ctx = NULL;
226         NET_API_STATUS status;
227         WERROR werr;
228
229         status = libnetapi_getctx(&ctx);
230         if (status != 0) {
231                 return status;
232         }
233
234         /* In parameters */
235         r.in.server_name = server_name;
236         r.in.level = level;
237
238         /* Out parameters */
239         r.out.buffer = buffer;
240
241         if (DEBUGLEVEL >= 10) {
242                 NDR_PRINT_IN_DEBUG(NetServerGetInfo, &r);
243         }
244
245         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
246                 werr = NetServerGetInfo_l(ctx, &r);
247         } else {
248                 werr = NetServerGetInfo_r(ctx, &r);
249         }
250
251         r.out.result = W_ERROR_V(werr);
252
253         if (DEBUGLEVEL >= 10) {
254                 NDR_PRINT_OUT_DEBUG(NetServerGetInfo, &r);
255         }
256
257         return r.out.result;
258 }
259
260 /****************************************************************
261  NetServerSetInfo
262 ****************************************************************/
263
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] */)
268 {
269         struct NetServerSetInfo r;
270         struct libnetapi_ctx *ctx = NULL;
271         NET_API_STATUS status;
272         WERROR werr;
273
274         status = libnetapi_getctx(&ctx);
275         if (status != 0) {
276                 return status;
277         }
278
279         /* In parameters */
280         r.in.server_name = server_name;
281         r.in.level = level;
282         r.in.buffer = buffer;
283
284         /* Out parameters */
285         r.out.parm_error = parm_error;
286
287         if (DEBUGLEVEL >= 10) {
288                 NDR_PRINT_IN_DEBUG(NetServerSetInfo, &r);
289         }
290
291         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
292                 werr = NetServerSetInfo_l(ctx, &r);
293         } else {
294                 werr = NetServerSetInfo_r(ctx, &r);
295         }
296
297         r.out.result = W_ERROR_V(werr);
298
299         if (DEBUGLEVEL >= 10) {
300                 NDR_PRINT_OUT_DEBUG(NetServerSetInfo, &r);
301         }
302
303         return r.out.result;
304 }
305
306 /****************************************************************
307  NetGetDCName
308 ****************************************************************/
309
310 NET_API_STATUS NetGetDCName(const char * server_name /* [in] [unique] */,
311                             const char * domain_name /* [in] [unique] */,
312                             uint8_t **buffer /* [out] [ref] */)
313 {
314         struct NetGetDCName r;
315         struct libnetapi_ctx *ctx = NULL;
316         NET_API_STATUS status;
317         WERROR werr;
318
319         status = libnetapi_getctx(&ctx);
320         if (status != 0) {
321                 return status;
322         }
323
324         /* In parameters */
325         r.in.server_name = server_name;
326         r.in.domain_name = domain_name;
327
328         /* Out parameters */
329         r.out.buffer = buffer;
330
331         if (DEBUGLEVEL >= 10) {
332                 NDR_PRINT_IN_DEBUG(NetGetDCName, &r);
333         }
334
335         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
336                 werr = NetGetDCName_l(ctx, &r);
337         } else {
338                 werr = NetGetDCName_r(ctx, &r);
339         }
340
341         r.out.result = W_ERROR_V(werr);
342
343         if (DEBUGLEVEL >= 10) {
344                 NDR_PRINT_OUT_DEBUG(NetGetDCName, &r);
345         }
346
347         return r.out.result;
348 }
349
350 /****************************************************************
351  NetGetAnyDCName
352 ****************************************************************/
353
354 NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */,
355                                const char * domain_name /* [in] [unique] */,
356                                uint8_t **buffer /* [out] [ref] */)
357 {
358         struct NetGetAnyDCName r;
359         struct libnetapi_ctx *ctx = NULL;
360         NET_API_STATUS status;
361         WERROR werr;
362
363         status = libnetapi_getctx(&ctx);
364         if (status != 0) {
365                 return status;
366         }
367
368         /* In parameters */
369         r.in.server_name = server_name;
370         r.in.domain_name = domain_name;
371
372         /* Out parameters */
373         r.out.buffer = buffer;
374
375         if (DEBUGLEVEL >= 10) {
376                 NDR_PRINT_IN_DEBUG(NetGetAnyDCName, &r);
377         }
378
379         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
380                 werr = NetGetAnyDCName_l(ctx, &r);
381         } else {
382                 werr = NetGetAnyDCName_r(ctx, &r);
383         }
384
385         r.out.result = W_ERROR_V(werr);
386
387         if (DEBUGLEVEL >= 10) {
388                 NDR_PRINT_OUT_DEBUG(NetGetAnyDCName, &r);
389         }
390
391         return r.out.result;
392 }
393
394 /****************************************************************
395  DsGetDcName
396 ****************************************************************/
397
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] */)
404 {
405         struct DsGetDcName r;
406         struct libnetapi_ctx *ctx = NULL;
407         NET_API_STATUS status;
408         WERROR werr;
409
410         status = libnetapi_getctx(&ctx);
411         if (status != 0) {
412                 return status;
413         }
414
415         /* In parameters */
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;
420         r.in.flags = flags;
421
422         /* Out parameters */
423         r.out.dc_info = dc_info;
424
425         if (DEBUGLEVEL >= 10) {
426                 NDR_PRINT_IN_DEBUG(DsGetDcName, &r);
427         }
428
429         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
430                 werr = DsGetDcName_l(ctx, &r);
431         } else {
432                 werr = DsGetDcName_r(ctx, &r);
433         }
434
435         r.out.result = W_ERROR_V(werr);
436
437         if (DEBUGLEVEL >= 10) {
438                 NDR_PRINT_OUT_DEBUG(DsGetDcName, &r);
439         }
440
441         return r.out.result;
442 }
443
444 /****************************************************************
445  NetUserAdd
446 ****************************************************************/
447
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] */)
452 {
453         struct NetUserAdd r;
454         struct libnetapi_ctx *ctx = NULL;
455         NET_API_STATUS status;
456         WERROR werr;
457
458         status = libnetapi_getctx(&ctx);
459         if (status != 0) {
460                 return status;
461         }
462
463         /* In parameters */
464         r.in.server_name = server_name;
465         r.in.level = level;
466         r.in.buffer = buffer;
467
468         /* Out parameters */
469         r.out.parm_error = parm_error;
470
471         if (DEBUGLEVEL >= 10) {
472                 NDR_PRINT_IN_DEBUG(NetUserAdd, &r);
473         }
474
475         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
476                 werr = NetUserAdd_l(ctx, &r);
477         } else {
478                 werr = NetUserAdd_r(ctx, &r);
479         }
480
481         r.out.result = W_ERROR_V(werr);
482
483         if (DEBUGLEVEL >= 10) {
484                 NDR_PRINT_OUT_DEBUG(NetUserAdd, &r);
485         }
486
487         return r.out.result;
488 }
489
490 /****************************************************************
491  NetUserDel
492 ****************************************************************/
493
494 NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */,
495                           const char * user_name /* [in] [ref] */)
496 {
497         struct NetUserDel r;
498         struct libnetapi_ctx *ctx = NULL;
499         NET_API_STATUS status;
500         WERROR werr;
501
502         status = libnetapi_getctx(&ctx);
503         if (status != 0) {
504                 return status;
505         }
506
507         /* In parameters */
508         r.in.server_name = server_name;
509         r.in.user_name = user_name;
510
511         /* Out parameters */
512
513         if (DEBUGLEVEL >= 10) {
514                 NDR_PRINT_IN_DEBUG(NetUserDel, &r);
515         }
516
517         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
518                 werr = NetUserDel_l(ctx, &r);
519         } else {
520                 werr = NetUserDel_r(ctx, &r);
521         }
522
523         r.out.result = W_ERROR_V(werr);
524
525         if (DEBUGLEVEL >= 10) {
526                 NDR_PRINT_OUT_DEBUG(NetUserDel, &r);
527         }
528
529         return r.out.result;
530 }
531
532 /****************************************************************
533  NetUserEnum
534 ****************************************************************/
535
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] */)
544 {
545         struct NetUserEnum r;
546         struct libnetapi_ctx *ctx = NULL;
547         NET_API_STATUS status;
548         WERROR werr;
549
550         status = libnetapi_getctx(&ctx);
551         if (status != 0) {
552                 return status;
553         }
554
555         /* In parameters */
556         r.in.server_name = server_name;
557         r.in.level = level;
558         r.in.filter = filter;
559         r.in.prefmaxlen = prefmaxlen;
560         r.in.resume_handle = resume_handle;
561
562         /* Out parameters */
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;
567
568         if (DEBUGLEVEL >= 10) {
569                 NDR_PRINT_IN_DEBUG(NetUserEnum, &r);
570         }
571
572         if (LIBNETAPI_LOCAL_SERVER(server_name)) {
573                 werr = NetUserEnum_l(ctx, &r);
574         } else {
575                 werr = NetUserEnum_r(ctx, &r);
576         }
577
578         r.out.result = W_ERROR_V(werr);
579
580         if (DEBUGLEVEL >= 10) {
581                 NDR_PRINT_OUT_DEBUG(NetUserEnum, &r);
582         }
583
584         return r.out.result;
585 }
586