1 #ifndef _LINUX_UIDGID_H
2 #define _LINUX_UIDGID_H
5 * A set of types for the internal kernel types representing uids and gids.
7 * The types defined in this header allow distinguishing which uids and gids in
8 * the kernel are values used by userspace and which uid and gid values are
9 * the internal kernel values. With the addition of user namespaces the values
10 * can be different. Using the type system makes it possible for the compiler
11 * to detect when we overlook these differences.
14 #include <linux/types.h>
15 #include <linux/highuid.h>
17 struct user_namespace
;
18 extern struct user_namespace init_user_ns
;
29 #define KUIDT_INIT(value) (kuid_t){ value }
30 #define KGIDT_INIT(value) (kgid_t){ value }
32 #ifdef CONFIG_MULTIUSER
33 static inline uid_t
__kuid_val(kuid_t uid
)
38 static inline gid_t
__kgid_val(kgid_t gid
)
43 static inline uid_t
__kuid_val(kuid_t uid
)
48 static inline gid_t
__kgid_val(kgid_t gid
)
54 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
55 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
57 #define INVALID_UID KUIDT_INIT(-1)
58 #define INVALID_GID KGIDT_INIT(-1)
60 static inline bool uid_eq(kuid_t left
, kuid_t right
)
62 return __kuid_val(left
) == __kuid_val(right
);
65 static inline bool gid_eq(kgid_t left
, kgid_t right
)
67 return __kgid_val(left
) == __kgid_val(right
);
70 static inline bool uid_gt(kuid_t left
, kuid_t right
)
72 return __kuid_val(left
) > __kuid_val(right
);
75 static inline bool gid_gt(kgid_t left
, kgid_t right
)
77 return __kgid_val(left
) > __kgid_val(right
);
80 static inline bool uid_gte(kuid_t left
, kuid_t right
)
82 return __kuid_val(left
) >= __kuid_val(right
);
85 static inline bool gid_gte(kgid_t left
, kgid_t right
)
87 return __kgid_val(left
) >= __kgid_val(right
);
90 static inline bool uid_lt(kuid_t left
, kuid_t right
)
92 return __kuid_val(left
) < __kuid_val(right
);
95 static inline bool gid_lt(kgid_t left
, kgid_t right
)
97 return __kgid_val(left
) < __kgid_val(right
);
100 static inline bool uid_lte(kuid_t left
, kuid_t right
)
102 return __kuid_val(left
) <= __kuid_val(right
);
105 static inline bool gid_lte(kgid_t left
, kgid_t right
)
107 return __kgid_val(left
) <= __kgid_val(right
);
110 static inline bool uid_valid(kuid_t uid
)
112 return __kuid_val(uid
) != (uid_t
) -1;
115 static inline bool gid_valid(kgid_t gid
)
117 return __kgid_val(gid
) != (gid_t
) -1;
120 #ifdef CONFIG_USER_NS
122 extern kuid_t
make_kuid(struct user_namespace
*from
, uid_t uid
);
123 extern kgid_t
make_kgid(struct user_namespace
*from
, gid_t gid
);
125 extern uid_t
from_kuid(struct user_namespace
*to
, kuid_t uid
);
126 extern gid_t
from_kgid(struct user_namespace
*to
, kgid_t gid
);
127 extern uid_t
from_kuid_munged(struct user_namespace
*to
, kuid_t uid
);
128 extern gid_t
from_kgid_munged(struct user_namespace
*to
, kgid_t gid
);
130 static inline bool kuid_has_mapping(struct user_namespace
*ns
, kuid_t uid
)
132 return from_kuid(ns
, uid
) != (uid_t
) -1;
135 static inline bool kgid_has_mapping(struct user_namespace
*ns
, kgid_t gid
)
137 return from_kgid(ns
, gid
) != (gid_t
) -1;
142 static inline kuid_t
make_kuid(struct user_namespace
*from
, uid_t uid
)
144 return KUIDT_INIT(uid
);
147 static inline kgid_t
make_kgid(struct user_namespace
*from
, gid_t gid
)
149 return KGIDT_INIT(gid
);
152 static inline uid_t
from_kuid(struct user_namespace
*to
, kuid_t kuid
)
154 return __kuid_val(kuid
);
157 static inline gid_t
from_kgid(struct user_namespace
*to
, kgid_t kgid
)
159 return __kgid_val(kgid
);
162 static inline uid_t
from_kuid_munged(struct user_namespace
*to
, kuid_t kuid
)
164 uid_t uid
= from_kuid(to
, kuid
);
165 if (uid
== (uid_t
)-1)
170 static inline gid_t
from_kgid_munged(struct user_namespace
*to
, kgid_t kgid
)
172 gid_t gid
= from_kgid(to
, kgid
);
173 if (gid
== (gid_t
)-1)
178 static inline bool kuid_has_mapping(struct user_namespace
*ns
, kuid_t uid
)
183 static inline bool kgid_has_mapping(struct user_namespace
*ns
, kgid_t gid
)
188 #endif /* CONFIG_USER_NS */
190 #endif /* _LINUX_UIDGID_H */