user_namespace.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. struct user_namespace {
  8. struct kref kref;
  9. struct user_namespace *parent;
  10. struct user_struct *creator;
  11. struct work_struct destroyer;
  12. };
  13. extern struct user_namespace init_user_ns;
  14. #ifdef CONFIG_USER_NS
  15. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  16. {
  17. if (ns)
  18. kref_get(&ns->kref);
  19. return ns;
  20. }
  21. extern int create_user_ns(struct cred *new);
  22. extern void free_user_ns(struct kref *kref);
  23. static inline void put_user_ns(struct user_namespace *ns)
  24. {
  25. if (ns)
  26. kref_put(&ns->kref, free_user_ns);
  27. }
  28. uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
  29. gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
  30. #else
  31. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  32. {
  33. return &init_user_ns;
  34. }
  35. static inline int create_user_ns(struct cred *new)
  36. {
  37. return -EINVAL;
  38. }
  39. static inline void put_user_ns(struct user_namespace *ns)
  40. {
  41. }
  42. static inline uid_t user_ns_map_uid(struct user_namespace *to,
  43. const struct cred *cred, uid_t uid)
  44. {
  45. return uid;
  46. }
  47. static inline gid_t user_ns_map_gid(struct user_namespace *to,
  48. const struct cred *cred, gid_t gid)
  49. {
  50. return gid;
  51. }
  52. #endif
  53. #endif /* _LINUX_USER_H */