mirror of
https://github.com/SELinuxProject/selinux
synced 2024-12-30 10:02:15 +00:00
9eb9c93275
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>
44 lines
804 B
C
44 lines
804 B
C
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <sys/xattr.h>
|
|
#include "selinux_internal.h"
|
|
#include "policy.h"
|
|
|
|
int fsetfilecon_raw(int fd, const char * context)
|
|
{
|
|
int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
|
|
0);
|
|
if (rc < 0 && errno == ENOTSUP) {
|
|
char * ccontext = NULL;
|
|
int err = errno;
|
|
if ((fgetfilecon_raw(fd, &ccontext) >= 0) &&
|
|
(strcmp(context,ccontext) == 0)) {
|
|
rc = 0;
|
|
} else {
|
|
errno = err;
|
|
}
|
|
freecon(ccontext);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
hidden_def(fsetfilecon_raw)
|
|
|
|
int fsetfilecon(int fd, const char *context)
|
|
{
|
|
int ret;
|
|
char * rcontext;
|
|
|
|
if (selinux_trans_to_raw_context(context, &rcontext))
|
|
return -1;
|
|
|
|
ret = fsetfilecon_raw(fd, rcontext);
|
|
|
|
freecon(rcontext);
|
|
|
|
return ret;
|
|
}
|