netapi32: Win64 printf format warning fixes.
[wine] / dlls / netapi32 / access.c
1 /*
2  * Copyright 2002 Andriy Palamarchuk
3  *
4  * netapi32 access functions
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "lmcons.h"
29 #include "lmaccess.h"
30 #include "lmapibuf.h"
31 #include "lmerr.h"
32 #include "winreg.h"
33 #include "winternl.h"
34 #include "ntsecapi.h"
35 #include "netapi32_misc.h"
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
40
41 static const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
42                                 'o','r',0};
43 static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
44
45 /************************************************************
46  *                NETAPI_ValidateServername
47  *
48  * Validates server name
49  */
50 static NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
51 {
52     if (ServerName)
53     {
54         if (ServerName[0] == 0)
55             return ERROR_BAD_NETPATH;
56         else if (
57             ((ServerName[0] == '\\') &&
58              (ServerName[1] != '\\'))
59             ||
60             ((ServerName[0] == '\\') &&
61              (ServerName[1] == '\\') &&
62              (ServerName[2] == 0))
63             )
64             return ERROR_INVALID_NAME;
65     }
66     return NERR_Success;
67 }
68
69 /************************************************************
70  *                NETAPI_IsKnownUser
71  *
72  * Checks whether the user name indicates current user.
73  */
74 static BOOL NETAPI_IsKnownUser(LPCWSTR UserName)
75 {
76     DWORD dwSize = UNLEN + 1;
77     BOOL Result;
78     LPWSTR buf;
79
80     if (!lstrcmpW(UserName, sAdminUserName) ||
81         !lstrcmpW(UserName, sGuestUserName))
82         return TRUE;
83     NetApiBufferAllocate(dwSize * sizeof(WCHAR), (LPVOID *) &buf);
84     Result = GetUserNameW(buf, &dwSize);
85
86     Result = Result && !lstrcmpW(UserName, buf);
87     NetApiBufferFree(buf);
88
89     return Result;
90 }
91
92 #define NETAPI_ForceKnownUser(UserName, FailureCode) \
93     if (!NETAPI_IsKnownUser(UserName)) \
94     { \
95         FIXME("Can't find information for user %s\n", \
96               debugstr_w(UserName)); \
97         return FailureCode; \
98     }
99
100 /************************************************************
101  *                NetUserAdd (NETAPI32.@)
102  */
103 NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername,
104                   DWORD level, LPBYTE bufptr, LPDWORD parm_err)
105 {
106     NET_API_STATUS status;
107     FIXME("(%s, %ld, %p, %p) stub!\n", debugstr_w(servername), level, bufptr, parm_err);
108
109     status = NETAPI_ValidateServername(servername);
110     if (status != NERR_Success)
111         return status;
112     
113     if ((bufptr != NULL) && (level > 0) && (level <= 4))
114     {
115         PUSER_INFO_1 ui = (PUSER_INFO_1) bufptr;
116         TRACE("usri%ld_name: %s\n", level, debugstr_w(ui->usri1_name));
117         TRACE("usri%ld_password: %s\n", level, debugstr_w(ui->usri1_password));
118         TRACE("usri%ld_comment: %s\n", level, debugstr_w(ui->usri1_comment));
119     }
120     return status;
121 }
122
123 /************************************************************
124  *                NetUserDel  (NETAPI32.@)
125  */
126 NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
127 {
128     NET_API_STATUS status;
129     FIXME("(%s, %s) stub!\n", debugstr_w(servername), debugstr_w(username));
130
131     status = NETAPI_ValidateServername(servername);
132     if (status != NERR_Success)
133         return status;
134
135     if (!NETAPI_IsKnownUser(username))
136         return NERR_UserNotFound;
137
138     /* Delete the user here */
139     return status;
140 }
141
142 /************************************************************
143  *                NetUserGetInfo  (NETAPI32.@)
144  */
145 NET_API_STATUS WINAPI
146 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
147                LPBYTE* bufptr)
148 {
149     NET_API_STATUS status;
150     TRACE("(%s, %s, %ld, %p)\n", debugstr_w(servername), debugstr_w(username),
151           level, bufptr);
152     status = NETAPI_ValidateServername(servername);
153     if (status != NERR_Success)
154         return status;
155     NETAPI_ForceLocalComputer(servername, NERR_InvalidComputer);
156     NETAPI_ForceKnownUser(username, NERR_UserNotFound);
157
158     switch (level)
159     {
160     case 0:
161     {
162         PUSER_INFO_0 ui;
163         int name_sz;
164
165         name_sz = lstrlenW(username) + 1;
166
167         /* set up buffer */
168         NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
169                              (LPVOID *) bufptr);
170
171         ui = (PUSER_INFO_0) *bufptr;
172         ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
173
174         /* get data */
175         lstrcpyW(ui->usri0_name, username);
176         break;
177     }
178
179     case 10:
180     {
181         PUSER_INFO_10 ui;
182         PUSER_INFO_0 ui0;
183         NET_API_STATUS status;
184         /* sizes of the field buffers in WCHARS */
185         int name_sz, comment_sz, usr_comment_sz, full_name_sz;
186
187         comment_sz = 1;
188         usr_comment_sz = 1;
189         full_name_sz = 1;
190
191         /* get data */
192         status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
193         if (status != NERR_Success)
194         {
195             NetApiBufferFree(ui0);
196             return status;
197         }
198         name_sz = lstrlenW(ui0->usri0_name) + 1;
199
200         /* set up buffer */
201         NetApiBufferAllocate(sizeof(USER_INFO_10) +
202                              (name_sz + comment_sz + usr_comment_sz +
203                               full_name_sz) * sizeof(WCHAR),
204                              (LPVOID *) bufptr);
205         ui = (PUSER_INFO_10) *bufptr;
206         ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
207         ui->usri10_comment = (LPWSTR) (
208             ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
209         ui->usri10_usr_comment = (LPWSTR) (
210             ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
211         ui->usri10_full_name = (LPWSTR) (
212             ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
213
214         /* set data */
215         lstrcpyW(ui->usri10_name, ui0->usri0_name);
216         NetApiBufferFree(ui0);
217         ui->usri10_comment[0] = 0;
218         ui->usri10_usr_comment[0] = 0;
219         ui->usri10_full_name[0] = 0;
220         break;
221     }
222
223     case 1:
224       {
225         static const WCHAR homedirW[] = {'H','O','M','E',0};
226         PUSER_INFO_1 ui;
227         PUSER_INFO_0 ui0;
228         NET_API_STATUS status;
229         /* sizes of the field buffers in WCHARS */
230         int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
231
232         password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
233         comment_sz = 1;
234         script_path_sz = 1;
235
236        /* get data */
237         status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
238         if (status != NERR_Success)
239         {
240             NetApiBufferFree(ui0);
241             return status;
242         }
243         name_sz = lstrlenW(ui0->usri0_name) + 1;
244         home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
245         /* set up buffer */
246         NetApiBufferAllocate(sizeof(USER_INFO_1) +
247                              (name_sz + password_sz + home_dir_sz +
248                               comment_sz + script_path_sz) * sizeof(WCHAR),
249                              (LPVOID *) bufptr);
250
251         ui = (PUSER_INFO_1) *bufptr;
252         ui->usri1_name = (LPWSTR) (ui + 1);
253         ui->usri1_password = ui->usri1_name + name_sz;
254         ui->usri1_home_dir = ui->usri1_password + password_sz;
255         ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
256         ui->usri1_script_path = ui->usri1_comment + comment_sz;
257         /* set data */
258         lstrcpyW(ui->usri1_name, ui0->usri0_name);
259         NetApiBufferFree(ui0);
260         ui->usri1_password[0] = 0;
261         ui->usri1_password_age = 0;
262         ui->usri1_priv = 0;
263         GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
264         ui->usri1_comment[0] = 0;
265         ui->usri1_flags = 0;
266         ui->usri1_script_path[0] = 0;
267         break;
268       }
269     case 2:
270     case 3:
271     case 4:
272     case 11:
273     case 20:
274     case 23:
275     case 1003:
276     case 1005:
277     case 1006:
278     case 1007:
279     case 1008:
280     case 1009:
281     case 1010:
282     case 1011:
283     case 1012:
284     case 1013:
285     case 1014:
286     case 1017:
287     case 1018:
288     case 1020:
289     case 1023:
290     case 1024:
291     case 1025:
292     case 1051:
293     case 1052:
294     case 1053:
295     {
296         FIXME("Level %ld is not implemented\n", level);
297         return NERR_InternalError;
298     }
299     default:
300         ERR("Invalid level %ld is specified\n", level);
301         return ERROR_INVALID_LEVEL;
302     }
303     return NERR_Success;
304 }
305
306 /************************************************************
307  *                NetUserGetLocalGroups  (NETAPI32.@)
308  */
309 NET_API_STATUS WINAPI
310 NetUserGetLocalGroups(LPCWSTR servername, LPCWSTR username, DWORD level,
311                       DWORD flags, LPBYTE* bufptr, DWORD prefmaxlen,
312                       LPDWORD entriesread, LPDWORD totalentries)
313 {
314     FIXME("(%s, %s, %ld, %08lx, %p %ld, %p, %p) stub!\n",
315           debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
316           prefmaxlen, entriesread, totalentries);
317     return NERR_InternalError;
318 }
319
320 /************************************************************
321  *                NetUserEnum  (NETAPI32.@)
322  */
323 NET_API_STATUS WINAPI
324 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
325             DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
326             LPDWORD resume_handle)
327 {
328   FIXME("(%s,%ld, 0x%ld,%p,%ld,%p,%p,%p) stub!\n", debugstr_w(servername), level,
329         filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
330
331   return ERROR_ACCESS_DENIED;
332 }
333
334 /************************************************************
335  *                ACCESS_QueryAdminDisplayInformation
336  *
337  *  Creates a buffer with information for the Admin User
338  */
339 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
340 {
341     static const WCHAR sAdminUserName[] = {
342         'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
343
344     /* sizes of the field buffers in WCHARS */
345     int name_sz, comment_sz, full_name_sz;
346     PNET_DISPLAY_USER usr;
347
348     /* set up buffer */
349     name_sz = lstrlenW(sAdminUserName);
350     comment_sz = 1;
351     full_name_sz = 1;
352     
353     *pdwSize = sizeof(NET_DISPLAY_USER);
354     *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
355     NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
356
357     usr = *buf;
358     usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
359     usr->usri1_comment = (LPWSTR) (
360         ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
361     usr->usri1_full_name = (LPWSTR) (
362         ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
363
364     /* set data */
365     lstrcpyW(usr->usri1_name, sAdminUserName);
366     usr->usri1_comment[0] = 0;
367     usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
368     usr->usri1_full_name[0] = 0;
369     usr->usri1_user_id = 500;
370     usr->usri1_next_index = 0;
371 }
372
373 /************************************************************
374  *                ACCESS_QueryGuestDisplayInformation
375  *
376  *  Creates a buffer with information for the Guest User
377  */
378 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
379 {
380     static const WCHAR sGuestUserName[] = {
381         'G','u','e','s','t',0 };
382
383     /* sizes of the field buffers in WCHARS */
384     int name_sz, comment_sz, full_name_sz;
385     PNET_DISPLAY_USER usr;
386
387     /* set up buffer */
388     name_sz = lstrlenW(sGuestUserName);
389     comment_sz = 1;
390     full_name_sz = 1;
391     
392     *pdwSize = sizeof(NET_DISPLAY_USER);
393     *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
394     NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
395
396     usr = *buf;
397     usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
398     usr->usri1_comment = (LPWSTR) (
399         ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
400     usr->usri1_full_name = (LPWSTR) (
401         ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
402
403     /* set data */
404     lstrcpyW(usr->usri1_name, sGuestUserName);
405     usr->usri1_comment[0] = 0;
406     usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
407         UF_DONT_EXPIRE_PASSWD;
408     usr->usri1_full_name[0] = 0;
409     usr->usri1_user_id = 500;
410     usr->usri1_next_index = 0;
411 }
412
413 /************************************************************
414  *                NetQueryDisplayInformation  (NETAPI32.@)
415  * Copies NET_DISPLAY_USER record.
416  */
417 static void ACCESS_CopyDisplayUser(PNET_DISPLAY_USER dest, LPWSTR *dest_buf,
418                             PNET_DISPLAY_USER src)
419 {
420     LPWSTR str = *dest_buf;
421
422     src->usri1_name = str;
423     lstrcpyW(src->usri1_name, dest->usri1_name);
424     str = (LPWSTR) (
425         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
426
427     src->usri1_comment = str;
428     lstrcpyW(src->usri1_comment, dest->usri1_comment);
429     str = (LPWSTR) (
430         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
431
432     src->usri1_flags = dest->usri1_flags;
433
434     src->usri1_full_name = str;
435     lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
436     str = (LPWSTR) (
437         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
438
439     src->usri1_user_id = dest->usri1_user_id;
440     src->usri1_next_index = dest->usri1_next_index;
441     *dest_buf = str;
442 }
443
444 /************************************************************
445  *                NetQueryDisplayInformation  (NETAPI32.@)
446  *
447  * The buffer structure:
448  * - array of fixed size record of the level type
449  * - strings, referenced by the record of the level type
450  */
451 NET_API_STATUS WINAPI
452 NetQueryDisplayInformation(
453     LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
454     DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
455     PVOID *SortedBuffer)
456 {
457     TRACE("(%s, %ld, %ld, %ld, %ld, %p, %p)\n", debugstr_w(ServerName),
458           Level, Index, EntriesRequested, PreferredMaximumLength,
459           ReturnedEntryCount, SortedBuffer);
460     NETAPI_ForceLocalComputer(ServerName, ERROR_ACCESS_DENIED);
461     switch (Level)
462     {
463     case 1:
464     {
465         /* current record */
466         PNET_DISPLAY_USER inf;
467         /* current available strings buffer */
468         LPWSTR str;
469         PNET_DISPLAY_USER admin, guest;
470         DWORD admin_size, guest_size;
471         LPWSTR name = NULL;
472         DWORD dwSize;
473
474         /* sizes of the field buffers in WCHARS */
475         int name_sz, comment_sz, full_name_sz;
476
477         /* number of the records, returned in SortedBuffer
478            3 - for current user, Administrator and Guest users
479          */
480         int records = 3;
481
482         FIXME("Level %ld partially implemented\n", Level);
483         *ReturnedEntryCount = records;
484         comment_sz = 1;
485         full_name_sz = 1;
486
487         /* get data */
488         dwSize = UNLEN + 1;
489         NetApiBufferAllocate(dwSize, (LPVOID *) &name);
490         if (!GetUserNameW(name, &dwSize))
491         {
492             NetApiBufferFree(name);
493             return ERROR_ACCESS_DENIED;
494         }
495         name_sz = dwSize;
496         ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
497         ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
498
499         /* set up buffer */
500         dwSize = sizeof(NET_DISPLAY_USER) * records;
501         dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
502
503         NetApiBufferAllocate(dwSize +
504                              admin_size - sizeof(NET_DISPLAY_USER) +
505                              guest_size - sizeof(NET_DISPLAY_USER),
506                              (LPVOID *) SortedBuffer);
507         inf = (PNET_DISPLAY_USER) *SortedBuffer;
508         str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
509         inf->usri1_name = str;
510         str = (LPWSTR) (
511             ((PBYTE) str) + name_sz * sizeof(WCHAR));
512         inf->usri1_comment = str;
513         str = (LPWSTR) (
514             ((PBYTE) str) + comment_sz * sizeof(WCHAR));
515         inf->usri1_full_name = str;
516         str = (LPWSTR) (
517             ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
518
519         /* set data */
520         lstrcpyW(inf->usri1_name, name);
521         NetApiBufferFree(name);
522         inf->usri1_comment[0] = 0;
523         inf->usri1_flags =
524             UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
525         inf->usri1_full_name[0] = 0;
526         inf->usri1_user_id = 0;
527         inf->usri1_next_index = 0;
528
529         inf++;
530         ACCESS_CopyDisplayUser(admin, &str, inf);
531         NetApiBufferFree(admin);
532
533         inf++;
534         ACCESS_CopyDisplayUser(guest, &str, inf);
535         NetApiBufferFree(guest);
536         break;
537     }
538
539     case 2:
540     case 3:
541     {
542         FIXME("Level %ld is not implemented\n", Level);
543         break;
544     }
545
546     default:
547         ERR("Invalid level %ld is specified\n", Level);
548         return ERROR_INVALID_LEVEL;
549     }
550     return NERR_Success;
551 }
552
553 /************************************************************
554  *                NetGetDCName  (NETAPI32.@)
555  *
556  *  Return the name of the primary domain controller (PDC)
557  */
558
559 NET_API_STATUS WINAPI
560 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
561 {
562   FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
563                  debugstr_w(domainname), bufptr);
564   return NERR_DCNotFound; /* say we can't find a domain controller */  
565 }
566
567
568 /******************************************************************************
569  * NetUserModalsGet  (NETAPI32.@)
570  *
571  * Retrieves global information for all users and global groups in the security
572  * database.
573  *
574  * PARAMS
575  *  szServer   [I] Specifies the DNS or the NetBIOS name of the remote server
576  *                 on which the function is to execute.
577  *  level      [I] Information level of the data.
578  *     0   Return global passwords parameters. bufptr points to a
579  *         USER_MODALS_INFO_0 struct.
580  *     1   Return logon server and domain controller information. bufptr
581  *         points to a USER_MODALS_INFO_1 struct.
582  *     2   Return domain name and identifier. bufptr points to a 
583  *         USER_MODALS_INFO_2 struct.
584  *     3   Return lockout information. bufptr points to a USER_MODALS_INFO_3
585  *         struct.
586  *  pbuffer    [I] Buffer that receives the data.
587  *
588  * RETURNS
589  *  Success: NERR_Success.
590  *  Failure: 
591  *     ERROR_ACCESS_DENIED - the user does not have access to the info.
592  *     NERR_InvalidComputer - computer name is invalid.
593  */
594 NET_API_STATUS WINAPI NetUserModalsGet(
595     LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
596 {
597     TRACE("(%s %ld %p)\n", debugstr_w(szServer), level, pbuffer);
598     
599     switch (level)
600     {
601         case 0:
602             /* return global passwords parameters */
603             FIXME("level 0 not implemented!\n");
604             *pbuffer = NULL;
605             return NERR_InternalError;
606         case 1:
607             /* return logon server and domain controller info */
608             FIXME("level 1 not implemented!\n");
609             *pbuffer = NULL;
610             return NERR_InternalError;
611         case 2:
612         {
613             /* return domain name and identifier */
614             PUSER_MODALS_INFO_2 umi;
615             LSA_HANDLE policyHandle;
616             LSA_OBJECT_ATTRIBUTES objectAttributes;
617             PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
618             NTSTATUS ntStatus;
619             PSID domainIdentifier = NULL;
620             int domainNameLen;
621
622             ZeroMemory(&objectAttributes, sizeof(objectAttributes));
623             objectAttributes.Length = sizeof(objectAttributes);
624
625             ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
626                                      POLICY_VIEW_LOCAL_INFORMATION,
627                                      &policyHandle);
628             if (ntStatus != STATUS_SUCCESS)
629             {
630                 WARN("LsaOpenPolicy failed with NT status %lx\n",
631                      LsaNtStatusToWinError(ntStatus));
632                 return ntStatus;
633             }
634
635             ntStatus = LsaQueryInformationPolicy(policyHandle,
636                                                  PolicyAccountDomainInformation,
637                                                  (PVOID *)&domainInfo);
638             if (ntStatus != STATUS_SUCCESS)
639             {
640                 WARN("LsaQueryInformationPolicy failed with NT status %lx\n",
641                      LsaNtStatusToWinError(ntStatus));
642                 LsaClose(policyHandle);
643                 return ntStatus;
644             }
645
646             domainIdentifier = domainInfo->DomainSid;
647             domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
648             LsaClose(policyHandle);
649
650             ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
651                                             GetLengthSid(domainIdentifier) +
652                                             domainNameLen * sizeof(WCHAR),
653                                             (LPVOID *)pbuffer);
654
655             if (ntStatus != NERR_Success)
656             {
657                 WARN("NetApiBufferAllocate() failed\n");
658                 LsaFreeMemory(domainInfo);
659                 return ntStatus;
660             }
661
662             umi = (USER_MODALS_INFO_2 *) *pbuffer;
663             umi->usrmod2_domain_id = (PSID)(*pbuffer +
664                 sizeof(USER_MODALS_INFO_2));
665             umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
666                 sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
667
668             lstrcpynW(umi->usrmod2_domain_name,
669                       domainInfo->DomainName.Buffer,
670                       domainNameLen);
671             CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
672                     domainIdentifier);
673
674             LsaFreeMemory(domainInfo);
675
676             break;
677         } 
678         case 3:
679             /* return lockout information */
680             FIXME("level 3 not implemented!\n");
681             *pbuffer = NULL;
682             return NERR_InternalError;
683         default:
684             WARN("Invalid level %ld is specified\n", level);
685             *pbuffer = NULL;
686             return ERROR_INVALID_LEVEL;
687     }
688
689     return NERR_Success;
690 }