]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/user_namespace.h
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[net-next-2.6.git] / include / linux / user_namespace.h
CommitLineData
acce292c
CLG
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>
77ec739d 7#include <linux/err.h>
acce292c
CLG
8
9#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
10#define UIDHASH_SZ (1 << UIDHASH_BITS)
11
12struct user_namespace {
13 struct kref kref;
735de223 14 struct hlist_head uidhash_table[UIDHASH_SZ];
18b6e041 15 struct user_struct *creator;
51708366 16 struct work_struct destroyer;
acce292c
CLG
17};
18
19extern struct user_namespace init_user_ns;
20
21#ifdef CONFIG_USER_NS
22
23static 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
18b6e041 30extern int create_user_ns(struct cred *new);
acce292c
CLG
31extern void free_user_ns(struct kref *kref);
32
33static inline void put_user_ns(struct user_namespace *ns)
34{
35 if (ns)
36 kref_put(&ns->kref, free_user_ns);
37}
38
5c1469de
EB
39uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
40gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
41
acce292c
CLG
42#else
43
44static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
45{
46 return &init_user_ns;
47}
48
18b6e041 49static inline int create_user_ns(struct cred *new)
acce292c 50{
18b6e041 51 return -EINVAL;
acce292c
CLG
52}
53
54static inline void put_user_ns(struct user_namespace *ns)
55{
56}
57
5c1469de
EB
58static inline uid_t user_ns_map_uid(struct user_namespace *to,
59 const struct cred *cred, uid_t uid)
60{
61 return uid;
62}
63static 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
acce292c
CLG
69#endif
70
71#endif /* _LINUX_USER_H */