Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150308160
D40640.id124435.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D40640.id124435.diff
View Options
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1281,36 +1281,44 @@
}
/*
- * Check if gid is a member of the group set.
+ * Returns whether gid designates a supplementary group in cred.
+ */
+static int
+supplementary_group_member
+(gid_t gid, struct ucred *cred)
+{
+ int l, h, m;
+
+ /*
+ * Perform a binary search of the supplemental groups. This is possible
+ * because we sort the groups in crsetgroups().
+ */
+ l = 1;
+ h = cred->cr_ngroups;
+
+ while (l < h) {
+ m = l + (h - l) / 2;
+ if (cred->cr_groups[m] < gid)
+ l = m + 1;
+ else
+ h = m;
+ }
+
+ return (l < cred->cr_ngroups && cred->cr_groups[l] == gid);
+}
+
+/*
+ * Check if gid is a member of the (effective) group set (i.e., effective and
+ * supplementary groups).
*/
int
groupmember(gid_t gid, struct ucred *cred)
{
- int l;
- int h;
- int m;
if (cred->cr_groups[0] == gid)
- return(1);
-
- /*
- * If gid was not our primary group, perform a binary search
- * of the supplemental groups. This is possible because we
- * sort the groups in crsetgroups().
- */
- l = 1;
- h = cred->cr_ngroups;
- while (l < h) {
- m = l + ((h - l) / 2);
- if (cred->cr_groups[m] < gid)
- l = m + 1;
- else
- h = m;
- }
- if ((l < cred->cr_ngroups) && (cred->cr_groups[l] == gid))
return (1);
- return (0);
+ return (supplementary_group_member(gid, cred));
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 1, 2:16 AM (15 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30660474
Default Alt Text
D40640.id124435.diff (1 KB)
Attached To
Mode
D40640: groupmember(): Extract the supplementary group search in a separate function
Attached
Detach File
Event Timeline
Log In to Comment