View | Details | Raw Unified | Return to issue 60696
Collapse All | Expand All

(-)desktop/source/app/officeipcthread.cxx (-46 / +12 lines)
Lines 54-62 Link Here
54
#ifndef _UTL_CONFIGMGR_HXX_
54
#ifndef _UTL_CONFIGMGR_HXX_
55
#include <unotools/configmgr.hxx>
55
#include <unotools/configmgr.hxx>
56
#endif
56
#endif
57
#ifndef _THREAD_HXX_
57
#ifndef _OSL_THREAD_HXX_
58
#include <osl/thread.hxx>
58
#include <osl/thread.hxx>
59
#endif
59
#endif
60
#ifndef _OSL_FILE_HXX_
61
#include <osl/file.hxx>
62
#endif
63
#include <officePipeHelper.hxx>
60
#ifndef _RTL_DIGEST_H_
64
#ifndef _RTL_DIGEST_H_
61
#include <rtl/digest.h>
65
#include <rtl/digest.h>
62
#endif
66
#endif
Lines 78-84 Link Here
78
#include <comphelper/processfactory.hxx>
79
#include <comphelper/processfactory.hxx>
79
#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
80
#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
80
81
81
82
using namespace vos;
82
using namespace vos;
83
using namespace rtl;
83
using namespace rtl;
84
using namespace desktop;
84
using namespace desktop;
Lines 112-147 namespace { struct Security : public rtl Link Here
112
::osl::Mutex*		OfficeIPCThread::pOfficeIPCThreadMutex = 0;
112
::osl::Mutex*		OfficeIPCThread::pOfficeIPCThreadMutex = 0;
113
113
114
114
115
String CreateMD5FromString( const OUString& aMsg )
116
{
117
	// PRE: aStr "file"
118
	// BACK: Str "ababab....0f" Hexcode String
119
120
	rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
121
	if ( handle > 0 )
122
	{
123
		const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
124
		sal_uInt32		 nSize = ( aMsg.getLength() * sizeof( sal_Unicode ));
125
		sal_uInt32		 nMD5KeyLen = rtl_digest_queryLength( handle );
126
		sal_uInt8*		 pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ];
127
128
		rtl_digest_init( handle, pData, nSize );
129
		rtl_digest_update( handle, pData, nSize );
130
		rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen );
131
		rtl_digest_destroy( handle );
132
133
		// Create hex-value string from the MD5 value to keep the string size minimal
134
		OUStringBuffer aBuffer( nMD5KeyLen * 2 + 1 );
135
		for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ )
136
			aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 );
137
138
		delete [] pMD5KeyBuffer;
139
		return aBuffer.makeStringAndClear();
140
	}
141
142
	return String();
143
}
144
145
class ProcessEventsClass_Impl
115
class ProcessEventsClass_Impl
146
{
116
{
147
public:
117
public:
Lines 304-327 OfficeIPCThread::Status OfficeIPCThread: Link Here
304
	if( pGlobalOfficeIPCThread )
274
	if( pGlobalOfficeIPCThread )
305
		return IPC_STATUS_OK;
275
		return IPC_STATUS_OK;
306
276
307
	::rtl::OUString aUserInstallPath;
308
    ::rtl::OUString aDummy;
309
310
	::vos::OStartupInfo aInfo;
277
	::vos::OStartupInfo aInfo;
311
	OfficeIPCThread* pThread = new OfficeIPCThread;
278
	OfficeIPCThread* pThread = new OfficeIPCThread;
312
279
313
	pThread->maPipeIdent = OUString( RTL_CONSTASCII_USTRINGPARAM( "SingleOfficeIPC_" ) );
314
315
	// The name of the named pipe is created with the hashcode of the user installation directory (without /user). We have to retrieve
280
	// The name of the named pipe is created with the hashcode of the user installation directory (without /user). We have to retrieve
316
	// this information from a unotools implementation.
281
	// this information from a unotools implementation.
317
	::utl::Bootstrap::PathStatus aLocateResult = ::utl::Bootstrap::locateUserInstallation( aUserInstallPath );
282
318
	if ( aLocateResult == ::utl::Bootstrap::PATH_EXISTS || aLocateResult == ::utl::Bootstrap::PATH_VALID)
283
	const OfficePipeNameData& aData = OfficePipeHelper::get();
319
		aDummy = aUserInstallPath;
284
	::rtl::OUString aDummy = aData.PipeNamePostfix();
320
	else
285
	pThread->maPipeIdent = aData.PipeNamePrefix();
321
	{
322
		delete pThread;
323
		return IPC_STATUS_BOOTSTRAP_ERROR;
324
	}
325
286
326
	// Try to  determine if we are the first office or not! This should prevent multiple
287
	// Try to  determine if we are the first office or not! This should prevent multiple
327
	// access to the user directory !
288
	// access to the user directory !
Lines 361-367 OfficeIPCThread::Status OfficeIPCThread: Link Here
361
		aUserInstallPathHashCode = OUString( szBuffer, strlen(szBuffer), osl_getThreadTextEncoding() );
322
		aUserInstallPathHashCode = OUString( szBuffer, strlen(szBuffer), osl_getThreadTextEncoding() );
362
    }
323
    }
