user_namespace.h 1.5 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 kref		kref;
24
	struct user_namespace	*parent;
25 26
	kuid_t			owner;
	kgid_t			group;
27 28 29 30 31 32 33 34 35 36 37 38 39
};

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;
}

40
extern int create_user_ns(struct cred *new);
41 42 43 44 45 46 47 48
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);
}

49 50 51 52 53
struct seq_operations;
extern struct seq_operations proc_uid_seq_operations;
extern struct seq_operations proc_gid_seq_operations;
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 *);
54 55 56 57 58 59 60
#else

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

61
static inline int create_user_ns(struct cred *new)
62
{
63
	return -EINVAL;
64 65 66 67 68 69
}

static inline void put_user_ns(struct user_namespace *ns)
{
}

70 71
#endif

72
#endif /* _LINUX_USER_H */