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 :
21 : #include <svl/folderrestriction.hxx>
22 : #include "osl/process.h"
23 : #include "tools/urlobj.hxx"
24 : #include "unotools/localfilehelper.hxx"
25 :
26 : //-----------------------------------------------------------------------------
27 :
28 0 : static void convertStringListToUrls (
29 : const rtl::OUString& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash )
30 : {
31 : const sal_Unicode cSeparator =
32 : #if defined(WNT)
33 : ';'
34 : #else
35 0 : ':'
36 : #endif
37 : ;
38 :
39 0 : sal_Int32 nIndex = 0;
40 0 : do
41 : {
42 : // the current token in the list
43 0 : rtl::OUString sCurrentToken = _rColonSeparatedList.getToken( 0, cSeparator, nIndex );
44 0 : if (!sCurrentToken.isEmpty())
45 : {
46 0 : INetURLObject aCurrentURL;
47 :
48 0 : rtl::OUString sURL;
49 0 : if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) )
50 0 : aCurrentURL = INetURLObject( sURL );
51 : else
52 : {
53 : // smart URL parsing, assuming FILE protocol
54 0 : aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE );
55 : }
56 :
57 0 : if ( _bFinalSlash )
58 0 : aCurrentURL.setFinalSlash( );
59 : else
60 0 : aCurrentURL.removeFinalSlash( );
61 0 : _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) );
62 0 : }
63 : }
64 : while ( nIndex >= 0 );
65 0 : }
66 :
67 : /** retrieves the value of an environment variable
68 : @return <TRUE/> if and only if the retrieved string value is not empty
69 : */
70 0 : static bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue )
71 : {
72 0 : _rValue = ::rtl::OUString();
73 0 : ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName );
74 0 : osl_getEnvironment( sEnvName.pData, &_rValue.pData );
75 0 : return !_rValue.isEmpty();
76 : }
77 :
78 : //-----------------------------------------------------------------------------
79 :
80 : namespace svt
81 : {
82 :
83 0 : void getUnrestrictedFolders( ::std::vector< String >& _rFolders )
84 : {
85 0 : _rFolders.resize( 0 );
86 0 : ::rtl::OUString sRestrictedPathList;
87 0 : if ( getEnvironmentValue( "RestrictedPath", sRestrictedPathList ) )
88 : {
89 : // append a final slash. This ensures that when we later on check
90 : // for unrestricted paths, we don't allow paths like "/home/user35" just because
91 : // "/home/user3" is allowed - with the final slash, we make it "/home/user3/".
92 0 : convertStringListToUrls( sRestrictedPathList, _rFolders, true );
93 0 : }
94 0 : }
95 :
96 : } // namespace svt
97 :
98 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|