diff options
author | Roshan Pius <rpius@chromium.org> | 2014-11-07 09:20:20 -0800 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-11-18 17:06:29 +0100 |
commit | ec14ebce79fbff907ccbe3acf68838657579e152 (patch) | |
tree | bb6ebf1b18cf980bcd8214427090cee2c6d68841 /src/libmbim-glib/mbim-proxy.c | |
parent | c65d3d8ee54d5b8bfa454c7770a5936bbd0341de (diff) |
libmbim-glib,proxy: add a configure flag to set the user ID of MBIM proxy
Currently, the MBIM proxy process assumes that it is run as root user and
that all incoming client connection users are also root.
However, it's not always preferable to run the MBIM proxy as root for
security reasons. On some platforms, the MBIM proxy could be constrained
to run as a less-privileged user and specially granted the permission to
access the MBIM device. So, adding a compile time flag in libmbim to check
for the specified user, rather than assume it to be the root user. If the flag is
not sent, it'll revert to the existing behaviour of checking for
user=root(i.e UID=0)
Diffstat (limited to 'src/libmbim-glib/mbim-proxy.c')
-rw-r--r-- | src/libmbim-glib/mbim-proxy.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/libmbim-glib/mbim-proxy.c b/src/libmbim-glib/mbim-proxy.c index aeced6d..0f86f19 100644 --- a/src/libmbim-glib/mbim-proxy.c +++ b/src/libmbim-glib/mbim-proxy.c @@ -25,12 +25,15 @@ #include <string.h> #include <ctype.h> #include <sys/file.h> +#include <sys/types.h> #include <errno.h> +#include <pwd.h> #include <glib.h> #include <glib/gstdio.h> #include <gio/gunixsocketaddress.h> +#include "config.h" #include "mbim-device.h" #include "mbim-utils.h" #include "mbim-proxy.h" @@ -1041,6 +1044,7 @@ incoming_cb (GSocketService *service, Client *client; GCredentials *credentials; GError *error = NULL; + struct passwd *expected_usr = NULL; uid_t uid; g_debug ("Client (%d) connection open...", g_socket_get_fd (g_socket_connection_get_socket (connection))); @@ -1060,8 +1064,17 @@ incoming_cb (GSocketService *service, return; } - if (uid != 0) { - g_warning ("Client not allowed: Not enough privileges"); + expected_usr = getpwnam (MBIM_PROXY_USERNAME); + if (!expected_usr) { + g_warning ("Unknown user configured: %s", MBIM_PROXY_USERNAME); + /* Falling back to check for root user if the configured user is unknown */ + if (uid != 0) { + g_warning ("Client not allowed: Not enough privileges"); + return; + } + } + else if (uid != expected_usr->pw_uid) { + g_warning ("Client not allowed: Not the expected user: %s", MBIM_PROXY_USERNAME); return; } @@ -1213,13 +1226,26 @@ MbimProxy * mbim_proxy_new (GError **error) { MbimProxy *self; - - /* Only root can run the mbim-proxy */ - if (getuid () != 0) { + struct passwd *expected_usr = NULL; + + /* Only the specified user can run the mbim-proxy */ + expected_usr = getpwnam (MBIM_PROXY_USERNAME); + if (!expected_usr) { + g_warning ("Unknown user configured: %s", MBIM_PROXY_USERNAME); + /* Falling back to check for root user if the configured user is unknown */ + if (getuid () != 0) { + g_set_error (error, + MBIM_CORE_ERROR, + MBIM_CORE_ERROR_FAILED, + "Not enough privileges"); + return NULL; + } + } + else if (getuid () != expected_usr->pw_uid) { g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED, - "Not enough privileges"); + "Not started with the expected user: %s", MBIM_PROXY_USERNAME); return NULL; } |