Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege

2015-03-01 Thread Qu Wenruo

On Wed, Feb 11, 2015 at 08:29:06AM +0800, Qu Wenruo wrote:


 Original Message 
Subject: Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check
valid root/sudo privilege
From: David Sterba dste...@suse.cz
To: Qu Wenruo quwen...@cn.fujitsu.com
Date: 2015年02月10日 21:30

On Mon, Feb 09, 2015 at 02:11:52PM +0800, Qu Wenruo wrote:

Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt
user to input password and will return 1 if no valid credential is
found.

And this makes test result quite annoying since it fails to mount and
still continue, which will always fail.

This patch introduced the new check_sudo() to check sudo before calling
$sudo. This function will check sudo -v -n to get the credential.
And if it fails, then the test will not be run.

This logic is fine, but the setup fails for me even if typing the
password is not required. I think the 'sudo -v' check is wrong as it
tries to refresh the credentials.

$ sudo -v -n
sudo: a password is required

while

$ sudo -n /bin/true

works.

Err, this seems strange.
I think the bug is in sudo itself.


Or the the way sudo is configured in /etc/sudoers.


BTW, what's the version of your sudo?
Mine works fine even no need for password:
$ sudo -v -n
No error

My sudo version is 1.8.11p2


1.8.10p3

I don't know how to fix it so it works for both of us.

Hmm, what about using the following priority to setup sudo in 
setup_root_helper()?


UID==0
sudo -v -n if it works  For newer sudo
sudo -n if it works  For your version or older

Thanks,
Qu
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege

2015-02-10 Thread David Sterba
On Mon, Feb 09, 2015 at 02:11:52PM +0800, Qu Wenruo wrote:
 Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt
 user to input password and will return 1 if no valid credential is
 found.
 
 And this makes test result quite annoying since it fails to mount and
 still continue, which will always fail.
 
 This patch introduced the new check_sudo() to check sudo before calling
 $sudo. This function will check sudo -v -n to get the credential.
 And if it fails, then the test will not be run.

This logic is fine, but the setup fails for me even if typing the
password is not required. I think the 'sudo -v' check is wrong as it
tries to refresh the credentials.

  $ sudo -v -n
  sudo: a password is required

while

  $ sudo -n /bin/true

works.
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege

2015-02-10 Thread Qu Wenruo


 Original Message 
Subject: Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check 
valid root/sudo privilege

From: David Sterba dste...@suse.cz
To: Qu Wenruo quwen...@cn.fujitsu.com
Date: 2015年02月10日 21:30

On Mon, Feb 09, 2015 at 02:11:52PM +0800, Qu Wenruo wrote:

Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt
user to input password and will return 1 if no valid credential is
found.

And this makes test result quite annoying since it fails to mount and
still continue, which will always fail.

This patch introduced the new check_sudo() to check sudo before calling
$sudo. This function will check sudo -v -n to get the credential.
And if it fails, then the test will not be run.

This logic is fine, but the setup fails for me even if typing the
password is not required. I think the 'sudo -v' check is wrong as it
tries to refresh the credentials.

   $ sudo -v -n
   sudo: a password is required

while

   $ sudo -n /bin/true

works.

Err, this seems strange.
I think the bug is in sudo itself.

BTW, what's the version of your sudo?
Mine works fine even no need for password:
$ sudo -v -n
No error

My sudo version is 1.8.11p2

Thanks,
Qu

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege

2015-02-08 Thread Qu Wenruo
Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt
user to input password and will return 1 if no valid credential is
found.

And this makes test result quite annoying since it fails to mount and
still continue, which will always fail.

This patch introduced the new check_sudo() to check sudo before calling
$sudo. This function will check sudo -v -n to get the credential.
And if it fails, then the test will not be run.

Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
 tests/common | 18 ++
 tests/fsck-tests/012-leaf-corruption/test.sh |  9 +
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/tests/common b/tests/common
index d7d2e9b..56ae0e6 100644
--- a/tests/common
+++ b/tests/common
@@ -62,3 +62,21 @@ setup_root_helper()
fi
have_root_helper=1
 }
+
+check_sudo()
+{
+   if [ $UID -eq 0 ]; then
+   return 0
+   elif [ $have_root_helper ]; then
+   $sudo -v  /dev/null
+   return $?
+   else
+   return 1
+   fi
+}
+
+not_run_lack_privlege ()
+{
+   echo [NOTRUN] root or valid sudo credential needed
+   exit 0
+}
diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh 
b/tests/fsck-tests/012-leaf-corruption/test.sh
index 896f717..7396b05 100755
--- a/tests/fsck-tests/012-leaf-corruption/test.sh
+++ b/tests/fsck-tests/012-leaf-corruption/test.sh
@@ -55,12 +55,14 @@ check_inode()
name=$5
 
# Check whether the inode exists
+   check_sudo || not_run_lack_privlege
exists=$($sudo find $path -inum $ino)
if [ -z $exists ]; then
_fail inode $ino not recovered correctly
fi
 
# Check inode type
+   check_sudo || not_run_lack_privlege
found_mode=$(printf %o 0x$($sudo stat $exists -c %f))
if [ $found_mode -ne $mode ]; then
echo $found_mode
@@ -68,6 +70,7 @@ check_inode()
fi
 
# Check inode size
+   check_sudo || not_run_lack_privlege
found_size=$($sudo stat $exists -c %s)
if [ $mode -ne 41700 -a $found_size -ne $size ]; then
_fail inode $ino size not recovered correctly
@@ -85,15 +88,12 @@ check_inode()
 check_leaf_corrupt_no_data_ext()
 {
image=$1
-   if [ $have_root_helper -ne 1 ]; then
-   echo  [NOTRUN] root privileges needed to verify recovery
-   exit 0
-   fi
if [ -z $TEST_MNT ]; then
echo \$TEST_MNT not set, use $(pwd)/tmp as fallback
TEST_MNT=$(pwd)/tmp
fi
mkdir -p $TEST_MNT || _fail failed to create mount point
+   check_sudo || not_run_lack_privlege
$sudo mount $image -o ro $TEST_MNT
 
i=0
@@ -106,6 +106,7 @@ check_leaf_corrupt_no_data_ext()
${leaf_no_data_ext_list[i + 4]}
((i+=4))
done
+   check_sudo || not_run_lack_privlege
$sudo umount $TEST_MNT
 }
 
-- 
2.3.0

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html