]> git.saurik.com Git - apt.git/blobdiff - methods/rsh.cc
You have to do the bounds check before the access.
[apt.git] / methods / rsh.cc
index 44aa7084d02b3592eedbf1bbb2ef2109031bc546..7b8af6f9b8636cd842313dbcc70e120fb8867e04 100644 (file)
@@ -17,7 +17,6 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/acquire-method.h>
 #include <apt-pkg/strutl.h>
 
 #include <stdlib.h>
 #include <apt-pkg/strutl.h>
 
 #include <stdlib.h>
@@ -34,7 +33,6 @@
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
-const char *Prog;
 unsigned long TimeOut = 120;
 Configuration::Item const *RshOptions = 0;
 time_t RSHMethod::FailTime = 0;
 unsigned long TimeOut = 120;
 Configuration::Item const *RshOptions = 0;
 time_t RSHMethod::FailTime = 0;
@@ -44,8 +42,8 @@ int RSHMethod::FailFd = -1;
 // RSHConn::RSHConn - Constructor                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // RSHConn::RSHConn - Constructor                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-RSHConn::RSHConn(URI Srv) : Len(0), WriteFd(-1), ReadFd(-1),
-                            ServerName(Srv), Process(-1) {
+RSHConn::RSHConn(std::string const &pProg, URI Srv) : Len(0), WriteFd(-1), ReadFd(-1),
+                            ServerName(Srv), Prog(pProg), Process(-1) {
    Buffer[0] = '\0';
 }
                                                                        /*}}}*/
    Buffer[0] = '\0';
 }
                                                                        /*}}}*/
@@ -128,7 +126,7 @@ bool RSHConn::Connect(std::string Host, unsigned int Port, std::string User)
       // Probably should do
       // dup2(open("/dev/null",O_RDONLY),STDERR_FILENO);
 
       // Probably should do
       // dup2(open("/dev/null",O_RDONLY),STDERR_FILENO);
 
-      Args[i++] = Prog;
+      Args[i++] = Prog.c_str();
 
       // Insert user-supplied command line options
       Configuration::Item const *Opts = RshOptions;
 
       // Insert user-supplied command line options
       Configuration::Item const *Opts = RshOptions;
@@ -385,9 +383,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
                                                                        /*}}}*/
 
 // RSHMethod::RSHMethod - Constructor                                  /*{{{*/
                                                                        /*}}}*/
 
 // RSHMethod::RSHMethod - Constructor                                  /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
+RSHMethod::RSHMethod(std::string &&pProg) : aptMethod(std::move(pProg),"1.0",SendConfig)
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
@@ -399,15 +395,17 @@ RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
 // ---------------------------------------------------------------------
 bool RSHMethod::Configuration(std::string Message)
 {
 // ---------------------------------------------------------------------
 bool RSHMethod::Configuration(std::string Message)
 {
-   char ProgStr[100];
-  
-   if (pkgAcqMethod::Configuration(Message) == false)
+   // enabling privilege dropping for this method requires configuration…
+   // â€¦ which is otherwise lifted straight from root, so use it by default.
+   _config->Set(std::string("Binary::") + Binary + "::APT::Sandbox::User", "");
+
+   if (aptMethod::Configuration(Message) == false)
       return false;
 
       return false;
 
-   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Timeout", Prog);
-   TimeOut = _config->FindI(ProgStr,TimeOut);
-   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Options", Prog);
-   RshOptions = _config->Tree(ProgStr);
+   std::string const timeconf = std::string("Acquire::") + Binary + "::Timeout";
+   TimeOut = _config->FindI(timeconf, TimeOut);
+   std::string const optsconf = std::string("Acquire::") + Binary + "::Options";
+   RshOptions = _config->Tree(optsconf.c_str());
 
    return true;
 }
 
    return true;
 }
@@ -445,7 +443,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
    // Connect to the server
    if (Server == 0 || Server->Comp(Get) == false) {
       delete Server;
    // Connect to the server
    if (Server == 0 || Server->Comp(Get) == false) {
       delete Server;
-      Server = new RSHConn(Get);
+      Server = new RSHConn(Binary, Get);
    }
 
    // Could not connect is a transient error..
    }
 
    // Could not connect is a transient error..
@@ -546,10 +544,5 @@ bool RSHMethod::Fetch(FetchItem *Itm)
 
 int main(int, const char *argv[])
 {
 
 int main(int, const char *argv[])
 {
-   setlocale(LC_ALL, "");
-
-   RSHMethod Mth;
-   Prog = strrchr(argv[0],'/');
-   Prog++;
-   return Mth.Run();
+   return RSHMethod(flNotDir(argv[0])).Run();
 }
 }