Browse Source

methods: Fail if we cannot drop privileges

Julian Andres Klode 11 years ago
parent
commit
7b18d5592f
8 changed files with 27 additions and 14 deletions
  1. 12 0
      apt-pkg/acquire-method.cc
  2. 1 1
      apt-pkg/acquire-method.h
  3. 2 2
      methods/copy.cc
  4. 3 3
      methods/ftp.cc
  5. 2 2
      methods/gpgv.cc
  6. 3 2
      methods/gzip.cc
  7. 2 2
      methods/http_main.cc
  8. 2 2
      methods/https.cc

+ 12 - 0
apt-pkg/acquire-method.cc

@@ -118,6 +118,18 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
 
    std::cout << "\n" << std::flush;
 }
+									/*}}}*/
+// AcqMethod::DropPrivsOrDie - Drop privileges or die		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::DropPrivsOrDie()
+{
+   if (!DropPrivs()) {
+      Fail(false);
+      exit(112);	/* call the european emergency number */
+   }
+}
+
 									/*}}}*/
 // AcqMethod::URIStart - Indicate a download is starting		/*{{{*/
 // ---------------------------------------------------------------------

+ 1 - 1
apt-pkg/acquire-method.h

@@ -105,7 +105,7 @@ class pkgAcqMethod
    
    pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
    virtual ~pkgAcqMethod() {};
-
+   void DropPrivsOrDie();
    private:
    APT_HIDDEN void Dequeue();
 };

+ 2 - 2
methods/copy.cc

@@ -118,8 +118,8 @@ int main()
 {
    setlocale(LC_ALL, "");
 
-   DropPrivs();
-
    CopyMethod Mth;
+
+   Mth.DropPrivsOrDie();
    return Mth.Run();
 }

+ 3 - 3
methods/ftp.cc

@@ -1107,9 +1107,6 @@ int main(int, const char *argv[])
 { 
    setlocale(LC_ALL, "");
 
-   // no more active ftp, sorry
-   DropPrivs();
-
    /* See if we should be come the http client - we do this for http
       proxy urls */
    if (getenv("ftp_proxy") != 0)
@@ -1134,6 +1131,9 @@ int main(int, const char *argv[])
    }
    
    FtpMethod Mth;
+
+   // no more active ftp, sorry
+   Mth.DropPrivsOrDie();
    
    return Mth.Run();
 }

+ 2 - 2
methods/gpgv.cc

@@ -262,10 +262,10 @@ bool GPGVMethod::Fetch(FetchItem *Itm)
 int main()
 {
    setlocale(LC_ALL, "");
-   
-   DropPrivs();
 
    GPGVMethod Mth;
 
+   Mth.DropPrivsOrDie();
+
    return Mth.Run();
 }

+ 3 - 2
methods/gzip.cc

@@ -135,11 +135,12 @@ int main(int, char *argv[])
 {
    setlocale(LC_ALL, "");
 
-   DropPrivs();
-
    Prog = strrchr(argv[0],'/');
    ++Prog;
 
    GzipMethod Mth;
+
+   Mth.DropPrivsOrDie();
+
    return Mth.Run();
 }

+ 2 - 2
methods/http_main.cc

@@ -12,8 +12,8 @@ int main()
    // closes the connection (this is dealt with via ServerDie())
    signal(SIGPIPE, SIG_IGN);
 
-   DropPrivs();
-
    HttpMethod Mth;
+
+   Mth.DropPrivsOrDie();
    return Mth.Loop();
 }

+ 2 - 2
methods/https.cc

@@ -443,11 +443,11 @@ int main()
 {
    setlocale(LC_ALL, "");
 
-   DropPrivs();
-
    HttpsMethod Mth;
    curl_global_init(CURL_GLOBAL_SSL) ;
 
+   Mth.DropPrivsOrDie();
+
    return Mth.Run();
 }