1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
32 #include "osl/diagnose.h"
33 #include "rtl/ustring.h"
34 /*#include "libxml/xmlstring.h"
38 * Helper : create a input stream from a file
40 Reference
< XInputStream
> createStreamFromFile( const OUString sFile
)
42 const sal_Char
* pcFile
;
45 aString
= OUStringToOString( sFile
, RTL_TEXTENCODING_ASCII_US
) ;
46 pcFile
= aString
.getStr() ;
47 if( pcFile
!= NULL
) {
48 FILE *f
= fopen( pcFile
, "rb" );
49 Reference
< XInputStream
> r
;
52 fseek( f
, 0 , SEEK_END
);
53 int nLength
= ftell( f
);
54 fseek( f
, 0 , SEEK_SET
);
56 Sequence
<sal_Int8
> seqIn(nLength
);
57 fread( seqIn
.getArray() , nLength
, 1 , f
);
59 r
= Reference
< XInputStream
> ( new OInputStream( seqIn
) );
71 * Helper : set a output stream to a file
73 Reference
< XOutputStream
> createStreamToFile( const OUString sFile
)
75 const sal_Char
* pcFile
;
78 aString
= OUStringToOString( sFile
, RTL_TEXTENCODING_ASCII_US
) ;
79 pcFile
= aString
.getStr() ;
81 return Reference
< XOutputStream
>( new OOutputStream( pcFile
) ) ;
87 * Helper : get service manager and context
89 Reference
< XMultiComponentFactory
> serviceManager( Reference
< XComponentContext
>& xContext
, OUString sUnoUrl
, OUString sRdbUrl
) throw( RuntimeException
, Exception
)
91 Reference
< XMultiComponentFactory
> xLocalServiceManager
= NULL
;
92 Reference
< XComponentContext
> xLocalComponentContext
= NULL
;
93 Reference
< XMultiComponentFactory
> xUsedServiceManager
= NULL
;
94 Reference
< XComponentContext
> xUsedComponentContext
= NULL
;
96 OSL_ENSURE( !sUnoUrl
.equalsAscii( "" ) ,
98 "No uno URI specified" ) ;
100 OSL_ENSURE( !sRdbUrl
.equalsAscii( "" ) ,
102 "No rdb URI specified" ) ;
104 if( sUnoUrl
.equalsAscii( "local" ) ) {
105 Reference
< XSimpleRegistry
> xSimpleRegistry
= createSimpleRegistry();
106 OSL_ENSURE( xSimpleRegistry
.is() ,
108 "Cannot create simple registry" ) ;
110 //xSimpleRegistry->open(OUString::createFromAscii("xmlsecurity.rdb"), sal_False, sal_False);
111 xSimpleRegistry
->open(sRdbUrl
, sal_True
, sal_False
);
112 OSL_ENSURE( xSimpleRegistry
->isValid() ,
114 "Cannot open xml security registry rdb" ) ;
116 xLocalComponentContext
= bootstrap_InitialComponentContext( xSimpleRegistry
) ;
117 OSL_ENSURE( xLocalComponentContext
.is() ,
119 "Cannot create intial component context" ) ;
121 xLocalServiceManager
= xLocalComponentContext
->getServiceManager() ;
122 OSL_ENSURE( xLocalServiceManager
.is() ,
124 "Cannot create intial service manager" ) ;
127 * Because of the exception rasied from
128 * ucbhelper/source/provider/provconf.cxx, lin 323
129 * I do not use the content broker at present
130 ********************************************************************
132 if( ::ucb::ContentBroker::get() == NULL ) {
133 Reference< lang::XMultiServiceFactory > xSvmg( xLocalServiceManager , UNO_QUERY ) ;
134 OSL_ENSURE( xLocalServiceManager.is() ,
136 "Cannot get multi-service factory" ) ;
138 Sequence< Any > args( 2 ) ;
139 args[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL ) ;
140 args[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE ) ;
141 if( ! ::ucb::ContentBroker::initialize( xSvmg , args ) ) {
142 throw RuntimeException( OUString::createFromAscii( "Cannot inlitialize ContentBroker" ) , Reference< XInterface >() , Any() ) ;
145 ********************************************************************/
147 xUsedComponentContext
= xLocalComponentContext
;
148 xUsedServiceManager
= xLocalServiceManager
;
150 Reference
< XComponentContext
> xLocalComponentContext
= defaultBootstrap_InitialComponentContext() ;
151 OSL_ENSURE( xLocalComponentContext
.is() ,
153 "Cannot create intial component context" ) ;
155 Reference
< XMultiComponentFactory
> xLocalServiceManager
= xLocalComponentContext
->getServiceManager();
156 OSL_ENSURE( xLocalServiceManager
.is() ,
158 "Cannot create intial service manager" ) ;
160 Reference
< XInterface
> urlResolver
=
161 xLocalServiceManager
->createInstanceWithContext( OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver") , xLocalComponentContext
) ;
162 OSL_ENSURE( urlResolver
.is() ,
164 "Cannot get service instance of \"bridge.UnoUrlResolver\"" ) ;
166 Reference
< XUnoUrlResolver
> xUnoUrlResolver( urlResolver
, UNO_QUERY
) ;
167 OSL_ENSURE( xUnoUrlResolver
.is() ,
169 "Cannot get interface of \"XUnoUrlResolver\" from service \"bridge.UnoUrlResolver\"" ) ;
171 Reference
< XInterface
> initialObject
= xUnoUrlResolver
->resolve( sUnoUrl
) ;
172 OSL_ENSURE( initialObject
.is() ,
174 "Cannot resolve uno url" ) ;
177 * Method 1: with Naming Service
178 ********************************************************************
179 Reference< XNamingService > xNamingService( initialObject , UNO_QUERY ) ;
180 OSL_ENSURE( xNamingService.is() ,
182 "Cannot get interface of \"XNamingService\" from URL resolver" ) ;
184 Reference< XInterface > serviceManager =
185 xNamingService->getRegisteredObject( OUString::createFromAscii( "StarOffice.ServiceManager" ) ) ;
186 OSL_ENSURE( serviceManager.is() ,
188 "Cannot get service instance of \"StarOffice.ServiceManager\"" ) ;
190 xUsedServiceManager = Reference< XMultiComponentFactory >( serviceManager , UNO_QUERY );
191 OSL_ENSURE( xUsedServiceManager.is() ,
193 "Cannot get interface of \"XMultiComponentFactory\" from service \"StarOffice.ServiceManager\"" ) ;
195 Reference< XPropertySet > xPropSet( xUsedServiceManager , UNO_QUERY ) ;
196 OSL_ENSURE( xPropSet.is() ,
198 "Cannot get interface of \"XPropertySet\" from service \"StarOffice.ServiceManager\"" ) ;
200 xPropSet->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext ;
201 OSL_ENSURE( xUsedComponentContext.is() ,
203 "Cannot create remote component context" ) ;
205 ********************************************************************/
208 * Method 2: with Componnent context
209 ********************************************************************
210 Reference< XPropertySet > xPropSet( initialObject , UNO_QUERY ) ;
211 OSL_ENSURE( xPropSet.is() ,
213 "Cannot get interface of \"XPropertySet\" from URL resolver" ) ;
215 xPropSet->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext ;
216 OSL_ENSURE( xUsedComponentContext.is() ,
218 "Cannot create remote component context" ) ;
220 xUsedServiceManager = xUsedComponentContext->getServiceManager();
221 OSL_ENSURE( xUsedServiceManager.is() ,
223 "Cannot create remote service manager" ) ;
224 ********************************************************************/
227 * Method 3: with Service Manager
228 ********************************************************************/
229 xUsedServiceManager
= Reference
< XMultiComponentFactory
>( initialObject
, UNO_QUERY
);
230 OSL_ENSURE( xUsedServiceManager
.is() ,
232 "Cannot create remote service manager" ) ;
234 Reference
< XPropertySet
> xPropSet( xUsedServiceManager
, UNO_QUERY
) ;
235 OSL_ENSURE( xPropSet
.is() ,
237 "Cannot get interface of \"XPropertySet\" from service \"StarOffice.ServiceManager\"" ) ;
239 xPropSet
->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext
;
240 OSL_ENSURE( xUsedComponentContext
.is() ,
242 "Cannot create remote component context" ) ;
243 /********************************************************************/
246 xContext
= xUsedComponentContext
;
247 return xUsedServiceManager
;
250 char* PriPK11PasswordFunc(
255 char* passwd
= NULL
;
257 if( retry
!= PR_TRUE
) {
258 passwd
= ( char* )PORT_Alloc( 20 ) ;
259 printf( "Input Password:\n" ) ;
260 scanf( "%s" , passwd
) ;
261 printf( "The passwod is [%s]\n" , passwd
) ;