1647f063dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3647f063dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4647f063dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5647f063dSAndrew Rist * distributed with this work for additional information
6647f063dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7647f063dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8647f063dSAndrew Rist * "License"); you may not use this file except in compliance
9647f063dSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11647f063dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13647f063dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14647f063dSAndrew Rist * software distributed under the License is distributed on an
15647f063dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16647f063dSAndrew Rist * KIND, either express or implied. See the License for the
17647f063dSAndrew Rist * specific language governing permissions and limitations
18647f063dSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20647f063dSAndrew Rist *************************************************************/
21647f063dSAndrew Rist
22647f063dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <stddef.h>
25cdf0e10cSrcweir
26cdf0e10cSrcweir /* Solaris 8 has no C99 stdint.h, and Solaris generally seems not to miss it for
27cdf0e10cSrcweir SIZE_MAX: */
28cdf0e10cSrcweir #if !defined __SUNPRO_C
29cdf0e10cSrcweir #include <stdint.h>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "system.h"
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <osl/security.h>
35cdf0e10cSrcweir #include <osl/diagnose.h>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "osl/thread.h"
38cdf0e10cSrcweir #include "osl/file.h"
39cdf0e10cSrcweir
40cdf0e10cSrcweir #if defined LINUX || defined SOLARIS
41cdf0e10cSrcweir #include <crypt.h>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include "secimpl.h"
45cdf0e10cSrcweir
46cdf0e10cSrcweir #ifndef NOPAM
47cdf0e10cSrcweir #ifndef PAM_BINARY_MSG
48cdf0e10cSrcweir #define PAM_BINARY_MSG 6
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir
52cdf0e10cSrcweir static oslSecurityError SAL_CALL
53*57fdf169Smseidel osl_psz_loginUser(const sal_Char* pszUserName, const sal_Char* pszPasswd, oslSecurity* pSecurity);
54cdf0e10cSrcweir sal_Bool SAL_CALL osl_psz_getUserIdent(oslSecurity Security, sal_Char *pszIdent, sal_uInt32 nMax);
55cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32 nMax);
56cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getHomeDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax);
57cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax);
58cdf0e10cSrcweir
sysconf_SC_GETPW_R_SIZE_MAX(size_t * value)59cdf0e10cSrcweir static sal_Bool sysconf_SC_GETPW_R_SIZE_MAX(size_t * value) {
60cdf0e10cSrcweir #if defined _SC_GETPW_R_SIZE_MAX
61cdf0e10cSrcweir long m;
62cdf0e10cSrcweir errno = 0;
63cdf0e10cSrcweir m = sysconf(_SC_GETPW_R_SIZE_MAX);
64cdf0e10cSrcweir if (m == -1) {
65cdf0e10cSrcweir /* _SC_GETPW_R_SIZE_MAX has no limit; some platforms like certain
66cdf0e10cSrcweir FreeBSD versions support sysconf(_SC_GETPW_R_SIZE_MAX) in a broken
67cdf0e10cSrcweir way and always set EINVAL, so be resilient here: */
68cdf0e10cSrcweir return sal_False;
69cdf0e10cSrcweir } else {
70cdf0e10cSrcweir OSL_ASSERT(m >= 0 && (unsigned long) m < SIZE_MAX);
71cdf0e10cSrcweir *value = (size_t) m;
72cdf0e10cSrcweir return sal_True;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir #else
75cdf0e10cSrcweir /* some platforms like Mac OS X 1.3 do not define _SC_GETPW_R_SIZE_MAX: */
76cdf0e10cSrcweir return sal_False;
77cdf0e10cSrcweir #endif
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
growSecurityImpl(oslSecurityImpl * impl,size_t * bufSize)80cdf0e10cSrcweir static oslSecurityImpl * growSecurityImpl(
81cdf0e10cSrcweir oslSecurityImpl * impl, size_t * bufSize)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir size_t n = 0;
84cdf0e10cSrcweir oslSecurityImpl * p = NULL;
85cdf0e10cSrcweir if (impl == NULL) {
86cdf0e10cSrcweir if (!sysconf_SC_GETPW_R_SIZE_MAX(&n)) {
87cdf0e10cSrcweir /* choose something sensible (the callers of growSecurityImpl will
88cdf0e10cSrcweir detect it if the allocated buffer is too small: */
89cdf0e10cSrcweir n = 1024;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir } else if (*bufSize <= SIZE_MAX / 2) {
92cdf0e10cSrcweir n = 2 * *bufSize;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir if (n != 0) {
95cdf0e10cSrcweir if (n <= SIZE_MAX - offsetof(oslSecurityImpl, m_buffer)) {
96cdf0e10cSrcweir *bufSize = n;
97cdf0e10cSrcweir n += offsetof(oslSecurityImpl, m_buffer);
98cdf0e10cSrcweir } else {
99cdf0e10cSrcweir *bufSize = SIZE_MAX - offsetof(oslSecurityImpl, m_buffer);
100cdf0e10cSrcweir n = SIZE_MAX;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir p = realloc(impl, n);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir if (p == NULL) {
105cdf0e10cSrcweir free(impl);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir return p;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
deleteSecurityImpl(oslSecurityImpl * impl)110cdf0e10cSrcweir static void deleteSecurityImpl(oslSecurityImpl * impl) {
111cdf0e10cSrcweir free(impl);
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
osl_getCurrentSecurity()114cdf0e10cSrcweir oslSecurity SAL_CALL osl_getCurrentSecurity()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir size_t n = 0;
117cdf0e10cSrcweir oslSecurityImpl * p = NULL;
118cdf0e10cSrcweir for (;;) {
119cdf0e10cSrcweir struct passwd * found;
120cdf0e10cSrcweir p = growSecurityImpl(p, &n);
121cdf0e10cSrcweir if (p == NULL) {
122cdf0e10cSrcweir return NULL;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir switch (getpwuid_r(getuid(), &p->m_pPasswd, p->m_buffer, n, &found)) {
125cdf0e10cSrcweir case ERANGE:
126cdf0e10cSrcweir break;
127cdf0e10cSrcweir case 0:
128cdf0e10cSrcweir if (found != NULL) {
129cdf0e10cSrcweir return p;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir /* fall through */
132cdf0e10cSrcweir default:
133cdf0e10cSrcweir deleteSecurityImpl(p);
134cdf0e10cSrcweir return NULL;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir
140cdf0e10cSrcweir #if defined LINUX && !defined NOPAM
141cdf0e10cSrcweir
142cdf0e10cSrcweir /*
143cdf0e10cSrcweir *
144cdf0e10cSrcweir * osl Routines for Pluggable Authentication Modules (PAM)
145cdf0e10cSrcweir * tested with Linux-PAM 0.66 on Redhat-6.0 and
146cdf0e10cSrcweir * Linux-PAM 0.64 on RedHat-5.2,
147cdf0e10cSrcweir * XXX Will probably not run on PAM 0.59 or prior, since
148cdf0e10cSrcweir * number of pam_response* responses has changed
149cdf0e10cSrcweir *
150cdf0e10cSrcweir */
151cdf0e10cSrcweir
152cdf0e10cSrcweir #include <security/pam_appl.h>
153cdf0e10cSrcweir
154cdf0e10cSrcweir typedef struct {
155cdf0e10cSrcweir char* name;
156cdf0e10cSrcweir char* password;
157cdf0e10cSrcweir } sal_PamData;
158cdf0e10cSrcweir
159cdf0e10cSrcweir typedef struct {
160cdf0e10cSrcweir int (*pam_start)(const char *service_name, const char *user,
161cdf0e10cSrcweir const struct pam_conv *pam_conversation,
162cdf0e10cSrcweir pam_handle_t **pamh);
163cdf0e10cSrcweir int (*pam_end) (pam_handle_t *pamh, int pam_status);
164cdf0e10cSrcweir int (*pam_authenticate) (pam_handle_t *pamh, int flags);
165cdf0e10cSrcweir int (*pam_acct_mgmt) (pam_handle_t *pamh, int flags);
166cdf0e10cSrcweir } sal_PamModule;
167cdf0e10cSrcweir
168cdf0e10cSrcweir /*
169cdf0e10cSrcweir * Implement a pam-conversation callback-routine,
170cdf0e10cSrcweir * it just supply name and password instead of prompting the user.
171cdf0e10cSrcweir * I guess that echo-off means 'ask for password' and echo-on means
172cdf0e10cSrcweir * 'ask for user-name'. In fact I've never been asked anything else
173cdf0e10cSrcweir * than the password
174cdf0e10cSrcweir * XXX Please notice that if a pam-module does ask anything else, we
175cdf0e10cSrcweir * are completely lost, and a pam-module is free to do so
176cdf0e10cSrcweir * XXX
177cdf0e10cSrcweir */
178cdf0e10cSrcweir
179cdf0e10cSrcweir static int
osl_PamConversation(int num_msg,const struct pam_message ** msgm,struct pam_response ** response,void * appdata_ptr)180cdf0e10cSrcweir osl_PamConversation (int num_msg, const struct pam_message **msgm,
181cdf0e10cSrcweir struct pam_response **response, void *appdata_ptr)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir int i;
184cdf0e10cSrcweir sal_Bool error;
185cdf0e10cSrcweir sal_PamData *pam_data;
186cdf0e10cSrcweir struct pam_response *p_reply;
187cdf0e10cSrcweir
188cdf0e10cSrcweir /* resource initialization */
189cdf0e10cSrcweir pam_data = (sal_PamData*) appdata_ptr;
190cdf0e10cSrcweir p_reply = (struct pam_response *) calloc( num_msg,
191cdf0e10cSrcweir sizeof(struct pam_response));
192cdf0e10cSrcweir if ( p_reply == NULL || pam_data == NULL )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir if ( p_reply != NULL )
195cdf0e10cSrcweir free ( p_reply );
196cdf0e10cSrcweir *response = NULL;
197cdf0e10cSrcweir return PAM_CONV_ERR;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir /* pseudo dialog */
201cdf0e10cSrcweir error = sal_False;
202cdf0e10cSrcweir for ( i = 0; i < num_msg ; i++ )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir switch ( msgm[ i ]->msg_style )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir case PAM_PROMPT_ECHO_OFF:
207cdf0e10cSrcweir p_reply[ i ].resp_retcode = 0;
208cdf0e10cSrcweir p_reply[ i ].resp = strdup( pam_data->password );
209cdf0e10cSrcweir break;
210cdf0e10cSrcweir case PAM_PROMPT_ECHO_ON:
211cdf0e10cSrcweir p_reply[ i ].resp_retcode = 0;
212cdf0e10cSrcweir p_reply[ i ].resp = strdup( pam_data->name );
213cdf0e10cSrcweir break;
214cdf0e10cSrcweir case PAM_ERROR_MSG:
215cdf0e10cSrcweir case PAM_TEXT_INFO:
216cdf0e10cSrcweir case PAM_BINARY_PROMPT:
217cdf0e10cSrcweir case PAM_BINARY_MSG:
218cdf0e10cSrcweir p_reply[ i ].resp_retcode = 0;
219cdf0e10cSrcweir p_reply[ i ].resp = NULL;
220cdf0e10cSrcweir break;
221cdf0e10cSrcweir default:
222cdf0e10cSrcweir error = sal_True;
223cdf0e10cSrcweir break;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir /* free resources on error */
228cdf0e10cSrcweir if ( error )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir for ( i = 0; i < num_msg ; i++ )
231cdf0e10cSrcweir if ( p_reply[ i ].resp )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir memset ( p_reply[ i ].resp, 0,
234cdf0e10cSrcweir strlen( p_reply[ i ].resp ) );
235cdf0e10cSrcweir free ( p_reply[ i ].resp );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir free ( p_reply );
238cdf0e10cSrcweir
239cdf0e10cSrcweir *response = NULL;
240cdf0e10cSrcweir return PAM_CONV_ERR;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir /* well done */
244cdf0e10cSrcweir *response = p_reply;
245cdf0e10cSrcweir return PAM_SUCCESS;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir #ifndef PAM_LINK
249cdf0e10cSrcweir /*
250cdf0e10cSrcweir * avoid linking against libpam.so, since it is not available on all systems,
251cdf0e10cSrcweir * instead load-on-call, returns structure which holds pointer to
252cdf0e10cSrcweir * pam-functions,
253cdf0e10cSrcweir * library is never closed in case of success
254cdf0e10cSrcweir */
255cdf0e10cSrcweir
osl_getPAM()256cdf0e10cSrcweir static sal_PamModule* osl_getPAM()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir static sal_PamModule *pam_module = NULL;
259cdf0e10cSrcweir static sal_Bool load_once = sal_False;
260cdf0e10cSrcweir
261cdf0e10cSrcweir if ( !load_once )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir /* get library-handle. cannot use osl-module, since
264cdf0e10cSrcweir RTLD_GLOBAL is required for PAM-0.64 RH 5.2
265cdf0e10cSrcweir (but not for PAM-0.66 RH 6.0) */
266cdf0e10cSrcweir void *pam_hdl;
267cdf0e10cSrcweir
268cdf0e10cSrcweir pam_hdl = dlopen( "libpam.so.0", RTLD_GLOBAL | RTLD_LAZY );
269cdf0e10cSrcweir
270cdf0e10cSrcweir if ( pam_hdl != NULL )
271cdf0e10cSrcweir pam_module = (sal_PamModule*)calloc( 1, sizeof(sal_PamModule) );
272cdf0e10cSrcweir
273cdf0e10cSrcweir /* load functions */
274cdf0e10cSrcweir if ( pam_module != NULL )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir pam_module->pam_acct_mgmt = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_acct_mgmt" );
277cdf0e10cSrcweir pam_module->pam_authenticate
278cdf0e10cSrcweir = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_authenticate" );
279cdf0e10cSrcweir pam_module->pam_end = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_end" );
280cdf0e10cSrcweir pam_module->pam_start = (int (*)(const char *, const char *, const struct pam_conv *, pam_handle_t **)) dlsym ( pam_hdl, "pam_start" );
281cdf0e10cSrcweir
282cdf0e10cSrcweir /* free resources, if not completely successful */
283cdf0e10cSrcweir if ( (pam_module->pam_start == NULL)
284cdf0e10cSrcweir || (pam_module->pam_end == NULL)
285cdf0e10cSrcweir || (pam_module->pam_authenticate == NULL)
286cdf0e10cSrcweir || (pam_module->pam_acct_mgmt == NULL) )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir free( pam_module );
289cdf0e10cSrcweir pam_module = NULL;
290cdf0e10cSrcweir dlclose( pam_hdl );
291cdf0e10cSrcweir }
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir /* never try again */
295cdf0e10cSrcweir load_once = sal_True;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir return pam_module;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir #endif
301cdf0e10cSrcweir
302cdf0e10cSrcweir /*
303cdf0e10cSrcweir * User Identification using PAM
304cdf0e10cSrcweir */
305cdf0e10cSrcweir
306cdf0e10cSrcweir static sal_Bool
osl_PamAuthentification(const sal_Char * name,const sal_Char * password)307cdf0e10cSrcweir osl_PamAuthentification( const sal_Char* name, const sal_Char* password )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir sal_Bool success = sal_False;
310cdf0e10cSrcweir
311cdf0e10cSrcweir #ifndef PAM_LINK
312cdf0e10cSrcweir sal_PamModule* pam_module;
313cdf0e10cSrcweir
314cdf0e10cSrcweir pam_module = osl_getPAM();
315cdf0e10cSrcweir if ( pam_module != NULL )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir #endif
318cdf0e10cSrcweir pam_handle_t *pam_handle = NULL;
319cdf0e10cSrcweir struct pam_conv pam_conversation;
320cdf0e10cSrcweir sal_PamData pam_data;
321cdf0e10cSrcweir
322cdf0e10cSrcweir int return_value;
323cdf0e10cSrcweir
324cdf0e10cSrcweir pam_data.name = (char*) name;
325cdf0e10cSrcweir pam_data.password = (char*) password;
326cdf0e10cSrcweir
327cdf0e10cSrcweir pam_conversation.conv = osl_PamConversation;
328cdf0e10cSrcweir pam_conversation.appdata_ptr = (void*)(&pam_data);
329cdf0e10cSrcweir
330cdf0e10cSrcweir #ifndef PAM_LINK
331cdf0e10cSrcweir return_value = pam_module->pam_start( "su", name,
332cdf0e10cSrcweir &pam_conversation, &pam_handle);
333cdf0e10cSrcweir #else
334cdf0e10cSrcweir return_value = pam_start( "su", name,
335cdf0e10cSrcweir &pam_conversation, &pam_handle);
336cdf0e10cSrcweir #endif
337cdf0e10cSrcweir if (return_value == PAM_SUCCESS )
338cdf0e10cSrcweir #ifndef PAM_LINK
339cdf0e10cSrcweir return_value = pam_module->pam_authenticate(pam_handle, 0);
340cdf0e10cSrcweir #else
341cdf0e10cSrcweir return_value = pam_authenticate(pam_handle, 0);
342cdf0e10cSrcweir #endif
343cdf0e10cSrcweir if (return_value == PAM_SUCCESS )
344cdf0e10cSrcweir #ifndef PAM_LINK
345cdf0e10cSrcweir return_value = pam_module->pam_acct_mgmt(pam_handle, 0);
346cdf0e10cSrcweir pam_module->pam_end( pam_handle, return_value );
347cdf0e10cSrcweir #else
348cdf0e10cSrcweir return_value = pam_acct_mgmt(pam_handle, 0);
349cdf0e10cSrcweir pam_end( pam_handle, return_value );
350cdf0e10cSrcweir #endif
351cdf0e10cSrcweir
352cdf0e10cSrcweir success = (sal_Bool)(return_value == PAM_SUCCESS);
353cdf0e10cSrcweir #ifndef PAM_LINK
354cdf0e10cSrcweir }
355cdf0e10cSrcweir #endif
356cdf0e10cSrcweir
357cdf0e10cSrcweir return success;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir
361cdf0e10cSrcweir #ifndef CRYPT_LINK
362cdf0e10cSrcweir /* dummy crypt, matches the interface of
363cdf0e10cSrcweir crypt() but does not encrypt at all */
364cdf0e10cSrcweir static const sal_Char* SAL_CALL
osl_noCrypt(const sal_Char * key,const sal_Char * salt)365cdf0e10cSrcweir osl_noCrypt ( const sal_Char *key, const sal_Char *salt )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir (void) salt; /* unused */
368cdf0e10cSrcweir return key;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir /* load-on-call crypt library and crypt symbol */
372cdf0e10cSrcweir static void* SAL_CALL
osl_getCrypt()373cdf0e10cSrcweir osl_getCrypt()
374cdf0e10cSrcweir {
375cdf0e10cSrcweir static char* (*crypt_sym)(const char*, const char*) = NULL;
376cdf0e10cSrcweir static sal_Bool load_once = sal_False;
377cdf0e10cSrcweir
378cdf0e10cSrcweir if ( !load_once )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir void * crypt_library;
381cdf0e10cSrcweir
382cdf0e10cSrcweir crypt_library = dlopen( "libcrypt.so.1", RTLD_GLOBAL | RTLD_LAZY ); /* never closed */
383cdf0e10cSrcweir if ( crypt_library != NULL )
384cdf0e10cSrcweir crypt_sym = (char* (*)(const char *, const char *)) dlsym(crypt_library, "crypt" );
385cdf0e10cSrcweir if ( crypt_sym == NULL ) /* no libcrypt or libcrypt without crypt */
386cdf0e10cSrcweir crypt_sym = (char* (*)(const char *, const char *)) &osl_noCrypt;
387cdf0e10cSrcweir
388cdf0e10cSrcweir load_once = sal_True;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
391cdf0e10cSrcweir return (void*)crypt_sym;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
394cdf0e10cSrcweir /* replacement for crypt function for password encryption, uses either
395cdf0e10cSrcweir strong encryption of dlopen'ed libcrypt.so.1 or dummy implementation
396cdf0e10cSrcweir with no encryption. Objective target is to avoid linking against
397cdf0e10cSrcweir libcrypt (not available on caldera open linux 2.2 #63822#) */
398cdf0e10cSrcweir static sal_Char* SAL_CALL
osl_dynamicCrypt(const sal_Char * key,const sal_Char * salt)399cdf0e10cSrcweir osl_dynamicCrypt ( const sal_Char *key, const sal_Char *salt )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir char* (*dynamic_crypt)(char *, char *);
402cdf0e10cSrcweir
403cdf0e10cSrcweir dynamic_crypt = (char * (*)(char *, char *)) osl_getCrypt();
404cdf0e10cSrcweir
405cdf0e10cSrcweir return dynamic_crypt( (sal_Char*)key, (sal_Char*)salt );
406cdf0e10cSrcweir }
407cdf0e10cSrcweir #endif
408cdf0e10cSrcweir
409cdf0e10cSrcweir /*
410cdf0e10cSrcweir * compare an encrypted and an unencrypted password for equality
411cdf0e10cSrcweir * returns true if passwords are equal, false otherwise
412cdf0e10cSrcweir * Note: uses crypt() and a mutex instead of crypt_r() since crypt_r needs
413cdf0e10cSrcweir * more than 128KByte of external buffer for struct crypt_data
414cdf0e10cSrcweir */
415cdf0e10cSrcweir
416cdf0e10cSrcweir static sal_Bool SAL_CALL
osl_equalPasswords(const sal_Char * pEncryptedPassword,const sal_Char * pPlainPassword)417cdf0e10cSrcweir osl_equalPasswords ( const sal_Char *pEncryptedPassword, const sal_Char *pPlainPassword )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir static pthread_mutex_t crypt_mutex = PTHREAD_MUTEX_INITIALIZER;
420cdf0e10cSrcweir
421cdf0e10cSrcweir sal_Bool success;
422cdf0e10cSrcweir sal_Char salt[3];
423cdf0e10cSrcweir sal_Char *encrypted_plain;
424cdf0e10cSrcweir
425cdf0e10cSrcweir salt[0] = pEncryptedPassword[0];
426cdf0e10cSrcweir salt[1] = pEncryptedPassword[1];
427cdf0e10cSrcweir salt[2] = '\0';
428cdf0e10cSrcweir
429cdf0e10cSrcweir pthread_mutex_lock(&crypt_mutex);
430cdf0e10cSrcweir
431cdf0e10cSrcweir #ifndef CRYPT_LINK
432cdf0e10cSrcweir encrypted_plain = (sal_Char *)osl_dynamicCrypt( pPlainPassword, salt );
433cdf0e10cSrcweir #else
434cdf0e10cSrcweir encrypted_plain = (sal_Char *)crypt( pPlainPassword, salt );
435cdf0e10cSrcweir #endif
436cdf0e10cSrcweir success = (sal_Bool) (strcmp(pEncryptedPassword, encrypted_plain) == 0);
437cdf0e10cSrcweir
438cdf0e10cSrcweir pthread_mutex_unlock(&crypt_mutex);
439cdf0e10cSrcweir
440cdf0e10cSrcweir return success;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir #endif /* defined LINUX && !defined NOPAM */
osl_loginUser(rtl_uString * ustrUserName,rtl_uString * ustrPassword,oslSecurity * pSecurity)444cdf0e10cSrcweir oslSecurityError SAL_CALL osl_loginUser(
445cdf0e10cSrcweir rtl_uString *ustrUserName,
446cdf0e10cSrcweir rtl_uString *ustrPassword,
447cdf0e10cSrcweir oslSecurity *pSecurity
448cdf0e10cSrcweir )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir oslSecurityError Error;
451509a48ffSpfg rtl_String* strUserName=NULL;
452509a48ffSpfg rtl_String* strPassword=NULL;
453509a48ffSpfg sal_Char* pszUserName=NULL;
454509a48ffSpfg sal_Char* pszPassword=NULL;
455cdf0e10cSrcweir
456509a48ffSpfg if ( ustrUserName != NULL )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir
459cdf0e10cSrcweir rtl_uString2String( &strUserName,
460cdf0e10cSrcweir rtl_uString_getStr(ustrUserName),
461cdf0e10cSrcweir rtl_uString_getLength(ustrUserName),
462cdf0e10cSrcweir RTL_TEXTENCODING_UTF8,
463cdf0e10cSrcweir OUSTRING_TO_OSTRING_CVTFLAGS );
464cdf0e10cSrcweir pszUserName = rtl_string_getStr(strUserName);
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir
468509a48ffSpfg if ( ustrPassword != NULL )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir rtl_uString2String( &strPassword,
471cdf0e10cSrcweir rtl_uString_getStr(ustrPassword),
472cdf0e10cSrcweir rtl_uString_getLength(ustrPassword),
473cdf0e10cSrcweir RTL_TEXTENCODING_UTF8,
474cdf0e10cSrcweir OUSTRING_TO_OSTRING_CVTFLAGS );
475cdf0e10cSrcweir pszPassword = rtl_string_getStr(strPassword);
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir
479cdf0e10cSrcweir Error=osl_psz_loginUser(pszUserName,pszPassword,pSecurity);
480cdf0e10cSrcweir
481509a48ffSpfg if ( strUserName != NULL )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir rtl_string_release(strUserName);
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
486cdf0e10cSrcweir if ( strPassword)
487cdf0e10cSrcweir {
488cdf0e10cSrcweir rtl_string_release(strPassword);
489cdf0e10cSrcweir }
490cdf0e10cSrcweir
491cdf0e10cSrcweir
492cdf0e10cSrcweir return Error;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir
496cdf0e10cSrcweir static oslSecurityError SAL_CALL
osl_psz_loginUser(const sal_Char * pszUserName,const sal_Char * pszPasswd,oslSecurity * pSecurity)497cdf0e10cSrcweir osl_psz_loginUser(const sal_Char* pszUserName, const sal_Char* pszPasswd,
498cdf0e10cSrcweir oslSecurity* pSecurity)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir #if defined NETBSD || defined SCO || defined AIX || defined FREEBSD || \
501cdf0e10cSrcweir defined MACOSX
502cdf0e10cSrcweir
503cdf0e10cSrcweir return osl_Security_E_None;
504cdf0e10cSrcweir
505cdf0e10cSrcweir #else
506cdf0e10cSrcweir
507cdf0e10cSrcweir oslSecurityError nError = osl_Security_E_Unknown;
508cdf0e10cSrcweir oslSecurityImpl * p = NULL;
509cdf0e10cSrcweir if (pszUserName != NULL && pszPasswd != NULL && pSecurity != NULL) {
510cdf0e10cSrcweir /* get nis or normal password, should succeed for any known user, but
511cdf0e10cSrcweir perhaps the password is wrong (i.e. 'x') if shadow passwords are in
512cdf0e10cSrcweir use or authentication must be done by PAM */
513cdf0e10cSrcweir size_t n = 0;
514cdf0e10cSrcweir int err = 0;
515cdf0e10cSrcweir struct passwd * found = NULL;
516cdf0e10cSrcweir for (;;) {
517cdf0e10cSrcweir p = growSecurityImpl(p, &n);
518cdf0e10cSrcweir if (p == NULL) {
519cdf0e10cSrcweir break;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir err = getpwnam_r(
522cdf0e10cSrcweir pszUserName, &p->m_pPasswd, p->m_buffer, n, &found);
523cdf0e10cSrcweir if (err != ERANGE) {
524cdf0e10cSrcweir break;
525cdf0e10cSrcweir }
526cdf0e10cSrcweir }
527cdf0e10cSrcweir if (p != NULL && err == 0) {
528cdf0e10cSrcweir if (found == NULL) {
529cdf0e10cSrcweir nError = osl_Security_E_UserUnknown;
530cdf0e10cSrcweir } else {
531cdf0e10cSrcweir #if defined LINUX && !defined NOPAM
532cdf0e10cSrcweir /* only root is able to read the /etc/shadow passwd, a normal
533cdf0e10cSrcweir user even can't read his own encrypted passwd */
534cdf0e10cSrcweir if (osl_equalPasswords(p->m_pPasswd.pw_passwd, pszPasswd) ||
535cdf0e10cSrcweir osl_PamAuthentification(pszUserName, pszPasswd))
536cdf0e10cSrcweir {
537cdf0e10cSrcweir nError = osl_Security_E_None;
538cdf0e10cSrcweir } else {
539cdf0e10cSrcweir char buffer[1024];
540cdf0e10cSrcweir struct spwd result_buf;
541cdf0e10cSrcweir struct spwd * pShadowPasswd;
542cdf0e10cSrcweir buffer[0] = '\0';
543cdf0e10cSrcweir if (getspnam_r(
544cdf0e10cSrcweir pszUserName, &result_buf, buffer, sizeof buffer,
545cdf0e10cSrcweir &pShadowPasswd) == 0 &&
546cdf0e10cSrcweir pShadowPasswd != NULL)
547cdf0e10cSrcweir {
548cdf0e10cSrcweir nError =
549cdf0e10cSrcweir osl_equalPasswords(
550cdf0e10cSrcweir pShadowPasswd->sp_pwdp, pszPasswd)
551cdf0e10cSrcweir ? osl_Security_E_None
552cdf0e10cSrcweir : osl_Security_E_WrongPassword;
553cdf0e10cSrcweir } else if (getuid() == 0) {
554cdf0e10cSrcweir /* mfe: Try to verify the root-password via nis */
555cdf0e10cSrcweir if (getspnam_r(
556cdf0e10cSrcweir "root", &result_buf, buffer, sizeof buffer,
557cdf0e10cSrcweir &pShadowPasswd) == 0 &&
558cdf0e10cSrcweir pShadowPasswd != NULL &&
559cdf0e10cSrcweir osl_equalPasswords(
560cdf0e10cSrcweir pShadowPasswd->sp_pwdp, pszPasswd))
561cdf0e10cSrcweir {
562cdf0e10cSrcweir nError = osl_Security_E_None;
563cdf0e10cSrcweir } else {
564cdf0e10cSrcweir /* mfe: we can't get via nis (glibc2.0.x has bug in
565cdf0e10cSrcweir getspnam_r) we try it with the normal getspnam */
566cdf0e10cSrcweir static pthread_mutex_t pwmutex =
567cdf0e10cSrcweir PTHREAD_MUTEX_INITIALIZER;
568cdf0e10cSrcweir pthread_mutex_lock(&pwmutex);
569cdf0e10cSrcweir pShadowPasswd = getspnam("root");
570cdf0e10cSrcweir pthread_mutex_unlock(&pwmutex);
571cdf0e10cSrcweir nError =
572cdf0e10cSrcweir ((pShadowPasswd != NULL &&
573cdf0e10cSrcweir osl_equalPasswords(
574cdf0e10cSrcweir pShadowPasswd->sp_pwdp, pszPasswd)) ||
575cdf0e10cSrcweir osl_PamAuthentification("root", pszPasswd))
576cdf0e10cSrcweir ? osl_Security_E_None
577cdf0e10cSrcweir : osl_Security_E_WrongPassword;
578cdf0e10cSrcweir }
579cdf0e10cSrcweir }
580cdf0e10cSrcweir }
581cdf0e10cSrcweir #else
582cdf0e10cSrcweir char buffer[1024];
583cdf0e10cSrcweir struct spwd spwdStruct;
584cdf0e10cSrcweir buffer[0] = '\0';
5857994814dSHerbert Dürr #ifdef OLD_SHADOW_API
586cdf0e10cSrcweir if (getspnam_r(pszUserName, &spwdStruct, buffer, sizeof buffer) != NULL)
587cdf0e10cSrcweir #else
588cdf0e10cSrcweir if (getspnam_r(pszUserName, &spwdStruct, buffer, sizeof buffer, NULL) == 0)
589cdf0e10cSrcweir #endif
590cdf0e10cSrcweir {
591cdf0e10cSrcweir char salt[3];
592cdf0e10cSrcweir char * cryptPasswd;
593cdf0e10cSrcweir strncpy(salt, spwdStruct.sp_pwdp, 2);
594cdf0e10cSrcweir salt[2] = '\0';
595cdf0e10cSrcweir cryptPasswd = (char *) crypt(pszPasswd, salt);
596cdf0e10cSrcweir if (strcmp(spwdStruct.sp_pwdp, cryptPasswd) == 0) {
597cdf0e10cSrcweir nError = osl_Security_E_None;
598cdf0e10cSrcweir } else if (getuid() == 0 &&
5997994814dSHerbert Dürr #ifdef OLD_SHADOW_API
600cdf0e10cSrcweir (getspnam_r("root", &spwdStruct, buffer, sizeof buffer) != NULL))
601cdf0e10cSrcweir #else
602cdf0e10cSrcweir (getspnam_r("root", &spwdStruct, buffer, sizeof buffer, NULL) == 0))
603cdf0e10cSrcweir #endif
604cdf0e10cSrcweir {
605cdf0e10cSrcweir /* if current process is running as root, allow to logon
606cdf0e10cSrcweir as any other user */
607cdf0e10cSrcweir strncpy(salt, spwdStruct.sp_pwdp, 2);
608cdf0e10cSrcweir salt[2] = '\0';
609cdf0e10cSrcweir cryptPasswd = (char *) crypt(pszPasswd, salt);
610cdf0e10cSrcweir if (strcmp(spwdStruct.sp_pwdp, cryptPasswd) == 0) {
611cdf0e10cSrcweir nError = osl_Security_E_None;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir } else {
614cdf0e10cSrcweir nError = osl_Security_E_WrongPassword;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir }
617cdf0e10cSrcweir #endif
618cdf0e10cSrcweir }
619cdf0e10cSrcweir }
620cdf0e10cSrcweir }
621cdf0e10cSrcweir if (nError == osl_Security_E_None) {
622cdf0e10cSrcweir *pSecurity = p;
623cdf0e10cSrcweir } else {
624cdf0e10cSrcweir deleteSecurityImpl(p);
625cdf0e10cSrcweir *pSecurity = NULL;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir return nError;
628cdf0e10cSrcweir
629cdf0e10cSrcweir #endif
630cdf0e10cSrcweir }
631cdf0e10cSrcweir
osl_loginUserOnFileServer(rtl_uString * strUserName,rtl_uString * strPasswd,rtl_uString * strFileServer,oslSecurity * pSecurity)632cdf0e10cSrcweir oslSecurityError SAL_CALL osl_loginUserOnFileServer(
633cdf0e10cSrcweir rtl_uString *strUserName,
634cdf0e10cSrcweir rtl_uString *strPasswd,
635cdf0e10cSrcweir rtl_uString *strFileServer,
636cdf0e10cSrcweir oslSecurity *pSecurity
637cdf0e10cSrcweir )
638cdf0e10cSrcweir {
639cdf0e10cSrcweir (void) strUserName; /* unused */
640cdf0e10cSrcweir (void) strPasswd; /* unused */
641cdf0e10cSrcweir (void) strFileServer; /* unused */
642cdf0e10cSrcweir (void) pSecurity; /* unused */
643cdf0e10cSrcweir return osl_Security_E_UserUnknown;
644cdf0e10cSrcweir }
645cdf0e10cSrcweir
646cdf0e10cSrcweir
osl_getUserIdent(oslSecurity Security,rtl_uString ** ustrIdent)647cdf0e10cSrcweir sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **ustrIdent)
648cdf0e10cSrcweir {
649cdf0e10cSrcweir sal_Bool bRet=sal_False;
650cdf0e10cSrcweir sal_Char pszIdent[1024];
651cdf0e10cSrcweir
652cdf0e10cSrcweir pszIdent[0] = '\0';
653cdf0e10cSrcweir
654cdf0e10cSrcweir bRet = osl_psz_getUserIdent(Security,pszIdent,sizeof(pszIdent));
655cdf0e10cSrcweir
656cdf0e10cSrcweir rtl_string2UString( ustrIdent, pszIdent, rtl_str_getLength( pszIdent ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
657cdf0e10cSrcweir OSL_ASSERT(*ustrIdent != NULL);
658cdf0e10cSrcweir
659cdf0e10cSrcweir return bRet;
660cdf0e10cSrcweir }
661cdf0e10cSrcweir
662cdf0e10cSrcweir
osl_psz_getUserIdent(oslSecurity Security,sal_Char * pszIdent,sal_uInt32 nMax)663cdf0e10cSrcweir sal_Bool SAL_CALL osl_psz_getUserIdent(oslSecurity Security, sal_Char *pszIdent, sal_uInt32 nMax)
664cdf0e10cSrcweir {
665cdf0e10cSrcweir sal_Char buffer[32];
666cdf0e10cSrcweir sal_Int32 nChr;
667cdf0e10cSrcweir
668cdf0e10cSrcweir oslSecurityImpl *pSecImpl = (oslSecurityImpl *)Security;
669cdf0e10cSrcweir
670cdf0e10cSrcweir if (pSecImpl == NULL)
671cdf0e10cSrcweir return sal_False;
672cdf0e10cSrcweir
673cdf0e10cSrcweir nChr = snprintf(buffer, sizeof(buffer), "%u", pSecImpl->m_pPasswd.pw_uid);
674cdf0e10cSrcweir if ( nChr < 0 || SAL_INT_CAST(sal_uInt32, nChr) >= sizeof(buffer)
675cdf0e10cSrcweir || SAL_INT_CAST(sal_uInt32, nChr) >= nMax )
676cdf0e10cSrcweir return sal_False; /* leave *pszIdent unmodified in case of failure */
677cdf0e10cSrcweir
678cdf0e10cSrcweir memcpy(pszIdent, buffer, nChr+1);
679cdf0e10cSrcweir return sal_True;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir
osl_getUserName(oslSecurity Security,rtl_uString ** ustrName)682cdf0e10cSrcweir sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **ustrName)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir sal_Bool bRet=sal_False;
685cdf0e10cSrcweir sal_Char pszName[1024];
686cdf0e10cSrcweir
687cdf0e10cSrcweir pszName[0] = '\0';
688cdf0e10cSrcweir
689cdf0e10cSrcweir bRet = osl_psz_getUserName(Security,pszName,sizeof(pszName));
690cdf0e10cSrcweir
691cdf0e10cSrcweir rtl_string2UString( ustrName, pszName, rtl_str_getLength( pszName ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
692cdf0e10cSrcweir OSL_ASSERT(*ustrName != NULL);
693cdf0e10cSrcweir
694cdf0e10cSrcweir return bRet;
695cdf0e10cSrcweir }
696cdf0e10cSrcweir
697cdf0e10cSrcweir
698cdf0e10cSrcweir
osl_psz_getUserName(oslSecurity Security,sal_Char * pszName,sal_uInt32 nMax)699cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32 nMax)
700cdf0e10cSrcweir {
701cdf0e10cSrcweir oslSecurityImpl *pSecImpl = (oslSecurityImpl *)Security;
702cdf0e10cSrcweir
703cdf0e10cSrcweir if (pSecImpl == NULL)
704cdf0e10cSrcweir return sal_False;
705cdf0e10cSrcweir
706cdf0e10cSrcweir strncpy(pszName, pSecImpl->m_pPasswd.pw_name, nMax);
707cdf0e10cSrcweir
708cdf0e10cSrcweir return sal_True;
709cdf0e10cSrcweir }
710cdf0e10cSrcweir
osl_getHomeDir(oslSecurity Security,rtl_uString ** pustrDirectory)711cdf0e10cSrcweir sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory)
712cdf0e10cSrcweir {
713cdf0e10cSrcweir sal_Bool bRet=sal_False;
714cdf0e10cSrcweir sal_Char pszDirectory[PATH_MAX];
715cdf0e10cSrcweir
716cdf0e10cSrcweir pszDirectory[0] = '\0';
717cdf0e10cSrcweir
718cdf0e10cSrcweir bRet = osl_psz_getHomeDir(Security,pszDirectory,sizeof(pszDirectory));
719cdf0e10cSrcweir
720cdf0e10cSrcweir if ( bRet == sal_True )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir rtl_string2UString( pustrDirectory, pszDirectory, rtl_str_getLength( pszDirectory ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
723cdf0e10cSrcweir OSL_ASSERT(*pustrDirectory != NULL);
724cdf0e10cSrcweir osl_getFileURLFromSystemPath( *pustrDirectory, pustrDirectory );
725cdf0e10cSrcweir }
726cdf0e10cSrcweir
727cdf0e10cSrcweir return bRet;
728cdf0e10cSrcweir }
729cdf0e10cSrcweir
730cdf0e10cSrcweir
osl_psz_getHomeDir(oslSecurity Security,sal_Char * pszDirectory,sal_uInt32 nMax)731cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getHomeDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax)
732cdf0e10cSrcweir {
733cdf0e10cSrcweir oslSecurityImpl *pSecImpl = (oslSecurityImpl *)Security;
734cdf0e10cSrcweir
735cdf0e10cSrcweir if (pSecImpl == NULL)
736cdf0e10cSrcweir return sal_False;
737cdf0e10cSrcweir
738cdf0e10cSrcweir /* if current user, check also environment for HOME */
739cdf0e10cSrcweir if (getuid() == pSecImpl->m_pPasswd.pw_uid)
740cdf0e10cSrcweir {
741cdf0e10cSrcweir sal_Char *pStr = NULL;
742cdf0e10cSrcweir #ifdef SOLARIS
743cdf0e10cSrcweir char buffer[8192];
744cdf0e10cSrcweir
745cdf0e10cSrcweir struct passwd pwd;
746cdf0e10cSrcweir struct passwd *ppwd;
747cdf0e10cSrcweir
748cdf0e10cSrcweir #ifdef _POSIX_PTHREAD_SEMANTICS
749cdf0e10cSrcweir if ( 0 != getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &ppwd ) )
750cdf0e10cSrcweir ppwd = NULL;
751cdf0e10cSrcweir #else
752cdf0e10cSrcweir ppwd = getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer) );
753cdf0e10cSrcweir #endif
754cdf0e10cSrcweir
755cdf0e10cSrcweir if ( ppwd )
756cdf0e10cSrcweir pStr = ppwd->pw_dir;
757cdf0e10cSrcweir #else
758cdf0e10cSrcweir pStr = getenv("HOME");
759cdf0e10cSrcweir #endif
760cdf0e10cSrcweir
761cdf0e10cSrcweir if ((pStr != NULL) && (strlen(pStr) > 0) &&
762cdf0e10cSrcweir (access(pStr, 0) == 0))
763cdf0e10cSrcweir strncpy(pszDirectory, pStr, nMax);
764cdf0e10cSrcweir else
765cdf0e10cSrcweir strncpy(pszDirectory, pSecImpl->m_pPasswd.pw_dir, nMax);
766cdf0e10cSrcweir }
767cdf0e10cSrcweir else
768cdf0e10cSrcweir strncpy(pszDirectory, pSecImpl->m_pPasswd.pw_dir, nMax);
769cdf0e10cSrcweir
770cdf0e10cSrcweir return sal_True;
771cdf0e10cSrcweir }
772cdf0e10cSrcweir
osl_getConfigDir(oslSecurity Security,rtl_uString ** pustrDirectory)773cdf0e10cSrcweir sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDirectory)
774cdf0e10cSrcweir {
775cdf0e10cSrcweir sal_Bool bRet = sal_False;
776cdf0e10cSrcweir sal_Char pszDirectory[PATH_MAX];
777cdf0e10cSrcweir
778cdf0e10cSrcweir pszDirectory[0] = '\0';
779cdf0e10cSrcweir
780cdf0e10cSrcweir bRet = osl_psz_getConfigDir(Security,pszDirectory,sizeof(pszDirectory));
781cdf0e10cSrcweir
782cdf0e10cSrcweir if ( bRet == sal_True )
783cdf0e10cSrcweir {
784cdf0e10cSrcweir rtl_string2UString( pustrDirectory, pszDirectory, rtl_str_getLength( pszDirectory ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
785cdf0e10cSrcweir OSL_ASSERT(*pustrDirectory != NULL);
786cdf0e10cSrcweir osl_getFileURLFromSystemPath( *pustrDirectory, pustrDirectory );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir
789cdf0e10cSrcweir return bRet;
790cdf0e10cSrcweir }
791cdf0e10cSrcweir
792cdf0e10cSrcweir #ifndef MACOSX
793cdf0e10cSrcweir
osl_psz_getConfigDir(oslSecurity Security,sal_Char * pszDirectory,sal_uInt32 nMax)794cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax)
795cdf0e10cSrcweir {
796cdf0e10cSrcweir sal_Char *pStr = getenv("XDG_CONFIG_HOME");
797cdf0e10cSrcweir
798cdf0e10cSrcweir if ((pStr == NULL) || (strlen(pStr) == 0) ||
799cdf0e10cSrcweir (access(pStr, 0) != 0))
800cdf0e10cSrcweir return (osl_psz_getHomeDir(Security, pszDirectory, nMax));
801cdf0e10cSrcweir
802cdf0e10cSrcweir strncpy(pszDirectory, pStr, nMax);
803cdf0e10cSrcweir return sal_True;
804cdf0e10cSrcweir }
805cdf0e10cSrcweir
806cdf0e10cSrcweir #else
807cdf0e10cSrcweir
808cdf0e10cSrcweir /*
809cdf0e10cSrcweir * FIXME: rewrite to use more flexible
810cdf0e10cSrcweir * NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)
811cdf0e10cSrcweir * as soon as we can bumb the baseline to Tiger (for NSApplicationSupportDirectory) and have
812cdf0e10cSrcweir * support for Objective-C in the build environment
813cdf0e10cSrcweir */
814cdf0e10cSrcweir
815cdf0e10cSrcweir #define MACOSX_CONFIG_DIR "/Library/Application Support"
osl_psz_getConfigDir(oslSecurity Security,sal_Char * pszDirectory,sal_uInt32 nMax)816cdf0e10cSrcweir static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax)
817cdf0e10cSrcweir {
818cdf0e10cSrcweir if( osl_psz_getHomeDir(Security, pszDirectory, nMax - sizeof(MACOSX_CONFIG_DIR) + 1) )
819cdf0e10cSrcweir {
820cdf0e10cSrcweir strcat( pszDirectory, MACOSX_CONFIG_DIR );
821cdf0e10cSrcweir return sal_True;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir
824cdf0e10cSrcweir return sal_False;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir
827cdf0e10cSrcweir #endif
828cdf0e10cSrcweir
osl_isAdministrator(oslSecurity Security)829cdf0e10cSrcweir sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security)
830cdf0e10cSrcweir {
831cdf0e10cSrcweir oslSecurityImpl *pSecImpl = (oslSecurityImpl *)Security;
832cdf0e10cSrcweir
833cdf0e10cSrcweir if (pSecImpl == NULL)
834cdf0e10cSrcweir return sal_False;
835cdf0e10cSrcweir
836cdf0e10cSrcweir if (pSecImpl->m_pPasswd.pw_uid != 0)
837cdf0e10cSrcweir return (sal_False);
838cdf0e10cSrcweir
839cdf0e10cSrcweir return (sal_True);
840cdf0e10cSrcweir }
841cdf0e10cSrcweir
osl_freeSecurityHandle(oslSecurity Security)842cdf0e10cSrcweir void SAL_CALL osl_freeSecurityHandle(oslSecurity Security)
843cdf0e10cSrcweir {
844cdf0e10cSrcweir deleteSecurityImpl(Security);
845cdf0e10cSrcweir }
846cdf0e10cSrcweir
847cdf0e10cSrcweir
osl_loadUserProfile(oslSecurity Security)848cdf0e10cSrcweir sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security)
849cdf0e10cSrcweir {
850cdf0e10cSrcweir (void) Security; /* unused */
851cdf0e10cSrcweir return sal_False;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir
osl_unloadUserProfile(oslSecurity Security)854cdf0e10cSrcweir void SAL_CALL osl_unloadUserProfile(oslSecurity Security)
855cdf0e10cSrcweir {
856cdf0e10cSrcweir (void) Security; /* unused */
857cdf0e10cSrcweir }
858