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/>.
20 #ifndef __LIB_NETAPI_H__
21 #define __LIB_NETAPI_H__
23 /****************************************************************
25 ****************************************************************/
27 NET_API_STATUS_SUCCESS = 0
30 #define ERROR_MORE_DATA ( 234L )
32 /****************************************************************
33 ****************************************************************/
40 uint16_t time_hi_and_version;
45 #endif /* _HEADER_misc */
47 #ifndef _HEADER_libnetapi
50 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
57 uint32_t sub_auths[MAXSUBAUTHS];
60 struct DOMAIN_CONTROLLER_INFO {
61 const char * domain_controller_name;
62 const char * domain_controller_address;
63 uint32_t domain_controller_address_type;
64 struct GUID domain_guid;
65 const char * domain_name;
66 const char * dns_forest_name;
68 const char * dc_site_name;
69 const char * client_site_name;
72 #define FILTER_TEMP_DUPLICATE_ACCOUNT ( 0x0001 )
73 #define FILTER_NORMAL_ACCOUNT ( 0x0002 )
74 #define FILTER_INTERDOMAIN_TRUST_ACCOUNT ( 0x0008 )
75 #define FILTER_WORKSTATION_TRUST_ACCOUNT ( 0x0010 )
76 #define FILTER_SERVER_TRUST_ACCOUNT ( 0x0020 )
78 struct SERVER_INFO_1005 {
79 const char * sv1005_comment;
83 const char * usri0_name;
87 const char * usri1_name;
88 const char * usri1_password;
89 uint32_t usri1_password_age;
91 const char * usri1_home_dir;
92 const char * usri1_comment;
94 const char * usri1_script_path;
97 struct NET_DISPLAY_USER {
98 const char * usri1_name;
99 const char * usri1_comment;
100 uint32_t usri1_flags;
101 const char * usri1_full_name;
102 uint32_t usri1_user_id;
103 uint32_t usri1_next_index;
106 struct NET_DISPLAY_MACHINE {
107 const char * usri2_name;
108 const char * usri2_comment;
109 uint32_t usri2_flags;
110 uint32_t usri2_user_id;
111 uint32_t usri2_next_index;
114 struct NET_DISPLAY_GROUP {
115 const char * grpi3_name;
116 const char * grpi3_comment;
117 uint32_t grpi3_group_id;
118 uint32_t grpi3_attributes;
119 uint32_t grpi3_next_index;
122 struct GROUP_INFO_0 {
123 const char * grpi0_name;
126 struct GROUP_INFO_1 {
127 const char * grpi1_name;
128 const char * grpi1_comment;
131 struct GROUP_INFO_2 {
132 const char * grpi2_name;
133 const char * grpi2_comment;
134 uint32_t grpi2_group_id;
135 uint32_t grpi2_attributes;
138 struct GROUP_INFO_3 {
139 const char * grpi3_name;
140 const char * grpi3_comment;
141 struct domsid grpi3_group_sid;
142 uint32_t grpi3_attributes;
145 struct GROUP_INFO_1002 {
146 const char * grpi1002_comment;
149 struct GROUP_INFO_1005 {
150 uint32_t grpi1005_attributes;
153 struct LOCALGROUP_INFO_0 {
154 const char * lgrpi0_name;
157 struct LOCALGROUP_INFO_1 {
158 const char * lgrpi1_name;
159 const char * lgrpi1_comment;
162 struct LOCALGROUP_INFO_1002 {
163 const char * lgrpi1002_comment;
166 struct TIME_OF_DAY_INFO {
167 uint32_t tod_elapsedt;
173 int32_t tod_timezone;
174 uint32_t tod_tinterval;
178 uint32_t tod_weekday;
181 #endif /* _HEADER_libnetapi */
183 /****************************************************************
184 ****************************************************************/
186 struct libnetapi_ctx {
196 /****************************************************************
197 ****************************************************************/
199 NET_API_STATUS libnetapi_init(struct libnetapi_ctx **ctx);
201 /****************************************************************
202 ****************************************************************/
204 NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx);
206 /****************************************************************
207 ****************************************************************/
209 NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx);
211 /****************************************************************
212 ****************************************************************/
214 NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
215 const char *debuglevel);
217 /****************************************************************
218 ****************************************************************/
220 NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
221 const char *username);
223 /****************************************************************
224 ****************************************************************/
226 NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
227 const char *password);
229 /****************************************************************
230 ****************************************************************/
232 NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
233 const char *workgroup);
235 /****************************************************************
236 ****************************************************************/
238 NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx);
240 /****************************************************************
241 ****************************************************************/
243 const char *libnetapi_errstr(NET_API_STATUS status);
245 /****************************************************************
246 ****************************************************************/
248 const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx,
249 NET_API_STATUS status);
252 /****************************************************************
254 ****************************************************************/
256 NET_API_STATUS NetApiBufferFree(void *buffer);
258 /************************************************************//**
260 * ConvertSidToStringSid
262 * @brief Convert a domain sid into a string
264 * @param[in] sid A pointer to a sid structure
265 * @param[in] sid_string A pointer that holds a pointer to a sid string. Caller
266 * needs to free with free(3)
268 ***************************************************************/
270 int ConvertSidToStringSid(const struct domsid *sid,
273 /************************************************************//**
277 * @brief Join a computer to a domain or workgroup
279 * @param[in] server The server name to connect to
280 * @param[in] domain The domain or workgroup to join
281 * @param[in] account_ou The organizational Unit to create the computer account
283 * @param[in] account The domain account used for joining a domain
284 * @param[in] password The domain account's password used for joining a domain
285 * @param[in] join_flags Bitmask field to define specific join features
286 * @return NET_API_STATUS
288 * example netdomjoin/netdomjoin.c
289 ***************************************************************/
291 NET_API_STATUS NetJoinDomain(const char * server /* [in] */,
292 const char * domain /* [in] [ref] */,
293 const char * account_ou /* [in] */,
294 const char * account /* [in] */,
295 const char * password /* [in] */,
296 uint32_t join_flags /* [in] */);
298 /************************************************************//**
302 * @brief Unjoin a computer from a domain or workgroup
304 * @param[in] server_name The server name to connect to
305 * @param[in] account The domain account used for unjoining a domain
306 * @param[in] password The domain account's password used for unjoining a domain
307 * @param[in] unjoin_flags Bitmask field to define specific unjoin features
308 * @return NET_API_STATUS
310 ***************************************************************/
312 NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] */,
313 const char * account /* [in] */,
314 const char * password /* [in] */,
315 uint32_t unjoin_flags /* [in] */);
317 /************************************************************//**
319 * NetGetJoinInformation
321 * @brief Unjoin a computer from a domain or workgroup
323 * @param[in] server_name The server name to connect to
324 * @param[out] name_buffer Returns the name of the workgroup or domain
325 * @param[out] name_type Returns the type of that name
326 * @return NET_API_STATUS
328 * example netdomjoin-gui/netdomjoin-gui.c
330 ***************************************************************/
332 NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] */,
333 const char * *name_buffer /* [out] [ref] */,
334 uint16_t *name_type /* [out] [ref] */);
336 /************************************************************//**
340 * @brief Query for the list of joinable organizational Units that can be used
343 * @param[in] server_name The server name to connect to
344 * @param[in] domain The AD domain to query
345 * @param[in] account The domain account used for the query
346 * @param[in] password The domain account's password used for the query
347 * @param[out] ou_count The number of ous returned
348 * @param[out] ous Returned string array containing the ous
349 * @return NET_API_STATUS
351 * example netdomjoin-gui/netdomjoin-gui.c
353 ***************************************************************/
355 NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */,
356 const char * domain /* [in] [ref] */,
357 const char * account /* [in] */,
358 const char * password /* [in] */,
359 uint32_t *ou_count /* [out] [ref] */,
360 const char * **ous /* [out] [ref] */);
362 /************************************************************//**
366 * @brief Get Information on a server
368 * @param[in] server_name The server name to connect to
369 * @param[in] level The level to define which information is requested
370 * @param[out] buffer The returned buffer carrying the SERVER_INFO structure
371 * @return NET_API_STATUS
373 ***************************************************************/
375 NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] */,
376 uint32_t level /* [in] */,
377 uint8_t **buffer /* [out] [ref] */);
379 /************************************************************//**
383 * @brief Get Information on a server
385 * @param[in] server_name The server name to connect to
386 * @param[in] level The level to define which information is set
387 * @param[in] buffer The buffer carrying the SERVER_INFO structure
388 * @param[out] parm_error On failure returns the invalid SERVER_INFO member
389 * @return NET_API_STATUS
391 ***************************************************************/
393 NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] */,
394 uint32_t level /* [in] */,
395 uint8_t *buffer /* [in] [ref] */,
396 uint32_t *parm_error /* [out] [ref] */);
398 /************************************************************//**
402 * @brief Query for the PDC for a given domain
404 * @param[in] server_name The server name to connect to
405 * @param[in] domain_name The name of the domain to lookup
406 * @param[out] buffer The name of the domain to lookup
407 * @return NET_API_STATUS
409 * example getdc/getdc.c
410 ***************************************************************/
412 NET_API_STATUS NetGetDCName(const char * server_name /* [in] */,
413 const char * domain_name /* [in] */,
414 uint8_t **buffer /* [out] [ref] */);
416 /************************************************************//**
420 * @brief Query for any DC for a given domain
422 * @param[in] server_name The server name to connect to
423 * @param[in] domain_name The name of the domain to lookup
424 * @param[out] buffer The name of the domain to lookup
425 * @return NET_API_STATUS
427 * example getdc/getdc.c
428 ***************************************************************/
430 NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */,
431 const char * domain_name /* [in] */,
432 uint8_t **buffer /* [out] [ref] */);
435 /************************************************************//**
439 * @brief Lookup a DC for a given domain and return information structure
441 * @param[in] server_name The server name to connect to
442 * @param[in] domain_name The name of the domain to lookup (cannot be NULL)
443 * @param[in] domain_guid The GUID of the domain to lookup (optional)
444 * @param[in] site_name The name of the site the DC should reside in
445 * @param[in] flags A bitmask to request specific features supported by the DC
446 * @param[out] dc_info Pointer to a DOMAIN_CONTROLLER_INFO structure
447 * @return NET_API_STATUS
449 * example dsgetdc/dsgetdc.c
450 ***************************************************************/
452 NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
453 const char * domain_name /* [in] [ref] */,
454 struct GUID *domain_guid /* [in] [unique] */,
455 const char * site_name /* [in] [unique] */,
456 uint32_t flags /* [in] */,
457 struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */);
459 /************************************************************//**
463 * @brief Create a user on a given server
465 * @param[in] server_name The server name to connect to
466 * @param[in] level The level of the USER_INFO structure passed in (Currently
467 * only level 1 is supported)
468 * @param[in] buffer The buffer carrying the USER_INFO structure
469 * @param[out] parm_error In case of error returns the failing member of the
471 * @return NET_API_STATUS
473 * example user/user_add.c
474 ***************************************************************/
476 NET_API_STATUS NetUserAdd(const char * server_name /* [in] */,
477 uint32_t level /* [in] */,
478 uint8_t *buffer /* [in] [ref] */,
479 uint32_t *parm_error /* [out] [ref] */);
481 /************************************************************//**
485 * @brief Delete a user on a given server
487 * @param[in] server_name The server name to connect to
488 * @param[in] user_name The user account to delete
489 * @return NET_API_STATUS
491 * example user/user_del.c
492 ***************************************************************/
494 NET_API_STATUS NetUserDel(const char * server_name /* [in] */,
495 const char * user_name /* [in] */);
497 /************************************************************//**
501 * @brief Enumerate accounts on a server
503 * @param[in] server_name The server name to connect to
504 * @param[in] level The enumeration level used for the query (Currently only
505 * level 0 is supported)
506 * @param[in] filter The account flags filter used for the query
507 * @param[out] buffer The returned enumeration buffer
508 * @param[in] prefmaxlen The requested maximal buffer size
509 * @param[out] entries_read The number of returned entries
510 * @param[out] total_entries The number of total entries
511 * @param[in,out] resume_handle A handle passed in and returned for resuming
513 * @return NET_API_STATUS
515 * example user/user_enum.c
516 ***************************************************************/
518 NET_API_STATUS NetUserEnum(const char * server_name /* [in] */,
519 uint32_t level /* [in] */,
520 uint32_t filter /* [in] */,
521 uint8_t **buffer /* [out] [ref] */,
522 uint32_t prefmaxlen /* [in] */,
523 uint32_t *entries_read /* [out] [ref] */,
524 uint32_t *total_entries /* [out] [ref] */,
525 uint32_t *resume_handle /* [in,out] [ref] */);
527 /************************************************************//**
529 * NetUserChangePassword
531 * @brief Change the password for a user on a given server or in a given domain
533 * @param[in] domain_name The server or domain name to connect to
534 * @param[in] user_name The user account to change the password for
535 * @param[in] old_password The user account's old password
536 * @param[in] new_password The user account's new password
537 * @return NET_API_STATUS
539 * example user/user_chgpwd.c
540 ***************************************************************/
542 NET_API_STATUS NetUserChangePassword(const char * domain_name /* [in] */,
543 const char * user_name /* [in] */,
544 const char * old_password /* [in] */,
545 const char * new_password /* [in] */);
547 /************************************************************//**
549 * NetQueryDisplayInformation
551 * @brief Enumerate accounts on a server
553 * @param[in] server_name The server name to connect to
554 * @param[in] level The enumeration level used for the query
555 * @param[in] idx The index to start the the display enumeration at
556 * @param[in] entries_requested The number of entries requested
557 * @param[in] prefmaxlen The requested maximal buffer size
558 * @param[out] entries_read The number of returned entries
559 * @param[out] buffer The returned display information buffer
560 * @return NET_API_STATUS
562 * example user/user_dispinfo.c
563 ***************************************************************/
565 NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */,
566 uint32_t level /* [in] */,
567 uint32_t idx /* [in] */,
568 uint32_t entries_requested /* [in] */,
569 uint32_t prefmaxlen /* [in] */,
570 uint32_t *entries_read /* [out] [ref] */,
571 void **buffer /* [out] [noprint,ref] */);
573 /************************************************************//**
577 * @brief Create Domain Group
579 * @param[in] server_name The server name to connect to
580 * @param[in] level The level used for the new group creation
581 * @param[in] buf The buffer containing the group structure
582 * @param[out] parm_err The returned parameter error number if any
583 * @return NET_API_STATUS
585 * example group/group_add.c
586 ***************************************************************/
588 NET_API_STATUS NetGroupAdd(const char * server_name /* [in] */,
589 uint32_t level /* [in] */,
590 uint8_t *buf /* [in] [ref] */,
591 uint32_t *parm_err /* [out] [ref] */);
593 /************************************************************//**
597 * @brief Delete Domain Group
599 * @param[in] server_name The server name to connect to
600 * @param[in] group_name The name of the group that is going to be deleted
601 * @return NET_API_STATUS
603 * example group/group_del.c
604 ***************************************************************/
606 NET_API_STATUS NetGroupDel(const char * server_name /* [in] */,
607 const char * group_name /* [in] */);
609 /************************************************************//**
613 * @brief Set Domain Group Information
615 * @param[in] server_name The server name to connect to
616 * @param[in] group_name The name of the group that is going to be modified
617 * @param[in] level The level defining the structure type in buf
618 * @param[in] buf The buffer containing a GROUP_INFO_X structure
619 * @param[out] parm_err The returned parameter error number if any
620 * @return NET_API_STATUS
622 * example group/group_setinfo.c
623 ***************************************************************/
625 NET_API_STATUS NetGroupSetInfo(const char * server_name /* [in] */,
626 const char * group_name /* [in] */,
627 uint32_t level /* [in] */,
628 uint8_t *buf /* [in] [ref] */,
629 uint32_t *parm_err /* [out] [ref] */);
631 /************************************************************//**
635 * @brief Get Domain Group Information
637 * @param[in] server_name The server name to connect to
638 * @param[in] group_name The name of the group that is going to be queried
639 * @param[in] level The level defining the requested GROUP_INFO_X structure
640 * @param[out] buf The buffer containing a GROUP_INFO_X structure
641 * @return NET_API_STATUS
643 * example group/group_getinfo.c
644 ***************************************************************/
646 NET_API_STATUS NetGroupGetInfo(const char * server_name /* [in] */,
647 const char * group_name /* [in] */,
648 uint32_t level /* [in] */,
649 uint8_t **buf /* [out] [ref] */);
651 /************************************************************//**
655 * @brief Add existing User to existing Domain Group
657 * @param[in] server_name The server name to connect to
658 * @param[in] group_name The name of the group that is going to be modified
659 * @param[in] user_name The name of the user that is going to be added to the
661 * @return NET_API_STATUS
663 * example group/group_adduser.c
664 ***************************************************************/
666 NET_API_STATUS NetGroupAddUser(const char * server_name /* [in] */,
667 const char * group_name /* [in] */,
668 const char * user_name /* [in] */);
670 /************************************************************//**
674 * @brief Remove User from Domain Group
676 * @param[in] server_name The server name to connect to
677 * @param[in] group_name The name of the group that is going to be modified
678 * @param[in] user_name The name of the user that is going to be removed from
680 * @return NET_API_STATUS
682 * example group/group_deluser.c
683 ***************************************************************/
685 NET_API_STATUS NetGroupDelUser(const char * server_name /* [in] */,
686 const char * group_name /* [in] */,
687 const char * user_name /* [in] */);
689 /************************************************************//**
693 * @brief Create Local Group
695 * @param[in] server_name The server name to connect to
696 * @param[in] level The level used for the new group creation
697 * @param[in] buf The buffer containing the group structure
698 * @param[out] parm_err The returned parameter error number if any
699 * @return NET_API_STATUS
701 * example localgroup/localgroup_add.c
702 ***************************************************************/
704 NET_API_STATUS NetLocalGroupAdd(const char * server_name /* [in] */,
705 uint32_t level /* [in] */,
706 uint8_t *buf /* [in] [ref] */,
707 uint32_t *parm_err /* [out] [ref] */);
709 /************************************************************//**
713 * @brief Delete Local Group
715 * @param[in] server_name The server name to connect to
716 * @param[in] group_name The name of the group that is going to be deleted
717 * @return NET_API_STATUS
719 * example localgroup/localgroup_del.c
720 ***************************************************************/
723 NET_API_STATUS NetLocalGroupDel(const char * server_name /* [in] */,
724 const char * group_name /* [in] */);
726 /************************************************************//**
728 * NetLocalGroupGetInfo
730 * @brief Get Local Group Information
732 * @param[in] server_name The server name to connect to
733 * @param[in] group_name The name of the group that is going to be queried
734 * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure
735 * @param[out] buf The buffer containing a LOCALGROUP_INFO_X structure
736 * @return NET_API_STATUS
738 * example localgroup/localgroup_getinfo.c
739 ***************************************************************/
741 NET_API_STATUS NetLocalGroupGetInfo(const char * server_name /* [in] */,
742 const char * group_name /* [in] */,
743 uint32_t level /* [in] */,
744 uint8_t **buf /* [out] [ref] */);
746 /************************************************************//**
748 * NetLocalGroupSetInfo
750 * @brief Set Local Group Information
752 * @param[in] server_name The server name to connect to
753 * @param[in] group_name The name of the group that is going to be modified
754 * @param[in] level The level defining the requested LOCALGROUP_INFO_X structure
755 * @param[in] buf The buffer containing a LOCALGROUP_INFO_X structure
756 * @param[out] parm_err The returned parameter error number if any
757 * @return NET_API_STATUS
759 * example localgroup/localgroup_setinfo.c
760 ***************************************************************/
763 NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */,
764 const char * group_name /* [in] */,
765 uint32_t level /* [in] */,
766 uint8_t *buf /* [in] [ref] */,
767 uint32_t *parm_err /* [out] [ref] */);
769 /************************************************************//**
773 * @brief Query remote Time of Day
775 * @param[in] server_name The server name to connect to
776 * @param[out] buf The buffer containing a TIME_OF_DAY_INFO structure
777 * @return NET_API_STATUS
779 * example server/remote_tod.c
780 ***************************************************************/
782 NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */,
783 uint8_t **buf /* [out] [ref] */);