Commit graph

32 commits

Author SHA1 Message Date
Thomas Haller
290d02536c auth-chain: avoid another idle-call when auth-request completes
NMAuthChain schedules (possibly) multiple authentication requests.
When they all complete, it will once invoke the result-callback.

There is no need to schedule this result-callback on another idle-handler,
because nm_auth_manager_polkit_authority_check_authorization() should guarantee
to invoke the callback never-synchronously and on a clean call-stack (to avoid
problems with re-entrancy). At that point, NMAuthChain does not need to
delay this further.
2018-04-13 09:09:46 +02:00
Thomas Haller
50b74731f6 auth-chain/trivial: rename nm_auth_chain_unref() to nm_auth_chain_destroy()
NMAuthChain is not really ref-counted. True, we have an internal ref-counter
to ensure that the instance stays alive while the callback is invoked. However,
the user cannot take additional references as there is no nm_auth_chain_ref().

When the user wants to get rid of the auth-chain, with the current API it
is important that the callback won't be called after that point. From the
name nm_auth_chain_unref(), it sounds like that there could be multiple references
to the auth-chain, and merely unreferencing the object might not guarantee that
the callback is canceled. However, that is luckily not the case, because
there is no real ref-counting involved here.

Just rename the destroy function to make this clearer.
2018-04-13 09:09:46 +02:00
Thomas Haller
d95717cdbe auth-chain: remove unused error argument 2018-04-13 09:09:46 +02:00
Thomas Haller
d0330bfa73 auth-chain: optimize tracking of user data for NMAuthChain
- instead of allocating memory separately for the @tag (key)
  and ChainData (data), store the tag also inside ChainData.
- instead of adding two separate key and value items to GHashTable,
  use g_hash_table_add(), which is optimized for this case.
