summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorDave Brolley <brolley@redhat.com>2009-11-20 17:10:06 -0500
committerDave Brolley <brolley@redhat.com>2009-11-20 17:10:06 -0500
commitbaba4e15bf291b698986f703c9ec89742012922c (patch)
treea778df0c15576e30e468d0c28a497e2037fca7c3 /util.cxx
parente16e0c563bf44a234396dbcfd2d0b6cfaac91078 (diff)
downloadsystemtap-steved-baba4e15bf291b698986f703c9ec89742012922c.tar.gz
systemtap-steved-baba4e15bf291b698986f703c9ec89742012922c.tar.xz
systemtap-steved-baba4e15bf291b698986f703c9ec89742012922c.zip
Allow members of the group stap-server to build the uprobes module.
Diffstat (limited to 'util.cxx')
-rw-r--r--util.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/util.cxx b/util.cxx
index b81d37cb..3887fcd1 100644
--- a/util.cxx
+++ b/util.cxx
@@ -22,6 +22,7 @@
extern "C" {
#include <fcntl.h>
+#include <grp.h>
#include <pwd.h>
#include <spawn.h>
#include <stdio.h>
@@ -188,6 +189,48 @@ remove_file_or_dir (const char *name)
return 0;
}
+// Determine whether the current user is in the given group.
+bool
+egid_in (const char *gname)
+{
+ gid_t gid, gidlist[NGROUPS_MAX];
+ gid_t target_gid;
+ int i, ngids;
+ struct group *group;
+
+ // Lookup the gid for the target group
+ errno = 0;
+ group = getgrnam(gname);
+
+ // If we couldn't find the group, then we can't be part of it.
+ if (group == NULL)
+ return false;
+
+ target_gid = group->gr_gid;
+
+ // According to the getgroups() man page, getgroups() may not
+ // return the effective gid, so try to match it first. */
+ gid = getegid();
+ if (gid == target_gid)
+ return true;
+
+ // Get the list of the user's groups.
+ ngids = getgroups(NGROUPS_MAX, gidlist);
+ if (ngids < 0) {
+ cerr << "Unable to retrieve group list" << endl;
+ return false;
+ }
+
+ for (i = 0; i < ngids; i++) {
+ // If the user is a member of the target group, then we're done.
+ if (gidlist[i] == target_gid)
+ return true;
+ }
+
+ // The user is not a member of the target group
+ return false;
+}
+
void
tokenize(const string& str, vector<string>& tokens,
const string& delimiters = " ")