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