oweals/opkg-lede.git
7 years agolibbb: remove unused variables
Jo-Philipp Wich [Tue, 14 Mar 2017 23:52:47 +0000 (00:52 +0100)]
libbb: remove unused variables

Remove unused variables from deb_extract() to avoid compiler warnings.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibbb: change gzip_read() buffer argument to void *
Jo-Philipp Wich [Tue, 14 Mar 2017 23:50:46 +0000 (00:50 +0100)]
libbb: change gzip_read() buffer argument to void *

Make gzip_read() expect a void * buffer argument to avoid signed vs unsigned
char mismatch warnings.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibbb: fix gzip_thread() warnings
Jo-Philipp Wich [Tue, 14 Mar 2017 23:47:23 +0000 (00:47 +0100)]
libbb: fix gzip_thread() warnings

 - mark function static
 - add missing return statement
 - avoid uninitialized use of "len"

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg/opkg_cmd.c: more robust PATH handling
Glenn Strauss [Thu, 2 Mar 2017 22:53:42 +0000 (17:53 -0500)]
libopkg/opkg_cmd.c: more robust PATH handling

preserve semantics of PATH when PATH is not set in environment

error and undefined behavior reported in
  https://github.com/openwrt/packages/issues/1922
when PATH not set in environment
(lighttpd executes CGI with empty base env, plus standard CGI env vars)

Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
[Jo-Philipp Wich: avoid free() on NULL, use default from cmake cache string]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: specify "/bin/sh" instead of "sh"
Glenn Strauss [Thu, 2 Mar 2017 22:53:09 +0000 (17:53 -0500)]
libopkg: specify "/bin/sh" instead of "sh"

avoid strange behavior with execvp() when PATH is not set in environment
(in which case confstr(_CS_PATH) should return something reasonable)

