user_namespace.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _LINUX_USER_NAMESPACE_H
  2. #define _LINUX_USER_NAMESPACE_H
  3. #include <linux/kref.h>
  4. #include <linux/nsproxy.h>
  5. #include <linux/sched.h>
  6. #include <linux/err.h>
  7. #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 7)
  8. #define UIDHASH_SZ (1 << UIDHASH_BITS)
  9. struct user_namespace {
  10. struct kref kref;
  11. struct hlist_head uidhash_table[UIDHASH_SZ];
  12. struct user_namespace *parent;
  13. struct user_struct *creator;
  14. struct work_struct destroyer;
  15. };
  16. extern struct user_namespace init_user_ns;
  17. #ifdef CONFIG_USER_NS
  18. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  19. {
  20. if (ns)
  21. kref_get(&ns->kref);
  22. return ns;
  23. }
  24. extern int create_user_ns(struct cred *new);
  25. extern void free_user_ns(struct kref *kref);
  26. static inline void put_user_ns(struct user_namespace *ns)
  27. {
  28. if (ns)
  29. kref_put(&ns->kref, free_user_ns);
  30. }
  31. uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
  32. gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
  33. #else
  34. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  35. {
  36. return &init_user_ns;
  37. }
  38. static inline int create_user_ns(struct cred *new)
  39. {
  40. return -EINVAL;
  41. }
  42. static inline void put_user_ns(struct user_namespace *ns)
  43. {
  44. }
  45. static inline uid_t user_ns_map_uid(struct user_namespace *to,
  46. const struct cred *cred, uid_t uid)
  47. {
  48. return uid;
  49. }
  50. static inline gid_t user_ns_map_gid(struct user_namespace *to,
  51. const struct cred *cred, gid_t gid)
  52. {
  53. return gid;
  54. }
  55. #endif
  56. #endif /* _LINUX_USER_H */