summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc60
-rw-r--r--apt-pkg/contrib/cmndline.cc6
-rw-r--r--apt-pkg/contrib/configuration.cc10
-rw-r--r--apt-pkg/contrib/configuration.h2
-rw-r--r--apt-pkg/contrib/error.cc35
-rw-r--r--apt-pkg/contrib/error.h2
-rw-r--r--apt-pkg/contrib/fileutl.cc73
-rw-r--r--apt-pkg/contrib/fileutl.h5
-rw-r--r--apt-pkg/contrib/gpgv.cc18
-rw-r--r--apt-pkg/contrib/hashes.cc18
-rw-r--r--apt-pkg/contrib/hashes.h3
-rw-r--r--apt-pkg/contrib/hashsum.cc2
-rw-r--r--apt-pkg/contrib/hashsum_template.h3
-rw-r--r--apt-pkg/contrib/macros.h2
-rw-r--r--apt-pkg/contrib/md5.h4
-rw-r--r--apt-pkg/contrib/mmap.cc8
-rw-r--r--apt-pkg/contrib/mmap.h1
-rw-r--r--apt-pkg/contrib/netrc.cc4
-rw-r--r--apt-pkg/contrib/progress.cc10
-rw-r--r--apt-pkg/contrib/progress.h3
-rw-r--r--apt-pkg/contrib/proxy.cc31
-rw-r--r--apt-pkg/contrib/sha1.h4
-rw-r--r--apt-pkg/contrib/sha2.h4
-rw-r--r--apt-pkg/contrib/sha2_internal.cc8
-rw-r--r--apt-pkg/contrib/sha2_internal.h2
-rw-r--r--apt-pkg/contrib/srvrec.cc4
-rw-r--r--apt-pkg/contrib/srvrec.h4
-rw-r--r--apt-pkg/contrib/string_view.h4
-rw-r--r--apt-pkg/contrib/strutl.cc22
-rw-r--r--apt-pkg/contrib/strutl.h7
30 files changed, 196 insertions, 163 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 428ef0161..93bfb9f42 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -10,26 +10,26 @@
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#include<config.h>
+#include <config.h>
#include <apt-pkg/cdromutl.h>
+#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
-#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
-#include <apt-pkg/configuration.h>
+#include <apt-pkg/md5.h>
#include <apt-pkg/strutl.h>
-#include <stdlib.h>
-#include <string.h>
#include <iostream>
#include <string>
#include <vector>
-#include <sys/statvfs.h>
#include <dirent.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <unistd.h>
-#include <stdio.h>
#include <apti18n.h>
/*}}}*/
@@ -184,26 +184,32 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
MD5Summation Hash;
bool writable_media = false;
+ int dirfd = open(CD.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (dirfd == -1)
+ return _error->Errno("open",_("Unable to read %s"),CD.c_str());
+
// if we are on a writable medium (like a usb-stick) that is just
// used like a cdrom don't use "." as it will constantly change,
// use .disk instead
- if (access(CD.c_str(), W_OK) == 0 && DirectoryExists(CD+string("/.disk")))
+ if (faccessat(dirfd, ".", W_OK, 0) == 0)
{
- writable_media = true;
- CD = CD.append("/.disk");
- if (_config->FindB("Debug::aptcdrom",false) == true)
- std::clog << "Found writable cdrom, using alternative path: " << CD
- << std::endl;
+ int diskfd = openat(dirfd, "./.disk", O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0);
+ if (diskfd != -1)
+ {
+ close(dirfd);
+ dirfd = diskfd;
+ writable_media = true;
+ CD = CD.append("/.disk");
+ if (_config->FindB("Debug::aptcdrom",false) == true)
+ std::clog << "Found writable cdrom, using alternative path: " << CD
+ << std::endl;
+ }
}
- string StartDir = SafeGetCWD();
- if (chdir(CD.c_str()) != 0)
- return _error->Errno("chdir",_("Unable to change to %s"),CD.c_str());
-
- DIR *D = opendir(".");
- if (D == 0)
+ DIR * const D = fdopendir(dirfd);
+ if (D == nullptr)
return _error->Errno("opendir",_("Unable to read %s"),CD.c_str());
-
+
/* Run over the directory, we assume that the reader order will never
change as the media is read-only. In theory if the kernel did
some sort of wacked caching this might not be true.. */
@@ -222,31 +228,24 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
else
{
struct stat Buf;
- if (stat(Dir->d_name,&Buf) != 0)
+ if (fstatat(dirfd, Dir->d_name, &Buf, 0) != 0)
continue;
strprintf(S, "%lu", (unsigned long)Buf.st_mtime);
}
Hash.Add(S.c_str());
Hash.Add(Dir->d_name);
- };
-
- if (chdir(StartDir.c_str()) != 0) {
- _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
- closedir(D);
- return false;
}
- closedir(D);
// Some stats from the fsys
std::string S;
if (_config->FindB("Debug::identcdrom",false) == false)
{
struct statvfs Buf;
- if (statvfs(CD.c_str(),&Buf) != 0)
+ if (fstatvfs(dirfd, &Buf) != 0)
return _error->Errno("statfs",_("Failed to stat the cdrom"));
- // We use a kilobyte block size to advoid overflow
+ // We use a kilobyte block size to avoid overflow
if (writable_media)
{
strprintf(S, "%lu", (unsigned long)(Buf.f_blocks*(Buf.f_bsize/1024)));
@@ -260,6 +259,7 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
else
strprintf(S, "-%u.debug", Version);
+ closedir(D);
Res = Hash.Result().Value() + S;
return true;
}
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 029ec3060..2b8bef2c5 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -11,17 +11,17 @@
##################################################################### */
/*}}}*/
// Include files /*{{{*/
-#include<config.h>
+#include <config.h>
-#include <apt-pkg/configuration.h>
#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
+#include <string>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <string>
#include <apti18n.h>
/*}}}*/
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 78a98d614..442e31dff 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -19,9 +19,9 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/macros.h>
+#include <apt-pkg/strutl.h>
#include <ctype.h>
#include <regex.h>
@@ -31,13 +31,13 @@
#include <string.h>
#include <algorithm>
-#include <iterator>
-#include <string>
-#include <stack>
-#include <vector>
#include <fstream>
+#include <iterator>
#include <sstream>
+#include <stack>
+#include <string>
#include <unordered_map>
+#include <vector>
#include <apti18n.h>
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 97a01e4cf..8d0835cf5 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -30,9 +30,9 @@
#include <regex.h>
+#include <iostream>
#include <string>
#include <vector>
-#include <iostream>
#include <apt-pkg/macros.h>
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index c06ea8364..0233dfd59 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -17,17 +17,17 @@
#include <apt-pkg/error.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <list>
+#include <algorithm>
+#include <cstring>
#include <iostream>
+#include <list>
+#include <string>
#include <errno.h>
+#include <stdarg.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <string>
-#include <cstring>
-#include <algorithm>
/*}}}*/
@@ -37,20 +37,21 @@
Per-Thread error object is maintained in much the same manner as libc
manages errno */
#if defined(_POSIX_THREADS) && defined(HAVE_PTHREAD)
- #include <pthread.h>
+#include <pthread.h>
- static pthread_key_t ErrorKey;
- static void ErrorDestroy(void *Obj) {delete (GlobalError *)Obj;};
- static void KeyAlloc() {pthread_key_create(&ErrorKey,ErrorDestroy);};
+static pthread_key_t ErrorKey;
+static void ErrorDestroy(void *Obj) { delete (GlobalError *)Obj; };
+static void KeyAlloc() { pthread_key_create(&ErrorKey, ErrorDestroy); };
- GlobalError *_GetErrorObj() {
- static pthread_once_t Once = PTHREAD_ONCE_INIT;
- pthread_once(&Once,KeyAlloc);
+GlobalError *_GetErrorObj()
+{
+ static pthread_once_t Once = PTHREAD_ONCE_INIT;
+ pthread_once(&Once, KeyAlloc);
- void *Res = pthread_getspecific(ErrorKey);
- if (Res == 0)
- pthread_setspecific(ErrorKey,Res = new GlobalError);
- return (GlobalError *)Res;
+ void *Res = pthread_getspecific(ErrorKey);
+ if (Res == 0)
+ pthread_setspecific(ErrorKey, Res = new GlobalError);
+ return (GlobalError *)Res;
}
#else
GlobalError *_GetErrorObj() {
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index b01a5fc1b..74b5cd5cf 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -46,8 +46,8 @@
#include <list>
#include <string>
-#include <stddef.h>
#include <stdarg.h>
+#include <stddef.h>
class GlobalError /*{{{*/
{
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e4c40fb4f..630a98ce4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -19,52 +19,52 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/sptr.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <apt-pkg/macros.h>
+#include <apt-pkg/sptr.h>
+#include <apt-pkg/strutl.h>
-#include <ctype.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <sys/select.h>
-#include <time.h>
-#include <string>
-#include <vector>
+#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <cstdio>
#include <iostream>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/wait.h>
+#include <string>
+#include <vector>
+#include <ctype.h>
#include <dirent.h>
-#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#include <glob.h>
-#include <pwd.h>
#include <grp.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
-#include <set>
#include <algorithm>
#include <memory>
+#include <set>
#ifdef HAVE_ZLIB
- #include <zlib.h>
+#include <zlib.h>
#endif
#ifdef HAVE_BZ2
- #include <bzlib.h>
+#include <bzlib.h>
#endif
#ifdef HAVE_LZMA
- #include <lzma.h>
+#include <lzma.h>
#endif
#ifdef HAVE_LZ4
- #include <lz4frame.h>
+#include <lz4frame.h>
#endif
#include <endian.h>
#include <stdint.h>
@@ -178,6 +178,21 @@ bool CopyFile(FileFd &From,FileFd &To)
return true;
}
/*}}}*/
+bool RemoveFileAt(char const * const Function, int const dirfd, std::string const &FileName)/*{{{*/
+{
+ if (FileName == "/dev/null")
+ return true;
+ errno = 0;
+ if (unlinkat(dirfd, FileName.c_str(), 0) != 0)
+ {
+ if (errno == ENOENT)
+ return true;
+
+ return _error->WarningE(Function,_("Problem unlinking the file %s"), FileName.c_str());
+ }
+ return true;
+}
+ /*}}}*/
bool RemoveFile(char const * const Function, std::string const &FileName)/*{{{*/
{
if (FileName == "/dev/null")
@@ -2832,7 +2847,7 @@ std::string GetTempDir(std::string const &User)
FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd) /*{{{*/
{
char fn[512];
- FileFd * const Fd = TmpFd == NULL ? new FileFd() : TmpFd;
+ FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd;
std::string const tempdir = GetTempDir();
snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
@@ -2843,12 +2858,16 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co
if (fd < 0)
{
_error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true))
{
_error->Errno("GetTempFile",_("Unable to write to %s"),fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
return Fd;
}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index dddeb70f5..5e857b5c8 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -21,12 +21,12 @@
#ifndef PKGLIB_FILEUTL_H
#define PKGLIB_FILEUTL_H
-#include <apt-pkg/macros.h>
#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/macros.h>
+#include <set>
#include <string>
#include <vector>
-#include <set>
#include <time.h>
#include <zlib.h>
@@ -161,6 +161,7 @@ class FileFd
bool RunScripts(const char *Cnf);
bool CopyFile(FileFd &From,FileFd &To);
bool RemoveFile(char const * const Function, std::string const &FileName);
+bool RemoveFileAt(char const * const Function, int const dirfd, std::string const &FileName);
int GetLock(std::string File,bool Errors = true);
bool FileExists(std::string File);
bool RealFileExists(std::string File);
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index cdf9481cb..cc1fbc5aa 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -1,21 +1,21 @@
// -*- mode: cpp; mode: fold -*-
// Include Files /*{{{*/
-#include<config.h>
+#include <config.h>
-#include<apt-pkg/configuration.h>
-#include<apt-pkg/error.h>
-#include<apt-pkg/strutl.h>
-#include<apt-pkg/fileutl.h>
-#include<apt-pkg/gpgv.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/gpgv.h>
+#include <apt-pkg/strutl.h>
#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <fcntl.h>
+#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <stddef.h>
#include <algorithm>
#include <fstream>
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 662c2bf8b..5a1d356f1 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -13,19 +13,19 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/hashes.h>
-#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/hashes.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
-#include <stddef.h>
#include <algorithm>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string>
#include <iostream>
+#include <string>
+#include <stddef.h>
+#include <stdlib.h>
+#include <unistd.h>
/*}}}*/
const char * HashString::_SupportedHashes[] =
@@ -339,7 +339,7 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size)
bool const ToEOF = (Size == UntilEOF);
while (Size != 0 || ToEOF)
{
- unsigned long long n = sizeof(Buf);
+ decltype(Size) n = sizeof(Buf);
if (!ToEOF) n = std::min(Size, n);
ssize_t const Res = read(Fd,Buf,n);
if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
@@ -363,9 +363,9 @@ bool Hashes::AddFD(FileFd &Fd,unsigned long long Size)
bool const ToEOF = (Size == 0);
while (Size != 0 || ToEOF)
{
- unsigned long long n = sizeof(Buf);
+ decltype(Size) n = sizeof(Buf);
if (!ToEOF) n = std::min(Size, n);
- unsigned long long a = 0;
+ decltype(Size) a = 0;
if (Fd.Read(Buf, n, &a) == false) // error
return false;
if (ToEOF == false)
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 1fe0afc00..1f8f45cb1 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -13,11 +13,10 @@
#ifndef APTPKG_HASHES_H
#define APTPKG_HASHES_H
-
+#include <apt-pkg/macros.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
-#include <apt-pkg/macros.h>
#include <cstring>
#include <string>
diff --git a/apt-pkg/contrib/hashsum.cc b/apt-pkg/contrib/hashsum.cc
index 25ccc187d..e8e86e92c 100644
--- a/apt-pkg/contrib/hashsum.cc
+++ b/apt-pkg/contrib/hashsum.cc
@@ -3,9 +3,9 @@
#include <apt-pkg/fileutl.h>
+#include "hashsum_template.h"
#include <algorithm>
#include <unistd.h>
-#include "hashsum_template.h"
// Summation::AddFD - Add content of file into the checksum /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h
index e5032d02f..2594f6aeb 100644
--- a/apt-pkg/contrib/hashsum_template.h
+++ b/apt-pkg/contrib/hashsum_template.h
@@ -10,9 +10,8 @@
#ifndef APTPKG_HASHSUM_TEMPLATE_H
#define APTPKG_HASHSUM_TEMPLATE_H
-
-#include <string>
#include <cstring>
+#include <string>
#ifdef APT_PKG_EXPOSE_STRING_VIEW
#include <apt-pkg/string_view.h>
#endif
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h
index bc1f523ea..5e22a195d 100644
--- a/apt-pkg/contrib/macros.h
+++ b/apt-pkg/contrib/macros.h
@@ -165,7 +165,7 @@
// See also buildlib/libversion.mak
#define APT_PKG_MAJOR 5
#define APT_PKG_MINOR 0
-#define APT_PKG_RELEASE 1
+#define APT_PKG_RELEASE 2
#define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR)
#endif
diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h
index a286f092a..ad0d31374 100644
--- a/apt-pkg/contrib/md5.h
+++ b/apt-pkg/contrib/md5.h
@@ -28,9 +28,9 @@
#include "hashsum_template.h"
#ifndef APT_10_CLEANER_HEADERS
-#include <string>
-#include <cstring>
#include <algorithm>
+#include <cstring>
+#include <string>
#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index cd24a2808..100796cdf 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -19,17 +19,17 @@
#define _DEFAULT_SOURCE
#include <config.h>
-#include <apt-pkg/mmap.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/macros.h>
+#include <apt-pkg/mmap.h>
+#include <cstring>
#include <string>
+#include <errno.h>
+#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <cstring>
#include <apti18n.h>
/*}}}*/
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 62e64b95e..df02b1b85 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -25,7 +25,6 @@
#ifndef PKGLIB_MMAP_H
#define PKGLIB_MMAP_H
-
#include <string>
#ifndef APT_8_CLEANER_HEADERS
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index 8840de72c..88027c989 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -17,12 +17,12 @@
#include <apt-pkg/strutl.h>
#include <iostream>
+#include <pwd.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stddef.h>
-#include <pwd.h>
#include "netrc.h"
diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc
index b93018154..7c5b15e6b 100644
--- a/apt-pkg/contrib/progress.cc
+++ b/apt-pkg/contrib/progress.cc
@@ -10,15 +10,15 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/progress.h>
-#include <sys/time.h>
-#include <string>
+#include <cstring>
#include <iostream>
+#include <string>
#include <stdio.h>
-#include <cstring>
+#include <sys/time.h>
#include <apti18n.h>
/*}}}*/
diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h
index 427b1bd35..43c84da71 100644
--- a/apt-pkg/contrib/progress.h
+++ b/apt-pkg/contrib/progress.h
@@ -21,10 +21,9 @@
#ifndef PKGLIB_PROGRESS_H
#define PKGLIB_PROGRESS_H
-
+#include <apt-pkg/macros.h>
#include <string>
#include <sys/time.h>
-#include <apt-pkg/macros.h>
#ifndef APT_8_CLEANER_HEADERS
using std::string;
diff --git a/apt-pkg/contrib/proxy.cc b/apt-pkg/contrib/proxy.cc
index 1b7a92c68..86582e1aa 100644
--- a/apt-pkg/contrib/proxy.cc
+++ b/apt-pkg/contrib/proxy.cc
@@ -7,12 +7,14 @@
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#include<apt-pkg/configuration.h>
-#include<apt-pkg/error.h>
-#include<apt-pkg/fileutl.h>
-#include<apt-pkg/strutl.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
-#include<iostream>
+#include <algorithm>
+#include <iostream>
+#include <fcntl.h>
#include <unistd.h>
#include "proxy.h"
@@ -21,6 +23,13 @@
// AutoDetectProxy - auto detect proxy /*{{{*/
// ---------------------------------------------------------------------
/* */
+static std::vector<std::string> CompatibleProxies(URI const &URL)
+{
+ if (URL.Access == "http" || URL.Access == "https")
+ return {"http", "https", "socks5h"};
+ return {URL.Access};
+}
+
bool AutoDetectProxy(URI &URL)
{
// we support both http/https debug options
@@ -41,6 +50,9 @@ bool AutoDetectProxy(URI &URL)
if (Debug)
std::clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << std::endl;
+ if (faccessat(AT_FDCWD, AutoDetectProxyCmd.c_str(), R_OK | X_OK, AT_EACCESS) != 0)
+ return _error->Errno("access", "ProxyAutoDetect command '%s' can not be executed!", AutoDetectProxyCmd.c_str());
+
std::string const urlstring = URL;
std::vector<const char *> Args;
Args.push_back(AutoDetectProxyCmd.c_str());
@@ -70,7 +82,14 @@ bool AutoDetectProxy(URI &URL)
if (Debug)
std::clog << "auto detect command returned: '" << cleanedbuf << "'" << std::endl;
- if (strstr(cleanedbuf, URL.Access.c_str()) == cleanedbuf || strcmp(cleanedbuf, "DIRECT") == 0)
+ auto compatibleTypes = CompatibleProxies(URL);
+ bool compatible = strcmp(cleanedbuf, "DIRECT") == 0 ||
+ compatibleTypes.end() != std::find_if(compatibleTypes.begin(),
+ compatibleTypes.end(), [cleanedbuf](std::string &compat) {
+ return strstr(cleanedbuf, compat.c_str()) == cleanedbuf;
+ });
+
+ if (compatible)
_config->Set("Acquire::"+URL.Access+"::proxy::"+URL.Host, cleanedbuf);
return true;
diff --git a/apt-pkg/contrib/sha1.h b/apt-pkg/contrib/sha1.h
index 3387c1cfd..967e2eae0 100644
--- a/apt-pkg/contrib/sha1.h
+++ b/apt-pkg/contrib/sha1.h
@@ -17,9 +17,9 @@
#include "hashsum_template.h"
#ifndef APT_10_CLEANER_HEADERS
-#include <string>
-#include <cstring>
#include <algorithm>
+#include <cstring>
+#include <string>
#endif
#ifndef APT_8_CLEANER_HEADERS
using std::string;
diff --git a/apt-pkg/contrib/sha2.h b/apt-pkg/contrib/sha2.h
index 164840d3b..d8127c66b 100644
--- a/apt-pkg/contrib/sha2.h
+++ b/apt-pkg/contrib/sha2.h
@@ -16,12 +16,12 @@
#include <cstring>
-#include "sha2_internal.h"
#include "hashsum_template.h"
+#include "sha2_internal.h"
#ifndef APT_10_CLEANER_HEADERS
-#include <string>
#include <algorithm>
+#include <string>
#include <stdint.h>
#endif
diff --git a/apt-pkg/contrib/sha2_internal.cc b/apt-pkg/contrib/sha2_internal.cc
index f70b7b17d..419b92aca 100644
--- a/apt-pkg/contrib/sha2_internal.cc
+++ b/apt-pkg/contrib/sha2_internal.cc
@@ -33,10 +33,10 @@
*/
#include <config.h>
-#include <endian.h>
-#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
-#include <assert.h> /* assert() */
#include "sha2_internal.h"
+#include <assert.h> /* assert() */
+#include <endian.h>
+#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
/*
* ASSERT NOTE:
@@ -93,7 +93,7 @@
/*
* Define the followingsha2_* types to types of the correct length on
- * the native archtecture. Most BSD systems and Linux define u_intXX_t
+ * the native architecture. Most BSD systems and Linux define u_intXX_t
* types. Machines with very recent ANSI C headers, can use the
* uintXX_t definintions from inttypes.h by defining SHA2_USE_INTTYPES_H
* during compile or in the sha.h header file.
diff --git a/apt-pkg/contrib/sha2_internal.h b/apt-pkg/contrib/sha2_internal.h
index 1b82d965d..fa4bfc4df 100644
--- a/apt-pkg/contrib/sha2_internal.h
+++ b/apt-pkg/contrib/sha2_internal.h
@@ -44,8 +44,8 @@
#ifdef SHA2_USE_INTTYPES_H
-#include <stddef.h>
#include <inttypes.h>
+#include <stddef.h>
#endif /* SHA2_USE_INTTYPES_H */
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index 327e59937..930989bfc 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/apt-pkg/contrib/srvrec.cc
@@ -10,8 +10,8 @@
#include <netdb.h>
-#include <netinet/in.h>
#include <arpa/nameser.h>
+#include <netinet/in.h>
#include <resolv.h>
#include <time.h>
@@ -22,10 +22,8 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
-
#include "srvrec.h"
-
bool SrvRec::operator==(SrvRec const &other) const
{
return (std::tie(target, priority, weight, port) ==
diff --git a/apt-pkg/contrib/srvrec.h b/apt-pkg/contrib/srvrec.h
index 01b810281..e22b7a1c6 100644
--- a/apt-pkg/contrib/srvrec.h
+++ b/apt-pkg/contrib/srvrec.h
@@ -9,9 +9,9 @@
#ifndef SRVREC_H
#define SRVREC_H
-#include <arpa/nameser.h>
-#include <vector>
#include <string>
+#include <vector>
+#include <arpa/nameser.h>
class SrvRec
{
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h
index c504edd27..536744e32 100644
--- a/apt-pkg/contrib/string_view.h
+++ b/apt-pkg/contrib/string_view.h
@@ -11,9 +11,9 @@
#if !defined(APT_STRINGVIEW_H) && defined(APT_PKG_EXPOSE_STRING_VIEW)
#define APT_STRINGVIEW_H
-#include <string.h>
-#include <string>
#include <apt-pkg/macros.h>
+#include <string>
+#include <string.h>
namespace APT {
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 88113f7a4..964f0d6c6 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -17,30 +17,30 @@
// Includes /*{{{*/
#include <config.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
-#include <array>
#include <algorithm>
+#include <array>
#include <iomanip>
#include <locale>
#include <sstream>
-#include <string>
#include <sstream>
+#include <string>
#include <vector>
+#include <ctype.h>
+#include <errno.h>
+#include <iconv.h>
+#include <regex.h>
+#include <stdarg.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
#include <string.h>
-#include <stdio.h>
+#include <time.h>
#include <unistd.h>
-#include <regex.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <iconv.h>
#include <apti18n.h>
/*}}}*/
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 73f27aa6c..cc39521da 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -16,17 +16,16 @@
#ifndef STRUTL_H
#define STRUTL_H
-
+#include <cstring>
+#include <iostream>
#include <limits>
#include <string>
-#include <cstring>
#include <vector>
-#include <iostream>
#ifdef APT_PKG_EXPOSE_STRING_VIEW
#include <apt-pkg/string_view.h>
#endif
-#include <time.h>
#include <stddef.h>
+#include <time.h>
#include "macros.h"