Hi,

I just wanted to see if there was still interest in the patch from
this thread last month.

Henry Yei <[email protected]>


On Mon, May 3, 2010 at 8:14 PM, Henry Yei <[email protected]> wrote:
> Garrett,
>
> This patch installs the trap for cleanup_test which removes the
> sudoers file only if it was installed by utimensat script, and also
> takes care of detecting whether sudo knows about the -n option.
>
> Signed-Off-By: <[email protected]>
>
>
> The patch was generated from ltp-dev git tree.
>
> I didn't realize Caspar's patch hadn't already been incorporated yet,
> so didn't account for it.
>
> Henry Yei <[email protected]>
>
>
> On Fri, Apr 30, 2010 at 7:41 PM, Garrett Cooper <[email protected]> wrote:
>> On Fri, Apr 30, 2010 at 3:56 PM, Henry Yei <[email protected]> wrote:
>>> If a sudo file exists, the patch doesn't touch it. If it does not, a
>>> sudoers file will be created and then it will remove it afterwards. I
>>> wouldn't feel confortable having a script modify a sudoers file if it
>>> already exists. The sudoers content that it does put in place just
>>> enables the root user to use sudo, which would not give it any more
>>> access than it already has. This text is available in every sudoers
>>> file I've looked at.
>>>
>>>
>>>
>>> While I was testing the patch with the ltp-dev branch, I noticed that
>>> the -n option was put in front of every sudo call in commit
>>> 2aa40f7e10518977881b933cc93b8f50847cf3cf in order to suppress the
>>> interactive password check.
>>>
>>> However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17
>>> from Ubuntu 9.04 supports the  -n option. The patch also removes the
>>> -n option from sudo calls. This option was added in 3/2008.
>>
>> Ugh. The sudo in gentoo did this though and that's the reason why I
>> added it in some scripts -- otherwise the pieces of junk halt waiting
>> for user input and I had manually kill the scripts >:(... I guess a
>> test will need to be added to ensure that sudo _does_ have the -n
>> option beforehand, if it does, add the -n option. Otherwise all people
>> running older versions are kind of SoL.
>>
>> sudo is still a non-standard tool and a pain in the butt to deal with
>> in scripts as it changes from time to time.
>>
>> FWIW your patch only deals with the case when the script `exits
>> cleanly' as there aren't any traps installed for cleanup_test.
>>
>>> On Fri, Apr 30, 2010 at 1:15 PM, Garrett Cooper <[email protected]> wrote:
>>>> On Fri, Apr 30, 2010 at 12:27 PM, Henry Yei <[email protected]> wrote:
>>>>> Speaking of the utimesat test and prerequisites, our test systems
>>>>> don't have a sudoers file by default, so we have an internal patch to
>>>>> utimesat to create a default one if non exist and remove it after the
>>>>> test is done. Would that be of interest to LTP?
>>>>>>>
>> Thanks,
>> -Garrett
>>
>

>>>>> On Tue, Apr 27, 2010 at 11:27 PM, Caspar Zhang <[email protected]> 
>>>>> wrote:
>>>>>> On Wed, Apr 28, 2010 at 2:04 PM, Garrett Cooper <[email protected]> 
>>>>>> wrote:
>>>>>>> The first item is different from the other two. The first one ignores 
>>>>>>> the
>>>>>>> signal (SIG_IGN), whereas the latter two cases reset the handler to the
>>>>>>> default one (SIG_DFL). I prefer the former format, because otherwise the
>>>>>>> signal handlers become reentrable on accident.
>>>>>>
>>>>>> I see. Thank you.
>>>>>>
>>>>>> The final patch ;-)
>>>>
>>>> If it:
>>>>
>>>> 1. Works in all cases, i.e. doesn't use version specific constructs
>>>> for sudo (which I haven't seen thus far, but just to be safe).
>>>> 2. Is properly reverted when the test is done (which includes the
>>>> following scenarios):
>>>>    a. File already exists. Backup the old file, revert it when the
>>>> test is completed (regardless of whether or not the test passed or the
>>>> test failed properly [*]).
>>>>    b. File doesn't exist. Nuke the file after the test is done.
>>>>
>>>>    ... sure.
>>>> Thanks,
>>>> -Garrett
>>>>
>>>> [*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
--- ltp-dev/testcases/kernel/syscalls/utimensat/utimensat_tests.sh	2010-04-30 15:33:10.779700483 -0700
+++ ltp-dev-wdir/testcases/kernel/syscalls/utimensat/utimensat_tests.sh	2010-05-03 19:53:52.271695289 -0700
@@ -64,13 +64,13 @@ setup_file()
     # Make sure any old version of file is deleted
 
     if test -e $FILE; then
-        sudo -n chattr -ai $FILE || return $?
-        sudo -n rm -f $FILE || return $?
+        sudo $s_arg chattr -ai $FILE || return $?
+        sudo $s_arg rm -f $FILE || return $?
     fi
 
     # Create file and make atime and mtime zero.
 
-    sudo -n -u $user_tester touch $FILE || return $?
+    sudo $s_arg -u $user_tester touch $FILE || return $?
     if ! $TEST_PROG -q $FILE 0 0 0 0 > $RESULT_FILE; then
         echo "Failed to set up test file $FILE" 1>&2
         exit 1
@@ -86,19 +86,19 @@ setup_file()
     # Set owner, permissions, and EFAs for file.
 
     if test -n "$2"; then
-        sudo -n chown $2 $FILE || return $?
+        sudo $s_arg chown $2 $FILE || return $?
     fi
 
-    sudo -n chmod $3 $FILE || return $?
+    sudo $s_arg chmod $3 $FILE || return $?
 
     if test -n "$4"; then
-        sudo -n chattr $4 $FILE || return $?
+        sudo $s_arg chattr $4 $FILE || return $?
     fi
 
     # Display file setup, for visual verification
 
     ls -l $FILE | awk '{ printf "Owner=%s; perms=%s; ", $3, $1}'
-    if ! sudo -n lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}'
+    if ! sudo $s_arg lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}'
     then
         return $?
     fi
@@ -215,7 +215,7 @@ run_test()
     cp $LTPROOT/testcases/bin/$TEST_PROG ./
     CMD="./$TEST_PROG -q $FILE $4"
     echo "$CMD"
-    sudo -n -u $user_tester $CMD > $RESULT_FILE
+    sudo $s_arg -u $user_tester $CMD > $RESULT_FILE
     check_result $? $5 $6 $7
     echo
 
@@ -224,7 +224,7 @@ run_test()
         setup_file $FILE "$1" "$2" "$3"
         CMD="./$TEST_PROG -q -d $FILE NULL $4"
         echo "$CMD"
-        sudo -n -u $user_tester $CMD > $RESULT_FILE
+        sudo $s_arg -u $user_tester $CMD > $RESULT_FILE
         check_result $? $5 $6 $7
         echo
     fi
@@ -237,18 +237,43 @@ run_test()
         setup_file $FILE "$1" "$2" "$3"
         CMD="./$TEST_PROG -q -w -d $FILE NULL $4"
         echo "$CMD"
-        sudo -n -u $user_tester $CMD > $RESULT_FILE
+        sudo $s_arg -u $user_tester $CMD > $RESULT_FILE
         check_result $? $5 $6 $7
         echo
     fi
 
-    sudo -n chattr -ai $FILE
-    sudo -n rm -f $FILE
+    sudo $s_arg chattr -ai $FILE
+    sudo $s_arg rm -f $FILE
+}
+
+cleanup_test()
+{
+	if test $sudoers_clean; then
+		sudo rm -f $sudoers
+	fi
 }
 #=====================================================================
 
 user_tester=nobody
-sudo -n -u $user_tester mkdir -p $TEST_DIR
+echo "test sudo for -n option, non-interactive"
+sudo -n true
+if test $? -eq 0; then
+	s_arg="-n"
+	echo "sudo supports -n"
+else
+	s_arg=
+	echo "sudo does not support -n"
+fi
+sudoers=/etc/sudoers
+if test ! -e $sudoers
+then
+	echo "root    ALL=(ALL)    ALL" > $sudoers
+	sudoers_clean=1
+	chmod 440 $sudoers
+	trap 'trap "" EXIT; cleanup_test' EXIT
+fi
+
+sudo $s_arg -u $user_tester mkdir -p $TEST_DIR
 cd $TEST_DIR
 chown root $LTPROOT/testcases/bin/$TEST_PROG
 chmod ugo+x,u+s $LTPROOT/testcases/bin/$TEST_PROG
------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to