3
0

selinux_common.c 946 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * libbb/selinux_common.c
  3. * -- common SELinux utility functions
  4. *
  5. * Copyright 2007 KaiGai Kohei <kaigai@kaigai.gr.jp>
  6. */
  7. #include "libbb.h"
  8. #include <selinux/context.h>
  9. context_t set_security_context_component(security_context_t cur_context,
  10. char *user, char *role, char *type, char *range)
  11. {
  12. context_t con = context_new(cur_context);
  13. if (!con)
  14. return NULL;
  15. if (user && context_user_set(con, user))
  16. goto error;
  17. if (type && context_type_set(con, type))
  18. goto error;
  19. if (range && context_range_set(con, range))
  20. goto error;
  21. if (role && context_role_set(con, role))
  22. goto error;
  23. return con;
  24. error:
  25. context_free(con);
  26. return NULL;
  27. }
  28. void setfscreatecon_or_die(security_context_t scontext)
  29. {
  30. if (setfscreatecon(scontext) < 0) {
  31. /* Can be NULL. All known printf implementations
  32. * display "(null)", "<null>" etc */
  33. bb_perror_msg_and_die("cannot set default "
  34. "file creation context to %s", scontext);
  35. }
  36. }