summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2013-03-18 19:36:55 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2013-03-18 19:36:55 +0100
commitf1828b6977972b4ef6da6401602b7938f6570c32 (patch)
treec04aa9cbd30e7ee4152f408ee13f663e332b7327 /apt-pkg/contrib
parent34747d46be3a15105d896266d8043f55d04e7735 (diff)
- add method to open (maybe) clearsigned files transparently
* ftparchive/writer.cc: - use OpenMaybeClearSignedFile to be free from detecting and skipping clearsigning metadata in dsc files
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/gpgv.cc55
-rw-r--r--apt-pkg/contrib/gpgv.h22
2 files changed, 76 insertions, 1 deletions
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index 5921d7c67..fc16dd32c 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -19,7 +19,7 @@
#include <apti18n.h>
/*}}}*/
-char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/
+static char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/
{
const char *tmpdir = getenv("TMPDIR");
#ifdef P_tmpdir
@@ -376,5 +376,58 @@ bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
fclose(out_signature);
fclose(in);
+ if (found_signature == true)
+ return _error->Error("Signature in file %s wasn't closed", InFile.c_str());
+
+ // if we haven't found any of them, this an unsigned file,
+ // so don't generate an error, but splitting was unsuccessful none-the-less
+ if (found_message_start == false && found_message_end == false)
+ return false;
+ // otherwise one missing indicates a syntax error
+ else if (found_message_start == false || found_message_end == false)
+ return _error->Error("Splitting of file %s failed as it doesn't contain all expected parts", InFile.c_str());
+
return true;
}
+ /*}}}*/
+bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile) /*{{{*/
+{
+ char * const message = GenerateTemporaryFileTemplate("fileutl.message");
+ int const messageFd = mkstemp(message);
+ if (messageFd == -1)
+ {
+ free(message);
+ return _error->Errno("mkstemp", "Couldn't create temporary file to work with %s", ClearSignedFileName.c_str());
+ }
+ // we have the fd, thats enough for us
+ unlink(message);
+ free(message);
+
+ int const duppedMsg = dup(messageFd);
+ if (duppedMsg == -1)
+ return _error->Errno("dup", "Couldn't duplicate FD to work with %s", ClearSignedFileName.c_str());
+
+ _error->PushToStack();
+ bool const splitDone = SplitClearSignedFile(ClearSignedFileName.c_str(), messageFd, NULL, -1);
+ bool const errorDone = _error->PendingError();
+ _error->MergeWithStack();
+ if (splitDone == false)
+ {
+ close(duppedMsg);
+
+ if (errorDone == true)
+ return false;
+
+ // we deal with an unsigned file
+ MessageFile.Open(ClearSignedFileName, FileFd::ReadOnly);
+ }
+ else // clear-signed
+ {
+ if (lseek(duppedMsg, 0, SEEK_SET) < 0)
+ return _error->Errno("lseek", "Unable to seek back in message fd for file %s", ClearSignedFileName.c_str());
+ MessageFile.OpenDescriptor(duppedMsg, FileFd::ReadOnly, true);
+ }
+
+ return MessageFile.Failed() == false;
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/gpgv.h b/apt-pkg/contrib/gpgv.h
index 8e04855e4..ab7d35ab1 100644
--- a/apt-pkg/contrib/gpgv.h
+++ b/apt-pkg/contrib/gpgv.h
@@ -12,6 +12,8 @@
#include <string>
#include <vector>
+#include <apt-pkg/fileutl.h>
+
#if __GNUC__ >= 4
#define APT_noreturn __attribute__ ((noreturn))
#else
@@ -52,10 +54,17 @@ inline void ExecGPGV(std::string const &File, std::string const &FileSig,
* The code doesn't support dash-encoded lines as these are not
* expected to be present in files we have to deal with.
*
+ * The content of the split files is undefined if the splitting was
+ * unsuccessful.
+ *
+ * Note that trying to split an unsigned file will fail, but
+ * not generate an error message.
+ *
* @param InFile is the clear-signed file
* @param ContentFile is the Fd the message will be written to
* @param ContentHeader is a list of all required Amored Headers for the message
* @param SignatureFile is the Fd all signatures will be written to
+ * @return true if the splitting was successful, false otherwise
*/
bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
std::vector<std::string> * const ContentHeader, int const SignatureFile);
@@ -74,4 +83,17 @@ bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
bool RecombineToClearSignedFile(std::string const &OutFile, int const ContentFile,
std::vector<std::string> const &ContentHeader, int const SignatureFile);
+/** \brief open a file which might be clear-signed
+ *
+ * This method tries to extract the (signed) message of a file.
+ * If the file isn't signed it will just open the given filename.
+ * Otherwise the message is extracted to a temporary file which
+ * will be opened instead.
+ *
+ * @param ClearSignedFileName is the name of the file to open
+ * @param[out] MessageFile is the FileFd in which the file will be opened
+ * @return true if opening was successful, otherwise false
+ */
+bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile);
+
#endif