From: NeilBrown Date: Sun, 31 Jan 2010 23:22:38 +0000 (+1100) Subject: Add test for "are we running as root". X-Git-Tag: mdadm-3.1.2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac5678dd9b67995a84bf2348d82e641d7895415e;p=thirdparty%2Fmdadm.git Add test for "are we running as root". 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 --- diff --git a/mdadm.c b/mdadm.c index be4fbf6d..eb124d53 100644 --- 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;