diff options
author | rhatdan <dwalsh@redhat.com> | 2012-10-17 15:28:49 -0400 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2013-02-05 20:14:40 -0500 |
commit | 13b599d7b80c1464683f66a1e93e02b984d94c1d (patch) | |
tree | 997f4d1706ce25a983b2d82db22d89ddf70c2f36 /libselinux/src/stringrep.c | |
parent | 067a436cf58b122fae0d5061e8414a33f4b0a991 (diff) | |
download | android_external_selinux-13b599d7b80c1464683f66a1e93e02b984d94c1d.tar.gz android_external_selinux-13b599d7b80c1464683f66a1e93e02b984d94c1d.tar.bz2 android_external_selinux-13b599d7b80c1464683f66a1e93e02b984d94c1d.zip |
libselinux: mode_to_security_class: interface to translate a mode_t in to a security class
coreutils needs to be able to take a statbuf and ask permissions
questions. This gives us the interface to translate that statbuf mode_t
into a security class which can be used.
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libselinux/src/stringrep.c')
-rw-r--r-- | libselinux/src/stringrep.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libselinux/src/stringrep.c b/libselinux/src/stringrep.c index 176ac34e..082778e5 100644 --- a/libselinux/src/stringrep.c +++ b/libselinux/src/stringrep.c @@ -436,6 +436,27 @@ security_class_t string_to_security_class(const char *s) return map_class(node->value); } +security_class_t mode_to_security_class(mode_t m) { + + if (S_ISREG(m)) + return string_to_security_class("file"); + if (S_ISDIR(m)) + return string_to_security_class("dir"); + if (S_ISCHR(m)) + return string_to_security_class("chr_file"); + if (S_ISBLK(m)) + return string_to_security_class("blk_file"); + if (S_ISFIFO(m)) + return string_to_security_class("fifo_file"); + if (S_ISLNK(m)) + return string_to_security_class("lnk_file"); + if (S_ISSOCK(m)) + return string_to_security_class("sock_file"); + + errno=EINVAL; + return 0; +} + access_vector_t string_to_av_perm(security_class_t tclass, const char *s) { struct discover_class_node *node; |