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 | #ifndef __LIB_NETAPI_H__
|
---|
21 | #define __LIB_NETAPI_H__
|
---|
22 |
|
---|
23 | #ifdef __cplusplus
|
---|
24 | extern "C" {
|
---|
25 | #endif /* __cplusplus */
|
---|
26 |
|
---|
27 | /****************************************************************
|
---|
28 | NET_API_STATUS
|
---|
29 | ****************************************************************/
|
---|
30 | typedef enum {
|
---|
31 | NET_API_STATUS_SUCCESS = 0
|
---|
32 | } NET_API_STATUS;
|
---|
33 |
|
---|
34 | #define ERROR_MORE_DATA ( 234L )
|
---|
35 |
|
---|
36 | /****************************************************************
|
---|
37 | ****************************************************************/
|
---|
38 |
|
---|
39 | #ifndef _HEADER_misc
|
---|
40 |
|
---|
41 | struct GUID {
|
---|
42 | uint32_t time_low;
|
---|
43 | uint16_t time_mid;
|
---|
44 | uint16_t time_hi_and_version;
|
---|
45 | uint8_t clock_seq[2];
|
---|
46 | uint8_t node[6];
|
---|
47 | };
|
---|
48 |
|
---|
49 | #endif /* _HEADER_misc */
|
---|
50 |
|
---|
51 | #ifndef _HEADER_libnetapi
|
---|
52 |
|
---|
53 | struct DOMAIN_CONTROLLER_INFO {
|
---|
54 | const char * domain_controller_name;
|
---|
55 | const char * domain_controller_address;
|
---|
56 | uint32_t domain_controller_address_type;
|
---|
57 | struct GUID domain_guid;
|
---|
58 | const char * domain_name;
|
---|
59 | const char * dns_forest_name;
|
---|
60 | uint32_t flags;
|
---|
61 | const char * dc_site_name;
|
---|
62 | const char * client_site_name;
|
---|
63 | };
|
---|
64 |
|
---|
65 | struct SERVER_INFO_1005 {
|
---|
66 | const char * sv1005_comment;
|
---|
67 | };
|
---|
68 |
|
---|
69 | struct USER_INFO_0 {
|
---|
70 | const char * usri0_name;
|
---|
71 | };
|
---|
72 |
|
---|
73 | struct USER_INFO_1 {
|
---|
74 | const char * usri1_name;
|
---|
75 | const char * usri1_password;
|
---|
76 | uint32_t usri1_password_age;
|
---|
77 | uint32_t usri1_priv;
|
---|
78 | const char * usri1_home_dir;
|
---|
79 | const char * usri1_comment;
|
---|
80 | uint32_t usri1_flags;
|
---|
81 | const char * usri1_script_path;
|
---|
82 | };
|
---|
83 |
|
---|
84 | struct NET_DISPLAY_USER {
|
---|
85 | const char * usri1_name;
|
---|
86 | const char * usri1_comment;
|
---|
87 | uint32_t usri1_flags;
|
---|
88 | const char * usri1_full_name;
|
---|
89 | uint32_t usri1_user_id;
|
---|
90 | uint32_t usri1_next_index;
|
---|
91 | };
|
---|
92 |
|
---|
93 | struct NET_DISPLAY_MACHINE {
|
---|
94 | const char * usri2_name;
|
---|
95 | const char * usri2_comment;
|
---|
96 | uint32_t usri2_flags;
|
---|
97 | uint32_t usri2_user_id;
|
---|
98 | uint32_t usri2_next_index;
|
---|
99 | };
|
---|
100 |
|
---|
101 | struct NET_DISPLAY_GROUP {
|
---|
102 | const char * grpi3_name;
|
---|
103 | const char * grpi3_comment;
|
---|
104 | uint32_t grpi3_group_id;
|
---|
105 | uint32_t grpi3_attributes;
|
---|
106 | uint32_t grpi3_next_index;
|
---|
107 | };
|
---|
108 |
|
---|
109 | #endif /* _HEADER_libnetapi */
|
---|
110 |
|
---|
111 | /****************************************************************
|
---|
112 | ****************************************************************/
|
---|
113 |
|
---|
114 | struct libnetapi_ctx {
|
---|
115 | char *debuglevel;
|
---|
116 | char *error_string;
|
---|
117 | char *username;
|
---|
118 | char *workgroup;
|
---|
119 | char *password;
|
---|
120 | char *krb5_cc_env;
|
---|
121 | int use_kerberos;
|
---|
122 | };
|
---|
123 |
|
---|
124 | /****************************************************************
|
---|
125 | ****************************************************************/
|
---|
126 |
|
---|
127 | NET_API_STATUS libnetapi_init(struct libnetapi_ctx **ctx);
|
---|
128 |
|
---|
129 | /****************************************************************
|
---|
130 | ****************************************************************/
|
---|
131 |
|
---|
132 | NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx);
|
---|
133 |
|
---|
134 | /****************************************************************
|
---|
135 | ****************************************************************/
|
---|
136 |
|
---|
137 | NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx);
|
---|
138 |
|
---|
139 | /****************************************************************
|
---|
140 | ****************************************************************/
|
---|
141 |
|
---|
142 | NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
|
---|
143 | const char *debuglevel);
|
---|
144 |
|
---|
145 | /****************************************************************
|
---|
146 | ****************************************************************/
|
---|
147 |
|
---|
148 | NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
|
---|
149 | const char *username);
|
---|
150 |
|
---|
151 | /****************************************************************
|
---|
152 | ****************************************************************/
|
---|
153 |
|
---|
154 | NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
|
---|
155 | const char *password);
|
---|
156 |
|
---|
157 | /****************************************************************
|
---|
158 | ****************************************************************/
|
---|
159 |
|
---|
160 | NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
|
---|
161 | const char *workgroup);
|
---|
162 |
|
---|
163 | /****************************************************************
|
---|
164 | ****************************************************************/
|
---|
165 |
|
---|
166 | NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx);
|
---|
167 |
|
---|
168 | /****************************************************************
|
---|
169 | ****************************************************************/
|
---|
170 |
|
---|
171 | const char *libnetapi_errstr(NET_API_STATUS status);
|
---|
172 |
|
---|
173 | /****************************************************************
|
---|
174 | ****************************************************************/
|
---|
175 |
|
---|
176 | const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx,
|
---|
177 | NET_API_STATUS status);
|
---|
178 |
|
---|
179 |
|
---|
180 | /****************************************************************
|
---|
181 | NetApiBufferFree
|
---|
182 | ****************************************************************/
|
---|
183 |
|
---|
184 | NET_API_STATUS NetApiBufferFree(void *buffer);
|
---|
185 |
|
---|
186 | /************************************************************//**
|
---|
187 | *
|
---|
188 | * NetJoinDomain
|
---|
189 | *
|
---|
190 | * @brief Join a computer to a domain or workgroup
|
---|
191 | *
|
---|
192 | * @param[in] server The server name to connect to
|
---|
193 | * @param[in] domain The domain or workgroup to join
|
---|
194 | * @param[in] account_ou The organizational Unit to create the computer account
|
---|
195 | * in (AD only)
|
---|
196 | * @param[in] account The domain account used for joining a domain
|
---|
197 | * @param[in] password The domain account's password used for joining a domain
|
---|
198 | * @param[in] join_flags Bitmask field to define specific join features
|
---|
199 | * @return NET_API_STATUS
|
---|
200 | *
|
---|
201 | * example netdomjoin/netdomjoin.c
|
---|
202 | ***************************************************************/
|
---|
203 |
|
---|
204 | NET_API_STATUS NetJoinDomain(const char * server /* [in] */,
|
---|
205 | const char * domain /* [in] [ref] */,
|
---|
206 | const char * account_ou /* [in] */,
|
---|
207 | const char * account /* [in] */,
|
---|
208 | const char * password /* [in] */,
|
---|
209 | uint32_t join_flags /* [in] */);
|
---|
210 |
|
---|
211 | /************************************************************//**
|
---|
212 | *
|
---|
213 | * NetUnjoinDomain
|
---|
214 | *
|
---|
215 | * @brief Unjoin a computer from a domain or workgroup
|
---|
216 | *
|
---|
217 | * @param[in] server_name The server name to connect to
|
---|
218 | * @param[in] account The domain account used for unjoining a domain
|
---|
219 | * @param[in] password The domain account's password used for unjoining a domain
|
---|
220 | * @param[in] unjoin_flags Bitmask field to define specific unjoin features
|
---|
221 | * @return NET_API_STATUS
|
---|
222 | *
|
---|
223 | ***************************************************************/
|
---|
224 |
|
---|
225 | NET_API_STATUS NetUnjoinDomain(const char * server_name /* [in] */,
|
---|
226 | const char * account /* [in] */,
|
---|
227 | const char * password /* [in] */,
|
---|
228 | uint32_t unjoin_flags /* [in] */);
|
---|
229 |
|
---|
230 | /************************************************************//**
|
---|
231 | *
|
---|
232 | * NetGetJoinInformation
|
---|
233 | *
|
---|
234 | * @brief Unjoin a computer from a domain or workgroup
|
---|
235 | *
|
---|
236 | * @param[in] server_name The server name to connect to
|
---|
237 | * @param[out] name_buffer Returns the name of the workgroup or domain
|
---|
238 | * @param[out] name_type Returns the type of that name
|
---|
239 | * @return NET_API_STATUS
|
---|
240 | *
|
---|
241 | * example netdomjoin-gui/netdomjoin-gui.c
|
---|
242 | *
|
---|
243 | ***************************************************************/
|
---|
244 |
|
---|
245 | NET_API_STATUS NetGetJoinInformation(const char * server_name /* [in] */,
|
---|
246 | const char * *name_buffer /* [out] [ref] */,
|
---|
247 | uint16_t *name_type /* [out] [ref] */);
|
---|
248 |
|
---|
249 | /************************************************************//**
|
---|
250 | *
|
---|
251 | * NetGetJoinableOUs
|
---|
252 | *
|
---|
253 | * @brief Query for the list of joinable organizational Units that can be used
|
---|
254 | * for joining AD
|
---|
255 | *
|
---|
256 | * @param[in] server_name The server name to connect to
|
---|
257 | * @param[in] domain The AD domain to query
|
---|
258 | * @param[in] account The domain account used for the query
|
---|
259 | * @param[in] password The domain account's password used for the query
|
---|
260 | * @param[out] ou_count The number of ous returned
|
---|
261 | * @param[out] ous Returned string array containing the ous
|
---|
262 | * @return NET_API_STATUS
|
---|
263 | *
|
---|
264 | * example netdomjoin-gui/netdomjoin-gui.c
|
---|
265 | *
|
---|
266 | ***************************************************************/
|
---|
267 |
|
---|
268 | NET_API_STATUS NetGetJoinableOUs(const char * server_name /* [in] */,
|
---|
269 | const char * domain /* [in] [ref] */,
|
---|
270 | const char * account /* [in] */,
|
---|
271 | const char * password /* [in] */,
|
---|
272 | uint32_t *ou_count /* [out] [ref] */,
|
---|
273 | const char * **ous /* [out] [ref] */);
|
---|
274 |
|
---|
275 | /************************************************************//**
|
---|
276 | *
|
---|
277 | * NetServerGetInfo
|
---|
278 | *
|
---|
279 | * @brief Get Information on a server
|
---|
280 | *
|
---|
281 | * @param[in] server_name The server name to connect to
|
---|
282 | * @param[in] level The level to define which information is requested
|
---|
283 | * @param[out] buffer The returned buffer carrying the SERVER_INFO structure
|
---|
284 | * @return NET_API_STATUS
|
---|
285 | *
|
---|
286 | ***************************************************************/
|
---|
287 |
|
---|
288 | NET_API_STATUS NetServerGetInfo(const char * server_name /* [in] */,
|
---|
289 | uint32_t level /* [in] */,
|
---|
290 | uint8_t **buffer /* [out] [ref] */);
|
---|
291 |
|
---|
292 | /************************************************************//**
|
---|
293 | *
|
---|
294 | * NetServerSetInfo
|
---|
295 | *
|
---|
296 | * @brief Get Information on a server
|
---|
297 | *
|
---|
298 | * @param[in] server_name The server name to connect to
|
---|
299 | * @param[in] level The level to define which information is set
|
---|
300 | * @param[in] buffer The buffer carrying the SERVER_INFO structure
|
---|
301 | * @param[out] parm_error On failure returns the invalid SERVER_INFO member
|
---|
302 | * @return NET_API_STATUS
|
---|
303 | *
|
---|
304 | ***************************************************************/
|
---|
305 |
|
---|
306 | NET_API_STATUS NetServerSetInfo(const char * server_name /* [in] */,
|
---|
307 | uint32_t level /* [in] */,
|
---|
308 | uint8_t *buffer /* [in] [ref] */,
|
---|
309 | uint32_t *parm_error /* [out] [ref] */);
|
---|
310 |
|
---|
311 | /************************************************************//**
|
---|
312 | *
|
---|
313 | * NetGetDCName
|
---|
314 | *
|
---|
315 | * @brief Query for the PDC for a given domain
|
---|
316 | *
|
---|
317 | * @param[in] server_name The server name to connect to
|
---|
318 | * @param[in] domain_name The name of the domain to lookup
|
---|
319 | * @param[out] buffer The name of the domain to lookup
|
---|
320 | * @return NET_API_STATUS
|
---|
321 | *
|
---|
322 | * example getdc/getdc.c
|
---|
323 | ***************************************************************/
|
---|
324 |
|
---|
325 | NET_API_STATUS NetGetDCName(const char * server_name /* [in] */,
|
---|
326 | const char * domain_name /* [in] */,
|
---|
327 | uint8_t **buffer /* [out] [ref] */);
|
---|
328 |
|
---|
329 | /************************************************************//**
|
---|
330 | *
|
---|
331 | * NetGetAnyDCName
|
---|
332 | *
|
---|
333 | * @brief Query for any DC for a given domain
|
---|
334 | *
|
---|
335 | * @param[in] server_name The server name to connect to
|
---|
336 | * @param[in] domain_name The name of the domain to lookup
|
---|
337 | * @param[out] buffer The name of the domain to lookup
|
---|
338 | * @return NET_API_STATUS
|
---|
339 | *
|
---|
340 | * example getdc/getdc.c
|
---|
341 | ***************************************************************/
|
---|
342 |
|
---|
343 | NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */,
|
---|
344 | const char * domain_name /* [in] */,
|
---|
345 | uint8_t **buffer /* [out] [ref] */);
|
---|
346 |
|
---|
347 |
|
---|
348 | /************************************************************//**
|
---|
349 | *
|
---|
350 | * DsGetDcName
|
---|
351 | *
|
---|
352 | * @brief Lookup a DC for a given domain and return information structure
|
---|
353 | *
|
---|
354 | * @param[in] server_name The server name to connect to
|
---|
355 | * @param[in] domain_name The name of the domain to lookup (cannot be NULL)
|
---|
356 | * @param[in] domain_guid The GUID of the domain to lookup (optional)
|
---|
357 | * @param[in] site_name The name of the site the DC should reside in
|
---|
358 | * @param[in] flags A bitmask to request specific features supported by the DC
|
---|
359 | * @param[out] dc_info Pointer to a DOMAIN_CONTROLLER_INFO structure
|
---|
360 | * @return NET_API_STATUS
|
---|
361 | *
|
---|
362 | * example dsgetdc/dsgetdc.c
|
---|
363 | ***************************************************************/
|
---|
364 |
|
---|
365 | NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
|
---|
366 | const char * domain_name /* [in] [ref] */,
|
---|
367 | struct GUID *domain_guid /* [in] [unique] */,
|
---|
368 | const char * site_name /* [in] [unique] */,
|
---|
369 | uint32_t flags /* [in] */,
|
---|
370 | struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */);
|
---|
371 |
|
---|
372 | /************************************************************//**
|
---|
373 | *
|
---|
374 | * NetUserAdd
|
---|
375 | *
|
---|
376 | * @brief Create a user on a given server
|
---|
377 | *
|
---|
378 | * @param[in] server_name The server name to connect to
|
---|
379 | * @param[in] level The level of the USER_INFO structure passed in (Currently
|
---|
380 | * only level 1 is supported)
|
---|
381 | * @param[in] buffer The buffer carrying the USER_INFO structure
|
---|
382 | * @param[out] parm_error In case of error returns the failing member of the
|
---|
383 | * structure
|
---|
384 | * @return NET_API_STATUS
|
---|
385 | *
|
---|
386 | * example user/user_add.c
|
---|
387 | ***************************************************************/
|
---|
388 |
|
---|
389 | NET_API_STATUS NetUserAdd(const char * server_name /* [in] */,
|
---|
390 | uint32_t level /* [in] */,
|
---|
391 | uint8_t *buffer /* [in] [ref] */,
|
---|
392 | uint32_t *parm_error /* [out] [ref] */);
|
---|
393 |
|
---|
394 | /************************************************************//**
|
---|
395 | *
|
---|
396 | * NetUserDel
|
---|
397 | *
|
---|
398 | * @brief Delete a user on a given server
|
---|
399 | *
|
---|
400 | * @param[in] server_name The server name to connect to
|
---|
401 | * @param[in] user_name The user account to delete
|
---|
402 | * @return NET_API_STATUS
|
---|
403 | *
|
---|
404 | * example user/user_del.c
|
---|
405 | ***************************************************************/
|
---|
406 |
|
---|
407 | NET_API_STATUS NetUserDel(const char * server_name /* [in] */,
|
---|
408 | const char * user_name /* [in] */);
|
---|
409 |
|
---|
410 | /************************************************************//**
|
---|
411 | *
|
---|
412 | * NetUserEnum
|
---|
413 | *
|
---|
414 | * @brief Enumerate accounts on a server
|
---|
415 | *
|
---|
416 | * @param[in] server_name The server name to connect to
|
---|
417 | * @param[in] level The enumeration level used for the query (Currently only
|
---|
418 | * level 0 is supported)
|
---|
419 | * @param[in] filter The account flags filter used for the query
|
---|
420 | * @param[out] buffer The returned enumeration buffer
|
---|
421 | * @param[in] prefmaxlen The requested maximal buffer size
|
---|
422 | * @param[out] entries_read The number of returned entries
|
---|
423 | * @param[out] total_entries The number of total entries
|
---|
424 | * @param[in,out] resume_handle A handle passed in and returned for resuming
|
---|
425 | * operations
|
---|
426 | * @return NET_API_STATUS
|
---|
427 | *
|
---|
428 | * example user/user_enum.c
|
---|
429 | ***************************************************************/
|
---|
430 |
|
---|
431 | NET_API_STATUS NetUserEnum(const char * server_name /* [in] */,
|
---|
432 | uint32_t level /* [in] */,
|
---|
433 | uint32_t filter /* [in] */,
|
---|
434 | uint8_t **buffer /* [out] [ref] */,
|
---|
435 | uint32_t prefmaxlen /* [in] */,
|
---|
436 | uint32_t *entries_read /* [out] [ref] */,
|
---|
437 | uint32_t *total_entries /* [out] [ref] */,
|
---|
438 | uint32_t *resume_handle /* [in,out] [ref] */);
|
---|
439 |
|
---|
440 | /************************************************************//**
|
---|
441 | *
|
---|
442 | * NetQueryDisplayInformation
|
---|
443 | *
|
---|
444 | * @brief Enumerate accounts on a server
|
---|
445 | *
|
---|
446 | * @param[in] server_name The server name to connect to
|
---|
447 | * @param[in] level The enumeration level used for the query
|
---|
448 | * @param[in] idx The index to start the the display enumeration at
|
---|
449 | * @param[in] entries_requested The number of entries requested
|
---|
450 | * @param[in] prefmaxlen The requested maximal buffer size
|
---|
451 | * @param[out] entries_read The number of returned entries
|
---|
452 | * @param[out] buffer The returned display information buffer
|
---|
453 | * @return NET_API_STATUS
|
---|
454 | *
|
---|
455 | * example user/user_dispinfo.c
|
---|
456 | ***************************************************************/
|
---|
457 |
|
---|
458 | NET_API_STATUS NetQueryDisplayInformation(const char * server_name /* [in] [unique] */,
|
---|
459 | uint32_t level /* [in] */,
|
---|
460 | uint32_t idx /* [in] */,
|
---|
461 | uint32_t entries_requested /* [in] */,
|
---|
462 | uint32_t prefmaxlen /* [in] */,
|
---|
463 | uint32_t *entries_read /* [out] [ref] */,
|
---|
464 | void **buffer /* [out] [noprint,ref] */);
|
---|
465 |
|
---|
466 | #ifdef __cplusplus
|
---|
467 | }
|
---|
468 | #endif /* __cplusplus */
|
---|
469 |
|
---|
470 | #endif /* __LIB_NETAPI_H__ */
|
---|