summaryrefslogtreecommitdiff
path: root/clients/cli/common.c
Commit message (Collapse)AuthorAgeFilesLines
* libnm,client: use nm_g_task_new() to set source-tag and check itThomas Haller2019-10-161-2/+1
| | | | | | Public API should validate input arguments with g_return_*(). Tag the task with the source function (using nm_g_task_new()) and check it in the corresponding _finish() function.
* all: unify format of our Copyright source code commentsThomas Haller2019-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```bash readarray -d '' FILES < <( git ls-files -z \ ':(exclude)po' \ ':(exclude)shared/c-rbtree' \ ':(exclude)shared/c-list' \ ':(exclude)shared/c-siphash' \ ':(exclude)shared/c-stdaux' \ ':(exclude)shared/n-acd' \ ':(exclude)shared/n-dhcp4' \ ':(exclude)src/systemd/src' \ ':(exclude)shared/systemd/src' \ ':(exclude)m4' \ ':(exclude)COPYING*' ) sed \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \ -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \ -i \ "${FILES[@]}" echo ">>> untouched Copyright lines" git grep Copyright "${FILES[@]}" echo ">>> Copyright lines with unusual extra" git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved sed \ -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \ -i \ "${FILES[@]}" ``` https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
* cli: Assert we don't require multiple commands during client initalizationMarco Trevisan (Treviño)2019-10-021-0/+2
| | | | | | | If a new command was requested while a client was in the process of being created we were just requesting a new client. This was causing leak, so let's strongly ensure this is not the case.
* cli: fix leaking error variable in command_done()Thomas Haller2019-10-021-1/+1
|
* cli: Use GTask to perform async requestsMarco Trevisan (Treviño)2019-10-021-44/+37
|
* all: manually drop code comments with file descriptionThomas Haller2019-10-011-3/+0
|
* cli: don't create a NMClient for the 'connection reload' commandBeniamino Galvani2019-09-171-0/+46
| | | | | | | | It is a waste of resources instantiating a NMClient, filling the object cache and then throwing everything away without using it. This can take seconds on slow systems with many objects. Since the ReloadConnections doesn't need anything from the cache, just execute the D-Bus method call directly.
* all: SPDX header conversionLubomir Rintel2019-09-101-14/+1
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* cli: tab complete only full D-Bus paths if there is no prefixth/cli-select-connectionThomas Haller2019-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | When tab completing connections by path name without any already typed parts, only suggest full D-Bus paths. The numbers are duplicate and not preferred. Before: $ nmcli connection show path <TAB> Display all 118 possibilities? (y or n) 1 46 /org/freedesktop/NetworkManager/Settings/29 10 47 /org/freedesktop/NetworkManager/Settings/3 11 48 /org/freedesktop/NetworkManager/Settings/30 12 49 /org/freedesktop/NetworkManager/Settings/31 13 5 /org/freedesktop/NetworkManager/Settings/32 Afterwards: $ nmcli connection show path <TAB> /org/freedesktop/NetworkManager/Settings/1 /org/freedesktop/NetworkManager/Settings/28 /org/freedesktop/NetworkManager/Settings/46 ... and $ nmcli connection modify path 4<TAB> 4 40 41 42 43 44 45 46 47 48 49
* cli: prefer matching connections by "uuid" instead of "id"Thomas Haller2019-04-151-27/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Scripts should refer to connections by UUID. That means, whenever a UUID matches, that is really what the user wants. The specifier "uuid" must have precedence over "id" (and all others). That means, we must search all connections. For example: $ UUIDS=($(nmcli -g TYPE,UUID connection show | sed -n 's/802-11-wireless://p')) $ nmcli -f connection.id,connection.uuid connection show "${UUIDS[@]}" in this case we must preferrably match by UUID, regardless of whether a "connection.id" exists. Note that if you have: $ nmcli connection show | grep fdf7b2d2-2858-3938-9b14-7f1b514a9a00 b fdf7b2d2-2858-3938-9b14-7f1b514a9a00 ethernet -- fdf7b2d2-2858-3938-9b14-7f1b514a9a00 ab9f3891-3420-335e-89da-f14c1b94c540 ethernet -- then certain commands will still select all matching connections: $ nmcli -f connection.id,connection.uuid --mode multiline connection show fdf7b2d2-2858-3938-9b14-7f1b514a9a00 connection.id: fdf7b2d2-2858-3938-9b14-7f1b514a9a00 connection.uuid: ab9f3891-3420-335e-89da-f14c1b94c540 connection.id: b connection.uuid: fdf7b2d2-2858-3938-9b14-7f1b514a9a00 This only makes a difference for commands that must pick only one profile: $ nmcli connection modify fdf7b2d2-2858-3938-9b14-7f1b514a9a00 con-name new-name
* cli: drop unnecessary NULL sentinel from nmc_complete_strings()Thomas Haller2019-04-151-12/+12
| | | | | | Since commit 62b939de4e22 ('cli: add nmc_complete_strv() which takes a string array for completion that may contain NULL'), the sentinel is no longer needed.
* cli: add nmc_complete_strv() which takes a string array for completion that ↵Thomas Haller2019-03-071-9/+25
| | | | | | | | | may contain NULL This will allow for a convenient calling pattern when some elements should be printed optionally. (cherry picked from commit 62b939de4e2288d0a9d305706db4cf47c34122d5)
* clients/secret-agent: allow suppressing prompting the entry-id when ↵Thomas Haller2019-02-141-5/+12
| | | | | | | | requesting secrets When asking for the preshared-key for WireGuard peers, the secret request will be very verbose with redundant information. Allow suppressing the entry id from the prompt.
* all: drop unnecessary includes of <errno.h> and <string.h>Thomas Haller2019-02-121-1/+0
| | | | | "nm-macros-interal.h" already includes <errno.h> and <string.h>. No need to include it everywhere else too.
* clients: don't tread secret agent as NMSecretAgentOldThomas Haller2019-02-051-1/+1
| | | | | | | | Most of the times we actually need a NMSecretAgentSimple typed pointer. This way, need need to cast less. But even if we would need to cast more, it's better to have pointers point to the actual type, not merely to avoid shortcomings of C.
* cli: drop gettext() wrappers for no_l10n to-string functionsThomas Haller2018-12-111-7/+1
| | | | | | | | | | In most cases, we don't want the translated string (only marked for translation, and then programatically the caller deciedes whether to translate or not). The few places that always call gettext() can do it explicitly. Now, that our functions are all "no_l10n" by default, rename them.
* cli: initialize readline before installing the redisplay handlerlr/readline-initLubomir Rintel2018-10-231-0/+4
| | | | | | | | | | | | | | | | | | | Otherwise readline decides to initialize terminal handling at the first readline call, and if that happens at the point it sees our non-echoing rl_redisplay. At that point, unless already intialized, readline wrongly convinces itself we do our own handling of terminal peculiarities (such as cursor movement, or erases). We do not -- we merely wrap the stock rl_redisplay(), temporarily hiding the actual characters. The rl_initialize() in nmc_readline_echo()s fixes broken line editing in password prompts that weren't preceded a previous non-password prompt. The other one is there for consistency only. (I guess we should be initializing readline before use anyway; although it seems to initialize itself anyway if we fail to do so...) https://github.com/NetworkManager/NetworkManager/pull/241
* cli: don't use global nm_cli in nmc_readline_*()Thomas Haller2018-10-101-21/+28
| | | | | | | | | | | | | | | Globals are bad. Don't let nmc_readline_helper() access nm_cli. Instead, pass nmc_config along. nmc_config albeit being a complex struct, is much more begning: - the configuration nmc_config is initialized early on and afterwards immutable. - it only contains simple fields, which affect the behavior. - it's not a global. While passing around the complex configuration struct, it is clear that all callpaths don't access additional global information.
* cli: print per-device & per-AF connectivity statusLubomir Rintel2018-09-241-0/+17
|
* cli: fix reading "vpn.secrets.*" from passwd-fileThomas Haller2018-09-141-3/+3
| | | | | | | | | | | | | | | | Due to a bug, we required VPN secrets to be prefixed with "vpn.secret." instead of "vpn.secrets.". This was a change in behavior with 1.12.0 release. Fix it, to restore the old behavior. For backward compatibility to the broken behavior, adjust parse_passwords() to treat accept that as well. https://bugzilla.redhat.com/show_bug.cgi?id=1628833 https://github.com/NetworkManager/NetworkManager/pull/201 Fixes: 0601b5d725b072bd3ce4ec60be867898a16f85cd (cherry picked from commit 5815ae8c60961f088e4e54b41ddf8254cb83574a)
* cli: add additional user-data argument to get_fcn()Thomas Haller2018-07-091-0/+2
| | | | | | | | | | | | | | | | | | | The function nmc_print() receives a list of "targets". These are essentially the rows that should be printed (while the "fields" list represents the columns). When filling the cells with values, it calles repeatedly get_fcn() on the column descriptors (fields), by passing each row (target). The caller must be well aware that the fields and targets are compatible. For example, in some cases the targets are NMDevice instances and the target type must correspond to what get_fcn() expects. Add another user-data pointer that is passed on along with the targets. That is useful, if we have a list of targets/rows, but pass in additional data that applies to all rows alike. It is still unused.
* cli: merge IPv4 and IPv6 versions of ip/dhcp config printThomas Haller2018-07-091-37/+22
|
* cli/trivial: move codeThomas Haller2018-07-091-11/+15
|
* cli: drop duplicate IPv6 property metadataThomas Haller2018-07-091-10/+0
|
* cli: rework printing of dhcp optionsThomas Haller2018-07-091-38/+72
|
* cli: return NULL strv array from _ip_config_get_routes() if there are no routesThomas Haller2018-06-151-0/+3
| | | | | | | | | | | | | | The property getter for certain properties tries to return a strv array. In this case, the result should be identical, whether an empty strv array or NULL is returned. Let _ip_config_get_routes() return %NULL if there are no routes. This should have no practical difference, but it actually exposes a bug in "cli/common/utils.c", which was previously hidden by not commonly returning %NULL. This bug will be fixed in the next commit.
* cli: allow specifying the connection by its filenameLubomir Rintel2018-06-111-1/+17
| | | | | This is handy for users who configure NetworkManager by dropping files into /etc.
* cli: use macro for list of argument for NmcMetaGenericInfo.get_fcn()th/cli-connection-handlingThomas Haller2018-05-141-18/+2
| | | | | | | | | | | | | | | The reasons are: - I want to locate all implmenetations of the get_fcn() handler. By consistently using this macro, you can just grep for the macro and find them all. - all implementations should follow the same style. This macro enforces the same names for arguments and avoids copy&paste. - if we are going to add or change an argument, it becomes easier. That's because we can easily identify all implementation and can change arguments in one place.
* cli: add and use macro for creating NmcMetaGenericInfo parent groupsThomas Haller2018-05-141-12/+2
|
* cli: rework connection handling for multiple resultsThomas Haller2018-05-141-28/+41
| | | | | | | | | | | | | | Functions like nmc_find_connection() and nmc_find_active_connection() can easily find multiple matching results. For example, the "connection.id" in NetworkManager is not enforced to be unique, so if the user adds multiple connections with the same name, they should be all selected. The previous API had a @pos argument, that allowed to iterate over the results. Change that, to return all matches in a GPtrArray. Also, extend connection-show and other places, to anticipate that a connection might be active multiple times in any moment.
* cli: move find_active_connection() to common.cThomas Haller2018-05-141-0/+77
| | | | | | Beside nmc_find_connection(), which is very similar. Also, drop unused argument @cons.
* cli: cleanup code paths in "connections.c"Thomas Haller2018-05-141-18/+20
|
* cli: use a palette to implement coloringLubomir Rintel2018-05-101-3/+3
| | | | | | | | | | | This basically replaces the (NMMetaTermColor, NMMetaTermFormat) combo with NMMetaColor that describes the colored element semantically as opposed to storing the raw attributes. A (currently static) paletted is used to translate the semantic color code to the actual ANSI controle sequence. This matches what terminal-colors.d(5) schemes use, making it convenient to implement customizable palettes.
* cli: sort DHCP options in connection show outputThomas Haller2018-04-231-7/+8
| | | | Otherwise, the output is unstable and changes every time.
* cli: merge IPv4 and IPv6 variants of print_dhcp_config()Thomas Haller2018-04-231-60/+8
|
* clients: set @out_is_default in property gettersBeniamino Galvani2018-04-131-2/+14
|
* clients: change nm_meta_abstract_info_get() to report defaultsBeniamino Galvani2018-04-131-0/+2
| | | | | Return a boolean to indicate whether the value is the default one, so that the caller can choose to hide it.
* cli: fix completion of help sub-commandBeniamino Galvani2018-02-131-3/+2
| | | | | | | | | | | | | | 'help' is completed without considering other alternatives: # nmcli connection modify h<TAB> help After the patch: # nmcli connection modify h<TAB> help home-wifi Fixes: 29bb6ae4fec37db177418bae9d9462b577d3b2fd
* clients/cli: use a nicer password promptLubomir Rintel2017-12-181-12/+30
| | | | | | | | | | Makes sense in order for the user to know that they're actually typing the password (edited just to illustrate the point, the actual output was shamefully messy and perhaps needs fixing too): $ nmcli c up Wrathmosphere Passwords or encryption keys are required to access the wireless network 'Wrathmosphere'. Password (802-1x.password): *********
* clients/cli: don't store a password in historyLubomir Rintel2017-12-181-0/+5
| | | | | | | | History is probably even not useful at all outside the interactive edit mode, but that is another story. This just avoids awkward surprises, such as: https://bugzilla.gnome.org/show_bug.cgi?id=791200
* clients: some cleanup of requesting VPN secretsThomas Haller2017-11-231-30/+28
|
* all: include "nm-utils/nm-hash-utils.h" by defaultThomas Haller2017-11-161-1/+0
| | | | | | | | | Next we will use siphash24() instead of the glib version g_direct_hash() or g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very fundamental and will be needed basically everywhere. Instead of requiring the users to include them, let it be included via "nm-default.h" header.
* libnm: avoid unnecessary copies accessing NMIPRoute's attributesThomas Haller2017-10-301-9/+16
| | | | | | | | | | We want to support large number of routes. Reduce the number of copies, by adding internal accessor functions. Also, work around a complaint from coverity: 46. NetworkManager-1.9.2/libnm-core/nm-utils.c:1987: dereference: Dereferencing a null pointer "names".
* core,clients: use our own string hashing function nm_str_hash()Thomas Haller2017-10-181-1/+2
| | | | | | | | | | | | | | | | | | | | Replace the usage of g_str_hash() with our own nm_str_hash(). GLib's g_str_hash() uses djb2 hashing function, just like we do at the moment. The only difference is, that we use a diffrent seed value. Note, that we initialize the hash seed with random data (by calling getrandom() or reading /dev/urandom). That is a change compared to before. This change of the hashing function and accessing the random pool might be undesired for libnm/libnm-core. Hence, the change is not done there as it possibly changes behavior for public API. Maybe we should do that later though. At this point, there isn't much of a change. This patch becomes interesting, if we decide to use a different hashing algorithm.
* build: move nm-client-utils.c to libnmc-base.aBeniamino Galvani2017-10-161-249/+0
| | | | | | | | | In a later commit we'll add a new generic client function used by nmcli and nmtui. nm-client-utils.c seems the right place for it, so move the file to the base library that is used by both clients. While at it, also put in that file some functions that will be needed by nmtui.
* cli: show additional route attributes in IP4_CONFIG outputThomas Haller2017-09-261-42/+57
|
* cli: refactor printing IP6 device infoThomas Haller2017-09-261-67/+117
|
* cli: fix failed assertion in readline helperBeniamino Galvani2017-06-151-2/+4
| | | | | | | | | | | | | | | | | | | | The INT signal can arrive after a new line has been processed in nmc_readline_helper(). In such case, the handler gets uninstalled by readline_cb() and nmc_seen_sigint() returns TRUE. However it's an error to call rl_callback_read_char() without handler, don't do it. Fixes the following: "readline: readline_callback_read_char() called with no handler!" #0 __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 __GI_abort () at abort.c:90 #2 rl_callback_read_char () at ../callback.c:116 #3 nmc_readline_helper (prompt=prompt@entry=0x2aa0d229080 "nmcli> ") at clients/cli/common.c:1387 #4 nmc_readline (prompt_fmt=prompt_fmt@entry=0x2aa0036ac9e "%s") at clients/cli/common.c:1448 #5 do_connection_edit (connection=0x2aa0d215440, nmc=0x2aa00391298 <nm_cli>) at clients/cli/connections.c:7072 Fixes: 995229181cac66c1ac5a2d63120ffbbe3ac136b0 https://bugzilla.redhat.com/show_bug.cgi?id=1458311
* cli: fix completion of connection typesBeniamino Galvani2017-04-201-2/+7
| | | | Return only main settings and the special slave types.
* cli: move completion for connection type to meta dataThomas Haller2017-04-121-0/+32
|