Commit graph

210 commits

Author SHA1 Message Date
Jo-Philipp Wich
4c532bfed2 ucode: add ucode interpreter plugin
The rpcd ucode plugin allows utilizing ucode scripts to register ubus
objects and to implement the objects method callbacks.

Upon startup, rpcd will compile and execute each ucode script in
`$INSTALL_PREFIX/share/ucode/` and register ubus proxy objects and
methods definitions according to the signature returned by the script.

Refer to examples/ucode/example-plugin.uc for details of the signature
format.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-08 20:09:24 +01:00
Jo-Philipp Wich
9c6ba38287 treewide: adjust ubus object type names
Drop the historically inherited "luci-rpc-" prefix and replace it with a
more appropriate "rpcd-plugin-" string.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-08 20:09:24 +01:00
Jo-Philipp Wich
75a96dc281 build: honour CMake install prefix in hardcoded paths
Search plugins, ACL ressources and other data files relative to the compile
time CMAKE_INSTALL_PREFIX instead of hardcoding `/usr`.

Also ensure that plugin libraries are installed into the lib/rpcd subdir.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-08 20:09:24 +01:00
Stijn Tintel
d11ffe9383 session: use blobmsg_get_u64 for RPC_DUMP_EXPIRES
We need to use blobmsg_get_u64 for RPC_DUMP_EXPIRES as this is now
BLOBMSG_TYPE_INT64.

Fixes: 20bf958bea ("session: use uloop_timeout_remaining64")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2021-11-04 14:42:38 +02:00
Stijn Tintel
20bf958bea session: use uloop_timeout_remaining64
The uloop_timeout_remaining is being deprecated.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: John Crispin <john@phrozen.org>
2021-11-04 13:15:38 +02:00
Jo-Philipp Wich
1fa35765dd session: unload rpcd configuration before checking login
Currently, rpcd cached /etc/config/rpcd once on the first login and then
keeps checking login attempts and ACL settings against the in-memory
copy until the process is restarted.

This is not desirable as we would like added, modified or removed accounts
to be effective immediately. In order to achive this behaviour, ensure to
unload the currently loaded rpcd configuration before looking up the login
account section.

Ref: https://github.com/openwrt/luci/issues/5179
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-13 20:41:02 +02:00
David Bauer
7a560a1a57 iwinfo: add 802.11ax HE support
Expose 802.11ax HE rate as well as HW / HT mode information. This is
required to add 802.11ax support to LuCI.

Signed-off-by: David Bauer <mail@david-bauer.net>
2021-05-05 01:30:36 +02:00
Daniel Golle
ccb75178cf
sys: packagelist: drop ABI version from package name
Having the ABI version appended to the package name is not very helpful
when checking for updated versions of a package online or requesting
a new image for the device from an updater service. In both cases,
the ABI version could have been bumped meanwhile and that name is then
simply not found.
Resolve this by removing the appended ABI version in the output of the
rpc-sys packagelist call.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-03-11 00:17:58 +00:00
Jo-Philipp Wich
d3f2041f43 uci: manually clear uci_ptr flags after uci_delete() operations
This is required to avoid potential use-after-free errors through the
uci_set()->uci_delete()->uci_expand_ptr() call chain when passing
zero-length strings as values.

Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3528
Suggested-by: olegio170 <olegios170@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-01-17 21:14:46 +01:00
Ansuel Smith
ea7f4717f8 iwinfo: include ht_operation data only if available
Check if ht_operation data are present and add them accordingly.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
2021-01-06 19:42:14 +00:00
Daniel Golle
5c15f5736d iwinfo: return hwmode 'ad' on 802.11ad-only hardware
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-01-05 22:32:45 +00:00
Daniel Golle
e28d4a58bf iwinfo: add support for 802.11ad and GCMP
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-01-05 19:09:17 +00:00
Ansuel Smith
4c66b31097 iwinfo: export center channel for info ubus call
Iwinfo export the center channel sued by the wifi. Include this data in
the ubus info call to better know the channel utilizzation of the wifi.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
2021-01-05 19:09:17 +00:00
Ansuel Smith
fd017ba339 iwinfo: add ht and vht operation info to wifi scan
Iwinfo exports ht and vht operation info useful to get channel info of
nearby stations. Add these new info to ubus output.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
2021-01-05 19:09:17 +00:00
Rafał Miłecki
3fea655981 rc: support init.d scripts with START=0
Use negative value (instead of 0) to indicate missing START.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2020-09-18 08:10:56 +02:00
Rafał Miłecki
646daa0bec rc: new ubus object for handling /etc/init.d/ scripts
This commit adds "rc" ubus object with methods "list" and "exec" for
listing and calling init.d script appropriately. It's useful for all
kind of UIs (e.g. LuCI) and custom apps.

