Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_USER_NAMESPACE_H |
| 2 | #define _LINUX_USER_NAMESPACE_H |
| 3 | |
| 4 | #include <linux/kref.h> |
| 5 | #include <linux/nsproxy.h> |
| 6 | #include <linux/sched.h> |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 7 | #include <linux/err.h> |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 8 | |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 9 | struct user_namespace { |
| 10 | struct kref kref; |
Eric W. Biederman | aeb3ae9 | 2011-11-16 21:59:43 -0800 | [diff] [blame] | 11 | struct user_namespace *parent; |
Eric W. Biederman | 783291e | 2011-11-17 01:32:59 -0800 | [diff] [blame^] | 12 | kuid_t owner; |
| 13 | kgid_t group; |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 14 | }; |
| 15 | |
| 16 | extern struct user_namespace init_user_ns; |
| 17 | |
| 18 | #ifdef CONFIG_USER_NS |
| 19 | |
| 20 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) |
| 21 | { |
| 22 | if (ns) |
| 23 | kref_get(&ns->kref); |
| 24 | return ns; |
| 25 | } |
| 26 | |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 27 | extern int create_user_ns(struct cred *new); |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 28 | extern void free_user_ns(struct kref *kref); |
| 29 | |
| 30 | static inline void put_user_ns(struct user_namespace *ns) |
| 31 | { |
| 32 | if (ns) |
| 33 | kref_put(&ns->kref, free_user_ns); |
| 34 | } |
| 35 | |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 36 | uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid); |
| 37 | gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid); |
| 38 | |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 39 | #else |
| 40 | |
| 41 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) |
| 42 | { |
| 43 | return &init_user_ns; |
| 44 | } |
| 45 | |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 46 | static inline int create_user_ns(struct cred *new) |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 47 | { |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 48 | return -EINVAL; |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static inline void put_user_ns(struct user_namespace *ns) |
| 52 | { |
| 53 | } |
| 54 | |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 55 | static inline uid_t user_ns_map_uid(struct user_namespace *to, |
| 56 | const struct cred *cred, uid_t uid) |
| 57 | { |
| 58 | return uid; |
| 59 | } |
| 60 | static inline gid_t user_ns_map_gid(struct user_namespace *to, |
| 61 | const struct cred *cred, gid_t gid) |
| 62 | { |
| 63 | return gid; |
| 64 | } |
| 65 | |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | #endif /* _LINUX_USER_H */ |