2 * Copyright 2002 Andriy Palamarchuk
4 * netapi32 access functions
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
40 BOOL
NETAPI_IsLocalComputer(LPCWSTR ServerName
);
42 /************************************************************
43 * ACCESS_QueryAdminDisplayInformation
45 * Creates a buffer with information for the Admin User
47 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
49 static const WCHAR sAdminUserName
[] = {
50 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
52 /* sizes of the field buffers in WCHARS */
53 int name_sz
, comment_sz
, full_name_sz
;
54 PNET_DISPLAY_USER usr
;
57 name_sz
= lstrlenW(sAdminUserName
) + 1;
61 *pdwSize
= sizeof(NET_DISPLAY_USER
);
62 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
63 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
66 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
67 usr
->usri1_comment
= (LPWSTR
) (
68 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
69 usr
->usri1_full_name
= (LPWSTR
) (
70 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
73 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
74 usr
->usri1_comment
[0] = 0;
75 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
76 usr
->usri1_full_name
[0] = 0;
77 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
78 usr
->usri1_next_index
= 0;
81 /************************************************************
82 * ACCESS_QueryGuestDisplayInformation
84 * Creates a buffer with information for the Guest User
86 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
88 static const WCHAR sGuestUserName
[] = {
89 'G','u','e','s','t',0 };
91 /* sizes of the field buffers in WCHARS */
92 int name_sz
, comment_sz
, full_name_sz
;
93 PNET_DISPLAY_USER usr
;
96 name_sz
= lstrlenW(sGuestUserName
) + 1;
100 *pdwSize
= sizeof(NET_DISPLAY_USER
);
101 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
102 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
105 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
106 usr
->usri1_comment
= (LPWSTR
) (
107 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
108 usr
->usri1_full_name
= (LPWSTR
) (
109 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
112 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
113 usr
->usri1_comment
[0] = 0;
114 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
115 UF_DONT_EXPIRE_PASSWD
;
116 usr
->usri1_full_name
[0] = 0;
117 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
118 usr
->usri1_next_index
= 0;
121 /************************************************************
122 * Copies NET_DISPLAY_USER record.
124 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
125 PNET_DISPLAY_USER src
)
127 LPWSTR str
= *dest_buf
;
129 src
->usri1_name
= str
;
130 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
132 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
134 src
->usri1_comment
= str
;
135 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
137 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
139 src
->usri1_flags
= dest
->usri1_flags
;
141 src
->usri1_full_name
= str
;
142 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
144 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
146 src
->usri1_user_id
= dest
->usri1_user_id
;
147 src
->usri1_next_index
= dest
->usri1_next_index
;
151 /************************************************************
152 * NetQueryDisplayInformation (NETAPI32.@)
154 * The buffer structure:
155 * - array of fixed size record of the level type
156 * - strings, referenced by the record of the level type
158 NET_API_STATUS WINAPI
159 NetQueryDisplayInformation(
160 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
161 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
164 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
165 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
166 ReturnedEntryCount
, SortedBuffer
);
168 if(!NETAPI_IsLocalComputer(ServerName
))
170 FIXME("Only implemented on local computer, but requested for "
171 "remote server %s\n", debugstr_w(ServerName
));
172 return ERROR_ACCESS_DENIED
;
180 PNET_DISPLAY_USER inf
;
181 /* current available strings buffer */
183 PNET_DISPLAY_USER admin
, guest
;
184 DWORD admin_size
, guest_size
;
188 /* sizes of the field buffers in WCHARS */
189 int name_sz
, comment_sz
, full_name_sz
;
191 /* number of the records, returned in SortedBuffer
192 3 - for current user, Administrator and Guest users
196 FIXME("Level %d partially implemented\n", Level
);
197 *ReturnedEntryCount
= records
;
203 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
204 if (!GetUserNameW(name
, &dwSize
))
206 NetApiBufferFree(name
);
207 return ERROR_ACCESS_DENIED
;
210 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
211 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
214 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
215 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
217 NetApiBufferAllocate(dwSize
+
218 admin_size
- sizeof(NET_DISPLAY_USER
) +
219 guest_size
- sizeof(NET_DISPLAY_USER
),
222 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
223 inf
->usri1_name
= str
;
225 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
226 inf
->usri1_comment
= str
;
228 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
229 inf
->usri1_full_name
= str
;
231 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
234 lstrcpyW(inf
->usri1_name
, name
);
235 NetApiBufferFree(name
);
236 inf
->usri1_comment
[0] = 0;
238 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
239 inf
->usri1_full_name
[0] = 0;
240 inf
->usri1_user_id
= 0;
241 inf
->usri1_next_index
= 0;
244 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
245 NetApiBufferFree(admin
);
248 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
249 NetApiBufferFree(guest
);
256 FIXME("Level %d is not implemented\n", Level
);
261 TRACE("Invalid level %d is specified\n", Level
);
262 return ERROR_INVALID_LEVEL
;
267 /************************************************************
268 * NetGetDCName (NETAPI32.@)
270 * Return the name of the primary domain controller (PDC)
273 NET_API_STATUS WINAPI
274 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
276 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
277 debugstr_w(domainname
), bufptr
);
278 return NERR_DCNotFound
; /* say we can't find a domain controller */
281 /******************************************************************************
282 * NetUserModalsGet (NETAPI32.@)
284 * Retrieves global information for all users and global groups in the security
288 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
289 * on which the function is to execute.
290 * level [I] Information level of the data.
291 * 0 Return global passwords parameters. bufptr points to a
292 * USER_MODALS_INFO_0 struct.
293 * 1 Return logon server and domain controller information. bufptr
294 * points to a USER_MODALS_INFO_1 struct.
295 * 2 Return domain name and identifier. bufptr points to a
296 * USER_MODALS_INFO_2 struct.
297 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
299 * pbuffer [I] Buffer that receives the data.
302 * Success: NERR_Success.
304 * ERROR_ACCESS_DENIED - the user does not have access to the info.
305 * NERR_InvalidComputer - computer name is invalid.
307 NET_API_STATUS WINAPI
NetUserModalsGet(
308 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
310 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
315 /* return global passwords parameters */
316 FIXME("level 0 not implemented!\n");
318 return NERR_InternalError
;
320 /* return logon server and domain controller info */
321 FIXME("level 1 not implemented!\n");
323 return NERR_InternalError
;
326 /* return domain name and identifier */
327 PUSER_MODALS_INFO_2 umi
;
328 LSA_HANDLE policyHandle
;
329 LSA_OBJECT_ATTRIBUTES objectAttributes
;
330 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
332 PSID domainIdentifier
= NULL
;
333 int domainNameLen
, domainIdLen
;
335 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
336 objectAttributes
.Length
= sizeof(objectAttributes
);
338 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
339 POLICY_VIEW_LOCAL_INFORMATION
,
341 if (ntStatus
!= STATUS_SUCCESS
)
343 WARN("LsaOpenPolicy failed with NT status %x\n",
344 LsaNtStatusToWinError(ntStatus
));
348 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
349 PolicyAccountDomainInformation
,
350 (PVOID
*)&domainInfo
);
351 if (ntStatus
!= STATUS_SUCCESS
)
353 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
354 LsaNtStatusToWinError(ntStatus
));
355 LsaClose(policyHandle
);
359 domainIdentifier
= domainInfo
->DomainSid
;
360 domainIdLen
= (domainIdentifier
) ? GetLengthSid(domainIdentifier
) : 0;
361 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
362 LsaClose(policyHandle
);
364 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
366 domainNameLen
* sizeof(WCHAR
),
369 if (ntStatus
!= NERR_Success
)
371 WARN("NetApiBufferAllocate() failed\n");
372 LsaFreeMemory(domainInfo
);
376 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
377 umi
->usrmod2_domain_id
= (domainIdLen
> 0) ? (*pbuffer
+ sizeof(USER_MODALS_INFO_2
)) : NULL
;
378 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
379 sizeof(USER_MODALS_INFO_2
) + domainIdLen
);
381 lstrcpynW(umi
->usrmod2_domain_name
,
382 domainInfo
->DomainName
.Buffer
,
385 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
388 LsaFreeMemory(domainInfo
);
393 /* return lockout information */
394 FIXME("level 3 not implemented!\n");
396 return NERR_InternalError
;
398 TRACE("Invalid level %d is specified\n", level
);
400 return ERROR_INVALID_LEVEL
;
406 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
408 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);