Example:
root@OpenWrt:~# ubus call rc list
{
	"blockd": {
		"start": 80,
		"enabled": true,
		"running": true
	},
	"dnsmasq": {
		"start": 19,
		"enabled": true,
		"running": true
	}
}
root@OpenWrt:~# ubus call rc init '{ "name": "blockd", "action": "disable" }'
root@OpenWrt:~# ubus call rc init '{ "name": "dnsmasq", "action": "stop" }'
root@OpenWrt:~# ubus call rc list
{
	"blockd": {
		"start": 80,
		"enabled": false,
		"running": true
	},
	"dnsmasq": {
		"start": 19,
		"enabled": true,
		"running": false
	}
}

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10 13:18:09 +02:00
Jo-Philipp Wich
078bb57e07 uci: reset uci_ptr flags when merging options during section add
Fixes: FS#3126
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-05-26 16:00:34 +02:00
Fabian Bläse
3df62bcebd session: deny access if password login is disabled
The special characters '!' and '*' in /etc/shadow are
used to disable password login for a specific account.

The character 'x' has no special meaning, but should not
be interpreted as an empty password.

However, rpcd did treat these special characters like no
password was set, which allows access even though the account
is disabled.

By removing the additional checks for these characters, the
encrypted password string is passed to crypt, which returns NULL
if the salt has an invalid format and therefore access is denied.

Fixes: FS#2634

Signed-off-by: Fabian Bläse <fabian@blaese.de>
2020-03-17 19:33:35 +01:00
Daniel Danzberger
efe51f41d6 iwinfo: add current hw and ht mode to info call
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
2020-01-05 19:56:34 +01:00
Jo-Philipp Wich
aaa08366e6 file: extend exec acl checks to commands with arguments
When the initial exec permission check on the executable path fails,
concatenate the command line with spaces and use the resulting string
as lookup path for a second exec permission check.

This allows for exec acls similar to this example:

    "file": {
        "/usr/bin/program --flag --option=1 arg *": [ "exec" ]
    }

The example above would allow executing `/usr/bin/program` with the
arguments `--flag`, `--option=1` and `arg` in exactly this order,
followed by any number of optional arguments as denoted by the
asterisk.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-11 09:13:05 +01:00
Jo-Philipp Wich
77ad0de092 plugin: avoid truncating numeric values
When parsing the JSON output of exec plugins, store integer values exceeding
32bit value limits as 64bit integer blob values.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-10 21:26:51 +01:00
Jo-Philipp Wich
d442d62dea plugin: fix double free in finish callback
Fixes: 37aa919 ("plugin: fix leaking invoked method name for exec plugins")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 12:01:36 +01:00
Yousong Zhou
ee26d83e98 main: exec_self: make clang analyzer happy
Prevent a theoretical leak of the args memory when the executable path
cannot be found.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace, commit description]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:26:24 +01:00
Yousong Zhou
90e40bd3d5 file: exec: properly free memory on error
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:26:18 +01:00
Yousong Zhou
9ecfada16d uci: free configs list memory on return
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:25:17 +01:00
Yousong Zhou
32fba361d5 exec: always call finish_cb to allow plugin to free up memory
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace, subject typo]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:24:46 +01:00
Jo-Philipp Wich
ca3e2d5e70 plugin: do not free method name separately
A previous commit changed the allocation method for the call context to
include the method name string memory directly, so we must not treat the
method member separately anymore.

Fixes: 37aa919 ("plugin: fix leaking invoked method name for exec plugins")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:23:30 +01:00
Yousong Zhou
02c6e1d08c exec: properly free memory on rpc_exec() error
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 09:23:22 +01:00
Yousong Zhou
cc50263504 plugin: exec: properly free memory on parse error
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2019-10-29 08:59:37 +01:00
Jo-Philipp Wich
bd0ed25214 uci: reset uci_ptr flags when merging set operations
In some cases, e.g. when subsequently setting multiple empty option
values, uci_set() might free the section pointer of the given reused
uci_ptr structure without zeroing it, leading to a use-after-free on
processing subsequent options.

Avoid this issue by clearing the lookup pointer flags in order to
prevent uci_set() from incorrectly branching into a uci_delete()
operation leading to the freeing of the section member.

Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-October/019592.html
Reported-by: Daniel Danzberger <daniel@dd-wrt.com>
Suggested-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-29 08:28:17 +01:00
Jo-Philipp Wich
37aa9196b6 plugin: fix leaking invoked method name for exec plugins
The invoked method name was separately duplicated from the call_context
structure. The structure itself is eventually freed by rpc_exec_reply()
but the method string it points to is lost after that.

