12#include <com/sun/star/beans/Optional.hpp>
19#include <officecfg/UserProfile.hxx>
27#include <systools/win32/comtools.hxx>
28#include <systools/win32/oleauto.hxx>
41 virtual OUString
GetSn() {
return ""; }
64constexpr OUStringLiteral givenname(u
"givenname");
65constexpr OUStringLiteral sn(u
"sn");
66constexpr char fathersname[](
"fathersname");
67constexpr OUStringLiteral initials(u
"initials");
68constexpr OUStringLiteral street(u
"street");
69constexpr OUStringLiteral l(u
"l");
70constexpr OUStringLiteral st(u
"st");
71constexpr char apartment[](
"apartment");
72constexpr OUStringLiteral postalcode(u
"postalcode");
73constexpr OUStringLiteral c(u
"c");
74constexpr OUStringLiteral o(u
"o");
75constexpr char position[](
"position");
76constexpr OUStringLiteral title(u
"title");
77constexpr OUStringLiteral homephone(u
"homephone");
78constexpr OUStringLiteral telephonenumber(u
"telephonenumber");
79constexpr OUStringLiteral facsimiletelephonenumber(u
"facsimiletelephonenumber");
80constexpr OUStringLiteral mail(u
"mail");
92 sal::systools::CoInitializeGuard aCoInitializeGuard(COINIT_APARTMENTTHREADED);
94 sal::systools::COMReference<IADsADSystemInfo> pADsys(CLSID_ADSystemInfo,
nullptr,
95 CLSCTX_INPROC_SERVER);
97 sal::systools::BStr sUserDN;
98 sal::systools::ThrowIfFailed(pADsys->get_UserName(&sUserDN),
"get_UserName failed");
103 OUString sLdapUserDN =
"LDAP://" + m_sUserDN;
104 sal::systools::COMReference<IADsUser> pUser;
105 sal::systools::ThrowIfFailed(ADsGetObject(o3tl::toW(sLdapUserDN.getStr()), IID_IADsUser,
106 reinterpret_cast<void**
>(&pUser)),
107 "ADsGetObject failed");
110 m_aMap[givenname] = Str(pUser, &IADsUser::get_FirstName);
111 m_aMap[sn] = Str(pUser, &IADsUser::get_LastName);
112 m_aMap[initials] = Str(pUser, L
"initials");
113 m_aMap[street] = Str(pUser, L
"streetAddress");
114 m_aMap[l] = Str(pUser, L
"l");
115 m_aMap[st] = Str(pUser, L
"st");
116 m_aMap[postalcode] = Str(pUser, L
"postalCode");
117 m_aMap[c] = Str(pUser, L
"co");
118 m_aMap[o] = Str(pUser, L
"company");
119 m_aMap[title] = Str(pUser, &IADsUser::get_Title);
120 m_aMap[homephone] = Str(pUser, L
"homePhone");
121 m_aMap[telephonenumber] = Str(pUser, L
"TelephoneNumber");
122 m_aMap[facsimiletelephonenumber] = Str(pUser, L
"facsimileTelephoneNumber");
123 m_aMap[mail] = Str(pUser, &IADsUser::get_EmailAddress);
127 catch (sal::systools::ComError&)
134 virtual OUString
GetGivenName()
override {
return m_aMap[givenname]; }
135 virtual OUString
GetSn()
override {
return m_aMap[sn]; }
136 virtual OUString
GetInitials()
override {
return m_aMap[initials]; }
137 virtual OUString
GetStreet()
override {
return m_aMap[street]; }
138 virtual OUString
GetCity()
override {
return m_aMap[l]; }
139 virtual OUString
GetState()
override {
return m_aMap[st]; }
140 virtual OUString
GetPostalCode()
override {
return m_aMap[postalcode]; }
141 virtual OUString
GetCountry()
override {
return m_aMap[c]; }
143 virtual OUString
GetTitle()
override {
return m_aMap[title]; }
144 virtual OUString
GetHomePhone()
override {
return m_aMap[homephone]; }
146 virtual OUString
GetFaxNumber()
override {
return m_aMap[facsimiletelephonenumber]; }
147 virtual OUString
GetMail()
override {
return m_aMap[mail]; }
150 typedef HRESULT (__stdcall IADsUser::*getstrfunc)(BSTR*);
151 static OUString Str(IADsUser* pUser, getstrfunc func)
153 sal::systools::BStr sBstr;
154 if (FAILED((pUser->*func)(&sBstr)))
156 return OUString(sBstr);
158 static OUString Str(IADsUser* pUser,
const wchar_t*
property)
160 sal::systools::BStr sBstrProp{ o3tl::toU(
property) };
161 struct AutoVariant :
public VARIANT
163 AutoVariant() { VariantInit(
this); }
164 ~AutoVariant() { VariantClear(
this); }
166 if (FAILED(pUser->GetEx(sBstrProp, &varArr)))
168 SAFEARRAY* sa = V_ARRAY(&varArr);
170 if (FAILED(SafeArrayGetLBound(sa, 1, &nStart)) || FAILED(SafeArrayGetUBound(sa, 1, &nEnd)))
173 for (LONG i = nStart;
i <= nEnd;
i++)
175 if (FAILED(SafeArrayGetElement(sa, &i, &varItem)))
177 if (varItem.vt == VT_BSTR)
178 return OUString(o3tl::toU(V_BSTR(&varItem)));
179 VariantClear(&varItem);
188 OUString sCachedData =
"user=" + m_sUserDN
190 +
"\0" + sn +
"=" +
GetSn()
201 +
"\0" + facsimiletelephonenumber +
"=" +
GetFaxNumber()
202 +
"\0" + mail +
"=" +
GetMail();
203 const css::uno::Sequence<sal_Int8> seqCachedData(
204 reinterpret_cast<const sal_Int8*
>(sCachedData.getStr()),
206 OUStringBuffer sOutBuf;
209 std::shared_ptr<comphelper::ConfigurationChanges> batch(
211 officecfg::UserProfile::WinUserInfo::Cache::set(sOutBuf.makeStringAndClear(), batch);
214 catch (
const css::uno::Exception&)
217 "ADsUserAccess: access to configuration data failed:");
223 if (m_sUserDN.isEmpty())
224 throw css::uno::RuntimeException();
226 OUString sCache = officecfg::UserProfile::WinUserInfo::Cache::get();
228 if (sCache.isEmpty())
229 throw css::uno::RuntimeException();
232 css::uno::Sequence<sal_Int8> seqCachedData;
234 sCache = OUString(
reinterpret_cast<const sal_Unicode*
>(seqCachedData.getConstArray()),
239 std::map<const OUString, OUString>
aMap;
243 const OUString sEntry = sCache.getToken(0,
'\0', nIndex);
244 sal_Int32 nEqIndex = 0;
245 const OUString sEntryName = sEntry.getToken(0,
'=', nEqIndex);
248 sEntryVal = sEntry.copy(nEqIndex);
249 if (sEntryName ==
"user")
252 aMap[sEntryName] = sEntryVal;
253 }
while (nIndex >= 0);
255 if (sUserDN != m_sUserDN)
256 throw css::uno::RuntimeException();
257 m_aMap = std::move(aMap);
261 std::map<const OUString, OUString> m_aMap;
272 GetUserNameExW(NameDisplay,
nullptr, &nSize);
273 if (GetLastError() != ERROR_MORE_DATA)
274 throw css::uno::RuntimeException();
275 auto pNameBuf(std::make_unique<
wchar_t[]>(nSize));
276 if (!GetUserNameExW(NameDisplay, pNameBuf.get(), &nSize))
277 throw css::uno::RuntimeException();
278 m_sName = o3tl::toU(pNameBuf.get());
280 catch (css::uno::RuntimeException&)
285 DWORD nSize = UNLEN + 1;
286 auto pNameBuf(std::make_unique<
wchar_t[]>(nSize));
287 if (!GetUserNameW(pNameBuf.get(), &nSize))
288 throw css::uno::RuntimeException();
289 m_sName = o3tl::toU(pNameBuf.get());
312 m_pImpl.reset(
new ADsUserAccess());
314 catch (css::uno::RuntimeException&)
316 m_pImpl.reset(
new SysInfoUserAccess);
324 throw css::lang::IllegalArgumentException(
"setPropertyValue not supported",
332 OUString sToken = PropertyName.getToken(0,
' ').getToken(0,
',');
333 if (sToken == givenname)
335 sValue =
m_pImpl->GetGivenName();
337 else if (sToken == sn)
341 else if (sToken == fathersname)
343 sValue =
m_pImpl->GetFathersname();
345 else if (sToken == initials)
347 sValue =
m_pImpl->GetInitials();
349 else if (sToken == street)
353 else if (sToken == l)
357 else if (sToken == st)
361 else if (sToken == apartment)
363 sValue =
m_pImpl->GetApartment();
365 else if (sToken == postalcode)
367 sValue =
m_pImpl->GetPostalCode();
369 else if (sToken == c)
371 sValue =
m_pImpl->GetCountry();
373 else if (sToken == o)
375 sValue =
m_pImpl->GetOrganization();
379 sValue =
m_pImpl->GetPosition();
381 else if (sToken == title)
385 else if (sToken == homephone)
387 sValue =
m_pImpl->GetHomePhone();
389 else if (sToken == telephonenumber)
391 sValue =
m_pImpl->GetTelephoneNumber();
393 else if (sToken == facsimiletelephonenumber)
395 sValue =
m_pImpl->GetFaxNumber();
397 else if (sToken == mail)
402 throw css::beans::UnknownPropertyException(sToken,
static_cast<cppu::OWeakObject*
>(
this));
404 return css::uno::Any(css::beans::Optional<css::uno::Any>(
405 !sValue.isEmpty(), sValue.isEmpty() ? css::uno::Any() : css::uno::Any(sValue)));
410 return "com.sun.star.comp.configuration.backend.WinUserInfoBe";
420 return {
"com.sun.star.configuration.backend.WinUserInfoBe" };
426extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
428 css::uno::Sequence<css::uno::Any>
const&)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_WinUserInfoBe_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static void encode(OUStringBuffer &aStrBuffer, const css::uno::Sequence< sal_Int8 > &aPass)
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
static std::shared_ptr< ConfigurationChanges > create()
virtual OUString GetHomePhone()
virtual OUString GetState()
virtual OUString GetTitle()
virtual OUString GetCity()
virtual OUString GetStreet()
virtual OUString GetApartment()
virtual OUString GetFaxNumber()
virtual OUString GetPosition()
virtual OUString GetInitials()
virtual OUString GetGivenName()=0
virtual OUString GetCountry()
virtual OUString GetPostalCode()
virtual OUString GetOrganization()
virtual OUString GetFathersname()
virtual ~WinUserInfoBe_Impl()
virtual OUString GetTelephoneNumber()
virtual OUString GetMail()
Implements the PlatformBackend service, a specialization of the XPropertySet service for retrieving A...
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setPropertyValue(OUString const &, css::uno::Any const &) override
virtual css::uno::Any SAL_CALL getPropertyValue(OUString const &PropertyName) override
virtual OUString SAL_CALL getImplementationName() override
virtual ~WinUserInfoBe() override
virtual sal_Bool SAL_CALL supportsService(const OUString &aServiceName) override
std::unique_ptr< WinUserInfoBe_Impl > m_pImpl
#define TOOLS_WARN_EXCEPTION(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
cppu::WeakComponentImplHelper< css::beans::XPropertySet, css::lang::XServiceInfo > BackendBase
HashMap_OWString_Interface aMap