Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37402835
en ru br
Репозитории ALT
S:1.46-alt0.2
5.1: 1.45-alt3
4.1: 1.45-alt2
4.0: 1.45-alt2
3.0: 1.44-alt1
www.altlinux.org/Changes

Группа :: Мониторинг
Пакет: ngrep

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: ngrep-1.45-alt-chroot.patch
Скачать


--- ngrep.c.orig	2006-11-28 16:38:43 +0300
+++ ngrep.c	2007-01-04 17:03:59 +0300
@@ -92,9 +92,9 @@
 #endif
 
 #if USE_PCRE
-#include "pcre-5.0/pcre.h"
+#include <pcre/pcre.h>
 #else
-#include "regex-0.12/regex.h"
+#include <regex.h>
 #endif
 
 #include "ngrep.h"
@@ -1173,43 +1173,45 @@ void update_windowsize(int32_t e) {
         }
     }
 }
+#endif /* !defined(_WIN32) */
 
-#if USE_DROPPRIVS
+#if defined(USE_DROPPRIVS) && !defined(_WIN32)                                                                               
+#define DROPPRIVS_DIR "/var/resolv"
 void drop_privs(void) {
     struct passwd *pw;
     uid_t newuid;
     gid_t newgid;
 
-    if ((getuid() || geteuid()) || dont_dropprivs)
+    if (dont_dropprivs || geteuid())
         return;
 
     pw = getpwnam(DROPPRIVS_USER);
     if (!pw) {
-        perror("attempt to drop privileges failed: getpwnam failed");
+	perror("attempt to drop privileges failed: user \"" DROPPRIVS_USER "\" lookup failed");
         clean_exit(-1);
     }
 
     newgid = pw->pw_gid;
     newuid = pw->pw_uid;
+    endpwent();
 
-    if (getgroups(0, NULL) > 0)
-        if (setgroups(1, &newgid) == -1) {
-            perror("attempt to drop privileges failed");
-            clean_exit(-1);
-        }
+    if (chdir(DROPPRIVS_DIR) < 0 || chroot(".") < 0) {
+        perror("attempt to drop privileges failed: chdir/chroot to \"" DROPPRIVS_DIR "\" failed");
+        clean_exit(-1);
+    }
 
-    if (((getgid()  != newgid) && (setgid(newgid)  == -1)) ||
-        ((getegid() != newgid) && (setegid(newgid) == -1)) ||
-        ((getuid()  != newuid) && (setuid(newuid)  == -1)) ||
-        ((geteuid() != newuid) && (seteuid(newuid) == -1))) {
+    if (setgroups(1, &newgid) < 0) {
+        perror("attempt to drop privileges failed: setgroups failed");
+        clean_exit(-1);
+    }
 
-        perror("attempt to drop privileges failed");
+    if (setgid(newgid) < 0 || setuid(newuid) < 0) {
+        perror("attempt to drop privileges failed: setgid/setuid failed");
         clean_exit(-1);
     }
 }
 
-#endif
-#endif
+#endif  /* if defined(USE_DROPPRIVS) && !defined(_WIN32) */
 
 void usage(int8_t e) {
     printf("usage: ngrep <-"
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin