]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add test for "are we running as root".
authorNeilBrown <neilb@suse.de>
Sun, 31 Jan 2010 23:22:38 +0000 (10:22 +1100)
committerNeilBrown <neilb@suse.de>
Sun, 31 Jan 2010 23:22:38 +0000 (10:22 +1100)
Most operations require root access.  Rather than ensure we generate
the right error message when something fails because we aren't root,
check early.
Note that "--examine" does not necessarily require root, so test
for that first.

Resolves-Debian-bug: 396570
Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.c

diff --git a/mdadm.c b/mdadm.c
index be4fbf6dc29519b726a22adf8a733e7a818aae1c..eb124d53dcfd4c99f1539412fb638b946fe42eea 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1046,6 +1046,12 @@ int main(int argc, char *argv[])
                }
        }
 
+       if ((mode != MISC || devmode != 'E') &&
+           geteuid() != 0) {
+               fprintf(stderr, Name ": must be super-user to perform this action\n");
+               exit(1);
+       }
+
        ident.autof = autof;
 
        rv = 0;