quartz: Use proper alloc/free functions for COM objects.
[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     NET_API_STATUS status;
314
315     FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
316           debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
317           prefmaxlen, entriesread, totalentries);
318
319     status = NETAPI_ValidateServername(servername);
320     if (status != NERR_Success)
321         return status;
322
323     if (!NETAPI_IsKnownUser(username))
324         return NERR_UserNotFound;
325
326     if (bufptr) *bufptr = NULL;
327     if (entriesread) *entriesread = 0;
328     if (totalentries) *totalentries = 0;
329
330     return NERR_Success;
331 }
332
333 /************************************************************
334  *                NetUserEnum  (NETAPI32.@)
335  */
336 NET_API_STATUS WINAPI
337 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
338             DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
339             LPDWORD resume_handle)
340 {
341   FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
342         filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
343
344   return ERROR_ACCESS_DENIED;
345 }
346
347 /************************************************************
348  *                ACCESS_QueryAdminDisplayInformation
349  *
350  *  Creates a buffer with information for the Admin User
351  */
352 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
353 {
354     static const WCHAR sAdminUserName[] = {
355         'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
356
357     /* sizes of the field buffers in WCHARS */
358     int name_sz, comment_sz, full_name_sz;
359     PNET_DISPLAY_USER usr;
360
361     /* set up buffer */
362     name_sz = lstrlenW(sAdminUserName);
363     comment_sz = 1;
364     full_name_sz = 1;
365     
366     *pdwSize = sizeof(NET_DISPLAY_USER);
367     *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
368     NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
369
370     usr = *buf;
371     usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
372     usr->usri1_comment = (LPWSTR) (
373         ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
374     usr->usri1_full_name = (LPWSTR) (
375         ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
376
377     /* set data */
378     lstrcpyW(usr->usri1_name, sAdminUserName);
379     usr->usri1_comment[0] = 0;
380     usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
381     usr->usri1_full_name[0] = 0;
382     usr->usri1_user_id = 500;
383     usr->usri1_next_index = 0;
384 }
385
386 /************************************************************
387  *                ACCESS_QueryGuestDisplayInformation
388  *
389  *  Creates a buffer with information for the Guest User
390  */
391 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
392 {
393     static const WCHAR sGuestUserName[] = {
394         'G','u','e','s','t',0 };
395
396     /* sizes of the field buffers in WCHARS */
397     int name_sz, comment_sz, full_name_sz;
398     PNET_DISPLAY_USER usr;
399
400     /* set up buffer */
401     name_sz = lstrlenW(sGuestUserName);
402     comment_sz = 1;
403     full_name_sz = 1;
404     
405     *pdwSize = sizeof(NET_DISPLAY_USER);
406     *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
407     NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
408
409     usr = *buf;
410     usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
411     usr->usri1_comment = (LPWSTR) (
412         ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
413     usr->usri1_full_name = (LPWSTR) (
414         ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
415
416     /* set data */
417     lstrcpyW(usr->usri1_name, sGuestUserName);
418     usr->usri1_comment[0] = 0;
419     usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
420         UF_DONT_EXPIRE_PASSWD;
421     usr->usri1_full_name[0] = 0;
422     usr->usri1_user_id = 500;
423     usr->usri1_next_index = 0;
424 }
425
426 /************************************************************
427  *                NetQueryDisplayInformation  (NETAPI32.@)
428  * Copies NET_DISPLAY_USER record.
429  */
430 static void ACCESS_CopyDisplayUser(PNET_DISPLAY_USER dest, LPWSTR *dest_buf,
431                             PNET_DISPLAY_USER src)
432 {
433     LPWSTR str = *dest_buf;
434
435     src->usri1_name = str;
436     lstrcpyW(src->usri1_name, dest->usri1_name);
437     str = (LPWSTR) (
438         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
439
440     src->usri1_comment = str;
441     lstrcpyW(src->usri1_comment, dest->usri1_comment);
442     str = (LPWSTR) (
443         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
444
445     src->usri1_flags = dest->usri1_flags;
446
447     src->usri1_full_name = str;
448     lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
449     str = (LPWSTR) (
450         ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
451
452     src->usri1_user_id = dest->usri1_user_id;
453     src->usri1_next_index = dest->usri1_next_index;
454     *dest_buf = str;
455 }
456
457 /************************************************************
458  *                NetQueryDisplayInformation  (NETAPI32.@)
459  *
460  * The buffer structure:
461  * - array of fixed size record of the level type
462  * - strings, referenced by the record of the level type
463  */
464 NET_API_STATUS WINAPI
465 NetQueryDisplayInformation(
466     LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
467     DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
468     PVOID *SortedBuffer)
469 {
470     TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
471           Level, Index, EntriesRequested, PreferredMaximumLength,
472           ReturnedEntryCount, SortedBuffer);
473     NETAPI_ForceLocalComputer(ServerName, ERROR_ACCESS_DENIED);
474     switch (Level)
475     {
476     case 1:
477     {
478         /* current record */
479         PNET_DISPLAY_USER inf;
480         /* current available strings buffer */
481         LPWSTR str;
482         PNET_DISPLAY_USER admin, guest;
483         DWORD admin_size, guest_size;
484         LPWSTR name = NULL;
485         DWORD dwSize;
486
487         /* sizes of the field buffers in WCHARS */
488         int name_sz, comment_sz, full_name_sz;
489
490         /* number of the records, returned in SortedBuffer
491            3 - for current user, Administrator and Guest users
492          */
493         int records = 3;
494
495         FIXME("Level %d partially implemented\n", Level);
496         *ReturnedEntryCount = records;
497         comment_sz = 1;
498         full_name_sz = 1;
499
500         /* get data */
501         dwSize = UNLEN + 1;
502         NetApiBufferAllocate(dwSize, (LPVOID *) &name);
503         if (!GetUserNameW(name, &dwSize))
504         {
505             NetApiBufferFree(name);
506             return ERROR_ACCESS_DENIED;
507         }
508         name_sz = dwSize;
509         ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
510         ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
511
512         /* set up buffer */
513         dwSize = sizeof(NET_DISPLAY_USER) * records;
514         dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
515
516         NetApiBufferAllocate(dwSize +
517                              admin_size - sizeof(NET_DISPLAY_USER) +
518                              guest_size - sizeof(NET_DISPLAY_USER),
519                              (LPVOID *) SortedBuffer);
520         inf = (PNET_DISPLAY_USER) *SortedBuffer;
521         str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
522         inf->usri1_name = str;
523         str = (LPWSTR) (
524             ((PBYTE) str) + name_sz * sizeof(WCHAR));
525         inf->usri1_comment = str;
526         str = (LPWSTR) (
527             ((PBYTE) str) + comment_sz * sizeof(WCHAR));
528         inf->usri1_full_name = str;
529         str = (LPWSTR) (
530             ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
531
532         /* set data */
533         lstrcpyW(inf->usri1_name, name);
534         NetApiBufferFree(name);
535         inf->usri1_comment[0] = 0;
536         inf->usri1_flags =
537             UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
538         inf->usri1_full_name[0] = 0;
539         inf->usri1_user_id = 0;
540         inf->usri1_next_index = 0;
541
542         inf++;
543         ACCESS_CopyDisplayUser(admin, &str, inf);
544         NetApiBufferFree(admin);
545
546         inf++;
547         ACCESS_CopyDisplayUser(guest, &str, inf);
548         NetApiBufferFree(guest);
549         break;
550     }
551
552     case 2:
553     case 3:
554     {
555         FIXME("Level %d is not implemented\n", Level);
556         break;
557     }
558
559     default:
560         ERR("Invalid level %d is specified\n", Level);
561         return ERROR_INVALID_LEVEL;
562     }
563     return NERR_Success;
564 }
565
566 /************************************************************
567  *                NetGetDCName  (NETAPI32.@)
568  *
569  *  Return the name of the primary domain controller (PDC)
570  */
571
572 NET_API_STATUS WINAPI
573 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
574 {
575   FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
576                  debugstr_w(domainname), bufptr);
577   return NERR_DCNotFound; /* say we can't find a domain controller */  
578 }
579
580
581 /******************************************************************************
582  * NetUserModalsGet  (NETAPI32.@)
583  *
584  * Retrieves global information for all users and global groups in the security
585  * database.
586  *
587  * PARAMS
588  *  szServer   [I] Specifies the DNS or the NetBIOS name of the remote server
589  *                 on which the function is to execute.
590  *  level      [I] Information level of the data.
591  *     0   Return global passwords parameters. bufptr points to a
592  *         USER_MODALS_INFO_0 struct.
593  *     1   Return logon server and domain controller information. bufptr
594  *         points to a USER_MODALS_INFO_1 struct.
595  *     2   Return domain name and identifier. bufptr points to a 
596  *         USER_MODALS_INFO_2 struct.
597  *     3   Return lockout information. bufptr points to a USER_MODALS_INFO_3
598  *         struct.
599  *  pbuffer    [I] Buffer that receives the data.
600  *
601  * RETURNS
602  *  Success: NERR_Success.
603  *  Failure: 
604  *     ERROR_ACCESS_DENIED - the user does not have access to the info.
605  *     NERR_InvalidComputer - computer name is invalid.
606  */
607 NET_API_STATUS WINAPI NetUserModalsGet(
608     LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
609 {
610     TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
611     
612     switch (level)
613     {
614         case 0:
615             /* return global passwords parameters */
616             FIXME("level 0 not implemented!\n");
617             *pbuffer = NULL;
618             return NERR_InternalError;
619         case 1:
620             /* return logon server and domain controller info */
621             FIXME("level 1 not implemented!\n");
622             *pbuffer = NULL;
623             return NERR_InternalError;
624         case 2:
625         {
626             /* return domain name and identifier */
627             PUSER_MODALS_INFO_2 umi;
628             LSA_HANDLE policyHandle;
629             LSA_OBJECT_ATTRIBUTES objectAttributes;
630             PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
631             NTSTATUS ntStatus;
632             PSID domainIdentifier = NULL;
633             int domainNameLen;
634
635             ZeroMemory(&objectAttributes, sizeof(objectAttributes));
636             objectAttributes.Length = sizeof(objectAttributes);
637
638             ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
639                                      POLICY_VIEW_LOCAL_INFORMATION,
640                                      &policyHandle);
641             if (ntStatus != STATUS_SUCCESS)
642             {
643                 WARN("LsaOpenPolicy failed with NT status %x\n",
644                      LsaNtStatusToWinError(ntStatus));
645                 return ntStatus;
646             }
647
648             ntStatus = LsaQueryInformationPolicy(policyHandle,
649                                                  PolicyAccountDomainInformation,
650                                                  (PVOID *)&domainInfo);
651             if (ntStatus != STATUS_SUCCESS)
652             {
653                 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
654                      LsaNtStatusToWinError(ntStatus));
655                 LsaClose(policyHandle);
656                 return ntStatus;
657             }
658
659             domainIdentifier = domainInfo->DomainSid;
660             domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
661             LsaClose(policyHandle);
662
663             ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
664                                             GetLengthSid(domainIdentifier) +
665                                             domainNameLen * sizeof(WCHAR),
666                                             (LPVOID *)pbuffer);
667
668             if (ntStatus != NERR_Success)
669             {
670                 WARN("NetApiBufferAllocate() failed\n");
671                 LsaFreeMemory(domainInfo);
672                 return ntStatus;
673             }
674
675             umi = (USER_MODALS_INFO_2 *) *pbuffer;
676             umi->usrmod2_domain_id = (PSID)(*pbuffer +
677                 sizeof(USER_MODALS_INFO_2));
678             umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
679                 sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
680
681             lstrcpynW(umi->usrmod2_domain_name,
682                       domainInfo->DomainName.Buffer,
683                       domainNameLen);
684             CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
685                     domainIdentifier);
686
687             LsaFreeMemory(domainInfo);
688
689             break;
690         } 
691         case 3:
692             /* return lockout information */
693             FIXME("level 3 not implemented!\n");
694             *pbuffer = NULL;
695             return NERR_InternalError;
696         default:
697             WARN("Invalid level %d is specified\n", level);
698             *pbuffer = NULL;
699             return ERROR_INVALID_LEVEL;
700     }
701
702     return NERR_Success;
703 }
704
705 /******************************************************************************
706  *                NetUserChangePassword  (NETAPI32.@)
707  * PARAMS
708  *  domainname  [I] Optional. Domain on which the user resides or the logon
709  *                  domain of the current user if NULL.
710  *  username    [I] Optional. Username to change the password for or the name
711  *                  of the current user if NULL.
712  *  oldpassword [I] The user's current password.
713  *  newpassword [I] The password that the user will be changed to using.
714  *
715  * RETURNS
716  *  Success: NERR_Success.
717  *  Failure: NERR_* failure code or win error code.
718  *
719  */
720 NET_API_STATUS WINAPI NetUserChangePassword(LPCWSTR domainname, LPCWSTR username,
721     LPCWSTR oldpassword, LPCWSTR newpassword)
722 {
723     FIXME("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
724     return NERR_InternalError;
725 }