Commit Graph

104 Commits

Author SHA1 Message Date
Thomas Haller
ba350a3495 cli: add additional user-data argument to get_fcn()
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.
2018-07-09 15:43:55 +02:00
Thomas Haller
940979a5a6 cli: merge IPv4 and IPv6 versions of ip/dhcp config print 2018-07-09 15:43:55 +02:00
Thomas Haller
bddf482fa1 cli/trivial: move code 2018-07-09 15:43:55 +02:00
Thomas Haller
ff273b8221 cli: drop duplicate IPv6 property metadata 2018-07-09 15:43:55 +02:00
Thomas Haller
096ac93f8a cli: rework printing of dhcp options 2018-07-09 15:43:55 +02:00
Thomas Haller
dba41ee1e1 cli: return NULL strv array from _ip_config_get_routes() if there are no routes
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.
2018-06-15 11:48:16 +02:00
Lubomir Rintel
d52573d125 cli: allow specifying the connection by its filename
This is handy for users who configure NetworkManager by dropping files
into /etc.
2018-06-11 15:09:42 +02:00
Thomas Haller
fc475f25f2 cli: use macro for list of argument for NmcMetaGenericInfo.get_fcn()
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.
2018-05-14 17:53:03 +02:00
Thomas Haller
69d5fc9bce cli: add and use macro for creating NmcMetaGenericInfo parent groups 2018-05-14 17:53:03 +02:00
Thomas Haller
4b3297271e cli: rework connection handling for multiple results
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.
2018-05-14 17:53:03 +02:00
Thomas Haller
5e34a4b424 cli: move find_active_connection() to common.c
Beside nmc_find_connection(), which is very similar.

Also, drop unused argument @cons.
2018-05-14 17:53:03 +02:00
Thomas Haller
f0a2686545 cli: cleanup code paths in "connections.c" 2018-05-14 17:53:03 +02:00
Lubomir Rintel
31aa2cfe29 cli: use a palette to implement coloring
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.
2018-05-10 14:36:58 +02:00
Thomas Haller
f2109cb810 cli: sort DHCP options in connection show output
Otherwise, the output is unstable and changes every time.
2018-04-23 15:44:44 +02:00
Thomas Haller
5e69b8b9f1 cli: merge IPv4 and IPv6 variants of print_dhcp_config() 2018-04-23 15:43:39 +02:00
Beniamino Galvani
50414353e1 clients: set @out_is_default in property getters 2018-04-13 17:02:55 +02:00
Beniamino Galvani
1f2319dcb9 clients: change nm_meta_abstract_info_get() to report defaults
Return a boolean to indicate whether the value is the default one, so
that the caller can choose to hide it.
2018-04-13 17:02:55 +02:00
Beniamino Galvani
6cba687bb3 cli: fix completion of help sub-command
'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: 29bb6ae4fe
2018-02-13 16:09:16 +01:00
Lubomir Rintel
9d95e1f175 clients/cli: use a nicer password prompt
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): *********
2017-12-18 14:47:37 +01:00
Lubomir Rintel
7c3e1d926a clients/cli: don't store a password in history
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
2017-12-18 14:47:31 +01:00
Thomas Haller
0601b5d725 clients: some cleanup of requesting VPN secrets 2017-11-23 14:44:25 +01:00
Thomas Haller
3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
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.
2017-11-16 11:49:51 +01:00
Thomas Haller
f3146de41b libnm: avoid unnecessary copies accessing NMIPRoute's attributes
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".
2017-10-30 14:12:41 +01:00
Thomas Haller
3434261811 core,clients: use our own string hashing function nm_str_hash()
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.
2017-10-18 13:05:00 +02:00
Beniamino Galvani
aa964ae969 build: move nm-client-utils.c to libnmc-base.a
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.
2017-10-16 17:25:35 +02:00
Thomas Haller
a22b017830 cli: show additional route attributes in IP4_CONFIG output 2017-09-26 19:36:51 +02:00
Thomas Haller
ccb83e34a3 cli: refactor printing IP6 device info 2017-09-26 19:36:51 +02:00
Beniamino Galvani
cd3a561251 cli: fix failed assertion in readline helper
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: 995229181c

https://bugzilla.redhat.com/show_bug.cgi?id=1458311
2017-06-15 10:03:58 +02:00
Beniamino Galvani
ed824102ff cli: fix completion of connection types
Return only main settings and the special slave types.
2017-04-20 14:34:20 +02:00
Thomas Haller
b629b98687 cli: move completion for connection type to meta data 2017-04-12 14:12:20 +02:00
Thomas Haller
41b31051f2 cli: use nmc_print() to output device's IP4 info
The IP4 info adds a new type: to expose strv arguments
for addresses, etc.
2017-04-12 14:00:00 +02:00
Thomas Haller
c5c48d4f5f cli: move global "loop" variable to nmcli.h header 2017-04-12 11:24:04 +02:00
Thomas Haller
f0d91455ca cli: move show_secret field to NmcConfig
The show-secret property is basically a part of the current
configuration, relevant during printing. It will be passed
on to nmc_print(), and hence must be part of NmcConfig.
2017-04-12 11:24:04 +02:00
Thomas Haller
9276655975 cli: move NmcMetaGenericInfo to "utils.h" 2017-04-05 16:53:06 +02:00
Thomas Haller
bfb9fd0d2f cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.

