blob: dc2d85a76376cf5f2b69de01bc2d32be0900384d [file] [log] [blame]
Cedric Le Goateracce2922007-07-15 23:40:59 -07001#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. Hallyn77ec7392007-07-15 23:41:01 -07007#include <linux/err.h>
Cedric Le Goateracce2922007-07-15 23:40:59 -07008
Pavel Emelyanov61642812011-01-12 17:00:46 -08009#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 7)
Cedric Le Goateracce2922007-07-15 23:40:59 -070010#define UIDHASH_SZ (1 << UIDHASH_BITS)
11
12struct user_namespace {
13 struct kref kref;
Pavel Emelyanov735de222007-09-18 22:46:44 -070014 struct hlist_head uidhash_table[UIDHASH_SZ];
Eric W. Biedermanaeb3ae92011-11-16 21:59:43 -080015 struct user_namespace *parent;
Serge Hallyn18b6e042008-10-15 16:38:45 -050016 struct user_struct *creator;
David Howells51708362009-02-27 14:03:03 -080017 struct work_struct destroyer;
Cedric Le Goateracce2922007-07-15 23:40:59 -070018};
19
20extern struct user_namespace init_user_ns;
21
22#ifdef CONFIG_USER_NS
23
24static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
25{
26 if (ns)
27 kref_get(&ns->kref);
28 return ns;
29}
30
Serge Hallyn18b6e042008-10-15 16:38:45 -050031extern int create_user_ns(struct cred *new);
Cedric Le Goateracce2922007-07-15 23:40:59 -070032extern void free_user_ns(struct kref *kref);
33
34static inline void put_user_ns(struct user_namespace *ns)
35{
36 if (ns)
37 kref_put(&ns->kref, free_user_ns);
38}
39
Eric W. Biederman5c1469d2010-06-13 03:28:03 +000040uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
41gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
42
Cedric Le Goateracce2922007-07-15 23:40:59 -070043#else
44
45static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
46{
47 return &init_user_ns;
48}
49
Serge Hallyn18b6e042008-10-15 16:38:45 -050050static inline int create_user_ns(struct cred *new)
Cedric Le Goateracce2922007-07-15 23:40:59 -070051{
Serge Hallyn18b6e042008-10-15 16:38:45 -050052 return -EINVAL;
Cedric Le Goateracce2922007-07-15 23:40:59 -070053}
54
55static inline void put_user_ns(struct user_namespace *ns)
56{
57}
58
Eric W. Biederman5c1469d2010-06-13 03:28:03 +000059static inline uid_t user_ns_map_uid(struct user_namespace *to,
60 const struct cred *cred, uid_t uid)
61{
62 return uid;
63}
64static inline gid_t user_ns_map_gid(struct user_namespace *to,
65 const struct cred *cred, gid_t gid)
66{
67 return gid;
68}
69
Cedric Le Goateracce2922007-07-15 23:40:59 -070070#endif
71
72#endif /* _LINUX_USER_H */