exports.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SELinux services exported to the rest of the kernel.
  3. *
  4. * Author: James Morris <jmorris@redhat.com>
  5. *
  6. * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
  7. * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2,
  11. * as published by the Free Software Foundation.
  12. */
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/selinux.h>
  17. #include <linux/fs.h>
  18. #include <linux/ipc.h>
  19. #include "security.h"
  20. #include "objsec.h"
  21. void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid)
  22. {
  23. struct task_security_struct *tsec = tsk->security;
  24. if (selinux_enabled)
  25. *ctxid = tsec->sid;
  26. else
  27. *ctxid = 0;
  28. }
  29. int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
  30. {
  31. if (selinux_enabled)
  32. return security_sid_to_context(ctxid, ctx, ctxlen);
  33. else {
  34. *ctx = NULL;
  35. *ctxlen = 0;
  36. }
  37. return 0;
  38. }
  39. void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
  40. {
  41. if (selinux_enabled) {
  42. struct inode_security_struct *isec = inode->i_security;
  43. *sid = isec->sid;
  44. return;
  45. }
  46. *sid = 0;
  47. }
  48. void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
  49. {
  50. if (selinux_enabled) {
  51. struct ipc_security_struct *isec = ipcp->security;
  52. *sid = isec->sid;
  53. return;
  54. }
  55. *sid = 0;
  56. }