get security_class_t for objects
Hi,
as an userspace object manager which uses libselinux, I am trying to use avc_has_perm(3) for determining access decisions. when I open a file, I can get its security context and change it to SID by using fgetfilecon(3) and avc_context_to_sid(3), respectively. but when I want to have access decision by calling avc_has_perm(3), I am not sure what to pass as the third argument,that is security_class_t. I would like to know if there is any API by which I can determine an already opened file`s class. may some one direct me to a sample code please
Best regards.
Quoted 10 lines · michel m
Hi,
as an userspace object manager which uses libselinux, I am trying to useavc_has_perm(3)for determining access decisions. when I open a file, I can get its security context and change it to SID by using fgetfilecon(3) andavc_context_to_sid(3), respectively. but when I want to have access decision by callingavc_has_perm(3), I am not sure what to pass as the third argument,that issecurity_class_t. I would like to know if there is any API by which I can determine an already opened file`s class. may some one direct me to a sample code please
You generally figure out that third parameter by using string_to_security_class() (found in libselinux, discussed in the selinux_check_passwd_access thread a few days ago). That will convert a string class name to a security_class_t. As far as an API to determine the class of an already opened file, fstat() combined with S_ISREG/S_ISDIR/etc. should do the trick. A bit more work than you might like, but that's how I'd do it.
Thanks,
Chad
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
thanks Chad,
but may you explain your tricky solution a bit more.
Regards.
Quoted 29 lines · Chad Sellers
Quoted 3 lines · michel m
Hi,
as an userspace object manager which uses libselinux, I am trying to useavc_has_perm(3)for determining access decisions. when I open a file, Ican
Quoted 2 lines
get its security context and change it to SID by using fgetfilecon(3) and
avc_context_to_sid(3), respectively. but when I want to have accessdecision
Quoted 2 lines
by calling
avc_has_perm(3), I am not sure what to pass as the third argument,that issecurity_class_t. I would like to know if there is anyAPI by
Quoted 1 line
which I can determine an already opened file`s class. may some one direct
me
Quoted 2 lines
to a sample code please
You generally figure out that third parameter by using
string_to_security_class()(found in libselinux, discussed in theselinux_check_passwd_accessthread a few days ago). That will convert a string class name to asecurity_class_t. As far as an API to determine the class of an already opened file,fstat()combined with S_ISREG/S_ISDIR/etc. should do the trick. A bit more work than you might like, but that's how I'd
do it.Thanks,
Chad
Quoted 3 lines · michel m
thanks Chad,
but may you explain your tricky solution a bit more.
Sure. I mean something like this:
fstat(fd, &statbuf);
if (S_ISREG(statbuf.st_mode))
class_string = "file";
else if (S_ISCHR(statbuf.st_mode))
class_string = "chr_file";
else if (S_ISBLK(statbuf.st_mode))
class_string = "blk_file";...
class = string_to_security_class(class_string);
Hope that helps,
Chad
Quoted 29 lines
Regards.
Quoted 24 lines · Chad Sellers
Quoted 11 lines · michel m
Hi,
as an userspace object manager which uses libselinux, I am trying to useavc_has_perm(3)for determining access decisions. when I open a file, I can get its security context and change it to SID by using fgetfilecon(3) andavc_context_to_sid(3), respectively. but when I want to have access decision by callingavc_has_perm(3), I am not sure what to pass as the third argument,that issecurity_class_t. I would like to know if there is any API by
which I can determine an already opened file`s class. may some one direct me to a sample code pleaseYou generally figure out that third parameter by using
string_to_security_class()(found in libselinux, discussed in theselinux_check_passwd_accessthread a few days ago). That will convert a string class name to asecurity_class_t. As far as an API to determine the class of an already opened file,fstat()combined with S_ISREG/S_ISDIR/etc. should do the trick. A bit more work than you might like, but that's how I'd do it.Thanks,
Chad
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.