Commit graph

210 commits

Author SHA1 Message Date
Jo-Philipp Wich
3aa81d0dfa file: access exec timeout via daemon ops structure
Since the plugin is not linked, but dlopen()'d with RTLD_LOCAL, we cannot
access global rpcd variables but need to access them via the common ops
structure symbol.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-28 12:12:04 +01:00
Jo-Philipp Wich
7235f34895 plugin: store pointer to exec timeout value in the ops structure
This is required for plugins that need access to the configured execution
timeout. The global variable cannot be used as-is since we dlopen() with
RTLD_LOCAL.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-28 12:10:40 +01:00
Jo-Philipp Wich
ccd7c0af75 treewide: rename exec_timeout to rpc_exec_timeout
Rename the extern int to denote a global symbol.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-28 12:07:58 +01:00
Jo-Philipp Wich
c79ef22285 main: fix logic bug when not specifying a timeout option
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-22 16:25:39 +01:00
Jo-Philipp Wich
2cc4b998ec file: use global exec timeout instead of own hardcoded limit
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-22 14:28:29 +01:00
Jo-Philipp Wich
ecd1660f17 exec: increase maximum execution time to 120s
Increase the maximum possible execution time to 120 seconds and add a new
command line flag `-t` which allows overwriting the default value.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-11-22 14:28:28 +01:00
Jo-Philipp Wich
41333abee4 uci: tighten uci reorder operation error handling
- Return UBUS_STATUS_INVALID_ARGUMENT for invalid section names
- Return UBUS_STATUS_NOT_FOUND if a section name could not be resolved
2018-08-09 00:07:27 +02:00
Jo-Philipp Wich
f91751b767 uci: tighten uci delete operation error handling
- Return UBUS_STATUS_NOT_FOUND if no object could be resolved for delete
- Return UBUS_STATUS_INVALID_ARGUMENT for invalid section names or types

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-09 00:07:27 +02:00
Jo-Philipp Wich
c2c612b67c uci: tighten uci set operation error handling
- Return UBUS_STATUS_NOT_FOUND if no section could be resolved for set
 - Return UBUS_STATUS_INVALID_ARGUMENT if unserializable values are found

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-09 00:07:27 +02:00
Jo-Philipp Wich
948bb51875 uci: tighten uci add operation error handling
- Return UBUS_STATUS_INVALID_ARGUMENT for invalid section or option names
- Return UBUS_STATUS_NOT_FOUND if a section name could not be resolved

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-09 00:07:26 +02:00
Jo-Philipp Wich
51980c687b uci: reject invalid section and option names
The invoked libuci functions do not reliably check their arguments, causing
malformed section and option names to end up in the delta file, letting the
uci cli and other components to segfault when processung such invalid
entries.

In order to prevent that, manually test received values before passing them
on to libuci.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-08-08 23:58:37 +02:00
Jo-Philipp Wich
820621952d uci: fix memory leak in rpc_uci_replace_savedir()
The rpc_uci_replace_savedir() function did not take into account that libuci
uci_set_savedir() does an additional implicit uci_strdup() of the directory
path string when appending a new delta directory item.

Due to this oversight, only the struct uci_element items got freed, but not
the duplicated path string, leading to leaking memory when invoking the uci
api with session id argument.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-05-13 21:13:05 +02:00
Jo-Philipp Wich
10f787881d exec: close stdout and stderr streams on child signal
This prevents timing out ubus call when the child invokes further detached
childs inheriting stdio descriptors.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-05-08 20:47:17 +02:00
Jo-Philipp Wich
92d0d75716 uci: use correct sort index when reordering sections
When reordering, the section indexes must be 0-based while the current
implementation incorrectly numbers starting with 1.

Fix this by start numbering ther sections with index 0.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-04-28 18:23:59 +02:00
Jo-Philipp Wich
66a9bad1a7 uci: fix memory leak in rpc_uci_apply_timeout()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-04-20 13:17:28 +02:00
Jo-Philipp Wich
2423162234 uci: switch to proper save directory on apply/rollback
The existing code failed to set the uci cursor save directory to the current
session path, causing the apply routine to either fail or to merge settings
from unrelated neighboring sessions, potentially leaking data.

