Commit graph

199 commits

Author SHA1 Message Date
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
Jo-Philipp Wich
7b7f254682 session: fix method signatures for create, list and destroy
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-02-09 12:51:44 +01:00
Felix Fietkau
1ceab6196f iwinfo: add support for requesting assoc info for a specific mac address
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-29 19:43:00 +01:00
Felix Fietkau
d99e8adc4f iwinfo: add 802.11ac hw mode
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-10-20 15:49:24 +02:00
Felix Fietkau
ed7d16a3e0 iwinfo: use UBUS_METHOD_NOARG
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-10-04 19:55:58 +02:00
Felix Fietkau
c1ed6d7856 plugin.h: explicitly include json.h
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-10-04 19:54:58 +02:00
Jo-Philipp Wich
7fd4564b8a plugin: fix parsing libexec plugin output
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-07-04 00:06:43 +02:00
Felix Fietkau
3c55504336 session: add missing include
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-29 23:22:50 +02:00
Luka Perkov
7c789622a6 uci: rework variable usage
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-05-29 13:04:21 +02:00
Luka Perkov
4cc6a9deb8 fix segmentation fault when plugins are loaded
Function rpc_plugin_register_library() is modifying the struct's contents in
list_add() call. That said, the rpc_plugin struct should not be defined as
const. This caused segmentation fault when built on up-to-date Arch Linux.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:57 +00:00
Luka Perkov
835b8b768d file: when writing a file make sure it's contents are stored
Fixes problems with ubi(fs).

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:48 +00:00
Luka Perkov
11f5072bb1 file: create a file on write if it does not exist
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-29 13:29:40 +00:00