2000-09-29 10:28:15 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* $RCSfile: regpathhelper.cxx,v $
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* $Revision: 1.14 $
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2005-09-08 02:52:13 $
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
2005-09-08 01:52:14 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-29 10:28:15 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifndef _OSL_FILE_HXX_
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#endif
|
2001-06-07 15:41:38 +00:00
|
|
|
#ifndef _OSL_SECURITY_HXX_
|
|
|
|
#include <osl/security.hxx>
|
|
|
|
#endif
|
2001-07-23 09:14:42 +00:00
|
|
|
#ifndef _OSL_THREAD_H_
|
|
|
|
#include <osl/thread.h>
|
|
|
|
#endif
|
2000-09-29 10:28:15 +00:00
|
|
|
#ifndef _VOS_PROCESS_HXX_
|
|
|
|
#include <vos/process.hxx>
|
|
|
|
#endif
|
2001-06-29 14:34:32 +00:00
|
|
|
#ifndef _RTL_TEXTENC_H
|
|
|
|
#include <rtl/textenc.h>
|
|
|
|
#endif
|
|
|
|
#ifndef _RTL_URI_H_
|
|
|
|
#include <rtl/uri.h>
|
|
|
|
#endif
|
|
|
|
#ifndef _RTL_URI_HXX_
|
|
|
|
#include <rtl/uri.hxx>
|
|
|
|
#endif
|
2000-09-29 10:28:15 +00:00
|
|
|
|
|
|
|
using namespace vos;
|
|
|
|
using namespace osl;
|
|
|
|
using namespace rtl;
|
|
|
|
|
|
|
|
#define PATH_DELEMITTER '/'
|
|
|
|
|
|
|
|
#define USER_REGISTRY_NAME_ENV "STAR_USER_REGISTRY"
|
|
|
|
#define SYSTEM_REGISTRY_NAME_ENV "STAR_REGISTRY"
|
2004-05-07 15:28:30 +00:00
|
|
|
#define REGISTRY_SYSTEM_NAME "services.rdb"
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2001-06-07 15:41:38 +00:00
|
|
|
#define REGISTRY_LOCAL_NAME "user60.rdb"
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2001-06-07 15:41:38 +00:00
|
|
|
#ifdef SAL_UNX
|
|
|
|
#define CONFIG_PATH_PREFIX "."
|
|
|
|
#else
|
|
|
|
#define CONFIG_PATH_PREFIX ""
|
|
|
|
#endif
|
2000-09-29 10:28:15 +00:00
|
|
|
|
|
|
|
namespace comphelper
|
|
|
|
{
|
|
|
|
|
2001-06-07 15:41:38 +00:00
|
|
|
/**
|
|
|
|
@return sal_True, if the office is started in a portal
|
|
|
|
environment.
|
|
|
|
sal_False, if the common office is started
|
|
|
|
*/
|
|
|
|
static sal_Bool retrievePortalUserDir( OUString *pDirectory )
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
|
|
|
OStartupInfo startInfo;
|
|
|
|
sal_uInt32 nArgs = startInfo.getCommandArgCount();
|
2001-06-07 15:41:38 +00:00
|
|
|
sal_Bool bIsPortalUser = sal_False;
|
2000-09-29 10:28:15 +00:00
|
|
|
OUString sArg;
|
2000-10-18 11:46:35 +00:00
|
|
|
while( nArgs > 0 )
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2000-10-09 15:27:18 +00:00
|
|
|
if ( !startInfo.getCommandArg(--nArgs, sArg) )
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
|
|
|
if ( sArg.indexOf(OUString::createFromAscii("-userid")) == 0 )
|
|
|
|
{
|
2001-06-07 15:41:38 +00:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
bIsPortalUser = sal_True;
|
2001-06-07 15:41:38 +00:00
|
|
|
sal_Int32 nStart = sArg.lastIndexOf( '[' );
|
|
|
|
sal_Int32 nEnd = sArg.lastIndexOf( ']' );
|
|
|
|
if( -1 == nStart || -1 == nEnd || nEnd < nStart)
|
|
|
|
{
|
|
|
|
*pDirectory = OUString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-29 14:34:32 +00:00
|
|
|
OUString aEncHome = sArg.copy( nStart + 1 , nEnd - nStart -1 );
|
|
|
|
*pDirectory = rtl::Uri::decode(aEncHome,
|
|
|
|
rtl_UriDecodeWithCharset,
|
|
|
|
RTL_TEXTENCODING_UTF8);
|
2001-06-07 15:41:38 +00:00
|
|
|
}
|
2000-09-29 10:28:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-07 15:41:38 +00:00
|
|
|
return bIsPortalUser;
|
|
|
|
}
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2001-06-07 15:41:38 +00:00
|
|
|
static OUString getDefaultLocalRegistry()
|
|
|
|
{
|
|
|
|
OUString uBuffer, userRegistryName;
|
|
|
|
OUString portalUserDir;
|
|
|
|
|
|
|
|
sal_Bool bIsPortalUser = retrievePortalUserDir( &portalUserDir );
|
|
|
|
|
2001-06-08 07:31:16 +00:00
|
|
|
if ( bIsPortalUser )
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2001-06-08 07:31:16 +00:00
|
|
|
if( portalUserDir.getLength() )
|
2001-06-07 15:41:38 +00:00
|
|
|
{
|
2001-06-08 07:31:16 +00:00
|
|
|
FileBase::getFileURLFromSystemPath( portalUserDir , portalUserDir );
|
|
|
|
userRegistryName = portalUserDir;
|
|
|
|
userRegistryName += OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"/user/" REGISTRY_LOCAL_NAME ) );
|
|
|
|
|
|
|
|
// Directory creation is probably necessary for bootstrapping a new
|
|
|
|
// user in the portal environment (the ucb uses this function).
|
|
|
|
// This should be solved differently, as
|
|
|
|
// no one expects this function to create anything ...
|
|
|
|
OUString sSeparator(RTL_CONSTASCII_USTRINGPARAM("/"));
|
|
|
|
OUString sPath(RTL_CONSTASCII_USTRINGPARAM("file://"));
|
|
|
|
FileBase::RC retRC = FileBase::E_None;
|
|
|
|
|
|
|
|
sal_Int32 nIndex = 3;
|
|
|
|
sPath += userRegistryName.getToken(2, '/', nIndex);
|
|
|
|
while( nIndex != -1 )
|
2001-05-11 10:47:32 +00:00
|
|
|
{
|
2001-06-08 07:31:16 +00:00
|
|
|
sPath += sSeparator;
|
|
|
|
sPath += userRegistryName.getToken(0, '/', nIndex);
|
|
|
|
if( nIndex == -1 )
|
|
|
|
break;
|
|
|
|
Directory aDir( sPath );
|
|
|
|
if( aDir.open() == FileBase::E_NOENT )
|
2001-05-11 10:47:32 +00:00
|
|
|
{
|
2001-06-08 07:31:16 +00:00
|
|
|
retRC = Directory::create(sPath);
|
|
|
|
if ( retRC != FileBase::E_None && retRC != FileBase::E_EXIST)
|
|
|
|
{
|
|
|
|
return OUString();
|
|
|
|
}
|
2001-05-11 10:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
2001-06-08 07:31:16 +00:00
|
|
|
else /* bIsPortalUser */
|
|
|
|
{
|
2001-06-07 15:41:38 +00:00
|
|
|
::osl::Security aUserSecurity;
|
2001-06-08 07:31:16 +00:00
|
|
|
aUserSecurity.getConfigDir( userRegistryName );
|
|
|
|
userRegistryName += OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"/" CONFIG_PATH_PREFIX REGISTRY_LOCAL_NAME ) );
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return userRegistryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OUString getPathToUserRegistry()
|
|
|
|
{
|
|
|
|
OUString userRegistryName;
|
|
|
|
FILE *f=NULL;
|
|
|
|
|
|
|
|
// search the environment STAR_USER_REGISTRY
|
|
|
|
OString sBuffer( getenv(USER_REGISTRY_NAME_ENV) );
|
|
|
|
if ( sBuffer.getLength() > 0 )
|
|
|
|
{
|
|
|
|
f = fopen( sBuffer.getStr(), "r" );
|
|
|
|
|
|
|
|
if (f != NULL)
|
|
|
|
{
|
|
|
|
fclose(f);
|
2001-07-23 09:14:42 +00:00
|
|
|
userRegistryName = OStringToOUString( sBuffer, osl_getThreadTextEncoding() );
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !userRegistryName.getLength() )
|
|
|
|
{
|
|
|
|
userRegistryName = getDefaultLocalRegistry();
|
|
|
|
}
|
|
|
|
|
|
|
|
return userRegistryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString getPathToSystemRegistry()
|
|
|
|
{
|
|
|
|
OUString uBuffer;
|
|
|
|
OUString registryBaseName( RTL_CONSTASCII_USTRINGPARAM(REGISTRY_SYSTEM_NAME) );
|
|
|
|
OUString systemRegistryName;
|
|
|
|
FILE *f=NULL;
|
|
|
|
|
|
|
|
// search in the directory of the executable
|
|
|
|
if( OStartupInfo::E_None == OStartupInfo().getExecutableFile(uBuffer) )
|
|
|
|
{
|
|
|
|
sal_uInt32 lastIndex = uBuffer.lastIndexOf(PATH_DELEMITTER);
|
|
|
|
if (lastIndex > 0)
|
|
|
|
{
|
|
|
|
uBuffer = uBuffer.copy(0, lastIndex + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uBuffer += registryBaseName;
|
|
|
|
|
2001-05-11 10:47:32 +00:00
|
|
|
if (!FileBase::getSystemPathFromFileURL(uBuffer, systemRegistryName))
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2001-07-23 09:14:42 +00:00
|
|
|
OString tmpStr( OUStringToOString(systemRegistryName, osl_getThreadTextEncoding()) );
|
2000-09-29 10:28:15 +00:00
|
|
|
f = fopen( tmpStr.getStr(), "r" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f == NULL)
|
|
|
|
{
|
|
|
|
// search the environment STAR_REGISTRY
|
|
|
|
OString tmpStr( getenv(SYSTEM_REGISTRY_NAME_ENV) );
|
|
|
|
if ( tmpStr.getLength() > 0 )
|
|
|
|
{
|
|
|
|
f = fopen(tmpStr.getStr(), "r");
|
|
|
|
|
|
|
|
if (f != NULL)
|
|
|
|
{
|
|
|
|
fclose(f);
|
2001-07-23 09:14:42 +00:00
|
|
|
systemRegistryName = OStringToOUString( tmpStr, osl_getThreadTextEncoding() );
|
2000-09-29 10:28:15 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
systemRegistryName = OUString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemRegistryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|