Commit graph

87 commits

Author SHA1 Message Date
Thomas Haller bc1014a93d all: replace _nm_utils_string_in_list() with g_strv_contains() 2016-06-17 12:25:33 +02:00
Thomas Haller cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller 8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller 2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Dan Winship 22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00
Thomas Haller 11371b5470 libnm: only call strlen() once in NMSetting8021x:path_to_scheme_value()
Also assert that path is not empty.
2015-03-12 18:12:25 +01:00
Thomas Haller cda7b158e2 libnm: ensure valid blob for nm_setting_802_1x_set_*_cert()
A valid blob cannot start with "file://", otherwise it would
break the implementation of the certificate properties in
NMSetting8021x. Simply reject every blob in nm_setting_802_1x_set_ca_cert()
et al. that is not valid according to get_cert_scheme().
2015-03-12 18:12:25 +01:00
Thomas Haller e59e68c528 libnm: combine get_cert_scheme() and verify_cert() and ensure valid paths for NMSetting8021x
get_cert_scheme() would return PATH scheme for binary data that
later will be rejected by verify_cert(). Even worse, get_cert_scheme()
would not check whether the path is NUL terminated, hence the following
can crash for an invalid connection:

  if (nm_setting_802_1x_get_ca_cert_scheme (s_8021x) == NM_SETTING_802_1X_CK_SCHEME_PATH)
      g_print ("path: %s", nm_setting_802_1x_get_ca_cert_path (s_8021x))

Combine the two functions so that already get_cert_scheme() does
the same validation as verify_cert().

Also change behavior and be more strict about invalid paths:

 - Now, the value is considered a PATH candidate if it starts with "file://",
   (sans NUL character).
   A change is that before, the "file://" (without NUL) would have
   been treated as BLOB, now it is an invalid PATH (UNKNOWN).

 - If the binary starts with "file://" it is considered as PATH but it
   is only valid, if all the fllowing is true:
   (a) the last character must be NUL.
   (b) there is no other intermediate NUL character.
       Before, an intermediate NUL character would have been accepted
       and the remainder would be ignored.
   (c) there is at least one non-NUL character after "file://".
   (d) the string must be fully valid utf8.

   The conditions (b) and (c) are new and some invalid(?) paths
   might no longer validate.
   Checking (d) moved from verify_cert() to get_cert_scheme().
   As set_cert_prop_helper() already called verify_cert(), this
   causes no additional change beyond (b).
2015-03-12 18:12:25 +01:00
Dan Winship 2d29c0527e docs: misc small fixes
Cleans up all of the warnings that aren't overly annoying to clean up.
2014-12-18 13:47:03 -05:00
Dan Winship c14486984e libnm, libnm-util: move settings doc generation to libnm-core
Move the settings/plugins doc generation from libnm-util to
libnm-core, since libnm-util isn't being updated for all new
properties.

With this commit, the keyfile and ifcfg-rh documentation is basically
unchanged, except that deprecated properties are now gone, and new
properties have been added, and the sections are in a different order.
(generate-plugin-docs.pl just outputs the settings in Makefile order,
and they were unsorted in libnm-util, but are sorted in libnm-core).

The settings documentation used for nm-settings.5, the D-Bus API docs,
and the nmcli help is changed a bit more at this point, and mostly for
the worse, since the libnm-core setting properties don't match up with
the D-Bus API as well as the libnm-util ones do. To be fixed...

