[NETAPI32]
[reactos.git] / reactos / dll / win32 / 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 "netapi32.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
24
25
26 /************************************************************
27 * ACCESS_QueryAdminDisplayInformation
28 *
29 * Creates a buffer with information for the Admin User
30 */
31 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
32 {
33 static const WCHAR sAdminUserName[] = {
34 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
35
36 /* sizes of the field buffers in WCHARS */
37 int name_sz, comment_sz, full_name_sz;
38 PNET_DISPLAY_USER usr;
39
40 /* set up buffer */
41 name_sz = lstrlenW(sAdminUserName) + 1;
42 comment_sz = 1;
43 full_name_sz = 1;
44
45 *pdwSize = sizeof(NET_DISPLAY_USER);
46 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
47 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
48
49 usr = *buf;
50 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
51 usr->usri1_comment = (LPWSTR) (
52 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
53 usr->usri1_full_name = (LPWSTR) (
54 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
55
56 /* set data */
57 lstrcpyW(usr->usri1_name, sAdminUserName);
58 usr->usri1_comment[0] = 0;
59 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
60 usr->usri1_full_name[0] = 0;
61 usr->usri1_user_id = DOMAIN_USER_RID_ADMIN;
62 usr->usri1_next_index = 0;
63 }
64
65 /************************************************************
66 * ACCESS_QueryGuestDisplayInformation
67 *
68 * Creates a buffer with information for the Guest User
69 */
70 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
71 {
72 static const WCHAR sGuestUserName[] = {
73 'G','u','e','s','t',0 };
74
75 /* sizes of the field buffers in WCHARS */
76 int name_sz, comment_sz, full_name_sz;
77 PNET_DISPLAY_USER usr;
78
79 /* set up buffer */
80 name_sz = lstrlenW(sGuestUserName) + 1;
81 comment_sz = 1;
82 full_name_sz = 1;
83
84 *pdwSize = sizeof(NET_DISPLAY_USER);
85 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
86 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
87
88 usr = *buf;
89 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
90 usr->usri1_comment = (LPWSTR) (
91 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
92 usr->usri1_full_name = (LPWSTR) (
93 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
94
95 /* set data */
96 lstrcpyW(usr->usri1_name, sGuestUserName);
97 usr->usri1_comment[0] = 0;
98 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
99 UF_DONT_EXPIRE_PASSWD;
100 usr->usri1_full_name[0] = 0;
101 usr->usri1_user_id = DOMAIN_USER_RID_GUEST;
102 usr->usri1_next_index = 0;
103 }
104
105 /************************************************************
106 * Copies NET_DISPLAY_USER record.
107 */
108 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER *dest, LPWSTR *dest_buf,
109 PNET_DISPLAY_USER src)
110 {
111 LPWSTR str = *dest_buf;
112
113 src->usri1_name = str;
114 lstrcpyW(src->usri1_name, dest->usri1_name);
115 str = (LPWSTR) (
116 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
117
118 src->usri1_comment = str;
119 lstrcpyW(src->usri1_comment, dest->usri1_comment);
120 str = (LPWSTR) (
121 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
122
123 src->usri1_flags = dest->usri1_flags;
124
125 src->usri1_full_name = str;
126 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
127 str = (LPWSTR) (
128 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
129
130 src->usri1_user_id = dest->usri1_user_id;
131 src->usri1_next_index = dest->usri1_next_index;
132 *dest_buf = str;
133 }
134
135 /************************************************************
136 * NetQueryDisplayInformation (NETAPI32.@)
137 *
138 * The buffer structure:
139 * - array of fixed size record of the level type
140 * - strings, referenced by the record of the level type
141 */
142 NET_API_STATUS WINAPI
143 NetQueryDisplayInformation(
144 LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
145 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
146 PVOID *SortedBuffer)
147 {
148 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
149 Level, Index, EntriesRequested, PreferredMaximumLength,
150 ReturnedEntryCount, SortedBuffer);
151
152 if(!NETAPI_IsLocalComputer(ServerName))
153 {
154 FIXME("Only implemented on local computer, but requested for "
155 "remote server %s\n", debugstr_w(ServerName));
156 return ERROR_ACCESS_DENIED;
157 }
158
159 switch (Level)
160 {
161 case 1:
162 {
163 /* current record */
164 PNET_DISPLAY_USER inf;
165 /* current available strings buffer */
166 LPWSTR str;
167 PNET_DISPLAY_USER admin, guest;
168 DWORD admin_size, guest_size;
169 LPWSTR name = NULL;
170 DWORD dwSize;
171
172 /* sizes of the field buffers in WCHARS */
173 int name_sz, comment_sz, full_name_sz;
174
175 /* number of the records, returned in SortedBuffer
176 3 - for current user, Administrator and Guest users
177 */
178 int records = 3;
179
180 FIXME("Level %d partially implemented\n", Level);
181 *ReturnedEntryCount = records;
182 comment_sz = 1;
183 full_name_sz = 1;
184
185 /* get data */
186 dwSize = UNLEN + 1;
187 NetApiBufferAllocate(dwSize * sizeof(WCHAR), (LPVOID *) &name);
188 if (!GetUserNameW(name, &dwSize))
189 {
190 NetApiBufferFree(name);
191 return ERROR_ACCESS_DENIED;
192 }
193 name_sz = dwSize;
194 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
195 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
196
197 /* set up buffer */
198 dwSize = sizeof(NET_DISPLAY_USER) * records;
199 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
200
201 NetApiBufferAllocate(dwSize +
202 admin_size - sizeof(NET_DISPLAY_USER) +
203 guest_size - sizeof(NET_DISPLAY_USER),
204 SortedBuffer);
205 inf = *SortedBuffer;
206 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
207 inf->usri1_name = str;
208 str = (LPWSTR) (
209 ((PBYTE) str) + name_sz * sizeof(WCHAR));
210 inf->usri1_comment = str;
211 str = (LPWSTR) (
212 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
213 inf->usri1_full_name = str;
214 str = (LPWSTR) (
215 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
216
217 /* set data */
218 lstrcpyW(inf->usri1_name, name);
219 NetApiBufferFree(name);
220 inf->usri1_comment[0] = 0;
221 inf->usri1_flags =
222 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
223 inf->usri1_full_name[0] = 0;
224 inf->usri1_user_id = 0;
225 inf->usri1_next_index = 0;
226
227 inf++;
228 ACCESS_CopyDisplayUser(admin, &str, inf);
229 NetApiBufferFree(admin);
230
231 inf++;
232 ACCESS_CopyDisplayUser(guest, &str, inf);
233 NetApiBufferFree(guest);
234 break;
235 }
236
237 case 2:
238 case 3:
239 {
240 FIXME("Level %d is not implemented\n", Level);
241 break;
242 }
243
244 default:
245 TRACE("Invalid level %d is specified\n", Level);
246 return ERROR_INVALID_LEVEL;
247 }
248 return NERR_Success;
249 }
250
251 /************************************************************
252 * NetGetDCName (NETAPI32.@)
253 *
254 * Return the name of the primary domain controller (PDC)
255 */
256
257 NET_API_STATUS WINAPI
258 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
259 {
260 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
261 debugstr_w(domainname), bufptr);
262 return NERR_DCNotFound; /* say we can't find a domain controller */
263 }
264
265
266 NET_API_STATUS WINAPI NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
267 {
268 FIXME("%s %d %p %p stub\n", debugstr_w(servername), level, bufptr, parm_err);
269 return NERR_Success;
270 }