secid.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor security identifier (secid) manipulation fns
  5. *
  6. * Copyright 2009-2010 Canonical Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation, version 2 of the
  11. * License.
  12. *
  13. *
  14. * AppArmor allocates a unique secid for every profile loaded. If a profile
  15. * is replaced it receives the secid of the profile it is replacing.
  16. *
  17. * The secid value of 0 is invalid.
  18. */
  19. #include <linux/spinlock.h>
  20. #include <linux/errno.h>
  21. #include <linux/err.h>
  22. #include "include/secid.h"
  23. /* global counter from which secids are allocated */
  24. static u32 global_secid;
  25. static DEFINE_SPINLOCK(secid_lock);
  26. /* TODO FIXME: add secid to profile mapping, and secid recycling */
  27. /**
  28. * aa_alloc_secid - allocate a new secid for a profile
  29. */
  30. u32 aa_alloc_secid(void)
  31. {
  32. u32 secid;
  33. /*
  34. * TODO FIXME: secid recycling - part of profile mapping table
  35. */
  36. spin_lock(&secid_lock);
  37. secid = (++global_secid);
  38. spin_unlock(&secid_lock);
  39. return secid;
  40. }
  41. /**
  42. * aa_free_secid - free a secid
  43. * @secid: secid to free
  44. */
  45. void aa_free_secid(u32 secid)
  46. {
  47. ; /* NOP ATM */
  48. }