CHANGES: snmpd: FEATURES: 1019429: Set supplementary groups via initgroups(3)
git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@16437 06827809-a52a-0410-b366-d66718629ded
diff --git a/agent/snmpd.c b/agent/snmpd.c
index 2ab395d..bc115f5 100644
--- a/agent/snmpd.c
+++ b/agent/snmpd.c
@@ -429,6 +429,9 @@
int fd;
FILE *PID;
#endif
+#if HAVE_GETPWNAM && HAVE_PWD_H
+ struct passwd *info;
+#endif
#ifndef WIN32
/*
@@ -735,7 +738,6 @@
uid = strtoul(optarg, &ecp, 10);
if (*ecp) {
#if HAVE_GETPWNAM && HAVE_PWD_H
- struct passwd *info;
info = getpwnam(optarg);
if (info) {
uid = info->pw_uid;
@@ -980,6 +982,19 @@
exit(1);
}
}
+#if HAVE_GETPWNAM && HAVE_PWD_H && HAVE_INITGROUPS
+ info = getpwuid(uid);
+ if (info) {
+ DEBUGMSGTL(("snmpd/main", "Supplementary groups for %s.\n", info->pw_name));
+ if (initgroups(info->pw_name, (gid != 0 ? gid : info->pw_gid)) == -1) {
+ snmp_log_perror("initgroups failed");
+ if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+ NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
+ exit(1);
+ }
+ }
+ }
+#endif
}
#endif
#endif
diff --git a/configure b/configure
index 10582d2..5538b56 100755
--- a/configure
+++ b/configure
@@ -39644,7 +39644,8 @@
-for ac_func in getpwnam getgrnam setgid setuid setgroups
+
+for ac_func in getpwnam getgrnam setgid setuid setgroups initgroups
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
diff --git a/configure.in b/configure.in
index 862070e..5c1a764 100644
--- a/configure.in
+++ b/configure.in
@@ -3630,7 +3630,7 @@
# solaris checks
AC_CHECK_FUNCS(getpagesize)
AC_CHECK_FUNCS(mkstemp)
-AC_CHECK_FUNCS(getpwnam getgrnam setgid setuid setgroups)
+AC_CHECK_FUNCS(getpwnam getgrnam setgid setuid setgroups initgroups)
# High resolution alarm support
AC_CHECK_FUNCS(setitimer)
# functions to support the clock.
diff --git a/include/net-snmp/net-snmp-config.h.in b/include/net-snmp/net-snmp-config.h.in
index 2eaf8cc..9b52e45 100644
--- a/include/net-snmp/net-snmp-config.h.in
+++ b/include/net-snmp/net-snmp-config.h.in
@@ -719,6 +719,9 @@
/* Define to 1 if you have the `setgroups' function. */
#undef HAVE_SETGROUPS
+/* Define to 1 if you have the `initgroups' function. */
+#undef HAVE_INITGROUPS
+
/* Define to 1 if you have the `setitimer' function. */
#undef HAVE_SETITIMER