user_namespace.h 1.9 KB
Newer Older
1 2 3 4 5 6
#ifndef _LINUX_USER_NAMESPACE_H
#define _LINUX_USER_NAMESPACE_H

#include <linux/kref.h>
#include <linux/nsproxy.h>
#include <linux/sched.h>
S
Serge E. Hallyn 已提交
7
#include <linux/err.h>
8

9 10 11 12 13 14 15 16 17 18 19
#define UID_GID_MAP_MAX_EXTENTS 5

struct uid_gid_map {	/* 64 bytes -- 1 cache line */
	u32 nr_extents;
	struct uid_gid_extent {
		u32 first;
		u32 lower_first;
		u32 count;
	} extent[UID_GID_MAP_MAX_EXTENTS];
};

20
struct user_namespace {
21 22
	struct uid_gid_map	uid_map;
	struct uid_gid_map	gid_map;
23
	struct uid_gid_map	projid_map;
24
	struct kref		kref;
25
	struct user_namespace	*parent;
26 27
	kuid_t			owner;
	kgid_t			group;
28
	unsigned int		proc_inum;
29 30 31 32 33 34 35 36 37 38 39 40 41
};

extern struct user_namespace init_user_ns;

#ifdef CONFIG_USER_NS

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
{
	if (ns)
		kref_get(&ns->kref);
	return ns;
}

42
extern int create_user_ns(struct cred *new);
43
extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
44 45 46 47 48 49 50 51
extern void free_user_ns(struct kref *kref);

static inline void put_user_ns(struct user_namespace *ns)
{
	if (ns)
		kref_put(&ns->kref, free_user_ns);
}

52 53 54
struct seq_operations;
extern struct seq_operations proc_uid_seq_operations;
extern struct seq_operations proc_gid_seq_operations;
55
extern struct seq_operations proc_projid_seq_operations;
56 57
extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
58
extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
59 60 61 62 63 64 65
#else

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
{
	return &init_user_ns;
}

66
static inline int create_user_ns(struct cred *new)
67
{
68
	return -EINVAL;
69 70
}

71 72 73 74 75 76 77 78
static inline int unshare_userns(unsigned long unshare_flags,
				 struct cred **new_cred)
{
	if (unshare_flags & CLONE_NEWUSER)
		return -EINVAL;
	return 0;
}

79 80 81 82
static inline void put_user_ns(struct user_namespace *ns)
{
}

83 84
#endif

85
#endif /* _LINUX_USER_H */