Use calloc_a() instead to allocate the string copy buffer together with
the context structure, to ensure that all involved memory is freed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-17 11:50:39 +02:00
Jo-Philipp Wich
95f0973c34 file: increase minimum read buffer size to 4096 bytes
Some sysfs or proc files contain more than 128 byte of data, e.g. the
/proc/filesystems or /proc/mounts files.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-21 14:58:38 +02:00
Jo-Philipp Wich
e2a7bc4c2f iwinfo: add WPA3 support
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-09 12:46:20 +02:00
Jo-Philipp Wich
69eeb1b480 file: refactor message parsing and permission checking
Refactor rpc_check_path() and wrap it with a macro to allow passing
different policies and permission names.

This allows using the function for non-read operations and simplifies
the message parsing code there.

Also change the stat and list methods to require "list" instead of
"read" permissions which is useful to allow browing the filesystem
without allowing read access to all files.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-08 18:29:18 +02:00
Jo-Philipp Wich
f65527a298 iwinfo: expose all rate info fields in assoclist reply
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-04 15:51:39 +02:00
Jo-Philipp Wich
7fec63611d sys: fix symbol redeclaration
Fixes: 27c24c7 ("rpcd: sys: actually move timespec declaration")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-04 15:51:39 +02:00
Jo-Philipp Wich
27c24c7c18 rpcd: sys: actually move timespec declaration
Move the timespec declaration to the function header, as mentioned in
commit "rpcd: Switch to nanosleep".

Fixes: 604db20 ("rpcd: Switch to nanosleep")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-03 11:36:31 +02:00
Jo-Philipp Wich
345363bf47 file: add remove operation
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-03 11:27:44 +02:00
Rosen Penev
604db20aa6 rpcd: Switch to nanosleep
usleep has been deprecated by POSIX.1-2001 and removed in POSIX.1-2008.
Fixes compilation when libc does not include usleep (optional with
uClibc-ng).

nanosleep also has the advantage of being more accurate.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
[move timespec definition to the top of the function]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-03 11:26:51 +02:00
Jo-Philipp Wich
821045f6ce file: add path based read/write/exec ACL checks
Introduce ACL checks to verify that the requested path may be read, written
or executed. This allows to restrict ubus file commands to specific paths.

To setup the required ACLs, the following ubus command may be used
on the command line:

ubus call session grant '{
  "ubus_rpc_session": "d41d8cd98f00b204e9800998ecf8427e",
  "scope": "file",
  "objects": [
    [ "/etc", "read" ],
    [ "/etc/*", "write" ],
    [ "/sbin/sysupgrade", "exec" ]
  ]
}'

The "read", "list", "stat" and "md5" procedures require "read" permissions,
the "write" procedure requires "write" permission and the "exec" procedure
requires "exec" permissions.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-01 18:29:03 +02:00
Jo-Philipp Wich
fb337e5a08 file: add stat() information to directory listings
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-09-01 18:29:03 +02:00
Petr Štetiar
89bfaa4246 Fix possible linker errors by using CMake find_library macro
Fixes following errors while compiling natively on x86:

 cc -fPIC -shared  -o rpcsys.so sys.c.o -lubox -lubus
 ld: cannot find -lubox
 ld: cannot find -lubus

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-06-05 13:10:50 +02:00
Jo-Philipp Wich
569284a119 session: handle NULL return values of crypt()
The crypt() function may return NULL with errno ENOSYS when an attempt
was made to crypt the plaintext password using a salt requesting an
unsupported cipher.

Avoid triggering segmentation faults in the subsequent strcmp() operation
by checking for a non-NULL hash value.

Fixes: FS#2291
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-05-22 14:25:52 +02:00
Daniel Danzberger
d610800a0f iwinfo: add mesh infos in assoclist.
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
2019-03-05 19:51:54 +01:00
Daniel Danzberger
6939c493cc iwinfo: add survey.
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
2019-03-05 19:51:54 +01:00
Daniel Danzberger
ceeccb1e02 iwinfo: show more stats from assoclist.
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
2019-03-05 19:51:54 +01:00
Jo-Philipp Wich
ffaa6132cb file: avoid closing stdio descriptors in rpc_file_exec_run
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:30:19 +01:00
Jo-Philipp Wich
67118a6b33 file: patch process stdin to /dev/null
This prevents broken pipe errors in executed child processes that
attempt to access stdin.

Suggested-by: Vytautas Virvičius <vy.virvicius@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:18:23 +01:00
Jo-Philipp Wich
2e8106ac56 file: remove unused members from struct rpc_file_exec_context
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:00:48 +01:00
Jo-Philipp Wich
e5243c16eb file: rpc_file_exec_run: fix potential memory leak and integer overflow
- Store the realloc result in a separate pointer so that we can free
   the original on allocation failure
 - Use an explicit uint8_t for the argument vector length instead of
   "char" which might be signed or unsigned, depending on the arch
 - Bail out with an invalid argument error if the argument vector
   exceeds 255 items

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-12-21 09:00:20 +01:00