blob: 8a391bd53de26c266d101d57d84c2879524c2038 [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
Cedric Le Goateracce2922007-07-15 23:40:59 -07009struct user_namespace {
10 struct kref kref;
Eric W. Biedermanaeb3ae92011-11-16 21:59:43 -080011 struct user_namespace *parent;
Eric W. Biederman783291e2011-11-17 01:32:59 -080012 kuid_t owner;
13 kgid_t group;
Cedric Le Goateracce2922007-07-15 23:40:59 -070014};
15
16extern struct user_namespace init_user_ns;
17
18#ifdef CONFIG_USER_NS
19
20static 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 Hallyn18b6e042008-10-15 16:38:45 -050027extern int create_user_ns(struct cred *new);
Cedric Le Goateracce2922007-07-15 23:40:59 -070028extern void free_user_ns(struct kref *kref);
29
30static 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. Biederman5c1469d2010-06-13 03:28:03 +000036uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
37gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
38
Cedric Le Goateracce2922007-07-15 23:40:59 -070039#else
40
41static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
42{
43 return &init_user_ns;
44}
45
Serge Hallyn18b6e042008-10-15 16:38:45 -050046static inline int create_user_ns(struct cred *new)
Cedric Le Goateracce2922007-07-15 23:40:59 -070047{
Serge Hallyn18b6e042008-10-15 16:38:45 -050048 return -EINVAL;
Cedric Le Goateracce2922007-07-15 23:40:59 -070049}
50
51static inline void put_user_ns(struct user_namespace *ns)
52{
53}
54
Eric W. Biederman5c1469d2010-06-13 03:28:03 +000055static inline uid_t user_ns_map_uid(struct user_namespace *to,
56 const struct cred *cred, uid_t uid)
57{
58 return uid;
59}
60static 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 Goateracce2922007-07-15 23:40:59 -070066#endif
67
68#endif /* _LINUX_USER_H */