1
2 #ifndef _LINUX_HIGHUID_H
3 #define _LINUX_HIGHUID_H
4
5 #include <linux/types.h>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 extern int overflowuid;
36 extern int overflowgid;
37
38 extern void __bad_uid(void);
39 extern void __bad_gid(void);
40
41 #define DEFAULT_OVERFLOWUID 65534
42 #define DEFAULT_OVERFLOWGID 65534
43
44 #ifdef CONFIG_UID16
45
46
47 #define high2lowuid(uid) ((uid) & ~0xFFFF ? (old_uid_t)overflowuid : (old_uid_t)(uid))
48 #define high2lowgid(gid) ((gid) & ~0xFFFF ? (old_gid_t)overflowgid : (old_gid_t)(gid))
49
50
51
52
53 #define low2highuid(uid) ((uid) == (old_uid_t)-1 ? (uid_t)-1 : (uid_t)(uid))
54 #define low2highgid(gid) ((gid) == (old_gid_t)-1 ? (gid_t)-1 : (gid_t)(gid))
55
56 #define __convert_uid(size, uid) \
57 (size >= sizeof(uid) ? (uid) : high2lowuid(uid))
58 #define __convert_gid(size, gid) \
59 (size >= sizeof(gid) ? (gid) : high2lowgid(gid))
60
61
62 #else
63
64 #define __convert_uid(size, uid) (uid)
65 #define __convert_gid(size, gid) (gid)
66
67 #endif
68
69
70 #define SET_UID(var, uid) do { (var) = __convert_uid(sizeof(var), (uid)); } while (0)
71 #define SET_GID(var, gid) do { (var) = __convert_gid(sizeof(var), (gid)); } while (0)
72
73
74
75
76
77
78
79
80
81
82 extern int fs_overflowuid;
83 extern int fs_overflowgid;
84
85 #define DEFAULT_FS_OVERFLOWUID 65534
86 #define DEFAULT_FS_OVERFLOWGID 65534
87
88
89
90
91
92 #define fs_high2lowuid(uid) ((uid) & ~0xFFFF ? (uid16_t)fs_overflowuid : (uid16_t)(uid))
93 #define fs_high2lowgid(gid) ((gid) & ~0xFFFF ? (gid16_t)fs_overflowgid : (gid16_t)(gid))
94
95 #define low_16_bits(x) ((x) & 0xFFFF)
96 #define high_16_bits(x) (((x) & 0xFFFF0000) >> 16)
97
98 #endif