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.

Signed-Off-By: <[email protected]>


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?
>>
>> 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-04-30 15:47:08.207696040 -0700
@@ -64,41 +64,41 @@ 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 chattr -ai $FILE || return $?
+        sudo rm -f $FILE || return $?
     fi
 
     # Create file and make atime and mtime zero.
 
-    sudo -n -u $user_tester touch $FILE || return $?
+    sudo -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
+        cleanup_test
     fi
 
     read res atime mtime < $RESULT_FILE
     if test "X$res" != "XSUCCESS" ||
                 test $atime -ne 0 || test $mtime != 0; then
         echo "Failed to set correct times on test file $FILE" 1>&2
-        exit 1
+        cleanup_test
     fi
 
     # Set owner, permissions, and EFAs for file.
 
     if test -n "$2"; then
-        sudo -n chown $2 $FILE || return $?
+        sudo chown $2 $FILE || return $?
     fi
 
-    sudo -n chmod $3 $FILE || return $?
+    sudo chmod $3 $FILE || return $?
 
     if test -n "$4"; then
-        sudo -n chattr $4 $FILE || return $?
+        sudo 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 lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}'
     then
         return $?
     fi
@@ -126,7 +126,7 @@ check_result()
 
     if test $STATUS -gt 1; then
         echo "FAILED (bad test setup)"
-        exit 1
+        cleanup_test
     fi
 
     read res atime mtime < $RESULT_FILE
@@ -204,7 +204,7 @@ run_test()
         W) do_write_fd_test=0
            ;;
         *) echo "run_test: bad usage"
-           exit 1
+           cleanup_test
            ;;
         esac
     done
@@ -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 -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 -u $user_tester $CMD > $RESULT_FILE
         check_result $? $5 $6 $7
         echo
     fi
@@ -237,18 +237,33 @@ 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 -u $user_tester $CMD > $RESULT_FILE
         check_result $? $5 $6 $7
         echo
     fi
 
-    sudo -n chattr -ai $FILE
-    sudo -n rm -f $FILE
+    sudo chattr -ai $FILE
+    sudo 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
+sudoers=/etc/sudoers
+if test ! -e $sudoers
+then
+	echo "root    ALL=(ALL)    ALL" > $sudoers
+	sudoers_clean=1
+	chmod 440 $sudoers
+fi
+sudo -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
@@ -437,6 +452,7 @@ echo "==================================
 
 echo
 
+cleanup_test
 rm -rf "$TEST_DIR"
 uname -a
 date
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to