X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/e0a243f33cd411f730af3c93aff38635c9668f9e..a1f3ac8aba0675321dd46d074af8abcbb10c19fd:/apt-pkg/contrib/gpgv.cc diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index c2c0ebb73..8796195b8 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -105,6 +106,28 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, std::vector dataHeader; char * sig = NULL; char * data = NULL; + char * conf = nullptr; + + // Dump the configuration so apt-key picks up the correct Dir values + { + conf = GenerateTemporaryFileTemplate("apt.conf"); + if (conf == nullptr) { + ioprintf(std::cerr, "Couldn't create tempfile names for passing config to apt-key"); + local_exit(EINTERNAL); + } + int confFd = mkstemp(conf); + if (confFd == -1) { + ioprintf(std::cerr, "Couldn't create temporary file %s for passing config to apt-key", conf); + local_exit(EINTERNAL); + } + local_exit.files.push_back(conf); + + std::ofstream confStream(conf); + close(confFd); + _config->Dump(confStream); + confStream.close(); + setenv("APT_CONFIG", conf, 1); + } if (releaseSignature == DETACHED) { @@ -175,58 +198,49 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, putenv((char *)"LC_MESSAGES="); } - if (releaseSignature == DETACHED) + + // We have created tempfiles we have to clean up + // and we do an additional check, so fork yet another time … + pid_t pid = ExecFork(); + if(pid < 0) { + ioprintf(std::cerr, "Fork failed for %s to check %s", Args[0], File.c_str()); + local_exit(EINTERNAL); + } + if(pid == 0) { + if (statusfd != -1) + dup2(fd[1], statusfd); execvp(Args[0], (char **) &Args[0]); ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str()); local_exit(EINTERNAL); } - else - { - // for clear-signed files we have created tempfiles we have to clean up - // and we do an additional check, so fork yet another time … - pid_t pid = ExecFork(); - if(pid < 0) { - ioprintf(std::cerr, "Fork failed for %s to check %s", Args[0], File.c_str()); - local_exit(EINTERNAL); - } - if(pid == 0) - { - if (statusfd != -1) - dup2(fd[1], statusfd); - execvp(Args[0], (char **) &Args[0]); - ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str()); - local_exit(EINTERNAL); - } - // Wait and collect the error code - taken from WaitPid as we need the exact Status - int Status; - while (waitpid(pid,&Status,0) != pid) - { - if (errno == EINTR) - continue; - ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "apt-key"); - local_exit(EINTERNAL); - } - - // check if it exit'ed normally … - if (WIFEXITED(Status) == false) - { - ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "apt-key"); - local_exit(EINTERNAL); - } + // Wait and collect the error code - taken from WaitPid as we need the exact Status + int Status; + while (waitpid(pid,&Status,0) != pid) + { + if (errno == EINTR) + continue; + ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "apt-key"); + local_exit(EINTERNAL); + } - // … and with a good exit code - if (WEXITSTATUS(Status) != 0) - { - ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "apt-key", WEXITSTATUS(Status)); - local_exit(WEXITSTATUS(Status)); - } + // check if it exit'ed normally … + if (WIFEXITED(Status) == false) + { + ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "apt-key"); + local_exit(EINTERNAL); + } - // everything fine - local_exit(0); + // … and with a good exit code + if (WEXITSTATUS(Status) != 0) + { + ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "apt-key", WEXITSTATUS(Status)); + local_exit(WEXITSTATUS(Status)); } - local_exit(EINTERNAL); // unreachable safe-guard + + // everything fine + local_exit(0); } /*}}}*/ // SplitClearSignedFile - split message into data/signature /*{{{*/