aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/procattr.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2014-02-19 09:16:17 -0500
committerStephen Smalley <sds@tycho.nsa.gov>2014-02-19 16:11:48 -0500
commit9eb9c9327563014ad6a807814e7975424642d5b9 (patch)
tree050b6180a59af9ee7622c80171d734f319c178f0 /libselinux/src/procattr.c
parent1cb368636bdaf465cd63178a0692db38865e943b (diff)
downloadandroid_external_selinux-9eb9c9327563014ad6a807814e7975424642d5b9.tar.gz
android_external_selinux-9eb9c9327563014ad6a807814e7975424642d5b9.tar.bz2
android_external_selinux-9eb9c9327563014ad6a807814e7975424642d5b9.zip
Get rid of security_context_t and fix const declarations.
In attempting to enable building various part of Android with -Wall -Werror, we found that the const security_context_t declarations in libselinux are incorrect; const char * was intended, but const security_context_t translates to char * const and triggers warnings on passing const char * from the caller. Easiest fix is to replace them all with const char *. And while we are at it, just get rid of all usage of security_context_t itself as it adds no value - there is no true encapsulation of the security context strings and callers already directly use string functions on them. typedef left to permit building legacy users until such a time as all are updated. This is a port of Change-Id I2f9df7bb9f575f76024c3e5f5b660345da2931a7 from Android, augmented to deal with all of the other code in upstream libselinux and updating the man pages too. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'libselinux/src/procattr.c')
-rw-r--r--libselinux/src/procattr.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
index 9fa61380..f9903505 100644
--- a/libselinux/src/procattr.c
+++ b/libselinux/src/procattr.c
@@ -9,15 +9,15 @@
#include "selinux_internal.h"
#include "policy.h"
-#define UNSET (const security_context_t) -1
+#define UNSET (char *) -1
static __thread pid_t cpid;
static __thread pid_t tid;
-static __thread security_context_t prev_current = UNSET;
-static __thread security_context_t prev_exec = UNSET;
-static __thread security_context_t prev_fscreate = UNSET;
-static __thread security_context_t prev_keycreate = UNSET;
-static __thread security_context_t prev_sockcreate = UNSET;
+static __thread char *prev_current = UNSET;
+static __thread char * prev_exec = UNSET;
+static __thread char * prev_fscreate = UNSET;
+static __thread char * prev_keycreate = UNSET;
+static __thread char * prev_sockcreate = UNSET;
static pthread_once_t once = PTHREAD_ONCE_INIT;
static pthread_key_t destructor_key;
@@ -107,7 +107,7 @@ static int openattr(pid_t pid, const char *attr, int flags)
return fd;
}
-static int getprocattrcon_raw(security_context_t * context,
+static int getprocattrcon_raw(char ** context,
pid_t pid, const char *attr)
{
char *buf;
@@ -115,7 +115,7 @@ static int getprocattrcon_raw(security_context_t * context,
int fd;
ssize_t ret;
int errno_hold;
- security_context_t prev_context;
+ char * prev_context;
__selinux_once(once, init_procattr);
init_thread_destructor();
@@ -193,11 +193,11 @@ static int getprocattrcon_raw(security_context_t * context,
return ret;
}
-static int getprocattrcon(security_context_t * context,
+static int getprocattrcon(char ** context,
pid_t pid, const char *attr)
{
int ret;
- security_context_t rcontext;
+ char * rcontext;
ret = getprocattrcon_raw(&rcontext, pid, attr);
@@ -209,13 +209,13 @@ static int getprocattrcon(security_context_t * context,
return ret;
}
-static int setprocattrcon_raw(security_context_t context,
+static int setprocattrcon_raw(const char * context,
pid_t pid, const char *attr)
{
int fd;
ssize_t ret;
int errno_hold;
- security_context_t *prev_context;
+ char **prev_context, *context2 = NULL;
__selinux_once(once, init_procattr);
init_thread_destructor();
@@ -255,11 +255,11 @@ static int setprocattrcon_raw(security_context_t context,
return -1;
if (context) {
ret = -1;
- context = strdup(context);
- if (!context)
+ context2 = strdup(context);
+ if (!context2)
goto out;
do {
- ret = write(fd, context, strlen(context) + 1);
+ ret = write(fd, context2, strlen(context2) + 1);
} while (ret < 0 && errno == EINTR);
} else {
do {
@@ -271,21 +271,21 @@ out:
close(fd);
errno = errno_hold;
if (ret < 0) {
- free(context);
+ free(context2);
return -1;
} else {
if (*prev_context != UNSET)
free(*prev_context);
- *prev_context = context;
+ *prev_context = context2;
return 0;
}
}
-static int setprocattrcon(const security_context_t context,
+static int setprocattrcon(const char * context,
pid_t pid, const char *attr)
{
int ret;
- security_context_t rcontext;
+ char * rcontext;
if (selinux_trans_to_raw_context(context, &rcontext))
return -1;
@@ -298,21 +298,21 @@ static int setprocattrcon(const security_context_t context,
}
#define getselfattr_def(fn, attr) \
- int get##fn##_raw(security_context_t *c) \
+ int get##fn##_raw(char **c) \
{ \
return getprocattrcon_raw(c, 0, #attr); \
} \
- int get##fn(security_context_t *c) \
+ int get##fn(char **c) \
{ \
return getprocattrcon(c, 0, #attr); \
}
#define setselfattr_def(fn, attr) \
- int set##fn##_raw(const security_context_t c) \
+ int set##fn##_raw(const char * c) \
{ \
return setprocattrcon_raw(c, 0, #attr); \
} \
- int set##fn(const security_context_t c) \
+ int set##fn(const char * c) \
{ \
return setprocattrcon(c, 0, #attr); \
}
@@ -322,11 +322,11 @@ static int setprocattrcon(const security_context_t context,
setselfattr_def(fn, attr)
#define getpidattr_def(fn, attr) \
- int get##fn##_raw(pid_t pid, security_context_t *c) \
+ int get##fn##_raw(pid_t pid, char **c) \
{ \
return getprocattrcon_raw(c, pid, #attr); \
} \
- int get##fn(pid_t pid, security_context_t *c) \
+ int get##fn(pid_t pid, char **c) \
{ \
return getprocattrcon(c, pid, #attr); \
}