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