def __init__(self, opts): sec1, sec2 = self._get_security(opts) # authsys1 = rpc.SecAuthSys(0, opts.machinename, opts.uid, opts.gid, []) authsys2 = rpc.SecAuthSys(0, opts.machinename, opts.uid + 1, opts.gid + 1, []) self.c1 = NFS4Client('client1_pid%i' % os.getpid(), opts.server, opts.port, opts.path, sec_list=[sec1], opts=opts) self.c2 = NFS4Client('client2_pid%i' % os.getpid(), opts.server, opts.port, opts.path, sec_list=[authsys2], opts=opts) self.longname = "a" * 512 self.uid = 0 self.gid = 0 self.opts = opts self.filedata = "This is the file test data." self.linkdata = "/etc/X11" self.stateid0 = stateid4(0, '') self.stateid1 = stateid4(0xffffffffL, '\xff' * 12)
def __init__(self, opts): sec1, sec2 = self._get_security(opts) # authsys1 = rpc.SecAuthSys(0, opts.machinename, opts.uid, opts.gid, []) authsys2 = rpc.SecAuthSys(0, opts.machinename, opts.uid+1, opts.gid+1, []) self.c1 = NFS4Client('client1_pid%i' % os.getpid(), opts.server, opts.port, opts.path, sec_list=[sec1], opts=opts) self.c2 = NFS4Client('client2_pid%i' % os.getpid(), opts.server, opts.port, opts.path, sec_list=[authsys2], opts=opts) self.longname = "a"*512 self.uid = 0 self.gid = 0 self.opts = opts self.filedata = "This is the file test data." self.linkdata = "/etc/X11" self.stateid0 = stateid4(0, '') self.stateid1 = stateid4(0xffffffffL, '\xff'*12)
def makeBadID(stateid): """Given a good stateid, makes it bad NOTE this looks into server opaque data, thus is very specific to server implementation. Consider this version of the function an example. """ boottime = stateid.other[0:4] bad = stateid4(stateid.seqid , boottime+"\07\07\07\07\07\07\07\07") return bad
def makeBadID(stateid): """Given a good stateid, makes it bad NOTE this looks into server opaque data, thus is very specific to server implementation. Consider this version of the function an example. """ boottime = stateid.other[0:4] bad = stateid4(stateid.seqid, boottime + "\07\07\07\07\07\07\07\07") return bad
def testBadStateid(t, env): """LOCK should return NFS4ERR_BAD_STATEID if use a bad id FLAGS: lock badid all DEPEND: MKFILE CODE: LOCK11 """ c = env.c1 c.init_connection() fh, stateid = c.create_confirm(t.code) res = c.lock_file(t.code, fh, stateid4(0, '')) check(res, NFS4ERR_BAD_STATEID, "LOCK with a bad stateid")
def testBadStateid(t, env): """OPEN_CONFIRM with a bad state should return NFS4ERR_BAD_STATEID FLAGS: openconfirm badid all CODE: OPCF5 """ c = env.c1 c.init_connection() res = c.create_file(t.code) check(res) fh = res.resarray[-1].switch.switch.object res = _confirm(t, c, fh, stateid4(0, '')) check(res, NFS4ERR_BAD_STATEID, "OPEN_CONFIRM with a bad state")
def testBadLockStateid(t, env): """LOCKU should return NFS4ERR_BAD_STATEID if use a bad id FLAGS: locku badid all DEPEND: MKFILE CODE: LKU8 """ c = env.c1 c.init_connection() fh, stateid = c.create_confirm(t.code) res1 = c.lock_file(t.code, fh, stateid) check(res1) res2 = c.unlock_file(1, fh, stateid4(0, "")) check(res2, NFS4ERR_BAD_STATEID, "LOCKU with a bad stateid")
def testBadLockStateid(t, env): """LOCKU should return NFS4ERR_BAD_STATEID if use a bad id FLAGS: locku badid all DEPEND: MKFILE CODE: LKU8 """ c = env.c1 c.init_connection() fh, stateid = c.create_confirm(t.code) res1 = c.lock_file(t.code, fh, stateid) check(res1) res2 = c.unlock_file(1, fh, stateid4(0, '')) check(res2, NFS4ERR_BAD_STATEID, "LOCKU with a bad stateid")
def makeBadIDganesha(stateid): """Given a good stateid, makes it bad NOTE this looks into server opaque data, thus is very specific to the Ganesha server. All tests which use this function have the flag 'ganesha' """ # Ganesha encodes the clientid into the first 64 bits of the 96 bit # other field, and then a 32 bit counter. We set that counter to 0 # to simulate a bad stateid. clientid = stateid.other[0:8] bad = stateid4(stateid.seqid, clientid + "\0\0\0\0") return bad
def makeBadIDganesha(stateid): """Given a good stateid, makes it bad NOTE this looks into server opaque data, thus is very specific to the Ganesha server. All tests which use this function have the flag 'ganesha' """ # Ganesha encodes the clientid into the first 64 bits of the 96 bit # other field, and then a 32 bit counter. We set that counter to 0 # to simulate a bad stateid. clientid = stateid.other[0:8] bad = stateid4(stateid.seqid , clientid+"\0\0\0\0") return bad
def makeStaleId(stateid): """Given a good stateid, makes it stale NOTE this looks into server opaque data, thus is very specific to the CITI linux server. All tests which use this function have the flag 'staleid'. This is also valid for Ganesha (and probably other server implementations, putting a 32 bit epoch into the first 32 bits of the stateid is the easiest way to detect stale stateid after reboot). """ # The first 4 bytes of the linux stateid correspond to a time. # Choose a value older than any reasonable time, without # risking the chance of conflict with the zero-stateid. staletime = "\0\0\0\1" stale = stateid4(stateid.seqid , staletime+"\0\0\0\0\0\0\0\0") return stale
def makeStaleId(stateid): """Given a good stateid, makes it stale NOTE this looks into server opaque data, thus is very specific to the CITI linux server. All tests which use this function have the flag 'staleid'. This is also valid for Ganesha (and probably other server implementations, putting a 32 bit epoch into the first 32 bits of the stateid is the easiest way to detect stale stateid after reboot). """ # The first 4 bytes of the linux stateid correspond to a time. # Choose a value older than any reasonable time, without # risking the chance of conflict with the zero-stateid. staletime = "\0\0\0\1" stale = stateid4(stateid.seqid, staletime + "\0\0\0\0\0\0\0\0") return stale
from st_create_session import create_session from nfs4_const import * from environment import check, checklist, fail, create_file, open_file, close_file from environment import open_create_file_op from nfs4_type import open_owner4, openflag4, createhow4, open_claim4 from nfs4_type import creatverfattr, fattr4, stateid4, locker4, lock_owner4 from nfs4_type import open_to_lock_owner4 import nfs4_ops as op import threading current_stateid = stateid4(1, '\0' * 12) def testOpenAndClose(t, env): """test current state id processing by having OPEN and CLOSE in a single compound FLAGS: currentstateid all CODE: CSID1 """ sess1 = env.c1.new_client_session(env.testname(t)) open_op = open_create_file_op(sess1, env.testname(t), open_create=OPEN4_CREATE) res = sess1.compound(open_op + [op.close(0, current_stateid)]) check(res, NFS4_OK) def testLockLockU(t, env): """test current state id processing by having LOCK and LOCKU in a single compound
from Crypto.Cipher import AES except ImportError: class AES(object): """Create a fake class to use as a placeholder. This will give an error only if actually used. """ MODE_CBC = 0 def new(self, *args, **kwargs): raise NotImplementedError("could not import Crypto.Cipher") # Special stateids state00 = nfs4_type.stateid4(0, "\0" * 12) state11 = nfs4_type.stateid4(0xffffffff, "\xff" * 12) state01 = nfs4_type.stateid4(1, "\0" * 12) import hashlib # Note this requires 2.5 or higher # Note that all the oid strings have tag and length bytes prepended, as # per description of sec_oid4 in draft26 sect 3.2 # The strings are oid values derived from RFC4055 section 2.1 # sha1 : 1.3.14.3.2.26 # sha256 : 2.16.840.1.101.3.4.2.4.1 # sha384 : 2.16.840.1.101.3.4.2.4.2 # sha512 : 2.16.840.1.101.3.4.2.4.3 # sha224 : 2.16.840.1.101.3.4.2.4.4 hash_oids = {
from st_create_session import create_session from nfs4_const import * from environment import check, checklist, fail, create_file, open_file, close_file from environment import open_create_file_op from nfs4_type import open_owner4, openflag4, createhow4, open_claim4 from nfs4_type import creatverfattr, fattr4, stateid4, locker4, lock_owner4 from nfs4_type import open_to_lock_owner4 import nfs4_ops as op import threading current_stateid = stateid4(1, '\0' * 12) def testOpenAndClose(t, env): """test current state id processing by having OPEN and CLOSE in a single compound FLAGS: currentstateid all CODE: CSID1 """ sess1 = env.c1.new_client_session(env.testname(t)) open_op = open_create_file_op(sess1, env.testname(t), open_create=OPEN4_CREATE) res = sess1.compound(open_op + [op.close(0, current_stateid)]) check(res, NFS4_OK) def testLockLockU(t, env):
import re from locking import Lock try: from Crypto.Cipher import AES except ImportError: class AES(object): """Create a fake class to use as a placeholder. This will give an error only if actually used. """ MODE_CBC = 0 def new(self, *args, **kwargs): raise NotImplementedError("could not import Crypto.Cipher") # Special stateids state00 = nfs4_type.stateid4(0, "\0" * 12) state11 = nfs4_type.stateid4(0xffffffff, "\xff" * 12) state01 = nfs4_type.stateid4(1, "\0" * 12) import hashlib # Note this requires 2.5 or higher # Note that all the oid strings have tag and length bytes prepended, as # per description of sec_oid4 in draft26 sect 3.2 # The strings are oid values derived from RFC4055 section 2.1 # sha1 : 1.3.14.3.2.26 # sha256 : 2.16.840.1.101.3.4.2.4.1 # sha384 : 2.16.840.1.101.3.4.2.4.2 # sha512 : 2.16.840.1.101.3.4.2.4.3 # sha224 : 2.16.840.1.101.3.4.2.4.4 hash_oids = {"sha1" : '\x06\x05\x2b\x0e\x03\x02\x1a',