* [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege
@ 2015-02-09 6:11 Qu Wenruo
2015-02-10 13:30 ` David Sterba
0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2015-02-09 6:11 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
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 <quwenruo@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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege
2015-02-09 6:11 [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege Qu Wenruo
@ 2015-02-10 13:30 ` David Sterba
2015-02-11 0:29 ` Qu Wenruo
0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2015-02-10 13:30 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, dsterba
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege
2015-02-10 13:30 ` David Sterba
@ 2015-02-11 0:29 ` Qu Wenruo
2015-02-27 16:11 ` David Sterba
0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2015-02-11 0:29 UTC (permalink / raw)
To: dsterba, linux-btrfs
-------- Original Message --------
Subject: Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check
valid root/sudo privilege
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege
2015-02-11 0:29 ` Qu Wenruo
@ 2015-02-27 16:11 ` David Sterba
2015-03-02 0:43 ` Qu Wenruo
0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2015-02-27 16:11 UTC (permalink / raw)
To: Qu Wenruo; +Cc: dsterba, linux-btrfs
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 <dsterba@suse.cz>
> To: Qu Wenruo <quwenruo@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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege
2015-02-27 16:11 ` David Sterba
@ 2015-03-02 0:43 ` Qu Wenruo
0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2015-03-02 0:43 UTC (permalink / raw)
To: dsterba, linux-btrfs
> 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 <dsterba@suse.cz>
>> To: Qu Wenruo <quwenruo@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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-02 0:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-09 6:11 [PATCH] btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege Qu Wenruo
2015-02-10 13:30 ` David Sterba
2015-02-11 0:29 ` Qu Wenruo
2015-02-27 16:11 ` David Sterba
2015-03-02 0:43 ` Qu Wenruo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.