printf: Remove unused 'bprintf'
[drm/drm-misc.git] / include / linux / uidgid.h
blobf85ec5613721fe1b4fc6c51b80c9a32cc617c19b
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_UIDGID_H
3 #define _LINUX_UIDGID_H
5 /*
6 * A set of types for the internal kernel types representing uids and gids.
8 * The types defined in this header allow distinguishing which uids and gids in
9 * the kernel are values used by userspace and which uid and gid values are
10 * the internal kernel values. With the addition of user namespaces the values
11 * can be different. Using the type system makes it possible for the compiler
12 * to detect when we overlook these differences.
15 #include <linux/uidgid_types.h>
16 #include <linux/highuid.h>
18 struct user_namespace;
19 extern struct user_namespace init_user_ns;
20 struct uid_gid_map;
22 #define KUIDT_INIT(value) (kuid_t){ value }
23 #define KGIDT_INIT(value) (kgid_t){ value }
25 #ifdef CONFIG_MULTIUSER
26 static inline uid_t __kuid_val(kuid_t uid)
28 return uid.val;
31 static inline gid_t __kgid_val(kgid_t gid)
33 return gid.val;
35 #else
36 static inline uid_t __kuid_val(kuid_t uid)
38 return 0;
41 static inline gid_t __kgid_val(kgid_t gid)
43 return 0;
45 #endif
47 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
48 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
50 #define INVALID_UID KUIDT_INIT(-1)
51 #define INVALID_GID KGIDT_INIT(-1)
53 static inline bool uid_eq(kuid_t left, kuid_t right)
55 return __kuid_val(left) == __kuid_val(right);
58 static inline bool gid_eq(kgid_t left, kgid_t right)
60 return __kgid_val(left) == __kgid_val(right);
63 static inline bool uid_gt(kuid_t left, kuid_t right)
65 return __kuid_val(left) > __kuid_val(right);
68 static inline bool gid_gt(kgid_t left, kgid_t right)
70 return __kgid_val(left) > __kgid_val(right);
73 static inline bool uid_gte(kuid_t left, kuid_t right)
75 return __kuid_val(left) >= __kuid_val(right);
78 static inline bool gid_gte(kgid_t left, kgid_t right)
80 return __kgid_val(left) >= __kgid_val(right);
83 static inline bool uid_lt(kuid_t left, kuid_t right)
85 return __kuid_val(left) < __kuid_val(right);
88 static inline bool gid_lt(kgid_t left, kgid_t right)
90 return __kgid_val(left) < __kgid_val(right);
93 static inline bool uid_lte(kuid_t left, kuid_t right)
95 return __kuid_val(left) <= __kuid_val(right);
98 static inline bool gid_lte(kgid_t left, kgid_t right)
100 return __kgid_val(left) <= __kgid_val(right);
103 static inline bool uid_valid(kuid_t uid)
105 return __kuid_val(uid) != (uid_t) -1;
108 static inline bool gid_valid(kgid_t gid)
110 return __kgid_val(gid) != (gid_t) -1;
113 #ifdef CONFIG_USER_NS
115 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
116 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
118 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
119 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
120 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
121 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
123 static inline bool kuid_has_mapping(struct user_namespace *ns, kuid_t uid)
125 return from_kuid(ns, uid) != (uid_t) -1;
128 static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
130 return from_kgid(ns, gid) != (gid_t) -1;
133 u32 map_id_down(struct uid_gid_map *map, u32 id);
134 u32 map_id_up(struct uid_gid_map *map, u32 id);
136 #else
138 static inline kuid_t make_kuid(struct user_namespace *from, uid_t uid)
140 return KUIDT_INIT(uid);
143 static inline kgid_t make_kgid(struct user_namespace *from, gid_t gid)
145 return KGIDT_INIT(gid);
148 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
150 return __kuid_val(kuid);
153 static inline gid_t from_kgid(struct user_namespace *to, kgid_t kgid)
155 return __kgid_val(kgid);
158 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
160 uid_t uid = from_kuid(to, kuid);
161 if (uid == (uid_t)-1)
162 uid = overflowuid;
163 return uid;
166 static inline gid_t from_kgid_munged(struct user_namespace *to, kgid_t kgid)
168 gid_t gid = from_kgid(to, kgid);
169 if (gid == (gid_t)-1)
170 gid = overflowgid;
171 return gid;
174 static inline bool kuid_has_mapping(struct user_namespace *ns, kuid_t uid)
176 return uid_valid(uid);
179 static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
181 return gid_valid(gid);
184 static inline u32 map_id_down(struct uid_gid_map *map, u32 id)
186 return id;
189 static inline u32 map_id_up(struct uid_gid_map *map, u32 id)
191 return id;
193 #endif /* CONFIG_USER_NS */
195 #endif /* _LINUX_UIDGID_H */