Daniel Golle [Fri, 4 Dec 2020 09:53:11 +0000 (09:53 +0000)]
ubusd: attempt to create socket folder
When ubus is running as root, /var/run/ubus most likely hasn't been
created as well (as that's the homedir of user ubus, and if a user
ubus was found, then ubus would run being that user).
Blindly attempt to create the directory (which won't do any harm if
it does exist and/or ubus is not running as root) to still be able to
start ubus in case of user ubus not existing.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Ansuel Smith [Fri, 23 Oct 2020 01:01:55 +0000 (03:01 +0200)]
ubusd_acl: add support for wildcard in methods
Add support for wildcard in methods to permit access to all methods
defined by the object. This can be usefull for process that run as
non-root user and needs to access ubus method.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Mon, 19 Oct 2020 14:14:47 +0000 (15:14 +0100)]
ubus: move /var/run/ubus.sock to /var/run/ubus/ubus.sock
This makes it possible to run ubus as non-root.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Petr Štetiar [Wed, 5 Aug 2020 08:27:24 +0000 (10:27 +0200)]
tests: cram: fix usage test
Add new subscribe command help.
Fixes: 59835ae530f5 ("cli: document usage of "subscribe" command")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Rafał Miłecki [Wed, 29 Jul 2020 08:17:18 +0000 (10:17 +0200)]
cli: document usage of "subscribe" command
Support for "subscribe" command was added years ago in the commit
453b87f6315f ("cli: add support for subscribing to objects"). Document
its usage.
Cc: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Alin Nastac [Mon, 3 Feb 2020 12:58:04 +0000 (13:58 +0100)]
lua: avoid truncation of large numeric values
If the Lua number exceeds the maximum value representable by an
unsigned 32bit integer, store it in an unsigned 64bit integer
field instead.
Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
[align code style, reword commit message]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Peter Stadler [Sat, 7 Dec 2019 11:45:47 +0000 (12:45 +0100)]
ubus: make libubus ready for linking into C++
Use extern "C" { ... } if using libubus.h in a C++ project.
Signed-off-by: Peter Stadler <peter.stadler@student.uibk.ac.at>
Petr Štetiar [Fri, 27 Dec 2019 13:48:32 +0000 (14:48 +0100)]
ubusd/libubus-io: fix socket descriptor passing
In commit
5d7ca8309d0a ("ubusd/libubus-io: fix variable sized struct
position warning") the position of cmsghdr struct has been changed in
order to fix clang-9 compiler warning, but it has introduced regression
in at least `logread` which hanged indefinitely.
So this patch reworks the socket descriptor passing in a way recommended
in the `cmsg(3)` manual page.
Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-December/020840.html
Fixes: 5d7ca8309d0a ("ubusd/libubus-io: fix variable sized struct position warning")
Reported-by: Hannu Nyman <hannu.nyman@welho.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 26 Dec 2019 08:46:05 +0000 (09:46 +0100)]
ci: enable unit testing
In commit
08f17c87a000 ("add fuzzer and cram based unit tests") some
fuzz/unit tests were added so enable them on CI as well.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 19 Dec 2019 10:25:56 +0000 (11:25 +0100)]
fix blob parsing vulnerability by using blob_parse_untrusted
blob_parse expects blobs from trusted inputs, but it can be supplied
with possibly malicious blobs from untrusted inputs as well, which might
lead to undefined behaviour and/or crash of ubus daemon. In order to
prevent such conditions, switch to blob_parse_untrusted which should
hopefully handle such untrusted inputs appropriately.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 19 Dec 2019 09:48:57 +0000 (10:48 +0100)]
ubus_monitor: workaround possibly false positive uses of memory after it is freed
scan-build from clang-9 has reported following:
libubox/list.h:141:2: warning: Use of memory after it is freed
_list_add(_new, head, head->next);
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 19 Dec 2019 10:10:46 +0000 (11:10 +0100)]
ubusd_monitor: fix possible null pointer dereference
This dereference could possibly happen if the calloc call fails as the
return value is unchecked. While at it refactor the code little bit to
make it easier to follow, use safe list iterator and provide return
value for ubusd_monitor_connect.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 19 Dec 2019 09:42:35 +0000 (10:42 +0100)]
ubus_common: remove duplicate ARRAY_SIZE and add missing include
ARRAY_SIZE is available from libubox/utils.h.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Mon, 16 Dec 2019 22:41:31 +0000 (23:41 +0100)]
workaround possibly false positive uses of memory after it is freed
scan-build from clang-9 has reported following:
libubox/list.h:83:22: warning: Use of memory after it is freed
entry->next->prev = entry->prev;
^~~~~~~~~~~
ubusd_event.c:42:3: warning: Use of memory after it is freed
ubusd_delete_event_source(ev);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Which might be a false positives, but in order to make the code pass the
static analyzer checks, rewrite the while loops on lists with the safe
list iterator.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Mon, 16 Dec 2019 22:02:02 +0000 (23:02 +0100)]
lua: ubus_lua_do_subscribe: fix copy&paste error
Fix copy&paste error in Lua ubus subscriber removal callback.
Addresses-Coverity-ID:
1412311 ("Copy-paste error")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Mon, 16 Dec 2019 20:52:55 +0000 (21:52 +0100)]
lua: workaround false positive dereference of null pointer
scan-build from clang-9 has reported following:
ubus.c:837:16: warning: Access to field 'rnotify' results in a dereference of a null pointer (loaded from variable 'sub')
sub->rnotify = luaL_ref(L, -2);
Which is false positive as the lua_error() does a long jump and
therefore never returns and this long jump probably confuses the static
analyzer. So this patch workarounds this false positive by helping
static analyzer by using common Lua idiom which is to return
lua_error()'s return value.
Ref: https://www.lua.org/manual/5.1/manual.html#lua_error
Addresses-Coverity-ID:
1412355 ("Dereference after null check")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 12 Dec 2019 22:24:15 +0000 (23:24 +0100)]
add fuzzer and cram based unit tests
For improved QA etc.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Thu, 12 Dec 2019 09:05:48 +0000 (10:05 +0100)]
refactor ubusd.c into reusable ubusd_library
In order to allow reusability in unit testing & fuzzing.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 12:31:59 +0000 (13:31 +0100)]
examples: remove dead increments
Fixes following error reported by clang-9 analyzer:
examples/server.c:244:2: warning: Value stored to 'argc' is never read
argc -= optind;
^ ~~~~~~
examples/server.c:245:2: warning: Value stored to 'argv' is never read
argv += optind;
^ ~~~~~~
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 11:59:40 +0000 (12:59 +0100)]
add initial GitLab CI support
Uses currently proof-of-concept openwrt-ci[1] in order to:
* improve the quality of the codebase in various areas
* decrease code review time and help merging contributions faster
* get automagic feedback loop on various platforms and tools
- out of tree build with OpenWrt SDK on following targets:
* ath79-generic
* imx6-generic
* malta-be
* mvebu-cortexa53
- out of tree native build on x86/64 with GCC (versions 7, 8, 9) and Clang 10
- out of tree native x86/64 static code analysis with cppcheck and
scan-build from Clang 9
1. https://gitlab.com/ynezz/openwrt-ci/
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 10:15:02 +0000 (11:15 +0100)]
libubus: fix incompatible pointer types assigment
Fixes following error reported by clang-9 analyzer:
libubus.c:286:19: error: incompatible pointer types assigning to 'struct blob_attr *' from 'char *' [-Werror,-Wincompatible-pointer-types]
ctx->msgbuf.data = (char *) calloc(UBUS_MSG_CHUNK_SIZE, sizeof(char));
Result of 'calloc' is converted to a pointer of type 'struct blob_attr',
which is incompatible with sizeof operand type 'char'.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 09:36:36 +0000 (10:36 +0100)]
iron out all extra compiler warnings
clang-9 on x86/64 has reported following warnings/errors:
libubus-acl.c:123:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
libubus-io.c:108:18: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
libubus-io.c:395:56: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
libubus-req.c:441:4: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:119:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_acl.c:152:5: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:348:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:352:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:357:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:362:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:367:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:447:16: error: comparison of integers of different signs: 'int' and '__size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
ubusd_acl.c:502:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:123:13: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:170:15: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:262:43: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:287:30: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_event.c:170:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_obj.c:71:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 09:07:08 +0000 (10:07 +0100)]
ubusd/libubus-io: fix variable sized struct position warning
Fixes following clang-9 compiler warnings:
ubusd.c:99:18: error: field 'h' with variable sized type 'struct cmsghdr' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
struct cmsghdr h;
^
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 09:04:36 +0000 (10:04 +0100)]
ubusd: fix comparison of integers of different signs
Fixes following clang-9 compiler warning:
ubusd.c:36:19: error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'int' [-Werror,-Wsign-compare]
if (ub->refcount == ~0) {
~~~~~~~~~~~~ ^ ~~
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar [Wed, 11 Dec 2019 08:59:02 +0000 (09:59 +0100)]
cmake: enable extra compiler checks
Let's enforce additional automatic checks enforced by the compiler in
order to catch possible errors during compilation.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Alban Bedel [Fri, 14 Jun 2019 14:51:56 +0000 (16:51 +0200)]
ubus: Support static builds
Extend the cmake config to build and install static libraries
when -DBUILD_STATIC=ON is used.
Signed-off-by: Alban Bedel <albeu@free.fr>
Felix Fietkau [Tue, 16 Apr 2019 09:13:44 +0000 (11:13 +0200)]
ubusd: retry sending messages on EINTR
Avoids unnecessary delays and/or blocking on messages
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Tue, 16 Apr 2019 09:00:49 +0000 (11:00 +0200)]
libubus: attempt to receive data before calling poll
Data is often already present here
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Tue, 16 Apr 2019 08:34:45 +0000 (10:34 +0200)]
libubus: do not abort recv_retry before completing a message
If the header is read but not the remainder of the message, the stream
will be out of sync and parsing of future messages won't work
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Hans Dedecker [Wed, 3 Oct 2018 13:36:18 +0000 (15:36 +0200)]
ubusd_acl: event send access list support
Adds event send access list support in ubus via the "send" keyword
Example of a json file:
{
"user": "superuser",
"send": [ "wireless.*" ],
}
Signed-off-by: Koen Dergent <koen.cj.dergent@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Hans Dedecker [Wed, 3 Oct 2018 13:36:17 +0000 (15:36 +0200)]
ubusd_acl: event listen access list support
Adds event listen access list support in ubus via the "listen" keyword
Example of a json file:
{
"user": "superuser",
"listen": [ "network.*" ],
}
Signed-off-by: Koen Dergent <koen.cj.dergent@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Hans Dedecker [Wed, 3 Oct 2018 13:36:16 +0000 (15:36 +0200)]
ubusd_acl: rework wildcard support
Wildcard access list support was failing in case multiple wildcards
entries were defined and/or when a specific access list string
overlapped a wildcard entry.
Root cause of the problem was the way how wildcard entries were sorted
in the avl tree by the compare function ubusd_acl_match_path resulting
into a non acces list match for a given object path.
The avl_tree sorting has been changed to make use of avl_strcmp; as such
there's no distinction anymore between non-wildcard and wildcard entries
in the avl_tree compare function as the boolean partial marks an access
list entry as a wildcard entry.
When trying to find an access list match for an object path the access list
tree is iterated as long as the number of characters between the access list
string and object path is monotonically increasing.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Hans Dedecker [Wed, 3 Oct 2018 13:36:15 +0000 (15:36 +0200)]
ubusd_event: move strmatch_len to ubus_common.h
Rename strmatch_len into ubus_strmatch_len and move it to ubus_common.h
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Marcus Comstedt [Tue, 21 Aug 2018 10:43:06 +0000 (12:43 +0200)]
ubus/lua: add support for BLOBMSG_TYPE_DOUBLE
Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
Felix Fietkau [Thu, 26 Jul 2018 13:17:36 +0000 (15:17 +0200)]
libubus: pass an empty UBUS_ATTR_DATA block if msg is NULL on invoke
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Wed, 25 Jul 2018 08:37:30 +0000 (10:37 +0200)]
libubus: check for non-NULL data before running callbacks
UBUS_MSG_INVOKE and UBUS_MSG_DATA can be sent without UBUS_ATTR_DATA
present. Most ubus users assume that the msg argument passed can never
be NULL, so this change prevents a crash
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Dirk Feytons [Tue, 16 Jan 2018 17:13:39 +0000 (18:13 +0100)]
ubus/lua: pass notification name to callback
The callback function registered to be invoked when subscribing to a
notification was only passed the notification data (if any) but not the name
of the notification.
This name is now passed as second argument to remain backwards compatible.
The example subscriber.lua has also be updated.
Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
John Crispin [Wed, 3 Jan 2018 10:56:48 +0000 (11:56 +0100)]
valgrind complained about these
==18834== Warning: invalid file descriptor -1 in syscall close()
==18834== at 0x5326D20: __close_nocancel (syscall-template.S:84)
==18834== by 0x5046DC7: ubus_process_obj_msg (libubus-obj.c:143)
==18834== by 0x5045E98: ubus_process_msg (libubus.c:106)
==18834== by 0x50468D0: ubus_handle_data (libubus-io.c:314)
==18834== by 0x4E3D125: uloop_run_events (uloop.c:198)
==18834== by 0x4E3D125: uloop_run_timeout (uloop.c:555)
==18834== by 0x109BEF: uloop_run (uloop.h:111)
==18834== by 0x109BEF: main (main.c:25)
Signed-off-by: John Crispin <john@phrozen.org>
John Crispin [Wed, 3 Jan 2018 10:52:56 +0000 (11:52 +0100)]
fix invalid close() call
valgrind complained about this one
==18632== Warning: invalid file descriptor -1 in syscall close()
==18632== at 0x5326D20: __close_nocancel (syscall-template.S:84)
==18632== by 0x5046C02: ubus_process_invoke (libubus-obj.c:98)
==18632== by 0x5046DC3: ubus_process_obj_msg (libubus-obj.c:142)
==18632== by 0x5045E98: ubus_process_msg (libubus.c:106)
==18632== by 0x50468D0: ubus_handle_data (libubus-io.c:314)
==18632== by 0x4E3D125: uloop_run_events (uloop.c:198)
==18632== by 0x4E3D125: uloop_run_timeout (uloop.c:555)
==18632== by 0x109BEF: uloop_run (uloop.h:111)
==18632== by 0x109BEF: main (main.c:25)
Signed-off-by: John Crispin <john@phrozen.org>
Alexandru Ardelean [Wed, 7 Jun 2017 11:09:31 +0000 (14:09 +0300)]
ubusd: move global retmsg per client
Even with the tx_queue-ing issue resolved, what
seems to happen afterwards, is that all the messages
seems to get through, but the client still loops
in the `ubus_complete_request()` waiting for
`req->status_msg` or for a timeout.
Though, the timeout does not seem to happen, because
the data is processed in `ubus_poll_data()`, with
a infinite poll() timeout (ubus_complete_request() is
called with timeout 0).
It's likely that either the `seq` or `peer` sent from
ubusd are wrong, and the client cannot get the correct
ubus request in `ubus_process_req_msg()`.
I haven't digged too deep into this ; setting the
`retmsg` object on the client struct seems to have
resolved any hanging with the `ubus list` command.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [fix placement of retmsg in cl]
Alexandru Ardelean [Wed, 5 Jul 2017 13:21:47 +0000 (16:21 +0300)]
ubusd_monitor: alloc & free the buffer outside of the loop
Should save a few cycles, since the data that's
being changed is only the seq number.
And the `ub` is always created as shared.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Alexandru Ardelean [Wed, 5 Jul 2017 13:21:22 +0000 (16:21 +0300)]
ubusd: rename goto label from `error` to `out`
Semantic has changed a bit.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Alexandru Ardelean [Wed, 5 Jul 2017 13:20:51 +0000 (16:20 +0300)]
ubusd: don't free messages in ubus_send_msg() anymore
This makes it clear that `ubus_msg_send()` is only
about sending and queue-ing messages, and has nothing
to do with free-ing.
It can be a bit misleading/confusing when trying to go
through the code and make assumptions about whether a
buffer is free'd in ubus_send_msg(), or is free'd outside.
In `ubusd_proto_receive_message()` the `ubus_msg_free()`
is now called before the `if (ret == -1)` check.
That way, all callbacks will have their messages free'd,
which is what's desired, but confusing, because:
* ubusd_handle_invoke() called ubus_msg_free() before returning -1
* ubusd_handle_notify() called ubus_msg_free() before returning -1
* ubusd_handle_response() called ubus_msg_send(,,free=true) before returning -1
* ubus_msg_send() would call ubus_msg_send(,,free=false)
* all other callback callers would `ubus_msg_send(,,free=true)`
(free the buffers in ubus_msg_send() )
In all other places, where `ubus_msg_send(,,free=true)`
an explicit `ubus_msg_free()` was added.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Bob Ham [Thu, 9 Nov 2017 15:53:24 +0000 (15:53 +0000)]
libubus: Fix deletion from context's object AVL tree when removing object
Objects are stored in the ubus context in an AVL tree. An AVL tree
node contains a pointer to a key value. For the ubus context, this
points to the id member of the object structure. In
ubus_remove_object_cb, the id member is set to zero and then after,
avl_delete is called and fails. To fix this, we call avl_delete
before setting the object id to zero.
Signed-off-by: Bob Ham <bob.ham@tomltd.co.uk>
Rosen Penev [Tue, 7 Nov 2017 20:34:20 +0000 (12:34 -0800)]
ubus: Remove unnecessary memset calls.
Replace malloc+memset with calloc.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
John Crispin [Wed, 1 Nov 2017 21:14:42 +0000 (22:14 +0100)]
libubus-req: add data_cb callback handling for ubus notifications
Signed-off-by: John Crispin <john@phrozen.org>
Hans Dedecker [Sat, 18 Feb 2017 12:41:53 +0000 (13:41 +0100)]
cli: fix listen_timeout compile issue
Variable listen_timeout is redefined as a function resulting into
a compile issue. Define the function as ubus_cli_listen_timeout
to fix the compile issue.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Hans Dedecker [Sat, 18 Feb 2017 12:41:52 +0000 (13:41 +0100)]
libubus: reset ctx->sock.error when doing ubus reconnect
When ubus connect fails ctx->sock.eof will be set but ctx->sock.error
can be set as well. Reset ctx->sock.error as well when doing ubus
reconnect
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Felix Fietkau [Wed, 15 Feb 2017 10:35:35 +0000 (11:35 +0100)]
cli: do not use default timeout for listen
Default to listening for events forever unless -t is explicitly
specified on the command line
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Tue, 14 Feb 2017 14:58:49 +0000 (15:58 +0100)]
cli: add support for subscribing to objects
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Alexandru Ardelean [Thu, 2 Feb 2017 15:59:49 +0000 (17:59 +0200)]
ubusd: fix incomplete copy of shared buf during queue-ing
For a shared ubus_msg_buf, the ubus_msg_ref function will
create a copy for queue-ing.
Problem is, that during the dequeue (especially) in client_cb,
the header is 0-ed (because it's was a newly alloc-ed buffer).
And during ubus_msg_writev(), the header info will be ignored
by the client.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Felix Fietkau [Fri, 3 Feb 2017 17:39:11 +0000 (18:39 +0100)]
libubus: do not modify uloop_cancelled
uloop_cancelled was used for two purposes within ubus_complete_request:
- interrupting recursive requests on SIGINT/SIGTERM
- breaking out of the poll loop in a recursive request that completed
Saving/restorung uloop_cancelled was buggy, leading to SIGTERM not being
processed properly. Simplify the logic by using a separate field for
internal use
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Fri, 3 Feb 2017 13:13:48 +0000 (14:13 +0100)]
libubus: reset ctx->sock.eof to fix reconnect issues
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Sun, 22 Jan 2017 13:33:37 +0000 (14:33 +0100)]
libubus: do not register/unregister with uloop during sync requests
This was leftover code from before this codepath was converted to
polling directly
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Sun, 22 Jan 2017 13:28:47 +0000 (14:28 +0100)]
libubus: move uloop_init() call to ubus_connect_ctx
uloop should not be used before it is initialized
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Mihai Richard [Thu, 19 Jan 2017 12:51:04 +0000 (12:51 +0000)]
ubusd: fix issue caused by an implicit cast
An -1 returned by ubus_msg_writev() will be interpreted as
UINT_MAX during a check to see how much data had could be
written on the socket.
Because sizeof() will return size_t it will promote the
comparsion to unsigned
Signed-off-by: Mihai Richard <mihairichard@live.com>
Abhimanyu Vishwakarma [Tue, 3 Jan 2017 06:07:05 +0000 (11:37 +0530)]
ubus: ubus_free: clear pending timers before freeing context
If a synchronous operation is executed on a ubus context after
uloop_done() has been called, the context's pending_timer
may remain in uloop's list of timeouts.
This leads to undefined behaviour during next execution of uloop
code, as it may be referring to unavailable memory or memory
that has been allocated for different purposes.
Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
Felix Fietkau [Sat, 24 Dec 2016 13:35:58 +0000 (14:35 +0100)]
libubus: reduce code duplication, fix indentation
Signed-off-by: Felix Fietkau <nbd@nbd.name>
amine ahd [Mon, 19 Dec 2016 09:30:36 +0000 (10:30 +0100)]
Allow sending a fd along a ubus_request
Signed-off-by: amine.ahd <amine.ahd@gmail.com>
Felix Fietkau [Sun, 20 Nov 2016 16:05:00 +0000 (17:05 +0100)]
ubusd: fix id lookup of objects with path and no methods
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Vasily Goldobin [Wed, 16 Nov 2016 15:26:13 +0000 (20:26 +0500)]
lua: add 'defer_request' and 'complete_deferred_request' functions
Add Lua bindings for 'ubus_defer_request' and 'ubus_complete_deferred_request' functions with sample code.
Signed-off-by: Vasily Goldobin <vasily@lynxtech.ru>
Felix Fietkau [Sun, 20 Nov 2016 15:40:06 +0000 (16:40 +0100)]
ubusd_proto: fix crash when trying to subscribe to system objects
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Sun, 20 Nov 2016 15:26:19 +0000 (16:26 +0100)]
build: remove /opt/local prefix
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Alexandru Ardelean [Thu, 5 May 2016 11:03:30 +0000 (14:03 +0300)]
cli: register event handler first, then do lookup
We seem to be getting timeout for ubus wait_for calls
every now and then.
And it's not reliably reproducible.
Looking at the code the only thing that would look like
a potetntial reason, is that between the ubus_lookup() and
ubus_register_event_handler() calls, there's a very narrow
window where the event would get sent out and we would not
get it, thus having to timeout.
It doesn't look like registering the event handler first
is a big problem for the whole wait_check_object() logic.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Denis Osvald [Thu, 25 Aug 2016 11:54:54 +0000 (13:54 +0200)]
ubusd: fix inverted check in ubusd_reply_add
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
Denis Osvald [Thu, 25 Aug 2016 11:54:52 +0000 (13:54 +0200)]
ubusd: don't check ACL when object is NULL
If there are any ACLs present other than global wildcard "*", the AVL
tree comparator will compare ACL key to object name. However, object
name can be NULL in cases where ACL check is done on call to internal
ubus objects (e.g. ubus monitor).
With this change we skip checking ACLs on such NULL objects.
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
Felix Fietkau [Tue, 23 Aug 2016 10:55:08 +0000 (12:55 +0200)]
ubusd: fix sending remove-object notification
Patch by Delio Brignoli <brignoli.delio@gmail.com>
Both ubusd_free_object (eventually via ubusd_create_object_event_msg)
and ubus_proto_send_msg_from_blob() use the same message buffer.
So ubusd_handle_remove_object builds the payload which gets (indirectly)
overwritten by the call to ubusd_free_object and then sent again by
ubus_proto_send_msg_from_blob.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Felix Fietkau [Tue, 23 Aug 2016 09:36:41 +0000 (11:36 +0200)]
ubusd: add missing NULL pointer checks for obj->type
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Florian Fainelli [Fri, 1 Jul 2016 21:57:44 +0000 (14:57 -0700)]
cmake: Fix find_library for ubusd and examples/server
Both ubusd and cli TARGET_LINK_LIBRARIES reference ${json} which is
obtained via find_library(), but since the find_library() is searched
after the TARGET_LINK_LIBRARIES for ubusd, ubusd always gets an empty
${json} variable.
examples/server also links against libjson-c, but we were not setting
TARGET_LINK_LIBRARIES accordingly, so do that too with ${json} appended.
This was causing linking errors for ubusd and then examples/server using
an external toolchain (stbgcc-4.8-1.x).
Fixes: 9f52d1769b762 ("cli: use the new json-c library name")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Rujun Wang [Thu, 23 Jun 2016 03:06:06 +0000 (11:06 +0800)]
Fix the length of msg buffer after realloc
Signed-off-by: Rujun Wang <chinawrj@gmail.com>
Iain Fraser [Thu, 19 May 2016 13:40:42 +0000 (14:40 +0100)]
Implemented publish/subscribe lua bindings to libubus-lua with example lua files.
John Crispin [Wed, 1 Jun 2016 09:37:30 +0000 (11:37 +0200)]
ubusd: remove systemd socket activation support
Signed-off-by: John Crispin <john@phrozen.org>
Matthias Schiffer [Tue, 24 May 2016 00:01:48 +0000 (02:01 +0200)]
ubusd: fix systemd socket activation support
62cdfc3 added systemd units including a ubus.socket unit, but didn't
actually add socket activation support to ubusd. This would cause the first
connection that activated ubusd to hang (as ubusd ignored it), and stopping
ubusd would break it completely (as ubusd removed the socket file).
The ENABLE_SYSTEMD default is changed to OFF as the socket activation uses
libsystemd, so setting ENABLE_SYSTEMD to ON will now require libsystemd.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Eyal Birger [Sun, 15 May 2016 05:13:27 +0000 (08:13 +0300)]
libubus: nullify stale msgbuf pointer in case of ubus_connect_ctx() failure
If the ubus_reconnect() call fails in ubus_connect_ctx(), the msgbuf.data
newly allocated buffer is freed, but its pointer in the ubus_context is not
removed.
This leads to a double free error if ubus_auto_shutdown() is called for cleanup
after ubus_auto_connect() failed to connect to ubusd.
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Petr Štetiar [Sat, 5 Mar 2016 13:59:33 +0000 (14:59 +0100)]
cmake: Add ubox, blobmsg_json libraries and include dirs lookup
Otherwise cmake uses files from system which sometimes isn't wanted, ie.
for testing.
Signed-off-by: Petr Å tetiar <ynezz@true.cz>
Zhao, Gang [Fri, 26 Feb 2016 09:18:39 +0000 (17:18 +0800)]
cli: add timeout support for listen command
Currently 'ubus listen' command does not respect the timeout parameter,
i.e., whether timeout parameter is provided, 'ubus listen' will always
run infinitely. This patch let 'ubus listen' command support the timeout
parameter. For example, 'ubus listen -t 60' will cause the command to
exit after 60 seconds.
Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
Zhao, Gang [Fri, 26 Feb 2016 09:18:38 +0000 (17:18 +0800)]
cli: static keyword tweak
Function ubus_cli_listen() is called only once, and function uloop_run()
and uloop_done() which need struct ubus_event_handler listener are
called within this function, so it's not needed to mark struct
ubus_event_handler listener as static. The same as pointer struct
ubus_context *ctx in main function.
Global struct commands is only used in this file, so it should be marked
static.
Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
Eyal Birger [Mon, 15 Feb 2016 04:09:38 +0000 (06:09 +0200)]
ubus: use network order in ubus message header fields
Changing the ubus message header fields from 'host' order to 'network' order
allows passing ubus messages between hosts with different endianity.
Example use (creating a ubus proxy):
on host A (e.g. big endian router already running ubusd), run:
$ socat TCP-LISTEN:5699,fork UNIX:/var/run/ubus.sock &
On host B (e.g. little endian development PC) run:
$ socat UNIX-LISTEN:/var/run/ubus.sock,fork TCP:<host A IP>:5699 &
Now ubus applications can be run on host B and seamlessly interact with ubus
applications on host A.
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Emanuel Taube [Fri, 12 Feb 2016 12:28:12 +0000 (13:28 +0100)]
libubus.h: marking unused variables
Inform the compiler that the variables are not gona be used to avoid
compiler warnings.
Signed-off-by: Emanuel Taube <emanuel.taube@gmail.com>
Ben Kelly [Tue, 2 Feb 2016 13:02:59 +0000 (15:02 +0200)]
libubus.h: add ubus_auto_shutdown()
Add ubus_auto_shutdown function, which ensures any pending uloop_timer is cancelled before calling ubus_shutdown on the context.
This avoids a condition where ubus_shutdown() is called during ubus_auto_connect attempting a reconnection.
Signed-off-by: Ben Kelly <ben@benjii.net>
Felix Fietkau [Tue, 26 Jan 2016 09:10:39 +0000 (10:10 +0100)]
ubusd: fix a memory leak on user/group client info
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 20 Jan 2016 13:59:04 +0000 (14:59 +0100)]
lua: fix stack leak in ubus method handling
Signed-off-by: Chen Bin <ewolfok@126.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 13 Jan 2016 11:28:37 +0000 (12:28 +0100)]
ubusd: add missing NULL pointer checks for ACL processing
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Alexandru Ardelean [Thu, 17 Dec 2015 08:45:22 +0000 (10:45 +0200)]
libubus: add null for ubus_context object in ubus_shutdown()
At the moment, we do our own null checks before calling ubus_free().
The likely-hood of 'ctx' being null (in ubus_free()) is low,
but since free() handles null, might make sense for ubus_free() to do so as well.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Felix Fietkau [Wed, 9 Dec 2015 19:16:31 +0000 (20:16 +0100)]
ubusd: allow all object access if uid=0 (ignore gid)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 18:48:08 +0000 (19:48 +0100)]
ubusd: fix the return code for acl check mismatch
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 18:39:24 +0000 (19:39 +0100)]
ubusd: simplify/fix avl loop in ubusd_reply_add()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 18:36:49 +0000 (19:36 +0100)]
ubusd: simplify/fix avl loop in ubusd_acl_check()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 17:35:07 +0000 (18:35 +0100)]
libubus: add socket EOF handling to ubus_complete_request()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 17:26:43 +0000 (18:26 +0100)]
libubus: fix error handling during close after partially receiving a message
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 16:44:00 +0000 (17:44 +0100)]
ubusd: make ACL path configurable on the command line
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Wed, 9 Dec 2015 16:36:08 +0000 (17:36 +0100)]
ubusd: remove a faulty and redundant check
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Karl Vogel [Mon, 7 Dec 2015 07:35:52 +0000 (08:35 +0100)]
ubus: Correct usage of timeout on poll function
As the man page explains:
"Specifying a timeout of zero causes poll() to return immediately,
even if no file descriptors are ready."
The use of 0 as timeout could cause libubus to busy loop if the
socket was non-blocking. For blocking sockets, this was less
apparent as the subsequent read() would then block.
Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
Felix Fietkau [Thu, 19 Nov 2015 21:32:29 +0000 (22:32 +0100)]
cli: add monitor support
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Thu, 19 Nov 2015 21:32:25 +0000 (22:32 +0100)]
libubus: add monitor support
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau [Thu, 19 Nov 2015 21:32:11 +0000 (22:32 +0100)]
ubusd: add monitor support
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Hans Dedecker [Mon, 2 Nov 2015 10:16:11 +0000 (11:16 +0100)]
libubus: Fix reverse order processing of pending ubus notifications messages
Append ubus notification messages to the tail of the pending list
so they're processed in the order as they're put onto the pending list
Signed-off-by: Xinxing Hu <xinxing.huchn@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Hans Dedecker [Mon, 2 Nov 2015 10:16:10 +0000 (11:16 +0100)]
lua: Fix stack imbalance in ubus_event_handler
The value from getglobal wasn't being removed from the stack,
resulting in an ever growing stack in the ubus event handler.
Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
John Crispin [Tue, 22 Sep 2015 04:20:55 +0000 (06:20 +0200)]
fix off-by-one in acl match iteration
Signed-off-by: John Crispin <blogic@openwrt.org>
John Crispin [Tue, 22 Sep 2015 04:12:08 +0000 (06:12 +0200)]
unbreak acl allocation
Signed-off-by: John Crispin <blogic@openwrt.org>