(I also removed the "plugins docs" line in each plugin docs comment
block while moving them, since those blocks will be used for more than
just plugins soon, and it's sort of obvious anyway.)
2014-11-19 09:24:09 -05:00
Dan Winship 53f5e9afa4 libnm*: fix library gettext usage
Libraries need to include <gi18n-lib.h>, not <gi18n.h>, so that _()
will get defined to "dgettext (GETTEXT_DOMAIN, string)" rather than
"gettext (string)" (which will use the program's default domain, which
works fine for programs in the NetworkManager tree, but not for
external users). Likewise, we need to call bindtextdomain() so that
gettext can find the translations if the library is installed in a
different prefix from the program using it (and
bind_textdomain_codeset(), so it will know the translations are in
UTF-8 even if the locale isn't).

(The fact that no one noticed this was broken before is because the
libraries didn't really start returning useful translated strings much
until 0.9.10, and none of the out-of-tree clients have been updated to
actually show those strings to users yet.)
2014-11-13 17:18:42 -05:00
Dan Winship 3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Jiří Klimeš 291674d82e libnm-util: add ifcfg-rh specific description for properties
as comments in libnm-util/nm-setting-*.c files
The comments are parsed by generate-plugin-docs.pl script.
2014-08-29 13:59:54 +02:00
Thomas Haller 22ca469011 libnm-util: fix warning converting between enum types in nm-setting-8021x.c
clang warns:

    make[4]: Entering directory `./NetworkManager/libnm-util'
      CC       nm-setting-8021x.lo
    nm-setting-8021x.c:1824:17: error: implicit conversion from enumeration type 'NMCryptoFileFormat' to different enumeration type 'NMSetting8021xCKFormat' [-Werror,-Wenum-conversion]
                    *out_format = format;
                                ~ ^~~~~~
    nm-setting-8021x.c:2135:17: error: implicit conversion from enumeration type 'NMCryptoFileFormat' to different enumeration type 'NMSetting8021xCKFormat' [-Werror,-Wenum-conversion]
                    *out_format = format;
                                ~ ^~~~~~

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:16:59 +02:00
Dan Winship 2570c5a17c libnm-util, libnm-glib: whitespace fixes
Fix indentation, kill trailing whitespace, split some long lines.
2014-07-15 09:44:55 -04:00
Dan Winship cb7e1893e7 libnm-util, libnm-glib: standardize copyright/license headers
- Remove list of authors from files that had them; these serve no
  purpose except to quickly get out of date (and were only used in
  libnm-util and not libnm-glib anyway).

- Just say "Copyright", not "(C) Copyright" or "Copyright (C)"

- Put copyright statement after the license, not before

- Remove "NetworkManager - Network link manager" from the few files
  that contained it, and "libnm_glib -- Access network status &
  information from glib applications" from the many files that
  contained it.

- Remove vim modeline from nm-device-olpc-mesh.[ch], add emacs modeline
  to files that were missing it.
2014-07-15 09:44:54 -04:00
Dan Winship cdc15cb2a6 libnm-util: remove NMSetting* GParamSpec docs
Remove all the GParamSpec docs, since everything now uses the gtk-doc
docs instead, so there's no point in having two copies of each (which
are often out of sync anyway).

Since we're touching so many lines anyway, also fix up the indentation
of the remaining property-installing lines, and add
G_PARAM_STATIC_STRINGS to each paramspec (so the nick strings don't
get strduped). Also, be consistent about starting a new line between
"g_object_class_install_property" and its opening parenthesis.
2014-06-19 17:45:03 -04:00
Dan Winship e8577083ca libnm-util: various NMSetting* property doc fixes/improvements
Fix up various issues with the docs for the NMSetting properties, and
pull in text from the GParamSpec docs where the GParamSpec docs were
better (or contained information that is necessary in the context of
nm-settings.5).

Also, consistently wrap all of the doc comments to the same width (80
columns).
2014-06-19 17:45:02 -04:00
Dan Winship 9de24b16e8 libnm-util: fix gtk-doc bugs in NMSetting* properties
Fix misused gtk-doc annotations and incorrectly-identified properties.

In particular, the upcoming introspection-based generate-settings-spec
expands macro and enum values, so if you use '%' where you should have
used '#', it will fail to find an expansion, and error out.
2014-06-19 17:45:02 -04:00
Dan Winship 8487a4490c libnm-util, libnm-glib: be consistent about "Wi-Fi", "Ethernet", "InfiniBand" in docs
We made the UIs consistent last year, but missed the documentation.
Fix the docs to also consistently use "Wi-Fi" rather than "WiFi",
"Wifi", "wifi", or "WiFI"; "Ethernet" rather than "ethernet"; and
"InfiniBand" rather than "Infiniband".
2014-06-19 17:45:01 -04:00
Jiří Klimeš 31cd3fe444 libnm-util: return better error messages on failures for _set_ functions 2014-05-12 10:46:41 +02:00
Jiří Klimeš 7c817d4176 libnm-util: add *_remove_*_by_value() functions for '802-1x' setting
nm_setting_802_1x_remove_eap_method_by_value()
nm_setting_802_1x_remove_altsubject_match_by_value()
nm_setting_802_1x_remove_phase2_altsubject_match_by_value()
2014-02-28 10:38:53 +01:00
Jiří Klimeš 3789412160 libnm-util: fix adding values to 'phase2-altsubject-matches'
It was mixed up with 'altsubject-matches'.
2014-02-25 18:42:24 +01:00
Jiří Klimeš 68066b40f2 libnm-util: fix verify_identity() in '802-1x' setting
We need to return FALSE on error, otherwise we pile GErrors and assert in
nm_setting_verify().
2014-02-25 15:57:54 +01:00
Jiří Klimeš c2a1cb1a44 docs: use %TRUE, %FALSE macros instead of plain TRUE, FALSE values for gtkdoc 2014-02-24 17:00:39 +01:00
Thomas Haller 9d319e6da0 libnm-util: refactor NMSetting name and register_settings
- refactor register_settings to allow lookup by GType and
  add the settings name to SettingInfo.

- setting NM_SETTING_NAME is deprecated and should not be set anymore.
  Indeed it has always be a bug, to reset the name to a different value.
  The only valid place to set the name was in the _init() function of
  the derived class itself.
  This is now no longer needed/possible. Instead the name get's
  detected based on the registered setting types. This makes use of
  the registered metadata that is available anyway since every
  usable setting has to register itself.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-12 21:47:13 +01:00
Dan Williams 983079cd59 libnm-util: remove usage of NM_SETTING_PARAM_SERIALIZE
The only property that is not serializes is each settings' 'name'
property, so the flag serves no purpose.
2013-12-02 15:26:12 -06:00
jvoisin 00ffb78c8d core: add support for EAP-PWD authentication 2013-10-23 21:07:30 -05:00
Jiří Klimeš 816ac9ee70 libnm-util: prefix errors with 'setting.property' instead of 'property' only 2013-06-13 10:05:18 +02:00
Dan Winship 43617d4c1d libnm-util: deprecate nm_utils_slist_free(), use g_slist_free_full() 2013-05-29 17:13:30 -03:00
Dan Williams 87517ba6df libnm-util: sync some 802.1x function arguments with documentation 2013-05-28 12:26:55 -05:00
Dan Williams f6064e7b74 libnm-util: implement connection changed signal
Emitted whenever settings are added or removed from the connection,
and whenever any property of any setting in the connection is changed.
2013-05-28 12:26:55 -05:00
Dan Williams 229cba8354 libnm-util: clarify 802.1x password and password-raw documentation 2013-05-03 10:31:50 -05:00
Martin Pitt 57a9fb3c89 Use %NULL macro in doc strings
Mass-converted "NULL" to "%NULL" in docstrings with

  find -name '*.c'| xargs sed -i '/^ \*.*[^%]NULL/ s/NULL\b/%NULL/g'
2013-04-19 10:08:17 -04:00
Jiří Klimeš dc58072f7b libnm-util: install :pin and :pin-flags as properties for NMSetting8021x
GLib-GObject-WARNING **: g_object_get_property: object class `NMSetting8021x' has no property named `pin'
GLib-GObject-WARNING **: g_object_get_property: object class `NMSetting8021x' has no property named `pin-flags'
2013-03-26 16:49:37 +01:00
Jiří Klimeš df142a5dc4 libnm-util: make property verification errors more descriptive
- fix g_set_error()/g_set_error_literal() usage
- make the error messages translatable
- use g_prefix_error() to prepend property name
2013-03-13 17:47:11 +01:00
Dan Williams 2878481c09 libnm-util: free temporary GByteArray when using NM_SETTING_802_1X_CK_SCHEME_PATH
If the certificate's format was valid, but we're asked to refer to it by
paths instead of using the raw data, 'data' would be leaked.

==23089== 8,232 (40 direct, 8,192 indirect) bytes in 1 blocks are definitely lost in loss record 5,109 of 5,123
==23089==    at 0x4A0881C: malloc (vg_replace_malloc.c:270)
==23089==    by 0x39B905488E: g_malloc (gmem.c:159)
==23089==    by 0x39B9068CA1: g_slice_alloc (gslice.c:1003)
==23089==    by 0x39B9024539: g_array_sized_new (garray.c:195)
==23089==    by 0x31FC0146EA: file_to_g_byte_array (crypto.c:319)
==23089==    by 0x31FC01543B: crypto_load_and_verify_certificate (crypto.c:606)
==23089==    by 0x31FC01ED26: nm_setting_802_1x_set_client_cert (nm-setting-8021x.c:819)
==23089==    by 0xC6944A4: eap_tls_reader (reader.c:2316)
==23089==    by 0xC692756: fill_8021x (reader.c:2714)
==23089==    by 0xC696151: wireless_connection_from_ifcfg (reader.c:2832)
==23089==    by 0xC698E3A: connection_from_file (reader.c:4316)
==23089==    by 0xC69135C: nm_ifcfg_connection_new (nm-ifcfg-connection.c:119)
==23089==
==23089== 8,352 (160 direct, 8,192 indirect) bytes in 4 blocks are definitely lost in loss record 5,110 of 5,123
==23089==    at 0x4A0881C: malloc (vg_replace_malloc.c:270)
==23089==    by 0x39B905488E: g_malloc (gmem.c:159)
==23089==    by 0x39B9068CA1: g_slice_alloc (gslice.c:1003)
==23089==    by 0x39B9024539: g_array_sized_new (garray.c:195)
==23089==    by 0x31FC0146EA: file_to_g_byte_array (crypto.c:319)
==23089==    by 0x31FC01543B: crypto_load_and_verify_certificate (crypto.c:606)
==23089==    by 0x31FC01E5E6: nm_setting_802_1x_set_ca_cert (nm-setting-8021x.c:538)
==23089==    by 0xC694DD8: eap_peap_reader (reader.c:2358)
==23089==    by 0xC692756: fill_8021x (reader.c:2714)
==23089==    by 0xC696151: wireless_connection_from_ifcfg (reader.c:2832)
==23089==    by 0xC698E3A: connection_from_file (reader.c:4316)
==23089==    by 0xC69135C: nm_ifcfg_connection_new (nm-ifcfg-connection.c:119)
2013-03-08 09:27:51 -06:00
Dan Winship d04f286327 all: remove pointless NULL checks
g_malloc(), etc, never return NULL, by API contract. Likewise, by
extension, no other glib function ever returns NULL due to lack of
memory. So remove lots of unnecessary checks (the vast majority of
which would have immediately crashed had they ever run anyway, since
g_set_error(), g_warning(), and nm_log_*() all need to allocate
memory).

https://bugzilla.gnome.org/show_bug.cgi?id=693678
2013-02-13 13:38:13 -05:00
Dan Williams 38e3819b4e libnm-util: clean up setting registration
Make setting type registration less icky; instead of having the
connection register all the settings, have the settings themselves
register that information at library load time.  Putting this sort
of thing in G_DEFINE_TYPE_WITH_CODE is apparently more standard
than the home-rolled stuff we had before.  Also document the
priority stuff so when adding new settings, people know what
priority to use.

(cleanups by jklimes)
2012-10-29 15:12:58 -05:00
Dan Winship 6878d20ac4 all: Don't use ctype.h macros
The ctype macros (eg, isalnum(), tolower()) are locale-dependent. Use
glib's ASCII-only versions instead.

Also, replace isascii() with g_ascii_isprint(), since isascii()
accepts control characters, which isn't what the code wanted in any of
the places where it was using it.
2012-09-26 12:14:37 -04:00
Dan Winship 839eab5564 Use glib-mkenums to generate enum types
Rather than generating enum classes by hand (and complaining in each
file that "this should really be standard"), use glib-mkenums.

Unfortunately, we need a very new version of glib-mkenums in order to
deal with NM's naming conventions and to fix a few other bugs, so just
import that into the source tree temporarily.

Also, to simplify the use of glib-mkenums, import Makefile.glib from
https://bugzilla.gnome.org/654395.

To avoid having to run glib-mkenums for every subdirectory of src/,
add a new "generated" directory, and put the generated enums files
there.

Finally, use Makefile.glib for marshallers too, and generate separate
ones for libnm-glib and NetworkManager.
2012-02-15 11:42:15 -05:00
Jiří Klimeš 0ba66f8272 libnm-util: add 'pac-file' property for 8021x setting (used in EAP-FAST) 2012-01-27 11:46:36 +01:00
Evan Broder dc92d1258d settings: Add new password-raw and password-raw-flags properties to 8021x.
In cases where the actual password is non-ASCII, it may not be
possible to deliver the 802.1x password as a D-Bus string. Instead
provide an alternate field holding the password as a byte array.

In cases where both a password and password-raw are supplied,
password is preferred.
2011-11-21 23:50:48 -06:00
Dan Williams a8eaa4a3ea docs: fix a wrong variable name in code documentation 2011-08-22 20:33:07 -05:00
Evan Broder 4f38f02add settings: add 802.1X setting properties for subject and altsubject matches
Includes subject_match and phase2_subject_match (string) parameters,
and altsubject_matches and phase2_altsubject_matches (list of string)
parameters.

subject_match is matched against a substring of the subject from the
certificate presented by the remote authentication server. If this
option is unset, no subject verification is performed.

altsubject_matches are each tested against the alternate subject name
(altSubjectName) of the certificate presented by the remote
authentication server. If this option is unset, no verification of the
altSubjectName is performed.
2011-08-19 18:20:41 -05:00
Dan Williams 8f48bc92e9 libnm-util: more 802.1x setting documentation updates 2011-07-02 15:47:15 -05:00
Dan Williams 479bd2b12e libnm-util: update 802.1x setting documentation 2011-07-02 15:38:41 -05:00
Dan Williams ab56b8e925 libnm-util: clarify certificate and key argument names
Clarify that these are supposed to be paths in the argument name;
this shouldn't break API as it's just an argument rename.  Helps
users figure out what the argument should be without as much trouble
as 'value', which is what it was before.
2011-05-10 12:44:01 -05:00