OLD | NEW |
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | 5 |
6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdlib.h> |
7 #include "primpl.h" | 8 #include "primpl.h" |
8 #include "prmem.h" | 9 #include "prmem.h" |
9 | 10 |
10 #if defined(XP_UNIX) | 11 #if defined(XP_UNIX) |
| 12 #include <unistd.h> |
11 #if defined(DARWIN) | 13 #if defined(DARWIN) |
12 #if defined(HAVE_CRT_EXTERNS_H) | 14 #if defined(HAVE_CRT_EXTERNS_H) |
13 #include <crt_externs.h> | 15 #include <crt_externs.h> |
14 #endif /* HAVE_CRT_EXTERNS_H */ | 16 #endif /* HAVE_CRT_EXTERNS_H */ |
15 #else /* DARWIN */ | 17 #else /* DARWIN */ |
16 PR_IMPORT_DATA(char **) environ; | 18 PR_IMPORT_DATA(char **) environ; |
17 #endif /* DARWIN */ | 19 #endif /* DARWIN */ |
18 #endif /* XP_UNIX */ | 20 #endif /* XP_UNIX */ |
19 | 21 |
| 22 #if !defined(HAVE_SECURE_GETENV) && defined(HAVE___SECURE_GETENV) |
| 23 #define secure_getenv __secure_getenv |
| 24 #define HAVE_SECURE_GETENV 1 |
| 25 #endif |
| 26 |
20 /* Lock used to lock the environment */ | 27 /* Lock used to lock the environment */ |
21 #if defined(_PR_NO_PREEMPT) | 28 #if defined(_PR_NO_PREEMPT) |
22 #define _PR_NEW_LOCK_ENV() | 29 #define _PR_NEW_LOCK_ENV() |
23 #define _PR_DELETE_LOCK_ENV() | 30 #define _PR_DELETE_LOCK_ENV() |
24 #define _PR_LOCK_ENV() | 31 #define _PR_LOCK_ENV() |
25 #define _PR_UNLOCK_ENV() | 32 #define _PR_UNLOCK_ENV() |
26 #elif defined(_PR_LOCAL_THREADS_ONLY) | 33 #elif defined(_PR_LOCAL_THREADS_ONLY) |
27 extern _PRCPU * _pr_primordialCPU; | 34 extern _PRCPU * _pr_primordialCPU; |
28 static PRIntn _is; | 35 static PRIntn _is; |
29 #define _PR_NEW_LOCK_ENV() | 36 #define _PR_NEW_LOCK_ENV() |
(...skipping 26 matching lines...) Expand all Loading... |
56 char *ev; | 63 char *ev; |
57 | 64 |
58 if (!_pr_initialized) _PR_ImplicitInitialization(); | 65 if (!_pr_initialized) _PR_ImplicitInitialization(); |
59 | 66 |
60 _PR_LOCK_ENV(); | 67 _PR_LOCK_ENV(); |
61 ev = _PR_MD_GET_ENV(var); | 68 ev = _PR_MD_GET_ENV(var); |
62 _PR_UNLOCK_ENV(); | 69 _PR_UNLOCK_ENV(); |
63 return ev; | 70 return ev; |
64 } | 71 } |
65 | 72 |
| 73 PR_IMPLEMENT(char*) PR_GetEnvSecure(const char *var) |
| 74 { |
| 75 #ifdef HAVE_SECURE_GETENV |
| 76 char *ev; |
| 77 |
| 78 if (!_pr_initialized) _PR_ImplicitInitialization(); |
| 79 |
| 80 _PR_LOCK_ENV(); |
| 81 ev = secure_getenv(var); |
| 82 _PR_UNLOCK_ENV(); |
| 83 |
| 84 return ev; |
| 85 #else |
| 86 #ifdef XP_UNIX |
| 87 /* |
| 88 ** Fall back to checking uids and gids. This won't detect any other |
| 89 ** privilege-granting mechanisms the platform may have. This also |
| 90 ** can't detect the case where the process already called |
| 91 ** setuid(geteuid()) and/or setgid(getegid()). |
| 92 */ |
| 93 if (getuid() != geteuid() || getgid() != getegid()) { |
| 94 return NULL; |
| 95 } |
| 96 #endif /* XP_UNIX */ |
| 97 return PR_GetEnv(var); |
| 98 #endif /* HAVE_SECURE_GETENV */ |
| 99 } |
| 100 |
66 PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) | 101 PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) |
67 { | 102 { |
68 PRIntn result; | 103 PRIntn result; |
69 | 104 |
70 if (!_pr_initialized) _PR_ImplicitInitialization(); | 105 if (!_pr_initialized) _PR_ImplicitInitialization(); |
71 | 106 |
72 if (!strchr(string, '=')) return(PR_FAILURE); | 107 if (!strchr(string, '=')) return(PR_FAILURE); |
73 | 108 |
74 _PR_LOCK_ENV(); | 109 _PR_LOCK_ENV(); |
75 result = _PR_MD_PUT_ENV((char*)string); | 110 result = _PR_MD_PUT_ENV((char*)string); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 _PR_UNLOCK_ENV(); | 153 _PR_UNLOCK_ENV(); |
119 return result; | 154 return result; |
120 } | 155 } |
121 #else | 156 #else |
122 /* This platform doesn't support raw access to the environ block. */ | 157 /* This platform doesn't support raw access to the environ block. */ |
123 PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void) | 158 PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void) |
124 { | 159 { |
125 return NULL; | 160 return NULL; |
126 } | 161 } |
127 #endif | 162 #endif |
OLD | NEW |