summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HACKING8
-rw-r--r--INSTALL4
-rw-r--r--configure.ac27
-rw-r--r--contrib/Makefile.am5
-rw-r--r--contrib/README3
-rwxr-xr-xcontrib/pacscripts.in2
-rwxr-xr-xcontrib/wget-xdelta.sh.in70
-rw-r--r--doc/.gitignore1
-rw-r--r--doc/Makefile.am4
-rw-r--r--doc/index.txt1
-rw-r--r--doc/makepkg.conf.5.txt9
-rw-r--r--doc/pacman-key.8.txt85
-rw-r--r--doc/pacman.8.txt7
-rw-r--r--doc/pacman.conf.5.txt9
-rw-r--r--doc/repo-add.8.txt7
-rw-r--r--etc/makepkg.conf.in11
-rw-r--r--lib/libalpm/Makefile.am4
-rw-r--r--lib/libalpm/add.c34
-rw-r--r--lib/libalpm/alpm.c24
-rw-r--r--lib/libalpm/alpm.h30
-rw-r--r--lib/libalpm/alpm_list.c87
-rw-r--r--lib/libalpm/backup.c14
-rw-r--r--lib/libalpm/base64.c190
-rw-r--r--lib/libalpm/base64.h68
-rw-r--r--lib/libalpm/be_local.c70
-rw-r--r--lib/libalpm/be_package.c49
-rw-r--r--lib/libalpm/be_sync.c70
-rw-r--r--lib/libalpm/conflict.c62
-rw-r--r--lib/libalpm/db.c177
-rw-r--r--lib/libalpm/db.h7
-rw-r--r--lib/libalpm/delta.c36
-rw-r--r--lib/libalpm/deps.c86
-rw-r--r--lib/libalpm/diskspace.c22
-rw-r--r--lib/libalpm/dload.c423
-rw-r--r--lib/libalpm/dload.h6
-rw-r--r--lib/libalpm/error.c28
-rw-r--r--lib/libalpm/graph.h2
-rw-r--r--lib/libalpm/group.c6
-rw-r--r--lib/libalpm/handle.c78
-rw-r--r--lib/libalpm/handle.h11
-rw-r--r--lib/libalpm/log.c4
-rw-r--r--lib/libalpm/package.c71
-rw-r--r--lib/libalpm/package.h3
-rw-r--r--lib/libalpm/pkghash.c34
-rw-r--r--lib/libalpm/remove.c16
-rw-r--r--lib/libalpm/signing.c280
-rw-r--r--lib/libalpm/signing.h39
-rw-r--r--lib/libalpm/sync.c73
-rw-r--r--lib/libalpm/trans.c62
-rw-r--r--lib/libalpm/util.c88
-rw-r--r--lib/libalpm/util.h6
-rw-r--r--lib/libalpm/version.c14
-rw-r--r--m4/libcurl.m4250
-rw-r--r--scripts/.gitignore1
-rw-r--r--scripts/Makefile.am3
-rw-r--r--scripts/makepkg.sh.in31
-rw-r--r--scripts/pacman-key.sh.in320
-rw-r--r--scripts/repo-add.sh.in85
-rw-r--r--src/pacman/Makefile.am2
-rw-r--r--src/pacman/callback.c2
-rw-r--r--src/pacman/conf.c8
-rw-r--r--src/pacman/conf.h4
-rw-r--r--src/pacman/database.c10
-rw-r--r--src/pacman/deptest.c4
-rw-r--r--src/pacman/package.c4
-rw-r--r--src/pacman/pacman.c140
-rw-r--r--src/pacman/query.c60
-rw-r--r--src/pacman/remove.c16
-rw-r--r--src/pacman/sync.c86
-rw-r--r--src/pacman/upgrade.c22
-rw-r--r--src/pacman/util.c122
-rw-r--r--src/util/cleanupdelta.c2
-rw-r--r--src/util/pactree.c18
-rw-r--r--src/util/testdb.c20
-rw-r--r--src/util/testpkg.c6
-rw-r--r--src/util/vercmp.c6
-rwxr-xr-xtest/pacman/pmdb.py10
-rwxr-xr-xtest/pacman/pmpkg.py1
-rw-r--r--test/pacman/tests/sign001.py9
-rw-r--r--test/pacman/tests/sign002.py10
-rw-r--r--test/pacman/tests/smoke004.py11
-rwxr-xr-xtest/pacman/util.py3
-rwxr-xr-xtest/util/vercmptest.sh2
83 files changed, 2685 insertions, 1110 deletions
diff --git a/HACKING b/HACKING
index c659ff0b..2df7ecc7 100644
--- a/HACKING
+++ b/HACKING
@@ -35,7 +35,7 @@ while(it) {
if(fn) {
fn(it->data);
} else {
- return(1);
+ return 1;
}
free(it);
it = ptr;
@@ -67,11 +67,11 @@ alpm_list_t *alpm_list_add(alpm_list_t *list, void *data)
NOT
// This is a comment
-5. Return statements should be written like a function call.
+5. Return statements should *not* be written like function calls.
- return(0);
- NOT
return 0;
+ NOT
+ return(0);
6. The sizeof() operator should accept a type, not a value. (TODO: in certain
cases, it may be better- should this be a set guideline? Read "The Practice
diff --git a/INSTALL b/INSTALL
index f9989d57..814118a1 100644
--- a/INSTALL
+++ b/INSTALL
@@ -16,8 +16,8 @@ properly build pacman.
libarchive
http://code.google.com/p/libarchive/
-libfetch
-ftp://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/net/libfetch/README.html
+libcurl
+http://curl.haxx.se/libcurl/
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
diff --git a/configure.ac b/configure.ac
index 23452225..87330afc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,10 +93,8 @@ AC_ARG_WITH(openssl,
AS_HELP_STRING([--with-openssl], [use OpenSSL crypto implementations instead of internal routines]),
[], [with_openssl=check])
-# Help line for libfetch
-AC_ARG_WITH(fetch,
- AS_HELP_STRING([--with-fetch], [use libfetch as an internal downloader]),
- [], [with_fetch=check])
+# Check for useable libcurl
+LIBCURL_CHECK_CONFIG([yes], [7.19.4])
# Help line for documentation
AC_ARG_ENABLE(doc,
@@ -149,24 +147,9 @@ AS_IF([test "x$with_openssl" != "xno"],
AC_MSG_RESULT(no))
AM_CONDITIONAL([HAVE_LIBSSL], [test "x$ac_cv_lib_ssl_MD5_Final" = "xyes"])
-# Enable or disable usage of libfetch
-AC_MSG_CHECKING(whether to link with libfetch)
-AS_IF([test "x$with_fetch" != "xno"],
- [AC_MSG_RESULT(yes)
- AC_CHECK_LIB([fetch], [fetchParseURL], ,
- [if test "x$with_fetch" != "xcheck"; then
- AC_MSG_FAILURE([--with-fetch was given, but -lfetch was not found])
- fi],
- [-lcrypto -ldl])
- # Check if libfetch supports connnection caching which we use
- AS_IF([test "x$ac_cv_lib_fetch_fetchParseURL" = "xyes"],
- [AC_CHECK_DECL(fetchConnectionCacheInit, ,
- AC_MSG_ERROR([libfetch must be version 2.28 or greater]),
- [#include <fetch.h>])
- ])
- ],
- AC_MSG_RESULT(no))
-AM_CONDITIONAL([HAVE_LIBFETCH], [test "x$ac_cv_lib_fetch_fetchParseURL" = "xyes"])
+# Check for gpgme
+AC_CHECK_LIB([gpgme], [gpgme_check_version], ,
+ AC_MSG_ERROR([gpgme is needed to compile pacman!]))
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h glob.h libintl.h locale.h mntent.h string.h \
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 827d9ec0..e9f77940 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -3,8 +3,7 @@ OURSCRIPTS = \
pacdiff \
paclist \
pacscripts \
- pacsearch \
- wget-xdelta.sh
+ pacsearch
OURFILES = \
bash_completion \
@@ -19,7 +18,6 @@ EXTRA_DIST = \
pacscripts.in \
pacsearch.in \
vimprojects \
- wget-xdelta.sh.in \
zsh_completion.in \
README
@@ -55,7 +53,6 @@ paclist: $(srcdir)/paclist.in
pacscripts: $(srcdir)/pacscripts.in
pacsearch: $(srcdir)/pacsearch.in
pactree: $(srcdir)/pactree.in
-wget-xdelta.sh: $(srcdir)/wget-xdelta.sh.in
zsh_completion: $(srcdir)/zsh_completion.in
# vim:set ts=2 sw=2 noet:
diff --git a/contrib/README b/contrib/README
index 4f591012..04b656f3 100644
--- a/contrib/README
+++ b/contrib/README
@@ -28,6 +28,3 @@ database entries. Useful for reuse, or possible config file extension.
vimprojects - a project file for the vim project plugin.
-wget-xdelta.sh - A download script for pacman which allows binary deltas
-generated with makepkg to be used instead of downloading full binary packages.
-This should cut download sizes for some package upgrades significantly.
diff --git a/contrib/pacscripts.in b/contrib/pacscripts.in
index d3664091..8ad5173b 100755
--- a/contrib/pacscripts.in
+++ b/contrib/pacscripts.in
@@ -61,7 +61,7 @@ spacman() {
if [ $EUID -eq 0 ]; then
pacman "$@"
else
- if [ ! "$(type -p sudo)" ]; then
+ if ! type -p sudo; then
error "Cannot find the sudo binary! Is sudo installed?"
error "Otherwise try to run the program as root"
exit 1
diff --git a/contrib/wget-xdelta.sh.in b/contrib/wget-xdelta.sh.in
deleted file mode 100755
index f2ac1c87..00000000
--- a/contrib/wget-xdelta.sh.in
+++ /dev/null
@@ -1,70 +0,0 @@
-#!@BASH_SHELL@
-
-if [ -r "@sysconfdir@/makepkg.conf" ]; then
- source @sysconfdir@/makepkg.conf
-else
- echo "wget-xdelta: Unable to find makepkg.conf"
- exit 1
-fi
-
-if [ -r ~/.makepkg.conf ]; then
- source ~/.makepkg.conf
-fi
-
-out_file=$(basename $1)
-file_url=$2
-
-if ! [[ "$out_file" =~ "pkg.tar.gz" ]]; then
- # If it's not a package file download as normal and exit.
- #wget --passive-ftp -c -O "$out_file" "$file_url"
- exit $?
-fi
-
-
-# Get the package name and version
-[[ "$out_file" =~ "$CARCH" ]] && arch="-$CARCH" || arch=""
-pkg_data=$(echo $out_file | \
- sed "s|^\(.*\)-\([[:alnum:]_\.]*-[[:alnum:]_\.]*\)${arch}${PKGEXT}.part|\1 \2|")
-pkgname=$(echo $pkg_data | cut -d ' ' -f 1)
-new_version=$(echo $pkg_data | cut -d ' ' -f 2)
-base_url=${file_url%/*}
-
-# Look for the last version
-for file in $(ls -r @localstatedir@/cache/pacman/pkg/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do
- [[ "$file" =~ "$CARCH" ]] && arch="-$CARCH" || arch=""
- check_version=$(echo $file | \
- sed "s|^.*/${pkgname}-\([[:alnum:]_\.]*-[[:alnum:]_\.]*\)${arch}$PKGEXT$|\1|" | \
- grep -v "^@localstatedir@/cache/pacman/pkg")
-
- [ "$check_version" = "" ] && continue
-
- vercmp=$(vercmp "$check_version" "$old_version")
- if [ "$check_version" != "$new_version" -a $vercmp -gt 0 ]; then
- old_version=$check_version
- old_file=$file
- fi
-done
-
-if [ "$old_version" != "" -a "$old_version" != "$new_version" ]; then
- # Great, we have a cached file, now calculate a patch name from it
- delta_name="$pkgname-${old_version}_to_${new_version}-${CARCH}.delta"
-
- echo "wget-xdelta: Attempting to download delta $delta_name..." >&2
- if wget --passive-ftp -c "$base_url/$delta_name"; then
- echo "wget-xdelta: Applying delta..."
- if xdelta patch "$delta_name" "$old_file" "$out_file"; then
- echo "wget-xdelta: Delta applied successfully!"
- rm "$delta_name"
- exit 0
- else
- echo "wget-xdelta: Failed to apply delta!"
- rm $delta_name
- fi
- fi
- fi
-
-echo "wget-xdelta: Downloading new package..."
-wget --passive-ftp -c -O "$out_file" "$file_url"
-exit $?
-
-# vim:set ts=4 sw=4 noet:
diff --git a/doc/.gitignore b/doc/.gitignore
index a6f4df7f..4c4e158d 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -3,6 +3,7 @@ libalpm.3
makepkg.8
makepkg.conf.5
pacman.8
+pacman-key.8
pacman.conf.5
repo-add.8
repo-remove.8
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 00a0e88d..ed9bb000 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -8,6 +8,7 @@ ASCIIDOC_MANS = \
makepkg.8 \
repo-add.8 \
vercmp.8 \
+ pacman-key.8 \
PKGBUILD.5 \
makepkg.conf.5 \
pacman.conf.5 \
@@ -20,6 +21,7 @@ HTML_MANPAGES = \
makepkg.8.html \
repo-add.8.html \
vercmp.8.html \
+ pacman-key.8.html \
PKGBUILD.5.html \
makepkg.conf.5.html \
pacman.conf.5.html \
@@ -41,6 +43,7 @@ EXTRA_DIST = \
makepkg.8.txt \
repo-add.8.txt \
vercmp.8.txt \
+ pacman-key.8.txt \
PKGBUILD.5.txt \
PKGBUILD-example.txt \
makepkg.conf.5.txt \
@@ -133,6 +136,7 @@ pacman.8 pacman.8.html: pacman.8.txt
makepkg.8 makepkg.8.html: makepkg.8.txt
repo-add.8 repo-add.8.html: repo-add.8.txt
vercmp.8 vercmp.8.html: vercmp.8.txt
+pacman-key.8 pacman-key.8.html: pacman-key.8.txt
PKGBUILD.5 PKGBUILD.5.html: PKGBUILD.5.txt PKGBUILD-example.txt
makepkg.conf.5 makepkg.conf.5.html: makepkg.conf.5.txt
pacman.conf.5 pacman.conf.5.html: pacman.conf.5.txt
diff --git a/doc/index.txt b/doc/index.txt
index a21cba18..8eddcfc5 100644
--- a/doc/index.txt
+++ b/doc/index.txt
@@ -41,6 +41,7 @@ configuration files dealing with pacman.
* linkman:makepkg[8]
* linkman:makepkg.conf[5]
* linkman:pacman[8]
+* linkman:pacman-key[8]
* linkman:pacman.conf[5]
* linkman:repo-add[8]
* linkman:vercmp[8]
diff --git a/doc/makepkg.conf.5.txt b/doc/makepkg.conf.5.txt
index 61302492..a9faa14d 100644
--- a/doc/makepkg.conf.5.txt
+++ b/doc/makepkg.conf.5.txt
@@ -70,7 +70,7 @@ Options
This is often used to set the number of jobs used, for example, `-j2`.
Other flags that make accepts can also be passed.
-**BUILDENV=(**fakeroot !distcc color !ccache**)**::
+**BUILDENV=(**fakeroot !distcc color !ccache !sign**)**::
This array contains options that affect the build environment, the defaults
are shown here. All options should always be left in the array; to enable
or disable an option simply remove or place an ``!'' at the front of the
@@ -98,6 +98,13 @@ Options
enabled or disabled for individual packages through the use of
makepkg's `--check` and `--nocheck` options respectively.
+ *sign*;;
+ Generate a PGP signature file using GnuPG. This will execute `gpg
+ --detach-sign --use-agent` on the built package to generate a detached
+ signature file, using the GPG agent if it is available. The signature
+ file will be the entire filename of the package with a ``.sig''
+ extension.
+
**DISTCC_HOSTS=**"host1 ..."::
If using DistCC, this is used to specify a space-delimited list of hosts
running in the DistCC cluster. In addition, you will want to modify your
diff --git a/doc/pacman-key.8.txt b/doc/pacman-key.8.txt
new file mode 100644
index 00000000..9bd135ce
--- /dev/null
+++ b/doc/pacman-key.8.txt
@@ -0,0 +1,85 @@
+/////
+vim:set ts=4 sw=4 syntax=asciidoc noet:
+/////
+pacman-key(8)
+=============
+
+
+Name
+----
+pacman-key - manage pacman's list of trusted keys
+
+
+Synopsis
+--------
+'pacman-key' [options] <command> [arguments]
+
+
+Description
+-----------
+pacman-key is a script used to manage pacman's keyring, which is the collection
+of GnuPG keys used to check signed packages. It provides the ability to import
+and export keys, fetch keys from keyservers and update the key trust database.
+
+
+Options
+-------
+*\--config* <file>::
+ Use an alternate config file instead of the `{sysconfdir}/pacman.conf`
+ default.
+
+*\--gpgdir* <dir>::
+ Set an alternate home directory for GnuPG. If unspecified, the value is
+ read from `{sysconfdir}/pacman.conf`.
+
+
+Commands
+-------
+*-a, \--add* file ...::
+ Add the key(s) contained in the specified file or files to pacman's
+ keyring. If a key already exists, update it.
+
+*\--adv* param ...::
+ Use this option to issue particular GnuPG actions to pacman's keyring. This
+ option should be used with care as it can modify pacman's trust in
+ packages' signatures.
+
+*-d, \--del* keyid ...::
+ Remove the key(s) identified by the specified keyid or keyids from pacman's
+ keyring.
+
+*-e, \--export* [keyid ...]::
+ Export key(s) identified by the specified keyid to 'stdout'. If no keyid is
+ specified, all keys will be exported.
+
+*-f, \--finger* [keyid ...]::
+ List a fingerprint for each specified keyid, or for all known keys if no
+ keyids are specified.
+
+*-h, \--help*::
+ Output syntax and command line options.
+
+*-l, \--list*::
+ Equivalent to --list-sigs from GnuPG.
+
+*-r, \--receive* keyserver keyid ...::
+ Fetch the specified keyids from the specified key server URL.
+
+*\--reload*::
+ Reloads the keys from the keyring package.
+
+*-t, \--trust* keyid::
+ Set the trust level of the given key.
+
+*-u, \--updatedb*::
+ Equivalent to \--check-trustdb in GnuPG.
+
+*-v, \--version*::
+ Displays the program version.
+
+
+See Also
+--------
+linkman:pacman[8], linkman:pacman.conf[5]
+
+include::footer.txt[]
diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index b727269b..f638123d 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -149,6 +149,13 @@ Options
Display debug messages. When reporting bugs, this option is recommended
to be used.
+*\--gpgdir* <dir>::
+ Specify a directory of files used by GnuPG to verify package signatures.
+ This directory should contain two files: `pubring.gpg` and `trustdb.gpg`.
+ `pubring.gpg` holds the public keys of all packagers. `trustdb.gpg`
+ contains a so-called trust database, which specifies that the keys are
+ authentic and trusted.
+
*\--logfile* <file>::
Specify an alternate log file. This is an absolute path, regardless of
the installation root setting.
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index bfa07458..ca1f8833 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -69,6 +69,15 @@ Options
to the first cache directory with write access. *NOTE*: this is an absolute
path, the root path is not automatically prepended.
+*GPGDir =* path/to/gpg/dir::
+ Overrides the default location of the directory containing configuration
+ files for GnuPG. A typical default is `{sysconfdir}/pacman.d/gnupg/`.
+ This directory should contain two files: `pubring.gpg` and `trustdb.gpg`.
+ `pubring.gpg` holds the public keys of all packagers. `trustdb.gpg`
+ contains a so-called trust database, which specifies that the keys are
+ authentic and trusted.
+ *NOTE*: this is an absolute path, the root path is not automatically
+ prepended.
*LogFile =* '/path/to/file'::
Overrides the default location of the pacman log file. A typical default
diff --git a/doc/repo-add.8.txt b/doc/repo-add.8.txt
index 75f49ef5..26009f67 100644
--- a/doc/repo-add.8.txt
+++ b/doc/repo-add.8.txt
@@ -43,6 +43,13 @@ Options
Force this program to keep quiet and run silent except for warning and
error messages.
+*-s, \--sign*::
+ Generate a PGP signature file using GnuPG. This will execute `gpg
+ --detach-sign --use-agent` on the generated database to generate a detached
+ signature file, using the GPG agent if it is available. The signature file
+ will be the entire filename of the database with a ``.sig'' extension.
+
+
See Also
--------
linkman:makepkg[8], linkman:pacman[8]
diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
index 81a11b1d..c3b7cc09 100644
--- a/etc/makepkg.conf.in
+++ b/etc/makepkg.conf.in
@@ -8,9 +8,9 @@
#
#-- The download utilities that makepkg should use to acquire sources
# Format: 'protocol::agent'
-DLAGENTS=('ftp::/usr/bin/wget -c --passive-ftp -t 3 --waitretry=3 -O %o %u'
- 'http::/usr/bin/wget -c -t 3 --waitretry=3 -O %o %u'
- 'https::/usr/bin/wget -c -t 3 --waitretry=3 --no-check-certificate -O %o %u'
+DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
+ 'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
'rsync::/usr/bin/rsync -z %u %o'
'scp::/usr/bin/scp -C %u %o')
@@ -39,7 +39,7 @@ CXXFLAGS="@CARCHFLAGS@-mtune=generic -O2 -pipe"
# BUILD ENVIRONMENT
#########################################################################
#
-# Defaults: BUILDENV=(fakeroot !distcc color !ccache check)
+# Defaults: BUILDENV=(fakeroot !distcc color !ccache check !sign)
# A negated environment option will do the opposite of the comments below.
#
#-- fakeroot: Allow building packages as a non-root user
@@ -47,8 +47,9 @@ CXXFLAGS="@CARCHFLAGS@-mtune=generic -O2 -pipe"
#-- color: Colorize output messages
#-- ccache: Use ccache to cache compilation
#-- check: Run the check() function if present in the PKGBUILD
+#-- sign: Generate PGP signature file
#
-BUILDENV=(fakeroot !distcc color !ccache check)
+BUILDENV=(fakeroot !distcc color !ccache check !sign)
#
#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
#-- specify a space-delimited list of hosts running in the DistCC cluster.
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index 1bda5714..fb224a59 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -25,6 +25,7 @@ libalpm_la_SOURCES = \
alpm.h alpm.c \
alpm_list.h alpm_list.c \
backup.h backup.c \
+ base64.h base64.c \
be_local.c \
be_package.c \
be_sync.c \
@@ -42,6 +43,7 @@ libalpm_la_SOURCES = \
package.h package.c \
pkghash.h pkghash.c \
remove.h remove.c \
+ signing.c signing.h \
sync.h sync.c \
trans.h trans.c \
util.h util.c \
@@ -52,7 +54,7 @@ libalpm_la_SOURCES += \
md5.h md5.c
endif
-libalpm_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_INFO)
+libalpm_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_INFO) @LIBCURL@
libalpm_la_LIBADD = $(LTLIBINTL)
# vim:set ts=2 sw=2 noet:
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 702b12e9..0a5cb539 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -91,7 +91,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
/* with the NEEDED flag, packages up to date are not reinstalled */
_alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
localpkgname, localpkgver);
- return(0);
+ return 0;
} else {
_alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"),
localpkgname, localpkgver);
@@ -109,7 +109,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
pkgname, pkgver);
trans->add = alpm_list_add(trans->add, pkg);
- return(0);
+ return 0;
}
static int perform_extraction(struct archive *archive,
@@ -132,9 +132,9 @@ static int perform_extraction(struct archive *archive,
origname, archive_error_string(archive));
alpm_logaction("error: could not extract %s (%s)\n",
origname, archive_error_string(archive));
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int extract_single_file(struct archive *archive,
@@ -169,7 +169,7 @@ static int extract_single_file(struct archive *archive,
* already been handled (for future possibilities) */
_alpm_log(PM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
} else {
/* build the new entryname relative to handle->root */
snprintf(filename, PATH_MAX, "%s%s", handle->root, entryname);
@@ -182,7 +182,7 @@ static int extract_single_file(struct archive *archive,
alpm_logaction("note: %s is in NoExtract, skipping extraction\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
}
/* Check for file existence. This is one of the more crucial parts
@@ -226,13 +226,13 @@ static int extract_single_file(struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
} else {
/* case 10/11: trying to overwrite dir with file/symlink, don't allow it */
_alpm_log(PM_LOG_ERROR, _("extract: not overwriting dir with file %s\n"),
entryname);
archive_read_data_skip(archive);
- return(1);
+ return 1;
}
} else if(S_ISLNK(lsbuf.st_mode) && S_ISDIR(entrymode)) {
/* case 9: existing symlink, dir in package */
@@ -241,13 +241,13 @@ static int extract_single_file(struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "extract: skipping symlink overwrite of %s\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
} else {
/* this is BAD. symlink was not to a directory */
_alpm_log(PM_LOG_ERROR, _("extract: symlink %s does not point to dir\n"),
entryname);
archive_read_data_skip(archive);
- return(1);
+ return 1;
}
} else if(S_ISREG(lsbuf.st_mode) && S_ISDIR(entrymode)) {
/* case 6: trying to overwrite file with dir */
@@ -299,7 +299,7 @@ static int extract_single_file(struct archive *archive,
/* error */
FREE(hash_orig);
FREE(entryname_orig);
- return(1);
+ return 1;
}
hash_local = alpm_compute_md5sum(filename);
@@ -442,7 +442,7 @@ static int extract_single_file(struct archive *archive,
if(ret == 1) {
/* error */
FREE(entryname_orig);
- return(1);
+ return 1;
}
/* calculate an hash if this is in newpkg's backup */
@@ -469,7 +469,7 @@ static int extract_single_file(struct archive *archive,
}
}
FREE(entryname_orig);
- return(errors);
+ return errors;
}
static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
@@ -705,7 +705,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
cleanup:
_alpm_pkg_free(oldpkg);
- return(ret);
+ return ret;
}
int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
@@ -720,7 +720,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
if(trans->add == NULL) {
- return(0);
+ return 0;
}
pkg_count = alpm_list_count(trans->add);
@@ -729,7 +729,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
/* loop through our package list adding/upgrading one at a time */
for(targ = trans->add; targ; targ = targ->next) {
if(handle->trans->state == STATE_INTERRUPTED) {
- return(ret);
+ return ret;
}
pmpkg_t *newpkg = (pmpkg_t *)targ->data;
@@ -750,7 +750,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
_alpm_ldconfig(handle->root);
}
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index a60a4bb6..bafd922b 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -23,9 +23,8 @@
#include "config.h"
-/* connection caching setup */
-#ifdef HAVE_LIBFETCH
-#include <fetch.h>
+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
#endif
/* libalpm */
@@ -58,18 +57,19 @@ int SYMEXPORT alpm_initialize(void)
/* error code should be set */
_alpm_handle_free(handle);
handle = NULL;
- return(-1);
+ return -1;
}
#ifdef ENABLE_NLS
bindtextdomain("libalpm", LOCALEDIR);
#endif
-#ifdef HAVE_LIBFETCH
- fetchConnectionCacheInit(5, 1);
+#ifdef HAVE_LIBCURL
+ curl_global_init(CURL_GLOBAL_SSL);
+ handle->curl = curl_easy_init();
#endif
- return(0);
+ return 0;
}
/** Release the library. This should be the last alpm call you make.
@@ -91,17 +91,17 @@ int SYMEXPORT alpm_release(void)
}
if(alpm_db_unregister_all() == -1) {
- return(-1);
+ return -1;
}
_alpm_handle_free(handle);
handle = NULL;
-#ifdef HAVE_LIBFETCH
- fetchConnectionCacheClose();
+#ifdef HAVE_LIBCURL
+ curl_global_cleanup();
#endif
- return(0);
+ return 0;
}
/** @} */
@@ -112,7 +112,7 @@ int SYMEXPORT alpm_release(void)
/* Get the version of library */
const char SYMEXPORT *alpm_version(void) {
- return(LIB_VERSION);
+ return LIB_VERSION;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 0f3b7166..b08191d0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -45,6 +45,7 @@ extern "C" {
typedef struct __pmdb_t pmdb_t;
typedef struct __pmpkg_t pmpkg_t;
+typedef struct __pmpgpsig_t pmpgpsig_t;
typedef struct __pmdelta_t pmdelta_t;
typedef struct __pmgrp_t pmgrp_t;
typedef struct __pmtrans_t pmtrans_t;
@@ -126,6 +127,9 @@ int alpm_option_set_logfile(const char *logfile);
const char *alpm_option_get_lockfile(void);
/* no set_lockfile, path is determined from dbpath */
+const char *alpm_option_get_signaturedir(void);
+int alpm_option_set_signaturedir(const char *signaturedir);
+
int alpm_option_get_usesyslog(void);
void alpm_option_set_usesyslog(int usesyslog);
@@ -215,6 +219,7 @@ time_t alpm_pkg_get_builddate(pmpkg_t *pkg);
time_t alpm_pkg_get_installdate(pmpkg_t *pkg);
const char *alpm_pkg_get_packager(pmpkg_t *pkg);
const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
+const pmpgpsig_t *alpm_pkg_get_pgpsig(pmpkg_t *pkg);
const char *alpm_pkg_get_arch(pmpkg_t *pkg);
off_t alpm_pkg_get_size(pmpkg_t *pkg);
off_t alpm_pkg_get_isize(pmpkg_t *pkg);
@@ -241,6 +246,22 @@ off_t alpm_pkg_download_size(pmpkg_t *newpkg);
alpm_list_t *alpm_pkg_unused_deltas(pmpkg_t *pkg);
/*
+ * Signatures
+ */
+
+int alpm_pkg_check_pgp_signature(pmpkg_t *pkg);
+int alpm_db_check_pgp_signature(pmdb_t *db);
+
+/* GPG signature verification option */
+typedef enum _pgp_verify_t {
+ PM_PGP_VERIFY_ALWAYS,
+ PM_PGP_VERIFY_OPTIONAL,
+ PM_PGP_VERIFY_NEVER
+} pgp_verify_t;
+
+int alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify);
+
+/*
* Deltas
*/
@@ -521,6 +542,10 @@ enum _pmerrno_t {
PM_ERR_PKG_INVALID_NAME,
PM_ERR_PKG_INVALID_ARCH,
PM_ERR_PKG_REPO_NOT_FOUND,
+ /* Signatures */
+ PM_ERR_SIG_MISSINGDIR,
+ PM_ERR_SIG_INVALID,
+ PM_ERR_SIG_UNKNOWN,
/* Deltas */
PM_ERR_DLT_INVALID,
PM_ERR_DLT_PATCHFAILED,
@@ -534,8 +559,9 @@ enum _pmerrno_t {
PM_ERR_INVALID_REGEX,
/* External library errors */
PM_ERR_LIBARCHIVE,
- PM_ERR_LIBFETCH,
- PM_ERR_EXTERNAL_DOWNLOAD
+ PM_ERR_LIBCURL,
+ PM_ERR_EXTERNAL_DOWNLOAD,
+ PM_ERR_GPGME
};
extern enum _pmerrno_t pm_errno;
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index f0619bcd..0a3f6502 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -92,7 +92,7 @@ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
ptr = calloc(1, sizeof(alpm_list_t));
if(ptr == NULL) {
- return(list);
+ return list;
}
ptr->data = data;
@@ -101,7 +101,7 @@ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
/* Special case: the input list is empty */
if(list == NULL) {
ptr->prev = ptr;
- return(ptr);
+ return ptr;
}
lp = alpm_list_last(list);
@@ -109,7 +109,7 @@ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
ptr->prev = lp;
list->prev = ptr;
- return(list);
+ return list;
}
/**
@@ -124,13 +124,13 @@ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn)
{
if(!fn || !list) {
- return(alpm_list_add(list, data));
+ return alpm_list_add(list, data);
} else {
alpm_list_t *add = NULL, *prev = NULL, *next = list;
add = calloc(1, sizeof(alpm_list_t));
if(add == NULL) {
- return(list);
+ return list;
}
add->data = data;
@@ -146,19 +146,19 @@ alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_
add->prev = list->prev; /* list != NULL */
add->next = list;
list->prev = add;
- return(add);
+ return add;
} else if(next == NULL) { /* another special case: add last element */
add->prev = prev;
add->next = NULL;
prev->next = add;
list->prev = add;
- return(list);
+ return list;
} else {
add->prev = prev;
add->next = next;
next->prev = add;
prev->next = add;
- return(list);
+ return list;
}
}
}
@@ -179,10 +179,10 @@ alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
alpm_list_t *tmp;
if (first == NULL) {
- return(second);
+ return second;
}
if (second == NULL) {
- return(first);
+ return first;
}
/* tmp is the last element of the first list */
tmp = first->prev;
@@ -193,7 +193,7 @@ alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
/* set the back reference to the tail */
second->prev = tmp;
- return(first);
+ return first;
}
/**
@@ -257,7 +257,7 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, a
}
newlist->prev = lp;
- return(newlist);
+ return newlist;
}
/**
@@ -282,7 +282,7 @@ alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn
right = alpm_list_msort(right, n - (n/2), fn);
list = alpm_list_mmerge(left, right, fn);
}
- return(list);
+ return list;
}
/**
@@ -298,7 +298,7 @@ alpm_list_t SYMEXPORT *alpm_list_remove_item(alpm_list_t *haystack,
alpm_list_t *item)
{
if(haystack == NULL || item == NULL) {
- return(haystack);
+ return haystack;
}
if(item == haystack) {
@@ -328,7 +328,7 @@ alpm_list_t SYMEXPORT *alpm_list_remove_item(alpm_list_t *haystack,
}
}
- return(haystack);
+ return haystack;
}
@@ -352,7 +352,7 @@ alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystack,
}
if(needle == NULL) {
- return(haystack);
+ return haystack;
}
while(i) {
@@ -373,7 +373,7 @@ alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystack,
}
}
- return(haystack);
+ return haystack;
}
/**
@@ -388,8 +388,8 @@ alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystack,
alpm_list_t SYMEXPORT *alpm_list_remove_str(alpm_list_t *haystack,
const char *needle, char **data)
{
- return(alpm_list_remove(haystack, (const void *)needle,
- (alpm_list_fn_cmp)strcmp, (void **)data));
+ return alpm_list_remove(haystack, (const void *)needle,
+ (alpm_list_fn_cmp)strcmp, (void **)data);
}
/**
@@ -411,7 +411,7 @@ alpm_list_t SYMEXPORT *alpm_list_remove_dupes(const alpm_list_t *list)
}
lp = lp->next;
}
- return(newlist);
+ return newlist;
}
/**
@@ -429,7 +429,7 @@ alpm_list_t SYMEXPORT *alpm_list_strdup(const alpm_list_t *list)
newlist = alpm_list_add(newlist, strdup(lp->data));
lp = lp->next;
}
- return(newlist);
+ return newlist;
}
/**
@@ -447,7 +447,7 @@ alpm_list_t SYMEXPORT *alpm_list_copy(const alpm_list_t *list)
newlist = alpm_list_add(newlist, lp->data);
lp = lp->next;
}
- return(newlist);
+ return newlist;
}
/**
@@ -473,7 +473,7 @@ alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list,
lp = lp->next;
}
}
- return(newlist);
+ return newlist;
}
/**
@@ -489,7 +489,7 @@ alpm_list_t SYMEXPORT *alpm_list_reverse(alpm_list_t *list)
alpm_list_t *newlist = NULL, *backup;
if(list == NULL) {
- return(NULL);
+ return NULL;
}
lp = alpm_list_last(list);
@@ -502,7 +502,7 @@ alpm_list_t SYMEXPORT *alpm_list_reverse(alpm_list_t *list)
lp = lp->prev;
}
list->prev = backup; /* restore tail pointer */
- return(newlist);
+ return newlist;
}
/* Accessors */
@@ -517,9 +517,9 @@ alpm_list_t SYMEXPORT *alpm_list_reverse(alpm_list_t *list)
inline alpm_list_t SYMEXPORT *alpm_list_first(const alpm_list_t *list)
{
if(list) {
- return((alpm_list_t*)list);
+ return (alpm_list_t *)list;
} else {
- return(NULL);
+ return NULL;
}
}
@@ -537,7 +537,7 @@ alpm_list_t SYMEXPORT *alpm_list_nth(const alpm_list_t *list, size_t n)
while(n--) {
i = i->next;
}
- return((alpm_list_t*)i);
+ return (alpm_list_t *)i;
}
/**
@@ -550,9 +550,9 @@ alpm_list_t SYMEXPORT *alpm_list_nth(const alpm_list_t *list, size_t n)
inline alpm_list_t SYMEXPORT *alpm_list_next(const alpm_list_t *node)
{
if(node) {
- return(node->next);
+ return node->next;
} else {
- return(NULL);
+ return NULL;
}
}
@@ -566,9 +566,9 @@ inline alpm_list_t SYMEXPORT *alpm_list_next(const alpm_list_t *node)
alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
{
if(list) {
- return(list->prev);
+ return list->prev;
} else {
- return(NULL);
+ return NULL;
}
}
@@ -581,8 +581,8 @@ alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
*/
void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
{
- if(node == NULL) return(NULL);
- return(node->data);
+ if(node == NULL) return NULL;
+ return node->data;
}
/* Misc */
@@ -602,7 +602,7 @@ size_t SYMEXPORT alpm_list_count(const alpm_list_t *list)
++i;
lp = lp->next;
}
- return(i);
+ return i;
}
/**
@@ -620,17 +620,17 @@ void SYMEXPORT *alpm_list_find(const alpm_list_t *haystack, const void *needle,
const alpm_list_t *lp = haystack;
while(lp) {
if(lp->data && fn(lp->data, needle) == 0) {
- return(lp->data);
+ return lp->data;
}
lp = lp->next;
}
- return(NULL);
+ return NULL;
}
/* trivial helper function for alpm_list_find_ptr */
static int ptr_cmp(const void *p, const void *q)
{
- return(p != q);
+ return (p != q);
}
/**
@@ -643,9 +643,10 @@ static int ptr_cmp(const void *p, const void *q)
*
* @return `needle` if found, NULL otherwise
*/
-void SYMEXPORT *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle)
+void SYMEXPORT *alpm_list_find_ptr(const alpm_list_t *haystack,
+ const void *needle)
{
- return(alpm_list_find(haystack, needle, ptr_cmp));
+ return alpm_list_find(haystack, needle, ptr_cmp);
}
/**
@@ -659,8 +660,8 @@ void SYMEXPORT *alpm_list_find_ptr(const alpm_list_t *haystack, const void *need
char SYMEXPORT *alpm_list_find_str(const alpm_list_t *haystack,
const char *needle)
{
- return((char *)alpm_list_find(haystack, (const void*)needle,
- (alpm_list_fn_cmp)strcmp));
+ return (char *)alpm_list_find(haystack, (const void *)needle,
+ (alpm_list_fn_cmp)strcmp);
}
/**
@@ -745,7 +746,7 @@ alpm_list_t SYMEXPORT *alpm_list_diff(const alpm_list_t *lhs,
alpm_list_free(left);
alpm_list_free(right);
- return(ret);
+ return ret;
}
/** @} */
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index ca955ca4..7df97471 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -47,7 +47,7 @@ static int backup_split(const char *string, char **file, char **hash)
/* don't need our dup as the fname wasn't requested, so free it */
FREE(str);
}
- return(0);
+ return 0;
}
*ptr = '\0';
ptr++;
@@ -59,21 +59,21 @@ static int backup_split(const char *string, char **file, char **hash)
*hash = strdup(ptr);
}
FREE(str);
- return(1);
+ return 1;
}
char *_alpm_backup_file(const char *string)
{
char *file = NULL;
backup_split(string, &file, NULL);
- return(file);
+ return file;
}
char *_alpm_backup_hash(const char *string)
{
char *hash = NULL;
backup_split(string, NULL, &hash);
- return(hash);
+ return hash;
}
/* Look for a filename in a pmpkg_t.backup list. If we find it,
@@ -86,7 +86,7 @@ char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
ALPM_LOG_FUNC;
if(file == NULL || backup == NULL) {
- return(NULL);
+ return NULL;
}
/* run through the backup list and parse out the hash for our file */
@@ -101,13 +101,13 @@ char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
}
if(strcmp(file, filename) == 0) {
FREE(filename);
- return(hash);
+ return hash;
}
FREE(filename);
FREE(hash);
}
- return(NULL);
+ return NULL;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/base64.c b/lib/libalpm/base64.c
new file mode 100644
index 00000000..fa8bec5c
--- /dev/null
+++ b/lib/libalpm/base64.c
@@ -0,0 +1,190 @@
+/*
+ * RFC 1521 base64 encoding/decoding
+ *
+ * Copyright (C) 2006-2010, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Pacman Notes:
+ *
+ * Taken from the PolarSSL project at www.polarssl.org under terms of the
+ * GPL. This is from version 0.14.2 of the library, and has been modified
+ * as following, which may be helpful for future updates:
+ * * remove "polarssl/config.h" include
+ * * change include from "polarssl/base64.h" to "base64.h"
+ * * removal of SELF_TEST code
+ */
+
+#include "base64.h"
+
+static const unsigned char base64_enc_map[64] =
+{
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
+ 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '+', '/'
+};
+
+static const unsigned char base64_dec_map[128] =
+{
+ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+ 127, 127, 127, 62, 127, 127, 127, 63, 52, 53,
+ 54, 55, 56, 57, 58, 59, 60, 61, 127, 127,
+ 127, 64, 127, 127, 127, 0, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 127, 127, 127, 127, 127, 127, 26, 27, 28,
+ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 127, 127, 127, 127, 127
+};
+
+/*
+ * Encode a buffer into base64 format
+ */
+int base64_encode( unsigned char *dst, int *dlen,
+ const unsigned char *src, int slen )
+{
+ int i, n;
+ int C1, C2, C3;
+ unsigned char *p;
+
+ if( slen == 0 )
+ return( 0 );
+
+ n = (slen << 3) / 6;
+
+ switch( (slen << 3) - (n * 6) )
+ {
+ case 2: n += 3; break;
+ case 4: n += 2; break;
+ default: break;
+ }
+
+ if( *dlen < n + 1 )
+ {
+ *dlen = n + 1;
+ return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
+ }
+
+ n = (slen / 3) * 3;
+
+ for( i = 0, p = dst; i < n; i += 3 )
+ {
+ C1 = *src++;
+ C2 = *src++;
+ C3 = *src++;
+
+ *p++ = base64_enc_map[(C1 >> 2) & 0x3F];
+ *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F];
+ *p++ = base64_enc_map[(((C2 & 15) << 2) + (C3 >> 6)) & 0x3F];
+ *p++ = base64_enc_map[C3 & 0x3F];
+ }
+
+ if( i < slen )
+ {
+ C1 = *src++;
+ C2 = ((i + 1) < slen) ? *src++ : 0;
+
+ *p++ = base64_enc_map[(C1 >> 2) & 0x3F];
+ *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F];
+
+ if( (i + 1) < slen )
+ *p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F];
+ else *p++ = '=';
+
+ *p++ = '=';
+ }
+
+ *dlen = p - dst;
+ *p = 0;
+
+ return( 0 );
+}
+
+/*
+ * Decode a base64-formatted buffer
+ */
+int base64_decode( unsigned char *dst, int *dlen,
+ const unsigned char *src, int slen )
+{
+ int i, j, n;
+ unsigned long x;
+ unsigned char *p;
+
+ for( i = j = n = 0; i < slen; i++ )
+ {
+ if( ( slen - i ) >= 2 &&
+ src[i] == '\r' && src[i + 1] == '\n' )
+ continue;
+
+ if( src[i] == '\n' )
+ continue;
+
+ if( src[i] == '=' && ++j > 2 )
+ return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
+
+ if( src[i] > 127 || base64_dec_map[src[i]] == 127 )
+ return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
+
+ if( base64_dec_map[src[i]] < 64 && j != 0 )
+ return( POLARSSL_ERR_BASE64_INVALID_CHARACTER );
+
+ n++;
+ }
+
+ if( n == 0 )
+ return( 0 );
+
+ n = ((n * 6) + 7) >> 3;
+
+ if( *dlen < n )
+ {
+ *dlen = n;
+ return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
+ }
+
+ for( j = 3, n = x = 0, p = dst; i > 0; i--, src++ )
+ {
+ if( *src == '\r' || *src == '\n' )
+ continue;
+
+ j -= ( base64_dec_map[*src] == 64 );
+ x = (x << 6) | ( base64_dec_map[*src] & 0x3F );
+
+ if( ++n == 4 )
+ {
+ n = 0;
+ if( j > 0 ) *p++ = (unsigned char)( x >> 16 );
+ if( j > 1 ) *p++ = (unsigned char)( x >> 8 );
+ if( j > 2 ) *p++ = (unsigned char)( x );
+ }
+ }
+
+ *dlen = p - dst;
+
+ return( 0 );
+}
diff --git a/lib/libalpm/base64.h b/lib/libalpm/base64.h
new file mode 100644
index 00000000..0ae9612c
--- /dev/null
+++ b/lib/libalpm/base64.h
@@ -0,0 +1,68 @@
+/**
+ * \file base64.h
+ *
+ * Copyright (C) 2006-2010, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _BASE64_H
+#define _BASE64_H
+
+#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL 0x0010
+#define POLARSSL_ERR_BASE64_INVALID_CHARACTER 0x0012
+
+/**
+ * \brief Encode a buffer into base64 format
+ *
+ * \param dst destination buffer
+ * \param dlen size of the buffer
+ * \param src source buffer
+ * \param slen amount of data to be encoded
+ *
+ * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
+ * *dlen is always updated to reflect the amount
+ * of data that has (or would have) been written.
+ *
+ * \note Call this function with *dlen = 0 to obtain the
+ * required buffer size in *dlen
+ */
+int base64_encode( unsigned char *dst, int *dlen,
+ const unsigned char *src, int slen );
+
+/**
+ * \brief Decode a base64-formatted buffer
+ *
+ * \param dst destination buffer
+ * \param dlen size of the buffer
+ * \param src source buffer
+ * \param slen amount of data to be decoded
+ *
+ * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
+ * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not
+ * correct. *dlen is always updated to reflect the amount
+ * of data that has (or would have) been written.
+ *
+ * \note Call this function with *dlen = 0 to obtain the
+ * required buffer size in *dlen
+ */
+int base64_decode( unsigned char *dst, int *dlen,
+ const unsigned char *src, int slen );
+
+#endif /* base64.h */
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index c13dffb4..82c1d591 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -51,8 +51,8 @@
#define LAZY_LOAD(info, errret) \
do { \
ALPM_LOG_FUNC; \
- ASSERT(handle != NULL, return(errret)); \
- ASSERT(pkg != NULL, return(errret)); \
+ ASSERT(handle != NULL, return (errret)); \
+ ASSERT(pkg != NULL, return (errret)); \
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
_alpm_local_db_read(pkg->origin_data.db, pkg, info); \
} \
@@ -73,13 +73,13 @@ static const char *_cache_get_filename(pmpkg_t *pkg)
static const char *_cache_get_name(pmpkg_t *pkg)
{
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
return pkg->name;
}
static const char *_cache_get_version(pmpkg_t *pkg)
{
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
return pkg->version;
}
@@ -160,8 +160,8 @@ static int _cache_has_scriptlet(pmpkg_t *pkg)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(pkg != NULL, return(-1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(pkg != NULL, return -1);
if(!(pkg->infolevel & INFRQ_SCRIPTLET)) {
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
@@ -210,8 +210,8 @@ static alpm_list_t *_cache_get_files(pmpkg_t *pkg)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(pkg != NULL, return NULL);
if(pkg->origin == PKG_FROM_LOCALDB
&& !(pkg->infolevel & INFRQ_FILES)) {
@@ -225,8 +225,8 @@ static alpm_list_t *_cache_get_backup(pmpkg_t *pkg)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(pkg != NULL, return NULL);
if(pkg->origin == PKG_FROM_LOCALDB
&& !(pkg->infolevel & INFRQ_FILES)) {
@@ -246,8 +246,8 @@ static void *_cache_changelog_open(pmpkg_t *pkg)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(pkg != NULL, return NULL);
char clfile[PATH_MAX];
snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
@@ -270,13 +270,13 @@ static void *_cache_changelog_open(pmpkg_t *pkg)
static size_t _cache_changelog_read(void *ptr, size_t size,
const pmpkg_t *pkg, const void *fp)
{
- return ( fread(ptr, 1, size, (FILE*)fp) );
+ return fread(ptr, 1, size, (FILE *)fp);
}
/*
static int _cache_changelog_feof(const pmpkg_t *pkg, void *fp)
{
- return( feof((FILE*)fp) );
+ return feof((FILE*)fp);
}
*/
@@ -289,7 +289,7 @@ static int _cache_changelog_feof(const pmpkg_t *pkg, void *fp)
*/
static int _cache_changelog_close(const pmpkg_t *pkg, void *fp)
{
- return( fclose((FILE*)fp) );
+ return fclose((FILE *)fp);
}
@@ -345,14 +345,14 @@ static int checkdbdir(pmdb_t *db)
RET_ERR(PM_ERR_SYSTEM, -1);
}
}
- return(0);
+ return 0;
}
static int is_dir(const char *path, struct dirent *entry)
{
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
if(entry->d_type != DT_UNKNOWN) {
- return(entry->d_type == DT_DIR);
+ return (entry->d_type == DT_DIR);
}
#endif
{
@@ -362,11 +362,11 @@ static int is_dir(const char *path, struct dirent *entry)
snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name);
if (!stat(buffer, &sbuf)) {
- return(S_ISDIR(sbuf.st_mode));
+ return S_ISDIR(sbuf.st_mode);
}
}
- return(0);
+ return 0;
}
static int local_db_populate(pmdb_t *db)
@@ -390,7 +390,7 @@ static int local_db_populate(pmdb_t *db)
if(dbdir == NULL) {
if(errno == ENOENT) {
/* no database existing yet is not an error */
- return(0);
+ return 0;
}
RET_ERR(PM_ERR_DB_OPEN, -1);
}
@@ -476,7 +476,7 @@ static int local_db_populate(pmdb_t *db)
if(count > 0) {
db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
}
- return(count);
+ return count;
}
/* Note: the return value must be freed by the caller */
@@ -490,7 +490,7 @@ static char *get_pkgpath(pmdb_t *db, pmpkg_t *info)
len = strlen(dbpath) + strlen(info->name) + strlen(info->version) + 3;
MALLOC(pkgpath, len, RET_ERR(PM_ERR_MEMORY, NULL));
sprintf(pkgpath, "%s%s-%s/", dbpath, info->name, info->version);
- return(pkgpath);
+ return pkgpath;
}
@@ -509,14 +509,14 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(info == NULL || info->name == NULL || info->version == NULL) {
_alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_local_db_read, skipping\n");
- return(-1);
+ return -1;
}
if(info->origin != PKG_FROM_LOCALDB) {
_alpm_log(PM_LOG_DEBUG,
"request to read info for a non-local package '%s', skipping...\n",
info->name);
- return(-1);
+ return -1;
}
/* bitmask logic here:
@@ -526,7 +526,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
* == to inforeq? nope, we need to load more info. */
if((info->infolevel & inforeq) == inforeq) {
/* already loaded all of this info, do nothing */
- return(0);
+ return 0;
}
_alpm_log(PM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
info->name, inforeq);
@@ -706,14 +706,14 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
info->infolevel |= inforeq;
free(pkgpath);
- return(0);
+ return 0;
error:
free(pkgpath);
if(fp) {
fclose(fp);
}
- return(-1);
+ return -1;
}
int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info)
@@ -723,7 +723,7 @@ int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info)
char *pkgpath = NULL;
if(checkdbdir(db) != 0) {
- return(-1);
+ return -1;
}
oldmask = umask(0000);
@@ -737,7 +737,7 @@ int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info)
free(pkgpath);
umask(oldmask);
- return(retval);
+ return retval;
}
int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
@@ -752,7 +752,7 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
ALPM_LOG_FUNC;
if(db == NULL || info == NULL) {
- return(-1);
+ return -1;
}
pkgpath = get_pkgpath(db, info);
@@ -761,7 +761,7 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
oldmask = umask(0022);
if(strcmp(db->treename, "local") != 0) {
- return(-1);
+ return -1;
}
/* DESC */
@@ -904,7 +904,7 @@ cleanup:
fclose(fp);
}
- return(retval);
+ return retval;
}
int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
@@ -925,7 +925,7 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
if(ret != 0) {
ret = -1;
}
- return(ret);
+ return ret;
}
static int local_db_version(pmdb_t *db)
@@ -977,7 +977,7 @@ done:
}
_alpm_log(PM_LOG_DEBUG, "local database version %d\n", version);
- return(version);
+ return version;
}
struct db_operations local_db_ops = {
@@ -1001,7 +1001,7 @@ pmdb_t *_alpm_db_register_local(void)
db->ops = &local_db_ops;
handle->db_local = db;
- return(db);
+ return db;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index f4837890..e86bffe6 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -47,7 +47,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
struct archive *archive = NULL;
struct archive_entry *entry;
@@ -69,14 +69,14 @@ static void *_package_changelog_open(pmpkg_t *pkg)
const char *entry_name = archive_entry_pathname(entry);
if(strcmp(entry_name, ".CHANGELOG") == 0) {
- return(archive);
+ return archive;
}
}
/* we didn't find a changelog */
archive_read_finish(archive);
errno = ENOENT;
- return(NULL);
+ return NULL;
}
/**
@@ -95,9 +95,9 @@ static size_t _package_changelog_read(void *ptr, size_t size,
/* Report error (negative values) */
if(sret < 0) {
pm_errno = PM_ERR_LIBARCHIVE;
- return(0);
+ return 0;
} else {
- return((size_t)sret);
+ return (size_t)sret;
}
}
@@ -105,7 +105,7 @@ static size_t _package_changelog_read(void *ptr, size_t size,
static int _package_changelog_feof(const pmpkg_t *pkg, void *fp)
{
// note: this doesn't quite work, no feof in libarchive
- return( archive_read_data((struct archive*)fp, NULL, 0) );
+ return archive_read_data((struct archive*)fp, NULL, 0);
}
*/
@@ -118,7 +118,7 @@ static int _package_changelog_feof(const pmpkg_t *pkg, void *fp)
*/
static int _package_changelog_close(const pmpkg_t *pkg, void *fp)
{
- return( archive_read_finish((struct archive *)fp) );
+ return archive_read_finish((struct archive *)fp);
}
/** Package file operations struct accessor. We implement this as a method
@@ -137,7 +137,7 @@ static struct pkg_operations *get_file_pkg_ops(void)
file_pkg_ops.changelog_close = _package_changelog_close;
file_pkg_ops_initialized = 1;
}
- return(&file_pkg_ops);
+ return &file_pkg_ops;
}
/**
@@ -226,7 +226,7 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
line[0] = '\0';
}
- return(0);
+ return 0;
}
/**
@@ -251,11 +251,31 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
RET_ERR(PM_ERR_WRONG_ARGS, NULL);
}
- if(stat(pkgfile, &st) != 0) {
+ /* attempt to stat the package file, ensure it exists */
+ if(stat(pkgfile, &st) == 0) {
+ char *pgpfile;
+ int ret;
+
+ newpkg = _alpm_pkg_new();
+ if(newpkg == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
+ newpkg->filename = strdup(pkgfile);
+ newpkg->size = st.st_size;
+
+ /* look around for a PGP signature file; load if available */
+ MALLOC(pgpfile, strlen(pkgfile) + 5, RET_ERR(PM_ERR_MEMORY, NULL));
+ sprintf(pgpfile, "%s.sig", pkgfile);
+ /* TODO: do something with ret value */
+ ret = _alpm_load_signature(pgpfile, &(newpkg->pgpsig));
+ FREE(pgpfile);
+ } else {
+ /* couldn't stat the pkgfile, return an error */
RET_ERR(PM_ERR_PKG_OPEN, NULL);
}
if((archive = archive_read_new()) == NULL) {
+ alpm_pkg_free(newpkg);
RET_ERR(PM_ERR_LIBARCHIVE, NULL);
}
@@ -264,6 +284,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
if (archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+ alpm_pkg_free(newpkg);
RET_ERR(PM_ERR_PKG_OPEN, NULL);
}
@@ -356,7 +377,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
newpkg->infolevel = INFRQ_BASE | INFRQ_DESC;
}
- return(newpkg);
+ return newpkg;
pkg_invalid:
pm_errno = PM_ERR_PKG_INVALID;
@@ -364,7 +385,7 @@ error:
_alpm_pkg_free(newpkg);
archive_read_finish(archive);
- return(NULL);
+ return NULL;
}
/** Create a package from a file.
@@ -389,10 +410,10 @@ int SYMEXPORT alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg)
*pkg = pkg_load(filename, full);
if(*pkg == NULL) {
/* pm_errno is set by pkg_load */
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 98516fd8..756f784f 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -126,24 +126,63 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
}
ret = _alpm_download_single_file(dbfile, db->servers, syncpath, force);
- free(dbfile);
- free(syncpath);
- umask(oldmask);
if(ret == 1) {
/* files match, do nothing */
pm_errno = 0;
- return(1);
+ goto cleanup;
} else if(ret == -1) {
/* pm_errno was set by the download code */
_alpm_log(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerrorlast());
- return(-1);
+ goto cleanup;
+ }
+
+ /* Download and check the signature of the database if needed */
+ if(db->pgp_verify != PM_PGP_VERIFY_NEVER) {
+ char *sigfile, *sigfilepath;
+ int sigret;
+
+ len = strlen(dbfile) + 5;
+ MALLOC(sigfile, len, RET_ERR(PM_ERR_MEMORY, -1));
+ sprintf(sigfile, "%s.sig", dbfile);
+
+ /* prevent old signature being used if the following download fails */
+ len = strlen(syncpath) + strlen(sigfile) + 1;
+ MALLOC(sigfilepath, len, RET_ERR(PM_ERR_MEMORY, -1));
+ sprintf(sigfilepath, "%s%s", syncpath, sigfile);
+ _alpm_rmrf(sigfilepath);
+ free(sigfilepath);
+
+ sigret = _alpm_download_single_file(sigfile, db->servers, syncpath, 0);
+ free(sigfile);
+
+ if(sigret == -1 && db->pgp_verify == PM_PGP_VERIFY_ALWAYS) {
+ _alpm_log(PM_LOG_ERROR, _("Failed to download signature for db: %s\n"),
+ alpm_strerrorlast());
+ pm_errno = PM_ERR_SIG_INVALID;
+ ret = -1;
+ goto cleanup;
+ }
+
+ sigret = alpm_db_check_pgp_signature(db);
+ if((db->pgp_verify == PM_PGP_VERIFY_ALWAYS && sigret != 0) ||
+ (db->pgp_verify == PM_PGP_VERIFY_OPTIONAL && sigret == 1)) {
+ /* pm_errno was set by the checking code */
+ /* TODO: should we just leave the unverified database */
+ ret = -1;
+ goto cleanup;
+ }
}
/* Cache needs to be rebuilt */
_alpm_db_free_pkgcache(db);
- return(0);
+cleanup:
+
+ free(dbfile);
+ free(syncpath);
+ umask(oldmask);
+ return ret;
}
/* Forward decl so I don't reorganize the whole file right now */
@@ -204,7 +243,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive)
/* assume it is at least somewhat compressed */
per_package = 200;
}
- return((size_t)(st->st_size / per_package) + 1);
+ return (size_t)((st->st_size / per_package) + 1);
}
static int sync_db_populate(pmdb_t *db)
@@ -294,7 +333,7 @@ static int sync_db_populate(pmdb_t *db)
}
archive_read_finish(archive);
- return(count);
+ return count;
}
#define READ_NEXT(s) do { \
@@ -334,7 +373,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
}
if(entryname == NULL) {
_alpm_log(PM_LOG_DEBUG, "invalid archive entry provided to _alpm_sync_db_read, skipping\n");
- return(-1);
+ return -1;
}
_alpm_log(PM_LOG_FUNCTION, "loading package data from archive entry %s\n",
@@ -365,7 +404,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
if(pkg == NULL) {
_alpm_log(PM_LOG_DEBUG, "package %s not found in %s sync database",
pkgname, db->treename);
- return(-1);
+ return -1;
}
if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0
@@ -418,6 +457,11 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
pkg->isize = atol(line);
} else if(strcmp(line, "%MD5SUM%") == 0) {
READ_AND_STORE(pkg->md5sum);
+ } else if(strcmp(line, "%SHA256SUM%") == 0) {
+ /* we don't do anything with this value right now */
+ READ_NEXT(line);
+ } else if(strcmp(line, "%PGPSIG%") == 0) {
+ READ_AND_STORE(pkg->pgpsig.encdata);
} else if(strcmp(line, "%REPLACES%") == 0) {
READ_AND_STORE_ALL(pkg->replaces);
} else if(strcmp(line, "%DEPENDS%") == 0) {
@@ -452,12 +496,12 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
error:
FREE(pkgname);
/* TODO: return 0 always? */
- return(0);
+ return 0;
}
static int sync_db_version(pmdb_t *db)
{
- return(2);
+ return 2;
}
struct db_operations sync_db_ops = {
@@ -490,7 +534,7 @@ pmdb_t *_alpm_db_register_sync(const char *treename)
db->ops = &sync_db_ops;
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
- return(db);
+ return db;
}
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 6faced16..b4ecd659 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -53,7 +53,7 @@ pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2,
STRDUP(conflict->package2, package2, RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(conflict->reason, reason, RET_ERR(PM_ERR_MEMORY, NULL));
- return(conflict);
+ return conflict;
}
void _alpm_conflict_free(pmconflict_t *conflict)
@@ -73,7 +73,7 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
STRDUP(newconflict->package2, conflict->package2, RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(newconflict->reason, conflict->reason, RET_ERR(PM_ERR_MEMORY, NULL));
- return(newconflict);
+ return newconflict;
}
static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
@@ -90,11 +90,11 @@ static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
const char *cpkg2 = conflict->package2;
if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0)
|| (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/** Adds the pkg1/pkg2 conflict to the baddeps list
@@ -173,7 +173,7 @@ alpm_list_t *_alpm_innerconflicts(alpm_list_t *packages)
_alpm_log(PM_LOG_DEBUG, "check targets vs targets\n");
check_conflict(packages, packages, &baddeps, 0);
- return(baddeps);
+ return baddeps;
}
/* Check for target vs (db - target) conflicts
@@ -187,7 +187,7 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(NULL);
+ return NULL;
}
alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db),
@@ -200,7 +200,7 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
check_conflict(dblist, packages, &baddeps, -1);
alpm_list_free(dblist);
- return(baddeps);
+ return baddeps;
}
/** Check the package conflicts in a database
@@ -209,7 +209,7 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
* @return an alpm_list_t of pmconflict_t
*/
alpm_list_t SYMEXPORT *alpm_checkconflicts(alpm_list_t *pkglist) {
- return(_alpm_innerconflicts(pkglist));
+ return _alpm_innerconflicts(pkglist);
}
/* Returns a alpm_list_t* of file conflicts.
@@ -246,7 +246,7 @@ static alpm_list_t *chk_fileconflicts(alpm_list_t *filesA, alpm_list_t *filesB)
}
}
- return(ret);
+ return ret;
}
/* Returns a alpm_list_t* of files that are in filesA but *NOT* in filesB
@@ -293,7 +293,7 @@ static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
pA = pA->next;
}
- return(ret);
+ return ret;
}
/* Adds pmfileconflict_t to a conflicts list. Pass the conflicts list, type (either
@@ -321,7 +321,7 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
_alpm_log(PM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
filestr, name1, name2 ? name2 : "(filesystem)");
- return(conflicts);
+ return conflicts;
}
void _alpm_fileconflict_free(pmfileconflict_t *conflict)
@@ -345,7 +345,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
snprintf(abspath, PATH_MAX, "%s%s", handle->root, dirpath);
dir = opendir(abspath);
if(dir == NULL) {
- return(1);
+ return 1;
}
while((ent = readdir(dir)) != NULL) {
const char *name = ent->d_name;
@@ -363,19 +363,19 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
continue;
} else {
closedir(dir);
- return(0);
+ return 0;
}
} else {
if(alpm_list_find_str(alpm_pkg_get_files(pkg), path)) {
continue;
} else {
closedir(dir);
- return(0);
+ return 0;
}
}
}
closedir(dir);
- return(1);
+ return 1;
}
/* Find file conflicts that may occur during the transaction with two checks:
@@ -391,7 +391,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
ALPM_LOG_FUNC;
if(db == NULL || upgrade == NULL || trans == NULL) {
- return(NULL);
+ return NULL;
}
/* TODO this whole function needs a huge change, which hopefully will
@@ -540,7 +540,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
numtargs, current);
- return(conflicts);
+ return conflicts;
}
const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict)
@@ -548,8 +548,8 @@ const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->package1;
}
@@ -559,8 +559,8 @@ const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->package2;
}
@@ -570,8 +570,8 @@ const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->reason;
}
@@ -581,8 +581,8 @@ const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->target;
}
@@ -592,8 +592,8 @@ pmfileconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conf
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(conflict != NULL, return(-1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(conflict != NULL, return -1);
return conflict->type;
}
@@ -603,8 +603,8 @@ const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->file;
}
@@ -614,8 +614,8 @@ const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(conflict != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(conflict != NULL, return NULL);
return conflict->ctarget;
}
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index bf6df06e..b2144354 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -61,7 +61,7 @@ pmdb_t SYMEXPORT *alpm_db_register_sync(const char *treename)
/* Do not register a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
- return(_alpm_db_register_sync(treename));
+ return _alpm_db_register_sync(treename);
}
/* Helper function for alpm_db_unregister{_all} */
@@ -100,7 +100,7 @@ int SYMEXPORT alpm_db_unregister_all(void)
i->data = NULL;
}
FREELIST(handle->dbs_sync);
- return(0);
+ return 0;
}
/** Unregister a package database
@@ -140,7 +140,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
}
db->ops->unregister(db);
- return(0);
+ return 0;
}
/** Set the serverlist of a database.
@@ -150,8 +150,6 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
*/
int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
{
- alpm_list_t *i;
- int found = 0;
char *newurl;
size_t len = 0;
@@ -160,16 +158,6 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
/* Sanity checks */
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- for(i = handle->dbs_sync; i && !found; i = i->next) {
- pmdb_t *sdb = i->data;
- if(strcmp(db->treename, sdb->treename) == 0) {
- found = 1;
- }
- }
- if(!found) {
- RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
- }
-
if(url) {
len = strlen(url);
}
@@ -187,6 +175,24 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
_alpm_log(PM_LOG_DEBUG, "serverlist flushed for '%s'\n", db->treename);
}
+ return 0;
+}
+/** Set the verify gpg signature option for a database.
+ * @param db database pointer
+ * @param verify enum pgp_verify_t
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+
+ db->pgp_verify = verify;
+ _alpm_log(PM_LOG_DEBUG, "adding VerifySig option to database '%s': %d\n",
+ db->treename, verify);
+
return(0);
}
@@ -199,8 +205,8 @@ const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
return db->treename;
}
@@ -216,13 +222,13 @@ const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
- ASSERT(db->servers != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
+ ASSERT(db->servers != NULL, return NULL);
url = (char*)db->servers->data;
- return(url);
+ return url;
}
@@ -236,11 +242,11 @@ pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
- ASSERT(name != NULL && strlen(name) != 0, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
+ ASSERT(name != NULL && strlen(name) != 0, return NULL);
- return(_alpm_db_get_pkgfromcache(db, name));
+ return _alpm_db_get_pkgfromcache(db, name);
}
/** Get the package cache of a package database
@@ -252,10 +258,10 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(pmdb_t *db)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
- return(_alpm_db_get_pkgcache(db));
+ return _alpm_db_get_pkgcache(db);
}
/** Get a group entry from a package database
@@ -268,11 +274,11 @@ pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
- ASSERT(name != NULL && strlen(name) != 0, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
+ ASSERT(name != NULL && strlen(name) != 0, return NULL);
- return(_alpm_db_get_grpfromcache(db, name));
+ return _alpm_db_get_grpfromcache(db, name);
}
/** Get the group cache of a package database
@@ -284,10 +290,10 @@ alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
- return(_alpm_db_get_grpcache(db));
+ return _alpm_db_get_grpcache(db);
}
/** Searches a database
@@ -300,10 +306,10 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(db != NULL, return NULL);
- return(_alpm_db_search(db, needles));
+ return _alpm_db_search(db, needles);
}
/** Set install reason for a package in db
@@ -328,16 +334,16 @@ int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t
_alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
if(alpm_pkg_get_reason(pkg) == reason) {
/* we are done */
- return(0);
+ return 0;
}
/* set reason (in pkgcache) */
pkg->reason = reason;
/* write DESC */
if(_alpm_local_db_write(db, pkg, INFRQ_DESC)) {
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/** @} */
@@ -352,7 +358,34 @@ pmdb_t *_alpm_db_new(const char *treename, int is_local)
STRDUP(db->treename, treename, RET_ERR(PM_ERR_MEMORY, NULL));
db->is_local = is_local;
- return(db);
+ return db;
+}
+
+const pmpgpsig_t *_alpm_db_pgpsig(pmdb_t *db)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(db != NULL, return(NULL));
+
+ if(db->pgpsig.rawdata == NULL) {
+ size_t len;
+ const char *dbfile;
+ char *sigfile;
+ int ret;
+
+ dbfile = _alpm_db_path(db);
+ len = strlen(dbfile) + 5;
+ MALLOC(sigfile, len, RET_ERR(PM_ERR_MEMORY, NULL));
+ sprintf(sigfile, "%s.sig", dbfile);
+
+ /* TODO: do something with ret value */
+ ret = _alpm_load_signature(sigfile, &(db->pgpsig));
+
+ FREE(sigfile);
+ }
+
+ return &(db->pgpsig);
}
void _alpm_db_free(pmdb_t *db)
@@ -363,6 +396,8 @@ void _alpm_db_free(pmdb_t *db)
_alpm_db_free_pkgcache(db);
/* cleanup server list */
FREELIST(db->servers);
+ /* only need to free rawdata */
+ FREE(db->pgpsig.rawdata);
FREE(db->_path);
FREE(db->treename);
FREE(db);
@@ -373,7 +408,7 @@ void _alpm_db_free(pmdb_t *db)
const char *_alpm_db_path(pmdb_t *db)
{
if(!db) {
- return(NULL);
+ return NULL;
}
if(!db->_path) {
const char *dbpath;
@@ -398,22 +433,22 @@ const char *_alpm_db_path(pmdb_t *db)
_alpm_log(PM_LOG_DEBUG, "database path for tree %s set to %s\n",
db->treename, db->_path);
}
- return(db->_path);
+ return db->_path;
}
int _alpm_db_version(pmdb_t *db)
{
if(!db) {
- return(-1);
+ return -1;
}
- return(db->ops->version(db));
+ return db->ops->version(db);
}
int _alpm_db_cmp(const void *d1, const void *d2)
{
pmdb_t *db1 = (pmdb_t *)d1;
pmdb_t *db2 = (pmdb_t *)d2;
- return(strcmp(db1->treename, db2->treename));
+ return strcmp(db1->treename, db2->treename);
}
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
@@ -489,7 +524,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
regfree(&reg);
}
- return(ret);
+ return ret;
}
/* Returns a new package cache from db.
@@ -500,7 +535,7 @@ int _alpm_db_load_pkgcache(pmdb_t *db)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(-1);
+ return -1;
}
_alpm_db_free_pkgcache(db);
@@ -509,11 +544,11 @@ int _alpm_db_load_pkgcache(pmdb_t *db)
if(db->ops->populate(db) == -1) {
_alpm_log(PM_LOG_DEBUG,
"failed to load package cache for repository '%s'\n", db->treename);
- return(-1);
+ return -1;
}
db->pkgcache_loaded = 1;
- return(0);
+ return 0;
}
void _alpm_db_free_pkgcache(pmdb_t *db)
@@ -540,7 +575,7 @@ pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(NULL);
+ return NULL;
}
if(!db->pkgcache_loaded) {
@@ -552,7 +587,7 @@ pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
_alpm_log(PM_LOG_DEBUG, "warning: pkgcache is NULL for db '%s'\n", db->treename);
}
- return(db->pkgcache);
+ return db->pkgcache;
}
alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
@@ -562,10 +597,10 @@ alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
pmpkghash_t *hash = _alpm_db_get_pkgcache_hash(db);
if(hash == NULL) {
- return(NULL);
+ return NULL;
}
- return(hash->list);
+ return hash->list;
}
/* "duplicate" pkg then add it to pkgcache */
@@ -576,12 +611,12 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
ALPM_LOG_FUNC;
if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
- return(-1);
+ return -1;
}
newpkg = _alpm_pkg_dup(pkg);
if(newpkg == NULL) {
- return(-1);
+ return -1;
}
_alpm_log(PM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n",
@@ -590,7 +625,7 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
_alpm_db_free_grpcache(db);
- return(0);
+ return 0;
}
int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
@@ -600,7 +635,7 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
ALPM_LOG_FUNC;
if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
- return(-1);
+ return -1;
}
_alpm_log(PM_LOG_DEBUG, "removing entry '%s' from '%s' cache\n",
@@ -611,14 +646,14 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
/* package not found */
_alpm_log(PM_LOG_DEBUG, "cannot remove entry '%s' from '%s' cache: not found\n",
alpm_pkg_get_name(pkg), db->treename);
- return(-1);
+ return -1;
}
_alpm_pkg_free(data);
_alpm_db_free_grpcache(db);
- return(0);
+ return 0;
}
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
@@ -626,17 +661,17 @@ pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(NULL);
+ return NULL;
}
pmpkghash_t *pkgcache = _alpm_db_get_pkgcache_hash(db);
if(!pkgcache) {
_alpm_log(PM_LOG_DEBUG, "warning: failed to get '%s' from NULL pkgcache\n",
target);
- return(NULL);
+ return NULL;
}
- return(_alpm_pkghash_find(pkgcache, target));
+ return _alpm_pkghash_find(pkgcache, target);
}
/* Returns a new group cache from db.
@@ -648,7 +683,7 @@ int _alpm_db_load_grpcache(pmdb_t *db)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(-1);
+ return -1;
}
_alpm_log(PM_LOG_DEBUG, "loading group cache for repository '%s'\n",
@@ -686,7 +721,7 @@ int _alpm_db_load_grpcache(pmdb_t *db)
}
db->grpcache_loaded = 1;
- return(0);
+ return 0;
}
void _alpm_db_free_grpcache(pmdb_t *db)
@@ -715,14 +750,14 @@ alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db)
ALPM_LOG_FUNC;
if(db == NULL) {
- return(NULL);
+ return NULL;
}
if(!db->grpcache_loaded) {
_alpm_db_load_grpcache(db);
}
- return(db->grpcache);
+ return db->grpcache;
}
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
@@ -732,18 +767,18 @@ pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
ALPM_LOG_FUNC;
if(db == NULL || target == NULL || strlen(target) == 0) {
- return(NULL);
+ return NULL;
}
for(i = _alpm_db_get_grpcache(db); i; i = i->next) {
pmgrp_t *info = i->data;
if(strcmp(info->name, target) == 0) {
- return(info);
+ return info;
}
}
- return(NULL);
+ return NULL;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 75776d71..204a0be0 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -31,6 +31,9 @@
#include <archive.h>
#include <archive_entry.h>
+#include "alpm.h"
+#include "signing.h"
+
/* Database entries */
typedef enum _pmdbinfrq_t {
INFRQ_BASE = 1,
@@ -60,6 +63,9 @@ struct __pmdb_t {
pmpkghash_t *pkgcache;
alpm_list_t *grpcache;
alpm_list_t *servers;
+ /* do not access directly, use _alpm_db_pgpsig(db) for lazy access */
+ pmpgpsig_t pgpsig;
+ pgp_verify_t pgp_verify;
struct db_operations *ops;
};
@@ -75,6 +81,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
pmdb_t *_alpm_db_register_local(void);
pmdb_t *_alpm_db_register_sync(const char *treename);
void _alpm_db_unregister(pmdb_t *db);
+const pmpgpsig_t *_alpm_db_pgpsig(pmdb_t *db);
/* be_*.c, backend specific calls */
int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index 10c982f2..d3213fd1 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -41,32 +41,32 @@
const char SYMEXPORT *alpm_delta_get_from(pmdelta_t *delta)
{
- ASSERT(delta != NULL, return(NULL));
- return(delta->from);
+ ASSERT(delta != NULL, return NULL);
+ return delta->from;
}
const char SYMEXPORT *alpm_delta_get_to(pmdelta_t *delta)
{
- ASSERT(delta != NULL, return(NULL));
- return(delta->to);
+ ASSERT(delta != NULL, return NULL);
+ return delta->to;
}
const char SYMEXPORT *alpm_delta_get_filename(pmdelta_t *delta)
{
- ASSERT(delta != NULL, return(NULL));
- return(delta->delta);
+ ASSERT(delta != NULL, return NULL);
+ return delta->delta;
}
const char SYMEXPORT *alpm_delta_get_md5sum(pmdelta_t *delta)
{
- ASSERT(delta != NULL, return(NULL));
- return(delta->delta_md5);
+ ASSERT(delta != NULL, return NULL);
+ return delta->delta_md5;
}
off_t SYMEXPORT alpm_delta_get_size(pmdelta_t *delta)
{
- ASSERT(delta != NULL, return(-1));
- return(delta->delta_size);
+ ASSERT(delta != NULL, return -1);
+ return delta->delta_size;
}
/** @} */
@@ -108,7 +108,7 @@ static alpm_list_t *graph_init(alpm_list_t *deltas, int reverse)
}
v_i->childptr = v_i->children;
}
- return(vertices);
+ return vertices;
}
static void graph_init_size(alpm_list_t *vertices)
@@ -205,7 +205,7 @@ static off_t shortest_path(alpm_list_t *vertices, const char *to, alpm_list_t **
*path = alpm_list_reverse(rpath);
alpm_list_free(rpath);
- return(bestsize);
+ return bestsize;
}
/** Calculates the shortest path from one version to another.
@@ -229,7 +229,7 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
if(deltas == NULL) {
*path = NULL;
- return(bestsize);
+ return bestsize;
}
_alpm_log(PM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);
@@ -245,7 +245,7 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
alpm_list_free(vertices);
*path = bestpath;
- return(bestsize);
+ return bestsize;
}
static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota)
@@ -273,7 +273,7 @@ static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota
}
alpm_list_free_inner(vertices, _alpm_graph_free);
alpm_list_free(vertices);
- return(unused);
+ return unused;
}
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(pmpkg_t *pkg)
@@ -283,7 +283,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(pmpkg_t *pkg)
alpm_pkg_get_deltas(pkg),
alpm_pkg_get_filename(pkg),
pkgsize * MAX_DELTA_RATIO);
- return(unused);
+ return unused;
}
@@ -308,7 +308,7 @@ pmdelta_t *_alpm_delta_parse(char *line)
if(regexec(&reg, line, 0, 0, 0) != 0) {
/* delta line is invalid, return NULL */
regfree(&reg);
- return(NULL);
+ return NULL;
}
regfree(&reg);
@@ -339,7 +339,7 @@ pmdelta_t *_alpm_delta_parse(char *line)
_alpm_log(PM_LOG_DEBUG, "delta : %s %s '%jd'\n", delta->from, delta->to, (intmax_t)delta->delta_size);
- return(delta);
+ return delta;
}
void _alpm_delta_free(pmdelta_t *delta)
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index dc85b318..ee95c897 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -56,7 +56,7 @@ static pmdepmissing_t *depmiss_new(const char *target, pmdepend_t *dep,
miss->depend = _alpm_dep_dup(dep);
STRDUP(miss->causingpkg, causingpkg, RET_ERR(PM_ERR_MEMORY, NULL));
- return(miss);
+ return miss;
}
void _alpm_depmiss_free(pmdepmissing_t *miss)
@@ -73,10 +73,10 @@ static int _alpm_dep_edge(pmpkg_t *pkg1, pmpkg_t *pkg2)
alpm_list_t *i;
for(i = alpm_pkg_get_depends(pkg1); i; i = i->next) {
if(_alpm_depcmp(pkg2, i->data)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/* Convert a list of pmpkg_t * to a graph structure,
@@ -110,7 +110,7 @@ static alpm_list_t *dep_graph_init(alpm_list_t *targets)
}
vertex_i->childptr = vertex_i->children;
}
- return(vertices);
+ return vertices;
}
/* Re-order a list of target packages with respect to their dependencies.
@@ -137,7 +137,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
ALPM_LOG_FUNC;
if(targets == NULL) {
- return(NULL);
+ return NULL;
}
_alpm_log(PM_LOG_DEBUG, "started sorting dependencies\n");
@@ -201,7 +201,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
alpm_list_free_inner(vertices, _alpm_graph_free);
alpm_list_free(vertices);
- return(newtargs);
+ return newtargs;
}
static int no_dep_version(void)
@@ -214,7 +214,7 @@ static pmdepend_t *filtered_depend(pmdepend_t *dep, int nodepversion)
{
if(nodepversion) {
pmdepend_t *newdep = _alpm_dep_dup(dep);
- ASSERT(newdep, return(dep));
+ ASSERT(newdep, return dep);
newdep->mod = PM_DEP_MOD_ANY;
dep = newdep;
}
@@ -235,10 +235,10 @@ static pmpkg_t *find_dep_satisfier(alpm_list_t *pkgs, pmdepend_t *dep)
for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = i->data;
if(_alpm_depcmp(pkg, dep)) {
- return(pkg);
+ return pkg;
}
}
- return(NULL);
+ return NULL;
}
/** Find a package satisfying a specified dependency.
@@ -252,7 +252,7 @@ pmpkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
pmdepend_t *dep = _alpm_splitdep(depstring);
pmpkg_t *pkg = find_dep_satisfier(pkgs, dep);
_alpm_dep_free(dep);
- return(pkg);
+ return pkg;
}
/** Checks dependencies and returns missing ones in a list.
@@ -343,7 +343,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
alpm_list_free(modified);
alpm_list_free(dblist);
- return(baddeps);
+ return baddeps;
}
static int dep_vercmp(const char *version1, pmdepmod_t mod,
@@ -364,7 +364,7 @@ static int dep_vercmp(const char *version1, pmdepmod_t mod,
default: equal = 1; break;
}
}
- return(equal);
+ return equal;
}
int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
@@ -380,7 +380,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
satisfy = (strcmp(pkg->name, dep->name) == 0
&& dep_vercmp(pkg->version, dep->mod, dep->version));
if(satisfy) {
- return(satisfy);
+ return satisfy;
}
}
@@ -406,7 +406,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
}
}
- return(satisfy);
+ return satisfy;
}
pmdepend_t *_alpm_splitdep(const char *depstring)
@@ -415,7 +415,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
const char *ptr, *version = NULL;
if(depstring == NULL) {
- return(NULL);
+ return NULL;
}
CALLOC(depend, 1, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
@@ -451,7 +451,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
STRDUP(depend->version, version, RET_ERR(PM_ERR_MEMORY, NULL));
}
- return(depend);
+ return depend;
}
pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
@@ -464,7 +464,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
STRDUP(newdep->version, dep->version, RET_ERR(PM_ERR_MEMORY, NULL));
newdep->mod = dep->mod;
- return(newdep);
+ return newdep;
}
/* These parameters are messy. We check if this package, given a list of
@@ -477,7 +477,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
alpm_list_t *i;
if(_alpm_pkg_find(targets, alpm_pkg_get_name(pkg))) {
- return(0);
+ return 0;
}
if(!include_explicit) {
@@ -485,7 +485,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) {
_alpm_log(PM_LOG_DEBUG, "excluding %s -- explicitly installed\n",
alpm_pkg_get_name(pkg));
- return(0);
+ return 0;
}
}
@@ -499,12 +499,12 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
pmpkg_t *lpkg = i->data;
if(_alpm_dep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) {
- return(0);
+ return 0;
}
}
/* it's ok to remove */
- return(1);
+ return 1;
}
/**
@@ -580,7 +580,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
continue;
}
}
- return(pkg);
+ return pkg;
}
}
/* 2. satisfiers (skip literals here) */
@@ -615,7 +615,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
pmpkg_t *pkg = i->data;
if (_alpm_pkghash_find(_alpm_db_get_pkgcache_hash(handle->db_local), pkg->name)) {
alpm_list_free(providers);
- return(pkg);
+ return pkg;
}
}
count = alpm_list_count(providers);
@@ -630,7 +630,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
if(index >= 0 && index < count) {
pmpkg_t *pkg = alpm_list_getdata(alpm_list_nth(providers, index));
alpm_list_free(providers);
- return(pkg);
+ return pkg;
}
alpm_list_free(providers);
providers = NULL;
@@ -641,7 +641,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
} else {
pm_errno = PM_ERR_PKG_NOT_FOUND;
}
- return(NULL);
+ return NULL;
}
/** Find a package satisfying a specified dependency.
@@ -657,13 +657,13 @@ pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstri
pmdepend_t *dep;
pmpkg_t *pkg;
- ASSERT(dbs, return(NULL));
+ ASSERT(dbs, return NULL);
dep = _alpm_splitdep(depstring);
- ASSERT(dep, return(NULL));
+ ASSERT(dep, return NULL);
pkg = resolvedep(dep, dbs, NULL, 1);
_alpm_dep_free(dep);
- return(pkg);
+ return pkg;
}
/**
@@ -699,7 +699,7 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
ALPM_LOG_FUNC;
if(_alpm_pkg_find(*packages, pkg->name) != NULL) {
- return(0);
+ return 0;
}
/* Create a copy of the packages list, so that it can be restored
@@ -760,7 +760,7 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
alpm_list_free(packages_copy);
}
_alpm_log(PM_LOG_DEBUG, "finished resolving dependencies\n");
- return(ret);
+ return ret;
}
const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
@@ -768,9 +768,9 @@ const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
- return(miss->target);
+ return miss->target;
}
const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss)
@@ -778,7 +778,7 @@ const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
return miss->causingpkg;
}
@@ -788,9 +788,9 @@ pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
- return(miss->depend);
+ return miss->depend;
}
pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
@@ -798,9 +798,9 @@ pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(dep != NULL, return(-1));
+ ASSERT(dep != NULL, return -1);
- return(dep->mod);
+ return dep->mod;
}
const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
@@ -808,9 +808,9 @@ const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
- return(dep->name);
+ return dep->name;
}
const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
@@ -818,9 +818,9 @@ const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
- return(dep->version);
+ return dep->version;
}
/** Reverse of splitdep; make a dep string from a pmdepend_t struct.
@@ -837,7 +837,7 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
if(dep->name) {
name = dep->name;
@@ -882,6 +882,6 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
MALLOC(str, len, RET_ERR(PM_ERR_MEMORY, NULL));
snprintf(str, len, "%s%s%s", name, opr, ver);
- return(str);
+ return str;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index 281173a2..983a3ac2 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -56,7 +56,7 @@ static int mount_point_cmp(const void *p1, const void *p2)
const alpm_mountpoint_t *mp1 = p1;
const alpm_mountpoint_t *mp2 = p2;
/* the negation will sort all mountpoints before their parent */
- return(-strcmp(mp1->mount_dir, mp2->mount_dir));
+ return -strcmp(mp1->mount_dir, mp2->mount_dir);
}
static alpm_list_t *mount_point_list(void)
@@ -72,7 +72,7 @@ static alpm_list_t *mount_point_list(void)
fp = setmntent(MOUNTED, "r");
if (fp == NULL) {
- return(NULL);
+ return NULL;
}
while((mnt = getmntent(fp))) {
@@ -104,7 +104,7 @@ static alpm_list_t *mount_point_list(void)
entries = getmntinfo(&fsp, MNT_NOWAIT);
if (entries < 0) {
- return(NULL);
+ return NULL;
}
for(; entries-- > 0; fsp++) {
@@ -128,7 +128,7 @@ static alpm_list_t *mount_point_list(void)
mp = ptr->data;
_alpm_log(PM_LOG_DEBUG, "mountpoint: %s\n", mp->mount_dir);
}
- return(mount_points);
+ return mount_points;
}
static alpm_mountpoint_t *match_mount_point(const alpm_list_t *mount_points,
@@ -140,12 +140,12 @@ static alpm_mountpoint_t *match_mount_point(const alpm_list_t *mount_points,
alpm_mountpoint_t *data = mp->data;
if(strncmp(data->mount_dir, real_path, data->mount_dir_len) == 0) {
- return(data);
+ return data;
}
}
/* should not get here... */
- return(NULL);
+ return NULL;
}
static int calculate_removed_size(const alpm_list_t *mount_points,
@@ -182,7 +182,7 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
mp->used |= USED_REMOVE;
}
- return(0);
+ return 0;
}
static int calculate_installed_size(const alpm_list_t *mount_points,
@@ -254,7 +254,7 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
archive_read_finish(archive);
cleanup:
- return(ret);
+ return ret;
}
int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
@@ -269,13 +269,13 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
mount_points = mount_point_list();
if(mount_points == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not determine filesystem mount points\n"));
- return(-1);
+ return -1;
}
root_mp = match_mount_point(mount_points, handle->root);
if(root_mp == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not determine root mount point %s\n"),
handle->root);
- return(-1);
+ return -1;
}
replaces = alpm_list_count(trans->remove);
@@ -352,7 +352,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
RET_ERR(PM_ERR_DISK_SPACE, -1);
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 7a98eb12..d9e9488a 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -29,14 +29,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
-/* the following two are needed for FreeBSD's libfetch */
-#include <limits.h> /* PATH_MAX */
-#if defined(HAVE_SYS_PARAM_H)
-#include <sys/param.h> /* MAXHOSTNAMELEN */
-#endif
-#ifdef HAVE_LIBFETCH
-#include <fetch.h>
+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
#endif
/* libalpm */
@@ -47,112 +42,183 @@
#include "util.h"
#include "handle.h"
-static char *get_filename(const char *url) {
+#ifdef HAVE_LIBCURL
+static double prevprogress; /* last download amount */
+#endif
+
+static char *get_filename(const char *url)
+{
char *filename = strrchr(url, '/');
if(filename != NULL) {
filename++;
}
- return(filename);
+ return filename;
}
-#ifdef HAVE_LIBFETCH
-static char *get_destfile(const char *path, const char *filename) {
- char *destfile;
- /* len = localpath len + filename len + null */
- size_t len = strlen(path) + strlen(filename) + 1;
- CALLOC(destfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
- snprintf(destfile, len, "%s%s", path, filename);
+#ifdef HAVE_LIBCURL
+static char *get_fullpath(const char *path, const char *filename,
+ const char *suffix)
+{
+ char *filepath;
+ /* len = localpath len + filename len + suffix len + null */
+ size_t len = strlen(path) + strlen(filename) + strlen(suffix) + 1;
+ CALLOC(filepath, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
+ snprintf(filepath, len, "%s%s%s", path, filename, suffix);
- return(destfile);
+ return filepath;
}
-static char *get_tempfile(const char *path, const char *filename) {
- char *tempfile;
- /* len = localpath len + filename len + '.part' len + null */
- size_t len = strlen(path) + strlen(filename) + 6;
- CALLOC(tempfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
- snprintf(tempfile, len, "%s%s.part", path, filename);
+#define check_stop() if(dload_interrupted) { ret = -1; goto cleanup; }
+enum sighandlers { OLD = 0, NEW = 1 };
- return(tempfile);
+int dload_interrupted;
+static void inthandler(int signum)
+{
+ dload_interrupted = 1;
}
-static const char *gethost(struct url *fileurl)
+static int curl_progress(void *file, double dltotal, double dlnow,
+ double ultotal, double ulnow)
{
- const char *host = _("disk");
- if(strcmp(SCHEME_FILE, fileurl->scheme) != 0) {
- host = fileurl->host;
+ struct fileinfo *dlfile = (struct fileinfo *)file;
+ double current_size, total_size;
+
+ /* unused parameters */
+ (void)ultotal;
+ (void)ulnow;
+
+ /* SIGINT sent, abort by alerting curl */
+ if(dload_interrupted) {
+ return 1;
+ }
+
+ /* none of what follows matters if the front end has no callback */
+ if(handle->dlcb == NULL) {
+ return 0;
}
- return(host);
+
+ current_size = dlfile->initial_size + dlnow;
+ total_size = dlfile->initial_size + dltotal;
+
+ if(DOUBLE_EQ(dltotal, 0) || DOUBLE_EQ(prevprogress, total_size)) {
+ return 0;
+ }
+
+ /* initialize the progress bar here to avoid displaying it when
+ * a repo is up to date and nothing gets downloaded */
+ if(DOUBLE_EQ(prevprogress, 0)) {
+ handle->dlcb(dlfile->filename, 0, (long)dltotal);
+ }
+
+ handle->dlcb(dlfile->filename, (long)current_size, (long)total_size);
+
+ prevprogress = current_size;
+
+ return 0;
}
-int dload_interrupted;
-static void inthandler(int signum)
+static int curl_gethost(const char *url, char *buffer)
{
- dload_interrupted = 1;
+ int hostlen;
+ char *p;
+
+ if(strncmp(url, "file://", 7) == 0) {
+ strcpy(buffer, _("disk"));
+ } else {
+ p = strstr(url, "//");
+ if(!p) {
+ return 1;
+ }
+ p += 2; /* jump over the found // */
+ hostlen = strcspn(p, "/");
+ if(hostlen > 255) {
+ /* buffer overflow imminent */
+ _alpm_log(PM_LOG_ERROR, _("buffer overflow detected"));
+ return 1;
+ }
+ snprintf(buffer, hostlen + 1, "%s", p);
+ }
+
+ return 0;
+}
+
+static int utimes_long(const char *path, long time)
+{
+ if(time != -1) {
+ struct timeval tv[2];
+ memset(&tv, 0, sizeof(tv));
+ tv[0].tv_sec = tv[1].tv_sec = time;
+ return utimes(path, tv);
+ }
+ return 0;
}
-#define check_stop() if(dload_interrupted) { ret = -1; goto cleanup; }
-enum sighandlers { OLD = 0, NEW = 1 };
-static int download_internal(const char *url, const char *localpath,
- int force) {
+static int curl_download_internal(const char *url, const char *localpath,
+ int force)
+{
+ int ret = -1;
FILE *localf = NULL;
+ const char *open_mode, *useragent;
+ char *destfile, *tempfile;
+ char hostname[256]; /* RFC1123 states applications should support this length */
struct stat st;
- int ret = 0;
- off_t dl_thisfile = 0;
- ssize_t nread = 0;
- char *tempfile, *destfile, *filename;
+ long httpresp, timecond, remote_time;
+ double remote_size, bytes_dl;
struct sigaction sig_pipe[2], sig_int[2];
+ struct fileinfo dlfile;
- off_t local_size = 0;
- time_t local_time = 0;
-
- struct url *fileurl;
- struct url_stat ust;
- fetchIO *dlf = NULL;
-
- char buffer[PM_DLBUF_LEN];
-
- filename = get_filename(url);
- if(!filename) {
+ dlfile.initial_size = 0.0;
+ dlfile.filename = get_filename(url);
+ if(!dlfile.filename || curl_gethost(url, hostname) != 0) {
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
}
- fileurl = fetchParseURL(url);
- if(!fileurl) {
- _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
- RET_ERR(PM_ERR_LIBFETCH, -1);
+ destfile = get_fullpath(localpath, dlfile.filename, "");
+ tempfile = get_fullpath(localpath, dlfile.filename, ".part");
+ if(!destfile || !tempfile) {
+ goto cleanup;
}
- destfile = get_destfile(localpath, filename);
- tempfile = get_tempfile(localpath, filename);
-
- if(stat(tempfile, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0) {
- _alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation\n");
- local_time = fileurl->last_modified = st.st_mtime;
- local_size = fileurl->offset = (off_t)st.st_size;
- dl_thisfile = st.st_size;
- localf = fopen(tempfile, "ab");
- } else if(!force && stat(destfile, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0) {
- _alpm_log(PM_LOG_DEBUG, "destfile found, using mtime only\n");
- local_time = fileurl->last_modified = st.st_mtime;
- local_size = /* no fu->off here */ (off_t)st.st_size;
- } else {
- _alpm_log(PM_LOG_DEBUG, "no file found matching criteria, starting from scratch\n");
+ /* the curl_easy handle is initialized with the alpm handle, so we only need
+ * to reset the curl handle set parameters for each time it's used. */
+ curl_easy_reset(handle->curl);
+ curl_easy_setopt(handle->curl, CURLOPT_URL, url);
+ curl_easy_setopt(handle->curl, CURLOPT_FAILONERROR, 1L);
+ curl_easy_setopt(handle->curl, CURLOPT_CONNECTTIMEOUT, 10L);
+ curl_easy_setopt(handle->curl, CURLOPT_FILETIME, 1L);
+ curl_easy_setopt(handle->curl, CURLOPT_NOPROGRESS, 0L);
+ curl_easy_setopt(handle->curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(handle->curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
+ curl_easy_setopt(handle->curl, CURLOPT_PROGRESSDATA, (void*)&dlfile);
+
+ useragent = getenv("HTTP_USER_AGENT");
+ if (useragent != NULL) {
+ curl_easy_setopt(handle->curl, CURLOPT_USERAGENT, useragent);
}
- /* pass the raw filename for passing to the callback function */
- _alpm_log(PM_LOG_DEBUG, "using '%s' for download progress\n", filename);
+ /* TODO: no assuming here. the calling function should tell us what's kosher */
+ if(!force && stat(destfile, &st) == 0) {
+ /* assume its a sync, so we're starting from scratch. but, only download
+ * our local is out of date. */
+ curl_easy_setopt(handle->curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+ curl_easy_setopt(handle->curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
+ } else if(stat(tempfile, &st) == 0 && st.st_size > 0) {
+ /* assume its a partial package download. we do not support resuming of
+ * transfers on partially downloaded sync DBs. */
+ open_mode = "ab";
+ curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, (long)st.st_size);
+ _alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation");
+ dlfile.initial_size = (double)st.st_size;
+ }
- /* print proxy info for debug purposes */
- _alpm_log(PM_LOG_DEBUG, "HTTP_PROXY: %s\n", getenv("HTTP_PROXY"));
- _alpm_log(PM_LOG_DEBUG, "http_proxy: %s\n", getenv("http_proxy"));
- _alpm_log(PM_LOG_DEBUG, "FTP_PROXY: %s\n", getenv("FTP_PROXY"));
- _alpm_log(PM_LOG_DEBUG, "ftp_proxy: %s\n", getenv("ftp_proxy"));
+ localf = fopen(tempfile, open_mode);
+ if(localf == NULL) {
+ goto cleanup;
+ }
- /* 10s timeout */
- fetchTimeout = 10;
+ curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, localf);
/* ignore any SIGPIPE signals- these may occur if our FTP socket dies or
* something along those lines. Store the old signal handler first. */
@@ -169,168 +235,64 @@ static int download_internal(const char *url, const char *localpath,
sigaction(SIGINT, NULL, &sig_int[OLD]);
sigaction(SIGINT, &sig_int[NEW], NULL);
- /* NOTE: libfetch does not reset the error code, be sure to do it before
- * calls into the library */
-
- /* TODO: if we call fetchStat() and get a redirect (disabling automagic
- * redirect following), we should repeat the file locator stuff and get a new
- * filename rather than only base if off the first URL, and then verify
- * get_filename() didn't return ''. Of course, libfetch might not even allow
- * us to even get that URL...FS#22645. This would allow us to download things
- * without totally puking like
- * http://www.archlinux.org/packages/community/x86_64/exim/download/ */
-
- /* find out the remote size *and* mtime in one go. there is a lot of
- * trouble in trying to do both size and "if-modified-since" logic in a
- * non-stat request, so avoid it. */
- fetchLastErrCode = 0;
- if(fetchStat(fileurl, &ust, "") == -1) {
- pm_errno = PM_ERR_LIBFETCH;
- _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
- filename, gethost(fileurl), fetchLastErrString);
- ret = -1;
- goto cleanup;
- }
- check_stop();
-
- _alpm_log(PM_LOG_DEBUG, "ust.mtime: %ld local_time: %ld compare: %ld\n",
- ust.mtime, local_time, local_time - ust.mtime);
- _alpm_log(PM_LOG_DEBUG, "ust.size: %jd local_size: %jd compare: %jd\n",
- (intmax_t)ust.size, (intmax_t)local_size, (intmax_t)(local_size - ust.size));
- if(!force && ust.mtime && ust.mtime == local_time
- && ust.size && ust.size == local_size) {
- /* the remote time and size values agreed with what we have, so move on
- * because there is nothing more to do. */
- _alpm_log(PM_LOG_DEBUG, "files are identical, skipping %s\n", filename);
- ret = 1;
- goto cleanup;
- }
- if(!ust.mtime || ust.mtime != local_time) {
- _alpm_log(PM_LOG_DEBUG, "mtimes were different or unavailable, downloading %s from beginning\n", filename);
- fileurl->offset = 0;
- }
-
- fetchLastErrCode = 0;
- dlf = fetchGet(fileurl, "");
- check_stop();
-
- if(fetchLastErrCode != 0 || dlf == NULL) {
- pm_errno = PM_ERR_LIBFETCH;
- _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
- filename, gethost(fileurl), fetchLastErrString);
- ret = -1;
- goto cleanup;
- } else {
- _alpm_log(PM_LOG_DEBUG, "connected to %s successfully\n", fileurl->host);
- }
-
- if(localf && fileurl->offset == 0) {
- _alpm_log(PM_LOG_WARNING, _("resuming download of %s not possible; starting over\n"), filename);
- fclose(localf);
- localf = NULL;
- } else if(fileurl->offset) {
- _alpm_log(PM_LOG_DEBUG, "resuming download at position %jd\n", (intmax_t)fileurl->offset);
- }
-
-
- if(localf == NULL) {
- _alpm_rmrf(tempfile);
- fileurl->offset = (off_t)0;
- dl_thisfile = 0;
- localf = fopen(tempfile, "wb");
- if(localf == NULL) { /* still null? */
- pm_errno = PM_ERR_RETRIEVE;
- _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
- tempfile, strerror(errno));
- ret = -1;
- goto cleanup;
- }
- }
-
/* Progress 0 - initialize */
- if(handle->dlcb) {
- handle->dlcb(filename, 0, ust.size);
- }
+ prevprogress = 0;
- while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
- check_stop();
- size_t nwritten = 0;
- nwritten = fwrite(buffer, 1, (size_t)nread, localf);
- if((nwritten != (size_t)nread) || ferror(localf)) {
- pm_errno = PM_ERR_RETRIEVE;
- _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
- tempfile, strerror(errno));
- ret = -1;
- goto cleanup;
- }
- dl_thisfile += nread;
+ /* perform transfer */
+ handle->curlerr = curl_easy_perform(handle->curl);
- if(handle->dlcb) {
- handle->dlcb(filename, dl_thisfile, ust.size);
- }
+ /* retrieve info about the state of the transfer */
+ curl_easy_getinfo(handle->curl, CURLINFO_RESPONSE_CODE, &httpresp);
+ curl_easy_getinfo(handle->curl, CURLINFO_FILETIME, &remote_time);
+ curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_size);
+ curl_easy_getinfo(handle->curl, CURLINFO_SIZE_DOWNLOAD, &bytes_dl);
+ curl_easy_getinfo(handle->curl, CURLINFO_CONDITION_UNMET, &timecond);
+
+ /* time condition was met and we didn't download anything. we need to
+ * clean up the 0 byte .part file that's left behind. */
+ if(DOUBLE_EQ(bytes_dl, 0) && timecond == 1) {
+ ret = 1;
+ unlink(tempfile);
+ goto cleanup;
}
- /* did the transfer complete normally? */
- if (nread == -1) {
- /* not PM_ERR_LIBFETCH here because libfetch error string might be empty */
- pm_errno = PM_ERR_RETRIEVE;
- _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s\n"),
- filename, gethost(fileurl));
- ret = -1;
+ if(handle->curlerr == CURLE_ABORTED_BY_CALLBACK) {
+ goto cleanup;
+ } else if(handle->curlerr != CURLE_OK) {
+ pm_errno = PM_ERR_LIBCURL;
+ _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
+ dlfile.filename, hostname, curl_easy_strerror(handle->curlerr));
+ unlink(tempfile);
goto cleanup;
}
- if (ust.size != -1 && dl_thisfile < ust.size) {
+ /* remote_size isn't necessarily the full size of the file, just what the
+ * server reported as remaining to download. compare it to what curl reported
+ * as actually being transferred during curl_easy_perform() */
+ if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) &&
+ !DOUBLE_EQ(bytes_dl, remote_size)) {
pm_errno = PM_ERR_RETRIEVE;
_alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
- filename, (intmax_t)dl_thisfile, (intmax_t)ust.size);
- ret = -1;
+ dlfile.filename, (intmax_t)bytes_dl, (intmax_t)remote_size);
goto cleanup;
}
- /* probably safer to close the file descriptors now before renaming the file,
- * for example to make sure the buffers are flushed.
- */
- fclose(localf);
- localf = NULL;
- fetchIO_close(dlf);
- dlf = NULL;
-
- /* set the times on the file to the same as that of the remote file */
- if(ust.mtime) {
- struct timeval tv[2];
- memset(&tv, 0, sizeof(tv));
- tv[0].tv_sec = ust.atime;
- tv[1].tv_sec = ust.mtime;
- utimes(tempfile, tv);
- }
- if(rename(tempfile, destfile)) {
- _alpm_log(PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
- tempfile, destfile, strerror(errno));
- ret = -1;
- }
ret = 0;
cleanup:
- FREE(tempfile);
- FREE(destfile);
if(localf != NULL) {
- /* if we still had a local file open, we got interrupted. set the mtimes on
- * the file accordingly. */
- fflush(localf);
- if(ust.mtime) {
- struct timeval tv[2];
- memset(&tv, 0, sizeof(tv));
- tv[0].tv_sec = ust.atime;
- tv[1].tv_sec = ust.mtime;
- futimes(fileno(localf), tv);
- }
fclose(localf);
+ utimes_long(tempfile, remote_time);
}
- if(dlf != NULL) {
- fetchIO_close(dlf);
+
+ /* TODO: A signature download will need to return success here as well before
+ * we're willing to rotate the new file into place. */
+ if(ret == 0) {
+ rename(tempfile, destfile);
}
- fetchFreeURL(fileurl);
+
+ FREE(tempfile);
+ FREE(destfile);
/* restore the old signal handlers */
sigaction(SIGINT, &sig_int[OLD], NULL);
@@ -340,15 +302,16 @@ cleanup:
raise(SIGINT);
}
- return(ret);
+ return ret;
}
#endif
static int download(const char *url, const char *localpath,
- int force) {
+ int force)
+{
if(handle->fetchcb == NULL) {
-#ifdef HAVE_LIBFETCH
- return(download_internal(url, localpath, force));
+#ifdef HAVE_LIBCURL
+ return curl_download_internal(url, localpath, force);
#else
RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
#endif
@@ -357,7 +320,7 @@ static int download(const char *url, const char *localpath,
if(ret == -1) {
RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
}
- return(ret);
+ return ret;
}
}
@@ -395,7 +358,7 @@ int _alpm_download_single_file(const char *filename,
}
}
- return(ret);
+ return ret;
}
int _alpm_download_files(alpm_list_t *files,
@@ -412,7 +375,7 @@ int _alpm_download_files(alpm_list_t *files,
}
}
- return(ret);
+ return ret;
}
/** Fetch a remote pkg.
@@ -437,13 +400,13 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *url)
ret = download(url, cachedir, 0);
if(ret == -1) {
_alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), url);
- return(NULL);
+ return NULL;
}
_alpm_log(PM_LOG_DEBUG, "successfully downloaded %s\n", url);
/* we should be able to find the file the second time around */
filepath = _alpm_filecache_find(filename);
- return(filepath);
+ return filepath;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h
index 63266491..5ce44b8a 100644
--- a/lib/libalpm/dload.h
+++ b/lib/libalpm/dload.h
@@ -25,7 +25,11 @@
#include <time.h>
-#define PM_DLBUF_LEN (1024 * 16)
+/* internal structure for communicating with curl progress callback */
+struct fileinfo {
+ char *filename;
+ double initial_size;
+};
int _alpm_download_single_file(const char *filename,
alpm_list_t *servers, const char *localpath,
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 21fbb48f..4d4a065c 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -20,21 +20,14 @@
#include "config.h"
-/* TODO: needed for the libfetch stuff, unfortunately- we should kill it */
-#include <stdio.h>
-/* the following two are needed for FreeBSD's libfetch */
-#include <limits.h> /* PATH_MAX */
-#if defined(HAVE_SYS_PARAM_H)
-#include <sys/param.h> /* MAXHOSTNAMELEN */
-#endif
-
-#ifdef HAVE_LIBFETCH
-#include <fetch.h> /* fetchLastErrString */
+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
#endif
/* libalpm */
#include "util.h"
#include "alpm.h"
+#include "handle.h"
const char SYMEXPORT *alpm_strerrorlast(void)
{
@@ -122,6 +115,13 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("package architecture is not valid");
case PM_ERR_PKG_REPO_NOT_FOUND:
return _("could not find repository for target");
+ /* Signatures */
+ case PM_ERR_SIG_MISSINGDIR:
+ return _("signature directory not configured correctly");
+ case PM_ERR_SIG_INVALID:
+ return _("invalid PGP signature");
+ case PM_ERR_SIG_UNKNOWN:
+ return _("unknown PGP signature");
/* Deltas */
case PM_ERR_DLT_INVALID:
return _("invalid or corrupted delta");
@@ -147,13 +147,15 @@ const char SYMEXPORT *alpm_strerror(int err)
* requires the archive struct, so we can't. Just use a generic
* error string instead. */
return _("libarchive error");
- case PM_ERR_LIBFETCH:
-#ifdef HAVE_LIBFETCH
- return fetchLastErrString;
+ case PM_ERR_LIBCURL:
+#ifdef HAVE_LIBCURL
+ return curl_easy_strerror(handle->curlerr);
#else
/* obviously shouldn't get here... */
return _("download library error");
#endif
+ case PM_ERR_GPGME:
+ return _("gpgme error");
case PM_ERR_EXTERNAL_DOWNLOAD:
return _("error invoking external downloader");
/* Unknown error! */
diff --git a/lib/libalpm/graph.h b/lib/libalpm/graph.h
index 07986f66..ce195145 100644
--- a/lib/libalpm/graph.h
+++ b/lib/libalpm/graph.h
@@ -38,7 +38,7 @@ static pmgraph_t *_alpm_graph_new(void)
pmgraph_t *graph = NULL;
CALLOC(graph, 1, sizeof(pmgraph_t), RET_ERR(PM_ERR_MEMORY, NULL));
- return(graph);
+ return graph;
}
static void _alpm_graph_free(void *data)
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index 398c2588..b13908c1 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -40,7 +40,7 @@ pmgrp_t *_alpm_grp_new(const char *name)
CALLOC(grp, 1, sizeof(pmgrp_t), RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(grp->name, name, RET_ERR(PM_ERR_MEMORY, NULL));
- return(grp);
+ return grp;
}
void _alpm_grp_free(pmgrp_t *grp)
@@ -62,7 +62,7 @@ const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(grp != NULL, return(NULL));
+ ASSERT(grp != NULL, return NULL);
return grp->name;
}
@@ -72,7 +72,7 @@ alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp)
ALPM_LOG_FUNC;
/* Sanity checks */
- ASSERT(grp != NULL, return(NULL));
+ ASSERT(grp != NULL, return NULL);
return grp->packages;
}
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index d4ebe82a..42c0cd1f 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -50,7 +50,7 @@ pmhandle_t *_alpm_handle_new()
CALLOC(handle, 1, sizeof(pmhandle_t), RET_ERR(PM_ERR_MEMORY, NULL));
- return(handle);
+ return handle;
}
void _alpm_handle_free(pmhandle_t *handle)
@@ -71,6 +71,11 @@ void _alpm_handle_free(pmhandle_t *handle)
closelog();
}
+#ifdef HAVE_LIBCURL
+ /* release curl handle */
+ curl_easy_cleanup(handle->curl);
+#endif
+
/* free memory */
_alpm_trans_free(handle->trans);
FREE(handle->root);
@@ -79,12 +84,14 @@ void _alpm_handle_free(pmhandle_t *handle)
FREE(handle->logfile);
FREE(handle->lockfile);
FREE(handle->arch);
+ FREE(handle->signaturedir);
FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade);
FREELIST(handle->noextract);
FREELIST(handle->ignorepkg);
FREELIST(handle->ignoregrp);
FREE(handle);
+
}
alpm_cb_log SYMEXPORT alpm_option_get_logcb()
@@ -168,6 +175,15 @@ const char SYMEXPORT *alpm_option_get_lockfile()
return handle->lockfile;
}
+const char SYMEXPORT *alpm_option_get_signaturedir()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->signaturedir;
+}
+
int SYMEXPORT alpm_option_get_usesyslog()
{
if (handle == NULL) {
@@ -304,18 +320,18 @@ int SYMEXPORT alpm_option_set_root(const char *root)
if(!root) {
pm_errno = PM_ERR_WRONG_ARGS;
- return(-1);
+ return -1;
}
if(stat(root, &st) == -1 || !S_ISDIR(st.st_mode)) {
pm_errno = PM_ERR_NOT_A_DIR;
- return(-1);
+ return -1;
}
realroot = calloc(PATH_MAX+1, sizeof(char));
if(!realpath(root, realroot)) {
FREE(realroot);
pm_errno = PM_ERR_NOT_A_DIR;
- return(-1);
+ return -1;
}
/* verify root ends in a '/' */
@@ -331,7 +347,7 @@ int SYMEXPORT alpm_option_set_root(const char *root)
handle->root[rootlen-1] = '/';
FREE(realroot);
_alpm_log(PM_LOG_DEBUG, "option 'root' = %s\n", handle->root);
- return(0);
+ return 0;
}
int SYMEXPORT alpm_option_set_dbpath(const char *dbpath)
@@ -344,11 +360,11 @@ int SYMEXPORT alpm_option_set_dbpath(const char *dbpath)
if(!dbpath) {
pm_errno = PM_ERR_WRONG_ARGS;
- return(-1);
+ return -1;
}
if(stat(dbpath, &st) == -1 || !S_ISDIR(st.st_mode)) {
pm_errno = PM_ERR_NOT_A_DIR;
- return(-1);
+ return -1;
}
/* verify dbpath ends in a '/' */
dbpathlen = strlen(dbpath);
@@ -370,7 +386,7 @@ int SYMEXPORT alpm_option_set_dbpath(const char *dbpath)
handle->lockfile = calloc(lockfilelen, sizeof(char));
snprintf(handle->lockfile, lockfilelen, "%s%s", handle->dbpath, lf);
_alpm_log(PM_LOG_DEBUG, "option 'lockfile' = %s\n", handle->lockfile);
- return(0);
+ return 0;
}
int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
@@ -382,7 +398,7 @@ int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
if(!cachedir) {
pm_errno = PM_ERR_WRONG_ARGS;
- return(-1);
+ return -1;
}
/* don't stat the cachedir yet, as it may not even be needed. we can
* fail later if it is needed and the path is invalid. */
@@ -397,7 +413,7 @@ int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
newcachedir[cachedirlen-1] = '/';
handle->cachedirs = alpm_list_add(handle->cachedirs, newcachedir);
_alpm_log(PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir);
- return(0);
+ return 0;
}
void SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs)
@@ -423,9 +439,9 @@ int SYMEXPORT alpm_option_remove_cachedir(const char *cachedir)
FREE(newcachedir);
if(vdata != NULL) {
FREE(vdata);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
int SYMEXPORT alpm_option_set_logfile(const char *logfile)
@@ -436,7 +452,7 @@ int SYMEXPORT alpm_option_set_logfile(const char *logfile)
if(!logfile) {
pm_errno = PM_ERR_WRONG_ARGS;
- return(-1);
+ return -1;
}
handle->logfile = strdup(logfile);
@@ -451,7 +467,25 @@ int SYMEXPORT alpm_option_set_logfile(const char *logfile)
handle->logstream = NULL;
}
_alpm_log(PM_LOG_DEBUG, "option 'logfile' = %s\n", handle->logfile);
- return(0);
+ return 0;
+}
+
+int SYMEXPORT alpm_option_set_signaturedir(const char *signaturedir)
+{
+ ALPM_LOG_FUNC;
+
+ if(!signaturedir) {
+ pm_errno = PM_ERR_WRONG_ARGS;
+ return -1;
+ }
+
+ if(handle->signaturedir) {
+ FREE(handle->signaturedir);
+ }
+ handle->signaturedir = strdup(signaturedir);
+
+ _alpm_log(PM_LOG_DEBUG, "option 'signaturedir' = %s\n", handle->signaturedir);
+ return 0;
}
void SYMEXPORT alpm_option_set_usesyslog(int usesyslog)
@@ -476,9 +510,9 @@ int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
handle->noupgrade = alpm_list_remove_str(handle->noupgrade, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
void SYMEXPORT alpm_option_add_noextract(const char *pkg)
@@ -498,9 +532,9 @@ int SYMEXPORT alpm_option_remove_noextract(const char *pkg)
handle->noextract = alpm_list_remove_str(handle->noextract, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
void SYMEXPORT alpm_option_add_ignorepkg(const char *pkg)
@@ -520,9 +554,9 @@ int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
handle->ignorepkg = alpm_list_remove_str(handle->ignorepkg, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
void SYMEXPORT alpm_option_add_ignoregrp(const char *grp)
@@ -542,9 +576,9 @@ int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
handle->ignoregrp = alpm_list_remove_str(handle->ignoregrp, grp, &vdata);
if(vdata != NULL) {
FREE(vdata);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
void SYMEXPORT alpm_option_set_arch(const char *arch)
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 2d962fe6..cf192bce 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -29,6 +29,10 @@
#include "alpm.h"
#include "trans.h"
+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
+#endif
+
typedef struct _pmhandle_t {
/* internal usage */
pmdb_t *db_local; /* local db pointer */
@@ -37,6 +41,12 @@ typedef struct _pmhandle_t {
FILE *lckstream; /* lock file stream pointer if one exists */
pmtrans_t *trans;
+#ifdef HAVE_LIBCURL
+ /* libcurl handle */
+ CURL *curl; /* reusable curl_easy handle */
+ CURLcode curlerr; /* last error produced by curl */
+#endif
+
/* callback functions */
alpm_cb_log logcb; /* Log callback function */
alpm_cb_download dlcb; /* Download callback function */
@@ -48,6 +58,7 @@ typedef struct _pmhandle_t {
char *dbpath; /* Base path to pacman's DBs */
char *logfile; /* Name of the log file */
char *lockfile; /* Name of the lock file */
+ char *signaturedir; /* Directory where GnuPG files are stored */
alpm_list_t *cachedirs; /* Paths to pacman cache directories */
/* package lists */
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index 09c6fb84..0d936e22 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -64,7 +64,7 @@ int SYMEXPORT alpm_logaction(const char *fmt, ...)
} else {
pm_errno = PM_ERR_SYSTEM;
}
- return(-1);
+ return -1;
}
}
@@ -83,7 +83,7 @@ int SYMEXPORT alpm_logaction(const char *fmt, ...)
* kpacman: "KPACMAN"
* This would allow us to share the log file between several frontends
* and know who does what */
- return(ret);
+ return ret;
}
/** @} */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index adb1ce9e..69c2b852 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -40,6 +40,7 @@
#include "delta.h"
#include "handle.h"
#include "deps.h"
+#include "base64.h"
/** \addtogroup alpm_packages Package Functions
* @brief Functions to manipulate libalpm packages
@@ -61,7 +62,7 @@ int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg)
_alpm_pkg_free(pkg);
}
- return(0);
+ return 0;
}
/** Check the integrity (with md5) of a package from the sync cache.
@@ -84,13 +85,13 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
retval = _alpm_test_md5sum(fpath, alpm_pkg_get_md5sum(pkg));
if(retval == 0) {
- return(0);
+ return 0;
} else if (retval == 1) {
pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
- return(retval);
+ return retval;
}
/* Default package accessor functions. These will get overridden by any
@@ -201,6 +202,42 @@ const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
return pkg->ops->get_md5sum(pkg);
}
+static int decode_pgpsig(pmpkg_t *pkg) {
+ int len = strlen(pkg->pgpsig.encdata);
+ const unsigned char *usline = (const unsigned char*)pkg->pgpsig.encdata;
+ int destlen = 0;
+ /* get the necessary size for the buffer by passing 0 */
+ int ret = base64_decode(NULL, &destlen, usline, len);
+ /* alloc our memory and repeat the call to decode */
+ MALLOC(pkg->pgpsig.rawdata, (size_t)destlen, goto error);
+ ret = base64_decode(pkg->pgpsig.rawdata, &destlen, usline, len);
+ pkg->pgpsig.rawlen = destlen;
+ if(ret != 0) {
+ goto error;
+ }
+
+ FREE(pkg->pgpsig.encdata);
+ return 0;
+
+error:
+ FREE(pkg->pgpsig.rawdata);
+ pkg->pgpsig.rawlen = 0;
+ return 1;
+}
+
+const pmpgpsig_t SYMEXPORT *alpm_pkg_get_pgpsig(pmpkg_t *pkg)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+ if(pkg->pgpsig.rawdata == NULL && pkg->pgpsig.encdata != NULL) {
+ decode_pgpsig(pkg);
+ }
+ return &(pkg->pgpsig);
+}
+
const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
{
return pkg->ops->get_arch(pkg);
@@ -274,10 +311,10 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg)
{
/* Sanity checks */
- ASSERT(pkg != NULL, return(NULL));
- ASSERT(pkg->origin != PKG_FROM_FILE, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
+ ASSERT(pkg->origin != PKG_FROM_FILE, return NULL);
- return(pkg->origin_data.db);
+ return pkg->origin_data.db;
}
/**
@@ -381,7 +418,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
reqs = alpm_list_msort(reqs, alpm_list_count(reqs), _alpm_str_cmp);
}
}
- return(reqs);
+ return reqs;
}
/** @} */
@@ -394,7 +431,7 @@ pmpkg_t *_alpm_pkg_new(void)
CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
- return(pkg);
+ return pkg;
}
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
@@ -445,7 +482,7 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
}
newpkg->infolevel = pkg->infolevel;
- return(newpkg);
+ return newpkg;
}
void _alpm_pkg_free(pmpkg_t *pkg)
@@ -463,6 +500,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
+ FREE(pkg->pgpsig.encdata);
+ FREE(pkg->pgpsig.rawdata);
FREE(pkg->arch);
FREELIST(pkg->licenses);
FREELIST(pkg->replaces);
@@ -522,7 +561,7 @@ int _alpm_pkg_cmp(const void *p1, const void *p2)
{
pmpkg_t *pkg1 = (pmpkg_t *)p1;
pmpkg_t *pkg2 = (pmpkg_t *)p2;
- return(strcoll(pkg1->name, pkg2->name));
+ return strcoll(pkg1->name, pkg2->name);
}
/* Test for existence of a package in a alpm_list_t*
@@ -536,7 +575,7 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
ALPM_LOG_FUNC;
if(needle == NULL || haystack == NULL) {
- return(NULL);
+ return NULL;
}
needle_hash = _alpm_hash_sdbm(needle);
@@ -552,11 +591,11 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
/* finally: we had hash match, verify string match */
if(strcmp(info->name, needle) == 0) {
- return(info);
+ return info;
}
}
}
- return(NULL);
+ return NULL;
}
/** Test if a package should be ignored.
@@ -574,18 +613,18 @@ int _alpm_pkg_should_ignore(pmpkg_t *pkg)
/* first see if the package is ignored */
if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
- return(1);
+ return 1;
}
/* next see if the package is in a group that is ignored */
for(groups = handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
char *grp = (char *)alpm_list_getdata(groups);
if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index b161d5f1..0b5f32d4 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -29,6 +29,7 @@
#include "alpm.h"
#include "db.h"
+#include "signing.h"
typedef enum _pmpkgfrom_t {
PKG_FROM_FILE = 1,
@@ -98,6 +99,8 @@ struct __pmpkg_t {
char *md5sum;
char *arch;
+ pmpgpsig_t pgpsig;
+
time_t builddate;
time_t installdate;
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c
index db98f94b..761ca72d 100644
--- a/lib/libalpm/pkghash.c
+++ b/lib/libalpm/pkghash.c
@@ -72,13 +72,13 @@ pmpkghash_t *_alpm_pkghash_create(size_t size)
if(hash->buckets < size) {
_alpm_log(PM_LOG_ERROR, _("database larger than maximum size\n"));
free(hash);
- return(NULL);
+ return NULL;
}
CALLOC(hash->hash_table, hash->buckets, sizeof(alpm_list_t*), \
free(hash); RET_ERR(PM_ERR_MEMORY, NULL));
- return(hash);
+ return hash;
}
static size_t get_hash_position(unsigned long name_hash, pmpkghash_t *hash)
@@ -93,7 +93,7 @@ static size_t get_hash_position(unsigned long name_hash, pmpkghash_t *hash)
position = (position + 1) % hash->buckets;
}
- return(position);
+ return position;
}
/* Expand the hash table size to the next increment and rebin the entries */
@@ -124,7 +124,7 @@ static pmpkghash_t *rehash(pmpkghash_t *oldhash)
newhash = _alpm_pkghash_create(newsize);
if(newhash == NULL) {
/* creation of newhash failed, stick with old one... */
- return(oldhash);
+ return oldhash;
}
newhash->list = oldhash->list;
@@ -145,7 +145,7 @@ static pmpkghash_t *rehash(pmpkghash_t *oldhash)
_alpm_pkghash_free(oldhash);
- return(newhash);
+ return newhash;
}
static pmpkghash_t *pkghash_add_pkg(pmpkghash_t *hash, pmpkg_t *pkg, int sorted)
@@ -154,7 +154,7 @@ static pmpkghash_t *pkghash_add_pkg(pmpkghash_t *hash, pmpkg_t *pkg, int sorted)
size_t position;
if(pkg == NULL || hash == NULL) {
- return(hash);
+ return hash;
}
if((hash->entries + 1) / MAX_HASH_LOAD > hash->buckets) {
@@ -165,7 +165,7 @@ static pmpkghash_t *pkghash_add_pkg(pmpkghash_t *hash, pmpkg_t *pkg, int sorted)
ptr = calloc(1, sizeof(alpm_list_t));
if(ptr == NULL) {
- return(hash);
+ return hash;
}
ptr->data = pkg;
@@ -180,17 +180,17 @@ static pmpkghash_t *pkghash_add_pkg(pmpkghash_t *hash, pmpkg_t *pkg, int sorted)
}
hash->entries += 1;
- return(hash);
+ return hash;
}
pmpkghash_t *_alpm_pkghash_add(pmpkghash_t *hash, pmpkg_t *pkg)
{
- return(pkghash_add_pkg(hash, pkg, 0));
+ return pkghash_add_pkg(hash, pkg, 0);
}
pmpkghash_t *_alpm_pkghash_add_sorted(pmpkghash_t *hash, pmpkg_t *pkg)
{
- return(pkghash_add_pkg(hash, pkg, 1));
+ return pkghash_add_pkg(hash, pkg, 1);
}
static size_t move_one_entry(pmpkghash_t *hash, size_t start, size_t end)
@@ -218,7 +218,7 @@ static size_t move_one_entry(pmpkghash_t *hash, size_t start, size_t end)
* e.g. (47 + 0 - 1) % 47 == 46 */
end = (hash->buckets + end - 1) % hash->buckets;
}
- return(end);
+ return end;
}
/**
@@ -241,7 +241,7 @@ pmpkghash_t *_alpm_pkghash_remove(pmpkghash_t *hash, pmpkg_t *pkg,
}
if(pkg == NULL || hash == NULL) {
- return(hash);
+ return hash;
}
position = pkg->name_hash % hash->buckets;
@@ -278,13 +278,13 @@ pmpkghash_t *_alpm_pkghash_remove(pmpkghash_t *hash, pmpkg_t *pkg,
position = prev;
}
- return(hash);
+ return hash;
}
position = (position + 1) % hash->buckets;
}
- return(hash);
+ return hash;
}
void _alpm_pkghash_free(pmpkghash_t *hash)
@@ -308,7 +308,7 @@ pmpkg_t *_alpm_pkghash_find(pmpkghash_t *hash, const char *name)
ALPM_LOG_FUNC;
if(name == NULL || hash == NULL) {
- return(NULL);
+ return NULL;
}
name_hash = _alpm_hash_sdbm(name);
@@ -319,13 +319,13 @@ pmpkg_t *_alpm_pkghash_find(pmpkghash_t *hash, const char *name)
pmpkg_t *info = lp->data;
if(info->name_hash == name_hash && strcmp(info->name, name) == 0) {
- return(info);
+ return info;
}
position = (position + 1) % hash->buckets;
}
- return(NULL);
+ return NULL;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 5def92a6..a01349ed 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -69,7 +69,7 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
_alpm_log(PM_LOG_DEBUG, "adding %s in the target list\n", pkgname);
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
- return(0);
+ return 0;
}
static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
@@ -185,7 +185,7 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
}
- return(0);
+ return 0;
}
static int can_remove_file(const char *path, alpm_list_t *skip)
@@ -196,7 +196,7 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
if(alpm_list_find_str(skip, file)) {
/* return success because we will never actually remove this file */
- return(1);
+ return 1;
}
/* If we fail write permissions due to a read-only filesystem, abort.
* Assume all other possible failures are covered somewhere else */
@@ -206,11 +206,11 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
* it - ignore "chmod -w" simple permission failures */
_alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
file, strerror(errno));
- return(0);
+ return 0;
}
}
- return(1);
+ return 1;
}
/* Helper function for iterating through a package's file and deleting them
@@ -351,7 +351,7 @@ db:
pkgname);
}
- return(0);
+ return 0;
}
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
@@ -375,7 +375,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
size_t targcount = alpm_list_count(targ);
if(handle->trans->state == STATE_INTERRUPTED) {
- return(0);
+ return 0;
}
/* get the name now so we can use it after package is removed */
@@ -457,7 +457,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* run ldconfig if it exists */
_alpm_ldconfig(handle->root);
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
new file mode 100644
index 00000000..c30650b1
--- /dev/null
+++ b/lib/libalpm/signing.c
@@ -0,0 +1,280 @@
+/*
+ * signing.c
+ *
+ * Copyright (c) 2008-2011 Pacman Development Team <pacman-dev@archlinux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <locale.h> /* setlocale() */
+#include <gpgme.h>
+
+/* libalpm */
+#include "signing.h"
+#include "package.h"
+#include "util.h"
+#include "log.h"
+#include "alpm.h"
+
+#define CHECK_ERR(void) do { \
+ if(err != GPG_ERR_NO_ERROR) { goto error; } \
+ } while(0)
+
+static int gpgme_init(void)
+{
+ static int init = 0;
+ const char *version;
+ gpgme_error_t err;
+ gpgme_engine_info_t enginfo;
+
+ ALPM_LOG_FUNC;
+
+ if(init) {
+ /* we already successfully initialized the library */
+ return 0;
+ }
+
+ if(!alpm_option_get_signaturedir()) {
+ RET_ERR(PM_ERR_SIG_MISSINGDIR, 1);
+ }
+
+ /* calling gpgme_check_version() returns the current version and runs
+ * some internal library setup code */
+ version = gpgme_check_version(NULL);
+ _alpm_log(PM_LOG_DEBUG, "GPGME version: %s\n", version);
+ gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+#ifdef LC_MESSAGES
+ gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
+#endif
+ /* NOTE:
+ * The GPGME library installs a SIGPIPE signal handler automatically if
+ * the default signal hander is in use. The only time we set a handler
+ * for SIGPIPE is in dload.c, and we reset it when we are done. Given that
+ * we do this, we can let GPGME do its automagic. However, if we install
+ * a library-wide SIGPIPE handler, we will have to be careful.
+ */
+
+ /* check for OpenPGP support (should be a no-brainer, but be safe) */
+ err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
+ CHECK_ERR();
+
+ /* set and check engine information */
+ err = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL,
+ alpm_option_get_signaturedir());
+ CHECK_ERR();
+ err = gpgme_get_engine_info(&enginfo);
+ CHECK_ERR();
+ _alpm_log(PM_LOG_DEBUG, "GPGME engine info: file=%s, home=%s\n",
+ enginfo->file_name, enginfo->home_dir);
+
+ init = 1;
+ return 0;
+
+error:
+ _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
+ RET_ERR(PM_ERR_GPGME, 1);
+}
+
+/**
+ * Check the PGP package signature for the given file.
+ * @param path the full path to a file
+ * @param sig PGP signature data in raw form (already decoded)
+ * @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
+ */
+int _alpm_gpgme_checksig(const char *path, const pmpgpsig_t *sig)
+{
+ int ret = 0;
+ gpgme_error_t err;
+ gpgme_ctx_t ctx;
+ gpgme_data_t filedata, sigdata;
+ gpgme_verify_result_t result;
+ gpgme_signature_t gpgsig;
+ FILE *file = NULL, *sigfile = NULL;
+
+ ALPM_LOG_FUNC;
+
+ if(!sig || !sig->rawdata) {
+ RET_ERR(PM_ERR_SIG_UNKNOWN, -1);
+ }
+ if(!path || access(path, R_OK) != 0) {
+ RET_ERR(PM_ERR_NOT_A_FILE, -1);
+ }
+ if(gpgme_init()) {
+ /* pm_errno was set in gpgme_init() */
+ return -1;
+ }
+
+ _alpm_log(PM_LOG_DEBUG, "checking signature for %s\n", path);
+
+ memset(&ctx, 0, sizeof(ctx));
+ memset(&sigdata, 0, sizeof(sigdata));
+ memset(&filedata, 0, sizeof(filedata));
+
+ err = gpgme_new(&ctx);
+ CHECK_ERR();
+
+ /* create our necessary data objects to verify the signature */
+ file = fopen(path, "rb");
+ if(file == NULL) {
+ pm_errno = PM_ERR_NOT_A_FILE;
+ ret = -1;
+ goto error;
+ }
+ err = gpgme_data_new_from_stream(&filedata, file);
+ CHECK_ERR();
+
+ /* next create data object for the signature */
+ err = gpgme_data_new_from_mem(&sigdata, (char*)sig->rawdata, sig->rawlen, 0);
+ CHECK_ERR();
+
+ /* here's where the magic happens */
+ err = gpgme_op_verify(ctx, sigdata, filedata, NULL);
+ CHECK_ERR();
+ result = gpgme_op_verify_result(ctx);
+ gpgsig = result->signatures;
+ if (!gpgsig || gpgsig->next) {
+ _alpm_log(PM_LOG_ERROR, _("Unexpected number of signatures\n"));
+ ret = -1;
+ goto error;
+ }
+ _alpm_log(PM_LOG_DEBUG, "summary=%x\n", gpgsig->summary);
+ _alpm_log(PM_LOG_DEBUG, "fpr=%s\n", gpgsig->fpr);
+ _alpm_log(PM_LOG_DEBUG, "status=%d\n", gpgsig->status);
+ _alpm_log(PM_LOG_DEBUG, "timestamp=%lu\n", gpgsig->timestamp);
+ _alpm_log(PM_LOG_DEBUG, "wrong_key_usage=%u\n", gpgsig->wrong_key_usage);
+ _alpm_log(PM_LOG_DEBUG, "pka_trust=%u\n", gpgsig->pka_trust);
+ _alpm_log(PM_LOG_DEBUG, "chain_model=%u\n", gpgsig->chain_model);
+ _alpm_log(PM_LOG_DEBUG, "validity=%d\n", gpgsig->validity);
+ _alpm_log(PM_LOG_DEBUG, "validity_reason=%d\n", gpgsig->validity_reason);
+ _alpm_log(PM_LOG_DEBUG, "key=%d\n", gpgsig->pubkey_algo);
+ _alpm_log(PM_LOG_DEBUG, "hash=%d\n", gpgsig->hash_algo);
+
+ if(gpgsig->summary & GPGME_SIGSUM_VALID) {
+ /* good signature, continue */
+ _alpm_log(PM_LOG_DEBUG, _("File %s has a valid signature.\n"),
+ path);
+ } else if(gpgsig->summary & GPGME_SIGSUM_GREEN) {
+ /* 'green' signature, not sure what to do here */
+ _alpm_log(PM_LOG_WARNING, _("File %s has a green signature.\n"),
+ path);
+ } else if(gpgsig->summary & GPGME_SIGSUM_KEY_MISSING) {
+ pm_errno = PM_ERR_SIG_UNKNOWN;
+ _alpm_log(PM_LOG_WARNING, _("File %s has a signature from an unknown key.\n"),
+ path);
+ ret = -1;
+ } else {
+ /* we'll capture everything else here */
+ pm_errno = PM_ERR_SIG_INVALID;
+ _alpm_log(PM_LOG_ERROR, _("File %s has an invalid signature.\n"),
+ path);
+ ret = 1;
+ }
+
+error:
+ gpgme_data_release(sigdata);
+ gpgme_data_release(filedata);
+ gpgme_release(ctx);
+ if(sigfile) {
+ fclose(sigfile);
+ }
+ if(file) {
+ fclose(file);
+ }
+ if(err != GPG_ERR_NO_ERROR) {
+ _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
+ RET_ERR(PM_ERR_GPGME, -1);
+ }
+ return ret;
+}
+
+/**
+ * Load the signature from the given path into the provided struct.
+ * @param sigfile the signature to attempt to load
+ * @param pgpsig the struct to place the data in
+ *
+ * @return 0 on success, 1 on file not found, -1 on error
+ */
+int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig) {
+ struct stat st;
+
+ if(access(sigfile, R_OK) == 0 && stat(sigfile, &st) == 0) {
+ FILE *f;
+ size_t bytes_read;
+
+ if(st.st_size > 4096) {
+ return -1;
+ }
+
+ if((f = fopen(sigfile, "rb")) == NULL) {
+ return -1;
+ }
+ CALLOC(pgpsig->rawdata, st.st_size, sizeof(unsigned char),
+ RET_ERR(PM_ERR_MEMORY, -1));
+ bytes_read = fread(pgpsig->rawdata, sizeof(char), st.st_size, f);
+ if(bytes_read == (size_t)st.st_size) {
+ pgpsig->rawlen = bytes_read;
+ _alpm_log(PM_LOG_DEBUG, "loaded gpg signature file, location %s\n",
+ sigfile);
+ } else {
+ _alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file %s"),
+ sigfile);
+ FREE(pgpsig->rawdata);
+ return -1;
+ }
+
+ fclose(f);
+ } else {
+ _alpm_log(PM_LOG_DEBUG, "signature file %s not found\n", sigfile);
+ /* not fatal...we return a different error code here */
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * Check the PGP package signature for the given package file.
+ * @param pkg the package to check
+ * @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
+ */
+int SYMEXPORT alpm_pkg_check_pgp_signature(pmpkg_t *pkg)
+{
+ ALPM_LOG_FUNC;
+ ASSERT(pkg != NULL, return 0);
+
+ return _alpm_gpgme_checksig(alpm_pkg_get_filename(pkg),
+ alpm_pkg_get_pgpsig(pkg));
+}
+
+/**
+ * Check the PGP package signature for the given database.
+ * @param db the database to check
+ * @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
+ */
+int SYMEXPORT alpm_db_check_pgp_signature(pmdb_t *db)
+{
+ ALPM_LOG_FUNC;
+ ASSERT(db != NULL, return(0));
+
+ return _alpm_gpgme_checksig(_alpm_db_path(db),
+ _alpm_db_pgpsig(db));
+}
+
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/signing.h b/lib/libalpm/signing.h
new file mode 100644
index 00000000..b37abf0f
--- /dev/null
+++ b/lib/libalpm/signing.h
@@ -0,0 +1,39 @@
+/*
+ * signing.h
+ *
+ * Copyright (c) 2008-2011 Pacman Development Team <pacman-dev@archlinux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ALPM_SIGNING_H
+#define _ALPM_SIGNING_H
+
+#include "alpm.h"
+
+struct __pmpgpsig_t {
+ /* we will either store the encoded data or the raw data-
+ * this way we can decode on an as-needed basis since most
+ * operations won't require the overhead of base64 decodes
+ * on all packages in a sync repository. */
+ char *encdata;
+ size_t rawlen;
+ unsigned char *rawdata;
+};
+
+int _alpm_gpgme_checksig(const char *path, const pmpgpsig_t *sig);
+int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig);
+
+#endif /* _ALPM_SIGNING_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index f83b0ef9..5428e40b 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -50,13 +50,14 @@
#include "delta.h"
#include "remove.h"
#include "diskspace.h"
+#include "signing.h"
/** Check for new version of pkg in sync repos
* (only the first occurrence is considered in sync)
*/
pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
{
- ASSERT(pkg != NULL, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
alpm_list_t *i;
pmpkg_t *spkg = NULL;
@@ -68,7 +69,7 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
if(spkg == NULL) {
_alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db => no upgrade\n",
alpm_pkg_get_name(pkg));
- return(NULL);
+ return NULL;
}
/* compare versions and see if spkg is an upgrade */
@@ -76,10 +77,10 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
_alpm_log(PM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
alpm_pkg_get_version(spkg));
- return(spkg);
+ return spkg;
}
/* spkg is not an upgrade */
- return(NULL);
+ return NULL;
}
/** Search for packages to upgrade and add them to the transaction.
@@ -200,7 +201,7 @@ int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
}
}
- return(0);
+ return 0;
}
/** Find group members across a list of databases.
@@ -242,7 +243,7 @@ alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs,
}
}
alpm_list_free(ignorelist);
- return(pkgs);
+ return pkgs;
}
/** Compute the size of the files that will be downloaded to install a
@@ -258,7 +259,7 @@ static int compute_download_size(pmpkg_t *newpkg)
if(newpkg->origin != PKG_FROM_SYNCDB) {
newpkg->infolevel |= INFRQ_DSIZE;
newpkg->download_size = 0;
- return(0);
+ return 0;
}
fname = alpm_pkg_get_filename(newpkg);
@@ -295,7 +296,7 @@ static int compute_download_size(pmpkg_t *newpkg)
newpkg->infolevel |= INFRQ_DSIZE;
newpkg->download_size = size;
- return(0);
+ return 0;
}
int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data)
@@ -551,7 +552,7 @@ cleanup:
alpm_list_free(unresolvable);
alpm_list_free(remove);
- return(ret);
+ return ret;
}
/** Returns the size of the files that will be downloaded to install a
@@ -564,13 +565,13 @@ off_t SYMEXPORT alpm_pkg_download_size(pmpkg_t *newpkg)
if(!(newpkg->infolevel & INFRQ_DSIZE)) {
compute_download_size(newpkg);
}
- return(newpkg->download_size);
+ return newpkg->download_size;
}
static int endswith(const char *filename, const char *extension)
{
const char *s = filename + strlen(filename) - strlen(extension);
- return(strcmp(s, extension) == 0);
+ return strcmp(s, extension) == 0;
}
/** Applies delta files to create an upgraded package file.
@@ -656,7 +657,7 @@ static int apply_deltas(pmtrans_t *trans)
}
}
- return(ret);
+ return ret;
}
/** Compares the md5sum of a file to the expected value.
@@ -665,33 +666,25 @@ static int apply_deltas(pmtrans_t *trans)
* should be deleted.
*
* @param trans the transaction
- * @param filename the filename of the file to test
+ * @param filename the absolute path of the file to test
* @param md5sum the expected md5sum of the file
*
* @return 0 if the md5sum matched, 1 if not, -1 in case of errors
*/
-static int test_md5sum(pmtrans_t *trans, const char *filename,
+static int test_md5sum(pmtrans_t *trans, const char *filepath,
const char *md5sum)
{
- char *filepath;
- int ret;
-
- filepath = _alpm_filecache_find(filename);
-
- ret = _alpm_test_md5sum(filepath, md5sum);
-
+ int ret = _alpm_test_md5sum(filepath, md5sum);
if(ret == 1) {
int doremove = 0;
- QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, (char *)filename,
+ QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, (char*)filepath,
NULL, NULL, &doremove);
if(doremove) {
unlink(filepath);
}
}
- FREE(filepath);
-
- return(ret);
+ return ret;
}
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
@@ -800,12 +793,14 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
for(i = deltas; i; i = i->next) {
pmdelta_t *d = alpm_list_getdata(i);
const char *filename = alpm_delta_get_filename(d);
+ char *filepath = _alpm_filecache_find(filename);
const char *md5sum = alpm_delta_get_md5sum(d);
- if(test_md5sum(trans, filename, md5sum) != 0) {
+ if(test_md5sum(trans, filepath, md5sum) != 0) {
errors++;
*data = alpm_list_add(*data, strdup(filename));
}
+ FREE(filepath);
}
if(errors) {
pm_errno = PM_ERR_DLT_INVALID;
@@ -829,6 +824,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_INTEGRITY_START, NULL, NULL);
errors = 0;
+
for(i = trans->add; i; i = i->next, current++) {
pmpkg_t *spkg = i->data;
int percent = (current * 100) / numtargs;
@@ -839,17 +835,33 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
numtargs, current);
const char *filename = alpm_pkg_get_filename(spkg);
+ char *filepath = _alpm_filecache_find(filename);
const char *md5sum = alpm_pkg_get_md5sum(spkg);
+ const pmpgpsig_t *pgpsig = alpm_pkg_get_pgpsig(spkg);
- if(test_md5sum(trans, filename, md5sum) != 0) {
+ /* check md5sum first */
+ if(test_md5sum(trans, filepath, md5sum) != 0) {
errors++;
*data = alpm_list_add(*data, strdup(filename));
+ FREE(filepath);
continue;
}
+ /* check PGP signature next */
+ pmdb_t *sdb = alpm_pkg_get_db(spkg);
+
+ if(sdb->pgp_verify != PM_PGP_VERIFY_NEVER) {
+ int ret = _alpm_gpgme_checksig(filepath, pgpsig);
+ if((sdb->pgp_verify == PM_PGP_VERIFY_ALWAYS && ret != 0) ||
+ (sdb->pgp_verify == PM_PGP_VERIFY_OPTIONAL && ret == 1)) {
+ errors++;
+ *data = alpm_list_add(*data, strdup(filename));
+ FREE(filepath);
+ continue;
+ }
+ }
/* load the package file and replace pkgcache entry with it in the target list */
/* TODO: alpm_pkg_get_db() will not work on this target anymore */
_alpm_log(PM_LOG_DEBUG, "replacing pkgcache entry with package file for target %s\n", spkg->name);
- char *filepath = _alpm_filecache_find(filename);
pmpkg_t *pkgfile;
if(alpm_pkg_load(filepath, 1, &pkgfile) != 0) {
_alpm_pkg_free(pkgfile);
@@ -863,9 +875,12 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
i->data = pkgfile;
_alpm_pkg_free_trans(spkg); /* spkg has been removed from the target list */
}
+
PROGRESS(trans, PM_TRANS_PROGRESS_INTEGRITY_START, "", 100,
numtargs, current);
EVENT(trans, PM_TRANS_EVT_INTEGRITY_DONE, NULL, NULL);
+
+
if(errors) {
pm_errno = PM_ERR_PKG_INVALID;
goto error;
@@ -935,7 +950,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
error:
FREELIST(files);
alpm_list_free(deltas);
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 4b29f9a8..81254198 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -66,7 +66,7 @@ static int make_lock(pmhandle_t *handle)
}
if(_alpm_makepath(dir)) {
FREE(dir);
- return(-1);
+ return -1;
}
FREE(dir);
@@ -79,9 +79,9 @@ static int make_lock(pmhandle_t *handle)
fflush(f);
fsync(fd);
handle->lckstream = f;
- return(0);
+ return 0;
}
- return(-1);
+ return -1;
}
/* Remove a lock file */
@@ -92,9 +92,9 @@ static int remove_lock(pmhandle_t *handle)
handle->lckstream = NULL;
}
if(unlink(handle->lockfile) == -1 && errno != ENOENT) {
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/** Initialize the transaction.
@@ -148,7 +148,7 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
handle->trans = trans;
- return(0);
+ return 0;
}
static alpm_list_t *check_arch(alpm_list_t *pkgs)
@@ -158,7 +158,7 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs)
const char *arch = alpm_option_get_arch();
if(!arch) {
- return(NULL);
+ return NULL;
}
for(i = pkgs; i; i = i->next) {
pmpkg_t *pkg = i->data;
@@ -173,7 +173,7 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs)
invalid = alpm_list_add(invalid, string);
}
}
- return(invalid);
+ return invalid;
}
/** Prepare a transaction.
@@ -198,7 +198,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
/* If there's nothing to do, return without complaining */
if(trans->add == NULL && trans->remove == NULL) {
- return(0);
+ return 0;
}
alpm_list_t *invalid = check_arch(trans->add);
@@ -212,18 +212,18 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
if(trans->add == NULL) {
if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
/* pm_errno is set by _alpm_remove_prepare() */
- return(-1);
+ return -1;
}
} else {
if(_alpm_sync_prepare(trans, handle->db_local, handle->dbs_sync, data) == -1) {
/* pm_errno is set by _alpm_sync_prepare() */
- return(-1);
+ return -1;
}
}
trans->state = STATE_PREPARED;
- return(0);
+ return 0;
}
/** Commit a transaction.
@@ -249,7 +249,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
/* If there's nothing to do, return without complaining */
if(trans->add == NULL && trans->remove == NULL) {
- return(0);
+ return 0;
}
trans->state = STATE_COMMITING;
@@ -257,18 +257,18 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
if(trans->add == NULL) {
if(_alpm_remove_packages(trans, handle->db_local) == -1) {
/* pm_errno is set by _alpm_remove_commit() */
- return(-1);
+ return -1;
}
} else {
if(_alpm_sync_commit(trans, handle->db_local, data) == -1) {
/* pm_errno is set by _alpm_sync_commit() */
- return(-1);
+ return -1;
}
}
trans->state = STATE_COMMITED;
- return(0);
+ return 0;
}
/** Interrupt a transaction.
@@ -290,7 +290,7 @@ int SYMEXPORT alpm_trans_interrupt(void)
trans->state = STATE_INTERRUPTED;
- return(0);
+ return 0;
}
/** Release a transaction.
@@ -324,7 +324,7 @@ int SYMEXPORT alpm_trans_release(void)
}
}
- return(0);
+ return 0;
}
/** @} */
@@ -338,7 +338,7 @@ pmtrans_t *_alpm_trans_new(void)
CALLOC(trans, 1, sizeof(pmtrans_t), RET_ERR(PM_ERR_MEMORY, NULL));
trans->state = STATE_IDLE;
- return(trans);
+ return trans;
}
void _alpm_trans_free(pmtrans_t *trans)
@@ -367,7 +367,7 @@ static int grep(const char *fn, const char *needle)
FILE *fp;
if((fp = fopen(fn, "r")) == NULL) {
- return(0);
+ return 0;
}
while(!feof(fp)) {
char line[1024];
@@ -378,11 +378,11 @@ static int grep(const char *fn, const char *needle)
* ends up being split across line reads */
if(strstr(line, needle)) {
fclose(fp);
- return(1);
+ return 1;
}
}
fclose(fp);
- return(0);
+ return 0;
}
int _alpm_runscriptlet(const char *root, const char *installfn,
@@ -402,7 +402,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
if(access(installfn, R_OK)) {
/* not found */
_alpm_log(PM_LOG_DEBUG, "scriptlet '%s' not found\n", installfn);
- return(0);
+ return 0;
}
/* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
@@ -413,7 +413,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root);
if(mkdtemp(tmpdir) == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not create temp directory\n"));
- return(1);
+ return 1;
} else {
clean_tmpdir = 1;
}
@@ -459,14 +459,14 @@ cleanup:
_alpm_log(PM_LOG_WARNING, _("could not remove tmpdir %s\n"), tmpdir);
}
- return(retval);
+ return retval;
}
int SYMEXPORT alpm_trans_get_flags()
{
/* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(handle->trans != NULL, return(-1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(handle->trans != NULL, return -1);
return handle->trans->flags;
}
@@ -474,8 +474,8 @@ int SYMEXPORT alpm_trans_get_flags()
alpm_list_t SYMEXPORT * alpm_trans_get_add()
{
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(handle->trans != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(handle->trans != NULL, return NULL);
return handle->trans->add;
}
@@ -483,8 +483,8 @@ alpm_list_t SYMEXPORT * alpm_trans_get_add()
alpm_list_t SYMEXPORT * alpm_trans_get_remove()
{
/* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(handle->trans != NULL, return(NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(handle->trans != NULL, return NULL);
return handle->trans->remove;
}
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 11e69041..660d4eb4 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -86,7 +86,7 @@ char* strsep(char** str, const char* delims)
int _alpm_makepath(const char *path)
{
- return(_alpm_makepath_mode(path, 0755));
+ return _alpm_makepath_mode(path, 0755);
}
/* does the same thing as 'mkdir -p' */
@@ -122,7 +122,7 @@ int _alpm_makepath_mode(const char *path, mode_t mode)
free(orig);
free(incr);
umask(oldmask);
- return(ret);
+ return ret;
}
#define CPBUFSIZE 8 * 1024
@@ -136,12 +136,12 @@ int _alpm_copyfile(const char *src, const char *dest)
in = fopen(src, "rb");
if(in == NULL) {
- return(1);
+ return 1;
}
out = fopen(dest, "wb");
if(out == NULL) {
fclose(in);
- return(1);
+ return 1;
}
CALLOC(buf, (size_t)CPBUFSIZE, (size_t)1, ret = 1; goto cleanup;);
@@ -174,7 +174,7 @@ cleanup:
fclose(in);
fclose(out);
FREE(buf);
- return(ret);
+ return ret;
}
/* Trim whitespace and newlines from a string
@@ -185,7 +185,7 @@ char *_alpm_strtrim(char *str)
if(*str == '\0') {
/* string is empty, so we're done. */
- return(str);
+ return str;
}
while(isspace((unsigned char)*pch)) {
@@ -197,7 +197,7 @@ char *_alpm_strtrim(char *str)
/* check if there wasn't anything but whitespace in the string. */
if(*str == '\0') {
- return(str);
+ return str;
}
pch = (str + (strlen(str) - 1));
@@ -206,7 +206,7 @@ char *_alpm_strtrim(char *str)
}
*++pch = '\0';
- return(str);
+ return str;
}
/* Compression functions */
@@ -224,12 +224,12 @@ int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn)
alpm_list_t *list = NULL;
int ret = 0;
if(fn == NULL) {
- return(1);
+ return 1;
}
list = alpm_list_add(list, (void *)fn);
ret = _alpm_unpack(archive, prefix, list, 1);
alpm_list_free(list);
- return(ret);
+ return ret;
}
/**
@@ -340,7 +340,7 @@ cleanup:
if(restore_cwd && chdir(cwd) != 0) {
_alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
}
- return(ret);
+ return ret;
}
/* does the same thing as 'rm -rf' */
@@ -355,18 +355,18 @@ int _alpm_rmrf(const char *path)
if(_alpm_lstat(path, &st) == 0) {
if(!S_ISDIR(st.st_mode)) {
if(!unlink(path)) {
- return(0);
+ return 0;
} else {
if(errno == ENOENT) {
- return(0);
+ return 0;
} else {
- return(1);
+ return 1;
}
}
} else {
dirp = opendir(path);
if(!dirp) {
- return(1);
+ return 1;
}
for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if(dp->d_ino) {
@@ -381,9 +381,9 @@ int _alpm_rmrf(const char *path)
errflag++;
}
}
- return(errflag);
+ return errflag;
}
- return(0);
+ return 0;
}
int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
@@ -414,7 +414,7 @@ int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
fflush(f);
}
- return(ret);
+ return ret;
}
int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
@@ -531,7 +531,7 @@ cleanup:
_alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
}
- return(retval);
+ return retval;
}
int _alpm_ldconfig(const char *root)
@@ -549,14 +549,14 @@ int _alpm_ldconfig(const char *root)
}
}
- return(0);
+ return 0;
}
/* Helper function for comparing strings using the
* alpm "compare func" signature */
int _alpm_str_cmp(const void *s1, const void *s2)
{
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
/** Find a filename in a registered alpm cachedir.
@@ -577,7 +577,7 @@ char *_alpm_filecache_find(const char* filename)
if(stat(path, &buf) == 0 && S_ISREG(buf.st_mode)) {
retpath = strdup(path);
_alpm_log(PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
- return(retpath);
+ return retpath;
}
}
/* package wasn't found in any cachedir */
@@ -603,11 +603,11 @@ const char *_alpm_filecache_setup(void)
cachedir);
if(_alpm_makepath(cachedir) == 0) {
_alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
- return(cachedir);
+ return cachedir;
}
} else if(S_ISDIR(buf.st_mode) && (buf.st_mode & S_IWUSR)) {
_alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
- return(cachedir);
+ return cachedir;
}
}
@@ -616,7 +616,7 @@ const char *_alpm_filecache_setup(void)
alpm_option_set_cachedirs(tmp);
_alpm_log(PM_LOG_DEBUG, "using cachedir: %s", "/tmp/\n");
_alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
- return(alpm_list_getdata(tmp));
+ return alpm_list_getdata(tmp);
}
/** lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink.
@@ -640,7 +640,7 @@ int _alpm_lstat(const char *path, struct stat *buf)
ret = lstat(newpath, buf);
FREE(newpath);
- return(ret);
+ return ret;
}
#ifdef HAVE_LIBSSL
@@ -651,11 +651,11 @@ static int md5_file(const char *path, unsigned char output[16])
MD5_CTX ctx;
unsigned char *buf;
- CALLOC(buf, 8192, sizeof(unsigned char), return(1));
+ CALLOC(buf, 8192, sizeof(unsigned char), RET_ERR(PM_ERR_MEMORY, 1));
if((f = fopen(path, "rb")) == NULL) {
free(buf);
- return(1);
+ return 1;
}
MD5_Init(&ctx);
@@ -671,11 +671,11 @@ static int md5_file(const char *path, unsigned char output[16])
if(ferror(f) != 0) {
fclose(f);
- return(2);
+ return 2;
}
fclose(f);
- return(0);
+ return 0;
}
#endif
@@ -692,7 +692,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
ALPM_LOG_FUNC;
- ASSERT(filename != NULL, return(NULL));
+ ASSERT(filename != NULL, return NULL);
/* allocate 32 chars plus 1 for null */
md5sum = calloc(33, sizeof(char));
@@ -711,7 +711,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
md5sum[32] = '\0';
_alpm_log(PM_LOG_DEBUG, "md5(%s) = %s\n", filename, md5sum);
- return(md5sum);
+ return md5sum;
}
int _alpm_test_md5sum(const char *filepath, const char *md5sum)
@@ -730,7 +730,7 @@ int _alpm_test_md5sum(const char *filepath, const char *md5sum)
}
FREE(md5sum2);
- return(ret);
+ return ret;
}
/* Note: does NOT handle sparse files on purpose for speed. */
@@ -803,7 +803,7 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
b->line_offset[len] = '\0';
b->block_offset = ++i;
/* this is the main return point; from here you can read b->line */
- return(ARCHIVE_OK);
+ return ARCHIVE_OK;
} else {
/* we've looked through the whole block but no newline, copy it */
size_t len = (size_t)(b->block + b->block_size - b->block_offset);
@@ -818,7 +818,7 @@ cleanup:
int ret = b->ret;
FREE(b->line);
memset(b, 0, sizeof(b));
- return(ret);
+ return ret;
}
}
@@ -832,7 +832,7 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg)
const char *version, *end;
if(target == NULL || pkg == NULL) {
- return(-1);
+ return -1;
}
end = target + strlen(target);
@@ -846,7 +846,7 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg)
for(version = end - 1; *version && *version != '-'; version--);
for(version = version - 1; *version && *version != '-'; version--);
if(*version != '-' || version == target) {
- return(-1);
+ return -1;
}
/* copy into fields and return */
@@ -864,7 +864,7 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg)
STRNDUP(pkg->name, target, version - target, RET_ERR(PM_ERR_MEMORY, -1));
pkg->name_hash = _alpm_hash_sdbm(pkg->name);
- return(0);
+ return 0;
}
/**
@@ -879,13 +879,13 @@ unsigned long _alpm_hash_sdbm(const char *str)
int c;
if(!str) {
- return(hash);
+ return hash;
}
while((c = *str++)) {
hash = c + (hash << 6) + (hash << 16) - hash;
}
- return(hash);
+ return hash;
}
long _alpm_parsedate(const char *line)
@@ -896,9 +896,9 @@ long _alpm_parsedate(const char *line)
setlocale(LC_TIME, "C");
strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm);
setlocale(LC_TIME, "");
- return(mktime(&tmp_tm));
+ return mktime(&tmp_tm);
}
- return(atol(line));
+ return atol(line);
}
#ifndef HAVE_STRNDUP
@@ -907,7 +907,7 @@ static size_t strnlen(const char *s, size_t max)
{
register const char *p;
for(p = s; *p && max--; ++p);
- return(p - s);
+ return (p - s);
}
char *strndup(const char *s, size_t n)
@@ -919,7 +919,7 @@ char *strndup(const char *s, size_t n)
return NULL;
new[len] = '\0';
- return (char *) memcpy(new, s, len);
+ return (char *)memcpy(new, s, len);
}
#endif
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 3232f004..1816e360 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -36,6 +36,8 @@
#include <time.h>
#include <sys/stat.h> /* struct stat */
#include <archive.h> /* struct archive */
+#include <math.h> /* fabs */
+#include <float.h> /* DBL_EPSILON */
#ifdef ENABLE_NLS
#include <libintl.h> /* here so it doesn't need to be included elsewhere */
@@ -59,7 +61,9 @@
#define RET_ERR(err, ret) do { pm_errno = (err); \
_alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
- return(ret); } while(0)
+ return (ret); } while(0)
+
+#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
/**
* Used as a buffer/state holder for _alpm_archive_fgets().
diff --git a/lib/libalpm/version.c b/lib/libalpm/version.c
index eba66210..9f3a9b71 100644
--- a/lib/libalpm/version.c
+++ b/lib/libalpm/version.c
@@ -93,7 +93,7 @@ static int rpmvercmp(const char *a, const char *b)
int ret = 0;
/* easy comparison to see if versions are identical */
- if(strcmp(a, b) == 0) return(0);
+ if(strcmp(a, b) == 0) return 0;
str1 = strdup(a);
str2 = strdup(b);
@@ -209,7 +209,7 @@ static int rpmvercmp(const char *a, const char *b)
cleanup:
free(str1);
free(str2);
- return(ret);
+ return ret;
}
/** Compare two version strings and determine which one is 'newer'.
@@ -235,15 +235,15 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
/* ensure our strings are not null */
if(!a && !b) {
- return(0);
+ return 0;
} else if(!a) {
- return(-1);
+ return -1;
} else if(!b) {
- return(1);
+ return 1;
}
/* another quick shortcut- if full version specs are equal */
if(strcmp(a, b) == 0) {
- return(0);
+ return 0;
}
/* Parse both versions into [epoch:]version[-release] triplets. We probably
@@ -266,7 +266,7 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
free(full1);
free(full2);
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/m4/libcurl.m4 b/m4/libcurl.m4
new file mode 100644
index 00000000..01a0575c
--- /dev/null
+++ b/m4/libcurl.m4
@@ -0,0 +1,250 @@
+# LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION],
+# [ACTION-IF-YES], [ACTION-IF-NO])
+# ----------------------------------------------------------
+# David Shaw <dshaw@jabberwocky.com> May-09-2006
+#
+# Checks for libcurl. DEFAULT-ACTION is the string yes or no to
+# specify whether to default to --with-libcurl or --without-libcurl.
+# If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the
+# minimum version of libcurl to accept. Pass the version as a regular
+# version number like 7.10.1. If not supplied, any version is
+# accepted. ACTION-IF-YES is a list of shell commands to run if
+# libcurl was successfully found and passed the various tests.
+# ACTION-IF-NO is a list of shell commands that are run otherwise.
+# Note that using --without-libcurl does run ACTION-IF-NO.
+#
+# This macro #defines HAVE_LIBCURL if a working libcurl setup is
+# found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary
+# values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are
+# the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy
+# where yyy are the various protocols supported by libcurl. Both xxx
+# and yyy are capitalized. See the list of AH_TEMPLATEs at the top of
+# the macro for the complete list of possible defines. Shell
+# variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also
+# defined to 'yes' for those features and protocols that were found.
+# Note that xxx and yyy keep the same capitalization as in the
+# curl-config list (e.g. it's "HTTP" and not "http").
+#
+# Users may override the detected values by doing something like:
+# LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure
+#
+# For the sake of sanity, this macro assumes that any libcurl that is
+# found is after version 7.7.2, the first version that included the
+# curl-config script. Note that it is very important for people
+# packaging binary versions of libcurl to include this script!
+# Without curl-config, we can only guess what protocols are available,
+# or use curl_version_info to figure it out at runtime.
+
+AC_DEFUN([LIBCURL_CHECK_CONFIG],
+[
+ AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
+ AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
+ AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
+ AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
+ AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
+ AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
+ AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
+ AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
+
+ AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_RTSP],[Defined if libcurl supports RTSP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_POP3],[Defined if libcurl supports POP3])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_IMAP],[Defined if libcurl supports IMAP])
+ AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP])
+
+ AC_ARG_WITH(libcurl,
+ AC_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]),
+ [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
+
+ if test "$_libcurl_with" != "no" ; then
+
+ AC_PROG_AWK
+
+ _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
+
+ _libcurl_try_link=yes
+
+ if test -d "$_libcurl_with" ; then
+ LIBCURL_CPPFLAGS="-I$withval/include"
+ _libcurl_ldflags="-L$withval/lib"
+ AC_PATH_PROG([_libcurl_config],[curl-config],[],
+ ["$withval/bin"])
+ else
+ AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH])
+ fi
+
+ if test x$_libcurl_config != "x" ; then
+ AC_CACHE_CHECK([for the version of libcurl],
+ [libcurl_cv_lib_curl_version],
+ [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
+
+ _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
+ _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
+
+ if test $_libcurl_wanted -gt 0 ; then
+ AC_CACHE_CHECK([for libcurl >= version $2],
+ [libcurl_cv_lib_version_ok],
+ [
+ if test $_libcurl_version -ge $_libcurl_wanted ; then
+ libcurl_cv_lib_version_ok=yes
+ else
+ libcurl_cv_lib_version_ok=no
+ fi
+ ])
+ fi
+
+ if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
+ if test x"$LIBCURL_CPPFLAGS" = "x" ; then
+ LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
+ fi
+ if test x"$LIBCURL" = "x" ; then
+ LIBCURL=`$_libcurl_config --libs`
+
+ # This is so silly, but Apple actually has a bug in their
+ # curl-config script. Fixed in Tiger, but there are still
+ # lots of Panther installs around.
+ case "${host}" in
+ powerpc-apple-darwin7*)
+ LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
+ ;;
+ esac
+ fi
+
+ # All curl-config scripts support --feature
+ _libcurl_features=`$_libcurl_config --feature`
+
+ # Is it modern enough to have --protocols? (7.12.4)
+ if test $_libcurl_version -ge 461828 ; then
+ _libcurl_protocols=`$_libcurl_config --protocols`
+ fi
+ else
+ _libcurl_try_link=no
+ fi
+
+ unset _libcurl_wanted
+ fi
+
+ if test $_libcurl_try_link = yes ; then
+
+ # we didn't find curl-config, so let's see if the user-supplied
+ # link line (or failing that, "-lcurl") is enough.
+ LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"}
+
+ AC_CACHE_CHECK([whether libcurl is usable],
+ [libcurl_cv_lib_curl_usable],
+ [
+ _libcurl_save_cppflags=$CPPFLAGS
+ CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
+ _libcurl_save_libs=$LIBS
+ LIBS="$LIBCURL $LIBS"
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <curl/curl.h>],[
+/* Try and use a few common options to force a failure if we are
+ missing symbols or can't link. */
+int x;
+curl_easy_setopt(NULL,CURLOPT_URL,NULL);
+x=CURL_ERROR_SIZE;
+x=CURLOPT_WRITEFUNCTION;
+x=CURLOPT_FILE;
+x=CURLOPT_ERRORBUFFER;
+x=CURLOPT_STDERR;
+x=CURLOPT_VERBOSE;
+])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
+
+ CPPFLAGS=$_libcurl_save_cppflags
+ LIBS=$_libcurl_save_libs
+ unset _libcurl_save_cppflags
+ unset _libcurl_save_libs
+ ])
+
+ if test $libcurl_cv_lib_curl_usable = yes ; then
+
+ # Does curl_free() exist in this version of libcurl?
+ # If not, fake it with free()
+
+ _libcurl_save_cppflags=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
+ _libcurl_save_libs=$LIBS
+ LIBS="$LIBS $LIBCURL"
+
+ AC_CHECK_FUNC(curl_free,,
+ AC_DEFINE(curl_free,free,
+ [Define curl_free() as free() if our version of curl lacks curl_free.]))
+
+ CPPFLAGS=$_libcurl_save_cppflags
+ LIBS=$_libcurl_save_libs
+ unset _libcurl_save_cppflags
+ unset _libcurl_save_libs
+
+ AC_DEFINE(HAVE_LIBCURL,1,
+ [Define to 1 if you have a functional curl library.])
+ AC_SUBST(LIBCURL_CPPFLAGS)
+ AC_SUBST(LIBCURL)
+
+ for _libcurl_feature in $_libcurl_features ; do
+ AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
+ eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
+ done
+
+ if test "x$_libcurl_protocols" = "x" ; then
+
+ # We don't have --protocols, so just assume that all
+ # protocols are available
+ _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP"
+
+ if test x$libcurl_feature_SSL = xyes ; then
+ _libcurl_protocols="$_libcurl_protocols HTTPS"
+
+ # FTPS wasn't standards-compliant until version
+ # 7.11.0 (0x070b00 == 461568)
+ if test $_libcurl_version -ge 461568; then
+ _libcurl_protocols="$_libcurl_protocols FTPS"
+ fi
+ fi
+
+ # RTSP, IMAP, POP3 and SMTP were added in
+ # 7.20.0 (0x071400 == 463872)
+ if test $_libcurl_version -ge 463872; then
+ _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP"
+ fi
+ fi
+
+ for _libcurl_protocol in $_libcurl_protocols ; do
+ AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
+ eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
+ done
+ else
+ unset LIBCURL
+ unset LIBCURL_CPPFLAGS
+ fi
+ fi
+
+ unset _libcurl_try_link
+ unset _libcurl_version_parse
+ unset _libcurl_config
+ unset _libcurl_feature
+ unset _libcurl_features
+ unset _libcurl_protocol
+ unset _libcurl_protocols
+ unset _libcurl_version
+ unset _libcurl_ldflags
+ fi
+
+ if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
+ # This is the IF-NO path
+ ifelse([$4],,:,[$4])
+ else
+ # This is the IF-YES path
+ ifelse([$3],,:,[$3])
+ fi
+
+ unset _libcurl_with
+])dnl
diff --git a/scripts/.gitignore b/scripts/.gitignore
index fe4616f2..927b14c8 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -5,3 +5,4 @@ rankmirrors
repo-add
repo-remove
pkgdelta
+pacman-key
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index ae6ce366..7c64e81c 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -8,6 +8,7 @@ bin_SCRIPTS = \
OURSCRIPTS = \
makepkg \
pacman-db-upgrade \
+ pacman-key \
pacman-optimize \
pkgdelta \
rankmirrors \
@@ -16,6 +17,7 @@ OURSCRIPTS = \
EXTRA_DIST = \
makepkg.sh.in \
pacman-db-upgrade.sh.in \
+ pacman-key.sh.in \
pacman-optimize.sh.in \
pkgdelta.sh.in \
rankmirrors.sh.in \
@@ -64,6 +66,7 @@ $(OURSCRIPTS): Makefile
makepkg: $(srcdir)/makepkg.sh.in
pacman-db-upgrade: $(srcdir)/pacman-db-upgrade.sh.in
+pacman-key: ${srcdir}/pacman-key.sh.in
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
pkgdelta: $(srcdir)/pkgdelta.sh.in
rankmirrors: $(srcdir)/rankmirrors.sh.in
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index eb7c3701..143d48fc 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -392,7 +392,7 @@ run_pacman() {
local cmd
printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
- if [ "$(type -p sudo)" ]; then
+ if type -p sudo >/dev/null; then
cmd="sudo $cmd"
else
cmd="su -c '$cmd'"
@@ -1068,6 +1068,9 @@ create_package() {
local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
local ret=0
+ [[ -f $pkg_file ]] && rm -f "$pkg_file"
+ [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
+
# when fileglobbing, we want * in an empty directory to expand to
# the null string rather than itself
shopt -s nullglob
@@ -1089,9 +1092,12 @@ create_package() {
exit 1 # TODO: error code
fi
+ create_signature "$pkg_file"
+
if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
ret=$?
+ [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
fi
if (( ret )); then
@@ -1099,6 +1105,25 @@ create_package() {
fi
}
+create_signature() {
+ if [[ $(check_buildenv sign) != "y" ]]; then
+ return
+ fi
+ local ret=0
+ local filename="$1"
+ msg "$(gettext "Signing package...")"
+ if ! type -p gpg >/dev/null; then
+ error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+ gpg --detach-sign --use-agent "$filename" || ret=$?
+ if (( ! ret )); then
+ msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
+ else
+ warning "$(gettext "Failed to sign package file.")"
+ fi
+}
+
create_srcpackage() {
cd "$startdir"
@@ -1688,6 +1713,8 @@ done
[[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
[[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
[[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
+[[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
+[[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
# default config is makepkg.conf
MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
@@ -1751,6 +1778,8 @@ fi
SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
+PKGEXT=${_PKGEXT:-$PKGEXT}
+SRCEXT=${_SRCEXT:-$SRCEXT}
if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
# The '\\0' is here to prevent gettext from thinking --holdver is an option
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
new file mode 100644
index 00000000..5746e64f
--- /dev/null
+++ b/scripts/pacman-key.sh.in
@@ -0,0 +1,320 @@
+#!@BASH_SHELL@ -e
+#
+# pacman-key - manages pacman's keyring
+# Based on apt-key, from Debian
+# @configure_input@
+#
+# Copyright (c) 2010 - Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+myver="@PACKAGE_VERSION@"
+
+msg() {
+ local mesg=$1; shift
+ printf "==> ${mesg}\n" "$@" >&1
+}
+
+msg2() {
+ (( QUIET )) && return
+ local mesg=$1; shift
+ printf " -> ${mesg}\n" "$@" >&1
+}
+
+warning() {
+ local mesg=$1; shift
+ printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
+}
+
+error() {
+ local mesg=$1; shift
+ printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
+}
+
+usage() {
+ printf "pacman-key (pacman) %s\n" ${myver}
+ echo
+ printf "$(gettext "Usage: %s [options] <command> [arguments]")\n" $(basename $0)
+ echo
+ echo "$(gettext "Manage pacman's list of trusted keys")"
+ echo
+ echo "$(gettext "Options must be placed before commands. The available options are:")"
+ printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$CONFIG"
+ echo "$(gettext " --gpgdir Set an alternate directory for gnupg")"
+ echo
+ echo "$(gettext "The available commands are:")"
+ echo "$(gettext " -a, --add [<file(s)>] Add the specified keys (empty for stdin)")"
+ echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")"
+ echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")"
+ echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")"
+ echo "$(gettext " -h, --help This help")"
+ echo "$(gettext " -l, --list List keys")"
+ echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")"
+ echo "$(gettext " -t, --trust <keyid(s)> Set the trust level of the given keyids")"
+ echo "$(gettext " -u, --updatedb Update the trustdb of pacman")"
+ echo "$(gettext " -V, --version Show program version")"
+ echo "$(gettext " --adv <params> Use pacman's keyring with advanced gpg commands")"
+ printf "$(gettext " --reload Reload the default keys")"
+ echo
+}
+
+version() {
+ printf "pacman-key (pacman) %s\n" "${myver}"
+ printf "$(gettext "\
+Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
+This is free software; see the source for copying conditions.\n\
+There is NO WARRANTY, to the extent permitted by law.\n")"
+}
+
+find_config() {
+ # Prints on stdin the values of all the options from the configuration file that
+ # are associated with the first parameter of this function.
+ # The option names are stripped
+ grep -e "^[[:blank:]]*$1[[:blank:]]*=.*" "$CONFIG" | cut -d= -f 2-
+}
+
+reload_keyring() {
+ local PACMAN_SHARE_DIR='@prefix@/share/pacman'
+ local GPG_NOKEYRING="gpg --batch --quiet --ignore-time-conflict --no-options --no-default-keyring --homedir ${PACMAN_KEYRING_DIR}"
+
+ # Variable used for iterating on keyrings
+ local key
+ local key_id
+
+ # Keyring with keys to be added to the keyring
+ local ADDED_KEYS="${PACMAN_SHARE_DIR}/addedkeys.gpg"
+
+ # Keyring with keys that were deprecated and will eventually be deleted
+ local DEPRECATED_KEYS="${PACMAN_SHARE_DIR}/deprecatedkeys.gpg"
+
+ # List of keys removed from the keyring. This file is not a keyring, unlike the others.
+ # It is a textual list of values that gpg recogniezes as identifiers for keys.
+ local REMOVED_KEYS="${PACMAN_SHARE_DIR}/removedkeys"
+
+ # Verify signatures of related files, if they exist
+ if [[ -r "${ADDED_KEYS}" ]]; then
+ msg "$(gettext "Verifying official keys file signature...")"
+ if ! ${GPG_PACMAN} --quiet --batch --verify "${ADDED_KEYS}.sig" 1>/dev/null; then
+ error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}"
+ exit 1
+ fi
+ fi
+
+ if [[ -r "${DEPRECATED_KEYS}" ]]; then
+ msg "$(gettext "Verifying deprecated keys file signature...")"
+ if ! ${GPG_PACMAN} --quiet --batch --verify "${DEPRECATED_KEYS}.sig" 1>/dev/null; then
+ error "$(gettext "The signature of file %s is not valid.")" "${DEPRECATED_KEYS}"
+ exit 1
+ fi
+ fi
+
+ if [[ -r "${REMOVED_KEYS}" ]]; then
+ msg "$(gettext "Verifying deleted keys file signature...")"
+ if ! ${GPG_PACMAN} --quiet --batch --verify "${REMOVED_KEYS}.sig"; then
+ error "$(gettext "The signature of file %s is not valid.")" "${REMOVED_KEYS}"
+ exit 1
+ fi
+ fi
+
+ # Read the key ids to an array. The conversion from whatever is inside the file
+ # to key ids is important, because key ids are the only guarantee of identification
+ # for the keys.
+ local -A removed_ids
+ if [[ -r "${REMOVED_KEYS}" ]]; then
+ while read key; do
+ local key_values name
+ key_values=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5,10 --output-delimiter=' ')
+ if [[ -n $key_values ]]; then
+ # The first word is the key_id
+ key_id=${key_values%% *}
+ # the rest if the name of the owner
+ name=${key_values#* }
+ if [[ -n ${key_id} ]]; then
+ # Mark this key to be deleted
+ removed_ids[$key_id]="$name"
+ fi
+ fi
+ done < "${REMOVED_KEYS}"
+ fi
+
+ # List of keys that must be kept installed, even if in the list of keys to be removed
+ local HOLD_KEYS=$(find_config "HoldKeys")
+
+ # Remove the keys that must be kept from the set of keys that should be removed
+ if [[ -n ${HOLD_KEYS} ]]; then
+ for key in ${HOLD_KEYS}; do
+ key_id=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5)
+ if [[ -n "${removed_ids[$key_id]}" ]]; then
+ unset removed_ids[$key_id]
+ fi
+ done
+ fi
+
+ # Add keys from the current set of keys from pacman-keyring package. The web of trust will
+ # be updated automatically.
+ if [[ -r "${ADDED_KEYS}" ]]; then
+ msg "$(gettext "Appending official keys...")"
+ local add_keys=$(${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5)
+ for key_id in ${add_keys}; do
+ # There is no point in adding a key that will be deleted right after
+ if [[ -z "${removed_ids[$key_id]}" ]]; then
+ ${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import
+ fi
+ done
+ fi
+
+ if [[ -r "${DEPRECATED_KEYS}" ]]; then
+ msg "$(gettext "Appending deprecated keys...")"
+ local add_keys=$(${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5)
+ for key_id in ${add_keys}; do
+ # There is no point in adding a key that will be deleted right after
+ if [[ -z "${removed_ids[$key_id]}" ]]; then
+ ${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import
+ fi
+ done
+ fi
+
+ # Remove the keys not marked to keep
+ if (( ${#removed_ids[@]} > 0 )); then
+ msg "$(gettext "Removing deleted keys from keyring...")"
+ for key_id in "${!removed_ids[@]}"; do
+ echo " removing key $key_id - ${removed_ids[$key_id]}"
+ ${GPG_PACMAN} --quiet --batch --yes --delete-key "${key_id}"
+ done
+ fi
+
+ # Update trustdb, just to be sure
+ msg "$(gettext "Updating trust database...")"
+ ${GPG_PACMAN} --batch --check-trustdb
+}
+
+# PROGRAM START
+if ! type gettext &>/dev/null; then
+ gettext() {
+ echo "$@"
+ }
+fi
+
+if [[ $1 != "--version" && $1 != "-V" && $1 != "--help" && $1 != "-h" && $1 != "" ]]; then
+ if type -p gpg >/dev/null 2>&1 = 1; then
+ error "$(gettext "gnupg does not seem to be installed.")"
+ msg2 "$(gettext "pacman-key requires gnupg for most operations.")"
+ exit 1
+ elif (( EUID != 0 )); then
+ error "$(gettext "pacman-key needs to be run as root.")"
+ exit 1
+ fi
+fi
+
+# Parse global options
+CONFIG="@sysconfdir@/pacman.conf"
+PACMAN_KEYRING_DIR="@sysconfdir@/pacman.d/gnupg"
+while [[ $1 =~ ^--(config|gpgdir)$ ]]; do
+ case "$1" in
+ --config) shift; CONFIG="$1" ;;
+ --gpgdir) shift; PACMAN_KEYRING_DIR="$1" ;;
+ esac
+ shift
+done
+
+if [[ ! -r "${CONFIG}" ]]; then
+ error "$(gettext "%s not found.")" "$CONFIG"
+ exit 1
+fi
+
+# Read GPGDIR from $CONFIG.
+# The pattern is: any spaces or tabs, GPGDir, any spaces or tabs, equal sign
+# and the rest of the line. The string is splitted after the first occurrence of =
+if [[ GPGDIR=$(find_config "GPGDir") == 0 ]]; then
+ PACMAN_KEYRING_DIR="${GPGDIR}"
+fi
+GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR}"
+
+# Parse and execute command
+command="$1"
+if [[ -z "${command}" ]]; then
+ usage
+ exit 1
+fi
+shift
+
+case "${command}" in
+ -a|--add)
+ # If there is no extra parameter, gpg will read stdin
+ ${GPG_PACMAN} --quiet --batch --import "$@"
+ ;;
+ -d|--del)
+ if (( $# == 0 )); then
+ error "$(gettext "You need to specify at least one key identifier")"
+ exit 1
+ fi
+ ${GPG_PACMAN} --quiet --batch --delete-key --yes "$@"
+ ;;
+ -u|--updatedb)
+ ${GPG_PACMAN} --batch --check-trustdb
+ ;;
+ --reload)
+ reload_keyring
+ ;;
+ -l|--list)
+ ${GPG_PACMAN} --batch --list-sigs "$@"
+ ;;
+ -f|--finger)
+ ${GPG_PACMAN} --batch --fingerprint "$@"
+ ;;
+ -e|--export)
+ ${GPG_PACMAN} --armor --export "$@"
+ ;;
+ -r|--receive)
+ if (( $# < 2 )); then
+ error "$(gettext "You need to specify the keyserver and at least one key identifier")"
+ exit 1
+ fi
+ keyserver="$1"
+ shift
+ ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "$@"
+ ;;
+ -t|--trust)
+ if (( $# == 0 )); then
+ error "$(gettext "You need to specify at least one key identifier")"
+ exit 1
+ fi
+ while (( $# > 0 )); do
+ # Verify if the key exists in pacman's keyring
+ if ${GPG_PACMAN} --list-keys "$1" > /dev/null 2>&1; then
+ ${GPG_PACMAN} --edit-key "$1"
+ else
+ error "$(gettext "The key identified by %s doesn't exist")" "$1"
+ exit 1
+ fi
+ shift
+ done
+ ;;
+ --adv)
+ msg "$(gettext "Executing: %s ")$*" "${GPG_PACMAN}"
+ ${GPG_PACMAN} "$@" || ret=$?
+ exit $ret
+ ;;
+ -h|--help)
+ usage; exit 0 ;;
+ -V|--version)
+ version; exit 0 ;;
+ *)
+ usage; exit 1 ;;
+esac
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index dfc93974..1c0347cc 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -30,6 +30,8 @@ confdir='@sysconfdir@'
QUIET=0
DELTA=0
WITHFILES=0
+SIGN=0
+VERIFY=0
REPO_DB_FILE=
LOCKFILE=
CLEAN_LOCK=0
@@ -62,7 +64,7 @@ error() {
# print usage instructions
usage() {
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
- printf "$(gettext "Usage: repo-add [-d] [-f] [-q] <path-to-db> <package|delta> ...\n")"
+ printf "$(gettext "Usage: repo-add [-d] [-f] [-q] [-s] [-v] <path-to-db> <package|delta> ...\n")"
printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\
@@ -79,7 +81,8 @@ Use the -d/--delta flag to automatically generate and add a delta file\n\
between the old entry and the new one, if the old package file is found\n\
next to the new one.\n\n")"
printf "$(gettext "\
-Use the -f/--files flag to update a database including file entries.\n\n")"
+Use the -f/--files flag to update a database including file entries.\n\n
+See repo-add(8) for more details and descriptions of the available options.\n\n")"
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
}
@@ -184,14 +187,56 @@ db_remove_delta()
return 1
} # end db_remove_delta
+# sign the package database once repackaged
+create_signature() {
+ (( ! SIGN )) && return
+ local dbfile="$1"
+ local ret=0
+ msg "$(gettext "Signing database...")"
+ if ! type -p gpg; then
+ error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+ gpg --detach-sign --use-agent "$dbfile" || ret=$?
+ if (( ! ret )); then
+ msg2 "$(gettext "Created signature file %s.")" "$dbfile.sig"
+ else
+ warning "$(gettext "Failed to sign package database.")"
+ fi
+}
+
+# verify the existing package database signature
+verify_signature() {
+ (( ! VERIFY )) && return
+ local dbfile="$1"
+ local ret=0
+ msg "$(gettext "Verifying database signature...")"
+ if ! type -p gpg; then
+ error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+ if [[ ! -f $dbfile.sig ]]; then
+ warning "$(gettext "No existing signature found, skipping verification.")"
+ return
+ fi
+ gpg --verify "$dbfile.sig" || ret=$?
+ if (( ! ret )); then
+ msg2 "$(gettext "Database signature file verified.")"
+ else
+ error "$(gettext "Database signature was NOT valid!")"
+ exit 1
+ fi
+}
+
# write an entry to the pacman database
# arg1 - path to package
db_write_entry()
{
# blank out all variables
local pkgfile="$1"
- local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager \
- _groups _licenses _replaces _depends _conflicts _provides _optdepends
+ local pkgname pkgver pkgdesc csize size url arch builddate packager \
+ _groups _licenses _replaces _depends _conflicts _provides _optdepends \
+ md5sum sha256sum pgpsig
local OLDIFS="$IFS"
# IFS (field separator) is only the newline character
@@ -219,10 +264,19 @@ db_write_entry()
IFS=$OLDIFS
- # get md5sum and compressed size of package
+ csize=$(@SIZECMD@ "$pkgfile")
+
+ # compute checksums
+ msg2 "$(gettext "Computing checksums...")"
md5sum="$(openssl dgst -md5 "$pkgfile")"
md5sum="${md5sum##* }"
- csize=$(@SIZECMD@ "$pkgfile")
+ sha256sum="$(openssl dgst -sha256 "$pkgfile")"
+ sha256sum="${sha256sum##* }"
+
+ # compute base64'd PGP signature
+ if [[ -f "$pkgfile.sig" ]]; then
+ pgpsig=$(openssl base64 -in "$pkgfile.sig" | tr -d '\n')
+ fi
# ensure $pkgname and $pkgver variables were found
if [[ -z $pkgname || -z $pkgver ]]; then
@@ -264,9 +318,12 @@ db_write_entry()
[[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc
[[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc
- # compute checksums
- msg2 "$(gettext "Computing md5 checksums...")"
+ # add checksums
echo -e "%MD5SUM%\n$md5sum\n" >>desc
+ echo -e "%SHA256SUM%\n$sha256sum\n" >>desc
+
+ # add PGP sig
+ [[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc
[[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc
write_list_entry "LICENSE" "$_licenses" "desc"
@@ -352,6 +409,7 @@ check_repo_db()
exit 1
fi
fi
+ verify_signature "$REPO_DB_FILE"
msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir"
else
@@ -482,6 +540,8 @@ for arg in "$@"; do
-q|--quiet) QUIET=1;;
-d|--delta) DELTA=1;;
-f|--files) WITHFILES=1;;
+ -s|--sign) SIGN=1;;
+ -v|--verify) VERIFY=1;;
*)
if [[ -z $REPO_DB_FILE ]]; then
REPO_DB_FILE="$arg"
@@ -519,15 +579,24 @@ if (( success )); then
warning "$(gettext "No packages remain, creating empty database.")"
bsdtar -c${TAR_OPT}f "$filename" -T /dev/null
fi
+ create_signature "$filename"
+
popd >/dev/null
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ [[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig"
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
+ [[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
dblink="${REPO_DB_FILE%.tar.*}"
target=${REPO_DB_FILE##*/}
ln -sf "$target" "$dblink" 2>/dev/null || \
ln -f "$target" "$dblink" 2>/dev/null || \
cp "$REPO_DB_FILE" "$dblink"
+ if [[ -f "$target.sig" ]]; then
+ ln -sf "$target.sig" "$dblink.sig" 2>/dev/null || \
+ ln -f "$target.sig" "$dblink.sig" 2>/dev/null || \
+ cp "$REPO_DB_FILE.sig" "$dblink.sig"
+ fi
else
msg "$(gettext "No packages modified, nothing to do.")"
exit 1
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index 31e8b134..333b8193 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -1,6 +1,7 @@
# paths set at make time
conffile = ${sysconfdir}/pacman.conf
dbpath = ${localstatedir}/lib/pacman/
+gpgdir = ${sysconfdir}/pacman.d/gnupg/
cachedir = ${localstatedir}/cache/pacman/pkg/
logfile = ${localstatedir}/log/pacman.log
@@ -10,6 +11,7 @@ DEFS = -DLOCALEDIR=\"@localedir@\" \
-DCONFFILE=\"$(conffile)\" \
-DROOTDIR=\"$(ROOTDIR)\" \
-DDBPATH=\"$(dbpath)\" \
+ -DGPGDIR=\"$(gpgdir)\" \
-DCACHEDIR=\"$(cachedir)\" \
-DLOGFILE=\"$(logfile)\" \
@DEFS@
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 5edcc966..08c1cf3f 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -81,7 +81,7 @@ static double get_update_timediff(int first_call)
}
}
- return(retval);
+ return retval;
}
/* refactored from cb_trans_progress */
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index e2a168ee..69110ab9 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -38,7 +38,7 @@ config_t *config_new(void)
pm_fprintf(stderr, PM_LOG_ERROR,
_("malloc failure: could not allocate %zd bytes\n"),
sizeof(config_t));
- return(NULL);
+ return NULL;
}
/* defaults which may get overridden later */
newconfig->op = PM_OP_MAIN;
@@ -46,13 +46,13 @@ config_t *config_new(void)
/* CONFFILE is defined at compile-time */
newconfig->configfile = strdup(CONFFILE);
- return(newconfig);
+ return newconfig;
}
int config_free(config_t *oldconfig)
{
if(oldconfig == NULL) {
- return(-1);
+ return -1;
}
FREELIST(oldconfig->holdpkg);
@@ -66,7 +66,7 @@ int config_free(config_t *oldconfig)
free(oldconfig);
oldconfig = NULL;
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 92c379fc..bb11bab2 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -40,6 +40,7 @@ typedef struct __config_t {
char *rootdir;
char *dbpath;
char *logfile;
+ char *gpgdir;
/* TODO how to handle cachedirs? */
unsigned short op_q_isfile;
@@ -106,7 +107,8 @@ enum {
OP_NEEDED,
OP_ASEXPLICIT,
OP_ARCH,
- OP_PRINTFORMAT
+ OP_PRINTFORMAT,
+ OP_GPGDIR
};
/* clean method */
diff --git a/src/pacman/database.c b/src/pacman/database.c
index 36433f33..9d6edab5 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -47,7 +47,7 @@ int pacman_database(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
if(config->flags & PM_TRANS_FLAG_ALLDEPS) { /* --asdeps */
@@ -56,12 +56,12 @@ int pacman_database(alpm_list_t *targets)
reason = PM_PKG_REASON_EXPLICIT;
} else {
pm_printf(PM_LOG_ERROR, _("no install reason specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Lock database */
if(trans_init(0) == -1) {
- return(1);
+ return 1;
}
db_local = alpm_option_get_localdb();
@@ -82,9 +82,9 @@ int pacman_database(alpm_list_t *targets)
/* Unlock database */
if(trans_release() == -1) {
- return(1);
+ return 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 8895b487..cc1e565b 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -47,7 +47,7 @@ int pacman_deptest(alpm_list_t *targets)
}
if(deps == NULL) {
- return(0);
+ return 0;
}
for(i = deps; i; i = alpm_list_next(i)) {
@@ -56,7 +56,7 @@ int pacman_deptest(alpm_list_t *targets)
printf("%s\n", dep);
}
alpm_list_free(deps);
- return(127);
+ return 127;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 77a5ee72..d8dde695 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -173,7 +173,7 @@ static const char *get_backup_file_status(const char *root,
if(md5sum == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not calculate checksums for %s\n"), path);
- return(NULL);
+ return NULL;
}
/* if checksums don't match, file has been modified */
@@ -195,7 +195,7 @@ static const char *get_backup_file_status(const char *root,
ret = "UNKNOWN";
}
}
- return(ret);
+ return ret;
}
/* Display list of backup files and their modification states
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 0ad03540..eac9c9c6 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -66,9 +66,9 @@ static int options_cmp(const void *p1, const void *p2)
const char *s1 = p1;
const char *s2 = p2;
- if(s1 == s2) return(0);
- if(!s1) return(-1);
- if(!s2) return(1);
+ if(s1 == s2) return 0;
+ if(!s1) return -1;
+ if(!s2) return 1;
/* First skip all spaces in both strings */
while(isspace((unsigned char)*s1)) {
s1++;
@@ -87,15 +87,15 @@ static int options_cmp(const void *p1, const void *p2)
s2++;
} else if(*s2 == '-') {
/* s1 short, s2 long */
- return(-1);
+ return -1;
} else if(*s1 == '-') {
/* s1 long, s2 short */
- return(1);
+ return 1;
}
/* two short -> strcmp */
}
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
/** Display usage/syntax for the specified operation.
@@ -207,6 +207,7 @@ static void usage(int op, const char * const myname)
addlist(_(" --cachedir <dir> set an alternate package cache location\n"));
addlist(_(" --config <path> set an alternate configuration file\n"));
addlist(_(" --debug display debug messages\n"));
+ addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n"));
addlist(_(" --logfile <path> set an alternate log file\n"));
addlist(_(" --noconfirm do not ask for any confirmation\n"));
}
@@ -302,7 +303,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
do {
ret = write(fd, buf, count);
} while(ret == -1 && errno == EINTR);
- return(ret);
+ return ret;
}
/** Catches thrown signals. Performs necessary cleanup to ensure database is
@@ -390,6 +391,17 @@ static void setlibpaths(void)
}
}
+ /* Set GnuPG's home directory. This is not relative to rootdir, even if
+ * rootdir is defined. Reasoning: gpgdir contains configuration data. */
+ if(config->gpgdir) {
+ ret = alpm_option_set_signaturedir(config->gpgdir);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"),
+ config->gpgdir, alpm_strerrorlast());
+ cleanup(ret);
+ }
+ }
+
/* add a default cachedir if one wasn't specified */
if(alpm_option_get_cachedirs() == NULL) {
alpm_option_add_cachedir(CACHEDIR);
@@ -398,7 +410,7 @@ static void setlibpaths(void)
}
}
-#define check_optarg() if(!optarg) { return(1); }
+#define check_optarg() if(!optarg) { return 1; }
typedef void (*fn_add) (const char *s);
@@ -412,7 +424,7 @@ static int parsearg_util_addlist(fn_add fn)
fn((char *)alpm_list_getdata(item));
}
FREELIST(list);
- return(0);
+ return 0;
}
/** Helper function for parsing operation from command-line arguments.
@@ -449,9 +461,9 @@ static int parsearg_op(int opt, int dryrun)
if(dryrun) break;
config->help = 1; break;
default:
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
/** Helper functions for parsing command-line arguments.
@@ -472,7 +484,7 @@ static int parsearg_global(int opt)
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast());
- return(1);
+ return 1;
}
break;
case OP_CONFIG:
@@ -497,7 +509,7 @@ static int parsearg_global(int opt)
default:
pm_printf(PM_LOG_ERROR, _("'%s' is not a valid debug level\n"),
optarg);
- return(1);
+ return 1;
}
} else {
config->logmask |= PM_LOG_DEBUG;
@@ -505,6 +517,9 @@ static int parsearg_global(int opt)
/* progress bars get wonky with debug on, shut them off */
config->noprogressbar = 1;
break;
+ case OP_GPGDIR:
+ config->gpgdir = strdup(optarg);
+ break;
case OP_LOGFILE:
check_optarg();
config->logfile = strndup(optarg, PATH_MAX);
@@ -516,9 +531,9 @@ static int parsearg_global(int opt)
break;
case 'r': check_optarg(); config->rootdir = strdup(optarg); break;
case 'v': (config->verbose)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_database(int opt)
@@ -526,9 +541,9 @@ static int parsearg_database(int opt)
switch(opt) {
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_query(int opt)
@@ -548,9 +563,9 @@ static int parsearg_query(int opt)
case 's': config->op_q_search = 1; break;
case 't': config->op_q_unrequired = 1; break;
case 'u': config->op_q_upgrade = 1; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -R -U */
@@ -572,15 +587,15 @@ static int parsearg_trans(int opt)
check_optarg();
config->print_format = strdup(optarg);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_remove(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'c': config->flags |= PM_TRANS_FLAG_CASCADE; break;
case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
@@ -592,16 +607,16 @@ static int parsearg_remove(int opt)
}
break;
case 'u': config->flags |= PM_TRANS_FLAG_UNNEEDED; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -U */
static int parsearg_upgrade(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
@@ -612,15 +627,15 @@ static int parsearg_upgrade(int opt)
case OP_IGNOREGROUP:
parsearg_util_addlist(alpm_option_add_ignoregrp);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_sync(int opt)
{
if (parsearg_upgrade(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
case 'c': (config->op_s_clean)++; break;
@@ -636,9 +651,9 @@ static int parsearg_sync(int opt)
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'y': (config->op_s_sync)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/** Parse command-line arguments for each operation.
@@ -706,6 +721,7 @@ static int parseargs(int argc, char *argv[])
{"asexplicit", no_argument, 0, OP_ASEXPLICIT},
{"arch", required_argument, 0, OP_ARCH},
{"print-format", required_argument, 0, OP_PRINTFORMAT},
+ {"gpgdir", required_argument, 0, OP_GPGDIR},
{0, 0, 0, 0}
};
@@ -717,22 +733,22 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* unknown option, getopt printed an error */
- return(1);
+ return 1;
}
parsearg_op(opt, 0);
}
if(config->op == 0) {
pm_printf(PM_LOG_ERROR, _("only one operation may be used at a time\n"));
- return(1);
+ return 1;
}
if(config->help) {
usage(config->op, mbasename(argv[0]));
- return(2);
+ return 2;
}
if(config->version) {
version();
- return(2);
+ return 2;
}
/* parse all other options */
@@ -744,7 +760,7 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* this should have failed during first pass already */
- return(1);
+ return 1;
} else if(parsearg_op(opt, 1) == 0) {
/* opt is an operation */
continue;
@@ -780,7 +796,7 @@ static int parseargs(int argc, char *argv[])
if(result != 0) {
/* global option parsing failed, abort */
pm_printf(PM_LOG_ERROR, _("invalid option\n"));
- return(result);
+ return result;
}
}
@@ -790,7 +806,7 @@ static int parseargs(int argc, char *argv[])
optind++;
}
- return(0);
+ return 0;
}
/* helper for being used with setrepeatingoption */
@@ -843,7 +859,7 @@ static char *get_filename(const char *url) {
if(filename != NULL) {
filename++;
}
- return(filename);
+ return filename;
}
static char *get_destfile(const char *path, const char *filename) {
@@ -853,7 +869,7 @@ static char *get_destfile(const char *path, const char *filename) {
destfile = calloc(len, sizeof(char));
snprintf(destfile, len, "%s%s", path, filename);
- return(destfile);
+ return destfile;
}
static char *get_tempfile(const char *path, const char *filename) {
@@ -863,7 +879,7 @@ static char *get_tempfile(const char *path, const char *filename) {
tempfile = calloc(len, sizeof(char));
snprintf(tempfile, len, "%s%s.part", path, filename);
- return(tempfile);
+ return tempfile;
}
/** External fetch callback */
@@ -955,7 +971,7 @@ cleanup:
free(tempfile);
free(parsedcmd);
- return(ret);
+ return ret;
}
static int _parse_options(const char *key, char *value,
@@ -1013,7 +1029,7 @@ static int _parse_options(const char *key, char *value,
if(alpm_option_add_cachedir(value) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
value, alpm_strerrorlast());
- return(1);
+ return 1;
}
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", value);
} else if(strcmp(key, "RootDir") == 0) {
@@ -1022,6 +1038,11 @@ static int _parse_options(const char *key, char *value,
config->rootdir = strdup(value);
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", value);
}
+ } else if (strcmp(key, "GPGDir") == 0) {
+ if(!config->gpgdir) {
+ config->gpgdir = strdup(value);
+ pm_printf(PM_LOG_DEBUG, "config: gpgdir: %s\n", value);
+ }
} else if (strcmp(key, "LogFile") == 0) {
if(!config->logfile) {
config->logfile = strdup(value);
@@ -1041,7 +1062,7 @@ static int _parse_options(const char *key, char *value,
}
}
- return(0);
+ return 0;
}
static int _add_mirror(pmdb_t *db, char *value)
@@ -1060,7 +1081,7 @@ static int _add_mirror(pmdb_t *db, char *value)
free(temp);
pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
" variable, but no Architecture is defined.\n"), value);
- return(1);
+ return 1;
}
server = temp;
}
@@ -1070,11 +1091,11 @@ static int _add_mirror(pmdb_t *db, char *value)
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
dbname, server, alpm_strerrorlast());
free(server);
- return(1);
+ return 1;
}
free(server);
- return(0);
+ return 0;
}
/* The real parseconfig. Called with a null section argument by the publicly
@@ -1093,7 +1114,7 @@ static int _parseconfig(const char *file, const char *givensection,
fp = fopen(file, "r");
if(fp == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file);
- return(1);
+ return 1;
}
/* if we are passed a section, use it as our starting point */
@@ -1225,6 +1246,24 @@ static int _parseconfig(const char *file, const char *givensection,
ret = 1;
goto cleanup;
}
+ } else if(strcmp(key, "VerifySig") == 0) {
+ if (strcmp(value, "Always") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_ALWAYS);
+ } else if (strcmp(value, "Optional") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_OPTIONAL);
+ } else if (strcmp(value, "Never") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_NEVER);
+ } else {
+ pm_printf(PM_LOG_ERROR, _("invalid value for 'VerifySig' : '%s'\n"), value);
+ ret = 1;
+ goto cleanup;
+ }
+ if (ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("could not add pgp verify option to database '%s': %s (%s)\n"),
+ alpm_db_get_name(db), value, alpm_strerrorlast());
+ goto cleanup;
+ }
+ pm_printf(PM_LOG_DEBUG, "config: VerifySig for %s: %s\n",alpm_db_get_name(db), value);
} else {
pm_printf(PM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
@@ -1242,7 +1281,7 @@ cleanup:
/* call setlibpaths here to ensure we have called it at least once */
setlibpaths();
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
- return(ret);
+ return ret;
}
/** Parse a configuration file.
@@ -1252,7 +1291,7 @@ cleanup:
static int parseconfig(const char *file)
{
/* call the real parseconfig function with a null section & db argument */
- return(_parseconfig(file, NULL, NULL));
+ return _parseconfig(file, NULL, NULL);
}
/** print commandline to logfile
@@ -1345,6 +1384,7 @@ int main(int argc, char *argv[])
/* define paths to reasonable defaults */
alpm_option_set_root(ROOTDIR);
alpm_option_set_dbpath(DBPATH);
+ alpm_option_set_signaturedir(GPGDIR);
alpm_option_set_logfile(LOGFILE);
/* Priority of options:
@@ -1479,7 +1519,7 @@ int main(int argc, char *argv[])
cleanup(ret);
/* not reached */
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/query.c b/src/pacman/query.c
index bd23d466..d2bfe690 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -43,15 +43,15 @@ static char *resolve_path(const char *file)
str = calloc(PATH_MAX + 1, sizeof(char));
if(!str) {
- return(NULL);
+ return NULL;
}
if(!realpath(file, str)) {
free(str);
- return(NULL);
+ return NULL;
}
- return(str);
+ return str;
}
/* check if filename exists in PATH */
@@ -61,10 +61,10 @@ static int search_path(char **filename, struct stat *bufptr)
size_t flen;
if ((envpath = getenv("PATH")) == NULL) {
- return(-1);
+ return -1;
}
if ((envpath = envpathsplit = strdup(envpath)) == NULL) {
- return(-1);
+ return -1;
}
flen = strlen(*filename);
@@ -84,12 +84,12 @@ static int search_path(char **filename, struct stat *bufptr)
free(*filename);
*filename = fullname;
free(envpath);
- return(0);
+ return 0;
}
free(fullname);
}
free(envpath);
- return(-1);
+ return -1;
}
static int query_fileowner(alpm_list_t *targets)
@@ -105,7 +105,7 @@ static int query_fileowner(alpm_list_t *targets)
/* This code is here for safety only */
if(targets == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n"));
- return(1);
+ return 1;
}
/* Set up our root path buffer. We only need to copy the location of root in
@@ -232,7 +232,7 @@ static int query_search(alpm_list_t *targets)
freelist = 0;
}
if(searchlist == NULL) {
- return(1);
+ return 1;
}
for(i = searchlist; i; i = alpm_list_next(i)) {
@@ -280,7 +280,7 @@ static int query_search(alpm_list_t *targets)
if(freelist) {
alpm_list_free(searchlist);
}
- return(0);
+ return 0;
}
static int query_group(alpm_list_t *targets)
@@ -343,19 +343,19 @@ static int is_foreign(pmpkg_t *pkg)
}
}
if(match == 0) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int is_unrequired(pmpkg_t *pkg)
{
alpm_list_t *requiredby = alpm_pkg_compute_requiredby(pkg);
if(requiredby == NULL) {
- return(1);
+ return 1;
}
FREELIST(requiredby);
- return(0);
+ return 0;
}
static int filter(pmpkg_t *pkg)
@@ -363,26 +363,26 @@ static int filter(pmpkg_t *pkg)
/* check if this package was explicitly installed */
if(config->op_q_explicit &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_EXPLICIT) {
- return(0);
+ return 0;
}
/* check if this package was installed as a dependency */
if(config->op_q_deps &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_DEPEND) {
- return(0);
+ return 0;
}
/* check if this pkg isn't in a sync DB */
if(config->op_q_foreign && !is_foreign(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is unrequired */
if(config->op_q_unrequired && !is_unrequired(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is outdated */
if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
- return(0);
+ return 0;
}
- return(1);
+ return 1;
}
/* Loop through the packages. For each package,
@@ -400,7 +400,7 @@ static int check(pmpkg_t *pkg)
if(rootlen + 1 > PATH_MAX) {
/* we are in trouble here */
pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
- return(1);
+ return 1;
}
strcpy(f, root);
@@ -434,7 +434,7 @@ static int check(pmpkg_t *pkg)
(unsigned long)errors), errors);
}
- return(errors != 0 ? 1 : 0);
+ return (errors != 0 ? 1 : 0);
}
static int display(pmpkg_t *pkg)
@@ -466,7 +466,7 @@ static int display(pmpkg_t *pkg)
printf("%s\n", alpm_pkg_get_name(pkg));
}
}
- return(ret);
+ return ret;
}
int pacman_query(alpm_list_t *targets)
@@ -482,13 +482,13 @@ int pacman_query(alpm_list_t *targets)
/* search for a package */
if(config->op_q_search) {
ret = query_search(targets);
- return(ret);
+ return ret;
}
/* looking for groups */
if(config->group) {
ret = query_group(targets);
- return(ret);
+ return ret;
}
if(config->op_q_foreign) {
@@ -496,7 +496,7 @@ int pacman_query(alpm_list_t *targets)
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ return 1;
}
}
@@ -508,7 +508,7 @@ int pacman_query(alpm_list_t *targets)
if(targets == NULL) {
if(config->op_q_isfile || config->op_q_owns) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
@@ -524,7 +524,7 @@ int pacman_query(alpm_list_t *targets)
if(!match) {
ret = 1;
}
- return(ret);
+ return ret;
}
/* Second: operations that require target(s) */
@@ -532,7 +532,7 @@ int pacman_query(alpm_list_t *targets)
/* determine the owner of a file */
if(config->op_q_owns) {
ret = query_fileowner(targets);
- return(ret);
+ return ret;
}
/* operations on named packages in the local DB
@@ -570,7 +570,7 @@ int pacman_query(alpm_list_t *targets)
ret = 1;
}
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index fb02e242..58e6edd5 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -40,25 +40,25 @@ static int remove_target(char *target)
if((info = alpm_db_get_pkg(db_local, target)) != NULL) {
if(alpm_remove_pkg(info) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/* fallback to group */
pmgrp_t *grp = alpm_db_readgrp(db_local, target);
if(grp == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': target not found\n", target);
- return(-1);
+ return -1;
}
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
pmpkg_t *pkg = alpm_list_getdata(p);
if(alpm_remove_pkg(pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
- return(-1);
+ return -1;
}
}
- return(0);
+ return 0;
}
/**
@@ -75,12 +75,12 @@ int pacman_remove(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Step 0: create a new transaction */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* Step 1: add targets to the created transaction */
@@ -173,7 +173,7 @@ cleanup:
if(trans_release() == -1) {
retval = 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 13b65a8f..b12206c4 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -47,7 +47,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
dir = opendir(dbpath);
if(dir == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, _("could not access database directory\n"));
- return(1);
+ return 1;
}
syncdbs = alpm_option_get_syncdbs();
@@ -84,7 +84,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
continue;
}
@@ -110,12 +110,12 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
}
}
closedir(dir);
- return(0);
+ return 0;
}
static int sync_cleandb_all(void) {
@@ -126,7 +126,7 @@ static int sync_cleandb_all(void) {
dbpath = alpm_option_get_dbpath();
printf(_("Database directory: %s\n"), dbpath);
if(!yesno(_("Do you want to remove unused repositories?"))) {
- return(0);
+ return 0;
}
/* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
* We will clean everything in dbpath/ except local/, sync/ and db.lck, and
@@ -137,7 +137,7 @@ static int sync_cleandb_all(void) {
ret += sync_cleandb(newdbpath, 1);
printf(_("Database directory cleaned up\n"));
- return(ret);
+ return ret;
}
static int sync_cleancache(int level)
@@ -165,12 +165,12 @@ static int sync_cleancache(int level)
printf(_(" All current sync database packages\n"));
}
if(!yesno(_("Do you want to remove all other packages from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing old packages from cache...\n"));
} else {
if(!noyes(_("Do you want to remove ALL files from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing all files from cache...\n"));
}
@@ -258,7 +258,7 @@ static int sync_cleancache(int level)
closedir(dir);
}
- return(ret);
+ return ret;
}
static int sync_synctree(int level, alpm_list_t *syncs)
@@ -267,7 +267,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
int success = 0, ret;
if(trans_init(0) == -1) {
- return(0);
+ return 0;
}
for(i = syncs; i; i = alpm_list_next(i)) {
@@ -286,7 +286,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
}
if(trans_release() == -1) {
- return(0);
+ return 0;
}
/* We should always succeed if at least one DB was upgraded - we may possibly
* fail later with unresolved deps, but that should be rare, and would be
@@ -295,7 +295,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
if(!success) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to synchronize any databases\n"));
}
- return(success > 0);
+ return (success > 0);
}
static void print_installed(pmdb_t *db_local, pmpkg_t *pkg)
@@ -384,7 +384,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(!found);
+ return !found;
}
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
@@ -432,7 +432,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(0);
+ return 0;
}
static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
@@ -466,7 +466,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(!db) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("repository '%s' does not exist\n"), repo);
- return(1);
+ return 1;
}
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
@@ -517,7 +517,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(ret);
+ return ret;
}
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
@@ -543,7 +543,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR,
_("repository \"%s\" was not found.\n"),repo);
alpm_list_free(ls);
- return(1);
+ return 1;
}
ls = alpm_list_add(ls, db);
@@ -573,7 +573,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_free(ls);
}
- return(0);
+ return 0;
}
static alpm_list_t *syncfirst(void) {
@@ -591,7 +591,7 @@ static alpm_list_t *syncfirst(void) {
}
}
- return(res);
+ return res;
}
static pmdb_t *get_db(const char *dbname)
@@ -600,10 +600,10 @@ static pmdb_t *get_db(const char *dbname)
for(i = alpm_option_get_syncdbs(); i; i = i->next) {
pmdb_t *db = i->data;
if(strcmp(alpm_db_get_name(db), dbname) == 0) {
- return(db);
+ return db;
}
}
- return(NULL);
+ return NULL;
}
static int process_pkg(pmpkg_t *pkg)
@@ -615,14 +615,14 @@ static int process_pkg(pmpkg_t *pkg)
|| pm_errno == PM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg));
- return(0);
+ return 0;
} else {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg),
alpm_strerrorlast());
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
static int process_group(alpm_list_t *dbs, char *group)
@@ -634,7 +634,7 @@ static int process_group(alpm_list_t *dbs, char *group)
if(!count) {
pm_fprintf(stderr, PM_LOG_ERROR, _("target not found: %s\n"), group);
- return(1);
+ return 1;
}
@@ -668,7 +668,7 @@ static int process_group(alpm_list_t *dbs, char *group)
}
cleanup:
alpm_list_free(pkgs);
- return(ret);
+ return ret;
}
static int process_targname(alpm_list_t *dblist, char *targname)
@@ -679,14 +679,14 @@ static int process_targname(alpm_list_t *dblist, char *targname)
if(pm_errno == PM_ERR_PKG_IGNORED) {
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname);
pm_errno = 0;
- return(0);
+ return 0;
}
if(pkg) {
- return(process_pkg(pkg));
+ return process_pkg(pkg);
}
/* fallback on group */
- return(process_group(dblist, targname));
+ return process_group(dblist, targname);
}
static int process_target(char *target)
@@ -721,7 +721,7 @@ static int process_target(char *target)
}
cleanup:
free(targstring);
- return(ret);
+ return ret;
}
static int sync_trans(alpm_list_t *targets)
@@ -733,7 +733,7 @@ static int sync_trans(alpm_list_t *targets)
/* Step 1: create a new transaction... */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* process targets */
@@ -873,7 +873,7 @@ cleanup:
retval = 1;
}
- return(retval);
+ return retval;
}
int pacman_sync(alpm_list_t *targets)
@@ -885,7 +885,7 @@ int pacman_sync(alpm_list_t *targets)
int ret = 0;
if(trans_init(0) == -1) {
- return(1);
+ return 1;
}
ret += sync_cleancache(config->op_s_clean);
@@ -896,14 +896,14 @@ int pacman_sync(alpm_list_t *targets)
ret++;
}
- return(ret);
+ return ret;
}
/* ensure we have at least one valid sync db set up */
sync_dbs = alpm_option_get_syncdbs();
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ return 1;
}
if(config->op_s_sync) {
@@ -911,40 +911,40 @@ int pacman_sync(alpm_list_t *targets)
printf(_(":: Synchronizing package databases...\n"));
alpm_logaction("synchronizing package lists\n");
if(!sync_synctree(config->op_s_sync, sync_dbs)) {
- return(1);
+ return 1;
}
}
/* search for a package */
if(config->op_s_search) {
- return(sync_search(sync_dbs, targets));
+ return sync_search(sync_dbs, targets);
}
/* look for groups */
if(config->group) {
- return(sync_group(config->group, sync_dbs, targets));
+ return sync_group(config->group, sync_dbs, targets);
}
/* get package info */
if(config->op_s_info) {
- return(sync_info(sync_dbs, targets));
+ return sync_info(sync_dbs, targets);
}
/* get a listing of files in sync DBs */
if(config->op_q_list) {
- return(sync_list(sync_dbs, targets));
+ return sync_list(sync_dbs, targets);
}
if(targets == NULL) {
if(config->op_s_upgrade) {
/* proceed */
} else if(config->op_s_sync) {
- return(0);
+ return 0;
} else {
/* don't proceed here unless we have an operation that doesn't require a
* target list */
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
}
@@ -979,7 +979,7 @@ int pacman_sync(alpm_list_t *targets)
int ret = sync_trans(targs);
FREELIST(targs);
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 8cd29da0..5b894001 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -46,7 +46,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Check for URL targets and process them
@@ -57,7 +57,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(str == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
(char *)i->data, alpm_strerrorlast());
- return(1);
+ return 1;
} else {
free(i->data);
i->data = str;
@@ -67,7 +67,7 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 1: create a new transaction */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* add targets to the created transaction */
@@ -79,14 +79,14 @@ int pacman_upgrade(alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
trans_release();
- return(1);
+ return 1;
}
if(alpm_add_pkg(pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
alpm_pkg_free(pkg);
trans_release();
- return(1);
+ return 1;
}
}
@@ -135,7 +135,7 @@ int pacman_upgrade(alpm_list_t *targets)
}
trans_release();
FREELIST(data);
- return(1);
+ return 1;
}
/* Step 3: perform the installation */
@@ -143,7 +143,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(config->print) {
print_packages(alpm_trans_get_add());
trans_release();
- return(0);
+ return 0;
}
/* print targets and ask user confirmation */
@@ -151,7 +151,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(packages == NULL) { /* we are done */
printf(_(" there is nothing to do\n"));
trans_release();
- return(retval);
+ return retval;
}
display_targets(alpm_trans_get_remove(), 0);
display_targets(alpm_trans_get_add(), 1);
@@ -159,7 +159,7 @@ int pacman_upgrade(alpm_list_t *targets)
int confirm = yesno(_("Proceed with installation?"));
if(!confirm) {
trans_release();
- return(retval);
+ return retval;
}
if(alpm_trans_commit(&data) == -1) {
@@ -197,13 +197,13 @@ int pacman_upgrade(alpm_list_t *targets)
}
FREELIST(data);
trans_release();
- return(1);
+ return 1;
}
if(trans_release() == -1) {
retval = 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 83368085..558d6f8f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -68,9 +68,9 @@ int trans_init(pmtransflag_t flags)
fprintf(stderr, _(" try running pacman-db-upgrade\n"));
}
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
int trans_release(void)
@@ -78,25 +78,25 @@ int trans_release(void)
if(alpm_trans_release() == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
alpm_strerrorlast());
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
int needs_root(void)
{
switch(config->op) {
case PM_OP_DATABASE:
- return(1);
+ return 1;
case PM_OP_UPGRADE:
case PM_OP_REMOVE:
- return(!config->print);
+ return !config->print;
case PM_OP_SYNC:
- return(config->op_s_clean || config->op_s_sync ||
+ return (config->op_s_clean || config->op_s_sync ||
(!config->group && !config->op_s_info && !config->op_q_list &&
!config->op_s_search && !config->print));
default:
- return(0);
+ return 0;
}
}
@@ -125,24 +125,24 @@ int rmrf(const char *path)
DIR *dirp;
if(!unlink(path)) {
- return(0);
+ return 0;
} else {
if(errno == ENOENT) {
- return(0);
+ return 0;
} else if(errno == EPERM) {
/* fallthrough */
} else if(errno == EISDIR) {
/* fallthrough */
} else if(errno == ENOTDIR) {
- return(1);
+ return 1;
} else {
/* not a directory */
- return(1);
+ return 1;
}
dirp = opendir(path);
if(!dirp) {
- return(1);
+ return 1;
}
for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if(dp->d_ino) {
@@ -157,7 +157,7 @@ int rmrf(const char *path)
if(rmdir(path)) {
errflag++;
}
- return(errflag);
+ return errflag;
}
}
@@ -170,9 +170,9 @@ const char *mbasename(const char *path)
{
const char *last = strrchr(path, '/');
if(last) {
- return(last + 1);
+ return last + 1;
}
- return(path);
+ return path;
}
/** Parse the dirname of a program from a path.
@@ -187,7 +187,7 @@ char *mdirname(const char *path)
/* null or empty path */
if(path == NULL || path == '\0') {
- return(strdup("."));
+ return strdup(".");
}
ret = strdup(path);
@@ -196,11 +196,11 @@ char *mdirname(const char *path)
if(last != NULL) {
/* we found a '/', so terminate our string */
*last = '\0';
- return(ret);
+ return ret;
}
/* no slash found */
free(ret);
- return(strdup("."));
+ return strdup(".");
}
/* output a string, but wrap words properly with a specified indentation
@@ -286,7 +286,7 @@ char *strtrim(char *str)
if(str == NULL || *str == '\0') {
/* string is empty, so we're done. */
- return(str);
+ return str;
}
while(isspace((unsigned char)*pch)) {
@@ -298,7 +298,7 @@ char *strtrim(char *str)
/* check if there wasn't anything but whitespace in the string. */
if(*str == '\0') {
- return(str);
+ return str;
}
pch = (str + (strlen(str) - 1));
@@ -307,7 +307,7 @@ char *strtrim(char *str)
}
*++pch = '\0';
- return(str);
+ return str;
}
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
@@ -321,7 +321,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
size_t newsz;
if(!str) {
- return(NULL);
+ return NULL;
}
p = str;
@@ -334,7 +334,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
/* no occurences of needle found */
if(!list) {
- return(strdup(str));
+ return strdup(str);
}
/* size of new string = size of old string + "number of occurences of needle"
* x "size difference between replace and needle" */
@@ -342,7 +342,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
alpm_list_count(list) * (replacesz - needlesz);
newstr = malloc(newsz);
if(!newstr) {
- return(NULL);
+ return NULL;
}
*newstr = '\0';
@@ -368,7 +368,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
}
*newp = '\0';
- return(newstr);
+ return newstr;
}
/** Splits a string into a list of strings using the chosen character as
@@ -388,7 +388,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
while((str = strchr(str, splitchar))) {
dup = strndup(prev, (size_t)(str - prev));
if(dup == NULL) {
- return(NULL);
+ return NULL;
}
list = alpm_list_add(list, dup);
@@ -398,11 +398,11 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
dup = strdup(prev);
if(dup == NULL) {
- return(NULL);
+ return NULL;
}
list = alpm_list_add(list, dup);
- return(list);
+ return list;
}
static int string_length(const char *s)
@@ -411,7 +411,7 @@ static int string_length(const char *s)
wchar_t *wcstr;
if(!s) {
- return(0);
+ return 0;
}
/* len goes from # bytes -> # chars -> # cols */
len = strlen(s) + 1;
@@ -420,7 +420,7 @@ static int string_length(const char *s)
len = wcswidth(wcstr, len);
free(wcstr);
- return(len);
+ return len;
}
void string_display(const char *title, const char *string)
@@ -568,11 +568,11 @@ static off_t pkg_get_size(pmpkg_t *pkg)
{
switch(config->op) {
case PM_OP_SYNC:
- return(alpm_pkg_download_size(pkg));
+ return alpm_pkg_download_size(pkg);
case PM_OP_UPGRADE:
- return(alpm_pkg_get_size(pkg));
+ return alpm_pkg_get_size(pkg);
default:
- return(alpm_pkg_get_isize(pkg));
+ return alpm_pkg_get_isize(pkg);
}
}
@@ -588,14 +588,14 @@ static char *pkg_get_location(pmpkg_t *pkg)
if(dburl) {
char *pkgurl = NULL;
pm_asprintf(&pkgurl, "%s/%s", dburl, alpm_pkg_get_filename(pkg));
- return(pkgurl);
+ return pkgurl;
}
case PM_OP_UPGRADE:
- return(strdup(alpm_pkg_get_filename(pkg)));
+ return strdup(alpm_pkg_get_filename(pkg));
default:
string = NULL;
pm_asprintf(&string, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
- return(string);
+ return string;
}
}
@@ -657,7 +657,7 @@ void print_packages(const alpm_list_t *packages)
* alpm "compare func" signature */
int str_cmp(const void *s1, const void *s2)
{
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg)
@@ -726,13 +726,13 @@ static int parseindex(char *s, int *val, int min, int max)
if(n < min || n > max) {
fprintf(stderr, _("Invalid value: %d is not between %d and %d\n"),
n, min, max);
- return(-1);
+ return -1;
}
*val = n;
- return(0);
+ return 0;
} else {
fprintf(stderr, _("Invalid number: %s\n"), s);
- return(-1);
+ return -1;
}
}
@@ -772,20 +772,20 @@ static int multiselect_parse(char *array, int count, char *response)
}
if(parseindex(starts, &start, 1, count) != 0)
- return(-1);
+ return -1;
if(!ends) {
array[start-1] = include;
} else {
if(parseindex(ends, &end, start, count) != 0)
- return(-1);
+ return -1;
for(int d = start; d <= end; d++) {
array[d-1] = include;
}
}
}
- return(0);
+ return 0;
}
int multiselect_question(char *array, int count)
@@ -823,7 +823,7 @@ int multiselect_question(char *array, int count)
}
break;
}
- return(0);
+ return 0;
}
int select_question(int count)
@@ -855,13 +855,13 @@ int select_question(int count)
int n;
if(parseindex(response, &n, 1, count) != 0)
continue;
- return(n-1);
+ return (n - 1);
}
}
break;
}
- return(preset-1);
+ return (preset - 1);
}
@@ -888,22 +888,22 @@ static int question(short preset, char *fmt, va_list args)
if(config->noconfirm) {
fprintf(stream, "\n");
- return(preset);
+ return preset;
}
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) == 0) {
- return(preset);
+ return preset;
}
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) {
- return(1);
+ return 1;
} else if (strcasecmp(response, _("N")) == 0 || strcasecmp(response, _("NO")) == 0) {
- return(0);
+ return 0;
}
}
- return(0);
+ return 0;
}
int yesno(char *fmt, ...)
@@ -915,7 +915,7 @@ int yesno(char *fmt, ...)
ret = question(1, fmt, args);
va_end(args);
- return(ret);
+ return ret;
}
int noyes(char *fmt, ...)
@@ -927,7 +927,7 @@ int noyes(char *fmt, ...)
ret = question(0, fmt, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_printf(pmloglevel_t level, const char *format, ...)
@@ -940,7 +940,7 @@ int pm_printf(pmloglevel_t level, const char *format, ...)
ret = pm_vfprintf(stdout, level, format, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...)
@@ -953,7 +953,7 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...)
ret = pm_vfprintf(stream, level, format, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_asprintf(char **string, const char *format, ...)
@@ -969,7 +969,7 @@ int pm_asprintf(char **string, const char *format, ...)
}
va_end(args);
- return(ret);
+ return ret;
}
int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args)
@@ -1005,7 +1005,7 @@ int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list
}
free(msg);
- return(ret);
+ return ret;
}
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args)
@@ -1053,7 +1053,7 @@ int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list ar
/* print the message using va_arg list */
ret = vfprintf(stream, format, args);
- return(ret);
+ return ret;
}
#ifndef HAVE_STRNDUP
@@ -1062,7 +1062,7 @@ static size_t strnlen(const char *s, size_t max)
{
register const char *p;
for(p = s; *p && max--; ++p);
- return(p - s);
+ return (p - s);
}
char *strndup(const char *s, size_t n)
@@ -1074,7 +1074,7 @@ char *strndup(const char *s, size_t n)
return NULL;
new[len] = '\0';
- return (char *) memcpy(new, s, len);
+ return (char *)memcpy(new, s, len);
}
#endif
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 71ba3a47..6388e840 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ return 1;
}
/* let us get log messages from libalpm */
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 6a10006f..94e628b6 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -60,12 +60,12 @@ static int alpm_local_init(void)
ret = alpm_initialize();
if(ret != 0) {
- return(ret);
+ return ret;
}
ret = alpm_option_set_root(ROOTDIR);
if(ret != 0) {
- return(ret);
+ return ret;
}
if(dbpath) {
@@ -74,15 +74,15 @@ static int alpm_local_init(void)
ret = alpm_option_set_dbpath(DBPATH);
}
if(ret != 0) {
- return(ret);
+ return ret;
}
db_local = alpm_option_get_localdb();
if(!db_local) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int parse_options(int argc, char *argv[])
@@ -137,12 +137,12 @@ static int parse_options(int argc, char *argv[])
case 'h':
case '?':
default:
- return(1);
+ return 1;
}
}
if(!argv[optind]) {
- return(1);
+ return 1;
}
if(!color) {
@@ -159,7 +159,7 @@ static int parse_options(int argc, char *argv[])
indent_size = 0;
}
- return(0);
+ return 0;
}
static void usage(void)
@@ -366,7 +366,7 @@ int main(int argc, char *argv[])
finish:
cleanup();
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 0436a23f..3d4fa6ae 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -63,7 +63,7 @@ static int check_localdb_files(void)
snprintf(path, sizeof(path), "%slocal", dbpath);
if(!(dir = opendir(path))) {
fprintf(stderr, "error : %s : %s\n", path, strerror(errno));
- return(1);
+ return 1;
}
while ((ent = readdir(dir)) != NULL) {
@@ -85,10 +85,10 @@ static int check_localdb_files(void)
}
if(closedir(dir)) {
fprintf(stderr, "error closing dbpath : %s\n", strerror(errno));
- return(1);
+ return 1;
}
- return(ret);
+ return ret;
}
static int checkdeps(alpm_list_t *pkglist)
@@ -107,7 +107,7 @@ static int checkdeps(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int checkconflicts(alpm_list_t *pkglist)
@@ -123,7 +123,7 @@ static int checkconflicts(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int check_localdb(void) {
@@ -133,7 +133,7 @@ static int check_localdb(void) {
ret = check_localdb_files();
if(ret) {
- return(ret);
+ return ret;
}
db = alpm_option_get_localdb();
@@ -145,7 +145,7 @@ static int check_localdb(void) {
pkglist = alpm_db_get_pkgcache(db);
ret += checkdeps(pkglist);
ret += checkconflicts(pkglist);
- return(ret);
+ return ret;
}
static int check_syncdbs(alpm_list_t *dbnames) {
@@ -169,7 +169,7 @@ static int check_syncdbs(alpm_list_t *dbnames) {
cleanup:
alpm_list_free(syncpkglist);
- return(ret);
+ return ret;
}
static void usage(void) {
@@ -206,7 +206,7 @@ int main(int argc, char *argv[])
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
/* let us get log messages from libalpm */
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
if(alpm_option_set_dbpath(dbpath) != 0) {
fprintf(stderr, "cannot set dbpath: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if(!dbnames) {
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index d0d9cac1..e562dde2 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -44,12 +44,12 @@ int main(int argc, char *argv[])
if(argc != 2) {
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
- return(1);
+ return 1;
}
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ return 1;
}
/* let us get log messages from libalpm */
@@ -79,5 +79,5 @@ int main(int argc, char *argv[])
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
}
- return(retval);
+ return retval;
}
diff --git a/src/util/vercmp.c b/src/util/vercmp.c
index adb5a42a..88cf49a6 100644
--- a/src/util/vercmp.c
+++ b/src/util/vercmp.c
@@ -45,13 +45,13 @@ int main(int argc, char *argv[])
if(argc == 1) {
usage();
- return(2);
+ return 2;
}
if(argc > 1 &&
(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0
|| strcmp(argv[1], "--usage") == 0)) {
usage();
- return(0);
+ return 0;
}
if(argc > 2) {
s2 = argv[2];
@@ -62,5 +62,5 @@ int main(int argc, char *argv[])
ret = alpm_pkg_vercmp(s1, s2);
printf("%d\n", ret);
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index b31498a7..1af24ae9 100755
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -89,6 +89,12 @@ class pmdb(object):
def __str__(self):
return "%s" % self.treename
+ def getverify(self):
+ for value in "Always","Never","Optional":
+ if value in self.treename:
+ return value
+ return "Never"
+
def getpkg(self, name):
"""
"""
@@ -150,6 +156,8 @@ class pmdb(object):
pkg.size = int(fd.readline().strip("\n"))
elif line == "%MD5SUM%":
pkg.md5sum = fd.readline().strip("\n")
+ elif line == "%PGPSIG%":
+ pkg.pgpsig = fd.readline().strip("\n")
elif line == "%REPLACES%":
pkg.replaces = _getsection(fd)
elif line == "%DEPENDS%":
@@ -241,6 +249,8 @@ class pmdb(object):
data.append(_mksection("CSIZE", pkg.csize))
if pkg.md5sum:
data.append(_mksection("MD5SUM", pkg.md5sum))
+ if pkg.pgpsig:
+ data.append(_mksection("PGPSIG", pkg.pgpsig))
if data:
data.append("")
filename = os.path.join(path, "desc")
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 73156ab2..ec51e5d4 100755
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -47,6 +47,7 @@ class pmpkg(object):
self.csize = 0
self.reason = 0
self.md5sum = "" # sync only
+ self.pgpsig = "" # sync only
self.replaces = []
self.depends = []
self.optdepends = []
diff --git a/test/pacman/tests/sign001.py b/test/pacman/tests/sign001.py
new file mode 100644
index 00000000..0ae417b7
--- /dev/null
+++ b/test/pacman/tests/sign001.py
@@ -0,0 +1,9 @@
+self.description = "Add a signature to a package DB"
+
+sp = pmpkg("pkg1")
+sp.pgpsig = "asdfasdfsdfasdfsdafasdfsdfasd"
+self.addpkg2db("sync+Always", sp)
+
+self.args = "-Ss"
+
+self.addrule("PACMAN_RETCODE=0")
diff --git a/test/pacman/tests/sign002.py b/test/pacman/tests/sign002.py
new file mode 100644
index 00000000..b55f331e
--- /dev/null
+++ b/test/pacman/tests/sign002.py
@@ -0,0 +1,10 @@
+self.description = "Verify a signature in a sync DB (failure)"
+
+sp = pmpkg("pkg1")
+sp.pgpsig = "iEYEABECAAYFAkhMOggACgkQXC5GoPU6du2WVQCffVxF8GKXJIY4juJBIw/ljLrQxygAnj2QlvsUd7MdFekLX18+Ov/xzgZ1"
+self.addpkg2db("sync+Always", sp)
+
+self.args = "-S %s" % sp.name
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("!PKG_EXIST=pkg1")
diff --git a/test/pacman/tests/smoke004.py b/test/pacman/tests/smoke004.py
new file mode 100644
index 00000000..1f9b883d
--- /dev/null
+++ b/test/pacman/tests/smoke004.py
@@ -0,0 +1,11 @@
+self.description = "Read a package DB with several PGP signatures"
+
+for i in range(1000):
+ sp = pmpkg("pkg%03d" % i)
+ sp.desc = "test description for package %d" % i
+ sp.pgpsig = "asdfasdfsdfasdfsdafasdfsdfasd"
+ self.addpkg2db("sync", sp)
+
+self.args = "-Ss"
+
+self.addrule("PACMAN_RETCODE=0")
diff --git a/test/pacman/util.py b/test/pacman/util.py
index b771a345..47255923 100755
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -132,8 +132,9 @@ def mkcfgfile(filename, root, option, db):
if key != "local":
value = db[key]
data.append("[%s]\n" \
+ "VerifySig = %s\n" \
"Server = file://%s" \
- % (value.treename,
+ % (value.treename, value.getverify(), \
os.path.join(root, SYNCREPO, value.treename)))
for optkey, optval in value.option.iteritems():
data.extend(["%s = %s" % (optkey, j) for j in optval])
diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh
index a9ed3b2a..0e799789 100755
--- a/test/util/vercmptest.sh
+++ b/test/util/vercmptest.sh
@@ -62,7 +62,7 @@ runtest() {
# use first arg as our binary if specified
[ -n "$1" ] && bin="$1"
-if [ ! $(type -p "$bin") ]; then
+if ! type -p "$bin"; then
echo "vercmp binary ($bin) could not be located"
exit 1
fi