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 | |
Pavel Emelyanov | 6164281 | 2011-01-12 17:00:46 -0800 | [diff] [blame] | 9 | #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 7) |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 10 | #define UIDHASH_SZ (1 << UIDHASH_BITS) |
| 11 | |
| 12 | struct user_namespace { |
| 13 | struct kref kref; |
Pavel Emelyanov | 735de22 | 2007-09-18 22:46:44 -0700 | [diff] [blame] | 14 | struct hlist_head uidhash_table[UIDHASH_SZ]; |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 15 | struct user_struct *creator; |
David Howells | 5170836 | 2009-02-27 14:03:03 -0800 | [diff] [blame] | 16 | struct work_struct destroyer; |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | extern struct user_namespace init_user_ns; |
| 20 | |
| 21 | #ifdef CONFIG_USER_NS |
| 22 | |
| 23 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) |
| 24 | { |
| 25 | if (ns) |
| 26 | kref_get(&ns->kref); |
| 27 | return ns; |
| 28 | } |
| 29 | |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 30 | extern int create_user_ns(struct cred *new); |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 31 | extern void free_user_ns(struct kref *kref); |
| 32 | |
| 33 | static inline void put_user_ns(struct user_namespace *ns) |
| 34 | { |
| 35 | if (ns) |
| 36 | kref_put(&ns->kref, free_user_ns); |
| 37 | } |
| 38 | |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 39 | uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid); |
| 40 | gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid); |
| 41 | |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 42 | #else |
| 43 | |
| 44 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) |
| 45 | { |
| 46 | return &init_user_ns; |
| 47 | } |
| 48 | |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 49 | static inline int create_user_ns(struct cred *new) |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 50 | { |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 51 | return -EINVAL; |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static inline void put_user_ns(struct user_namespace *ns) |
| 55 | { |
| 56 | } |
| 57 | |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 58 | static inline uid_t user_ns_map_uid(struct user_namespace *to, |
| 59 | const struct cred *cred, uid_t uid) |
| 60 | { |
| 61 | return uid; |
| 62 | } |
| 63 | static inline gid_t user_ns_map_gid(struct user_namespace *to, |
| 64 | const struct cred *cred, gid_t gid) |
| 65 | { |
| 66 | return gid; |
| 67 | } |
| 68 | |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | #endif /* _LINUX_USER_H */ |