363
	else
324
	else
364
		aUserInstallPathHashCode = CreateMD5FromString( aDummy );
325
	{
326
		aUserInstallPathHashCode = aData.PipeNamePostfix();
327
	}
365
	
328
	
366
329
367
	// Check result to create a hash code from the user install path
330
	// Check result to create a hash code from the user install path
(-)desktop/source/deployment/misc/dp_misc.cxx (-47 / +4 lines)
Lines 35-40 Link Here
35
35
36
#include "dp_misc.h"
36
#include "dp_misc.h"
37
#include "dp_interact.h"
37
#include "dp_interact.h"
38
#include "officePipeHelper.hxx"
38
#include "rtl/uri.hxx"
39
#include "rtl/uri.hxx"
39
#include "rtl/digest.h"
40
#include "rtl/digest.h"
40
#include "rtl/random.h"
41
#include "rtl/random.h"
Lines 53-58 Link Here
53
54
54
using namespace ::com::sun::star;
55
using namespace ::com::sun::star;
55
using namespace ::com::sun::star::uno;
56
using namespace ::com::sun::star::uno;
57
using namespace desktop;
56
using ::rtl::OUString;
58
using ::rtl::OUString;
57
59
58
namespace dp_misc {
60
namespace dp_misc {
Lines 99-151 struct OfficePipeId : public rtl::Static Link Here
99
101
100
const OUString OfficePipeId::operator () ()
102
const OUString OfficePipeId::operator () ()
101
{
103
{
102
    OUString userPath = OUSTR("${$SYSBINDIR/" SAL_CONFIGFILE("bootstrap")
104
	const OfficePipeNameData& aData = OfficePipeHelper::get();
103
                              ":UserInstallation}");
105
	return aData.PipeName();
104
    ::rtl::Bootstrap::expandMacros( userPath );
105
    OSL_ASSERT( userPath.getLength() > 0 );
106
    
107
    // normalize path:
108
    ::osl::FileStatus status( FileStatusMask_FileURL );
109
    ::osl::DirectoryItem dirItem;
110
    if (::osl::DirectoryItem::get( userPath, dirItem )
111
        != ::osl::DirectoryItem::E_None ||
112
        dirItem.getFileStatus( status )
113
        != ::osl::DirectoryItem::E_None ||
114
        !status.isValid( FileStatusMask_FileURL ) ||
115
        ::osl::FileBase::getAbsoluteFileURL(
116
            OUString(), status.getFileURL(), userPath )
117
        != ::osl::FileBase::E_None)
118
    {
119
        throw RuntimeException(
120
            OUSTR("No valid file URL in " SAL_CONFIGFILE("bootstrap") ": ") +
121
            userPath, Reference<XInterface>() );
122
    }
123
    
124
    rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
125
    if (digest <= 0) {
126
        throw RuntimeException(
127
            OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 );
128
    }
129
    
130
    sal_uInt8 const * data =
131
        reinterpret_cast<sal_uInt8 const *>(userPath.getStr());
132
    sal_Size size = (userPath.getLength() * sizeof (sal_Unicode));
133
    sal_uInt32 md5_key_len = rtl_digest_queryLength( digest );
134
    ::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] );
135
    
136
    rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) );
137
    rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) );
138
    rtl_digest_get( digest, md5_buf.get(), md5_key_len );
139
    rtl_digest_destroy( digest );
140
    
141
    // create hex-value string from the MD5 value to keep
142
    // the string size minimal
143
    ::rtl::OUStringBuffer buf;
144
    buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SingleOfficeIPC_") );
145
    for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) {
146
        buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 );
147
    }
148
    return buf.makeStringAndClear();
149
}
106
}
150
107
151
} // anon namespace
108
} // anon namespace
(-) (+151 lines)
Added Link Here
1
/*************************************************************************
2
 *
3
 *  OpenOffice.org - a multi-platform office productivity suite
4
 *
5
 *  $RCSfile: speed-splash-ipc-name.diff,v $
6
 *
7
 *  $Revision: 1.5 $
8
 *
9
 *  last change: $Author: noelpwer $ $Date: 2006/01/19 09:36:18 $
10
 *
11
 *  The Contents of this file are made available subject to
12
 *  the terms of GNU Lesser General Public License Version 2.1.
13
 *
14
 *
15
 *    GNU Lesser General Public License Version 2.1
16
 *    =============================================
17
 *    Copyright 2005 by Sun Microsystems, Inc.
18
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
19
 *
20
 *    This library is free software; you can redistribute it and/or
21
 *    modify it under the terms of the GNU Lesser General Public
22
 *    License version 2.1, as published by the Free Software Foundation.
23
 *
24
 *    This library is distributed in the hope that it will be useful,
25
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
 *    Lesser General Public License for more details.
28
 *
29
 *    You should have received a copy of the GNU Lesser General Public
30
 *    License along with this library; if not, write to the Free Software
31
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32
 *    MA  02111-1307  USA
33
 *
34
 ************************************************************************/
