aboutsummaryrefslogtreecommitdiff
path: root/crypto/compat
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2014-07-10 06:21:51 -0500
committerBrent Cook <busterb@gmail.com>2014-07-10 06:22:54 -0500
commit2b6dbc39ef274d5298daad1ff864be8fc3c56537 (patch)
treebed05f6232bad0278f952bcfa173c50c202f4309 /crypto/compat
parente9eff5016a4ec2153c037c1b888acd2755965755 (diff)
downloadportable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.tar.gz
portable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.tar.bz2
portable-2b6dbc39ef274d5298daad1ff864be8fc3c56537.zip
initial top-level import of subdirectories
Diffstat (limited to 'crypto/compat')
-rw-r--r--crypto/compat/issetugid_linux.c47
-rw-r--r--crypto/compat/thread_private.h6
2 files changed, 53 insertions, 0 deletions
diff --git a/crypto/compat/issetugid_linux.c b/crypto/compat/issetugid_linux.c
new file mode 100644
index 0000000..669edce
--- /dev/null
+++ b/crypto/compat/issetugid_linux.c
@@ -0,0 +1,47 @@
1/*
2 * issetugid implementation for Linux
3 * Public domain
4 */
5
6#include <errno.h>
7#include <gnu/libc-version.h>
8#include <string.h>
9#include <sys/types.h>
10#include <unistd.h>
11
12/*
13 * Linux-specific glibc 2.16+ interface for determining if a process was
14 * launched setuid/setgid or with additional capabilities.
15 */
16#ifdef HAVE_GETAUXVAL
17#include <sys/auxv.h>
18#endif
19
20int issetugid(void)
21{
22#ifdef HAVE_GETAUXVAL
23 /*
24 * The API for glibc < 2.19 does not indicate if there is an error with
25 * getauxval. While it should not be the case that any 2.6 or greater
26 * kernel ever does not supply AT_SECURE, an emulated software environment
27 * might rewrite the aux vector.
28 *
29 * See https://sourceware.org/bugzilla/show_bug.cgi?id=15846
30 *
31 * Perhaps this code should just read the aux vector itself, so we have
32 * backward-compatibility and error handling in older glibc versions.
33 * info: http://lwn.net/Articles/519085/
34 *
35 */
36 const char *glcv = gnu_get_libc_version();
37 if (strverscmp(glcv, "2.19") >= 0) {
38 errno = 0;
39 if (getauxval(AT_SECURE) == 0) {
40 if (errno != ENOENT) {
41 return 0;
42 }
43 }
44 }
45#endif
46 return 1;
47}
diff --git a/crypto/compat/thread_private.h b/crypto/compat/thread_private.h
new file mode 100644
index 0000000..3286a7c
--- /dev/null
+++ b/crypto/compat/thread_private.h
@@ -0,0 +1,6 @@
1#include <pthread.h>
2
3static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
4
5#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
6#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)