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
23 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
25 BOOL
NETAPI_IsLocalComputer(LPCWSTR ServerName
);
27 /************************************************************
28 * ACCESS_QueryAdminDisplayInformation
30 * Creates a buffer with information for the Admin User
32 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
34 static const WCHAR sAdminUserName
[] = {
35 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
37 /* sizes of the field buffers in WCHARS */
38 int name_sz
, comment_sz
, full_name_sz
;
39 PNET_DISPLAY_USER usr
;
42 name_sz
= lstrlenW(sAdminUserName
) + 1;
46 *pdwSize
= sizeof(NET_DISPLAY_USER
);
47 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
48 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
51 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
52 usr
->usri1_comment
= (LPWSTR
) (
53 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
54 usr
->usri1_full_name
= (LPWSTR
) (
55 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
58 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
59 usr
->usri1_comment
[0] = 0;
60 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
61 usr
->usri1_full_name
[0] = 0;
62 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
63 usr
->usri1_next_index
= 0;
66 /************************************************************
67 * ACCESS_QueryGuestDisplayInformation
69 * Creates a buffer with information for the Guest User
71 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
73 static const WCHAR sGuestUserName
[] = {
74 'G','u','e','s','t',0 };
76 /* sizes of the field buffers in WCHARS */
77 int name_sz
, comment_sz
, full_name_sz
;
78 PNET_DISPLAY_USER usr
;
81 name_sz
= lstrlenW(sGuestUserName
) + 1;
85 *pdwSize
= sizeof(NET_DISPLAY_USER
);
86 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
87 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
90 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
91 usr
->usri1_comment
= (LPWSTR
) (
92 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
93 usr
->usri1_full_name
= (LPWSTR
) (
94 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
97 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
98 usr
->usri1_comment
[0] = 0;
99 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
100 UF_DONT_EXPIRE_PASSWD
;
101 usr
->usri1_full_name
[0] = 0;
102 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
103 usr
->usri1_next_index
= 0;
106 /************************************************************
107 * Copies NET_DISPLAY_USER record.
109 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
110 PNET_DISPLAY_USER src
)
112 LPWSTR str
= *dest_buf
;
114 src
->usri1_name
= str
;
115 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
117 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
119 src
->usri1_comment
= str
;
120 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
122 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
124 src
->usri1_flags
= dest
->usri1_flags
;
126 src
->usri1_full_name
= str
;
127 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
129 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
131 src
->usri1_user_id
= dest
->usri1_user_id
;
132 src
->usri1_next_index
= dest
->usri1_next_index
;
136 /************************************************************
137 * NetQueryDisplayInformation (NETAPI32.@)
139 * The buffer structure:
140 * - array of fixed size record of the level type
141 * - strings, referenced by the record of the level type
143 NET_API_STATUS WINAPI
144 NetQueryDisplayInformation(
145 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
146 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
149 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
150 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
151 ReturnedEntryCount
, SortedBuffer
);
153 if(!NETAPI_IsLocalComputer(ServerName
))
155 FIXME("Only implemented on local computer, but requested for "
156 "remote server %s\n", debugstr_w(ServerName
));
157 return ERROR_ACCESS_DENIED
;
165 PNET_DISPLAY_USER inf
;
166 /* current available strings buffer */
168 PNET_DISPLAY_USER admin
, guest
;
169 DWORD admin_size
, guest_size
;
173 /* sizes of the field buffers in WCHARS */
174 int name_sz
, comment_sz
, full_name_sz
;
176 /* number of the records, returned in SortedBuffer
177 3 - for current user, Administrator and Guest users
181 FIXME("Level %d partially implemented\n", Level
);
182 *ReturnedEntryCount
= records
;
188 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
189 if (!GetUserNameW(name
, &dwSize
))
191 NetApiBufferFree(name
);
192 return ERROR_ACCESS_DENIED
;
195 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
196 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
199 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
200 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
202 NetApiBufferAllocate(dwSize
+
203 admin_size
- sizeof(NET_DISPLAY_USER
) +
204 guest_size
- sizeof(NET_DISPLAY_USER
),
207 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
208 inf
->usri1_name
= str
;
210 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
211 inf
->usri1_comment
= str
;
213 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
214 inf
->usri1_full_name
= str
;
216 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
219 lstrcpyW(inf
->usri1_name
, name
);
220 NetApiBufferFree(name
);
221 inf
->usri1_comment
[0] = 0;
223 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
224 inf
->usri1_full_name
[0] = 0;
225 inf
->usri1_user_id
= 0;
226 inf
->usri1_next_index
= 0;
229 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
230 NetApiBufferFree(admin
);
233 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
234 NetApiBufferFree(guest
);
241 FIXME("Level %d is not implemented\n", Level
);
246 TRACE("Invalid level %d is specified\n", Level
);
247 return ERROR_INVALID_LEVEL
;
252 /************************************************************
253 * NetGetDCName (NETAPI32.@)
255 * Return the name of the primary domain controller (PDC)
258 NET_API_STATUS WINAPI
259 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
261 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
262 debugstr_w(domainname
), bufptr
);
263 return NERR_DCNotFound
; /* say we can't find a domain controller */
266 /******************************************************************************
267 * NetUserModalsGet (NETAPI32.@)
269 * Retrieves global information for all users and global groups in the security
273 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
274 * on which the function is to execute.
275 * level [I] Information level of the data.
276 * 0 Return global passwords parameters. bufptr points to a
277 * USER_MODALS_INFO_0 struct.
278 * 1 Return logon server and domain controller information. bufptr
279 * points to a USER_MODALS_INFO_1 struct.
280 * 2 Return domain name and identifier. bufptr points to a
281 * USER_MODALS_INFO_2 struct.
282 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
284 * pbuffer [I] Buffer that receives the data.
287 * Success: NERR_Success.
289 * ERROR_ACCESS_DENIED - the user does not have access to the info.
290 * NERR_InvalidComputer - computer name is invalid.
292 NET_API_STATUS WINAPI
NetUserModalsGet(
293 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
295 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
300 /* return global passwords parameters */
301 FIXME("level 0 not implemented!\n");
303 return NERR_InternalError
;
305 /* return logon server and domain controller info */
306 FIXME("level 1 not implemented!\n");
308 return NERR_InternalError
;
311 /* return domain name and identifier */
312 PUSER_MODALS_INFO_2 umi
;
313 LSA_HANDLE policyHandle
;
314 LSA_OBJECT_ATTRIBUTES objectAttributes
;
315 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
317 PSID domainIdentifier
= NULL
;
318 int domainNameLen
, domainIdLen
;
320 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
321 objectAttributes
.Length
= sizeof(objectAttributes
);
323 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
324 POLICY_VIEW_LOCAL_INFORMATION
,
326 if (ntStatus
!= STATUS_SUCCESS
)
328 WARN("LsaOpenPolicy failed with NT status %x\n",
329 LsaNtStatusToWinError(ntStatus
));
333 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
334 PolicyAccountDomainInformation
,
335 (PVOID
*)&domainInfo
);
336 if (ntStatus
!= STATUS_SUCCESS
)
338 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
339 LsaNtStatusToWinError(ntStatus
));
340 LsaClose(policyHandle
);
344 domainIdentifier
= domainInfo
->DomainSid
;
345 domainIdLen
= (domainIdentifier
) ? GetLengthSid(domainIdentifier
) : 0;
346 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
347 LsaClose(policyHandle
);
349 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
351 domainNameLen
* sizeof(WCHAR
),
354 if (ntStatus
!= NERR_Success
)
356 WARN("NetApiBufferAllocate() failed\n");
357 LsaFreeMemory(domainInfo
);
361 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
362 umi
->usrmod2_domain_id
= (domainIdLen
> 0) ? (*pbuffer
+ sizeof(USER_MODALS_INFO_2
)) : NULL
;
363 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
364 sizeof(USER_MODALS_INFO_2
) + domainIdLen
);
366 lstrcpynW(umi
->usrmod2_domain_name
,
367 domainInfo
->DomainName
.Buffer
,
370 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
373 LsaFreeMemory(domainInfo
);
378 /* return lockout information */
379 FIXME("level 3 not implemented!\n");
381 return NERR_InternalError
;
383 TRACE("Invalid level %d is specified\n", level
);
385 return ERROR_INVALID_LEVEL
;
391 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
393 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);