#define APT_APTMETHOD_H
#include <apt-pkg/acquire-method.h>
+#include <apt-pkg/configuration.h>
#include <string>
class aptMethod : public pkgAcqMethod
{
char const * const Binary;
- public:
- virtual bool Configuration(std::string Message) APT_OVERRIDE;
- bool CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const;
-
- aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) : pkgAcqMethod(Ver, Flags), Binary(Binary) {};
+public:
+ virtual bool Configuration(std::string Message) APT_OVERRIDE
+ {
+ if (pkgAcqMethod::Configuration(Message) == false)
+ return false;
+
+ std::string const conf = std::string("Binary::") + Binary;
+ _config->MoveSubTree(conf.c_str(), NULL);
+
+ DropPrivsOrDie();
+
+ return true;
+ }
+
+ bool CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const
+ {
+ Hashes Hash(Itm->ExpectedHashes);
+ FileFd Fd;
+ if (Fd.Open(Res.Filename, FileFd::ReadOnly) == false || Hash.AddFD(Fd) == false)
+ return false;
+ Res.TakeHashes(Hash);
+ return true;
+ }
+
+ aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) :
+ pkgAcqMethod(Ver, Flags), Binary(Binary)
+ {}
};
-bool aptMethod::Configuration(std::string Message)
-{
- if (pkgAcqMethod::Configuration(Message) == false)
- return false;
-
- DropPrivsOrDie();
-
- return true;
-}
-bool aptMethod::CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const
-{
- Hashes Hash(Itm->ExpectedHashes);
- FileFd Fd;
- if (Fd.Open(Res.Filename, FileFd::ReadOnly) == false || Hash.AddFD(Fd) == false)
- return false;
- Res.TakeHashes(Hash);
- return true;
-}
#endif
// FtpMethod::FtpMethod - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-FtpMethod::FtpMethod() : pkgAcqMethod("1.0",SendConfig)
+FtpMethod::FtpMethod() : aptMethod("ftp","1.0",SendConfig)
{
signal(SIGTERM,SigTerm);
signal(SIGINT,SigTerm);
/* We stash the desired pipeline depth */
bool FtpMethod::Configuration(string Message)
{
- if (pkgAcqMethod::Configuration(Message) == false)
+ if (aptMethod::Configuration(Message) == false)
return false;
-
- TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
- // no more active ftp, sorry
- DropPrivsOrDie();
+ TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
return true;
}
#include <apt-pkg/acquire-method.h>
#include <apt-pkg/strutl.h>
+#include "aptmethod.h"
#include <sys/socket.h>
#include <sys/types.h>
~FTPConn();
};
-class FtpMethod : public pkgAcqMethod
+class FtpMethod : public aptMethod
{
virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE;
virtual bool Configuration(std::string Message) APT_OVERRIDE;
#include <apt-pkg/gpgv.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include "aptmethod.h"
#include <ctype.h>
#include <errno.h>
#define GNUPGREVKEYSIG "[GNUPG:] REVKEYSIG"
#define GNUPGNODATA "[GNUPG:] NODATA"
-class GPGVMethod : public pkgAcqMethod
+class GPGVMethod : public aptMethod
{
private:
string VerifyGetSigners(const char *file, const char *outfile,
protected:
virtual bool URIAcquire(std::string const &Message, FetchItem *Itm) APT_OVERRIDE;
- virtual bool Configuration(string Message) APT_OVERRIDE;
public:
- GPGVMethod() : pkgAcqMethod("1.0",SingleInstance | SendConfig) {};
+ GPGVMethod() : aptMethod("gpgv","1.0",SingleInstance | SendConfig) {};
};
-bool GPGVMethod::Configuration(string Message)
-{
- if (pkgAcqMethod::Configuration(Message) == false)
- return false;
-
- DropPrivsOrDie();
-
- return true;
-}
-
string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
std::string const &key,
vector<string> &GoodSigners,
#include <apt-pkg/hashes.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/aptconfiguration.h>
+#include "aptmethod.h"
#include <string.h>
#include <sys/stat.h>
#include <apti18n.h>
/*}}}*/
-const char *Prog;
-
-class GzipMethod : public pkgAcqMethod
+class GzipMethod : public aptMethod
{
+ std::string const Prog;
virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE;
- virtual bool Configuration(std::string Message) APT_OVERRIDE;
-
- public:
-
- GzipMethod() : pkgAcqMethod("1.1",SingleInstance | SendConfig) {};
-};
-
-bool GzipMethod::Configuration(std::string Message)
-{
- if (pkgAcqMethod::Configuration(Message) == false)
- return false;
- DropPrivsOrDie();
+ public:
- return true;
-}
+ GzipMethod(std::string const &pProg) : aptMethod(pProg.c_str(),"1.1",SingleInstance | SendConfig), Prog(pProg) {};
+};
// GzipMethod::Fetch - Decompress the passed URI /*{{{*/
// ---------------------------------------------------------------------
if (compressor->Name == Prog)
break;
if (compressor == compressors.end())
- return _error->Error("Extraction of file %s requires unknown compressor %s", Path.c_str(), Prog);
+ return _error->Error("Extraction of file %s requires unknown compressor %s", Path.c_str(), Prog.c_str());
// Open the source and destination files
FileFd From;
{
setlocale(LC_ALL, "");
- Prog = strrchr(argv[0],'/');
- ++Prog;
-
- GzipMethod Mth;
-
+ GzipMethod Mth(flNotDir(argv[0]));
return Mth.Run();
}
public:
friend struct HttpServerState;
- HttpMethod() : ServerMethod("1.2",Pipeline | SendConfig)
+ HttpMethod() : ServerMethod("http", "1.2",Pipeline | SendConfig)
{
File = 0;
Server = 0;
using pkgAcqMethod::FetchResult;
using pkgAcqMethod::FetchItem;
- HttpsMethod() : ServerMethod("1.2",Pipeline | SendConfig), File(NULL)
+ HttpsMethod() : ServerMethod("https","1.2",Pipeline | SendConfig), File(NULL)
{
curl = curl_easy_init();
};
#include <apt-pkg/strutl.h>
#include <apt-pkg/hashes.h>
#include <apt-pkg/configuration.h>
+#include "aptmethod.h"
#include <stddef.h>
#include <iostream>
}
};
-class RredMethod : public pkgAcqMethod {
+class RredMethod : public aptMethod {
private:
bool Debug;
return true;
}
- bool Configuration(std::string Message) APT_OVERRIDE
- {
- if (pkgAcqMethod::Configuration(Message) == false)
- return false;
-
- DropPrivsOrDie();
-
- return true;
- }
-
public:
- RredMethod() : pkgAcqMethod("2.0",SingleInstance | SendConfig), Debug(false) {}
+ RredMethod() : aptMethod("rred", "2.0",SingleInstance | SendConfig), Debug(false) {}
};
int main(int argc, char **argv)
// RSHMethod::RSHMethod - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
+RSHMethod::RSHMethod(std::string const &pProg) : aptMethod(pProg.c_str(),"1.0",SendConfig), Prog(pProg)
{
signal(SIGTERM,SigTerm);
signal(SIGINT,SigTerm);
// ---------------------------------------------------------------------
bool RSHMethod::Configuration(std::string Message)
{
- char ProgStr[100];
-
- if (pkgAcqMethod::Configuration(Message) == false)
+ if (aptMethod::Configuration(Message) == 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::") + Prog + "::Timeout";
+ TimeOut = _config->FindI(timeconf, TimeOut);
+ std::string const optsconf = std::string("Acquire::") + Prog + "::Options";
+ RshOptions = _config->Tree(optsconf.c_str());
return true;
}
{
setlocale(LC_ALL, "");
- RSHMethod Mth;
- Prog = strrchr(argv[0],'/');
- Prog++;
+ RSHMethod Mth(flNotDir(argv[0]));
return Mth.Run();
}
};
#include <apt-pkg/acquire-method.h>
+#include "aptmethod.h"
-class RSHMethod : public pkgAcqMethod
+class RSHMethod : public aptMethod
{
+ std::string const Prog;
virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE;
virtual bool Configuration(std::string Message) APT_OVERRIDE;
public:
- RSHMethod();
+ RSHMethod(std::string const &Prog);
};
#endif
}
/*}}}*/
-bool ServerMethod::Configuration(string Message) /*{{{*/
-{
- if (pkgAcqMethod::Configuration(Message) == false)
- return false;
-
- DropPrivsOrDie();
-
- return true;
-}
- /*}}}*/
-
// ServerMethod::DealWithHeaders - Handle the retrieved header data /*{{{*/
// ---------------------------------------------------------------------
/* We look at the header data we got back from the server and decide what
return MaxSizeInQueue;
}
/*}}}*/
-ServerMethod::ServerMethod(const char *Ver,unsigned long Flags) : /*{{{*/
- pkgAcqMethod(Ver, Flags), Server(nullptr), File(NULL), PipelineDepth(10),
+ServerMethod::ServerMethod(char const * const Binary, char const * const Ver,unsigned long const Flags) :/*{{{*/
+ aptMethod(Binary, Ver, Flags), Server(nullptr), File(NULL), PipelineDepth(10),
AllowRedirect(false), Debug(false)
{
}
#include <apt-pkg/strutl.h>
#include <apt-pkg/acquire-method.h>
+#include "aptmethod.h"
#include <time.h>
#include <iostream>
virtual ~ServerState() {};
};
-class ServerMethod : public pkgAcqMethod
+class ServerMethod : public aptMethod
{
protected:
virtual bool Fetch(FetchItem *) APT_OVERRIDE;
static time_t FailTime;
static APT_NORETURN void SigTerm(int);
- virtual bool Configuration(std::string Message) APT_OVERRIDE;
virtual bool Flush() { return Server->Flush(File); };
int Loop();
virtual std::unique_ptr<ServerState> CreateServerState(URI const &uri) = 0;
virtual void RotateDNS() = 0;
- ServerMethod(const char *Ver,unsigned long Flags = 0);
+ ServerMethod(char const * const Binary, char const * const Ver,unsigned long const Flags);
virtual ~ServerMethod() {};
};
echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
- # store apt-key were we can access it, even if we run it as a different user
- # destroys coverage reporting though, so just do it for root for now
+ # either store apt-key were we can access it, even if we run it as a different user
+ #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
+ #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
+ #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
+ # destroys coverage reporting though, so we disable changing user for the calling gpgv
+ echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
if [ "$(id -u)" = '0' ]; then
- cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
- chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
- echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
- else
- echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
+ echo 'Binary::gpgv::Debug::NoDropPrivs "true";' >>aptconfig.conf
fi
cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF