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 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
);
545 case ACCESS_DENIED_ACE_TYPE
:
547 ACCESS_DENIED_ACE
*ace
= (ACCESS_DENIED_ACE
*)src
;
548 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
549 memset( &dst
->object
, 0, sizeof(dst
->object
) );
550 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
552 case SYSTEM_AUDIT_ACE_TYPE
:
554 SYSTEM_AUDIT_ACE
*ace
= (SYSTEM_AUDIT_ACE
*)src
;
555 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
556 memset( &dst
->object
, 0, sizeof(dst
->object
) );
557 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
559 case SYSTEM_ALARM_ACE_TYPE
:
561 SYSTEM_ALARM_ACE
*ace
= (SYSTEM_ALARM_ACE
*)src
;
562 dst
->access_mask
= access_mask_to_samba( ace
->Mask
);
563 memset( &dst
->object
, 0, sizeof(dst
->object
) );
564 sid_to_samba( (const SID
*)&ace
->SidStart
, &dst
->trustee
);
567 ERR( "unhandled type %u\n", src
->AceType
);
568 return ERROR_INVALID_PARAMETER
;
573 static NET_API_STATUS
acl_to_samba( const ACL
*src
, struct acl
*dst
)
575 NET_API_STATUS status
;
579 switch (src
->AclRevision
)
582 dst
->revision
= ACL_REVISION_ADS
;
585 ERR( "unkhandled revision %u\n", src
->AclRevision
);
586 return ERROR_UNKNOWN_REVISION
;
588 dst
->size
= sizeof(*dst
);
589 src_ace
= (ACE_HEADER
*)(src
+ 1);
590 dst
->aces
= (struct ace
*)(dst
+ 1);
591 for (i
= 0; i
< src
->AceCount
; i
++)
593 if ((status
= ace_to_samba( src_ace
, &dst
->aces
[i
] ))) return status
;
594 src_ace
= (ACE_HEADER
*)((char *)src_ace
+ src_ace
->AceSize
);
595 dst
->size
+= dst
->aces
[i
].size
;
600 #define SELF_RELATIVE_FIELD(sd,field)\
601 ((char *)(sd) + ((SECURITY_DESCRIPTOR_RELATIVE *)(sd))->field)
603 static NET_API_STATUS
sd_to_samba( const SECURITY_DESCRIPTOR
*src
, struct security_descriptor
*dst
)
605 NET_API_STATUS status
;
606 const SID
*owner
, *group
;
607 const ACL
*dacl
, *sacl
;
608 unsigned int offset
= sizeof(*dst
);
610 if (src
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
611 return ERROR_UNKNOWN_REVISION
;
613 dst
->revision
= SECURITY_DESCRIPTOR_REVISION_1
;
614 dst
->type
= sd_control_to_samba( src
->Control
);
616 if (src
->Control
& SE_SELF_RELATIVE
)
618 if (!src
->Owner
) dst
->owner_sid
= NULL
;
621 dst
->owner_sid
= (struct sid
*)((char *)dst
+ offset
);
622 owner
= (const SID
*)SELF_RELATIVE_FIELD( src
, Owner
);
623 if ((status
= sid_to_samba( owner
, dst
->owner_sid
))) return status
;
624 offset
+= sizeof(struct sid
);
626 if (!src
->Group
) dst
->group_sid
= NULL
;
629 dst
->group_sid
= (struct sid
*)((char *)dst
+ offset
);
630 group
= (const SID
*)SELF_RELATIVE_FIELD( src
, Group
);
631 if ((status
= sid_to_samba( group
, dst
->group_sid
))) return status
;
632 offset
+= sizeof(struct sid
);
634 if (!(src
->Control
& SE_SACL_PRESENT
)) dst
->sacl
= NULL
;
637 dst
->sacl
= (struct acl
*)((char *)dst
+ offset
);
638 sacl
= (const ACL
*)SELF_RELATIVE_FIELD( src
, Sacl
);
639 if ((status
= acl_to_samba( sacl
, dst
->sacl
))) return status
;
640 offset
+= dst
->sacl
->size
;
642 if (!(src
->Control
& SE_DACL_PRESENT
)) dst
->dacl
= NULL
;
645 dst
->dacl
= (struct acl
*)((char *)dst
+ offset
);
646 dacl
= (const ACL
*)SELF_RELATIVE_FIELD( src
, Dacl
);
647 if ((status
= acl_to_samba( dacl
, dst
->dacl
))) return status
;
652 if (!src
->Owner
) dst
->owner_sid
= NULL
;
655 dst
->owner_sid
= (struct sid
*)((char *)dst
+ offset
);
656 if ((status
= sid_to_samba( src
->Owner
, dst
->owner_sid
))) return status
;
657 offset
+= sizeof(struct sid
);
659 if (!src
->Group
) dst
->group_sid
= NULL
;
662 dst
->group_sid
= (struct sid
*)((char *)dst
+ offset
);
663 if ((status
= sid_to_samba( src
->Group
, dst
->group_sid
))) return status
;
664 offset
+= sizeof(struct sid
);
666 if (!(src
->Control
& SE_SACL_PRESENT
)) dst
->sacl
= NULL
;
669 dst
->sacl
= (struct acl
*)((char *)dst
+ offset
);
670 if ((status
= acl_to_samba( src
->Sacl
, dst
->sacl
))) return status
;
671 offset
+= dst
->sacl
->size
;
673 if (!(src
->Control
& SE_DACL_PRESENT
)) dst
->dacl
= NULL
;
676 dst
->dacl
= (struct acl
*)((char *)dst
+ offset
);
677 if ((status
= acl_to_samba( src
->Dacl
, dst
->dacl
))) return status
;
683 static unsigned int sd_to_samba_size( const SECURITY_DESCRIPTOR
*sd
)
685 unsigned int ret
= sizeof(struct security_descriptor
);
687 if (sd
->Owner
) ret
+= sizeof(struct sid
);
688 if (sd
->Group
) ret
+= sizeof(struct sid
);
689 if (sd
->Control
& SE_SACL_PRESENT
)
690 ret
+= sizeof(struct acl
) + sd
->Sacl
->AceCount
* sizeof(struct ace
);
691 if (sd
->Control
& SE_DACL_PRESENT
)
692 ret
+= sizeof(struct acl
) + sd
->Dacl
->AceCount
* sizeof(struct ace
);
696 static NET_API_STATUS
share_info_502_to_samba( const BYTE
*buf
, unsigned char **bufptr
)
698 NET_API_STATUS status
;
699 struct share_info_502
*ret
;
700 SHARE_INFO_502
*info
= (SHARE_INFO_502
*)buf
;
701 DWORD len
= 0, size
= 0;
705 if (info
->shi502_netname
)
706 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_netname
, -1, NULL
, 0, NULL
, NULL
);
707 if (info
->shi502_remark
)
708 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_remark
, -1, NULL
, 0, NULL
, NULL
);
709 if (info
->shi502_path
)
710 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_path
, -1, NULL
, 0, NULL
, NULL
);
711 if (info
->shi502_passwd
)
712 len
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_passwd
, -1, NULL
, 0, NULL
, NULL
);
713 if (info
->shi502_security_descriptor
)
714 size
= sd_to_samba_size( info
->shi502_security_descriptor
);
715 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ret
) + (len
* sizeof(WCHAR
)) + size
)))
716 return ERROR_OUTOFMEMORY
;
718 ptr
= (char *)(ret
+ 1);
719 if (!info
->shi502_netname
) ret
->shi502_netname
= NULL
;
722 ret
->shi502_netname
= ptr
;
723 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_netname
, -1, ptr
, len
, NULL
, NULL
);
725 ret
->shi502_type
= info
->shi502_type
;
726 if (!info
->shi502_remark
) ret
->shi502_remark
= NULL
;
729 ret
->shi502_remark
= ptr
;
730 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_remark
, -1, ptr
, len
, NULL
, NULL
);
732 ret
->shi502_permissions
= info
->shi502_permissions
;
733 ret
->shi502_max_uses
= info
->shi502_max_uses
;
734 ret
->shi502_current_uses
= info
->shi502_current_uses
;
735 if (!info
->shi502_path
) ret
->shi502_path
= NULL
;
738 ret
->shi502_path
= ptr
;
739 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_path
, -1, ptr
, len
, NULL
, NULL
);
741 if (!info
->shi502_passwd
) ret
->shi502_passwd
= NULL
;
744 ret
->shi502_passwd
= ptr
;
745 ptr
+= WideCharToMultiByte( CP_UNIXCP
, 0, info
->shi502_passwd
, -1, ptr
, len
, NULL
, NULL
);
747 ret
->shi502_reserved
= info
->shi502_reserved
;
748 if (!info
->shi502_security_descriptor
) ret
->shi502_security_descriptor
= NULL
;
751 status
= sd_to_samba( info
->shi502_security_descriptor
, (struct security_descriptor
*)ptr
);
754 HeapFree( GetProcessHeap(), 0, ret
);
757 ret
->shi502_security_descriptor
= (struct security_descriptor
*)ptr
;
759 *bufptr
= (unsigned char *)ret
;
763 static NET_API_STATUS
share_info_to_samba( DWORD level
, const BYTE
*buf
, unsigned char **bufptr
)
767 case 2: return share_info_2_to_samba( buf
, bufptr
);
768 case 502: return share_info_502_to_samba( buf
, bufptr
);
770 FIXME( "level %u not supported\n", level
);
771 return ERROR_NOT_SUPPORTED
;
775 static NET_API_STATUS
share_add( LMSTR servername
, DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
779 NET_API_STATUS status
;
781 if (servername
&& !(server
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
782 status
= share_info_to_samba( level
, buf
, &info
);
787 status
= pNetShareAdd( server
, level
, info
, &err
);
788 HeapFree( GetProcessHeap(), 0, info
);
789 if (parm_err
) *parm_err
= err
;
791 HeapFree( GetProcessHeap(), 0, server
);
795 static NET_API_STATUS
share_del( LMSTR servername
, LMSTR netname
, DWORD reserved
)
797 char *server
= NULL
, *share
;
798 NET_API_STATUS status
;
800 if (servername
&& !(server
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
801 if (!(share
= strdup_unixcp( netname
)))
803 HeapFree( GetProcessHeap(), 0, server
);
804 return ERROR_OUTOFMEMORY
;
806 status
= pNetShareDel( server
, share
, reserved
);
807 HeapFree( GetProcessHeap(), 0, server
);
808 HeapFree( GetProcessHeap(), 0, share
);
812 struct wksta_info_100
814 unsigned int wki100_platform_id
;
815 const char *wki100_computername
;
816 const char *wki100_langroup
;
817 unsigned int wki100_ver_major
;
818 unsigned int wki100_ver_minor
;
821 static NET_API_STATUS
wksta_info_100_from_samba( const unsigned char *buf
, BYTE
**bufptr
)
824 struct wksta_info_100
*info
= (struct wksta_info_100
*)buf
;
828 if (info
->wki100_computername
)
829 len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_computername
, -1, NULL
, 0 );
830 if (info
->wki100_langroup
)
831 len
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_langroup
, -1, NULL
, 0 );
832 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ret
) + (len
* sizeof(WCHAR
) ))))
833 return ERROR_OUTOFMEMORY
;
835 ptr
= (WCHAR
*)(ret
+ 1);
836 ret
->wki100_platform_id
= info
->wki100_platform_id
;
837 if (!info
->wki100_computername
) ret
->wki100_computername
= NULL
;
840 ret
->wki100_computername
= ptr
;
841 ptr
+= MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_computername
, -1, ptr
, len
);
843 if (!info
->wki100_langroup
) ret
->wki100_langroup
= NULL
;
846 ret
->wki100_langroup
= ptr
;
847 MultiByteToWideChar( CP_UNIXCP
, 0, info
->wki100_langroup
, -1, ptr
, len
);
849 ret
->wki100_ver_major
= info
->wki100_ver_major
;
850 ret
->wki100_ver_minor
= info
->wki100_ver_minor
;
851 *bufptr
= (BYTE
*)ret
;
855 static NET_API_STATUS
wksta_info_from_samba( DWORD level
, const unsigned char *buf
, BYTE
**bufptr
)
859 case 100: return wksta_info_100_from_samba( buf
, bufptr
);
861 FIXME( "level %u not supported\n", level
);
862 return ERROR_NOT_SUPPORTED
;
866 static NET_API_STATUS
wksta_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
868 NET_API_STATUS status
;
870 unsigned char *buf
= NULL
;
872 if (servername
&& !(wksta
= strdup_unixcp( servername
))) return ERROR_OUTOFMEMORY
;
873 status
= pNetWkstaGetInfo( wksta
, level
, &buf
);
874 HeapFree( GetProcessHeap(), 0, wksta
);
877 status
= wksta_info_from_samba( level
, buf
, bufptr
);
878 pNetApiBufferFree( buf
);
885 static BOOL
libnetapi_init(void)
890 static NET_API_STATUS
server_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
893 return ERROR_NOT_SUPPORTED
;
895 static NET_API_STATUS
share_add( LMSTR servername
, DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
898 return ERROR_NOT_SUPPORTED
;
900 static NET_API_STATUS
share_del( LMSTR servername
, LMSTR netname
, DWORD reserved
)
903 return ERROR_NOT_SUPPORTED
;
905 static NET_API_STATUS
wksta_getinfo( LMSTR servername
, DWORD level
, LPBYTE
*bufptr
)
908 return ERROR_NOT_SUPPORTED
;
911 #endif /* SONAME_LIBNETAPI */
913 /************************************************************
914 * NETAPI_IsLocalComputer
916 * Checks whether the server name indicates local machine.
918 static BOOL
NETAPI_IsLocalComputer( LMCSTR name
)
920 WCHAR buf
[MAX_COMPUTERNAME_LENGTH
+ 1];
921 DWORD size
= sizeof(buf
) / sizeof(buf
[0]);
924 if (!name
|| !name
[0]) return TRUE
;
926 ret
= GetComputerNameW( buf
, &size
);
927 if (ret
&& name
[0] == '\\' && name
[1] == '\\') name
+= 2;
928 return ret
&& !strcmpiW( name
, buf
);
931 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
933 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
936 case DLL_PROCESS_ATTACH
:
937 DisableThreadLibraryCalls(hinstDLL
);
941 case DLL_PROCESS_DETACH
:
942 if (lpvReserved
) break;
950 /************************************************************
951 * NetServerEnum (NETAPI32.@)
953 NET_API_STATUS WINAPI
NetServerEnum(
959 LPDWORD totalentries
,
962 LPDWORD resume_handle
965 FIXME("Stub (%s %d %p %d %p %p %d %s %p)\n", debugstr_w(servername
),
966 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, servertype
,
967 debugstr_w(domain
), resume_handle
);
969 return ERROR_NO_BROWSER_SERVERS_FOUND
;
972 /************************************************************
973 * NetServerEnumEx (NETAPI32.@)
975 NET_API_STATUS WINAPI
NetServerEnumEx(
981 LPDWORD totalentries
,
984 LMCSTR FirstNameToReturn
)
986 FIXME("Stub (%s %d %p %d %p %p %d %s %s)\n",
987 debugstr_w(ServerName
), Level
, Bufptr
, PrefMaxlen
, EntriesRead
, totalentries
,
988 servertype
, debugstr_w(domain
), debugstr_w(FirstNameToReturn
));
990 return ERROR_NO_BROWSER_SERVERS_FOUND
;
993 /************************************************************
994 * NetServerDiskEnum (NETAPI32.@)
996 NET_API_STATUS WINAPI
NetServerDiskEnum(
1001 LPDWORD EntriesRead
,
1002 LPDWORD totalentries
,
1003 LPDWORD Resume_Handle
)
1005 FIXME("Stub (%s %d %p %d %p %p %p)\n", debugstr_w(ServerName
),
1006 Level
, Bufptr
, PrefMaxlen
, EntriesRead
, totalentries
, Resume_Handle
);
1008 return ERROR_NO_BROWSER_SERVERS_FOUND
;
1011 /************************************************************
1012 * NetServerGetInfo (NETAPI32.@)
1014 NET_API_STATUS WINAPI
NetServerGetInfo(LMSTR servername
, DWORD level
, LPBYTE
* bufptr
)
1017 BOOL local
= NETAPI_IsLocalComputer( servername
);
1019 TRACE("%s %d %p\n", debugstr_w( servername
), level
, bufptr
);
1023 if (libnetapi_init()) return server_getinfo( servername
, level
, bufptr
);
1024 FIXME( "remote computers not supported\n" );
1025 return ERROR_INVALID_LEVEL
;
1027 if (!bufptr
) return ERROR_INVALID_PARAMETER
;
1034 DWORD computerNameLen
, size
;
1035 WCHAR computerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1037 computerNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
1038 GetComputerNameW(computerName
, &computerNameLen
);
1039 computerNameLen
++; /* include NULL terminator */
1041 size
= sizeof(SERVER_INFO_101
) + computerNameLen
* sizeof(WCHAR
);
1042 ret
= NetApiBufferAllocate(size
, (LPVOID
*)bufptr
);
1043 if (ret
== NERR_Success
)
1045 /* INFO_100 structure is a subset of INFO_101 */
1046 PSERVER_INFO_101 info
= (PSERVER_INFO_101
)*bufptr
;
1047 OSVERSIONINFOW verInfo
;
1049 info
->sv101_platform_id
= PLATFORM_ID_NT
;
1050 info
->sv101_name
= (LMSTR
)(*bufptr
+ sizeof(SERVER_INFO_101
));
1051 memcpy(info
->sv101_name
, computerName
,
1052 computerNameLen
* sizeof(WCHAR
));
1053 verInfo
.dwOSVersionInfoSize
= sizeof(verInfo
);
1054 GetVersionExW(&verInfo
);
1055 info
->sv101_version_major
= verInfo
.dwMajorVersion
;
1056 info
->sv101_version_minor
= verInfo
.dwMinorVersion
;
1057 /* Use generic type as no wine equivalent of DC / Server */
1058 info
->sv101_type
= SV_TYPE_NT
;
1059 info
->sv101_comment
= NULL
;
1065 FIXME("level %d unimplemented\n", level
);
1066 ret
= ERROR_INVALID_LEVEL
;
1072 /************************************************************
1073 * NetStatisticsGet (NETAPI32.@)
1075 NET_API_STATUS WINAPI
NetStatisticsGet(LMSTR server
, LMSTR service
,
1076 DWORD level
, DWORD options
,
1079 TRACE("(%p, %p, %d, %d, %p)\n", server
, service
, level
, options
, bufptr
);
1080 return NERR_InternalError
;
1083 NET_API_STATUS WINAPI
NetUseEnum(LMSTR server
, DWORD level
, LPBYTE
* bufptr
, DWORD prefmaxsize
,
1084 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resumehandle
)
1086 FIXME("stub (%p, %d, %p, %d, %p, %p, %p)\n", server
, level
, bufptr
, prefmaxsize
,
1087 entriesread
, totalentries
, resumehandle
);
1088 return ERROR_NOT_SUPPORTED
;
1091 NET_API_STATUS WINAPI
NetScheduleJobAdd(LPCWSTR server
, LPBYTE bufptr
, LPDWORD jobid
)
1093 FIXME("stub (%s, %p, %p)\n", debugstr_w(server
), bufptr
, jobid
);
1094 return NERR_Success
;
1097 NET_API_STATUS WINAPI
NetScheduleJobEnum(LPCWSTR server
, LPBYTE
* bufptr
, DWORD prefmaxsize
, LPDWORD entriesread
,
1098 LPDWORD totalentries
, LPDWORD resumehandle
)
1100 FIXME("stub (%s, %p, %d, %p, %p, %p)\n", debugstr_w(server
), bufptr
, prefmaxsize
, entriesread
, totalentries
, resumehandle
);
1103 return NERR_Success
;
1106 NET_API_STATUS WINAPI
NetUseGetInfo(LMSTR server
, LMSTR name
, DWORD level
, LPBYTE
*bufptr
)
1108 FIXME("stub (%p, %p, %d, %p)\n", server
, name
, level
, bufptr
);
1109 return ERROR_NOT_SUPPORTED
;
1113 /************************************************************
1114 * NetApiBufferAllocate (NETAPI32.@)
1116 NET_API_STATUS WINAPI
NetApiBufferAllocate(DWORD ByteCount
, LPVOID
* Buffer
)
1118 TRACE("(%d, %p)\n", ByteCount
, Buffer
);
1120 if (Buffer
== NULL
) return ERROR_INVALID_PARAMETER
;
1121 *Buffer
= HeapAlloc(GetProcessHeap(), 0, ByteCount
);
1123 return NERR_Success
;
1125 return GetLastError();
1128 /************************************************************
1129 * NetApiBufferFree (NETAPI32.@)
1131 NET_API_STATUS WINAPI
NetApiBufferFree(LPVOID Buffer
)
1133 TRACE("(%p)\n", Buffer
);
1134 HeapFree(GetProcessHeap(), 0, Buffer
);
1135 return NERR_Success
;
1138 /************************************************************
1139 * NetApiBufferReallocate (NETAPI32.@)
1141 NET_API_STATUS WINAPI
NetApiBufferReallocate(LPVOID OldBuffer
, DWORD NewByteCount
,
1144 TRACE("(%p, %d, %p)\n", OldBuffer
, NewByteCount
, NewBuffer
);
1148 *NewBuffer
= HeapReAlloc(GetProcessHeap(), 0, OldBuffer
, NewByteCount
);
1150 *NewBuffer
= HeapAlloc(GetProcessHeap(), 0, NewByteCount
);
1151 return *NewBuffer
? NERR_Success
: GetLastError();
1155 if (!HeapFree(GetProcessHeap(), 0, OldBuffer
)) return GetLastError();
1157 return NERR_Success
;
1161 /************************************************************
1162 * NetApiBufferSize (NETAPI32.@)
1164 NET_API_STATUS WINAPI
NetApiBufferSize(LPVOID Buffer
, LPDWORD ByteCount
)
1168 TRACE("(%p, %p)\n", Buffer
, ByteCount
);
1170 return ERROR_INVALID_PARAMETER
;
1171 dw
= HeapSize(GetProcessHeap(), 0, Buffer
);
1172 TRACE("size: %d\n", dw
);
1173 if (dw
!= 0xFFFFFFFF)
1178 return NERR_Success
;
1181 /************************************************************
1182 * NetSessionEnum (NETAPI32.@)
1185 * servername [I] Pointer to a string with the name of the server
1186 * UncClientName [I] Pointer to a string with the name of the session
1187 * username [I] Pointer to a string with the name of the user
1188 * level [I] Data information level
1189 * bufptr [O] Buffer to the data
1190 * prefmaxlen [I] Preferred maximum length of the data
1191 * entriesread [O] Pointer to the number of entries enumerated
1192 * totalentries [O] Pointer to the possible number of entries
1193 * resume_handle [I/O] Pointer to a handle for subsequent searches
1196 * If successful, the function returns NERR_Success
1197 * On failure it returns:
1198 * ERROR_ACCESS_DENIED User has no access to the requested information
1199 * ERROR_INVALID_LEVEL Value of 'level' is not correct
1200 * ERROR_INVALID_PARAMETER Wrong parameter
1201 * ERROR_MORE_DATA Need a larger buffer
1202 * ERROR_NOT_ENOUGH_MEMORY Not enough memory
1203 * NERR_ClientNameNotFound A session does not exist on a given computer
1204 * NERR_InvalidComputer Invalid computer name
1205 * NERR_UserNotFound User name could not be found.
1207 NET_API_STATUS WINAPI
NetSessionEnum(LMSTR servername
, LMSTR UncClientName
,
1208 LMSTR username
, DWORD level
, LPBYTE
* bufptr
, DWORD prefmaxlen
, LPDWORD entriesread
,
1209 LPDWORD totalentries
, LPDWORD resume_handle
)
1211 FIXME("Stub (%s %s %s %d %p %d %p %p %p)\n", debugstr_w(servername
),
1212 debugstr_w(UncClientName
), debugstr_w(username
),
1213 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
1215 return NERR_Success
;
1218 /************************************************************
1219 * NetShareEnum (NETAPI32.@)
1222 * servername [I] Pointer to a string with the name of the server
1223 * level [I] Data information level
1224 * bufptr [O] Buffer to the data
1225 * prefmaxlen [I] Preferred maximum length of the data
1226 * entriesread [O] Pointer to the number of entries enumerated
1227 * totalentries [O] Pointer to the possible number of entries
1228 * resume_handle [I/O] Pointer to a handle for subsequent searches
1231 * If successful, the function returns NERR_Success
1232 * On failure it returns a system error code (FIXME: find out which)
1235 NET_API_STATUS WINAPI
NetShareEnum( LMSTR servername
, DWORD level
, LPBYTE
* bufptr
,
1236 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
1238 FIXME("Stub (%s %d %p %d %p %p %p)\n", debugstr_w(servername
), level
, bufptr
,
1239 prefmaxlen
, entriesread
, totalentries
, resume_handle
);
1241 return ERROR_NOT_SUPPORTED
;
1244 /************************************************************
1245 * NetShareDel (NETAPI32.@)
1247 NET_API_STATUS WINAPI
NetShareDel(LMSTR servername
, LMSTR netname
, DWORD reserved
)
1249 BOOL local
= NETAPI_IsLocalComputer( servername
);
1251 TRACE("%s %s %d\n", debugstr_w(servername
), debugstr_w(netname
), reserved
);
1255 if (libnetapi_init()) return share_del( servername
, netname
, reserved
);
1256 FIXME( "remote computers not supported\n" );
1259 FIXME("%s %s %d\n", debugstr_w(servername
), debugstr_w(netname
), reserved
);
1260 return NERR_Success
;
1263 /************************************************************
1264 * NetShareGetInfo (NETAPI32.@)
1266 NET_API_STATUS WINAPI
NetShareGetInfo(LMSTR servername
, LMSTR netname
,
1267 DWORD level
, LPBYTE
*bufptr
)
1269 FIXME("Stub (%s %s %d %p)\n", debugstr_w(servername
),
1270 debugstr_w(netname
),level
, bufptr
);
1271 return NERR_NetNameNotFound
;
1274 /************************************************************
1275 * NetShareAdd (NETAPI32.@)
1277 NET_API_STATUS WINAPI
NetShareAdd(LMSTR servername
,
1278 DWORD level
, LPBYTE buf
, LPDWORD parm_err
)
1280 BOOL local
= NETAPI_IsLocalComputer( servername
);
1282 TRACE("%s %d %p %p\n", debugstr_w(servername
), level
, buf
, parm_err
);
1286 if (libnetapi_init()) return share_add( servername
, level
, buf
, parm_err
);
1287 FIXME( "remote computers not supported\n" );
1290 FIXME("%s %d %p %p\n", debugstr_w(servername
), level
, buf
, parm_err
);
1291 return ERROR_NOT_SUPPORTED
;
1294 /************************************************************
1295 * NetFileEnum (NETAPI32.@)
1297 NET_API_STATUS WINAPI
NetFileEnum(
1298 LPWSTR ServerName
, LPWSTR BasePath
, LPWSTR UserName
,
1299 DWORD Level
, LPBYTE
* BufPtr
, DWORD PrefMaxLen
,
1300 LPDWORD EntriesRead
, LPDWORD TotalEntries
, PDWORD_PTR ResumeHandle
)
1302 FIXME("(%s, %s, %s, %u): stub\n", debugstr_w(ServerName
), debugstr_w(BasePath
),
1303 debugstr_w(UserName
), Level
);
1304 return ERROR_NOT_SUPPORTED
;
1307 static void wprint_mac(WCHAR
* buffer
, int len
, const MIB_IFROW
*ifRow
)
1322 for (i
= 0; i
< ifRow
->dwPhysAddrLen
&& 2 * i
< len
; i
++)
1324 val
= ifRow
->bPhysAddr
[i
];
1326 buffer
[2*i
] = (WCHAR
)((val
>>4) + 'A' - 10);
1328 buffer
[2*i
] = (WCHAR
)((val
>>4) + '0');
1329 if ((val
& 0xf ) >9)
1330 buffer
[2*i
+1] = (WCHAR
)((val
& 0xf) + 'A' - 10);
1332 buffer
[2*i
+1] = (WCHAR
)((val
& 0xf) + '0');
1337 /* Theoretically this could be too short, except that MS defines
1338 * MAX_ADAPTER_NAME as 128, and MAX_INTERFACE_NAME_LEN as 256, and both
1339 * represent a count of WCHARs, so even with an extraordinarily long header
1340 * this will be plenty
1342 #define MAX_TRANSPORT_NAME MAX_INTERFACE_NAME_LEN
1343 #define MAX_TRANSPORT_ADDR 13
1345 #define NBT_TRANSPORT_NAME_HEADER "\\Device\\NetBT_Tcpip_"
1346 #define UNKNOWN_TRANSPORT_NAME_HEADER "\\Device\\UnknownTransport_"
1348 static void wprint_name(WCHAR
*buffer
, int len
, ULONG transport
,
1362 if (!memcmp(&transport
, TRANSPORT_NBT
, sizeof(ULONG
)))
1363 name
= NBT_TRANSPORT_NAME_HEADER
;
1365 name
= UNKNOWN_TRANSPORT_NAME_HEADER
;
1367 for (ptr1
= buffer
; *name
&& ptr1
< buffer
+ len
; ptr1
++, name
++)
1369 for (ptr2
= ifRow
->wszName
; *ptr2
&& ptr1
< buffer
+ len
; ptr1
++, ptr2
++)
1374 /***********************************************************************
1375 * NetWkstaTransportEnum (NETAPI32.@)
1378 struct WkstaTransportEnumData
1387 /**********************************************************************/
1389 static BOOL
WkstaEnumAdaptersCallback(UCHAR totalLANAs
, UCHAR lanaIndex
,
1390 ULONG transport
, const NetBIOSAdapterImpl
*data
, void *closure
)
1393 struct WkstaTransportEnumData
*enumData
= closure
;
1395 if (enumData
&& enumData
->pbuf
)
1401 enumData
->n_adapt
= totalLANAs
;
1402 enumData
->n_read
= 0;
1404 toAllocate
= totalLANAs
* (sizeof(WKSTA_TRANSPORT_INFO_0
)
1405 + MAX_TRANSPORT_NAME
* sizeof(WCHAR
) +
1406 MAX_TRANSPORT_ADDR
* sizeof(WCHAR
));
1407 if (enumData
->prefmaxlen
!= MAX_PREFERRED_LENGTH
)
1408 toAllocate
= enumData
->prefmaxlen
;
1409 NetApiBufferAllocate(toAllocate
, (LPVOID
*)enumData
->pbuf
);
1411 if (*(enumData
->pbuf
))
1415 if (enumData
->prefmaxlen
== MAX_PREFERRED_LENGTH
)
1416 spaceFor
= totalLANAs
;
1418 spaceFor
= enumData
->prefmaxlen
/
1419 (sizeof(WKSTA_TRANSPORT_INFO_0
) + (MAX_TRANSPORT_NAME
+
1420 MAX_TRANSPORT_ADDR
) * sizeof(WCHAR
));
1421 if (enumData
->n_read
< spaceFor
)
1423 PWKSTA_TRANSPORT_INFO_0 ti
;
1424 LMSTR transport_name
, transport_addr
;
1427 ti
= (PWKSTA_TRANSPORT_INFO_0
)(*(enumData
->pbuf
) +
1428 enumData
->n_read
* sizeof(WKSTA_TRANSPORT_INFO_0
));
1429 transport_name
= (LMSTR
)(*(enumData
->pbuf
) +
1430 totalLANAs
* sizeof(WKSTA_TRANSPORT_INFO_0
) +
1431 enumData
->n_read
* MAX_TRANSPORT_NAME
* sizeof(WCHAR
));
1432 transport_addr
= (LMSTR
)(*(enumData
->pbuf
) +
1433 totalLANAs
* (sizeof(WKSTA_TRANSPORT_INFO_0
) +
1434 MAX_TRANSPORT_NAME
* sizeof(WCHAR
)) +
1435 enumData
->n_read
* MAX_TRANSPORT_ADDR
* sizeof(WCHAR
));
1437 ifRow
.dwIndex
= data
->ifIndex
;
1439 ti
->wkti0_quality_of_service
= 0;
1440 ti
->wkti0_number_of_vcs
= 0;
1441 ti
->wkti0_transport_name
= transport_name
;
1442 wprint_name(ti
->wkti0_transport_name
, MAX_TRANSPORT_NAME
,
1444 ti
->wkti0_transport_address
= transport_addr
;
1445 wprint_mac(ti
->wkti0_transport_address
, MAX_TRANSPORT_ADDR
,
1447 if (!memcmp(&transport
, TRANSPORT_NBT
, sizeof(ULONG
)))
1448 ti
->wkti0_wan_ish
= TRUE
;
1450 ti
->wkti0_wan_ish
= FALSE
;
1451 TRACE("%d of %d:ti at %p\n", lanaIndex
, totalLANAs
, ti
);
1452 TRACE("transport_name at %p %s\n",
1453 ti
->wkti0_transport_name
,
1454 debugstr_w(ti
->wkti0_transport_name
));
1455 TRACE("transport_address at %p %s\n",
1456 ti
->wkti0_transport_address
,
1457 debugstr_w(ti
->wkti0_transport_address
));
1459 enumData
->ret
= NERR_Success
;
1464 enumData
->ret
= ERROR_MORE_DATA
;
1470 enumData
->ret
= ERROR_OUTOFMEMORY
;
1479 /**********************************************************************/
1481 NET_API_STATUS WINAPI
1482 NetWkstaTransportEnum(LMSTR ServerName
, DWORD level
, PBYTE
* pbuf
,
1483 DWORD prefmaxlen
, LPDWORD read_entries
,
1484 PDWORD total_entries
, PDWORD hresume
)
1488 TRACE(":%s, 0x%08x, %p, 0x%08x, %p, %p, %p\n", debugstr_w(ServerName
),
1489 level
, pbuf
, prefmaxlen
, read_entries
, total_entries
,hresume
);
1490 if (!NETAPI_IsLocalComputer(ServerName
))
1492 FIXME(":not implemented for non-local computers\n");
1493 ret
= ERROR_INVALID_LEVEL
;
1497 if (hresume
&& *hresume
)
1499 FIXME(":resume handle not implemented\n");
1500 return ERROR_INVALID_LEVEL
;
1505 case 0: /* transport info */
1507 ULONG allTransports
;
1508 struct WkstaTransportEnumData enumData
;
1510 if (NetBIOSNumAdapters() == 0)
1511 return ERROR_NETWORK_UNREACHABLE
;
1513 return STATUS_ACCESS_VIOLATION
;
1514 if (!total_entries
|| !pbuf
)
1515 return RPC_X_NULL_REF_POINTER
;
1517 enumData
.prefmaxlen
= prefmaxlen
;
1518 enumData
.pbuf
= pbuf
;
1519 memcpy(&allTransports
, ALL_TRANSPORTS
, sizeof(ULONG
));
1520 NetBIOSEnumAdapters(allTransports
, WkstaEnumAdaptersCallback
,
1522 *read_entries
= enumData
.n_read
;
1523 *total_entries
= enumData
.n_adapt
;
1524 if (hresume
) *hresume
= 0;
1529 TRACE("Invalid level %d is specified\n", level
);
1530 ret
= ERROR_INVALID_LEVEL
;
1536 /************************************************************
1537 * NetWkstaUserGetInfo (NETAPI32.@)
1539 NET_API_STATUS WINAPI
NetWkstaUserGetInfo(LMSTR reserved
, DWORD level
,
1542 NET_API_STATUS nastatus
;
1544 TRACE("(%s, %d, %p)\n", debugstr_w(reserved
), level
, bufptr
);
1549 PWKSTA_USER_INFO_0 ui
;
1550 DWORD dwSize
= UNLEN
+ 1;
1553 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_0
) + dwSize
* sizeof(WCHAR
),
1555 if (nastatus
!= NERR_Success
)
1556 return ERROR_NOT_ENOUGH_MEMORY
;
1558 ui
= (PWKSTA_USER_INFO_0
) *bufptr
;
1559 ui
->wkui0_username
= (LMSTR
) (*bufptr
+ sizeof(WKSTA_USER_INFO_0
));
1562 if (!GetUserNameW(ui
->wkui0_username
, &dwSize
))
1564 NetApiBufferFree(ui
);
1565 return ERROR_NOT_ENOUGH_MEMORY
;
1568 nastatus
= NetApiBufferReallocate(
1569 *bufptr
, sizeof(WKSTA_USER_INFO_0
) +
1570 (lstrlenW(ui
->wkui0_username
) + 1) * sizeof(WCHAR
),
1572 if (nastatus
!= NERR_Success
)
1580 PWKSTA_USER_INFO_1 ui
;
1581 PWKSTA_USER_INFO_0 ui0
;
1582 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
1583 LSA_HANDLE PolicyHandle
;
1584 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
1587 /* sizes of the field buffers in WCHARS */
1588 int username_sz
, logon_domain_sz
, oth_domains_sz
, logon_server_sz
;
1590 FIXME("Level 1 processing is partially implemented\n");
1592 logon_server_sz
= 1;
1594 /* get some information first to estimate size of the buffer */
1596 nastatus
= NetWkstaUserGetInfo(NULL
, 0, (PBYTE
*) &ui0
);
1597 if (nastatus
!= NERR_Success
)
1599 username_sz
= lstrlenW(ui0
->wkui0_username
) + 1;
1601 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
1602 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
1603 POLICY_VIEW_LOCAL_INFORMATION
,
1605 if (NtStatus
!= STATUS_SUCCESS
)
1607 TRACE("LsaOpenPolicyFailed with NT status %x\n",
1608 LsaNtStatusToWinError(NtStatus
));
1609 NetApiBufferFree(ui0
);
1610 return ERROR_NOT_ENOUGH_MEMORY
;
1612 LsaQueryInformationPolicy(PolicyHandle
, PolicyAccountDomainInformation
,
1613 (PVOID
*) &DomainInfo
);
1614 logon_domain_sz
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
1615 LsaClose(PolicyHandle
);
1618 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_1
) +
1619 (username_sz
+ logon_domain_sz
+
1620 oth_domains_sz
+ logon_server_sz
) * sizeof(WCHAR
),
1622 if (nastatus
!= NERR_Success
) {
1623 NetApiBufferFree(ui0
);
1626 ui
= (WKSTA_USER_INFO_1
*) *bufptr
;
1627 ui
->wkui1_username
= (LMSTR
) (*bufptr
+ sizeof(WKSTA_USER_INFO_1
));
1628 ui
->wkui1_logon_domain
= (LMSTR
) (
1629 ((PBYTE
) ui
->wkui1_username
) + username_sz
* sizeof(WCHAR
));
1630 ui
->wkui1_oth_domains
= (LMSTR
) (
1631 ((PBYTE
) ui
->wkui1_logon_domain
) +
1632 logon_domain_sz
* sizeof(WCHAR
));
1633 ui
->wkui1_logon_server
= (LMSTR
) (
1634 ((PBYTE
) ui
->wkui1_oth_domains
) +
1635 oth_domains_sz
* sizeof(WCHAR
));
1638 lstrcpyW(ui
->wkui1_username
, ui0
->wkui0_username
);
1639 NetApiBufferFree(ui0
);
1641 lstrcpynW(ui
->wkui1_logon_domain
, DomainInfo
->DomainName
.Buffer
,
1643 LsaFreeMemory(DomainInfo
);
1645 /* FIXME. Not implemented. Populated with empty strings */
1646 ui
->wkui1_oth_domains
[0] = 0;
1647 ui
->wkui1_logon_server
[0] = 0;
1652 PWKSTA_USER_INFO_1101 ui
;
1655 FIXME("Stub. Level 1101 processing is not implemented\n");
1656 /* FIXME see also wkui1_oth_domains for level 1 */
1659 nastatus
= NetApiBufferAllocate(sizeof(WKSTA_USER_INFO_1101
) + dwSize
* sizeof(WCHAR
),
1661 if (nastatus
!= NERR_Success
)
1663 ui
= (PWKSTA_USER_INFO_1101
) *bufptr
;
1664 ui
->wkui1101_oth_domains
= (LMSTR
)(ui
+ 1);
1667 ui
->wkui1101_oth_domains
[0] = 0;
1671 TRACE("Invalid level %d is specified\n", level
);
1672 return ERROR_INVALID_LEVEL
;
1674 return NERR_Success
;
1677 /************************************************************
1678 * NetWkstaUserEnum (NETAPI32.@)
1680 NET_API_STATUS WINAPI
1681 NetWkstaUserEnum(LMSTR servername
, DWORD level
, LPBYTE
* bufptr
,
1682 DWORD prefmaxlen
, LPDWORD entriesread
,
1683 LPDWORD totalentries
, LPDWORD resumehandle
)
1685 FIXME("(%s, %d, %p, %d, %p, %p, %p): stub!\n", debugstr_w(servername
),
1686 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resumehandle
);
1687 return ERROR_INVALID_PARAMETER
;
1690 /************************************************************
1691 * NetpGetComputerName (NETAPI32.@)
1693 NET_API_STATUS WINAPI
NetpGetComputerName(LPWSTR
*Buffer
)
1695 DWORD dwSize
= MAX_COMPUTERNAME_LENGTH
+ 1;
1697 TRACE("(%p)\n", Buffer
);
1698 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) Buffer
);
1699 if (GetComputerNameW(*Buffer
, &dwSize
))
1701 return NetApiBufferReallocate(
1702 *Buffer
, (dwSize
+ 1) * sizeof(WCHAR
),
1707 NetApiBufferFree(*Buffer
);
1708 return ERROR_NOT_ENOUGH_MEMORY
;
1712 NET_API_STATUS WINAPI
I_NetNameCompare(LPVOID p1
, LPWSTR wkgrp
, LPWSTR comp
,
1713 LPVOID p4
, LPVOID p5
)
1715 FIXME("(%p %s %s %p %p): stub\n", p1
, debugstr_w(wkgrp
), debugstr_w(comp
),
1717 return ERROR_INVALID_PARAMETER
;
1720 NET_API_STATUS WINAPI
I_NetNameValidate(LPVOID p1
, LPWSTR wkgrp
, LPVOID p3
,
1723 FIXME("(%p %s %p %p): stub\n", p1
, debugstr_w(wkgrp
), p3
, p4
);
1724 return ERROR_INVALID_PARAMETER
;
1727 NET_API_STATUS WINAPI
NetWkstaGetInfo( LMSTR servername
, DWORD level
,
1731 BOOL local
= NETAPI_IsLocalComputer( servername
);
1733 TRACE("%s %d %p\n", debugstr_w( servername
), level
, bufptr
);
1737 if (libnetapi_init()) return wksta_getinfo( servername
, level
, bufptr
);
1738 FIXME( "remote computers not supported\n" );
1739 return ERROR_INVALID_LEVEL
;
1741 if (!bufptr
) return ERROR_INVALID_PARAMETER
;
1749 static const WCHAR lanroot
[] = {'c',':','\\','l','a','n','m','a','n',0}; /* FIXME */
1750 DWORD computerNameLen
, domainNameLen
, size
;
1751 WCHAR computerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1752 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
1753 LSA_HANDLE PolicyHandle
;
1756 computerNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
1757 GetComputerNameW(computerName
, &computerNameLen
);
1758 computerNameLen
++; /* include NULL terminator */
1760 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
1761 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
1762 POLICY_VIEW_LOCAL_INFORMATION
, &PolicyHandle
);
1763 if (NtStatus
!= STATUS_SUCCESS
)
1764 ret
= LsaNtStatusToWinError(NtStatus
);
1767 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
1769 LsaQueryInformationPolicy(PolicyHandle
,
1770 PolicyAccountDomainInformation
, (PVOID
*)&DomainInfo
);
1771 domainNameLen
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
1772 size
= sizeof(WKSTA_INFO_102
) + computerNameLen
* sizeof(WCHAR
)
1773 + domainNameLen
* sizeof(WCHAR
) + sizeof(lanroot
);
1774 ret
= NetApiBufferAllocate(size
, (LPVOID
*)bufptr
);
1775 if (ret
== NERR_Success
)
1777 /* INFO_100 and INFO_101 structures are subsets of INFO_102 */
1778 PWKSTA_INFO_102 info
= (PWKSTA_INFO_102
)*bufptr
;
1779 OSVERSIONINFOW verInfo
;
1781 info
->wki102_platform_id
= PLATFORM_ID_NT
;
1782 info
->wki102_computername
= (LMSTR
)(*bufptr
+
1783 sizeof(WKSTA_INFO_102
));
1784 memcpy(info
->wki102_computername
, computerName
,
1785 computerNameLen
* sizeof(WCHAR
));
1786 info
->wki102_langroup
= info
->wki102_computername
+ computerNameLen
;
1787 memcpy(info
->wki102_langroup
, DomainInfo
->DomainName
.Buffer
,
1788 domainNameLen
* sizeof(WCHAR
));
1789 info
->wki102_lanroot
= info
->wki102_langroup
+ domainNameLen
;
1790 memcpy(info
->wki102_lanroot
, lanroot
, sizeof(lanroot
));
1791 memset(&verInfo
, 0, sizeof(verInfo
));
1792 verInfo
.dwOSVersionInfoSize
= sizeof(verInfo
);
1793 GetVersionExW(&verInfo
);
1794 info
->wki102_ver_major
= verInfo
.dwMajorVersion
;
1795 info
->wki102_ver_minor
= verInfo
.dwMinorVersion
;
1796 info
->wki102_logged_on_users
= 1;
1798 LsaFreeMemory(DomainInfo
);
1799 LsaClose(PolicyHandle
);
1805 FIXME("level %d unimplemented\n", level
);
1806 ret
= ERROR_INVALID_LEVEL
;
1811 /************************************************************
1812 * NetGetJoinInformation (NETAPI32.@)
1814 NET_API_STATUS NET_API_FUNCTION
NetGetJoinInformation(
1817 PNETSETUP_JOIN_STATUS type
)
1819 static const WCHAR workgroupW
[] = {'W','o','r','k','g','r','o','u','p',0};
1821 FIXME("Semi-stub %s %p %p\n", wine_dbgstr_w(Server
), Name
, type
);
1824 return ERROR_INVALID_PARAMETER
;
1826 NetApiBufferAllocate(sizeof(workgroupW
), (LPVOID
*)Name
);
1827 lstrcpyW(*Name
, workgroupW
);
1828 *type
= NetSetupWorkgroupName
;
1830 return NERR_Success
;
1833 /************************************************************
1834 * NetUserGetGroups (NETAPI32.@)
1836 NET_API_STATUS NET_API_FUNCTION
NetUserGetGroups(
1842 LPDWORD entriesread
,
1843 LPDWORD totalentries
)
1845 FIXME("%s %s %d %p %d %p %p stub\n", debugstr_w(servername
),
1846 debugstr_w(username
), level
, bufptr
, prefixmaxlen
, entriesread
,
1853 return ERROR_INVALID_LEVEL
;
1859 WCHAR user_name
[LM20_UNLEN
+1];
1860 WCHAR user_password
[PWLEN
+ 1];
1861 DWORD sec_since_passwd_change
;
1864 LPWSTR user_comment
;
1866 LPWSTR user_logon_script_path
;
1869 static struct list user_list
= LIST_INIT( user_list
);
1871 /************************************************************
1872 * NETAPI_ValidateServername
1874 * Validates server name
1876 static NET_API_STATUS
NETAPI_ValidateServername(LPCWSTR ServerName
)
1880 if (ServerName
[0] == 0)
1881 return ERROR_BAD_NETPATH
;
1883 ((ServerName
[0] == '\\') &&
1884 (ServerName
[1] != '\\'))
1886 ((ServerName
[0] == '\\') &&
1887 (ServerName
[1] == '\\') &&
1888 (ServerName
[2] == 0))
1890 return ERROR_INVALID_NAME
;
1892 return NERR_Success
;
1895 /************************************************************
1898 * Looks for a user in the user database.
1899 * Returns a pointer to the entry in the user list when the user
1900 * is found, NULL otherwise.
1902 static struct sam_user
* NETAPI_FindUser(LPCWSTR UserName
)
1904 struct sam_user
*user
;
1906 LIST_FOR_EACH_ENTRY(user
, &user_list
, struct sam_user
, entry
)
1908 if(lstrcmpW(user
->user_name
, UserName
) == 0)
1914 static BOOL
NETAPI_IsCurrentUser(LPCWSTR username
)
1916 LPWSTR curr_user
= NULL
;
1920 dwSize
= LM20_UNLEN
+1;
1921 curr_user
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
1924 ERR("Failed to allocate memory for user name.\n");
1927 if(!GetUserNameW(curr_user
, &dwSize
))
1929 ERR("Failed to get current user's user name.\n");
1932 if (!lstrcmpW(curr_user
, username
))
1938 HeapFree(GetProcessHeap(), 0, curr_user
);
1942 /************************************************************
1943 * NetUserAdd (NETAPI32.@)
1945 NET_API_STATUS WINAPI
NetUserAdd(LPCWSTR servername
,
1946 DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
1948 NET_API_STATUS status
;
1949 struct sam_user
* su
= NULL
;
1951 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
1953 if((status
= NETAPI_ValidateServername(servername
)) != NERR_Success
)
1958 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
1961 FIXME("Level 3 and 4 not implemented.\n");
1964 FIXME("Level 2 not implemented.\n");
1968 PUSER_INFO_1 ui
= (PUSER_INFO_1
) bufptr
;
1969 su
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user
));
1972 status
= NERR_InternalError
;
1976 if(lstrlenW(ui
->usri1_name
) > LM20_UNLEN
)
1978 status
= NERR_BadUsername
;
1982 /*FIXME: do other checks for a valid username */
1983 lstrcpyW(su
->user_name
, ui
->usri1_name
);
1985 if(lstrlenW(ui
->usri1_password
) > PWLEN
)
1987 /* Always return PasswordTooShort on invalid passwords. */
1988 status
= NERR_PasswordTooShort
;
1991 lstrcpyW(su
->user_password
, ui
->usri1_password
);
1993 su
->sec_since_passwd_change
= ui
->usri1_password_age
;
1994 su
->user_priv
= ui
->usri1_priv
;
1995 su
->user_flags
= ui
->usri1_flags
;
1997 /*FIXME: set the other LPWSTRs to NULL for now */
1998 su
->home_dir
= NULL
;
1999 su
->user_comment
= NULL
;
2000 su
->user_logon_script_path
= NULL
;
2002 list_add_head(&user_list
, &su
->entry
);
2003 return NERR_Success
;
2006 TRACE("Invalid level %d specified.\n", level
);
2007 status
= ERROR_INVALID_LEVEL
;
2011 HeapFree(GetProcessHeap(), 0, su
);
2016 /************************************************************
2017 * NetUserDel (NETAPI32.@)
2019 NET_API_STATUS WINAPI
NetUserDel(LPCWSTR servername
, LPCWSTR username
)
2021 NET_API_STATUS status
;
2022 struct sam_user
*user
;
2024 TRACE("(%s, %s)\n", debugstr_w(servername
), debugstr_w(username
));
2026 if((status
= NETAPI_ValidateServername(servername
))!= NERR_Success
)
2029 if ((user
= NETAPI_FindUser(username
)) == NULL
)
2030 return NERR_UserNotFound
;
2032 list_remove(&user
->entry
);
2034 HeapFree(GetProcessHeap(), 0, user
->home_dir
);
2035 HeapFree(GetProcessHeap(), 0, user
->user_comment
);
2036 HeapFree(GetProcessHeap(), 0, user
->user_logon_script_path
);
2037 HeapFree(GetProcessHeap(), 0, user
);
2039 return NERR_Success
;
2042 /************************************************************
2043 * NetUserGetInfo (NETAPI32.@)
2045 NET_API_STATUS WINAPI
2046 NetUserGetInfo(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
2049 NET_API_STATUS status
;
2050 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername
), debugstr_w(username
),
2052 status
= NETAPI_ValidateServername(servername
);
2053 if (status
!= NERR_Success
)
2056 if(!NETAPI_IsLocalComputer(servername
))
2058 FIXME("Only implemented for local computer, but remote server"
2059 "%s was requested.\n", debugstr_w(servername
));
2060 return NERR_InvalidComputer
;
2063 if(!NETAPI_FindUser(username
) && !NETAPI_IsCurrentUser(username
))
2065 TRACE("User %s is unknown.\n", debugstr_w(username
));
2066 return NERR_UserNotFound
;
2076 name_sz
= lstrlenW(username
) + 1;
2079 NetApiBufferAllocate(sizeof(USER_INFO_0
) + name_sz
* sizeof(WCHAR
),
2082 ui
= (PUSER_INFO_0
) *bufptr
;
2083 ui
->usri0_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_0
));
2086 lstrcpyW(ui
->usri0_name
, username
);
2094 /* sizes of the field buffers in WCHARS */
2095 int name_sz
, comment_sz
, usr_comment_sz
, full_name_sz
;
2102 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
2103 if (status
!= NERR_Success
)
2105 NetApiBufferFree(ui0
);
2108 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
2111 NetApiBufferAllocate(sizeof(USER_INFO_10
) +
2112 (name_sz
+ comment_sz
+ usr_comment_sz
+
2113 full_name_sz
) * sizeof(WCHAR
),
2115 ui
= (PUSER_INFO_10
) *bufptr
;
2116 ui
->usri10_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_10
));
2117 ui
->usri10_comment
= (LPWSTR
) (
2118 ((PBYTE
) ui
->usri10_name
) + name_sz
* sizeof(WCHAR
));
2119 ui
->usri10_usr_comment
= (LPWSTR
) (
2120 ((PBYTE
) ui
->usri10_comment
) + comment_sz
* sizeof(WCHAR
));
2121 ui
->usri10_full_name
= (LPWSTR
) (
2122 ((PBYTE
) ui
->usri10_usr_comment
) + usr_comment_sz
* sizeof(WCHAR
));
2125 lstrcpyW(ui
->usri10_name
, ui0
->usri0_name
);
2126 NetApiBufferFree(ui0
);
2127 ui
->usri10_comment
[0] = 0;
2128 ui
->usri10_usr_comment
[0] = 0;
2129 ui
->usri10_full_name
[0] = 0;
2135 static const WCHAR homedirW
[] = {'H','O','M','E',0};
2138 /* sizes of the field buffers in WCHARS */
2139 int name_sz
, password_sz
, home_dir_sz
, comment_sz
, script_path_sz
;
2141 password_sz
= 1; /* not filled out for security reasons for NetUserGetInfo*/
2146 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
2147 if (status
!= NERR_Success
)
2149 NetApiBufferFree(ui0
);
2152 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
2153 home_dir_sz
= GetEnvironmentVariableW(homedirW
, NULL
,0);
2155 NetApiBufferAllocate(sizeof(USER_INFO_1
) +
2156 (name_sz
+ password_sz
+ home_dir_sz
+
2157 comment_sz
+ script_path_sz
) * sizeof(WCHAR
),
2160 ui
= (PUSER_INFO_1
) *bufptr
;
2161 ui
->usri1_name
= (LPWSTR
) (ui
+ 1);
2162 ui
->usri1_password
= ui
->usri1_name
+ name_sz
;
2163 ui
->usri1_home_dir
= ui
->usri1_password
+ password_sz
;
2164 ui
->usri1_comment
= ui
->usri1_home_dir
+ home_dir_sz
;
2165 ui
->usri1_script_path
= ui
->usri1_comment
+ comment_sz
;
2167 lstrcpyW(ui
->usri1_name
, ui0
->usri0_name
);
2168 NetApiBufferFree(ui0
);
2169 ui
->usri1_password
[0] = 0;
2170 ui
->usri1_password_age
= 0;
2172 GetEnvironmentVariableW(homedirW
, ui
->usri1_home_dir
,home_dir_sz
);
2173 ui
->usri1_comment
[0] = 0;
2174 ui
->usri1_flags
= 0;
2175 ui
->usri1_script_path
[0] = 0;
2205 FIXME("Level %d is not implemented\n", level
);
2206 return NERR_InternalError
;
2209 TRACE("Invalid level %d is specified\n", level
);
2210 return ERROR_INVALID_LEVEL
;
2212 return NERR_Success
;
2215 /************************************************************
2216 * NetUserGetLocalGroups (NETAPI32.@)
2218 NET_API_STATUS WINAPI
2219 NetUserGetLocalGroups(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
2220 DWORD flags
, LPBYTE
* bufptr
, DWORD prefmaxlen
,
2221 LPDWORD entriesread
, LPDWORD totalentries
)
2223 NET_API_STATUS status
;
2224 const WCHAR admins
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0};
2226 LOCALGROUP_USERS_INFO_0
* info
;
2229 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
2230 debugstr_w(servername
), debugstr_w(username
), level
, flags
, bufptr
,
2231 prefmaxlen
, entriesread
, totalentries
);
2233 status
= NETAPI_ValidateServername(servername
);
2234 if (status
!= NERR_Success
)
2238 NetApiBufferAllocate(size
* sizeof(WCHAR
), (LPVOID
*)¤tuser
);
2239 if (!GetUserNameW(currentuser
, &size
)) {
2240 NetApiBufferFree(currentuser
);
2241 return ERROR_NOT_ENOUGH_MEMORY
;
2244 if (lstrcmpiW(username
, currentuser
) && NETAPI_FindUser(username
))
2246 NetApiBufferFree(currentuser
);
2247 return NERR_UserNotFound
;
2250 NetApiBufferFree(currentuser
);
2252 size
= sizeof(*info
) + sizeof(admins
);
2254 if(prefmaxlen
< size
)
2255 status
= ERROR_MORE_DATA
;
2257 status
= NetApiBufferAllocate(size
, (LPVOID
*)&info
);
2259 if(status
!= NERR_Success
)
2266 info
->lgrui0_name
= (LPWSTR
)((LPBYTE
)info
+ sizeof(*info
));
2267 lstrcpyW(info
->lgrui0_name
, admins
);
2269 *bufptr
= (LPBYTE
)info
;
2272 return NERR_Success
;
2275 /************************************************************
2276 * NetUserEnum (NETAPI32.@)
2278 NET_API_STATUS WINAPI
2279 NetUserEnum(LPCWSTR servername
, DWORD level
, DWORD filter
, LPBYTE
* bufptr
,
2280 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
,
2281 LPDWORD resume_handle
)
2283 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername
), level
,
2284 filter
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
2286 return ERROR_ACCESS_DENIED
;
2289 /************************************************************
2290 * ACCESS_QueryAdminDisplayInformation
2292 * Creates a buffer with information for the Admin User
2294 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
2296 static const WCHAR sAdminUserName
[] = {
2297 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
2299 /* sizes of the field buffers in WCHARS */
2300 int name_sz
, comment_sz
, full_name_sz
;
2301 PNET_DISPLAY_USER usr
;
2304 name_sz
= lstrlenW(sAdminUserName
) + 1;
2308 *pdwSize
= sizeof(NET_DISPLAY_USER
);
2309 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2310 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
2313 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
2314 usr
->usri1_comment
= (LPWSTR
) (
2315 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
2316 usr
->usri1_full_name
= (LPWSTR
) (
2317 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
2320 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
2321 usr
->usri1_comment
[0] = 0;
2322 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
2323 usr
->usri1_full_name
[0] = 0;
2324 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
2325 usr
->usri1_next_index
= 0;
2328 /************************************************************
2329 * ACCESS_QueryGuestDisplayInformation
2331 * Creates a buffer with information for the Guest User
2333 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
2335 static const WCHAR sGuestUserName
[] = {
2336 'G','u','e','s','t',0 };
2338 /* sizes of the field buffers in WCHARS */
2339 int name_sz
, comment_sz
, full_name_sz
;
2340 PNET_DISPLAY_USER usr
;
2343 name_sz
= lstrlenW(sGuestUserName
) + 1;
2347 *pdwSize
= sizeof(NET_DISPLAY_USER
);
2348 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2349 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
2352 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
2353 usr
->usri1_comment
= (LPWSTR
) (
2354 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
2355 usr
->usri1_full_name
= (LPWSTR
) (
2356 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
2359 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
2360 usr
->usri1_comment
[0] = 0;
2361 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
2362 UF_DONT_EXPIRE_PASSWD
;
2363 usr
->usri1_full_name
[0] = 0;
2364 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
2365 usr
->usri1_next_index
= 0;
2368 /************************************************************
2369 * Copies NET_DISPLAY_USER record.
2371 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
2372 PNET_DISPLAY_USER src
)
2374 LPWSTR str
= *dest_buf
;
2376 src
->usri1_name
= str
;
2377 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
2379 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2381 src
->usri1_comment
= str
;
2382 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
2384 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2386 src
->usri1_flags
= dest
->usri1_flags
;
2388 src
->usri1_full_name
= str
;
2389 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
2391 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2393 src
->usri1_user_id
= dest
->usri1_user_id
;
2394 src
->usri1_next_index
= dest
->usri1_next_index
;
2398 /************************************************************
2399 * NetQueryDisplayInformation (NETAPI32.@)
2401 * The buffer structure:
2402 * - array of fixed size record of the level type
2403 * - strings, referenced by the record of the level type
2405 NET_API_STATUS WINAPI
2406 NetQueryDisplayInformation(
2407 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
2408 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
2409 PVOID
*SortedBuffer
)
2411 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
2412 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
2413 ReturnedEntryCount
, SortedBuffer
);
2415 if(!NETAPI_IsLocalComputer(ServerName
))
2417 FIXME("Only implemented on local computer, but requested for "
2418 "remote server %s\n", debugstr_w(ServerName
));
2419 return ERROR_ACCESS_DENIED
;
2426 /* current record */
2427 PNET_DISPLAY_USER inf
;
2428 /* current available strings buffer */
2430 PNET_DISPLAY_USER admin
, guest
;
2431 DWORD admin_size
, guest_size
;
2435 /* sizes of the field buffers in WCHARS */
2436 int name_sz
, comment_sz
, full_name_sz
;
2438 /* number of the records, returned in SortedBuffer
2439 3 - for current user, Administrator and Guest users
2443 FIXME("Level %d partially implemented\n", Level
);
2444 *ReturnedEntryCount
= records
;
2450 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
2451 if (!GetUserNameW(name
, &dwSize
))
2453 NetApiBufferFree(name
);
2454 return ERROR_ACCESS_DENIED
;
2457 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
2458 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
2461 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
2462 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
2464 NetApiBufferAllocate(dwSize
+
2465 admin_size
- sizeof(NET_DISPLAY_USER
) +
2466 guest_size
- sizeof(NET_DISPLAY_USER
),
2468 inf
= *SortedBuffer
;
2469 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
2470 inf
->usri1_name
= str
;
2472 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
2473 inf
->usri1_comment
= str
;
2475 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
2476 inf
->usri1_full_name
= str
;
2478 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
2481 lstrcpyW(inf
->usri1_name
, name
);
2482 NetApiBufferFree(name
);
2483 inf
->usri1_comment
[0] = 0;
2485 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
2486 inf
->usri1_full_name
[0] = 0;
2487 inf
->usri1_user_id
= 0;
2488 inf
->usri1_next_index
= 0;
2491 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
2492 NetApiBufferFree(admin
);
2495 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
2496 NetApiBufferFree(guest
);
2503 FIXME("Level %d is not implemented\n", Level
);
2508 TRACE("Invalid level %d is specified\n", Level
);
2509 return ERROR_INVALID_LEVEL
;
2511 return NERR_Success
;
2514 /************************************************************
2515 * NetGetDCName (NETAPI32.@)
2517 * Return the name of the primary domain controller (PDC)
2520 NET_API_STATUS WINAPI
2521 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
2523 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
2524 debugstr_w(domainname
), bufptr
);
2525 return NERR_DCNotFound
; /* say we can't find a domain controller */
2528 /************************************************************
2529 * NetGetAnyDCName (NETAPI32.@)
2531 * Return the name of any domain controller (DC) for a
2532 * domain that is directly trusted by the specified server
2535 NET_API_STATUS WINAPI
NetGetAnyDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
2537 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
2538 debugstr_w(domainname
), bufptr
);
2539 return ERROR_NO_SUCH_DOMAIN
;
2542 /************************************************************
2543 * NetGroupEnum (NETAPI32.@)
2546 NET_API_STATUS WINAPI
2547 NetGroupEnum(LPCWSTR servername
, DWORD level
, LPBYTE
*bufptr
, DWORD prefmaxlen
,
2548 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
2550 FIXME("(%s, %d, %p, %d, %p, %p, %p) stub!\n", debugstr_w(servername
),
2551 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
2552 return ERROR_ACCESS_DENIED
;
2555 /************************************************************
2556 * NetGroupGetInfo (NETAPI32.@)
2559 NET_API_STATUS WINAPI
NetGroupGetInfo(LPCWSTR servername
, LPCWSTR groupname
, DWORD level
, LPBYTE
*bufptr
)
2561 FIXME("(%s, %s, %d, %p) stub!\n", debugstr_w(servername
), debugstr_w(groupname
), level
, bufptr
);
2562 return ERROR_ACCESS_DENIED
;
2565 /******************************************************************************
2566 * NetUserModalsGet (NETAPI32.@)
2568 * Retrieves global information for all users and global groups in the security
2572 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
2573 * on which the function is to execute.
2574 * level [I] Information level of the data.
2575 * 0 Return global passwords parameters. bufptr points to a
2576 * USER_MODALS_INFO_0 struct.
2577 * 1 Return logon server and domain controller information. bufptr
2578 * points to a USER_MODALS_INFO_1 struct.
2579 * 2 Return domain name and identifier. bufptr points to a
2580 * USER_MODALS_INFO_2 struct.
2581 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
2583 * pbuffer [I] Buffer that receives the data.
2586 * Success: NERR_Success.
2588 * ERROR_ACCESS_DENIED - the user does not have access to the info.
2589 * NERR_InvalidComputer - computer name is invalid.
2591 NET_API_STATUS WINAPI
NetUserModalsGet(
2592 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
2594 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
2599 /* return global passwords parameters */
2600 FIXME("level 0 not implemented!\n");
2602 return NERR_InternalError
;
2604 /* return logon server and domain controller info */
2605 FIXME("level 1 not implemented!\n");
2607 return NERR_InternalError
;
2610 /* return domain name and identifier */
2611 PUSER_MODALS_INFO_2 umi
;
2612 LSA_HANDLE policyHandle
;
2613 LSA_OBJECT_ATTRIBUTES objectAttributes
;
2614 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
2616 PSID domainIdentifier
= NULL
;
2619 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
2620 objectAttributes
.Length
= sizeof(objectAttributes
);
2622 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
2623 POLICY_VIEW_LOCAL_INFORMATION
,
2625 if (ntStatus
!= STATUS_SUCCESS
)
2627 WARN("LsaOpenPolicy failed with NT status %x\n",
2628 LsaNtStatusToWinError(ntStatus
));
2632 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
2633 PolicyAccountDomainInformation
,
2634 (PVOID
*)&domainInfo
);
2635 if (ntStatus
!= STATUS_SUCCESS
)
2637 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
2638 LsaNtStatusToWinError(ntStatus
));
2639 LsaClose(policyHandle
);
2643 domainIdentifier
= domainInfo
->DomainSid
;
2644 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
2645 LsaClose(policyHandle
);
2647 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
2648 GetLengthSid(domainIdentifier
) +
2649 domainNameLen
* sizeof(WCHAR
),
2652 if (ntStatus
!= NERR_Success
)
2654 WARN("NetApiBufferAllocate() failed\n");
2655 LsaFreeMemory(domainInfo
);
2659 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
2660 umi
->usrmod2_domain_id
= *pbuffer
+ sizeof(USER_MODALS_INFO_2
);
2661 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
2662 sizeof(USER_MODALS_INFO_2
) + GetLengthSid(domainIdentifier
));
2664 lstrcpynW(umi
->usrmod2_domain_name
,
2665 domainInfo
->DomainName
.Buffer
,
2667 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
2670 LsaFreeMemory(domainInfo
);
2675 /* return lockout information */
2676 FIXME("level 3 not implemented!\n");
2678 return NERR_InternalError
;
2680 TRACE("Invalid level %d is specified\n", level
);
2682 return ERROR_INVALID_LEVEL
;
2685 return NERR_Success
;
2688 static NET_API_STATUS
change_password_smb( LPCWSTR domainname
, LPCWSTR username
,
2689 LPCWSTR oldpassword
, LPCWSTR newpassword
)
2692 NET_API_STATUS ret
= NERR_Success
;
2693 static char option_silent
[] = "-s";
2694 static char option_user
[] = "-U";
2695 static char option_remote
[] = "-r";
2696 static char smbpasswd
[] = "smbpasswd";
2700 char *server
= NULL
, *user
, *argv
[7], *old
= NULL
, *new = NULL
;
2702 if (domainname
&& !(server
= strdup_unixcp( domainname
))) return ERROR_OUTOFMEMORY
;
2703 if (!(user
= strdup_unixcp( username
)))
2705 ret
= ERROR_OUTOFMEMORY
;
2708 if (!(old
= strdup_unixcp( oldpassword
)))
2710 ret
= ERROR_OUTOFMEMORY
;
2713 if (!(new = strdup_unixcp( newpassword
)))
2715 ret
= ERROR_OUTOFMEMORY
;
2718 argv
[0] = smbpasswd
;
2719 argv
[1] = option_silent
;
2720 argv
[2] = option_user
;
2724 argv
[4] = option_remote
;
2728 else argv
[4] = NULL
;
2730 if (pipe( pipe_out
) == -1)
2732 ret
= NERR_InternalError
;
2735 fcntl( pipe_out
[0], F_SETFD
, FD_CLOEXEC
);
2736 fcntl( pipe_out
[1], F_SETFD
, FD_CLOEXEC
);
2738 switch ((pid
= fork()))
2741 close( pipe_out
[0] );
2742 close( pipe_out
[1] );
2743 ret
= NERR_InternalError
;
2746 dup2( pipe_out
[0], 0 );
2747 close( pipe_out
[0] );
2748 close( pipe_out
[1] );
2749 execvp( "smbpasswd", argv
);
2750 ERR( "can't execute smbpasswd, is it installed?\n" );
2753 close( pipe_out
[0] );
2756 write( pipe_out
[1], old
, strlen( old
) );
2757 write( pipe_out
[1], "\n", 1 );
2758 write( pipe_out
[1], new, strlen( new ) );
2759 write( pipe_out
[1], "\n", 1 );
2760 write( pipe_out
[1], new, strlen( new ) );
2761 write( pipe_out
[1], "\n", 1 );
2762 close( pipe_out
[1] );
2765 wret
= waitpid(pid
, &status
, 0);
2766 } while (wret
< 0 && errno
== EINTR
);
2768 if (ret
== NERR_Success
&& (wret
< 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)))
2769 ret
= NERR_InternalError
;
2772 HeapFree( GetProcessHeap(), 0, server
);
2773 HeapFree( GetProcessHeap(), 0, user
);
2774 HeapFree( GetProcessHeap(), 0, old
);
2775 HeapFree( GetProcessHeap(), 0, new );
2778 ERR( "no fork support on this platform\n" );
2779 return NERR_InternalError
;
2783 /******************************************************************************
2784 * NetUserChangePassword (NETAPI32.@)
2786 * domainname [I] Optional. Domain on which the user resides or the logon
2787 * domain of the current user if NULL.
2788 * username [I] Optional. Username to change the password for or the name
2789 * of the current user if NULL.
2790 * oldpassword [I] The user's current password.
2791 * newpassword [I] The password that the user will be changed to using.
2794 * Success: NERR_Success.
2795 * Failure: NERR_* failure code or win error code.
2798 NET_API_STATUS WINAPI
NetUserChangePassword(LPCWSTR domainname
, LPCWSTR username
,
2799 LPCWSTR oldpassword
, LPCWSTR newpassword
)
2801 struct sam_user
*user
;
2803 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname
), debugstr_w(username
));
2805 if (!change_password_smb( domainname
, username
, oldpassword
, newpassword
))
2806 return NERR_Success
;
2809 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname
));
2811 if((user
= NETAPI_FindUser(username
)) == NULL
)
2812 return NERR_UserNotFound
;
2814 if(lstrcmpW(user
->user_password
, oldpassword
) != 0)
2815 return ERROR_INVALID_PASSWORD
;
2817 if(lstrlenW(newpassword
) > PWLEN
)
2818 return ERROR_PASSWORD_RESTRICTION
;
2820 lstrcpyW(user
->user_password
, newpassword
);
2822 return NERR_Success
;
2825 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
2827 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
2828 return NERR_Success
;
2831 NET_API_STATUS WINAPI
NetUseDel(LMSTR servername
, LMSTR usename
, DWORD forcecond
)
2833 FIXME("%s %s %d stub\n", debugstr_w(servername
), debugstr_w(usename
), forcecond
);
2834 return NERR_Success
;
2837 /************************************************************
2838 * I_BrowserSetNetlogonState (NETAPI32.@)
2840 NET_API_STATUS WINAPI
I_BrowserSetNetlogonState(
2841 LPWSTR ServerName
, LPWSTR DomainName
, LPWSTR EmulatedServerName
,
2844 return ERROR_NOT_SUPPORTED
;
2847 /************************************************************
2848 * I_BrowserQueryEmulatedDomains (NETAPI32.@)
2850 NET_API_STATUS WINAPI
I_BrowserQueryEmulatedDomains(
2851 LPWSTR ServerName
, PBROWSER_EMULATED_DOMAIN
*EmulatedDomains
,
2852 LPDWORD EntriesRead
)
2854 return ERROR_NOT_SUPPORTED
;
2857 DWORD WINAPI
DsGetDcNameW(LPCWSTR ComputerName
, LPCWSTR AvoidDCName
,
2858 GUID
* DomainGuid
, LPCWSTR SiteName
, ULONG Flags
,
2859 PDOMAIN_CONTROLLER_INFOW
*DomainControllerInfo
)
2861 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_w(ComputerName
),
2862 debugstr_w(AvoidDCName
), debugstr_guid(DomainGuid
),
2863 debugstr_w(SiteName
), Flags
, DomainControllerInfo
);
2864 return ERROR_CALL_NOT_IMPLEMENTED
;
2867 DWORD WINAPI
DsGetDcNameA(LPCSTR ComputerName
, LPCSTR AvoidDCName
,
2868 GUID
* DomainGuid
, LPCSTR SiteName
, ULONG Flags
,
2869 PDOMAIN_CONTROLLER_INFOA
*DomainControllerInfo
)
2871 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_a(ComputerName
),
2872 debugstr_a(AvoidDCName
), debugstr_guid(DomainGuid
),
2873 debugstr_a(SiteName
), Flags
, DomainControllerInfo
);
2874 return ERROR_CALL_NOT_IMPLEMENTED
;
2877 DWORD WINAPI
DsGetSiteNameW(LPCWSTR ComputerName
, LPWSTR
*SiteName
)
2879 FIXME("(%s, %p): stub\n", debugstr_w(ComputerName
), SiteName
);
2880 return ERROR_CALL_NOT_IMPLEMENTED
;
2883 DWORD WINAPI
DsGetSiteNameA(LPCSTR ComputerName
, LPSTR
*SiteName
)
2885 FIXME("(%s, %p): stub\n", debugstr_a(ComputerName
), SiteName
);
2886 return ERROR_CALL_NOT_IMPLEMENTED
;
2889 /************************************************************
2890 * DsRoleFreeMemory (NETAPI32.@)
2893 * Buffer [I] Pointer to the to-be-freed buffer.
2898 VOID WINAPI
DsRoleFreeMemory(PVOID Buffer
)
2900 TRACE("(%p)\n", Buffer
);
2901 HeapFree(GetProcessHeap(), 0, Buffer
);
2904 /************************************************************
2905 * DsRoleGetPrimaryDomainInformation (NETAPI32.@)
2908 * lpServer [I] Pointer to UNICODE string with ComputerName
2909 * InfoLevel [I] Type of data to retrieve
2910 * Buffer [O] Pointer to to the requested data
2915 * When lpServer is NULL, use the local computer
2917 DWORD WINAPI
DsRoleGetPrimaryDomainInformation(
2918 LPCWSTR lpServer
, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel
,
2923 FIXME("(%p, %d, %p) stub\n", lpServer
, InfoLevel
, Buffer
);
2925 /* Check some input parameters */
2927 if (!Buffer
) return ERROR_INVALID_PARAMETER
;
2928 if ((InfoLevel
< DsRolePrimaryDomainInfoBasic
) || (InfoLevel
> DsRoleOperationState
)) return ERROR_INVALID_PARAMETER
;
2933 case DsRolePrimaryDomainInfoBasic
:
2935 LSA_OBJECT_ATTRIBUTES ObjectAttributes
;
2936 LSA_HANDLE PolicyHandle
;
2937 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo
;
2939 int logon_domain_sz
;
2941 PDSROLE_PRIMARY_DOMAIN_INFO_BASIC basic
;
2943 ZeroMemory(&ObjectAttributes
, sizeof(ObjectAttributes
));
2944 NtStatus
= LsaOpenPolicy(NULL
, &ObjectAttributes
,
2945 POLICY_VIEW_LOCAL_INFORMATION
, &PolicyHandle
);
2946 if (NtStatus
!= STATUS_SUCCESS
)
2948 TRACE("LsaOpenPolicyFailed with NT status %x\n",
2949 LsaNtStatusToWinError(NtStatus
));
2950 return ERROR_OUTOFMEMORY
;
2952 LsaQueryInformationPolicy(PolicyHandle
,
2953 PolicyAccountDomainInformation
, (PVOID
*)&DomainInfo
);
2954 logon_domain_sz
= lstrlenW(DomainInfo
->DomainName
.Buffer
) + 1;
2955 LsaClose(PolicyHandle
);
2957 size
= sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC
) +
2958 logon_domain_sz
* sizeof(WCHAR
);
2959 basic
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
2962 basic
->MachineRole
= DsRole_RoleStandaloneWorkstation
;
2963 basic
->DomainNameFlat
= (LPWSTR
)((LPBYTE
)basic
+
2964 sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC
));
2965 lstrcpyW(basic
->DomainNameFlat
, DomainInfo
->DomainName
.Buffer
);
2966 ret
= ERROR_SUCCESS
;
2969 ret
= ERROR_OUTOFMEMORY
;
2970 *Buffer
= (PBYTE
)basic
;
2971 LsaFreeMemory(DomainInfo
);
2975 ret
= ERROR_CALL_NOT_IMPLEMENTED
;
2980 /************************************************************
2981 * NetLocalGroupAdd (NETAPI32.@)
2983 NET_API_STATUS WINAPI
NetLocalGroupAdd(
2989 FIXME("(%s %d %p %p) stub!\n", debugstr_w(servername
), level
, buf
,
2991 return NERR_Success
;
2994 /************************************************************
2995 * NetLocalGroupAddMember (NETAPI32.@)
2997 NET_API_STATUS WINAPI
NetLocalGroupAddMember(
3002 FIXME("(%s %s %p) stub!\n", debugstr_w(servername
),
3003 debugstr_w(groupname
), membersid
);
3004 return NERR_Success
;
3007 /************************************************************
3008 * NetLocalGroupAddMembers (NETAPI32.@)
3010 NET_API_STATUS WINAPI
NetLocalGroupAddMembers(
3017 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3018 debugstr_w(groupname
), level
, buf
, totalentries
);
3019 return NERR_Success
;
3022 /************************************************************
3023 * NetLocalGroupDel (NETAPI32.@)
3025 NET_API_STATUS WINAPI
NetLocalGroupDel(
3029 FIXME("(%s %s) stub!\n", debugstr_w(servername
), debugstr_w(groupname
));
3030 return NERR_Success
;
3033 /************************************************************
3034 * NetLocalGroupDelMember (NETAPI32.@)
3036 NET_API_STATUS WINAPI
NetLocalGroupDelMember(
3041 FIXME("(%s %s %p) stub!\n", debugstr_w(servername
),
3042 debugstr_w(groupname
), membersid
);
3043 return NERR_Success
;
3046 /************************************************************
3047 * NetLocalGroupDelMembers (NETAPI32.@)
3049 NET_API_STATUS WINAPI
NetLocalGroupDelMembers(
3056 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3057 debugstr_w(groupname
), level
, buf
, totalentries
);
3058 return NERR_Success
;
3061 /************************************************************
3062 * NetLocalGroupEnum (NETAPI32.@)
3064 NET_API_STATUS WINAPI
NetLocalGroupEnum(
3069 LPDWORD entriesread
,
3070 LPDWORD totalentries
,
3071 PDWORD_PTR resumehandle
)
3073 FIXME("(%s %d %p %d %p %p %p) stub!\n", debugstr_w(servername
),
3074 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resumehandle
);
3077 return NERR_Success
;
3080 /************************************************************
3081 * NetLocalGroupGetInfo (NETAPI32.@)
3083 NET_API_STATUS WINAPI
NetLocalGroupGetInfo(
3089 static const WCHAR commentW
[]={'N','o',' ','c','o','m','m','e','n','t',0};
3090 LOCALGROUP_INFO_1
* info
;
3093 FIXME("(%s %s %d %p) semi-stub!\n", debugstr_w(servername
),
3094 debugstr_w(groupname
), level
, bufptr
);
3096 size
= sizeof(*info
) + sizeof(WCHAR
) * (lstrlenW(groupname
)+1) + sizeof(commentW
);
3097 NetApiBufferAllocate(size
, (LPVOID
*)&info
);
3099 info
->lgrpi1_name
= (LPWSTR
)(info
+ 1);
3100 lstrcpyW(info
->lgrpi1_name
, groupname
);
3102 info
->lgrpi1_comment
= info
->lgrpi1_name
+ lstrlenW(groupname
) + 1;
3103 lstrcpyW(info
->lgrpi1_comment
, commentW
);
3105 *bufptr
= (LPBYTE
)info
;
3107 return NERR_Success
;
3110 /************************************************************
3111 * NetLocalGroupGetMembers (NETAPI32.@)
3113 NET_API_STATUS WINAPI
NetLocalGroupGetMembers(
3115 LPCWSTR localgroupname
,
3119 LPDWORD entriesread
,
3120 LPDWORD totalentries
,
3121 PDWORD_PTR resumehandle
)
3123 FIXME("(%s %s %d %p %d, %p %p %p) stub!\n", debugstr_w(servername
),
3124 debugstr_w(localgroupname
), level
, bufptr
, prefmaxlen
, entriesread
,
3125 totalentries
, resumehandle
);
3129 WCHAR userName
[MAX_COMPUTERNAME_LENGTH
+ 1];
3132 PLOCALGROUP_MEMBERS_INFO_3 ptr
;
3134 /* still a stub, current user is belonging to all groups */
3139 userNameLen
= MAX_COMPUTERNAME_LENGTH
+ 1;
3140 if (!GetUserNameW(userName
,&userNameLen
))
3141 return ERROR_NOT_ENOUGH_MEMORY
;
3143 needlen
= sizeof(LOCALGROUP_MEMBERS_INFO_3
) +
3144 (userNameLen
+2) * sizeof(WCHAR
);
3145 if (prefmaxlen
!= MAX_PREFERRED_LENGTH
)
3146 len
= min(prefmaxlen
,needlen
);
3150 NetApiBufferAllocate(len
, (LPVOID
*) bufptr
);
3152 return ERROR_MORE_DATA
;
3154 ptr
= (PLOCALGROUP_MEMBERS_INFO_3
)*bufptr
;
3155 ptr
->lgrmi3_domainandname
= (LPWSTR
)(*bufptr
+sizeof(LOCALGROUP_MEMBERS_INFO_3
));
3156 lstrcpyW(ptr
->lgrmi3_domainandname
,userName
);
3161 return NERR_Success
;
3164 /************************************************************
3165 * NetLocalGroupSetInfo (NETAPI32.@)
3167 NET_API_STATUS WINAPI
NetLocalGroupSetInfo(
3174 FIXME("(%s %s %d %p %p) stub!\n", debugstr_w(servername
),
3175 debugstr_w(groupname
), level
, buf
, parm_err
);
3176 return NERR_Success
;
3179 /************************************************************
3180 * NetLocalGroupSetMember (NETAPI32.@)
3182 NET_API_STATUS WINAPI
NetLocalGroupSetMembers(
3189 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername
),
3190 debugstr_w(groupname
), level
, buf
, totalentries
);
3191 return NERR_Success
;