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  * This file is part of LibreOffice published API.
22  */
23 
24 #ifndef INCLUDED_OSL_SECURITY_H
25 #define INCLUDED_OSL_SECURITY_H
26 
27 #include "sal/config.h"
28 
29 #include "rtl/ustring.h"
30 #include "sal/saldllapi.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef enum {
37     osl_Security_E_None,
38     osl_Security_E_UserUnknown,
39     osl_Security_E_WrongPassword,
40     osl_Security_E_Unknown,
41     osl_Security_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
42 } oslSecurityError;
43 
44 /** Process handle
45     @see osl_loginUser
46     @see osl_freeSecurityHandle
47     @see osl_executeProcess
48 */
49 typedef void* oslSecurity;
50 
51 /** Create a security handle for the current user.
52     @return a security handle or NULL on failure.
53     @see osl_freeSecurityHandle
54     @see osl_executeProcess
55     @see osl_executeApplication
56 */
57 SAL_DLLPUBLIC oslSecurity SAL_CALL osl_getCurrentSecurity(void);
58 
59 /** Deprecated API
60     Create a security handle for the denoted user.
61     Try to log in the user on the local system.
62     @param[in] strUserName denotes the name of the user to log in.
63     @param[in] strPasswd the password for this user.
64     @param[out] pSecurity returns the security handle if user could be logged in.
65     @return osl_Security_E_None if user could be logged in, otherwise an error-code.
66     @see osl_freeSecurityHandle
67     @see osl_executeProcess
68     @see osl_executeApplication
69 */
70 SAL_DLLPUBLIC oslSecurityError SAL_CALL osl_loginUser(
71     rtl_uString *strUserName,
72     rtl_uString *strPasswd,
73     oslSecurity *pSecurity
74     );
75 
76 /** Create a security handle for the denoted user.
77     Try to log in the user on the denoted file server. On success the homedir will be
78     the mapped drive on this server.
79     @param[in] strUserName denotes the name of the user to log in.
80     @param[in] strPasswd the password for this user.
81     @param[in] strFileServer denotes the file server on which the user is logged in.
82     @param[out] pSecurity returns the security handle if user could be logged in.
83     @return osl_Security_E_None if user could be logged in, otherwise an error-code.
84     @see osl_freeSecurityHandle
85     @see osl_executeProcess
86     @see osl_executeApplication
87 */
88 SAL_DLLPUBLIC oslSecurityError SAL_CALL osl_loginUserOnFileServer(
89     rtl_uString *strUserName,
90     rtl_uString *strPasswd,
91     rtl_uString *strFileServer,
92     oslSecurity *pSecurity
93     );
94 
95 /** Query if the user who is denotes by this security has administrator rights.
96     @param[in] Security the security handle for th user.
97     @return True, if the user has administrator rights, otherwise false.
98 */
99 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_isAdministrator(
100         oslSecurity Security);
101 
102 /** Free the security handle, created by osl_loginUser or osl_getCurrentSecurity.
103     @param[in] Security the security handle.
104     @see osl_loginUser
105 */
106 SAL_DLLPUBLIC void SAL_CALL osl_freeSecurityHandle(
107         oslSecurity Security);
108 
109 /** Get the login ident for the user of this security handle.
110     @param[in] Security the security handle.
111     @param[out] strIdent the string that receives the ident on success.
112     @return True, if the security handle is valid, otherwise False.
113 */
114 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserIdent(
115         oslSecurity Security, rtl_uString **strIdent);
116 
117 /** Get the login name for the user of this security handle.
118     @param[in] Security the security handle.
119     @param[out] strName the string that receives the user name on success.
120     @return True, if the security handle is valid, otherwise False.
121 */
122 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserName(
123         oslSecurity Security, rtl_uString **strName);
124 
125 /** Get the login name for the user of this security handle,
126     excluding the domain name on Windows.
127     @param[in] Security the security handle.
128     @param[out] strName the string that receives the user name on success.
129     @return True, if the security handle is valid, otherwise False.
130     @since LibreOffice 5.2
131 */
132 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getShortUserName(
133         oslSecurity Security, rtl_uString **strName);
134 
135 /** Get the home directory of the user of this security handle.
136     @param[in] Security the security handle.
137     @param[out] strDirectory the string that receives the directory path on success.
138     @return True, if the security handle is valid, otherwise False.
139 */
140 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getHomeDir(
141         oslSecurity Security, rtl_uString **strDirectory);
142 
143 /** Get the directory for configuration data of the user of this security handle.
144     @param[in] Security the security handle.
145     @param[out] strDirectory the string that receives the directory path on success.
146     @return True, if the security handle is valid, otherwise False.
147 */
148 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getConfigDir(
149         oslSecurity Security, rtl_uString **strDirectory);
150 
151 
152 /** Load Profile of the User
153     Implemented just for Windows
154     @param[in] Security previously fetch Security of the User
155     @return True if the Profile could successfully loaded, False otherwise.
156 */
157 
158 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_loadUserProfile(
159         oslSecurity Security);
160 
161 
162 /** Unload a User Profile
163     Implemented just for Windows
164     @param[in] Security previously fetch Security of the User
165     @return nothing is returned!
166 */
167 
168 SAL_DLLPUBLIC void SAL_CALL osl_unloadUserProfile(
169         oslSecurity Security);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif // INCLUDED_OSL_SECURITY_H
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
178