Solve the issue by switching the uci cursor save directory to the session
directory before performing the actual apply actions.

Additionally set the save directory path to "/dev/null" during rollback, to
avoid merging unrelated system wide uci changes when restoring configs from
the snapshot directory.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-04-20 13:15:46 +02:00
Jo-Philipp Wich
edd37f8dbb uci: add rpc_uci_replace_savedir() helper
The rpc_uci_replace_savedir() function removes all configured save directories
from the uci cursor instance and adds the given path argument as sole item.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-04-19 13:54:40 +02:00
Jo-Philipp Wich
eb09f3a3fd session: ignore non-string username attribute upon restore
When restoring session information from blob data, only consider the
embedded username attribute if it is a string value.

Other types may cause invalid memory accesses when attempting to strcmp()
the attribute value.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-03-15 12:29:15 +01:00
Jo-Philipp Wich
3d400c723b session: support reclaiming pending apply session
Reclaim the pending apply session upon login when the username matches the
current login.

This is required to support apply-confirm-rollback workflow for ubus browser
clients, since changing IPs requires re-login to the device due to cross
domain restrictions.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-03-15 12:29:15 +01:00
Jo-Philipp Wich
f0f6f81edb session: remove redundant key attribute to rpc_session_set()
The given const char *key was used to look up the blob attribute, while
the blob attributes internal name was used to store it in the avl tree.

This leads to confusion and potential memory leaks when the given key name
does not match the blob attributes internal name.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-03-15 12:29:15 +01:00
Jo-Philipp Wich
6994c87a42 uci: fix session delta isolation
The libuci `uci_set_savedir()` function does not replace, but appends the
requested delta directory to the search path, this causes information leaks
between sessions.

Due to a lack of an official api for this, clear the uci contexts private
delta path before setting the save directory.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-03-15 12:29:15 +01:00
Daniel Golle
cfe1e75c91 sys: packagelist: allow listing all packages
Introduce optional boolean attribute 'all' to allow listing all
installed packages instead of only the user-selected ones.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2017-12-06 18:44:23 +01:00
Roman Yeryomin
74a784f037 sys: fix passwd path
Signed-off-by: Roman Yeryomin <roman@advem.lv>
2017-11-28 18:17:02 +01:00
Daniel Golle
a0231be8fb sys: fix memory leak in packagelist
Fixes commit 4e483312b0.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2017-11-12 23:25:59 +01:00
Daniel Golle
4e483312b0 sys: add packagelist method
Add method to list installed software packages directly from
/usr/lib/opkg/status (ie. no need to have opkg installed).

ubus call rpc-sys packagelist

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2017-11-12 20:32:35 +01:00
Rafał Miłecki
9a8640183c plugin: use RTLD_LOCAL instead of RTLD_GLOBAL when loading library
RTLD_GLOBAL was used to allow plugins use each other symbols but this
facility was (most likely) never used and is a bad design anyway. If
there is a common code it should just go to a library.

Using RTLD_LOCAL on the other hand saves us from conflicting symbols
used by different plugins. An example can be iwinfo plugin using libnl.
If there appears to be another plugin using incompatible netlink
implementation this will result in a problem. Both plugins will start
using the same libnl which will break one of them.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2017-11-09 15:49:15 +01:00
Florian Fainelli
0577cfc1ac cmake: Find libubox/blobmsg_json.h
Add a CMake FIND_PATH and INCLUDE_DIRECTORIES searching for blobmsg_json.h.
Some external toolchains which do not include standard locations would fail to
find the header otherwise.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2016-12-11 09:16:30 +01:00
Florian Fainelli
26c98ec94d sys: Check return values of chdir and write
Fixes the following warnings:

