From patchwork Wed May 13 00:07:34 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: 6392901 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D6F8ABEEE1 for ; Wed, 13 May 2015 00:08:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADBCF203F7 for ; Wed, 13 May 2015 00:08:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9259E203DF for ; Wed, 13 May 2015 00:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964807AbbEMAIs (ORCPT ); Tue, 12 May 2015 20:08:48 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:32857 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964799AbbEMAIr (ORCPT ); Tue, 12 May 2015 20:08:47 -0400 Received: by wief7 with SMTP id f7so124085426wie.0 for ; Tue, 12 May 2015 17:08:46 -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=LDluvH5B2v2QR9ZDxVy9cpUo/QnRuv9ii68x5UdltHI=; b=0dm2lqdagnj6LMJAiyt2JDJhod6x4Z05mnfTkFVkt1f1W5gTzuNChdSnJd21hbkWPR 8W6t+y+wUIlrwzb5y5xh1QAl5FQONJIkz4U/3n3A1CGSIeFwrzxCgKybXL3v98Mc4qfi cXZ+cVH048ssdyFqI2h6sSsVpXdCtgGODtkbuA4moClMqwveVSrr4NhfWxX5QBqRZ41w rtVtGbpPEnHdjhDOVLd+MAdVK487f8EUxkw+G6559exa0iO7zcOf+bvC/tZWJAnfVoFa yIwA9owu3FDxDvtDJsDq+cwxAiZ5bQPqKFjIfEfuchMcIpQ2hzjj7KCjQOt7V8GXIqv+ SU3w== X-Received: by 10.194.48.48 with SMTP id i16mr35473793wjn.40.1431475726059; Tue, 12 May 2015 17:08:46 -0700 (PDT) Received: from nuc.local (80-110-112-232.cgn.dynamic.surfer.at. [80.110.112.232]) by mx.google.com with ESMTPSA id b10sm1641604wic.1.2015.05.12.17.08.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 May 2015 17:08:45 -0700 (PDT) From: Andreas Gruenbacher To: fstests@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH] generic/326: Test the permission to set file times Date: Wed, 13 May 2015 02:07:34 +0200 Message-Id: <1431475654-23274-1-git-send-email-andreas.gruenbacher@gmail.com> X-Mailer: git-send-email 2.4.0 In-Reply-To: <20150512234005.GC4316@dastard> References: <20150512234005.GC4316@dastard> 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=ham 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. Signed-off-by: Andreas Gruenbacher --- src/fs_perms.c | 14 +++++++++- tests/generic/326 | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/326.out | 7 +++++ tests/generic/group | 1 + 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 tests/generic/326 create mode 100644 tests/generic/326.out diff --git a/src/fs_perms.c b/src/fs_perms.c index ea188c4..519db5b 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,7 +59,7 @@ 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); } @@ -113,6 +115,16 @@ int testfperm(int userId, int groupId, char* fperm) { seteuid(0); setegid(0); return(nuthertmpi); + } else if (!strcmp("t", fperm)) { + return 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 + }; + + return utime("test.file", ×) ? 0 : 1; } else { if((testfile=fopen("test.file",fperm))){ fclose(testfile); diff --git a/tests/generic/326 b/tests/generic/326 new file mode 100755 index 0000000..16388c1 --- /dev/null +++ b/tests/generic/326 @@ -0,0 +1,74 @@ +#! /bin/bash +# FSQA Test No. 326 +# +# 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 + +# 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 + +status=0 +exit diff --git a/tests/generic/326.out b/tests/generic/326.out new file mode 100644 index 0000000..78f7543 --- /dev/null +++ b/tests/generic/326.out @@ -0,0 +1,7 @@ +QA output created by 326 +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/group b/tests/generic/group index b6f4b01..1f2f3d2 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -192,3 +192,4 @@ 323 auto aio stress 324 auto fsr quick 325 auto quick data log +326 perms auto quick