From patchwork Thu Apr 24 10:59:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4049451 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 714169F1F4 for ; Thu, 24 Apr 2014 11:08:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 830FD202EC for ; Thu, 24 Apr 2014 11:08:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 828DD201BA for ; Thu, 24 Apr 2014 11:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753959AbaDXLIf (ORCPT ); Thu, 24 Apr 2014 07:08:35 -0400 Received: from mail-pb0-f49.google.com ([209.85.160.49]:35410 "EHLO mail-pb0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755103AbaDXK7R (ORCPT ); Thu, 24 Apr 2014 06:59:17 -0400 Received: by mail-pb0-f49.google.com with SMTP id rr13so1808979pbb.8 for ; Thu, 24 Apr 2014 03:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=M62sxIgAI0Of4LymWYBZp2UwhWl/sRbAQMLDUvu6hrA=; b=hOzTXRI0fXGi8aNQ9GvgSv2ghwN90MwU2oxibaUCqXIYHzIvR9rhoTpICJU6d2PCO4 z8q9KFEeLMURY1jWtwOjlRWcPcN8pGhGYELNSH/ay3tszGfB6b82932btmhNz4J05fMq Q+99WJnTKt8p3x7eFWhqOYIfRLER+M5US7nEJrzNsShBlDE4Z0ZdzJxI13ELAnfEd5wX faDtvpz/3kW2PNU5nbPipiLRLKbF9yUCJE+7/Warzy1mxb9/zvMzpXR1wD8MuW8fxk4r HKB5jWKrceaexRDM7gq5yP1VhqjKp6g42l3YDLSiC1+D1lDHhFmrYYe/nN0S9bVDJBCD 06sA== X-Received: by 10.69.31.235 with SMTP id kp11mr64707199pbd.33.1398337156881; Thu, 24 Apr 2014 03:59:16 -0700 (PDT) Received: from [192.168.0.102] ([110.190.116.5]) by mx.google.com with ESMTPSA id qx11sm18760276pab.35.2014.04.24.03.59.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Apr 2014 03:59:15 -0700 (PDT) Message-ID: <5358EE7C.3030905@gmail.com> Date: Thu, 24 Apr 2014 18:59:08 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: "J. Bruce Fields" CC: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] NFS4.0: Cases for SGID/UID status after writing Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Signed-off-by: Kinglong Mee --- nfs4.0/servertests/environment.py | 10 +++++ nfs4.0/servertests/st_write.py | 90 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/nfs4.0/servertests/environment.py b/nfs4.0/servertests/environment.py index 993320d..355a928 100644 --- a/nfs4.0/servertests/environment.py +++ b/nfs4.0/servertests/environment.py @@ -113,6 +113,7 @@ class Environment(testmod.Environment): self.longname = "a"*512 self.uid = 0 self.gid = 0 + self.nclnt = 2 self.opts = opts self.filedata = "This is the file test data." self.linkdata = "/etc/X11" @@ -388,3 +389,12 @@ def compareTimes(time1, time2): if time1.nseconds > time2.nseconds: return 1 return 0 + +def clientWithSys(env, uid, gid): + opts = env.opts + env.nclnt += 1 + authsys = rpc.SecAuthSys(0, opts.machinename, uid, gid, []) + c = NFS4Client('client%d_pid%i' % (env.nclnt, os.getpid()), + opts.server, opts.port, opts.path, + sec_list=[authsys], opts=opts) + return c diff --git a/nfs4.0/servertests/st_write.py b/nfs4.0/servertests/st_write.py index 1a4deaf..d47704e 100644 --- a/nfs4.0/servertests/st_write.py +++ b/nfs4.0/servertests/st_write.py @@ -1,6 +1,6 @@ from nfs4_const import * from nfs4_type import * -from environment import check, checklist, compareTimes, makeBadID, makeBadIDganesha, makeStaleId +from environment import check, checklist, compareTimes, makeBadID, makeBadIDganesha, makeStaleId, clientWithSys import struct _text = 'write data' # len=10 @@ -384,3 +384,91 @@ def testSizes(t, env): ops += [c.getattr([FATTR4_SIZE]), c.getattr([FATTR4_SIZE])] res = c.compound(ops) check(res, msg="length %d WRITE" % i) + +def doCheckMode(t, c, fh, mode): + ops = c.use_obj(fh) + ops += [c.getattr([FATTR4_MODE, FATTR4_OWNER, FATTR4_OWNER_GROUP])] + res = c.compound(ops) + check(res) + + attrs = res.resarray[-1].obj_attributes + if FATTR4_MODE not in attrs.keys(): + t.fail("Attributes not contains FATTR4_MODE") + resmode = attrs[FATTR4_MODE] + if resmode != mode: + t.fail("Mode is %o, not expected %o" % (resmode, mode)) + +def doCheckSGUID(t, env, fsguid = 0, wsguid = 0, cmode = 06777): + c = env.c1 + path = c.homedir + [t.code] + res = c.create_obj(path, attrs={FATTR4_MODE:0777}) + check(res) + + c1 = clientWithSys(env, fsguid, fsguid) + c1.init_connection() + + attrs = {FATTR4_SIZE: 32, FATTR4_MODE: 06777} + path += [t.code] + fh, stateid = c1.create_confirm(t.code, path, attrs=attrs, + deny=OPEN4_SHARE_DENY_NONE) + doCheckMode(t, c1, fh, 06777) + + c2 = clientWithSys(env, wsguid, wsguid) + c2.init_connection() + + ops = c2.use_obj(fh) + ops += [c2.write_op(stateid4(0, ''), 0, UNSTABLE4, 'for test')] + res = c2.compound(ops) + check(res) + + doCheckMode(t, c2, fh, cmode) + +def testSGUIDRootRoot(t, env): + """ root writing data to file (blongs to root) + will not clear the SUID/SGID mode + + FLAGS: wrtie file all + DEPEND: MODE MKFILE + CODE: WRT16a + """ + doCheckSGUID(t, env) + +def testSGUIDRootNoRoot(t, env): + """ root writing data to file (blongs to no-root) + will not clear the SUID/SGID mode + + FLAGS: wrtie file all + DEPEND: MODE MKFILE + CODE: WRT16b + """ + doCheckSGUID(t, env, 9999) + +def testSGUIDNoRootSelf(t, env): + """ no-root writing data to file (blongs to self) + will clear the SUID/SGID mode + + FLAGS: wrtie file all + DEPEND: MODE MKFILE + CODE: WRT16c + """ + doCheckSGUID(t, env, 9999, 9999, 0777) + +def testSGUIDNoRootRoot(t, env): + """ no-root writing data to file (blongs to root) + will clear the SUID/SGID mode + + FLAGS: wrtie file all + DEPEND: MODE MKFILE + CODE: WRT16d + """ + doCheckSGUID(t, env, 0, 9999, 0777) + +def testSGUIDNoRootNoRoot(t, env): + """ no-root writing data to file (blongs to no-root) + will clear the SUID/SGID mode + + FLAGS: wrtie file all + DEPEND: MODE MKFILE + CODE: WRT16e + """ + doCheckSGUID(t, env, 6666, 9999, 0777)