Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "com/sun/star/task/DocumentPasswordRequest.hpp"
21 : : #include "com/sun/star/task/DocumentPasswordRequest2.hpp"
22 : : #include "com/sun/star/task/DocumentMSPasswordRequest.hpp"
23 : : #include "com/sun/star/task/DocumentMSPasswordRequest2.hpp"
24 : : #include "com/sun/star/task/MasterPasswordRequest.hpp"
25 : : #include "com/sun/star/task/XInteractionAbort.hpp"
26 : : #include "com/sun/star/task/XInteractionPassword.hpp"
27 : : #include "com/sun/star/task/XInteractionPassword2.hpp"
28 : : #include "com/sun/star/task/XInteractionRetry.hpp"
29 : : #include "com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp"
30 : : #include "com/sun/star/ucb/URLAuthenticationRequest.hpp"
31 : :
32 : : #include "osl/diagnose.h"
33 : : #include "rtl/digest.h"
34 : : #include "osl/mutex.hxx"
35 : : #include "tools/errcode.hxx"
36 : : #include "vcl/msgbox.hxx"
37 : : #include "vcl/abstdlg.hxx"
38 : : #include "vcl/svapp.hxx"
39 : :
40 : : #include "ids.hrc"
41 : : #include "getcontinuations.hxx"
42 : : #include "passwordcontainer.hxx"
43 : : #include "loginerr.hxx"
44 : : #include "logindlg.hxx"
45 : : #include "masterpasscrtdlg.hxx"
46 : : #include "masterpassworddlg.hxx"
47 : : #include "passworddlg.hxx"
48 : :
49 : : #include "iahndl.hxx"
50 : :
51 : : #include <boost/scoped_ptr.hpp>
52 : :
53 : : using namespace com::sun::star;
54 : :
55 : : namespace {
56 : :
57 : : void
58 : 0 : executeLoginDialog(
59 : : Window * pParent,
60 : : LoginErrorInfo & rInfo,
61 : : rtl::OUString const & rRealm)
62 : : SAL_THROW((uno::RuntimeException))
63 : : {
64 : : try
65 : : {
66 [ # # ]: 0 : SolarMutexGuard aGuard;
67 : :
68 : 0 : bool bAccount = (rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_ACCOUNT) != 0;
69 : 0 : bool bSavePassword = rInfo.GetCanRememberPassword();
70 : 0 : bool bCanUseSysCreds = rInfo.GetCanUseSystemCredentials();
71 : :
72 : 0 : sal_uInt16 nFlags = 0;
73 [ # # ]: 0 : if (rInfo.GetPath().Len() == 0)
74 : 0 : nFlags |= LF_NO_PATH;
75 [ # # ]: 0 : if (rInfo.GetErrorText().Len() == 0)
76 : 0 : nFlags |= LF_NO_ERRORTEXT;
77 [ # # ]: 0 : if (!bAccount)
78 : 0 : nFlags |= LF_NO_ACCOUNT;
79 [ # # ]: 0 : if (!(rInfo.GetFlags() & LOGINERROR_FLAG_MODIFY_USER_NAME))
80 : 0 : nFlags |= LF_USERNAME_READONLY;
81 : :
82 [ # # ]: 0 : if (!bSavePassword)
83 : 0 : nFlags |= LF_NO_SAVEPASSWORD;
84 : :
85 [ # # ]: 0 : if (!bCanUseSysCreds)
86 : 0 : nFlags |= LF_NO_USESYSCREDS;
87 : :
88 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
89 : : boost::scoped_ptr< LoginDialog > xDialog(
90 [ # # ][ # # ]: 0 : new LoginDialog( pParent, nFlags, rInfo.GetServer(), rRealm, xManager.get()));
[ # # ]
91 [ # # ]: 0 : if (rInfo.GetErrorText().Len() != 0)
92 [ # # ]: 0 : xDialog->SetErrorText(rInfo.GetErrorText());
93 [ # # ]: 0 : xDialog->SetName(rInfo.GetUserName());
94 [ # # ]: 0 : if (bAccount)
95 [ # # ]: 0 : xDialog->ClearAccount();
96 : : else
97 [ # # ]: 0 : xDialog->ClearPassword();
98 [ # # ]: 0 : xDialog->SetPassword(rInfo.GetPassword());
99 : :
100 [ # # ]: 0 : if (bSavePassword)
101 : : {
102 : : xDialog->SetSavePasswordText(
103 : 0 : ResId(rInfo.GetIsRememberPersistent()
104 : : ? RID_SAVE_PASSWORD
105 : : : RID_KEEP_PASSWORD,
106 [ # # ][ # # ]: 0 : *xManager.get()));
[ # # ][ # # ]
107 : :
108 [ # # ]: 0 : xDialog->SetSavePassword(rInfo.GetIsRememberPassword());
109 : : }
110 : :
111 [ # # ]: 0 : if ( bCanUseSysCreds )
112 [ # # ]: 0 : xDialog->SetUseSystemCredentials( rInfo.GetIsUseSystemCredentials() );
113 : :
114 [ # # ]: 0 : rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK :
115 [ # # ]: 0 : ERRCODE_BUTTON_CANCEL);
116 [ # # ][ # # ]: 0 : rInfo.SetUserName(xDialog->GetName());
[ # # ]
117 [ # # ][ # # ]: 0 : rInfo.SetPassword(xDialog->GetPassword());
[ # # ]
118 [ # # ][ # # ]: 0 : rInfo.SetAccount(xDialog->GetAccount());
[ # # ]
119 [ # # ]: 0 : rInfo.SetIsRememberPassword(xDialog->IsSavePassword());
120 : :
121 [ # # ]: 0 : if ( bCanUseSysCreds )
122 [ # # ][ # # ]: 0 : rInfo.SetIsUseSystemCredentials( xDialog->IsUseSystemCredentials() );
[ # # ][ # # ]
123 : : }
124 [ # # ]: 0 : catch (std::bad_alloc const &)
125 : : {
126 : : throw uno::RuntimeException(
127 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
128 [ # # # # ]: 0 : uno::Reference< uno::XInterface >());
129 : : }
130 : 0 : }
131 : :
132 : 0 : void getRememberModes(
133 : : uno::Sequence< ucb::RememberAuthentication > const & rRememberModes,
134 : : ucb::RememberAuthentication & rPreferredMode,
135 : : ucb::RememberAuthentication & rAlternateMode )
136 : : {
137 : 0 : sal_Int32 nCount = rRememberModes.getLength();
138 : : OSL_ENSURE( (nCount > 0) && (nCount < 4),
139 : : "ucb::RememberAuthentication sequence size mismatch!" );
140 [ # # ]: 0 : if ( nCount == 1 )
141 : : {
142 : 0 : rPreferredMode = rAlternateMode = rRememberModes[ 0 ];
143 : 0 : return;
144 : : }
145 : : else
146 : : {
147 : 0 : bool bHasRememberModeSession = false;
148 : 0 : bool bHasRememberModePersistent = false;
149 : :
150 [ # # ]: 0 : for (sal_Int32 i = 0; i < nCount; ++i)
151 : : {
152 [ # # # # ]: 0 : switch ( rRememberModes[i] )
153 : : {
154 : : case ucb::RememberAuthentication_NO:
155 : 0 : break;
156 : : case ucb::RememberAuthentication_SESSION:
157 : 0 : bHasRememberModeSession = true;
158 : 0 : break;
159 : : case ucb::RememberAuthentication_PERSISTENT:
160 : 0 : bHasRememberModePersistent = true;
161 : 0 : break;
162 : : default:
163 : : OSL_TRACE( "Unsupported RememberAuthentication value" );
164 : 0 : break;
165 : : }
166 : : }
167 : :
168 [ # # ]: 0 : if (bHasRememberModePersistent)
169 : : {
170 : 0 : rPreferredMode = ucb::RememberAuthentication_PERSISTENT;
171 [ # # ]: 0 : if (bHasRememberModeSession)
172 : 0 : rAlternateMode = ucb::RememberAuthentication_SESSION;
173 : : else
174 : 0 : rAlternateMode = ucb::RememberAuthentication_NO;
175 : : }
176 : : else
177 : : {
178 : 0 : rPreferredMode = ucb::RememberAuthentication_SESSION;
179 : 0 : rAlternateMode = ucb::RememberAuthentication_NO;
180 : : }
181 : : }
182 : : }
183 : :
184 : : void
185 : 0 : handleAuthenticationRequest_(
186 : : Window * pParent,
187 : : uno::Reference< task::XInteractionHandler > const & xIH,
188 : : uno::Reference< lang::XMultiServiceFactory > const & xServiceFactory,
189 : : ucb::AuthenticationRequest const & rRequest,
190 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
191 : : rContinuations,
192 : : const rtl::OUString & rURL)
193 : : SAL_THROW((uno::RuntimeException))
194 : : {
195 : 0 : uno::Reference< task::XInteractionRetry > xRetry;
196 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
197 : : uno::Reference< ucb::XInteractionSupplyAuthentication >
198 : 0 : xSupplyAuthentication;
199 : : uno::Reference< ucb::XInteractionSupplyAuthentication2 >
200 : 0 : xSupplyAuthentication2;
201 [ # # ]: 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
202 [ # # ]: 0 : if (xSupplyAuthentication.is())
203 [ # # ]: 0 : xSupplyAuthentication2.set(xSupplyAuthentication, uno::UNO_QUERY);
204 : :
205 : : //////////////////////////
206 : : // First, try to obtain credentials from password container service.
207 [ # # ]: 0 : uui::PasswordContainerHelper aPwContainerHelper(xServiceFactory);
208 [ # # ][ # # ]: 0 : if (aPwContainerHelper.handleAuthenticationRequest(rRequest,
209 : : xSupplyAuthentication,
210 : : rURL,
211 : : xIH))
212 : : {
213 [ # # ][ # # ]: 0 : xSupplyAuthentication->select();
214 : 0 : return;
215 : : }
216 : :
217 : : //////////////////////////
218 : : // Second, try to obtain credentials from user via password dialog.
219 : : ucb::RememberAuthentication eDefaultRememberMode
220 : 0 : = ucb::RememberAuthentication_SESSION;
221 : : ucb::RememberAuthentication ePreferredRememberMode
222 : 0 : = eDefaultRememberMode;
223 : : ucb::RememberAuthentication eAlternateRememberMode
224 : 0 : = ucb::RememberAuthentication_NO;
225 : :
226 [ # # ]: 0 : if (xSupplyAuthentication.is())
227 : : {
228 : : getRememberModes(
229 [ # # ]: 0 : xSupplyAuthentication->getRememberPasswordModes(
230 : 0 : eDefaultRememberMode),
231 : : ePreferredRememberMode,
232 [ # # ][ # # ]: 0 : eAlternateRememberMode);
[ # # ]
233 : : }
234 : :
235 : : sal_Bool bCanUseSystemCredentials;
236 : : sal_Bool bDefaultUseSystemCredentials;
237 [ # # ]: 0 : if (xSupplyAuthentication2.is())
238 : : {
239 : : bCanUseSystemCredentials
240 [ # # ]: 0 : = xSupplyAuthentication2->canUseSystemCredentials(
241 [ # # ]: 0 : bDefaultUseSystemCredentials);
242 : : }
243 : : else
244 : : {
245 : 0 : bCanUseSystemCredentials = sal_False;
246 : 0 : bDefaultUseSystemCredentials = sal_False;
247 : : }
248 : :
249 [ # # ]: 0 : LoginErrorInfo aInfo;
250 [ # # ][ # # ]: 0 : aInfo.SetTitle(rRequest.ServerName);
[ # # ]
251 [ # # ][ # # ]: 0 : aInfo.SetServer(rRequest.ServerName);
[ # # ]
252 [ # # ]: 0 : if (rRequest.HasAccount)
253 [ # # ][ # # ]: 0 : aInfo.SetAccount(rRequest.Account);
[ # # ]
254 [ # # ]: 0 : if (rRequest.HasUserName)
255 [ # # ][ # # ]: 0 : aInfo.SetUserName(rRequest.UserName);
[ # # ]
256 [ # # ]: 0 : if (rRequest.HasPassword)
257 [ # # ][ # # ]: 0 : aInfo.SetPassword(rRequest.Password);
[ # # ]
258 [ # # ][ # # ]: 0 : aInfo.SetErrorText(rRequest.Diagnostic);
[ # # ]
259 : :
260 : : aInfo.SetCanRememberPassword(
261 : 0 : ePreferredRememberMode != eAlternateRememberMode);
262 : : aInfo.SetIsRememberPassword(
263 : 0 : ePreferredRememberMode == eDefaultRememberMode);
264 : : aInfo.SetIsRememberPersistent(
265 : 0 : ePreferredRememberMode == ucb::RememberAuthentication_PERSISTENT);
266 : :
267 : 0 : aInfo.SetCanUseSystemCredentials(bCanUseSystemCredentials);
268 : 0 : aInfo.SetIsUseSystemCredentials( bDefaultUseSystemCredentials );
269 : : aInfo.SetModifyAccount(rRequest.HasAccount
270 : 0 : && xSupplyAuthentication.is()
271 [ # # ][ # # ]: 0 : && xSupplyAuthentication->canSetAccount());
[ # # ]
[ # # # # ]
272 : : aInfo.SetModifyUserName(rRequest.HasUserName
273 : 0 : && xSupplyAuthentication.is()
274 [ # # ][ # # ]: 0 : && xSupplyAuthentication->canSetUserName());
[ # # ]
[ # # # # ]
275 : : executeLoginDialog(pParent,
276 : : aInfo,
277 [ # # ][ # # ]: 0 : rRequest.HasRealm ? rRequest.Realm : rtl::OUString());
278 [ # # # ]: 0 : switch (aInfo.GetResult())
279 : : {
280 : : case ERRCODE_BUTTON_OK:
281 [ # # ]: 0 : if (xSupplyAuthentication.is())
282 : : {
283 [ # # ][ # # ]: 0 : if (xSupplyAuthentication->canSetUserName())
[ # # ]
284 [ # # ][ # # ]: 0 : xSupplyAuthentication->setUserName(aInfo.GetUserName());
[ # # ]
285 [ # # ][ # # ]: 0 : if (xSupplyAuthentication->canSetPassword())
[ # # ]
286 [ # # ][ # # ]: 0 : xSupplyAuthentication->setPassword(aInfo.GetPassword());
[ # # ]
287 : :
288 [ # # ]: 0 : if (ePreferredRememberMode != eAlternateRememberMode)
289 : : {
290 : : // user had the choice.
291 [ # # ]: 0 : if (aInfo.GetIsRememberPassword())
292 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
293 [ # # ]: 0 : ePreferredRememberMode);
294 : : else
295 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
296 [ # # ]: 0 : eAlternateRememberMode);
297 : : }
298 : : else
299 : : {
300 : : // user had no choice.
301 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
302 [ # # ]: 0 : ePreferredRememberMode);
303 : : }
304 : :
305 [ # # ]: 0 : if (rRequest.HasRealm)
306 : : {
307 [ # # ][ # # ]: 0 : if (xSupplyAuthentication->canSetRealm())
[ # # ]
308 [ # # ][ # # ]: 0 : xSupplyAuthentication->setRealm(aInfo.GetAccount());
[ # # ]
309 : : }
310 [ # # ][ # # ]: 0 : else if (xSupplyAuthentication->canSetAccount())
[ # # ]
311 [ # # ][ # # ]: 0 : xSupplyAuthentication->setAccount(aInfo.GetAccount());
[ # # ]
312 : :
313 [ # # ][ # # ]: 0 : if ( xSupplyAuthentication2.is() && bCanUseSystemCredentials )
[ # # ]
314 [ # # ]: 0 : xSupplyAuthentication2->setUseSystemCredentials(
315 [ # # ]: 0 : aInfo.GetIsUseSystemCredentials() );
316 : :
317 [ # # ][ # # ]: 0 : xSupplyAuthentication->select();
318 : : }
319 : :
320 : : //////////////////////////
321 : : // Third, store credentials in password container.
322 : :
323 [ # # ]: 0 : if ( aInfo.GetIsUseSystemCredentials() )
324 : : {
325 [ # # ]: 0 : if (aInfo.GetIsRememberPassword())
326 : : {
327 [ # # ]: 0 : if (!aPwContainerHelper.addRecord(
328 : 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
329 : : rtl::OUString(), // empty u/p -> sys creds
330 : : uno::Sequence< rtl::OUString >(),
331 : : xIH,
332 : : ePreferredRememberMode
333 [ # # ][ # # ]: 0 : == ucb::RememberAuthentication_PERSISTENT))
[ # # ][ # # ]
334 : : {
335 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
336 [ # # ]: 0 : ucb::RememberAuthentication_NO);
337 : : }
338 : : }
339 [ # # ]: 0 : else if (eAlternateRememberMode
340 : : == ucb::RememberAuthentication_SESSION)
341 : : {
342 [ # # ]: 0 : if (!aPwContainerHelper.addRecord(
343 : 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
344 : : rtl::OUString(), // empty u/p -> sys creds
345 : : uno::Sequence< rtl::OUString >(),
346 : : xIH,
347 [ # # ][ # # ]: 0 : false /* SESSION */))
[ # # ][ # # ]
348 : : {
349 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
350 [ # # ]: 0 : ucb::RememberAuthentication_NO);
351 : : }
352 : : }
353 : : }
354 : : // Empty user name can not be valid:
355 [ # # ]: 0 : else if (aInfo.GetUserName().Len() != 0)
356 : : {
357 : : uno::Sequence< rtl::OUString >
358 [ # # ][ # # ]: 0 : aPassList(aInfo.GetAccount().Len() == 0 ? 1 : 2);
359 [ # # ][ # # ]: 0 : aPassList[0] = aInfo.GetPassword();
360 [ # # ]: 0 : if (aInfo.GetAccount().Len() != 0)
361 [ # # ][ # # ]: 0 : aPassList[1] = aInfo.GetAccount();
362 : :
363 [ # # ]: 0 : if (aInfo.GetIsRememberPassword())
364 : : {
365 [ # # ]: 0 : if (!aPwContainerHelper.addRecord(
366 : 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
367 : 0 : aInfo.GetUserName(),
368 : : aPassList,
369 : : xIH,
370 : : ePreferredRememberMode
371 [ # # ]: 0 : == ucb::RememberAuthentication_PERSISTENT))
[ # # # # ]
372 : : {
373 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
374 [ # # ]: 0 : ucb::RememberAuthentication_NO);
375 : : }
376 : : }
377 [ # # ]: 0 : else if (eAlternateRememberMode
378 : : == ucb::RememberAuthentication_SESSION)
379 : : {
380 [ # # ]: 0 : if (!aPwContainerHelper.addRecord(
381 : 0 : !rURL.isEmpty() ? rURL : rRequest.ServerName,
382 : 0 : aInfo.GetUserName(),
383 : : aPassList,
384 : : xIH,
385 [ # # ]: 0 : false /* SESSION */))
[ # # # # ]
386 : : {
387 [ # # ]: 0 : xSupplyAuthentication->setRememberPassword(
388 [ # # ]: 0 : ucb::RememberAuthentication_NO);
389 : : }
390 [ # # ]: 0 : }
391 : : }
392 : 0 : break;
393 : :
394 : : case ERRCODE_BUTTON_RETRY:
395 [ # # ]: 0 : if (xRetry.is())
396 [ # # ][ # # ]: 0 : xRetry->select();
397 : 0 : break;
398 : :
399 : : default:
400 [ # # ]: 0 : if (xAbort.is())
401 [ # # ][ # # ]: 0 : xAbort->select();
402 : 0 : break;
403 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
404 : : }
405 : :
406 : : void
407 : 0 : executeMasterPasswordDialog(
408 : : Window * pParent,
409 : : LoginErrorInfo & rInfo,
410 : : task::PasswordRequestMode nMode)
411 : : SAL_THROW((uno::RuntimeException))
412 : : {
413 : 0 : rtl::OString aMaster;
414 : : try
415 : : {
416 [ # # ]: 0 : SolarMutexGuard aGuard;
417 : :
418 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
419 [ # # ]: 0 : if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
420 : : {
421 : : boost::scoped_ptr< MasterPasswordCreateDialog > xDialog(
422 [ # # ][ # # ]: 0 : new MasterPasswordCreateDialog(pParent, xManager.get()));
423 [ # # ]: 0 : rInfo.SetResult(xDialog->Execute()
424 [ # # ]: 0 : == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
425 : : aMaster = rtl::OUStringToOString(
426 [ # # ][ # # ]: 0 : xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
[ # # ][ # # ]
[ # # ]
427 : : }
428 : : else
429 : : {
430 : : boost::scoped_ptr< MasterPasswordDialog > xDialog(
431 [ # # ][ # # ]: 0 : new MasterPasswordDialog(pParent, nMode, xManager.get()));
432 [ # # ]: 0 : rInfo.SetResult(xDialog->Execute()
433 [ # # ]: 0 : == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL);
434 : : aMaster = rtl::OUStringToOString(
435 [ # # ][ # # ]: 0 : xDialog->GetMasterPassword(), RTL_TEXTENCODING_UTF8);
[ # # ][ # # ]
[ # # ]
436 [ # # ][ # # ]: 0 : }
437 : : }
438 [ # # ]: 0 : catch (std::bad_alloc const &)
439 : : {
440 : : throw uno::RuntimeException(
441 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
442 [ # # # # ]: 0 : uno::Reference< uno::XInterface >());
443 : : }
444 : :
445 : : sal_uInt8 aKey[RTL_DIGEST_LENGTH_MD5];
446 : : rtl_digest_PBKDF2(aKey,
447 : : RTL_DIGEST_LENGTH_MD5,
448 : 0 : reinterpret_cast< sal_uInt8 const * >(aMaster.getStr()),
449 : 0 : aMaster.getLength(),
450 : : reinterpret_cast< sal_uInt8 const * >(
451 : : "3B5509ABA6BC42D9A3A1F3DAD49E56A51"),
452 : : 32,
453 : 0 : 1000);
454 : :
455 : 0 : rtl::OUStringBuffer aBuffer;
456 [ # # ]: 0 : for (int i = 0; i < RTL_DIGEST_LENGTH_MD5; ++i)
457 : : {
458 [ # # ]: 0 : aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] >> 4)));
459 [ # # ]: 0 : aBuffer.append(static_cast< sal_Unicode >('a' + (aKey[i] & 15)));
460 : : }
461 [ # # ][ # # ]: 0 : rInfo.SetPassword(aBuffer.makeStringAndClear());
[ # # ][ # # ]
462 : 0 : }
463 : :
464 : : void
465 : 0 : handleMasterPasswordRequest_(
466 : : Window * pParent,
467 : : task::PasswordRequestMode nMode,
468 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
469 : : rContinuations)
470 : : SAL_THROW((uno::RuntimeException))
471 : : {
472 : 0 : uno::Reference< task::XInteractionRetry > xRetry;
473 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
474 : : uno::Reference< ucb::XInteractionSupplyAuthentication >
475 : 0 : xSupplyAuthentication;
476 [ # # ]: 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xSupplyAuthentication);
477 [ # # ]: 0 : LoginErrorInfo aInfo;
478 : :
479 : : // in case of master password a hash code is returned
480 [ # # ]: 0 : executeMasterPasswordDialog(pParent, aInfo, nMode);
481 : :
482 [ # # # ]: 0 : switch (aInfo.GetResult())
483 : : {
484 : : case ERRCODE_BUTTON_OK:
485 [ # # ]: 0 : if (xSupplyAuthentication.is())
486 : : {
487 [ # # ][ # # ]: 0 : if (xSupplyAuthentication->canSetPassword())
[ # # ]
488 [ # # ][ # # ]: 0 : xSupplyAuthentication->setPassword(aInfo.GetPassword());
[ # # ]
489 [ # # ][ # # ]: 0 : xSupplyAuthentication->select();
490 : : }
491 : 0 : break;
492 : :
493 : : case ERRCODE_BUTTON_RETRY:
494 [ # # ]: 0 : if (xRetry.is())
495 [ # # ][ # # ]: 0 : xRetry->select();
496 : 0 : break;
497 : :
498 : : default:
499 [ # # ]: 0 : if (xAbort.is())
500 [ # # ][ # # ]: 0 : xAbort->select();
501 : 0 : break;
502 [ # # ]: 0 : }
503 : 0 : }
504 : :
505 : : void
506 : 0 : executePasswordDialog(
507 : : Window * pParent,
508 : : LoginErrorInfo & rInfo,
509 : : task::PasswordRequestMode nMode,
510 : : ::rtl::OUString aDocName,
511 : : bool bMSCryptoMode,
512 : : bool bIsPasswordToModify,
513 : : bool bIsSimplePasswordRequest )
514 : : SAL_THROW((uno::RuntimeException))
515 : : {
516 : : try
517 : : {
518 [ # # ]: 0 : SolarMutexGuard aGuard;
519 : :
520 [ # # ]: 0 : boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
521 [ # # ]: 0 : if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
522 : : {
523 [ # # ]: 0 : if (bIsSimplePasswordRequest)
524 : : {
525 : : boost::scoped_ptr< PasswordDialog > pDialog(
526 : : new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
527 [ # # ][ # # ]: 0 : bIsPasswordToModify, bIsSimplePasswordRequest ) );
528 : 0 : pDialog->SetMinLen(0);
529 : :
530 [ # # ][ # # ]: 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
531 [ # # ][ # # ]: 0 : rInfo.SetPassword( pDialog->GetPassword() );
[ # # ][ # # ]
532 : : }
533 : : else
534 : : {
535 [ # # ]: 0 : const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
536 : :
537 [ # # ]: 0 : VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
538 [ # # ]: 0 : AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
539 : 0 : boost::scoped_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
540 : :
541 [ # # ][ # # ]: 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
542 [ # # ][ # # ]: 0 : rInfo.SetPassword( pDialog->GetPasswordToOpen() );
[ # # ]
543 [ # # ][ # # ]: 0 : rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
[ # # ]
544 [ # # ][ # # ]: 0 : rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
545 : : }
546 : : }
547 : : else // enter password or reenter password
548 : : {
549 : : boost::scoped_ptr< PasswordDialog > pDialog(
550 : : new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
551 [ # # ][ # # ]: 0 : bIsPasswordToModify, bIsSimplePasswordRequest ) );
552 : 0 : pDialog->SetMinLen(0);
553 : :
554 [ # # ][ # # ]: 0 : rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
555 [ # # ][ # # ]: 0 : rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
[ # # ][ # # ]
[ # # ]
556 [ # # ][ # # ]: 0 : rInfo.SetPasswordToModify( bIsPasswordToModify ? pDialog->GetPassword() : String() );
[ # # ][ # # ]
[ # # ][ # # ]
557 [ # # ][ # # ]: 0 : }
558 : : }
559 [ # # ]: 0 : catch (std::bad_alloc const &)
560 : : {
561 : : throw uno::RuntimeException(
562 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
563 [ # # # # ]: 0 : uno::Reference< uno::XInterface>());
564 : : }
565 : 0 : }
566 : :
567 : : void
568 : 0 : handlePasswordRequest_(
569 : : Window * pParent,
570 : : task::PasswordRequestMode nMode,
571 : : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
572 : : rContinuations,
573 : : ::rtl::OUString aDocumentName,
574 : : bool bMSCryptoMode,
575 : : bool bIsPasswordToModify,
576 : : bool bIsSimplePasswordRequest = false )
577 : : SAL_THROW((uno::RuntimeException))
578 : : {
579 : 0 : uno::Reference< task::XInteractionRetry > xRetry;
580 : 0 : uno::Reference< task::XInteractionAbort > xAbort;
581 : 0 : uno::Reference< task::XInteractionPassword > xPassword;
582 : 0 : uno::Reference< task::XInteractionPassword2 > xPassword2;
583 [ # # ]: 0 : getContinuations(rContinuations, &xRetry, &xAbort, &xPassword2, &xPassword);
584 : :
585 [ # # ][ # # ]: 0 : if ( xPassword2.is() && !xPassword.is() )
[ # # ]
586 [ # # ]: 0 : xPassword.set( xPassword2, uno::UNO_QUERY_THROW );
587 : :
588 [ # # ]: 0 : LoginErrorInfo aInfo;
589 : :
590 : : executePasswordDialog( pParent, aInfo, nMode,
591 [ # # ]: 0 : aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
592 : :
593 [ # # # ]: 0 : switch (aInfo.GetResult())
594 : : {
595 : : case ERRCODE_BUTTON_OK:
596 : : OSL_ENSURE( !bIsPasswordToModify || xPassword2.is(), "PasswordToModify is requested, but there is no Interaction!" );
597 [ # # ]: 0 : if (xPassword.is())
598 : : {
599 [ # # ]: 0 : if (xPassword2.is())
600 : : {
601 [ # # ][ # # ]: 0 : xPassword2->setPasswordToModify( aInfo.GetPasswordToModify() );
[ # # ]
602 [ # # ][ # # ]: 0 : xPassword2->setRecommendReadOnly( aInfo.IsRecommendToOpenReadonly() );
603 : : }
604 : :
605 [ # # ][ # # ]: 0 : xPassword->setPassword(aInfo.GetPassword());
[ # # ]
606 [ # # ][ # # ]: 0 : xPassword->select();
607 : : }
608 : 0 : break;
609 : :
610 : : case ERRCODE_BUTTON_RETRY:
611 [ # # ]: 0 : if (xRetry.is())
612 [ # # ][ # # ]: 0 : xRetry->select();
613 : 0 : break;
614 : :
615 : : default:
616 [ # # ]: 0 : if (xAbort.is())
617 [ # # ][ # # ]: 0 : xAbort->select();
618 : 0 : break;
619 [ # # ]: 0 : }
620 : 0 : }
621 : :
622 : : } // namespace
623 : :
624 : : bool
625 : 0 : UUIInteractionHelper::handleAuthenticationRequest(
626 : : uno::Reference< task::XInteractionRequest > const & rRequest)
627 : : SAL_THROW((uno::RuntimeException))
628 : : {
629 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
630 : :
631 [ # # ]: 0 : ucb::URLAuthenticationRequest aURLAuthenticationRequest;
632 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aURLAuthenticationRequest)
633 : : {
634 : : handleAuthenticationRequest_(getParentProperty(),
635 : : getInteractionHandler(),
636 : : m_xServiceFactory,
637 : : aURLAuthenticationRequest,
638 [ # # ]: 0 : rRequest->getContinuations(),
639 [ # # ][ # # ]: 0 : aURLAuthenticationRequest.URL);
[ # # ][ # # ]
[ # # ]
640 : 0 : return true;
641 : : }
642 : :
643 [ # # ]: 0 : ucb::AuthenticationRequest aAuthenticationRequest;
644 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aAuthenticationRequest)
645 : : {
646 : : handleAuthenticationRequest_(getParentProperty(),
647 : : getInteractionHandler(),
648 : : m_xServiceFactory,
649 : : aAuthenticationRequest,
650 [ # # ]: 0 : rRequest->getContinuations(),
651 [ # # ][ # # ]: 0 : rtl::OUString());
[ # # ][ # # ]
[ # # ]
652 : 0 : return true;
653 : : }
654 [ # # ][ # # ]: 0 : return false;
655 : : }
656 : :
657 : : bool
658 : 0 : UUIInteractionHelper::handleMasterPasswordRequest(
659 : : uno::Reference< task::XInteractionRequest > const & rRequest)
660 : : SAL_THROW((uno::RuntimeException))
661 : : {
662 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
663 : :
664 [ # # ]: 0 : task::MasterPasswordRequest aMasterPasswordRequest;
665 [ # # ][ # # ]: 0 : if (aAnyRequest >>= aMasterPasswordRequest)
666 : : {
667 : : handleMasterPasswordRequest_(getParentProperty(),
668 : : aMasterPasswordRequest.Mode,
669 [ # # ][ # # ]: 0 : rRequest->getContinuations());
[ # # ][ # # ]
[ # # ]
670 : 0 : return true;
671 : : }
672 [ # # ]: 0 : return false;
673 : : }
674 : :
675 : : bool
676 : 0 : UUIInteractionHelper::handlePasswordRequest(
677 : : uno::Reference< task::XInteractionRequest > const & rRequest)
678 : : SAL_THROW((uno::RuntimeException))
679 : : {
680 : : // parameters to be filled for the call to handlePasswordRequest_
681 [ # # ]: 0 : Window * pParent = getParentProperty();
682 : 0 : task::PasswordRequestMode nMode = task::PasswordRequestMode_PASSWORD_ENTER;
683 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations = rRequest->getContinuations();
684 : 0 : ::rtl::OUString aDocumentName;
685 : 0 : bool bMSCryptoMode = false;
686 : 0 : bool bIsPasswordToModify = false;
687 : :
688 : 0 : bool bDoHandleRequest = false;
689 : :
690 [ # # ][ # # ]: 0 : uno::Any aAnyRequest(rRequest->getRequest());
691 : :
692 [ # # ]: 0 : task::DocumentPasswordRequest2 aDocumentPasswordRequest2;
693 [ # # ][ # # ]: 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest2))
[ # # ][ # # ]
694 : : {
695 : 0 : nMode = aDocumentPasswordRequest2.Mode;
696 : 0 : aDocumentName = aDocumentPasswordRequest2.Name;
697 : : OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
698 : 0 : bIsPasswordToModify = aDocumentPasswordRequest2.IsRequestPasswordToModify;
699 : :
700 : 0 : bDoHandleRequest = true;
701 : : }
702 : :
703 [ # # ]: 0 : task::DocumentPasswordRequest aDocumentPasswordRequest;
704 [ # # ][ # # ]: 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentPasswordRequest))
[ # # ][ # # ]
705 : : {
706 : 0 : nMode = aDocumentPasswordRequest.Mode;
707 : 0 : aDocumentName = aDocumentPasswordRequest.Name;
708 : : OSL_ENSURE( bMSCryptoMode == false, "bMSCryptoMode should be false" );
709 : : OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
710 : :
711 : 0 : bDoHandleRequest = true;
712 : : }
713 : :
714 [ # # ]: 0 : task::DocumentMSPasswordRequest2 aDocumentMSPasswordRequest2;
715 [ # # ][ # # ]: 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest2))
[ # # ][ # # ]
716 : : {
717 : 0 : nMode = aDocumentMSPasswordRequest2.Mode;
718 : 0 : aDocumentName = aDocumentMSPasswordRequest2.Name;
719 : 0 : bMSCryptoMode = true;
720 : 0 : bIsPasswordToModify = aDocumentMSPasswordRequest2.IsRequestPasswordToModify;
721 : :
722 : 0 : bDoHandleRequest = true;
723 : : }
724 : :
725 [ # # ]: 0 : task::DocumentMSPasswordRequest aDocumentMSPasswordRequest;
726 [ # # ][ # # ]: 0 : if (!bDoHandleRequest && (aAnyRequest >>= aDocumentMSPasswordRequest))
[ # # ][ # # ]
727 : : {
728 : 0 : nMode = aDocumentMSPasswordRequest.Mode;
729 : 0 : aDocumentName = aDocumentMSPasswordRequest.Name;
730 : 0 : bMSCryptoMode = true;
731 : : OSL_ENSURE( bIsPasswordToModify == false, "bIsPasswordToModify should be false" );
732 : :
733 : 0 : bDoHandleRequest = true;
734 : : }
735 : :
736 [ # # ]: 0 : if (bDoHandleRequest)
737 : : {
738 : : handlePasswordRequest_( pParent, nMode, rContinuations,
739 [ # # ]: 0 : aDocumentName, bMSCryptoMode, bIsPasswordToModify );
740 : 0 : return true;
741 : : }
742 : :
743 [ # # ]: 0 : task::PasswordRequest aPasswordRequest;
744 [ # # ][ # # ]: 0 : if( aAnyRequest >>= aPasswordRequest )
745 : : {
746 : : handlePasswordRequest_(getParentProperty(),
747 : : aPasswordRequest.Mode,
748 [ # # ]: 0 : rRequest->getContinuations(),
749 : : rtl::OUString(),
750 : : false /* bool bMSCryptoMode */,
751 : : false /* bool bIsPasswordToModify */,
752 [ # # ][ # # ]: 0 : true /* bool bIsSimplePasswordRequest */ );
[ # # ][ # # ]
753 : 0 : return true;
754 : : }
755 : :
756 [ # # ][ # # ]: 0 : return false;
[ # # ][ # # ]
[ # # ][ # # ]
757 : : }
758 : :
759 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|