From patchwork Thu May 14 13:50:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_Gr=C3=BCnbacher?= X-Patchwork-Id: 6405781 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 775439F318 for ; Thu, 14 May 2015 13:51:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F52A202B4 for ; Thu, 14 May 2015 13:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C8152044C for ; Thu, 14 May 2015 13:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933420AbbENNu6 (ORCPT ); Thu, 14 May 2015 09:50:58 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:36700 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933418AbbENNu4 (ORCPT ); Thu, 14 May 2015 09:50:56 -0400 Received: by wizk4 with SMTP id k4so242045052wiz.1 for ; Thu, 14 May 2015 06:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QDpuAQskxZUxOZDwVoqHK2HY/V1TzeE+4gvcrHhFHJc=; b=pJoNee/aJ6vnURyuECMEBZf+vlUvGNFNiZBCJWx/voihJtfX+41+4dzIfanT3QN+Mh j9nPkRnNkXK9PJnxMt9h0ELZ2DFPmLWkCs0+Tu7t6Heb+JKIerah8M2OZ74p+t1+OBgN UQdqcb24iZw+TMqkal9YHcZeRdeXXUBLs7FR0w1sTtwe4Gpm7GjC7hWByX+VMojX8d02 kUjJw0oOEcxtvAnGzZLEyT/pMon2+VLO/uismA67b1Q7hISgK/+Kz7Xk2xBtSwQYeI0L Ae9OZd/y8QUG1yrh+SSmG2A9LevoTfb/NT1pk6aAU0O3Y2arIwXocq4TV2bJkTQYAq8g vQdA== X-Received: by 10.180.88.72 with SMTP id be8mr49326948wib.45.1431611454565; Thu, 14 May 2015 06:50:54 -0700 (PDT) Received: from nuc.home.com (80-110-112-232.cgn.dynamic.surfer.at. [80.110.112.232]) by mx.google.com with ESMTPSA id gy8sm13413660wib.13.2015.05.14.06.50.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2015 06:50:53 -0700 (PDT) From: Andreas Gruenbacher To: Dave Chinner Cc: fstests@vger.kernel.org, Christoph Hellwig Subject: [PATCH] generic/087,126: Test the permission to set file times Date: Thu, 14 May 2015 15:50:09 +0200 Message-Id: <1431611409-26892-2-git-send-email-andreas.gruenbacher@gmail.com> X-Mailer: git-send-email 2.4.0 In-Reply-To: <1431611409-26892-1-git-send-email-andreas.gruenbacher@gmail.com> References: <20150514103028.GR15721@dastard> <1431611409-26892-1-git-send-email-andreas.gruenbacher@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check if setting the file access and modification times to the current time and to a specific timestamp is allowed when expected. In generic/126, remove a left-over temporary file. Signed-off-by: Andreas Gruenbacher --- src/fs_perms.c | 85 +++++++++++++++++++++++++++++---------------------- tests/generic/087 | 77 ++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/087.out | 7 +++++ tests/generic/126 | 2 ++ tests/generic/group | 1 + 5 files changed, 135 insertions(+), 37 deletions(-) create mode 100755 tests/generic/087 create mode 100644 tests/generic/087.out diff --git a/src/fs_perms.c b/src/fs_perms.c index ea188c4..5780016 100644 --- a/src/fs_perms.c +++ b/src/fs_perms.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include int testsetup(mode_t mode, int cuserId, int cgroupId); int testfperm(int userId, int groupId, char* fperm); @@ -57,13 +59,13 @@ int main( int argc, char *argv[]) { exresult = atoi(argv[7]); break; default: - printf("Usage: %s \n",argv[0]); + printf("Usage: %s \n",argv[0]); exit(0); } testsetup(mode,cuserId,cgroupId); result=testfperm(userId,groupId,fperm); - system("rm test.file"); + system("rm -f test.file"); printf("%s a %03o file owned by (%d/%d) as user/group(%d/%d) ",fperm,mode,cuserId,cgroupId,userId,groupId); if (result == exresult) { printf("PASS\n"); @@ -84,46 +86,55 @@ int testsetup(mode_t mode, int cuserId, int cgroupId) { int testfperm(int userId, int groupId, char* fperm) { - FILE *testfile; - pid_t PID; - int tmpi,nuthertmpi; + int ret; -/* SET CURRENT USER/GROUP PERMISSIONS */ + /* SET CURRENT USER/GROUP PERMISSIONS */ + ret = -1; if(setegid(groupId)) { - printf("could not setegid to %d.\n",groupId); - seteuid(0); - setegid(0); - return(-1); - } + printf("could not setegid to %d.\n",groupId); + goto out; + } if(seteuid(userId)) { - printf("could not seteuid to %d.\n",userId); - seteuid(0); - setegid(0); - return(-1); - } + printf("could not seteuid to %d.\n",userId); + goto out; + } if (!strcmp("x", fperm)) { - PID = fork(); - if (PID == 0) { - execlp("./test.file","test.file",NULL); - exit(0); - } - wait(&tmpi); - nuthertmpi=WEXITSTATUS(tmpi); - seteuid(0); - setegid(0); - return(nuthertmpi); + int status; + pid_t pid; + + pid = fork(); + if (pid == 0) { + execlp("./test.file","test.file",NULL); + exit(0); + } + wait(&status); + ret = WEXITSTATUS(status); + } else if (!strcmp("t", fperm)) { + ret = utime("test.file", NULL) ? 0 : 1; + } else if (!strcmp("T", fperm)) { + time_t now = time(NULL); + struct utimbuf times = { + .actime = now - 1, + .modtime = now - 1 + }; + + ret = utime("test.file", ×) ? 0 : 1; } else { - if((testfile=fopen("test.file",fperm))){ - fclose(testfile); - seteuid(0); - setegid(0); - return (1); - } - else { - seteuid(0); - setegid(0); - return (0); - } + FILE *file; + + if((file = fopen("test.file",fperm))){ + fclose(file); + ret = 1; + goto out; + } else { + ret = 0; + goto out; + } } + +out: + seteuid(0); + setegid(0); + return ret; } diff --git a/tests/generic/087 b/tests/generic/087 new file mode 100755 index 0000000..9653230 --- /dev/null +++ b/tests/generic/087 @@ -0,0 +1,77 @@ +#! /bin/bash +# FSQA Test No. 087 +# +# Check if setting the file access and modification times to the current time +# (t) and to a specific timestamp (T) is allowed when expected. +# +# From utime(2): Changing timestamps is permitted when: either the process has +# appropriate privileges, or the effective user ID equals the user ID of the +# file, or [the process is trying to set the timestamps to the current time] +# and the process has write permission for the file. +# +# Note that the last of these tests will always wrongly succeed over NFSv2. +# For NFSv3+, that test will wrongly succeed until kernel commit +# "Disable NFSv2 timestamp workaround for NFSv3+". +# +#----------------------------------------------------------------------- +# Copyright (c) 2015 Red Hat, Inc. +# Author: Andreas Gruenbacher +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_test + +QA_FS_PERMS=$here/src/fs_perms + +cd $TEST_DIR +cp $here/src/testx ./testx.file + +# The owner: +$QA_FS_PERMS 600 99 99 99 99 t 1 +$QA_FS_PERMS 600 99 99 99 99 T 1 + +# Other processes with and without write permission: +$QA_FS_PERMS 600 99 99 100 99 t 0 +$QA_FS_PERMS 600 99 99 100 99 T 0 +$QA_FS_PERMS 660 99 99 100 99 t 1 +$QA_FS_PERMS 660 99 99 100 99 T 0 + +rm -f ./testx.file + +status=0 +exit diff --git a/tests/generic/087.out b/tests/generic/087.out new file mode 100644 index 0000000..d74cc32 --- /dev/null +++ b/tests/generic/087.out @@ -0,0 +1,7 @@ +QA output created by 087 +t a 600 file owned by (99/99) as user/group(99/99) PASS +T a 600 file owned by (99/99) as user/group(99/99) PASS +t a 600 file owned by (99/99) as user/group(100/99) PASS +T a 600 file owned by (99/99) as user/group(100/99) PASS +t a 660 file owned by (99/99) as user/group(100/99) PASS +T a 660 file owned by (99/99) as user/group(100/99) PASS diff --git a/tests/generic/126 b/tests/generic/126 index a22d587..bb3a566 100755 --- a/tests/generic/126 +++ b/tests/generic/126 @@ -70,5 +70,7 @@ $QA_FS_PERMS 200 99 99 200 99 w 1 $QA_FS_PERMS 040 99 99 99 500 r 1 $QA_FS_PERMS 400 99 99 200 99 r 1 +rm -f ./testx.file + status=0 exit diff --git a/tests/generic/group b/tests/generic/group index b6f4b01..5308c37 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -89,6 +89,7 @@ 084 auto metadata quick 085 auto freeze mount 086 auto prealloc preallocrw quick +087 perms auto quick 088 perms auto quick 089 metadata auto 091 rw auto quick