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