Is there a way in C to get the SELinux context of a file?


Yes, it’s getfilecon(3) in libselinux:

char * context;
int easize = getfilecon("/path/to/your/file", &context);

If the returned size is non-negative, context contains the file’s context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.