35
36
#ifndef _OFFICEPIPEHELPER_HXX_
37
#define _OFFICEPIPEHELPER_HXX_
38
#include <rtl/instance.hxx>
39
#include <rtl/ustrbuf.hxx>
40
#include <rtl/digest.h>
41
#include <rtl/random.h>
42
#include <rtl/bootstrap.hxx>
43
#include <osl/file.hxx>
44
#include <osl/pipe.hxx>
45
#include <osl/security.hxx>
46
#include <osl/thread.hxx>
47
#include <osl/mutex.hxx>
48
#include <vos/process.hxx>
49
#include <com/sun/star/uno/RuntimeException.hpp>
50
#include <string.h>
51
namespace desktop
52
{
53
54
class OfficePipeNameData
55
{
56
friend class OfficePipeHelper;
57
	::rtl::OUString sPipePostName;
58
	::rtl::OUString sPipePrefix;
59
public:
60
	const ::rtl::OUString& PipeNamePrefix() const { return sPipePrefix; }
61
	const ::rtl::OUString& PipeNamePostfix() const { return sPipePostName; }
62
	const ::rtl::OUString PipeName() const { return sPipePrefix + sPipePostName; }
63
};  
64
65
struct OfficePipeHelper : public rtl::StaticWithInit<const OfficePipeNameData, OfficePipeHelper> {
66
    const OfficePipeNameData operator () ();
67
};
68
69
const OfficePipeNameData OfficePipeHelper::operator () ()
70
{
71
    OfficePipeNameData aData;
72
    aData.sPipePrefix = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SingleOfficeIPC_") );
73
    rtl::OUString userPath(RTL_CONSTASCII_USTRINGPARAM("${$SYSBINDIR/" SAL_CONFIGFILE("bootstrap")
74
                              ":UserInstallation}") );
75
    ::rtl::Bootstrap::expandMacros( userPath );
76
    OSL_ASSERT( userPath.getLength() > 0 );
77
    
78
    // normalize path:
79
    ::osl::FileStatus status( FileStatusMask_FileURL );
80
    ::osl::DirectoryItem dirItem;
81
    if (::osl::DirectoryItem::get( userPath, dirItem )
82
        != ::osl::DirectoryItem::E_None ||
83
        dirItem.getFileStatus( status )
84
        != ::osl::DirectoryItem::E_None ||
85
        !status.isValid( FileStatusMask_FileURL ) ||
86
        ::osl::FileBase::getAbsoluteFileURL(
87
            rtl::OUString(), status.getFileURL(), userPath )
88
        != ::osl::FileBase::E_None)
89
    {
90
        throw com::sun::star::uno::RuntimeException(
91
            rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No valid file URL in " SAL_CONFIGFILE("bootstrap") ": ") ) +
92
            userPath, com::sun::star::uno::Reference<com::sun::star::uno::XInterface>() );
93
    }
94
    ::rtl::OUStringBuffer buf;
95
#ifdef UNX	
96
    ::vos::OStartupInfo aInfo;
97
    rtl::OUString aPath;
98
    aInfo.getExecutableFile( aPath );
99
    sal_Int32 lastIndex = aPath.lastIndexOf('/');
100
    if ( lastIndex > 0 )
101
        aPath = aPath.copy( 0, lastIndex+1 );
102
103
    osl::File::getSystemPathFromFileURL( aPath, userPath);
104
105
    /* Quick and simple to replicate hash */
106
    sal_uInt32 nHash = 0;
107
    if (userPath.getLength() > 0)
108
    {
109
        rtl::OString aUTF8 = rtl::OUStringToOString( userPath,
110
            RTL_TEXTENCODING_UTF8 );
111
        const sal_Char *pStr = aUTF8;
112
        nHash = *pStr;
113
        for (sal_Int32 i = 1; i < aUTF8.getLength(); i++)
114
            nHash = (nHash << 5) - nHash + pStr[i];
115
    }
116
    sal_Char szBuffer[128];
117
    sprintf( szBuffer, "%d-%x", SUPD, nHash );
118
    buf.append( rtl::OUString( szBuffer, strlen(szBuffer), osl_getThreadTextEncoding() ) );
119
#else 
120
      
121
    rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
122
    if (digest <= 0) {
123
        throw RuntimeException(
124
            OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 );
125
    }
126
    
127
    sal_uInt8 const * data =
128
        reinterpret_cast<sal_uInt8 const *>(userPath.getStr());
129
    sal_Size size = (userPath.getLength() * sizeof (sal_Unicode));
130
    sal_uInt32 md5_key_len = rtl_digest_queryLength( digest );
131
    ::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] );
132
    
133
    rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) );
134
    rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) );
135
    rtl_digest_get( digest, md5_buf.get(), md5_key_len );
136
    rtl_digest_destroy( digest );
137
    
138
    // create hex-value string from the MD5 value to keep
139
    // the string size minimal
140
    for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) {
141
        buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 );
142
    }
143
#endif
144
    aData.sPipePostName =  buf.makeStringAndClear();
145
    return aData;
146
}
147
148
    
149
} // namespace desktop
150
151
#endif // _OFFICEPIPEHELPER_HXX

Return to issue 60696