rpcd/sys.c: In function 'rpc_cgi_password_set':
rpcd/sys.c:116:8: error: ignoring return value of 'chdir', declared with attribute warn_unused_result [-Werror=unused-result]
   chdir("/");
        ^
rpcd/sys.c:125:8: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
   write(fds[1], blobmsg_data(tb[RPC_P_PASSWORD]),
        ^
rpcd/sys.c:127:8: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
   write(fds[1], "\n", 1);
        ^
rpcd/sys.c:131:8: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
   write(fds[1], blobmsg_data(tb[RPC_P_PASSWORD]),
        ^
rpcd/sys.c:133:8: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
   write(fds[1], "\n", 1);
        ^
cc1: all warnings being treated as errors

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2016-12-11 09:15:27 +01:00
Florian Fainelli
f4089654a3 cmake: Find libubus.h
Add a CMake FIND_PATH and INCLUDE_DIRECTORIES searching for libubus.h. Some
external toolchains which do not include standard locations would fail
to find the header otherwise.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2016-07-27 17:28:46 +02:00
Jo-Philipp Wich
23417e94d2 iwinfo: expose available HT rates
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2016-06-30 00:36:01 +02:00
Denis Osvald
f8174eacef iwinfo: zero out ccode buffer since library doesn't
Making an ubus call iwinfo countrylist '{"device":"radio0"}' will result
in some entries having garbage uninitialized stack bytes in the "code"
fields.

With this patch we zero-initialize the buffer that libiwinfo writes to,
making it NUL-terminated so that behavior doesn't happen anymore.

Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-06-05 16:05:23 +02:00
Luka Perkov
73aea9b8b6 file: add myself in Copyright header
Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:15:27 +02:00
Luka Perkov
2350c6fa91 file: handle return output of b64_decode
Solve this compile warning:

file.c:300:16: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
                if (data_len < 0)

Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:15:08 +02:00
Luka Perkov
c8c8f7d014 file: add append write support
Signed-off-by: Luka Perkov <luka@openwrt.org>
2016-04-12 17:14:42 +02:00
Jo-Philipp Wich
e64cbdd9b4 uci: allow setting zero-length values (to delete an option)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-11-23 19:11:44 +01:00
Javier Domingo Cansino
fb6e4604fb paths: substitute literal with macro
Signed-off-by: Javier Domingo Cansino <javierdo1@gmail.com>
2015-11-20 18:00:28 +01:00
John Crispin
f00890cd6e add a reload_config method to the uci object
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-08-25 23:56:32 +02:00
John Crispin
032346f479 add a system object that allows us to set passwords and trigger sysupgrade
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-08-25 23:56:32 +02:00
Luka Perkov
410802e106 file: be consistent with string termination character
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:21:39 +02:00
Luka Perkov
4db5df8a96 file: add support for setting mode when writing files
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:21:28 +02:00
Luka Perkov
fc895bb1e2 file: add support for base64
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-07-15 00:20:17 +02:00
Jo-Philipp Wich
3d655417ab uci: unload package on revert
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-05-17 14:13:02 +02:00
Luka Perkov
9a6bfa110a file: add md5sum support
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-04-12 21:24:39 +02:00
John Crispin
311c85e7d9 properly handle return codes
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-03-28 18:36:40 +01:00
Luka Perkov
361b823e8d file: free memory after opendir()
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:41 +01:00
Luka Perkov
b65f6a844f file: use blob_buf_free()
Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:36 +01:00
Luka Perkov
e2d37b7e40 file: show "data" ubus parameter only when used
The ubus calls for file read, list and stat do not use data parameter, so lets
remove them to avoid confusion.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2015-03-11 16:25:29 +01:00
John Crispin
b71df5b75f fix for json 0.12
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-03-08 15:04:13 +01:00
Jo-Philipp Wich
805e8ce891 cmake: fix libcrypt test
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-02-26 16:34:31 +01:00
Jo-Philipp Wich
a75c310e7c iwinfo: add phyname procedure
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-02-11 14:07:31 +01:00