1 /* Copyright 2001 Mike McCormack
2 * Copyright 2002 Andriy Palamarchuk
3 * Copyright 2003 Juan Lang
4 * Copyright 2005,2006 Paul Vriens
5 * Copyright 2006 Robert Reif
6 * Copyright 2013 Hans Leidekker for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
29 #ifdef HAVE_SYS_WAIT_H
37 #define WIN32_NO_STATUS
54 #include "wine/debug.h"
55 #include "wine/library.h"
56 #include "wine/list.h"
57 #include "wine/unicode.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
61 static char *strdup_unixcp( const WCHAR
*str
)
64 int len
= WideCharToMultiByte( CP_UNIXCP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
65 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
66 WideCharToMultiByte( CP_UNIXCP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
70 #ifdef SONAME_LIBNETAPI
72 static void *libnetapi_handle
;
73 static void *libnetapi_ctx
;
75 static DWORD (*plibnetapi_init
)(void **);
76 static DWORD (*plibnetapi_free
)(void *);
77 static DWORD (*plibnetapi_set_debuglevel
)(void *, const char *);
78 static DWORD (*plibnetapi_set_username
)(void *, const char *);
79 static DWORD (*plibnetapi_set_password
)(void *, const char *);
81 static NET_API_STATUS (*pNetApiBufferAllocate
)(unsigned int, void **);
82 static NET_API_STATUS (*pNetApiBufferFree
)(void *);
83 static NET_API_STATUS (*pNetServerGetInfo
)(const char *, unsigned int, unsigned char **);
84 static NET_API_STATUS (*pNetShareAdd
)(const char *, unsigned int, unsigned char *, unsigned int *);
85 static NET_API_STATUS (*pNetShareDel
)(const char *, const char *, unsigned int);
86 static NET_API_STATUS (*pNetWkstaGetInfo
)(const char *, unsigned int, unsigned char **);
88 static void destroy_context(void)
90 TRACE( "destroying %p\n", libnetapi_ctx
);
91 plibnetapi_free( libnetapi_ctx
);
95 static BOOL
init_context(void)
99 if ((status
= plibnetapi_init( &libnetapi_ctx
)))
101 ERR( "Failed to initialize context %u\n", status
);
104 if (TRACE_ON( netapi32
) && (status
= plibnetapi_set_debuglevel( libnetapi_ctx
, "10" )))
106 ERR( "Failed to set debug level %u\n", status
);
110 /* perform an anonymous login by default (avoids a password prompt) */
111 if ((status
= plibnetapi_set_username( libnetapi_ctx
, "Guest" )))
113 ERR( "Failed to set username %u\n", status
);
117 if ((status
= plibnetapi_set_password( libnetapi_ctx
, "" )))
119 ERR( "Failed to set password %u\n", status
);
123 TRACE( "using %p\n", libnetapi_ctx
);
127 static BOOL
libnetapi_init(void)
131 if (libnetapi_handle
) return TRUE
;
132 if (!(libnetapi_handle
= wine_dlopen( SONAME_LIBNETAPI
, RTLD_NOW
, buf
, sizeof(buf
) )))
134 WARN( "Failed to load libnetapi: %s\n", buf
);
138 #define LOAD_FUNCPTR(f) \
139 if (!(p##f = wine_dlsym( libnetapi_handle, #f, buf, sizeof(buf) ))) \
141 ERR( "Failed to load %s: %s\n", #f, buf ); \
145 LOAD_FUNCPTR(libnetapi_init
)
146 LOAD_FUNCPTR(libnetapi_free
)
147 LOAD_FUNCPTR(libnetapi_set_debuglevel
)
148 LOAD_FUNCPTR(libnetapi_set_username
)
149 LOAD_FUNCPTR(libnetapi_set_password
)
151 LOAD_FUNCPTR(NetApiBufferAllocate
)
152 LOAD_FUNCPTR(NetApiBufferFree
)
153 LOAD_FUNCPTR(NetServerGetInfo
)
154 LOAD_FUNCPTR(NetShareAdd
)
155 LOAD_FUNCPTR(NetShareDel
)
156 LOAD_FUNCPTR(NetWkstaGetInfo
)
159 if (init_context()) return TRUE
;
162 wine_dlclose( libnetapi_handle
, NULL
, 0 );
163 libnetapi_handle
= NULL
;
167 struct server_info_101
169 unsigned int sv101_platform_id
;
170 const char *sv101_name
;
171 unsigned int sv101_version_major
;
172 unsigned int sv101_version_minor
;
173 unsigned int sv101_type
;
174 const char *sv101_comment
;
177 static NET_API_STATUS
server_info_101_from_samba( const unsigned char *buf
, BYTE
**bufptr
)
179 SERVER_INFO_101
*ret
;
180 struct server_info_101
*info
= (struct server_info_101
*)buf
;
184 if (info
->sv101_name
) len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->sv101_name
, -1, NULL
, 0 );
185 if (info
->sv101_comment
) len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->sv101_comment
, -1, NULL
, 0 );
186 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ret
) + (len
* sizeof(WCHAR
) ))))
187 return ERROR_OUTOFMEMORY
;
189 ptr
= (WCHAR
*)(ret
+ 1);
190 ret
->sv101_platform_id
= info
->sv101_platform_id
;
191 if (!info
->sv101_name
) ret
->sv101_name
= NULL
;
194 ret
->sv101_name
= ptr
;
195 ptr
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->sv101_name
, -1, ptr
, len
);
197 ret
->sv101_version_major
= info
->sv101_version_major
;
198 ret
->sv101_version_minor
= info
->sv101_version_minor
;
199 ret
->sv101_type
= info
->sv101_type
;
200 if (!info
->sv101_comment
) ret
->sv101_comment
= NULL
;
203 ret
->sv101_comment
= ptr
;
204 MultiByteToWideChar( CP_UNIXCP
, 0, info
->sv101_comment
, -1, ptr
, len
);
206 *bufptr
= (BYTE
*)ret
;
210 static NET_API_STATUS
server_info_from_samba( DWORD level
, const unsigned char *buf
, BYTE
**bufptr
)
214 case 101: return server_info_101_from_samba( buf
, bufptr
);
216 FIXME( "level %u not supported\n", level
);
217 return ERROR_NOT_SUPPORTED
;
221 static NET_API_STATUS
server_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
223 NET_API_STATUS status
;
225 unsigned char *buf
= NULL
;
227 if (servername
&& !(server
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
228 status
= pNetServerGetInfo( server
, level
, &buf
);
229 HeapFree( GetProcessHeap(), 0, server
);
232 status
= server_info_from_samba( level
, buf
, bufptr
);
233 pNetApiBufferFree( buf
);
240 const char *shi2_netname
;
241 unsigned int shi2_type
;
242 const char *shi2_remark
;
243 unsigned int shi2_permissions
;
244 unsigned int shi2_max_uses
;
245 unsigned int shi2_current_uses
;
246 const char *shi2_path
;
247 const char *shi2_passwd
;
250 static NET_API_STATUS
share_info_2_to_samba( const BYTE
*buf
, unsigned char **bufptr
)
252 struct share_info_2
*ret
;
253 SHARE_INFO_2
*info
= (SHARE_INFO_2
*)buf
;
257 if (info
->shi2_netname
)
258 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_netname
, -1, NULL
, 0, NULL
, NULL
);
259 if (info
->shi2_remark
)
260 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_remark
, -1, NULL
, 0, NULL
, NULL
);
262 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_path
, -1, NULL
, 0, NULL
, NULL
);
263 if (info
->shi2_passwd
)
264 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_passwd
, -1, NULL
, 0, NULL
, NULL
);
265 if (!(ret
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret
) + len
)))
266 return ERROR_OUTOFMEMORY
;
268 ptr
= (char *)(ret
+ 1);
269 if (!info
->shi2_netname
) ret
->shi2_netname
= NULL
;
272 ret
->shi2_netname
= ptr
;
273 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_netname
, -1, ptr
, len
, NULL
, NULL
);
275 ret
->shi2_type
= info
->shi2_type
;
276 if (!info
->shi2_remark
) ret
->shi2_remark
= NULL
;
279 ret
->shi2_remark
= ptr
;
280 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_remark
, -1, ptr
, len
, NULL
, NULL
);
282 ret
->shi2_permissions
= info
->shi2_permissions
;
283 ret
->shi2_max_uses
= info
->shi2_max_uses
;
284 ret
->shi2_current_uses
= info
->shi2_current_uses
;
285 if (!info
->shi2_path
) ret
->shi2_path
= NULL
;
288 ret
->shi2_path
= ptr
;
289 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_path
, -1, ptr
, len
, NULL
, NULL
);
291 if (!info
->shi2_passwd
) ret
->shi2_passwd
= NULL
;
294 ret
->shi2_passwd
= ptr
;
295 WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi2_passwd
, -1, ptr
, len
, NULL
, NULL
);
297 *bufptr
= (unsigned char *)ret
;
303 unsigned char sid_rev_num
;
304 unsigned char num_auths
;
305 unsigned char id_auth
[6];
306 unsigned int sub_auths
[15];
311 ACE_TYPE_ACCESS_ALLOWED
,
312 ACE_TYPE_ACCESS_DENIED
,
313 ACE_TYPE_SYSTEM_AUDIT
,
314 ACE_TYPE_SYSTEM_ALARM
,
315 ACE_TYPE_ALLOWED_COMPOUND
,
316 ACE_TYPE_ACCESS_ALLOWED_OBJECT
,
317 ACE_TYPE_ACCESS_DENIED_OBJECT
,
318 ACE_TYPE_SYSTEM_AUDIT_OBJECT
,
319 ACE_TYPE_SYSTEM_ALARM_OBJECT
322 #define SEC_ACE_FLAG_OBJECT_INHERIT 0x01
323 #define SEC_ACE_FLAG_CONTAINER_INHERIT 0x02
324 #define SEC_ACE_FLAG_NO_PROPAGATE_INHERIT 0x04
325 #define SEC_ACE_FLAG_INHERIT_ONLY 0x08
326 #define SEC_ACE_FLAG_INHERITED_ACE 0x10
327 #define SEC_ACE_FLAG_SUCCESSFUL_ACCESS 0x40
328 #define SEC_ACE_FLAG_FAILED_ACCESS 0x80
332 unsigned int time_low
;
333 unsigned short time_mid
;
334 unsigned short time_hi_and_version
;
335 unsigned char clock_seq
[2];
336 unsigned char node
[6];
339 union ace_object_type
344 union ace_object_inherited_type
346 struct guid inherited_type
;
352 union ace_object_type type
;
353 union ace_object_inherited_type inherited_type
;
358 struct ace_object object
;
366 unsigned int access_mask
;
367 union ace_object_ctr object
;
373 ACL_REVISION_NT4
= 2,
379 enum acl_revision revision
;
381 unsigned int num_aces
;
385 enum security_descriptor_revision
387 SECURITY_DESCRIPTOR_REVISION_1
= 1
390 #define SEC_DESC_OWNER_DEFAULTED 0x0001
391 #define SEC_DESC_GROUP_DEFAULTED 0x0002
392 #define SEC_DESC_DACL_PRESENT 0x0004
393 #define SEC_DESC_DACL_DEFAULTED 0x0008
394 #define SEC_DESC_SACL_PRESENT 0x0010
395 #define SEC_DESC_SACL_DEFAULTED 0x0020
396 #define SEC_DESC_DACL_TRUSTED 0x0040
397 #define SEC_DESC_SERVER_SECURITY 0x0080
398 #define SEC_DESC_DACL_AUTO_INHERIT_REQ 0x0100
399 #define SEC_DESC_SACL_AUTO_INHERIT_REQ 0x0200
400 #define SEC_DESC_DACL_AUTO_INHERITED 0x0400
401 #define SEC_DESC_SACL_AUTO_INHERITED 0x0800
402 #define SEC_DESC_DACL_PROTECTED 0x1000
403 #define SEC_DESC_SACL_PROTECTED 0x2000
404 #define SEC_DESC_RM_CONTROL_VALID 0x4000
405 #define SEC_DESC_SELF_RELATIVE 0x8000
407 struct security_descriptor
409 enum security_descriptor_revision revision
;
411 struct sid
*owner_sid
;
412 struct sid
*group_sid
;
417 struct share_info_502
419 const char *shi502_netname
;
420 unsigned int shi502_type
;
421 const char *shi502_remark
;
422 unsigned int shi502_permissions
;
423 unsigned int shi502_max_uses
;
424 unsigned int shi502_current_uses
;
425 const char *shi502_path
;
426 const char *shi502_passwd
;
427 unsigned int shi502_reserved
;
428 struct security_descriptor
*shi502_security_descriptor
;
431 static unsigned short sd_control_to_samba( SECURITY_DESCRIPTOR_CONTROL control
)
433 unsigned short ret
= 0;
435 if (control
& SE_OWNER_DEFAULTED
) ret
|= SEC_DESC_OWNER_DEFAULTED
;
436 if (control
& SE_GROUP_DEFAULTED
) ret
|= SEC_DESC_GROUP_DEFAULTED
;
437 if (control
& SE_DACL_PRESENT
) ret
|= SEC_DESC_DACL_PRESENT
;
438 if (control
& SE_DACL_DEFAULTED
) ret
|= SEC_DESC_DACL_DEFAULTED
;
439 if (control
& SE_SACL_PRESENT
) ret
|= SEC_DESC_SACL_PRESENT
;
440 if (control
& SE_SACL_DEFAULTED
) ret
|= SEC_DESC_SACL_DEFAULTED
;
441 if (control
& SE_DACL_AUTO_INHERIT_REQ
) ret
|= SEC_DESC_DACL_AUTO_INHERIT_REQ
;
442 if (control
& SE_SACL_AUTO_INHERIT_REQ
) ret
|= SEC_DESC_SACL_AUTO_INHERIT_REQ
;
443 if (control
& SE_DACL_AUTO_INHERITED
) ret
|= SEC_DESC_DACL_AUTO_INHERITED
;
444 if (control
& SE_SACL_AUTO_INHERITED
) ret
|= SEC_DESC_SACL_AUTO_INHERITED
;
445 if (control
& SE_DACL_PROTECTED
) ret
|= SEC_DESC_DACL_PROTECTED
;
446 if (control
& SE_SACL_PROTECTED
) ret
|= SEC_DESC_SACL_PROTECTED
;
447 if (control
& SE_RM_CONTROL_VALID
) ret
|= SEC_DESC_RM_CONTROL_VALID
;
451 static NET_API_STATUS
sid_to_samba( const SID
*src
, struct sid
*dst
)
455 if (src
->Revision
!= 1)
457 ERR( "unknown revision %u\n", src
->Revision
);
458 return ERROR_UNKNOWN_REVISION
;
460 if (src
->SubAuthorityCount
> SID_MAX_SUB_AUTHORITIES
)
462 WARN( "invalid subauthority count %u\n", src
->SubAuthorityCount
);
463 return ERROR_INVALID_PARAMETER
;
465 dst
->sid_rev_num
= SECURITY_DESCRIPTOR_REVISION_1
;
466 dst
->num_auths
= src
->SubAuthorityCount
;
467 for (i
= 0; i
< 6; i
++) dst
->id_auth
[i
] = src
->IdentifierAuthority
.Value
[i
];
468 for (i
= 0; i
< dst
->num_auths
; i
++) dst
->sub_auths
[i
] = src
->SubAuthority
[i
];
472 static enum ace_type
ace_type_to_samba( BYTE type
)
476 case ACCESS_ALLOWED_ACE_TYPE
: return ACE_TYPE_ACCESS_ALLOWED
;
477 case ACCESS_DENIED_ACE_TYPE
: return ACE_TYPE_ACCESS_DENIED
;
478 case SYSTEM_AUDIT_ACE_TYPE
: return ACE_TYPE_SYSTEM_AUDIT
;
479 case SYSTEM_ALARM_ACE_TYPE
: return ACE_TYPE_SYSTEM_ALARM
;
481 ERR( "unhandled type %u\n", type
);
486 static unsigned char ace_flags_to_samba( BYTE flags
)
488 static const BYTE known_flags
=
489 OBJECT_INHERIT_ACE
| CONTAINER_INHERIT_ACE
| NO_PROPAGATE_INHERIT_ACE
|
490 INHERIT_ONLY_ACE
| INHERITED_ACE
| SUCCESSFUL_ACCESS_ACE_FLAG
| FAILED_ACCESS_ACE_FLAG
;
491 unsigned char ret
= 0;
493 if (flags
& ~known_flags
)
495 ERR( "unknown flags %x\n", flags
& ~known_flags
);
498 if (flags
& OBJECT_INHERIT_ACE
) ret
|= SEC_ACE_FLAG_OBJECT_INHERIT
;
499 if (flags
& CONTAINER_INHERIT_ACE
) ret
|= SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
;
500 if (flags
& NO_PROPAGATE_INHERIT_ACE
) ret
|= SEC_ACE_FLAG_NO_PROPAGATE_INHERIT
;
501 if (flags
& INHERIT_ONLY_ACE
) ret
|= SEC_ACE_FLAG_INHERIT_ONLY
;
502 if (flags
& INHERITED_ACE
) ret
|= SEC_ACE_FLAG_INHERITED_ACE
;
503 if (flags
& SUCCESSFUL_ACCESS_ACE_FLAG
) ret
|= SEC_ACE_FLAG_SUCCESSFUL_ACCESS
;
504 if (flags
& FAILED_ACCESS_ACE_FLAG
) ret
|= SEC_ACE_FLAG_FAILED_ACCESS
;
508 #define GENERIC_ALL_ACCESS (1 << 28)
509 #define GENERIC_EXECUTE_ACCESS (1 << 29)
510 #define GENERIC_WRITE_ACCESS (1 << 30)
511 #define GENERIC_READ_ACCESS (1 << 31)
513 static unsigned int access_mask_to_samba( DWORD mask
)
515 static const DWORD known_rights
=
516 GENERIC_ALL
| GENERIC_EXECUTE
| GENERIC_WRITE
| GENERIC_READ
;
517 unsigned int ret
= 0;
519 if (mask
& ~known_rights
)
521 ERR( "unknown rights %x\n", mask
& ~known_rights
);
524 if (mask
& GENERIC_ALL
) ret
|= GENERIC_ALL_ACCESS
;
525 if (mask
& GENERIC_EXECUTE
) ret
|= GENERIC_EXECUTE_ACCESS
;
526 if (mask
& GENERIC_WRITE
) ret
|= GENERIC_WRITE_ACCESS
;
527 if (mask
& GENERIC_READ
) ret
|= GENERIC_READ_ACCESS
;
531 static NET_API_STATUS
ace_to_samba( const ACE_HEADER
*src
, struct ace
*dst
)
533 dst
->type
= ace_type_to_samba( src
->AceType
);
534 dst
->flags
= ace_flags_to_samba( src
->AceFlags
);
535 dst
->size
= sizeof(*dst
);
536 switch (src
->AceType
)
538 case ACCESS_ALLOWED_ACE_TYPE
:
540 ACCESS_ALLOWED_ACE
*ace
= (ACCESS_ALLOWED_ACE
*)src
;
541 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
542 memset( &dst
->object
, 0, sizeof(dst
->object
) );
543 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
546 case ACCESS_DENIED_ACE_TYPE
:
548 ACCESS_DENIED_ACE
*ace
= (ACCESS_DENIED_ACE
*)src
;
549 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
550 memset( &dst
->object
, 0, sizeof(dst
->object
) );
551 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
554 case SYSTEM_AUDIT_ACE_TYPE
:
556 SYSTEM_AUDIT_ACE
*ace
= (SYSTEM_AUDIT_ACE
*)src
;
557 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
558 memset( &dst
->object
, 0, sizeof(dst
->object
) );
559 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
562 case SYSTEM_ALARM_ACE_TYPE
:
564 SYSTEM_ALARM_ACE
*ace
= (SYSTEM_ALARM_ACE
*)src
;
565 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
566 memset( &dst
->object
, 0, sizeof(dst
->object
) );
567 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
571 ERR( "unhandled type %u\n", src
->AceType
);
572 return ERROR_INVALID_PARAMETER
;
577 static NET_API_STATUS
acl_to_samba( const ACL
*src
, struct acl
*dst
)
579 NET_API_STATUS status
;
583 switch (src
->AclRevision
)
586 dst
->revision
= ACL_REVISION_ADS
;
589 ERR( "unkhandled revision %u\n", src
->AclRevision
);
590 return ERROR_UNKNOWN_REVISION
;
592 dst
->size
= sizeof(*dst
);
593 src_ace
= (ACE_HEADER
*)(src
+ 1);
594 dst
->aces
= (struct ace
*)(dst
+ 1);
595 for (i
= 0; i
< src
->AceCount
; i
++)
597 if ((status
= ace_to_samba( src_ace
, &dst
->aces
[i
] ))) return status
;
598 src_ace
= (ACE_HEADER
*)((char *)src_ace
+ src_ace
->AceSize
);
599 dst
->size
+= dst
->aces
[i
].size
;
604 #define SELF_RELATIVE_FIELD(sd,field)\
605 ((char *)(sd) + ((SECURITY_DESCRIPTOR_RELATIVE *)(sd))->field)
607 static NET_API_STATUS
sd_to_samba( const SECURITY_DESCRIPTOR
*src
, struct security_descriptor
*dst
)
609 NET_API_STATUS status
;
610 const SID
*owner
, *group
;
611 const ACL
*dacl
, *sacl
;
612 unsigned int offset
= sizeof(*dst
);
614 if (src
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
615 return ERROR_UNKNOWN_REVISION
;
617 dst
->revision
= SECURITY_DESCRIPTOR_REVISION_1
;
618 dst
->type
= sd_control_to_samba( src
->Control
);
620 if (src
->Control
& SE_SELF_RELATIVE
)
622 if (!src
->Owner
) dst
->owner_sid
= NULL
;
625 dst
->owner_sid
= (struct sid
*)((char *)dst
+ offset
);
626 owner
= (const SID
*)SELF_RELATIVE_FIELD( src
, Owner
);
627 if ((status
= sid_to_samba( owner
, dst
->owner_sid
))) return status
;
628 offset
+= sizeof(struct sid
);
630 if (!src
->Group
) dst
->group_sid
= NULL
;
633 dst
->group_sid
= (struct sid
*)((char *)dst
+ offset
);
634 group
= (const SID
*)SELF_RELATIVE_FIELD( src
, Group
);
635 if ((status
= sid_to_samba( group
, dst
->group_sid
))) return status
;
636 offset
+= sizeof(struct sid
);
638 if (!(src
->Control
& SE_SACL_PRESENT
)) dst
->sacl
= NULL
;
641 dst
->sacl
= (struct acl
*)((char *)dst
+ offset
);
642 sacl
= (const ACL
*)SELF_RELATIVE_FIELD( src
, Sacl
);
643 if ((status
= acl_to_samba( sacl
, dst
->sacl
))) return status
;
644 offset
+= dst
->sacl
->size
;
646 if (!(src
->Control
& SE_DACL_PRESENT
)) dst
->dacl
= NULL
;
649 dst
->dacl
= (struct acl
*)((char *)dst
+ offset
);
650 dacl
= (const ACL
*)SELF_RELATIVE_FIELD( src
, Dacl
);
651 if ((status
= acl_to_samba( dacl
, dst
->dacl
))) return status
;
656 if (!src
->Owner
) dst
->owner_sid
= NULL
;
659 dst
->owner_sid
= (struct sid
*)((char *)dst
+ offset
);
660 if ((status
= sid_to_samba( src
->Owner
, dst
->owner_sid
))) return status
;
661 offset
+= sizeof(struct sid
);
663 if (!src
->Group
) dst
->group_sid
= NULL
;
666 dst
->group_sid
= (struct sid
*)((char *)dst
+ offset
);
667 if ((status
= sid_to_samba( src
->Group
, dst
->group_sid
))) return status
;
668 offset
+= sizeof(struct sid
);
670 if (!(src
->Control
& SE_SACL_PRESENT
)) dst
->sacl
= NULL
;
673 dst
->sacl
= (struct acl
*)((char *)dst
+ offset
);
674 if ((status
= acl_to_samba( src
->Sacl
, dst
->sacl
))) return status
;
675 offset
+= dst
->sacl
->size
;
677 if (!(src
->Control
& SE_DACL_PRESENT
)) dst
->dacl
= NULL
;
680 dst
->dacl
= (struct acl
*)((char *)dst
+ offset
);
681 if ((status
= acl_to_samba( src
->Dacl
, dst
->dacl
))) return status
;
687 static unsigned int sd_to_samba_size( const SECURITY_DESCRIPTOR
*sd
)
689 unsigned int ret
= sizeof(struct security_descriptor
);
691 if (sd
->Owner
) ret
+= sizeof(struct sid
);
692 if (sd
->Group
) ret
+= sizeof(struct sid
);
693 if (sd
->Control
& SE_SACL_PRESENT
)
694 ret
+= sizeof(struct acl
) + sd
->Sacl
->AceCount
* sizeof(struct ace
);
695 if (sd
->Control
& SE_DACL_PRESENT
)
696 ret
+= sizeof(struct acl
) + sd
->Dacl
->AceCount
* sizeof(struct ace
);
700 static NET_API_STATUS
share_info_502_to_samba( const BYTE
*buf
, unsigned char **bufptr
)
702 NET_API_STATUS status
;
703 struct share_info_502
*ret
;
704 SHARE_INFO_502
*info
= (SHARE_INFO_502
*)buf
;
705 DWORD len
= 0, size
= 0;
709 if (info
->shi502_netname
)
710 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_netname
, -1, NULL
, 0, NULL
, NULL
);
711 if (info
->shi502_remark
)
712 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_remark
, -1, NULL
, 0, NULL
, NULL
);
713 if (info
->shi502_path
)
714 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_path
, -1, NULL
, 0, NULL
, NULL
);
715 if (info
->shi502_passwd
)
716 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_passwd
, -1, NULL
, 0, NULL
, NULL
);
717 if (info
->shi502_security_descriptor
)
718 size
= sd_to_samba_size( info
->shi502_security_descriptor
);
719 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ret
) + (len
* sizeof(WCHAR
)) + size
)))
720 return ERROR_OUTOFMEMORY
;
722 ptr
= (char *)(ret
+ 1);
723 if (!info
->shi502_netname
) ret
->shi502_netname
= NULL
;
726 ret
->shi502_netname
= ptr
;
727 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_netname
, -1, ptr
, len
, NULL
, NULL
);
729 ret
->shi502_type
= info
->shi502_type
;
730 if (!info
->shi502_remark
) ret
->shi502_remark
= NULL
;
733 ret
->shi502_remark
= ptr
;
734 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_remark
, -1, ptr
, len
, NULL
, NULL
);
736 ret
->shi502_permissions
= info
->shi502_permissions
;
737 ret
->shi502_max_uses
= info
->shi502_max_uses
;
738 ret
->shi502_current_uses
= info
->shi502_current_uses
;
739 if (!info
->shi502_path
) ret
->shi502_path
= NULL
;
742 ret
->shi502_path
= ptr
;
743 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_path
, -1, ptr
, len
, NULL
, NULL
);
745 if (!info
->shi502_passwd
) ret
->shi502_passwd
= NULL
;
748 ret
->shi502_passwd
= ptr
;
749 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_passwd
, -1, ptr
, len
, NULL
, NULL
);
751 ret
->shi502_reserved
= info
->shi502_reserved
;
752 if (!info
->shi502_security_descriptor
) ret
->shi502_security_descriptor
= NULL
;
755 status
= sd_to_samba( info
->shi502_security_descriptor
, (struct security_descriptor
*)ptr
);
758 HeapFree( GetProcessHeap(), 0, ret
);
761 ret
->shi502_security_descriptor
= (struct security_descriptor
*)ptr
;
763 *bufptr
= (unsigned char *)ret
;
767 static NET_API_STATUS
share_info_to_samba( DWORD level
, const BYTE
*buf
, unsigned char **bufptr
)
771 case 2: return share_info_2_to_samba( buf
, bufptr
);
772 case 502: return share_info_502_to_samba( buf
, bufptr
);
774 FIXME( "level %u not supported\n", level
);
775 return ERROR_NOT_SUPPORTED
;
779 static NET_API_STATUS
share_add( LMSTR servername
, DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
783 NET_API_STATUS status
;
785 if (servername
&& !(server
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
786 status
= share_info_to_samba( level
, buf
, &info
);
791 status
= pNetShareAdd( server
, level
, info
, &err
);
792 HeapFree( GetProcessHeap(), 0, info
);
793 if (parm_err
) *parm_err
= err
;
795 HeapFree( GetProcessHeap(), 0, server
);
799 static NET_API_STATUS
share_del( LMSTR servername
, LMSTR netname
, DWORD reserved
)
801 char *server
= NULL
, *share
;
802 NET_API_STATUS status
;
804 if (servername
&& !(server
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
805 if (!(share
= strdup_unixcp( netname
)))
807 HeapFree( GetProcessHeap(), 0, server
);
808 return ERROR_OUTOFMEMORY
;
810 status
= pNetShareDel( server
, share
, reserved
);
811 HeapFree( GetProcessHeap(), 0, server
);
812 HeapFree( GetProcessHeap(), 0, share
);
816 struct wksta_info_100
818 unsigned int wki100_platform_id
;
819 const char *wki100_computername
;
820 const char *wki100_langroup
;
821 unsigned int wki100_ver_major
;
822 unsigned int wki100_ver_minor
;
825 static NET_API_STATUS
wksta_info_100_from_samba( const unsigned char *buf
, BYTE
**bufptr
)
828 struct wksta_info_100
*info
= (struct wksta_info_100
*)buf
;
832 if (info
->wki100_computername
)
833 len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_computername
, -1, NULL
, 0 );
834 if (info
->wki100_langroup
)
835 len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_langroup
, -1, NULL
, 0 );
836 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ret
) + (len
* sizeof(WCHAR
) ))))
837 return ERROR_OUTOFMEMORY
;
839 ptr
= (WCHAR
*)(ret
+ 1);
840 ret
->wki100_platform_id
= info
->wki100_platform_id
;
841 if (!info
->wki100_computername
) ret
->wki100_computername
= NULL
;
844 ret
->wki100_computername
= ptr
;
845 ptr
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_computername
, -1, ptr
, len
);
847 if (!info
->wki100_langroup
) ret
->wki100_langroup
= NULL
;
850 ret
->wki100_langroup
= ptr
;
851 MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_langroup
, -1, ptr
, len
);
853 ret
->wki100_ver_major
= info
->wki100_ver_major
;
854 ret
->wki100_ver_minor
= info
->wki100_ver_minor
;
855 *bufptr
= (BYTE
*)ret
;
859 static NET_API_STATUS
wksta_info_from_samba( DWORD level
, const unsigned char *buf
, BYTE
**bufptr
)
863 case 100: return wksta_info_100_from_samba( buf
, bufptr
);
865 FIXME( "level %u not supported\n", level
);
866 return ERROR_NOT_SUPPORTED
;
870 static NET_API_STATUS
wksta_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
872 NET_API_STATUS status
;
874 unsigned char *buf
= NULL
;
876 if (servername
&& !(wksta
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
877 status
= pNetWkstaGetInfo( wksta
, level
, &buf
);
878 HeapFree( GetProcessHeap(), 0, wksta
);
881 status
= wksta_info_from_samba( level
, buf
, bufptr
);
882 pNetApiBufferFree( buf
);
889 static BOOL
libnetapi_init(void)
894 static NET_API_STATUS
server_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
897 return ERROR_NOT_SUPPORTED
;
899 static NET_API_STATUS
share_add( LMSTR servername
, DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
902 return ERROR_NOT_SUPPORTED
;
904 static NET_API_STATUS
share_del( LMSTR servername
, LMSTR netname
, DWORD reserved
)
907 return ERROR_NOT_SUPPORTED
;
909 static NET_API_STATUS
wksta_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
912 return ERROR_NOT_SUPPORTED
;
915 #endif /* SONAME_LIBNETAPI */
917 /************************************************************
918 * NETAPI_IsLocalComputer
920 * Checks whether the server name indicates local machine.
922 static BOOL
NETAPI_IsLocalComputer( LMCSTR name
)
924 WCHAR buf
[MAX_COMPUTERNAME_LENGTH
+ 1];
925 DWORD size
= sizeof(buf
) / sizeof(buf
[0]);
928 if (!name
|| !name
[0]) return TRUE
;
930 ret
= GetComputerNameW( buf
, &size
);
931 if (ret
&& name
[0] == '\\' && name
[1] == '\\') name
+= 2;
932 return ret
&& !strcmpiW( name
, buf
);
935 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
937 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
940 case DLL_PROCESS_ATTACH
:
941 DisableThreadLibraryCalls(hinstDLL
);
945 case DLL_PROCESS_DETACH
:
946 if (lpvReserved
) break;
954 /************************************************************
955 * NetServerEnum (NETAPI32.@)
957 NET_API_STATUS WINAPI
NetServerEnum(
963 LPDWORD totalentries
,
966 LPDWORD resume_handle
969 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(servername
),
970 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, servertype
,
971 debugstr_w(domain
), resume_handle
);
973 return ERROR_NO_BROWSER_SERVERS_FOUND
;
976 /************************************************************
977 * NetServerEnumEx (NETAPI32.@)
979 NET_API_STATUS WINAPI
NetServerEnumEx(
985 LPDWORD totalentries
,
988 LMCSTR FirstNameToReturn
)
990 FIXME("Stub (%s %d %p %d %p %p %d %s %s)\n",
991 debugstr_w(ServerName
), Level
, Bufptr
, PrefMaxlen
, EntriesRead
, totalentries
,
992 servertype
, debugstr_w(domain
), debugstr_w(FirstNameToReturn
));
994 return ERROR_NO_BROWSER_SERVERS_FOUND
;
997 /************************************************************
998 * NetServerDiskEnum (NETAPI32.@)
1000 NET_API_STATUS WINAPI
NetServerDiskEnum(
1005 LPDWORD EntriesRead
,
1006 LPDWORD totalentries
,
1007 LPDWORD Resume_Handle
)
1009 FIXME("Stub (%s %d %p %d %p %p %p)\n", debugstr_w(ServerName
),
1010 Level
, Bufptr
, PrefMaxlen
, EntriesRead
, totalentries
, Resume_Handle
);
1012 return ERROR_NO_BROWSER_SERVERS_FOUND
;
1015 /************************************************************
1016 * NetServerGetInfo (NETAPI32.@)
1018 NET_API_STATUS WINAPI
NetServerGetInfo(LMSTR servername
, DWORD level
, LPBYTE
* bufptr
)
1021 BOOL local
= NETAPI_IsLocalComputer( servername
);
1023 TRACE("%s %d %p\n", debugstr_w( servername
), level
, bufptr
);
1027 if (libnetapi_init()) return server_getinfo( servername
, level
, bufptr
);
1028 FIXME( "remote computers not supported\n" );
1029 return ERROR_INVALID_LEVEL
;
1031 if (!bufptr
) return ERROR_INVALID_PARAMETER
;
1038 DWORD computerNameLen
, size
;
1039 WCHAR computerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1041 computerNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
1042 GetComputerNameW(computerName
, &computerNameLen
);
1043 computerNameLen
++; /* include NULL terminator */
1045 /* Plus 1 for empty comment */
1046 size
= sizeof(SERVER_INFO_101
) + (computerNameLen
+ 1) * sizeof(WCHAR
);
1047 ret
= NetApiBufferAllocate(size
, (LPVOID
*)bufptr
);
1048 if (ret
== NERR_Success
)
1050 /* INFO_100 structure is a subset of INFO_101 */
1051 PSERVER_INFO_101 info
= (PSERVER_INFO_101
)*bufptr
;
1052 OSVERSIONINFOW verInfo
;
1054 info
->sv101_platform_id
= PLATFORM_ID_NT
;
1055 info
->sv101_name
= (LMSTR
)(*bufptr
+ sizeof(SERVER_INFO_101
));
1056 memcpy(info
->sv101_name
, computerName
,
1057 computerNameLen
* sizeof(WCHAR
));
1058 verInfo
.dwOSVersionInfoSize
= sizeof(verInfo
);
1059 GetVersionExW(&verInfo
);
1060 info
->sv101_version_major
= verInfo
.dwMajorVersion
;
1061 info
->sv101_version_minor
= verInfo
.dwMinorVersion
;
1062 /* Use generic type as no wine equivalent of DC / Server */
1063 info
->sv101_type
= SV_TYPE_NT
;
1064 info
->sv101_comment
= (LMSTR
)(*bufptr
+ sizeof(SERVER_INFO_101
)
1065 + computerNameLen
* sizeof(WCHAR
));
1066 info
->sv101_comment
[0] = '\0';
1072 FIXME("level %d unimplemented\n", level
);
1073 ret
= ERROR_INVALID_LEVEL
;
1079 /************************************************************
1080 * NetStatisticsGet (NETAPI32.@)
1082 NET_API_STATUS WINAPI
NetStatisticsGet(LMSTR server
, LMSTR service
,
1083 DWORD level
, DWORD options
,
1087 static const WCHAR SERVICE_WORKSTATION
[] = {
1088 'L', 'a', 'n', 'm', 'a', 'n',
1089 'W', 'o', 'r', 'k', 's', 't', 'a', 't', 'i', 'o', 'n', '\0'};
1090 static const WCHAR SERVICE_SERVER
[] = {
1091 'L', 'a', 'n', 'm', 'a', 'n',
1092 'S', 'e', 'r', 'v', 'e', 'r', '\0'};
1095 STAT_WORKSTATION_0 workst
;
1096 STAT_SERVER_0 server
;
1100 TRACE("(server %s, service %s, level %d, options %d, buffer %p): stub\n",
1101 debugstr_w(server
), debugstr_w(service
), level
, options
, bufptr
);
1103 res
= NetApiBufferAllocate(sizeof(*stat
), &dataptr
);
1104 if (res
!= NERR_Success
) return res
;
1106 res
= NERR_InternalError
;
1111 if (!lstrcmpW(service
, SERVICE_WORKSTATION
))
1113 /* Fill the struct STAT_WORKSTATION_0 properly */
1114 memset(&stat
->workst
, 0, sizeof(stat
->workst
));
1117 else if (!lstrcmpW(service
, SERVICE_SERVER
))
1119 /* Fill the struct STAT_SERVER_0 properly */
1120 memset(&stat
->server
, 0, sizeof(stat
->server
));
1125 if (res
!= NERR_Success
)
1126 NetApiBufferFree(dataptr
);
1133 NET_API_STATUS WINAPI
NetUseEnum(LMSTR server
, DWORD level
, LPBYTE
* bufptr
, DWORD prefmaxsize
,
1134 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resumehandle
)
1136 FIXME("stub (%p, %d, %p, %d, %p, %p, %p)\n", server
, level
, bufptr
, prefmaxsize
,
1137 entriesread
, totalentries
, resumehandle
);
1138 return ERROR_NOT_SUPPORTED
;
1141 NET_API_STATUS WINAPI
NetScheduleJobAdd(LPCWSTR server
, LPBYTE bufptr
, LPDWORD jobid
)
1143 FIXME("stub (%s, %p, %p)\n", debugstr_w(server
), bufptr
, jobid
);
1144 return NERR_Success
;
1147 NET_API_STATUS WINAPI
NetScheduleJobDel(LPCWSTR server
, DWORD minjobid
, DWORD maxjobid
)
1149 FIXME("stub (%s, %d, %d)\n", debugstr_w(server
), minjobid
, maxjobid
);
1150 return NERR_Success
;
1153 NET_API_STATUS WINAPI
NetScheduleJobEnum(LPCWSTR server
, LPBYTE
* bufptr
, DWORD prefmaxsize
, LPDWORD entriesread
,
1154 LPDWORD totalentries
, LPDWORD resumehandle
)
1156 FIXME("stub (%s, %p, %d, %p, %p, %p)\n", debugstr_w(server
), bufptr
, prefmaxsize
, entriesread
, totalentries
, resumehandle
);
1159 return NERR_Success
;
1162 NET_API_STATUS WINAPI
NetUseGetInfo(LMSTR server
, LMSTR name
, DWORD level
, LPBYTE
*bufptr
)
1164 FIXME("stub (%p, %p, %d, %p)\n", server
, name
, level
, bufptr
);
1165 return ERROR_NOT_SUPPORTED
;
1169 /************************************************************
1170 * NetApiBufferAllocate (NETAPI32.@)
1172 NET_API_STATUS WINAPI
NetApiBufferAllocate(DWORD ByteCount
, LPVOID
* Buffer
)
1174 TRACE("(%d, %p)\n", ByteCount
, Buffer
);
1176 if (Buffer
== NULL
) return ERROR_INVALID_PARAMETER
;
1177 *Buffer
= HeapAlloc(GetProcessHeap(), 0, ByteCount
);
1179 return NERR_Success
;
1181 return GetLastError();
1184 /************************************************************
1185 * NetApiBufferFree (NETAPI32.@)
1187 NET_API_STATUS WINAPI
NetApiBufferFree(LPVOID Buffer
)
1189 TRACE("(%p)\n", Buffer
);
1190 HeapFree(GetProcessHeap(), 0, Buffer
);
1191 return NERR_Success
;
1194 /************************************************************
1195 * NetApiBufferReallocate (NETAPI32.@)
1197 NET_API_STATUS WINAPI
NetApiBufferReallocate(LPVOID OldBuffer
, DWORD NewByteCount
,
1200 TRACE("(%p, %d, %p)\n", OldBuffer
, NewByteCount
, NewBuffer
);
1204 *NewBuffer
= HeapReAlloc(GetProcessHeap(), 0, OldBuffer
, NewByteCount
);
1206 *NewBuffer
= HeapAlloc(GetProcessHeap(), 0, NewByteCount
);
1207 return *NewBuffer
? NERR_Success
: GetLastError();
1211 if (!HeapFree(GetProcessHeap(), 0, OldBuffer
)) return GetLastError();
1213 return NERR_Success
;
1217 /************************************************************
1218 * NetApiBufferSize (NETAPI32.@)
1220 NET_API_STATUS WINAPI
NetApiBufferSize(LPVOID Buffer
, LPDWORD ByteCount
)
1224 TRACE("(%p, %p)\n", Buffer
, ByteCount
);
1226 return ERROR_INVALID_PARAMETER
;
1227 dw
= HeapSize(GetProcessHeap(), 0, Buffer
);
1228 TRACE("size: %d\n", dw
);
1229 if (dw
!= 0xFFFFFFFF)
1234 return NERR_Success
;
1237 /************************************************************
1238 * NetSessionEnum (NETAPI32.@)
1241 * servername [I] Pointer to a string with the name of the server
1242 * UncClientName [I] Pointer to a string with the name of the session
1243 * username [I] Pointer to a string with the name of the user
1244 * level [I] Data information level
1245 * bufptr [O] Buffer to the data
1246 * prefmaxlen [I] Preferred maximum length of the data
1247 * entriesread [O] Pointer to the number of entries enumerated
1248 * totalentries [O] Pointer to the possible number of entries
1249 * resume_handle [I/O] Pointer to a handle for subsequent searches
1252 * If successful, the function returns NERR_Success
1253 * On failure it returns:
1254 * ERROR_ACCESS_DENIED User has no access to the requested information
1255 * ERROR_INVALID_LEVEL Value of 'level' is not correct
1256 * ERROR_INVALID_PARAMETER Wrong parameter
1257 * ERROR_MORE_DATA Need a larger buffer
1258 * ERROR_NOT_ENOUGH_MEMORY Not enough memory
1259 * NERR_ClientNameNotFound A session does not exist on a given computer
1260 * NERR_InvalidComputer Invalid computer name
1261 * NERR_UserNotFound User name could not be found.
1263 NET_API_STATUS WINAPI
NetSessionEnum(LMSTR servername
, LMSTR UncClientName
,
1264 LMSTR username
, DWORD level
, LPBYTE
* bufptr
, DWORD prefmaxlen
, LPDWORD entriesread
,
1265 LPDWORD totalentries
, LPDWORD resume_handle
)
1267 FIXME("Stub (%s %s %s %d %p %d %p %p %p)\n", debugstr_w(servername
),
1268 debugstr_w(UncClientName
), debugstr_w(username
),
1269 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
1271 return NERR_Success
;
1274 /************************************************************
1275 * NetShareEnum (NETAPI32.@)
1278 * servername [I] Pointer to a string with the name of the server
1279 * level [I] Data information level
1280 * bufptr [O] Buffer to the data
1281 * prefmaxlen [I] Preferred maximum length of the data
1282 * entriesread [O] Pointer to the number of entries enumerated
1283 * totalentries [O] Pointer to the possible number of entries
1284 * resume_handle [I/O] Pointer to a handle for subsequent searches
1287 * If successful, the function returns NERR_Success
1288 * On failure it returns a system error code (FIXME: find out which)
1291 NET_API_STATUS WINAPI
NetShareEnum( LMSTR servername
, DWORD level
, LPBYTE
* bufptr
,
1292 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
1294 FIXME("Stub (%s %d %p %d %p %p %p)\n", debugstr_w(servername
), level
, bufptr
,
1295 prefmaxlen
, entriesread
, totalentries
, resume_handle
);
1297 return ERROR_NOT_SUPPORTED
;
1300 /************************************************************
1301 * NetShareDel (NETAPI32.@)
1303 NET_API_STATUS WINAPI
NetShareDel(LMSTR servername
, LMSTR netname
, DWORD reserved
)
1305 BOOL local
= NETAPI_IsLocalComputer( servername
);
1307 TRACE("%s %s %d\n", debugstr_w(servername
), debugstr_w(netname
), reserved
);
1311 if (libnetapi_init()) return share_del( servername
, netname
, reserved
);
1312 FIXME( "remote computers not supported\n" );
1315 FIXME("%s %s %d\n", debugstr_w(servername
), debugstr_w(netname
), reserved
);
1316 return NERR_Success
;
1319 /************************************************************
1320 * NetShareGetInfo (NETAPI32.@)
1322 NET_API_STATUS WINAPI
NetShareGetInfo(LMSTR servername
, LMSTR netname
,
1323 DWORD level
, LPBYTE
*bufptr
)
1325 FIXME("Stub (%s %s %d %p)\n", debugstr_w(servername
),
1326 debugstr_w(netname
),level
, bufptr
);
1327 return NERR_NetNameNotFound
;
1330 /************************************************************
1331 * NetShareAdd (NETAPI32.@)
1333 NET_API_STATUS WINAPI
NetShareAdd(LMSTR servername
,
1334 DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
1336 BOOL local
= NETAPI_IsLocalComputer( servername
);
1338 TRACE("%s %d %p %p\n", debugstr_w(servername
), level
, buf
, parm_err
);
1342 if (libnetapi_init()) return share_add( servername
, level
, buf
, parm_err
);
1343 FIXME( "remote computers not supported\n" );
1346 FIXME("%s %d %p %p\n", debugstr_w(servername
), level
, buf
, parm_err
);
1347 return ERROR_NOT_SUPPORTED
;
1350 /************************************************************
1351 * NetFileEnum (NETAPI32.@)
1353 NET_API_STATUS WINAPI
NetFileEnum(
1354 LPWSTR ServerName
, LPWSTR BasePath
, LPWSTR UserName
,
1355 DWORD Level
, LPBYTE
* BufPtr
, DWORD PrefMaxLen
,
1356 LPDWORD EntriesRead
, LPDWORD TotalEntries
, PDWORD_PTR ResumeHandle
)
1358 FIXME("(%s, %s, %s, %u): stub\n", debugstr_w(ServerName
), debugstr_w(BasePath
),
1359 debugstr_w(UserName
), Level
);
1360 return ERROR_NOT_SUPPORTED
;
1363 static void wprint_mac(WCHAR
* buffer
, int len
, const MIB_IFROW
*ifRow
)
1378 for (i
= 0; i
< ifRow
->dwPhysAddrLen
&& 2 * i
< len
; i
++)
1380 val
= ifRow
->bPhysAddr
[i
];
1382 buffer
[2*i
] = (WCHAR
)((val
>>4) + 'A' - 10);
1384 buffer
[2*i
] = (WCHAR
)((val
>>4) + '0');
1385 if ((val
& 0xf ) >9)
1386 buffer
[2*i
+1] = (WCHAR
)((val
& 0xf) + 'A' - 10);
1388 buffer
[2*i
+1] = (WCHAR
)((val
& 0xf) + '0');
1393 /* Theoretically this could be too short, except that MS defines
1394 * MAX_ADAPTER_NAME as 128, and MAX_INTERFACE_NAME_LEN as 256, and both
1395 * represent a count of WCHARs, so even with an extraordinarily long header
1396 * this will be plenty
1398 #define MAX_TRANSPORT_NAME MAX_INTERFACE_NAME_LEN
1399 #define MAX_TRANSPORT_ADDR 13
1401 #define NBT_TRANSPORT_NAME_HEADER "\\Device\\NetBT_Tcpip_"
1402 #define UNKNOWN_TRANSPORT_NAME_HEADER "\\Device\\UnknownTransport_"
1404 static void wprint_name(WCHAR
*buffer
, int len
, ULONG transport
,
1418 if (!memcmp(&transport
, TRANSPORT_NBT
, sizeof(ULONG
)))
1419 name
= NBT_TRANSPORT_NAME_HEADER
;
1421 name
= UNKNOWN_TRANSPORT_NAME_HEADER
;
1423 for (ptr1
= buffer
; *name
&& ptr1
< buffer
+ len
; ptr1
++, name
++)
1425 for (ptr2
= ifRow
->wszName
; *ptr2
&& ptr1
< buffer
+ len
; ptr1
++, ptr2
++)
1430 /***********************************************************************
1431 * NetWkstaTransportEnum (NETAPI32.@)
1434 struct WkstaTransportEnumData
1443 /**********************************************************************/
1445 static BOOL
WkstaEnumAdaptersCallback(UCHAR totalLANAs
, UCHAR lanaIndex
,
1446 ULONG transport
, const NetBIOSAdapterImpl
*data
, void *closure
)
1449 struct WkstaTransportEnumData
*enumData
= closure
;
1451 if (enumData
&& enumData
->pbuf
)
1457 enumData
->n_adapt
= totalLANAs
;
1458 enumData
->n_read
= 0;
1460 toAllocate
= totalLANAs
* (sizeof(WKSTA_TRANSPORT_INFO_0
)
1461 + MAX_TRANSPORT_NAME
* sizeof(WCHAR
) +
1462 MAX_TRANSPORT_ADDR
* sizeof(WCHAR
));
1463 if (enumData
->prefmaxlen
!= MAX_PREFERRED_LENGTH
)
1464 toAllocate
= enumData
->prefmaxlen
;
1465 NetApiBufferAllocate(toAllocate
, (LPVOID
*)enumData
->pbuf
);
1467 if (*(enumData
->pbuf
))
1471 if (enumData
->prefmaxlen
== MAX_PREFERRED_LENGTH
)
1472 spaceFor
= totalLANAs
;
1474 spaceFor
= enumData
->prefmaxlen
/
1475 (sizeof(WKSTA_TRANSPORT_INFO_0
) + (MAX_TRANSPORT_NAME
+
1476 MAX_TRANSPORT_ADDR
) * sizeof(WCHAR
));
1477 if (enumData
->n_read
< spaceFor
)
1479 PWKSTA_TRANSPORT_INFO_0 ti
;
1480 LMSTR transport_name
, transport_addr
;
1483 ti
= (PWKSTA_TRANSPORT_INFO_0
)(*(enumData
->pbuf
) +
1484 enumData
->n_read
* sizeof(WKSTA_TRANSPORT_INFO_0
));
1485 transport_name
= (LMSTR
)(*(enumData
->pbuf
) +
1486 totalLANAs
* sizeof(WKSTA_TRANSPORT_INFO_0
) +
1487 enumData
->n_read
* MAX_TRANSPORT_NAME
* sizeof(WCHAR
));
1488 transport_addr
= (LMSTR
)(*(enumData
->pbuf
) +
1489 totalLANAs
* (sizeof(WKSTA_TRANSPORT_INFO_0
) +
1490 MAX_TRANSPORT_NAME
* sizeof(WCHAR
)) +
1491 enumData
->n_read
* MAX_TRANSPORT_ADDR
* sizeof(WCHAR
));
1493 ifRow
.dwIndex
= data
->ifIndex
;
1495 ti
->wkti0_quality_of_service
= 0;
1496 ti
->wkti0_number_of_vcs
= 0;
1497 ti
->wkti0_transport_name
= transport_name
;
1498 wprint_name(ti
->wkti0_transport_name
, MAX_TRANSPORT_NAME
,
1500 ti
->wkti0_transport_address
= transport_addr
;
1501 wprint_mac(ti
->wkti0_transport_address
, MAX_TRANSPORT_ADDR
,
1503 if (!memcmp(&transport
, TRANSPORT_NBT
, sizeof(ULONG
)))
1504 ti
->wkti0_wan_ish
= TRUE
;
1506 ti
->wkti0_wan_ish
= FALSE
;
1507 TRACE("%d of %d:ti at %p\n", lanaIndex
, totalLANAs
, ti
);
1508 TRACE("transport_name at %p %s\n",
1509 ti
->wkti0_transport_name
,
1510 debugstr_w(ti
->wkti0_transport_name
));
1511 TRACE("transport_address at %p %s\n",
1512 ti
->wkti0_transport_address
,
1513 debugstr_w(ti
->wkti0_transport_address
));
1515 enumData
->ret
= NERR_Success
;
1520 enumData
->ret
= ERROR_MORE_DATA
;
1526 enumData
->ret
= ERROR_OUTOFMEMORY
;
1535 /**********************************************************************/
1537 NET_API_STATUS WINAPI
1538 NetWkstaTransportEnum(LMSTR ServerName
, DWORD level
, PBYTE
* pbuf
,
1539 DWORD prefmaxlen
, LPDWORD read_entries
,
1540 PDWORD total_entries
, PDWORD hresume
)
1544 TRACE(":%s, 0x%08x, %p, 0x%08x, %p, %p, %p\n", debugstr_w(ServerName
),
1545 level
, pbuf
, prefmaxlen
, read_entries
, total_entries
,hresume
);
1546 if (!NETAPI_IsLocalComputer(ServerName
))
1548 FIXME(":not implemented for non-local computers\n");
1549 ret
= ERROR_INVALID_LEVEL
;
1553 if (hresume
&& *hresume
)
1555 FIXME(":resume handle not implemented\n");
1556 return ERROR_INVALID_LEVEL
;
1561 case 0: /* transport info */
1563 ULONG allTransports
;
1564 struct WkstaTransportEnumData enumData
;
1566 if (NetBIOSNumAdapters() == 0)
1567 return ERROR_NETWORK_UNREACHABLE
;
1569 return STATUS_ACCESS_VIOLATION
;
1570 if (!total_entries
|| !pbuf
)
1571 return RPC_X_NULL_REF_POINTER
;
1573 enumData
.prefmaxlen
= prefmaxlen
;
1574 enumData
.pbuf
= pbuf
;
1575 memcpy(&allTransports
, ALL_TRANSPORTS
, sizeof(ULONG
));
1576 NetBIOSEnumAdapters(allTransports
, WkstaEnumAdaptersCallback
,
1578 *read_entries
= enumData
.n_read
;
1579 *total_entries
= enumData
.n_adapt
;
1580 if (hresume
) *hresume
= 0;
1585 TRACE("Invalid level %d is specified\n", level
);
1586 ret
= ERROR_INVALID_LEVEL
;
1592 /************************************************************
1593 * NetWkstaUserGetInfo (NETAPI32.@)
1595 NET_API_STATUS WINAPI
NetWkstaUserGetInfo(LMSTR reserved
, DWORD level
,
1598 NET_API_STATUS nastatus
;
1600 TRACE("(%s, %d, %p)\n", debugstr_w(reserved
), level
, bufptr
);
1605 PWKSTA_USER_INFO_0 ui
;
1606 DWORD dwSize
= UNLEN
+ 1;
1609 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_0
) + dwSize
* sizeof(WCHAR
),
1611 if (nastatus
!= NERR_Success
)
1612 return ERROR_NOT_ENOUGH_MEMORY
;
1614 ui
= (PWKSTA_USER_INFO_0
) *bufptr
;
1615 ui
->wkui0_username
= (LMSTR
) (*bufptr
+ sizeof(WKSTA_USER_INFO_0
));
1618 if (!GetUserNameW(ui
->wkui0_username
, &dwSize
))
1620 NetApiBufferFree(ui
);
1621 return ERROR_NOT_ENOUGH_MEMORY
;
1624 nastatus
= NetApiBufferReallocate(
1625 *bufptr
, sizeof(WKSTA_USER_INFO_0
) +
1626 (lstrlenW(ui
->wkui0_username
) + 1) * sizeof(WCHAR
),
1628 if (nastatus
!= NERR_Success
)
1636 PWKSTA_USER_INFO_1 ui
;
1637 PWKSTA_USER_INFO_0 ui0
;
1638 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
1639 LSA_HANDLE PolicyHandle
;
1640 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
1643 /* sizes of the field buffers in WCHARS */
1644 int username_sz
, logon_domain_sz
, oth_domains_sz
, logon_server_sz
;
1646 FIXME("Level 1 processing is partially implemented\n");
1648 logon_server_sz
= 1;
1650 /* get some information first to estimate size of the buffer */
1652 nastatus
= NetWkstaUserGetInfo(NULL
, 0, (PBYTE
*) &ui0
);
1653 if (nastatus
!= NERR_Success
)
1655 username_sz
= lstrlenW(ui0
->wkui0_username
) + 1;
1657 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
1658 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
1659 POLICY_VIEW_LOCAL_INFORMATION
,
1661 if (NtStatus
!= STATUS_SUCCESS
)
1663 TRACE("LsaOpenPolicyFailed with NT status %x\n",
1664 LsaNtStatusToWinError(NtStatus
));
1665 NetApiBufferFree(ui0
);
1666 return ERROR_NOT_ENOUGH_MEMORY
;
1668 LsaQueryInformationPolicy(PolicyHandle
, PolicyAccountDomainInformation
,
1669 (PVOID
*) &DomainInfo
);
1670 logon_domain_sz
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
1671 LsaClose(PolicyHandle
);
1674 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_1
) +
1675 (username_sz
+ logon_domain_sz
+
1676 oth_domains_sz
+ logon_server_sz
) * sizeof(WCHAR
),
1678 if (nastatus
!= NERR_Success
) {
1679 NetApiBufferFree(ui0
);
1682 ui
= (WKSTA_USER_INFO_1
*) *bufptr
;
1683 ui
->wkui1_username
= (LMSTR
) (*bufptr
+ sizeof(WKSTA_USER_INFO_1
));
1684 ui
->wkui1_logon_domain
= (LMSTR
) (
1685 ((PBYTE
) ui
->wkui1_username
) + username_sz
* sizeof(WCHAR
));
1686 ui
->wkui1_oth_domains
= (LMSTR
) (
1687 ((PBYTE
) ui
->wkui1_logon_domain
) +
1688 logon_domain_sz
* sizeof(WCHAR
));
1689 ui
->wkui1_logon_server
= (LMSTR
) (
1690 ((PBYTE
) ui
->wkui1_oth_domains
) +
1691 oth_domains_sz
* sizeof(WCHAR
));
1694 lstrcpyW(ui
->wkui1_username
, ui0
->wkui0_username
);
1695 NetApiBufferFree(ui0
);
1697 lstrcpynW(ui
->wkui1_logon_domain
, DomainInfo
->DomainName
.Buffer
,
1699 LsaFreeMemory(DomainInfo
);
1701 /* FIXME. Not implemented. Populated with empty strings */
1702 ui
->wkui1_oth_domains
[0] = 0;
1703 ui
->wkui1_logon_server
[0] = 0;
1708 PWKSTA_USER_INFO_1101 ui
;
1711 FIXME("Stub. Level 1101 processing is not implemented\n");
1712 /* FIXME see also wkui1_oth_domains for level 1 */
1715 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_1101
) + dwSize
* sizeof(WCHAR
),
1717 if (nastatus
!= NERR_Success
)
1719 ui
= (PWKSTA_USER_INFO_1101
) *bufptr
;
1720 ui
->wkui1101_oth_domains
= (LMSTR
)(ui
+ 1);
1723 ui
->wkui1101_oth_domains
[0] = 0;
1727 TRACE("Invalid level %d is specified\n", level
);
1728 return ERROR_INVALID_LEVEL
;
1730 return NERR_Success
;
1733 /************************************************************
1734 * NetWkstaUserEnum (NETAPI32.@)
1736 NET_API_STATUS WINAPI
1737 NetWkstaUserEnum(LMSTR servername
, DWORD level
, LPBYTE
* bufptr
,
1738 DWORD prefmaxlen
, LPDWORD entriesread
,
1739 LPDWORD totalentries
, LPDWORD resumehandle
)
1741 FIXME("(%s, %d, %p, %d, %p, %p, %p): stub!\n", debugstr_w(servername
),
1742 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resumehandle
);
1743 return ERROR_INVALID_PARAMETER
;
1746 /************************************************************
1747 * NetpGetComputerName (NETAPI32.@)
1749 NET_API_STATUS WINAPI
NetpGetComputerName(LPWSTR
*Buffer
)
1751 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
1753 TRACE("(%p)\n", Buffer
);
1754 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) Buffer
);
1755 if (GetComputerNameW(*Buffer
, &dwSize
))
1757 return NetApiBufferReallocate(
1758 *Buffer
, (dwSize
+ 1) * sizeof(WCHAR
),
1763 NetApiBufferFree(*Buffer
);
1764 return ERROR_NOT_ENOUGH_MEMORY
;
1768 NET_API_STATUS WINAPI
I_NetNameCompare(LPVOID p1
, LPWSTR wkgrp
, LPWSTR comp
,
1769 LPVOID p4
, LPVOID p5
)
1771 FIXME("(%p %s %s %p %p): stub\n", p1
, debugstr_w(wkgrp
), debugstr_w(comp
),
1773 return ERROR_INVALID_PARAMETER
;
1776 NET_API_STATUS WINAPI
I_NetNameValidate(LPVOID p1
, LPWSTR wkgrp
, LPVOID p3
,
1779 FIXME("(%p %s %p %p): stub\n", p1
, debugstr_w(wkgrp
), p3
, p4
);
1780 return ERROR_INVALID_PARAMETER
;
1783 NET_API_STATUS WINAPI
NetWkstaGetInfo( LMSTR servername
, DWORD level
,
1787 BOOL local
= NETAPI_IsLocalComputer( servername
);
1789 TRACE("%s %d %p\n", debugstr_w( servername
), level
, bufptr
);
1793 if (libnetapi_init()) return wksta_getinfo( servername
, level
, bufptr
);
1794 FIXME( "remote computers not supported\n" );
1795 return ERROR_INVALID_LEVEL
;
1797 if (!bufptr
) return ERROR_INVALID_PARAMETER
;
1805 static const WCHAR lanroot
[] = {'c',':','\\','l','a','n','m','a','n',0}; /* FIXME */
1806 DWORD computerNameLen
, domainNameLen
, size
;
1807 WCHAR computerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1808 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
1809 LSA_HANDLE PolicyHandle
;
1812 computerNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
1813 GetComputerNameW(computerName
, &computerNameLen
);
1814 computerNameLen
++; /* include NULL terminator */
1816 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
1817 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
1818 POLICY_VIEW_LOCAL_INFORMATION
, &PolicyHandle
);
1819 if (NtStatus
!= STATUS_SUCCESS
)
1820 ret
= LsaNtStatusToWinError(NtStatus
);
1823 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
1825 LsaQueryInformationPolicy(PolicyHandle
,
1826 PolicyAccountDomainInformation
, (PVOID
*)&DomainInfo
);
1827 domainNameLen
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
1828 size
= sizeof(WKSTA_INFO_102
) + computerNameLen
* sizeof(WCHAR
)
1829 + domainNameLen
* sizeof(WCHAR
) + sizeof(lanroot
);
1830 ret
= NetApiBufferAllocate(size
, (LPVOID
*)bufptr
);
1831 if (ret
== NERR_Success
)
1833 /* INFO_100 and INFO_101 structures are subsets of INFO_102 */
1834 PWKSTA_INFO_102 info
= (PWKSTA_INFO_102
)*bufptr
;
1835 OSVERSIONINFOW verInfo
;
1837 info
->wki102_platform_id
= PLATFORM_ID_NT
;
1838 info
->wki102_computername
= (LMSTR
)(*bufptr
+
1839 sizeof(WKSTA_INFO_102
));
1840 memcpy(info
->wki102_computername
, computerName
,
1841 computerNameLen
* sizeof(WCHAR
));
1842 info
->wki102_langroup
= info
->wki102_computername
+ computerNameLen
;
1843 memcpy(info
->wki102_langroup
, DomainInfo
->DomainName
.Buffer
,
1844 domainNameLen
* sizeof(WCHAR
));
1845 info
->wki102_lanroot
= info
->wki102_langroup
+ domainNameLen
;
1846 memcpy(info
->wki102_lanroot
, lanroot
, sizeof(lanroot
));
1847 memset(&verInfo
, 0, sizeof(verInfo
));
1848 verInfo
.dwOSVersionInfoSize
= sizeof(verInfo
);
1849 GetVersionExW(&verInfo
);
1850 info
->wki102_ver_major
= verInfo
.dwMajorVersion
;
1851 info
->wki102_ver_minor
= verInfo
.dwMinorVersion
;
1852 info
->wki102_logged_on_users
= 1;
1854 LsaFreeMemory(DomainInfo
);
1855 LsaClose(PolicyHandle
);
1861 FIXME("level %d unimplemented\n", level
);
1862 ret
= ERROR_INVALID_LEVEL
;
1867 /************************************************************
1868 * NetGetJoinInformation (NETAPI32.@)
1870 NET_API_STATUS NET_API_FUNCTION
NetGetJoinInformation(
1873 PNETSETUP_JOIN_STATUS type
)
1875 static const WCHAR workgroupW
[] = {'W','o','r','k','g','r','o','u','p',0};
1877 FIXME("Semi-stub %s %p %p\n", wine_dbgstr_w(Server
), Name
, type
);
1880 return ERROR_INVALID_PARAMETER
;
1882 NetApiBufferAllocate(sizeof(workgroupW
), (LPVOID
*)Name
);
1883 lstrcpyW(*Name
, workgroupW
);
1884 *type
= NetSetupWorkgroupName
;
1886 return NERR_Success
;
1889 /************************************************************
1890 * NetUserGetGroups (NETAPI32.@)
1892 NET_API_STATUS NET_API_FUNCTION
NetUserGetGroups(
1898 LPDWORD entriesread
,
1899 LPDWORD totalentries
)
1901 FIXME("%s %s %d %p %d %p %p stub\n", debugstr_w(servername
),
1902 debugstr_w(username
), level
, bufptr
, prefixmaxlen
, entriesread
,
1909 return ERROR_INVALID_LEVEL
;
1915 WCHAR user_name
[LM20_UNLEN
+1];
1916 WCHAR user_password
[PWLEN
+ 1];
1917 DWORD sec_since_passwd_change
;
1920 LPWSTR user_comment
;
1922 LPWSTR user_logon_script_path
;
1925 static struct list user_list
= LIST_INIT( user_list
);
1927 /************************************************************
1928 * NETAPI_ValidateServername
1930 * Validates server name
1932 static NET_API_STATUS
NETAPI_ValidateServername(LPCWSTR ServerName
)
1936 if (ServerName
[0] == 0)
1937 return ERROR_BAD_NETPATH
;
1939 ((ServerName
[0] == '\\') &&
1940 (ServerName
[1] != '\\'))
1942 ((ServerName
[0] == '\\') &&
1943 (ServerName
[1] == '\\') &&
1944 (ServerName
[2] == 0))
1946 return ERROR_INVALID_NAME
;
1948 return NERR_Success
;
1951 /************************************************************
1954 * Looks for a user in the user database.
1955 * Returns a pointer to the entry in the user list when the user
1956 * is found, NULL otherwise.
1958 static struct sam_user
* NETAPI_FindUser(LPCWSTR UserName
)
1960 struct sam_user
*user
;
1962 LIST_FOR_EACH_ENTRY(user
, &user_list
, struct sam_user
, entry
)
1964 if(lstrcmpW(user
->user_name
, UserName
) == 0)
1970 static BOOL
NETAPI_IsCurrentUser(LPCWSTR username
)
1972 LPWSTR curr_user
= NULL
;
1976 dwSize
= LM20_UNLEN
+1;
1977 curr_user
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
1980 ERR("Failed to allocate memory for user name.\n");
1983 if(!GetUserNameW(curr_user
, &dwSize
))
1985 ERR("Failed to get current user's user name.\n");
1988 if (!lstrcmpW(curr_user
, username
))
1994 HeapFree(GetProcessHeap(), 0, curr_user
);
1998 /************************************************************
1999 * NetUserAdd (NETAPI32.@)
2001 NET_API_STATUS WINAPI
NetUserAdd(LPCWSTR servername
,
2002 DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
2004 NET_API_STATUS status
;
2005 struct sam_user
* su
= NULL
;
2007 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
2009 if((status
= NETAPI_ValidateServername(servername
)) != NERR_Success
)
2014 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
2017 FIXME("Level 3 and 4 not implemented.\n");
2020 FIXME("Level 2 not implemented.\n");
2024 PUSER_INFO_1 ui
= (PUSER_INFO_1
) bufptr
;
2025 su
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user
));
2028 status
= NERR_InternalError
;
2032 if(lstrlenW(ui
->usri1_name
) > LM20_UNLEN
)
2034 status
= NERR_BadUsername
;
2038 /*FIXME: do other checks for a valid username */
2039 lstrcpyW(su
->user_name
, ui
->usri1_name
);
2041 if(lstrlenW(ui
->usri1_password
) > PWLEN
)
2043 /* Always return PasswordTooShort on invalid passwords. */
2044 status
= NERR_PasswordTooShort
;
2047 lstrcpyW(su
->user_password
, ui
->usri1_password
);
2049 su
->sec_since_passwd_change
= ui
->usri1_password_age
;
2050 su
->user_priv
= ui
->usri1_priv
;
2051 su
->user_flags
= ui
->usri1_flags
;
2053 /*FIXME: set the other LPWSTRs to NULL for now */
2054 su
->home_dir
= NULL
;
2055 su
->user_comment
= NULL
;
2056 su
->user_logon_script_path
= NULL
;
2058 list_add_head(&user_list
, &su
->entry
);
2059 return NERR_Success
;
2062 TRACE("Invalid level %d specified.\n", level
);
2063 status
= ERROR_INVALID_LEVEL
;
2067 HeapFree(GetProcessHeap(), 0, su
);
2072 /************************************************************
2073 * NetUserDel (NETAPI32.@)
2075 NET_API_STATUS WINAPI
NetUserDel(LPCWSTR servername
, LPCWSTR username
)
2077 NET_API_STATUS status
;
2078 struct sam_user
*user
;
2080 TRACE("(%s, %s)\n", debugstr_w(servername
), debugstr_w(username
));
2082 if((status
= NETAPI_ValidateServername(servername
))!= NERR_Success
)
2085 if ((user
= NETAPI_FindUser(username
)) == NULL
)
2086 return NERR_UserNotFound
;
2088 list_remove(&user
->entry
);
2090 HeapFree(GetProcessHeap(), 0, user
->home_dir
);
2091 HeapFree(GetProcessHeap(), 0, user
->user_comment
);
2092 HeapFree(GetProcessHeap(), 0, user
->user_logon_script_path
);
2093 HeapFree(GetProcessHeap(), 0, user
);
2095 return NERR_Success
;
2098 /************************************************************
2099 * NetUserGetInfo (NETAPI32.@)
2101 NET_API_STATUS WINAPI
2102 NetUserGetInfo(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
2105 NET_API_STATUS status
;
2106 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername
), debugstr_w(username
),
2108 status
= NETAPI_ValidateServername(servername
);
2109 if (status
!= NERR_Success
)
2112 if(!NETAPI_IsLocalComputer(servername
))
2114 FIXME("Only implemented for local computer, but remote server"
2115 "%s was requested.\n", debugstr_w(servername
));
2116 return NERR_InvalidComputer
;
2119 if(!NETAPI_FindUser(username
) && !NETAPI_IsCurrentUser(username
))
2121 TRACE("User %s is unknown.\n", debugstr_w(username
));
2122 return NERR_UserNotFound
;
2132 name_sz
= lstrlenW(username
) + 1;
2135 NetApiBufferAllocate(sizeof(USER_INFO_0
) + name_sz
* sizeof(WCHAR
),
2138 ui
= (PUSER_INFO_0
) *bufptr
;
2139 ui
->usri0_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_0
));
2142 lstrcpyW(ui
->usri0_name
, username
);
2150 /* sizes of the field buffers in WCHARS */
2151 int name_sz
, comment_sz
, usr_comment_sz
, full_name_sz
;
2158 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
2159 if (status
!= NERR_Success
)
2161 NetApiBufferFree(ui0
);
2164 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
2167 NetApiBufferAllocate(sizeof(USER_INFO_10
) +
2168 (name_sz
+ comment_sz
+ usr_comment_sz
+
2169 full_name_sz
) * sizeof(WCHAR
),
2171 ui
= (PUSER_INFO_10
) *bufptr
;
2172 ui
->usri10_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_10
));
2173 ui
->usri10_comment
= (LPWSTR
) (
2174 ((PBYTE
) ui
->usri10_name
) + name_sz
* sizeof(WCHAR
));
2175 ui
->usri10_usr_comment
= (LPWSTR
) (
2176 ((PBYTE
) ui
->usri10_comment
) + comment_sz
* sizeof(WCHAR
));
2177 ui
->usri10_full_name
= (LPWSTR
) (
2178 ((PBYTE
) ui
->usri10_usr_comment
) + usr_comment_sz
* sizeof(WCHAR
));
2181 lstrcpyW(ui
->usri10_name
, ui0
->usri0_name
);
2182 NetApiBufferFree(ui0
);
2183 ui
->usri10_comment
[0] = 0;
2184 ui
->usri10_usr_comment
[0] = 0;
2185 ui
->usri10_full_name
[0] = 0;
2191 static const WCHAR homedirW
[] = {'H','O','M','E',0};
2194 /* sizes of the field buffers in WCHARS */
2195 int name_sz
, password_sz
, home_dir_sz
, comment_sz
, script_path_sz
;
2197 password_sz
= 1; /* not filled out for security reasons for NetUserGetInfo*/
2202 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
2203 if (status
!= NERR_Success
)
2205 NetApiBufferFree(ui0
);
2208 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
2209 home_dir_sz
= GetEnvironmentVariableW(homedirW
, NULL
,0);
2211 NetApiBufferAllocate(sizeof(USER_INFO_1
) +
2212 (name_sz
+ password_sz
+ home_dir_sz
+
2213 comment_sz
+ script_path_sz
) * sizeof(WCHAR
),
2216 ui
= (PUSER_INFO_1
) *bufptr
;
2217 ui
->usri1_name
= (LPWSTR
) (ui
+ 1);
2218 ui
->usri1_password
= ui
->usri1_name
+ name_sz
;
2219 ui
->usri1_home_dir
= ui
->usri1_password
+ password_sz
;
2220 ui
->usri1_comment
= ui
->usri1_home_dir
+ home_dir_sz
;
2221 ui
->usri1_script_path
= ui
->usri1_comment
+ comment_sz
;
2223 lstrcpyW(ui
->usri1_name
, ui0
->usri0_name
);
2224 NetApiBufferFree(ui0
);
2225 ui
->usri1_password
[0] = 0;
2226 ui
->usri1_password_age
= 0;
2228 GetEnvironmentVariableW(homedirW
, ui
->usri1_home_dir
,home_dir_sz
);
2229 ui
->usri1_comment
[0] = 0;
2230 ui
->usri1_flags
= 0;
2231 ui
->usri1_script_path
[0] = 0;
2261 FIXME("Level %d is not implemented\n", level
);
2262 return NERR_InternalError
;
2265 TRACE("Invalid level %d is specified\n", level
);
2266 return ERROR_INVALID_LEVEL
;
2268 return NERR_Success
;
2271 /************************************************************
2272 * NetUserGetLocalGroups (NETAPI32.@)
2274 NET_API_STATUS WINAPI
2275 NetUserGetLocalGroups(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
2276 DWORD flags
, LPBYTE
* bufptr
, DWORD prefmaxlen
,
2277 LPDWORD entriesread
, LPDWORD totalentries
)
2279 NET_API_STATUS status
;
2280 const WCHAR admins
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0};
2282 LOCALGROUP_USERS_INFO_0
* info
;
2285 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
2286 debugstr_w(servername
), debugstr_w(username
), level
, flags
, bufptr
,
2287 prefmaxlen
, entriesread
, totalentries
);
2289 status
= NETAPI_ValidateServername(servername
);
2290 if (status
!= NERR_Success
)
2294 NetApiBufferAllocate(size
* sizeof(WCHAR
), (LPVOID
*)¤tuser
);
2295 if (!GetUserNameW(currentuser
, &size
)) {
2296 NetApiBufferFree(currentuser
);
2297 return ERROR_NOT_ENOUGH_MEMORY
;
2300 if (lstrcmpiW(username
, currentuser
) && NETAPI_FindUser(username
))
2302 NetApiBufferFree(currentuser
);
2303 return NERR_UserNotFound
;
2306 NetApiBufferFree(currentuser
);
2308 size
= sizeof(*info
) + sizeof(admins
);
2310 if(prefmaxlen
< size
)
2311 status
= ERROR_MORE_DATA
;
2313 status
= NetApiBufferAllocate(size
, (LPVOID
*)&info
);
2315 if(status
!= NERR_Success
)
2322 info
->lgrui0_name
= (LPWSTR
)((LPBYTE
)info
+ sizeof(*info
));
2323 lstrcpyW(info
->lgrui0_name
, admins
);
2325 *bufptr
= (LPBYTE
)info
;
2328 return NERR_Success
;
2331 /************************************************************
2332 * NetUserEnum (NETAPI32.@)
2334 NET_API_STATUS WINAPI
2335 NetUserEnum(LPCWSTR servername
, DWORD level
, DWORD filter
, LPBYTE
* bufptr
,
2336 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
,
2337 LPDWORD resume_handle
)
2339 NET_API_STATUS status
;
2340 WCHAR user
[UNLEN
+ 1];
2341 DWORD size
, len
= sizeof(user
)/sizeof(user
[0]);
2343 TRACE("(%s, %u, 0x%x, %p, %u, %p, %p, %p)\n", debugstr_w(servername
), level
,
2344 filter
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
2346 status
= NETAPI_ValidateServername(servername
);
2347 if (status
!= NERR_Success
)
2350 if (!NETAPI_IsLocalComputer(servername
))
2352 FIXME("Only implemented for local computer, but remote server"
2353 "%s was requested.\n", debugstr_w(servername
));
2354 return NERR_InvalidComputer
;
2357 if (!GetUserNameW(user
, &len
)) return GetLastError();
2365 size
= sizeof(*info
) + (strlenW(user
) + 1) * sizeof(WCHAR
);
2367 if (prefmaxlen
< size
)
2368 status
= ERROR_MORE_DATA
;
2370 status
= NetApiBufferAllocate(size
, (void **)&info
);
2372 if (status
!= NERR_Success
)
2375 info
->usri0_name
= (WCHAR
*)((char *)info
+ sizeof(*info
));
2376 strcpyW(info
->usri0_name
, user
);
2378 *bufptr
= (BYTE
*)info
;
2379 *entriesread
= *totalentries
= 1;
2390 size
= sizeof(*info
) + (strlenW(user
) + 1) * sizeof(WCHAR
);
2392 if (prefmaxlen
< size
)
2393 status
= ERROR_MORE_DATA
;
2395 status
= NetApiBufferAllocate(size
, (void **)&info
);
2397 if (status
!= NERR_Success
)
2401 LookupAccountNameW(NULL
, user
, NULL
, &size
, NULL
, &len
, &use
);
2402 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2403 return GetLastError();
2405 status
= NetApiBufferAllocate(size
, (void **)&sid
);
2406 if (status
!= NERR_Success
)
2409 if (!LookupAccountNameW(NULL
, user
, sid
, &size
, NULL
, &len
, &use
))
2410 return GetLastError();
2412 count
= GetSidSubAuthorityCount(sid
);
2413 rid
= GetSidSubAuthority(sid
, *count
- 1);
2415 info
->usri20_name
= (WCHAR
*)((char *)info
+ sizeof(*info
));
2416 strcpyW(info
->usri20_name
, user
);
2417 info
->usri20_full_name
= NULL
;
2418 info
->usri20_comment
= NULL
;
2419 info
->usri20_flags
= UF_NORMAL_ACCOUNT
;
2420 info
->usri20_user_id
= *rid
;
2422 *bufptr
= (BYTE
*)info
;
2423 *entriesread
= *totalentries
= 1;
2425 NetApiBufferFree(sid
);
2429 FIXME("level %u not supported\n", level
);
2430 return ERROR_INVALID_LEVEL
;
2432 return NERR_Success
;
2435 /************************************************************
2436 * ACCESS_QueryAdminDisplayInformation
2438 * Creates a buffer with information for the Admin User
2440 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
2442 static const WCHAR sAdminUserName
[] = {
2443 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
2445 /* sizes of the field buffers in WCHARS */
2446 int name_sz
, comment_sz
, full_name_sz
;
2447 PNET_DISPLAY_USER usr
;
2450 name_sz
= lstrlenW(sAdminUserName
) + 1;
2454 *pdwSize
= sizeof(NET_DISPLAY_USER
);
2455 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2456 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
2459 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
2460 usr
->usri1_comment
= (LPWSTR
) (
2461 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
2462 usr
->usri1_full_name
= (LPWSTR
) (
2463 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
2466 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
2467 usr
->usri1_comment
[0] = 0;
2468 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
2469 usr
->usri1_full_name
[0] = 0;
2470 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
2471 usr
->usri1_next_index
= 0;
2474 /************************************************************
2475 * ACCESS_QueryGuestDisplayInformation
2477 * Creates a buffer with information for the Guest User
2479 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
2481 static const WCHAR sGuestUserName
[] = {
2482 'G','u','e','s','t',0 };
2484 /* sizes of the field buffers in WCHARS */
2485 int name_sz
, comment_sz
, full_name_sz
;
2486 PNET_DISPLAY_USER usr
;
2489 name_sz
= lstrlenW(sGuestUserName
) + 1;
2493 *pdwSize
= sizeof(NET_DISPLAY_USER
);
2494 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2495 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
2498 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
2499 usr
->usri1_comment
= (LPWSTR
) (
2500 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
2501 usr
->usri1_full_name
= (LPWSTR
) (
2502 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
2505 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
2506 usr
->usri1_comment
[0] = 0;
2507 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
2508 UF_DONT_EXPIRE_PASSWD
;
2509 usr
->usri1_full_name
[0] = 0;
2510 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
2511 usr
->usri1_next_index
= 0;
2514 /************************************************************
2515 * Copies NET_DISPLAY_USER record.
2517 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
2518 PNET_DISPLAY_USER src
)
2520 LPWSTR str
= *dest_buf
;
2522 src
->usri1_name
= str
;
2523 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
2525 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2527 src
->usri1_comment
= str
;
2528 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
2530 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2532 src
->usri1_flags
= dest
->usri1_flags
;
2534 src
->usri1_full_name
= str
;
2535 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
2537 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2539 src
->usri1_user_id
= dest
->usri1_user_id
;
2540 src
->usri1_next_index
= dest
->usri1_next_index
;
2544 /************************************************************
2545 * NetQueryDisplayInformation (NETAPI32.@)
2547 * The buffer structure:
2548 * - array of fixed size record of the level type
2549 * - strings, referenced by the record of the level type
2551 NET_API_STATUS WINAPI
2552 NetQueryDisplayInformation(
2553 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
2554 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
2555 PVOID
*SortedBuffer
)
2557 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
2558 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
2559 ReturnedEntryCount
, SortedBuffer
);
2561 if(!NETAPI_IsLocalComputer(ServerName
))
2563 FIXME("Only implemented on local computer, but requested for "
2564 "remote server %s\n", debugstr_w(ServerName
));
2565 return ERROR_ACCESS_DENIED
;
2572 /* current record */
2573 PNET_DISPLAY_USER inf
;
2574 /* current available strings buffer */
2576 PNET_DISPLAY_USER admin
, guest
;
2577 DWORD admin_size
, guest_size
;
2581 /* sizes of the field buffers in WCHARS */
2582 int name_sz
, comment_sz
, full_name_sz
;
2584 /* number of the records, returned in SortedBuffer
2585 3 - for current user, Administrator and Guest users
2589 FIXME("Level %d partially implemented\n", Level
);
2590 *ReturnedEntryCount
= records
;
2596 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
2597 if (!GetUserNameW(name
, &dwSize
))
2599 NetApiBufferFree(name
);
2600 return ERROR_ACCESS_DENIED
;
2603 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
2604 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
2607 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
2608 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2610 NetApiBufferAllocate(dwSize
+
2611 admin_size
- sizeof(NET_DISPLAY_USER
) +
2612 guest_size
- sizeof(NET_DISPLAY_USER
),
2614 inf
= *SortedBuffer
;
2615 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
2616 inf
->usri1_name
= str
;
2618 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
2619 inf
->usri1_comment
= str
;
2621 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
2622 inf
->usri1_full_name
= str
;
2624 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
2627 lstrcpyW(inf
->usri1_name
, name
);
2628 NetApiBufferFree(name
);
2629 inf
->usri1_comment
[0] = 0;
2631 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
2632 inf
->usri1_full_name
[0] = 0;
2633 inf
->usri1_user_id
= 0;
2634 inf
->usri1_next_index
= 0;
2637 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
2638 NetApiBufferFree(admin
);
2641 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
2642 NetApiBufferFree(guest
);
2649 FIXME("Level %d is not implemented\n", Level
);
2654 TRACE("Invalid level %d is specified\n", Level
);
2655 return ERROR_INVALID_LEVEL
;
2657 return NERR_Success
;
2660 /************************************************************
2661 * NetGetDCName (NETAPI32.@)
2663 * Return the name of the primary domain controller (PDC)
2666 NET_API_STATUS WINAPI
2667 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
2669 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
2670 debugstr_w(domainname
), bufptr
);
2671 return NERR_DCNotFound
; /* say we can't find a domain controller */
2674 /************************************************************
2675 * NetGetAnyDCName (NETAPI32.@)
2677 * Return the name of any domain controller (DC) for a
2678 * domain that is directly trusted by the specified server
2681 NET_API_STATUS WINAPI
NetGetAnyDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
2683 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
2684 debugstr_w(domainname
), bufptr
);
2685 return ERROR_NO_SUCH_DOMAIN
;
2688 /************************************************************
2689 * NetGroupAddUser (NETAPI32.@)
2691 NET_API_STATUS WINAPI
2692 NetGroupAddUser(LPCWSTR servername
, LPCWSTR groupname
, LPCWSTR username
)
2694 FIXME("(%s, %s, %s) stub!\n", debugstr_w(servername
),
2695 debugstr_w(groupname
), debugstr_w(username
));
2696 return NERR_Success
;
2699 /************************************************************
2700 * NetGroupEnum (NETAPI32.@)
2703 NET_API_STATUS WINAPI
2704 NetGroupEnum(LPCWSTR servername
, DWORD level
, LPBYTE
*bufptr
, DWORD prefmaxlen
,
2705 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
2707 FIXME("(%s, %d, %p, %d, %p, %p, %p) stub!\n", debugstr_w(servername
),
2708 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
2709 return ERROR_ACCESS_DENIED
;
2712 /************************************************************
2713 * NetGroupGetInfo (NETAPI32.@)
2716 NET_API_STATUS WINAPI
NetGroupGetInfo(LPCWSTR servername
, LPCWSTR groupname
, DWORD level
, LPBYTE
*bufptr
)
2718 FIXME("(%s, %s, %d, %p) stub!\n", debugstr_w(servername
), debugstr_w(groupname
), level
, bufptr
);
2719 return ERROR_ACCESS_DENIED
;
2722 /******************************************************************************
2723 * NetUserModalsGet (NETAPI32.@)
2725 * Retrieves global information for all users and global groups in the security
2729 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
2730 * on which the function is to execute.
2731 * level [I] Information level of the data.
2732 * 0 Return global passwords parameters. bufptr points to a
2733 * USER_MODALS_INFO_0 struct.
2734 * 1 Return logon server and domain controller information. bufptr
2735 * points to a USER_MODALS_INFO_1 struct.
2736 * 2 Return domain name and identifier. bufptr points to a
2737 * USER_MODALS_INFO_2 struct.
2738 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
2740 * pbuffer [I] Buffer that receives the data.
2743 * Success: NERR_Success.
2745 * ERROR_ACCESS_DENIED - the user does not have access to the info.
2746 * NERR_InvalidComputer - computer name is invalid.
2748 NET_API_STATUS WINAPI
NetUserModalsGet(
2749 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
2751 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
2756 /* return global passwords parameters */
2757 FIXME("level 0 not implemented!\n");
2759 return NERR_InternalError
;
2761 /* return logon server and domain controller info */
2762 FIXME("level 1 not implemented!\n");
2764 return NERR_InternalError
;
2767 /* return domain name and identifier */
2768 PUSER_MODALS_INFO_2 umi
;
2769 LSA_HANDLE policyHandle
;
2770 LSA_OBJECT_ATTRIBUTES objectAttributes
;
2771 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
2773 PSID domainIdentifier
= NULL
;
2776 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
2777 objectAttributes
.Length
= sizeof(objectAttributes
);
2779 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
2780 POLICY_VIEW_LOCAL_INFORMATION
,
2782 if (ntStatus
!= STATUS_SUCCESS
)
2784 WARN("LsaOpenPolicy failed with NT status %x\n",
2785 LsaNtStatusToWinError(ntStatus
));
2789 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
2790 PolicyAccountDomainInformation
,
2791 (PVOID
*)&domainInfo
);
2792 if (ntStatus
!= STATUS_SUCCESS
)
2794 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
2795 LsaNtStatusToWinError(ntStatus
));
2796 LsaClose(policyHandle
);
2800 domainIdentifier
= domainInfo
->DomainSid
;
2801 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
2802 LsaClose(policyHandle
);
2804 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
2805 GetLengthSid(domainIdentifier
) +
2806 domainNameLen
* sizeof(WCHAR
),
2809 if (ntStatus
!= NERR_Success
)
2811 WARN("NetApiBufferAllocate() failed\n");
2812 LsaFreeMemory(domainInfo
);
2816 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
2817 umi
->usrmod2_domain_id
= *pbuffer
+ sizeof(USER_MODALS_INFO_2
);
2818 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
2819 sizeof(USER_MODALS_INFO_2
) + GetLengthSid(domainIdentifier
));
2821 lstrcpynW(umi
->usrmod2_domain_name
,
2822 domainInfo
->DomainName
.Buffer
,
2824 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
2827 LsaFreeMemory(domainInfo
);
2832 /* return lockout information */
2833 FIXME("level 3 not implemented!\n");
2835 return NERR_InternalError
;
2837 TRACE("Invalid level %d is specified\n", level
);
2839 return ERROR_INVALID_LEVEL
;
2842 return NERR_Success
;
2845 static NET_API_STATUS
change_password_smb( LPCWSTR domainname
, LPCWSTR username
,
2846 LPCWSTR oldpassword
, LPCWSTR newpassword
)
2849 NET_API_STATUS ret
= NERR_Success
;
2850 static char option_silent
[] = "-s";
2851 static char option_user
[] = "-U";
2852 static char option_remote
[] = "-r";
2853 static char smbpasswd
[] = "smbpasswd";
2857 char *server
= NULL
, *user
, *argv
[7], *old
= NULL
, *new = NULL
;
2859 if (domainname
&& !(server
= strdup_unixcp( domainname
))) return ERROR_OUTOFMEMORY
;
2860 if (!(user
= strdup_unixcp( username
)))
2862 ret
= ERROR_OUTOFMEMORY
;
2865 if (!(old
= strdup_unixcp( oldpassword
)))
2867 ret
= ERROR_OUTOFMEMORY
;
2870 if (!(new = strdup_unixcp( newpassword
)))
2872 ret
= ERROR_OUTOFMEMORY
;
2875 argv
[0] = smbpasswd
;
2876 argv
[1] = option_silent
;
2877 argv
[2] = option_user
;
2881 argv
[4] = option_remote
;
2885 else argv
[4] = NULL
;
2887 if (pipe( pipe_out
) == -1)
2889 ret
= NERR_InternalError
;
2892 fcntl( pipe_out
[0], F_SETFD
, FD_CLOEXEC
);
2893 fcntl( pipe_out
[1], F_SETFD
, FD_CLOEXEC
);
2895 switch ((pid
= fork()))
2898 close( pipe_out
[0] );
2899 close( pipe_out
[1] );
2900 ret
= NERR_InternalError
;
2903 dup2( pipe_out
[0], 0 );
2904 close( pipe_out
[0] );
2905 close( pipe_out
[1] );
2906 execvp( "smbpasswd", argv
);
2907 ERR( "can't execute smbpasswd, is it installed?\n" );
2910 close( pipe_out
[0] );
2913 write( pipe_out
[1], old
, strlen( old
) );
2914 write( pipe_out
[1], "\n", 1 );
2915 write( pipe_out
[1], new, strlen( new ) );
2916 write( pipe_out
[1], "\n", 1 );
2917 write( pipe_out
[1], new, strlen( new ) );
2918 write( pipe_out
[1], "\n", 1 );
2919 close( pipe_out
[1] );
2922 wret
= waitpid(pid
, &status
, 0);
2923 } while (wret
< 0 && errno
== EINTR
);
2925 if (ret
== NERR_Success
&& (wret
< 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)))
2926 ret
= NERR_InternalError
;
2929 HeapFree( GetProcessHeap(), 0, server
);
2930 HeapFree( GetProcessHeap(), 0, user
);
2931 HeapFree( GetProcessHeap(), 0, old
);
2932 HeapFree( GetProcessHeap(), 0, new );
2935 ERR( "no fork support on this platform\n" );
2936 return NERR_InternalError
;
2940 /******************************************************************************
2941 * NetUserChangePassword (NETAPI32.@)
2943 * domainname [I] Optional. Domain on which the user resides or the logon
2944 * domain of the current user if NULL.
2945 * username [I] Optional. Username to change the password for or the name
2946 * of the current user if NULL.
2947 * oldpassword [I] The user's current password.
2948 * newpassword [I] The password that the user will be changed to using.
2951 * Success: NERR_Success.
2952 * Failure: NERR_* failure code or win error code.
2955 NET_API_STATUS WINAPI
NetUserChangePassword(LPCWSTR domainname
, LPCWSTR username
,
2956 LPCWSTR oldpassword
, LPCWSTR newpassword
)
2958 struct sam_user
*user
;
2960 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname
), debugstr_w(username
));
2962 if (!change_password_smb( domainname
, username
, oldpassword
, newpassword
))
2963 return NERR_Success
;
2966 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname
));
2968 if((user
= NETAPI_FindUser(username
)) == NULL
)
2969 return NERR_UserNotFound
;
2971 if(lstrcmpW(user
->user_password
, oldpassword
) != 0)
2972 return ERROR_INVALID_PASSWORD
;
2974 if(lstrlenW(newpassword
) > PWLEN
)
2975 return ERROR_PASSWORD_RESTRICTION
;
2977 lstrcpyW(user
->user_password
, newpassword
);
2979 return NERR_Success
;
2982 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
2984 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
2985 return NERR_Success
;
2988 NET_API_STATUS WINAPI
NetUseDel(LMSTR servername
, LMSTR usename
, DWORD forcecond
)
2990 FIXME("%s %s %d stub\n", debugstr_w(servername
), debugstr_w(usename
), forcecond
);
2991 return NERR_Success
;
2994 /************************************************************
2995 * I_BrowserSetNetlogonState (NETAPI32.@)
2997 NET_API_STATUS WINAPI
I_BrowserSetNetlogonState(
2998 LPWSTR ServerName
, LPWSTR DomainName
, LPWSTR EmulatedServerName
,
3001 return ERROR_NOT_SUPPORTED
;
3004 /************************************************************
3005 * I_BrowserQueryEmulatedDomains (NETAPI32.@)
3007 NET_API_STATUS WINAPI
I_BrowserQueryEmulatedDomains(
3008 LPWSTR ServerName
, PBROWSER_EMULATED_DOMAIN
*EmulatedDomains
,
3009 LPDWORD EntriesRead
)
3011 return ERROR_NOT_SUPPORTED
;
3014 DWORD WINAPI
DsGetDcNameW(LPCWSTR ComputerName
, LPCWSTR AvoidDCName
,
3015 GUID
* DomainGuid
, LPCWSTR SiteName
, ULONG Flags
,
3016 PDOMAIN_CONTROLLER_INFOW
*DomainControllerInfo
)
3018 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_w(ComputerName
),
3019 debugstr_w(AvoidDCName
), debugstr_guid(DomainGuid
),
3020 debugstr_w(SiteName
), Flags
, DomainControllerInfo
);
3021 return ERROR_CALL_NOT_IMPLEMENTED
;
3024 DWORD WINAPI
DsGetDcNameA(LPCSTR ComputerName
, LPCSTR AvoidDCName
,
3025 GUID
* DomainGuid
, LPCSTR SiteName
, ULONG Flags
,
3026 PDOMAIN_CONTROLLER_INFOA
*DomainControllerInfo
)
3028 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_a(ComputerName
),
3029 debugstr_a(AvoidDCName
), debugstr_guid(DomainGuid
),
3030 debugstr_a(SiteName
), Flags
, DomainControllerInfo
);
3031 return ERROR_CALL_NOT_IMPLEMENTED
;
3034 DWORD WINAPI
DsGetSiteNameW(LPCWSTR ComputerName
, LPWSTR
*SiteName
)
3036 FIXME("(%s, %p): stub\n", debugstr_w(ComputerName
), SiteName
);
3037 return ERROR_CALL_NOT_IMPLEMENTED
;
3040 DWORD WINAPI
DsGetSiteNameA(LPCSTR ComputerName
, LPSTR
*SiteName
)
3042 FIXME("(%s, %p): stub\n", debugstr_a(ComputerName
), SiteName
);
3043 return ERROR_CALL_NOT_IMPLEMENTED
;
3046 /************************************************************
3047 * DsRoleFreeMemory (NETAPI32.@)
3050 * Buffer [I] Pointer to the to-be-freed buffer.
3055 VOID WINAPI
DsRoleFreeMemory(PVOID Buffer
)
3057 TRACE("(%p)\n", Buffer
);
3058 HeapFree(GetProcessHeap(), 0, Buffer
);
3061 /************************************************************
3062 * DsRoleGetPrimaryDomainInformation (NETAPI32.@)
3065 * lpServer [I] Pointer to UNICODE string with ComputerName
3066 * InfoLevel [I] Type of data to retrieve
3067 * Buffer [O] Pointer to to the requested data
3072 * When lpServer is NULL, use the local computer
3074 DWORD WINAPI
DsRoleGetPrimaryDomainInformation(
3075 LPCWSTR lpServer
, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel
,
3080 FIXME("(%p, %d, %p) stub\n", lpServer
, InfoLevel
, Buffer
);
3082 /* Check some input parameters */
3084 if (!Buffer
) return ERROR_INVALID_PARAMETER
;
3085 if ((InfoLevel
< DsRolePrimaryDomainInfoBasic
) || (InfoLevel
> DsRoleOperationState
)) return ERROR_INVALID_PARAMETER
;
3090 case DsRolePrimaryDomainInfoBasic
:
3092 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
3093 LSA_HANDLE PolicyHandle
;
3094 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
3096 int logon_domain_sz
;
3098 PDSROLE_PRIMARY_DOMAIN_INFO_BASIC basic
;
3100 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
3101 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
3102 POLICY_VIEW_LOCAL_INFORMATION
, &PolicyHandle
);
3103 if (NtStatus
!= STATUS_SUCCESS
)
3105 TRACE("LsaOpenPolicyFailed with NT status %x\n",
3106 LsaNtStatusToWinError(NtStatus
));
3107 return ERROR_OUTOFMEMORY
;
3109 LsaQueryInformationPolicy(PolicyHandle
,
3110 PolicyAccountDomainInformation
, (PVOID
*)&DomainInfo
);
3111 logon_domain_sz
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
3112 LsaClose(PolicyHandle
);
3114 size
= sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC
) +
3115 logon_domain_sz
* sizeof(WCHAR
);
3116 basic
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
3119 basic
->MachineRole
= DsRole_RoleStandaloneWorkstation
;
3120 basic
->DomainNameFlat
= (LPWSTR
)((LPBYTE
)basic
+
3121 sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC
));
3122 lstrcpyW(basic
->DomainNameFlat
, DomainInfo
->DomainName
.Buffer
);
3123 ret
= ERROR_SUCCESS
;
3126 ret
= ERROR_OUTOFMEMORY
;
3127 *Buffer
= (PBYTE
)basic
;
3128 LsaFreeMemory(DomainInfo
);
3132 ret
= ERROR_CALL_NOT_IMPLEMENTED
;
3137 /************************************************************
3138 * NetLocalGroupAdd (NETAPI32.@)
3140 NET_API_STATUS WINAPI
NetLocalGroupAdd(
3146 FIXME("(%s %d %p %p) stub!\n", debugstr_w(servername
), level
, buf
,
3148 return NERR_Success
;
3151 /************************************************************
3152 * NetLocalGroupAddMember (NETAPI32.@)
3154 NET_API_STATUS WINAPI
NetLocalGroupAddMember(
3159 FIXME("(%s %s %p) stub!\n", debugstr_w(servername
),
3160 debugstr_w(groupname
), membersid
);
3161 return NERR_Success
;
3164 /************************************************************
3165 * NetLocalGroupAddMembers (NETAPI32.@)
3167 NET_API_STATUS WINAPI
NetLocalGroupAddMembers(
3174 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3175 debugstr_w(groupname
), level
, buf
, totalentries
);
3176 return NERR_Success
;
3179 /************************************************************
3180 * NetLocalGroupDel (NETAPI32.@)
3182 NET_API_STATUS WINAPI
NetLocalGroupDel(
3186 FIXME("(%s %s) stub!\n", debugstr_w(servername
), debugstr_w(groupname
));
3187 return NERR_Success
;
3190 /************************************************************
3191 * NetLocalGroupDelMember (NETAPI32.@)
3193 NET_API_STATUS WINAPI
NetLocalGroupDelMember(
3198 FIXME("(%s %s %p) stub!\n", debugstr_w(servername
),
3199 debugstr_w(groupname
), membersid
);
3200 return NERR_Success
;
3203 /************************************************************
3204 * NetLocalGroupDelMembers (NETAPI32.@)
3206 NET_API_STATUS WINAPI
NetLocalGroupDelMembers(
3213 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3214 debugstr_w(groupname
), level
, buf
, totalentries
);
3215 return NERR_Success
;
3218 /************************************************************
3219 * NetLocalGroupEnum (NETAPI32.@)
3221 NET_API_STATUS WINAPI
NetLocalGroupEnum(
3226 LPDWORD entriesread
,
3227 LPDWORD totalentries
,
3228 PDWORD_PTR resumehandle
)
3230 FIXME("(%s %d %p %d %p %p %p) stub!\n", debugstr_w(servername
),
3231 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resumehandle
);
3234 return NERR_Success
;
3237 /************************************************************
3238 * NetLocalGroupGetInfo (NETAPI32.@)
3240 NET_API_STATUS WINAPI
NetLocalGroupGetInfo(
3246 static const WCHAR commentW
[]={'N','o',' ','c','o','m','m','e','n','t',0};
3247 LOCALGROUP_INFO_1
* info
;
3250 FIXME("(%s %s %d %p) semi-stub!\n", debugstr_w(servername
),
3251 debugstr_w(groupname
), level
, bufptr
);
3253 size
= sizeof(*info
) + sizeof(WCHAR
) * (lstrlenW(groupname
)+1) + sizeof(commentW
);
3254 NetApiBufferAllocate(size
, (LPVOID
*)&info
);
3256 info
->lgrpi1_name
= (LPWSTR
)(info
+ 1);
3257 lstrcpyW(info
->lgrpi1_name
, groupname
);
3259 info
->lgrpi1_comment
= info
->lgrpi1_name
+ lstrlenW(groupname
) + 1;
3260 lstrcpyW(info
->lgrpi1_comment
, commentW
);
3262 *bufptr
= (LPBYTE
)info
;
3264 return NERR_Success
;
3267 /************************************************************
3268 * NetLocalGroupGetMembers (NETAPI32.@)
3270 NET_API_STATUS WINAPI
NetLocalGroupGetMembers(
3272 LPCWSTR localgroupname
,
3276 LPDWORD entriesread
,
3277 LPDWORD totalentries
,
3278 PDWORD_PTR resumehandle
)
3280 FIXME("(%s %s %d %p %d, %p %p %p) stub!\n", debugstr_w(servername
),
3281 debugstr_w(localgroupname
), level
, bufptr
, prefmaxlen
, entriesread
,
3282 totalentries
, resumehandle
);
3286 WCHAR userName
[MAX_COMPUTERNAME_LENGTH
+ 1];
3289 PLOCALGROUP_MEMBERS_INFO_3 ptr
;
3291 /* still a stub, current user is belonging to all groups */
3296 userNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
3297 if (!GetUserNameW(userName
,&userNameLen
))
3298 return ERROR_NOT_ENOUGH_MEMORY
;
3300 needlen
= sizeof(LOCALGROUP_MEMBERS_INFO_3
) +
3301 (userNameLen
+2) * sizeof(WCHAR
);
3302 if (prefmaxlen
!= MAX_PREFERRED_LENGTH
)
3303 len
= min(prefmaxlen
,needlen
);
3307 NetApiBufferAllocate(len
, (LPVOID
*) bufptr
);
3309 return ERROR_MORE_DATA
;
3311 ptr
= (PLOCALGROUP_MEMBERS_INFO_3
)*bufptr
;
3312 ptr
->lgrmi3_domainandname
= (LPWSTR
)(*bufptr
+sizeof(LOCALGROUP_MEMBERS_INFO_3
));
3313 lstrcpyW(ptr
->lgrmi3_domainandname
,userName
);
3318 return NERR_Success
;
3321 /************************************************************
3322 * NetLocalGroupSetInfo (NETAPI32.@)
3324 NET_API_STATUS WINAPI
NetLocalGroupSetInfo(
3331 FIXME("(%s %s %d %p %p) stub!\n", debugstr_w(servername
),
3332 debugstr_w(groupname
), level
, buf
, parm_err
);
3333 return NERR_Success
;
3336 /************************************************************
3337 * NetLocalGroupSetMember (NETAPI32.@)
3339 NET_API_STATUS WINAPI
NetLocalGroupSetMembers(
3346 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3347 debugstr_w(groupname
), level
, buf
, totalentries
);
3348 return NERR_Success
;