reproducable running openwrt 15.05 and 15.05.1 and attempting to install
a software package (e.g. libuuid) via LuCI (prior to openwrt/luci#1048).
(https://github.com/openwrt/luci/pull/1048) libuuid.postinst fails with
status 255 on 15.05 and opkg segfaults in 15.05.1.  This probably merits
further exploration.

Originally reported in https://github.com/openwrt/packages/issues/1922

Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
7 years agounarchive: fix possible segmentation fault in deb_extract()
Jo-Philipp Wich [Tue, 28 Feb 2017 23:46:39 +0000 (00:46 +0100)]
unarchive: fix possible segmentation fault in deb_extract()

When a not existing or unreachable file path is passed to deb_extract(),
the wfopen() call fails, causing a jump to the cleanup: label which leads
to a call to gzip_close() on the tar_outer structure.

The tar_outer structure however contains uninitialized memory at this point,
causing gzip_close() to operate on garbage data. Depending on the nature of
the unitialized memory, this might lead to all sorts of issues, e.g. freeing
of not allocated memory or invoking fclose() on garbage pointers.

Solve this problem by initializing the tar_outer and tar_inner structures
right at the declaration.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: forward "provided_by_hand" flag in pkg_merge()
Jo-Philipp Wich [Tue, 28 Feb 2017 23:08:40 +0000 (00:08 +0100)]
pkg: forward "provided_by_hand" flag in pkg_merge()

Due to the fact that we now load status files after preparing the abstract
structures describing the cli specified packages, we need to ensure that the
"provided_by_hand" flag is properly conveyed in pkg_merge(), otherwise the
cli provided package archive might get ignored in favor to a newer version
from feeds.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: mark bit fields in pkg_t unsigned
Jo-Philipp Wich [Tue, 28 Feb 2017 22:53:41 +0000 (23:53 +0100)]
pkg: mark bit fields in pkg_t unsigned

Qualify the bit field type as unsigned int to ensure that set flags are
interpreted as "1" and not "-1".

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agoopkg_cmd: avoid null pointer dereference in opkg_what_depends_conflicts_cmd()
Jo-Philipp Wich [Mon, 27 Feb 2017 22:23:59 +0000 (23:23 +0100)]
opkg_cmd: avoid null pointer dereference in opkg_what_depends_conflicts_cmd()

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agoopkg_cmd: fix endless loop in whatprovides/whatreplaces
Jo-Philipp Wich [Mon, 27 Feb 2017 19:19:21 +0000 (20:19 +0100)]
opkg_cmd: fix endless loop in whatprovides/whatreplaces

Fix the loop semantics in opkg_what_provides_replaces_cmd() to properly
advance the package vector pointer.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg_depends: propagate virtual provided detail flag to providers
Jo-Philipp Wich [Mon, 27 Feb 2017 18:24:31 +0000 (19:24 +0100)]
pkg_depends: propagate virtual provided detail flag to providers

When the provided abstract package (e.g. "px5g" provided by "px5g-mbedtls") is
marked as requiring details, then mark the provider abstract package as well.

This ensures that package info for discrete provider packages is acquired and
retained if the virtual package they provide is being depended upon by another
package requiring details.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg_depends: fix unsatisfied dependency installation order
Pieter Smith [Thu, 23 Feb 2017 12:54:14 +0000 (13:54 +0100)]
pkg_depends: fix unsatisfied dependency installation order

Unsatisfied dependencies are not being installed in the correct order. The
algorithm is not crawling down the dependency chain first when inserting
unsatisfied dependencies, resulting in a correct installation order only for
the first layer of dependencies.

This patch changes the unsatisfied dependency insertion order to first add leaf
dependencies, then move up the chain. The result is a list of unsatisfied
dependencies ordered most-dependent-first.

An example that resulted in the incorrect installation order was:
  A -> B
  A -> C
  B -> D

Without the fix, a most-dependent-first installation order was not guaranteed
more than one layer deep, resulting in an installation order where B is
incorrectly installed before D:
  B, D, C, A

After the fix, the installation order follows most-dependent first irrespective
of the number of layers:
  D, B, C, A

Signed-off-by: Pieter Smith <pieter.smith@philips.com>
[Jo-Philipp Wich: rebased onto opkg-lede.git]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix some overly aggressive line wrapping in pkg_depends.c
Jo-Philipp Wich [Thu, 23 Feb 2017 15:37:35 +0000 (16:37 +0100)]
libopkg: fix some overly aggressive line wrapping in pkg_depends.c

Then deeply nested blocks in pkg_depends.c tripped up Lindent, causing it
to perform overly aggressive line wrapping.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove stray printf()
Jo-Philipp Wich [Thu, 23 Feb 2017 08:42:47 +0000 (09:42 +0100)]
libopkg: remove stray printf()

This lone printf() statement was accidentally left in the code during some
previous refactoring session.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: switch to GPL2 SHA256 implementation
Jo-Philipp Wich [Wed, 22 Feb 2017 15:13:49 +0000 (16:13 +0100)]
libopkg: switch to GPL2 SHA256 implementation

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: initialize conffile list during status parsing
Jo-Philipp Wich [Wed, 22 Feb 2017 12:27:20 +0000 (13:27 +0100)]
libopkg: initialize conffile list during status parsing

When parsing conffile information from status files, we need to initialize
the conffile list head upon encountering a "Conffiles:" line, otherwise
parse_conffiles() will ignore all subsequent entries due to a missing list
pointer.

Fixes missing conffile information in /usr/lib/opkg/status on a fresh
installation.

Reported-by: Hartmut Birr <e9hack@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: enable usign support
Jo-Philipp Wich [Mon, 20 Feb 2017 13:43:30 +0000 (14:43 +0100)]
build: enable usign support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: allow to pass version via CMake
Jo-Philipp Wich [Sat, 18 Feb 2017 14:45:53 +0000 (15:45 +0100)]
build: allow to pass version via CMake

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove OpenSSL support
Jo-Philipp Wich [Sat, 18 Feb 2017 14:06:38 +0000 (15:06 +0100)]
libopkg: remove OpenSSL support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove Curl support
Jo-Philipp Wich [Sat, 18 Feb 2017 14:04:02 +0000 (15:04 +0100)]
libopkg: remove Curl support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove GPG support
Jo-Philipp Wich [Sat, 18 Feb 2017 14:00:14 +0000 (15:00 +0100)]
libopkg: remove GPG support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove x509 support
Jo-Philipp Wich [Sat, 18 Feb 2017 13:57:20 +0000 (14:57 +0100)]
libopkg: remove x509 support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: drop custom md5 implementation, unconditionally enable sha256 support
Jo-Philipp Wich [Sat, 18 Feb 2017 13:53:16 +0000 (14:53 +0100)]
libopkg: drop custom md5 implementation, unconditionally enable sha256 support

Drop custom md5 implementation and switch to the one provided by libubox,
also remove support for enabling/disabling checksum support and always build
it unconditionally.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix pkg_set_int(), pkg_get_int()
Jo-Philipp Wich [Sat, 18 Feb 2017 13:35:53 +0000 (14:35 +0100)]
libopkg: fix pkg_set_int(), pkg_get_int()

Fix the return values of pkg_get_int() and pkg_set_int() to properly
convert the pointers from/to integer values.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: properly fix parse_version()
Jo-Philipp Wich [Sat, 18 Feb 2017 12:48:25 +0000 (13:48 +0100)]
libopkg: properly fix parse_version()

A previous attempt to fix the verison/revision split caused unterminated
strings to get stored in the blob buffer, properly fix this case now.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: fix handling of string options
Jo-Philipp Wich [Sat, 18 Feb 2017 12:32:45 +0000 (13:32 +0100)]
build: fix handling of string options

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: do not modify original version string in parse_version()
Jo-Philipp Wich [Fri, 17 Feb 2017 19:01:42 +0000 (20:01 +0100)]
libopkg: do not modify original version string in parse_version()

The parse_version() function might be parsing the version string of another
pkg_t instance so we must not modify it inplace to truncate the revision
part, otherwise we will clobber the original version, leading to failing
comparisations later on.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: add install target for opkg-cl
Jo-Philipp Wich [Fri, 17 Feb 2017 17:43:19 +0000 (18:43 +0100)]
build: add install target for opkg-cl

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: enable SHA256 support
Jo-Philipp Wich [Fri, 17 Feb 2017 17:28:19 +0000 (18:28 +0100)]
build: enable SHA256 support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agoopkg-cl: remove config.h reference
Jo-Philipp Wich [Fri, 17 Feb 2017 17:26:40 +0000 (18:26 +0100)]
opkg-cl: remove config.h reference

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: remove config.h references
Jo-Philipp Wich [Fri, 17 Feb 2017 17:26:18 +0000 (18:26 +0100)]
libopkg: remove config.h references

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: infer VERSION from Git history
Jo-Philipp Wich [Fri, 17 Feb 2017 17:22:02 +0000 (18:22 +0100)]
build: infer VERSION from Git history

Pass short hash and commit date as VERSION string.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: do not unconditionally link libpthread
Jo-Philipp Wich [Fri, 17 Feb 2017 17:19:53 +0000 (18:19 +0100)]
build: do not unconditionally link libpthread

Some environments, e.g. musl libc based ones, do not have a dedicated
libpthread, so only link it if it exists.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agoopkg-cl: add missing include to import FNM_CASEFOLD
Jo-Philipp Wich [Fri, 17 Feb 2017 14:58:57 +0000 (15:58 +0100)]
opkg-cl: add missing include to import FNM_CASEFOLD

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: expose LOCK_FILE option
Jo-Philipp Wich [Fri, 17 Feb 2017 14:36:08 +0000 (15:36 +0100)]
build: expose LOCK_FILE option

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: remove outdated files
Jo-Philipp Wich [Fri, 17 Feb 2017 14:21:44 +0000 (15:21 +0100)]
build: remove outdated files

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: remove automake/autoconf build system
Jo-Philipp Wich [Fri, 17 Feb 2017 14:17:36 +0000 (15:17 +0100)]
build: remove automake/autoconf build system

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years ago.gitignore: ignore test executables
Jo-Philipp Wich [Fri, 17 Feb 2017 14:13:29 +0000 (15:13 +0100)]
.gitignore: ignore test executables

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years ago.gitignore: ignore CMake artifacts
Jo-Philipp Wich [Fri, 17 Feb 2017 14:10:07 +0000 (15:10 +0100)]
.gitignore: ignore CMake artifacts

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agotests: fix build of opkg_extract_test
Jo-Philipp Wich [Fri, 17 Feb 2017 14:08:44 +0000 (15:08 +0100)]
tests: fix build of opkg_extract_test

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: add cmake build system
Jo-Philipp Wich [Fri, 17 Feb 2017 14:08:03 +0000 (15:08 +0100)]
build: add cmake build system

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agoopkg-cl: stop preloading package feeds on install
Jo-Philipp Wich [Thu, 16 Feb 2017 15:44:07 +0000 (16:44 +0100)]
opkg-cl: stop preloading package feeds on install

Instead of unconditionally loading all package feed lists entirely into
memory, let opkg_install_cmd() selectively parse the lists using the new
pkg_hash_load_package_details() helper.

This will result in a slightly longer runtime but dramatically reduces the
memory requirements. On an x86_64 test system, the peak heap memory
consumption during an "opkg install luci" dropped from 3.7 MB to about
360 KB, a decrease of roughly 90%.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: selectively load package feeds in opkg_info_status_cmd()
Jo-Philipp Wich [Thu, 16 Feb 2017 15:36:58 +0000 (16:36 +0100)]
libopkg: selectively load package feeds in opkg_info_status_cmd()

Use the new pkg_hash_load_package_details() helper to selectively load the
dependency subgraphs of the to be installed packages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: immediately free packages not marked for detail parsing
Jo-Philipp Wich [Thu, 16 Feb 2017 15:33:57 +0000 (16:33 +0100)]
libopkg: immediately free packages not marked for detail parsing

Stop recording packages into the dependency graph which are not flagged
with SF_NEED_DETAILS.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: avoid aggregating multiple identical providers
Jo-Philipp Wich [Thu, 16 Feb 2017 14:56:14 +0000 (15:56 +0100)]
libopkg: avoid aggregating multiple identical providers

Since we might do multiple parsing runs over the feed list files in the
future, ensure that we do not insert the abstract provider package multiple
times into the provided_by vector.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: implement pkg_hash_load_package_details() helper
Jo-Philipp Wich [Thu, 16 Feb 2017 11:19:02 +0000 (12:19 +0100)]
libopkg: implement pkg_hash_load_package_details() helper

The purpose of this new function is to keep parsing feed lists until
all package detail requests are satisified.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: support passing default state flags in pkg_hash_load_feeds()
Jo-Philipp Wich [Thu, 16 Feb 2017 11:16:29 +0000 (12:16 +0100)]
libopkg: support passing default state flags in pkg_hash_load_feeds()

Add a new argument to pkg_hash_load_feeds() which allows specifying default
state flags that should be applied to all loaded packages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: flag package with SF_NEED_DETAIL in pkg_init_from_file()
Jo-Philipp Wich [Thu, 16 Feb 2017 11:12:04 +0000 (12:12 +0100)]
libopkg: flag package with SF_NEED_DETAIL in pkg_init_from_file()

Flag the package loaded from file as SF_NEED_DETAIL to properly fetch and
resolve dependencies.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix printing provides in pkg_formatted_field()
Jo-Philipp Wich [Thu, 16 Feb 2017 11:10:16 +0000 (12:10 +0100)]
libopkg: fix printing provides in pkg_formatted_field()

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix pkg_deinit() to properly free the resources in the blob buffer
Jo-Philipp Wich [Thu, 16 Feb 2017 10:57:55 +0000 (11:57 +0100)]
libopkg: fix pkg_deinit() to properly free the resources in the blob buffer

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: free old provides list in pkg_merge()
Jo-Philipp Wich [Thu, 16 Feb 2017 10:50:02 +0000 (11:50 +0100)]
libopkg: free old provides list in pkg_merge()

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix merging PKG_CONFFILES in pkg_merge()
Jo-Philipp Wich [Thu, 16 Feb 2017 10:47:48 +0000 (11:47 +0100)]
libopkg: fix merging PKG_CONFFILES in pkg_merge()

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix pkg_set_ptr() to properly set NULL pointers
Jo-Philipp Wich [Thu, 16 Feb 2017 10:46:31 +0000 (11:46 +0100)]
libopkg: fix pkg_set_ptr() to properly set NULL pointers

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: allow passing common package state flags to pkg_hash_add_from_file()
Jo-Philipp Wich [Wed, 15 Feb 2017 23:24:29 +0000 (00:24 +0100)]
libopkg: allow passing common package state flags to pkg_hash_add_from_file()

Add a new parameter to pkg_hash_add_from_file() for passing package state
flags that shall be applied to all pkg_t instances parsed from the given
file and use it to mark all packages loaded from local status files with
the SF_NEED_DETAIL flag.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: propagate SF_NEED_DETAIL from abstract to discrete package
Jo-Philipp Wich [Wed, 15 Feb 2017 23:21:05 +0000 (00:21 +0100)]
libopkg: propagate SF_NEED_DETAIL from abstract to discrete package

During parsing, propagate the state of the SF_NEED_DETAIL flag from the
related abstract package to the discrete pkg_t instance getting assembled.

This is required to ensure that subsequent parsing of pkg_t's dependency
lists considers the state of SF_NEED_DETAIL.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: do not clobber package flags during parsing
Jo-Philipp Wich [Wed, 15 Feb 2017 23:18:25 +0000 (00:18 +0100)]
libopkg: do not clobber package flags during parsing

When parsing "Status:" lines from package control or list files, do not
overwrite previously set flags in the package structure.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: propagate SF_NEED_DETAIL to related packages
Jo-Philipp Wich [Wed, 15 Feb 2017 23:15:05 +0000 (00:15 +0100)]
libopkg: propagate SF_NEED_DETAIL to related packages

When parsing Provides, Suggests, Conflicts, Replaces and Depends lists,
propagate the parent package SF_NEED_DETAIL flag to related abstract
packages in order to ensure that the entire related dependency graph
is processed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: directly pass type to parseDepends()
Jo-Philipp Wich [Wed, 15 Feb 2017 23:09:05 +0000 (00:09 +0100)]
libopkg: directly pass type to parseDepends()

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: expose abstract_pkg_fetch_by_name()
Jo-Philipp Wich [Wed, 15 Feb 2017 23:01:58 +0000 (00:01 +0100)]
libopkg: expose abstract_pkg_fetch_by_name()

We need this function in other places later in order to be able to fetch
abstract packages without implicitely creating them.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: mark to-be-installed non-local, non-url packages for detail parsing
Jo-Philipp Wich [Wed, 15 Feb 2017 22:54:13 +0000 (23:54 +0100)]
libopkg: mark to-be-installed non-local, non-url packages for detail parsing

When just a package name is passed to opkg install, we need to retrieve
information about this package from the feeds list so stage an abstract
package with the given name and flag it with SF_NEED_DETAIL.

Packages specified as local file paths or direct download URLs do not
need this special treatment as the required details can be extracted
from their embedded control files.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: introduce SF_NEED_DETAIL flag
Jo-Philipp Wich [Wed, 15 Feb 2017 22:47:53 +0000 (23:47 +0100)]
libopkg: introduce SF_NEED_DETAIL flag

Introduce a new pkt_t state_flag value SF_NEED_DETAIL which will be used
to mark packages for which we require details.

When parsing the feed lists, we'll only keep information about packages
marked with SF_NEED_DETAIL and packages related to them through Provides,
Suggests, Conflicts, Depends etc.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: make checksum_bin2hex() and checksum_hex2bin() cope with NULL
Jo-Philipp Wich [Wed, 15 Feb 2017 22:42:58 +0000 (23:42 +0100)]
libopkg: make checksum_bin2hex() and checksum_hex2bin() cope with NULL

Those functions may be called with a NULL source pointer, especially during
pkg_merge(), so allow that to keep call sites simple.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix unsatisfied dependency reporting
Jo-Philipp Wich [Wed, 15 Feb 2017 22:39:47 +0000 (23:39 +0100)]
libopkg: fix unsatisfied dependency reporting

Previous refactoring of pkg_hash_fetch_unsatisfied_dependencies() caused the
outermost loop counter variable to not get incremented anymore, causing the
function to always report the first dependency as unsatisifed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix hex encoding/decoding, add checksum getter/setter
Jo-Philipp Wich [Mon, 13 Feb 2017 17:07:04 +0000 (18:07 +0100)]
libopkg: fix hex encoding/decoding, add checksum getter/setter

Fix broken hex encoding/decoding due to the use of signed chars and introduce
new convenience getters and setters to simplify the checksum usage.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: store checksums in binary form, use integer index for architecture
Jo-Philipp Wich [Mon, 13 Feb 2017 17:07:04 +0000 (18:07 +0100)]
libopkg: store checksums in binary form, use integer index for architecture

Instead of storing a copy of the architecture string and architecture
priority value in each pkg_t instance, declare a 3 bit wide field which
allows referencing the architecture in the global config array by index.

The 3 bit field allows referencing up to 8 different architectures which
is more than enough for the systems we target with opkg. Another nice side
effect is that we can coalesce this field with other flag values in pkg_t,
saving 4 bytes for an int member.

Also convert the hexadecimal checksums to binary format before storing them in
pkg_t's blob buffer to save 50% of the space per checksum.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: move active_list structure out of pkg_t
Jo-Philipp Wich [Mon, 13 Feb 2017 13:31:24 +0000 (14:31 +0100)]
pkg: move active_list structure out of pkg_t

The active list head is only used by a tiny fraction of the allocated
package structures in memory so do not waste heap memory by allocating
space for it in all loaded packages.

Instead allocate active list heads dynamically where needed and point
them to the corresponding packages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: convert most other struct members into dynamic blob buffer fields
Jo-Philipp Wich [Sun, 12 Feb 2017 20:43:11 +0000 (21:43 +0100)]
pkg: convert most other struct members into dynamic blob buffer fields

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: store size, installed size and installed time info in blob buffer
Jo-Philipp Wich [Fri, 10 Feb 2017 21:56:13 +0000 (22:56 +0100)]
pkg: store size, installed size and installed time info in blob buffer

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: use a blob buffer in pkg_t to store variable fields
Jo-Philipp Wich [Fri, 10 Feb 2017 16:14:53 +0000 (17:14 +0100)]
pkg: use a blob buffer in pkg_t to store variable fields

Adds infrastructure to use a blob buffer in pkg_t to store and retrieve
optional dynamic fields.

This reduces the size of the pkg_t structure itself and lays the
ground work for further optimization.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agopkg: coalesce soem flag members into a packed bit field
Jo-Philipp Wich [Fri, 10 Feb 2017 15:21:14 +0000 (16:21 +0100)]
pkg: coalesce soem flag members into a packed bit field

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agotreewrite: use Lindent to reformat to kernel coding style
Jo-Philipp Wich [Fri, 10 Feb 2017 10:20:23 +0000 (11:20 +0100)]
treewrite: use Lindent to reformat to kernel coding style

Use the kernels "Lindent" script to reformat files using kernel coding style.
This should make subsequent refactoring much easier.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: clarify messages and errors related to downloads
Jo-Philipp Wich [Fri, 10 Feb 2017 10:06:38 +0000 (11:06 +0100)]
libopkg: clarify messages and errors related to downloads

Clarify opkg's messages related to downloads:

 * more visible error message for package list download failure
 * separate error message for signature file download error
 * if wget returns 4, signal the network error more clearly
 * remove '.' from end of filenames and URLs

 * try signature check only if the package list was downloaded ok.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
7 years agolibopkg: run prerm scripts for the old version also on upgrade
Jo-Philipp Wich [Fri, 10 Feb 2017 10:05:44 +0000 (11:05 +0100)]
libopkg: run prerm scripts for the old version also on upgrade

To make sure we properly restart services on upgrade we need to
call the prerm script of the old package, in case the init script
changes (or vanishes).

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Acked-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix use-after-free with duplicate packages on the command line
Jo-Philipp Wich [Fri, 10 Feb 2017 10:04:10 +0000 (11:04 +0100)]
libopkg: fix use-after-free with duplicate packages on the command line

When the same package file is specified multiple times on the opkg install
command line, the name pointer on the argv array becomes stale after the
package structures have been merged, leading to invalid memory accesses
upon install.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement --size
Jo-Philipp Wich [Fri, 10 Feb 2017 09:57:45 +0000 (10:57 +0100)]
cli: implement --size

Implement a new switch "--size" which causes opkg to print the package size
in the listing output.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement --lists-dir
Jo-Philipp Wich [Fri, 10 Feb 2017 09:44:17 +0000 (10:44 +0100)]
cli: implement --lists-dir

Add a new flag --lists-dir which allows setting the package feed list
directory from command arguments.

This is required to be able to use opkg without any configuration file.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix --force-checksum to cover sha256sum cases as well
Jo-Philipp Wich [Fri, 10 Feb 2017 09:43:57 +0000 (10:43 +0100)]
libopkg: fix --force-checksum to cover sha256sum cases as well

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: make MD5 support optional
Jo-Philipp Wich [Fri, 10 Feb 2017 09:41:51 +0000 (10:41 +0100)]
libopkg: make MD5 support optional

Disable md5 support code by default and introduce a new configure flag
"--enable-md5" which allows reenabling the code.

This shrinks the opkg executable by a few KB.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: drop support for Release files
Jo-Philipp Wich [Fri, 10 Feb 2017 09:40:04 +0000 (10:40 +0100)]
libopkg: drop support for Release files

Remove support for Release files as this facility is unused in LEDE/OpenWrt.
Removing this allows us to shrink the opkg executable a little bit.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement --force-signature
Jo-Philipp Wich [Fri, 10 Feb 2017 09:37:02 +0000 (10:37 +0100)]
cli: implement --force-signature

Implement a new "--force-signature" flag which causes opkg to ignore signature
verification errors.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: add support for signature checking through usign
Jo-Philipp Wich [Fri, 10 Feb 2017 09:34:21 +0000 (10:34 +0100)]
libopkg: add support for signature checking through usign

Adds a new configure switch "--enable-usign" which enables code to perform
package feed signature checking using an external "/usr/sbin/opkg-key" helper
program.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: pass PKG_UPGRADE variable to package scripts
Jo-Philipp Wich [Fri, 10 Feb 2017 09:31:55 +0000 (10:31 +0100)]
libopkg: pass PKG_UPGRADE variable to package scripts

When installing or upgrading packages, pass an PKG_UPGRADE environment
variable to maintainer scripts to allow the to perform different actions
depending on whether a package is freshly installed or upgraded.

During installs the PKG_UPGRADE variable will be set to 0 and during
upgrades to 1.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement --force-checksum
Jo-Philipp Wich [Fri, 10 Feb 2017 09:30:33 +0000 (10:30 +0100)]
cli: implement --force-checksum

Introduce a new --force-checksum flag which allows installing packages even if
the checksum does not match. This is useful for development and debugging.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: suppress empty provides
Jo-Philipp Wich [Fri, 10 Feb 2017 09:29:44 +0000 (10:29 +0100)]
libopkg: suppress empty provides

When writing out status information, suppress the Provides field if there
are no providers.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: discard empty control file fields
Jo-Philipp Wich [Fri, 10 Feb 2017 09:28:09 +0000 (10:28 +0100)]
libopkg: discard empty control file fields

If the resulting string is empty after whitespace trimming, free it and
store NULL instead of an empty string buffer.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: store compressed package lists
Jo-Philipp Wich [Fri, 10 Feb 2017 09:24:58 +0000 (10:24 +0100)]
libopkg: store compressed package lists

To save storage space, store the package lists in compressed form and
decompress them on-the-fly during parsing.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibbb: use external gzip command as I/O layer
Jo-Philipp Wich [Fri, 10 Feb 2017 09:19:14 +0000 (10:19 +0100)]
libbb: use external gzip command as I/O layer

Remove the builtin inflate code and rely on the external gzip command instead
to inflate data streams.

This change is needed to properly support vfork(). We cannot use the builtin
code because it uses a single global state which will get clobbered when
recursively inflating nested archives.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement find command
Jo-Philipp Wich [Fri, 10 Feb 2017 09:18:18 +0000 (10:18 +0100)]
cli: implement find command

Introduce a new opkg "find" command which matches both the name and the
description of packages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: implement --nocase flag
Jo-Philipp Wich [Fri, 10 Feb 2017 09:16:33 +0000 (10:16 +0100)]
cli: implement --nocase flag

Introduce a new --nocase flag which causes all opkg pattern matching
operations to ignore the case.

This is useful to find packages with uppercase letters in their name.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: line-wrap descriptions only on interactive terminals
Jo-Philipp Wich [Fri, 10 Feb 2017 09:14:02 +0000 (10:14 +0100)]
libopkg: line-wrap descriptions only on interactive terminals

Various programs call opkg and extract information from its list and info
commands. To simplify parsing the output, do not line-wrap long description
lines if opkg is not talking to a tty.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: fix double-free crash on recursive package removal
Jo-Philipp Wich [Fri, 10 Feb 2017 09:04:57 +0000 (10:04 +0100)]
libopkg: fix double-free crash on recursive package removal

The opkg_remove_dependent_pkgs() function will trigger a pkg_vec_free() and
break the loop when an error is returned by opkg_remove_pkg().

Since the vector is freed anyway after the loop, a double free occurs,
leading to a segmentation fault.

This situation commonly happens when recursively deleting packages in
conjunction with --autoremove where dependent packages might already have
been removed by previous iterations.

Simply break the loop without prematurely freeing the vector to fix this.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: do not rely on getline()
Jo-Philipp Wich [Fri, 10 Feb 2017 09:03:19 +0000 (10:03 +0100)]
libopkg: do not rely on getline()

OpenWrt/LEDE uses opkg on both the target systems and the build hosts and not
every supported host system provides a getline() implementation.

Rewrite affected code to not require the getline() function.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: print error messages to stderr
Jo-Philipp Wich [Fri, 10 Feb 2017 09:02:42 +0000 (10:02 +0100)]
libopkg: print error messages to stderr

Print the collected error list to stderr isntead of stdout. This is useful
for wrapping programs that treat stdout and stderr differently.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agolibopkg: strip trailing white space in conffile specification
Jo-Philipp Wich [Fri, 10 Feb 2017 08:59:59 +0000 (09:59 +0100)]
libopkg: strip trailing white space in conffile specification

The conffile entries in package control lines may have trailing white space,
causing opkg to fail looking up the file paths.

Trim white space to avoid this error.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: default to /etc/opkg.conf
Jo-Philipp Wich [Fri, 10 Feb 2017 08:58:20 +0000 (09:58 +0100)]
cli: default to /etc/opkg.conf

If neither --conf-file nor --offline-root are specified, default to the
traditional /etc/opkg.conf location to retain compatibility with OpenWrt/LEDE.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agocli: enforce argument to upgrade command
Jo-Philipp Wich [Fri, 10 Feb 2017 08:57:18 +0000 (09:57 +0100)]
cli: enforce argument to upgrade command

Blindly upgrading all upgradable packages usually brick the system, so disable
support for argument-less upgrade commands for now.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: statically link libopkg
Jo-Philipp Wich [Fri, 10 Feb 2017 08:54:34 +0000 (09:54 +0100)]
build: statically link libopkg

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: allow overriding host cpu with make variable
Jo-Philipp Wich [Fri, 10 Feb 2017 08:53:40 +0000 (09:53 +0100)]
build: allow overriding host cpu with make variable

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: remove output shaving support
Jo-Philipp Wich [Fri, 10 Feb 2017 08:51:44 +0000 (09:51 +0100)]
build: remove output shaving support

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
7 years agobuild: missing pkg.m4
Jo-Philipp Wich [Fri, 10 Feb 2017 08:50:20 +0000 (09:50 +0100)]
build: missing pkg.m4

Signed-off-by: Jo-Philipp Wich <jo@mein.io>