summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2010-06-10 14:01:18 +0200
committerMichael Vogt <mvo@debian.org>2010-06-10 14:01:18 +0200
commite934f8c63aabf4ff94962a4602c143b52b19b3cb (patch)
tree8f4774cc300c0621cc4532b53eef2a04e5e56b3c /methods
parent189bb640d2443a5fcaade2ce169429c629ba3148 (diff)
parent97f4026d93a85838439263d30146c3ad25fef474 (diff)
merged from david
Diffstat (limited to 'methods')
-rw-r--r--methods/gpgv.cc88
-rw-r--r--methods/http.h2
-rw-r--r--methods/mirror.cc27
3 files changed, 28 insertions, 89 deletions
diff --git a/methods/gpgv.cc b/methods/gpgv.cc
index a149d67dd..018e4f622 100644
--- a/methods/gpgv.cc
+++ b/methods/gpgv.cc
@@ -2,6 +2,7 @@
#include <apt-pkg/acquire-method.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/indexcopy.h>
#include <apti18n.h>
#include <utime.h>
@@ -54,97 +55,29 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
if (Debug == true)
std::clog << "inside VerifyGetSigners" << std::endl;
- pid_t pid;
int fd[2];
- FILE *pipein;
- int status;
- string const gpgvpath = _config->Find("Dir::Bin::gpg", "/usr/bin/gpgv");
- // FIXME: remove support for deprecated APT::GPGV setting
- string const trustedFile = _config->FindFile("Dir::Etc::Trusted",
- _config->Find("APT::GPGV::TrustedKeyring", "/etc/apt/trusted.gpg").c_str());
- string const trustedPath = _config->FindDir("Dir::Etc::TrustedParts", "/etc/apt/trusted.gpg.d");
- if (Debug == true)
- {
- std::clog << "gpgv path: " << gpgvpath << std::endl;
- std::clog << "Keyring file: " << trustedFile << std::endl;
- std::clog << "Keyring path: " << trustedPath << std::endl;
- }
-
- vector<string> keyrings = GetListOfFilesInDir(trustedPath, "gpg", false);
- if (FileExists(trustedFile) == true)
- keyrings.push_back(trustedFile);
-
- if (keyrings.empty() == true)
- {
- // TRANSLATOR: %s is the trusted keyring parts directory
- ioprintf(ret, _("No keyring installed in %s."), trustedPath.c_str());
- return ret.str();
- }
if (pipe(fd) < 0)
return "Couldn't create pipe";
- pid = fork();
+ pid_t pid = fork();
if (pid < 0)
return string("Couldn't spawn new process") + strerror(errno);
else if (pid == 0)
{
- std::vector<const char *> Args;
- Args.reserve(30);
-
- Args.push_back(gpgvpath.c_str());
- Args.push_back("--status-fd");
- Args.push_back("3");
- Args.push_back("--ignore-time-conflict");
- for (vector<string>::const_iterator K = keyrings.begin();
- K != keyrings.end(); ++K)
+ if (SigVerify::RunGPGV(outfile, file, 3, fd) == false)
{
- Args.push_back("--keyring");
- Args.push_back(K->c_str());
+ // TRANSLATOR: %s is the trusted keyring parts directory
+ ioprintf(ret, _("No keyring installed in %s."),
+ _config->FindDir("Dir::Etc::TrustedParts", "/etc/apt/trusted.gpg.d").c_str());
+ return ret.str();
}
-
- Configuration::Item const *Opts;
- Opts = _config->Tree("Acquire::gpgv::Options");
- if (Opts != 0)
- {
- Opts = Opts->Child;
- for (; Opts != 0; Opts = Opts->Next)
- {
- if (Opts->Value.empty() == true)
- continue;
- Args.push_back(Opts->Value.c_str());
- }
- }
- Args.push_back(file);
- Args.push_back(outfile);
- Args.push_back(NULL);
-
- if (Debug == true)
- {
- std::clog << "Preparing to exec: " << gpgvpath;
- for(std::vector<const char *>::const_iterator a = Args.begin();*a != NULL; ++a)
- std::clog << " " << *a;
- std::clog << std::endl;
- }
- int const nullfd = open("/dev/null", O_RDONLY);
- close(fd[0]);
- // Redirect output to /dev/null; we read from the status fd
- dup2(nullfd, STDOUT_FILENO);
- dup2(nullfd, STDERR_FILENO);
- // Redirect the pipe to the status fd (3)
- dup2(fd[1], 3);
-
- putenv((char *)"LANG=");
- putenv((char *)"LC_ALL=");
- putenv((char *)"LC_MESSAGES=");
- execvp(gpgvpath.c_str(), (char **) &Args[0]);
-
exit(111);
}
close(fd[1]);
- pipein = fdopen(fd[0], "r");
-
+ FILE *pipein = fdopen(fd[0], "r");
+
// Loop over the output of gpgv, and check the signatures.
size_t buffersize = 64;
char *buffer = (char *) malloc(buffersize);
@@ -217,6 +150,7 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
}
fclose(pipein);
+ int status;
waitpid(pid, &status, 0);
if (Debug == true)
{
@@ -235,7 +169,7 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile,
}
else if (WEXITSTATUS(status) == 111)
{
- ioprintf(ret, _("Could not execute '%s' to verify signature (is gpgv installed?)"), gpgvpath.c_str());
+ ioprintf(ret, _("Could not execute 'gpgv' to verify signature (is gpgv installed?)"));
return ret.str();
}
else
diff --git a/methods/http.h b/methods/http.h
index d0677bdaa..0bc019e77 100644
--- a/methods/http.h
+++ b/methods/http.h
@@ -13,7 +13,7 @@
#define MAXLEN 360
-
+#include <apt-pkg/hashes.h>
using std::cout;
using std::endl;
diff --git a/methods/mirror.cc b/methods/mirror.cc
index b2b6b2ecf..e8873d97b 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -153,11 +153,12 @@ void MirrorMethod::CurrentQueueUriToMirror()
return;
// find current mirror and select next one
- for (int i=0; i < AllMirrors.size(); i++)
+ for (vector<string>::const_iterator mirror = AllMirrors.begin();
+ mirror != AllMirrors.end(); ++mirror)
{
- if (Queue->Uri.find(AllMirrors[i]) == 0)
+ if (Queue->Uri.find(*mirror) == 0)
{
- Queue->Uri.replace(0, AllMirrors[i].size(), BaseUri);
+ Queue->Uri.replace(0, mirror->length(), BaseUri);
return;
}
}
@@ -168,15 +169,19 @@ void MirrorMethod::CurrentQueueUriToMirror()
bool MirrorMethod::TryNextMirror()
{
// find current mirror and select next one
- for (int i=0; i < AllMirrors.size()-1; i++)
+ for (vector<string>::const_iterator mirror = AllMirrors.begin();
+ mirror != AllMirrors.end(); ++mirror)
{
- if (Queue->Uri.find(AllMirrors[i]) == 0)
- {
- Queue->Uri.replace(0, AllMirrors[i].size(), AllMirrors[i+1]);
- if (Debug)
- clog << "TryNextMirror: " << Queue->Uri << endl;
- return true;
- }
+ if (Queue->Uri.find(*mirror) != 0)
+ continue;
+
+ vector<string>::const_iterator nextmirror = mirror + 1;
+ if (nextmirror != AllMirrors.end())
+ break;
+ Queue->Uri.replace(0, mirror->length(), *nextmirror);
+ if (Debug)
+ clog << "TryNextMirror: " << Queue->Uri << endl;
+ return true;
}
if (Debug)