Backport to stable nm-0-9-10: help & version options non-root




Backport to stable nm-0-9-10,
make it possible for non-root user to NetworkManager --help / --version.

Before:
$ NetworkManager 
You must be root to run NetworkManager!
$ NetworkManager --help
You must be root to run NetworkManager!
$ NetworkManager --version
You must be root to run NetworkManager!

Now:
$ NetworkManager 
You must be root to run NetworkManager!
$ NetworkManager --help
Usage:
  NetworkManager [OPTION...]
...
$ NetworkManager --version
0.9.10.2-3.fc21

See:
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?h=nm-1-0&id=4a42792
http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=95786a4

---
 src/main.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/main.c b/src/main.c
index 0713bc8..9f3021f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -325,6 +325,17 @@ _init_nm_debug (const char *debug)
        }
 }
 
+void     nm_main_utils_ensure_root (void);
+
+void
+nm_main_utils_ensure_root ()
+{
+       if (getuid () != 0) {
+               fprintf (stderr, _("You must be root to run NetworkManager!\n"));
+               exit (1);
+       }
+}
+
 /*
  * main
  *
@@ -397,11 +408,6 @@ main (int argc, char *argv[])
                exit (1);
        }
 
-       if (getuid () != 0) {
-               fprintf (stderr, _("You must be root to run NetworkManager!\n"));
-               exit (1);
-       }
-
        if (!nm_utils_init (&error)) {
                fprintf (stderr, _("Unable to initialize NetworkManager libraries: %s\n"),
                         error->message);
@@ -484,6 +490,8 @@ main (int argc, char *argv[])
                g_free (path);
        }
 
+       nm_main_utils_ensure_root ();
+
        /* Setup runtime directory */
        if (g_mkdir_with_parents (NMRUNDIR, 0755) != 0) {
                nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMRUNDIR, strerror (errno));
-- 
2.1.0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]