summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* rc: add option to get info for a single script in list methodHEADmasterChristian Marangi2023-01-311-1/+14
| | | | | | | | | | Add option to get info for a single script in list method. To get info of a particular script pass the name arg to the list method. If the script doesn't exist an empty table is returned. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* rc: add option to skip running check for list methodChristian Marangi2023-01-311-3/+22
| | | | | | | | | | | | | Running check may be slow and increase result time in the other of 70ms for the list method. Add an option to skip running check by passing the skip_running_check as true in the list method args to speedup execution if the running info is not needed. With the option set to true the execution time lower to just 5ms. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* rc: add support for scanning USE_PROCD and skip running if not supportedChristian Marangi2023-01-311-2/+9
| | | | | | | | | | | | Running check is supported only in procd scripts. This cause prolonged execution time since the function needs to timeout. To fix this check if the script USE_PROCD and run running check only if supported. Also provide running info only if the running check is supported. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* rc: fix and improve script scanning START and STOPChristian Marangi2023-01-311-2/+5
| | | | | | | | | | | | | | Currently we stop searching at the first occurence of START or STOP entry. This is wrong since we totally miss the other data (START or STOP) in the occurence of the other. Fix and improve script scanning by: - Increase the line max length to 255 char to read it in one go. - Scan only the first 10 lines. - Don't stop at the first occurence and try to search also for the other data. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* iwinfo: add "band" and "mhz" to the scan outputAndre Heider2023-01-211-1/+5
| | | | | | | Providing the channel alone isn't clear as there're overlapping channels on e.g. band 2 and 6. Signed-off-by: Andre Heider <a.heider@gmail.com>
* iwinfo: add "band" to the freqlist outputAndre Heider2023-01-211-1/+4
| | | | | | | So that consumers don't have to fiddle around with mapping frequencies to bands, which everyone seems to do a little differently. Signed-off-by: Andre Heider <a.heider@gmail.com>
* iwinfo: add flags to freqlist outputChristian Marangi2023-01-211-0/+5
| | | | | | | | | A channel can declare restriction where it should be used only indoors or should not be used at all. Expose these restriction in the channel data as additional info with the restricted info. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* iwinfo: add "hwmodes_text" to the info outputAndre Heider2022-12-161-0/+4
| | | | | | This is a preformatted string like "ac/ax/b/g/n" for presentation. Signed-off-by: Andre Heider <a.heider@gmail.com>
* iwinfo: clean up rpc_iwinfo_call_hw_ht_mode()Andre Heider2022-12-161-12/+11
| | | | | | | There's no need to call hwmodelist() again, just pass on the earlier result. Signed-off-by: Andre Heider <a.heider@gmail.com>
* iwinfo: reuse infos provided by libiwinfoAndre Heider2022-12-161-175/+84
| | | | | | | | | | | | Don't hardcode bit/name pairs, instead iterate over what's known to the library and use that instead. This automatically adds the missing ciphers CCMP256 and GCMP256 - and any future ones. The only difference in the output is the order of the 'hwmodes' array. Signed-off-by: Andre Heider <a.heider@gmail.com>
* iwinfo: constify string map arg for rpc_iwinfo_call_int()Andre Heider2022-12-161-1/+1
| | | | Fixes the build since the string maps have been constified.
* ucode: write ucode runtime exceptions to stderrJo-Philipp Wich2022-09-211-0/+18
| | | | | | | Write unhandled exceptions in invoked ucode method handlers to stderr in order to simplify debugging failing scripts. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* ucode: pass-through `ubus_rpc_session` argumentJo-Philipp Wich2022-09-121-1/+6
| | | | | | | Allow the special `ubus_rpc_session` method call argument even if it is not specified in the policy. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* ucode: initialize module search path earlyJo-Philipp Wich2022-09-121-1/+4
| | | | | | | Ensure that the default module search path is initialized before compiling ucode handler scripts in order to support compile time import statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* sys: mitigate possible strncpy string truncationPetr Štetiar2022-08-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | gcc 10 with -O2 reports following: In function ‘strncpy’, inlined from ‘rpc_sys_packagelist’ at /opt/devel/openwrt/c-projects/rpcd/sys.c:244:4: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 128 equals destination size [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘strncpy’, inlined from ‘rpc_sys_packagelist’ at /opt/devel/openwrt/c-projects/rpcd/sys.c:227:4: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 128 equals destination size [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since it is not possible to avoid truncation by strncpy, it is necessary to make sure the result of strncpy is properly NUL-terminated and the NUL must be inserted explicitly, after strncpy has returned. References: #10442 Reported-by: Alexey Smirnov <s.alexey@gmail.com> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* ucode: parse ucode plugin scripts in raw mode, init search pathJo-Philipp Wich2022-08-122-3/+3
| | | | | | | | | | | It makes little sense to execute rpcd ucode plugin scripts in template mode since those scripts are supposed to output structured JSON data, so change the parse config to compile scripts in raw mode. Also initialize the default library search path which is required in recent ucode versions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* iwinfo: fix compilation error with GCC 12Christian 'Ansuel' Marangi2022-05-311-1/+1
| | | | | | | | | | | | | | | | | | | | Fix compilation error with GCC 12. In file included from /home/ansuel/openwrt/staging_dir/target-aarch64_cortex-a53_musl/usr/include/libubus.h:23, from iwinfo.c:21: In function 'blobmsg_close_array', inlined from 'rpc_iwinfo_assoclist' at iwinfo.c:643:3: /home/ansuel/openwrt/staging_dir/target-aarch64_cortex-a53_musl/usr/include/libubox/blobmsg.h:250:9: error: 'c' may be used uninitialized [-Werror=maybe-uninitialized] 250 | blob_nest_end(buf, cookie); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ iwinfo.c: In function 'rpc_iwinfo_assoclist': iwinfo.c:564:15: note: 'c' was declared here 564 | void *c, *d, *e; | ^ cc1: all warnings being treated as errors ninja: build stopped: subcommand failed. Signed-off-by: Christian 'Ansuel' Marangi <ansuelsmth@gmail.com>
* ucode: adjust to latest ucode apiJo-Philipp Wich2022-02-071-12/+13
| | | | | | | | | | | | The public libucode api has been revised to return and expect an uc_program_t pointer instead of a main function reference. The program (former main function) is also not implicitly released by uc_vm_execute() anymore. Adjust the ucode plugin accordingly to match the new requirements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* ucode: add ucode interpreter pluginJo-Philipp Wich2021-12-084-2/+1210
| | | | | | | | | | | | | | 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>
* treewide: adjust ubus object type namesJo-Philipp Wich2021-12-086-6/+6
| | | | | | | 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>
* build: honour CMake install prefix in hardcoded pathsJo-Philipp Wich2021-12-083-5/+5
| | | | | | | | | 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>
* session: use blobmsg_get_u64 for RPC_DUMP_EXPIRESStijn Tintel2021-11-041-1/+1
| | | | | | | | | We need to use blobmsg_get_u64 for RPC_DUMP_EXPIRES as this is now BLOBMSG_TYPE_INT64. Fixes: 20bf958bea20 ("session: use uloop_timeout_remaining64") Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be> Acked-by: Jo-Philipp Wich <jo@mein.io>
* session: use uloop_timeout_remaining64Stijn Tintel2021-11-041-2/+2
| | | | | | | The uloop_timeout_remaining is being deprecated. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be> Acked-by: John Crispin <john@phrozen.org>
* session: unload rpcd configuration before checking loginJo-Philipp Wich2021-07-131-0/+6
| | | | | | | | | | | | | | 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>
* iwinfo: add 802.11ax HE supportDavid Bauer2021-05-051-0/+45
| | | | | | | 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>
* sys: packagelist: drop ABI version from package nameDaniel Golle2021-03-111-0/+12
| | | | | | | | | | | | 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>
* uci: manually clear uci_ptr flags after uci_delete() operationsJo-Philipp Wich2021-01-171-1/+5
| | | | | | | | | | 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>
* iwinfo: include ht_operation data only if availableAnsuel Smith2021-01-061-5/+7
| | | | | | Check if ht_operation data are present and add them accordingly. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* iwinfo: return hwmode 'ad' on 802.11ad-only hardwareDaniel Golle2021-01-051-0/+6
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* iwinfo: add support for 802.11ad and GCMPDaniel Golle2021-01-051-0/+6
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* iwinfo: export center channel for info ubus callAnsuel Smith2021-01-051-0/+2
| | | | | | | 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>
* iwinfo: add ht and vht operation info to wifi scanAnsuel Smith2021-01-051-1/+15
| | | | | | | 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>
* rc: support init.d scripts with START=0Rafał Miłecki2020-09-181-8/+12
| | | | | | Use negative value (instead of 0) to indicate missing START. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* rc: new ubus object for handling /etc/init.d/ scriptsRafał Miłecki2020-09-104-3/+375
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* uci: reset uci_ptr flags when merging options during section addJo-Philipp Wich2020-05-261-0/+1
| | | | | Fixes: FS#3126 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* session: deny access if password login is disabledFabian Bläse2020-03-171-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* iwinfo: add current hw and ht mode to info callDaniel Danzberger2020-01-051-0/+44
| | | | Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
* file: extend exec acl checks to commands with argumentsJo-Philipp Wich2019-12-111-2/+28
| | | | | | | | | | | | | | | | | | | 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>
* plugin: avoid truncating numeric valuesJo-Philipp Wich2019-11-101-2/+72
| | | | | | | 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>
* plugin: fix double free in finish callbackJo-Philipp Wich2019-10-291-1/+0
| | | | | Fixes: 37aa919 ("plugin: fix leaking invoked method name for exec plugins") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* main: exec_self: make clang analyzer happyYousong Zhou2019-10-291-3/+8
| | | | | | | | | 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>
* file: exec: properly free memory on errorYousong Zhou2019-10-291-3/+18
| | | | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> [fix whitespace] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* uci: free configs list memory on returnYousong Zhou2019-10-291-0/+4
| | | | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> [fix whitespace] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* exec: always call finish_cb to allow plugin to free up memoryYousong Zhou2019-10-291-5/+5
| | | | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> [fix whitespace, subject typo] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* plugin: do not free method name separatelyJo-Philipp Wich2019-10-291-4/+1
| | | | | | | | | 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>
* exec: properly free memory on rpc_exec() errorYousong Zhou2019-10-292-4/+12
| | | | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> [fix whitespace] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* plugin: exec: properly free memory on parse errorYousong Zhou2019-10-291-2/+7
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* uci: reset uci_ptr flags when merging set operationsJo-Philipp Wich2019-10-291-0/+1
| | | | | | | | | | | | | | | | 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>
* plugin: fix leaking invoked method name for exec pluginsJo-Philipp Wich2019-10-171-3/+3
| | | | | | | | | | | 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>
* file: increase minimum read buffer size to 4096 bytesJo-Philipp Wich2019-09-211-1/+1
| | | | | | | 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>