However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.

Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.

Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-04-05 16:53:06 +02:00
Thomas Haller
aae721d0df cli: pass arguments for print_data separately of NmcOutputData
Don't pass on large structs of input arguments. It only convolutes
which arguments are passed, and where they come from.
2017-04-05 16:53:06 +02:00
Thomas Haller
f973f0841a cli: merge NmcPrintFields into NmcOutputData and pass it directly to print_required_fields() 2017-04-05 16:53:06 +02:00
Francesco Giudici
6a3d77fbe6 nmcli: allow cmd specific option parsing in next_arg() func
Options dependant on specific commands (e.g., nmcli connection show
--active) are now allowed to be processed by the next_arg() function.
This would allow autocompletion to expand options belonging to specific
command first, and then global ones.

Note that global options ("--ask" and "--show-secrets") will be auto-completed
everywhere but only if at least a '-' is passed. Command specific ones
(--temporary, --active, --order) will be auto-completed only after the command
they belongs to but without requiring the user to pass a heading '-'.

Example:
'nmcli connection show -a'
will expand '-a' into '--active', but
'nmcli connection add -a`
will expand '-a' into '--ask' (as it is a global option)

This commit fixes also autocompletion for:
nmcli connection modify --temporary
2017-04-05 15:43:40 +02:00
Thomas Haller
29bcfc2522 cli: don't track output data in global NmCli structure
We should not violate the global data to track the output data
while it is constructed and printed.

Most of the time, we actually clear the output data anyway --
either before constructing it, or after printing it.
In some cases we didn't, but I think that is a bug. It's really
hard to keep track of this.

The output data should belong to a certain scope and get destroyed
afterwards. Passing it around is very confusing. Don't do that.
2017-03-30 14:56:21 +02:00
Thomas Haller
85acdd70e7 cli: split print_data() in a part with and without side-effects
To better understand which part of the code have side effects,
split print_data() in a part that mutilates the input array
and a part that only prints.
2017-03-30 13:46:09 +02:00
Thomas Haller
2ea670ab96 cli: split output data from NmCli to a separate field 2017-03-30 13:34:35 +02:00
Thomas Haller
98ce4a8d5d cli: separate input and in-out arguments in print_data()
Don't pass down the entire NmCli instance. The output_data
array is modified by print_data(), the rest is read-only input.
2017-03-30 13:09:59 +02:00
Thomas Haller
e847d0f121 cli: pass configuration options separately from NmCli structure
The NmCli structure is passed around everywhere and contains all
the state of the program. It is very hard to follow which parts
are used where.

Split out more configuration options to a NmcConfig field. This field
is mostly immutable, and modified at particular places that now can be
easily found.
2017-03-30 13:09:59 +02:00
Thomas Haller
a63c4d0824 cli: use designated initializers for setting NmcOutputField fields
Otherwise, changing the structure is difficult because it all depends
on the order (and you don't immdiately see which field is used where).

Also, drop the name_l10n field.
2017-03-30 13:09:58 +02:00
Thomas Haller
23298bfc88 cli: move utils function from common.h to nm-meta-setting-desc.c
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
2017-03-30 13:09:58 +02:00
Thomas Haller
cb66cf96d7 cli: add values_func() to NmcPropertyInfo and use for "connection" setting 2017-03-30 13:09:55 +02:00
Lubomir Rintel
16902a2be6 cli: use next_arg() on argument boundary
Shift argc and argc manually between argument ant its value and use
next_arg() between arguments everywhere. Whill be useful to parse global
arguments.
2017-03-28 15:32:05 +02:00
Thomas Haller
22b7282d84 all: use "unsigned" instead of "unsigned int" 2017-03-14 11:26:29 +01:00
Beniamino Galvani
d094914120 cli: support route options 2017-03-06 15:20:25 +01:00
Lubomir Rintel
84c484ed5b cli: make match() return boolean
Coccinelle semantic patch:

  @@
  @@
  -int
  +gboolean
          matches (...);

  @@
  expression pattern, cmd, len;
  @@
  -int
  +gboolean
          matches (...)
          {
                  ...
  -               return memcmp (pattern, cmd, len);
  +               return memcmp (pattern, cmd, len) == 0;
          }

  @@
  expression prefix, str;
  @@
  (
  -matches (prefix, str) != 0
  +!matches (prefix, str)
  |
  -matches (prefix, str) == 0
  +matches (prefix, str)
  )

  @@
  expression prefix, str;
  @@
  -(matches (prefix, str))
  +matches (prefix, str)

  @@
  expression prefix, str;
  @@
  -(!matches (prefix, str))
  +!matches (prefix, str)

spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
  --include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 13:04:07 +01:00