xref: /trunk/main/vos/source/security.cxx (revision e8c8fa4b)
1*e8c8fa4bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*e8c8fa4bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e8c8fa4bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e8c8fa4bSAndrew Rist  * distributed with this work for additional information
6*e8c8fa4bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e8c8fa4bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e8c8fa4bSAndrew Rist  * "License"); you may not use this file except in compliance
9*e8c8fa4bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*e8c8fa4bSAndrew Rist  *
11*e8c8fa4bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e8c8fa4bSAndrew Rist  *
13*e8c8fa4bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e8c8fa4bSAndrew Rist  * software distributed under the License is distributed on an
15*e8c8fa4bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e8c8fa4bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*e8c8fa4bSAndrew Rist  * specific language governing permissions and limitations
18*e8c8fa4bSAndrew Rist  * under the License.
19*e8c8fa4bSAndrew Rist  *
20*e8c8fa4bSAndrew Rist  *************************************************************/
21*e8c8fa4bSAndrew Rist 
22*e8c8fa4bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <vos/security.hxx>
26cdf0e10cSrcweir #include <vos/diagnose.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir using namespace vos;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////
31cdf0e10cSrcweir // Object super class
32cdf0e10cSrcweir 
33cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OSecurity, vos), VOS_NAMESPACE(OSecurity, vos), VOS_NAMESPACE(OObject, vos), 0);
34cdf0e10cSrcweir 
OSecurity()35cdf0e10cSrcweir OSecurity::OSecurity()
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 	m_oslSecurity = osl_getCurrentSecurity();
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
~OSecurity()40cdf0e10cSrcweir OSecurity::~OSecurity()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     osl_freeSecurityHandle(m_oslSecurity);
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
logonUser(const rtl::OUString & strName,const rtl::OUString & strPasswd)45cdf0e10cSrcweir sal_Bool OSecurity::logonUser(const rtl::OUString& strName,
46cdf0e10cSrcweir 							  const rtl::OUString& strPasswd)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     osl_freeSecurityHandle(m_oslSecurity);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     m_oslSecurity = NULL;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	return (osl_loginUser( strName.pData, strPasswd.pData, &m_oslSecurity)
53cdf0e10cSrcweir 	        == osl_Security_E_None);
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
logonUser(const rtl::OUString & strName,const rtl::OUString & strPasswd,const rtl::OUString & strFileServer)57cdf0e10cSrcweir sal_Bool OSecurity::logonUser( const rtl::OUString& strName,
58cdf0e10cSrcweir 							   const rtl::OUString& strPasswd,
59cdf0e10cSrcweir 							   const rtl::OUString& strFileServer )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     osl_freeSecurityHandle(m_oslSecurity);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     m_oslSecurity = NULL;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     return (osl_loginUserOnFileServer(strName.pData, strPasswd.pData, strFileServer.pData, &m_oslSecurity)
66cdf0e10cSrcweir 	        == osl_Security_E_None);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
getUserIdent(rtl::OUString & strIdent) const70cdf0e10cSrcweir sal_Bool OSecurity::getUserIdent( rtl::OUString& strIdent) const
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	VOS_ASSERT(m_oslSecurity);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     return osl_getUserIdent( m_oslSecurity, &strIdent.pData );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
getUserName(rtl::OUString & strName) const78cdf0e10cSrcweir sal_Bool OSecurity::getUserName( rtl::OUString& strName ) const
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	VOS_ASSERT(m_oslSecurity);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     return osl_getUserName( m_oslSecurity, &strName.pData );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
getHomeDir(rtl::OUString & strDirectory) const86cdf0e10cSrcweir sal_Bool OSecurity::getHomeDir( rtl::OUString& strDirectory) const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	VOS_ASSERT(m_oslSecurity);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     return osl_getHomeDir(m_oslSecurity, &strDirectory.pData );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
getConfigDir(rtl::OUString & strDirectory) const94cdf0e10cSrcweir sal_Bool OSecurity::getConfigDir( rtl::OUString& strDirectory ) const
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	VOS_ASSERT(m_oslSecurity);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     return osl_getConfigDir( m_oslSecurity, &strDirectory.pData );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
isAdministrator() const101cdf0e10cSrcweir sal_Bool OSecurity::isAdministrator() const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	VOS_ASSERT(m_oslSecurity);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     return osl_isAdministrator(m_oslSecurity);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
operator oslSecurity() const108cdf0e10cSrcweir OSecurity::operator oslSecurity() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     return m_oslSecurity;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113