4 * Copyright 2018 Dmitry Timoshkov
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
31 #define SECURITY_WIN32
34 #include "wine/test.h"
36 static WCHAR
*strchrW(const WCHAR
*str
, WCHAR ch
)
38 do { if (*str
== ch
) return (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
42 static void test_ComputerName(void)
44 static const WCHAR cnW
[] = { 'C','N','=' };
45 static const WCHAR ComputersW
[] = { 'C','N','=','C','o','m','p','u','t','e','r','s' };
47 ULONG size
, name_size
;
48 WCHAR name
[MAX_COMPUTERNAME_LENGTH
+ 1];
50 IADsADSystemInfo
*sysinfo
;
54 name_size
= MAX_COMPUTERNAME_LENGTH
+ 1;
55 SetLastError(0xdeadbeef);
56 ret
= GetComputerNameW(name
, &name_size
);
57 ok(ret
, "GetComputerName error %u\n", GetLastError());
59 /* Distinguished name (rfc1779) is supposed to look like this:
60 * "CN=COMPNAME,CN=Computers,DC=domain,DC=com"
64 SetLastError(0xdeadbeef);
65 ret
= GetComputerObjectNameW(NameFullyQualifiedDN
, buf
, &size
);
66 ok(ret
|| GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO
, "GetComputerObjectName error %u\n", GetLastError());
70 ok(size
== lstrlenW(buf
) + 1, "got %u, expected %u\n", size
, lstrlenW(buf
) + 1);
71 ok(!memcmp(buf
, cnW
, sizeof(cnW
)), "got %s\n", wine_dbgstr_w(buf
));
72 ok(!memcmp(buf
+ 3, name
, name_size
), "got %s (name_size = %u)\n", wine_dbgstr_w(buf
), name_size
);
73 p
= strchrW(buf
, ',');
74 ok(p
!= NULL
, "delimiter was not found\n");
75 ok(p
&& !memcmp(p
+ 1, ComputersW
, sizeof(ComputersW
)), "got %s\n", p
? wine_dbgstr_w(p
+ 1) : wine_dbgstr_w(buf
));
78 hr
= CoCreateInstance(&CLSID_ADSystemInfo
, 0, CLSCTX_ALL
, &IID_IADsADSystemInfo
, (void **)&sysinfo
);
79 ok(hr
== S_OK
, "got %#x\n", hr
);
81 hr
= IADsADSystemInfo_get_ComputerName(sysinfo
, &bstr
);
83 ok(hr
== S_OK
|| hr
== HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO
), "got %#x\n", hr
);
86 ok(!lstrcmpW(bstr
, buf
), "got %s, expected %s\n", wine_dbgstr_w(bstr
), wine_dbgstr_w(buf
));
90 IADsADSystemInfo_Release(sysinfo
);
93 static void test_UserName(void)
95 static const WCHAR cnW
[] = { 'C','N','=' };
96 static const WCHAR UsersW
[] = { 'C','N','=','U','s','e','r','s' };
98 ULONG size
, name_size
;
101 IADsADSystemInfo
*sysinfo
;
106 SetLastError(0xdeadbeef);
107 ret
= GetUserNameW(name
, &name_size
);
108 ok(ret
, "GetUserName error %u\n", GetLastError());
110 /* Distinguished name (rfc1779) is supposed to look like this:
111 * "CN=username,CN=Users,DC=domain,DC=com"
115 SetLastError(0xdeadbeef);
116 ret
= GetUserNameExW(NameFullyQualifiedDN
, buf
, &size
);
117 ok(ret
|| GetLastError() == ERROR_NONE_MAPPED
, "GetUserNameEx error %u\n", GetLastError());
121 ok(size
== lstrlenW(buf
), "got %u, expected %u\n", size
, lstrlenW(buf
));
122 ok(!memcmp(buf
, cnW
, sizeof(cnW
)), "got %s\n", wine_dbgstr_w(buf
));
123 ok(!memcmp(buf
+ 3, name
, name_size
), "got %s (name_size = %u)\n", wine_dbgstr_w(buf
), name_size
);
124 p
= strchrW(buf
, ',');
125 ok(p
!= NULL
, "delimiter was not found\n");
126 ok(p
&& !memcmp(p
+ 1, UsersW
, sizeof(UsersW
)), "got %s\n", p
? wine_dbgstr_w(p
+ 1) : wine_dbgstr_w(buf
));
129 hr
= CoCreateInstance(&CLSID_ADSystemInfo
, 0, CLSCTX_ALL
, &IID_IADsADSystemInfo
, (void **)&sysinfo
);
130 ok(hr
== S_OK
, "got %#x\n", hr
);
132 hr
= IADsADSystemInfo_get_UserName(sysinfo
, &bstr
);
134 ok(hr
== S_OK
|| hr
== HRESULT_FROM_WIN32(ERROR_NONE_MAPPED
), "got %#x\n", hr
);
137 ok(!lstrcmpW(bstr
, buf
), "got %s, expected %s\n", wine_dbgstr_w(bstr
), wine_dbgstr_w(buf
));
141 IADsADSystemInfo_Release(sysinfo
);
144 static void test_sysinfo(void)
147 IADsADSystemInfo
*sysinfo
;
153 hr
= CoCreateInstance(&CLSID_ADSystemInfo
, 0, CLSCTX_ALL
, &IID_IUnknown
, (void **)&sysinfo
);
154 ok(hr
== S_OK
, "got %#x\n", hr
);
155 IADsADSystemInfo_Release(sysinfo
);
157 hr
= CoCreateInstance(&CLSID_ADSystemInfo
, 0, CLSCTX_ALL
, &IID_IADsADSystemInfo
, (void **)&sysinfo
);
158 ok(hr
== S_OK
, "got %#x\n", hr
);
160 hr
= IADsADSystemInfo_QueryInterface(sysinfo
, &IID_IDispatch
, (void **)&dispatch
);
161 ok(hr
== S_OK
, "got %#x\n", hr
);
162 IDispatch_Release(dispatch
);
164 hr
= IADsADSystemInfo_get_UserName(sysinfo
, &bstr
);
166 ok(hr
== S_OK
|| hr
== HRESULT_FROM_WIN32(ERROR_NONE_MAPPED
), "got %#x\n", hr
);
169 skip("Computer is not part of a domain, skipping the tests\n");
170 IADsADSystemInfo_Release(sysinfo
);
175 hr
= IADsADSystemInfo_get_ComputerName(sysinfo
, &bstr
);
176 ok(hr
== S_OK
, "got %#x\n", hr
);
177 if (hr
== S_OK
) SysFreeString(bstr
);
179 hr
= IADsADSystemInfo_get_SiteName(sysinfo
, &bstr
);
180 ok(hr
== S_OK
, "got %#x\n", hr
);
181 if (hr
== S_OK
) SysFreeString(bstr
);
183 hr
= IADsADSystemInfo_get_DomainShortName(sysinfo
, &bstr
);
184 ok(hr
== S_OK
, "got %#x\n", hr
);
185 if (hr
== S_OK
) SysFreeString(bstr
);
187 hr
= IADsADSystemInfo_get_DomainDNSName(sysinfo
, &bstr
);
188 ok(hr
== S_OK
, "got %#x\n", hr
);
189 if (hr
== S_OK
) SysFreeString(bstr
);
191 hr
= IADsADSystemInfo_get_ForestDNSName(sysinfo
, &bstr
);
192 ok(hr
== S_OK
, "got %#x\n", hr
);
193 if (hr
== S_OK
) SysFreeString(bstr
);
195 hr
= IADsADSystemInfo_get_PDCRoleOwner(sysinfo
, &bstr
);
196 ok(hr
== S_OK
, "got %#x\n", hr
);
197 if (hr
== S_OK
) SysFreeString(bstr
);
199 hr
= IADsADSystemInfo_get_IsNativeMode(sysinfo
, &value
);
200 ok(hr
== S_OK
, "got %#x\n", hr
);
201 if (hr
== S_OK
) ok(value
== VARIANT_TRUE
, "IsNativeMode: %s\n", value
== VARIANT_TRUE
? "yes" : "no");
203 hr
= IADsADSystemInfo_GetAnyDCName(sysinfo
, &bstr
);
204 ok(hr
== S_OK
, "got %#x\n", hr
);
205 if (hr
== S_OK
) SysFreeString(bstr
);
207 IADsADSystemInfo_Release(sysinfo
);
214 hr
= CoInitialize(NULL
);
215 ok(hr
== S_OK
, "got %#x\n", hr
);