2018-04-06 11:53:00 +02:00
Thomas Haller
67828918c9 auth-chain: don't compare pointers explicitly against NULL 2018-04-05 17:45:30 +02:00
Thomas Haller
c984f0f283 auth-chain: split handling auth-call in idle
auth_call_complete() had two callers: once from the idle handler, and
once from pk_call_cb(). The conditions are slightly different, split
the function in two. For one, this allows to unset the obsolete
call_idle_id.
2018-04-05 17:45:30 +02:00
Thomas Haller
2a998075e5 auth-chain/trivial: move code 2018-04-05 17:45:30 +02:00
Thomas Haller
6335627e77 auth-chain: drop unused nm_auth_chain_get_data_ulong() 2018-04-05 17:45:30 +02:00
Thomas Haller
6f4d5b2dfb auth-chain: use CList for tracking pending authentication requests 2018-04-05 17:45:30 +02: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
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
Dan Williams
e6f8494dc6 auth-utils: fix possibly uninitialized variables
src/nm-auth-utils.c:343:6: error: 'is_authorized' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   if (is_authorized) {
      ^
src/nm-auth-utils.c:320:11: note: 'is_authorized' was declared here
  gboolean is_authorized, is_challenge;
           ^
src/nm-auth-utils.c:346:13: error: 'is_challenge' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   } else if (is_challenge) {
             ^
src/nm-auth-utils.c:320:26: note: 'is_challenge' was declared here
  gboolean is_authorized, is_challenge;
                          ^

(cherry picked from commit 24ab2a4945)
2017-04-07 12:03:14 -05:00
Thomas Haller
ec2681d4db all: use nm_clear_g_cancellable() 2017-03-13 12:00:23 +01:00
Lubomir Rintel
00dbf6e90a auth-utils: don't fail the auth chain if we can't get a single permissions
It could be that the client is just newer and it's just too harsh to
fail the whole request. Leave the unknown permission in unknown and
possibly proceed filling in the rest.
2016-11-11 17:41:43 +01:00
Beniamino Galvani
b9e89c918f core: fix builds without polkit support
Fix the following build error:

 nm-auth-utils.c: In function ‘nm_auth_chain_add_call’:
 nm-auth-utils.c:402:46: error: ‘DBUS_GERROR’ undeclared (first use in this function)
     call->chain->error = g_error_new_literal (DBUS_GERROR,

Fixes: 1cf35cb26b
2016-08-17 11:28:55 +02:00
Thomas Haller
8e54cfdb27 all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" header 2016-06-01 19:06:35 +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
9e3d3083d2 auth-utils: some refactoring in nm-auth-utils.c
- move nm_auth_chain_check_done() and nm_auth_chain_remove_call()
  into the only caller auth_call_complete().

- take a ref of the "context" argument.

- in nm_auth_chain_add_call(), assert that we didn't yet invoke the
  done-callback. The auth-chain should not be reusued.

- use slice allocator for ChainData, AuthCall and NMAuthChain
2015-09-18 14:31:31 +02:00
Dan Winship
1cf35cb26b core: final gdbus porting
Port remaining bits to gdbus and remove stray dbus-glib references

Drop the dbus-glib version check from configure, since nothing depends
on new dbus-glib any more.

Move nm-dbus-glib-types.h and nm-gvaluearray-compat.h from include/ to
libnm-util/ since they are now only used by libnm-util and libnm-glib.
2015-08-10 09:41:26 -04:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Beniamino Galvani
e49cc5dfcd auth-utils: add nm_auth_chain_get_subject() 2015-08-04 09:32:12 +02:00
Dan Winship
c1dd3b6eed core: move D-Bus export/unexport into NMExportedObject
Move D-Bus export/unexport handling into NMExportedObject and remove
type-specific export/get_path methods (export paths are now specified
at the class level, and NMExportedObject handles the counters for all
exported types automatically).

Since all exportable objects now use the same get_path() method, we
can also add some helper methods to simplify get_property()
implementations for object-path and object-path-array properties.
2015-07-24 13:25:47 -04:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Lubomir Rintel
da5c332151 auth-utils: memleak: free the key when we steal data
==5177== 6 (+6) bytes in 1 (+1) blocks are definitely lost in loss record 118 of 6,581
==5177==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==5177==    by 0x7F4A6F5: g_malloc (gmem.c:97)
==5177==    by 0x7F6301E: g_strdup (gstrfuncs.c:356)
==5177==    by 0x4AD902: nm_auth_chain_set_data (nm-auth-utils.c:194)
==5177==    by 0x50919E: impl_agent_manager_register_with_capabilities (nm-agent-manager.c:323)
==5177==    by 0x62649BE: invoke_object_method (dbus-gobject.c:1899)
==5177==    by 0x62649BE: object_registration_message (dbus-gobject.c:2161)
==5177==    by 0x649D5CE: _dbus_object_tree_dispatch_and_unlock (dbus-object-tree.c:1018)
==5177==    by 0x648F193: dbus_connection_dispatch (dbus-connection.c:4718)
==5177==    by 0x6261DB4: message_queue_dispatch (dbus-gmain.c:90)
==5177==    by 0x7F44AEA: g_main_dispatch (gmain.c:3111)
==5177==    by 0x7F44AEA: g_main_context_dispatch (gmain.c:3710)
==5177==    by 0x7F44E87: g_main_context_iterate.isra.29 (gmain.c:3781)
==5177==    by 0x7F451B1: g_main_loop_run (gmain.c:3975)
2015-02-18 18:10:47 +01:00
Pavel Šimerda
cd5d5655ba auth: don't enforce user session
Access to connection configuration should not be blocked by absence of a
user session tracked using logind or consolekit. Access control based on
UID is sufficient.

This patch ensures that the user can always access connections even if
he doesn't have a session tracked by logind or consolekit and even when
NetworkManager is not built with logind or consolekit support.

Please note that presence or absence of a session tracked by logind or
consolekit doesn't carry any security information.

Acked-By: Thomas Haller <thaller@redhat.com>
Acked-By: Dan Williams <dcbw@redhat.com>
2015-02-17 17:11:08 +01:00
Pavel Šimerda
d42f2c11b7 auth: remove session monitor argument
There's no need to call `nm_session_monitor_get()` individually for each
call to `nm_auth_is_subject_in_acl()`.

Acked-By: Thomas Haller <thaller@redhat.com>
2015-01-05 18:38:44 +01:00
Pavel Šimerda
5fb31ba5d1 session: switch code to nm_session_monitor_session_exists()
Acked-By: Thomas Haller <thaller@redhat.com>
2015-01-05 18:38:22 +01: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
Thomas Haller
53e244bef6 auth: support disabling POLKIT authentication entirely at compile time
Let the user completly disable polkit authentication by
building NM with configure option  '--enable-polkit=disabled'.

In that case, configuring 'main.auth-polkit=yes' will fail all
authentication requests (except root-requests, which are always granted).

This reduces the size of the NetworkManager binary by some 26KB (16KB
stripped).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:51:11 +02:00
Thomas Haller
eabe7d856c auth: rework polkit autorization to use DBUS interface directly
This makes NetworkManager independent of <polkit/polkit.h>
development headers and libpolkit-gobject-1.so library.
Instead communicate directly with polkit using its DBUS
interface.

PolicyKit support is now always compiled in. You can control
polkit authorization with the configuration option
  [main]
  auth-polkit=yes|no

If the configure option is omitted, a build time default
value is used. This default value can be set with the
configure option --enable-polkit.

This commit adds a new class NMAuthManager that reimplements the
relevant DBUS client parts. It takes source code from the polkit
library.

https://bugzilla.gnome.org/show_bug.cgi?id=734146

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:51:11 +02:00
Thomas Haller
05494423de auth: rename file nm-manager-auth.* to nm-auth-utils.*
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:00:11 +02:00
Renamed from src/nm-manager-auth.c (Browse further)