xref: /aoo42x/main/sal/inc/osl/security.hxx (revision 565d668c)
1*565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*565d668cSAndrew Rist  * distributed with this work for additional information
6*565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9*565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*565d668cSAndrew Rist  *
11*565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*565d668cSAndrew Rist  *
13*565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*565d668cSAndrew Rist  * software distributed under the License is distributed on an
15*565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*565d668cSAndrew Rist  * specific language governing permissions and limitations
18*565d668cSAndrew Rist  * under the License.
19*565d668cSAndrew Rist  *
20*565d668cSAndrew Rist  *************************************************************/
21*565d668cSAndrew Rist 
22*565d668cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _OSL_SECURITY_HXX_
25cdf0e10cSrcweir #define _OSL_SECURITY_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _OSL_SECURITY_DECL_HXX
30cdf0e10cSrcweir #	include <osl/security_decl.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace osl
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 
Security()36cdf0e10cSrcweir inline Security::Security()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	m_handle = osl_getCurrentSecurity();
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
~Security()41cdf0e10cSrcweir inline Security::~Security()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     osl_freeSecurityHandle(m_handle);
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
logonUser(const rtl::OUString & strName,const rtl::OUString & strPasswd)46cdf0e10cSrcweir inline sal_Bool Security::logonUser(const rtl::OUString& strName,
47cdf0e10cSrcweir 									const rtl::OUString& strPasswd)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     osl_freeSecurityHandle(m_handle);
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     m_handle = 0;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	return (osl_loginUser( strName.pData, strPasswd.pData, &m_handle)
54cdf0e10cSrcweir 	        == osl_Security_E_None);
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
logonUser(const rtl::OUString & strName,const rtl::OUString & strPasswd,const rtl::OUString & strFileServer)57cdf0e10cSrcweir inline sal_Bool Security::logonUser( const rtl::OUString& strName,
58cdf0e10cSrcweir 									  const rtl::OUString& strPasswd,
59cdf0e10cSrcweir 									  const rtl::OUString& strFileServer )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     osl_freeSecurityHandle(m_handle);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     m_handle = NULL;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     return (osl_loginUserOnFileServer(strName.pData, strPasswd.pData, strFileServer.pData, &m_handle)
66cdf0e10cSrcweir 	        == osl_Security_E_None);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
getUserIdent(rtl::OUString & strIdent) const69cdf0e10cSrcweir inline sal_Bool Security::getUserIdent( rtl::OUString& strIdent) const
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     return osl_getUserIdent( m_handle, &strIdent.pData );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
getUserName(rtl::OUString & strName) const75cdf0e10cSrcweir inline sal_Bool Security::getUserName( rtl::OUString& strName ) const
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     return osl_getUserName( m_handle, &strName.pData );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
getHomeDir(rtl::OUString & strDirectory) const81cdf0e10cSrcweir inline sal_Bool Security::getHomeDir( rtl::OUString& strDirectory) const
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     return osl_getHomeDir(m_handle, &strDirectory.pData );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 
getConfigDir(rtl::OUString & strDirectory) const87cdf0e10cSrcweir inline sal_Bool Security::getConfigDir( rtl::OUString& strDirectory ) const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     return osl_getConfigDir( m_handle, &strDirectory.pData );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
isAdministrator() const92cdf0e10cSrcweir inline sal_Bool Security::isAdministrator() const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     return osl_isAdministrator(m_handle);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
getHandle() const97cdf0e10cSrcweir inline oslSecurity Security::getHandle() const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     return m_handle;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir #endif	// _OSL_SECURITY_HXX_
106cdf0e10cSrcweir 
107