2 * Copyright 2002 Andriy Palamarchuk
4 * netapi32 access functions
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.
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.
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
23 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
26 /************************************************************
27 * ACCESS_QueryAdminDisplayInformation
29 * Creates a buffer with information for the Admin User
31 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
33 static const WCHAR sAdminUserName
[] = {
34 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
36 /* sizes of the field buffers in WCHARS */
37 int name_sz
, comment_sz
, full_name_sz
;
38 PNET_DISPLAY_USER usr
;
41 name_sz
= lstrlenW(sAdminUserName
) + 1;
45 *pdwSize
= sizeof(NET_DISPLAY_USER
);
46 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
47 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) 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
));
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;
65 /************************************************************
66 * ACCESS_QueryGuestDisplayInformation
68 * Creates a buffer with information for the Guest User
70 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
72 static const WCHAR sGuestUserName
[] = {
73 'G','u','e','s','t',0 };
75 /* sizes of the field buffers in WCHARS */
76 int name_sz
, comment_sz
, full_name_sz
;
77 PNET_DISPLAY_USER usr
;
80 name_sz
= lstrlenW(sGuestUserName
) + 1;
84 *pdwSize
= sizeof(NET_DISPLAY_USER
);
85 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
86 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) 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
));
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;
105 /************************************************************
106 * Copies NET_DISPLAY_USER record.
108 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
109 PNET_DISPLAY_USER src
)
111 LPWSTR str
= *dest_buf
;
113 src
->usri1_name
= str
;
114 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
116 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
118 src
->usri1_comment
= str
;
119 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
121 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
123 src
->usri1_flags
= dest
->usri1_flags
;
125 src
->usri1_full_name
= str
;
126 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
128 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
130 src
->usri1_user_id
= dest
->usri1_user_id
;
131 src
->usri1_next_index
= dest
->usri1_next_index
;
135 /************************************************************
136 * NetQueryDisplayInformation (NETAPI32.@)
138 * The buffer structure:
139 * - array of fixed size record of the level type
140 * - strings, referenced by the record of the level type
142 NET_API_STATUS WINAPI
143 NetQueryDisplayInformation(
144 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
145 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
148 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
149 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
150 ReturnedEntryCount
, SortedBuffer
);
152 if(!NETAPI_IsLocalComputer(ServerName
))
154 FIXME("Only implemented on local computer, but requested for "
155 "remote server %s\n", debugstr_w(ServerName
));
156 return ERROR_ACCESS_DENIED
;
164 PNET_DISPLAY_USER inf
;
165 /* current available strings buffer */
167 PNET_DISPLAY_USER admin
, guest
;
168 DWORD admin_size
, guest_size
;
172 /* sizes of the field buffers in WCHARS */
173 int name_sz
, comment_sz
, full_name_sz
;
175 /* number of the records, returned in SortedBuffer
176 3 - for current user, Administrator and Guest users
180 FIXME("Level %d partially implemented\n", Level
);
181 *ReturnedEntryCount
= records
;
187 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
188 if (!GetUserNameW(name
, &dwSize
))
190 NetApiBufferFree(name
);
191 return ERROR_ACCESS_DENIED
;
194 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
195 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
198 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
199 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
201 NetApiBufferAllocate(dwSize
+
202 admin_size
- sizeof(NET_DISPLAY_USER
) +
203 guest_size
- sizeof(NET_DISPLAY_USER
),
206 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
207 inf
->usri1_name
= str
;
209 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
210 inf
->usri1_comment
= str
;
212 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
213 inf
->usri1_full_name
= str
;
215 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
218 lstrcpyW(inf
->usri1_name
, name
);
219 NetApiBufferFree(name
);
220 inf
->usri1_comment
[0] = 0;
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;
228 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
229 NetApiBufferFree(admin
);
232 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
233 NetApiBufferFree(guest
);
240 FIXME("Level %d is not implemented\n", Level
);
245 TRACE("Invalid level %d is specified\n", Level
);
246 return ERROR_INVALID_LEVEL
;
251 /************************************************************
252 * NetGetDCName (NETAPI32.@)
254 * Return the name of the primary domain controller (PDC)
257 NET_API_STATUS WINAPI
258 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
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 */
266 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
268 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);