]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3549] Spurious initgroups() error message
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 11 Nov 2018 11:03:14 +0000 (12:03 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 11 Nov 2018 11:03:14 +0000 (12:03 +0100)
bk: 5be80c72etERR8v9S3109Xyd6jkUAQ

ChangeLog
ntpd/ntpd.c

index f381a093cf948c1202162000eaf2d8abbf1a1dcf..42bcd34d7d411e4c5ce2511523e3de593aa4bf0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3549] Spurious initgroups() error message <perlinger@ntp.org>
+  - patch by Christous Zoulas
+
 ---
 (4.2.8p12) 2018/08/14 Released by Harlan Stenn <stenn@ntp.org>
 
index b477a71804bffc347b45f3ec3794c5a6bbd670ab..070d7e9b5c9af0afc7ad76b45799bb3b4c57092e 100644 (file)
@@ -688,24 +688,9 @@ getgroup:
        return 1;
 }
 
-/*
- * Change (effective) user and group IDs, also initialize the supplementary group access list
- */
-int
-set_user_group_ids(
-       )
+static int
+set_group_ids(void)
 {
-       /* If the the user was already mapped, no need to map it again */
-       if ((NULL != user) && (0 == sw_uid)) {
-               if (0 == map_user())
-                       exit (-1);
-       }
-       /* same applies for the group */
-       if ((NULL != group) && (0 == sw_gid)) {
-               if (0 == map_group())
-                       exit (-1);
-       }
-
        if (user && initgroups(user, sw_gid)) {
                msyslog(LOG_ERR, "Cannot initgroups() to user `%s': %m", user);
                return 0;
@@ -729,6 +714,12 @@ set_user_group_ids(
                        msyslog(LOG_ERR, "initgroups(<%s>, %d) filed: %m", pw->pw_name, pw->pw_gid);
                        return 0;
                }
+       return 1;
+}
+
+static int
+set_user_ids(void)
+{
        if (user && setuid(sw_uid)) {
                msyslog(LOG_ERR, "Cannot setuid() to user `%s': %m", user);
                return 0;
@@ -737,6 +728,31 @@ set_user_group_ids(
                msyslog(LOG_ERR, "Cannot seteuid() to user `%s': %m", user);
                return 0;
        }
+       return 1;
+}
+
+/*
+ * Change (effective) user and group IDs, also initialize the supplementary group access list
+ */
+int set_user_group_ids(void);
+int
+set_user_group_ids(void)
+{
+       /* If the the user was already mapped, no need to map it again */
+       if ((NULL != user) && (0 == sw_uid)) {
+               if (0 == map_user())
+                       exit (-1);
+       }
+       /* same applies for the group */
+       if ((NULL != group) && (0 == sw_gid)) {
+               if (0 == map_group())
+                       exit (-1);
+       }
+
+       if (getegid() != sw_gid && 0 == set_group_ids())
+               return 0;
+       if (geteuid() != sw_uid && 0 == set_user_ids())
+               return 0;
 
        return 1;
 }